Project import generated by Copybara.

GitOrigin-RevId: c55f2b9a3212fdb49d89ea101e924d46bfd959a2
diff --git a/.clang-format b/.clang-format
deleted file mode 100644
index 901467b..0000000
--- a/.clang-format
+++ /dev/null
@@ -1,130 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-#
-# clang-format configuration file. Intended for clang-format >= 4.
-#
-# For more information, see:
-#
-#   Documentation/process/clang-format.rst
-#   https://clang.llvm.org/docs/ClangFormat.html
-#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
-#
----
-AccessModifierOffset: -4
-AlignAfterOpenBracket: Align
-AlignConsecutiveAssignments: false
-AlignConsecutiveDeclarations: false
-#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
-AlignOperands: true
-AlignTrailingComments: false
-AllowAllParametersOfDeclarationOnNextLine: false
-AllowShortBlocksOnASingleLine: false
-AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: None
-AllowShortIfStatementsOnASingleLine: false
-AllowShortLoopsOnASingleLine: false
-AlwaysBreakAfterDefinitionReturnType: None
-AlwaysBreakAfterReturnType: None
-AlwaysBreakBeforeMultilineStrings: false
-AlwaysBreakTemplateDeclarations: false
-BinPackArguments: true
-BinPackParameters: true
-BraceWrapping:
-  AfterClass: false
-  AfterControlStatement: false
-  AfterEnum: false
-  AfterFunction: true
-  AfterNamespace: true
-  AfterObjCDeclaration: false
-  AfterStruct: false
-  AfterUnion: false
-  #AfterExternBlock: false # Unknown to clang-format-5.0
-  BeforeCatch: false
-  BeforeElse: false
-  IndentBraces: false
-  #SplitEmptyFunction: true # Unknown to clang-format-4.0
-  #SplitEmptyRecord: true # Unknown to clang-format-4.0
-  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
-BreakBeforeBinaryOperators: None
-BreakBeforeBraces: Custom
-#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
-BreakBeforeTernaryOperators: false
-BreakConstructorInitializersBeforeComma: false
-#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
-BreakAfterJavaFieldAnnotations: false
-BreakStringLiterals: false
-ColumnLimit: 80
-CommentPragmas: '^ IWYU pragma:'
-#CompactNamespaces: false # Unknown to clang-format-4.0
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
-ConstructorInitializerIndentWidth: 8
-ContinuationIndentWidth: 8
-Cpp11BracedListStyle: false
-DerivePointerAlignment: false
-DisableFormat: false
-ExperimentalAutoDetectBinPacking: false
-#FixNamespaceComments: false # Unknown to clang-format-4.0
-
-# Taken from:
-#   git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ \
-#   | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$,  - '\1'," \
-#   | sort | uniq
-ForEachMacros:
-  - 'list_for_each_entry'
-  - 'list_for_each_entry_safe'
-  - 'mnl_attr_for_each_nested'
-  - 'hlist_for_each'
-  - 'hlist_for_each_safe'
-  - 'hlist_for_each_entry'
-
-#IncludeBlocks: Preserve # Unknown to clang-format-5.0
-IncludeCategories:
-  - Regex: '.*'
-    Priority: 1
-IncludeIsMainRegex: '(Test)?$'
-IndentCaseLabels: false
-#IndentPPDirectives: None # Unknown to clang-format-5.0
-IndentWidth: 8
-IndentWrappedFunctionNames: false
-JavaScriptQuotes: Leave
-JavaScriptWrapImports: true
-KeepEmptyLinesAtTheStartOfBlocks: false
-MacroBlockBegin: ''
-MacroBlockEnd: ''
-MaxEmptyLinesToKeep: 1
-NamespaceIndentation: Inner
-#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
-ObjCBlockIndentWidth: 8
-ObjCSpaceAfterProperty: true
-ObjCSpaceBeforeProtocolList: true
-
-# Taken from git's rules
-#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
-PenaltyBreakBeforeFirstCallParameter: 30
-PenaltyBreakComment: 10
-PenaltyBreakFirstLessLess: 0
-PenaltyBreakString: 10
-PenaltyExcessCharacter: 100
-PenaltyReturnTypeOnItsOwnLine: 60
-
-PointerAlignment: Right
-ReflowComments: false
-SortIncludes: false
-#SortUsingDeclarations: false # Unknown to clang-format-4.0
-SpaceAfterCStyleCast: false
-SpaceAfterTemplateKeyword: true
-SpaceBeforeAssignmentOperators: true
-#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
-#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
-SpaceBeforeParens: ControlStatements
-#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
-SpaceInEmptyParentheses: false
-SpacesBeforeTrailingComments: 1
-SpacesInAngles: false
-SpacesInContainerLiterals: false
-SpacesInCStyleCastParentheses: false
-SpacesInParentheses: false
-SpacesInSquareBrackets: false
-Standard: Cpp03
-TabWidth: 8
-UseTab: Always
-...
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index e5234a3..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,41 +0,0 @@
-# locally generated
-Config
-static-syms.h
-config.*
-*.o
-*.a
-*.so
-*~
-\#*#
-
-# cscope
-cscope.*
-ncscope.*
-tags
-TAGS
-
-# git files that we don't want to ignore even it they are dot-files
-!.gitignore
-!.mailmap
-
-# for patch generation
-*.diff
-*.patch
-*.orig
-*.rej
-
-# for quilt
-.pc
-patches
-series
-
-# for gdb
-.gdbinit
-.gdb_history
-*.gdb
-
-# tests
-testsuite/results
-testsuite/iproute2/iproute2-this
-testsuite/tools/generate_nlmsg
-testsuite/tests/ip/link/dev_wo_vf_rate.nl
diff --git a/.mailmap b/.mailmap
deleted file mode 100644
index fd40c91..0000000
--- a/.mailmap
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# This list is used by git-shortlog to fix a few botched name translations
-# in the git archive, either because the author's full name was messed up
-# and/or not always written the same way, making contributions from the
-# same person appearing not to be so or badly displayed.
-#
-# Format
-#  Full name <goodaddress> <badaddress> 
-Steve Wise <larrystevenwise@gmail.com> <swise@opengridcomputing.com>
-Steve Wise <larrystevenwise@gmail.com> <swise@chelsio.com>
-
-Stephen Hemminger <stephen@networkplumber.org> <sthemmin@microsoft.com>
-Stephen Hemminger <stephen@networkplumber.org> <shemming@brocade.com>
-Stephen Hemminger <stephen@networkplumber.org> <stephen.hemminger@vyatta.com>
-Stephen Hemminger <stephen@networkplumber.org> <shemminger@vyatta.com>
-Stephen Hemminger <stephen@networkplumber.org> <shemminger>
-Stephen Hemminger <stephen@networkplumber.org> <shemminger@linux-foundation.org>
-Stephen Hemminger <stephen@networkplumber.org> <shemminger@osdl.org>
-Stephen Hemminger <stephen@networkplumber.org> <osdl.org!shemminger>
-Stephen Hemminger <stephen@networkplumber.org> <osdl.net!shemminger>
-
-David Ahern <dsahern@gmail.com> <dsa@cumulusnetworks.com>
diff --git a/MODULE_LICENSE_GPL b/MODULE_LICENSE_GPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_GPL
diff --git a/Makefile b/Makefile
index 0b79b1f..67176be 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,12 @@
-# SPDX-License-Identifier: GPL-2.0
-# Top level Makefile for iproute2
-
-ifeq ("$(origin V)", "command line")
-VERBOSE = $(V)
-endif
-ifndef VERBOSE
-VERBOSE = 0
-endif
-
-ifeq ($(VERBOSE),0)
-MAKEFLAGS += --no-print-directory
-endif
-
 PREFIX?=/usr
 LIBDIR?=$(PREFIX)/lib
 SBINDIR?=/sbin
 CONFDIR?=/etc/iproute2
-NETNS_RUN_DIR?=/var/run/netns
-NETNS_ETC_DIR?=/etc/netns
 DATADIR?=$(PREFIX)/share
-HDRDIR?=$(PREFIX)/include/iproute2
 DOCDIR?=$(DATADIR)/doc/iproute2
 MANDIR?=$(DATADIR)/man
 ARPDDIR?=/var/lib/arpd
 KERNEL_INCLUDE?=/usr/include
-BASH_COMPDIR?=$(DATADIR)/bash-completion/completions
 
 # Path to db_185.h include
 DBM_INCLUDE:=$(DESTDIR)/usr/include
@@ -36,87 +18,70 @@
 DEFINES+= -DNO_SHARED_LIBS
 endif
 
-DEFINES+=-DCONFDIR=\"$(CONFDIR)\" \
-         -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
-         -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\"
+DEFINES+=-DCONFDIR=\"$(CONFDIR)\"
+
+#options for decnet
+ADDLIB+=dnet_ntop.o dnet_pton.o
+
+#options for ipx
+ADDLIB+=ipx_ntop.o ipx_pton.o
 
 #options for mpls
 ADDLIB+=mpls_ntop.o mpls_pton.o
 
-CC := gcc
-HOSTCC ?= $(CC)
+CC = gcc
+HOSTCC = gcc
 DEFINES += -D_GNU_SOURCE
 # Turn on transparent support for LFS
 DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-CCOPTS = -O2 -pipe
+CCOPTS = -O2
 WFLAGS := -Wall -Wstrict-prototypes  -Wmissing-prototypes
 WFLAGS += -Wmissing-declarations -Wold-style-definition -Wformat=2
 
-CFLAGS := $(WFLAGS) $(CCOPTS) -I../include -I../include/uapi $(DEFINES) $(CFLAGS)
+CFLAGS := $(WFLAGS) $(CCOPTS) -I../include $(DEFINES) $(CFLAGS)
 YACCFLAGS = -d -t -v
 
-SUBDIRS=lib ip tc bridge misc netem genl tipc devlink rdma man
+SUBDIRS=lib ip tc bridge misc netem genl tipc man
 
-LIBNETLINK=../lib/libutil.a ../lib/libnetlink.a
+LIBNETLINK=../lib/libnetlink.a ../lib/libutil.a
 LDLIBS += $(LIBNETLINK)
 
-all: config.mk
+all: Config
 	@set -e; \
 	for i in $(SUBDIRS); \
-	do echo; echo $$i; $(MAKE) $(MFLAGS) -C $$i; done
+	do $(MAKE) $(MFLAGS) -C $$i; done
 
-help:
-	@echo "Make Targets:"
-	@echo " all                 - build binaries"
-	@echo " clean               - remove products of build"
-	@echo " distclean           - remove configuration and build"
-	@echo " install             - install binaries on local machine"
-	@echo " check               - run tests"
-	@echo " cscope              - build cscope database"
-	@echo " snapshot            - generate version number header"
-	@echo ""
-	@echo "Make Arguments:"
-	@echo " V=[0|1]             - set build verbosity level"
-
-config.mk:
+Config:
 	sh configure $(KERNEL_INCLUDE)
 
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONFDIR)
 	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
-	install -m 0755 -d $(DESTDIR)$(HDRDIR)
-	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
+	install -m 0755 -d $(DESTDIR)$(DOCDIR)/examples
+	install -m 0755 -d $(DESTDIR)$(DOCDIR)/examples/diffserv
+	install -m 0644 README.iproute2+tc $(shell find examples -maxdepth 1 -type f) \
+		$(DESTDIR)$(DOCDIR)/examples
+	install -m 0644 $(shell find examples/diffserv -maxdepth 1 -type f) \
+		$(DESTDIR)$(DOCDIR)/examples/diffserv
+	@for i in $(SUBDIRS) doc; do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONFDIR)
-	install -m 0755 -d $(DESTDIR)$(BASH_COMPDIR)
-	install -m 0644 bash-completion/tc $(DESTDIR)$(BASH_COMPDIR)
-	install -m 0644 include/bpf_elf.h $(DESTDIR)$(HDRDIR)
 
 snapshot:
 	echo "static const char SNAPSHOT[] = \""`date +%y%m%d`"\";" \
 		> include/SNAPSHOT.h
 
 clean:
-	@for i in $(SUBDIRS) testsuite; \
+	@for i in $(SUBDIRS) doc; \
 	do $(MAKE) $(MFLAGS) -C $$i clean; done
 
 clobber:
-	touch config.mk
+	touch Config
 	$(MAKE) $(MFLAGS) clean
-	rm -f config.mk cscope.*
+	rm -f Config cscope.*
 
 distclean: clobber
 
-check: all
-	$(MAKE) -C testsuite
-	$(MAKE) -C testsuite alltests
-	@if command -v man >/dev/null 2>&1; then \
-		echo "Checking manpages for syntax errors..."; \
-		$(MAKE) -C man check; \
-	else \
-		echo "man not installed, skipping checks for syntax errors."; \
-	fi
-
 cscope:
 	cscope -b -q -R -Iinclude -sip -slib -smisc -snetem -stc
 
diff --git a/NOTICE b/NOTICE
deleted file mode 120000
index d24842f..0000000
--- a/NOTICE
+++ /dev/null
@@ -1 +0,0 @@
-COPYING
\ No newline at end of file
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..3912109
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,340 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+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 Program or any portion
+of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+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 Program, 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 Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) 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; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, 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 executable.  However, as a
+special exception, the source code 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.
+
+If distribution of executable or 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 counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program 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.
+
+  5. 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 Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program 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 to
+this License.
+
+  7. 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 Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program 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 Program.
+
+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.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program 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.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies 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 Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, 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
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. 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 PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+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 program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..f002a84
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,2 @@
+ek@google.com
+lorenzo@google.com
diff --git a/README b/README
index bc82187..c7a5118 100644
--- a/README
+++ b/README
@@ -1,32 +1,28 @@
 This is a set of utilities for Linux networking.
 
 Information:
-    https://wiki.linuxfoundation.org/networking/iproute2
+    http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2
 
 Download:
     http://www.kernel.org/pub/linux/utils/net/iproute2/
 
-Stable version repository:
-    git://git.kernel.org/pub/scm/network/iproute2/iproute2.git
-
-Development repository:
-    git://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git
+Repository:
+    git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git
 
 How to compile this.
 --------------------
 1. libdbm
 
-arpd needs to have the berkeleydb development libraries. For Debian
-users this is the package with a name like libdbX.X-dev.
+arpd needs to have the db4 development libraries. For Debian
+users this is the package with a name like libdb4.x-dev.
 DBM_INCLUDE points to the directory with db_185.h which
 is the include file used by arpd to get to the old format Berkeley
 database routines.  Often this is in the db-devel package.
 
 2. make
 
-The makefile will automatically build a config.mk file which
-contains definitions of libraries that may or may not be available
-on the system such as: ATM, ELF, MNL, and SELINUX.
+The makefile will automatically build a Config file which
+contains whether or not ATM is available, etc.
 
 3. To make documentation, cd to doc/ directory , then
    look at start of Makefile and set correct values for
diff --git a/README.decnet b/README.decnet
new file mode 100644
index 0000000..4300f90
--- /dev/null
+++ b/README.decnet
@@ -0,0 +1,33 @@
+
+Here are a few quick points about DECnet support...
+
+ o iproute2 is the tool of choice for configuring the DECnet support for
+   Linux. For many features, it is the only tool which can be used to
+   configure them.
+
+ o No name resolution is available as yet, all addresses must be
+   entered numerically.
+
+ o Remember to set the hardware address of the interface using: 
+
+   ip link set ethX address xx:xx:xx:xx:xx:xx
+      (where xx:xx:xx:xx:xx:xx is the MAC address for your DECnet node
+       address)
+
+   if your Ethernet card won't listen to more than one unicast
+   mac address at once. If the Linux DECnet stack doesn't talk to
+   any other DECnet nodes, then check this with tcpdump and if its
+   a problem, change the mac address (but do this _before_ starting
+   any other network protocol on the interface)
+
+ o Whilst you can use ip addr add to add more than one DECnet address to an
+   interface, don't expect addresses which are not the same as the
+   kernels node address to work properly with 2.4 kernels. This should
+   be fine with 2.6 kernels as the routing code has been extensively
+   modified and improved.
+
+ o The DECnet support is currently self contained. It does not depend on
+   the libdnet library.
+
+Steve Whitehouse <steve@chygwyn.com>
+
diff --git a/README.devel b/README.devel
index 60c9546..9b7d11e 100644
--- a/README.devel
+++ b/README.devel
@@ -4,15 +4,12 @@
 Please submit both to the Linux networking mailing list
    <netdev@vger.kernel.org>
 
-The current source for the stable version is in the git repository:
-    git://git.kernel.org/pub/scm/network/iproute2/iproute2.git
+The current source is in the git repository:
+    git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git
 
-The development git repository is available at the following address:
-    git://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git
+The master branch contains the source corresponding to the current
+code in the mainline Linux kernel (ie follows Linus). The net-next
+branch is a temporary branch that tracks the code intended for the
+next release; it corresponds with networking development branch in
+the kernel.
 
-The stable repository contains the source corresponding to the
-current code in the Linux networking tree (net), which in turn is
-aligned on the mainline Linux kernel (ie follows Linus).
-The iproute2-next repository tracks the code intended for the next
-release; it corresponds with networking development tree (net-next)
-in the kernel.
diff --git a/README.distribution b/README.distribution
new file mode 100644
index 0000000..4e2e8ea
--- /dev/null
+++ b/README.distribution
@@ -0,0 +1,95 @@
+I. About the distribution tables
+
+The table used for "synthesizing" the distribution is essentially a scaled,
+translated, inverse to the cumulative distribution function.
+
+Here's how to think about it: Let F() be the cumulative distribution
+function for a probability distribution X.  We'll assume we've scaled
+things so that X has mean 0 and standard deviation 1, though that's not
+so important here.  Then:
+
+	F(x) = P(X <= x) = \int_{-inf}^x f
+
+where f is the probability density function.
+
+F is monotonically increasing, so has an inverse function G, with range
+0 to 1.  Here, G(t) = the x such that P(X <= x) = t.  (In general, G may
+have singularities if X has point masses, i.e., points x such that
+P(X = x) > 0.)
+
+Now we create a tabular representation of G as follows:  Choose some table
+size N, and for the ith entry, put in G(i/N).  Let's call this table T.
+
+The claim now is, I can create a (discrete) random variable Y whose
+distribution has the same approximate "shape" as X, simply by letting
+Y = T(U), where U is a discrete uniform random variable with range 1 to N.
+To see this, it's enough to show that Y's cumulative distribution function,
+(let's call it H), is a discrete approximation to F.  But
+
+	H(x) = P(Y <= x)
+	     = (# of entries in T <= x) / N   -- as Y chosen uniformly from T
+	     = i/N, where i is the largest integer such that G(i/N) <= x
+	     = i/N, where i is the largest integer such that i/N <= F(x)
+	     		-- since G and F are inverse functions (and F is
+	     		   increasing)
+	     = floor(N*F(x))/N
+
+as desired.
+
+II. How to create distribution tables (in theory)
+
+How can we create this table in practice? In some cases, F may have a
+simple expression which allows evaluating its inverse directly.  The
+Pareto distribution is one example of this.  In other cases, and
+especially for matching an experimentally observed distribution, it's
+easiest simply to create a table for F and "invert" it.  Here, we give
+a concrete example, namely how the new "experimental" distribution was
+created.
+
+1. Collect enough data points to characterize the distribution.  Here, I
+collected 25,000 "ping" roundtrip times to a "distant" point (time.nist.gov).
+That's far more data than is really necessary, but it was fairly painless to
+collect it, so...
+
+2. Normalize the data so that it has mean 0 and standard deviation 1.
+
+3. Determine the cumulative distribution.  The code I wrote creates a table
+covering the range -10 to +10, with granularity .00005.  Obviously, this
+is absurdly over-precise, but since it's a one-time only computation, I
+figured it hardly mattered.
+
+4. Invert the table: for each table entry F(x) = y, make the y*TABLESIZE
+(here, 4096) entry be x*TABLEFACTOR (here, 8192).  This creates a table
+for the ("normalized") inverse of size TABLESIZE, covering its domain 0
+to 1 with granularity 1/TABLESIZE.  Note that even with the granularity
+used in creating the table for F, it's possible not all the entries in
+the table for G will be filled in.  So, make a pass through the
+inverse's table, filling in any missing entries by linear interpolation.
+
+III. How to create distribution tables (in practice)
+
+If you want to do all this yourself, I've provided several tools to help:
+
+1. maketable does the steps 2-4 above, and then generates the appropriate
+header file.  So if you have your own time distribution, you can generate
+the header simply by:
+
+	maketable < time.values > header.h
+
+2. As explained in the other README file, the somewhat sleazy way I have
+of generating correlated values needs correction.  You can generate your
+own correction tables by compiling makesigtable and makemutable with
+your header file.  Check the Makefile to see how this is done.
+
+3. Warning: maketable, makesigtable and especially makemutable do
+enormous amounts of floating point arithmetic.  Don't try running
+these on an old 486.  (NIST Net itself will run fine on such a
+system, since in operation, it just needs to do a few simple integral
+calculations.  But getting there takes some work.)
+
+4. The tables produced are all normalized for mean 0 and standard
+deviation 1.  How do you know what values to use for real?  Here, I've
+provided a simple "stats" utility.  Give it a series of floating point
+values, and it will return their mean (mu), standard deviation (sigma),
+and correlation coefficient (rho).  You can then plug these values
+directly into NIST Net.
diff --git a/README.iproute2+tc b/README.iproute2+tc
new file mode 100644
index 0000000..2a5638d
--- /dev/null
+++ b/README.iproute2+tc
@@ -0,0 +1,123 @@
+iproute2+tc*
+
+It's the first release of Linux traffic control engine.
+
+
+NOTES.
+* csz scheduler is inoperational at the moment, and probably
+  never will be repaired but replaced with h-pfq scheduler.
+* To use "fw" classifier you will need ipfwchains patch.
+* No manual available. Ask me, if you have problems (only try to guess
+  answer yourself at first 8)).
+
+
+Micro-manual how to start it the first time
+-------------------------------------------
+
+A. Attach CBQ to eth1:
+
+tc qdisc add dev eth1 root handle 1: cbq bandwidth 10Mbit allot 1514 cell 8 \
+avpkt 1000 mpu 64
+
+B. Add root class:
+
+tc class add dev eth1 parent 1:0 classid 1:1 cbq bandwidth 10Mbit rate 10Mbit \
+allot 1514 cell 8 weight 1Mbit prio 8 maxburst 20 avpkt 1000
+
+C. Add default interactive class:
+
+tc class add dev eth1 parent 1:1 classid 1:2 cbq bandwidth 10Mbit rate 1Mbit \
+allot 1514 cell 8 weight 100Kbit prio 3 maxburst 20 avpkt 1000 split 1:0 \
+defmap c0
+
+D. Add default class:
+
+tc class add dev eth1 parent 1:1 classid 1:3 cbq bandwidth 10Mbit rate 8Mbit \
+allot 1514 cell 8 weight 800Kbit prio 7 maxburst 20 avpkt 1000 split 1:0 \
+defmap 3f
+
+etc. etc. etc. Well, it is enough to start 8) The rest can be guessed 8)
+Look also at more elaborated example, ready to start rsvpd,
+in rsvp/cbqinit.eth1.
+
+
+Terminology and advices about setting CBQ parameters may be found in Sally Floyd
+papers. 
+
+
+Pairs X:Y are class handles, X:0 are qdisc handles.
+weight should be proportional to rate for leaf classes
+(I choosed it ten times less, but it is not necessary)
+
+defmap is bitmap of logical priorities served by this class.
+
+E. Another qdiscs are simpler. F.e. let's join TBF on class 1:2
+
+tc qdisc add dev eth1 parent 1:2 tbf rate 64Kbit buffer 5Kb/8 limit 10Kb
+
+F. Look at all that we created:
+
+tc qdisc ls dev eth1
+tc class ls dev eth1
+
+G. Install "route" classifier on root of cbq and map destination from realm
+1 to class 1:2
+
+tc filter add dev eth1 parent 1:0 protocol ip prio 100 route to 1 classid 1:2
+
+H. Assign routes to 10.11.12.0/24 to realm 1
+
+ip route add 10.11.12.0/24 dev eth1 via whatever realm 1
+
+etc. The same thing can be made with rules.
+I still did not test ipchains, but they should work too.
+
+
+Setup and code example of BPF classifier and action can be found under
+examples/bpf/, which should explain everything for getting started.
+
+
+Setup of rsvp and u32 classifiers is more hairy.
+If you read RSVP specs, you will understand how rsvp classifier
+works easily. What's about u32... That's example:
+
+
+#! /bin/sh
+
+TC=/home/root/tc
+
+# Setup classifier root on eth1 root (it is cbq)
+$TC filter add dev eth1 parent 1:0 prio 5 protocol ip u32
+
+# Create hash table of 256 slots with ID 1:
+$TC filter add dev eth1 parent 1:0 prio 5 handle 1: u32 divisor 256
+
+# Add to 6th slot of hash table rule to select tcp/telnet to 193.233.7.75
+# direct it to class 1:4 and prescribe to fall to best effort,
+# if traffic violate TBF (32kbit,5K)
+$TC filter add dev eth1 parent 1:0 prio 5 u32 ht 1:6: \
+	match ip dst 193.233.7.75 \
+	match tcp dst 0x17 0xffff \
+	flowid 1:4 \
+	police rate 32kbit buffer 5kb/8 mpu 64 mtu 1514 index 1
+
+# Add to 1th slot of hash table rule to select icmp to 193.233.7.75
+# direct it to class 1:4 and prescribe to fall to best effort,
+# if traffic violate TBF (10kbit,5K)
+$TC filter add dev eth1 parent 1:0 prio 5 u32 ht 1:: \
+	sample ip protocol 1 0xff \
+	match ip dst 193.233.7.75 \
+	flowid 1:4 \
+	police rate 10kbit buffer 5kb/8 mpu 64 mtu 1514 index 2
+
+# Lookup hash table, if it is not fragmented frame
+# Use protocol as hash key
+$TC filter add dev eth1 parent 1:0 prio 5 handle ::1 u32 ht 800:: \
+	match ip nofrag \
+	offset mask 0x0F00 shift 6 \
+	hashkey mask 0x00ff0000 at 8 \
+	link 1:
+
+
+Alexey Kuznetsov
+kuznet@ms2.inr.ac.ru
diff --git a/README.lnstat b/README.lnstat
new file mode 100644
index 0000000..057925f
--- /dev/null
+++ b/README.lnstat
@@ -0,0 +1,81 @@
+lnstat - linux networking statistics
+(C) 2004 Harald Welte <laforge@gnumonks.org
+======================================================================
+
+This tool is a generalized and more feature-complete replacement for the old
+'rtstat' program.
+
+In addition to routing cache statistics, it supports any kind of statistics
+the linux kernel exports via a file in /proc/net/stat.  In a stock 2.6.9
+kernel, this is 
+	per-protocol neighbour cache statistics 
+		(ipv4, ipv6, atm, decnet)
+	routing cache statistics
+		(ipv4)
+	connection tracking statistics
+		(ipv4)
+
+Please note that lnstat will adopt to any additional statistics that might be
+added to the kernel at some later point
+
+I personally always like examples more than any reference documentation, so I
+list the following examples.  If somebody wants to do a manpage, feel free
+to send me a patch :)
+
+EXAMPLES:
+
+In order to get a list of supported statistics files, you can run
+
+	lnstat -d
+
+It will display something like
+ 
+/proc/net/stat/arp_cache:
+         1: entries
+         2: allocs
+         3: destroys
+[...]
+/proc/net/stat/rt_cache:
+         1: entries
+         2: in_hit
+         3: in_slow_tot
+
+You can now select the files/keys you are interested by something like
+
+	lnstat -k arp_cache:entries,rt_cache:in_hit,arp_cache:destroys
+
+arp_cach|rt_cache|arp_cach|
+ entries|  in_hit|destroys|
+       6|       6|       0|
+       6|       0|       0|
+       6|       2|       0|
+
+
+You can specify the interval (e.g. 10 seconds) by:
+	
+	lnstat -i 10
+
+You can specify to only use one particular statistics file:
+
+	lnstat -f ip_conntrack
+
+You can specify individual field widths 
+
+	lnstat -k arp_cache:entries,rt_cache:entries -w 20,8
+
+You can specify not to print a header at all
+	
+	lnstat -s 0
+
+You can specify to print a header only at start of the program
+
+	lnstat -s 1
+
+You can specify to print a header at start and every 20 lines:
+
+	lnstat -s 20
+
+You can specify the number of samples you want to take (e.g. 5):
+	
+	lnstat -c 5
+
diff --git a/README.version b/README.version
new file mode 100644
index 0000000..082fb9f
--- /dev/null
+++ b/README.version
@@ -0,0 +1,3 @@
+URL: https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.4.0.tar.gz
+Version: 3.4.0
+BugComponent: 119449
diff --git a/bash-completion/tc b/bash-completion/tc
deleted file mode 100644
index 007e1c2..0000000
--- a/bash-completion/tc
+++ /dev/null
@@ -1,800 +0,0 @@
-# tc(8) completion                                         -*- shell-script -*-
-# Copyright 2016 6WIND S.A.
-# Copyright 2016 Quentin Monnet <quentin.monnet@6wind.com>
-
-QDISC_KIND=' choke codel bfifo pfifo pfifo_head_drop fq fq_codel gred hhf \
-            mqprio multiq netem pfifo_fast pie red rr sfb sfq tbf atm cbq drr \
-            dsmark hfsc htb prio qfq '
-FILTER_KIND=' basic bpf cgroup flow flower fw route rsvp tcindex u32 matchall '
-ACTION_KIND=' gact mirred bpf sample '
-
-# Takes a list of words in argument; each one of them is added to COMPREPLY if
-# it is not already present on the command line. Returns no value.
-_tc_once_attr()
-{
-    local w subcword found
-    for w in $*; do
-        found=0
-        for (( subcword=3; subcword < ${#words[@]}-1; subcword++ )); do
-            if [[ $w == ${words[subcword]} ]]; then
-                found=1
-                break
-            fi
-        done
-        [[ $found -eq 0 ]] && \
-            COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )
-    done
-}
-
-# Takes a list of words in argument; each one of them is added to COMPREPLY if
-# it is not already present on the command line from the provided index. Returns
-# no value.
-_tc_once_attr_from()
-{
-    local w subcword found from=$1
-    shift
-    for w in $*; do
-        found=0
-        for (( subcword=$from; subcword < ${#words[@]}-1; subcword++ )); do
-            if [[ $w == ${words[subcword]} ]]; then
-                found=1
-                break
-            fi
-        done
-        [[ $found -eq 0 ]] && \
-            COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )
-    done
-}
-
-# Takes a list of words in argument; adds them all to COMPREPLY if none of them
-# is already present on the command line. Returns no value.
-_tc_one_of_list()
-{
-    local w subcword
-    for w in $*; do
-        for (( subcword=3; subcword < ${#words[@]}-1; subcword++ )); do
-            [[ $w == ${words[subcword]} ]] && return 1
-        done
-    done
-    COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
-}
-
-# Takes a list of words in argument; adds them all to COMPREPLY if none of them
-# is already present on the command line from the provided index. Returns no
-# value.
-_tc_one_of_list_from()
-{
-    local w subcword from=$1
-    shift
-    for w in $*; do
-        for (( subcword=$from; subcword < ${#words[@]}-1; subcword++ )); do
-            [[ $w == ${words[subcword]} ]] && return 1
-        done
-    done
-    COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
-}
-
-# Returns "$cur ${cur}arg1 ${cur}arg2 ..."
-_tc_expand_units()
-{
-    [[ $cur =~ ^[0-9]+ ]] || return 1
-    local value=${cur%%[^0-9]*}
-    [[ $cur == $value ]] && echo $cur
-    echo ${@/#/$value}
-}
-
-# Complete based on given word, usually $prev (or possibly the word before),
-# for when an argument or an option name has but a few possible arguments (so
-# tc does not take particular commands into account here).
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_direct_complete()
-{
-    case $1 in
-        # Command options
-        dev)
-            _available_interfaces
-            return 0
-            ;;
-        classid)
-            return 0
-            ;;
-        estimator)
-            local list=$( _tc_expand_units 'secs' 'msecs' 'usecs' )
-            COMPREPLY+=( $( compgen -W "$list" -- "$cur" ) )
-            return 0
-            ;;
-        handle)
-            return 0
-            ;;
-        parent|flowid)
-            local i iface ids cmd
-            for (( i=3; i < ${#words[@]}-2; i++ )); do
-                [[ ${words[i]} == dev ]] && iface=${words[i+1]}
-                break
-            done
-            for cmd in qdisc class; do
-                if [[ -n $iface ]]; then
-                    ids+=$( tc $cmd show dev $iface 2>/dev/null | \
-                        cut -d\  -f 3 )" "
-                else
-                    ids+=$( tc $cmd show 2>/dev/null | cut -d\  -f 3 )
-                fi
-            done
-            [[ $ids != " " ]] && \
-                COMPREPLY+=( $( compgen -W "$ids" -- "$cur" ) )
-            return 0
-            ;;
-        protocol) # list comes from lib/ll_proto.c
-            COMPREPLY+=( $( compgen -W ' 802.1Q 802.1ad 802_2 802_3 LLDP aarp \
-                all aoe arp atalk atmfate atmmpoa ax25 bpq can control cust \
-                ddcmp dec diag dna_dl dna_rc dna_rt econet ieeepup ieeepupat \
-                ip ipv4 ipv6 ipx irda lat localtalk loop mobitex ppp_disc \
-                ppp_mp ppp_ses ppptalk pup pupat rarp sca snap tipc tr_802_2 \
-                wan_ppp x25' -- "$cur" ) )
-            return 0
-            ;;
-        prio)
-            return 0
-            ;;
-        stab)
-            COMPREPLY+=( $( compgen -W 'mtu tsize mpu overhead
-                linklayer' -- "$cur" ) )
-            ;;
-
-        # Qdiscs and classes options
-        alpha|bands|beta|buckets|corrupt|debug|decrement|default|\
-        default_index|depth|direct_qlen|divisor|duplicate|ewma|flow_limit|\
-        flows|hh_limit|increment|indices|linklayer|non_hh_weight|num_tc|\
-        penalty_burst|penalty_rate|prio|priomap|probability|queues|r2q|\
-        reorder|vq|vqs)
-            return 0
-            ;;
-        setup)
-            COMPREPLY+=( $( compgen -W 'vqs' -- "$cur" ) )
-            return 0
-            ;;
-        hw)
-            COMPREPLY+=( $( compgen -W '1 0' -- "$cur" ) )
-            return 0
-            ;;
-        distribution)
-            COMPREPLY+=( $( compgen -W 'uniform normal pareto
-                paretonormal' -- "$cur" ) )
-            return 0
-            ;;
-        loss)
-            COMPREPLY+=( $( compgen -W 'random state gmodel' -- "$cur" ) )
-            return 0
-            ;;
-
-        # Qdiscs and classes options options
-        gap|gmodel|state)
-            return 0
-            ;;
-
-        # Filters options
-        map)
-            COMPREPLY+=( $( compgen -W 'key' -- "$cur" ) )
-            return 0
-            ;;
-        hash)
-            COMPREPLY+=( $( compgen -W 'keys' -- "$cur" ) )
-            return 0
-            ;;
-        indev)
-            _available_interfaces
-            return 0
-            ;;
-        eth_type)
-            COMPREPLY+=( $( compgen -W 'ipv4 ipv6' -- "$cur" ) )
-            return 0
-            ;;
-        ip_proto)
-            COMPREPLY+=( $( compgen -W 'tcp udp' -- "$cur" ) )
-            return 0
-            ;;
-
-        # Filters options options
-        key|keys)
-            [[ ${words[@]} =~ graft ]] && return 1
-            COMPREPLY+=( $( compgen -W 'src dst proto proto-src proto-dst iif \
-                priority mark nfct nfct-src nfct-dst nfct-proto-src \
-                nfct-proto-dst rt-classid sk-uid sk-gid vlan-tag rxhash' -- \
-                "$cur" ) )
-            return 0
-            ;;
-
-        # BPF options - used for filters, actions, and exec
-        export|bytecode|bytecode-file|object-file)
-            _filedir
-            return 0
-            ;;
-        object-pinned|graft) # Pinned object is probably under /sys/fs/bpf/
-            [[ -n "$cur" ]] && _filedir && return 0
-            COMPREPLY=( $( compgen -G "/sys/fs/bpf/*" -- "$cur" ) ) || _filedir
-            compopt -o nospace
-            return 0
-            ;;
-        section)
-            if (type objdump > /dev/null 2>&1) ; then
-                local fword objfile section_list
-                for (( fword=3; fword < ${#words[@]}-3; fword++ )); do
-                    if [[ ${words[fword]} == object-file ]]; then
-                        objfile=${words[fword+1]}
-                        break
-                    fi
-                done
-                section_list=$( objdump -h $objfile 2>/dev/null | \
-                    sed -n 's/^ *[0-9]\+ \([^ ]*\) *.*/\1/p' )
-                COMPREPLY+=( $( compgen -W "$section_list" -- "$cur" ) )
-            fi
-            return 0
-            ;;
-        import|run)
-            _filedir
-            return 0
-            ;;
-        type)
-            COMPREPLY+=( $( compgen -W 'cls act' -- "$cur" ) )
-            return 0
-            ;;
-
-        # Actions options
-        random)
-            _tc_one_of_list 'netrand determ'
-            return 0
-            ;;
-
-        # Units for option arguments
-        bandwidth|maxrate|peakrate|rate)
-            local list=$( _tc_expand_units 'bit' \
-                'kbit' 'kibit' 'kbps' 'kibps' \
-                'mbit' 'mibit' 'mbps' 'mibps' \
-                'gbit' 'gibit' 'gbps' 'gibps' \
-                'tbit' 'tibit' 'tbps' 'tibps' )
-            COMPREPLY+=( $( compgen -W "$list" -- "$cur" ) )
-            ;;
-        admit_bytes|avpkt|burst|cell|initial_quantum|limit|max|min|mtu|mpu|\
-        overhead|quantum|redflowlist)
-            local list=$( _tc_expand_units \
-                'b' 'kbit' 'k' 'mbit' 'm' 'gbit' 'g' )
-            COMPREPLY+=( $( compgen -W "$list" -- "$cur" ) )
-            ;;
-        db|delay|evict_timeout|interval|latency|perturb|rehash|reset_timeout|\
-        target|tupdate)
-            local list=$( _tc_expand_units 'secs' 'msecs' 'usecs' )
-            COMPREPLY+=( $( compgen -W "$list" -- "$cur" ) )
-            ;;
-    esac
-    return 1
-}
-
-# Complete with options names for qdiscs. Each qdisc has its own set of options
-# and it seems we cannot really parse it from anywhere, so we add it manually
-# in this function.
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_qdisc_options()
-{
-    case $1 in
-        choke)
-            _tc_once_attr 'limit bandwidth ecn min max burst'
-            return 0
-            ;;
-        codel)
-            _tc_once_attr 'limit target interval'
-            _tc_one_of_list 'ecn noecn'
-            return 0
-            ;;
-        bfifo|pfifo|pfifo_head_drop)
-            _tc_once_attr 'limit'
-            return 0
-            ;;
-        fq)
-            _tc_once_attr 'limit flow_limit quantum initial_quantum maxrate \
-                buckets'
-            _tc_one_of_list 'pacing nopacing'
-            return 0
-            ;;
-        fq_codel)
-            _tc_once_attr 'limit flows target interval quantum'
-            _tc_one_of_list 'ecn noecn'
-            return 0
-            ;;
-        gred)
-            _tc_once_attr 'setup vqs default grio vq prio limit min max avpkt \
-                burst probability bandwidth ecn harddrop'
-            return 0
-            ;;
-        hhf)
-            _tc_once_attr 'limit quantum hh_limit reset_timeout admit_bytes \
-                evict_timeout non_hh_weight'
-            return 0
-            ;;
-        mqprio)
-            _tc_once_attr 'num_tc map queues hw'
-            return 0
-            ;;
-        netem)
-            _tc_once_attr 'delay distribution corrupt duplicate loss ecn \
-                reorder rate'
-            return 0
-            ;;
-        pie)
-            _tc_once_attr 'limit target tupdate alpha beta'
-            _tc_one_of_list 'bytemode nobytemode'
-            _tc_one_of_list 'ecn noecn'
-            return 0
-            ;;
-        red)
-            _tc_once_attr 'limit min max avpkt burst adaptive probability \
-                bandwidth ecn harddrop'
-            return 0
-            ;;
-        rr|prio)
-            _tc_once_attr 'bands priomap multiqueue'
-            return 0
-            ;;
-        sfb)
-            _tc_once_attr 'rehash db limit max target increment decrement \
-                penalty_rate penalty_burst'
-            return 0
-            ;;
-        sfq)
-            _tc_once_attr 'limit perturb quantum divisor flows depth headdrop \
-                redflowlimit min max avpkt burst probability ecn harddrop'
-            return 0
-            ;;
-        tbf)
-            _tc_once_attr 'limit burst rate mtu peakrate latency overhead \
-                linklayer'
-            return 0
-            ;;
-        cbq)
-            _tc_once_attr 'bandwidth avpkt mpu cell ewma'
-            return 0
-            ;;
-        dsmark)
-            _tc_once_attr 'indices default_index set_tc_index'
-            return 0
-            ;;
-        hfsc)
-            _tc_once_attr 'default'
-            return 0
-            ;;
-        htb)
-            _tc_once_attr 'default r2q direct_qlen debug'
-            return 0
-            ;;
-        multiq|pfifo_fast|atm|drr|qfq)
-            return 0
-            ;;
-    esac
-    return 1
-}
-
-# Complete with options names for BPF filters or actions.
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_bpf_options()
-{
-    [[ ${words[${#words[@]}-3]} == object-file ]] && \
-        _tc_once_attr 'section export'
-    [[ ${words[${#words[@]}-5]} == object-file ]] && \
-        [[ ${words[${#words[@]}-3]} =~ (section|export) ]] && \
-        _tc_once_attr 'section export'
-    _tc_one_of_list 'bytecode bytecode-file object-file object-pinned'
-    _tc_once_attr 'verbose index direct-action action classid'
-    return 0
-}
-
-# Complete with options names for filter actions.
-# This function is recursive, thus allowing multiple actions statement to be
-# parsed.
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_filter_action_options()
-{
-    for ((acwd=$1; acwd < ${#words[@]}-1; acwd++));
-    do
-        if [[ action == ${words[acwd]} ]]; then
-            _tc_filter_action_options $((acwd+1)) && return 0
-        fi
-    done
-
-    local action acwd
-    for ((acwd=$1; acwd < ${#words[@]}-1; acwd++)); do
-        if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then
-            _tc_one_of_list_from $acwd action
-            _tc_action_options $acwd && return 0
-        fi
-    done
-    _tc_one_of_list_from $acwd $ACTION_KIND
-    return 0
-}
-
-# Complete with options names for filters.
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_filter_options()
-{
-
-    for ((acwd=$1; acwd < ${#words[@]}-1; acwd++));
-    do
-        if [[ action == ${words[acwd]} ]]; then
-            _tc_filter_action_options $((acwd+1)) && return 0
-        fi
-    done
-
-    filter=${words[$1]}
-    case $filter in
-        basic)
-            _tc_once_attr 'match action classid'
-            return 0
-            ;;
-        bpf)
-            _tc_bpf_options
-            return 0
-            ;;
-        cgroup)
-            _tc_once_attr 'match action'
-            return 0
-            ;;
-        flow)
-            local i
-            for (( i=5; i < ${#words[@]}-1; i++ )); do
-                if [[ ${words[i]} =~ ^keys?$ ]]; then
-                    _tc_direct_complete 'key'
-                    COMPREPLY+=( $( compgen -W 'or and xor rshift addend' -- \
-                        "$cur" ) )
-                    break
-                fi
-            done
-            _tc_once_attr 'map hash divisor baseclass match action'
-            return 0
-            ;;
-        matchall)
-            _tc_once_attr 'action classid skip_sw skip_hw'
-            return 0
-            ;;
-        flower)
-            _tc_once_attr 'action classid indev dst_mac src_mac eth_type \
-                ip_proto dst_ip src_ip dst_port src_port'
-            return 0
-            ;;
-        fw)
-            _tc_once_attr 'action classid'
-            return 0
-            ;;
-        route)
-            _tc_one_of_list 'from fromif'
-            _tc_once_attr 'to classid action'
-            return 0
-            ;;
-        rsvp)
-            _tc_once_attr 'ipproto session sender classid action tunnelid \
-                tunnel flowlabel spi/ah spi/esp u8 u16 u32'
-            [[ ${words[${#words[@]}-3]} == tunnel ]] && \
-                    COMPREPLY+=( $( compgen -W 'skip' -- "$cur" ) )
-            [[ ${words[${#words[@]}-3]} =~ u(8|16|32) ]] && \
-                    COMPREPLY+=( $( compgen -W 'mask' -- "$cur" ) )
-            [[ ${words[${#words[@]}-3]} == mask ]] && \
-                    COMPREPLY+=( $( compgen -W 'at' -- "$cur" ) )
-            return 0
-            ;;
-        tcindex)
-            _tc_once_attr 'hash mask shift classid action'
-            _tc_one_of_list 'pass_on fall_through'
-            return 0
-            ;;
-        u32)
-            _tc_once_attr 'match link classid action offset ht hashkey sample'
-            COMPREPLY+=( $( compgen -W 'ip ip6 udp tcp icmp u8 u16 u32 mark \
-                divisor' -- "$cur" ) )
-            return 0
-            ;;
-    esac
-    return 1
-}
-
-# Complete with options names for actions.
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_action_options()
-{
-    local from=$1
-    local action=${words[from]}
-    case $action in
-        bpf)
-            _tc_bpf_options
-            return 0
-            ;;
-        mirred)
-            _tc_one_of_list_from $from 'ingress egress'
-            _tc_one_of_list_from $from 'mirror redirect'
-            _tc_once_attr_from $from 'index dev'
-            return 0
-            ;;
-        sample)
-            _tc_once_attr_from $from 'rate'
-            _tc_once_attr_from $from 'trunc'
-            _tc_once_attr_from $from 'group'
-            return 0
-            ;;
-        gact)
-            _tc_one_of_list_from $from 'reclassify drop continue pass'
-            _tc_once_attr_from $from 'random'
-            return 0
-            ;;
-    esac
-    return 1
-}
-
-# Complete with options names for exec.
-# Returns 0 is completion should stop after running this function, 1 otherwise.
-_tc_exec_options()
-{
-    case $1 in
-        import)
-            [[ ${words[${#words[@]}-3]} == import ]] && \
-                _tc_once_attr 'run'
-            return 0
-            ;;
-        graft)
-            COMPREPLY+=( $( compgen -W 'key type' -- "$cur" ) )
-            [[ ${words[${#words[@]}-3]} == object-file ]] && \
-                _tc_once_attr 'type'
-            _tc_bpf_options
-            return 0
-            ;;
-    esac
-    return 1
-}
-
-# Main completion function
-# Logic is as follows:
-#   1. Check if previous word is a global option; if so, propose arguments.
-#   2. Check if current word is a global option; if so, propose completion.
-#   3. Check for the presence of a main command (qdisc|class|filter|...). If
-#      there is one, first call _tc_direct_complete to see if previous word is
-#      waiting for a particular completion. If so, propose completion and exit.
-#   4. Extract main command and -- if available -- its subcommand
-#      (add|delete|show|...).
-#   5. Propose completion based on main and sub- command in use. Additional
-#      functions may be called for qdiscs, classes or filter options.
-_tc()
-{
-    local cur prev words cword
-    _init_completion || return
-
-    case $prev in
-        -V|-Version)
-            return 0
-            ;;
-        -b|-batch|-cf|-conf)
-            _filedir
-            return 0
-            ;;
-        -force)
-            COMPREPLY=( $( compgen -W '-batch' -- "$cur" ) )
-            return 0
-            ;;
-        -nm|name)
-            [[ -r /etc/iproute2/tc_cls ]] || \
-                COMPREPLY=( $( compgen -W '-conf' -- "$cur" ) )
-            return 0
-            ;;
-        -n|-net|-netns)
-            local nslist=$( ip netns list 2>/dev/null )
-            COMPREPLY+=( $( compgen -W "$nslist" -- "$cur" ) )
-            return 0
-            ;;
-        -tshort)
-            _tc_once_attr '-statistics'
-            COMPREPLY+=( $( compgen -W 'monitor' -- "$cur" ) )
-            return 0
-            ;;
-        -timestamp)
-            _tc_once_attr '-statistics -tshort'
-            COMPREPLY+=( $( compgen -W 'monitor' -- "$cur" ) )
-            return 0
-            ;;
-    esac
-
-    # Search for main commands
-    local subcword cmd subcmd
-    for (( subcword=1; subcword < ${#words[@]}-1; subcword++ )); do
-        [[ ${words[subcword]} == -b?(atch) ]] && return 0
-        [[ -n $cmd ]] && subcmd=${words[subcword]} && break
-        [[ ${words[subcword]} != -* && \
-            ${words[subcword-1]} != -@(n?(et?(ns))|c?(on)f) ]] && \
-            cmd=${words[subcword]}
-    done
-
-    if [[ -z $cmd ]]; then
-        case $cur in
-            -*)
-                local c='-Version -statistics -details -raw -pretty \
-                    -iec -graphe -batch -name -netns -timestamp'
-                [[ $cword -eq 1 ]] && c+=' -force'
-                COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
-                return 0
-                ;;
-            *)
-                COMPREPLY=( $( compgen -W "help $( tc help 2>&1 | \
-                    command sed \
-                    -e '/OBJECT := /!d' \
-                    -e 's/.*{//' \
-                    -e 's/}.*//' \
-                    -e \ 's/|//g' )" -- "$cur" ) )
-                return 0
-                ;;
-        esac
-    fi
-
-    [[ $subcmd == help ]] && return 0
-
-    # For this set of commands we may create COMPREPLY just by analysing the
-    # previous word, if it expects for a specific list of options or values.
-    if [[ $cmd =~ (qdisc|class|filter|action|exec) ]]; then
-        _tc_direct_complete $prev && return 0
-        if [[ ${words[${#words[@]}-3]} == estimator ]]; then
-            local list=$( _tc_expand_units 'secs' 'msecs' 'usecs' )
-            COMPREPLY+=( $( compgen -W "$list" -- "$cur" ) ) && return 0
-        fi
-    fi
-
-    # Completion depends on main command and subcommand in use.
-    case $cmd in
-        qdisc)
-            case $subcmd in
-                add|change|replace|link|del|delete)
-                    if [[ $(($cword-$subcword)) -eq 1 ]]; then
-                        COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) )
-                        return 0
-                    fi
-                    local qdisc qdwd
-                    for ((qdwd=$subcword; qdwd < ${#words[@]}-1; qdwd++)); do
-                        if [[ $QDISC_KIND =~ ' '${words[qdwd]}' ' ]]; then
-                            qdisc=${words[qdwd]}
-                            _tc_qdisc_options $qdisc && return 0
-                        fi
-                    done
-                    _tc_one_of_list $QDISC_KIND
-                    _tc_one_of_list 'root ingress parent clsact'
-                    _tc_once_attr 'handle estimator stab'
-                    ;;
-                show)
-                    _tc_once_attr 'dev'
-                    _tc_one_of_list 'ingress clsact'
-                    _tc_once_attr '-statistics -details -raw -pretty -iec \
-                        -graph -name'
-                    ;;
-                help)
-                    return 0
-                    ;;
-                *)
-                    [[ $cword -eq $subcword ]] && \
-                        COMPREPLY=( $( compgen -W 'help add delete change \
-                            replace link show' -- "$cur" ) )
-                    ;;
-            esac
-            ;;
-
-        class)
-            case $subcmd in
-                add|change|replace|del|delete)
-                    if [[ $(($cword-$subcword)) -eq 1 ]]; then
-                        COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) )
-                        return 0
-                    fi
-                    local qdisc qdwd
-                    for ((qdwd=$subcword; qdwd < ${#words[@]}-1; qdwd++)); do
-                        if [[ $QDISC_KIND =~ ' '${words[qdwd]}' ' ]]; then
-                            qdisc=${words[qdwd]}
-                            _tc_qdisc_options $qdisc && return 0
-                        fi
-                    done
-                    _tc_one_of_list $QDISC_KIND
-                    _tc_one_of_list 'root parent'
-                    _tc_once_attr 'classid'
-                    ;;
-                show)
-                    _tc_once_attr 'dev'
-                    _tc_one_of_list 'root parent'
-                    _tc_once_attr '-statistics -details -raw -pretty -iec \
-                        -graph -name'
-                    ;;
-                help)
-                    return 0
-                    ;;
-                *)
-                    [[ $cword -eq $subcword ]] && \
-                        COMPREPLY=( $( compgen -W 'help add delete change \
-                            replace show' -- "$cur" ) )
-                    ;;
-            esac
-            ;;
-
-        filter)
-            case $subcmd in
-                add|change|replace|del|delete)
-                    if [[ $(($cword-$subcword)) -eq 1 ]]; then
-                        COMPREPLY=( $( compgen -W 'dev' -- "$cur" ) )
-                        return 0
-                    fi
-                    local filter fltwd
-                    for ((fltwd=$subcword; fltwd < ${#words[@]}-1; fltwd++));
-                    do
-                        if [[ $FILTER_KIND =~ ' '${words[fltwd]}' ' ]]; then
-                            _tc_filter_options $fltwd && return 0
-                        fi
-                    done
-                    _tc_one_of_list $FILTER_KIND
-                    _tc_one_of_list 'root ingress egress parent'
-                    _tc_once_attr 'handle estimator pref protocol'
-                    ;;
-                show)
-                    _tc_once_attr 'dev'
-                    _tc_one_of_list 'root ingress egress parent'
-                    _tc_once_attr '-statistics -details -raw -pretty -iec \
-                        -graph -name'
-                    ;;
-                help)
-                    return 0
-                    ;;
-                *)
-                    [[ $cword -eq $subcword ]] && \
-                        COMPREPLY=( $( compgen -W 'help add delete change \
-                            replace show' -- "$cur" ) )
-                    ;;
-            esac
-            ;;
-
-        action)
-            case $subcmd in
-                add|change|replace)
-                    local action acwd
-                    for ((acwd=$subcword; acwd < ${#words[@]}-1; acwd++)); do
-                        if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then
-                            _tc_action_options $acwd && return 0
-                        fi
-                    done
-                    _tc_one_of_list $ACTION_KIND
-                    ;;
-                get|del|delete)
-                    _tc_once_attr 'index'
-                    ;;
-                lst|list|flush|show)
-                    _tc_one_of_list $ACTION_KIND
-                    ;;
-                *)
-                    [[ $cword -eq $subcword ]] && \
-                        COMPREPLY=( $( compgen -W 'help add delete change \
-                            replace show list flush action' -- "$cur" ) )
-                    ;;
-            esac
-            ;;
-
-        monitor)
-            COMPREPLY=( $( compgen -W 'help' -- "$cur" ) )
-            ;;
-
-        exec)
-            case $subcmd in
-                bpf)
-                    local excmd exwd EXEC_KIND=' import debug graft '
-                    for ((exwd=$subcword; exwd < ${#words[@]}-1; exwd++)); do
-                        if [[ $EXEC_KIND =~ ' '${words[exwd]}' ' ]]; then
-                            excmd=${words[exwd]}
-                            _tc_exec_options $excmd && return 0
-                        fi
-                    done
-                    _tc_one_of_list $EXEC_KIND
-                    ;;
-                *)
-                    [[ $cword -eq $subcword ]] && \
-                        COMPREPLY=( $( compgen -W 'bpf' -- "$cur" ) )
-                    ;;
-            esac
-            ;;
-    esac
-} &&
-complete -F _tc tc
-
-# ex: ts=4 sw=4 et filetype=sh
diff --git a/bridge/Android.mk b/bridge/Android.mk
deleted file mode 100644
index cf0487f..0000000
--- a/bridge/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := bridge
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := bridge.c \
-		   fdb.c \
-		   monitor.c \
-		   link.c \
-		   mdb.c \
-		   vlan.c
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
-		    $(LOCAL_PATH)/../include/uapi
-LOCAL_STATIC_LIBRARIES := libnetlink \
-			  libiprouteutil
-LOCAL_CFLAGS := \
-    -O2 -W -Wall \
-    -Wno-implicit-function-declaration \
-    -Wno-missing-field-initializers \
-    -Wno-pointer-arith \
-    -Wno-sign-compare \
-    -Wno-unused-parameter \
-    -Werror \
-    -D_GNU_SOURCE -DHAVE_SETNS
-include $(BUILD_EXECUTABLE)
diff --git a/bridge/Makefile b/bridge/Makefile
index c6b7d08..9800753 100644
--- a/bridge/Makefile
+++ b/bridge/Makefile
@@ -1,15 +1,18 @@
-# SPDX-License-Identifier: GPL-2.0
 BROBJ = bridge.o fdb.o monitor.o link.o mdb.o vlan.o
 
-include ../config.mk
+include ../Config
+
+ifeq ($(IP_CONFIG_SETNS),y)
+	CFLAGS += -DHAVE_SETNS
+endif
 
 all: bridge
 
-bridge: $(BROBJ) $(LIBNETLINK)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
+bridge: $(BROBJ) $(LIBNETLINK) 
 
 install: all
 	install -m 0755 bridge $(DESTDIR)$(SBINDIR)
 
 clean:
 	rm -f $(BROBJ) bridge
+
diff --git a/bridge/br_common.h b/bridge/br_common.h
index b5798da..169a162 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -1,26 +1,20 @@
-/* SPDX-License-Identifier: GPL-2.0 */
+extern int print_linkinfo(const struct sockaddr_nl *who,
+			  struct nlmsghdr *n,
+			  void *arg);
+extern int print_fdb(const struct sockaddr_nl *who,
+		     struct nlmsghdr *n, void *arg);
+extern int print_mdb(const struct sockaddr_nl *who,
+		     struct nlmsghdr *n, void *arg);
 
-#define MDB_RTA(r) \
-		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(struct br_mdb_entry))))
-
-#define MDB_RTR_RTA(r) \
-		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32))))
-
-void print_vlan_info(struct rtattr *tb, int ifindex);
-int print_linkinfo(struct nlmsghdr *n, void *arg);
-int print_mdb_mon(struct nlmsghdr *n, void *arg);
-int print_fdb(struct nlmsghdr *n, void *arg);
-
-int do_fdb(int argc, char **argv);
-int do_mdb(int argc, char **argv);
-int do_monitor(int argc, char **argv);
-int do_vlan(int argc, char **argv);
-int do_link(int argc, char **argv);
+extern int do_fdb(int argc, char **argv);
+extern int do_mdb(int argc, char **argv);
+extern int do_monitor(int argc, char **argv);
+extern int do_vlan(int argc, char **argv);
+extern int do_link(int argc, char **argv);
 
 extern int preferred_family;
 extern int show_stats;
 extern int show_details;
 extern int timestamp;
 extern int compress_vlans;
-extern int json;
 extern struct rtnl_handle rth;
diff --git a/bridge/bridge.c b/bridge/bridge.c
index a50d9d5..72f153f 100644
--- a/bridge/bridge.c
+++ b/bridge/bridge.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Get/set/delete bridge with netlink
  *
@@ -16,19 +15,18 @@
 #include "utils.h"
 #include "br_common.h"
 #include "namespace.h"
-#include "color.h"
 
 struct rtnl_handle rth = { .fd = -1 };
 int preferred_family = AF_UNSPEC;
+int resolve_hosts;
 int oneline;
 int show_stats;
 int show_details;
-static int color;
 int compress_vlans;
-int json;
 int timestamp;
-static const char *batch_file;
+char *batch_file;
 int force;
+const char *_SL_;
 
 static void usage(void) __attribute__((noreturn));
 
@@ -40,7 +38,7 @@
 "where	OBJECT := { link | fdb | mdb | vlan | monitor }\n"
 "	OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
 "		     -o[neline] | -t[imestamp] | -n[etns] name |\n"
-"		     -c[ompressvlans] -color -p[retty] -j[son] }\n");
+"		     -c[ompressvlans] }\n");
 	exit(-1);
 }
 
@@ -97,8 +95,6 @@
 		return EXIT_FAILURE;
 	}
 
-	rtnl_set_strict_dump(&rth);
-
 	cmdlineno = 0;
 	while (getcmdline(&line, &len, stdin) != -1) {
 		char *largv[100];
@@ -175,13 +171,8 @@
 				exit(-1);
 		} else if (matches(opt, "-compressvlans") == 0) {
 			++compress_vlans;
-		} else if (matches_color(opt, &color)) {
 		} else if (matches(opt, "-force") == 0) {
 			++force;
-		} else if (matches(opt, "-json") == 0) {
-			++json;
-		} else if (matches(opt, "-pretty") == 0) {
-			++pretty;
 		} else if (matches(opt, "-batch") == 0) {
 			argc--;
 			argv++;
@@ -199,16 +190,12 @@
 
 	_SL_ = oneline ? "\\" : "\n";
 
-	check_enable_color(color, json);
-
 	if (batch_file)
 		return batch(batch_file);
 
 	if (rtnl_open(&rth, 0) < 0)
 		exit(1);
 
-	rtnl_set_strict_dump(&rth);
-
 	if (argc > 1)
 		return do_cmd(argv[1], argc-1, argv+1);
 
diff --git a/bridge/fdb.c b/bridge/fdb.c
index 941ce2d..4d10925 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Get/set/delete fdb table with netlink
  *
@@ -22,29 +21,25 @@
 #include <linux/neighbour.h>
 #include <string.h>
 #include <limits.h>
-#include <stdbool.h>
 
-#include "json_print.h"
 #include "libnetlink.h"
 #include "br_common.h"
 #include "rt_names.h"
 #include "utils.h"
 
-static unsigned int filter_index, filter_vlan, filter_state, filter_master;
+static unsigned int filter_index;
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
-		"              [ self ] [ master ] [ use ] [ router ] [ extern_learn ]\n"
-		"              [ sticky ] [ local | static | dynamic ] [ dst IPADDR ]\n"
-		"              [ vlan VID ] [ port PORT] [ vni VNI ] [ via DEV ]\n"
-		"              [ src_vni VNI ]\n"
-		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n");
+	fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
+			"              [ self ] [ master ] [ use ] [ router ]\n"
+			"              [ local | temp ] [ dst IPADDR ] [ vlan VID ]\n"
+		        "              [ port PORT] [ vni VNI ] [ via DEV ]\n");
+	fprintf(stderr, "       bridge fdb [ show [ br BRDEV ] [ brport DEV ] ]\n");
 	exit(-1);
 }
 
-static const char *state_n2a(unsigned int s)
+static const char *state_n2a(unsigned s)
 {
 	static char buf[32];
 
@@ -64,80 +59,17 @@
 	return buf;
 }
 
-static int state_a2n(unsigned int *s, const char *arg)
-{
-	if (matches(arg, "permanent") == 0)
-		*s = NUD_PERMANENT;
-	else if (matches(arg, "static") == 0 || matches(arg, "temp") == 0)
-		*s = NUD_NOARP;
-	else if (matches(arg, "stale") == 0)
-		*s = NUD_STALE;
-	else if (matches(arg, "reachable") == 0 || matches(arg, "dynamic") == 0)
-		*s = NUD_REACHABLE;
-	else if (strcmp(arg, "all") == 0)
-		*s = ~0;
-	else if (get_unsigned(s, arg, 0))
-		return -1;
-
-	return 0;
-}
-
-static void fdb_print_flags(FILE *fp, unsigned int flags)
-{
-	open_json_array(PRINT_JSON,
-			is_json_context() ?  "flags" : "");
-
-	if (flags & NTF_SELF)
-		print_string(PRINT_ANY, NULL, "%s ", "self");
-
-	if (flags & NTF_ROUTER)
-		print_string(PRINT_ANY, NULL, "%s ", "router");
-
-	if (flags & NTF_EXT_LEARNED)
-		print_string(PRINT_ANY, NULL, "%s ", "extern_learn");
-
-	if (flags & NTF_OFFLOADED)
-		print_string(PRINT_ANY, NULL, "%s ", "offload");
-
-	if (flags & NTF_MASTER)
-		print_string(PRINT_ANY, NULL, "%s ", "master");
-
-	if (flags & NTF_STICKY)
-		print_string(PRINT_ANY, NULL, "%s ", "sticky");
-
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void fdb_print_stats(FILE *fp, const struct nda_cacheinfo *ci)
-{
-	static int hz;
-
-	if (!hz)
-		hz = get_user_hz();
-
-	if (is_json_context()) {
-		print_uint(PRINT_JSON, "used", NULL,
-				 ci->ndm_used / hz);
-		print_uint(PRINT_JSON, "updated", NULL,
-				ci->ndm_updated / hz);
-	} else {
-		fprintf(fp, "used %d/%d ", ci->ndm_used / hz,
-					ci->ndm_updated / hz);
-
-	}
-}
-
-int print_fdb(struct nlmsghdr *n, void *arg)
+int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	FILE *fp = arg;
 	struct ndmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[NDA_MAX+1];
-	__u16 vid = 0;
+	struct rtattr * tb[NDA_MAX+1];
 
 	if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
 		fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n",
 			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
+
 		return 0;
 	}
 
@@ -153,153 +85,104 @@
 	if (filter_index && filter_index != r->ndm_ifindex)
 		return 0;
 
-	if (filter_state && !(r->ndm_state & filter_state))
-		return 0;
-
 	parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
 		     n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
-	if (tb[NDA_VLAN])
-		vid = rta_getattr_u16(tb[NDA_VLAN]);
-
-	if (filter_vlan && filter_vlan != vid)
-		return 0;
-
-	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELNEIGH)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
 	if (tb[NDA_LLADDR]) {
-		const char *lladdr;
 		SPRINT_BUF(b1);
-
-		lladdr = ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
-				     RTA_PAYLOAD(tb[NDA_LLADDR]),
-				     ll_index_to_type(r->ndm_ifindex),
-				     b1, sizeof(b1));
-
-		print_color_string(PRINT_ANY, COLOR_MAC,
-				   "mac", "%s ", lladdr);
+		fprintf(fp, "%s ",
+			ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
+				    RTA_PAYLOAD(tb[NDA_LLADDR]),
+				    ll_index_to_type(r->ndm_ifindex),
+				    b1, sizeof(b1)));
 	}
 
 	if (!filter_index && r->ndm_ifindex)
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "ifname", "dev %s ",
-				   ll_index_to_name(r->ndm_ifindex));
+		fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
 
 	if (tb[NDA_DST]) {
+		SPRINT_BUF(abuf);
 		int family = AF_INET;
-		const char *dst;
 
 		if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
 			family = AF_INET6;
 
-		dst = format_host(family,
-				  RTA_PAYLOAD(tb[NDA_DST]),
-				  RTA_DATA(tb[NDA_DST]));
-
-		print_color_string(PRINT_ANY,
-				   ifa_family_color(family),
-				    "dst", "dst %s ", dst);
+		fprintf(fp, "dst %s ",
+			format_host(family,
+				    RTA_PAYLOAD(tb[NDA_DST]),
+				    RTA_DATA(tb[NDA_DST]),
+				    abuf, sizeof(abuf)));
 	}
 
-	if (vid)
-		print_uint(PRINT_ANY,
-				 "vlan", "vlan %hu ", vid);
+	if (tb[NDA_VLAN]) {
+		__u16 vid = rta_getattr_u16(tb[NDA_VLAN]);
+		fprintf(fp, "vlan %hu ", vid);
+	}
 
 	if (tb[NDA_PORT])
-		print_uint(PRINT_ANY,
-				 "port", "port %u ",
-				 rta_getattr_be16(tb[NDA_PORT]));
-
+		fprintf(fp, "port %d ", ntohs(rta_getattr_u16(tb[NDA_PORT])));
 	if (tb[NDA_VNI])
-		print_uint(PRINT_ANY,
-				 "vni", "vni %u ",
-				 rta_getattr_u32(tb[NDA_VNI]));
-
-	if (tb[NDA_SRC_VNI])
-		print_uint(PRINT_ANY,
-				 "src_vni", "src_vni %u ",
-				rta_getattr_u32(tb[NDA_SRC_VNI]));
-
+		fprintf(fp, "vni %d ", rta_getattr_u32(tb[NDA_VNI]));
 	if (tb[NDA_IFINDEX]) {
 		unsigned int ifindex = rta_getattr_u32(tb[NDA_IFINDEX]);
 
-		if (tb[NDA_LINK_NETNSID])
-			print_uint(PRINT_ANY,
-					 "viaIfIndex", "via ifindex %u ",
-					 ifindex);
-		else
-			print_string(PRINT_ANY,
-					   "viaIf", "via %s ",
-					   ll_index_to_name(ifindex));
-	}
+		if (ifindex) {
+			char ifname[IF_NAMESIZE];
 
+			if (!tb[NDA_LINK_NETNSID] &&
+			    if_indextoname(ifindex, ifname))
+				fprintf(fp, "via %s ", ifname);
+			else
+				fprintf(fp, "via ifindex %u ", ifindex);
+		}
+	}
 	if (tb[NDA_LINK_NETNSID])
-		print_uint(PRINT_ANY,
-				 "linkNetNsId", "link-netnsid %d ",
-				 rta_getattr_u32(tb[NDA_LINK_NETNSID]));
+		fprintf(fp, "link-netnsid %d ",
+			rta_getattr_u32(tb[NDA_LINK_NETNSID]));
 
-	if (show_stats && tb[NDA_CACHEINFO])
-		fdb_print_stats(fp, RTA_DATA(tb[NDA_CACHEINFO]));
+	if (show_stats && tb[NDA_CACHEINFO]) {
+		struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
+		int hz = get_user_hz();
 
-	fdb_print_flags(fp, r->ndm_flags);
-
-
+		fprintf(fp, "used %d/%d ", ci->ndm_used/hz,
+		       ci->ndm_updated/hz);
+	}
+	if (r->ndm_flags & NTF_SELF)
+		fprintf(fp, "self ");
 	if (tb[NDA_MASTER])
-		print_string(PRINT_ANY, "master", "master %s ",
-			     ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
+		fprintf(fp, "master %s ",
+			ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
+	else if (r->ndm_flags & NTF_MASTER)
+		fprintf(fp, "master ");
+	if (r->ndm_flags & NTF_ROUTER)
+		fprintf(fp, "router ");
+	if (r->ndm_flags & NTF_EXT_LEARNED)
+		fprintf(fp, "offload ");
 
-	print_string(PRINT_ANY, "state", "%s\n",
-			   state_n2a(r->ndm_state));
-	close_json_object();
+	fprintf(fp, "%s\n", state_n2a(r->ndm_state));
 	fflush(fp);
-	return 0;
-}
-
-static int fdb_linkdump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	int err;
-
-	if (filter_index) {
-		struct ifinfomsg *ifm = NLMSG_DATA(nlh);
-
-		ifm->ifi_index = filter_index;
-	}
-
-	if (filter_master) {
-		err = addattr32(nlh, reqlen, IFLA_MASTER, filter_master);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
-static int fdb_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	int err;
-
-	if (filter_index) {
-		struct ndmsg *ndm = NLMSG_DATA(nlh);
-
-		ndm->ndm_ifindex = filter_index;
-	}
-
-	if (filter_master) {
-		err = addattr32(nlh, reqlen, NDA_MASTER, filter_master);
-		if (err)
-			return err;
-	}
 
 	return 0;
 }
 
 static int fdb_show(int argc, char **argv)
 {
+	struct {
+		struct nlmsghdr 	n;
+		struct ifinfomsg	ifm;
+		char   			buf[256];
+	} req;
+
 	char *filter_dev = NULL;
 	char *br = NULL;
-	int rc;
+	int msg_size = sizeof(struct ifinfomsg);
+
+	memset(&req, 0, sizeof(req));
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+	req.ifm.ifi_family = PF_BRIDGE;
 
 	while (argc > 0) {
 		if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) {
@@ -308,18 +191,6 @@
 		} else if (strcmp(*argv, "br") == 0) {
 			NEXT_ARG();
 			br = *argv;
-		} else if (strcmp(*argv, "vlan") == 0) {
-			NEXT_ARG();
-			if (filter_vlan)
-				duparg("vlan", *argv);
-			filter_vlan = atoi(*argv);
-		} else if (strcmp(*argv, "state") == 0) {
-			unsigned int state;
-
-			NEXT_ARG();
-			if (state_a2n(&state, *argv))
-				invarg("invalid state", *argv);
-			filter_state |= state;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -329,37 +200,34 @@
 
 	if (br) {
 		int br_ifindex = ll_name_to_index(br);
-
 		if (br_ifindex == 0) {
 			fprintf(stderr, "Cannot find bridge device \"%s\"\n", br);
 			return -1;
 		}
-		filter_master = br_ifindex;
+		addattr32(&req.n, sizeof(req), IFLA_MASTER, br_ifindex);
+		msg_size += RTA_LENGTH(4);
 	}
 
 	/*we'll keep around filter_dev for older kernels */
 	if (filter_dev) {
-		filter_index = ll_name_to_index(filter_dev);
-		if (!filter_index)
-			return nodev(filter_dev);
+		filter_index = if_nametoindex(filter_dev);
+		if (filter_index == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n",
+				filter_dev);
+			return -1;
+		}
+		req.ifm.ifi_index = filter_index;
 	}
 
-	if (rth.flags & RTNL_HANDLE_F_STRICT_CHK)
-		rc = rtnl_neighdump_req(&rth, PF_BRIDGE, fdb_dump_filter);
-	else
-		rc = rtnl_fdb_linkdump_req_filter_fn(&rth, fdb_linkdump_filter);
-	if (rc < 0) {
+	if (rtnl_dump_request(&rth, RTM_GETNEIGH, &req.ifm, msg_size) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
-	fflush(stdout);
 
 	return 0;
 }
@@ -367,16 +235,10 @@
 static int fdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
-		struct nlmsghdr	n;
-		struct ndmsg		ndm;
-		char			buf[256];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.ndm.ndm_family = PF_BRIDGE,
-		.ndm.ndm_state = NUD_NOARP,
-	};
+		struct nlmsghdr 	n;
+		struct ndmsg 		ndm;
+		char   			buf[256];
+	} req;
 	char *addr = NULL;
 	char *d = NULL;
 	char abuf[ETH_ALEN];
@@ -384,11 +246,18 @@
 	inet_prefix dst;
 	unsigned long port = 0;
 	unsigned long vni = ~0;
-	unsigned long src_vni = ~0;
 	unsigned int via = 0;
 	char *endptr;
 	short vid = -1;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.ndm.ndm_family = PF_BRIDGE;
+	req.ndm.ndm_state = NUD_NOARP;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
@@ -418,32 +287,22 @@
 			if ((endptr && *endptr) ||
 			    (vni >> 24) || vni == ULONG_MAX)
 				invarg("invalid VNI\n", *argv);
-		} else if (strcmp(*argv, "src_vni") == 0) {
-			NEXT_ARG();
-			src_vni = strtoul(*argv, &endptr, 0);
-			if ((endptr && *endptr) ||
-			    (src_vni >> 24) || src_vni == ULONG_MAX)
-				invarg("invalid src VNI\n", *argv);
 		} else if (strcmp(*argv, "via") == 0) {
 			NEXT_ARG();
-			via = ll_name_to_index(*argv);
-			if (!via)
-				exit(nodev(*argv));
+			via = if_nametoindex(*argv);
+			if (via == 0)
+				invarg("invalid device\n", *argv);
 		} else if (strcmp(*argv, "self") == 0) {
 			req.ndm.ndm_flags |= NTF_SELF;
 		} else if (matches(*argv, "master") == 0) {
 			req.ndm.ndm_flags |= NTF_MASTER;
 		} else if (matches(*argv, "router") == 0) {
 			req.ndm.ndm_flags |= NTF_ROUTER;
-		} else if (matches(*argv, "local") == 0 ||
+		} else if (matches(*argv, "local") == 0||
 			   matches(*argv, "permanent") == 0) {
 			req.ndm.ndm_state |= NUD_PERMANENT;
-		} else if (matches(*argv, "temp") == 0 ||
-			   matches(*argv, "static") == 0) {
+		} else if (matches(*argv, "temp") == 0) {
 			req.ndm.ndm_state |= NUD_REACHABLE;
-		} else if (matches(*argv, "dynamic") == 0) {
-			req.ndm.ndm_state |= NUD_REACHABLE;
-			req.ndm.ndm_state &= ~NUD_NOARP;
 		} else if (matches(*argv, "vlan") == 0) {
 			if (vid >= 0)
 				duparg2("vlan", *argv);
@@ -451,14 +310,10 @@
 			vid = atoi(*argv);
 		} else if (matches(*argv, "use") == 0) {
 			req.ndm.ndm_flags |= NTF_USE;
-		} else if (matches(*argv, "extern_learn") == 0) {
-			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
-		} else if (matches(*argv, "sticky") == 0) {
-			req.ndm.ndm_flags |= NTF_STICKY;
 		} else {
-			if (strcmp(*argv, "to") == 0)
+			if (strcmp(*argv, "to") == 0) {
 				NEXT_ARG();
-
+			}
 			if (matches(*argv, "help") == 0)
 				usage();
 			if (addr)
@@ -503,16 +358,16 @@
 	}
 	if (vni != ~0)
 		addattr32(&req.n, sizeof(req), NDA_VNI, vni);
-	if (src_vni != ~0)
-		addattr32(&req.n, sizeof(req), NDA_SRC_VNI, src_vni);
 	if (via)
 		addattr32(&req.n, sizeof(req), NDA_IFINDEX, via);
 
 	req.ndm.ndm_ifindex = ll_name_to_index(d);
-	if (!req.ndm.ndm_ifindex)
-		return nodev(d);
+	if (req.ndm.ndm_ifindex == 0) {
+		fprintf(stderr, "Cannot find device \"%s\"\n", d);
+		return -1;
+	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -1;
 
 	return 0;
diff --git a/bridge/link.c b/bridge/link.c
index 074edf0..a9b1262 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -12,7 +11,6 @@
 #include <string.h>
 #include <stdbool.h>
 
-#include "json_print.h"
 #include "libnetlink.h"
 #include "utils.h"
 #include "br_common.h"
@@ -27,21 +25,17 @@
 	[BR_STATE_BLOCKING] = "blocking",
 };
 
-static const char *hw_mode[] = {
-	"VEB", "VEPA"
-};
+extern char *if_indextoname (unsigned int __ifindex, char *__ifname);
 
-static void print_link_flags(FILE *fp, unsigned int flags, unsigned int mdown)
+static void print_link_flags(FILE *fp, unsigned flags)
 {
-	open_json_array(PRINT_ANY, is_json_context() ? "flags" : "<");
+	fprintf(fp, "<");
 	if (flags & IFF_UP && !(flags & IFF_RUNNING))
-		print_string(PRINT_ANY, NULL,
-			     flags ? "%s," : "%s", "NO-CARRIER");
+		fprintf(fp, "NO-CARRIER%s", flags ? "," : "");
 	flags &= ~IFF_RUNNING;
-
-#define _PF(f) if (flags&IFF_##f) {					\
-		flags &= ~IFF_##f ;					\
-		print_string(PRINT_ANY, NULL, flags ? "%s," : "%s", #f); }
+#define _PF(f) if (flags&IFF_##f) { \
+                  flags &= ~IFF_##f ; \
+                  fprintf(fp, #f "%s", flags ? "," : ""); }
 	_PF(LOOPBACK);
 	_PF(BROADCAST);
 	_PF(POINTOPOINT);
@@ -61,152 +55,61 @@
 	_PF(DORMANT);
 	_PF(ECHO);
 #undef _PF
-	if (flags)
-		print_hex(PRINT_ANY, NULL, "%x", flags);
-	if (mdown)
-		print_string(PRINT_ANY, NULL, ",%s", "M-DOWN");
-	close_json_array(PRINT_ANY, "> ");
+        if (flags)
+		fprintf(fp, "%x", flags);
+	fprintf(fp, "> ");
 }
 
-static void print_portstate(__u8 state)
+static const char *oper_states[] = {
+	"UNKNOWN", "NOTPRESENT", "DOWN", "LOWERLAYERDOWN",
+	"TESTING", "DORMANT",	 "UP"
+};
+
+static const char *hw_mode[] = {"VEB", "VEPA"};
+
+static void print_operstate(FILE *f, __u8 state)
+{
+	if (state >= sizeof(oper_states)/sizeof(oper_states[0]))
+		fprintf(f, "state %#x ", state);
+	else
+		fprintf(f, "state %s ", oper_states[state]);
+}
+
+static void print_portstate(FILE *f, __u8 state)
 {
 	if (state <= BR_STATE_BLOCKING)
-		print_string(PRINT_ANY, "state",
-			     "state %s ", port_states[state]);
+		fprintf(f, "state %s ", port_states[state]);
 	else
-		print_uint(PRINT_ANY, "state",
-			     "state (%d) ", state);
+		fprintf(f, "state (%d) ", state);
 }
 
-static void print_onoff(FILE *fp, const char *flag, __u8 val)
+static void print_onoff(FILE *f, char *flag, __u8 val)
 {
-	if (is_json_context())
-		print_bool(PRINT_JSON, flag, NULL, val);
+	fprintf(f, "%s %s ", flag, val ? "on" : "off");
+}
+
+static void print_hwmode(FILE *f, __u16 mode)
+{
+	if (mode >= sizeof(hw_mode)/sizeof(hw_mode[0]))
+		fprintf(f, "hwmode %#hx ", mode);
 	else
-		fprintf(fp, "%s %s ", flag, val ? "on" : "off");
+		fprintf(f, "hwmode %s ", hw_mode[mode]);
 }
 
-static void print_hwmode(__u16 mode)
-{
-	if (mode >= ARRAY_SIZE(hw_mode))
-		print_0xhex(PRINT_ANY, "hwmode",
-			    "hwmode %#llx ", mode);
-	else
-		print_string(PRINT_ANY, "hwmode",
-			     "hwmode %s ", hw_mode[mode]);
-}
-
-static void print_protinfo(FILE *fp, struct rtattr *attr)
-{
-	if (attr->rta_type & NLA_F_NESTED) {
-		struct rtattr *prtb[IFLA_BRPORT_MAX + 1];
-
-		parse_rtattr_nested(prtb, IFLA_BRPORT_MAX, attr);
-
-		if (prtb[IFLA_BRPORT_STATE])
-			print_portstate(rta_getattr_u8(prtb[IFLA_BRPORT_STATE]));
-
-		if (prtb[IFLA_BRPORT_PRIORITY])
-			print_uint(PRINT_ANY, "priority",
-				   "priority %u ",
-				   rta_getattr_u16(prtb[IFLA_BRPORT_PRIORITY]));
-
-		if (prtb[IFLA_BRPORT_COST])
-			print_uint(PRINT_ANY, "cost",
-				   "cost %u ",
-				   rta_getattr_u32(prtb[IFLA_BRPORT_COST]));
-
-		if (!show_details)
-			return;
-
-		if (!is_json_context())
-			fprintf(fp, "%s    ", _SL_);
-
-		if (prtb[IFLA_BRPORT_MODE])
-			print_onoff(fp, "hairpin",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_MODE]));
-		if (prtb[IFLA_BRPORT_GUARD])
-			print_onoff(fp, "guard",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_GUARD]));
-		if (prtb[IFLA_BRPORT_PROTECT])
-			print_onoff(fp, "root_block",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT]));
-		if (prtb[IFLA_BRPORT_FAST_LEAVE])
-			print_onoff(fp, "fastleave",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE]));
-		if (prtb[IFLA_BRPORT_LEARNING])
-			print_onoff(fp, "learning",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING]));
-		if (prtb[IFLA_BRPORT_LEARNING_SYNC])
-			print_onoff(fp, "learning_sync",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC]));
-		if (prtb[IFLA_BRPORT_UNICAST_FLOOD])
-			print_onoff(fp, "flood",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD]));
-		if (prtb[IFLA_BRPORT_MCAST_FLOOD])
-			print_onoff(fp, "mcast_flood",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_FLOOD]));
-		if (prtb[IFLA_BRPORT_MCAST_TO_UCAST])
-			print_onoff(fp, "mcast_to_unicast",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_TO_UCAST]));
-		if (prtb[IFLA_BRPORT_NEIGH_SUPPRESS])
-			print_onoff(fp, "neigh_suppress",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS]));
-		if (prtb[IFLA_BRPORT_VLAN_TUNNEL])
-			print_onoff(fp, "vlan_tunnel",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL]));
-
-		if (prtb[IFLA_BRPORT_BACKUP_PORT]) {
-			int ifidx;
-
-			ifidx = rta_getattr_u32(prtb[IFLA_BRPORT_BACKUP_PORT]);
-			print_string(PRINT_ANY,
-				     "backup_port", "backup_port %s ",
-				     ll_index_to_name(ifidx));
-		}
-
-		if (prtb[IFLA_BRPORT_ISOLATED])
-			print_onoff(fp, "isolated",
-				    rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED]));
-	} else
-		print_portstate(rta_getattr_u8(attr));
-}
-
-
-/*
- * This is reported by HW devices that have some bridging
- * capabilities.
- */
-static void print_af_spec(struct rtattr *attr, int ifindex)
-{
-	struct rtattr *aftb[IFLA_BRIDGE_MAX+1];
-
-	parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, attr);
-
-	if (aftb[IFLA_BRIDGE_MODE])
-		print_hwmode(rta_getattr_u16(aftb[IFLA_BRIDGE_MODE]));
-
-	if (!show_details)
-		return;
-
-	if (aftb[IFLA_BRIDGE_VLAN_INFO])
-		print_vlan_info(aftb[IFLA_BRIDGE_VLAN_INFO], ifindex);
-}
-
-int print_linkinfo(struct nlmsghdr *n, void *arg)
+int print_linkinfo(const struct sockaddr_nl *who,
+		   struct nlmsghdr *n, void *arg)
 {
 	FILE *fp = arg;
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
-	unsigned int m_flag = 0;
 	int len = n->nlmsg_len;
-	const char *name;
+	struct ifinfomsg *ifi = NLMSG_DATA(n);
+	struct rtattr * tb[IFLA_MAX+1];
+	char b1[IFNAMSIZ];
 
 	len -= NLMSG_LENGTH(sizeof(*ifi));
 	if (len < 0) {
 		fprintf(stderr, "Message too short!\n");
 		return -1;
-	}
+        }
 
 	if (!(ifi->ifi_family == AF_BRIDGE || ifi->ifi_family == AF_UNSPEC))
 		return 0;
@@ -216,62 +119,116 @@
 
 	parse_rtattr_flags(tb, IFLA_MAX, IFLA_RTA(ifi), len, NLA_F_NESTED);
 
-	name = get_ifname_rta(ifi->ifi_index, tb[IFLA_IFNAME]);
-	if (!name)
+	if (tb[IFLA_IFNAME] == NULL) {
+		fprintf(stderr, "BUG: nil ifname\n");
 		return -1;
-
-	open_json_object(NULL);
-	if (n->nlmsg_type == RTM_DELLINK)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
-
-	print_int(PRINT_ANY, "ifindex", "%d: ", ifi->ifi_index);
-	m_flag = print_name_and_link("%s: ", name, tb);
-	print_link_flags(fp, ifi->ifi_flags, m_flag);
-
-	if (tb[IFLA_MTU])
-		print_int(PRINT_ANY,
-			  "mtu", "mtu %u ",
-			  rta_getattr_u32(tb[IFLA_MTU]));
-
-	if (tb[IFLA_MASTER]) {
-		int master = rta_getattr_u32(tb[IFLA_MASTER]);
-
-		print_string(PRINT_ANY, "master", "master %s ",
-			     ll_index_to_name(master));
 	}
 
-	if (tb[IFLA_PROTINFO])
-		print_protinfo(fp, tb[IFLA_PROTINFO]);
+	if (n->nlmsg_type == RTM_DELLINK)
+		fprintf(fp, "Deleted ");
 
-	if (tb[IFLA_AF_SPEC])
-		print_af_spec(tb[IFLA_AF_SPEC], ifi->ifi_index);
+	fprintf(fp, "%d: %s ", ifi->ifi_index,
+		tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
 
-	print_string(PRINT_FP, NULL, "%s", "\n");
-	close_json_object();
+	if (tb[IFLA_OPERSTATE])
+		print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
+
+	if (tb[IFLA_LINK]) {
+		SPRINT_BUF(b1);
+		int iflink = rta_getattr_u32(tb[IFLA_LINK]);
+		if (iflink == 0)
+			fprintf(fp, "@NONE: ");
+		else
+			fprintf(fp, "@%s: ",
+				if_indextoname(iflink, b1));
+	} else
+		fprintf(fp, ": ");
+
+	print_link_flags(fp, ifi->ifi_flags);
+
+	if (tb[IFLA_MTU])
+		fprintf(fp, "mtu %u ", rta_getattr_u32(tb[IFLA_MTU]));
+
+	if (tb[IFLA_MASTER])
+		fprintf(fp, "master %s ",
+			if_indextoname(rta_getattr_u32(tb[IFLA_MASTER]), b1));
+
+	if (tb[IFLA_PROTINFO]) {
+		if (tb[IFLA_PROTINFO]->rta_type & NLA_F_NESTED) {
+			struct rtattr *prtb[IFLA_BRPORT_MAX+1];
+
+			parse_rtattr_nested(prtb, IFLA_BRPORT_MAX,
+					    tb[IFLA_PROTINFO]);
+
+			if (prtb[IFLA_BRPORT_STATE])
+				print_portstate(fp,
+						rta_getattr_u8(prtb[IFLA_BRPORT_STATE]));
+			if (prtb[IFLA_BRPORT_PRIORITY])
+				fprintf(fp, "priority %hu ",
+					rta_getattr_u16(prtb[IFLA_BRPORT_PRIORITY]));
+			if (prtb[IFLA_BRPORT_COST])
+				fprintf(fp, "cost %u ",
+					rta_getattr_u32(prtb[IFLA_BRPORT_COST]));
+
+			if (show_details) {
+				fprintf(fp, "%s    ", _SL_);
+
+				if (prtb[IFLA_BRPORT_MODE])
+					print_onoff(fp, "hairpin",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_MODE]));
+				if (prtb[IFLA_BRPORT_GUARD])
+					print_onoff(fp, "guard",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_GUARD]));
+				if (prtb[IFLA_BRPORT_PROTECT])
+					print_onoff(fp, "root_block",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT]));
+				if (prtb[IFLA_BRPORT_FAST_LEAVE])
+					print_onoff(fp, "fastleave",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE]));
+				if (prtb[IFLA_BRPORT_LEARNING])
+					print_onoff(fp, "learning",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING]));
+				if (prtb[IFLA_BRPORT_LEARNING_SYNC])
+					print_onoff(fp, "learning_sync",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC]));
+				if (prtb[IFLA_BRPORT_UNICAST_FLOOD])
+					print_onoff(fp, "flood",
+						    rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD]));
+			}
+		} else
+			print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO]));
+	}
+
+	if (tb[IFLA_AF_SPEC]) {
+		/* This is reported by HW devices that have some bridging
+		 * capabilities.
+		 */
+		struct rtattr *aftb[IFLA_BRIDGE_MAX+1];
+
+		parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]);
+
+		if (aftb[IFLA_BRIDGE_MODE])
+			print_hwmode(fp, rta_getattr_u16(aftb[IFLA_BRIDGE_MODE]));
+	}
+
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ]\n"
-		"                               [ guard {on | off} ]\n"
-		"                               [ hairpin {on | off} ]\n"
-		"                               [ fastleave {on | off} ]\n"
-		"                               [ root_block {on | off} ]\n"
-		"                               [ learning {on | off} ]\n"
-		"                               [ learning_sync {on | off} ]\n"
-		"                               [ flood {on | off} ]\n"
-		"                               [ mcast_flood {on | off} ]\n"
-		"                               [ mcast_to_unicast {on | off} ]\n"
-		"                               [ neigh_suppress {on | off} ]\n"
-		"                               [ vlan_tunnel {on | off} ]\n"
-		"                               [ isolated {on | off} ]\n"
-		"                               [ hwmode {vepa | veb} ]\n"
-		"                               [ backup_port DEVICE ] [ nobackup_port ]\n"
-		"                               [ self ] [ master ]\n"
-		"       bridge link show [dev DEV]\n");
+	fprintf(stderr, "Usage: bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ]\n");
+	fprintf(stderr, "                               [ guard {on | off} ]\n");
+	fprintf(stderr, "                               [ hairpin {on | off} ] \n");
+	fprintf(stderr, "                               [ fastleave {on | off} ]\n");
+	fprintf(stderr,	"                               [ root_block {on | off} ]\n");
+	fprintf(stderr,	"                               [ learning {on | off} ]\n");
+	fprintf(stderr,	"                               [ learning_sync {on | off} ]\n");
+	fprintf(stderr,	"                               [ flood {on | off} ]\n");
+	fprintf(stderr, "                               [ hwmode {vepa | veb} ]\n");
+	fprintf(stderr, "                               [ self ] [ master ]\n");
+	fprintf(stderr, "       bridge link show [dev DEV]\n");
 	exit(-1);
 }
 
@@ -297,22 +254,11 @@
 		struct nlmsghdr  n;
 		struct ifinfomsg ifm;
 		char             buf[512];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_SETLINK,
-		.ifm.ifi_family = PF_BRIDGE,
-	};
+	} req;
 	char *d = NULL;
-	int backup_port_idx = -1;
-	__s8 neigh_suppress = -1;
 	__s8 learning = -1;
 	__s8 learning_sync = -1;
 	__s8 flood = -1;
-	__s8 vlan_tunnel = -1;
-	__s8 mcast_flood = -1;
-	__s8 mcast_to_unicast = -1;
-	__s8 isolated = -1;
 	__s8 hairpin = -1;
 	__s8 bpdu_guard = -1;
 	__s8 fast_leave = -1;
@@ -324,6 +270,13 @@
 	__u16 flags = 0;
 	struct rtattr *nest;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = RTM_SETLINK;
+	req.ifm.ifi_family = PF_BRIDGE;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
@@ -334,7 +287,7 @@
 				return -1;
 		} else if (strcmp(*argv, "hairpin") == 0) {
 			NEXT_ARG();
-			if (!on_off("hairpin", &hairpin, *argv))
+			if (!on_off("hairping", &hairpin, *argv))
 				return -1;
 		} else if (strcmp(*argv, "fastleave") == 0) {
 			NEXT_ARG();
@@ -356,14 +309,6 @@
 			NEXT_ARG();
 			if (!on_off("flood", &flood, *argv))
 				return -1;
-		} else if (strcmp(*argv, "mcast_flood") == 0) {
-			NEXT_ARG();
-			if (!on_off("mcast_flood", &mcast_flood, *argv))
-				return -1;
-		} else if (strcmp(*argv, "mcast_to_unicast") == 0) {
-			NEXT_ARG();
-			if (!on_off("mcast_to_unicast", &mcast_to_unicast, *argv))
-				return -1;
 		} else if (strcmp(*argv, "cost") == 0) {
 			NEXT_ARG();
 			cost = atoi(*argv);
@@ -373,8 +318,7 @@
 		} else if (strcmp(*argv, "state") == 0) {
 			NEXT_ARG();
 			char *endptr;
-			size_t nstates = ARRAY_SIZE(port_states);
-
+			size_t nstates = sizeof(port_states) / sizeof(*port_states);
 			state = strtol(*argv, &endptr, 10);
 			if (!(**argv != '\0' && *endptr == '\0')) {
 				for (state = 0; state < nstates; state++)
@@ -395,37 +339,14 @@
 				mode = BRIDGE_MODE_VEB;
 			else {
 				fprintf(stderr,
-					"Mode argument must be \"vepa\" or \"veb\".\n");
+					"Mode argument must be \"vepa\" or "
+					"\"veb\".\n");
 				return -1;
 			}
 		} else if (strcmp(*argv, "self") == 0) {
 			flags |= BRIDGE_FLAGS_SELF;
 		} else if (strcmp(*argv, "master") == 0) {
 			flags |= BRIDGE_FLAGS_MASTER;
-		} else if (strcmp(*argv, "neigh_suppress") == 0) {
-			NEXT_ARG();
-			if (!on_off("neigh_suppress", &neigh_suppress,
-				    *argv))
-				return -1;
-		} else if (strcmp(*argv, "vlan_tunnel") == 0) {
-			NEXT_ARG();
-			if (!on_off("vlan_tunnel", &vlan_tunnel,
-				    *argv))
-				return -1;
-		} else if (strcmp(*argv, "isolated") == 0) {
-			NEXT_ARG();
-			if (!on_off("isolated", &isolated, *argv))
-				return -1;
-		} else if (strcmp(*argv, "backup_port") == 0) {
-			NEXT_ARG();
-			backup_port_idx = ll_name_to_index(*argv);
-			if (!backup_port_idx) {
-				fprintf(stderr, "Error: device %s does not exist\n",
-					*argv);
-				return -1;
-			}
-		} else if (strcmp(*argv, "nobackup_port") == 0) {
-			backup_port_idx = 0;
 		} else {
 			usage();
 		}
@@ -460,12 +381,6 @@
 		addattr8(&req.n, sizeof(req), IFLA_BRPORT_PROTECT, root_block);
 	if (flood >= 0)
 		addattr8(&req.n, sizeof(req), IFLA_BRPORT_UNICAST_FLOOD, flood);
-	if (mcast_flood >= 0)
-		addattr8(&req.n, sizeof(req), IFLA_BRPORT_MCAST_FLOOD,
-			 mcast_flood);
-	if (mcast_to_unicast >= 0)
-		addattr8(&req.n, sizeof(req), IFLA_BRPORT_MCAST_TO_UCAST,
-			 mcast_to_unicast);
 	if (learning >= 0)
 		addattr8(&req.n, sizeof(req), IFLA_BRPORT_LEARNING, learning);
 	if (learning_sync >= 0)
@@ -481,19 +396,6 @@
 	if (state >= 0)
 		addattr8(&req.n, sizeof(req), IFLA_BRPORT_STATE, state);
 
-	if (neigh_suppress != -1)
-		addattr8(&req.n, sizeof(req), IFLA_BRPORT_NEIGH_SUPPRESS,
-			 neigh_suppress);
-	if (vlan_tunnel != -1)
-		addattr8(&req.n, sizeof(req), IFLA_BRPORT_VLAN_TUNNEL,
-			 vlan_tunnel);
-	if (isolated != -1)
-		addattr8(&req.n, sizeof(req), IFLA_BRPORT_ISOLATED, isolated);
-
-	if (backup_port_idx != -1)
-		addattr32(&req.n, sizeof(req), IFLA_BRPORT_BACKUP_PORT,
-			  backup_port_idx);
-
 	addattr_nest_end(&req.n, nest);
 
 	/* IFLA_AF_SPEC nested attribute. Contains IFLA_BRIDGE_FLAGS that
@@ -513,7 +415,7 @@
 		addattr_nest_end(&req.n, nest);
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -1;
 
 	return 0;
@@ -534,34 +436,22 @@
 	}
 
 	if (filter_dev) {
-		filter_index = ll_name_to_index(filter_dev);
-		if (!filter_index)
-			return nodev(filter_dev);
-	}
-
-	if (show_details) {
-		if (rtnl_linkdump_req_filter(&rth, PF_BRIDGE,
-					     (compress_vlans ?
-					      RTEXT_FILTER_BRVLAN_COMPRESSED :
-					      RTEXT_FILTER_BRVLAN)) < 0) {
-			perror("Cannon send dump request");
-			exit(1);
-		}
-	} else {
-		if (rtnl_linkdump_req(&rth, PF_BRIDGE) < 0) {
-			perror("Cannon send dump request");
-			exit(1);
+		if ((filter_index = ll_name_to_index(filter_dev)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n",
+				filter_dev);
+			return -1;
 		}
 	}
 
-	new_json_obj(json);
+	if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETLINK) < 0) {
+		perror("Cannon send dump request");
+		exit(1);
+	}
+
 	if (rtnl_dump_filter(&rth, print_linkinfo, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-
-	delete_json_obj();
-	fflush(stdout);
 	return 0;
 }
 
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 928ae56..24c4903 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Get mdb table with netlink
  */
@@ -19,216 +18,80 @@
 #include "br_common.h"
 #include "rt_names.h"
 #include "utils.h"
-#include "json_print.h"
 
 #ifndef MDBA_RTA
 #define MDBA_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct br_port_msg))))
+	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct br_port_msg))))
 #endif
 
-static unsigned int filter_index, filter_vlan;
+static unsigned int filter_index;
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [permanent | temp] [vid VID]\n"
-		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
+	fprintf(stderr, "Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [permanent | temp] [vid VID]\n");
+	fprintf(stderr, "       bridge mdb {show} [ dev DEV ]\n");
 	exit(-1);
 }
 
-static bool is_temp_mcast_rtr(__u8 type)
+static void br_print_router_ports(FILE *f, struct rtattr *attr)
 {
-	return type == MDB_RTR_TYPE_TEMP_QUERY || type == MDB_RTR_TYPE_TEMP;
-}
-
-static const char *format_timer(__u32 ticks)
-{
-	struct timeval tv;
-	static char tbuf[32];
-
-	__jiffies_to_tv(&tv, ticks);
-	snprintf(tbuf, sizeof(tbuf), "%4lu.%.2lu",
-		 (unsigned long)tv.tv_sec,
-		 (unsigned long)tv.tv_usec / 10000);
-
-	return tbuf;
-}
-
-static void __print_router_port_stats(FILE *f, struct rtattr *pattr)
-{
-	struct rtattr *tb[MDBA_ROUTER_PATTR_MAX + 1];
-
-	parse_rtattr(tb, MDBA_ROUTER_PATTR_MAX, MDB_RTR_RTA(RTA_DATA(pattr)),
-		     RTA_PAYLOAD(pattr) - RTA_ALIGN(sizeof(uint32_t)));
-
-	if (tb[MDBA_ROUTER_PATTR_TIMER]) {
-		__u32 timer = rta_getattr_u32(tb[MDBA_ROUTER_PATTR_TIMER]);
-
-		print_string(PRINT_ANY, "timer", " %s",
-			     format_timer(timer));
-	}
-
-	if (tb[MDBA_ROUTER_PATTR_TYPE]) {
-		__u8 type = rta_getattr_u8(tb[MDBA_ROUTER_PATTR_TYPE]);
-
-		print_string(PRINT_ANY, "type", " %s",
-			     is_temp_mcast_rtr(type) ? "temp" : "permanent");
-	}
-}
-
-static void br_print_router_ports(FILE *f, struct rtattr *attr,
-				  const char *brifname)
-{
-	int rem = RTA_PAYLOAD(attr);
-	struct rtattr *i;
-
-	if (is_json_context())
-		open_json_array(PRINT_JSON, brifname);
-	else if (!show_stats)
-		fprintf(f, "router ports on %s: ", brifname);
-
-	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		uint32_t *port_ifindex = RTA_DATA(i);
-		const char *port_ifname = ll_index_to_name(*port_ifindex);
-
-		if (is_json_context()) {
-			open_json_object(NULL);
-			print_string(PRINT_JSON, "port", NULL, port_ifname);
-
-			if (show_stats)
-				__print_router_port_stats(f, i);
-			close_json_object();
-		} else if (show_stats) {
-			fprintf(f, "router ports on %s: %s",
-				brifname, port_ifname);
-
-			__print_router_port_stats(f, i);
-			fprintf(f, "\n");
-		} else {
-			fprintf(f, "%s ", port_ifname);
-		}
-	}
-
-	if (!show_stats)
-		print_nl();
-
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
-			    struct nlmsghdr *n, struct rtattr **tb)
-{
-	SPRINT_BUF(abuf);
-	const char *dev;
-	const void *src;
-	int af;
-
-	if (filter_vlan && e->vid != filter_vlan)
-		return;
-
-	af = e->addr.proto == htons(ETH_P_IP) ? AF_INET : AF_INET6;
-	src = af == AF_INET ? (const void *)&e->addr.u.ip4 :
-			      (const void *)&e->addr.u.ip6;
-	dev = ll_index_to_name(ifindex);
-
-	open_json_object(NULL);
-
-	print_int(PRINT_JSON, "index", NULL, ifindex);
-	print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "dev %s", dev);
-	print_string(PRINT_ANY, "port", " port %s",
-		     ll_index_to_name(e->ifindex));
-
-	print_color_string(PRINT_ANY, ifa_family_color(af),
-			    "grp", " grp %s",
-			    inet_ntop(af, src, abuf, sizeof(abuf)));
-
-	print_string(PRINT_ANY, "state", " %s",
-			   (e->state & MDB_PERMANENT) ? "permanent" : "temp");
-
-	open_json_array(PRINT_JSON, "flags");
-	if (e->flags & MDB_FLAGS_OFFLOAD)
-		print_string(PRINT_ANY, NULL, " %s", "offload");
-	close_json_array(PRINT_JSON, NULL);
-
-	if (e->vid)
-		print_uint(PRINT_ANY, "vid", " vid %u", e->vid);
-
-	if (show_stats && tb && tb[MDBA_MDB_EATTR_TIMER]) {
-		__u32 timer = rta_getattr_u32(tb[MDBA_MDB_EATTR_TIMER]);
-
-		print_string(PRINT_ANY, "timer", " %s",
-			     format_timer(timer));
-	}
-
-	print_nl();
-	close_json_object();
-}
-
-static void br_print_mdb_entry(FILE *f, int ifindex, struct rtattr *attr,
-			       struct nlmsghdr *n)
-{
-	struct rtattr *etb[MDBA_MDB_EATTR_MAX + 1];
-	struct br_mdb_entry *e;
+	uint32_t *port_ifindex;
 	struct rtattr *i;
 	int rem;
 
 	rem = RTA_PAYLOAD(attr);
 	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		e = RTA_DATA(i);
-		parse_rtattr(etb, MDBA_MDB_EATTR_MAX, MDB_RTA(RTA_DATA(i)),
-			     RTA_PAYLOAD(i) - RTA_ALIGN(sizeof(*e)));
-		print_mdb_entry(f, ifindex, e, n, etb);
+		port_ifindex = RTA_DATA(i);
+		fprintf(f, "%s ", ll_index_to_name(*port_ifindex));
 	}
+
+	fprintf(f, "\n");
 }
 
-static void print_mdb_entries(FILE *fp, struct nlmsghdr *n,
-			      int ifindex,  struct rtattr *mdb)
+static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e,
+			    struct nlmsghdr *n)
 {
-	int rem = RTA_PAYLOAD(mdb);
+	SPRINT_BUF(abuf);
+	const void *src;
+	int af;
+
+	af = e->addr.proto == htons(ETH_P_IP) ? AF_INET : AF_INET6;
+	src = af == AF_INET ? (const void *)&e->addr.u.ip4 :
+			      (const void *)&e->addr.u.ip6;
+	if (n->nlmsg_type == RTM_DELMDB)
+		fprintf(f, "Deleted ");
+	fprintf(f, "dev %s port %s grp %s %s", ll_index_to_name(ifindex),
+		ll_index_to_name(e->ifindex),
+		inet_ntop(af, src, abuf, sizeof(abuf)),
+		(e->state & MDB_PERMANENT) ? "permanent" : "temp");
+	if (e->vid)
+		fprintf(f, " vid %hu", e->vid);
+	fprintf(f, "\n");
+}
+
+static void br_print_mdb_entry(FILE *f, int ifindex, struct rtattr *attr,
+			       struct nlmsghdr *n)
+{
 	struct rtattr *i;
+	int rem;
+	struct br_mdb_entry *e;
 
-	for (i = RTA_DATA(mdb); RTA_OK(i, rem); i = RTA_NEXT(i, rem))
-		br_print_mdb_entry(fp, ifindex, i, n);
-}
-
-static void print_router_entries(FILE *fp, struct nlmsghdr *n,
-				 int ifindex, struct rtattr *router)
-{
-	const char *brifname = ll_index_to_name(ifindex);
-
-	if (n->nlmsg_type == RTM_GETMDB) {
-		if (show_details)
-			br_print_router_ports(fp, router, brifname);
-	} else {
-		struct rtattr *i = RTA_DATA(router);
-		uint32_t *port_ifindex = RTA_DATA(i);
-		const char *port_name = ll_index_to_name(*port_ifindex);
-
-		if (is_json_context()) {
-			open_json_array(PRINT_JSON, brifname);
-			open_json_object(NULL);
-
-			print_string(PRINT_JSON, "port", NULL,
-				     port_name);
-			close_json_object();
-			close_json_array(PRINT_JSON, NULL);
-		} else {
-			fprintf(fp, "router port dev %s master %s\n",
-				port_name, brifname);
-		}
+	rem = RTA_PAYLOAD(attr);
+	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
+		e = RTA_DATA(i);
+		print_mdb_entry(f, ifindex, e, n);
 	}
 }
 
-static int __parse_mdb_nlmsg(struct nlmsghdr *n, struct rtattr **tb)
+int print_mdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
+	FILE *fp = arg;
 	struct br_port_msg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
+	struct rtattr *tb[MDBA_MAX+1], *i;
 
-	if (n->nlmsg_type != RTM_GETMDB &&
-	    n->nlmsg_type != RTM_NEWMDB &&
-	    n->nlmsg_type != RTM_DELMDB) {
-		fprintf(stderr,
-			"Not RTM_GETMDB, RTM_NEWMDB or RTM_DELMDB: %08x %08x %08x\n",
+	if (n->nlmsg_type != RTM_GETMDB && n->nlmsg_type != RTM_NEWMDB && n->nlmsg_type != RTM_DELMDB) {
+		fprintf(stderr, "Not RTM_GETMDB, RTM_NEWMDB or RTM_DELMDB: %08x %08x %08x\n",
 			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
 
 		return 0;
@@ -245,62 +108,34 @@
 
 	parse_rtattr(tb, MDBA_MAX, MDBA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
-	return 1;
-}
+	if (tb[MDBA_MDB]) {
+		int rem = RTA_PAYLOAD(tb[MDBA_MDB]);
 
-static int print_mdbs(struct nlmsghdr *n, void *arg)
-{
-	struct br_port_msg *r = NLMSG_DATA(n);
-	struct rtattr *tb[MDBA_MAX+1];
-	FILE *fp = arg;
-	int ret;
+		for (i = RTA_DATA(tb[MDBA_MDB]); RTA_OK(i, rem); i = RTA_NEXT(i, rem))
+			br_print_mdb_entry(fp, r->ifindex, i, n);
+	}
 
-	ret = __parse_mdb_nlmsg(n, tb);
-	if (ret != 1)
-		return ret;
+	if (tb[MDBA_ROUTER]) {
+		if (n->nlmsg_type == RTM_GETMDB) {
+			if (show_details) {
+				fprintf(fp, "router ports on %s: ",
+					ll_index_to_name(r->ifindex));
+				br_print_router_ports(fp, tb[MDBA_ROUTER]);
+			}
+		} else {
+			uint32_t *port_ifindex;
 
-	if (tb[MDBA_MDB])
-		print_mdb_entries(fp, n, r->ifindex, tb[MDBA_MDB]);
+			i = RTA_DATA(tb[MDBA_ROUTER]);
+			port_ifindex = RTA_DATA(i);
+			if (n->nlmsg_type == RTM_DELMDB)
+				fprintf(fp, "Deleted ");
+			fprintf(fp, "router port dev %s master %s\n",
+				ll_index_to_name(*port_ifindex),
+				ll_index_to_name(r->ifindex));
+		}
+	}
 
-	return 0;
-}
-
-static int print_rtrs(struct nlmsghdr *n, void *arg)
-{
-	struct br_port_msg *r = NLMSG_DATA(n);
-	struct rtattr *tb[MDBA_MAX+1];
-	FILE *fp = arg;
-	int ret;
-
-	ret = __parse_mdb_nlmsg(n, tb);
-	if (ret != 1)
-		return ret;
-
-	if (tb[MDBA_ROUTER])
-		print_router_entries(fp, n, r->ifindex, tb[MDBA_ROUTER]);
-
-	return 0;
-}
-
-int print_mdb_mon(struct nlmsghdr *n, void *arg)
-{
-	struct br_port_msg *r = NLMSG_DATA(n);
-	struct rtattr *tb[MDBA_MAX+1];
-	FILE *fp = arg;
-	int ret;
-
-	ret = __parse_mdb_nlmsg(n, tb);
-	if (ret != 1)
-		return ret;
-
-	if (n->nlmsg_type == RTM_DELMDB)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
-
-	if (tb[MDBA_MDB])
-		print_mdb_entries(fp, n, r->ifindex, tb[MDBA_MDB]);
-
-	if (tb[MDBA_ROUTER])
-		print_router_entries(fp, n, r->ifindex, tb[MDBA_ROUTER]);
+	fflush(fp);
 
 	return 0;
 }
@@ -315,53 +150,28 @@
 			if (filter_dev)
 				duparg("dev", *argv);
 			filter_dev = *argv;
-		} else if (strcmp(*argv, "vid") == 0) {
-			NEXT_ARG();
-			if (filter_vlan)
-				duparg("vid", *argv);
-			filter_vlan = atoi(*argv);
 		}
 		argc--; argv++;
 	}
 
 	if (filter_dev) {
-		filter_index = ll_name_to_index(filter_dev);
-		if (!filter_index)
-			return nodev(filter_dev);
+		filter_index = if_nametoindex(filter_dev);
+		if (filter_index == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n",
+				filter_dev);
+			return -1;
+		}
 	}
 
-	new_json_obj(json);
-	open_json_object(NULL);
-
-	/* get mdb entries */
-	if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
+	if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETMDB) < 0) {
 		perror("Cannot send dump request");
 		return -1;
 	}
 
-	open_json_array(PRINT_JSON, "mdb");
-	if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) {
+	if (rtnl_dump_filter(&rth, print_mdb, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return -1;
 	}
-	close_json_array(PRINT_JSON, NULL);
-
-	/* get router ports */
-	if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
-		perror("Cannot send dump request");
-		return -1;
-	}
-
-	open_json_object("router");
-	if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return -1;
-	}
-	close_json_object();
-
-	close_json_object();
-	delete_json_obj();
-	fflush(stdout);
 
 	return 0;
 }
@@ -369,19 +179,22 @@
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
-		struct nlmsghdr	n;
+		struct nlmsghdr 	n;
 		struct br_port_msg	bpm;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_port_msg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.bpm.family = PF_BRIDGE,
-	};
-	struct br_mdb_entry entry = {};
+		char   			buf[1024];
+	} req;
+	struct br_mdb_entry entry;
 	char *d = NULL, *p = NULL, *grp = NULL;
 	short vid = 0;
 
+	memset(&req, 0, sizeof(req));
+	memset(&entry, 0, sizeof(entry));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_port_msg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.bpm.family = PF_BRIDGE;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
@@ -413,12 +226,16 @@
 	}
 
 	req.bpm.ifindex = ll_name_to_index(d);
-	if (!req.bpm.ifindex)
-		return nodev(d);
+	if (req.bpm.ifindex == 0) {
+		fprintf(stderr, "Cannot find device \"%s\"\n", d);
+		return -1;
+	}
 
 	entry.ifindex = ll_name_to_index(p);
-	if (!entry.ifindex)
-		return nodev(p);
+	if (entry.ifindex == 0) {
+		fprintf(stderr, "Cannot find device \"%s\"\n", p);
+		return -1;
+	}
 
 	if (!inet_pton(AF_INET, grp, &entry.addr.u.ip4)) {
 		if (!inet_pton(AF_INET6, grp, &entry.addr.u.ip6)) {
@@ -432,7 +249,7 @@
 	entry.vid = vid;
 	addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry));
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -1;
 
 	return 0;
diff --git a/bridge/monitor.c b/bridge/monitor.c
index 08439a6..d8341ec 100644
--- a/bridge/monitor.c
+++ b/bridge/monitor.c
@@ -27,7 +27,7 @@
 
 
 static void usage(void) __attribute__((noreturn));
-static int prefix_banner;
+int prefix_banner;
 
 static void usage(void)
 {
@@ -35,7 +35,8 @@
 	exit(-1);
 }
 
-static int accept_msg(struct rtnl_ctrl_data *ctrl,
+static int accept_msg(const struct sockaddr_nl *who,
+		      struct rtnl_ctrl_data *ctrl,
 		      struct nlmsghdr *n, void *arg)
 {
 	FILE *fp = arg;
@@ -49,19 +50,19 @@
 		if (prefix_banner)
 			fprintf(fp, "[LINK]");
 
-		return print_linkinfo(n, arg);
+		return print_linkinfo(who, n, arg);
 
 	case RTM_NEWNEIGH:
 	case RTM_DELNEIGH:
 		if (prefix_banner)
 			fprintf(fp, "[NEIGH]");
-		return print_fdb(n, arg);
+		return print_fdb(who, n, arg);
 
 	case RTM_NEWMDB:
 	case RTM_DELMDB:
 		if (prefix_banner)
 			fprintf(fp, "[MDB]");
-		return print_mdb_mon(n, arg);
+		return print_mdb(who, n, arg);
 
 	case NLMSG_TSTAMP:
 		print_nlmsg_timestamp(fp, n);
@@ -75,10 +76,10 @@
 int do_monitor(int argc, char **argv)
 {
 	char *file = NULL;
-	unsigned int groups = ~RTMGRP_TC;
-	int llink = 0;
-	int lneigh = 0;
-	int lmdb = 0;
+	unsigned groups = ~RTMGRP_TC;
+	int llink=0;
+	int lneigh=0;
+	int lmdb=0;
 
 	rtnl_close(&rth);
 
@@ -87,7 +88,7 @@
 			NEXT_ARG();
 			file = *argv;
 		} else if (matches(*argv, "link") == 0) {
-			llink = 1;
+			llink=1;
 			groups = 0;
 		} else if (matches(*argv, "fdb") == 0) {
 			lneigh = 1;
@@ -97,7 +98,7 @@
 			groups = 0;
 		} else if (strcmp(*argv, "all") == 0) {
 			groups = ~RTMGRP_TC;
-			prefix_banner = 1;
+			prefix_banner=1;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
@@ -121,7 +122,6 @@
 	if (file) {
 		FILE *fp;
 		int err;
-
 		fp = fopen(file, "r");
 		if (fp == NULL) {
 			perror("Cannot fopen");
@@ -141,3 +141,4 @@
 
 	return 0;
 }
+
diff --git a/bridge/vlan.c b/bridge/vlan.c
index 6d33b0a..ac2f523 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -10,139 +9,41 @@
 #include <linux/if_ether.h>
 #include <string.h>
 
-#include "json_print.h"
 #include "libnetlink.h"
 #include "br_common.h"
 #include "utils.h"
 
-static unsigned int filter_index, filter_vlan;
-static int show_vlan_tunnel_info = 0;
+static unsigned int filter_index;
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ tunnel_info id TUNNEL_ID ]\n"
-		"                                                     [ pvid ] [ untagged ]\n"
-		"                                                     [ self ] [ master ]\n"
-		"       bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n"
-		"       bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n");
+	fprintf(stderr, "Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ pvid] [ untagged ]\n");
+	fprintf(stderr, "                                                     [ self ] [ master ]\n");
+	fprintf(stderr, "       bridge vlan { show } [ dev DEV ]\n");
 	exit(-1);
 }
 
-static int parse_tunnel_info(int *argcp, char ***argvp, __u32 *tun_id_start,
-			     __u32 *tun_id_end)
-{
-	char **argv = *argvp;
-	int argc = *argcp;
-	char *t;
-
-	NEXT_ARG();
-	if (!matches(*argv, "id")) {
-		NEXT_ARG();
-		t = strchr(*argv, '-');
-		if (t) {
-			*t = '\0';
-			if (get_u32(tun_id_start, *argv, 0) ||
-				    *tun_id_start >= 1u << 24)
-				invarg("invalid tun id", *argv);
-			if (get_u32(tun_id_end, t + 1, 0) ||
-				    *tun_id_end >= 1u << 24)
-				invarg("invalid tun id", *argv);
-
-		} else {
-			if (get_u32(tun_id_start, *argv, 0) ||
-				    *tun_id_start >= 1u << 24)
-				invarg("invalid tun id", *argv);
-		}
-	} else {
-		invarg("tunnel id expected", *argv);
-	}
-
-	*argcp = argc;
-	*argvp = argv;
-
-	return 0;
-}
-
-static int add_tunnel_info(struct nlmsghdr *n, int reqsize,
-			   __u16 vid, __u32 tun_id, __u16 flags)
-{
-	struct rtattr *tinfo;
-
-	tinfo = addattr_nest(n, reqsize, IFLA_BRIDGE_VLAN_TUNNEL_INFO);
-	addattr32(n, reqsize, IFLA_BRIDGE_VLAN_TUNNEL_ID, tun_id);
-	addattr32(n, reqsize, IFLA_BRIDGE_VLAN_TUNNEL_VID, vid);
-	addattr32(n, reqsize, IFLA_BRIDGE_VLAN_TUNNEL_FLAGS, flags);
-
-	addattr_nest_end(n, tinfo);
-
-	return 0;
-}
-
-static int add_tunnel_info_range(struct nlmsghdr *n, int reqsize,
-				 __u16 vid_start, int16_t vid_end,
-				 __u32 tun_id_start, __u32 tun_id_end)
-{
-	if (vid_end != -1 && (vid_end - vid_start) > 0) {
-		add_tunnel_info(n, reqsize, vid_start, tun_id_start,
-				BRIDGE_VLAN_INFO_RANGE_BEGIN);
-
-		add_tunnel_info(n, reqsize, vid_end, tun_id_end,
-				BRIDGE_VLAN_INFO_RANGE_END);
-	} else {
-		add_tunnel_info(n, reqsize, vid_start, tun_id_start, 0);
-	}
-
-	return 0;
-}
-
-static int add_vlan_info_range(struct nlmsghdr *n, int reqsize, __u16 vid_start,
-			       int16_t vid_end, __u16 flags)
-{
-	struct bridge_vlan_info vinfo = {};
-
-	vinfo.flags = flags;
-	vinfo.vid = vid_start;
-	if (vid_end != -1) {
-		/* send vlan range start */
-		addattr_l(n, reqsize, IFLA_BRIDGE_VLAN_INFO, &vinfo,
-			  sizeof(vinfo));
-		vinfo.flags &= ~BRIDGE_VLAN_INFO_RANGE_BEGIN;
-
-		/* Now send the vlan range end */
-		vinfo.flags |= BRIDGE_VLAN_INFO_RANGE_END;
-		vinfo.vid = vid_end;
-		addattr_l(n, reqsize, IFLA_BRIDGE_VLAN_INFO, &vinfo,
-			  sizeof(vinfo));
-	} else {
-		addattr_l(n, reqsize, IFLA_BRIDGE_VLAN_INFO, &vinfo,
-			  sizeof(vinfo));
-	}
-
-	return 0;
-}
-
 static int vlan_modify(int cmd, int argc, char **argv)
 {
 	struct {
-		struct nlmsghdr	n;
-		struct ifinfomsg	ifm;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = cmd,
-		.ifm.ifi_family = PF_BRIDGE,
-	};
+		struct nlmsghdr 	n;
+		struct ifinfomsg 	ifm;
+		char   			buf[1024];
+	} req;
 	char *d = NULL;
 	short vid = -1;
 	short vid_end = -1;
 	struct rtattr *afspec;
-	struct bridge_vlan_info vinfo = {};
-	bool tunnel_info_set = false;
+	struct bridge_vlan_info vinfo;
 	unsigned short flags = 0;
-	__u32 tun_id_start = 0;
-	__u32 tun_id_end = 0;
+
+	memset(&vinfo, 0, sizeof(vinfo));
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = cmd;
+	req.ifm.ifi_family = PF_BRIDGE;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -150,7 +51,6 @@
 			d = *argv;
 		} else if (strcmp(*argv, "vid") == 0) {
 			char *p;
-
 			NEXT_ARG();
 			p = strchr(*argv, '-');
 			if (p) {
@@ -170,15 +70,10 @@
 			vinfo.flags |= BRIDGE_VLAN_INFO_PVID;
 		} else if (strcmp(*argv, "untagged") == 0) {
 			vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED;
-		} else if (strcmp(*argv, "tunnel_info") == 0) {
-				if (parse_tunnel_info(&argc, &argv,
-						      &tun_id_start,
-						      &tun_id_end))
-					return -1;
-				tunnel_info_set = true;
 		} else {
-			if (matches(*argv, "help") == 0)
+			if (matches(*argv, "help") == 0) {
 				NEXT_ARG();
+			}
 		}
 		argc--; argv++;
 	}
@@ -217,142 +112,39 @@
 	if (flags)
 		addattr16(&req.n, sizeof(req), IFLA_BRIDGE_FLAGS, flags);
 
-	if (tunnel_info_set)
-		add_tunnel_info_range(&req.n, sizeof(req), vid, vid_end,
-				      tun_id_start, tun_id_end);
-	else
-		add_vlan_info_range(&req.n, sizeof(req), vid, vid_end,
-				    vinfo.flags);
+	vinfo.vid = vid;
+	if (vid_end != -1) {
+		/* send vlan range start */
+		addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
+			  sizeof(vinfo));
+		vinfo.flags &= ~BRIDGE_VLAN_INFO_RANGE_BEGIN;
+
+		/* Now send the vlan range end */
+		vinfo.flags |= BRIDGE_VLAN_INFO_RANGE_END;
+		vinfo.vid = vid_end;
+		addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
+			  sizeof(vinfo));
+	} else {
+		addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
+			  sizeof(vinfo));
+	}
 
 	addattr_nest_end(&req.n, afspec);
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -1;
 
 	return 0;
 }
 
-/* In order to use this function for both filtering and non-filtering cases
- * we need to make it a tristate:
- * return -1 - if filtering we've gone over so don't continue
- * return  0 - skip entry and continue (applies to range start or to entries
- *             which are less than filter_vlan)
- * return  1 - print the entry and continue
- */
-static int filter_vlan_check(__u16 vid, __u16 flags)
+static int print_vlan(const struct sockaddr_nl *who,
+		      struct nlmsghdr *n,
+		      void *arg)
 {
-	/* if we're filtering we should stop on the first greater entry */
-	if (filter_vlan && vid > filter_vlan &&
-	    !(flags & BRIDGE_VLAN_INFO_RANGE_END))
-		return -1;
-	if ((flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) ||
-	    vid < filter_vlan)
-		return 0;
-
-	return 1;
-}
-
-static void open_vlan_port(int ifi_index, const char *fmt)
-{
-	open_json_object(NULL);
-	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt,
-			   ll_index_to_name(ifi_index));
-	open_json_array(PRINT_JSON, "vlans");
-}
-
-static void close_vlan_port(void)
-{
-	close_json_array(PRINT_JSON, NULL);
-	close_json_object();
-}
-
-static void print_range(const char *name, __u16 start, __u16 id)
-{
-	char end[64];
-
-	snprintf(end, sizeof(end), "%sEnd", name);
-
-	print_hu(PRINT_ANY, name, "\t %hu", start);
-	if (start != id)
-		print_hu(PRINT_ANY, end, "-%hu", id);
-
-}
-
-static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
-{
-	struct rtattr *i, *list = tb;
-	int rem = RTA_PAYLOAD(list);
-	__u16 last_vid_start = 0;
-	__u32 last_tunid_start = 0;
-
-	if (!filter_vlan)
-		open_vlan_port(ifindex, "%s");
-
-	open_json_array(PRINT_JSON, "tunnel");
-	for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		struct rtattr *ttb[IFLA_BRIDGE_VLAN_TUNNEL_MAX+1];
-		__u32 tunnel_id = 0;
-		__u16 tunnel_vid = 0;
-		__u16 tunnel_flags = 0;
-		int vcheck_ret;
-
-		if (i->rta_type != IFLA_BRIDGE_VLAN_TUNNEL_INFO)
-			continue;
-
-		parse_rtattr(ttb, IFLA_BRIDGE_VLAN_TUNNEL_MAX,
-			     RTA_DATA(i), RTA_PAYLOAD(i));
-
-		if (ttb[IFLA_BRIDGE_VLAN_TUNNEL_VID])
-			tunnel_vid =
-				rta_getattr_u32(ttb[IFLA_BRIDGE_VLAN_TUNNEL_VID]);
-		else
-			continue;
-
-		if (ttb[IFLA_BRIDGE_VLAN_TUNNEL_ID])
-			tunnel_id =
-				rta_getattr_u32(ttb[IFLA_BRIDGE_VLAN_TUNNEL_ID]);
-
-		if (ttb[IFLA_BRIDGE_VLAN_TUNNEL_FLAGS])
-			tunnel_flags =
-				rta_getattr_u32(ttb[IFLA_BRIDGE_VLAN_TUNNEL_FLAGS]);
-
-		if (!(tunnel_flags & BRIDGE_VLAN_INFO_RANGE_END)) {
-			last_vid_start = tunnel_vid;
-			last_tunid_start = tunnel_id;
-		}
-
-		vcheck_ret = filter_vlan_check(tunnel_vid, tunnel_flags);
-		if (vcheck_ret == -1)
-			break;
-		else if (vcheck_ret == 0)
-			continue;
-
-		if (tunnel_flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
-			continue;
-
-		if (filter_vlan)
-			open_vlan_port(ifindex, "%s");
-
-		open_json_object(NULL);
-		print_range("vlan", last_vid_start, tunnel_vid);
-		print_range("tunid", last_tunid_start, tunnel_id);
-		close_json_object();
-
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-		if (filter_vlan)
-			close_vlan_port();
-	}
-
-	if (!filter_vlan)
-		close_vlan_port();
-}
-
-static int print_vlan_tunnel(struct nlmsghdr *n, void *arg)
-{
-	struct ifinfomsg *ifm = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
-	int len = n->nlmsg_len;
 	FILE *fp = arg;
+	struct ifinfomsg *ifm = NLMSG_DATA(n);
+	int len = n->nlmsg_len;
+	struct rtattr * tb[IFLA_MAX+1];
 
 	if (n->nlmsg_type != RTM_NEWLINK) {
 		fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
@@ -376,169 +168,34 @@
 
 	/* if AF_SPEC isn't there, vlan table is not preset for this port */
 	if (!tb[IFLA_AF_SPEC]) {
-		if (!filter_vlan && !is_json_context()) {
-			color_fprintf(fp, COLOR_IFNAME, "%s",
-				      ll_index_to_name(ifm->ifi_index));
-			fprintf(fp, "\tNone\n");
+		fprintf(fp, "%s\tNone\n", ll_index_to_name(ifm->ifi_index));
+		return 0;
+	} else {
+		struct rtattr *i, *list = tb[IFLA_AF_SPEC];
+		int rem = RTA_PAYLOAD(list);
+
+		fprintf(fp, "%s", ll_index_to_name(ifm->ifi_index));
+		for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
+			struct bridge_vlan_info *vinfo;
+
+			if (i->rta_type != IFLA_BRIDGE_VLAN_INFO)
+				continue;
+
+			vinfo = RTA_DATA(i);
+			if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END)
+				fprintf(fp, "-%hu", vinfo->vid);
+			else
+				fprintf(fp, "\t %hu", vinfo->vid);
+			if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
+				continue;
+			if (vinfo->flags & BRIDGE_VLAN_INFO_PVID)
+				fprintf(fp, " PVID");
+			if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED)
+				fprintf(fp, " Egress Untagged");
+			fprintf(fp, "\n");
 		}
-		return 0;
 	}
-
-	print_vlan_tunnel_info(fp, tb[IFLA_AF_SPEC], ifm->ifi_index);
-
-	fflush(fp);
-	return 0;
-}
-
-static int print_vlan(struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = arg;
-	struct ifinfomsg *ifm = NLMSG_DATA(n);
-	int len = n->nlmsg_len;
-	struct rtattr *tb[IFLA_MAX+1];
-
-	if (n->nlmsg_type != RTM_NEWLINK) {
-		fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
-			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
-		return 0;
-	}
-
-	len -= NLMSG_LENGTH(sizeof(*ifm));
-	if (len < 0) {
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-
-	if (ifm->ifi_family != AF_BRIDGE)
-		return 0;
-
-	if (filter_index && filter_index != ifm->ifi_index)
-		return 0;
-
-	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifm), len);
-
-	/* if AF_SPEC isn't there, vlan table is not preset for this port */
-	if (!tb[IFLA_AF_SPEC]) {
-		if (!filter_vlan && !is_json_context()) {
-			color_fprintf(fp, COLOR_IFNAME, "%s",
-				      ll_index_to_name(ifm->ifi_index));
-			fprintf(fp, "\tNone\n");
-		}
-		return 0;
-	}
-
-	print_vlan_info(tb[IFLA_AF_SPEC], ifm->ifi_index);
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	fflush(fp);
-	return 0;
-}
-
-static void print_vlan_flags(__u16 flags)
-{
-	if (flags == 0)
-		return;
-
-	open_json_array(PRINT_JSON, "flags");
-	if (flags & BRIDGE_VLAN_INFO_PVID)
-		print_string(PRINT_ANY, NULL, " %s", "PVID");
-
-	if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
-		print_string(PRINT_ANY, NULL, " %s", "Egress Untagged");
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats)
-{
-	open_json_object(NULL);
-	print_hu(PRINT_ANY, "vid", " %hu", vstats->vid);
-
-	print_vlan_flags(vstats->flags);
-
-	print_lluint(PRINT_ANY, "rx_bytes",
-		     "\n                   RX: %llu bytes",
-		     vstats->rx_bytes);
-	print_lluint(PRINT_ANY, "rx_packets", " %llu packets\n",
-		vstats->rx_packets);
-	print_lluint(PRINT_ANY, "tx_bytes",
-		     "                   TX: %llu bytes",
-		     vstats->tx_bytes);
-	print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n",
-		vstats->tx_packets);
-	close_json_object();
-}
-
-static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
-{
-	struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1];
-	struct rtattr *i, *list;
-	bool found_vlan = false;
-	int rem;
-
-	parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr),
-		     RTA_PAYLOAD(attr));
-	if (!brtb[LINK_XSTATS_TYPE_BRIDGE])
-		return;
-
-	list = brtb[LINK_XSTATS_TYPE_BRIDGE];
-	rem = RTA_PAYLOAD(list);
-
-	for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		const struct bridge_vlan_xstats *vstats = RTA_DATA(i);
-
-		if (i->rta_type != BRIDGE_XSTATS_VLAN)
-			continue;
-
-		if (filter_vlan && filter_vlan != vstats->vid)
-			continue;
-
-		/* skip pure port entries, they'll be dumped via the slave stats call */
-		if ((vstats->flags & BRIDGE_VLAN_INFO_MASTER) &&
-		    !(vstats->flags & BRIDGE_VLAN_INFO_BRENTRY))
-			continue;
-
-		/* found vlan stats, first time print the interface name */
-		if (!found_vlan) {
-			open_vlan_port(ifindex, "%-16s");
-			found_vlan = true;
-		} else {
-			print_string(PRINT_FP, NULL, "%-16s", "");
-		}
-		print_one_vlan_stats(vstats);
-	}
-
-	/* vlan_port is opened only if there are any vlan stats */
-	if (found_vlan)
-		close_vlan_port();
-}
-
-static int print_vlan_stats(struct nlmsghdr *n, void *arg)
-{
-	struct if_stats_msg *ifsm = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_STATS_MAX+1];
-	int len = n->nlmsg_len;
-	FILE *fp = arg;
-
-	len -= NLMSG_LENGTH(sizeof(*ifsm));
-	if (len < 0) {
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-
-	if (filter_index && filter_index != ifsm->ifindex)
-		return 0;
-
-	parse_rtattr(tb, IFLA_STATS_MAX, IFLA_STATS_RTA(ifsm), len);
-
-	/* We have to check if any of the two attrs are usable */
-	if (tb[IFLA_STATS_LINK_XSTATS])
-		print_vlan_stats_attr(tb[IFLA_STATS_LINK_XSTATS],
-				      ifsm->ifindex);
-
-	if (tb[IFLA_STATS_LINK_XSTATS_SLAVE])
-		print_vlan_stats_attr(tb[IFLA_STATS_LINK_XSTATS_SLAVE],
-				      ifsm->ifindex);
-
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
@@ -546,7 +203,6 @@
 static int vlan_show(int argc, char **argv)
 {
 	char *filter_dev = NULL;
-	int ret = 0;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -554,116 +210,35 @@
 			if (filter_dev)
 				duparg("dev", *argv);
 			filter_dev = *argv;
-		} else if (strcmp(*argv, "vid") == 0) {
-			NEXT_ARG();
-			if (filter_vlan)
-				duparg("vid", *argv);
-			filter_vlan = atoi(*argv);
 		}
 		argc--; argv++;
 	}
 
 	if (filter_dev) {
-		filter_index = ll_name_to_index(filter_dev);
-		if (!filter_index)
-			return nodev(filter_dev);
-	}
-
-	new_json_obj(json);
-
-	if (!show_stats) {
-		if (rtnl_linkdump_req_filter(&rth, PF_BRIDGE,
-					     (compress_vlans ?
-					      RTEXT_FILTER_BRVLAN_COMPRESSED :
-					      RTEXT_FILTER_BRVLAN)) < 0) {
-			perror("Cannont send dump request");
-			exit(1);
-		}
-
-		if (!is_json_context()) {
-			if (show_vlan_tunnel_info)
-				printf("port\tvlan ids\ttunnel id\n");
-			else
-				printf("port\tvlan ids\n");
-		}
-
-		if (show_vlan_tunnel_info)
-			ret = rtnl_dump_filter(&rth, print_vlan_tunnel,
-					       stdout);
-		else
-			ret = rtnl_dump_filter(&rth, print_vlan, stdout);
-		if (ret < 0) {
-			fprintf(stderr, "Dump ternminated\n");
-			exit(1);
-		}
-	} else {
-		__u32 filt_mask;
-
-		filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS);
-		if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
-			perror("Cannont send dump request");
-			exit(1);
-		}
-
-		if (!is_json_context())
-			printf("%-16s vlan id\n", "port");
-
-		if (rtnl_dump_filter(&rth, print_vlan_stats, stdout) < 0) {
-			fprintf(stderr, "Dump terminated\n");
-			exit(1);
-		}
-
-		filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE);
-		if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
-			perror("Cannont send slave dump request");
-			exit(1);
-		}
-
-		if (rtnl_dump_filter(&rth, print_vlan_stats, stdout) < 0) {
-			fprintf(stderr, "Dump terminated\n");
-			exit(1);
+		if ((filter_index = if_nametoindex(filter_dev)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n",
+			       filter_dev);
+			return -1;
 		}
 	}
 
-	delete_json_obj();
-	fflush(stdout);
+	if (rtnl_wilddump_req_filter(&rth, PF_BRIDGE, RTM_GETLINK,
+				    (compress_vlans ?
+				    RTEXT_FILTER_BRVLAN_COMPRESSED :
+				    RTEXT_FILTER_BRVLAN)) < 0) {
+		perror("Cannont send dump request");
+		exit(1);
+	}
+
+	printf("port\tvlan ids\n");
+	if (rtnl_dump_filter(&rth, print_vlan, stdout) < 0) {
+		fprintf(stderr, "Dump ternminated\n");
+		exit(1);
+	}
+
 	return 0;
 }
 
-void print_vlan_info(struct rtattr *tb, int ifindex)
-{
-	struct rtattr *i, *list = tb;
-	int rem = RTA_PAYLOAD(list);
-	__u16 last_vid_start = 0;
-
-	open_vlan_port(ifindex, "%s");
-
-	for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		struct bridge_vlan_info *vinfo;
-		int vcheck_ret;
-
-		if (i->rta_type != IFLA_BRIDGE_VLAN_INFO)
-			continue;
-
-		vinfo = RTA_DATA(i);
-
-		if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
-			last_vid_start = vinfo->vid;
-		vcheck_ret = filter_vlan_check(vinfo->vid, vinfo->flags);
-		if (vcheck_ret == -1)
-			break;
-		else if (vcheck_ret == 0)
-			continue;
-
-		open_json_object(NULL);
-		print_range("vlan", last_vid_start, vinfo->vid);
-
-		print_vlan_flags(vinfo->flags);
-		close_json_object();
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-	}
-	close_vlan_port();
-}
 
 int do_vlan(int argc, char **argv)
 {
@@ -678,16 +253,11 @@
 		    matches(*argv, "lst") == 0 ||
 		    matches(*argv, "list") == 0)
 			return vlan_show(argc-1, argv+1);
-		if (matches(*argv, "tunnelshow") == 0) {
-			show_vlan_tunnel_info = 1;
-			return vlan_show(argc-1, argv+1);
-		}
 		if (matches(*argv, "help") == 0)
 			usage();
-	} else {
+	} else
 		return vlan_show(0, NULL);
-	}
 
-	fprintf(stderr, "Command \"%s\" is unknown, try \"bridge vlan help\".\n", *argv);
+	fprintf(stderr, "Command \"%s\" is unknown, try \"bridge fdb help\".\n", *argv);
 	exit(-1);
 }
diff --git a/configure b/configure
index 45fcffb..d2540b0 100755
--- a/configure
+++ b/configure
@@ -1,24 +1,38 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0
+#! /bin/bash
 # This is not an autoconf generated configure
 #
 INCLUDE=${1:-"$PWD/include"}
 
-# Output file which is input to Makefile
-CONFIG=config.mk
-
 # Make a temp directory in build tree.
 TMPDIR=$(mktemp -d config.XXXXXX)
 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
 
+check_prog()
+{
+    echo -n "$2"
+    command -v $1 >/dev/null 2>&1 && (echo "$3:=y" >> Config; echo "yes") || (echo "no"; return 1)
+}
+
+check_docs()
+{
+    if check_prog latex " latex: " HAVE_LATEX; then
+        check_prog pdflatex " pdflatex: " HAVE_PDFLATEX || echo " WARNING: no PDF docs can be built from LaTeX files"
+        check_prog sgml2latex " sgml2latex: " HAVE_SGML2LATEX || echo " WARNING: no LaTeX files can be build from SGML files"
+    else
+        echo " WARNING: no docs can be built from LaTeX files"
+    fi
+
+    check_prog sgml2html " sgml2html: " HAVE_SGML2HTML || echo " WARNING: no HTML docs can be built from SGML"
+}
+
 check_toolchain()
 {
     : ${PKG_CONFIG:=pkg-config}
     : ${AR=ar}
     : ${CC=gcc}
-    echo "PKG_CONFIG:=${PKG_CONFIG}" >>$CONFIG
-    echo "AR:=${AR}" >>$CONFIG
-    echo "CC:=${CC}" >>$CONFIG
+    echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
+    echo "AR:=${AR}" >>Config
+    echo "CC:=${CC}" >>Config
 }
 
 check_atm()
@@ -32,8 +46,10 @@
 }
 EOF
 
-    if $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1; then
-	echo "TC_CONFIG_ATM:=y" >>$CONFIG
+    $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1
+    if [ $? -eq 0 ]
+    then
+	echo "TC_CONFIG_ATM:=y" >>Config
 	echo yes
     else
 	echo no
@@ -41,13 +57,6 @@
     rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
 }
 
-check_xtables()
-{
-	if ! ${PKG_CONFIG} xtables --exists; then
-		echo "TC_CONFIG_NO_XT:=y" >>$CONFIG
-	fi
-}
-
 check_xt()
 {
     #check if we have xtables from iptables >= 1.4.5.
@@ -71,8 +80,9 @@
 EOF
 
     if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL \
-	$(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1; then
-	echo "TC_CONFIG_XT:=y" >>$CONFIG
+	$(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1
+    then
+	echo "TC_CONFIG_XT:=y" >>Config
 	echo "using xtables"
     fi
     rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
@@ -80,10 +90,13 @@
 
 check_xt_old()
 {
-    # bail if previous XT checks has already succeeded.
-    grep -q TC_CONFIG_XT $CONFIG && return
+    # bail if previous XT checks has already succeded.
+    if grep -q TC_CONFIG_XT Config
+    then
+	return
+    fi
 
-    #check if we don't need our internal header ..
+    #check if we dont need our internal header ..
     cat >$TMPDIR/ipttest.c <<EOF
 #include <xtables.h>
 char *lib_dir;
@@ -105,8 +118,10 @@
 
 EOF
 
-    if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1; then
-	echo "TC_CONFIG_XT_OLD:=y" >>$CONFIG
+    $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
+    if [ $? -eq 0 ]
+    then
+	echo "TC_CONFIG_XT_OLD:=y" >>Config
 	echo "using old xtables (no need for xt-internal.h)"
     fi
     rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
@@ -114,8 +129,11 @@
 
 check_xt_old_internal_h()
 {
-    # bail if previous XT checks has already succeeded.
-    grep -q TC_CONFIG_XT $CONFIG && return
+    # bail if previous XT checks has already succeded.
+    if grep -q TC_CONFIG_XT Config
+    then
+	return
+    fi
 
     #check if we need our own internal.h
     cat >$TMPDIR/ipttest.c <<EOF
@@ -139,16 +157,20 @@
 }
 
 EOF
-	if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1; then
+	$CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
+
+	if [ $? -eq 0 ]
+	then
 	    echo "using old xtables with xt-internal.h"
-	    echo "TC_CONFIG_XT_OLD_H:=y" >>$CONFIG
+	    echo "TC_CONFIG_XT_OLD_H:=y" >>Config
 	fi
 	rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
 }
 
 check_ipt()
 {
-	if ! grep TC_CONFIG_XT $CONFIG > /dev/null; then
+	if ! grep TC_CONFIG_XT Config > /dev/null
+	then
 		echo "using iptables"
 	fi
 }
@@ -158,16 +180,16 @@
 	IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
 	if [ -n "$IPT_LIB_DIR" ]; then
 		echo $IPT_LIB_DIR
-		echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> $CONFIG
+		echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> Config
 		return
 	fi
 
-	for dir in /lib /usr/lib /usr/local/lib; do
-		for file in "xtables" "iptables"; do
-			file="$dir/$file/lib*t_*so"
+	for dir in /lib /usr/lib /usr/local/lib
+	do
+		for file in $dir/{xtables,iptables}/lib*t_*so ; do
 			if [ -f $file ]; then
 				echo ${file%/*}
-				echo "IPT_LIB_DIR:=${file%/*}" >> $CONFIG
+				echo "IPT_LIB_DIR:=${file%/*}" >> Config
 				return
 			fi
 		done
@@ -185,10 +207,11 @@
 	return 0;
 }
 EOF
-    if $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1; then
-	echo "IP_CONFIG_SETNS:=y" >>$CONFIG
+    $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
+    if [ $? -eq 0 ]
+    then
+	echo "IP_CONFIG_SETNS:=y" >>Config
 	echo "yes"
-	echo "CFLAGS += -DHAVE_SETNS" >>$CONFIG
     else
 	echo "no"
     fi
@@ -216,8 +239,9 @@
 #endif
 EOF
 
-    if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1; then
-	echo "TC_CONFIG_IPSET:=y" >>$CONFIG
+    if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
+    then
+	echo "TC_CONFIG_IPSET:=y" >>Config
 	echo "yes"
     else
 	echo "no"
@@ -227,26 +251,34 @@
 
 check_elf()
 {
-    if ${PKG_CONFIG} libelf --exists; then
-	echo "HAVE_ELF:=y" >>$CONFIG
-	echo "yes"
+    cat >$TMPDIR/elftest.c <<EOF
+#include <libelf.h>
+#include <gelf.h>
+int main(void)
+{
+	Elf_Scn *scn;
+	GElf_Shdr shdr;
+	return elf_version(EV_CURRENT);
+}
+EOF
 
-	echo 'CFLAGS += -DHAVE_ELF' `${PKG_CONFIG} libelf --cflags` >> $CONFIG
-	echo 'LDLIBS += ' `${PKG_CONFIG} libelf --libs` >>$CONFIG
+    if $CC -I$INCLUDE -o $TMPDIR/elftest $TMPDIR/elftest.c -lelf >/dev/null 2>&1
+    then
+	echo "TC_CONFIG_ELF:=y" >>Config
+	echo "yes"
     else
 	echo "no"
     fi
+    rm -f $TMPDIR/elftest.c $TMPDIR/elftest
 }
 
 check_selinux()
 # SELinux is a compile time option in the ss utility
 {
-	if ${PKG_CONFIG} libselinux --exists; then
-		echo "HAVE_SELINUX:=y" >>$CONFIG
+	if ${PKG_CONFIG} libselinux --exists
+	then
+		echo "HAVE_SELINUX:=y" >>Config
 		echo "yes"
-
-		echo 'LDLIBS +=' `${PKG_CONFIG} --libs libselinux` >>$CONFIG
-		echo 'CFLAGS += -DHAVE_SELINUX' `${PKG_CONFIG} --cflags libselinux` >>$CONFIG
 	else
 		echo "no"
 	fi
@@ -254,12 +286,10 @@
 
 check_mnl()
 {
-	if ${PKG_CONFIG} libmnl --exists; then
-		echo "HAVE_MNL:=y" >>$CONFIG
+	if ${PKG_CONFIG} libmnl --exists
+	then
+		echo "HAVE_MNL:=y" >>Config
 		echo "yes"
-
-		echo 'CFLAGS += -DHAVE_LIBMNL' `${PKG_CONFIG} libmnl --cflags` >>$CONFIG
-		echo 'LDLIBS +=' `${PKG_CONFIG} libmnl --libs` >> $CONFIG
 	else
 		echo "no"
 	fi
@@ -276,8 +306,10 @@
 	return 0;
 }
 EOF
-    if $CC -I$INCLUDE -o $TMPDIR/dbtest $TMPDIR/dbtest.c -ldb >/dev/null 2>&1; then
-	echo "HAVE_BERKELEY_DB:=y" >>$CONFIG
+    $CC -I$INCLUDE -o $TMPDIR/dbtest $TMPDIR/dbtest.c -ldb >/dev/null 2>&1
+    if [ $? -eq 0 ]
+    then
+	echo "HAVE_BERKELEY_DB:=y" >>Config
 	echo "yes"
     else
 	echo "no"
@@ -285,73 +317,7 @@
     rm -f $TMPDIR/dbtest.c $TMPDIR/dbtest
 }
 
-check_strlcpy()
-{
-    cat >$TMPDIR/strtest.c <<EOF
-#include <string.h>
-int main(int argc, char **argv) {
-	char dst[10];
-	strlcpy(dst, "test", sizeof(dst));
-	return 0;
-}
-EOF
-    if $CC -I$INCLUDE -o $TMPDIR/strtest $TMPDIR/strtest.c >/dev/null 2>&1; then
-	echo "no"
-    else
-	if ${PKG_CONFIG} libbsd --exists; then
-		echo 'CFLAGS += -DHAVE_LIBBSD' `${PKG_CONFIG} libbsd --cflags` >>$CONFIG
-		echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG
-		echo "no"
-	else
-		echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
-		echo "yes"
-	fi
-    fi
-    rm -f $TMPDIR/strtest.c $TMPDIR/strtest
-}
-
-check_cap()
-{
-	if ${PKG_CONFIG} libcap --exists; then
-		echo "HAVE_CAP:=y" >>$CONFIG
-		echo "yes"
-
-		echo 'CFLAGS += -DHAVE_LIBCAP' `${PKG_CONFIG} libcap --cflags` >>$CONFIG
-		echo 'LDLIBS +=' `${PKG_CONFIG} libcap --libs` >> $CONFIG
-	else
-		echo "no"
-	fi
-}
-
-quiet_config()
-{
-	cat <<EOF
-# user can control verbosity similar to kernel builds (e.g., V=1)
-ifeq ("\$(origin V)", "command line")
-  VERBOSE = \$(V)
-endif
-ifndef VERBOSE
-  VERBOSE = 0
-endif
-ifeq (\$(VERBOSE),1)
-  Q =
-else
-  Q = @
-endif
-
-ifeq (\$(VERBOSE), 0)
-    QUIET_CC       = @echo '    CC       '\$@;
-    QUIET_AR       = @echo '    AR       '\$@;
-    QUIET_LINK     = @echo '    LINK     '\$@;
-    QUIET_YACC     = @echo '    YACC     '\$@;
-    QUIET_LEX      = @echo '    LEX      '\$@;
-endif
-EOF
-}
-
-echo "# Generated config based on" $INCLUDE >$CONFIG
-quiet_config >> $CONFIG
-
+echo "# Generated config based on" $INCLUDE >Config
 check_toolchain
 
 echo "TC schedulers"
@@ -359,23 +325,18 @@
 echo -n " ATM	"
 check_atm
 
-check_xtables
-if ! grep -q TC_CONFIG_NO_XT $CONFIG; then
-	echo -n " IPT	"
-	check_xt
-	check_xt_old
-	check_xt_old_internal_h
-	check_ipt
+echo -n " IPT	"
+check_xt
+check_xt_old
+check_xt_old_internal_h
+check_ipt
 
-	echo -n " IPSET  "
-	check_ipset
-fi
+echo -n " IPSET  "
+check_ipset
 
 echo
-if ! grep -q TC_CONFIG_NO_XT $CONFIG; then
-	echo -n "iptables modules directory: "
-	check_ipt_lib_dir
-fi
+echo -n "iptables modules directory: "
+check_ipt_lib_dir
 
 echo -n "libc has setns: "
 check_setns
@@ -392,12 +353,7 @@
 echo -n "Berkeley DB: "
 check_berkeley_db
 
-echo -n "need for strlcpy: "
-check_strlcpy
-
-echo -n "libcap support: "
-check_cap
-
-echo >> $CONFIG
-echo "%.o: %.c" >> $CONFIG
-echo '	$(QUIET_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CPPFLAGS) -c -o $@ $<' >> $CONFIG
+echo
+echo -n "docs:"
+check_docs
+echo
diff --git a/devlink/.gitignore b/devlink/.gitignore
deleted file mode 100644
index 08d175f..0000000
--- a/devlink/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-devlink
diff --git a/devlink/Makefile b/devlink/Makefile
deleted file mode 100644
index 7da7d1f..0000000
--- a/devlink/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-include ../config.mk
-
-TARGETS :=
-
-ifeq ($(HAVE_MNL),y)
-
-DEVLINKOBJ = devlink.o mnlg.o
-TARGETS += devlink
-
-endif
-
-all: $(TARGETS) $(LIBS)
-
-devlink: $(DEVLINKOBJ)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
-
-install: all
-	for i in $(TARGETS); \
-	do install -m 0755 $$i $(DESTDIR)$(SBINDIR); \
-	done
-
-clean:
-	rm -f $(DEVLINKOBJ) $(TARGETS)
diff --git a/devlink/devlink.c b/devlink/devlink.c
deleted file mode 100644
index 056ac95..0000000
--- a/devlink/devlink.c
+++ /dev/null
@@ -1,7257 +0,0 @@
-/*
- * devlink.c	Devlink tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:     Jiri Pirko <jiri@mellanox.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <limits.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <sys/sysinfo.h>
-#define _LINUX_SYSINFO_H /* avoid collision with musl header */
-#include <linux/genetlink.h>
-#include <linux/devlink.h>
-#include <libmnl/libmnl.h>
-#include <netinet/ether.h>
-#include <sys/types.h>
-
-#include "SNAPSHOT.h"
-#include "list.h"
-#include "mnlg.h"
-#include "json_writer.h"
-#include "utils.h"
-
-#define ESWITCH_MODE_LEGACY "legacy"
-#define ESWITCH_MODE_SWITCHDEV "switchdev"
-#define ESWITCH_INLINE_MODE_NONE "none"
-#define ESWITCH_INLINE_MODE_LINK "link"
-#define ESWITCH_INLINE_MODE_NETWORK "network"
-#define ESWITCH_INLINE_MODE_TRANSPORT "transport"
-
-#define PARAM_CMODE_RUNTIME_STR "runtime"
-#define PARAM_CMODE_DRIVERINIT_STR "driverinit"
-#define PARAM_CMODE_PERMANENT_STR "permanent"
-#define DL_ARGS_REQUIRED_MAX_ERR_LEN 80
-
-#define HEALTH_REPORTER_STATE_HEALTHY_STR "healthy"
-#define HEALTH_REPORTER_STATE_ERROR_STR "error"
-#define HEALTH_REPORTER_TIMESTAMP_FMT_LEN 80
-
-static int g_new_line_count;
-static int g_indent_level;
-static bool g_indent_newline;
-
-#define INDENT_STR_STEP 2
-#define INDENT_STR_MAXLEN 32
-static char g_indent_str[INDENT_STR_MAXLEN + 1] = "";
-
-static void __attribute__((format(printf, 1, 2)))
-pr_err(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-}
-
-static void __attribute__((format(printf, 1, 2)))
-pr_out(const char *fmt, ...)
-{
-	va_list ap;
-
-	if (g_indent_newline) {
-		printf("%s", g_indent_str);
-		g_indent_newline = false;
-	}
-	va_start(ap, fmt);
-	vprintf(fmt, ap);
-	va_end(ap);
-	g_new_line_count = 0;
-}
-
-static void __attribute__((format(printf, 2, 3)))
-pr_out_sp(unsigned int num, const char *fmt, ...)
-{
-	va_list ap;
-	int ret;
-
-	va_start(ap, fmt);
-	ret = vprintf(fmt, ap);
-	va_end(ap);
-
-	if (ret < num)
-		printf("%*s", num - ret, "");
-	g_new_line_count = 0;			\
-}
-
-static void __attribute__((format(printf, 1, 2)))
-pr_out_tty(const char *fmt, ...)
-{
-	va_list ap;
-
-	if (!isatty(STDOUT_FILENO))
-		return;
-	va_start(ap, fmt);
-	vprintf(fmt, ap);
-	va_end(ap);
-}
-
-static void __pr_out_indent_inc(void)
-{
-	if (g_indent_level + INDENT_STR_STEP > INDENT_STR_MAXLEN)
-		return;
-	g_indent_level += INDENT_STR_STEP;
-	memset(g_indent_str, ' ', sizeof(g_indent_str));
-	g_indent_str[g_indent_level] = '\0';
-}
-
-static void __pr_out_indent_dec(void)
-{
-	if (g_indent_level - INDENT_STR_STEP < 0)
-		return;
-	g_indent_level -= INDENT_STR_STEP;
-	g_indent_str[g_indent_level] = '\0';
-}
-
-static void __pr_out_newline(void)
-{
-	if (g_new_line_count < 1) {
-		pr_out("\n");
-		g_indent_newline = true;
-	}
-	g_new_line_count++;
-}
-
-static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
-				 mnl_cb_t data_cb, void *data)
-{
-	int err;
-
-	err = mnlg_socket_recv_run(nlg, data_cb, data);
-	if (err < 0) {
-		pr_err("devlink answers: %s\n", strerror(errno));
-		return -errno;
-	}
-	return 0;
-}
-
-static int _mnlg_socket_send(struct mnlg_socket *nlg,
-			     const struct nlmsghdr *nlh)
-{
-	int err;
-
-	err = mnlg_socket_send(nlg, nlh);
-	if (err < 0) {
-		pr_err("Failed to call mnlg_socket_send\n");
-		return -errno;
-	}
-	return 0;
-}
-
-static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
-			       const struct nlmsghdr *nlh,
-			       mnl_cb_t data_cb, void *data)
-{
-	int err;
-
-	err = _mnlg_socket_send(nlg, nlh);
-	if (err)
-		return err;
-	return _mnlg_socket_recv_run(nlg, data_cb, data);
-}
-
-static int _mnlg_socket_group_add(struct mnlg_socket *nlg,
-				  const char *group_name)
-{
-	int err;
-
-	err = mnlg_socket_group_add(nlg, group_name);
-	if (err < 0) {
-		pr_err("Failed to call mnlg_socket_group_add\n");
-		return -errno;
-	}
-	return 0;
-}
-
-struct ifname_map {
-	struct list_head list;
-	char *bus_name;
-	char *dev_name;
-	uint32_t port_index;
-	char *ifname;
-};
-
-static struct ifname_map *ifname_map_alloc(const char *bus_name,
-					   const char *dev_name,
-					   uint32_t port_index,
-					   const char *ifname)
-{
-	struct ifname_map *ifname_map;
-
-	ifname_map = calloc(1, sizeof(*ifname_map));
-	if (!ifname_map)
-		return NULL;
-	ifname_map->bus_name = strdup(bus_name);
-	ifname_map->dev_name = strdup(dev_name);
-	ifname_map->port_index = port_index;
-	ifname_map->ifname = strdup(ifname);
-	if (!ifname_map->bus_name || !ifname_map->dev_name ||
-	    !ifname_map->ifname) {
-		free(ifname_map->ifname);
-		free(ifname_map->dev_name);
-		free(ifname_map->bus_name);
-		free(ifname_map);
-		return NULL;
-	}
-	return ifname_map;
-}
-
-static void ifname_map_free(struct ifname_map *ifname_map)
-{
-	free(ifname_map->ifname);
-	free(ifname_map->dev_name);
-	free(ifname_map->bus_name);
-	free(ifname_map);
-}
-
-#define DL_OPT_HANDLE		BIT(0)
-#define DL_OPT_HANDLEP		BIT(1)
-#define DL_OPT_PORT_TYPE	BIT(2)
-#define DL_OPT_PORT_COUNT	BIT(3)
-#define DL_OPT_SB		BIT(4)
-#define DL_OPT_SB_POOL		BIT(5)
-#define DL_OPT_SB_SIZE		BIT(6)
-#define DL_OPT_SB_TYPE		BIT(7)
-#define DL_OPT_SB_THTYPE	BIT(8)
-#define DL_OPT_SB_TH		BIT(9)
-#define DL_OPT_SB_TC		BIT(10)
-#define DL_OPT_ESWITCH_MODE	BIT(11)
-#define DL_OPT_ESWITCH_INLINE_MODE	BIT(12)
-#define DL_OPT_DPIPE_TABLE_NAME	BIT(13)
-#define DL_OPT_DPIPE_TABLE_COUNTERS	BIT(14)
-#define DL_OPT_ESWITCH_ENCAP_MODE	BIT(15)
-#define DL_OPT_RESOURCE_PATH	BIT(16)
-#define DL_OPT_RESOURCE_SIZE	BIT(17)
-#define DL_OPT_PARAM_NAME	BIT(18)
-#define DL_OPT_PARAM_VALUE	BIT(19)
-#define DL_OPT_PARAM_CMODE	BIT(20)
-#define DL_OPT_HANDLE_REGION		BIT(21)
-#define DL_OPT_REGION_SNAPSHOT_ID	BIT(22)
-#define DL_OPT_REGION_ADDRESS		BIT(23)
-#define DL_OPT_REGION_LENGTH		BIT(24)
-#define DL_OPT_FLASH_FILE_NAME	BIT(25)
-#define DL_OPT_FLASH_COMPONENT	BIT(26)
-#define DL_OPT_HEALTH_REPORTER_NAME	BIT(27)
-#define DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD	BIT(28)
-#define DL_OPT_HEALTH_REPORTER_AUTO_RECOVER	BIT(29)
-#define DL_OPT_TRAP_NAME		BIT(30)
-#define DL_OPT_TRAP_ACTION		BIT(31)
-#define DL_OPT_TRAP_GROUP_NAME		BIT(32)
-
-struct dl_opts {
-	uint64_t present; /* flags of present items */
-	char *bus_name;
-	char *dev_name;
-	uint32_t port_index;
-	enum devlink_port_type port_type;
-	uint32_t port_count;
-	uint32_t sb_index;
-	uint16_t sb_pool_index;
-	uint32_t sb_pool_size;
-	enum devlink_sb_pool_type sb_pool_type;
-	enum devlink_sb_threshold_type sb_pool_thtype;
-	uint32_t sb_threshold;
-	uint16_t sb_tc_index;
-	enum devlink_eswitch_mode eswitch_mode;
-	enum devlink_eswitch_inline_mode eswitch_inline_mode;
-	const char *dpipe_table_name;
-	bool dpipe_counters_enable;
-	bool eswitch_encap_mode;
-	const char *resource_path;
-	uint32_t resource_size;
-	uint32_t resource_id;
-	bool resource_id_valid;
-	const char *param_name;
-	const char *param_value;
-	enum devlink_param_cmode cmode;
-	char *region_name;
-	uint32_t region_snapshot_id;
-	uint64_t region_address;
-	uint64_t region_length;
-	const char *flash_file_name;
-	const char *flash_component;
-	const char *reporter_name;
-	uint64_t reporter_graceful_period;
-	bool reporter_auto_recover;
-	const char *trap_name;
-	const char *trap_group_name;
-	enum devlink_trap_action trap_action;
-};
-
-struct dl {
-	struct mnlg_socket *nlg;
-	struct list_head ifname_map_list;
-	int argc;
-	char **argv;
-	bool no_nice_names;
-	struct dl_opts opts;
-	json_writer_t *jw;
-	bool json_output;
-	bool pretty_output;
-	bool verbose;
-	bool stats;
-	struct {
-		bool present;
-		char *bus_name;
-		char *dev_name;
-		uint32_t port_index;
-	} arr_last;
-};
-
-static int dl_argc(struct dl *dl)
-{
-	return dl->argc;
-}
-
-static char *dl_argv(struct dl *dl)
-{
-	if (dl_argc(dl) == 0)
-		return NULL;
-	return *dl->argv;
-}
-
-static void dl_arg_inc(struct dl *dl)
-{
-	if (dl_argc(dl) == 0)
-		return;
-	dl->argc--;
-	dl->argv++;
-}
-
-static char *dl_argv_next(struct dl *dl)
-{
-	char *ret;
-
-	if (dl_argc(dl) == 0)
-		return NULL;
-
-	ret = *dl->argv;
-	dl_arg_inc(dl);
-	return ret;
-}
-
-static char *dl_argv_index(struct dl *dl, unsigned int index)
-{
-	if (index >= dl_argc(dl))
-		return NULL;
-	return dl->argv[index];
-}
-
-static int strcmpx(const char *str1, const char *str2)
-{
-	if (strlen(str1) > strlen(str2))
-		return -1;
-	return strncmp(str1, str2, strlen(str1));
-}
-
-static bool dl_argv_match(struct dl *dl, const char *pattern)
-{
-	if (dl_argc(dl) == 0)
-		return false;
-	return strcmpx(dl_argv(dl), pattern) == 0;
-}
-
-static bool dl_no_arg(struct dl *dl)
-{
-	return dl_argc(dl) == 0;
-}
-
-static void __pr_out_indent_newline(struct dl *dl)
-{
-	if (!g_indent_newline && !dl->json_output)
-		pr_out(" ");
-}
-
-static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
-	[DEVLINK_ATTR_BUS_NAME] = MNL_TYPE_NUL_STRING,
-	[DEVLINK_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
-	[DEVLINK_ATTR_PORT_INDEX] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_PORT_TYPE] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_PORT_DESIRED_TYPE] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_PORT_NETDEV_IFINDEX] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_PORT_NETDEV_NAME] = MNL_TYPE_NUL_STRING,
-	[DEVLINK_ATTR_PORT_IBDEV_NAME] = MNL_TYPE_NUL_STRING,
-	[DEVLINK_ATTR_SB_INDEX] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_SB_SIZE] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_SB_INGRESS_TC_COUNT] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_SB_EGRESS_TC_COUNT] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_SB_POOL_INDEX] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_SB_POOL_TYPE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_SB_POOL_SIZE] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_SB_THRESHOLD] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_SB_TC_INDEX] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_SB_OCC_CUR] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_SB_OCC_MAX] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_ESWITCH_MODE] = MNL_TYPE_U16,
-	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_DPIPE_TABLES] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_TABLE] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_TABLE_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_DPIPE_TABLE_SIZE] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_DPIPE_TABLE_MATCHES] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_TABLE_ACTIONS] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] =  MNL_TYPE_U8,
-	[DEVLINK_ATTR_DPIPE_ENTRIES] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_ENTRY] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_ENTRY_INDEX] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_DPIPE_MATCH] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_MATCH_VALUE] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_MATCH_TYPE] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_ACTION] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_ACTION_VALUE] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_ACTION_TYPE] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_VALUE_MAPPING] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_HEADERS] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_HEADER] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_HEADER_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_DPIPE_HEADER_ID] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_HEADER_FIELDS] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_DPIPE_HEADER_INDEX] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_FIELD] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_DPIPE_FIELD_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_DPIPE_FIELD_ID] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_PARAM] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_PARAM_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_PARAM_TYPE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_PARAM_VALUES_LIST] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_PARAM_VALUE] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_PARAM_VALUE_CMODE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_REGION_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_REGION_SIZE] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_REGION_SNAPSHOTS] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_REGION_SNAPSHOT] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_REGION_SNAPSHOT_ID] = MNL_TYPE_U32,
-	[DEVLINK_ATTR_REGION_CHUNKS] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_REGION_CHUNK] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_REGION_CHUNK_DATA] = MNL_TYPE_BINARY,
-	[DEVLINK_ATTR_REGION_CHUNK_ADDR] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_REGION_CHUNK_LEN] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_INFO_DRIVER_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_INFO_SERIAL_NUMBER] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_INFO_VERSION_FIXED] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_INFO_VERSION_RUNNING] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_INFO_VERSION_STORED] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_INFO_VERSION_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_INFO_VERSION_VALUE] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_HEALTH_REPORTER] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_HEALTH_REPORTER_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_HEALTH_REPORTER_STATE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_STATS] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_TRAP_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_TRAP_ACTION] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_TRAP_TYPE] = MNL_TYPE_U8,
-	[DEVLINK_ATTR_TRAP_GENERIC] = MNL_TYPE_FLAG,
-	[DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
-	[DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
-	[DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
-};
-
-static const enum mnl_attr_data_type
-devlink_stats_policy[DEVLINK_ATTR_STATS_MAX + 1] = {
-	[DEVLINK_ATTR_STATS_RX_PACKETS] = MNL_TYPE_U64,
-	[DEVLINK_ATTR_STATS_RX_BYTES] = MNL_TYPE_U64,
-};
-
-static int attr_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	int type;
-
-	if (mnl_attr_type_valid(attr, DEVLINK_ATTR_MAX) < 0)
-		return MNL_CB_OK;
-
-	type = mnl_attr_get_type(attr);
-	if (mnl_attr_validate(attr, devlink_policy[type]) < 0)
-		return MNL_CB_ERROR;
-
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-static int attr_stats_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	int type;
-
-	/* Allow the tool to work on top of newer kernels that might contain
-	 * more attributes.
-	 */
-	if (mnl_attr_type_valid(attr, DEVLINK_ATTR_STATS_MAX) < 0)
-		return MNL_CB_OK;
-
-	type = mnl_attr_get_type(attr);
-	if (mnl_attr_validate(attr, devlink_stats_policy[type]) < 0)
-		return MNL_CB_ERROR;
-
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-static int ifname_map_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct dl *dl = data;
-	struct ifname_map *ifname_map;
-	const char *bus_name;
-	const char *dev_name;
-	uint32_t port_ifindex;
-	const char *port_ifname;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PORT_INDEX])
-		return MNL_CB_ERROR;
-
-	if (!tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
-		return MNL_CB_OK;
-
-	bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
-	dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
-	port_ifindex = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
-	port_ifname = mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]);
-	ifname_map = ifname_map_alloc(bus_name, dev_name,
-				      port_ifindex, port_ifname);
-	if (!ifname_map)
-		return MNL_CB_ERROR;
-	list_add(&ifname_map->list, &dl->ifname_map_list);
-
-	return MNL_CB_OK;
-}
-
-static void ifname_map_fini(struct dl *dl)
-{
-	struct ifname_map *ifname_map, *tmp;
-
-	list_for_each_entry_safe(ifname_map, tmp,
-				 &dl->ifname_map_list, list) {
-		list_del(&ifname_map->list);
-		ifname_map_free(ifname_map);
-	}
-}
-
-static int ifname_map_init(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	INIT_LIST_HEAD(&dl->ifname_map_list);
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET,
-			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
-
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, ifname_map_cb, dl);
-	if (err) {
-		ifname_map_fini(dl);
-		return err;
-	}
-	return 0;
-}
-
-static int ifname_map_lookup(struct dl *dl, const char *ifname,
-			     char **p_bus_name, char **p_dev_name,
-			     uint32_t *p_port_index)
-{
-	struct ifname_map *ifname_map;
-
-	list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
-		if (strcmp(ifname, ifname_map->ifname) == 0) {
-			*p_bus_name = ifname_map->bus_name;
-			*p_dev_name = ifname_map->dev_name;
-			*p_port_index = ifname_map->port_index;
-			return 0;
-		}
-	}
-	return -ENOENT;
-}
-
-static int ifname_map_rev_lookup(struct dl *dl, const char *bus_name,
-				 const char *dev_name, uint32_t port_index,
-				 char **p_ifname)
-{
-	struct ifname_map *ifname_map;
-
-	list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
-		if (strcmp(bus_name, ifname_map->bus_name) == 0 &&
-		    strcmp(dev_name, ifname_map->dev_name) == 0 &&
-		    port_index == ifname_map->port_index) {
-			*p_ifname = ifname_map->ifname;
-			return 0;
-		}
-	}
-	return -ENOENT;
-}
-
-static unsigned int strslashcount(char *str)
-{
-	unsigned int count = 0;
-	char *pos = str;
-
-	while ((pos = strchr(pos, '/'))) {
-		count++;
-		pos++;
-	}
-	return count;
-}
-
-static int strslashrsplit(char *str, char **before, char **after)
-{
-	char *slash;
-
-	slash = strrchr(str, '/');
-	if (!slash)
-		return -EINVAL;
-	*slash = '\0';
-	*before = str;
-	*after = slash + 1;
-	return 0;
-}
-
-static int strtouint64_t(const char *str, uint64_t *p_val)
-{
-	char *endptr;
-	unsigned long long int val;
-
-	val = strtoull(str, &endptr, 10);
-	if (endptr == str || *endptr != '\0')
-		return -EINVAL;
-	if (val > ULONG_MAX)
-		return -ERANGE;
-	*p_val = val;
-	return 0;
-}
-
-static int strtouint32_t(const char *str, uint32_t *p_val)
-{
-	char *endptr;
-	unsigned long int val;
-
-	val = strtoul(str, &endptr, 10);
-	if (endptr == str || *endptr != '\0')
-		return -EINVAL;
-	if (val > UINT_MAX)
-		return -ERANGE;
-	*p_val = val;
-	return 0;
-}
-
-static int strtouint16_t(const char *str, uint16_t *p_val)
-{
-	char *endptr;
-	unsigned long int val;
-
-	val = strtoul(str, &endptr, 10);
-	if (endptr == str || *endptr != '\0')
-		return -EINVAL;
-	if (val > USHRT_MAX)
-		return -ERANGE;
-	*p_val = val;
-	return 0;
-}
-
-static int strtouint8_t(const char *str, uint8_t *p_val)
-{
-	char *endptr;
-	unsigned long int val;
-
-	val = strtoul(str, &endptr, 10);
-	if (endptr == str || *endptr != '\0')
-		return -EINVAL;
-	if (val > UCHAR_MAX)
-		return -ERANGE;
-	*p_val = val;
-	return 0;
-}
-
-static int strtobool(const char *str, bool *p_val)
-{
-	bool val;
-
-	if (!strcmp(str, "true") || !strcmp(str, "1"))
-		val = true;
-	else if (!strcmp(str, "false") || !strcmp(str, "0"))
-		val = false;
-	else
-		return -EINVAL;
-	*p_val = val;
-	return 0;
-}
-
-static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name)
-{
-	strslashrsplit(str, p_bus_name, p_dev_name);
-	return 0;
-}
-
-static int dl_argv_handle(struct dl *dl, char **p_bus_name, char **p_dev_name)
-{
-	char *str = dl_argv_next(dl);
-
-	if (!str) {
-		pr_err("Devlink identification (\"bus_name/dev_name\") expected\n");
-		return -EINVAL;
-	}
-	if (strslashcount(str) != 1) {
-		pr_err("Wrong devlink identification string format.\n");
-		pr_err("Expected \"bus_name/dev_name\".\n");
-		return -EINVAL;
-	}
-	return __dl_argv_handle(str, p_bus_name, p_dev_name);
-}
-
-static int __dl_argv_handle_port(char *str,
-				 char **p_bus_name, char **p_dev_name,
-				 uint32_t *p_port_index)
-{
-	char *handlestr;
-	char *portstr;
-	int err;
-
-	err = strslashrsplit(str, &handlestr, &portstr);
-	if (err) {
-		pr_err("Port identification \"%s\" is invalid\n", str);
-		return err;
-	}
-	err = strtouint32_t(portstr, p_port_index);
-	if (err) {
-		pr_err("Port index \"%s\" is not a number or not within range\n",
-		       portstr);
-		return err;
-	}
-	err = strslashrsplit(handlestr, p_bus_name, p_dev_name);
-	if (err) {
-		pr_err("Port identification \"%s\" is invalid\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int __dl_argv_handle_port_ifname(struct dl *dl, char *str,
-					char **p_bus_name, char **p_dev_name,
-					uint32_t *p_port_index)
-{
-	int err;
-
-	err = ifname_map_lookup(dl, str, p_bus_name, p_dev_name,
-				p_port_index);
-	if (err) {
-		pr_err("Netdevice \"%s\" not found\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int dl_argv_handle_port(struct dl *dl, char **p_bus_name,
-			       char **p_dev_name, uint32_t *p_port_index)
-{
-	char *str = dl_argv_next(dl);
-	unsigned int slash_count;
-
-	if (!str) {
-		pr_err("Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\") expected.\n");
-		return -EINVAL;
-	}
-	slash_count = strslashcount(str);
-	switch (slash_count) {
-	case 0:
-		return __dl_argv_handle_port_ifname(dl, str, p_bus_name,
-						    p_dev_name, p_port_index);
-	case 2:
-		return __dl_argv_handle_port(str, p_bus_name,
-					     p_dev_name, p_port_index);
-	default:
-		pr_err("Wrong port identification string format.\n");
-		pr_err("Expected \"bus_name/dev_name/port_index\" or \"netdev_ifname\".\n");
-		return -EINVAL;
-	}
-}
-
-static int dl_argv_handle_both(struct dl *dl, char **p_bus_name,
-			       char **p_dev_name, uint32_t *p_port_index,
-			       uint64_t *p_handle_bit)
-{
-	char *str = dl_argv_next(dl);
-	unsigned int slash_count;
-	int err;
-
-	if (!str) {
-		pr_err("One of following identifications expected:\n"
-		       "Devlink identification (\"bus_name/dev_name\")\n"
-		       "Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\")\n");
-		return -EINVAL;
-	}
-	slash_count = strslashcount(str);
-	if (slash_count == 1) {
-		err = __dl_argv_handle(str, p_bus_name, p_dev_name);
-		if (err)
-			return err;
-		*p_handle_bit = DL_OPT_HANDLE;
-	} else if (slash_count == 2) {
-		err = __dl_argv_handle_port(str, p_bus_name,
-					    p_dev_name, p_port_index);
-		if (err)
-			return err;
-		*p_handle_bit = DL_OPT_HANDLEP;
-	} else if (slash_count == 0) {
-		err = __dl_argv_handle_port_ifname(dl, str, p_bus_name,
-						   p_dev_name, p_port_index);
-		if (err)
-			return err;
-		*p_handle_bit = DL_OPT_HANDLEP;
-	} else {
-		pr_err("Wrong port identification string format.\n");
-		pr_err("Expected \"bus_name/dev_name\" or \"bus_name/dev_name/port_index\" or \"netdev_ifname\".\n");
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int __dl_argv_handle_region(char *str, char **p_bus_name,
-				   char **p_dev_name, char **p_region)
-{
-	char *handlestr;
-	int err;
-
-	err = strslashrsplit(str, &handlestr, p_region);
-	if (err) {
-		pr_err("Region identification \"%s\" is invalid\n", str);
-		return err;
-	}
-	err = strslashrsplit(handlestr, p_bus_name, p_dev_name);
-	if (err) {
-		pr_err("Region identification \"%s\" is invalid\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int dl_argv_handle_region(struct dl *dl, char **p_bus_name,
-					char **p_dev_name, char **p_region)
-{
-	char *str = dl_argv_next(dl);
-	unsigned int slash_count;
-
-	if (!str) {
-		pr_err("Expected \"bus_name/dev_name/region\" identification.\n");
-		return -EINVAL;
-	}
-
-	slash_count = strslashcount(str);
-	if (slash_count != 2) {
-		pr_err("Wrong region identification string format.\n");
-		pr_err("Expected \"bus_name/dev_name/region\" identification.\n"".\n");
-		return -EINVAL;
-	}
-
-	return __dl_argv_handle_region(str, p_bus_name, p_dev_name, p_region);
-}
-
-static int dl_argv_uint64_t(struct dl *dl, uint64_t *p_val)
-{
-	char *str = dl_argv_next(dl);
-	int err;
-
-	if (!str) {
-		pr_err("Unsigned number argument expected\n");
-		return -EINVAL;
-	}
-
-	err = strtouint64_t(str, p_val);
-	if (err) {
-		pr_err("\"%s\" is not a number or not within range\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int dl_argv_uint32_t(struct dl *dl, uint32_t *p_val)
-{
-	char *str = dl_argv_next(dl);
-	int err;
-
-	if (!str) {
-		pr_err("Unsigned number argument expected\n");
-		return -EINVAL;
-	}
-
-	err = strtouint32_t(str, p_val);
-	if (err) {
-		pr_err("\"%s\" is not a number or not within range\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int dl_argv_uint16_t(struct dl *dl, uint16_t *p_val)
-{
-	char *str = dl_argv_next(dl);
-	int err;
-
-	if (!str) {
-		pr_err("Unsigned number argument expected\n");
-		return -EINVAL;
-	}
-
-	err = strtouint16_t(str, p_val);
-	if (err) {
-		pr_err("\"%s\" is not a number or not within range\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int dl_argv_bool(struct dl *dl, bool *p_val)
-{
-	char *str = dl_argv_next(dl);
-	int err;
-
-	if (!str) {
-		pr_err("Boolean argument expected\n");
-		return -EINVAL;
-	}
-
-	err = strtobool(str, p_val);
-	if (err) {
-		pr_err("\"%s\" is not a valid boolean value\n", str);
-		return err;
-	}
-	return 0;
-}
-
-static int dl_argv_str(struct dl *dl, const char **p_str)
-{
-	const char *str = dl_argv_next(dl);
-
-	if (!str) {
-		pr_err("String parameter expected\n");
-		return -EINVAL;
-	}
-	*p_str = str;
-	return 0;
-}
-
-static int port_type_get(const char *typestr, enum devlink_port_type *p_type)
-{
-	if (strcmp(typestr, "auto") == 0) {
-		*p_type = DEVLINK_PORT_TYPE_AUTO;
-	} else if (strcmp(typestr, "eth") == 0) {
-		*p_type = DEVLINK_PORT_TYPE_ETH;
-	} else if (strcmp(typestr, "ib") == 0) {
-		*p_type = DEVLINK_PORT_TYPE_IB;
-	} else {
-		pr_err("Unknown port type \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int pool_type_get(const char *typestr, enum devlink_sb_pool_type *p_type)
-{
-	if (strcmp(typestr, "ingress") == 0) {
-		*p_type = DEVLINK_SB_POOL_TYPE_INGRESS;
-	} else if (strcmp(typestr, "egress") == 0) {
-		*p_type = DEVLINK_SB_POOL_TYPE_EGRESS;
-	} else {
-		pr_err("Unknown pool type \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int threshold_type_get(const char *typestr,
-			      enum devlink_sb_threshold_type *p_type)
-{
-	if (strcmp(typestr, "static") == 0) {
-		*p_type = DEVLINK_SB_THRESHOLD_TYPE_STATIC;
-	} else if (strcmp(typestr, "dynamic") == 0) {
-		*p_type = DEVLINK_SB_THRESHOLD_TYPE_DYNAMIC;
-	} else {
-		pr_err("Unknown threshold type \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int eswitch_mode_get(const char *typestr,
-			    enum devlink_eswitch_mode *p_mode)
-{
-	if (strcmp(typestr, ESWITCH_MODE_LEGACY) == 0) {
-		*p_mode = DEVLINK_ESWITCH_MODE_LEGACY;
-	} else if (strcmp(typestr, ESWITCH_MODE_SWITCHDEV) == 0) {
-		*p_mode = DEVLINK_ESWITCH_MODE_SWITCHDEV;
-	} else {
-		pr_err("Unknown eswitch mode \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int eswitch_inline_mode_get(const char *typestr,
-				   enum devlink_eswitch_inline_mode *p_mode)
-{
-	if (strcmp(typestr, ESWITCH_INLINE_MODE_NONE) == 0) {
-		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_NONE;
-	} else if (strcmp(typestr, ESWITCH_INLINE_MODE_LINK) == 0) {
-		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_LINK;
-	} else if (strcmp(typestr, ESWITCH_INLINE_MODE_NETWORK) == 0) {
-		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_NETWORK;
-	} else if (strcmp(typestr, ESWITCH_INLINE_MODE_TRANSPORT) == 0) {
-		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT;
-	} else {
-		pr_err("Unknown eswitch inline mode \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int dpipe_counters_enable_get(const char *typestr,
-				     bool *counters_enable)
-{
-	if (strcmp(typestr, "enable") == 0) {
-		*counters_enable = 1;
-	} else if (strcmp(typestr, "disable") == 0) {
-		*counters_enable = 0;
-	} else {
-		pr_err("Unknown counter_state \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
-{
-	if (strcmp(typestr, "enable") == 0) {
-		*p_mode = true;
-	} else if (strcmp(typestr, "disable") == 0) {
-		*p_mode = false;
-	} else {
-		pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int param_cmode_get(const char *cmodestr,
-			   enum devlink_param_cmode *cmode)
-{
-	if (strcmp(cmodestr, PARAM_CMODE_RUNTIME_STR) == 0) {
-		*cmode = DEVLINK_PARAM_CMODE_RUNTIME;
-	} else if (strcmp(cmodestr, PARAM_CMODE_DRIVERINIT_STR) == 0) {
-		*cmode = DEVLINK_PARAM_CMODE_DRIVERINIT;
-	} else if (strcmp(cmodestr, PARAM_CMODE_PERMANENT_STR) == 0) {
-		*cmode = DEVLINK_PARAM_CMODE_PERMANENT;
-	} else {
-		pr_err("Unknown configuration mode \"%s\"\n", cmodestr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-static int trap_action_get(const char *actionstr,
-			   enum devlink_trap_action *p_action)
-{
-	if (strcmp(actionstr, "drop") == 0) {
-		*p_action = DEVLINK_TRAP_ACTION_DROP;
-	} else if (strcmp(actionstr, "trap") == 0) {
-		*p_action = DEVLINK_TRAP_ACTION_TRAP;
-	} else {
-		pr_err("Unknown trap action \"%s\"\n", actionstr);
-		return -EINVAL;
-	}
-	return 0;
-}
-
-struct dl_args_metadata {
-	uint64_t o_flag;
-	char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN];
-};
-
-static const struct dl_args_metadata dl_args_required[] = {
-	{DL_OPT_PORT_TYPE,	      "Port type not set."},
-	{DL_OPT_PORT_COUNT,	      "Port split count option expected."},
-	{DL_OPT_SB_POOL,	      "Pool index option expected."},
-	{DL_OPT_SB_SIZE,	      "Pool size option expected."},
-	{DL_OPT_SB_TYPE,	      "Pool type option expected."},
-	{DL_OPT_SB_THTYPE,	      "Pool threshold type option expected."},
-	{DL_OPT_SB_TH,		      "Threshold option expected."},
-	{DL_OPT_SB_TC,		      "TC index option expected."},
-	{DL_OPT_ESWITCH_MODE,	      "E-Switch mode option expected."},
-	{DL_OPT_ESWITCH_INLINE_MODE,  "E-Switch inline-mode option expected."},
-	{DL_OPT_DPIPE_TABLE_NAME,     "Dpipe table name expected."},
-	{DL_OPT_DPIPE_TABLE_COUNTERS, "Dpipe table counter state expected."},
-	{DL_OPT_ESWITCH_ENCAP_MODE,   "E-Switch encapsulation option expected."},
-	{DL_OPT_RESOURCE_PATH,	      "Resource path expected."},
-	{DL_OPT_RESOURCE_SIZE,	      "Resource size expected."},
-	{DL_OPT_PARAM_NAME,	      "Parameter name expected."},
-	{DL_OPT_PARAM_VALUE,	      "Value to set expected."},
-	{DL_OPT_PARAM_CMODE,	      "Configuration mode expected."},
-	{DL_OPT_REGION_SNAPSHOT_ID,   "Region snapshot id expected."},
-	{DL_OPT_REGION_ADDRESS,	      "Region address value expected."},
-	{DL_OPT_REGION_LENGTH,	      "Region length value expected."},
-	{DL_OPT_HEALTH_REPORTER_NAME, "Reporter's name is expected."},
-	{DL_OPT_TRAP_NAME,            "Trap's name is expected."},
-	{DL_OPT_TRAP_GROUP_NAME,      "Trap group's name is expected."},
-};
-
-static int dl_args_finding_required_validate(uint64_t o_required,
-					     uint64_t o_found)
-{
-	uint64_t o_flag;
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(dl_args_required); i++) {
-		o_flag = dl_args_required[i].o_flag;
-		if ((o_required & o_flag) && !(o_found & o_flag)) {
-			pr_err("%s\n", dl_args_required[i].err_msg);
-			return -EINVAL;
-		}
-	}
-	return 0;
-}
-
-static int dl_argv_parse(struct dl *dl, uint64_t o_required,
-			 uint64_t o_optional)
-{
-	struct dl_opts *opts = &dl->opts;
-	uint64_t o_all = o_required | o_optional;
-	uint64_t o_found = 0;
-	int err;
-
-	if (o_required & DL_OPT_HANDLE && o_required & DL_OPT_HANDLEP) {
-		uint64_t handle_bit;
-
-		err = dl_argv_handle_both(dl, &opts->bus_name, &opts->dev_name,
-					  &opts->port_index, &handle_bit);
-		if (err)
-			return err;
-		o_found |= handle_bit;
-	} else if (o_required & DL_OPT_HANDLE) {
-		err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name);
-		if (err)
-			return err;
-		o_found |= DL_OPT_HANDLE;
-	} else if (o_required & DL_OPT_HANDLEP) {
-		err = dl_argv_handle_port(dl, &opts->bus_name, &opts->dev_name,
-					  &opts->port_index);
-		if (err)
-			return err;
-		o_found |= DL_OPT_HANDLEP;
-	} else if (o_required & DL_OPT_HANDLE_REGION) {
-		err = dl_argv_handle_region(dl, &opts->bus_name,
-					    &opts->dev_name,
-					    &opts->region_name);
-		if (err)
-			return err;
-		o_found |= DL_OPT_HANDLE_REGION;
-	}
-
-	while (dl_argc(dl)) {
-		if (dl_argv_match(dl, "type") &&
-		    (o_all & DL_OPT_PORT_TYPE)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = port_type_get(typestr, &opts->port_type);
-			if (err)
-				return err;
-			o_found |= DL_OPT_PORT_TYPE;
-		} else if (dl_argv_match(dl, "count") &&
-			   (o_all & DL_OPT_PORT_COUNT)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint32_t(dl, &opts->port_count);
-			if (err)
-				return err;
-			o_found |= DL_OPT_PORT_COUNT;
-		} else if (dl_argv_match(dl, "sb") &&
-			   (o_all & DL_OPT_SB)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint32_t(dl, &opts->sb_index);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB;
-		} else if (dl_argv_match(dl, "pool") &&
-			   (o_all & DL_OPT_SB_POOL)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint16_t(dl, &opts->sb_pool_index);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB_POOL;
-		} else if (dl_argv_match(dl, "size") &&
-			   (o_all & DL_OPT_SB_SIZE)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint32_t(dl, &opts->sb_pool_size);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB_SIZE;
-		} else if (dl_argv_match(dl, "type") &&
-			   (o_all & DL_OPT_SB_TYPE)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = pool_type_get(typestr, &opts->sb_pool_type);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB_TYPE;
-		} else if (dl_argv_match(dl, "thtype") &&
-			   (o_all & DL_OPT_SB_THTYPE)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = threshold_type_get(typestr,
-						 &opts->sb_pool_thtype);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB_THTYPE;
-		} else if (dl_argv_match(dl, "th") &&
-			   (o_all & DL_OPT_SB_TH)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint32_t(dl, &opts->sb_threshold);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB_TH;
-		} else if (dl_argv_match(dl, "tc") &&
-			   (o_all & DL_OPT_SB_TC)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint16_t(dl, &opts->sb_tc_index);
-			if (err)
-				return err;
-			o_found |= DL_OPT_SB_TC;
-		} else if (dl_argv_match(dl, "mode") &&
-			   (o_all & DL_OPT_ESWITCH_MODE)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = eswitch_mode_get(typestr, &opts->eswitch_mode);
-			if (err)
-				return err;
-			o_found |= DL_OPT_ESWITCH_MODE;
-		} else if (dl_argv_match(dl, "inline-mode") &&
-			   (o_all & DL_OPT_ESWITCH_INLINE_MODE)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = eswitch_inline_mode_get(
-				typestr, &opts->eswitch_inline_mode);
-			if (err)
-				return err;
-			o_found |= DL_OPT_ESWITCH_INLINE_MODE;
-		} else if (dl_argv_match(dl, "name") &&
-			   (o_all & DL_OPT_DPIPE_TABLE_NAME)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->dpipe_table_name);
-			if (err)
-				return err;
-			o_found |= DL_OPT_DPIPE_TABLE_NAME;
-		} else if (dl_argv_match(dl, "counters") &&
-			   (o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = dpipe_counters_enable_get(typestr,
-							&opts->dpipe_counters_enable);
-			if (err)
-				return err;
-			o_found |= DL_OPT_DPIPE_TABLE_COUNTERS;
-		} else if (dl_argv_match(dl, "encap") &&
-			   (o_all & DL_OPT_ESWITCH_ENCAP_MODE)) {
-			const char *typestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &typestr);
-			if (err)
-				return err;
-			err = eswitch_encap_mode_get(typestr,
-						     &opts->eswitch_encap_mode);
-			if (err)
-				return err;
-			o_found |= DL_OPT_ESWITCH_ENCAP_MODE;
-		} else if (dl_argv_match(dl, "path") &&
-			   (o_all & DL_OPT_RESOURCE_PATH)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->resource_path);
-			if (err)
-				return err;
-			o_found |= DL_OPT_RESOURCE_PATH;
-		} else if (dl_argv_match(dl, "size") &&
-			   (o_all & DL_OPT_RESOURCE_SIZE)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint32_t(dl, &opts->resource_size);
-			if (err)
-				return err;
-			o_found |= DL_OPT_RESOURCE_SIZE;
-		} else if (dl_argv_match(dl, "name") &&
-			   (o_all & DL_OPT_PARAM_NAME)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->param_name);
-			if (err)
-				return err;
-			o_found |= DL_OPT_PARAM_NAME;
-		} else if (dl_argv_match(dl, "value") &&
-			   (o_all & DL_OPT_PARAM_VALUE)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->param_value);
-			if (err)
-				return err;
-			o_found |= DL_OPT_PARAM_VALUE;
-		} else if (dl_argv_match(dl, "cmode") &&
-			   (o_all & DL_OPT_PARAM_CMODE)) {
-			const char *cmodestr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &cmodestr);
-			if (err)
-				return err;
-			err = param_cmode_get(cmodestr, &opts->cmode);
-			if (err)
-				return err;
-			o_found |= DL_OPT_PARAM_CMODE;
-		} else if (dl_argv_match(dl, "snapshot") &&
-			   (o_all & DL_OPT_REGION_SNAPSHOT_ID)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint32_t(dl, &opts->region_snapshot_id);
-			if (err)
-				return err;
-			o_found |= DL_OPT_REGION_SNAPSHOT_ID;
-		} else if (dl_argv_match(dl, "address") &&
-			   (o_all & DL_OPT_REGION_ADDRESS)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint64_t(dl, &opts->region_address);
-			if (err)
-				return err;
-			o_found |= DL_OPT_REGION_ADDRESS;
-		} else if (dl_argv_match(dl, "length") &&
-			   (o_all & DL_OPT_REGION_LENGTH)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint64_t(dl, &opts->region_length);
-			if (err)
-				return err;
-			o_found |= DL_OPT_REGION_LENGTH;
-		} else if (dl_argv_match(dl, "file") &&
-			   (o_all & DL_OPT_FLASH_FILE_NAME)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->flash_file_name);
-			if (err)
-				return err;
-			o_found |= DL_OPT_FLASH_FILE_NAME;
-		} else if (dl_argv_match(dl, "component") &&
-			   (o_all & DL_OPT_FLASH_COMPONENT)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->flash_component);
-			if (err)
-				return err;
-			o_found |= DL_OPT_FLASH_COMPONENT;
-		} else if (dl_argv_match(dl, "reporter") &&
-			   (o_all & DL_OPT_HEALTH_REPORTER_NAME)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->reporter_name);
-			if (err)
-				return err;
-			o_found |= DL_OPT_HEALTH_REPORTER_NAME;
-		} else if (dl_argv_match(dl, "grace_period") &&
-			   (o_all & DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD)) {
-			dl_arg_inc(dl);
-			err = dl_argv_uint64_t(dl,
-					       &opts->reporter_graceful_period);
-			if (err)
-				return err;
-			o_found |= DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD;
-		} else if (dl_argv_match(dl, "auto_recover") &&
-			(o_all & DL_OPT_HEALTH_REPORTER_AUTO_RECOVER)) {
-			dl_arg_inc(dl);
-			err = dl_argv_bool(dl, &opts->reporter_auto_recover);
-			if (err)
-				return err;
-			o_found |= DL_OPT_HEALTH_REPORTER_AUTO_RECOVER;
-		} else if (dl_argv_match(dl, "trap") &&
-			   (o_all & DL_OPT_TRAP_NAME)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->trap_name);
-			if (err)
-				return err;
-			o_found |= DL_OPT_TRAP_NAME;
-		} else if (dl_argv_match(dl, "group") &&
-			   (o_all & DL_OPT_TRAP_GROUP_NAME)) {
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &opts->trap_group_name);
-			if (err)
-				return err;
-			o_found |= DL_OPT_TRAP_GROUP_NAME;
-		} else if (dl_argv_match(dl, "action") &&
-			   (o_all & DL_OPT_TRAP_ACTION)) {
-			const char *actionstr;
-
-			dl_arg_inc(dl);
-			err = dl_argv_str(dl, &actionstr);
-			if (err)
-				return err;
-			err = trap_action_get(actionstr, &opts->trap_action);
-			if (err)
-				return err;
-			o_found |= DL_OPT_TRAP_ACTION;
-		} else {
-			pr_err("Unknown option \"%s\"\n", dl_argv(dl));
-			return -EINVAL;
-		}
-	}
-
-	opts->present = o_found;
-
-	if ((o_optional & DL_OPT_SB) && !(o_found & DL_OPT_SB)) {
-		opts->sb_index = 0;
-		opts->present |= DL_OPT_SB;
-	}
-
-	return dl_args_finding_required_validate(o_required, o_found);
-}
-
-static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
-{
-	struct dl_opts *opts = &dl->opts;
-
-	if (opts->present & DL_OPT_HANDLE) {
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, opts->bus_name);
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name);
-	} else if (opts->present & DL_OPT_HANDLEP) {
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, opts->bus_name);
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name);
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX,
-				 opts->port_index);
-	} else if (opts->present & DL_OPT_HANDLE_REGION) {
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, opts->bus_name);
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name);
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME,
-				  opts->region_name);
-	}
-	if (opts->present & DL_OPT_PORT_TYPE)
-		mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_TYPE,
-				 opts->port_type);
-	if (opts->present & DL_OPT_PORT_COUNT)
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_SPLIT_COUNT,
-				 opts->port_count);
-	if (opts->present & DL_OPT_SB)
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX,
-				 opts->sb_index);
-	if (opts->present & DL_OPT_SB_POOL)
-		mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX,
-				 opts->sb_pool_index);
-	if (opts->present & DL_OPT_SB_SIZE)
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_POOL_SIZE,
-				 opts->sb_pool_size);
-	if (opts->present & DL_OPT_SB_TYPE)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_TYPE,
-				opts->sb_pool_type);
-	if (opts->present & DL_OPT_SB_THTYPE)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE,
-				opts->sb_pool_thtype);
-	if (opts->present & DL_OPT_SB_TH)
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_THRESHOLD,
-				 opts->sb_threshold);
-	if (opts->present & DL_OPT_SB_TC)
-		mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_TC_INDEX,
-				 opts->sb_tc_index);
-	if (opts->present & DL_OPT_ESWITCH_MODE)
-		mnl_attr_put_u16(nlh, DEVLINK_ATTR_ESWITCH_MODE,
-				 opts->eswitch_mode);
-	if (opts->present & DL_OPT_ESWITCH_INLINE_MODE)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_INLINE_MODE,
-				opts->eswitch_inline_mode);
-	if (opts->present & DL_OPT_DPIPE_TABLE_NAME)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_DPIPE_TABLE_NAME,
-				  opts->dpipe_table_name);
-	if (opts->present & DL_OPT_DPIPE_TABLE_COUNTERS)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED,
-				opts->dpipe_counters_enable);
-	if (opts->present & DL_OPT_ESWITCH_ENCAP_MODE)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_ENCAP_MODE,
-				opts->eswitch_encap_mode);
-	if ((opts->present & DL_OPT_RESOURCE_PATH) && opts->resource_id_valid)
-		mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_ID,
-				 opts->resource_id);
-	if (opts->present & DL_OPT_RESOURCE_SIZE)
-		mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_SIZE,
-				 opts->resource_size);
-	if (opts->present & DL_OPT_PARAM_NAME)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME,
-				  opts->param_name);
-	if (opts->present & DL_OPT_PARAM_CMODE)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_VALUE_CMODE,
-				opts->cmode);
-	if (opts->present & DL_OPT_REGION_SNAPSHOT_ID)
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID,
-				 opts->region_snapshot_id);
-	if (opts->present & DL_OPT_REGION_ADDRESS)
-		mnl_attr_put_u64(nlh, DEVLINK_ATTR_REGION_CHUNK_ADDR,
-				 opts->region_address);
-	if (opts->present & DL_OPT_REGION_LENGTH)
-		mnl_attr_put_u64(nlh, DEVLINK_ATTR_REGION_CHUNK_LEN,
-				 opts->region_length);
-	if (opts->present & DL_OPT_FLASH_FILE_NAME)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME,
-				  opts->flash_file_name);
-	if (opts->present & DL_OPT_FLASH_COMPONENT)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_FLASH_UPDATE_COMPONENT,
-				  opts->flash_component);
-	if (opts->present & DL_OPT_HEALTH_REPORTER_NAME)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
-				  opts->reporter_name);
-	if (opts->present & DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD)
-		mnl_attr_put_u64(nlh,
-				 DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD,
-				 opts->reporter_graceful_period);
-	if (opts->present & DL_OPT_HEALTH_REPORTER_AUTO_RECOVER)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,
-				opts->reporter_auto_recover);
-	if (opts->present & DL_OPT_TRAP_NAME)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME,
-				  opts->trap_name);
-	if (opts->present & DL_OPT_TRAP_GROUP_NAME)
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_GROUP_NAME,
-				  opts->trap_group_name);
-	if (opts->present & DL_OPT_TRAP_ACTION)
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION,
-				opts->trap_action);
-
-}
-
-static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
-			     uint64_t o_required, uint64_t o_optional)
-{
-	int err;
-
-	err = dl_argv_parse(dl, o_required, o_optional);
-	if (err)
-		return err;
-	dl_opts_put(nlh, dl);
-	return 0;
-}
-
-static bool dl_dump_filter(struct dl *dl, struct nlattr **tb)
-{
-	struct dl_opts *opts = &dl->opts;
-	struct nlattr *attr_bus_name = tb[DEVLINK_ATTR_BUS_NAME];
-	struct nlattr *attr_dev_name = tb[DEVLINK_ATTR_DEV_NAME];
-	struct nlattr *attr_port_index = tb[DEVLINK_ATTR_PORT_INDEX];
-	struct nlattr *attr_sb_index = tb[DEVLINK_ATTR_SB_INDEX];
-
-	if (opts->present & DL_OPT_HANDLE &&
-	    attr_bus_name && attr_dev_name) {
-		const char *bus_name = mnl_attr_get_str(attr_bus_name);
-		const char *dev_name = mnl_attr_get_str(attr_dev_name);
-
-		if (strcmp(bus_name, opts->bus_name) != 0 ||
-		    strcmp(dev_name, opts->dev_name) != 0)
-			return false;
-	}
-	if (opts->present & DL_OPT_HANDLEP &&
-	    attr_bus_name && attr_dev_name && attr_port_index) {
-		const char *bus_name = mnl_attr_get_str(attr_bus_name);
-		const char *dev_name = mnl_attr_get_str(attr_dev_name);
-		uint32_t port_index = mnl_attr_get_u32(attr_port_index);
-
-		if (strcmp(bus_name, opts->bus_name) != 0 ||
-		    strcmp(dev_name, opts->dev_name) != 0 ||
-		    port_index != opts->port_index)
-			return false;
-	}
-	if (opts->present & DL_OPT_SB && attr_sb_index) {
-		uint32_t sb_index = mnl_attr_get_u32(attr_sb_index);
-
-		if (sb_index != opts->sb_index)
-			return false;
-	}
-	return true;
-}
-
-static void cmd_dev_help(void)
-{
-	pr_err("Usage: devlink dev show [ DEV ]\n");
-	pr_err("       devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n");
-	pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
-	pr_err("                               [ encap { disable | enable } ]\n");
-	pr_err("       devlink dev eswitch show DEV\n");
-	pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
-	pr_err("       devlink dev param show [DEV name PARAMETER]\n");
-	pr_err("       devlink dev reload DEV\n");
-	pr_err("       devlink dev info [ DEV ]\n");
-	pr_err("       devlink dev flash DEV file PATH [ component NAME ]\n");
-}
-
-static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name,
-				const char *dev_name)
-{
-	if (!dl->arr_last.present)
-		return false;
-	return strcmp(dl->arr_last.bus_name, bus_name) == 0 &&
-	       strcmp(dl->arr_last.dev_name, dev_name) == 0;
-}
-
-static void arr_last_handle_set(struct dl *dl, const char *bus_name,
-				const char *dev_name)
-{
-	dl->arr_last.present = true;
-	free(dl->arr_last.dev_name);
-	free(dl->arr_last.bus_name);
-	dl->arr_last.bus_name = strdup(bus_name);
-	dl->arr_last.dev_name = strdup(dev_name);
-}
-
-static bool should_arr_last_handle_start(struct dl *dl, const char *bus_name,
-					 const char *dev_name)
-{
-	return !cmp_arr_last_handle(dl, bus_name, dev_name);
-}
-
-static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name,
-				       const char *dev_name)
-{
-	return dl->arr_last.present &&
-	       !cmp_arr_last_handle(dl, bus_name, dev_name);
-}
-
-static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb,
-				  bool content, bool array)
-{
-	const char *bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
-	const char *dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
-	char buf[64];
-
-	sprintf(buf, "%s/%s", bus_name, dev_name);
-
-	if (dl->json_output) {
-		if (array) {
-			if (should_arr_last_handle_end(dl, bus_name, dev_name))
-				jsonw_end_array(dl->jw);
-			if (should_arr_last_handle_start(dl, bus_name,
-							 dev_name)) {
-				jsonw_name(dl->jw, buf);
-				jsonw_start_array(dl->jw);
-				jsonw_start_object(dl->jw);
-				arr_last_handle_set(dl, bus_name, dev_name);
-			} else {
-				jsonw_start_object(dl->jw);
-			}
-		} else {
-			jsonw_name(dl->jw, buf);
-			jsonw_start_object(dl->jw);
-		}
-	} else {
-		if (array) {
-			if (should_arr_last_handle_end(dl, bus_name, dev_name))
-				__pr_out_indent_dec();
-			if (should_arr_last_handle_start(dl, bus_name,
-							 dev_name)) {
-				pr_out("%s%s", buf, content ? ":" : "");
-				__pr_out_newline();
-				__pr_out_indent_inc();
-				arr_last_handle_set(dl, bus_name, dev_name);
-			}
-		} else {
-			pr_out("%s%s", buf, content ? ":" : "");
-		}
-	}
-}
-
-static void pr_out_handle_start_arr(struct dl *dl, struct nlattr **tb)
-{
-	__pr_out_handle_start(dl, tb, true, true);
-}
-
-static void pr_out_handle_end(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_end_object(dl->jw);
-	else
-		__pr_out_newline();
-}
-
-static void pr_out_handle(struct dl *dl, struct nlattr **tb)
-{
-	__pr_out_handle_start(dl, tb, false, false);
-	pr_out_handle_end(dl);
-}
-
-static bool cmp_arr_last_port_handle(struct dl *dl, const char *bus_name,
-				     const char *dev_name, uint32_t port_index)
-{
-	return cmp_arr_last_handle(dl, bus_name, dev_name) &&
-	       dl->arr_last.port_index == port_index;
-}
-
-static void arr_last_port_handle_set(struct dl *dl, const char *bus_name,
-				     const char *dev_name, uint32_t port_index)
-{
-	arr_last_handle_set(dl, bus_name, dev_name);
-	dl->arr_last.port_index = port_index;
-}
-
-static bool should_arr_last_port_handle_start(struct dl *dl,
-					      const char *bus_name,
-					      const char *dev_name,
-					      uint32_t port_index)
-{
-	return !cmp_arr_last_port_handle(dl, bus_name, dev_name, port_index);
-}
-
-static bool should_arr_last_port_handle_end(struct dl *dl,
-					    const char *bus_name,
-					    const char *dev_name,
-					    uint32_t port_index)
-{
-	return dl->arr_last.present &&
-	       !cmp_arr_last_port_handle(dl, bus_name, dev_name, port_index);
-}
-
-static void __pr_out_port_handle_start(struct dl *dl, const char *bus_name,
-				       const char *dev_name,
-				       uint32_t port_index, bool try_nice,
-				       bool array)
-{
-	static char buf[64];
-	char *ifname = NULL;
-
-	if (dl->no_nice_names || !try_nice ||
-	    ifname_map_rev_lookup(dl, bus_name, dev_name,
-				  port_index, &ifname) != 0)
-		sprintf(buf, "%s/%s/%d", bus_name, dev_name, port_index);
-	else
-		sprintf(buf, "%s", ifname);
-
-	if (dl->json_output) {
-		if (array) {
-			if (should_arr_last_port_handle_end(dl, bus_name,
-							    dev_name,
-							    port_index))
-				jsonw_end_array(dl->jw);
-			if (should_arr_last_port_handle_start(dl, bus_name,
-							      dev_name,
-							      port_index)) {
-				jsonw_name(dl->jw, buf);
-				jsonw_start_array(dl->jw);
-				jsonw_start_object(dl->jw);
-				arr_last_port_handle_set(dl, bus_name, dev_name,
-							 port_index);
-			} else {
-				jsonw_start_object(dl->jw);
-			}
-		} else {
-			jsonw_name(dl->jw, buf);
-			jsonw_start_object(dl->jw);
-		}
-	} else {
-		pr_out("%s:", buf);
-	}
-}
-
-static void pr_out_port_handle_start(struct dl *dl, struct nlattr **tb, bool try_nice)
-{
-	const char *bus_name;
-	const char *dev_name;
-	uint32_t port_index;
-
-	bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
-	dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
-	port_index = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
-	__pr_out_port_handle_start(dl, bus_name, dev_name, port_index, try_nice, false);
-}
-
-static void pr_out_port_handle_start_arr(struct dl *dl, struct nlattr **tb, bool try_nice)
-{
-	const char *bus_name;
-	const char *dev_name;
-	uint32_t port_index;
-
-	bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
-	dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
-	port_index = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
-	__pr_out_port_handle_start(dl, bus_name, dev_name, port_index, try_nice, true);
-}
-
-static void pr_out_port_handle_end(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_end_object(dl->jw);
-	else
-		pr_out("\n");
-}
-
-
-static void pr_out_str(struct dl *dl, const char *name, const char *val)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_string_field(dl->jw, name, val);
-	else
-		pr_out("%s %s", name, val);
-}
-
-static void pr_out_bool(struct dl *dl, const char *name, bool val)
-{
-	if (dl->json_output)
-		jsonw_bool_field(dl->jw, name, val);
-	else
-		pr_out_str(dl, name, val ? "true" : "false");
-}
-
-static void pr_out_uint(struct dl *dl, const char *name, unsigned int val)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_uint_field(dl->jw, name, val);
-	else
-		pr_out("%s %u", name, val);
-}
-
-static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
-{
-	__pr_out_indent_newline(dl);
-	if (val == (uint64_t) -1)
-		return pr_out_str(dl, name, "unlimited");
-
-	if (dl->json_output)
-		jsonw_u64_field(dl->jw, name, val);
-	else
-		pr_out("%s %"PRIu64, name, val);
-}
-
-static void pr_out_bool_value(struct dl *dl, bool value)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_bool(dl->jw, value);
-	else
-		pr_out("%s", value ? "true" : "false");
-}
-
-static void pr_out_uint_value(struct dl *dl, unsigned int value)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_uint(dl->jw, value);
-	else
-		pr_out("%u", value);
-}
-
-static void pr_out_uint64_value(struct dl *dl, uint64_t value)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_u64(dl->jw, value);
-	else
-		pr_out("%"PRIu64, value);
-}
-
-static bool is_binary_eol(int i)
-{
-	return !(i%16);
-}
-
-static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
-{
-	int i = 0;
-
-	while (i < len) {
-		if (dl->json_output)
-			jsonw_printf(dl->jw, "%d", data[i]);
-		else
-			pr_out("%02x ", data[i]);
-		i++;
-		if (!dl->json_output && is_binary_eol(i))
-			__pr_out_newline();
-	}
-	if (!dl->json_output && !is_binary_eol(i))
-		__pr_out_newline();
-}
-
-static void pr_out_str_value(struct dl *dl, const char *value)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_string(dl->jw, value);
-	else
-		pr_out("%s", value);
-}
-
-static void pr_out_name(struct dl *dl, const char *name)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output)
-		jsonw_name(dl->jw, name);
-	else
-		pr_out("%s:", name);
-}
-
-static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr)
-{
-	if (dl->json_output) {
-		jsonw_name(dl->jw, "address");
-		jsonw_uint(dl->jw, addr);
-		jsonw_name(dl->jw, "data");
-		jsonw_start_array(dl->jw);
-	}
-}
-
-static void pr_out_region_chunk_end(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_end_array(dl->jw);
-}
-
-static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
-				uint64_t addr)
-{
-	static uint64_t align_val;
-	uint32_t i = 0;
-
-	pr_out_region_chunk_start(dl, addr);
-	while (i < len) {
-		if (!dl->json_output)
-			if (!(align_val % 16))
-				pr_out("%s%016"PRIx64" ",
-				       align_val ? "\n" : "",
-				       addr);
-
-		align_val++;
-
-		if (dl->json_output)
-			jsonw_printf(dl->jw, "%d", data[i]);
-		else
-			pr_out("%02x ", data[i]);
-
-		addr++;
-		i++;
-	}
-	pr_out_region_chunk_end(dl);
-}
-
-static void pr_out_section_start(struct dl *dl, const char *name)
-{
-	if (dl->json_output) {
-		jsonw_start_object(dl->jw);
-		jsonw_name(dl->jw, name);
-		jsonw_start_object(dl->jw);
-	}
-}
-
-static void pr_out_section_end(struct dl *dl)
-{
-	if (dl->json_output) {
-		if (dl->arr_last.present)
-			jsonw_end_array(dl->jw);
-		jsonw_end_object(dl->jw);
-		jsonw_end_object(dl->jw);
-	}
-}
-
-static void pr_out_array_start(struct dl *dl, const char *name)
-{
-	if (dl->json_output) {
-		jsonw_name(dl->jw, name);
-		jsonw_start_array(dl->jw);
-	} else {
-		__pr_out_indent_inc();
-		__pr_out_newline();
-		pr_out("%s:", name);
-		__pr_out_indent_inc();
-		__pr_out_newline();
-	}
-}
-
-static void pr_out_array_end(struct dl *dl)
-{
-	if (dl->json_output) {
-		jsonw_end_array(dl->jw);
-	} else {
-		__pr_out_indent_dec();
-		__pr_out_indent_dec();
-	}
-}
-
-static void pr_out_object_start(struct dl *dl, const char *name)
-{
-	if (dl->json_output) {
-		jsonw_name(dl->jw, name);
-		jsonw_start_object(dl->jw);
-	} else {
-		__pr_out_indent_inc();
-		__pr_out_newline();
-		pr_out("%s:", name);
-		__pr_out_indent_inc();
-		__pr_out_newline();
-	}
-}
-
-static void pr_out_object_end(struct dl *dl)
-{
-	if (dl->json_output) {
-		jsonw_end_object(dl->jw);
-	} else {
-		__pr_out_indent_dec();
-		__pr_out_indent_dec();
-	}
-}
-
-static void pr_out_entry_start(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_start_object(dl->jw);
-}
-
-static void pr_out_entry_end(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_end_object(dl->jw);
-	else
-		__pr_out_newline();
-}
-
-static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats)
-{
-	struct nlattr *tb[DEVLINK_ATTR_STATS_MAX + 1] = {};
-	int err;
-
-	if (!dl->stats)
-		return;
-
-	err = mnl_attr_parse_nested(nla_stats, attr_stats_cb, tb);
-	if (err != MNL_CB_OK)
-		return;
-
-	pr_out_object_start(dl, "stats");
-	pr_out_object_start(dl, "rx");
-	if (tb[DEVLINK_ATTR_STATS_RX_BYTES])
-		pr_out_u64(dl, "bytes",
-			   mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_BYTES]));
-	if (tb[DEVLINK_ATTR_STATS_RX_PACKETS])
-		pr_out_u64(dl, "packets",
-			   mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_PACKETS]));
-	pr_out_object_end(dl);
-	pr_out_object_end(dl);
-}
-
-static const char *param_cmode_name(uint8_t cmode)
-{
-	switch (cmode) {
-	case DEVLINK_PARAM_CMODE_RUNTIME:
-		return PARAM_CMODE_RUNTIME_STR;
-	case DEVLINK_PARAM_CMODE_DRIVERINIT:
-		return PARAM_CMODE_DRIVERINIT_STR;
-	case DEVLINK_PARAM_CMODE_PERMANENT:
-		return PARAM_CMODE_PERMANENT_STR;
-	default: return "<unknown type>";
-	}
-}
-
-static const char *eswitch_mode_name(uint32_t mode)
-{
-	switch (mode) {
-	case DEVLINK_ESWITCH_MODE_LEGACY: return ESWITCH_MODE_LEGACY;
-	case DEVLINK_ESWITCH_MODE_SWITCHDEV: return ESWITCH_MODE_SWITCHDEV;
-	default: return "<unknown mode>";
-	}
-}
-
-static const char *eswitch_inline_mode_name(uint32_t mode)
-{
-	switch (mode) {
-	case DEVLINK_ESWITCH_INLINE_MODE_NONE:
-		return ESWITCH_INLINE_MODE_NONE;
-	case DEVLINK_ESWITCH_INLINE_MODE_LINK:
-		return ESWITCH_INLINE_MODE_LINK;
-	case DEVLINK_ESWITCH_INLINE_MODE_NETWORK:
-		return ESWITCH_INLINE_MODE_NETWORK;
-	case DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT:
-		return ESWITCH_INLINE_MODE_TRANSPORT;
-	default:
-		return "<unknown mode>";
-	}
-}
-
-static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
-{
-	__pr_out_handle_start(dl, tb, true, false);
-
-	if (tb[DEVLINK_ATTR_ESWITCH_MODE])
-		pr_out_str(dl, "mode",
-			   eswitch_mode_name(mnl_attr_get_u16(tb[DEVLINK_ATTR_ESWITCH_MODE])));
-
-	if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])
-		pr_out_str(dl, "inline-mode",
-			   eswitch_inline_mode_name(mnl_attr_get_u8(
-				   tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
-
-	if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) {
-		bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]);
-
-		pr_out_str(dl, "encap", encap_mode ? "enable" : "disable");
-	}
-
-	pr_out_handle_end(dl);
-}
-
-static int cmd_dev_eswitch_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-	pr_out_eswitch(dl, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_dev_eswitch_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_GET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
-	if (err)
-		return err;
-
-	pr_out_section_start(dl, "dev");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_eswitch_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static int cmd_dev_eswitch_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
-				DL_OPT_ESWITCH_MODE |
-				DL_OPT_ESWITCH_INLINE_MODE |
-				DL_OPT_ESWITCH_ENCAP_MODE);
-
-	if (err)
-		return err;
-
-	if (dl->opts.present == 1) {
-		pr_err("Need to set at least one option\n");
-		return -ENOENT;
-	}
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_dev_eswitch(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_dev_help();
-		return 0;
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_dev_eswitch_set(dl);
-	} else if (dl_argv_match(dl, "show")) {
-		dl_arg_inc(dl);
-		return cmd_dev_eswitch_show(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-struct param_val_conv {
-	const char *name;
-	const char *vstr;
-	uint32_t vuint;
-};
-
-static bool param_val_conv_exists(const struct param_val_conv *param_val_conv,
-				  uint32_t len, const char *name)
-{
-	uint32_t i;
-
-	for (i = 0; i < len; i++)
-		if (!strcmp(param_val_conv[i].name, name))
-			return true;
-
-	return false;
-}
-
-static int
-param_val_conv_uint_get(const struct param_val_conv *param_val_conv,
-			uint32_t len, const char *name, const char *vstr,
-			uint32_t *vuint)
-{
-	uint32_t i;
-
-	for (i = 0; i < len; i++)
-		if (!strcmp(param_val_conv[i].name, name) &&
-		    !strcmp(param_val_conv[i].vstr, vstr)) {
-			*vuint = param_val_conv[i].vuint;
-			return 0;
-		}
-
-	return -ENOENT;
-}
-
-static int
-param_val_conv_str_get(const struct param_val_conv *param_val_conv,
-		       uint32_t len, const char *name, uint32_t vuint,
-		       const char **vstr)
-{
-	uint32_t i;
-
-	for (i = 0; i < len; i++)
-		if (!strcmp(param_val_conv[i].name, name) &&
-		    param_val_conv[i].vuint == vuint) {
-			*vstr = param_val_conv[i].vstr;
-			return 0;
-		}
-
-	return -ENOENT;
-}
-
-static const struct param_val_conv param_val_conv[] = {
-	{
-		.name = "fw_load_policy",
-		.vstr = "driver",
-		.vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_DRIVER,
-	},
-	{
-		.name = "fw_load_policy",
-		.vstr = "flash",
-		.vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_FLASH,
-	},
-	{
-		.name = "reset_dev_on_drv_probe",
-		.vstr = "unknown",
-		.vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_UNKNOWN,
-	},
-	{
-		.name = "fw_load_policy",
-		.vstr = "unknown",
-		.vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_UNKNOWN,
-	},
-	{
-		.name = "reset_dev_on_drv_probe",
-		.vstr = "always",
-		.vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_ALWAYS,
-	},
-	{
-		.name = "reset_dev_on_drv_probe",
-		.vstr = "never",
-		.vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_NEVER,
-	},
-	{
-		.name = "reset_dev_on_drv_probe",
-		.vstr = "disk",
-		.vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_DISK,
-	},
-};
-
-#define PARAM_VAL_CONV_LEN ARRAY_SIZE(param_val_conv)
-
-static void pr_out_param_value(struct dl *dl, const char *nla_name,
-			       int nla_type, struct nlattr *nl)
-{
-	struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *val_attr;
-	const char *vstr;
-	bool conv_exists;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_value);
-	if (err != MNL_CB_OK)
-		return;
-
-	if (!nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE] ||
-	    (nla_type != MNL_TYPE_FLAG &&
-	     !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
-		return;
-
-	pr_out_str(dl, "cmode",
-		   param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
-	val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
-
-	conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
-					    nla_name);
-
-	switch (nla_type) {
-	case MNL_TYPE_U8:
-		if (conv_exists) {
-			err = param_val_conv_str_get(param_val_conv,
-						     PARAM_VAL_CONV_LEN,
-						     nla_name,
-						     mnl_attr_get_u8(val_attr),
-						     &vstr);
-			if (err)
-				return;
-			pr_out_str(dl, "value", vstr);
-		} else {
-			pr_out_uint(dl, "value", mnl_attr_get_u8(val_attr));
-		}
-		break;
-	case MNL_TYPE_U16:
-		if (conv_exists) {
-			err = param_val_conv_str_get(param_val_conv,
-						     PARAM_VAL_CONV_LEN,
-						     nla_name,
-						     mnl_attr_get_u16(val_attr),
-						     &vstr);
-			if (err)
-				return;
-			pr_out_str(dl, "value", vstr);
-		} else {
-			pr_out_uint(dl, "value", mnl_attr_get_u16(val_attr));
-		}
-		break;
-	case MNL_TYPE_U32:
-		if (conv_exists) {
-			err = param_val_conv_str_get(param_val_conv,
-						     PARAM_VAL_CONV_LEN,
-						     nla_name,
-						     mnl_attr_get_u32(val_attr),
-						     &vstr);
-			if (err)
-				return;
-			pr_out_str(dl, "value", vstr);
-		} else {
-			pr_out_uint(dl, "value", mnl_attr_get_u32(val_attr));
-		}
-		break;
-	case MNL_TYPE_STRING:
-		pr_out_str(dl, "value", mnl_attr_get_str(val_attr));
-		break;
-	case MNL_TYPE_FLAG:
-		pr_out_bool(dl, "value", val_attr ? true : false);
-		break;
-	}
-}
-
-static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
-{
-	struct nlattr *nla_param[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *param_value_attr;
-	const char *nla_name;
-	int nla_type;
-	int err;
-
-	err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_PARAM], attr_cb, nla_param);
-	if (err != MNL_CB_OK)
-		return;
-	if (!nla_param[DEVLINK_ATTR_PARAM_NAME] ||
-	    !nla_param[DEVLINK_ATTR_PARAM_TYPE] ||
-	    !nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST])
-		return;
-
-	if (array)
-		pr_out_handle_start_arr(dl, tb);
-	else
-		__pr_out_handle_start(dl, tb, true, false);
-
-	nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
-
-	nla_name = mnl_attr_get_str(nla_param[DEVLINK_ATTR_PARAM_NAME]);
-	pr_out_str(dl, "name", nla_name);
-
-	if (!nla_param[DEVLINK_ATTR_PARAM_GENERIC])
-		pr_out_str(dl, "type", "driver-specific");
-	else
-		pr_out_str(dl, "type", "generic");
-
-	pr_out_array_start(dl, "values");
-	mnl_attr_for_each_nested(param_value_attr,
-				 nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST]) {
-		pr_out_entry_start(dl);
-		pr_out_param_value(dl, nla_name, nla_type, param_value_attr);
-		pr_out_entry_end(dl);
-	}
-	pr_out_array_end(dl);
-	pr_out_handle_end(dl);
-}
-
-static int cmd_dev_param_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct dl *dl = data;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PARAM])
-		return MNL_CB_ERROR;
-	pr_out_param(dl, tb, true);
-	return MNL_CB_OK;
-}
-
-struct param_ctx {
-	struct dl *dl;
-	int nla_type;
-	union {
-		uint8_t vu8;
-		uint16_t vu16;
-		uint32_t vu32;
-		const char *vstr;
-		bool vbool;
-	} value;
-};
-
-static int cmd_dev_param_set_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *nla_param[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *param_value_attr;
-	enum devlink_param_cmode cmode;
-	struct param_ctx *ctx = data;
-	struct dl *dl = ctx->dl;
-	int nla_type;
-	int err;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PARAM])
-		return MNL_CB_ERROR;
-
-	err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_PARAM], attr_cb, nla_param);
-	if (err != MNL_CB_OK)
-		return MNL_CB_ERROR;
-
-	if (!nla_param[DEVLINK_ATTR_PARAM_TYPE] ||
-	    !nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST])
-		return MNL_CB_ERROR;
-
-	nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
-	mnl_attr_for_each_nested(param_value_attr,
-				 nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST]) {
-		struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
-		struct nlattr *val_attr;
-
-		err = mnl_attr_parse_nested(param_value_attr,
-					    attr_cb, nla_value);
-		if (err != MNL_CB_OK)
-			return MNL_CB_ERROR;
-
-		if (!nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE] ||
-		    (nla_type != MNL_TYPE_FLAG &&
-		     !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
-			return MNL_CB_ERROR;
-
-		cmode = mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE]);
-		if (cmode == dl->opts.cmode) {
-			val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
-			switch (nla_type) {
-			case MNL_TYPE_U8:
-				ctx->value.vu8 = mnl_attr_get_u8(val_attr);
-				break;
-			case MNL_TYPE_U16:
-				ctx->value.vu16 = mnl_attr_get_u16(val_attr);
-				break;
-			case MNL_TYPE_U32:
-				ctx->value.vu32 = mnl_attr_get_u32(val_attr);
-				break;
-			case MNL_TYPE_STRING:
-				ctx->value.vstr = mnl_attr_get_str(val_attr);
-				break;
-			case MNL_TYPE_FLAG:
-				ctx->value.vbool = val_attr ? true : false;
-				break;
-			}
-			break;
-		}
-	}
-	ctx->nla_type = nla_type;
-	return MNL_CB_OK;
-}
-
-static int cmd_dev_param_set(struct dl *dl)
-{
-	struct param_ctx ctx = {};
-	struct nlmsghdr *nlh;
-	bool conv_exists;
-	uint32_t val_u32;
-	uint16_t val_u16;
-	uint8_t val_u8;
-	bool val_bool;
-	int err;
-
-	err = dl_argv_parse(dl, DL_OPT_HANDLE |
-			    DL_OPT_PARAM_NAME |
-			    DL_OPT_PARAM_VALUE |
-			    DL_OPT_PARAM_CMODE, 0);
-	if (err)
-		return err;
-
-	/* Get value type */
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_GET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-	dl_opts_put(nlh, dl);
-
-	ctx.dl = dl;
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_param_set_cb, &ctx);
-	if (err)
-		return err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-	dl_opts_put(nlh, dl);
-
-	conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
-					    dl->opts.param_name);
-
-	mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_TYPE, ctx.nla_type);
-	switch (ctx.nla_type) {
-	case MNL_TYPE_U8:
-		if (conv_exists) {
-			err = param_val_conv_uint_get(param_val_conv,
-						      PARAM_VAL_CONV_LEN,
-						      dl->opts.param_name,
-						      dl->opts.param_value,
-						      &val_u32);
-			val_u8 = val_u32;
-		} else {
-			err = strtouint8_t(dl->opts.param_value, &val_u8);
-		}
-		if (err)
-			goto err_param_value_parse;
-		if (val_u8 == ctx.value.vu8)
-			return 0;
-		mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u8);
-		break;
-	case MNL_TYPE_U16:
-		if (conv_exists) {
-			err = param_val_conv_uint_get(param_val_conv,
-						      PARAM_VAL_CONV_LEN,
-						      dl->opts.param_name,
-						      dl->opts.param_value,
-						      &val_u32);
-			val_u16 = val_u32;
-		} else {
-			err = strtouint16_t(dl->opts.param_value, &val_u16);
-		}
-		if (err)
-			goto err_param_value_parse;
-		if (val_u16 == ctx.value.vu16)
-			return 0;
-		mnl_attr_put_u16(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u16);
-		break;
-	case MNL_TYPE_U32:
-		if (conv_exists)
-			err = param_val_conv_uint_get(param_val_conv,
-						      PARAM_VAL_CONV_LEN,
-						      dl->opts.param_name,
-						      dl->opts.param_value,
-						      &val_u32);
-		else
-			err = strtouint32_t(dl->opts.param_value, &val_u32);
-		if (err)
-			goto err_param_value_parse;
-		if (val_u32 == ctx.value.vu32)
-			return 0;
-		mnl_attr_put_u32(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u32);
-		break;
-	case MNL_TYPE_FLAG:
-		err = strtobool(dl->opts.param_value, &val_bool);
-		if (err)
-			goto err_param_value_parse;
-		if (val_bool == ctx.value.vbool)
-			return 0;
-		if (val_bool)
-			mnl_attr_put(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA,
-				     0, NULL);
-		break;
-	case MNL_TYPE_STRING:
-		mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA,
-				  dl->opts.param_value);
-		if (!strcmp(dl->opts.param_value, ctx.value.vstr))
-			return 0;
-		break;
-	default:
-		printf("Value type not supported\n");
-		return -ENOTSUP;
-	}
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-
-err_param_value_parse:
-	pr_err("Value \"%s\" is not a number or not within range\n",
-	       dl->opts.param_value);
-	return err;
-}
-
-static int cmd_dev_param_show(struct dl *dl)
-{
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	struct nlmsghdr *nlh;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE |
-					DL_OPT_PARAM_NAME, 0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "param");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_param_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static int cmd_dev_param(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_dev_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_dev_param_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_dev_param_set(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	uint8_t reload_failed = 0;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	if (tb[DEVLINK_ATTR_RELOAD_FAILED])
-		reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
-
-	if (reload_failed) {
-		__pr_out_handle_start(dl, tb, true, false);
-		pr_out_bool(dl, "reload_failed", true);
-		pr_out_handle_end(dl);
-	} else {
-		pr_out_handle(dl, tb);
-	}
-
-	return MNL_CB_OK;
-}
-
-static int cmd_dev_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "dev");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static void cmd_dev_reload_help(void)
-{
-	pr_err("Usage: devlink dev reload [ DEV ]\n");
-}
-
-static int cmd_dev_reload(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_dev_reload_help();
-		return 0;
-	}
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
-				   const char *name, int type)
-{
-	struct nlattr *version;
-
-	mnl_attr_for_each(version, nlh, sizeof(struct genlmsghdr)) {
-		struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-		const char *ver_value;
-		const char *ver_name;
-		int err;
-
-		if (mnl_attr_get_type(version) != type)
-			continue;
-
-		err = mnl_attr_parse_nested(version, attr_cb, tb);
-		if (err != MNL_CB_OK)
-			continue;
-
-		if (!tb[DEVLINK_ATTR_INFO_VERSION_NAME] ||
-		    !tb[DEVLINK_ATTR_INFO_VERSION_VALUE])
-			continue;
-
-		if (name) {
-			pr_out_object_start(dl, name);
-			name = NULL;
-		}
-
-		ver_name = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_NAME]);
-		ver_value = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_VALUE]);
-
-		pr_out_str(dl, ver_name, ver_value);
-		if (!dl->json_output)
-			__pr_out_newline();
-	}
-
-	if (!name)
-		pr_out_object_end(dl);
-}
-
-static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
-			struct nlattr **tb, bool has_versions)
-{
-	__pr_out_handle_start(dl, tb, true, false);
-
-	__pr_out_indent_inc();
-	if (tb[DEVLINK_ATTR_INFO_DRIVER_NAME]) {
-		struct nlattr *nla_drv = tb[DEVLINK_ATTR_INFO_DRIVER_NAME];
-
-		if (!dl->json_output)
-			__pr_out_newline();
-		pr_out_str(dl, "driver", mnl_attr_get_str(nla_drv));
-	}
-
-	if (tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER]) {
-		struct nlattr *nla_sn = tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER];
-
-		if (!dl->json_output)
-			__pr_out_newline();
-		pr_out_str(dl, "serial_number", mnl_attr_get_str(nla_sn));
-	}
-	__pr_out_indent_dec();
-
-	if (has_versions) {
-		pr_out_object_start(dl, "versions");
-
-		pr_out_versions_single(dl, nlh, "fixed",
-				       DEVLINK_ATTR_INFO_VERSION_FIXED);
-		pr_out_versions_single(dl, nlh, "running",
-				       DEVLINK_ATTR_INFO_VERSION_RUNNING);
-		pr_out_versions_single(dl, nlh, "stored",
-				       DEVLINK_ATTR_INFO_VERSION_STORED);
-
-		pr_out_object_end(dl);
-	}
-
-	pr_out_handle_end(dl);
-}
-
-static int cmd_versions_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	bool has_versions, has_info;
-	struct dl *dl = data;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	has_versions = tb[DEVLINK_ATTR_INFO_VERSION_FIXED] ||
-		tb[DEVLINK_ATTR_INFO_VERSION_RUNNING] ||
-		tb[DEVLINK_ATTR_INFO_VERSION_STORED];
-	has_info = tb[DEVLINK_ATTR_INFO_DRIVER_NAME] ||
-		tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER] ||
-		has_versions;
-
-	if (has_info)
-		pr_out_info(dl, nlh, tb, has_versions);
-
-	return MNL_CB_OK;
-}
-
-static void cmd_dev_info_help(void)
-{
-	pr_err("Usage: devlink dev info [ DEV ]\n");
-}
-
-static int cmd_dev_info(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argv_match(dl, "help")) {
-		cmd_dev_info_help();
-		return 0;
-	}
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_INFO_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "info");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_versions_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static void cmd_dev_flash_help(void)
-{
-	pr_err("Usage: devlink dev flash DEV file PATH [ component NAME ]\n");
-}
-
-
-struct cmd_dev_flash_status_ctx {
-	struct dl *dl;
-	char *last_msg;
-	char *last_component;
-	uint8_t not_first:1,
-		last_pc:1,
-		received_end:1,
-		flash_done:1;
-};
-
-static int nullstrcmp(const char *str1, const char *str2)
-{
-	if (str1 && str2)
-		return strcmp(str1, str2);
-	if (!str1 && !str2)
-		return 0;
-	return str1 ? 1 : -1;
-}
-
-static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct cmd_dev_flash_status_ctx *ctx = data;
-	struct dl_opts *opts = &ctx->dl->opts;
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	const char *component = NULL;
-	uint64_t done = 0, total = 0;
-	const char *msg = NULL;
-	const char *bus_name;
-	const char *dev_name;
-
-	if (genl->cmd != DEVLINK_CMD_FLASH_UPDATE_STATUS &&
-	    genl->cmd != DEVLINK_CMD_FLASH_UPDATE_END)
-		return MNL_CB_STOP;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-	bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
-	dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
-	if (strcmp(bus_name, opts->bus_name) ||
-	    strcmp(dev_name, opts->dev_name))
-		return MNL_CB_ERROR;
-
-	if (genl->cmd == DEVLINK_CMD_FLASH_UPDATE_END && ctx->not_first) {
-		pr_out("\n");
-		free(ctx->last_msg);
-		free(ctx->last_component);
-		ctx->received_end = 1;
-		return MNL_CB_STOP;
-	}
-
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
-		msg = mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]);
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
-		component = mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]);
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
-		done = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE]);
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL])
-		total = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL]);
-
-	if (!nullstrcmp(msg, ctx->last_msg) &&
-	    !nullstrcmp(component, ctx->last_component) &&
-	    ctx->last_pc && ctx->not_first) {
-		pr_out_tty("\b\b\b\b\b"); /* clean percentage */
-	} else {
-		if (ctx->not_first)
-			pr_out("\n");
-		if (component) {
-			pr_out("[%s] ", component);
-			free(ctx->last_component);
-			ctx->last_component = strdup(component);
-		}
-		if (msg) {
-			pr_out("%s", msg);
-			free(ctx->last_msg);
-			ctx->last_msg = strdup(msg);
-		}
-	}
-	if (total) {
-		pr_out_tty(" %3lu%%", (done * 100) / total);
-		ctx->last_pc = 1;
-	} else {
-		ctx->last_pc = 0;
-	}
-	fflush(stdout);
-	ctx->not_first = 1;
-
-	return MNL_CB_STOP;
-}
-
-static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
-				     struct mnlg_socket *nlg_ntf,
-				     int pipe_r)
-{
-	int nlfd = mnlg_socket_get_fd(nlg_ntf);
-	fd_set fds[3];
-	int fdmax;
-	int i;
-	int err;
-	int err2;
-
-	for (i = 0; i < 3; i++)
-		FD_ZERO(&fds[i]);
-	FD_SET(pipe_r, &fds[0]);
-	fdmax = pipe_r + 1;
-	FD_SET(nlfd, &fds[0]);
-	if (nlfd >= fdmax)
-		fdmax = nlfd + 1;
-
-	while (select(fdmax, &fds[0], &fds[1], &fds[2], NULL) < 0) {
-		if (errno == EINTR)
-			continue;
-		pr_err("select() failed\n");
-		return -errno;
-	}
-	if (FD_ISSET(nlfd, &fds[0])) {
-		err = _mnlg_socket_recv_run(nlg_ntf,
-					    cmd_dev_flash_status_cb, ctx);
-		if (err)
-			return err;
-	}
-	if (FD_ISSET(pipe_r, &fds[0])) {
-		err = read(pipe_r, &err2, sizeof(err2));
-		if (err == -1) {
-			pr_err("Failed to read pipe\n");
-			return -errno;
-		}
-		if (err2)
-			return err2;
-		ctx->flash_done = 1;
-	}
-	return 0;
-}
-
-
-static int cmd_dev_flash(struct dl *dl)
-{
-	struct cmd_dev_flash_status_ctx ctx = {.dl = dl,};
-	struct mnlg_socket *nlg_ntf;
-	struct nlmsghdr *nlh;
-	int pipe_r, pipe_w;
-	int pipe_fds[2];
-	pid_t pid;
-	int err;
-
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_dev_flash_help();
-		return 0;
-	}
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_FLASH_UPDATE,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_FLASH_FILE_NAME,
-				DL_OPT_FLASH_COMPONENT);
-	if (err)
-		return err;
-
-	nlg_ntf = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION);
-	if (!nlg_ntf)
-		return err;
-
-	err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
-	if (err)
-		return err;
-
-	err = pipe(pipe_fds);
-	if (err == -1)
-		return -errno;
-	pipe_r = pipe_fds[0];
-	pipe_w = pipe_fds[1];
-
-	pid = fork();
-	if (pid == -1) {
-		close(pipe_r);
-		close(pipe_w);
-		return -errno;
-	} else if (!pid) {
-		/* In child, just execute the flash and pass returned
-		 * value through pipe once it is done.
-		 */
-		close(pipe_r);
-		err = _mnlg_socket_send(dl->nlg, nlh);
-		write(pipe_w, &err, sizeof(err));
-		close(pipe_w);
-		exit(0);
-	}
-	close(pipe_w);
-
-	do {
-		err = cmd_dev_flash_fds_process(&ctx, nlg_ntf, pipe_r);
-		if (err)
-			goto out;
-	} while (!ctx.flash_done || (ctx.not_first && !ctx.received_end));
-
-	err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
-out:
-	close(pipe_r);
-	mnlg_socket_close(nlg_ntf);
-	return err;
-}
-
-static int cmd_dev(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_dev_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_dev_show(dl);
-	} else if (dl_argv_match(dl, "eswitch")) {
-		dl_arg_inc(dl);
-		return cmd_dev_eswitch(dl);
-	} else if (dl_argv_match(dl, "reload")) {
-		dl_arg_inc(dl);
-		return cmd_dev_reload(dl);
-	} else if (dl_argv_match(dl, "param")) {
-		dl_arg_inc(dl);
-		return cmd_dev_param(dl);
-	} else if (dl_argv_match(dl, "info")) {
-		dl_arg_inc(dl);
-		return cmd_dev_info(dl);
-	} else if (dl_argv_match(dl, "flash")) {
-		dl_arg_inc(dl);
-		return cmd_dev_flash(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void cmd_port_help(void)
-{
-	pr_err("Usage: devlink port show [ DEV/PORT_INDEX ]\n");
-	pr_err("       devlink port set DEV/PORT_INDEX [ type { eth | ib | auto} ]\n");
-	pr_err("       devlink port split DEV/PORT_INDEX count COUNT\n");
-	pr_err("       devlink port unsplit DEV/PORT_INDEX\n");
-}
-
-static const char *port_type_name(uint32_t type)
-{
-	switch (type) {
-	case DEVLINK_PORT_TYPE_NOTSET: return "notset";
-	case DEVLINK_PORT_TYPE_AUTO: return "auto";
-	case DEVLINK_PORT_TYPE_ETH: return "eth";
-	case DEVLINK_PORT_TYPE_IB: return "ib";
-	default: return "<unknown type>";
-	}
-}
-
-static const char *port_flavour_name(uint16_t flavour)
-{
-	switch (flavour) {
-	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
-		return "physical";
-	case DEVLINK_PORT_FLAVOUR_CPU:
-		return "cpu";
-	case DEVLINK_PORT_FLAVOUR_DSA:
-		return "dsa";
-	case DEVLINK_PORT_FLAVOUR_PCI_PF:
-		return "pcipf";
-	case DEVLINK_PORT_FLAVOUR_PCI_VF:
-		return "pcivf";
-	default:
-		return "<unknown flavour>";
-	}
-}
-
-static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb)
-{
-	uint16_t fn_num;
-
-	if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
-		fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
-		pr_out_uint(dl, "pfnum", fn_num);
-	}
-	if (tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]) {
-		fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
-		pr_out_uint(dl, "vfnum", fn_num);
-	}
-}
-
-static void pr_out_port(struct dl *dl, struct nlattr **tb)
-{
-	struct nlattr *pt_attr = tb[DEVLINK_ATTR_PORT_TYPE];
-	struct nlattr *dpt_attr = tb[DEVLINK_ATTR_PORT_DESIRED_TYPE];
-
-	pr_out_port_handle_start(dl, tb, false);
-	if (pt_attr) {
-		uint16_t port_type = mnl_attr_get_u16(pt_attr);
-
-		pr_out_str(dl, "type", port_type_name(port_type));
-		if (dpt_attr) {
-			uint16_t des_port_type = mnl_attr_get_u16(dpt_attr);
-
-			if (port_type != des_port_type)
-				pr_out_str(dl, "des_type",
-					   port_type_name(des_port_type));
-		}
-	}
-	if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
-		pr_out_str(dl, "netdev",
-			   mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
-	if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME])
-		pr_out_str(dl, "ibdev",
-			   mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
-	if (tb[DEVLINK_ATTR_PORT_FLAVOUR]) {
-		uint16_t port_flavour =
-				mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
-
-		pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
-
-		switch (port_flavour) {
-		case DEVLINK_PORT_FLAVOUR_PCI_PF:
-		case DEVLINK_PORT_FLAVOUR_PCI_VF:
-			pr_out_port_pfvf_num(dl, tb);
-			break;
-		default:
-			break;
-		}
-	}
-	if (tb[DEVLINK_ATTR_PORT_NUMBER]) {
-		uint32_t port_number;
-
-		port_number = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_NUMBER]);
-		pr_out_uint(dl, "port", port_number);
-	}
-	if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
-		pr_out_uint(dl, "split_group",
-			    mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_SPLIT_GROUP]));
-	pr_out_port_handle_end(dl);
-}
-
-static int cmd_port_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PORT_INDEX])
-		return MNL_CB_ERROR;
-	pr_out_port(dl, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_port_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "port");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static int cmd_port_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_TYPE, 0);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_port_split(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SPLIT,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_COUNT, 0);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_port_unsplit(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_UNSPLIT,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_port(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_port_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") ||  dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_port_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_port_set(dl);
-	} else if (dl_argv_match(dl, "split")) {
-		dl_arg_inc(dl);
-		return cmd_port_split(dl);
-	} else if (dl_argv_match(dl, "unsplit")) {
-		dl_arg_inc(dl);
-		return cmd_port_unsplit(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void cmd_sb_help(void)
-{
-	pr_err("Usage: devlink sb show [ DEV [ sb SB_INDEX ] ]\n");
-	pr_err("       devlink sb pool show [ DEV [ sb SB_INDEX ] pool POOL_INDEX ]\n");
-	pr_err("       devlink sb pool set DEV [ sb SB_INDEX ] pool POOL_INDEX\n");
-	pr_err("                           size POOL_SIZE thtype { static | dynamic }\n");
-	pr_err("       devlink sb port pool show [ DEV/PORT_INDEX [ sb SB_INDEX ]\n");
-	pr_err("                                   pool POOL_INDEX ]\n");
-	pr_err("       devlink sb port pool set DEV/PORT_INDEX [ sb SB_INDEX ]\n");
-	pr_err("                                pool POOL_INDEX th THRESHOLD\n");
-	pr_err("       devlink sb tc bind show [ DEV/PORT_INDEX [ sb SB_INDEX ] tc TC_INDEX\n");
-	pr_err("                                 type { ingress | egress } ]\n");
-	pr_err("       devlink sb tc bind set DEV/PORT_INDEX [ sb SB_INDEX ] tc TC_INDEX\n");
-	pr_err("                              type { ingress | egress } pool POOL_INDEX\n");
-	pr_err("                              th THRESHOLD\n");
-	pr_err("       devlink sb occupancy show { DEV | DEV/PORT_INDEX } [ sb SB_INDEX ]\n");
-	pr_err("       devlink sb occupancy snapshot DEV [ sb SB_INDEX ]\n");
-	pr_err("       devlink sb occupancy clearmax DEV [ sb SB_INDEX ]\n");
-}
-
-static void pr_out_sb(struct dl *dl, struct nlattr **tb)
-{
-	pr_out_handle_start_arr(dl, tb);
-	pr_out_uint(dl, "sb",
-		    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-	pr_out_uint(dl, "size",
-		    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_SIZE]));
-	pr_out_uint(dl, "ing_pools",
-		    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT]));
-	pr_out_uint(dl, "eg_pools",
-		    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT]));
-	pr_out_uint(dl, "ing_tcs",
-		    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_TC_COUNT]));
-	pr_out_uint(dl, "eg_tcs",
-		    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_TC_COUNT]));
-	pr_out_handle_end(dl);
-}
-
-static int cmd_sb_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_SB_INDEX] || !tb[DEVLINK_ATTR_SB_SIZE] ||
-	    !tb[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT] ||
-	    !tb[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT] ||
-	    !tb[DEVLINK_ATTR_SB_INGRESS_TC_COUNT] ||
-	    !tb[DEVLINK_ATTR_SB_EGRESS_TC_COUNT])
-		return MNL_CB_ERROR;
-	pr_out_sb(dl, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_sb_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "sb");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static const char *pool_type_name(uint8_t type)
-{
-	switch (type) {
-	case DEVLINK_SB_POOL_TYPE_INGRESS: return "ingress";
-	case DEVLINK_SB_POOL_TYPE_EGRESS: return "egress";
-	default: return "<unknown type>";
-	}
-}
-
-static const char *threshold_type_name(uint8_t type)
-{
-	switch (type) {
-	case DEVLINK_SB_THRESHOLD_TYPE_STATIC: return "static";
-	case DEVLINK_SB_THRESHOLD_TYPE_DYNAMIC: return "dynamic";
-	default: return "<unknown type>";
-	}
-}
-
-static void pr_out_sb_pool(struct dl *dl, struct nlattr **tb)
-{
-	pr_out_handle_start_arr(dl, tb);
-	pr_out_uint(dl, "sb",
-		    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-	pr_out_uint(dl, "pool",
-		    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-	pr_out_str(dl, "type",
-		   pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
-	pr_out_uint(dl, "size",
-		    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_SIZE]));
-	pr_out_str(dl, "thtype",
-		   threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
-	if (tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE])
-		pr_out_uint(dl, "cell_size",
-			    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE]));
-	pr_out_handle_end(dl);
-}
-
-static int cmd_sb_pool_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_SB_INDEX] || !tb[DEVLINK_ATTR_SB_POOL_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_POOL_TYPE] || !tb[DEVLINK_ATTR_SB_POOL_SIZE] ||
-	    !tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])
-		return MNL_CB_ERROR;
-	pr_out_sb_pool(dl, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_sb_pool_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_POOL_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SB_POOL,
-					DL_OPT_SB);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "pool");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_pool_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static int cmd_sb_pool_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_POOL_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SB_POOL |
-				DL_OPT_SB_SIZE | DL_OPT_SB_THTYPE, DL_OPT_SB);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_sb_pool(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_sb_pool_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_sb_pool_set(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void pr_out_sb_port_pool(struct dl *dl, struct nlattr **tb)
-{
-	pr_out_port_handle_start_arr(dl, tb, true);
-	pr_out_uint(dl, "sb",
-		    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-	pr_out_uint(dl, "pool",
-		    mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-	pr_out_uint(dl, "threshold",
-		    mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
-	pr_out_port_handle_end(dl);
-}
-
-static int cmd_sb_port_pool_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PORT_INDEX] || !tb[DEVLINK_ATTR_SB_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_POOL_INDEX] || !tb[DEVLINK_ATTR_SB_THRESHOLD])
-		return MNL_CB_ERROR;
-	pr_out_sb_port_pool(dl, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_sb_port_pool_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl,
-					DL_OPT_HANDLEP | DL_OPT_SB_POOL,
-					DL_OPT_SB);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "port_pool");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_port_pool_show_cb, dl);
-	pr_out_section_end(dl);
-	return 0;
-}
-
-static int cmd_sb_port_pool_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_POOL |
-				DL_OPT_SB_TH, DL_OPT_SB);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_sb_port_pool(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_sb_port_pool_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_sb_port_pool_set(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int cmd_sb_port(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "pool")) {
-		dl_arg_inc(dl);
-		return cmd_sb_port_pool(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void pr_out_sb_tc_bind(struct dl *dl, struct nlattr **tb)
-{
-	pr_out_port_handle_start_arr(dl, tb, true);
-	pr_out_uint(dl, "sb",
-	       mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-	pr_out_uint(dl, "tc",
-	       mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]));
-	pr_out_str(dl, "type",
-	       pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
-	pr_out_uint(dl, "pool",
-	       mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-	pr_out_uint(dl, "threshold",
-	       mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
-	pr_out_port_handle_end(dl);
-}
-
-static int cmd_sb_tc_bind_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PORT_INDEX] || !tb[DEVLINK_ATTR_SB_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_TC_INDEX] || !tb[DEVLINK_ATTR_SB_POOL_TYPE] ||
-	    !tb[DEVLINK_ATTR_SB_POOL_INDEX] || !tb[DEVLINK_ATTR_SB_THRESHOLD])
-		return MNL_CB_ERROR;
-	pr_out_sb_tc_bind(dl, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_sb_tc_bind_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_TC |
-					DL_OPT_SB_TYPE, DL_OPT_SB);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "tc_bind");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_tc_bind_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static int cmd_sb_tc_bind_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_TC |
-				DL_OPT_SB_TYPE | DL_OPT_SB_POOL | DL_OPT_SB_TH,
-				DL_OPT_SB);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_sb_tc_bind(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_sb_tc_bind_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_sb_tc_bind_set(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int cmd_sb_tc(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "bind")) {
-		dl_arg_inc(dl);
-		return cmd_sb_tc_bind(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-struct occ_item {
-	struct list_head list;
-	uint32_t index;
-	uint32_t cur;
-	uint32_t max;
-	uint32_t bound_pool_index;
-};
-
-struct occ_port {
-	struct list_head list;
-	char *bus_name;
-	char *dev_name;
-	uint32_t port_index;
-	uint32_t sb_index;
-	struct list_head pool_list;
-	struct list_head ing_tc_list;
-	struct list_head eg_tc_list;
-};
-
-struct occ_show {
-	struct dl *dl;
-	int err;
-	struct list_head port_list;
-};
-
-static struct occ_item *occ_item_alloc(void)
-{
-	return calloc(1, sizeof(struct occ_item));
-}
-
-static void occ_item_free(struct occ_item *occ_item)
-{
-	free(occ_item);
-}
-
-static struct occ_port *occ_port_alloc(uint32_t port_index)
-{
-	struct occ_port *occ_port;
-
-	occ_port = calloc(1, sizeof(*occ_port));
-	if (!occ_port)
-		return NULL;
-	occ_port->port_index = port_index;
-	INIT_LIST_HEAD(&occ_port->pool_list);
-	INIT_LIST_HEAD(&occ_port->ing_tc_list);
-	INIT_LIST_HEAD(&occ_port->eg_tc_list);
-	return occ_port;
-}
-
-static void occ_port_free(struct occ_port *occ_port)
-{
-	struct occ_item *occ_item, *tmp;
-
-	list_for_each_entry_safe(occ_item, tmp, &occ_port->pool_list, list)
-		occ_item_free(occ_item);
-	list_for_each_entry_safe(occ_item, tmp, &occ_port->ing_tc_list, list)
-		occ_item_free(occ_item);
-	list_for_each_entry_safe(occ_item, tmp, &occ_port->eg_tc_list, list)
-		occ_item_free(occ_item);
-}
-
-static struct occ_show *occ_show_alloc(struct dl *dl)
-{
-	struct occ_show *occ_show;
-
-	occ_show = calloc(1, sizeof(*occ_show));
-	if (!occ_show)
-		return NULL;
-	occ_show->dl = dl;
-	INIT_LIST_HEAD(&occ_show->port_list);
-	return occ_show;
-}
-
-static void occ_show_free(struct occ_show *occ_show)
-{
-	struct occ_port *occ_port, *tmp;
-
-	list_for_each_entry_safe(occ_port, tmp, &occ_show->port_list, list)
-		occ_port_free(occ_port);
-}
-
-static struct occ_port *occ_port_get(struct occ_show *occ_show,
-				     struct nlattr **tb)
-{
-	struct occ_port *occ_port;
-	uint32_t port_index;
-
-	port_index = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
-
-	list_for_each_entry_reverse(occ_port, &occ_show->port_list, list) {
-		if (occ_port->port_index == port_index)
-			return occ_port;
-	}
-	occ_port = occ_port_alloc(port_index);
-	if (!occ_port)
-		return NULL;
-	list_add_tail(&occ_port->list, &occ_show->port_list);
-	return occ_port;
-}
-
-static void pr_out_occ_show_item_list(const char *label, struct list_head *list,
-				      bool bound_pool)
-{
-	struct occ_item *occ_item;
-	int i = 1;
-
-	pr_out_sp(7, "  %s:", label);
-	list_for_each_entry(occ_item, list, list) {
-		if ((i - 1) % 4 == 0 && i != 1)
-			pr_out_sp(7, " ");
-		if (bound_pool)
-			pr_out_sp(7, "%2u(%u):", occ_item->index,
-				  occ_item->bound_pool_index);
-		else
-			pr_out_sp(7, "%2u:", occ_item->index);
-		pr_out_sp(21, "%10u/%u", occ_item->cur, occ_item->max);
-		if (i++ % 4 == 0)
-			pr_out("\n");
-	}
-	if ((i - 1) % 4 != 0)
-		pr_out("\n");
-}
-
-static void pr_out_json_occ_show_item_list(struct dl *dl, const char *label,
-					   struct list_head *list,
-					   bool bound_pool)
-{
-	struct occ_item *occ_item;
-	char buf[32];
-
-	jsonw_name(dl->jw, label);
-	jsonw_start_object(dl->jw);
-	list_for_each_entry(occ_item, list, list) {
-		sprintf(buf, "%u", occ_item->index);
-		jsonw_name(dl->jw, buf);
-		jsonw_start_object(dl->jw);
-		if (bound_pool)
-			jsonw_uint_field(dl->jw, "bound_pool",
-					 occ_item->bound_pool_index);
-		jsonw_uint_field(dl->jw, "current", occ_item->cur);
-		jsonw_uint_field(dl->jw, "max", occ_item->max);
-		jsonw_end_object(dl->jw);
-	}
-	jsonw_end_object(dl->jw);
-}
-
-static void pr_out_occ_show_port(struct dl *dl, struct occ_port *occ_port)
-{
-	if (dl->json_output) {
-		pr_out_json_occ_show_item_list(dl, "pool",
-					       &occ_port->pool_list, false);
-		pr_out_json_occ_show_item_list(dl, "itc",
-					       &occ_port->ing_tc_list, true);
-		pr_out_json_occ_show_item_list(dl, "etc",
-					       &occ_port->eg_tc_list, true);
-	} else {
-		pr_out("\n");
-		pr_out_occ_show_item_list("pool", &occ_port->pool_list, false);
-		pr_out_occ_show_item_list("itc", &occ_port->ing_tc_list, true);
-		pr_out_occ_show_item_list("etc", &occ_port->eg_tc_list, true);
-	}
-}
-
-static void pr_out_occ_show(struct occ_show *occ_show)
-{
-	struct dl *dl = occ_show->dl;
-	struct dl_opts *opts = &dl->opts;
-	struct occ_port *occ_port;
-
-	list_for_each_entry(occ_port, &occ_show->port_list, list) {
-		__pr_out_port_handle_start(dl, opts->bus_name, opts->dev_name,
-					   occ_port->port_index, true, false);
-		pr_out_occ_show_port(dl, occ_port);
-		pr_out_port_handle_end(dl);
-	}
-}
-
-static void cmd_sb_occ_port_pool_process(struct occ_show *occ_show,
-					 struct nlattr **tb)
-{
-	struct occ_port *occ_port;
-	struct occ_item *occ_item;
-
-	if (occ_show->err || !dl_dump_filter(occ_show->dl, tb))
-		return;
-
-	occ_port = occ_port_get(occ_show, tb);
-	if (!occ_port) {
-		occ_show->err = -ENOMEM;
-		return;
-	}
-
-	occ_item = occ_item_alloc();
-	if (!occ_item) {
-		occ_show->err = -ENOMEM;
-		return;
-	}
-	occ_item->index = mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]);
-	occ_item->cur = mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_OCC_CUR]);
-	occ_item->max = mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_OCC_MAX]);
-	list_add_tail(&occ_item->list, &occ_port->pool_list);
-}
-
-static int cmd_sb_occ_port_pool_process_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct occ_show *occ_show = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PORT_INDEX] || !tb[DEVLINK_ATTR_SB_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_POOL_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_OCC_CUR] || !tb[DEVLINK_ATTR_SB_OCC_MAX])
-		return MNL_CB_ERROR;
-	cmd_sb_occ_port_pool_process(occ_show, tb);
-	return MNL_CB_OK;
-}
-
-static void cmd_sb_occ_tc_pool_process(struct occ_show *occ_show,
-				       struct nlattr **tb)
-{
-	struct occ_port *occ_port;
-	struct occ_item *occ_item;
-	uint8_t pool_type;
-
-	if (occ_show->err || !dl_dump_filter(occ_show->dl, tb))
-		return;
-
-	occ_port = occ_port_get(occ_show, tb);
-	if (!occ_port) {
-		occ_show->err = -ENOMEM;
-		return;
-	}
-
-	occ_item = occ_item_alloc();
-	if (!occ_item) {
-		occ_show->err = -ENOMEM;
-		return;
-	}
-	occ_item->index = mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]);
-	occ_item->cur = mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_OCC_CUR]);
-	occ_item->max = mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_OCC_MAX]);
-	occ_item->bound_pool_index =
-			mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]);
-	pool_type = mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE]);
-	if (pool_type == DEVLINK_SB_POOL_TYPE_INGRESS)
-		list_add_tail(&occ_item->list, &occ_port->ing_tc_list);
-	else if (pool_type == DEVLINK_SB_POOL_TYPE_EGRESS)
-		list_add_tail(&occ_item->list, &occ_port->eg_tc_list);
-	else
-		occ_item_free(occ_item);
-}
-
-static int cmd_sb_occ_tc_pool_process_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct occ_show *occ_show = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_PORT_INDEX] || !tb[DEVLINK_ATTR_SB_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_TC_INDEX] || !tb[DEVLINK_ATTR_SB_POOL_TYPE] ||
-	    !tb[DEVLINK_ATTR_SB_POOL_INDEX] ||
-	    !tb[DEVLINK_ATTR_SB_OCC_CUR] || !tb[DEVLINK_ATTR_SB_OCC_MAX])
-		return MNL_CB_ERROR;
-	cmd_sb_occ_tc_pool_process(occ_show, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_sb_occ_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	struct occ_show *occ_show;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP;
-	int err;
-
-	err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HANDLEP, DL_OPT_SB);
-	if (err)
-		return err;
-
-	occ_show = occ_show_alloc(dl);
-	if (!occ_show)
-		return -ENOMEM;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags);
-
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh,
-				  cmd_sb_occ_port_pool_process_cb, occ_show);
-	if (err)
-		goto out;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags);
-
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh,
-				  cmd_sb_occ_tc_pool_process_cb, occ_show);
-	if (err)
-		goto out;
-
-	pr_out_section_start(dl, "occupancy");
-	pr_out_occ_show(occ_show);
-	pr_out_section_end(dl);
-
-out:
-	occ_show_free(occ_show);
-	return err;
-}
-
-static int cmd_sb_occ_snapshot(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_OCC_SNAPSHOT,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_sb_occ_clearmax(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_OCC_MAX_CLEAR,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_sb_occ(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list")) {
-		dl_arg_inc(dl);
-		return cmd_sb_occ_show(dl);
-	} else if (dl_argv_match(dl, "snapshot")) {
-		dl_arg_inc(dl);
-		return cmd_sb_occ_snapshot(dl);
-	} else if (dl_argv_match(dl, "clearmax")) {
-		dl_arg_inc(dl);
-		return cmd_sb_occ_clearmax(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int cmd_sb(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_sb_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_sb_show(dl);
-	} else if (dl_argv_match(dl, "pool")) {
-		dl_arg_inc(dl);
-		return cmd_sb_pool(dl);
-	} else if (dl_argv_match(dl, "port")) {
-		dl_arg_inc(dl);
-		return cmd_sb_port(dl);
-	} else if (dl_argv_match(dl, "tc")) {
-		dl_arg_inc(dl);
-		return cmd_sb_tc(dl);
-	} else if (dl_argv_match(dl, "occupancy")) {
-		dl_arg_inc(dl);
-		return cmd_sb_occ(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static const char *cmd_name(uint8_t cmd)
-{
-	switch (cmd) {
-	case DEVLINK_CMD_UNSPEC: return "unspec";
-	case DEVLINK_CMD_GET: return "get";
-	case DEVLINK_CMD_SET: return "set";
-	case DEVLINK_CMD_NEW: return "new";
-	case DEVLINK_CMD_DEL: return "del";
-	case DEVLINK_CMD_PORT_GET: return "get";
-	case DEVLINK_CMD_PORT_SET: return "set";
-	case DEVLINK_CMD_PORT_NEW: return "new";
-	case DEVLINK_CMD_PORT_DEL: return "del";
-	case DEVLINK_CMD_PARAM_GET: return "get";
-	case DEVLINK_CMD_PARAM_SET: return "set";
-	case DEVLINK_CMD_PARAM_NEW: return "new";
-	case DEVLINK_CMD_PARAM_DEL: return "del";
-	case DEVLINK_CMD_REGION_GET: return "get";
-	case DEVLINK_CMD_REGION_SET: return "set";
-	case DEVLINK_CMD_REGION_NEW: return "new";
-	case DEVLINK_CMD_REGION_DEL: return "del";
-	case DEVLINK_CMD_FLASH_UPDATE: return "begin";
-	case DEVLINK_CMD_FLASH_UPDATE_END: return "end";
-	case DEVLINK_CMD_FLASH_UPDATE_STATUS: return "status";
-	case DEVLINK_CMD_TRAP_GET: return "get";
-	case DEVLINK_CMD_TRAP_SET: return "set";
-	case DEVLINK_CMD_TRAP_NEW: return "new";
-	case DEVLINK_CMD_TRAP_DEL: return "del";
-	case DEVLINK_CMD_TRAP_GROUP_GET: return "get";
-	case DEVLINK_CMD_TRAP_GROUP_SET: return "set";
-	case DEVLINK_CMD_TRAP_GROUP_NEW: return "new";
-	case DEVLINK_CMD_TRAP_GROUP_DEL: return "del";
-	default: return "<unknown cmd>";
-	}
-}
-
-static const char *cmd_obj(uint8_t cmd)
-{
-	switch (cmd) {
-	case DEVLINK_CMD_UNSPEC: return "unspec";
-	case DEVLINK_CMD_GET:
-	case DEVLINK_CMD_SET:
-	case DEVLINK_CMD_NEW:
-	case DEVLINK_CMD_DEL:
-		return "dev";
-	case DEVLINK_CMD_PORT_GET:
-	case DEVLINK_CMD_PORT_SET:
-	case DEVLINK_CMD_PORT_NEW:
-	case DEVLINK_CMD_PORT_DEL:
-		return "port";
-	case DEVLINK_CMD_PARAM_GET:
-	case DEVLINK_CMD_PARAM_SET:
-	case DEVLINK_CMD_PARAM_NEW:
-	case DEVLINK_CMD_PARAM_DEL:
-		return "param";
-	case DEVLINK_CMD_REGION_GET:
-	case DEVLINK_CMD_REGION_SET:
-	case DEVLINK_CMD_REGION_NEW:
-	case DEVLINK_CMD_REGION_DEL:
-		return "region";
-	case DEVLINK_CMD_FLASH_UPDATE:
-	case DEVLINK_CMD_FLASH_UPDATE_END:
-	case DEVLINK_CMD_FLASH_UPDATE_STATUS:
-		return "flash";
-	case DEVLINK_CMD_TRAP_GET:
-	case DEVLINK_CMD_TRAP_SET:
-	case DEVLINK_CMD_TRAP_NEW:
-	case DEVLINK_CMD_TRAP_DEL:
-		return "trap";
-	case DEVLINK_CMD_TRAP_GROUP_GET:
-	case DEVLINK_CMD_TRAP_GROUP_SET:
-	case DEVLINK_CMD_TRAP_GROUP_NEW:
-	case DEVLINK_CMD_TRAP_GROUP_DEL:
-		return "trap-group";
-	default: return "<unknown obj>";
-	}
-}
-
-static void pr_out_mon_header(uint8_t cmd)
-{
-	pr_out("[%s,%s] ", cmd_obj(cmd), cmd_name(cmd));
-}
-
-static bool cmd_filter_check(struct dl *dl, uint8_t cmd)
-{
-	const char *obj = cmd_obj(cmd);
-	unsigned int index = 0;
-	const char *cur_obj;
-
-	if (dl_no_arg(dl))
-		return true;
-	while ((cur_obj = dl_argv_index(dl, index++))) {
-		if (strcmp(cur_obj, obj) == 0 || strcmp(cur_obj, "all") == 0)
-			return true;
-	}
-	return false;
-}
-
-static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
-{
-	__pr_out_handle_start(dl, tb, true, false);
-
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
-		pr_out_str(dl, "msg",
-			   mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
-
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
-		pr_out_str(dl, "component",
-			   mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
-
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
-		pr_out_u64(dl, "done",
-			   mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE]));
-
-	if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL])
-		pr_out_u64(dl, "total",
-			   mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL]));
-
-	pr_out_handle_end(dl);
-}
-
-static void pr_out_region(struct dl *dl, struct nlattr **tb);
-static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array);
-static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array);
-
-static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dl *dl = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	uint8_t cmd = genl->cmd;
-
-	if (!cmd_filter_check(dl, cmd))
-		return MNL_CB_OK;
-
-	switch (cmd) {
-	case DEVLINK_CMD_GET: /* fall through */
-	case DEVLINK_CMD_SET: /* fall through */
-	case DEVLINK_CMD_NEW: /* fall through */
-	case DEVLINK_CMD_DEL:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_handle(dl, tb);
-		break;
-	case DEVLINK_CMD_PORT_GET: /* fall through */
-	case DEVLINK_CMD_PORT_SET: /* fall through */
-	case DEVLINK_CMD_PORT_NEW: /* fall through */
-	case DEVLINK_CMD_PORT_DEL:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-		    !tb[DEVLINK_ATTR_PORT_INDEX])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_port(dl, tb);
-		break;
-	case DEVLINK_CMD_PARAM_GET: /* fall through */
-	case DEVLINK_CMD_PARAM_SET: /* fall through */
-	case DEVLINK_CMD_PARAM_NEW: /* fall through */
-	case DEVLINK_CMD_PARAM_DEL:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-		    !tb[DEVLINK_ATTR_PARAM])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_param(dl, tb, false);
-		break;
-	case DEVLINK_CMD_REGION_GET: /* fall through */
-	case DEVLINK_CMD_REGION_SET: /* fall through */
-	case DEVLINK_CMD_REGION_NEW: /* fall through */
-	case DEVLINK_CMD_REGION_DEL:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-		    !tb[DEVLINK_ATTR_REGION_NAME])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_region(dl, tb);
-		break;
-	case DEVLINK_CMD_FLASH_UPDATE: /* fall through */
-	case DEVLINK_CMD_FLASH_UPDATE_END: /* fall through */
-	case DEVLINK_CMD_FLASH_UPDATE_STATUS:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_flash_update(dl, tb);
-		break;
-	case DEVLINK_CMD_TRAP_GET: /* fall through */
-	case DEVLINK_CMD_TRAP_SET: /* fall through */
-	case DEVLINK_CMD_TRAP_NEW: /* fall through */
-	case DEVLINK_CMD_TRAP_DEL:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-		    !tb[DEVLINK_ATTR_TRAP_NAME] ||
-		    !tb[DEVLINK_ATTR_TRAP_TYPE] ||
-		    !tb[DEVLINK_ATTR_TRAP_ACTION] ||
-		    !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] ||
-		    !tb[DEVLINK_ATTR_TRAP_METADATA] ||
-		    !tb[DEVLINK_ATTR_STATS])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_trap(dl, tb, false);
-		break;
-	case DEVLINK_CMD_TRAP_GROUP_GET: /* fall through */
-	case DEVLINK_CMD_TRAP_GROUP_SET: /* fall through */
-	case DEVLINK_CMD_TRAP_GROUP_NEW: /* fall through */
-	case DEVLINK_CMD_TRAP_GROUP_DEL:
-		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-		    !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] ||
-		    !tb[DEVLINK_ATTR_STATS])
-			return MNL_CB_ERROR;
-		pr_out_mon_header(genl->cmd);
-		pr_out_trap_group(dl, tb, false);
-		break;
-	}
-	return MNL_CB_OK;
-}
-
-static int cmd_mon_show(struct dl *dl)
-{
-	int err;
-	unsigned int index = 0;
-	const char *cur_obj;
-
-	while ((cur_obj = dl_argv_index(dl, index++))) {
-		if (strcmp(cur_obj, "all") != 0 &&
-		    strcmp(cur_obj, "dev") != 0 &&
-		    strcmp(cur_obj, "port") != 0 &&
-		    strcmp(cur_obj, "trap") != 0 &&
-		    strcmp(cur_obj, "trap-group") != 0) {
-			pr_err("Unknown object \"%s\"\n", cur_obj);
-			return -EINVAL;
-		}
-	}
-	err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME);
-	if (err)
-		return err;
-	err = _mnlg_socket_recv_run(dl->nlg, cmd_mon_show_cb, dl);
-	if (err)
-		return err;
-	return 0;
-}
-
-static void cmd_mon_help(void)
-{
-	pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n"
-	       "where  OBJECT-LIST := { dev | port | trap | trap-group }\n");
-}
-
-static int cmd_mon(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_mon_help();
-		return 0;
-	}
-	return cmd_mon_show(dl);
-}
-
-struct dpipe_field {
-	char *name;
-	unsigned int id;
-	unsigned int bitwidth;
-	enum devlink_dpipe_field_mapping_type mapping_type;
-};
-
-struct dpipe_header {
-	struct list_head list;
-	char *name;
-	unsigned int id;
-	struct dpipe_field *fields;
-	unsigned int fields_count;
-};
-
-struct dpipe_table {
-	struct list_head list;
-	char *name;
-	unsigned int resource_id;
-	bool resource_valid;
-};
-
-struct dpipe_tables {
-	struct list_head table_list;
-};
-
-struct resource {
-	char *name;
-	uint64_t size;
-	uint64_t size_new;
-	uint64_t size_min;
-	uint64_t size_max;
-	uint64_t size_gran;
-	enum devlink_resource_unit unit;
-	bool size_valid;
-	uint64_t size_occ;
-	bool occ_valid;
-	uint64_t id;
-	struct list_head list;
-	struct list_head resource_list;
-	struct resource *parent;
-};
-
-struct resources {
-	struct list_head resource_list;
-};
-
-struct resource_ctx {
-	struct dl *dl;
-	int err;
-	struct resources *resources;
-	struct dpipe_tables *tables;
-	bool print_resources;
-	bool pending_change;
-};
-
-static struct resource *resource_alloc(void)
-{
-	struct resource *resource;
-
-	resource = calloc(1, sizeof(struct resource));
-	if (!resource)
-		return NULL;
-	INIT_LIST_HEAD(&resource->resource_list);
-	return resource;
-}
-
-static void resource_free(struct resource *resource)
-{
-	struct resource *child_resource, *tmp;
-
-	list_for_each_entry_safe(child_resource, tmp, &resource->resource_list,
-				 list) {
-		free(child_resource->name);
-		resource_free(child_resource);
-	}
-	free(resource);
-}
-
-static struct resources *resources_alloc(void)
-{
-	struct resources *resources;
-
-	resources = calloc(1, sizeof(struct resources));
-	if (!resources)
-		return NULL;
-	INIT_LIST_HEAD(&resources->resource_list);
-	return resources;
-}
-
-static void resources_free(struct resources *resources)
-{
-	struct resource *resource, *tmp;
-
-	list_for_each_entry_safe(resource, tmp, &resources->resource_list, list)
-		resource_free(resource);
-}
-
-static int resource_ctx_init(struct resource_ctx *ctx, struct dl *dl)
-{
-	ctx->resources = resources_alloc();
-	if (!ctx->resources)
-		return -ENOMEM;
-	ctx->dl = dl;
-	return 0;
-}
-
-static void resource_ctx_fini(struct resource_ctx *ctx)
-{
-	resources_free(ctx->resources);
-}
-
-struct dpipe_ctx {
-	struct dl *dl;
-	int err;
-	struct list_head global_headers;
-	struct list_head local_headers;
-	struct dpipe_tables *tables;
-	struct resources *resources;
-	bool print_headers;
-	bool print_tables;
-};
-
-static struct dpipe_header *dpipe_header_alloc(unsigned int fields_count)
-{
-	struct dpipe_header *header;
-
-	header = calloc(1, sizeof(struct dpipe_header));
-	if (!header)
-		return NULL;
-	header->fields = calloc(fields_count, sizeof(struct dpipe_field));
-	if (!header->fields)
-		goto err_fields_alloc;
-	header->fields_count = fields_count;
-	return header;
-
-err_fields_alloc:
-	free(header);
-	return NULL;
-}
-
-static void dpipe_header_free(struct dpipe_header *header)
-{
-	free(header->fields);
-	free(header);
-}
-
-static void dpipe_header_clear(struct dpipe_header *header)
-{
-	struct dpipe_field *field;
-	int i;
-
-	for (i = 0; i < header->fields_count; i++) {
-		field = &header->fields[i];
-		free(field->name);
-	}
-	free(header->name);
-}
-
-static void dpipe_header_add(struct dpipe_ctx *ctx,
-			     struct dpipe_header *header, bool global)
-{
-	if (global)
-		list_add(&header->list, &ctx->global_headers);
-	else
-		list_add(&header->list, &ctx->local_headers);
-}
-
-static void dpipe_header_del(struct dpipe_header *header)
-{
-	list_del(&header->list);
-}
-
-static struct dpipe_table *dpipe_table_alloc(void)
-{
-	return calloc(1, sizeof(struct dpipe_table));
-}
-
-static void dpipe_table_free(struct dpipe_table *table)
-{
-	free(table);
-}
-
-static struct dpipe_tables *dpipe_tables_alloc(void)
-{
-	struct dpipe_tables *tables;
-
-	tables = calloc(1, sizeof(struct dpipe_tables));
-	if (!tables)
-		return NULL;
-	INIT_LIST_HEAD(&tables->table_list);
-	return tables;
-}
-
-static void dpipe_tables_free(struct dpipe_tables *tables)
-{
-	struct dpipe_table *table, *tmp;
-
-	list_for_each_entry_safe(table, tmp, &tables->table_list, list)
-		dpipe_table_free(table);
-	free(tables);
-}
-
-static int dpipe_ctx_init(struct dpipe_ctx *ctx, struct dl *dl)
-{
-	ctx->tables = dpipe_tables_alloc();
-	if (!ctx->tables)
-		return -ENOMEM;
-
-	ctx->dl = dl;
-	INIT_LIST_HEAD(&ctx->global_headers);
-	INIT_LIST_HEAD(&ctx->local_headers);
-	return 0;
-}
-
-static void dpipe_ctx_fini(struct dpipe_ctx *ctx)
-{
-	struct dpipe_header *header, *tmp;
-
-	list_for_each_entry_safe(header, tmp, &ctx->global_headers,
-				 list) {
-		dpipe_header_del(header);
-		dpipe_header_clear(header);
-		dpipe_header_free(header);
-	}
-	list_for_each_entry_safe(header, tmp, &ctx->local_headers,
-				 list) {
-		dpipe_header_del(header);
-		dpipe_header_clear(header);
-		dpipe_header_free(header);
-	}
-	dpipe_tables_free(ctx->tables);
-}
-
-static const char *dpipe_header_id2s(struct dpipe_ctx *ctx,
-				     uint32_t header_id, bool global)
-{
-	struct list_head *header_list;
-	struct dpipe_header *header;
-
-	if (global)
-		header_list = &ctx->global_headers;
-	else
-		header_list = &ctx->local_headers;
-	list_for_each_entry(header, header_list, list) {
-		if (header->id != header_id)
-			continue;
-		return header->name;
-	}
-	return NULL;
-}
-
-static const char *dpipe_field_id2s(struct dpipe_ctx *ctx,
-				    uint32_t header_id,
-				    uint32_t field_id, bool global)
-{
-	struct list_head *header_list;
-	struct dpipe_header *header;
-
-	if (global)
-		header_list = &ctx->global_headers;
-	else
-		header_list = &ctx->local_headers;
-	list_for_each_entry(header, header_list, list) {
-		if (header->id != header_id)
-			continue;
-		return header->fields[field_id].name;
-	}
-	return NULL;
-}
-
-static const char *
-dpipe_field_mapping_e2s(enum devlink_dpipe_field_mapping_type mapping_type)
-{
-	switch (mapping_type) {
-	case DEVLINK_DPIPE_FIELD_MAPPING_TYPE_NONE:
-		return NULL;
-	case DEVLINK_DPIPE_FIELD_MAPPING_TYPE_IFINDEX:
-		return "ifindex";
-	default:
-		return "<unknown>";
-	}
-}
-
-static const char *
-dpipe_mapping_get(struct dpipe_ctx *ctx, uint32_t header_id,
-		  uint32_t field_id, bool global)
-{
-	enum devlink_dpipe_field_mapping_type mapping_type;
-	struct list_head *header_list;
-	struct dpipe_header *header;
-
-	if (global)
-		header_list = &ctx->global_headers;
-	else
-		header_list = &ctx->local_headers;
-	list_for_each_entry(header, header_list, list) {
-		if (header->id != header_id)
-			continue;
-		mapping_type = header->fields[field_id].mapping_type;
-		return dpipe_field_mapping_e2s(mapping_type);
-	}
-	return NULL;
-}
-
-static void pr_out_dpipe_fields(struct dpipe_ctx *ctx,
-				struct dpipe_field *fields,
-				unsigned int field_count)
-{
-	struct dpipe_field *field;
-	int i;
-
-	for (i = 0; i < field_count; i++) {
-		field = &fields[i];
-		pr_out_entry_start(ctx->dl);
-		pr_out_str(ctx->dl, "name", field->name);
-		if (ctx->dl->verbose)
-			pr_out_uint(ctx->dl, "id", field->id);
-		pr_out_uint(ctx->dl, "bitwidth", field->bitwidth);
-		if (field->mapping_type)
-			pr_out_str(ctx->dl, "mapping_type",
-				   dpipe_field_mapping_e2s(field->mapping_type));
-		pr_out_entry_end(ctx->dl);
-	}
-}
-
-static void
-pr_out_dpipe_header(struct dpipe_ctx *ctx, struct nlattr **tb,
-		    struct dpipe_header *header, bool global)
-{
-	pr_out_handle_start_arr(ctx->dl, tb);
-	pr_out_str(ctx->dl, "name", header->name);
-	if (ctx->dl->verbose) {
-		pr_out_uint(ctx->dl, "id", header->id);
-		pr_out_str(ctx->dl, "global",
-			   global ? "true" : "false");
-	}
-	pr_out_array_start(ctx->dl, "field");
-	pr_out_dpipe_fields(ctx, header->fields,
-			    header->fields_count);
-	pr_out_array_end(ctx->dl);
-	pr_out_handle_end(ctx->dl);
-}
-
-static void pr_out_dpipe_headers(struct dpipe_ctx *ctx,
-				 struct nlattr **tb)
-{
-	struct dpipe_header *header;
-
-	list_for_each_entry(header, &ctx->local_headers, list)
-		pr_out_dpipe_header(ctx, tb, header, false);
-
-	list_for_each_entry(header, &ctx->global_headers, list)
-		pr_out_dpipe_header(ctx, tb, header, true);
-}
-
-static int dpipe_header_field_get(struct nlattr *nl, struct dpipe_field *field)
-{
-	struct nlattr *nla_field[DEVLINK_ATTR_MAX + 1] = {};
-	const char *name;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_field);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-	if (!nla_field[DEVLINK_ATTR_DPIPE_FIELD_ID] ||
-	    !nla_field[DEVLINK_ATTR_DPIPE_FIELD_NAME] ||
-	    !nla_field[DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH] ||
-	    !nla_field[DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE])
-		return -EINVAL;
-
-	name = mnl_attr_get_str(nla_field[DEVLINK_ATTR_DPIPE_FIELD_NAME]);
-	field->id = mnl_attr_get_u32(nla_field[DEVLINK_ATTR_DPIPE_FIELD_ID]);
-	field->bitwidth = mnl_attr_get_u32(nla_field[DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH]);
-	field->name = strdup(name);
-	if (!field->name)
-		return -ENOMEM;
-	field->mapping_type = mnl_attr_get_u32(nla_field[DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE]);
-	return 0;
-}
-
-static int dpipe_header_fields_get(struct nlattr *nla_fields,
-				   struct dpipe_field *fields)
-{
-	struct nlattr *nla_field;
-	int count = 0;
-	int err;
-
-	mnl_attr_for_each_nested(nla_field, nla_fields) {
-		err = dpipe_header_field_get(nla_field, &fields[count]);
-		if (err)
-			return err;
-		count++;
-	}
-	return 0;
-}
-
-static unsigned int dpipe_header_field_count_get(struct nlattr *nla_fields)
-{
-	struct nlattr *nla_field;
-	unsigned int count = 0;
-
-	mnl_attr_for_each_nested(nla_field, nla_fields)
-		count++;
-	return count;
-}
-
-static int dpipe_header_get(struct dpipe_ctx *ctx, struct nlattr *nl)
-{
-	struct nlattr *nla_header[DEVLINK_ATTR_MAX + 1] = {};
-	struct dpipe_header *header;
-	unsigned int fields_count;
-	const char *header_name;
-	bool global;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_header);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_header[DEVLINK_ATTR_DPIPE_HEADER_NAME] ||
-	    !nla_header[DEVLINK_ATTR_DPIPE_HEADER_ID] ||
-	    !nla_header[DEVLINK_ATTR_DPIPE_HEADER_FIELDS])
-		return -EINVAL;
-
-	fields_count = dpipe_header_field_count_get(nla_header[DEVLINK_ATTR_DPIPE_HEADER_FIELDS]);
-	header = dpipe_header_alloc(fields_count);
-	if (!header)
-		return -ENOMEM;
-
-	header_name = mnl_attr_get_str(nla_header[DEVLINK_ATTR_DPIPE_HEADER_NAME]);
-	header->name = strdup(header_name);
-	header->id = mnl_attr_get_u32(nla_header[DEVLINK_ATTR_DPIPE_HEADER_ID]);
-	header->fields_count = fields_count;
-	global = !!mnl_attr_get_u8(nla_header[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
-
-	err = dpipe_header_fields_get(nla_header[DEVLINK_ATTR_DPIPE_HEADER_FIELDS],
-				      header->fields);
-	if (err)
-		goto err_field_get;
-	dpipe_header_add(ctx, header, global);
-	return 0;
-
-err_field_get:
-	dpipe_header_free(header);
-	return err;
-}
-
-static int dpipe_headers_get(struct dpipe_ctx *ctx, struct nlattr **tb)
-{
-	struct nlattr *nla_headers = tb[DEVLINK_ATTR_DPIPE_HEADERS];
-	struct nlattr *nla_header;
-	int err;
-
-	mnl_attr_for_each_nested(nla_header, nla_headers) {
-		err = dpipe_header_get(ctx, nla_header);
-		if (err)
-			return err;
-	}
-	return 0;
-}
-
-static int cmd_dpipe_header_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dpipe_ctx *ctx = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	int err;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_DPIPE_HEADERS])
-		return MNL_CB_ERROR;
-	err = dpipe_headers_get(ctx, tb);
-	if (err) {
-		ctx->err = err;
-		return MNL_CB_ERROR;
-	}
-
-	if (ctx->print_headers)
-		pr_out_dpipe_headers(ctx, tb);
-	return MNL_CB_OK;
-}
-
-static int cmd_dpipe_headers_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	struct dpipe_ctx ctx = {};
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
-	if (err)
-		return err;
-
-	err = dpipe_ctx_init(&ctx, dl);
-	if (err)
-		return err;
-
-	ctx.print_headers = true;
-
-	pr_out_section_start(dl, "header");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
-	if (err)
-		pr_err("error get headers %s\n", strerror(ctx.err));
-	pr_out_section_end(dl);
-
-	dpipe_ctx_fini(&ctx);
-	return err;
-}
-
-static void cmd_dpipe_header_help(void)
-{
-	pr_err("Usage: devlink dpipe headers show DEV\n");
-}
-
-static int cmd_dpipe_header(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_dpipe_header_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe_headers_show(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static const char
-*dpipe_action_type_e2s(enum devlink_dpipe_action_type action_type)
-{
-	switch (action_type) {
-	case DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY:
-		return "field_modify";
-	default:
-		return "<unknown>";
-	}
-}
-
-struct dpipe_op_info {
-	uint32_t header_id;
-	uint32_t field_id;
-	bool header_global;
-};
-
-struct dpipe_action {
-	struct dpipe_op_info info;
-	uint32_t type;
-};
-
-static void pr_out_dpipe_action(struct dpipe_action *action,
-				struct dpipe_ctx *ctx)
-{
-	struct dpipe_op_info *op_info = &action->info;
-	const char *mapping;
-
-	pr_out_str(ctx->dl, "type",
-		   dpipe_action_type_e2s(action->type));
-	pr_out_str(ctx->dl, "header",
-		   dpipe_header_id2s(ctx, op_info->header_id,
-				     op_info->header_global));
-	pr_out_str(ctx->dl, "field",
-		   dpipe_field_id2s(ctx, op_info->header_id,
-				    op_info->field_id,
-				    op_info->header_global));
-	mapping = dpipe_mapping_get(ctx, op_info->header_id,
-				    op_info->field_id,
-				    op_info->header_global);
-	if (mapping)
-		pr_out_str(ctx->dl, "mapping", mapping);
-}
-
-static int dpipe_action_parse(struct dpipe_action *action, struct nlattr *nl)
-{
-	struct nlattr *nla_action[DEVLINK_ATTR_MAX + 1] = {};
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_action);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_action[DEVLINK_ATTR_DPIPE_ACTION_TYPE] ||
-	    !nla_action[DEVLINK_ATTR_DPIPE_HEADER_INDEX] ||
-	    !nla_action[DEVLINK_ATTR_DPIPE_HEADER_ID] ||
-	    !nla_action[DEVLINK_ATTR_DPIPE_FIELD_ID]) {
-		return -EINVAL;
-	}
-
-	action->type = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_ACTION_TYPE]);
-	action->info.header_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_HEADER_ID]);
-	action->info.field_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_FIELD_ID]);
-	action->info.header_global = !!mnl_attr_get_u8(nla_action[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
-
-	return 0;
-}
-
-static int dpipe_table_actions_show(struct dpipe_ctx *ctx,
-				    struct nlattr *nla_actions)
-{
-	struct nlattr *nla_action;
-	struct dpipe_action action;
-
-	mnl_attr_for_each_nested(nla_action, nla_actions) {
-		pr_out_entry_start(ctx->dl);
-		if (dpipe_action_parse(&action, nla_action))
-			goto err_action_parse;
-		pr_out_dpipe_action(&action, ctx);
-		pr_out_entry_end(ctx->dl);
-	}
-	return 0;
-
-err_action_parse:
-	pr_out_entry_end(ctx->dl);
-	return -EINVAL;
-}
-
-static const char *
-dpipe_match_type_e2s(enum devlink_dpipe_match_type match_type)
-{
-	switch (match_type) {
-	case DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT:
-		return "field_exact";
-	default:
-		return "<unknown>";
-	}
-}
-
-struct dpipe_match {
-	struct dpipe_op_info info;
-	uint32_t type;
-};
-
-static void pr_out_dpipe_match(struct dpipe_match *match,
-			       struct dpipe_ctx *ctx)
-{
-	struct dpipe_op_info *op_info = &match->info;
-	const char *mapping;
-
-	pr_out_str(ctx->dl, "type",
-		   dpipe_match_type_e2s(match->type));
-	pr_out_str(ctx->dl, "header",
-		   dpipe_header_id2s(ctx, op_info->header_id,
-				     op_info->header_global));
-	pr_out_str(ctx->dl, "field",
-		   dpipe_field_id2s(ctx, op_info->header_id,
-				    op_info->field_id,
-				    op_info->header_global));
-	mapping = dpipe_mapping_get(ctx, op_info->header_id,
-				    op_info->field_id,
-				    op_info->header_global);
-	if (mapping)
-		pr_out_str(ctx->dl, "mapping", mapping);
-}
-
-static int dpipe_match_parse(struct dpipe_match *match,
-			     struct nlattr *nl)
-
-{
-	struct nlattr *nla_match[DEVLINK_ATTR_MAX + 1] = {};
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_match);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_match[DEVLINK_ATTR_DPIPE_MATCH_TYPE] ||
-	    !nla_match[DEVLINK_ATTR_DPIPE_HEADER_INDEX] ||
-	    !nla_match[DEVLINK_ATTR_DPIPE_HEADER_ID] ||
-	    !nla_match[DEVLINK_ATTR_DPIPE_FIELD_ID]) {
-		return -EINVAL;
-	}
-
-	match->type = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_MATCH_TYPE]);
-	match->info.header_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_HEADER_ID]);
-	match->info.field_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_FIELD_ID]);
-	match->info.header_global = !!mnl_attr_get_u8(nla_match[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
-
-	return 0;
-}
-
-static int dpipe_table_matches_show(struct dpipe_ctx *ctx,
-				    struct nlattr *nla_matches)
-{
-	struct nlattr *nla_match;
-	struct dpipe_match match;
-
-	mnl_attr_for_each_nested(nla_match, nla_matches) {
-		pr_out_entry_start(ctx->dl);
-		if (dpipe_match_parse(&match, nla_match))
-			goto err_match_parse;
-		pr_out_dpipe_match(&match, ctx);
-		pr_out_entry_end(ctx->dl);
-	}
-	return 0;
-
-err_match_parse:
-	pr_out_entry_end(ctx->dl);
-	return -EINVAL;
-}
-
-static struct resource *
-resource_find(struct resources *resources, struct resource *resource,
-	      uint64_t resource_id)
-{
-	struct list_head *list_head;
-
-	if (!resource)
-		list_head = &resources->resource_list;
-	else
-		list_head = &resource->resource_list;
-
-	list_for_each_entry(resource, list_head, list) {
-		struct resource *child_resource;
-
-		if (resource->id == resource_id)
-			return resource;
-
-		child_resource = resource_find(resources, resource,
-					       resource_id);
-		if (child_resource)
-			return child_resource;
-	}
-	return NULL;
-}
-
-static void
-resource_path_print(struct dl *dl, struct resources *resources,
-		    uint64_t resource_id)
-{
-	struct resource *resource, *parent_resource;
-	const char del[] = "/";
-	int path_len = 0;
-	char *path;
-
-	resource = resource_find(resources, NULL, resource_id);
-	if (!resource)
-		return;
-
-	for (parent_resource = resource; parent_resource;
-	     parent_resource = parent_resource->parent)
-		path_len += strlen(parent_resource->name) + 1;
-
-	path_len++;
-	path = calloc(1, path_len);
-	if (!path)
-		return;
-
-	path += path_len - 1;
-	for (parent_resource = resource; parent_resource;
-		parent_resource = parent_resource->parent) {
-		path -= strlen(parent_resource->name);
-		memcpy(path, parent_resource->name,
-		       strlen(parent_resource->name));
-		path -= strlen(del);
-		memcpy(path, del, strlen(del));
-	}
-	pr_out_str(dl, "resource_path", path);
-	free(path);
-}
-
-static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
-{
-	struct nlattr *nla_table[DEVLINK_ATTR_MAX + 1] = {};
-	struct dpipe_table *table;
-	uint32_t resource_units;
-	bool counters_enabled;
-	bool resource_valid;
-	uint32_t size;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_table);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_table[DEVLINK_ATTR_DPIPE_TABLE_NAME] ||
-	    !nla_table[DEVLINK_ATTR_DPIPE_TABLE_SIZE] ||
-	    !nla_table[DEVLINK_ATTR_DPIPE_TABLE_ACTIONS] ||
-	    !nla_table[DEVLINK_ATTR_DPIPE_TABLE_MATCHES] ||
-	    !nla_table[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED]) {
-		return -EINVAL;
-	}
-
-	table = dpipe_table_alloc();
-	if (!table)
-		return -ENOMEM;
-
-	table->name = strdup(mnl_attr_get_str(nla_table[DEVLINK_ATTR_DPIPE_TABLE_NAME]));
-	size = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_SIZE]);
-	counters_enabled = !!mnl_attr_get_u8(nla_table[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED]);
-
-	resource_valid = nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID] &&
-			 ctx->resources;
-	if (resource_valid) {
-		table->resource_id = mnl_attr_get_u64(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID]);
-		table->resource_valid = true;
-	}
-
-	list_add_tail(&table->list, &ctx->tables->table_list);
-	if (!ctx->print_tables)
-		return 0;
-
-	pr_out_str(ctx->dl, "name", table->name);
-	pr_out_uint(ctx->dl, "size", size);
-	pr_out_str(ctx->dl, "counters_enabled",
-		   counters_enabled ? "true" : "false");
-
-	if (resource_valid) {
-		resource_units = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS]);
-		resource_path_print(ctx->dl, ctx->resources,
-				    table->resource_id);
-		pr_out_uint(ctx->dl, "resource_units", resource_units);
-	}
-
-	pr_out_array_start(ctx->dl, "match");
-	if (dpipe_table_matches_show(ctx, nla_table[DEVLINK_ATTR_DPIPE_TABLE_MATCHES]))
-		goto err_matches_show;
-	pr_out_array_end(ctx->dl);
-
-	pr_out_array_start(ctx->dl, "action");
-	if (dpipe_table_actions_show(ctx, nla_table[DEVLINK_ATTR_DPIPE_TABLE_ACTIONS]))
-		goto err_actions_show;
-	pr_out_array_end(ctx->dl);
-
-	return 0;
-
-err_actions_show:
-err_matches_show:
-	pr_out_array_end(ctx->dl);
-	return -EINVAL;
-}
-
-static int dpipe_tables_show(struct dpipe_ctx *ctx, struct nlattr **tb)
-{
-	struct nlattr *nla_tables = tb[DEVLINK_ATTR_DPIPE_TABLES];
-	struct nlattr *nla_table;
-
-	mnl_attr_for_each_nested(nla_table, nla_tables) {
-		if (ctx->print_tables)
-			pr_out_handle_start_arr(ctx->dl, tb);
-		if (dpipe_table_show(ctx, nla_table))
-			goto err_table_show;
-		if (ctx->print_tables)
-			pr_out_handle_end(ctx->dl);
-	}
-	return 0;
-
-err_table_show:
-	if (ctx->print_tables)
-		pr_out_handle_end(ctx->dl);
-	return -EINVAL;
-}
-
-static int cmd_dpipe_table_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dpipe_ctx *ctx = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_DPIPE_TABLES])
-		return MNL_CB_ERROR;
-
-	if (dpipe_tables_show(ctx, tb))
-		return MNL_CB_ERROR;
-	return MNL_CB_OK;
-}
-
-static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data);
-
-static int cmd_dpipe_table_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	struct dpipe_ctx dpipe_ctx = {};
-	struct resource_ctx resource_ctx = {};
-	uint16_t flags = NLM_F_REQUEST;
-	int err;
-
-	err = dl_argv_parse(dl, DL_OPT_HANDLE, DL_OPT_DPIPE_TABLE_NAME);
-	if (err)
-		return err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
-
-	err = dpipe_ctx_init(&dpipe_ctx, dl);
-	if (err)
-		return err;
-
-	dpipe_ctx.print_tables = true;
-
-	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb,
-				  &dpipe_ctx);
-	if (err) {
-		pr_err("error get headers %s\n", strerror(dpipe_ctx.err));
-		goto err_headers_get;
-	}
-
-	err = resource_ctx_init(&resource_ctx, dl);
-	if (err)
-		goto err_resource_ctx_init;
-
-	resource_ctx.print_resources = false;
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP, flags);
-	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb,
-				  &resource_ctx);
-	if (!err)
-		dpipe_ctx.resources = resource_ctx.resources;
-
-	flags = NLM_F_REQUEST | NLM_F_ACK;
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET, flags);
-	dl_opts_put(nlh, dl);
-
-	pr_out_section_start(dl, "table");
-	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, &dpipe_ctx);
-	pr_out_section_end(dl);
-
-	resource_ctx_fini(&resource_ctx);
-	dpipe_ctx_fini(&dpipe_ctx);
-	return 0;
-
-err_resource_ctx_init:
-err_headers_get:
-	dpipe_ctx_fini(&dpipe_ctx);
-	return err;
-}
-
-static int cmd_dpipe_table_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl,
-				DL_OPT_HANDLE | DL_OPT_DPIPE_TABLE_NAME |
-				DL_OPT_DPIPE_TABLE_COUNTERS, 0);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-enum dpipe_value_type {
-	DPIPE_VALUE_TYPE_VALUE,
-	DPIPE_VALUE_TYPE_MASK,
-};
-
-static const char *
-dpipe_value_type_e2s(enum dpipe_value_type type)
-{
-	switch (type) {
-	case DPIPE_VALUE_TYPE_VALUE:
-		return "value";
-	case DPIPE_VALUE_TYPE_MASK:
-		return "value_mask";
-	default:
-		return "<unknown>";
-	}
-}
-
-struct dpipe_field_printer {
-	unsigned int field_id;
-	void (*printer)(struct dpipe_ctx *, enum dpipe_value_type, void *);
-};
-
-struct dpipe_header_printer {
-	struct dpipe_field_printer *printers;
-	unsigned int printers_count;
-	unsigned int header_id;
-};
-
-static void dpipe_field_printer_ipv4_addr(struct dpipe_ctx *ctx,
-					  enum dpipe_value_type type,
-					  void *value)
-{
-	struct in_addr ip_addr;
-
-	ip_addr.s_addr = htonl(*(uint32_t *)value);
-	pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
-}
-
-static void
-dpipe_field_printer_ethernet_addr(struct dpipe_ctx *ctx,
-				  enum dpipe_value_type type,
-				  void *value)
-{
-	pr_out_str(ctx->dl, dpipe_value_type_e2s(type),
-		   ether_ntoa((struct ether_addr *)value));
-}
-
-static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
-					  enum dpipe_value_type type,
-					  void *value)
-{
-	char str[INET6_ADDRSTRLEN];
-
-	inet_ntop(AF_INET6, value, str, INET6_ADDRSTRLEN);
-	pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str);
-}
-
-static struct dpipe_field_printer dpipe_field_printers_ipv4[] = {
-	{
-		.printer = dpipe_field_printer_ipv4_addr,
-		.field_id = DEVLINK_DPIPE_FIELD_IPV4_DST_IP,
-	}
-};
-
-static struct dpipe_header_printer dpipe_header_printer_ipv4  = {
-	.printers = dpipe_field_printers_ipv4,
-	.printers_count = ARRAY_SIZE(dpipe_field_printers_ipv4),
-	.header_id = DEVLINK_DPIPE_HEADER_IPV4,
-};
-
-static struct dpipe_field_printer dpipe_field_printers_ethernet[] = {
-	{
-		.printer = dpipe_field_printer_ethernet_addr,
-		.field_id = DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC,
-	},
-};
-
-static struct dpipe_header_printer dpipe_header_printer_ethernet = {
-	.printers = dpipe_field_printers_ethernet,
-	.printers_count = ARRAY_SIZE(dpipe_field_printers_ethernet),
-	.header_id = DEVLINK_DPIPE_HEADER_ETHERNET,
-};
-
-static struct dpipe_field_printer dpipe_field_printers_ipv6[] = {
-	{
-		.printer = dpipe_field_printer_ipv6_addr,
-		.field_id = DEVLINK_DPIPE_FIELD_IPV6_DST_IP,
-	}
-};
-
-static struct dpipe_header_printer dpipe_header_printer_ipv6 = {
-	.printers = dpipe_field_printers_ipv6,
-	.printers_count = ARRAY_SIZE(dpipe_field_printers_ipv6),
-	.header_id = DEVLINK_DPIPE_HEADER_IPV6,
-};
-
-static struct dpipe_header_printer *dpipe_header_printers[] = {
-	&dpipe_header_printer_ipv4,
-	&dpipe_header_printer_ethernet,
-	&dpipe_header_printer_ipv6,
-};
-
-static int dpipe_print_prot_header(struct dpipe_ctx *ctx,
-				   struct dpipe_op_info *info,
-				   enum dpipe_value_type type,
-				   void *value)
-{
-	unsigned int header_printers_count = ARRAY_SIZE(dpipe_header_printers);
-	struct dpipe_header_printer *header_printer;
-	struct dpipe_field_printer *field_printer;
-	unsigned int field_printers_count;
-	int j;
-	int i;
-
-	for (i = 0; i < header_printers_count; i++) {
-		header_printer = dpipe_header_printers[i];
-		if (header_printer->header_id != info->header_id)
-			continue;
-		field_printers_count = header_printer->printers_count;
-		for (j = 0; j < field_printers_count; j++) {
-			field_printer = &header_printer->printers[j];
-			if (field_printer->field_id != info->field_id)
-				continue;
-			field_printer->printer(ctx, type, value);
-			return 0;
-		}
-	}
-
-	return -EINVAL;
-}
-
-static void __pr_out_entry_value(struct dpipe_ctx *ctx,
-				 void *value,
-				 unsigned int value_len,
-				 struct dpipe_op_info *info,
-				 enum dpipe_value_type type)
-{
-	if (info->header_global &&
-	    !dpipe_print_prot_header(ctx, info, type, value))
-		return;
-
-	if (value_len == sizeof(uint32_t)) {
-		uint32_t *value_32 = value;
-
-		pr_out_uint(ctx->dl, dpipe_value_type_e2s(type), *value_32);
-	}
-}
-
-static void pr_out_dpipe_entry_value(struct dpipe_ctx *ctx,
-				     struct nlattr **nla_match_value,
-				     struct dpipe_op_info *info)
-{
-	void *value, *value_mask;
-	uint32_t value_mapping;
-	uint16_t value_len;
-	bool mask, mapping;
-
-	mask = !!nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MASK];
-	mapping = !!nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING];
-
-	value_len = mnl_attr_get_payload_len(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
-	value = mnl_attr_get_payload(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
-
-	if (mapping) {
-		value_mapping = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING]);
-		pr_out_uint(ctx->dl, "mapping_value", value_mapping);
-	}
-
-	if (mask) {
-		value_mask = mnl_attr_get_payload(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
-		__pr_out_entry_value(ctx, value_mask, value_len, info,
-				     DPIPE_VALUE_TYPE_MASK);
-	}
-
-	__pr_out_entry_value(ctx, value, value_len, info, DPIPE_VALUE_TYPE_VALUE);
-}
-
-static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,
-					struct nlattr *nl)
-{
-	struct nlattr *nla_match_value[DEVLINK_ATTR_MAX + 1] = {};
-	struct dpipe_match match;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_match_value);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_match_value[DEVLINK_ATTR_DPIPE_MATCH] ||
-	    !nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]) {
-		return -EINVAL;
-	}
-
-	pr_out_entry_start(ctx->dl);
-	if (dpipe_match_parse(&match,
-			      nla_match_value[DEVLINK_ATTR_DPIPE_MATCH]))
-		goto err_match_parse;
-	pr_out_dpipe_match(&match, ctx);
-	pr_out_dpipe_entry_value(ctx, nla_match_value, &match.info);
-	pr_out_entry_end(ctx->dl);
-
-	return 0;
-
-err_match_parse:
-	pr_out_entry_end(ctx->dl);
-	return -EINVAL;
-}
-
-static int dpipe_entry_action_value_show(struct dpipe_ctx *ctx,
-					 struct nlattr *nl)
-{
-	struct nlattr *nla_action_value[DEVLINK_ATTR_MAX + 1] = {};
-	struct dpipe_action action;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_action_value);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_action_value[DEVLINK_ATTR_DPIPE_ACTION] ||
-	    !nla_action_value[DEVLINK_ATTR_DPIPE_VALUE]) {
-		return -EINVAL;
-	}
-
-	pr_out_entry_start(ctx->dl);
-	if (dpipe_action_parse(&action,
-			       nla_action_value[DEVLINK_ATTR_DPIPE_ACTION]))
-		goto err_action_parse;
-	pr_out_dpipe_action(&action, ctx);
-	pr_out_dpipe_entry_value(ctx, nla_action_value, &action.info);
-	pr_out_entry_end(ctx->dl);
-
-	return 0;
-
-err_action_parse:
-	pr_out_entry_end(ctx->dl);
-	return -EINVAL;
-}
-
-static int
-dpipe_tables_action_values_show(struct dpipe_ctx *ctx,
-				struct nlattr *nla_action_values)
-{
-	struct nlattr *nla_action_value;
-
-	mnl_attr_for_each_nested(nla_action_value, nla_action_values) {
-		if (dpipe_entry_action_value_show(ctx, nla_action_value))
-			return -EINVAL;
-	}
-	return 0;
-}
-
-static int
-dpipe_tables_match_values_show(struct dpipe_ctx *ctx,
-			       struct nlattr *nla_match_values)
-{
-	struct nlattr *nla_match_value;
-
-	mnl_attr_for_each_nested(nla_match_value, nla_match_values) {
-		if (dpipe_entry_match_value_show(ctx, nla_match_value))
-			return -EINVAL;
-	}
-	return 0;
-}
-
-static int dpipe_entry_show(struct dpipe_ctx *ctx, struct nlattr *nl)
-{
-	struct nlattr *nla_entry[DEVLINK_ATTR_MAX + 1] = {};
-	uint32_t entry_index;
-	uint64_t counter;
-	int err;
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_entry);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	if (!nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_INDEX] ||
-	    !nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES] ||
-	    !nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES]) {
-		return -EINVAL;
-	}
-
-	entry_index = mnl_attr_get_u32(nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_INDEX]);
-	pr_out_uint(ctx->dl, "index", entry_index);
-
-	if (nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER]) {
-		counter = mnl_attr_get_u64(nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER]);
-		pr_out_uint(ctx->dl, "counter", counter);
-	}
-
-	pr_out_array_start(ctx->dl, "match_value");
-	if (dpipe_tables_match_values_show(ctx,
-					   nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES]))
-		goto err_match_values_show;
-	pr_out_array_end(ctx->dl);
-
-	pr_out_array_start(ctx->dl, "action_value");
-	if (dpipe_tables_action_values_show(ctx,
-					    nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES]))
-		goto err_action_values_show;
-	pr_out_array_end(ctx->dl);
-	return 0;
-
-err_action_values_show:
-err_match_values_show:
-	pr_out_array_end(ctx->dl);
-	return -EINVAL;
-}
-
-static int dpipe_table_entries_show(struct dpipe_ctx *ctx, struct nlattr **tb)
-{
-	struct nlattr *nla_entries = tb[DEVLINK_ATTR_DPIPE_ENTRIES];
-	struct nlattr *nla_entry;
-
-	mnl_attr_for_each_nested(nla_entry, nla_entries) {
-		pr_out_handle_start_arr(ctx->dl, tb);
-		if (dpipe_entry_show(ctx, nla_entry))
-			goto err_entry_show;
-		pr_out_handle_end(ctx->dl);
-	}
-	return 0;
-
-err_entry_show:
-	pr_out_handle_end(ctx->dl);
-	return -EINVAL;
-}
-
-static int cmd_dpipe_table_entry_dump_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct dpipe_ctx *ctx = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_DPIPE_ENTRIES])
-		return MNL_CB_ERROR;
-
-	if (dpipe_table_entries_show(ctx, tb))
-		return MNL_CB_ERROR;
-	return MNL_CB_OK;
-}
-
-static int cmd_dpipe_table_dump(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	struct dpipe_ctx ctx = {};
-	uint16_t flags = NLM_F_REQUEST;
-	int err;
-
-	err = dpipe_ctx_init(&ctx, dl);
-	if (err)
-		return err;
-
-	err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_DPIPE_TABLE_NAME, 0);
-	if (err)
-		goto out;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
-	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
-	if (err) {
-		pr_err("error get headers %s\n", strerror(ctx.err));
-		goto out;
-	}
-
-	flags = NLM_F_REQUEST | NLM_F_ACK;
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_ENTRIES_GET, flags);
-	dl_opts_put(nlh, dl);
-
-	pr_out_section_start(dl, "table_entry");
-	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_entry_dump_cb, &ctx);
-	pr_out_section_end(dl);
-out:
-	dpipe_ctx_fini(&ctx);
-	return err;
-}
-
-static void cmd_dpipe_table_help(void)
-{
-	pr_err("Usage: devlink dpipe table [ OBJECT-LIST ]\n"
-	       "where  OBJECT-LIST := { show | set | dump }\n");
-}
-
-static int cmd_dpipe_table(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_dpipe_table_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe_table_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe_table_set(dl);
-	}  else if (dl_argv_match(dl, "dump")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe_table_dump(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void cmd_dpipe_help(void)
-{
-	pr_err("Usage: devlink dpipe [ OBJECT-LIST ]\n"
-	       "where  OBJECT-LIST := { header | table }\n");
-}
-
-static int cmd_dpipe(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_dpipe_help();
-		return 0;
-	} else if (dl_argv_match(dl, "header")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe_header(dl);
-	} else if (dl_argv_match(dl, "table")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe_table(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int
-resource_parse(struct resource_ctx *ctx, struct resource *resource,
-	       struct nlattr **nla_resource)
-{
-	if (!nla_resource[DEVLINK_ATTR_RESOURCE_NAME] ||
-	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE] ||
-	    !nla_resource[DEVLINK_ATTR_RESOURCE_ID] ||
-	    !nla_resource[DEVLINK_ATTR_RESOURCE_UNIT] ||
-	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MIN] ||
-	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MAX] ||
-	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_GRAN]) {
-		return -EINVAL;
-	}
-
-	resource->name = strdup(mnl_attr_get_str(nla_resource[DEVLINK_ATTR_RESOURCE_NAME]));
-	resource->size = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE]);
-	resource->id = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_ID]);
-	resource->unit = mnl_attr_get_u8(nla_resource[DEVLINK_ATTR_RESOURCE_UNIT]);
-	resource->size_min = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MIN]);
-	resource->size_max = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MAX]);
-	resource->size_gran = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_GRAN]);
-
-	if (nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_NEW])
-		resource->size_new = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_NEW]);
-	else
-		resource->size_new = resource->size;
-
-	if (nla_resource[DEVLINK_ATTR_RESOURCE_OCC]) {
-		resource->size_occ = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_OCC]);
-		resource->occ_valid = true;
-	}
-
-	if (resource->size_new != resource->size)
-		ctx->pending_change = true;
-
-	return 0;
-}
-
-static int
-resource_get(struct resource_ctx *ctx, struct resource *resource,
-	     struct resource *parent_resource, struct nlattr *nl)
-{
-	struct nlattr *nla_resource[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *nla_child_resource;
-	struct nlattr *nla_resources;
-	bool top = false;
-	int err;
-
-	if (!resource) {
-		nla_resources = nl;
-		top = true;
-		goto out;
-	}
-
-	err = mnl_attr_parse_nested(nl, attr_cb, nla_resource);
-	if (err != MNL_CB_OK)
-		return -EINVAL;
-
-	err = resource_parse(ctx, resource, nla_resource);
-	if (err)
-		return err;
-
-	resource->parent = parent_resource;
-	if (!nla_resource[DEVLINK_ATTR_RESOURCE_LIST])
-		return 0;
-
-	resource->size_valid = !!mnl_attr_get_u8(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_VALID]);
-	nla_resources = nla_resource[DEVLINK_ATTR_RESOURCE_LIST];
-out:
-	mnl_attr_for_each_nested(nla_child_resource, nla_resources) {
-		struct resource *child_resource;
-		struct list_head *list;
-
-		child_resource = resource_alloc();
-		if (!child_resource)
-			return -ENOMEM;
-
-		if (top)
-			list = &ctx->resources->resource_list;
-		else
-			list = &resource->resource_list;
-
-		list_add_tail(&child_resource->list, list);
-		err = resource_get(ctx, child_resource, resource,
-				   nla_child_resource);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
-static const char *resource_unit_str_get(enum devlink_resource_unit unit)
-{
-	switch (unit) {
-	case DEVLINK_RESOURCE_UNIT_ENTRY: return "entry";
-	default: return "<unknown unit>";
-	}
-}
-
-static void resource_show(struct resource *resource,
-			  struct resource_ctx *ctx)
-{
-	struct resource *child_resource;
-	struct dpipe_table *table;
-	struct dl *dl = ctx->dl;
-	bool array = false;
-
-	pr_out_str(dl, "name", resource->name);
-	if (dl->verbose)
-		resource_path_print(dl, ctx->resources, resource->id);
-	pr_out_u64(dl, "size", resource->size);
-	if (resource->size != resource->size_new)
-		pr_out_u64(dl, "size_new", resource->size_new);
-	if (resource->occ_valid)
-		pr_out_uint(dl, "occ", resource->size_occ);
-	pr_out_str(dl, "unit", resource_unit_str_get(resource->unit));
-
-	if (resource->size_min != resource->size_max) {
-		pr_out_uint(dl, "size_min", resource->size_min);
-		pr_out_u64(dl, "size_max", resource->size_max);
-		pr_out_uint(dl, "size_gran", resource->size_gran);
-	}
-
-	list_for_each_entry(table, &ctx->tables->table_list, list)
-		if (table->resource_id == resource->id &&
-		    table->resource_valid)
-			array = true;
-
-	if (array)
-		pr_out_array_start(dl, "dpipe_tables");
-	else
-		pr_out_str(dl, "dpipe_tables", "none");
-
-	list_for_each_entry(table, &ctx->tables->table_list, list) {
-		if (table->resource_id != resource->id ||
-		    !table->resource_valid)
-			continue;
-		pr_out_entry_start(dl);
-		pr_out_str(dl, "table_name", table->name);
-		pr_out_entry_end(dl);
-	}
-	if (array)
-		pr_out_array_end(dl);
-
-	if (list_empty(&resource->resource_list))
-		return;
-
-	if (ctx->pending_change)
-		pr_out_str(dl, "size_valid", resource->size_valid ?
-			   "true" : "false");
-	pr_out_array_start(dl, "resources");
-	list_for_each_entry(child_resource, &resource->resource_list, list) {
-		pr_out_entry_start(dl);
-		resource_show(child_resource, ctx);
-		pr_out_entry_end(dl);
-	}
-	pr_out_array_end(dl);
-}
-
-static void
-resources_show(struct resource_ctx *ctx, struct nlattr **tb)
-{
-	struct resources *resources = ctx->resources;
-	struct resource *resource;
-
-	list_for_each_entry(resource, &resources->resource_list, list) {
-		pr_out_handle_start_arr(ctx->dl, tb);
-		resource_show(resource, ctx);
-		pr_out_handle_end(ctx->dl);
-	}
-}
-
-static int resources_get(struct resource_ctx *ctx, struct nlattr **tb)
-{
-	return resource_get(ctx, NULL, NULL, tb[DEVLINK_ATTR_RESOURCE_LIST]);
-}
-
-static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct resource_ctx *ctx = data;
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	int err;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_RESOURCE_LIST])
-		return MNL_CB_ERROR;
-
-	err = resources_get(ctx, tb);
-	if (err) {
-		ctx->err = err;
-		return MNL_CB_ERROR;
-	}
-
-	if (ctx->print_resources)
-		resources_show(ctx, tb);
-
-	return MNL_CB_OK;
-}
-
-static int cmd_resource_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	struct dpipe_ctx dpipe_ctx = {};
-	struct resource_ctx resource_ctx = {};
-	int err;
-
-	err = dl_argv_parse(dl, DL_OPT_HANDLE, 0);
-	if (err)
-		return err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET,
-			       NLM_F_REQUEST);
-	dl_opts_put(nlh, dl);
-
-	err = dpipe_ctx_init(&dpipe_ctx, dl);
-	if (err)
-		return err;
-
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb,
-				  &dpipe_ctx);
-	if (err) {
-		pr_err("error get tables %s\n", strerror(dpipe_ctx.err));
-		goto out;
-	}
-
-	err = resource_ctx_init(&resource_ctx, dl);
-	if (err)
-		goto out;
-
-	resource_ctx.print_resources = true;
-	resource_ctx.tables = dpipe_ctx.tables;
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
-			       NLM_F_REQUEST | NLM_F_ACK);
-	dl_opts_put(nlh, dl);
-	pr_out_section_start(dl, "resources");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb,
-				  &resource_ctx);
-	pr_out_section_end(dl);
-	resource_ctx_fini(&resource_ctx);
-out:
-	dpipe_ctx_fini(&dpipe_ctx);
-	return err;
-}
-
-static void cmd_resource_help(void)
-{
-	pr_err("Usage: devlink resource show DEV\n"
-	       "       devlink resource set DEV path PATH size SIZE\n");
-}
-
-static struct resource *
-resource_find_by_name(struct list_head *list, char *name)
-{
-	struct resource *resource;
-
-	list_for_each_entry(resource, list, list) {
-		if (!strcmp(resource->name, name))
-			return resource;
-	}
-	return NULL;
-}
-
-static int
-resource_path_parse(struct resource_ctx *ctx, const char *resource_path,
-		    uint32_t *p_resource_id, bool *p_resource_valid)
-{
-	struct resource *resource;
-	uint32_t resource_id = 0;
-	char *resource_path_dup;
-	struct list_head *list;
-	const char del[] = "/";
-	char *resource_name;
-
-	resource_path_dup = strdup(resource_path);
-	list = &ctx->resources->resource_list;
-	resource_name = strtok(resource_path_dup, del);
-	while (resource_name != NULL) {
-		resource = resource_find_by_name(list, resource_name);
-		if (!resource)
-			goto err_resource_lookup;
-
-		list = &resource->resource_list;
-		resource_name = strtok(NULL, del);
-		resource_id = resource->id;
-	}
-	free(resource_path_dup);
-	*p_resource_valid = true;
-	*p_resource_id = resource_id;
-	return 0;
-
-err_resource_lookup:
-	free(resource_path_dup);
-	return -EINVAL;
-}
-
-static int cmd_resource_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	struct resource_ctx ctx = {};
-	int err;
-
-	err = resource_ctx_init(&ctx, dl);
-	if (err)
-		return err;
-
-	ctx.print_resources = false;
-	err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_RESOURCE_PATH |
-			    DL_OPT_RESOURCE_SIZE, 0);
-	if (err)
-		goto out;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
-			       NLM_F_REQUEST);
-	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb, &ctx);
-	if (err) {
-		pr_err("error getting resources %s\n", strerror(ctx.err));
-		goto out;
-	}
-
-	err = resource_path_parse(&ctx, dl->opts.resource_path,
-				  &dl->opts.resource_id,
-				  &dl->opts.resource_id_valid);
-	if (err) {
-		pr_err("error parsing resource path %s\n", strerror(-err));
-		goto out;
-	}
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-out:
-	resource_ctx_fini(&ctx);
-	return err;
-}
-
-static int cmd_resource(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		cmd_resource_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show")) {
-		dl_arg_inc(dl);
-		return cmd_resource_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_resource_set(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void pr_out_region_handle_start(struct dl *dl, struct nlattr **tb)
-{
-	const char *bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
-	const char *dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
-	const char *region_name = mnl_attr_get_str(tb[DEVLINK_ATTR_REGION_NAME]);
-	char buf[256];
-
-	sprintf(buf, "%s/%s/%s", bus_name, dev_name, region_name);
-	if (dl->json_output) {
-		jsonw_name(dl->jw, buf);
-		jsonw_start_object(dl->jw);
-	} else {
-		pr_out("%s:", buf);
-	}
-}
-
-static void pr_out_region_handle_end(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_end_object(dl->jw);
-	else
-		pr_out("\n");
-}
-
-static void pr_out_region_snapshots_start(struct dl *dl, bool array)
-{
-	__pr_out_indent_newline(dl);
-	if (dl->json_output) {
-		jsonw_name(dl->jw, "snapshot");
-		jsonw_start_array(dl->jw);
-	} else {
-		pr_out("snapshot %s", array ? "[" : "");
-	}
-}
-
-static void pr_out_region_snapshots_end(struct dl *dl, bool array)
-{
-	if (dl->json_output)
-		jsonw_end_array(dl->jw);
-	else if (array)
-		pr_out("]");
-}
-
-static void pr_out_region_snapshots_id(struct dl *dl, struct nlattr **tb, int index)
-{
-	uint32_t snapshot_id;
-
-	if (!tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID])
-		return;
-
-	snapshot_id = mnl_attr_get_u32(tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
-
-	if (dl->json_output)
-		jsonw_uint(dl->jw, snapshot_id);
-	else
-		pr_out("%s%u", index ? " " : "", snapshot_id);
-}
-
-static void pr_out_snapshots(struct dl *dl, struct nlattr **tb)
-{
-	struct nlattr *tb_snapshot[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *nla_sanpshot;
-	int err, index = 0;
-
-	pr_out_region_snapshots_start(dl, true);
-	mnl_attr_for_each_nested(nla_sanpshot, tb[DEVLINK_ATTR_REGION_SNAPSHOTS]) {
-		err = mnl_attr_parse_nested(nla_sanpshot, attr_cb, tb_snapshot);
-		if (err != MNL_CB_OK)
-			return;
-		pr_out_region_snapshots_id(dl, tb_snapshot, index++);
-	}
-	pr_out_region_snapshots_end(dl, true);
-}
-
-static void pr_out_snapshot(struct dl *dl, struct nlattr **tb)
-{
-	pr_out_region_snapshots_start(dl, false);
-	pr_out_region_snapshots_id(dl, tb, 0);
-	pr_out_region_snapshots_end(dl, false);
-}
-
-static void pr_out_region(struct dl *dl, struct nlattr **tb)
-{
-	pr_out_region_handle_start(dl, tb);
-
-	if (tb[DEVLINK_ATTR_REGION_SIZE])
-		pr_out_u64(dl, "size",
-			   mnl_attr_get_u64(tb[DEVLINK_ATTR_REGION_SIZE]));
-
-	if (tb[DEVLINK_ATTR_REGION_SNAPSHOTS])
-		pr_out_snapshots(dl, tb);
-
-	if (tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID])
-		pr_out_snapshot(dl, tb);
-
-	pr_out_region_handle_end(dl);
-}
-
-static int cmd_region_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct dl *dl = data;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_REGION_NAME] || !tb[DEVLINK_ATTR_REGION_SIZE])
-		return MNL_CB_ERROR;
-
-	pr_out_region(dl, tb);
-
-	return MNL_CB_OK;
-}
-
-static int cmd_region_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION, 0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "regions");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static int cmd_region_snapshot_del(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_DEL,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION |
-				DL_OPT_REGION_SNAPSHOT_ID, 0);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_region_read_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *nla_entry, *nla_chunk_data, *nla_chunk_addr;
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb_field[DEVLINK_ATTR_MAX + 1] = {};
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct dl *dl = data;
-	int err;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_REGION_CHUNKS])
-		return MNL_CB_ERROR;
-
-	mnl_attr_for_each_nested(nla_entry, tb[DEVLINK_ATTR_REGION_CHUNKS]) {
-		err = mnl_attr_parse_nested(nla_entry, attr_cb, tb_field);
-		if (err != MNL_CB_OK)
-			return MNL_CB_ERROR;
-
-		nla_chunk_data = tb_field[DEVLINK_ATTR_REGION_CHUNK_DATA];
-		if (!nla_chunk_data)
-			continue;
-
-		nla_chunk_addr = tb_field[DEVLINK_ATTR_REGION_CHUNK_ADDR];
-		if (!nla_chunk_addr)
-			continue;
-
-		pr_out_region_chunk(dl, mnl_attr_get_payload(nla_chunk_data),
-				    mnl_attr_get_payload_len(nla_chunk_data),
-				    mnl_attr_get_u64(nla_chunk_addr));
-	}
-	return MNL_CB_OK;
-}
-
-static int cmd_region_dump(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_READ,
-			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION |
-				DL_OPT_REGION_SNAPSHOT_ID, 0);
-	if (err)
-		return err;
-
-	pr_out_section_start(dl, "dump");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_read_cb, dl);
-	pr_out_section_end(dl);
-	if (!dl->json_output)
-		pr_out("\n");
-	return err;
-}
-
-static int cmd_region_read(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_READ,
-			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION |
-				DL_OPT_REGION_ADDRESS | DL_OPT_REGION_LENGTH |
-				DL_OPT_REGION_SNAPSHOT_ID, 0);
-	if (err)
-		return err;
-
-	pr_out_section_start(dl, "read");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_read_cb, dl);
-	pr_out_section_end(dl);
-	if (!dl->json_output)
-		pr_out("\n");
-	return err;
-}
-
-static void cmd_region_help(void)
-{
-	pr_err("Usage: devlink region show [ DEV/REGION ]\n");
-	pr_err("       devlink region del DEV/REGION snapshot SNAPSHOT_ID\n");
-	pr_err("       devlink region dump DEV/REGION [ snapshot SNAPSHOT_ID ]\n");
-	pr_err("       devlink region read DEV/REGION [ snapshot SNAPSHOT_ID ] address ADDRESS length LENGTH\n");
-}
-
-static int cmd_region(struct dl *dl)
-{
-	if (dl_no_arg(dl)) {
-		return cmd_region_show(dl);
-	} else if (dl_argv_match(dl, "help")) {
-		cmd_region_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show")) {
-		dl_arg_inc(dl);
-		return cmd_region_show(dl);
-	} else if (dl_argv_match(dl, "del")) {
-		dl_arg_inc(dl);
-		return cmd_region_snapshot_del(dl);
-	} else if (dl_argv_match(dl, "dump")) {
-		dl_arg_inc(dl);
-		return cmd_region_dump(dl);
-	} else if (dl_argv_match(dl, "read")) {
-		dl_arg_inc(dl);
-		return cmd_region_read(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int cmd_health_set_params(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-	err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME,
-			    DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD |
-			    DL_OPT_HEALTH_REPORTER_AUTO_RECOVER);
-	if (err)
-		return err;
-
-	dl_opts_put(nlh, dl);
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_health_dump_clear(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl,
-				DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME, 0);
-	if (err)
-		return err;
-
-	dl_opts_put(nlh, dl);
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
-{
-	uint8_t *data;
-	uint32_t len;
-
-	switch (type) {
-	case MNL_TYPE_FLAG:
-		pr_out_bool_value(dl, mnl_attr_get_u8(nl_data));
-		break;
-	case MNL_TYPE_U8:
-		pr_out_uint_value(dl, mnl_attr_get_u8(nl_data));
-		break;
-	case MNL_TYPE_U16:
-		pr_out_uint_value(dl, mnl_attr_get_u16(nl_data));
-		break;
-	case MNL_TYPE_U32:
-		pr_out_uint_value(dl, mnl_attr_get_u32(nl_data));
-		break;
-	case MNL_TYPE_U64:
-		pr_out_uint64_value(dl, mnl_attr_get_u64(nl_data));
-		break;
-	case MNL_TYPE_NUL_STRING:
-		pr_out_str_value(dl, mnl_attr_get_str(nl_data));
-		break;
-	case MNL_TYPE_BINARY:
-		len = mnl_attr_get_payload_len(nl_data);
-		data = mnl_attr_get_payload(nl_data);
-		pr_out_binary_value(dl, data, len);
-		break;
-	default:
-		return -EINVAL;
-	}
-	return MNL_CB_OK;
-}
-
-struct nest_entry {
-	int attr_type;
-	struct list_head list;
-};
-
-struct fmsg_cb_data {
-	struct dl *dl;
-	uint8_t value_type;
-	struct list_head entry_list;
-};
-
-static int cmd_fmsg_nest_queue(struct fmsg_cb_data *fmsg_data,
-			       uint8_t *attr_value, bool insert)
-{
-	struct nest_entry *entry;
-
-	if (insert) {
-		entry = malloc(sizeof(struct nest_entry));
-		if (!entry)
-			return -ENOMEM;
-
-		entry->attr_type = *attr_value;
-		list_add(&entry->list, &fmsg_data->entry_list);
-	} else {
-		if (list_empty(&fmsg_data->entry_list))
-			return MNL_CB_ERROR;
-		entry = list_first_entry(&fmsg_data->entry_list,
-					 struct nest_entry, list);
-		*attr_value = entry->attr_type;
-		list_del(&entry->list);
-		free(entry);
-	}
-	return MNL_CB_OK;
-}
-
-static int cmd_fmsg_nest(struct fmsg_cb_data *fmsg_data, uint8_t nest_value,
-			 bool start)
-{
-	struct dl *dl = fmsg_data->dl;
-	uint8_t value = nest_value;
-	int err;
-
-	err = cmd_fmsg_nest_queue(fmsg_data, &value, start);
-	if (err != MNL_CB_OK)
-		return err;
-
-	switch (value) {
-	case DEVLINK_ATTR_FMSG_OBJ_NEST_START:
-		if (start)
-			pr_out_entry_start(dl);
-		else
-			pr_out_entry_end(dl);
-		break;
-	case DEVLINK_ATTR_FMSG_PAIR_NEST_START:
-		break;
-	case DEVLINK_ATTR_FMSG_ARR_NEST_START:
-		if (dl->json_output) {
-			if (start)
-				jsonw_start_array(dl->jw);
-			else
-				jsonw_end_array(dl->jw);
-		} else {
-			if (start) {
-				__pr_out_newline();
-				__pr_out_indent_inc();
-			} else {
-				__pr_out_indent_dec();
-			}
-		}
-		break;
-	default:
-		return -EINVAL;
-	}
-	return MNL_CB_OK;
-}
-
-static int cmd_fmsg_object_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct fmsg_cb_data *fmsg_data = data;
-	struct dl *dl = fmsg_data->dl;
-	struct nlattr *nla_object;
-	int attr_type;
-	int err;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_FMSG])
-		return MNL_CB_ERROR;
-
-	mnl_attr_for_each_nested(nla_object, tb[DEVLINK_ATTR_FMSG]) {
-		attr_type = mnl_attr_get_type(nla_object);
-		switch (attr_type) {
-		case DEVLINK_ATTR_FMSG_OBJ_NEST_START:
-		case DEVLINK_ATTR_FMSG_PAIR_NEST_START:
-		case DEVLINK_ATTR_FMSG_ARR_NEST_START:
-			err = cmd_fmsg_nest(fmsg_data, attr_type, true);
-			if (err != MNL_CB_OK)
-				return err;
-			break;
-		case DEVLINK_ATTR_FMSG_NEST_END:
-			err = cmd_fmsg_nest(fmsg_data, attr_type, false);
-			if (err != MNL_CB_OK)
-				return err;
-			break;
-		case DEVLINK_ATTR_FMSG_OBJ_NAME:
-			pr_out_name(dl, mnl_attr_get_str(nla_object));
-			break;
-		case DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE:
-			fmsg_data->value_type = mnl_attr_get_u8(nla_object);
-			break;
-		case DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA:
-			err = fmsg_value_show(dl, fmsg_data->value_type,
-					      nla_object);
-			if (err != MNL_CB_OK)
-				return err;
-			break;
-		default:
-			return -EINVAL;
-		}
-	}
-	return MNL_CB_OK;
-}
-
-static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
-{
-	struct fmsg_cb_data data;
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, cmd, flags | NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl,
-				DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME, 0);
-	if (err)
-		return err;
-
-	data.dl = dl;
-	INIT_LIST_HEAD(&data.entry_list);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_fmsg_object_cb, &data);
-	return err;
-}
-
-static int cmd_health_dump_show(struct dl *dl)
-{
-	return cmd_health_object_common(dl,
-					DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
-					NLM_F_DUMP);
-}
-
-static int cmd_health_diagnose(struct dl *dl)
-{
-	return cmd_health_object_common(dl,
-					DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE,
-					0);
-}
-
-static int cmd_health_recover(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl,
-				DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME, 0);
-	if (err)
-		return err;
-
-	dl_opts_put(nlh, dl);
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-enum devlink_health_reporter_state {
-	DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
-	DEVLINK_HEALTH_REPORTER_STATE_ERROR,
-};
-
-static const char *health_state_name(uint8_t state)
-{
-	switch (state) {
-	case DEVLINK_HEALTH_REPORTER_STATE_HEALTHY:
-		return HEALTH_REPORTER_STATE_HEALTHY_STR;
-	case DEVLINK_HEALTH_REPORTER_STATE_ERROR:
-		return HEALTH_REPORTER_STATE_ERROR_STR;
-	default:
-		return "<unknown state>";
-	}
-}
-
-static void format_logtime(uint64_t time_ms, char *ts_date, char *ts_time)
-{
-	struct sysinfo s_info;
-	struct tm *info;
-	time_t now, sec;
-	int err;
-
-	time(&now);
-	info = localtime(&now);
-	err = sysinfo(&s_info);
-	if (err)
-		goto out;
-	/* Subtract uptime in sec from now yields the time of system
-	 * uptime. To this, add time_ms which is the amount of
-	 * milliseconds elapsed between uptime and the dump taken.
-	 */
-	sec = now - s_info.uptime + time_ms / 1000;
-	info = localtime(&sec);
-out:
-	strftime(ts_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", info);
-	strftime(ts_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", info);
-}
-
-static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
-{
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	enum devlink_health_reporter_state state;
-	const struct nlattr *attr;
-	uint64_t time_ms;
-	int err;
-
-	err = mnl_attr_parse_nested(tb_health[DEVLINK_ATTR_HEALTH_REPORTER],
-				    attr_cb, tb);
-	if (err != MNL_CB_OK)
-		return;
-
-	if (!tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME] ||
-	    !tb[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT] ||
-	    !tb[DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT] ||
-	    !tb[DEVLINK_ATTR_HEALTH_REPORTER_STATE])
-		return;
-
-	pr_out_handle_start_arr(dl, tb_health);
-
-	pr_out_str(dl, "reporter",
-		   mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
-	if (!dl->json_output) {
-		__pr_out_newline();
-		__pr_out_indent_inc();
-	}
-	state = mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_STATE]);
-	pr_out_str(dl, "state", health_state_name(state));
-	pr_out_u64(dl, "error",
-		   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT]));
-	pr_out_u64(dl, "recover",
-		   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT]));
-	if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS]) {
-		char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
-		char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
-
-		attr = tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS];
-		time_ms = mnl_attr_get_u64(attr);
-		format_logtime(time_ms, dump_date, dump_time);
-
-		pr_out_str(dl, "last_dump_date", dump_date);
-		pr_out_str(dl, "last_dump_time", dump_time);
-	}
-	if (tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD])
-		pr_out_u64(dl, "grace_period",
-			   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]));
-	if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])
-		pr_out_bool(dl, "auto_recover",
-			    mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]));
-
-	__pr_out_indent_dec();
-	pr_out_handle_end(dl);
-}
-
-static int cmd_health_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct dl *dl = data;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_HEALTH_REPORTER])
-		return MNL_CB_ERROR;
-
-	pr_out_health(dl, tb);
-
-	return MNL_CB_OK;
-}
-
-static int cmd_health_show(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_GET,
-			       flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl,
-					DL_OPT_HANDLE |
-					DL_OPT_HEALTH_REPORTER_NAME, 0);
-		if (err)
-			return err;
-	}
-	pr_out_section_start(dl, "health");
-
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_health_show_cb, dl);
-	pr_out_section_end(dl);
-	return err;
-}
-
-static void cmd_health_help(void)
-{
-	pr_err("Usage: devlink health show [ dev DEV reporter REPORTER_NAME ]\n");
-	pr_err("       devlink health recover DEV reporter REPORTER_NAME\n");
-	pr_err("       devlink health diagnose DEV reporter REPORTER_NAME\n");
-	pr_err("       devlink health dump show DEV reporter REPORTER_NAME\n");
-	pr_err("       devlink health dump clear DEV reporter REPORTER_NAME\n");
-	pr_err("       devlink health set DEV reporter REPORTER_NAME { grace_period | auto_recover } { msec | boolean }\n");
-}
-
-static int cmd_health(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_health_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_health_show(dl);
-	} else if (dl_argv_match(dl, "recover")) {
-		dl_arg_inc(dl);
-		return cmd_health_recover(dl);
-	} else if (dl_argv_match(dl, "diagnose")) {
-		dl_arg_inc(dl);
-		return cmd_health_diagnose(dl);
-	} else if (dl_argv_match(dl, "dump")) {
-		dl_arg_inc(dl);
-		if (dl_argv_match(dl, "show")) {
-			dl_arg_inc(dl);
-			return cmd_health_dump_show(dl);
-		} else if (dl_argv_match(dl, "clear")) {
-			dl_arg_inc(dl);
-			return cmd_health_dump_clear(dl);
-		}
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_health_set_params(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static const char *trap_type_name(uint8_t type)
-{
-	switch (type) {
-	case DEVLINK_TRAP_TYPE_DROP:
-		return "drop";
-	case DEVLINK_TRAP_TYPE_EXCEPTION:
-		return "exception";
-	default:
-		return "<unknown type>";
-	}
-}
-
-static const char *trap_action_name(uint8_t action)
-{
-	switch (action) {
-	case DEVLINK_TRAP_ACTION_DROP:
-		return "drop";
-	case DEVLINK_TRAP_ACTION_TRAP:
-		return "trap";
-	default:
-		return "<unknown action>";
-	}
-}
-
-static const char *trap_metadata_name(const struct nlattr *attr)
-{
-	switch (attr->nla_type) {
-	case DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT:
-		return "input_port";
-	default:
-		return "<unknown metadata type>";
-	}
-}
-static void pr_out_trap_metadata(struct dl *dl, struct nlattr *attr)
-{
-	struct nlattr *attr_metadata;
-
-	pr_out_array_start(dl, "metadata");
-	mnl_attr_for_each_nested(attr_metadata, attr)
-		pr_out_str_value(dl, trap_metadata_name(attr_metadata));
-	pr_out_array_end(dl);
-}
-
-static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array)
-{
-	uint8_t action = mnl_attr_get_u8(tb[DEVLINK_ATTR_TRAP_ACTION]);
-	uint8_t type = mnl_attr_get_u8(tb[DEVLINK_ATTR_TRAP_TYPE]);
-
-	if (array)
-		pr_out_handle_start_arr(dl, tb);
-	else
-		__pr_out_handle_start(dl, tb, true, false);
-
-	pr_out_str(dl, "name", mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
-	pr_out_str(dl, "type", trap_type_name(type));
-	pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
-	pr_out_str(dl, "action", trap_action_name(action));
-	pr_out_str(dl, "group",
-		   mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
-	if (dl->verbose)
-		pr_out_trap_metadata(dl, tb[DEVLINK_ATTR_TRAP_METADATA]);
-	pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
-	pr_out_handle_end(dl);
-}
-
-static int cmd_trap_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct dl *dl = data;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_TRAP_NAME] || !tb[DEVLINK_ATTR_TRAP_TYPE] ||
-	    !tb[DEVLINK_ATTR_TRAP_ACTION] ||
-	    !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] ||
-	    !tb[DEVLINK_ATTR_TRAP_METADATA] || !tb[DEVLINK_ATTR_STATS])
-		return MNL_CB_ERROR;
-
-	pr_out_trap(dl, tb, true);
-
-	return MNL_CB_OK;
-}
-
-static void cmd_trap_help(void)
-{
-	pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop } ]\n");
-	pr_err("       devlink trap show [ DEV trap TRAP ]\n");
-	pr_err("       devlink trap group set DEV group GROUP [ action { trap | drop } ]\n");
-	pr_err("       devlink trap group show [ DEV group GROUP ]\n");
-}
-
-static int cmd_trap_show(struct dl *dl)
-{
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	struct nlmsghdr *nlh;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl,
-					DL_OPT_HANDLE | DL_OPT_TRAP_NAME, 0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "trap");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_show_cb, dl);
-	pr_out_section_end(dl);
-
-	return err;
-}
-
-static int cmd_trap_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_TRAP_NAME,
-				DL_OPT_TRAP_ACTION);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array)
-{
-	if (array)
-		pr_out_handle_start_arr(dl, tb);
-	else
-		__pr_out_handle_start(dl, tb, true, false);
-
-	pr_out_str(dl, "name",
-		   mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
-	pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
-	pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
-	pr_out_handle_end(dl);
-}
-
-static int cmd_trap_group_show_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-	struct dl *dl = data;
-
-	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
-	    !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] || !tb[DEVLINK_ATTR_STATS])
-		return MNL_CB_ERROR;
-
-	pr_out_trap_group(dl, tb, true);
-
-	return MNL_CB_OK;
-}
-
-static int cmd_trap_group_show(struct dl *dl)
-{
-	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	struct nlmsghdr *nlh;
-	int err;
-
-	if (dl_argc(dl) == 0)
-		flags |= NLM_F_DUMP;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GROUP_GET, flags);
-
-	if (dl_argc(dl) > 0) {
-		err = dl_argv_parse_put(nlh, dl,
-					DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME,
-					0);
-		if (err)
-			return err;
-	}
-
-	pr_out_section_start(dl, "trap_group");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_group_show_cb, dl);
-	pr_out_section_end(dl);
-
-	return err;
-}
-
-static int cmd_trap_group_set(struct dl *dl)
-{
-	struct nlmsghdr *nlh;
-	int err;
-
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GROUP_SET,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl,
-				DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME,
-				DL_OPT_TRAP_ACTION);
-	if (err)
-		return err;
-
-	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
-}
-
-static int cmd_trap_group(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_trap_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_trap_group_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_trap_group_set(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int cmd_trap(struct dl *dl)
-{
-	if (dl_argv_match(dl, "help")) {
-		cmd_trap_help();
-		return 0;
-	} else if (dl_argv_match(dl, "show") ||
-		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
-		dl_arg_inc(dl);
-		return cmd_trap_show(dl);
-	} else if (dl_argv_match(dl, "set")) {
-		dl_arg_inc(dl);
-		return cmd_trap_set(dl);
-	} else if (dl_argv_match(dl, "group")) {
-		dl_arg_inc(dl);
-		return cmd_trap_group(dl);
-	}
-	pr_err("Command \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static void help(void)
-{
-	pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
-	       "       devlink [ -f[orce] ] -b[atch] filename\n"
-	       "where  OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health | trap }\n"
-	       "       OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] }\n");
-}
-
-static int dl_cmd(struct dl *dl, int argc, char **argv)
-{
-	dl->argc = argc;
-	dl->argv = argv;
-
-	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-		help();
-		return 0;
-	} else if (dl_argv_match(dl, "dev")) {
-		dl_arg_inc(dl);
-		return cmd_dev(dl);
-	} else if (dl_argv_match(dl, "port")) {
-		dl_arg_inc(dl);
-		return cmd_port(dl);
-	} else if (dl_argv_match(dl, "sb")) {
-		dl_arg_inc(dl);
-		return cmd_sb(dl);
-	} else if (dl_argv_match(dl, "monitor")) {
-		dl_arg_inc(dl);
-		return cmd_mon(dl);
-	} else if (dl_argv_match(dl, "dpipe")) {
-		dl_arg_inc(dl);
-		return cmd_dpipe(dl);
-	} else if (dl_argv_match(dl, "resource")) {
-		dl_arg_inc(dl);
-		return cmd_resource(dl);
-	} else if (dl_argv_match(dl, "region")) {
-		dl_arg_inc(dl);
-		return cmd_region(dl);
-	} else if (dl_argv_match(dl, "health")) {
-		dl_arg_inc(dl);
-		return cmd_health(dl);
-	} else if (dl_argv_match(dl, "trap")) {
-		dl_arg_inc(dl);
-		return cmd_trap(dl);
-	}
-	pr_err("Object \"%s\" not found\n", dl_argv(dl));
-	return -ENOENT;
-}
-
-static int dl_init(struct dl *dl)
-{
-	int err;
-
-	dl->nlg = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION);
-	if (!dl->nlg) {
-		pr_err("Failed to connect to devlink Netlink\n");
-		return -errno;
-	}
-
-	err = ifname_map_init(dl);
-	if (err) {
-		pr_err("Failed to create index map\n");
-		goto err_ifname_map_create;
-	}
-	if (dl->json_output) {
-		dl->jw = jsonw_new(stdout);
-		if (!dl->jw) {
-			pr_err("Failed to create JSON writer\n");
-			goto err_json_new;
-		}
-		jsonw_pretty(dl->jw, dl->pretty_output);
-	}
-	return 0;
-
-err_json_new:
-	ifname_map_fini(dl);
-err_ifname_map_create:
-	mnlg_socket_close(dl->nlg);
-	return err;
-}
-
-static void dl_fini(struct dl *dl)
-{
-	if (dl->json_output)
-		jsonw_destroy(&dl->jw);
-	ifname_map_fini(dl);
-	mnlg_socket_close(dl->nlg);
-}
-
-static struct dl *dl_alloc(void)
-{
-	struct dl *dl;
-
-	dl = calloc(1, sizeof(*dl));
-	if (!dl)
-		return NULL;
-	return dl;
-}
-
-static void dl_free(struct dl *dl)
-{
-	free(dl);
-}
-
-static int dl_batch(struct dl *dl, const char *name, bool force)
-{
-	char *line = NULL;
-	size_t len = 0;
-	int ret = EXIT_SUCCESS;
-
-	if (name && strcmp(name, "-") != 0) {
-		if (freopen(name, "r", stdin) == NULL) {
-			fprintf(stderr,
-				"Cannot open file \"%s\" for reading: %s\n",
-				name, strerror(errno));
-			return EXIT_FAILURE;
-		}
-	}
-
-	cmdlineno = 0;
-	while (getcmdline(&line, &len, stdin) != -1) {
-		char *largv[100];
-		int largc;
-
-		largc = makeargs(line, largv, 100);
-		if (!largc)
-			continue;	/* blank line */
-
-		if (dl_cmd(dl, largc, largv)) {
-			fprintf(stderr, "Command failed %s:%d\n",
-				name, cmdlineno);
-			ret = EXIT_FAILURE;
-			if (!force)
-				break;
-		}
-	}
-
-	if (line)
-		free(line);
-
-	return ret;
-}
-
-int main(int argc, char **argv)
-{
-	static const struct option long_options[] = {
-		{ "Version",		no_argument,		NULL, 'V' },
-		{ "force",		no_argument,		NULL, 'f' },
-		{ "batch",		required_argument,	NULL, 'b' },
-		{ "no-nice-names",	no_argument,		NULL, 'n' },
-		{ "json",		no_argument,		NULL, 'j' },
-		{ "pretty",		no_argument,		NULL, 'p' },
-		{ "verbose",		no_argument,		NULL, 'v' },
-		{ "statistics",		no_argument,		NULL, 's' },
-		{ NULL, 0, NULL, 0 }
-	};
-	const char *batch_file = NULL;
-	bool force = false;
-	struct dl *dl;
-	int opt;
-	int err;
-	int ret;
-
-	dl = dl_alloc();
-	if (!dl) {
-		pr_err("Failed to allocate memory for devlink\n");
-		return EXIT_FAILURE;
-	}
-
-	while ((opt = getopt_long(argc, argv, "Vfb:njpvs",
-				  long_options, NULL)) >= 0) {
-
-		switch (opt) {
-		case 'V':
-			printf("devlink utility, iproute2-ss%s\n", SNAPSHOT);
-			ret = EXIT_SUCCESS;
-			goto dl_free;
-		case 'f':
-			force = true;
-			break;
-		case 'b':
-			batch_file = optarg;
-			break;
-		case 'n':
-			dl->no_nice_names = true;
-			break;
-		case 'j':
-			dl->json_output = true;
-			break;
-		case 'p':
-			dl->pretty_output = true;
-			break;
-		case 'v':
-			dl->verbose = true;
-			break;
-		case 's':
-			dl->stats = true;
-			break;
-		default:
-			pr_err("Unknown option.\n");
-			help();
-			ret = EXIT_FAILURE;
-			goto dl_free;
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	err = dl_init(dl);
-	if (err) {
-		ret = EXIT_FAILURE;
-		goto dl_free;
-	}
-
-	if (batch_file)
-		err = dl_batch(dl, batch_file, force);
-	else
-		err = dl_cmd(dl, argc, argv);
-
-	if (err) {
-		ret = EXIT_FAILURE;
-		goto dl_fini;
-	}
-
-	ret = EXIT_SUCCESS;
-
-dl_fini:
-	dl_fini(dl);
-dl_free:
-	dl_free(dl);
-
-	return ret;
-}
diff --git a/devlink/mnlg.c b/devlink/mnlg.c
deleted file mode 100644
index c7d25e8..0000000
--- a/devlink/mnlg.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- *   mnlg.c	Generic Netlink helpers for libmnl
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:     Jiri Pirko <jiri@mellanox.com>
- */
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <time.h>
-#include <libmnl/libmnl.h>
-#include <linux/genetlink.h>
-
-#include "libnetlink.h"
-#include "utils.h"
-#include "mnlg.h"
-
-struct mnlg_socket {
-	struct mnl_socket *nl;
-	char *buf;
-	uint32_t id;
-	uint8_t version;
-	unsigned int seq;
-	unsigned int portid;
-};
-
-static struct nlmsghdr *__mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
-					   uint16_t flags, uint32_t id,
-					   uint8_t version)
-{
-	struct nlmsghdr *nlh;
-	struct genlmsghdr *genl;
-
-	nlh = mnl_nlmsg_put_header(nlg->buf);
-	nlh->nlmsg_type	= id;
-	nlh->nlmsg_flags = flags;
-	nlg->seq = time(NULL);
-	nlh->nlmsg_seq = nlg->seq;
-
-	genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr));
-	genl->cmd = cmd;
-	genl->version = version;
-
-	return nlh;
-}
-
-struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
-				  uint16_t flags)
-{
-	return __mnlg_msg_prepare(nlg, cmd, flags, nlg->id, nlg->version);
-}
-
-int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh)
-{
-	return mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
-}
-
-static int mnlg_cb_noop(const struct nlmsghdr *nlh, void *data)
-{
-	return MNL_CB_OK;
-}
-
-static int mnlg_cb_error(const struct nlmsghdr *nlh, void *data)
-{
-	const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
-
-	/* Netlink subsystems returns the errno value with different signess */
-	if (err->error < 0)
-		errno = -err->error;
-	else
-		errno = err->error;
-
-	if (nl_dump_ext_ack(nlh, NULL))
-		return MNL_CB_ERROR;
-
-	return err->error == 0 ? MNL_CB_STOP : MNL_CB_ERROR;
-}
-
-static int mnlg_cb_stop(const struct nlmsghdr *nlh, void *data)
-{
-	int len = *(int *)NLMSG_DATA(nlh);
-
-	if (len < 0) {
-		errno = -len;
-		nl_dump_ext_ack_done(nlh, len);
-		return MNL_CB_ERROR;
-	}
-	return MNL_CB_STOP;
-}
-
-static mnl_cb_t mnlg_cb_array[NLMSG_MIN_TYPE] = {
-	[NLMSG_NOOP]	= mnlg_cb_noop,
-	[NLMSG_ERROR]	= mnlg_cb_error,
-	[NLMSG_DONE]	= mnlg_cb_stop,
-	[NLMSG_OVERRUN]	= mnlg_cb_noop,
-};
-
-int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data)
-{
-	int err;
-
-	do {
-		err = mnl_socket_recvfrom(nlg->nl, nlg->buf,
-					  MNL_SOCKET_BUFFER_SIZE);
-		if (err <= 0)
-			break;
-		err = mnl_cb_run2(nlg->buf, err, nlg->seq, nlg->portid,
-				  data_cb, data, mnlg_cb_array,
-				  ARRAY_SIZE(mnlg_cb_array));
-	} while (err > 0);
-
-	return err;
-}
-
-struct group_info {
-	bool found;
-	uint32_t id;
-	const char *name;
-};
-
-static int parse_mc_grps_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	int type = mnl_attr_get_type(attr);
-
-	if (mnl_attr_type_valid(attr, CTRL_ATTR_MCAST_GRP_MAX) < 0)
-		return MNL_CB_OK;
-
-	switch (type) {
-	case CTRL_ATTR_MCAST_GRP_ID:
-		if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
-			return MNL_CB_ERROR;
-		break;
-	case CTRL_ATTR_MCAST_GRP_NAME:
-		if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
-			return MNL_CB_ERROR;
-		break;
-	}
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-static void parse_genl_mc_grps(struct nlattr *nested,
-			       struct group_info *group_info)
-{
-	struct nlattr *pos;
-	const char *name;
-
-	mnl_attr_for_each_nested(pos, nested) {
-		struct nlattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1] = {};
-
-		mnl_attr_parse_nested(pos, parse_mc_grps_cb, tb);
-		if (!tb[CTRL_ATTR_MCAST_GRP_NAME] ||
-		    !tb[CTRL_ATTR_MCAST_GRP_ID])
-			continue;
-
-		name = mnl_attr_get_str(tb[CTRL_ATTR_MCAST_GRP_NAME]);
-		if (strcmp(name, group_info->name) != 0)
-			continue;
-
-		group_info->id = mnl_attr_get_u32(tb[CTRL_ATTR_MCAST_GRP_ID]);
-		group_info->found = true;
-	}
-}
-
-static int get_group_id_attr_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	int type = mnl_attr_get_type(attr);
-
-	if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
-		return MNL_CB_ERROR;
-
-	if (type == CTRL_ATTR_MCAST_GROUPS &&
-	    mnl_attr_validate(attr, MNL_TYPE_NESTED) < 0)
-		return MNL_CB_ERROR;
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-static int get_group_id_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct group_info *group_info = data;
-	struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), get_group_id_attr_cb, tb);
-	if (!tb[CTRL_ATTR_MCAST_GROUPS])
-		return MNL_CB_ERROR;
-	parse_genl_mc_grps(tb[CTRL_ATTR_MCAST_GROUPS], group_info);
-	return MNL_CB_OK;
-}
-
-int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name)
-{
-	struct nlmsghdr *nlh;
-	struct group_info group_info;
-	int err;
-
-	nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY,
-				 NLM_F_REQUEST | NLM_F_ACK, GENL_ID_CTRL, 1);
-	mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, nlg->id);
-
-	err = mnlg_socket_send(nlg, nlh);
-	if (err < 0)
-		return err;
-
-	group_info.found = false;
-	group_info.name = group_name;
-	err = mnlg_socket_recv_run(nlg, get_group_id_cb, &group_info);
-	if (err < 0)
-		return err;
-
-	if (!group_info.found) {
-		errno = ENOENT;
-		return -1;
-	}
-
-	err = mnl_socket_setsockopt(nlg->nl, NETLINK_ADD_MEMBERSHIP,
-				    &group_info.id, sizeof(group_info.id));
-	if (err < 0)
-		return err;
-
-	return 0;
-}
-
-static int get_family_id_attr_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	int type = mnl_attr_get_type(attr);
-
-	if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
-		return MNL_CB_ERROR;
-
-	if (type == CTRL_ATTR_FAMILY_ID &&
-	    mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
-		return MNL_CB_ERROR;
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-static int get_family_id_cb(const struct nlmsghdr *nlh, void *data)
-{
-	uint32_t *p_id = data;
-	struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
-	mnl_attr_parse(nlh, sizeof(*genl), get_family_id_attr_cb, tb);
-	if (!tb[CTRL_ATTR_FAMILY_ID])
-		return MNL_CB_ERROR;
-	*p_id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
-	return MNL_CB_OK;
-}
-
-struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version)
-{
-	struct mnlg_socket *nlg;
-	struct nlmsghdr *nlh;
-	int one = 1;
-	int err;
-
-	nlg = malloc(sizeof(*nlg));
-	if (!nlg)
-		return NULL;
-
-	nlg->buf = malloc(MNL_SOCKET_BUFFER_SIZE);
-	if (!nlg->buf)
-		goto err_buf_alloc;
-
-	nlg->nl = mnl_socket_open(NETLINK_GENERIC);
-	if (!nlg->nl)
-		goto err_mnl_socket_open;
-
-	/* Older kernels may no support capped/extended ACK reporting */
-	mnl_socket_setsockopt(nlg->nl, NETLINK_CAP_ACK, &one, sizeof(one));
-	mnl_socket_setsockopt(nlg->nl, NETLINK_EXT_ACK, &one, sizeof(one));
-
-	err = mnl_socket_bind(nlg->nl, 0, MNL_SOCKET_AUTOPID);
-	if (err < 0)
-		goto err_mnl_socket_bind;
-
-	nlg->portid = mnl_socket_get_portid(nlg->nl);
-
-	nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY,
-				 NLM_F_REQUEST | NLM_F_ACK, GENL_ID_CTRL, 1);
-	mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, family_name);
-
-	err = mnlg_socket_send(nlg, nlh);
-	if (err < 0)
-		goto err_mnlg_socket_send;
-
-	err = mnlg_socket_recv_run(nlg, get_family_id_cb, &nlg->id);
-	if (err < 0)
-		goto err_mnlg_socket_recv_run;
-
-	nlg->version = version;
-	return nlg;
-
-err_mnlg_socket_recv_run:
-err_mnlg_socket_send:
-err_mnl_socket_bind:
-	mnl_socket_close(nlg->nl);
-err_mnl_socket_open:
-	free(nlg->buf);
-err_buf_alloc:
-	free(nlg);
-	return NULL;
-}
-
-void mnlg_socket_close(struct mnlg_socket *nlg)
-{
-	mnl_socket_close(nlg->nl);
-	free(nlg->buf);
-	free(nlg);
-}
-
-int mnlg_socket_get_fd(struct mnlg_socket *nlg)
-{
-	return mnl_socket_get_fd(nlg->nl);
-}
diff --git a/devlink/mnlg.h b/devlink/mnlg.h
deleted file mode 100644
index 61bc5a3..0000000
--- a/devlink/mnlg.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *   mnlg.h	Generic Netlink helpers for libmnl
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:     Jiri Pirko <jiri@mellanox.com>
- */
-
-#ifndef _MNLG_H_
-#define _MNLG_H_
-
-#include <libmnl/libmnl.h>
-
-struct mnlg_socket;
-
-struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
-				  uint16_t flags);
-int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh);
-int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data);
-int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name);
-struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version);
-void mnlg_socket_close(struct mnlg_socket *nlg);
-int mnlg_socket_get_fd(struct mnlg_socket *nlg);
-
-#endif /* _MNLG_H_ */
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..e9c0ff7
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,73 @@
+PSFILES=ip-cref.ps ip-tunnels.ps api-ip6-flowlabels.ps ss.ps nstat.ps arpd.ps rtstat.ps
+# tc-cref.ps
+# api-rtnl.tex api-pmtudisc.tex api-news.tex
+# iki-netdev.ps iki-neighdst.ps
+
+
+LATEX=latex
+DVIPS=dvips
+SGML2DVI=sgml2latex
+SGML2HTML=sgml2html -s 0
+LPR=lpr -Zsduplex
+SHELL=bash
+PAGESIZE=a4
+PAGESPERPAGE=2
+
+HTMLFILES=$(subst .sgml,.html,$(shell echo *.sgml))
+DVIFILES=$(subst .ps,.dvi,$(PSFILES))
+PDFFILES=$(subst .ps,.pdf,$(PSFILES))
+
+
+all: pstwocol
+
+pstwocol: $(PSFILES)
+
+html: $(HTMLFILES)
+
+dvi: $(DVIFILES)
+
+pdf: $(PDFFILES)
+
+print: $(PSFILES)
+	$(LPR) $(PSFILES)
+
+%.tex: %.sgml
+	$(SGML2DVI) --output=tex $<
+
+%.dvi: %.sgml
+	$(SGML2DVI) --output=dvi $<
+
+%.dvi: %.tex
+	@set -e; pass=2; echo "Running LaTeX $<"; \
+	while [ `$(LATEX) $< </dev/null 2>&1 | \
+		 grep -c '^\(LaTeX Warning: Label(s) may\|No file \|! Emergency stop\)'` -ge 1 ]; do \
+		if [ $$pass -gt 3 ]; then \
+			echo "Seems, something is wrong. Try by hands." ; exit 1 ; \
+		fi; \
+		echo "Re-running LaTeX $<, $${pass}d pass"; pass=$$[$$pass + 1]; \
+	done
+
+%.pdf: %.tex
+	@set -e; pass=2; echo "Running pdfLaTeX $<"; \
+	while [ `pdflatex $< </dev/null 2>&1 | \
+		 grep -c '^\(LaTeX Warning: Label(s) may\|No file \|! Emergency stop\)'` -ge 1 ]; do \
+		if [ $$pass -gt 3 ]; then \
+			echo "Seems, something is wrong. Try by hands." ; exit 1 ; \
+		fi; \
+		echo "Re-running pdfLaTeX $<, $${pass}d pass"; pass=$$[$$pass + 1]; \
+	done
+#%.pdf: %.ps
+#	ps2pdf $<
+
+%.ps: %.dvi
+	$(DVIPS) $< -o $@
+
+%.html: %.sgml
+	$(SGML2HTML) $<
+
+install:
+	install -m 0644 $(shell echo *.tex) $(DESTDIR)$(DOCDIR)
+	install -m 0644 $(shell echo *.sgml) $(DESTDIR)$(DOCDIR)
+
+clean:
+	rm -f *.aux *.log *.toc $(PSFILES) $(DVIFILES) *.html *.pdf
diff --git a/doc/Plan b/doc/Plan
new file mode 100644
index 0000000..55f478e
--- /dev/null
+++ b/doc/Plan
@@ -0,0 +1,16 @@
+Partially finished work.
+
+1.  User Reference manuals.
+1.1 IP Command reference (ip-cref.tex, published)
+1.2 TC Command reference (tc-cref.tex)
+1.3 IP tunnels (ip-tunnels.tex, published)
+
+2.  Linux-2.2 Networking API
+2.1 RTNETLINK (api-rtnl.tex)
+2.2 Path MTU Discovery (api-pmtudisc.tex)
+2.3 IPv6 Flow Labels (api-ip6-flowlabels.tex, published)
+2.4 Miscellaneous extensions (api-misc.tex)
+
+3.  Linux-2.2 Networking Intra-Kernel Interfaces
+3.1 NetDev --- Networking Devices and netdev... (iki-netdev.tex)
+3.2 Neighbour cache and destination cache. (iki-neighdst.tex)
diff --git a/doc/SNAPSHOT.tex b/doc/SNAPSHOT.tex
new file mode 100644
index 0000000..7ed0298
--- /dev/null
+++ b/doc/SNAPSHOT.tex
@@ -0,0 +1 @@
+\def\Draft{020116}
diff --git a/doc/actions/actions-general b/doc/actions/actions-general
index 407a514..70f7cd6 100644
--- a/doc/actions/actions-general
+++ b/doc/actions/actions-general
@@ -6,8 +6,8 @@
 -----------
 
 An extension to the filtering/classification architecture of Linux Traffic
-Control.
-Up to 2.6.8 the only action that could be "attached" to a filter was policing.
+Control. 
+Up to 2.6.8 the only action that could be "attached" to a filter was policing. 
 i.e you could say something like:
 
 -----
@@ -17,11 +17,11 @@
 
 which implies "if a packet is seen on the ingress of the lo device with
 a source IP address of 127.0.0.1/32 we give it a classification id  of 1:1 and
-we execute a policing action which rate limits its bandwidth utilization
+we execute a policing action which rate limits its bandwidth utilization 
 to 1.5Mbps".
 
 The new extensions allow for more than just policing actions to be added.
-They are also fully backward compatible. If you have a kernel that doesn't
+They are also fully backward compatible. If you have a kernel that doesnt
 understand them, then the effect is null i.e if you have a newer tc
 but older kernel, the actions are not installed. Likewise if you
 have a newer kernel but older tc, obviously the tc will use current
@@ -29,9 +29,9 @@
 both newer tc and kernel. If you are reading this you have the
 right tc ;->
 
-A side effect is that we can now get stateless firewalling to work with tc.
+A side effect is that we can now get stateless firewalling to work with tc. 
 Essentially this is now an alternative to iptables.
-I won't go into details of my dislike for iptables at times, but
+I wont go into details of my dislike for iptables at times, but 
 scalability is one of the main issues; however, if you need stateful
 classification - use netfilter (for now).
 
@@ -61,7 +61,7 @@
 match ip src 127.0.0.1/32 flowid 1:1 \
 action police mtu 4000 rate 1500kbit burst 90k
 
-" generic Actions" (gact) at the moment are:
+" generic Actions" (gact) at the moment are: 
 { drop, pass, reclassify, continue}
 (If you have others, no listed here give me a reason and we will add them)
 +drop says to drop the packet
@@ -77,7 +77,7 @@
 In terms of hooks:
 *ingress is mapped to pre-routing hook
 *egress is mapped to post-routing hook
-I don't see much value in the other hooks, if you see it and email me good
+I dont see much value in the other hooks, if you see it and email me good
 reasons, the addition is trivial.
 
 Example syntax for iptables targets usage becomes:
@@ -93,43 +93,43 @@
 
 3) A feature i call pipe
 The motivation is derived from Unix pipe mechanism but applied to packets.
-Essentially take a matching packet and pass it through
+Essentially take a matching packet and pass it through 
 action1 | action2 | action3 etc.
 You could do something similar to this with the tc policer and the "continue"
-operator but this rather restricts it to just the policer and requires
-multiple rules (and lookups, hence quiet inefficient);
+operator but this rather restricts it to just the policer and requires 
+multiple rules (and lookups, hence quiet inefficient); 
 
-as an example -- and please note that this is just an example _not_ The
+as an example -- and please note that this is just an example _not_ The 
 Word Youve Been Waiting For (yes i have had problems giving examples
 which ended becoming dogma in documents and people modifying them a little
-to look clever);
+to look clever); 
 
-i selected the metering rates to be small so that i can show better how
+i selected the metering rates to be small so that i can show better how 
 things work.
+ 
+The script below does the following: 
+- an incoming packet from 10.0.0.21 is first given a firewall mark of 1. 
 
-The script below does the following:
-- an incoming packet from 10.0.0.21 is first given a firewall mark of 1.
+- It is then metered to make sure it does not exceed its allocated rate of 
+1Kbps. If it doesnt exceed rate, this is where we terminate action execution.
 
-- It is then metered to make sure it does not exceed its allocated rate of
-1Kbps. If it doesn't exceed rate, this is where we terminate action execution.
-
-- If it does exceed its rate, its "color" changes to a mark of 2 and it is
+- If it does exceed its rate, its "color" changes to a mark of 2 and it is 
 then passed through a second meter.
 
--The second meter is shared across all flows on that device [i am surpised
-that this seems to be not a well know feature of the policer; Bert was telling
+-The second meter is shared across all flows on that device [i am suprised 
+that this seems to be not a well know feature of the policer; Bert was telling 
 me that someone was writing a qdisc just to do sharing across multiple devices;
 it must be the summer heat again; weve had someone doing that every year around
-summer  -- the key to sharing is to use a operator "index" in your policer
-rules (example "index 20"). All your rules have to use the same index to
+summer  -- the key to sharing is to use a operator "index" in your policer 
+rules (example "index 20"). All your rules have to use the same index to 
 share.]
-
+ 
 -If the second meter is exceeded the color of the flow changes further to 3.
 
 -We then pass the packet to another meter which is shared across all devices
 in the system. If this meter is exceeded we drop the packet.
 
-Note the mark can be used further up the system to do things like policy
+Note the mark can be used further up the system to do things like policy 
 or more interesting things on the egress.
 
 ------------------ cut here -------------------------------
@@ -145,7 +145,7 @@
 action ipt -j mark --set-mark 1 index 2 \
 #
 # then pass it through a policer which allows 1kbps; if the flow
-# doesn't exceed that rate, this is where we stop, if it exceeds we
+# doesnt exceed that rate, this is where we stop, if it exceeds we
 # pipe the packet to the next action
 action police rate 1kbit burst 9k pipe \
 #
@@ -161,31 +161,31 @@
 # and then attempt to borrow from a meter used by all devices in the
 # system. Should this be exceeded, drop the packet on the floor.
 action police index 20 mtu 5000 rate 1kbit burst 90k drop
----------------------------------
+--------------------------------- 
 
-Now lets see the actions installed with
+Now lets see the actions installed with 
 "tc filter show parent ffff: dev eth0"
 
 -------- output -----------
 jroot# tc filter show parent ffff: dev eth0
-filter protocol ip pref 1 u32
-filter protocol ip pref 1 u32 fh 800: ht divisor 1
-filter protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:15
+filter protocol ip pref 1 u32 
+filter protocol ip pref 1 u32 fh 800: ht divisor 1 
+filter protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:15 
 
-   action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING
+   action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING 
         target MARK set 0x1  index 2
 
-   action order 2: police 1 action pipe rate 1Kbit burst 9Kb mtu 2Kb
+   action order 2: police 1 action pipe rate 1Kbit burst 9Kb mtu 2Kb 
 
-   action order 3: tablename: mangle  hook: NF_IP_PRE_ROUTING
+   action order 3: tablename: mangle  hook: NF_IP_PRE_ROUTING 
         target MARK set 0x2  index 1
 
-   action order 4: police 30 action pipe rate 1Kbit burst 10Kb mtu 5000b
+   action order 4: police 30 action pipe rate 1Kbit burst 10Kb mtu 5000b 
 
-   action order 5: tablename: mangle  hook: NF_IP_PRE_ROUTING
+   action order 5: tablename: mangle  hook: NF_IP_PRE_ROUTING 
         target MARK set 0x3  index 3
 
-   action order 6: police 20 action drop rate 1Kbit burst 90Kb mtu 5000b
+   action order 6: police 20 action drop rate 1Kbit burst 90Kb mtu 5000b 
 
   match 0a000015/ffffffff at 12
 -------------------------------
@@ -209,31 +209,31 @@
 
 --------------
 jroot# tc -s filter show parent ffff: dev eth0
-filter protocol ip pref 1 u32
-filter protocol ip pref 1 u32 fh 800: ht divisor 1
+filter protocol ip pref 1 u32 
+filter protocol ip pref 1 u32 fh 800: ht divisor 1 
 filter protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
-5
+5 
 
-   action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING
+   action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING 
         target MARK set 0x1  index 2
-         Sent 188832 bytes 2248 pkts (dropped 0, overlimits 0)
+         Sent 188832 bytes 2248 pkts (dropped 0, overlimits 0) 
 
-   action order 2: police 1 action pipe rate 1Kbit burst 9Kb mtu 2Kb
-         Sent 188832 bytes 2248 pkts (dropped 0, overlimits 2122)
+   action order 2: police 1 action pipe rate 1Kbit burst 9Kb mtu 2Kb 
+         Sent 188832 bytes 2248 pkts (dropped 0, overlimits 2122) 
 
-   action order 3: tablename: mangle  hook: NF_IP_PRE_ROUTING
+   action order 3: tablename: mangle  hook: NF_IP_PRE_ROUTING 
         target MARK set 0x2  index 1
-         Sent 178248 bytes 2122 pkts (dropped 0, overlimits 0)
+         Sent 178248 bytes 2122 pkts (dropped 0, overlimits 0) 
 
-   action order 4: police 30 action pipe rate 1Kbit burst 10Kb mtu 5000b
-         Sent 178248 bytes 2122 pkts (dropped 0, overlimits 1945)
+   action order 4: police 30 action pipe rate 1Kbit burst 10Kb mtu 5000b 
+         Sent 178248 bytes 2122 pkts (dropped 0, overlimits 1945) 
 
-   action order 5: tablename: mangle  hook: NF_IP_PRE_ROUTING
+   action order 5: tablename: mangle  hook: NF_IP_PRE_ROUTING 
         target MARK set 0x3  index 3
-         Sent 163380 bytes 1945 pkts (dropped 0, overlimits 0)
+         Sent 163380 bytes 1945 pkts (dropped 0, overlimits 0) 
 
-   action order 6: police 20 action drop rate 1Kbit burst 90Kb mtu 5000b
-         Sent 163380 bytes 1945 pkts (dropped 0, overlimits 437)
+   action order 6: police 20 action drop rate 1Kbit burst 90Kb mtu 5000b 
+         Sent 163380 bytes 1945 pkts (dropped 0, overlimits 437) 
 
   match 0a000015/ffffffff at 12
 -------------------------------
@@ -241,7 +241,7 @@
 Neat, eh?
 
 
-Want to  write an action module?
+Wanna write an action module?
 ------------------------------
 Its easy. Either look at the code or send me email. I will document at
 some point; will also accept documentation.
@@ -254,3 +254,4 @@
 Expect new things in the spurious time i have to work on this
 (particularly around end of year when i have typically get time off
 from work).
+
diff --git a/doc/actions/gact-usage b/doc/actions/gact-usage
index 5fc3e62..de1308d 100644
--- a/doc/actions/gact-usage
+++ b/doc/actions/gact-usage
@@ -1,13 +1,13 @@
 
 gact <ACTION> [RAND] [INDEX]
 
-Where:
-	ACTION := reclassify | drop | continue | pass | ok
+Where: 
+	ACTION := reclassify | drop | continue | pass | ok 
 	RAND := random <RANDTYPE> <ACTION> <VAL>
 	RANDTYPE := netrand | determ
         VAL : = value not exceeding 10000
         INDEX := index value used
-
+      
 ACTION semantics
 - pass and ok are equivalent to accept
 - continue allows to restart classification lookup
@@ -42,14 +42,14 @@
          random type none pass val 0
          index 1 ref 1 bind 1 installed 59 sec used 35 sec
          Sent 1680 bytes 20 pkts (dropped 20, overlimits 0 )
-
+ 
 ----
 
 # example 2
 #allow 1 out 10 randomly using the netrand generator
 tc filter add dev eth0 parent ffff: protocol ip prio 6 u32 match ip src \
 10.0.0.9/32 flowid 1:16 action drop random netrand ok 10
-
+ 
 ping -c 20 10.0.0.9
 
 ----
@@ -59,14 +59,14 @@
          random type netrand pass val 10
          index 5 ref 1 bind 1 installed 49 sec used 25 sec
          Sent 1680 bytes 20 pkts (dropped 16, overlimits 0 )
-
+                                                                                
 --------
 #alternative: deterministically accept every second packet
 tc filter add dev eth0 parent ffff: protocol ip prio 6 u32 match ip src \
 10.0.0.9/32 flowid 1:16 action drop random determ ok 2
-
+                                                                                
 ping -c 20 10.0.0.9
-
+                                                                                
 tc -s filter show parent ffff: dev eth0
 -----
 filter protocol ip pref 6 u32 filter protocol ip pref 6 u32 fh 800: ht divisor 1filter protocol ip pref 6 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:16  (rule hit 20 success 20)
@@ -76,3 +76,4 @@
          index 4 ref 1 bind 1 installed 118 sec used 82 sec
          Sent 1680 bytes 20 pkts (dropped 10, overlimits 0 )
 -----
+
diff --git a/doc/actions/ifb-README b/doc/actions/ifb-README
index 5fe9171..3d01179 100644
--- a/doc/actions/ifb-README
+++ b/doc/actions/ifb-README
@@ -6,47 +6,47 @@
 Known IMQ/IFB USES
 ------------------
 
-As far as i know the reasons listed below is why people use IMQ.
+As far as i know the reasons listed below is why people use IMQ. 
 It would be nice to know of anything else that i missed.
 
 1) qdiscs/policies that are per device as opposed to system wide.
 IFB allows for sharing.
 
 2) Allows for queueing incoming traffic for shaping instead of
-dropping. I am not aware of any study that shows policing is
+dropping. I am not aware of any study that shows policing is 
 worse than shaping in achieving the end goal of rate control.
 I would be interested if anyone is experimenting.
 
-3) Very interesting use: if you are serving p2p you may want to give
-preference to your own locally originated traffic (when responses come back)
+3) Very interesting use: if you are serving p2p you may wanna give 
+preference to your own localy originated traffic (when responses come back)
 vs someone using your system to do bittorent. So QoSing based on state
-comes in as the solution. What people did to achieve this was stick
+comes in as the solution. What people did to achive this was stick
 the IMQ somewhere prelocal hook.
 I think this is a pretty neat feature to have in Linux in general.
 (i.e not just for IMQ).
-But i won't go back to putting netfilter hooks in the device to satisfy
-this.  I also don't think its worth it hacking ifb some more to be
+But i wont go back to putting netfilter hooks in the device to satisfy
+this.  I also dont think its worth it hacking ifb some more to be 
 aware of say L3 info and play ip rule tricks to achieve this.
---> Instead the plan is to have a conntrack related action. This action will
-selectively either query/create conntrack state on incoming packets.
-Packets could then be redirected to ifb based on what happens -> eg
-on incoming packets; if we find they are of known state we could send to
-a different queue than one which didn't have existing state. This
+--> Instead the plan is to have a contrack related action. This action will
+selectively either query/create contrack state on incoming packets. 
+Packets could then be redirected to ifb based on what happens -> eg 
+on incoming packets; if we find they are of known state we could send to 
+a different queue than one which didnt have existing state. This
 all however is dependent on whatever rules the admin enters.
 
 At the moment this 3rd function does not exist yet. I have decided that
-instead of sitting on the patch for another year, to release it and then
-if there is pressure i will add this feature.
+instead of sitting on the patch for another year, to release it and then 
+if theres pressure i will add this feature.
 
 An example, to provide functionality that most people use IMQ for below:
 
 --------
 export TC="/sbin/tc"
 
-$TC qdisc add dev ifb0 root handle 1: prio
+$TC qdisc add dev ifb0 root handle 1: prio 
 $TC qdisc add dev ifb0 parent 1:1 handle 10: sfq
 $TC qdisc add dev ifb0 parent 1:2 handle 20: tbf rate 20kbit buffer 1600 limit 3000
-$TC qdisc add dev ifb0 parent 1:3 handle 30: sfq
+$TC qdisc add dev ifb0 parent 1:3 handle 30: sfq                                
 $TC filter add dev ifb0 protocol ip pref 1 parent 1: handle 1 fw classid 1:1
 $TC filter add dev ifb0 protocol ip pref 2 parent 1: handle 2 fw classid 1:2
 
@@ -54,7 +54,7 @@
 
 $TC qdisc add dev eth0 ingress
 
-# redirect all IP packets arriving in eth0 to ifb0
+# redirect all IP packets arriving in eth0 to ifb0 
 # use mark 1 --> puts them onto class 1:1
 $TC filter add dev eth0 parent ffff: protocol ip prio 10 u32 \
 match u32 0 0 flowid 1:1 \
@@ -77,44 +77,44 @@
 --- 10.22 ping statistics ---
 3 packets transmitted, 3 packets received, 0% packet loss
 round-trip min/avg/max = 0.6/1.3/2.8 ms
-[root@jzny action-tests]#
+[root@jzny action-tests]# 
 -----
 Now look at some stats:
 
 ---
 [root@jmandrake]:~# $TC -s filter show parent ffff: dev eth0
-filter protocol ip pref 10 u32
-filter protocol ip pref 10 u32 fh 800: ht divisor 1
-filter protocol ip pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
+filter protocol ip pref 10 u32 
+filter protocol ip pref 10 u32 fh 800: ht divisor 1 
+filter protocol ip pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 
   match 00000000/00000000 at 0
-        action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING
-        target MARK set 0x1
-        index 1 ref 1 bind 1 installed 4195sec  used 27sec
-         Sent 252 bytes 3 pkts (dropped 0, overlimits 0)
+        action order 1: tablename: mangle  hook: NF_IP_PRE_ROUTING 
+        target MARK set 0x1  
+        index 1 ref 1 bind 1 installed 4195sec  used 27sec 
+         Sent 252 bytes 3 pkts (dropped 0, overlimits 0) 
 
         action order 2: mirred (Egress Redirect to device ifb0) stolen
         index 1 ref 1 bind 1 installed 165 sec used 27 sec
-         Sent 252 bytes 3 pkts (dropped 0, overlimits 0)
+         Sent 252 bytes 3 pkts (dropped 0, overlimits 0) 
 
 [root@jmandrake]:~# $TC -s qdisc
-qdisc sfq 30: dev ifb0 limit 128p quantum 1514b
- Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
-qdisc tbf 20: dev ifb0 rate 20Kbit burst 1575b lat 2147.5s
- Sent 210 bytes 3 pkts (dropped 0, overlimits 0)
-qdisc sfq 10: dev ifb0 limit 128p quantum 1514b
- Sent 294 bytes 3 pkts (dropped 0, overlimits 0)
+qdisc sfq 30: dev ifb0 limit 128p quantum 1514b 
+ Sent 0 bytes 0 pkts (dropped 0, overlimits 0) 
+qdisc tbf 20: dev ifb0 rate 20Kbit burst 1575b lat 2147.5s 
+ Sent 210 bytes 3 pkts (dropped 0, overlimits 0) 
+qdisc sfq 10: dev ifb0 limit 128p quantum 1514b 
+ Sent 294 bytes 3 pkts (dropped 0, overlimits 0) 
 qdisc prio 1: dev ifb0 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
- Sent 504 bytes 6 pkts (dropped 0, overlimits 0)
-qdisc ingress ffff: dev eth0 ----------------
- Sent 308 bytes 5 pkts (dropped 0, overlimits 0)
+ Sent 504 bytes 6 pkts (dropped 0, overlimits 0) 
+qdisc ingress ffff: dev eth0 ---------------- 
+ Sent 308 bytes 5 pkts (dropped 0, overlimits 0) 
 
 [root@jmandrake]:~# ifconfig ifb0
-ifb0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00
+ifb0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
           inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
           UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
           RX packets:6 errors:0 dropped:3 overruns:0 frame:0
           TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
-          collisions:0 txqueuelen:32
+          collisions:0 txqueuelen:32 
           RX bytes:504 (504.0 b)  TX bytes:252 (252.0 b)
 -----
 
diff --git a/doc/actions/mirred-usage b/doc/actions/mirred-usage
index 482ff66..2622c43 100644
--- a/doc/actions/mirred-usage
+++ b/doc/actions/mirred-usage
@@ -7,10 +7,10 @@
 on more than just a port (eg a 5 tuple classifier). They may also be
 capable of redirecting.
 
-Usage:
+Usage: 
 
-mirred <DIRECTION> <ACTION> [index INDEX] <dev DEVICENAME>
-where:
+mirred <DIRECTION> <ACTION> [index INDEX] <dev DEVICENAME> 
+where: 
 DIRECTION := <ingress | egress>
 ACTION := <mirror | redirect>
 INDEX is the specific policy instance id
@@ -18,7 +18,7 @@
 
 Direction:
 - Ingress is not supported at the moment. It will be in the
-future as well as mirror/redirecting to a socket.
+future as well as mirror/redirecting to a socket. 
 
 Action:
 - Mirror takes a copy of the packet and sends it to specified
@@ -26,17 +26,17 @@
 - redirect
 steals the packet and redirects to specified destination dev.
 
-What NOT to do if you don't want your machine to crash:
+What NOT to do if you dont want your machine to crash:
 ------------------------------------------------------
 
-Do not create loops!
+Do not create loops! 
 Loops are not hard to create in the egress qdiscs.
 
-Here are simple rules to follow if you don't want to get
+Here are simple rules to follow if you dont want to get
 hurt:
 A) Do not have the same packet go to same netdevice twice
 in a single graph of policies. Your machine will just hang!
-This is design intent _not a bug_ to teach you some lessons.
+This is design intent _not a bug_ to teach you some lessons. 
 
 In the future if there are easy ways to do this in the kernel
 without affecting other packets not interested in this feature
@@ -51,7 +51,7 @@
 Remember that IFB is a very specialized case of packet redirecting
 device. Instead of redirecting it puts packets at the exact spot
 on the stack it found them from.
-Redirecting from ifbX->ifbY will actually not crash your machine but your
+Redirecting from ifbX->ifbY will actually not crash your machine but your 
 packets will all be dropped (this is much simpler to detect
 and resolve and is only affecting users of ifb as opposed to the
 whole stack).
@@ -64,7 +64,7 @@
 
 1) Mirror all packets arriving on eth0 to be sent out on eth1.
 You may have a sniffer or some accounting box hooked up on eth1.
-
+ 
 ---
 tc qdisc add dev eth0 ingress
 tc filter add dev eth0 parent ffff: protocol ip prio 10 u32 \
@@ -100,7 +100,7 @@
 3) Even more funky example:
 
 #
-#allow 1 out 10 packets on ingress of lo to randomly make it to the
+#allow 1 out 10 packets on ingress of lo to randomly make it to the 
 # host A (Randomness uses the netrand generator)
 #
 ---
@@ -111,9 +111,9 @@
 ---
 
 4)
-# for packets from 10.0.0.9 going out on eth0 (could be local
-# IP or something # we are forwarding) -
-# if exceeding a 100Kbps rate, then redirect to eth1
+# for packets from 10.0.0.9 going out on eth0 (could be local 
+# IP or something # we are forwarding) - 
+# if exceeding a 100Kbps rate, then redirect to eth1 
 #
 
 ---
@@ -129,7 +129,7 @@
 This is a very useful debug feature.
 
 Lets say you are policing packets from alias 192.168.200.200/32
-you don't want those to exceed 100kbps going out.
+you dont want those to exceed 100kbps going out.
 
 ---
 tc qdisc add dev eth0 handle 1:0 root prio
@@ -158,7 +158,7 @@
 BSDs speacialized log device does without needing one).
 
 If you replace mirror with redirect, those packets will be
-blackholed and will never make it out.
+blackholed and will never make it out. 
 
 cheers,
 jamal
diff --git a/doc/api-ip6-flowlabels.tex b/doc/api-ip6-flowlabels.tex
new file mode 100644
index 0000000..aa34e94
--- /dev/null
+++ b/doc/api-ip6-flowlabels.tex
@@ -0,0 +1,429 @@
+\documentstyle[12pt,twoside]{article}
+\def\TITLE{IPv6 Flow Labels}
+\input preamble
+\begin{center}
+\Large\bf IPv6 Flow Labels in Linux-2.2.
+\end{center}
+
+
+\begin{center}
+{ \large Alexey~N.~Kuznetsov } \\
+\em Institute for Nuclear Research, Moscow \\
+\verb|kuznet@ms2.inr.ac.ru| \\
+\rm April 11, 1999
+\end{center}
+
+\vspace{5mm}
+
+\tableofcontents
+
+\section{Introduction.}
+
+Every IPv6 packet carries 28 bits of flow information. RFC2460 splits
+these bits to two fields: 8 bits of traffic class (or DS field, if you
+prefer this term) and 20 bits of flow label. Currently there exist
+no well-defined API to manage IPv6 flow information. In this document
+I describe an attempt to design the API for Linux-2.2 IPv6 stack.
+
+\vskip 1mm
+
+The API must solve the following tasks:
+
+\begin{enumerate}
+
+\item To allow user to set traffic class bits.
+
+\item To allow user to read traffic class bits of received packets.
+This feature is not so useful as the first one, however it will be
+necessary f.e.\ to implement ECN [RFC2481] for datagram oriented services
+or to implement receiver side of SRP or another end-to-end protocol
+using traffic class bits.
+
+\item To assign flow labels to packets sent by user.
+
+\item To get flow labels of received packets. I do not know
+any applications of this feature, but it is possible that receiver will
+want to use flow labels to distinguish sub-flows.
+
+\item To allocate flow labels in the way, compliant to RFC2460. Namely:
+
+\begin{itemize}
+\item
+Flow labels must be uniformly distributed (pseudo-)random numbers,
+so that any subset of 20 bits can be used as hash key.
+
+\item
+Flows with coinciding source address and flow label must have identical
+destination address and not-fragmentable extensions headers (i.e.\ 
+hop by hop options and all the headers up to and including routing header,
+if it is present.)
+
+\begin{NB}
+There is a hole in specs: some hop-by-hop options can be
+defined only on per-packet base (f.e.\  jumbo payload option).
+Essentially, it means that such options cannot present in packets
+with flow labels.
+\end{NB}
+\begin{NB}
+NB notes here and below reflect only my personal opinion,
+they should be read with smile or should not be read at all :-).
+\end{NB}
+
+
+\item
+Flow labels have finite lifetime and source is not allowed to reuse
+flow label for another flow within the maximal lifetime has expired,
+so that intermediate nodes will be able to invalidate flow state before
+the label is taken over by another flow.
+Flow state, including lifetime, is propagated along datagram path
+by some application specific methods
+(f.e.\ in RSVP PATH messages or in some hop-by-hop option).
+
+
+\end{itemize}
+
+\end{enumerate}
+
+\section{Sending/receiving flow information.}
+
+\paragraph{Discussion.}
+\addcontentsline{toc}{subsection}{Discussion}
+It was proposed (Where? I do not remember any explicit statement)
+to solve the first four tasks using
+\verb|sin6_flowinfo| field added to \verb|struct| \verb|sockaddr_in6|
+(see RFC2553).
+
+\begin{NB}
+	This method is difficult to consider as reasonable, because it
+	puts additional overhead to all the services, despite of only
+	very small subset of them (none, to be more exact) really use it.
+	It contradicts both to IETF spirit and the letter. Before RFC2553
+	one justification existed, IPv6 address alignment left 4 byte
+	hole in \verb|sockaddr_in6| in any case. Now it has no justification.
+\end{NB}
+
+We have two problems with this method. The first one is common for all OSes:
+if \verb|recvmsg()| initializes \verb|sin6_flowinfo| to flow info
+of received packet, we loose one very important property of BSD socket API,
+namely, we are not allowed to use received address for reply directly
+and have to mangle it, even if we are not interested in flowinfo subtleties.
+
+\begin{NB}
+	RFC2553 adds new requirement: to clear \verb|sin6_flowinfo|.
+	Certainly, it is not solution but rather attempt to force applications
+	to make unnecessary work. Well, as usually, one mistake in design
+	is followed by attempts	to patch the hole and more mistakes...
+\end{NB}
+
+Another problem is Linux specific. Historically Linux IPv6 did not
+initialize \verb|sin6_flowinfo| at all, so that, if kernel does not
+support flow labels, this field is not zero, but a random number.
+Some applications also did not take care about it. 
+
+\begin{NB}
+Following RFC2553 such applications can be considered as broken,
+but I still think that they are right: clearing all the address
+before filling known fields is robust but stupid solution.
+Useless wasting CPU cycles and
+memory bandwidth is not a good idea. Such patches are acceptable
+as temporary hacks, but not as standard of the future.
+\end{NB}
+
+
+\paragraph{Implementation.}
+\addcontentsline{toc}{subsection}{Implementation}
+By default Linux IPv6 does not read \verb|sin6_flowinfo| field
+assuming that common applications are not obliged to initialize it
+and are permitted to consider it as pure alignment padding.
+In order to tell kernel that application
+is aware of this field, it is necessary to set socket option
+\verb|IPV6_FLOWINFO_SEND|.
+
+\begin{verbatim}
+  int on = 1;
+  setsockopt(sock, SOL_IPV6, IPV6_FLOWINFO_SEND,
+             (void*)&on, sizeof(on));
+\end{verbatim}
+
+Linux kernel never fills \verb|sin6_flowinfo| field, when passing
+message to user space, though the kernels which support flow labels
+initialize it to zero. If user wants to get received flowinfo, he
+will set option \verb|IPV6_FLOWINFO| and after this he will receive
+flowinfo as ancillary data object of type \verb|IPV6_FLOWINFO|
+(cf.\ RFC2292).
+
+\begin{verbatim}
+  int on = 1;
+  setsockopt(sock, SOL_IPV6, IPV6_FLOWINFO, (void*)&on, sizeof(on));
+\end{verbatim}
+
+Flowinfo received and latched by a connected TCP socket also may be fetched
+with \verb|getsockopt()| \verb|IPV6_PKTOPTIONS| together with
+another optional information.
+
+Besides that, in the spirit of RFC2292 the option \verb|IPV6_FLOWINFO|
+may be used as alternative way to send flowinfo with \verb|sendmsg()| or
+to latch it with \verb|IPV6_PKTOPTIONS|.
+
+\paragraph{Note about IPv6 options and destination address.}
+\addcontentsline{toc}{subsection}{IPv6 options and destination address}
+If \verb|sin6_flowinfo| does contain not zero flow label,
+destination address in \verb|sin6_addr| and non-fragmentable
+extension headers are ignored. Instead, kernel uses the values
+cached at flow setup (see below). However, for connected sockets
+kernel prefers the values set at connection time.
+
+\paragraph{Example.}
+\addcontentsline{toc}{subsection}{Example}
+After setting socket option \verb|IPV6_FLOWINFO|
+flowlabel and DS field are received as ancillary data object
+of type \verb|IPV6_FLOWINFO| and level \verb|SOL_IPV6|.
+In the cases when it is convenient to use \verb|recvfrom(2)|,
+it is possible to replace library variant with your own one,
+sort of:
+
+\begin{verbatim}
+#include <sys/socket.h>
+#include <netinet/in6.h>
+
+size_t recvfrom(int fd, char *buf, size_t len, int flags,
+                struct sockaddr *addr, int *addrlen)
+{
+  size_t cc;
+  char cbuf[128];
+  struct cmsghdr *c;
+  struct iovec iov = { buf, len };
+  struct msghdr msg = { addr, *addrlen,
+                        &iov,  1,
+                        cbuf, sizeof(cbuf),
+                        0 };
+
+  cc = recvmsg(fd, &msg, flags);
+  if (cc < 0)
+    return cc;
+  ((struct sockaddr_in6*)addr)->sin6_flowinfo = 0;
+  *addrlen = msg.msg_namelen;
+  for (c=CMSG_FIRSTHDR(&msg); c; c = CMSG_NEXTHDR(&msg, c)) {
+    if (c->cmsg_level != SOL_IPV6 ||
+      c->cmsg_type != IPV6_FLOWINFO)
+        continue;
+    ((struct sockaddr_in6*)addr)->sin6_flowinfo = *(__u32*)CMSG_DATA(c);
+  }
+  return cc;
+}
+\end{verbatim}
+
+
+
+\section{Flow label management.}
+
+\paragraph{Discussion.}
+\addcontentsline{toc}{subsection}{Discussion}
+Requirements of RFC2460 are pretty tough. Particularly, lifetimes
+longer than boot time require to store allocated labels at stable
+storage, so that the full implementation necessarily includes user space flow
+label manager. There are at least three different approaches:
+
+\begin{enumerate}
+\item {\bf ``Cooperative''. } We could leave flow label allocation wholly
+to user space. When user needs label he requests manager directly. The approach
+is valid, but as any ``cooperative'' approach it suffers of security problems.
+
+\begin{NB}
+One idea is to disallow not privileged user to allocate flow
+labels, but instead to pass the socket to manager via \verb|SCM_RIGHTS|
+control message, so that it will allocate label and assign it to socket
+itself. Hmm... the idea is interesting.
+\end{NB}
+
+\item {\bf ``Indirect''.} Kernel redirects requests to user level daemon
+and does not install label until the daemon acknowledged the request.
+The approach is the most promising, it is especially pleasant to recognize
+parallel with IPsec API [RFC2367,Craig]. Actually, it may share API with
+IPsec.
+
+\item {\bf ``Stupid''.} To allocate labels in kernel space. It is the simplest
+method, but it suffers of two serious flaws: the first,
+we cannot lease labels with lifetimes longer than boot time, the second, 
+it is sensitive to DoS attacks. Kernel have to remember all the obsolete
+labels until their expiration and malicious user may fastly eat all the
+flow label space.
+
+\end{enumerate}
+
+Certainly, I choose the most ``stupid'' method. It is the cheapest one
+for implementor (i.e.\ me), and taking into account that flow labels
+still have no serious applications it is not useful to work on more
+advanced API, especially, taking into account that eventually we
+will get it for no fee together with IPsec.
+
+
+\paragraph{Implementation.}
+\addcontentsline{toc}{subsection}{Implementation}
+Socket option \verb|IPV6_FLOWLABEL_MGR| allows to
+request flow label manager to allocate new flow label, to reuse
+already allocated one or to delete old flow label.
+Its argument is \verb|struct| \verb|in6_flowlabel_req|:
+
+\begin{verbatim}
+struct in6_flowlabel_req
+{
+        struct in6_addr flr_dst;
+        __u32           flr_label;
+        __u8            flr_action;
+        __u8            flr_share;
+        __u16           flr_flags;
+        __u16           flr_expires;
+        __u16           flr_linger;
+        __u32         __flr_reserved;
+        /* Options in format of IPV6_PKTOPTIONS */
+};
+\end{verbatim}
+
+\begin{itemize}
+
+\item \verb|dst| is IPv6 destination address associated with the label.
+
+\item \verb|label| is flow label value in network byte order. If it is zero,
+kernel will allocate new pseudo-random number. Otherwise, kernel will try
+to lease flow label ordered by user. In this case, it is user task to provide
+necessary flow label randomness.
+
+\item \verb|action| is requested operation. Currently, only three operations
+are defined:
+
+\begin{verbatim}
+#define IPV6_FL_A_GET   0   /* Get flow label */
+#define IPV6_FL_A_PUT   1   /* Release flow label */
+#define IPV6_FL_A_RENEW 2   /* Update expire time */
+\end{verbatim}
+
+\item \verb|flags| are optional modifiers. Currently
+only \verb|IPV6_FL_A_GET| has modifiers:
+
+\begin{verbatim}
+#define IPV6_FL_F_CREATE 1   /* Allowed to create new label */
+#define IPV6_FL_F_EXCL   2   /* Do not create new label */
+\end{verbatim}
+
+
+\item \verb|share| defines who is allowed to reuse the same flow label.
+
+\begin{verbatim}
+#define IPV6_FL_S_NONE    0   /* Not defined */
+#define IPV6_FL_S_EXCL    1   /* Label is private */
+#define IPV6_FL_S_PROCESS 2   /* May be reused by this process */
+#define IPV6_FL_S_USER    3   /* May be reused by this user */
+#define IPV6_FL_S_ANY     255 /* Anyone may reuse it */
+\end{verbatim}
+
+\item \verb|linger| is time in seconds. After the last user releases flow
+label, it will not be reused with different destination and options at least
+during this time. If \verb|share| is not \verb|IPV6_FL_S_EXCL| the label
+still can be shared by another sockets. Current implementation does not allow
+unprivileged user to set linger longer than 60 sec.
+
+\item \verb|expires| is time in seconds. Flow label will be kept at least
+for this time, but it will not be destroyed before user released it explicitly
+or closed all the sockets using it. Current implementation does not allow
+unprivileged user to set timeout longer than 60 sec. Proviledged applications
+MAY set longer lifetimes, but in this case they MUST save allocated
+labels at stable storage and restore them back after reboot before the first
+application allocates new flow.
+
+\end{itemize}
+
+This structure is followed by optional extension headers associated
+with this flow label in format of \verb|IPV6_PKTOPTIONS|. Only
+\verb|IPV6_HOPOPTS|, \verb|IPV6_RTHDR| and, if \verb|IPV6_RTHDR| presents,
+\verb|IPV6_DSTOPTS| are allowed.
+
+\paragraph{Example.}
+\addcontentsline{toc}{subsection}{Example}
+ The function \verb|get_flow_label| allocates
+private flow label.
+
+\begin{verbatim}
+int get_flow_label(int fd, struct sockaddr_in6 *dst, __u32 fl)
+{
+        int on = 1;
+        struct in6_flowlabel_req freq;
+
+        memset(&freq, 0, sizeof(freq));
+        freq.flr_label = htonl(fl);
+        freq.flr_action = IPV6_FL_A_GET;
+        freq.flr_flags = IPV6_FL_F_CREATE | IPV6_FL_F_EXCL;
+        freq.flr_share = IPV6_FL_S_EXCL;
+        memcpy(&freq.flr_dst, &dst->sin6_addr, 16);
+        if (setsockopt(fd, SOL_IPV6, IPV6_FLOWLABEL_MGR,
+                       &freq, sizeof(freq)) == -1) {
+                perror ("can't lease flowlabel");
+                return -1;
+        }
+        dst->sin6_flowinfo |= freq.flr_label;
+
+        if (setsockopt(fd, SOL_IPV6, IPV6_FLOWINFO_SEND,
+                       &on, sizeof(on)) == -1) {
+                perror ("can't send flowinfo");
+
+                freq.flr_action = IPV6_FL_A_PUT;
+                setsockopt(fd, SOL_IPV6, IPV6_FLOWLABEL_MGR,
+                           &freq, sizeof(freq));
+                return -1;
+        }
+        return 0;
+}
+\end{verbatim}
+
+A bit more complicated example using routing header can be found
+in \verb|ping6| utility (\verb|iputils| package). Linux rsvpd backend
+contains an example of using operation \verb|IPV6_FL_A_RENEW|.
+
+\paragraph{Listing flow labels.} 
+\addcontentsline{toc}{subsection}{Listing flow labels}
+List of currently allocated
+flow labels may be read from \verb|/proc/net/ip6_flowlabel|.
+
+\begin{verbatim}
+Label S Owner Users Linger Expires Dst                              Opt
+A1BE5 1 0     0     6      3       3ffe2400000000010a0020fffe71fb30 0
+\end{verbatim}
+
+\begin{itemize}
+\item \verb|Label| is hexadecimal flow label value.
+\item \verb|S| is sharing style.
+\item \verb|Owner| is ID of creator, it is zero, pid or uid, depending on
+		sharing style.
+\item \verb|Users| is number of applications using the label now.
+\item \verb|Linger| is \verb|linger| of this label in seconds.
+\item \verb|Expires| is time until expiration of the label in seconds. It may
+	be negative, if the label is in use.
+\item \verb|Dst| is IPv6 destination address.
+\item \verb|Opt| is length of options, associated with the label. Option
+	data are not accessible.
+\end{itemize}
+
+
+\paragraph{Flow labels and RSVP.} 
+\addcontentsline{toc}{subsection}{Flow labels and RSVP}
+RSVP daemon supports IPv6 flow labels
+without any modifications to standard ISI RAPI. Sender must allocate
+flow label, fill corresponding sender template and submit it to local rsvp
+daemon. rsvpd will check the label and start to announce it in PATH
+messages. Rsvpd on sender node will renew the flow label, so that it will not
+be reused before path state expires and all the intermediate
+routers and receiver purge flow state.
+
+\verb|rtap| utility is modified to parse flow labels. F.e.\ if user allocated
+flow label \verb|0xA1234|, he may write:
+
+\begin{verbatim}
+RTAP> sender 3ffe:2400::1/FL0xA1234 <Tspec>
+\end{verbatim}
+
+Receiver makes reservation with command:
+\begin{verbatim}
+RTAP> reserve ff 3ffe:2400::1/FL0xA1234 <Flowspec>
+\end{verbatim}
+
+\end{document}
diff --git a/doc/arpd.sgml b/doc/arpd.sgml
new file mode 100644
index 0000000..0ab79c6
--- /dev/null
+++ b/doc/arpd.sgml
@@ -0,0 +1,130 @@
+<!doctype linuxdoc system>
+
+<article>
+
+<title>ARPD Daemon
+<author>Alexey Kuznetsov, <tt/kuznet@ms2.inr.ac.ru/
+<date>some_negative_number, 20 Sep 2001
+<abstract>
+<tt/arpd/ is daemon collecting gratuitous ARP information, saving
+it on local disk and feeding it to kernel on demand to avoid
+redundant broadcasting due to limited size of kernel ARP cache. 
+</abstract>
+
+
+<p><bf/Description/
+
+<p>The format of the command is:
+
+<tscreen><verb>
+       arpd OPTIONS [ INTERFACE [ INTERFACE ... ] ]
+</verb></tscreen>
+
+<p> <tt/OPTIONS/ are:
+
+<itemize>
+
+<item><tt/-l/ - dump <tt/arpd/ database to stdout and exit. Output consists
+of three columns: interface index, IP address and MAC address.
+Negative entries for dead hosts are also shown, in this case MAC address
+is replaced by word <tt/FAILED/ followed by colon and time when the fact
+that host is dead was proven the last time.
+
+<item><tt/-f FILE/  - read and load <tt/arpd/ database from <tt/FILE/
+in text format similar dumped by option <tt/-l/. Exit after load,
+probably listing resulting database, if option <tt/-l/ is also given.
+If <tt/FILE/ is <tt/-/, <tt/stdin/ is read to get ARP table.
+ 
+<item><tt/-b DATABASE/  - location of database file. Default location is
+<tt>/var/lib/arpd/arpd.db</tt>.
+
+<item><tt/-a NUMBER/ - <tt/arpd/ not only passively listens ARP on wire, but
+also send brodcast queries itself. <tt/NUMBER/ is number of such queries
+to make before destination is considered as dead. When <tt/arpd/ is started
+as kernel helper (i.e. with <tt/app_solicit/ enabled in <tt/sysctl/
+or even with option <tt/-k/) without this option and still did not learn enough
+information, you can observe 1 second gaps in service. Not fatal, but
+not good.
+
+<item><tt/-k/ - suppress sending broadcast queries by kernel. It takes
+sense together with option <tt/-a/.
+
+<item><tt/-n TIME/ - timeout of negative cache. When resolution fails <tt/arpd/
+suppresses further attempts to resolve for this period. It makes sense
+only together with option <tt/-k/. This timeout should not be too much
+longer than boot time of a typical host not supporting gratuitous ARP.
+Default value is 60 seconds.
+
+<item><tt/-R RATE/ - maximal steady rate of broadcasts sent by <tt/arpd/
+in packets per second. Default value is 1.
+
+<item><tt/-B NUMBER/ - number of broadcasts sent by <tt/arpd/ back to back.
+Default value is 3. Together with option <tt/-R/ this option allows
+to police broadcasting not to exceed <tt/B+R*T/ over any interval
+of time <tt/T/.
+
+</itemize>
+
+<p><tt/INTERFACE/ is name of networking inteface to watch.
+If no interfaces given, <tt/arpd/ monitors all the interfaces.
+In this case <tt/arpd/ does not adjust <tt/sysctl/ parameters,
+it is supposed user does this himself after <tt/arpd/ is started.
+
+
+<p> Signals
+
+<p> <tt/arpd/ exits gracefully syncing database and restoring adjusted
+<tt/sysctl/ parameters, when receives <tt/SIGINT/ or <tt/SIGTERM/.
+<tt/SIGHUP/ syncs database to disk. <tt/SIGUSR1/ sends some statistics
+to <tt/syslog/. Effect of another signals is undefined, they may corrupt
+database and leave <tt/sysctl/ parameters in an unpredictable state.
+
+<p> Note
+
+<p> In order to <tt/arpd/ be able to serve as ARP resolver, kernel must be
+compiled with the option <tt/CONFIG_ARPD/ and, in the case when interface list
+is not given on command line, variable <tt/app_solicit/
+on interfaces of interest should be set in <tt>/proc/sys/net/ipv4/neigh/*</tt>.
+If this is not made <tt/arpd/ still collects gratuitous ARP information
+in its database.
+
+<p> Examples
+
+<enum>
+<item> Start <tt/arpd/ to collect gratuitous ARP, but not messing
+with kernel functionality:
+
+<tscreen><verb>
+   arpd -b /var/tmp/arpd.db
+</verb></tscreen>
+
+<item> Look at result after some time:
+
+<tscreen><verb>
+   killall arpd
+   arpd -l -b /var/tmp/arpd.db
+</verb></tscreen>
+
+<item> To enable kernel helper, leaving leading role to kernel:
+
+<tscreen><verb>
+   arpd -b /var/tmp/arpd.db -a 1 eth0 eth1
+</verb></tscreen>
+
+<item> Completely replace kernel resolution on interfaces <tt/eth0/
+and <tt/eth1/. In this case kernel still does unicast probing to
+validate entries, but all the broadcast activity is suppressed
+and made under authority of <tt/arpd/: 
+
+<tscreen><verb>
+   arpd -b /var/tmp/arpd.db -a 3 -k eth0 eth1
+</verb></tscreen>
+
+This is mode which <tt/arpd/ is supposed to work normally.
+It is not default just to prevent occasional enabling of too aggressive
+mode occasionally.
+
+</enum>
+
+</article>
+
diff --git a/doc/do-psnup b/doc/do-psnup
new file mode 100644
index 0000000..2dce848
--- /dev/null
+++ b/doc/do-psnup
@@ -0,0 +1,16 @@
+#! /bin/bash
+# $1 = Temporary file . "string"
+# $2 = File to process . "string"
+# $3 = Page size . ie: a4 , letter ... "string"
+# $4 = Number of pages to fit on a single sheet . "numeric"
+
+if type psnup >&/dev/null; then
+	echo "psnup -$4 -p$3 $1 $2"
+	psnup -$4 -p$3 $1 $2
+elif type psmulti >&/dev/null; then
+	echo "psmulti $1 > $2"
+	psmulti $1 > $2
+else
+	echo "cp $1 $2"
+	cp $1 $2
+fi
diff --git a/doc/ip-cref.tex b/doc/ip-cref.tex
new file mode 100644
index 0000000..67094c9
--- /dev/null
+++ b/doc/ip-cref.tex
@@ -0,0 +1,3449 @@
+\documentstyle[12pt,twoside]{article}
+\def\TITLE{IP Command Reference}
+\input preamble
+\begin{center}
+\Large\bf IP Command Reference.
+\end{center}
+
+
+\begin{center}
+{ \large Alexey~N.~Kuznetsov } \\
+\em Institute for Nuclear Research, Moscow \\
+\verb|kuznet@ms2.inr.ac.ru| \\
+\rm April 14, 1999
+\end{center}
+
+\vspace{5mm}
+
+\tableofcontents
+
+\newpage
+
+\section{About this document}
+
+This document presents a comprehensive description of the \verb|ip| utility
+from the \verb|iproute2| package. It is not a tutorial or user's guide.
+It is a {\em dictionary\/}, not explaining terms,
+but translating them into other terms, which may also be unknown to the reader.
+However, the document is self-contained and the reader, provided they have a
+basic networking background, will find enough information
+and examples to understand and configure Linux-2.2 IP and IPv6
+networking.
+
+This document is split into sections explaining \verb|ip| commands
+and options, decrypting \verb|ip| output and containing a few examples.
+More voluminous examples and some topics, which require more elaborate
+discussion, are in the appendix.
+
+The paragraphs beginning with NB contain side notes, warnings about
+bugs and design drawbacks. They may be skipped at the first reading.
+
+\section{{\tt ip} --- command syntax}
+
+The generic form of an \verb|ip| command is:
+\begin{verbatim}
+ip [ OPTIONS ] OBJECT [ COMMAND [ ARGUMENTS ]]
+\end{verbatim}
+where \verb|OPTIONS| is a set of optional modifiers affecting the
+general behaviour of the \verb|ip| utility or changing its output. All options
+begin with the character \verb|'-'| and may be used in either long or abbreviated 
+forms. Currently, the following options are available:
+
+\begin{itemize}
+\item \verb|-V|, \verb|-Version|
+
+--- print the version of the \verb|ip| utility and exit.
+
+
+\item \verb|-s|, \verb|-stats|, \verb|-statistics|
+
+--- output more information. If the option
+appears twice or more, the amount of information increases.
+As a rule, the information is statistics or some time values.
+
+\item \verb|-d|, \verb|-details|
+
+--- output more detailed information.
+
+\item \verb|-f|, \verb|-family| followed by a protocol family
+identifier: \verb|inet|, \verb|inet6| or \verb|link|.
+
+--- enforce the protocol family to use. If the option is not present,
+the protocol family is guessed from other arguments. If the rest of the command
+line does not give enough information to guess the family, \verb|ip| falls back to the default
+one, usually \verb|inet| or \verb|any|. \verb|link| is a special family
+identifier meaning that no networking protocol is involved.
+
+\item \verb|-4|
+
+--- shortcut for \verb|-family inet|.
+
+\item \verb|-6|
+
+--- shortcut for \verb|-family inet6|.
+
+\item \verb|-0|
+
+--- shortcut for \verb|-family link|.
+
+
+\item \verb|-o|, \verb|-oneline|
+
+--- output each record on a single line, replacing line feeds
+with the \verb|'\'| character. This is convenient when you want to
+count records with \verb|wc| or to \verb|grep| the output. The trivial
+script \verb|rtpr| converts the output back into readable form.
+
+\item \verb|-r|, \verb|-resolve|
+
+--- use the system's name resolver to print DNS names instead of
+host addresses.
+
+\begin{NB}
+ Do not use this option when reporting bugs or asking for advice.
+\end{NB}
+\begin{NB}
+ \verb|ip| never uses DNS to resolve names to addresses.
+\end{NB}
+
+\item \verb|-b|, \verb|-batch FILE|
+
+--- read commands from provided file or standart input and invoke them.
+First failure will cause termination of \verb|ip|.
+In batch \verb|FILE| everything which begins with \verb|#| symbol is
+ignored and can be used for comments.
+\paragraph{Example:}
+\begin{verbatim}
+kuznet@kaiser $ cat /tmp/ip_batch.ip
+# This is a comment
+tuntap add mode tap tap1 # This is an another comment
+link set up dev tap1
+addr add 10.0.0.1/24 dev tap1
+kuznet@kaiser $ sudo ip -b /tmp/ip_batch.ip
+\end{verbatim}
+or from standart input:
+\begin{verbatim}
+kuznet@kaiser $ cat /tmp/ip_batch.ip | sudo ip -b -
+\end{verbatim}
+
+\item \verb|-force|
+
+--- don't terminate ip on errors in batch mode.
+If there were any errors during execution of the commands,
+the application return code will be non zero.
+
+\item \verb|-l|, \verb|-loops COUNT|
+
+--- specify maximum number of loops the 'ip addr flush' logic will attempt
+before giving up. The default is 10.  Zero (0) means loop until all
+addresses are removed.
+
+\end{itemize}
+
+\verb|OBJECT| is the object to manage or to get information about.
+The object types currently understood by \verb|ip| are:
+
+\begin{itemize}
+\item \verb|link| --- network device
+\item \verb|address| --- protocol (IP or IPv6) address on a device
+\item \verb|neighbour| --- ARP or NDISC cache entry
+\item \verb|route| --- routing table entry
+\item \verb|rule| --- rule in routing policy database
+\item \verb|maddress| --- multicast address
+\item \verb|mroute| --- multicast routing cache entry
+\item \verb|tunnel| --- tunnel over IP
+\end{itemize}
+
+Again, the names of all objects may be written in full or
+abbreviated form, f.e.\ \verb|address| is abbreviated as \verb|addr|
+or just \verb|a|.
+
+\verb|COMMAND| specifies the action to perform on the object.
+The set of possible actions depends on the object type.
+As a rule, it is possible to \verb|add|, \verb|delete| and
+\verb|show| (or \verb|list|) objects, but some objects
+do not allow all of these operations or have some additional commands.
+The \verb|help| command is available for all objects. It prints
+out a list of available commands and argument syntax conventions.
+
+If no command is given, some default command is assumed.
+Usually it is \verb|list| or, if the objects of this class
+cannot be listed, \verb|help|.
+
+\verb|ARGUMENTS| is a list of arguments to the command.
+The arguments depend on the command and object. There are two types of arguments:
+{\em flags\/}, consisting of a single keyword, and {\em parameters\/},
+consisting of a keyword followed by a value. For convenience,
+each command has some {\em default parameter\/}
+which may be omitted. F.e.\ parameter \verb|dev| is the default
+for the {\tt ip link} command, so {\tt ip link ls eth0} is equivalent
+to {\tt ip link ls dev eth0}.
+In the command descriptions below such parameters
+are distinguished with the marker: ``(default)''.
+
+Almost all keywords may be abbreviated with several first (or even single)
+letters. The shortcuts are convenient when \verb|ip| is used interactively,
+but they are not recommended in scripts or when reporting bugs
+or asking for advice. ``Officially'' allowed abbreviations are listed
+in the document body.
+
+
+
+\section{{\tt ip} --- error messages}
+
+\verb|ip| may fail for one of the following reasons:
+
+\begin{itemize}
+\item
+A syntax error on the command line: an unknown keyword, incorrectly formatted
+IP address {\em et al\/}. In this case \verb|ip| prints an error message
+and exits. As a rule, the error message will contain information
+about the reason for the failure. Sometimes it also prints a help page.
+
+\item
+The arguments did not pass verification for self-consistency.
+
+\item
+\verb|ip| failed to compile a kernel request from the arguments
+because the user didn't give enough information.
+
+\item
+The kernel returned an error to some syscall. In this case \verb|ip|
+prints the error message, as it is output with \verb|perror(3)|,
+prefixed with a comment and a syscall identifier.
+
+\item
+The kernel returned an error to some RTNETLINK request.
+In this case \verb|ip| prints the error message, as it is output
+with \verb|perror(3)| prefixed with ``RTNETLINK answers:''.
+
+\end{itemize}
+
+All the operations are atomic, i.e.\ 
+if the \verb|ip| utility fails, it does not change anything
+in the system. One harmful exception is \verb|ip link| command
+(Sec.\ref{IP-LINK}, p.\pageref{IP-LINK}),
+which may change only some of the device parameters given
+on command line.
+
+It is difficult to list all the error messages (especially
+syntax errors). However, as a rule, their meaning is clear
+from the context of the command.
+
+The most common mistakes are:
+
+\begin{enumerate}
+\item Netlink is not configured in the kernel. The message is:
+\begin{verbatim}
+Cannot open netlink socket: Invalid value
+\end{verbatim}
+
+\item RTNETLINK is not configured in the kernel. In this case
+one of the following messages may be printed, depending on the command:
+\begin{verbatim}
+Cannot talk to rtnetlink: Connection refused
+Cannot send dump request: Connection refused
+\end{verbatim}
+
+\item The \verb|CONFIG_IP_MULTIPLE_TABLES| option was not selected
+when configuring the kernel. In this case any attempt to use the
+\verb|ip| \verb|rule| command will fail, f.e.
+\begin{verbatim}
+kuznet@kaiser $ ip rule list
+RTNETLINK error: Invalid argument
+dump terminated
+\end{verbatim}
+
+\end{enumerate}
+
+
+\section{{\tt ip link} --- network device configuration}
+\label{IP-LINK}
+
+\paragraph{Object:} A \verb|link| is a network device and the corresponding
+commands display and change the state of devices.
+
+\paragraph{Commands:} \verb|set| and \verb|show| (or \verb|list|).
+
+\subsection{{\tt ip link set} --- change device attributes}
+
+\paragraph{Abbreviations:} \verb|set|, \verb|s|.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|dev NAME| (default)
+
+--- \verb|NAME| specifies the network device on which to operate.
+
+\item \verb|up| and \verb|down|
+
+--- change the state of the device to \verb|UP| or \verb|DOWN|.
+
+\item \verb|arp on| or \verb|arp off|
+
+--- change the \verb|NOARP| flag on the device.
+
+\begin{NB}
+This operation is {\em not allowed\/} if the device is in state \verb|UP|.
+Though neither the \verb|ip| utility nor the kernel check for this condition.
+You can get unpredictable results changing this flag while the
+device is running.
+\end{NB}
+
+\item \verb|multicast on| or \verb|multicast off|
+
+--- change the \verb|MULTICAST| flag on the device.
+
+\item \verb|dynamic on| or \verb|dynamic off|
+
+--- change the \verb|DYNAMIC| flag on the device.
+
+\item \verb|name NAME|
+
+--- change the name of the device. This operation is not
+recommended if the device is running or has some addresses
+already configured.
+
+\item \verb|txqueuelen NUMBER| or \verb|txqlen NUMBER|
+
+--- change the transmit queue length of the device.
+
+\item \verb|mtu NUMBER|
+
+--- change the MTU of the device.
+
+\item \verb|address LLADDRESS|
+
+--- change the station address of the interface.
+
+\item \verb|broadcast LLADDRESS|, \verb|brd LLADDRESS| or \verb|peer LLADDRESS|
+
+--- change the link layer broadcast address or the peer address when
+the interface is \verb|POINTOPOINT|.
+
+\vskip 1mm
+\begin{NB}
+For most devices (f.e.\ for Ethernet) changing the link layer
+broadcast address will break networking.
+Do not use it, if you do not understand what this operation really does.
+\end{NB}
+
+\item \verb|netns PID|
+
+--- move the device to the network namespace associated with the process PID.
+
+\end{itemize}
+
+\vskip 1mm
+\begin{NB}
+The \verb|PROMISC| and \verb|ALLMULTI| flags are considered
+obsolete and should not be changed administratively, though
+the {\tt ip} utility will allow that.
+\end{NB}
+
+\paragraph{Warning:} If multiple parameter changes are requested,
+\verb|ip| aborts immediately after any of the changes have failed.
+This is the only case when \verb|ip| can move the system to
+an unpredictable state. The solution is to avoid changing
+several parameters with one {\tt ip link set} call.
+
+\paragraph{Examples:}
+\begin{itemize}
+\item \verb|ip link set dummy address 00:00:00:00:00:01|
+
+--- change the station address of the interface \verb|dummy|.
+
+\item \verb|ip link set dummy up|
+
+--- start the interface \verb|dummy|.
+
+\end{itemize}
+
+
+\subsection{{\tt ip link show} --- display device attributes}
+\label{IP-LINK-SHOW}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|lst|, \verb|sh|, \verb|ls|,
+\verb|l|.
+
+\paragraph{Arguments:}
+\begin{itemize}
+\item \verb|dev NAME| (default)
+
+--- \verb|NAME| specifies the network device to show.
+If this argument is omitted all devices are listed.
+
+\item \verb|up|
+
+--- only display running interfaces.
+
+\end{itemize}
+
+
+\paragraph{Output format:}
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip link ls eth0
+3: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc cbq qlen 100
+    link/ether 00:a0:cc:66:18:78 brd ff:ff:ff:ff:ff:ff
+kuznet@alisa:~ $ ip link ls sit0
+5: sit0@NONE: <NOARP,UP> mtu 1480 qdisc noqueue
+    link/sit 0.0.0.0 brd 0.0.0.0
+kuznet@alisa:~ $ ip link ls dummy
+2: dummy: <BROADCAST,NOARP> mtu 1500 qdisc noop
+    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
+kuznet@alisa:~ $ 
+\end{verbatim}
+
+
+The number before each colon is an {\em interface index\/} or {\em ifindex\/}.
+This number uniquely identifies the interface. This is followed by the {\em interface name\/}
+(\verb|eth0|, \verb|sit0| etc.). The interface name is also
+unique at every given moment. However, the interface may disappear from the
+list (f.e.\ when the corresponding driver module is unloaded) and another
+one with the same name may be created later. Besides that,
+the administrator may change the name of any device with
+\verb|ip| \verb|link| \verb|set| \verb|name|
+to make it more intelligible.
+
+The interface name may have another name or \verb|NONE| appended 
+after the \verb|@| sign. This means that this device is bound to some other
+device,
+i.e.\ packets send through it are encapsulated and sent via the ``master''
+device. If the name is \verb|NONE|, the master is unknown.
+
+Then we see the interface {\em mtu\/} (``maximal transfer unit''). This determines
+the maximal size of data which can be sent as a single packet over this interface.
+
+{\em qdisc\/} (``queuing discipline'') shows the queuing algorithm used
+on the interface. Particularly, \verb|noqueue| means that this interface
+does not queue anything and \verb|noop| means that the interface is in blackhole
+mode i.e.\ all packets sent to it are immediately discarded.
+{\em qlen\/} is the default transmit queue length of the device measured
+in packets.
+
+The interface flags are summarized in the angle brackets.
+
+\begin{itemize}
+\item \verb|UP| --- the device is turned on. It is ready to accept
+packets for transmission and it may inject into the kernel packets received
+from other nodes on the network.
+
+\item \verb|LOOPBACK| --- the interface does not communicate with other
+hosts. All packets sent through it will be returned
+and nothing but bounced packets can be received.
+
+\item \verb|BROADCAST| --- the device has the facility to send packets
+to all hosts sharing the same link. A typical example is an Ethernet link.
+
+\item \verb|POINTOPOINT| --- the link has only two ends with one node
+attached to each end. All packets sent to this link will reach the peer
+and all packets received by us came from this single peer.
+
+If neither \verb|LOOPBACK| nor \verb|BROADCAST| nor \verb|POINTOPOINT|
+are set, the interface is assumed to be NMBA (Non-Broadcast Multi-Access).
+This is the most generic type of device and the most complicated one, because
+the host attached to a NBMA link has no means to send to anyone
+without additionally configured information.
+
+\item \verb|MULTICAST| --- is an advisory flag indicating that the interface
+is aware of multicasting i.e.\ sending packets to some subset of neighbouring
+nodes. Broadcasting is a particular case of multicasting, where the multicast
+group consists of all nodes on the link. It is important to emphasize
+that software {\em must not\/} interpret the absence of this flag as the inability
+to use multicasting on this interface. Any \verb|POINTOPOINT| and
+\verb|BROADCAST| link is multicasting by definition, because we have
+direct access to all the neighbours and, hence, to any part of them.
+Certainly, the use of high bandwidth multicast transfers is not recommended
+on broadcast-only links because of high expense, but it is not strictly
+prohibited.
+
+\item \verb|PROMISC| --- the device listens to and feeds to the kernel all
+traffic on the link even if it is not destined for us, not broadcasted
+and not destined for a multicast group of which we are member. Usually
+this mode exists only on broadcast links and is used by bridges and for network
+monitoring.
+
+\item \verb|ALLMULTI| --- the device receives all multicast packets
+wandering on the link. This mode is used by multicast routers.
+
+\item \verb|NOARP| --- this flag is different from the other ones. It has
+no invariant value and its interpretation depends on the network protocols
+involved. As a rule, it indicates that the device needs no address
+resolution and that the software or hardware knows how to deliver packets
+without any help from the protocol stacks.
+
+\item \verb|DYNAMIC| --- is an advisory flag indicating that the interface is
+dynamically created and destroyed.
+
+\item \verb|SLAVE| --- this interface is bonded to some other interfaces
+to share link capacities.
+
+\end{itemize}
+
+\vskip 1mm
+\begin{NB}
+There are other flags but they are either obsolete (\verb|NOTRAILERS|)
+or not implemented (\verb|DEBUG|) or specific to some devices
+(\verb|MASTER|, \verb|AUTOMEDIA| and \verb|PORTSEL|). We do not discuss
+them here.
+\end{NB}
+
+
+The second line contains information on the link layer addresses
+associated with the device. The first word (\verb|ether|, \verb|sit|)
+defines the interface hardware type. This type determines the format and semantics
+of the addresses and is logically part of the address.
+The default format of the station address and the broadcast address
+(or the peer address for pointopoint links) is a
+sequence of hexadecimal bytes separated by colons, but some link
+types may have their natural address format, f.e.\ addresses
+of tunnels over IP are printed as dotted-quad IP addresses.
+
+\vskip 1mm
+\begin{NB}
+  NBMA links have no well-defined broadcast or peer address,
+  however this field may contain useful information, f.e.\
+  about the address of broadcast relay or about the address of the ARP server.
+\end{NB}
+\begin{NB}
+Multicast addresses are not shown by this command, see
+\verb|ip maddr ls| in~Sec.\ref{IP-MADDR} (p.\pageref{IP-MADDR} of this
+document).
+\end{NB}
+
+
+\paragraph{Statistics:} With the \verb|-statistics| option, \verb|ip| also
+prints interface statistics:
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip -s link ls eth0
+3: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc cbq qlen 100
+    link/ether 00:a0:cc:66:18:78 brd ff:ff:ff:ff:ff:ff
+    RX: bytes  packets  errors  dropped overrun mcast   
+    2449949362 2786187  0       0       0       0      
+    TX: bytes  packets  errors  dropped carrier collsns 
+    178558497  1783945  332     0       332     35172  
+kuznet@alisa:~ $
+\end{verbatim}
+\verb|RX:| and \verb|TX:| lines summarize receiver and transmitter
+statistics. They contain:
+\begin{itemize}
+\item \verb|bytes| --- the total number of bytes received or transmitted
+on the interface. This number wraps when the maximal length of the data type
+natural for the architecture is exceeded, so continuous monitoring requires
+a user level daemon snapping it periodically.
+\item \verb|packets| --- the total number of packets received or transmitted
+on the interface.
+\item \verb|errors| --- the total number of receiver or transmitter errors.
+\item \verb|dropped| --- the total number of packets dropped due to lack
+of resources.
+\item \verb|overrun| --- the total number of receiver overruns resulting
+in dropped packets. As a rule, if the interface is overrun, it means
+serious problems in the kernel or that your machine is too slow
+for this interface.
+\item \verb|mcast| --- the total number of received multicast packets. This option
+is only supported by a few devices.
+\item \verb|carrier| --- total number of link media failures f.e.\ because
+of lost carrier.
+\item \verb|collsns| --- the total number of collision events
+on Ethernet-like media. This number may have a different sense on other
+link types.
+\item \verb|compressed| --- the total number of compressed packets. This is
+available only for links using VJ header compression.
+\end{itemize}
+
+
+If the \verb|-s| option is entered twice or more,
+\verb|ip| prints more detailed statistics on receiver
+and transmitter errors.
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip -s -s link ls eth0
+3: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc cbq qlen 100
+    link/ether 00:a0:cc:66:18:78 brd ff:ff:ff:ff:ff:ff
+    RX: bytes  packets  errors  dropped overrun mcast   
+    2449949362 2786187  0       0       0       0      
+    RX errors: length   crc     frame   fifo    missed
+               0        0       0       0       0      
+    TX: bytes  packets  errors  dropped carrier collsns 
+    178558497  1783945  332     0       332     35172  
+    TX errors: aborted  fifo    window  heartbeat
+               0        0       0       332    
+kuznet@alisa:~ $
+\end{verbatim}
+These error names are pure Ethernetisms. Other devices
+may have non zero values in these fields but they may be
+interpreted differently.
+
+
+\section{{\tt ip address} --- protocol address management}
+
+\paragraph{Abbreviations:} \verb|address|, \verb|addr|, \verb|a|.
+
+\paragraph{Object:} The \verb|address| is a protocol (IP or IPv6) address attached
+to a network device. Each device must have at least one address
+to use the corresponding protocol. It is possible to have several
+different addresses attached to one device. These addresses are not
+discriminated, so that the term {\em alias\/} is not quite appropriate
+for them and we do not use it in this document.
+
+The \verb|ip addr| command displays addresses and their properties,
+adds new addresses and deletes old ones.
+
+\paragraph{Commands:} \verb|add|, \verb|delete|, \verb|flush| and \verb|show|
+(or \verb|list|).
+
+
+\subsection{{\tt ip address add} --- add a new protocol address}
+\label{IP-ADDR-ADD}
+
+\paragraph{Abbreviations:} \verb|add|, \verb|a|.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|dev NAME|
+
+\noindent--- the name of the device to add the address to.
+
+\item \verb|local ADDRESS| (default)
+
+--- the address of the interface. The format of the address depends
+on the protocol. It is a dotted quad for IP and a sequence of hexadecimal halfwords
+separated by colons for IPv6. The \verb|ADDRESS| may be followed by
+a slash and a decimal number which encodes the network prefix length.
+
+
+\item \verb|peer ADDRESS|
+
+--- the address of the remote endpoint for pointopoint interfaces.
+Again, the \verb|ADDRESS| may be followed by a slash and a decimal number,
+encoding the network prefix length. If a peer address is specified,
+the local address {\em cannot\/} have a prefix length. The network prefix is associated
+with the peer rather than with the local address.
+
+
+\item \verb|broadcast ADDRESS|
+
+--- the broadcast address on the interface.
+
+It is possible to use the special symbols \verb|'+'| and \verb|'-'|
+instead of the broadcast address. In this case, the broadcast address
+is derived by setting/resetting the host bits of the interface prefix.
+
+\vskip 1mm
+\begin{NB}
+Unlike \verb|ifconfig|, the \verb|ip| utility {\em does not\/} set any broadcast
+address unless explicitly requested.
+\end{NB}
+
+
+\item \verb|label NAME|
+
+--- Each address may be tagged with a label string.
+In order to preserve compatibility with Linux-2.0 net aliases,
+this string must coincide with the name of the device or must be prefixed
+with the device name followed by colon.
+
+
+\item \verb|scope SCOPE_VALUE|
+
+--- the scope of the area where this address is valid.
+The available scopes are listed in file \verb|/etc/iproute2/rt_scopes|.
+Predefined scope values are:
+
+ \begin{itemize}
+	\item \verb|global| --- the address is globally valid.
+	\item \verb|site| --- (IPv6 only) the address is site local,
+	i.e.\ it is valid inside this site.
+	\item \verb|link| --- the address is link local, i.e.\ 
+	it is valid only on this device.
+	\item \verb|host| --- the address is valid only inside this host.
+ \end{itemize}
+
+Appendix~\ref{ADDR-SEL} (p.\pageref{ADDR-SEL} of this document)
+contains more details on address scopes.
+
+\end{itemize}
+
+\paragraph{Examples:}
+\begin{itemize}
+\item \verb|ip addr add 127.0.0.1/8 dev lo brd + scope host|
+
+--- add the usual loopback address to the loopback device.
+
+\item \verb|ip addr add 10.0.0.1/24 brd + dev eth0 label eth0:Alias|
+
+--- add the address 10.0.0.1 with prefix length 24 (i.e.\ netmask
+\verb|255.255.255.0|), standard broadcast and label \verb|eth0:Alias|
+to the interface \verb|eth0|.
+\end{itemize}
+
+
+\subsection{{\tt ip address delete} --- delete a protocol address}
+
+\paragraph{Abbreviations:} \verb|delete|, \verb|del|, \verb|d|.
+
+\paragraph{Arguments:} coincide with the arguments of \verb|ip addr add|.
+The device name is a required argument. The rest are optional.
+If no arguments are given, the first address is deleted.
+
+\paragraph{Examples:}
+\begin{itemize}
+\item \verb|ip addr del 127.0.0.1/8 dev lo|
+
+--- deletes the loopback address from the loopback device.
+It would be best not to repeat this experiment.
+
+\item Disable IP on the interface \verb|eth0|:
+\begin{verbatim}
+  while ip -f inet addr del dev eth0; do
+    : nothing
+  done
+\end{verbatim}
+Another method to disable IP on an interface using {\tt ip addr flush}
+may be found in sec.\ref{IP-ADDR-FLUSH}, p.\pageref{IP-ADDR-FLUSH}.
+
+\end{itemize}
+
+
+\subsection{{\tt ip address show} --- display protocol addresses}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|lst|, \verb|sh|, \verb|ls|,
+\verb|l|.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|dev NAME| (default)
+
+--- the name of the device.
+
+\item \verb|scope SCOPE_VAL|
+
+--- only list addresses with this scope.
+
+\item \verb|to PREFIX|
+
+--- only list addresses matching this prefix.
+
+\item \verb|label PATTERN|
+
+--- only list addresses with labels matching the \verb|PATTERN|.
+\verb|PATTERN| is a usual shell style pattern.
+
+
+\item \verb|dynamic| and \verb|permanent|
+
+--- (IPv6 only) only list addresses installed due to stateless
+address configuration or only list permanent (not dynamic) addresses.
+
+\item \verb|tentative|
+
+--- (IPv6 only) only list addresses which did not pass duplicate
+address detection.
+
+\item \verb|deprecated|
+
+--- (IPv6 only) only list deprecated addresses.
+
+
+\item  \verb|primary| and \verb|secondary|
+
+--- only list primary (or secondary) addresses.
+
+\end{itemize}
+
+
+\paragraph{Output format:}
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip addr ls eth0
+3: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc cbq qlen 100
+    link/ether 00:a0:cc:66:18:78 brd ff:ff:ff:ff:ff:ff
+    inet 193.233.7.90/24 brd 193.233.7.255 scope global eth0
+    inet6 3ffe:2400:0:1:2a0:ccff:fe66:1878/64 scope global dynamic 
+       valid_lft forever preferred_lft 604746sec
+    inet6 fe80::2a0:ccff:fe66:1878/10 scope link 
+kuznet@alisa:~ $ 
+\end{verbatim}
+
+The first two lines coincide with the output of \verb|ip link ls|.
+It is natural to interpret link layer addresses
+as addresses of the protocol family \verb|AF_PACKET|.
+
+Then the list of IP and IPv6 addresses follows, accompanied by
+additional address attributes: scope value (see Sec.\ref{IP-ADDR-ADD},
+p.\pageref{IP-ADDR-ADD} above), flags and the address label.
+
+Address flags are set by the kernel and cannot be changed
+administratively. Currently, the following flags are defined:
+
+\begin{enumerate}
+\item \verb|secondary|
+
+--- the address is not used when selecting the default source address
+of outgoing packets (Cf.\ Appendix~\ref{ADDR-SEL}, p.\pageref{ADDR-SEL}.).
+An IP address becomes secondary if another address with the same
+prefix bits already exists. The first address is primary.
+It is the leader of the group of all secondary addresses. When the leader
+is deleted, all secondaries are purged too.
+There is a tweak in \verb|/proc/sys/net/ipv4/conf/<dev>/promote_secondaries|
+which activate secondaries promotion when a primary is deleted.
+To permanently enable this feature on all devices add
+\verb|net.ipv4.conf.all.promote_secondaries=1| to \verb|/etc/sysctl.conf|.
+This tweak is available in linux 2.6.15 and later.
+
+
+\item \verb|dynamic|
+
+--- the address was created due to stateless autoconfiguration~\cite{RFC-ADDRCONF}.
+In this case the output also contains information on times, when
+the address is still valid. After \verb|preferred_lft| expires the address is
+moved to the deprecated state. After \verb|valid_lft| expires the address
+is finally invalidated.
+
+\item \verb|deprecated|
+
+--- the address is deprecated, i.e.\ it is still valid, but cannot
+be used by newly created connections.
+
+\item \verb|tentative|
+
+--- the address is not used because duplicate address detection~\cite{RFC-ADDRCONF}
+is still not complete or failed.
+
+\end{enumerate}
+
+
+\subsection{{\tt ip address flush} --- flush protocol addresses}
+\label{IP-ADDR-FLUSH}
+
+\paragraph{Abbreviations:} \verb|flush|, \verb|f|.
+
+\paragraph{Description:}This command flushes the protocol addresses
+selected by some criteria.
+
+\paragraph{Arguments:} This command has the same arguments as \verb|show|.
+The difference is that it does not run when no arguments are given.
+
+\paragraph{Warning:} This command (and other \verb|flush| commands
+described below) is pretty dangerous. If you make a mistake, it will
+not forgive it, but will cruelly purge all the addresses.
+
+\paragraph{Statistics:} With the \verb|-statistics| option, the command
+becomes verbose. It prints out the number of deleted addresses and the number
+of rounds made to flush the address list. If this option is given
+twice, \verb|ip addr flush| also dumps all the deleted addresses
+in the format described in the previous subsection.
+
+\paragraph{Example:} Delete all the addresses from the private network
+10.0.0.0/8:
+\begin{verbatim}
+netadm@amber:~ # ip -s -s a f to 10/8
+2: dummy    inet 10.7.7.7/16 brd 10.7.255.255 scope global dummy
+3: eth0    inet 10.10.7.7/16 brd 10.10.255.255 scope global eth0
+4: eth1    inet 10.8.7.7/16 brd 10.8.255.255 scope global eth1
+
+*** Round 1, deleting 3 addresses ***
+*** Flush is complete after 1 round ***
+netadm@amber:~ # 
+\end{verbatim}
+Another instructive example is disabling IP on all the Ethernets:
+\begin{verbatim}
+netadm@amber:~ # ip -4 addr flush label "eth*"
+\end{verbatim}
+And the last example shows how to flush all the IPv6 addresses
+acquired by the host from stateless address autoconfiguration
+after you enabled forwarding or disabled autoconfiguration.
+\begin{verbatim}
+netadm@amber:~ # ip -6 addr flush dynamic
+\end{verbatim}
+
+
+
+\section{{\tt ip neighbour} --- neighbour/arp tables management}
+
+\paragraph{Abbreviations:} \verb|neighbour|, \verb|neighbor|, \verb|neigh|,
+\verb|n|.
+
+\paragraph{Object:} \verb|neighbour| objects establish bindings between protocol
+addresses and link layer addresses for hosts sharing the same link.
+Neighbour entries are organized into tables. The IPv4 neighbour table
+is known by another name --- the ARP table.
+
+The corresponding commands display neighbour bindings
+and their properties, add new neighbour entries and delete old ones.
+
+\paragraph{Commands:} \verb|add|, \verb|change|, \verb|replace|,
+\verb|delete|, \verb|flush| and \verb|show| (or \verb|list|).
+
+\paragraph{See also:} Appendix~\ref{PROXY-NEIGH}, p.\pageref{PROXY-NEIGH}
+describes how to manage proxy ARP/NDISC with the \verb|ip| utility.
+
+
+\subsection{{\tt ip neighbour add} --- add a new neighbour entry\\
+	{\tt ip neighbour change} --- change an existing entry\\
+	{\tt ip neighbour replace} --- add a new entry or change an existing one}
+
+\paragraph{Abbreviations:} \verb|add|, \verb|a|; \verb|change|, \verb|chg|;
+\verb|replace|,	\verb|repl|.
+
+\paragraph{Description:} These commands create new neighbour records
+or update existing ones.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|to ADDRESS| (default)
+
+--- the protocol address of the neighbour. It is either an IPv4 or IPv6 address.
+
+\item \verb|dev NAME|
+
+--- the interface to which this neighbour is attached.
+
+
+\item \verb|lladdr LLADDRESS|
+
+--- the link layer address of the neighbour. \verb|LLADDRESS| can also be
+\verb|null|. 
+
+\item \verb|nud NUD_STATE|
+
+--- the state of the neighbour entry. \verb|nud| is an abbreviation for ``Neighbour
+Unreachability Detection''. The state can take one of the following values:
+
+\begin{enumerate}
+\item \verb|permanent| --- the neighbour entry is valid forever and can be only be removed
+administratively.
+\item \verb|noarp| --- the neighbour entry is valid. No attempts to validate
+this entry will be made but it can be removed when its lifetime expires.
+\item \verb|reachable| --- the neighbour entry is valid until the reachability
+timeout expires.
+\item \verb|stale| --- the neighbour entry is valid but suspicious.
+This option to \verb|ip neigh| does not change the neighbour state if
+it was valid and the address is not changed by this command.
+\end{enumerate}
+
+\end{itemize}
+
+\paragraph{Examples:}
+\begin{itemize}
+\item \verb|ip neigh add 10.0.0.3 lladdr 0:0:0:0:0:1 dev eth0 nud perm|
+
+--- add a permanent ARP entry for the neighbour 10.0.0.3 on the device \verb|eth0|.
+
+\item \verb|ip neigh chg 10.0.0.3 dev eth0 nud reachable|
+
+--- change its state to \verb|reachable|.
+\end{itemize}
+
+
+\subsection{{\tt ip neighbour delete} --- delete a neighbour entry}
+
+\paragraph{Abbreviations:} \verb|delete|, \verb|del|, \verb|d|.
+
+\paragraph{Description:} This command invalidates a neighbour entry.
+
+\paragraph{Arguments:} The arguments are the same as with \verb|ip neigh add|,
+except that \verb|lladdr| and \verb|nud| are ignored.
+
+
+\paragraph{Example:}
+\begin{itemize}
+\item \verb|ip neigh del 10.0.0.3 dev eth0|
+
+--- invalidate an ARP entry for the neighbour 10.0.0.3 on the device \verb|eth0|.
+
+\end{itemize}
+
+\begin{NB}
+ The deleted neighbour entry will not disappear from the tables
+ immediately. If it is in use it cannot be deleted until the last
+ client releases it. Otherwise it will be destroyed during
+ the next garbage collection.
+\end{NB}
+
+
+\paragraph{Warning:} Attempts to delete or manually change
+a \verb|noarp| entry created by the kernel may result in unpredictable behaviour.
+Particularly, the kernel may try to resolve this address even
+on a \verb|NOARP| interface or if the address is multicast or broadcast.
+
+
+\subsection{{\tt ip neighbour show} --- list neighbour entries}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|sh|, \verb|ls|.
+
+\paragraph{Description:}This commands displays neighbour tables.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+
+\item \verb|to ADDRESS| (default)
+
+--- the prefix selecting the neighbours to list.
+
+\item \verb|dev NAME|
+
+--- only list the neighbours attached to this device.
+
+\item \verb|unused|
+
+--- only list neighbours which are not currently in use.
+
+\item \verb|nud NUD_STATE|
+
+--- only list neighbour entries in this state. \verb|NUD_STATE| takes
+values listed below or the special value \verb|all| which means all states.
+This option may occur more than once. If this option is absent, \verb|ip|
+lists all entries except for \verb|none| and \verb|noarp|.
+
+\end{itemize}
+
+
+\paragraph{Output format:}
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip neigh ls
+:: dev lo lladdr 00:00:00:00:00:00 nud noarp
+fe80::200:cff:fe76:3f85 dev eth0 lladdr 00:00:0c:76:3f:85 router \
+    nud stale
+0.0.0.0 dev lo lladdr 00:00:00:00:00:00 nud noarp
+193.233.7.254 dev eth0 lladdr 00:00:0c:76:3f:85 nud reachable
+193.233.7.85 dev eth0 lladdr 00:e0:1e:63:39:00 nud stale
+kuznet@alisa:~ $ 
+\end{verbatim}
+
+The first word of each line is the protocol address of the neighbour.
+Then the device name follows. The rest of the line describes the contents of
+the neighbour entry identified by the pair (device, address).
+
+\verb|lladdr| is the link layer address of the neighbour.
+
+\verb|nud| is the state of the ``neighbour unreachability detection'' machine
+for this entry. The detailed description of the neighbour
+state machine can be found in~\cite{RFC-NDISC}. Here is the full list
+of the states with short descriptions:
+
+\begin{enumerate}
+\item\verb|none| --- the state of the neighbour is void.
+\item\verb|incomplete| --- the neighbour is in the process of resolution.
+\item\verb|reachable| --- the neighbour is valid and apparently reachable.
+\item\verb|stale| --- the neighbour is valid, but is probably already
+unreachable, so the kernel will try to check it at the first transmission.
+\item\verb|delay| --- a packet has been sent to the stale neighbour and the kernel is waiting
+for confirmation.
+\item\verb|probe| --- the delay timer expired but no confirmation was received.
+The kernel has started to probe the neighbour with ARP/NDISC messages.
+\item\verb|failed| --- resolution has failed.
+\item\verb|noarp| --- the neighbour is valid. No attempts to check the entry
+will be made.
+\item\verb|permanent| --- it is a \verb|noarp| entry, but only the administrator
+may remove the entry from the neighbour table.
+\end{enumerate}
+
+The link layer address is valid in all states except for \verb|none|,
+\verb|failed| and \verb|incomplete|.
+
+IPv6 neighbours can be marked with the additional flag \verb|router|
+which means that the neighbour introduced itself as an IPv6 router~\cite{RFC-NDISC}.
+
+\paragraph{Statistics:} The \verb|-statistics| option displays some usage
+statistics, f.e.\
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip -s n ls 193.233.7.254
+193.233.7.254 dev eth0 lladdr 00:00:0c:76:3f:85 ref 5 used 12/13/20 \
+    nud reachable
+kuznet@alisa:~ $ 
+\end{verbatim}
+
+Here \verb|ref| is the number of users of this entry
+and \verb|used| is a triplet of time intervals in seconds
+separated by slashes. In this case they show that:
+
+\begin{enumerate}
+\item the entry was used 12 seconds ago.
+\item the entry was confirmed 13 seconds ago.
+\item the entry was updated 20 seconds ago.
+\end{enumerate}
+
+\subsection{{\tt ip neighbour flush} --- flush neighbour entries}
+
+\paragraph{Abbreviations:} \verb|flush|, \verb|f|.
+
+\paragraph{Description:}This command flushes neighbour tables, selecting
+entries to flush by some criteria.
+
+\paragraph{Arguments:} This command has the same arguments as \verb|show|.
+The differences are that it does not run when no arguments are given,
+and that the default neighbour states to be flushed do not include
+\verb|permanent| and \verb|noarp|.
+
+
+\paragraph{Statistics:} With the \verb|-statistics| option, the command
+becomes verbose. It prints out the number of deleted neighbours and the number
+of rounds made to flush the neighbour table. If the option is given
+twice, \verb|ip neigh flush| also dumps all the deleted neighbours
+in the format described in the previous subsection.
+
+\paragraph{Example:}
+\begin{verbatim}
+netadm@alisa:~ # ip -s -s n f 193.233.7.254
+193.233.7.254 dev eth0 lladdr 00:00:0c:76:3f:85 ref 5 used 12/13/20 \
+    nud reachable
+
+*** Round 1, deleting 1 entries ***
+*** Flush is complete after 1 round ***
+netadm@alisa:~ # 
+\end{verbatim}
+
+
+\section{{\tt ip route} --- routing table management}
+\label{IP-ROUTE}
+
+\paragraph{Abbreviations:} \verb|route|, \verb|ro|, \verb|r|.
+
+\paragraph{Object:} \verb|route| entries in the kernel routing tables keep
+information about paths to other networked nodes.
+
+Each route entry has a {\em key\/} consisting of a {\em prefix\/}
+(i.e.\ a pair containing a network address and the length of its mask) and,
+optionally, the TOS value. An IP packet matches the route if the highest
+bits of its destination address are equal to the route prefix at least
+up to the prefix length and if the TOS of the route is zero or equal to
+the TOS of the packet.
+ 
+If several routes match the packet, the following pruning rules
+are used to select the best one (see~\cite{RFC1812}):
+\begin{enumerate}
+\item The longest matching prefix is selected. All shorter ones
+are dropped.
+
+\item If the TOS of some route with the longest prefix is equal to the TOS
+of the packet, the routes with different TOS are dropped.
+
+If no exact TOS match was found and routes with TOS=0 exist,
+the rest of routes are pruned.
+
+Otherwise, the route lookup fails.
+
+\item If several routes remain after the previous steps, then
+the routes with the best preference values are selected.
+
+\item If we still have several routes, then the {\em first\/} of them
+is selected.
+
+\begin{NB}
+ Note the ambiguity of the last step. Unfortunately, Linux
+ historically allows such a bizarre situation. The sense of the
+word ``first'' depends on the order of route additions and it is practically
+impossible to maintain a bundle of such routes in this order.
+\end{NB}
+
+For simplicity we will limit ourselves to the case where such a situation
+is impossible and routes are uniquely identified by the triplet
+\{prefix, tos, preference\}. Actually, it is impossible to create
+non-unique routes with \verb|ip| commands described in this section.
+
+One useful exception to this rule is the default route on non-forwarding
+hosts. It is ``officially'' allowed to have several fallback routes
+when several routers are present on directly connected networks.
+In this case, Linux-2.2 makes ``dead gateway detection''~\cite{RFC1122}
+controlled by neighbour unreachability detection and by advice
+from transport protocols to select a working router, so the order
+of the routes is not essential. However, in this case,
+fiddling with default routes manually is not recommended. Use the Router Discovery
+protocol (see Appendix~\ref{EXAMPLE-SETUP}, p.\pageref{EXAMPLE-SETUP})
+instead. Actually, Linux-2.2 IPv6 does not give user level applications
+any access to default routes.
+\end{enumerate}
+
+Certainly, the steps above are not performed exactly
+in this sequence. Instead, the routing table in the kernel is kept
+in some data structure to achieve the final result
+with minimal cost. However, not depending on a particular
+routing algorithm implemented in the kernel, we can summarize
+the statements above as: a route is identified by the triplet
+\{prefix, tos, preference\}. This {\em key\/} lets us locate
+the route in the routing table.
+
+\paragraph{Route attributes:} Each route key refers to a routing
+information record containing
+the data required to deliver IP packets (f.e.\ output device and
+next hop router) and some optional attributes (f.e. the path MTU or
+the preferred source address when communicating with this destination).
+These attributes are described in the following subsection.
+
+\paragraph{Route types:} \label{IP-ROUTE-TYPES}
+It is important that the set
+of required and optional attributes depend on the route {\em type\/}.
+The most important route type
+is \verb|unicast|. It describes real paths to other hosts.
+As a rule, common routing tables contain only such routes. However,
+there are other types of routes with different semantics. The
+full list of types understood by Linux-2.2 is:
+\begin{itemize}
+\item \verb|unicast| --- the route entry describes real paths to the
+destinations covered by the route prefix.
+\item \verb|unreachable| --- these destinations are unreachable. Packets
+are discarded and the ICMP message {\em host unreachable\/} is generated.
+The local senders get an \verb|EHOSTUNREACH| error.
+\item \verb|blackhole| --- these destinations are unreachable. Packets
+are discarded silently. The local senders get an \verb|EINVAL| error.
+\item \verb|prohibit| --- these destinations are unreachable. Packets
+are discarded and the ICMP message {\em communication administratively
+prohibited\/} is generated. The local senders get an \verb|EACCES| error.
+\item \verb|local| --- the destinations are assigned to this
+host. The packets are looped back and delivered locally.
+\item \verb|broadcast| --- the destinations are broadcast addresses.
+The packets are sent as link broadcasts.
+\item \verb|throw| --- a special control route used together with policy
+rules (see sec.\ref{IP-RULE}, p.\pageref{IP-RULE}). If such a route is selected, lookup
+in this table is terminated pretending that no route was found.
+Without policy routing it is equivalent to the absence of the route in the routing
+table. The packets are dropped and the ICMP message {\em net unreachable\/}
+is generated. The local senders get an \verb|ENETUNREACH| error.
+\item \verb|nat| --- a special NAT route. Destinations covered by the prefix
+are considered to be dummy (or external) addresses which require translation
+to real (or internal) ones before forwarding. The addresses to translate to
+are selected with the attribute \verb|via|. More about NAT is
+in Appendix~\ref{ROUTE-NAT}, p.\pageref{ROUTE-NAT}.
+\item \verb|anycast| --- ({\em not implemented\/}) the destinations are
+{\em anycast\/} addresses assigned to this host. They are mainly equivalent
+to \verb|local| with one difference: such addresses are invalid when used
+as the source address of any packet.
+\item \verb|multicast| --- a special type used for multicast routing.
+It is not present in normal routing tables.
+\end{itemize}
+
+\paragraph{Route tables:} Linux-2.2 can pack routes into several routing
+tables identified by a number in the range from 1 to 255 or by
+name from the file \verb|/etc/iproute2/rt_tables|. By default all normal
+routes are inserted into the \verb|main| table (ID 254) and the kernel only uses
+this table when calculating routes.
+
+Actually, one other table always exists, which is invisible but
+even more important. It is the \verb|local| table (ID 255). This table
+consists of routes for local and broadcast addresses. The kernel maintains
+this table automatically and the administrator usually need not modify it
+or even look at it.
+
+The multiple routing tables enter the game when {\em policy routing\/}
+is used. See sec.\ref{IP-RULE}, p.\pageref{IP-RULE}.
+In this case, the table identifier effectively becomes
+one more parameter, which should be added to the triplet
+\{prefix, tos, preference\} to uniquely identify the route.
+
+
+\subsection{{\tt ip route add} --- add a new route\\
+	{\tt ip route change} --- change a route\\
+	{\tt ip route replace} --- change a route or add a new one}
+\label{IP-ROUTE-ADD}
+
+\paragraph{Abbreviations:} \verb|add|, \verb|a|; \verb|change|, \verb|chg|;
+	\verb|replace|, \verb|repl|.
+
+
+\paragraph{Arguments:}
+\begin{itemize}
+\item \verb|to PREFIX| or \verb|to TYPE PREFIX| (default)
+
+--- the destination prefix of the route. If \verb|TYPE| is omitted,
+\verb|ip| assumes type \verb|unicast|. Other values of \verb|TYPE|
+are listed above. \verb|PREFIX| is an IP or IPv6 address optionally followed
+by a slash and the prefix length. If the length of the prefix is missing,
+\verb|ip| assumes a full-length host route. There is also a special
+\verb|PREFIX| --- \verb|default| --- which is equivalent to IP \verb|0/0| or
+to IPv6 \verb|::/0|.
+
+\item \verb|tos TOS| or \verb|dsfield TOS|
+
+--- the Type Of Service (TOS) key. This key has no associated mask and
+the longest match is understood as: First, compare the TOS
+of the route and of the packet. If they are not equal, then the packet
+may still match a route with a zero TOS. \verb|TOS| is either an 8 bit hexadecimal
+number or an identifier from {\tt /etc/iproute2/rt\_dsfield}.
+
+
+\item \verb|metric NUMBER| or \verb|preference NUMBER|
+
+--- the preference value of the route. \verb|NUMBER| is an arbitrary 32bit number.
+
+\item \verb|table TABLEID|
+
+--- the table to add this route to.
+\verb|TABLEID| may be a number or a string from the file
+\verb|/etc/iproute2/rt_tables|. If this parameter is omitted,
+\verb|ip| assumes the \verb|main| table, with the exception of
+\verb|local|, \verb|broadcast| and \verb|nat| routes, which are
+put into the \verb|local| table by default.
+
+\item \verb|dev NAME|
+
+--- the output device name.
+
+\item \verb|via ADDRESS|
+
+--- the address of the nexthop router. Actually, the sense of this field depends
+on the route type. For normal \verb|unicast| routes it is either the true nexthop
+router or, if it is a direct route installed in BSD compatibility mode,
+it can be a local address of the interface.
+For NAT routes it is the first address of the block of translated IP destinations.
+
+\item \verb|src ADDRESS|
+
+--- the source address to prefer when sending to the destinations
+covered by the route prefix.
+
+\item \verb|realm REALMID|
+
+--- the realm to which this route is assigned.
+\verb|REALMID| may be a number or a string from the file
+\verb|/etc/iproute2/rt_realms|. Sec.\ref{RT-REALMS} (p.\pageref{RT-REALMS})
+contains more information on realms.
+
+\item \verb|mtu MTU| or \verb|mtu lock MTU|
+
+--- the MTU along the path to the destination. If the modifier \verb|lock| is
+not used, the MTU may be updated by the kernel due to Path MTU Discovery.
+If the modifier \verb|lock| is used, no path MTU discovery will be tried,
+all packets will be sent without the DF bit in IPv4 case
+or fragmented to MTU for IPv6.
+
+\item \verb|window NUMBER|
+
+--- the maximal window for TCP to advertise to these destinations,
+measured in bytes. It limits maximal data bursts that our TCP
+peers are allowed to send to us.
+
+\item \verb|rtt NUMBER|
+
+--- the initial RTT (``Round Trip Time'') estimate.
+
+
+\item \verb|rttvar NUMBER|
+
+--- \threeonly the initial RTT variance estimate.
+
+
+\item \verb|ssthresh NUMBER|
+
+--- \threeonly an estimate for the initial slow start threshold.
+
+
+\item \verb|cwnd NUMBER|
+
+--- \threeonly the clamp for congestion window. It is ignored if the \verb|lock|
+    flag is not used.
+
+
+\item \verb|advmss NUMBER|
+
+--- \threeonly the MSS (``Maximal Segment Size'') to advertise to these
+    destinations when establishing TCP connections. If it is not given,
+    Linux uses a default value calculated from the first hop device MTU.
+
+\begin{NB}
+  If the path to these destination is asymmetric, this guess may be wrong.
+\end{NB}
+
+\item \verb|reordering NUMBER|
+
+--- \threeonly Maximal reordering on the path to this destination.
+    If it is not given, Linux uses the value selected with \verb|sysctl|
+    variable \verb|net/ipv4/tcp_reordering|.
+
+\item \verb|hoplimit NUMBER|
+
+--- [2.5.74+ only] Maximum number of hops on the path to this destination.
+    The default is the value selected with the \verb|sysctl| variable
+    \verb|net/ipv4/ip_default_ttl|.
+
+\item \verb|initcwnd NUMBER|
+--- [2.5.70+ only] Initial congestion window size for connections to
+    this destination. Actual window size is this value multiplied by the
+    MSS (``Maximal Segment Size'') for same connection. The default is
+    zero, meaning to use the values specified in~\cite{RFC2414}.
+
++\item \verb|initrwnd NUMBER|
+ 
++--- [2.6.33+ only] Initial receive window size for connections to 
++    this destination. The actual window size is this value multiplied
++    by the MSS (''Maximal Segment Size'') of the connection. The default
++    value is zero, meaning to use Slow Start value.
+ 
+\item \verb|nexthop NEXTHOP|
+
+--- the nexthop of a multipath route. \verb|NEXTHOP| is a complex value
+with its own syntax similar to the top level argument lists:
+\begin{itemize}
+\item \verb|via ADDRESS| is the nexthop router.
+\item \verb|dev NAME| is the output device.
+\item \verb|weight NUMBER| is a weight for this element of a multipath
+route reflecting its relative bandwidth or quality.
+\end{itemize}
+
+\item \verb|scope SCOPE_VAL|
+
+--- the scope of the destinations covered by the route prefix.
+\verb|SCOPE_VAL| may be a number or a string from the file
+\verb|/etc/iproute2/rt_scopes|.
+If this parameter is omitted,
+\verb|ip| assumes scope \verb|global| for all gatewayed \verb|unicast|
+routes, scope \verb|link| for direct \verb|unicast| and \verb|broadcast| routes
+and scope \verb|host| for \verb|local| routes.
+
+\item \verb|protocol RTPROTO|
+
+--- the routing protocol identifier of this route.
+\verb|RTPROTO| may be a number or a string from the file
+\verb|/etc/iproute2/rt_protos|. If the routing protocol ID is
+not given, \verb|ip| assumes protocol \verb|boot| (i.e.\
+it assumes the route was added by someone who doesn't
+understand what they are doing). Several protocol values have a fixed interpretation.
+Namely:
+\begin{itemize}
+\item \verb|redirect| --- the route was installed due to an ICMP redirect.
+\item \verb|kernel| --- the route was installed by the kernel during
+autoconfiguration.
+\item \verb|boot| --- the route was installed during the bootup sequence.
+If a routing daemon starts, it will purge all of them.
+\item \verb|static| --- the route was installed by the administrator
+to override dynamic routing. Routing daemon will respect them
+and, probably, even advertise them to its peers.
+\item \verb|ra| --- the route was installed by Router Discovery protocol.
+\end{itemize}
+The rest of the values are not reserved and the administrator is free
+to assign (or not to assign) protocol tags. At least, routing
+daemons should take care of setting some unique protocol values,
+f.e.\ as they are assigned in \verb|rtnetlink.h| or in \verb|rt_protos|
+database.
+
+
+\item \verb|onlink|
+
+--- pretend that the nexthop is directly attached to this link,
+even if it does not match any interface prefix. One application of this
+option may be found in~\cite{IP-TUNNELS}.
+
+\item \verb|pref PREF|
+
+--- the IPv6 route preference.
+\verb|PREF| PREF is a string specifying the route preference as defined in
+RFC4191 for Router Discovery messages. Namely:
+\begin{itemize}
+\item \verb|low| --- the route has a lowest priority.
+\item \verb|medium| --- the route has a default priority.
+\item \verb|high| --- the route has a highest priority.
+\end{itemize}
+
+\end{itemize}
+
+
+\begin{NB}
+  Actually there are more commands: \verb|prepend| does the same
+  thing as classic \verb|route add|, i.e.\ adds a route, even if another
+  route to the same destination exists. Its opposite case is \verb|append|,
+  which adds the route to the end of the list. Avoid these
+  features.
+\end{NB}
+\begin{NB}
+  More sad news, IPv6 only understands the \verb|append| command correctly.
+  All the others are translated into \verb|append| commands. Certainly,
+  this will change in the future.
+\end{NB}
+
+\paragraph{Examples:}
+\begin{itemize}
+\item add a plain route to network 10.0.0/24 via gateway 193.233.7.65
+\begin{verbatim}
+  ip route add 10.0.0/24 via 193.233.7.65
+\end{verbatim}
+\item change it to a direct route via the \verb|dummy| device
+\begin{verbatim}
+  ip ro chg 10.0.0/24 dev dummy
+\end{verbatim}
+\item add a default multipath route splitting the load between \verb|ppp0|
+and \verb|ppp1|
+\begin{verbatim}
+  ip route add default scope global nexthop dev ppp0 \
+                                    nexthop dev ppp1
+\end{verbatim}
+Note the scope value. It is not necessary but it informs the kernel
+that this route is gatewayed rather than direct. Actually, if you
+know the addresses of remote endpoints it would be better to use the
+\verb|via| parameter.
+\item announce that the address 192.203.80.144 is not a real one, but
+should be translated to 193.233.7.83 before forwarding
+\begin{verbatim}
+  ip route add nat 192.203.80.144 via 193.233.7.83
+\end{verbatim}
+Backward translation is setup with policy rules described
+in the following section (sec.\ref{IP-RULE}, p.\pageref{IP-RULE}).
+\end{itemize}
+
+\subsection{{\tt ip route delete} --- delete a route}
+
+\paragraph{Abbreviations:} \verb|delete|, \verb|del|, \verb|d|.
+
+\paragraph{Arguments:} \verb|ip route del| has the same arguments as
+\verb|ip route add|, but their semantics are a bit different.
+
+Key values (\verb|to|, \verb|tos|, \verb|preference| and \verb|table|)
+select the route to delete. If optional attributes are present, \verb|ip|
+verifies that they coincide with the attributes of the route to delete.
+If no route with the given key and attributes was found, \verb|ip route del|
+fails.
+\begin{NB}
+Linux-2.0 had the option to delete a route selected only by prefix address,
+ignoring its length (i.e.\ netmask). This option no longer exists
+because it was ambiguous. However, look at {\tt ip route flush}
+(sec.\ref{IP-ROUTE-FLUSH}, p.\pageref{IP-ROUTE-FLUSH}) which
+provides similar and even richer functionality.
+\end{NB}
+
+\paragraph{Example:}
+\begin{itemize}
+\item delete the multipath route created by the command in previous subsection
+\begin{verbatim}
+  ip route del default scope global nexthop dev ppp0 \
+                                    nexthop dev ppp1
+\end{verbatim}
+\end{itemize}
+
+
+
+\subsection{{\tt ip route show} --- list routes}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|sh|, \verb|ls|, \verb|l|.
+
+\paragraph{Description:} the command displays the contents of the routing tables
+or the route(s) selected by some criteria.
+
+
+\paragraph{Arguments:}
+\begin{itemize}
+\item \verb|to SELECTOR| (default)
+
+--- only select routes from the given range of destinations. \verb|SELECTOR|
+consists of an optional modifier (\verb|root|, \verb|match| or \verb|exact|)
+and a prefix. \verb|root PREFIX| selects routes with prefixes not shorter
+than \verb|PREFIX|. F.e.\ \verb|root 0/0| selects the entire routing table.
+\verb|match PREFIX| selects routes with prefixes not longer than
+\verb|PREFIX|. F.e.\ \verb|match 10.0/16| selects \verb|10.0/16|,
+\verb|10/8| and \verb|0/0|, but it does not select \verb|10.1/16| and
+\verb|10.0.0/24|. And \verb|exact PREFIX| (or just \verb|PREFIX|)
+selects routes with this exact prefix. If neither of these options
+are present, \verb|ip| assumes \verb|root 0/0| i.e.\ it lists the entire table.
+
+
+\item \verb|tos TOS| or \verb|dsfield TOS|
+
+ --- only select routes with the given TOS.
+
+
+\item \verb|table TABLEID|
+
+ --- show the routes from this table(s). The default setting is to show
+\verb|table| \verb|main|. \verb|TABLEID| may either be the ID of a real table
+or one of the special values:
+  \begin{itemize}
+  \item \verb|all| --- list all of the tables.
+  \item \verb|cache| --- dump the routing cache.
+  \end{itemize}
+\begin{NB}
+  IPv6 has a single table. However, splitting it into \verb|main|, \verb|local|
+  and \verb|cache| is emulated by the \verb|ip| utility.
+\end{NB}
+
+\item \verb|cloned| or \verb|cached|
+
+--- list cloned routes i.e.\ routes which were dynamically forked from
+other routes because some route attribute (f.e.\ MTU) was updated.
+Actually, it is equivalent to \verb|table cache|.
+
+\item \verb|from SELECTOR|
+
+--- the same syntax as for \verb|to|, but it binds the source address range
+rather than destinations. Note that the \verb|from| option only works with
+cloned routes.
+
+\item \verb|protocol RTPROTO|
+
+--- only list routes of this protocol.
+
+
+\item \verb|scope SCOPE_VAL|
+
+--- only list routes with this scope.
+
+\item \verb|type TYPE|
+
+--- only list routes of this type.
+
+\item \verb|dev NAME|
+
+--- only list routes going via this device.
+
+\item \verb|via PREFIX|
+
+--- only list routes going via the nexthop routers selected by \verb|PREFIX|.
+
+\item \verb|src PREFIX|
+
+--- only list routes with preferred source addresses selected
+by \verb|PREFIX|.
+
+\item \verb|realm REALMID| or \verb|realms FROMREALM/TOREALM|
+
+--- only list routes with these realms.
+
+\end{itemize}
+
+\paragraph{Examples:} Let us count routes of protocol \verb|gated/bgp|
+on a router:
+\begin{verbatim}
+kuznet@amber:~ $ ip ro ls proto gated/bgp | wc
+   1413    9891    79010
+kuznet@amber:~ $
+\end{verbatim}
+To count the size of the routing cache, we have to use the \verb|-o| option
+because cached attributes can take more than one line of output:
+\begin{verbatim}
+kuznet@amber:~ $ ip -o ro ls cloned | wc
+   159    2543    18707
+kuznet@amber:~ $
+\end{verbatim}
+
+
+\paragraph{Output format:} The output of this command consists
+of per route records separated by line feeds.
+However, some records may consist
+of more than one line: particularly, this is the case when the route
+is cloned or you requested additional statistics. If the
+\verb|-o| option was given, then line feeds separating lines inside
+records are replaced with the backslash sign.
+
+The output has the same syntax as arguments given to {\tt ip route add},
+so that it can be understood easily. F.e.\
+\begin{verbatim}
+kuznet@amber:~ $ ip ro ls 193.233.7/24
+193.233.7.0/24 dev eth0  proto gated/conn  scope link \
+    src 193.233.7.65 realms inr.ac 
+kuznet@amber:~ $
+\end{verbatim}
+
+If you list cloned entries, the output contains other attributes which
+are evaluated during route calculation and updated during route
+lifetime. An example of the output is:
+\begin{verbatim}
+kuznet@amber:~ $ ip ro ls 193.233.7.82 tab cache
+193.233.7.82 from 193.233.7.82 dev eth0  src 193.233.7.65 \
+  realms inr.ac/inr.ac 
+    cache <src-direct,redirect>  mtu 1500 rtt 300 iif eth0
+193.233.7.82 dev eth0  src 193.233.7.65 realms inr.ac 
+    cache  mtu 1500 rtt 300
+kuznet@amber:~ $
+\end{verbatim}
+\begin{NB}
+  \label{NB-strange-route}
+  The route looks a bit strange, doesn't it? Did you notice that
+  it is a path from 193.233.7.82 back to 193.233.82? Well, you will
+  see in the section on \verb|ip route get| (p.\pageref{NB-nature-of-strangeness})
+  how it appeared.
+\end{NB}
+The second line, starting with the word \verb|cache|, shows
+additional attributes which normal routes do not possess.
+Cached flags are summarized in angle brackets:
+\begin{itemize}
+\item \verb|local| --- packets are delivered locally.
+It stands for loopback unicast routes, for broadcast routes
+and for multicast routes, if this host is a member of the corresponding
+group.
+
+\item \verb|reject| --- the path is bad. Any attempt to use it results
+in an error. See attribute \verb|error| below (p.\pageref{IP-ROUTE-GET-error}).
+
+\item \verb|mc| --- the destination is multicast.
+
+\item \verb|brd| --- the destination is broadcast.
+
+\item \verb|src-direct| --- the source is on a directly connected
+interface.
+
+\item \verb|redirected| --- the route was created by an ICMP Redirect.
+
+\item \verb|redirect| --- packets going via this route will 
+trigger an ICMP redirect.
+
+\item \verb|fastroute| --- the route is eligible to be used for fastroute.
+
+\item \verb|equalize| --- make packet by packet randomization
+along this path.
+
+\item \verb|dst-nat| --- the destination address requires translation.
+
+\item \verb|src-nat| --- the source address requires translation.
+
+\item \verb|masq| --- the source address requires masquerading.
+This feature disappeared in linux-2.4.
+
+\item \verb|notify| --- ({\em not implemented}) change/deletion
+of this route will trigger RTNETLINK notification.
+\end{itemize}
+
+Then some optional attributes follow:
+\begin{itemize}
+\item \verb|error| --- on \verb|reject| routes it is error code
+returned to local senders when they try to use this route.
+These error codes are translated into ICMP error codes, sent to remote
+senders, according to the rules described above in the subsection
+devoted to route types (p.\pageref{IP-ROUTE-TYPES}).
+\label{IP-ROUTE-GET-error}
+
+\item \verb|expires| --- this entry will expire after this timeout.
+
+\item \verb|iif| --- the packets for this path are expected to arrive
+on this interface.
+\end{itemize}
+
+\paragraph{Statistics:} With the \verb|-statistics| option, more
+information about this route is shown:
+\begin{itemize}
+\item \verb|users| --- the number of users of this entry.
+\item \verb|age| --- shows when this route was last used.
+\item \verb|used| --- the number of lookups of this route since its creation.
+\end{itemize}
+
+\subsection{{\tt ip route save} -- save routing tables}
+\label{IP-ROUTE-SAVE}
+
+\paragraph{Description:} this command saves the contents of the routing
+tables or the route(s) selected by some criteria to standard output.
+
+\paragraph{Arguments:} \verb|ip route save| has the same arguments as
+\verb|ip route show|.
+
+\paragraph{Example:} This saves all the routes to the {\tt saved\_routes}
+file:
+\begin{verbatim}
+dan@caffeine:~ # ip route save > saved_routes
+\end{verbatim}
+
+\paragraph{Output format:} The format of the data stream provided by
+\verb|ip route save| is that of \verb|rtnetlink|.  See
+\verb|rtnetlink(7)| for more information.
+
+\subsection{{\tt ip route restore} -- restore routing tables}
+\label{IP-ROUTE-RESTORE}
+
+\paragraph{Description:} this command restores the contents of the routing
+tables according to a data stream as provided by \verb|ip route save| via
+standard input.  Note that any routes already in the table are left unchanged.
+Any routes in the input stream that already exist in the tables are ignored.
+
+\paragraph{Arguments:} This command takes no arguments.
+
+\paragraph{Example:} This restores all routes that were saved to the
+{\tt saved\_routes} file:
+
+\begin{verbatim}
+dan@caffeine:~ # ip route restore < saved_routes
+\end{verbatim}
+
+\subsection{{\tt ip route flush} --- flush routing tables}
+\label{IP-ROUTE-FLUSH}
+
+\paragraph{Abbreviations:} \verb|flush|, \verb|f|.
+
+\paragraph{Description:} this command flushes routes selected
+by some criteria.
+
+\paragraph{Arguments:} the arguments have the same syntax and semantics
+as the arguments of \verb|ip route show|, but routing tables are not
+listed but purged. The only difference is the default action: \verb|show|
+dumps all the IP main routing table but \verb|flush| prints the helper page.
+The reason for this difference does not require any explanation, does it?
+
+
+\paragraph{Statistics:} With the \verb|-statistics| option, the command
+becomes verbose. It prints out the number of deleted routes and the number
+of rounds made to flush the routing table. If the option is given
+twice, \verb|ip route flush| also dumps all the deleted routes
+in the format described in the previous subsection.
+
+\paragraph{Examples:} The first example flushes all the
+gatewayed routes from the main table (f.e.\ after a routing daemon crash).
+\begin{verbatim}
+netadm@amber:~ # ip -4 ro flush scope global type unicast
+\end{verbatim}
+This option deserves to be put into a scriptlet \verb|routef|.
+\begin{NB}
+This option was described in the \verb|route(8)| man page borrowed
+from BSD, but was never implemented in Linux.
+\end{NB}
+
+The second example flushes all IPv6 cloned routes:
+\begin{verbatim}
+netadm@amber:~ # ip -6 -s -s ro flush cache
+3ffe:2400::220:afff:fef4:c5d1 via 3ffe:2400::220:afff:fef4:c5d1 \
+  dev eth0  metric 0 
+    cache  used 2 age 12sec mtu 1500 rtt 300
+3ffe:2400::280:adff:feb7:8034 via 3ffe:2400::280:adff:feb7:8034 \
+  dev eth0  metric 0 
+    cache  used 2 age 15sec mtu 1500 rtt 300
+3ffe:2400::280:c8ff:fe59:5bcc via 3ffe:2400::280:c8ff:fe59:5bcc \
+  dev eth0  metric 0 
+    cache  users 1 used 1 age 23sec mtu 1500 rtt 300
+3ffe:2400:0:1:2a0:ccff:fe66:1878 via 3ffe:2400:0:1:2a0:ccff:fe66:1878 \
+  dev eth1  metric 0 
+    cache  used 2 age 20sec mtu 1500 rtt 300
+3ffe:2400:0:1:a00:20ff:fe71:fb30 via 3ffe:2400:0:1:a00:20ff:fe71:fb30 \
+  dev eth1  metric 0 
+    cache  used 2 age 33sec mtu 1500 rtt 300
+ff02::1 via ff02::1 dev eth1  metric 0 
+    cache  users 1 used 1 age 45sec mtu 1500 rtt 300
+
+*** Round 1, deleting 6 entries ***
+*** Flush is complete after 1 round ***
+netadm@amber:~ # ip -6 -s -s ro flush cache
+Nothing to flush.
+netadm@amber:~ #
+\end{verbatim}
+
+The third example flushes BGP routing tables after a \verb|gated|
+death.
+\begin{verbatim}
+netadm@amber:~ # ip ro ls proto gated/bgp | wc
+   1408    9856    78730
+netadm@amber:~ # ip -s ro f proto gated/bgp
+
+*** Round 1, deleting 1408 entries ***
+*** Flush is complete after 1 round ***
+netadm@amber:~ # ip ro f proto gated/bgp
+Nothing to flush.
+netadm@amber:~ # ip ro ls proto gated/bgp
+netadm@amber:~ #
+\end{verbatim}
+
+
+\subsection{{\tt ip route get} --- get a single route}
+\label{IP-ROUTE-GET}
+
+\paragraph{Abbreviations:} \verb|get|, \verb|g|.
+
+\paragraph{Description:} this command gets a single route to a destination
+and prints its contents exactly as the kernel sees it.
+
+\paragraph{Arguments:} 
+\begin{itemize}
+\item \verb|to ADDRESS| (default)
+
+--- the destination address.
+
+\item \verb|from ADDRESS|
+
+--- the source address.
+
+\item \verb|tos TOS| or \verb|dsfield TOS|
+
+--- the Type Of Service.
+
+\item \verb|iif NAME|
+
+--- the device from which this packet is expected to arrive.
+
+\item \verb|oif NAME|
+
+--- force the output device on which this packet will be routed.
+
+\item \verb|connected|
+
+--- if no source address (option \verb|from|) was given, relookup
+the route with the source set to the preferred address received from the first lookup.
+If policy routing is used, it may be a different route.
+
+\end{itemize}
+
+Note that this operation is not equivalent to \verb|ip route show|.
+\verb|show| shows existing routes. \verb|get| resolves them and
+creates new clones if necessary. Essentially, \verb|get|
+is equivalent to sending a packet along this path.
+If the \verb|iif| argument is not given, the kernel creates a route
+to output packets towards the requested destination.
+This is equivalent to pinging the destination
+with a subsequent {\tt ip route ls cache}, however, no packets are
+actually sent. With the \verb|iif| argument, the kernel pretends
+that a packet arrived from this interface and searches for
+a path to forward the packet.
+
+\paragraph{Output format:} This command outputs routes in the same
+format as \verb|ip route ls|.
+
+\paragraph{Examples:} 
+\begin{itemize}
+\item Find a route to output packets to 193.233.7.82:
+\begin{verbatim}
+kuznet@amber:~ $ ip route get 193.233.7.82
+193.233.7.82 dev eth0  src 193.233.7.65 realms inr.ac
+    cache  mtu 1500 rtt 300
+kuznet@amber:~ $
+\end{verbatim}
+
+\item Find a route to forward packets arriving on \verb|eth0|
+from 193.233.7.82 and destined for 193.233.7.82:
+\begin{verbatim}
+kuznet@amber:~ $ ip r g 193.233.7.82 from 193.233.7.82 iif eth0
+193.233.7.82 from 193.233.7.82 dev eth0  src 193.233.7.65 \
+  realms inr.ac/inr.ac 
+    cache <src-direct,redirect>  mtu 1500 rtt 300 iif eth0
+kuznet@amber:~ $
+\end{verbatim}
+\begin{NB}
+  \label{NB-nature-of-strangeness}
+  This is the command that created the funny route from 193.233.7.82
+  looped back to 193.233.7.82 (cf.\ NB on~p.\pageref{NB-strange-route}).
+  Note the \verb|redirect| flag on it.
+\end{NB}
+
+\item Find a multicast route for packets arriving on \verb|eth0|
+from host 193.233.7.82 and destined for multicast group 224.2.127.254
+(it is assumed that a multicast routing daemon is running.
+In this case, it is \verb|pimd|)
+\begin{verbatim}
+kuznet@amber:~ $ ip r g 224.2.127.254 from 193.233.7.82 iif eth0
+multicast 224.2.127.254 from 193.233.7.82 dev lo  \
+  src 193.233.7.65 realms inr.ac/cosmos 
+    cache <mc> iif eth0 Oifs: eth1 pimreg
+kuznet@amber:~ $
+\end{verbatim}
+This route differs from the ones seen before. It contains a ``normal'' part
+and a ``multicast'' part. The normal part is used to deliver (or not to
+deliver) the packet to local IP listeners. In this case the router
+is not a member
+of this group, so that route has no \verb|local| flag and only
+forwards packets. The output device for such entries is always loopback.
+The multicast part consists of an additional \verb|Oifs:| list showing
+the output interfaces.
+\end{itemize}
+
+
+It is time for a more complicated example. Let us add an invalid
+gatewayed route for a destination which is really directly connected:
+\begin{verbatim}
+netadm@alisa:~ # ip route add 193.233.7.98 via 193.233.7.254
+netadm@alisa:~ # ip route get 193.233.7.98
+193.233.7.98 via 193.233.7.254 dev eth0  src 193.233.7.90
+    cache  mtu 1500 rtt 3072
+netadm@alisa:~ #
+\end{verbatim}
+and probe it with ping:
+\begin{verbatim}
+netadm@alisa:~ # ping -n 193.233.7.98
+PING 193.233.7.98 (193.233.7.98) from 193.233.7.90 : 56 data bytes
+From 193.233.7.254: Redirect Host(New nexthop: 193.233.7.98)
+64 bytes from 193.233.7.98: icmp_seq=0 ttl=255 time=3.5 ms
+From 193.233.7.254: Redirect Host(New nexthop: 193.233.7.98)
+64 bytes from 193.233.7.98: icmp_seq=1 ttl=255 time=2.2 ms
+64 bytes from 193.233.7.98: icmp_seq=2 ttl=255 time=0.4 ms
+64 bytes from 193.233.7.98: icmp_seq=3 ttl=255 time=0.4 ms
+64 bytes from 193.233.7.98: icmp_seq=4 ttl=255 time=0.4 ms
+^C
+--- 193.233.7.98 ping statistics ---
+5 packets transmitted, 5 packets received, 0% packet loss
+round-trip min/avg/max = 0.4/1.3/3.5 ms
+netadm@alisa:~ #
+\end{verbatim}
+What happened? Router 193.233.7.254 understood that we have a much
+better path to the destination and sent us an ICMP redirect message.
+We may retry \verb|ip route get| to see what we have in the routing
+tables now:
+\begin{verbatim}
+netadm@alisa:~ # ip route get 193.233.7.98
+193.233.7.98 dev eth0  src 193.233.7.90 
+    cache <redirected>  mtu 1500 rtt 3072
+netadm@alisa:~ #
+\end{verbatim}
+
+
+
+\section{{\tt ip rule} --- routing policy database management}
+\label{IP-RULE}
+
+\paragraph{Abbreviations:} \verb|rule|, \verb|ru|.
+
+\paragraph{Object:} \verb|rule|s in the routing policy database control
+the route selection algorithm.
+
+Classic routing algorithms used in the Internet make routing decisions
+based only on the destination address of packets (and in theory,
+but not in practice, on the TOS field). The seminal review of classic
+routing algorithms and their modifications can be found in~\cite{RFC1812}.
+
+In some circumstances we want to route packets differently depending not only
+on destination addresses, but also on other packet fields: source address,
+IP protocol, transport protocol ports or even packet payload.
+This task is called ``policy routing''.
+
+\begin{NB}
+  ``policy routing'' $\neq$ ``routing policy''.
+
+\noindent	``policy routing'' $=$ ``cunning routing''.
+
+\noindent	``routing policy'' $=$ ``routing tactics'' or ``routing plan''.
+\end{NB}
+
+To solve this task, the conventional destination based routing table, ordered
+according to the longest match rule, is replaced with a ``routing policy
+database'' (or RPDB), which selects routes
+by executing some set of rules. The rules may have lots of keys of different
+natures and therefore they have no natural ordering, but one imposed
+by the administrator. Linux-2.2 RPDB is a linear list of rules
+ordered by numeric priority value.
+RPDB explicitly allows matching a few packet fields:
+
+\begin{itemize}
+\item packet source address.
+\item packet destination address.
+\item TOS.
+\item incoming interface (which is packet metadata, rather than a packet field).
+\end{itemize}
+
+Matching IP protocols and transport ports is also possible,
+indirectly, via \verb|ipchains|, by exploiting their ability
+to mark some classes of packets with \verb|fwmark|. Therefore,
+\verb|fwmark| is also included in the set of keys checked by rules.
+
+Each policy routing rule consists of a {\em selector\/} and an {\em action\/}
+predicate. The RPDB is scanned in the order of increasing priority. The selector
+of each rule is applied to \{source address, destination address, incoming
+interface, tos, fwmark\} and, if the selector matches the packet,
+the action is performed.  The action predicate may return with success.
+In this case, it will either give a route or failure indication
+and the RPDB lookup is terminated. Otherwise, the RPDB program
+continues on the next rule.
+
+What is the action, semantically? The natural action is to select the
+nexthop and the output device. This is what
+Cisco IOS~\cite{IOS} does. Let us call it ``match \& set''.
+The Linux-2.2 approach is more flexible. The action includes
+lookups in destination-based routing tables and selecting
+a route from these tables according to the classic longest match algorithm.
+The ``match \& set'' approach is the simplest case of the Linux one. It is realized
+when a second level routing table contains a single default route.
+Recall that Linux-2.2 supports multiple tables
+managed with the \verb|ip route| command, described in the previous section.
+
+At startup time the kernel configures the default RPDB consisting of three
+rules:
+
+\begin{enumerate}
+\item Priority: 0, Selector: match anything, Action: lookup routing
+table \verb|local| (ID 255).
+The \verb|local| table is a special routing table containing
+high priority control routes for local and broadcast addresses.
+
+Rule 0 is special. It cannot be deleted or overridden.
+
+
+\item Priority: 32766, Selector: match anything, Action: lookup routing
+table \verb|main| (ID 254).
+The \verb|main| table is the normal routing table containing all non-policy
+routes. This rule may be deleted and/or overridden with other
+ones by the administrator.
+
+\item Priority: 32767, Selector: match anything, Action: lookup routing
+table \verb|default| (ID 253).
+The \verb|default| table is empty. It is reserved for some
+post-processing if no previous default rules selected the packet.
+This rule may also be deleted.
+
+\end{enumerate}
+
+Do not confuse routing tables with rules: rules point to routing tables,
+several rules may refer to one routing table and some routing tables
+may have no rules pointing to them. If the administrator deletes all the rules
+referring to a table, the table is not used, but it still exists
+and will disappear only after all the routes contained in it are deleted.
+
+
+\paragraph{Rule attributes:} Each RPDB entry has additional
+attributes. F.e.\ each rule has a pointer to some routing
+table. NAT and masquerading rules have an attribute to select new IP
+address to translate/masquerade. Besides that, rules have some
+optional attributes, which routes have, namely \verb|realms|.
+These values do not override those contained in the routing tables. They
+are only used if the route did not select any attributes.
+
+
+\paragraph{Rule types:} The RPDB may contain rules of the following
+types:
+\begin{itemize}
+\item \verb|unicast| --- the rule prescribes to return the route found
+in the routing table referenced by the rule.
+\item \verb|blackhole| --- the rule prescribes to silently drop the packet.
+\item \verb|unreachable| --- the rule prescribes to generate a ``Network
+is unreachable'' error.
+\item \verb|prohibit| --- the rule prescribes to generate
+``Communication is administratively prohibited'' error.
+\item \verb|nat| --- the rule prescribes to translate the source address
+of the IP packet into some other value. More about NAT is
+in Appendix~\ref{ROUTE-NAT}, p.\pageref{ROUTE-NAT}.
+\end{itemize}
+
+
+\paragraph{Commands:} \verb|add|, \verb|delete| and \verb|show|
+(or \verb|list|).
+
+\subsection{{\tt ip rule add} --- insert a new rule\\
+	{\tt ip rule delete} --- delete a rule}
+\label{IP-RULE-ADD}
+
+\paragraph{Abbreviations:} \verb|add|, \verb|a|; \verb|delete|, \verb|del|,
+	\verb|d|.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|type TYPE| (default)
+
+--- the type of this rule. The list of valid types was given in the previous
+subsection.
+
+\item \verb|from PREFIX|
+
+--- select the source prefix to match.
+
+\item \verb|to PREFIX|
+
+--- select the destination prefix to match.
+
+\item \verb|iif NAME|
+
+--- select the incoming device to match. If the interface is loopback,
+the rule only matches packets originating from this host. This means that you
+may create separate routing tables for forwarded and local packets and,
+hence, completely segregate them.
+
+\item \verb|tos TOS| or \verb|dsfield TOS|
+
+--- select the TOS value to match.
+
+\item \verb|fwmark MARK|
+
+--- select the \verb|fwmark| value to match.
+
+\item \verb|priority PREFERENCE|
+
+--- the priority of this rule. Each rule should have an explicitly
+set {\em unique\/} priority value.
+\begin{NB}
+  Really, for historical reasons \verb|ip rule add| does not require a
+  priority value and allows them to be non-unique.
+  If the user does not supplied a priority, it is selected by the kernel.
+  If the user creates a rule with a priority value that
+  already exists, the kernel does not reject the request. It adds
+  the new rule before all old rules of the same priority.
+
+  It is mistake in design, no more. And it will be fixed one day,
+  so do not rely on this feature. Use explicit priorities.
+\end{NB}
+
+
+\item \verb|table TABLEID|
+
+--- the routing table identifier to lookup if the rule selector matches.
+
+\item \verb|realms FROM/TO|
+
+--- Realms to select if the rule matched and the routing table lookup
+succeeded. Realm \verb|TO| is only used if the route did not select
+any realm.
+
+\item \verb|nat ADDRESS|
+
+--- The base of the IP address block to translate (for source addresses).
+The \verb|ADDRESS| may be either the start of the block of NAT addresses
+(selected by NAT routes) or in linux-2.2 a local host address (or even zero).
+In the last case the router does not translate the packets,
+but masquerades them to this address; this feature disappered in 2.4.
+More about NAT is in Appendix~\ref{ROUTE-NAT},
+p.\pageref{ROUTE-NAT}.
+
+\end{itemize}
+
+\paragraph{Warning:} Changes to the RPDB made with these commands
+do not become active immediately. It is assumed that after
+a script finishes a batch of updates, it flushes the routing cache
+with \verb|ip route flush cache|.
+
+\paragraph{Examples:}
+\begin{itemize}
+\item Route packets with source addresses from 192.203.80/24
+according to routing table \verb|inr.ruhep|:
+\begin{verbatim}
+ip ru add from 192.203.80.0/24 table inr.ruhep prio 220
+\end{verbatim}
+
+\item Translate packet source address 193.233.7.83 into 192.203.80.144
+and route it according to table \#1 (actually, it is \verb|inr.ruhep|):
+\begin{verbatim}
+ip ru add from 193.233.7.83 nat 192.203.80.144 table 1 prio 320
+\end{verbatim}
+
+\item Delete the unused default rule:
+\begin{verbatim}
+ip ru del prio 32767
+\end{verbatim}
+
+\end{itemize}
+
+
+
+\subsection{{\tt ip rule show} --- list rules}
+\label{IP-RULE-SHOW}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|sh|, \verb|ls|, \verb|l|.
+
+
+\paragraph{Arguments:} Good news, this is one command that has no arguments.
+
+\paragraph{Output format:}
+
+\begin{verbatim}
+kuznet@amber:~ $ ip ru ls
+0:	from all lookup local 
+200:	from 192.203.80.0/24 to 193.233.7.0/24 lookup main
+210:	from 192.203.80.0/24 to 192.203.80.0/24 lookup main
+220:	from 192.203.80.0/24 lookup inr.ruhep realms inr.ruhep/radio-msu
+300:	from 193.233.7.83 to 193.233.7.0/24 lookup main
+310:	from 193.233.7.83 to 192.203.80.0/24 lookup main
+320:	from 193.233.7.83 lookup inr.ruhep map-to 192.203.80.144
+32766:	from all lookup main 
+kuznet@amber:~ $
+\end{verbatim}
+
+In the first column is the rule priority value followed
+by a colon. Then the selectors follow. Each key is prefixed
+with the same keyword that was used to create the rule.
+
+The keyword \verb|lookup| is followed by a routing table identifier,
+as it is recorded in the file \verb|/etc/iproute2/rt_tables|.
+
+If the rule does NAT (f.e.\ rule \#320), it is shown by the keyword
+\verb|map-to| followed by the start of the block of addresses to map.
+
+The sense of this example is pretty simple. The prefixes
+192.203.80.0/24 and 193.233.7.0/24 form the internal network, but
+they are routed differently when the packets leave it.
+Besides that, the host 193.233.7.83 is translated into
+another prefix to look like 192.203.80.144 when talking
+to the outer world.
+
+\subsection{{\tt ip rule save} -- save rules tables}
+\label{IP-RULE-SAVE}
+
+\paragraph{Description:} this command saves the contents of the rules
+tables or the rule(s) selected by some criteria to standard output.
+
+\paragraph{Arguments:} \verb|ip rule save| has the same arguments as
+\verb|ip rule show|.
+
+\paragraph{Example:} This saves all the rules to the {\tt saved\_rules}
+file:
+\begin{verbatim}
+dan@caffeine:~ # ip rule save > saved_rules
+\end{verbatim}
+
+\paragraph{Output format:} The format of the data stream provided by
+\verb|ip rule save| is that of \verb|rtnetlink|.  See
+\verb|rtnetlink(7)| for more information.
+
+\subsection{{\tt ip rule restore} -- restore rules tables}
+\label{IP-RULE-RESTORE}
+
+\paragraph{Description:} this command restores the contents of the rules
+tables according to a data stream as provided by \verb|ip rule save| via
+standard input.  Note that any rules already in the table are left unchanged,
+and duplicates are not ignored.
+
+\paragraph{Arguments:} This command takes no arguments.
+
+\paragraph{Example:} This restores all rules that were saved to the
+{\tt saved\_rules} file:
+
+\begin{verbatim}
+dan@caffeine:~ # ip rule restore < saved_rules
+\end{verbatim}
+
+
+
+\section{{\tt ip maddress} --- multicast addresses management}
+\label{IP-MADDR}
+
+\paragraph{Object:} \verb|maddress| objects are multicast addresses.
+
+\paragraph{Commands:} \verb|add|, \verb|delete|, \verb|show| (or \verb|list|).
+
+\subsection{{\tt ip maddress show} --- list multicast addresses}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|sh|, \verb|ls|, \verb|l|.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+
+\item \verb|dev NAME| (default)
+
+--- the device name.
+
+\end{itemize}
+
+\paragraph{Output format:}
+
+\begin{verbatim}
+kuznet@alisa:~ $ ip maddr ls dummy
+2:  dummy
+    link  33:33:00:00:00:01
+    link  01:00:5e:00:00:01
+    inet  224.0.0.1 users 2
+    inet6 ff02::1
+kuznet@alisa:~ $ 
+\end{verbatim}
+
+The first line of the output shows the interface index and its name.
+Then the multicast address list follows. Each line starts with the
+protocol identifier. The word \verb|link| denotes a link layer
+multicast addresses.
+
+If a multicast address has more than one user, the number
+of users is shown after the \verb|users| keyword.
+
+One additional feature not present in the example above
+is the \verb|static| flag, which indicates that the address was joined
+with \verb|ip maddr add|. See the following subsection.
+
+
+
+\subsection{{\tt ip maddress add} --- add a multicast address\\
+	    {\tt ip maddress delete} --- delete a multicast address}
+
+\paragraph{Abbreviations:} \verb|add|, \verb|a|; \verb|delete|, \verb|del|, \verb|d|.
+
+\paragraph{Description:} these commands attach/detach
+a static link layer multicast address to listen on the interface.
+Note that it is impossible to join protocol multicast groups
+statically. This command only manages link layer addresses.
+
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|address LLADDRESS| (default)
+
+--- the link layer multicast address.
+
+\item \verb|dev NAME|
+
+--- the device to join/leave this multicast address.
+
+\end{itemize}
+
+
+\paragraph{Example:} Let us continue with the example from the previous subsection.
+
+\begin{verbatim}
+netadm@alisa:~ # ip maddr add 33:33:00:00:00:01 dev dummy
+netadm@alisa:~ # ip -0 maddr ls dummy
+2:  dummy
+    link  33:33:00:00:00:01 users 2 static
+    link  01:00:5e:00:00:01
+netadm@alisa:~ # ip maddr del 33:33:00:00:00:01 dev dummy
+\end{verbatim}
+
+\begin{NB}
+ Neither \verb|ip| nor the kernel check for multicast address validity.
+ Particularly, this means that you can try to load a unicast address
+ instead of a multicast address. Most drivers will ignore such addresses,
+ but several (f.e.\ Tulip) will intern it to their on-board filter.
+ The effects may be strange. Namely, the addresses become additional
+ local link addresses and, if you loaded the address of another host
+ to the router, wait for duplicated packets on the wire.
+ It is not a bug, but rather a hole in the API and intra-kernel interfaces.
+ This feature is really more useful for traffic monitoring, but using it
+ with Linux-2.2 you {\em have to\/} be sure that the host is not
+ a router and, especially, that it is not a transparent proxy or masquerading
+ agent.
+\end{NB}
+
+
+
+\section{{\tt ip mroute} --- multicast routing cache management}
+\label{IP-MROUTE}
+
+\paragraph{Abbreviations:} \verb|mroute|, \verb|mr|.
+
+\paragraph{Object:} \verb|mroute| objects are multicast routing cache
+entries created by a user level mrouting daemon
+(f.e.\ \verb|pimd| or \verb|mrouted|).
+
+Due to the limitations of the current interface to the multicast routing
+engine, it is impossible to change \verb|mroute| objects administratively,
+so we may only display them. This limitation will be removed
+in the future.
+
+\paragraph{Commands:} \verb|show| (or \verb|list|).
+
+
+\subsection{{\tt ip mroute show} --- list mroute cache entries}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|sh|, \verb|ls|, \verb|l|.
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+\item \verb|to PREFIX| (default)
+
+--- the prefix selecting the destination multicast addresses to list.
+
+
+\item \verb|iif NAME|
+
+--- the interface on which multicast packets are received.
+
+
+\item \verb|from PREFIX|
+
+--- the prefix selecting the IP source addresses of the multicast route.
+
+
+\end{itemize}
+
+\paragraph{Output format:}
+
+\begin{verbatim}
+kuznet@amber:~ $ ip mroute ls
+(193.232.127.6, 224.0.1.39)      Iif: unresolved 
+(193.232.244.34, 224.0.1.40)     Iif: unresolved 
+(193.233.7.65, 224.66.66.66)     Iif: eth0       Oifs: pimreg 
+kuznet@amber:~ $ 
+\end{verbatim}
+
+Each line shows one (S,G) entry in the multicast routing cache,
+where S is the source address and G is the multicast group. \verb|Iif| is
+the interface on which multicast packets are expected to arrive.
+If the word \verb|unresolved| is there instead of the interface name,
+it means that the routing daemon still hasn't resolved this entry.
+The keyword \verb|oifs| is followed by a list of output interfaces, separated
+by spaces. If a multicast routing entry is created with non-trivial
+TTL scope, administrative distances are appended to the device names
+in the \verb|oifs| list.
+
+\paragraph{Statistics:} The \verb|-statistics| option also prints the
+number of packets and bytes forwarded along this route and
+the number of packets that arrived on the wrong interface, if this number is not zero.
+
+\begin{verbatim}
+kuznet@amber:~ $ ip -s mr ls 224.66/16
+(193.233.7.65, 224.66.66.66)     Iif: eth0       Oifs: pimreg 
+  9383 packets, 300256 bytes
+kuznet@amber:~ $
+\end{verbatim}
+
+
+\section{{\tt ip tunnel} --- tunnel configuration}
+\label{IP-TUNNEL}
+
+\paragraph{Abbreviations:} \verb|tunnel|, \verb|tunl|.
+
+\paragraph{Object:} \verb|tunnel| objects are tunnels, encapsulating
+packets in IPv4 packets and then sending them over the IP infrastructure.
+
+\paragraph{Commands:} \verb|add|, \verb|delete|, \verb|change|, \verb|show|
+(or \verb|list|).
+
+\paragraph{See also:} A more informal discussion of tunneling
+over IP and the \verb|ip tunnel| command can be found in~\cite{IP-TUNNELS}.
+
+\subsection{{\tt ip tunnel add} --- add a new tunnel\\
+	{\tt ip tunnel change} --- change an existing tunnel\\
+	{\tt ip tunnel delete} --- destroy a tunnel}
+
+\paragraph{Abbreviations:} \verb|add|, \verb|a|; \verb|change|, \verb|chg|;
+\verb|delete|, \verb|del|, \verb|d|.
+
+
+\paragraph{Arguments:}
+
+\begin{itemize}
+
+\item \verb|name NAME| (default)
+
+--- select the tunnel device name.
+
+\item \verb|mode MODE|
+
+--- set the tunnel mode. Three modes are currently available:
+	\verb|ipip|, \verb|sit| and \verb|gre|.
+
+\item \verb|remote ADDRESS|
+
+--- set the remote endpoint of the tunnel.
+
+\item \verb|local ADDRESS|
+
+--- set the fixed local address for tunneled packets.
+It must be an address on another interface of this host.
+
+\item \verb|ttl N|
+
+--- set a fixed TTL \verb|N| on tunneled packets.
+	\verb|N| is a number in the range 1--255. 0 is a special value
+	meaning that packets inherit the TTL value. 
+		The default value is: \verb|inherit|.
+
+\item \verb|tos T| or \verb|dsfield T|
+
+--- set a fixed TOS \verb|T| on tunneled packets.
+		The default value is: \verb|inherit|.
+
+
+
+\item \verb|dev NAME| 
+
+--- bind the tunnel to the device \verb|NAME| so that
+	tunneled packets will only be routed via this device and will
+	not be able to escape to another device when the route to endpoint changes.
+
+\item \verb|nopmtudisc|
+
+--- disable Path MTU Discovery on this tunnel.
+	It is enabled by default. Note that a fixed ttl is incompatible
+	with this option: tunnelling with a fixed ttl always makes pmtu discovery.
+
+\item \verb|key K|, \verb|ikey K|, \verb|okey K|
+
+--- (only GRE tunnels) use keyed GRE with key \verb|K|. \verb|K| is
+	either a number or an IP address-like dotted quad.
+   The \verb|key| parameter sets the key to use in both directions.
+   The \verb|ikey| and \verb|okey| parameters set different keys for input and output.
+   
+
+\item \verb|csum|, \verb|icsum|, \verb|ocsum|
+
+--- (only GRE tunnels) generate/require checksums for tunneled packets.
+   The \verb|ocsum| flag calculates checksums for outgoing packets.
+   The \verb|icsum| flag requires that all input packets have the correct
+   checksum. The \verb|csum| flag is equivalent to the combination
+  ``\verb|icsum| \verb|ocsum|''.
+
+\item \verb|seq|, \verb|iseq|, \verb|oseq|
+
+--- (only GRE tunnels) serialize packets.
+   The \verb|oseq| flag enables sequencing of outgoing packets.
+   The \verb|iseq| flag requires that all input packets are serialized.
+   The \verb|seq| flag is equivalent to the combination ``\verb|iseq| \verb|oseq|''.
+
+\begin{NB}
+ I think this option does not
+	work. At least, I did not test it, did not debug it and
+	do not even understand how it is supposed to work or for what
+	purpose Cisco planned to use it. Do not use it.
+\end{NB}
+
+
+\end{itemize}
+
+\paragraph{Example:} Create a pointopoint IPv6 tunnel with maximal TTL of 32.
+\begin{verbatim}
+netadm@amber:~ # ip tunl add Cisco mode sit remote 192.31.7.104 \
+    local 192.203.80.142 ttl 32 
+\end{verbatim}
+
+\subsection{{\tt ip tunnel show} --- list tunnels}
+
+\paragraph{Abbreviations:} \verb|show|, \verb|list|, \verb|sh|, \verb|ls|, \verb|l|.
+
+
+\paragraph{Arguments:} None.
+
+\paragraph{Output format:}
+\begin{verbatim}
+kuznet@amber:~ $ ip tunl ls Cisco
+Cisco: ipv6/ip  remote 192.31.7.104  local 192.203.80.142  ttl 32 
+kuznet@amber:~ $ 
+\end{verbatim}
+The line starts with the tunnel device name followed by a colon.
+Then the tunnel mode follows. The parameters of the tunnel are listed
+with the same keywords that were used when creating the tunnel.
+
+\paragraph{Statistics:}
+
+\begin{verbatim}
+kuznet@amber:~ $ ip -s tunl ls Cisco
+Cisco: ipv6/ip  remote 192.31.7.104  local 192.203.80.142  ttl 32 
+RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts
+    12566      1707516      0      0        0        0       
+TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs
+    13445      1879677      0      0        0        0     
+kuznet@amber:~ $ 
+\end{verbatim}
+Essentially, these numbers are the same as the numbers
+printed with {\tt ip -s link show}
+(sec.\ref{IP-LINK-SHOW}, p.\pageref{IP-LINK-SHOW}) but the tags are different
+to reflect that they are tunnel specific.
+\begin{itemize}
+\item \verb|CsumErrs| --- the total number of packets dropped
+because of checksum failures for a GRE tunnel with checksumming enabled.
+\item \verb|OutOfSeq| --- the total number of packets dropped
+because they arrived out of sequence for a GRE tunnel with
+serialization enabled.
+\item \verb|Mcasts| --- the total number of multicast packets
+received on a broadcast GRE tunnel.
+\item \verb|DeadLoop| --- the total number of packets which were not
+transmitted because the tunnel is looped back to itself.
+\item \verb|NoRoute| --- the total number of packets which were not
+transmitted because there is no IP route to the remote endpoint.
+\item \verb|NoBufs| --- the total number of packets which were not
+transmitted because the kernel failed to allocate a buffer.
+\end{itemize}
+
+
+\section{{\tt ip monitor} and {\tt rtmon} --- state monitoring}
+\label{IP-MONITOR}
+
+The \verb|ip| utility can monitor the state of devices, addresses
+and routes continuously. This option has a slightly different format.
+Namely,
+the \verb|monitor| command is the first in the command line and then
+the object list follows:
+\begin{verbatim}
+  ip monitor [ file FILE ] [ all | OBJECT-LIST ] [ label ]
+\end{verbatim}
+\verb|OBJECT-LIST| is the list of object types that we want to
+monitor.  It may contain \verb|link|, \verb|address| and \verb|route|.
+Specifying \verb|label| indicates that output lines should be labelled
+with the type of object being printed --- this happens by default if
+\verb|all| is specified.  If no \verb|file| argument is given,
+\verb|ip| opens RTNETLINK, listens on it and dumps state changes in
+the format described in previous sections.
+
+If a file name is given, it does not listen on RTNETLINK,
+but opens the file containing RTNETLINK messages saved in binary format
+and dumps them. Such a history file can be generated with the
+\verb|rtmon| utility. This utility has a command line syntax similar to
+\verb|ip monitor|.
+Ideally, \verb|rtmon| should be started before
+the first network configuration command is issued. F.e.\ if
+you insert:
+\begin{verbatim}
+  rtmon file /var/log/rtmon.log
+\end{verbatim}
+in a startup script, you will be able to view the full history
+later.
+
+Certainly, it is possible to start \verb|rtmon| at any time.
+It prepends the history with the state snapshot dumped at the moment
+of starting.
+
+
+\section{Route realms and policy propagation, {\tt rtacct}}
+\label{RT-REALMS}
+
+On routers using OSPF ASE or, especially, the BGP protocol, routing
+tables may be huge. If we want to classify or to account for the packets
+per route, we will have to keep lots of information. Even worse, if we
+want to distinguish the packets not only by their destination, but
+also by their source, the task gets quadratic complexity and its solution
+is physically impossible.
+
+One approach to propagating the policy from routing protocols
+to the forwarding engine has been proposed in~\cite{IOS-BGP-PP}.
+Essentially, Cisco Policy Propagation via BGP is based on the fact
+that dedicated routers all have the RIB (Routing Information Base)
+close to the forwarding engine, so policy routing rules can
+check all the route attributes, including ASPATH information
+and community strings.
+
+The Linux architecture, splitting the RIB (maintained by a user level
+daemon) and the kernel based FIB (Forwarding Information Base),
+does not allow such a simple approach.
+
+It is to our fortune because there is another solution
+which allows even more flexible policy and richer semantics.
+
+Namely, routes can be clustered together in user space, based on their
+attributes.  F.e.\ a BGP router knows route ASPATH, its community;
+an OSPF router knows the route tag or its area. The administrator, when adding
+routes manually, also knows their nature. Providing that the number of such
+aggregates (we call them {\em realms\/}) is low, the task of full
+classification both by source and destination becomes quite manageable.
+
+So each route may be assigned to a realm. It is assumed that
+this identification is made by a routing daemon, but static routes
+can also be handled manually with \verb|ip route| (see sec.\ref{IP-ROUTE},
+p.\pageref{IP-ROUTE}).
+\begin{NB}
+  There is a patch to \verb|gated|, allowing classification of routes
+  to realms with all the set of policy rules implemented in \verb|gated|:
+  by prefix, by ASPATH, by origin, by tag etc.
+\end{NB}
+
+To facilitate the construction (f.e.\ in case the routing
+daemon is not aware of realms), missing realms may be completed
+with routing policy rules, see sec.~\ref{IP-RULE}, p.\pageref{IP-RULE}.
+
+For each packet the kernel calculates a tuple of realms: source realm
+and destination realm, using the following algorithm:
+
+\begin{enumerate}
+\item If the route has a realm, the destination realm of the packet is set to it.
+\item If the rule has a source realm, the source realm of the packet is set to it.
+If the destination realm was not inherited from the route and the rule has a destination realm,
+it is also set.
+\item If at least one of the realms is still unknown, the kernel finds
+the reversed route to the source of the packet.
+\item If the source realm is still unknown, get it from the reversed route.
+\item If one of the realms is still unknown, swap the realms of reversed
+routes and apply step 2 again.
+\end{enumerate}
+
+After this procedure is completed we know what realm the packet
+arrived from and the realm where it is going to propagate to.
+If some of the realms are unknown, they are initialized to zero
+(or realm \verb|unknown|).
+
+The main application of realms is the TC \verb|route| classifier~\cite{TC-CREF},
+where they are used to help assign packets to traffic classes,
+to account, police and schedule them according to this
+classification.
+
+A much simpler but still very useful application is incoming packet
+accounting by realms. The kernel gathers a packet statistics summary
+which can be viewed with the \verb|rtacct| utility.
+\begin{verbatim}
+kuznet@amber:~ $ rtacct russia
+Realm      BytesTo    PktsTo     BytesFrom  PktsFrom   
+russia     20576778   169176     47080168   153805     
+kuznet@amber:~ $
+\end{verbatim}
+This shows that this router received 153805 packets from
+the realm \verb|russia| and forwarded 169176 packets to \verb|russia|.
+The realm \verb|russia| consists of routes with ASPATHs not leaving
+Russia.
+
+Note that locally originating packets are not accounted here,
+\verb|rtacct| shows incoming packets only. Using the \verb|route|
+classifier (see~\cite{TC-CREF}) you can get even more detailed
+accounting information about outgoing packets, optionally
+summarizing traffic not only by source or destination, but
+by any pair of source and destination realms.
+
+
+\begin{thebibliography}{99}
+\addcontentsline{toc}{section}{References}
+\bibitem{RFC-NDISC} T.~Narten, E.~Nordmark, W.~Simpson.
+``Neighbor Discovery for IP Version 6 (IPv6)'', RFC-2461.
+
+\bibitem{RFC-ADDRCONF} S.~Thomson, T.~Narten.
+``IPv6 Stateless Address Autoconfiguration'', RFC-2462.
+
+\bibitem{RFC1812} F.~Baker.
+``Requirements for IP Version 4 Routers'', RFC-1812.
+
+\bibitem{RFC1122} R.~T.~Braden.
+``Requirements for Internet hosts --- communication layers'', RFC-1122.
+
+\bibitem{IOS} ``Cisco IOS Release 12.0 Network Protocols
+Command Reference, Part 1'' and
+``Cisco IOS Release 12.0 Quality of Service Solutions
+Configuration Guide: Configuring Policy-Based Routing'',\\
+http://www.cisco.com/univercd/cc/td/doc/product/software/ios120.
+
+\bibitem{IP-TUNNELS} A.~N.~Kuznetsov.
+``Tunnels over IP in Linux-2.2'', \\
+In: {\tt ftp://ftp.inr.ac.ru/ip-routing/iproute2-current.tar.gz}.
+
+\bibitem{TC-CREF} A.~N.~Kuznetsov. ``TC Command Reference'',\\
+In: {\tt ftp://ftp.inr.ac.ru/ip-routing/iproute2-current.tar.gz}.
+
+\bibitem{IOS-BGP-PP} ``Cisco IOS Release 12.0 Quality of Service Solutions
+Configuration Guide: Configuring QoS Policy Propagation via
+Border Gateway Protocol'',\\
+http://www.cisco.com/univercd/cc/td/doc/product/software/ios120.
+
+\bibitem{RFC-DHCP} R.~Droms.
+``Dynamic Host Configuration Protocol.'', RFC-2131
+
+\bibitem{RFC2414}  M.~Allman, S.~Floyd, C.~Partridge.
+``Increasing TCP's Initial Window'', RFC-2414.
+
+\end{thebibliography}
+
+
+
+
+\appendix
+\addcontentsline{toc}{section}{Appendix}
+
+\section{Source address selection}
+\label{ADDR-SEL}
+
+When a host creates an IP packet, it must select some source
+address. Correct source address selection is a critical procedure,
+because it gives the receiver the information needed to deliver a
+reply. If the source is selected incorrectly, in the best case,
+the backward path may appear different to the forward one which
+is harmful for performance. In the worst case, when the addresses
+are administratively scoped, the reply may be lost entirely.
+
+Linux-2.2 selects source addresses using the following algorithm:
+
+\begin{itemize}
+\item
+The application may select a source address explicitly with \verb|bind(2)|
+syscall or supplying it to \verb|sendmsg(2)| via the ancillary data object
+\verb|IP_PKTINFO|. In this case the kernel only checks the validity
+of the address and never tries to ``improve'' an incorrect user choice,
+generating an error instead.
+\begin{NB}
+ Never say ``Never''. The sysctl option \verb|ip_dynaddr| breaks
+ this axiom. It has been made deliberately with the purpose
+ of automatically reselecting the address on hosts with dynamic dial-out interfaces.
+ However, this hack {\em must not\/} be used on multihomed hosts
+ and especially on routers: it would break them.
+\end{NB}
+
+
+\item Otherwise, IP routing tables can contain an explicit source
+address hint for this destination. The hint is set with the \verb|src| parameter
+to the \verb|ip route| command, sec.\ref{IP-ROUTE}, p.\pageref{IP-ROUTE}.
+
+
+\item Otherwise, the kernel searches through the list of addresses
+attached to the interface through which the packets will be routed.
+The search strategies are different for IP and IPv6. Namely:
+
+\begin{itemize}
+\item IPv6 searches for the first valid, not deprecated address
+with the same scope as the destination.
+
+\item IP searches for the first valid address with a scope wider
+than the scope of the destination but it prefers addresses
+which fall to the same subnet as the nexthop of the route
+to the destination. Unlike IPv6, the scopes of IPv4 destinations
+are not encoded in their addresses but are supplied
+in routing tables instead (the \verb|scope| parameter to the \verb|ip route| command,
+sec.\ref{IP-ROUTE}, p.\pageref{IP-ROUTE}).
+
+\end{itemize}
+
+
+\item Otherwise, if the scope of the destination is \verb|link| or \verb|host|,
+the algorithm fails and returns a zero source address.
+
+\item Otherwise, all interfaces are scanned to search for an address
+with an appropriate scope. The loopback device \verb|lo| is always the first
+in the search list, so that if an address with global scope (not 127.0.0.1!)
+is configured on loopback, it is always preferred.
+
+\end{itemize}
+
+
+\section{Proxy ARP/NDISC}
+\label{PROXY-NEIGH}
+
+Routers may answer ARP/NDISC solicitations on behalf of other hosts.
+In Linux-2.2 proxy ARP on an interface may be enabled
+by setting the kernel \verb|sysctl| variable 
+\verb|/proc/sys/net/ipv4/conf/<dev>/proxy_arp| to 1. After this, the router
+starts to answer ARP requests on the interface \verb|<dev>|, provided
+the route to the requested destination does {\em not\/} go back via the same
+device.
+
+The variable \verb|/proc/sys/net/ipv4/conf/all/proxy_arp| enables proxy
+ARP on all the IP devices.
+
+However, this approach fails in the case of IPv6 because the router
+must join the solicited node multicast address to listen for the corresponding
+NDISC queries. It means that proxy NDISC is possible only on a per destination
+basis.
+
+Logically, proxy ARP/NDISC is not a kernel task. It can easily be implemented
+in user space. However, similar functionality was present in BSD kernels
+and in Linux-2.0, so we have to preserve it at least to the extent that
+is standardized in BSD.
+\begin{NB}
+  Linux-2.0 ARP had a feature called {\em subnet\/} proxy ARP.
+  It is replaced with the sysctl flag in Linux-2.2.
+\end{NB}
+
+
+The \verb|ip| utility provides a way to manage proxy ARP/NDISC
+with the \verb|ip neigh| command, namely:
+\begin{verbatim}
+  ip neigh add proxy ADDRESS [ dev NAME ]
+\end{verbatim}
+adds a new proxy ARP/NDISC record and
+\begin{verbatim}
+  ip neigh del proxy ADDRESS [ dev NAME ]
+\end{verbatim}
+deletes it.
+
+If the name of the device is not given, the router will answer solicitations
+for address \verb|ADDRESS| on all devices, otherwise it will only serve
+the device \verb|NAME|. Even if the proxy entry is created with
+\verb|ip neigh|, the router {\em will not\/} answer a query if the route
+to the destination goes back via the interface from which the solicitation
+was received.
+
+It is important to emphasize that proxy entries have {\em no\/}
+parameters other than these (IP/IPv6 address and optional device).
+Particularly, the entry does not store any link layer address.
+It always advertises the station address of the interface
+on which it sends advertisements (i.e. it's own station address).
+
+\section{Route NAT status}
+\label{ROUTE-NAT}
+
+NAT (or ``Network Address Translation'') remaps some parts
+of the IP address space into other ones. Linux-2.2 route NAT is supposed
+to be used to facilitate policy routing by rewriting addresses
+to other routing domains or to help while renumbering sites
+to another prefix.
+
+\paragraph{What it is not:}
+It is necessary to emphasize that {\em it is not supposed\/}
+to be used to compress address space or to split load.
+This is not missing functionality but a design principle.
+Route NAT is {\em stateless\/}. It does not hold any state
+about translated sessions. This means that it handles any number
+of sessions flawlessly. But it also means that it is {\em static\/}.
+It cannot detect the moment when the last TCP client stops
+using an address. For the same reason, it will not help to split
+load between several servers.
+\begin{NB}
+It is a pretty commonly held belief that it is useful to split load between
+several servers with NAT. This is a mistake. All you get from this
+is the requirement that the router keep the state of all the TCP connections
+going via it. Well, if the router is so powerful, run apache on it. 8)
+\end{NB}
+
+The second feature: it does not touch packet payload,
+does not try to ``improve'' broken protocols by looking
+through its data and mangling it. It mangles IP addresses,
+only IP addresses and nothing but IP addresses.
+This also, is not missing any functionality.
+
+To resume: if you need to compress address space or keep
+active FTP clients happy, your choice is not route NAT but masquerading,
+port forwarding, NAPT etc. 
+\begin{NB}
+By the way, you may also want to look at
+http://www.suse.com/\~mha/HyperNews/get/linux-ip-nat.html
+\end{NB}
+
+
+\paragraph{How it works.}
+Some part of the address space is reserved for dummy addresses
+which will look for all the world like some host addresses
+inside your network. No other hosts may use these addresses,
+however other routers may also be configured to translate them.
+\begin{NB}
+A great advantage of route NAT is that it may be used not
+only in stub networks but in environments with arbitrarily complicated
+structure. It does not firewall, it {\em forwards.}
+\end{NB}
+These addresses are selected by the \verb|ip route| command
+(sec.\ref{IP-ROUTE-ADD}, p.\pageref{IP-ROUTE-ADD}). F.e.\
+\begin{verbatim}
+  ip route add nat 192.203.80.144 via 193.233.7.83
+\end{verbatim}
+states that the single address 192.203.80.144 is a dummy NAT address.
+For all the world it looks like a host address inside our network.
+For neighbouring hosts and routers it looks like the local address
+of the translating router. The router answers ARP for it, advertises
+this address as routed via it, {\em et al\/}. When the router
+receives a packet destined for 192.203.80.144, it replaces 
+this address with 193.233.7.83 which is the address of some real
+host and forwards the packet. If you need to remap
+blocks of addresses, you may use a command like:
+\begin{verbatim}
+  ip route add nat 192.203.80.192/26 via 193.233.7.64
+\end{verbatim}
+This command will map a block of 63 addresses 192.203.80.192-255 to
+193.233.7.64-127.
+
+When an internal host (193.233.7.83 in the example above)
+sends something to the outer world and these packets are forwarded
+by our router, it should translate the source address 193.233.7.83
+into 192.203.80.144. This task is solved by setting a special
+policy rule (sec.\ref{IP-RULE-ADD}, p.\pageref{IP-RULE-ADD}):
+\begin{verbatim}
+  ip rule add prio 320 from 193.233.7.83 nat 192.203.80.144
+\end{verbatim}
+This rule says that the source address 193.233.7.83
+should be translated into 192.203.80.144 before forwarding.
+It is important that the address after the \verb|nat| keyword
+is some NAT address, declared by {\tt ip route add nat}.
+If it is just a random address the router will not map to it.
+\begin{NB}
+The exception is when the address is a local address of this
+router (or 0.0.0.0) and masquerading is configured in the linux-2.2
+kernel. In this case the router will masquerade the packets as this address.
+If 0.0.0.0 is selected, the result is equivalent to one
+obtained with firewalling rules. Otherwise, you have the way
+to order Linux to masquerade to this fixed address.
+NAT mechanism used in linux-2.4 is more flexible than
+masquerading, so that this feature has lost meaning and disabled.
+\end{NB}
+
+If the network has non-trivial internal structure, it is
+useful and even necessary to add rules disabling translation
+when a packet does not leave this network. Let us return to the
+example from sec.\ref{IP-RULE-SHOW} (p.\pageref{IP-RULE-SHOW}).
+\begin{verbatim}
+300:	from 193.233.7.83 to 193.233.7.0/24 lookup main
+310:	from 193.233.7.83 to 192.203.80.0/24 lookup main
+320:	from 193.233.7.83 lookup inr.ruhep map-to 192.203.80.144
+\end{verbatim}
+This block of rules causes normal forwarding when
+packets from 193.233.7.83 do not leave networks 193.233.7/24
+and 192.203.80/24. Also, if the \verb|inr.ruhep| table does not
+contain a route to the destination (which means that the routing
+domain owning addresses from 192.203.80/24 is dead), no translation
+will occur. Otherwise, the packets are translated.
+
+\paragraph{How to only translate selected ports:}
+If you only want to translate selected ports (f.e.\ http)
+and leave the rest intact, you may use \verb|ipchains|
+to \verb|fwmark| a class of packets.
+Suppose you did and all the packets from 193.233.7.83
+destined for port 80 are marked with marker 0x1234 in input fwchain.
+In this case you may replace rule \#320 with:
+\begin{verbatim}
+320:	from 193.233.7.83 fwmark 1234 lookup main map-to 192.203.80.144
+\end{verbatim}
+and translation will only be enabled for outgoing http requests.
+
+\section{Example: minimal host setup}
+\label{EXAMPLE-SETUP}
+
+The following script gives an example of a fault safe
+setup of IP (and IPv6, if it is compiled into the kernel)
+in the common case of a node attached to a single broadcast
+network. A more advanced script, which may be used both on multihomed
+hosts and on routers, is described in the following
+section.
+
+The utilities used in the script may be found in the
+directory ftp://ftp.inr.ac.ru/ip-routing/:
+\begin{enumerate}
+\item \verb|ip| --- package \verb|iproute2|.
+\item \verb|arping| --- package \verb|iputils|.
+\item \verb|rdisc| --- package \verb|iputils|.
+\end{enumerate}
+\begin{NB}
+It also refers to a DHCP client, \verb|dhcpcd|. I should refrain from
+recommending a good DHCP client to use. All that I can
+say is that ISC \verb|dhcp-2.0b1pl6| patched with the patch that
+can be found in the \verb|dhcp.bootp.rarp| subdirectory of
+the same ftp site {\em does\/} work,
+at least on Ethernet and Token Ring.
+\end{NB}
+
+\begin{verbatim}
+#! /bin/bash
+\end{verbatim}
+\begin{flushleft}
+\# {\bf Usage: \verb|ifone ADDRESS[/PREFIX-LENGTH] [DEVICE]|}\\
+\# {\bf Parameters:}\\
+\# \$1 --- Static IP address, optionally followed by prefix length.\\
+\# \$2 --- Device name. If it is missing, \verb|eth0| is asssumed.\\
+\# F.e. \verb|ifone 193.233.7.90|
+\end{flushleft}
+\begin{verbatim}
+dev=$2
+: ${dev:=eth0}
+ipaddr=
+\end{verbatim}
+\# Parse IP address, splitting prefix length.
+\begin{verbatim}
+if [ "$1" != "" ]; then
+  ipaddr=${1%/*}
+  if [ "$1" != "$ipaddr" ]; then
+    pfxlen=${1#*/}
+  fi
+  : ${pfxlen:=24}
+fi
+pfx="${ipaddr}/${pfxlen}"
+\end{verbatim}
+
+\begin{flushleft}
+\# {\bf Step 0} --- enable loopback.\\
+\#\\
+\# This step is necessary on any networked box before attempt\\
+\# to configure any other device.\\
+\end{flushleft}
+\begin{verbatim}
+ip link set up dev lo
+ip addr add 127.0.0.1/8 dev lo brd + scope host
+\end{verbatim}
+\begin{flushleft}
+\# IPv6 autoconfigure themself on loopback.\\
+\#\\
+\# If user gave loopback as device, we add the address as alias and exit.
+\end{flushleft}
+\begin{verbatim}
+if [ "$dev" = "lo" ]; then
+  if [ "$ipaddr" != "" -a  "$ipaddr" != "127.0.0.1" ]; then
+    ip address add $ipaddr dev $dev
+    exit $?
+  fi
+  exit 0
+fi
+\end{verbatim}
+
+\noindent\# {\bf Step 1} --- enable device \verb|$dev|
+
+\begin{verbatim}
+if ! ip link set up dev $dev ; then
+  echo "Cannot enable interface $dev. Aborting." 1>&2
+  exit 1
+fi
+\end{verbatim}
+\begin{flushleft}
+\# The interface is \verb|UP|. IPv6 started stateless autoconfiguration itself,\\
+\# and its configuration finishes here. However,\\
+\# IP still needs some static preconfigured address.
+\end{flushleft}
+\begin{verbatim}
+if [ "$ipaddr" = "" ]; then
+  echo "No address for $dev is configured, trying DHCP..." 1>&2
+  dhcpcd
+  exit $?
+fi
+\end{verbatim}
+
+\begin{flushleft}
+\# {\bf Step 2} --- IP Duplicate Address Detection~\cite{RFC-DHCP}.\\
+\# Send two probes and wait for result for 3 seconds.\\
+\# If the interface opens slower f.e.\ due to long media detection,\\
+\# you want to increase the timeout.\\
+\end{flushleft}
+\begin{verbatim}
+if ! arping -q -c 2 -w 3 -D -I $dev $ipaddr ; then
+  echo "Address $ipaddr is busy, trying DHCP..." 1>&2
+  dhcpcd
+  exit $?
+fi
+\end{verbatim}
+\begin{flushleft}
+\# OK, the address is unique, we may add it on the interface.\\
+\#\\
+\# {\bf Step 3} --- Configure the address on the interface.
+\end{flushleft}
+
+\begin{verbatim}
+if ! ip address add $pfx brd + dev $dev; then
+  echo "Failed to add $pfx on $dev, trying DHCP..." 1>&2
+  dhcpcd
+  exit $?
+fi
+\end{verbatim}
+
+\noindent\# {\bf Step 4} --- Announce our presence on the link.
+\begin{verbatim}
+arping -A -c 1 -I $dev $ipaddr
+noarp=$?
+( sleep 2;
+  arping -U -c 1 -I $dev $ipaddr ) >& /dev/null </dev/null &
+\end{verbatim}
+
+\begin{flushleft}
+\# {\bf Step 5} (optional) --- Add some control routes.\\
+\#\\
+\# 1. Prohibit link local multicast addresses.\\
+\# 2. Prohibit link local (alias, limited) broadcast.\\
+\# 3. Add default multicast route.
+\end{flushleft}
+\begin{verbatim}
+ip route add unreachable 224.0.0.0/24 
+ip route add unreachable 255.255.255.255
+if [ `ip link ls $dev | grep -c MULTICAST` -ge 1 ]; then
+  ip route add 224.0.0.0/4 dev $dev scope global
+fi
+\end{verbatim}
+
+\begin{flushleft}
+\# {\bf Step 6} --- Add fallback default route with huge metric.\\
+\# If a proxy ARP server is present on the interface, we will be\\
+\# able to talk to all the Internet without further configuration.\\
+\# It is not so cheap though and we still hope that this route\\
+\# will be overridden by more correct one by rdisc.\\
+\# Do not make this step if the device is not ARPable,\\
+\# because dead nexthop detection does not work on them.
+\end{flushleft}
+\begin{verbatim}
+if [ "$noarp" = "0" ]; then
+  ip ro add default dev $dev metric 30000 scope global
+fi
+\end{verbatim}
+
+\begin{flushleft}
+\# {\bf Step 7} --- Restart router discovery and exit.
+\end{flushleft}
+\begin{verbatim}
+killall -HUP rdisc || rdisc -fs
+exit 0
+\end{verbatim}
+
+
+\section{Example: {\protect\tt ifcfg} --- interface address management}
+\label{EXAMPLE-IFCFG}
+
+This is a simplistic script replacing one option of \verb|ifconfig|,
+namely, IP address management. It not only adds
+addresses, but also carries out Duplicate Address Detection~\cite{RFC-DHCP},
+sends unsolicited ARP to update the caches of other hosts sharing
+the interface, adds some control routes and restarts Router Discovery
+when it is necessary.
+
+I strongly recommend using it {\em instead\/} of \verb|ifconfig| both
+on hosts and on routers.
+
+\begin{verbatim}
+#! /bin/bash
+\end{verbatim}
+\begin{flushleft}
+\# {\bf Usage: \verb?ifcfg DEVICE[:ALIAS] [add|del] ADDRESS[/LENGTH] [PEER]?}\\
+\# {\bf Parameters:}\\
+\# ---Device name. It may have alias suffix, separated by colon.\\
+\# ---Command: add, delete or stop.\\
+\# ---IP address, optionally followed by prefix length.\\
+\# ---Optional peer address for pointopoint interfaces.\\
+\# F.e. \verb|ifcfg eth0 193.233.7.90/24|
+
+\noindent\# This function determines, whether it is router or host.\\
+\# It returns 0, if the host is apparently not router.
+\end{flushleft}
+\begin{verbatim}
+CheckForwarding () {
+  local sbase fwd
+  sbase=/proc/sys/net/ipv4/conf
+  fwd=0
+  if [ -d $sbase ]; then
+    for dir in $sbase/*/forwarding; do
+      fwd=$[$fwd + `cat $dir`]
+    done
+  else
+    fwd=2
+  fi
+  return $fwd
+}
+\end{verbatim}
+\begin{flushleft}
+\# This function restarts Router Discovery.\\
+\end{flushleft}
+\begin{verbatim}
+RestartRDISC () {
+  killall -HUP rdisc || rdisc -fs
+}
+\end{verbatim}
+\begin{flushleft}
+\# Calculate ABC "natural" mask length\\
+\# Arg: \$1 = dotquad address
+\end{flushleft}
+\begin{verbatim}
+ABCMaskLen () {
+  local class;
+  class=${1%%.*}
+  if [ $class -eq 0 -o $class -ge 224 ]; then return 0
+  elif [ $class -ge 192 ]; then return 24
+  elif [ $class -ge 128 ]; then return 16
+  else  return 8 ; fi
+}
+\end{verbatim}
+
+
+\begin{flushleft}
+\# {\bf MAIN()}\\
+\#\\
+\# Strip alias suffix separated by colon.
+\end{flushleft}
+\begin{verbatim}
+label="label $1"
+ldev=$1
+dev=${1%:*}
+if [ "$dev" = "" -o "$1" = "help" ]; then
+  echo "Usage: ifcfg DEV [[add|del [ADDR[/LEN]] [PEER] | stop]" 1>&2
+  echo "       add - add new address" 1>&2
+  echo "       del - delete address" 1>&2
+  echo "       stop - completely disable IP" 1>&2
+  exit 1
+fi
+shift
+
+CheckForwarding
+fwd=$?
+\end{verbatim}
+\begin{flushleft}
+\# Parse command. If it is ``stop'', flush and exit.
+\end{flushleft}
+\begin{verbatim}
+deleting=0
+case "$1" in
+add) shift ;;
+stop)
+  if [ "$ldev" != "$dev" ]; then
+    echo "Cannot stop alias $ldev" 1>&2
+    exit 1;
+  fi
+  ip -4 addr flush dev $dev $label || exit 1
+  if [ $fwd -eq 0 ]; then RestartRDISC; fi
+  exit 0 ;;
+del*)
+  deleting=1; shift ;;
+*)
+esac
+\end{verbatim}
+\begin{flushleft}
+\# Parse prefix, split prefix length, separated by slash.
+\end{flushleft}
+\begin{verbatim}
+ipaddr=
+pfxlen=
+if [ "$1" != "" ]; then
+  ipaddr=${1%/*}
+  if [ "$1" != "$ipaddr" ]; then
+    pfxlen=${1#*/}
+  fi
+  if [ "$ipaddr" = "" ]; then
+    echo "$1 is bad IP address." 1>&2
+    exit 1
+  fi
+fi
+shift
+\end{verbatim}
+\begin{flushleft}
+\# If peer address is present, prefix length is 32.\\
+\# Otherwise, if prefix length was not given, guess it.
+\end{flushleft}
+\begin{verbatim}
+peer=$1
+if [ "$peer" != "" ]; then
+  if [ "$pfxlen" != "" -a "$pfxlen" != "32" ]; then
+    echo "Peer address with non-trivial netmask." 1>&2
+    exit 1
+  fi
+  pfx="$ipaddr peer $peer"
+else
+  if [ "$pfxlen" = "" ]; then
+    ABCMaskLen $ipaddr
+    pfxlen=$?
+  fi
+  pfx="$ipaddr/$pfxlen"
+fi
+if [ "$ldev" = "$dev" -a "$ipaddr" != "" ]; then
+  label=
+fi
+\end{verbatim}
+\begin{flushleft}
+\# If deletion was requested, delete the address and restart RDISC
+\end{flushleft}
+\begin{verbatim}
+if [ $deleting -ne 0 ]; then
+  ip addr del $pfx dev $dev $label || exit 1
+  if [ $fwd -eq 0 ]; then RestartRDISC; fi
+  exit 0
+fi
+\end{verbatim}
+\begin{flushleft}
+\# Start interface initialization.\\
+\#\\
+\# {\bf Step 0} --- enable device \verb|$dev|
+\end{flushleft}
+\begin{verbatim}
+if ! ip link set up dev $dev ; then
+  echo "Error: cannot enable interface $dev." 1>&2
+  exit 1
+fi
+if [ "$ipaddr" = "" ]; then exit 0; fi
+\end{verbatim}
+\begin{flushleft}
+\# {\bf Step 1} --- IP Duplicate Address Detection~\cite{RFC-DHCP}.\\
+\# Send two probes and wait for result for 3 seconds.\\
+\# If the interface opens slower f.e.\ due to long media detection,\\
+\# you want to increase the timeout.\\
+\end{flushleft}
+\begin{verbatim}
+if ! arping -q -c 2 -w 3 -D -I $dev $ipaddr ; then
+  echo "Error: some host already uses address $ipaddr on $dev." 1>&2
+  exit 1
+fi
+\end{verbatim}
+\begin{flushleft}
+\# OK, the address is unique. We may add it to the interface.\\
+\#\\
+\# {\bf Step 2} --- Configure the address on the interface.
+\end{flushleft}
+\begin{verbatim}
+if ! ip address add $pfx brd + dev $dev $label; then
+  echo "Error: failed to add $pfx on $dev." 1>&2
+  exit 1
+fi
+\end{verbatim}
+\noindent\# {\bf Step 3} --- Announce our presence on the link
+\begin{verbatim}
+arping -q -A -c 1 -I $dev $ipaddr
+noarp=$?
+( sleep 2 ;
+  arping -q -U -c 1 -I $dev $ipaddr ) >& /dev/null </dev/null &
+\end{verbatim}
+\begin{flushleft}
+\# {\bf Step 4} (optional) --- Add some control routes.\\
+\#\\
+\# 1. Prohibit link local multicast addresses.\\
+\# 2. Prohibit link local (alias, limited) broadcast.\\
+\# 3. Add default multicast route.
+\end{flushleft}
+\begin{verbatim}
+ip route add unreachable 224.0.0.0/24 >& /dev/null 
+ip route add unreachable 255.255.255.255 >& /dev/null
+if [ `ip link ls $dev | grep -c MULTICAST` -ge 1 ]; then
+  ip route add 224.0.0.0/4 dev $dev scope global >& /dev/null
+fi
+\end{verbatim}
+\begin{flushleft}
+\# {\bf Step 5} --- Add fallback default route with huge metric.\\
+\# If a proxy ARP server is present on the interface, we will be\\
+\# able to talk to all the Internet without further configuration.\\
+\# Do not make this step on router or if the device is not ARPable.\\
+\# because dead nexthop detection does not work on them.
+\end{flushleft}
+\begin{verbatim}
+if [ $fwd -eq 0 ]; then
+  if [ $noarp -eq 0 ]; then
+    ip ro append default dev $dev metric 30000 scope global
+  elif [ "$peer" != "" ]; then
+    if ping -q -c 2 -w 4 $peer ; then
+      ip ro append default via $peer dev $dev metric 30001
+    fi
+  fi
+  RestartRDISC
+fi
+
+exit 0
+\end{verbatim}
+\begin{flushleft}
+\# End of {\bf MAIN()}
+\end{flushleft}
+
+
+\end{document}
diff --git a/doc/ip-tunnels.tex b/doc/ip-tunnels.tex
new file mode 100644
index 0000000..0a8c930
--- /dev/null
+++ b/doc/ip-tunnels.tex
@@ -0,0 +1,469 @@
+\documentstyle[12pt,twoside]{article}
+\def\TITLE{Tunnels over IP}
+\input preamble
+\begin{center}
+\Large\bf Tunnels over IP in Linux-2.2
+\end{center}
+
+
+\begin{center}
+{ \large Alexey~N.~Kuznetsov } \\
+\em Institute for Nuclear Research, Moscow \\
+\verb|kuznet@ms2.inr.ac.ru| \\
+\rm March 17, 1999
+\end{center}
+
+\vspace{5mm}
+
+\tableofcontents
+
+
+\section{Instead of introduction: micro-FAQ.}
+
+\begin{itemize}
+
+\item
+Q: In linux-2.0.36 I used:
+\begin{verbatim} 
+    ifconfig tunl1 10.0.0.1 pointopoint 193.233.7.65
+\end{verbatim} 
+to create tunnel. It does not work in 2.2.0!
+
+A: You are right, it does not work. The command written above is split to two commands.
+\begin{verbatim}
+    ip tunnel add MY-TUNNEL mode ipip remote 193.233.7.65
+\end{verbatim} 
+will create tunnel device with name \verb|MY-TUNNEL|. Now you may configure
+it with:
+\begin{verbatim} 
+    ifconfig MY-TUNNEL 10.0.0.1
+\end{verbatim} 
+Certainly, if you prefer name \verb|tunl1| to \verb|MY-TUNNEL|,
+you still may use it.
+
+\item
+Q: In linux-2.0.36 I used:
+\begin{verbatim} 
+    ifconfig tunl0 10.0.0.1
+    route add -net 10.0.0.0 gw 193.233.7.65 dev tunl0
+\end{verbatim} 
+to tunnel net 10.0.0.0 via router 193.233.7.65. It does not
+work in 2.2.0! Moreover, \verb|route| prints a funny error sort of
+``network unreachable'' and after this I found a strange direct route
+to 10.0.0.0 via \verb|tunl0| in routing table.
+
+A: Yes, in 2.2 the rule that {\em normal} gateway must reside on directly
+connected network has not any exceptions. You may tell kernel, that
+this particular route is {\em abnormal}:
+\begin{verbatim} 
+  ifconfig tunl0 10.0.0.1 netmask 255.255.255.255
+  ip route add 10.0.0.0/8 via 193.233.7.65 dev tunl0 onlink
+\end{verbatim}
+Note keyword \verb|onlink|, it is the magic key that orders kernel
+not to check for consistency of gateway address.
+Probably, after this explanation you have already guessed another method
+to cheat kernel:
+\begin{verbatim} 
+  ifconfig tunl0 10.0.0.1 netmask 255.255.255.255
+  route add -host 193.233.7.65 dev tunl0
+  route add -net 10.0.0.0 netmask 255.0.0.0 gw 193.233.7.65
+  route del -host 193.233.7.65 dev tunl0
+\end{verbatim}
+Well, if you like such tricks, nobody may prohibit you to use them.
+Only do not forget
+that between \verb|route add| and \verb|route del| host 193.233.7.65 is
+unreachable.
+
+\item
+Q: In 2.0.36 I used to load \verb|tunnel| device module and \verb|ipip| module.
+I cannot find any \verb|tunnel| in 2.2!
+
+A: Linux-2.2 has single module \verb|ipip| for both directions of tunneling
+and for all IPIP tunnel devices.
+
+\item
+Q: \verb|traceroute| does not work over tunnel! Well, stop... It works,
+     only skips some number of hops.
+
+A: Yes. By default tunnel driver copies \verb|ttl| value from
+inner packet to outer one. It means that path traversed by tunneled
+packets to another endpoint is not hidden. If you dislike this, or if you
+are going to use some routing protocol expecting that packets
+with ttl 1 will reach peering host (f.e.\ RIP, OSPF or EBGP)
+and you are not afraid of
+tunnel loops, you may append option \verb|ttl 64|, when creating tunnel
+with \verb|ip tunnel add|.
+
+\item
+Q: ... Well, list of things, which 2.0 was able to do finishes.
+
+\end{itemize}
+
+\paragraph{Summary of differences between 2.2 and 2.0.}
+
+\begin{itemize}
+
+\item {\bf In 2.0} you could compile tunnel device into kernel
+	and got set of 4 devices \verb|tunl0| ... \verb|tunl3| or,
+	alternatively, compile it as module and load new module
+	for each new tunnel. Also, module \verb|ipip| was necessary
+	to receive tunneled packets.
+
+      {\bf 2.2} has {\em one\/} module \verb|ipip|. Loading it you get base
+	tunnel device \verb|tunl0| and another tunnels may be created with command
+	\verb|ip tunnel add|. These new devices may have arbitrary names.
+
+
+\item {\bf In 2.0} you set remote tunnel endpoint address with
+	the command \verb|ifconfig| ... \verb|pointopoint A|.
+
+	{\bf In 2.2} this command has the same semantics on all
+	the interfaces, namely it sets not tunnel endpoint,
+	but address of peering host, which is directly reachable
+	via this tunnel,
+	rather than via Internet. Actual tunnel endpoint address \verb|A|
+	should be set with \verb|ip tunnel add ... remote A|.
+
+\item {\bf In 2.0} you create tunnel routes with the command:
+\begin{verbatim}
+    route add -net 10.0.0.0 gw A dev tunl0
+\end{verbatim}
+
+	{\bf 2.2} interprets this command equally for all device
+	kinds and gateway is required to be directly reachable via this tunnel,
+	rather than via Internet. You still may use \verb|ip route add ... onlink|
+	to override this behaviour.
+
+\end{itemize}
+
+
+\section{Tunnel setup: basics}
+
+Standard Linux-2.2 kernel supports three flavor of tunnels,
+listed in the following table:
+\vspace{2mm}
+
+\begin{tabular}{lll}
+\vrule depth 0.8ex width 0pt\relax
+Mode & Description  & Base device \\
+ipip & IP over IP & tunl0 \\
+sit & IPv6 over IP & sit0 \\
+gre & ANY over GRE over IP & gre0
+\end{tabular}
+
+\vspace{2mm}
+
+\noindent All the kinds of tunnels are created with one command:
+\begin{verbatim}
+  ip tunnel add <NAME> mode <MODE> [ local <S> ] [ remote <D> ]
+\end{verbatim}
+
+This command creates new tunnel device with name \verb|<NAME>|.
+The \verb|<NAME>| is an arbitrary string. Particularly,
+it may be even \verb|eth0|. The rest of parameters set
+different tunnel characteristics.
+
+\begin{itemize}
+
+\item
+\verb|mode <MODE>| sets tunnel mode. Three modes are available now
+	\verb|ipip|, \verb|sit| and \verb|gre|.
+
+\item
+\verb|remote <D>| sets remote endpoint of the tunnel to IP
+	address \verb|<D>|.
+\item
+\verb|local <S>| sets fixed local address for tunneled
+	packets. It must be an address on another interface of this host.
+
+\end{itemize}
+
+\let\thefootnote\oldthefootnote
+
+Both \verb|remote| and \verb|local| may be omitted. In this case we
+say that they are zero or wildcard. Two tunnels of one mode cannot
+have the same \verb|remote| and \verb|local|. Particularly it means
+that base device or fallback tunnel cannot be replicated.\footnote{
+This restriction is relaxed for keyed GRE tunnels.}
+
+Tunnels are divided to two classes: {\bf pointopoint} tunnels, which
+have some not wildcard \verb|remote| address and deliver all the packets
+to this destination, and {\bf NBMA} (i.e. Non-Broadcast Multi-Access) tunnels,
+which have no \verb|remote|. Particularly, base devices (f.e.\ \verb|tunl0|)
+are NBMA, because they have neither \verb|remote| nor
+\verb|local| addresses.
+
+
+After tunnel device is created you should configure it as you did
+it with another devices. Certainly, the configuration of tunnels has
+some features related to the fact that they work over existing Internet
+routing infrastructure and simultaneously create new virtual links,
+which changes this infrastructure. The danger that not enough careful
+tunnel setup will result in formation of tunnel loops,
+collapse of routing or flooding network with exponentially
+growing number of tunneled fragments is very real.
+
+
+Protocol setup on pointopoint tunnels does not differ of configuration
+of another devices. You should set a protocol address with \verb|ifconfig|
+and add routes with \verb|route| utility.
+
+NBMA tunnels are different. To route something via NBMA tunnel
+you have to explain to driver, where it should deliver packets to.
+The only way to make it is to create special routes with gateway
+address pointing to desired endpoint. F.e.\ 
+\begin{verbatim}
+    ip route add 10.0.0.0/24 via <A> dev tunl0 onlink
+\end{verbatim}
+It is important to use option \verb|onlink|, otherwise
+kernel will refuse request to create route via gateway not directly
+reachable over device \verb|tunl0|. With IPv6 the situation is much simpler:
+when you start device \verb|sit0|, it automatically configures itself
+with all IPv4 addresses mapped to IPv6 space, so that all IPv4
+Internet is {\em really reachable} via \verb|sit0|! Excellent, the command
+\begin{verbatim}
+    ip route add 3FFE::/16 via ::193.233.7.65 dev sit0
+\end{verbatim}
+will route \verb|3FFE::/16| via \verb|sit0|, sending all the packets
+destined to this prefix to 193.233.7.65.
+
+\section{Tunnel setup: options}
+
+Command \verb|ip tunnel add| has several additional options.
+\begin{itemize}
+
+\item \verb|ttl N| --- set fixed TTL \verb|N| on tunneled packets.
+	\verb|N| is number in the range 1--255. 0 is special value,
+	meaning that packets inherit TTL value. 
+		Default value is: \verb|inherit|.
+
+\item \verb|tos T| --- set fixed tos \verb|T| on tunneled packets.
+		Default value is: \verb|inherit|.
+
+\item \verb|dev DEV| --- bind tunnel to device \verb|DEV|, so that
+	tunneled packets will be routed only via this device and will
+	not be able to escape to another device, when route to endpoint changes.
+
+\item \verb|nopmtudisc| --- disable Path MTU Discovery on this tunnel.
+	It is enabled by default. Note that fixed ttl is incompatible
+	with this option: tunnels with fixed ttl always make pmtu discovery.
+
+\end{itemize}
+
+\verb|ipip| and \verb|sit| tunnels have no more options. \verb|gre|
+tunnels are more complicated:
+
+\begin{itemize}
+
+\item \verb|key K| --- use keyed GRE with key \verb|K|. \verb|K| is
+	either number or IP address-like dotted quad.
+
+\item \verb|csum| --- checksum tunneled packets.
+
+\item \verb|seq| --- serialize packets.
+\begin{NB}
+	I think this option does not
+	work. At least, I did not test it, did not debug it and
+	even do not understand,	how it is supposed to work and for what
+	purpose Cisco planned to use it.
+\end{NB}
+
+\end{itemize}
+
+
+Actually, these GRE options can be set separately for input and
+output directions by prefixing corresponding keywords with letter
+\verb|i| or \verb|o|. F.e.\ \verb|icsum| orders to accept only
+packets with correct checksum and \verb|ocsum| means, that
+our host will calculate and send checksum.
+
+Command \verb|ip tunnel add| is not the only operation,
+which can be made with tunnels. Certainly, you may get short help page
+with:
+\begin{verbatim}
+    ip tunnel help
+\end{verbatim}
+
+Besides that, you may view list of installed tunnels with the help of command:
+\begin{verbatim}
+    ip tunnel ls
+\end{verbatim}
+Also you may look at statistics:
+\begin{verbatim}
+    ip -s tunnel ls Cisco
+\end{verbatim}
+where \verb|Cisco| is name of tunnel device. Command
+\begin{verbatim}
+    ip tunnel del Cisco
+\end{verbatim}
+destroys tunnel \verb|Cisco|. And, finally,
+\begin{verbatim}
+    ip tunnel change Cisco mode sit local ME remote HE ttl 32
+\end{verbatim}
+changes its parameters.
+
+\section{Differences 2.2 and 2.0 tunnels revisited.}
+
+Now we can discuss more subtle differences between tunneling in 2.0
+and 2.2.
+
+\begin{itemize}
+
+\item In 2.0 all tunneled packets were received promiscuously
+as soon as you loaded module \verb|ipip|. 2.2 tries to select the best
+tunnel device and packet looks as received on this. F.e.\ if host
+received \verb|ipip| packet from host \verb|D| destined to our
+local address \verb|S|, kernel searches for matching tunnels
+in order:
+
+\begin{tabular}{ll}
+1 & \verb|remote| is \verb|D| and \verb|local| is \verb|S| \\
+2 & \verb|remote| is \verb|D| and \verb|local| is wildcard \\
+3 & \verb|remote| is wildcard and \verb|local| is \verb|S| \\
+4 & \verb|tunl0|
+\end{tabular}
+
+If tunnel exists, but it is not in \verb|UP| state, the tunnel is ignored.
+Note, that if \verb|tunl0| is \verb|UP| it receives all the IPIP packets,
+not acknowledged by more specific tunnels.
+Be careful, it means that without carefully installed firewall rules
+anyone on the Internet may inject to your network any packets with
+source addresses indistinguishable from local ones. It is not so bad idea
+to design tunnels in the way enforcing maximal route symmetry
+and to enable reversed path filter (\verb|rp_filter| sysctl option) on
+tunnel devices.
+
+\item In 2.2 you can monitor and debug tunnels with \verb|tcpdump|.
+F.e.\ \verb|tcpdump| \verb|-i Cisco| \verb|-nvv| will dump packets,
+which kernel output, via tunnel \verb|Cisco| and the packets received on it
+from kernel viewpoint.
+
+\end{itemize}
+
+
+\section{Linux and Cisco IOS tunnels.}
+
+Among another tunnels Cisco IOS supports IPIP and GRE.
+Essentially, Cisco setup is subset of options, available for Linux.
+Let us consider the simplest example:
+
+\begin{verbatim}
+interface Tunnel0
+ tunnel mode gre ip
+ tunnel source 10.10.14.1
+ tunnel destination 10.10.13.2
+\end{verbatim}
+
+
+This command set translates to:
+
+\begin{verbatim}
+    ip tunnel add Tunnel0 \
+        mode gre \
+        local 10.10.14.1 \
+        remote 10.10.13.2
+\end{verbatim}
+
+Any questions? No questions.
+
+\section{Interaction IPIP tunnels and DVMRP.}
+
+DVMRP exploits IPIP tunnels to route multicasts via Internet.
+\verb|mrouted| creates
+IPIP tunnels listed in its configuration file automatically.
+From kernel and user viewpoints there are no differences between
+tunnels, created in this way, and tunnels created by \verb|ip tunnel|.
+I.e.\ if \verb|mrouted| created some tunnel, it may be used to
+route unicast packets, provided appropriate routes are added.
+And vice versa, if administrator has already created a tunnel,
+it will be reused by \verb|mrouted|, if it requests DVMRP
+tunnel with the same local and remote addresses.
+
+Do not wonder, if your manually configured tunnel is
+destroyed, when mrouted exits.
+
+
+\section{Broadcast GRE ``tunnels''.}
+
+It is possible to set \verb|remote| for GRE tunnel to a multicast
+address. Such tunnel becomes {\bf broadcast} tunnel (though word
+tunnel is not quite appropriate in this case, it is rather virtual network).
+\begin{verbatim}
+  ip tunnel add Universe local 193.233.7.65 \
+                         remote 224.66.66.66 ttl 16
+  ip addr add 10.0.0.1/16 dev Universe
+  ip link set Universe up
+\end{verbatim}
+This tunnel is true broadcast network and broadcast packets are
+sent to multicast group 224.66.66.66. By default such tunnel starts
+to resolve both IP and IPv6 addresses via ARP/NDISC, so that
+if multicast routing is supported in surrounding network, all GRE nodes
+will find one another automatically and will form virtual Ethernet-like
+broadcast network. If multicast routing does not work, it is unpleasant
+but not fatal flaw. The tunnel becomes NBMA rather than broadcast network.
+You may disable dynamic ARPing by:
+\begin{verbatim}
+  echo 0 > /proc/sys/net/ipv4/neigh/Universe/mcast_solicit
+\end{verbatim}
+and to add required information to ARP tables manually:
+\begin{verbatim}
+  ip neigh add 10.0.0.2 lladdr 128.6.190.2 dev Universe nud permanent
+\end{verbatim}
+In this case packets sent to 10.0.0.2 will be encapsulated in GRE
+and sent to 128.6.190.2. It is possible to facilitate address resolution
+using methods typical for another NBMA networks f.e.\ to start user
+level \verb|arpd| daemon, which will maintain database of hosts attached
+to GRE virtual network or ask for information
+dedicated ARP or NHRP server.
+
+
+Actually, such setup is the most natural for tunneling,
+it is really flexible, scalable and easily managable, so that
+it is strongly recommended to be used with GRE tunnels instead of ugly
+hack with NBMA mode and \verb|onlink| modifier. Unfortunately,
+by historical reasons broadcast mode is not supported by IPIP tunnels,
+but this probably will change in future.
+
+
+
+\section{Traffic control issues.}
+
+Tunnels are devices, hence all the power of Linux traffic control
+applies to them. The simplest (and the most useful in practice)
+example is limiting tunnel bandwidth. The following command:
+\begin{verbatim}
+    tc qdisc add dev tunl0 root tbf \
+        rate 128Kbit burst 4K limit 10K
+\end{verbatim}
+will limit tunneled traffic to 128Kbit with maximal burst size of 4K
+and queuing not more than 10K.
+
+However, you should remember, that tunnels are {\em virtual} devices
+implemented in software and true queue management is impossible for them
+just because they have no queues. Instead, it is better to create classes
+on real physical interfaces and to map tunneled packets to them.
+In general case of dynamic routing you should create such classes
+on all outgoing interfaces, or, alternatively,
+to use option \verb|dev DEV| to bind tunnel to a fixed physical device.
+In the last case packets will be routed only via specified device
+and you need to setup corresponding classes only on it.
+Though you have to pay for this convenience,
+if routing will change, your tunnel will fail.
+
+Suppose that CBQ class \verb|1:ABC| has been created on device \verb|eth0| 
+specially for tunnel \verb|Cisco| with endpoints \verb|S| and \verb|D|.
+Now you can select IPIP packets with addresses \verb|S| and \verb|D|
+with some classifier and map them to class \verb|1:ABC|. F.e.\ 
+it is easy to make with \verb|rsvp| classifier:
+\begin{verbatim}
+    tc filter add dev eth0 pref 100 proto ip rsvp \
+        session D ipproto ipip filter S \
+        classid 1:ABC
+\end{verbatim}
+
+If you want to make more detailed classification of sub-flows
+transmitted via tunnel, you can build CBQ subtree,
+rooted at \verb|1:ABC| and attach to subroot set of rules parsing
+IPIP packets more deeply.
+
+\end{document}
diff --git a/doc/nstat.sgml b/doc/nstat.sgml
new file mode 100644
index 0000000..48cacc6
--- /dev/null
+++ b/doc/nstat.sgml
@@ -0,0 +1,110 @@
+<!doctype linuxdoc system>
+
+<article>
+
+<title>NSTAT, IFSTAT and RTACCT Utilities
+<author>Alexey Kuznetsov, <tt/kuznet@ms2.inr.ac.ru/
+<date>some_negative_number, 20 Sep 2001
+<abstract>
+<tt/nstat/, <tt/ifstat/ and <tt/rtacct/ are simple tools helping
+to monitor kernel snmp counters and network interface statistics.
+</abstract>
+
+<p> These utilities are very similar, so that I describe
+them simultaneously, using name <tt/Xstat/ in the places which apply
+to all of them.
+
+<p>The format of the command is:
+
+<tscreen><verb>
+       Xstat [ OPTIONS ] [ PATTERN [ PATTERN ... ] ]
+</verb></tscreen>
+
+<p>
+<tt/PATTERN/ is shell style pattern, selecting identifier
+of SNMP variables or interfaces to show. Variable is displayed
+if one of patterns matches its name. If no patterns are given,
+<tt/Xstat/ assumes that user wants to see all the variables.  
+
+<p> <tt/OPTIONS/ is list of single letter options, using common unix
+conventions.
+
+<itemize>
+<item><tt/-h/  - show help page
+<item><tt/-?/  - the same, of course
+<item><tt/-v/, <tt/-V/  - print version of <tt/Xstat/ and exit
+<item><tt/-z/ - dump zero counters too. By default they are not shown.
+<item><tt/-a/ - dump absolute values of counters. By default <tt/Xstat/
+                calculates increments since the previous use.
+<item><tt/-s/ - do not update history, so that the next time you will
+                see counters including values accumulated to the moment
+                of this measurement too.
+<item><tt/-n/ - do not display anything, only update history.
+<item><tt/-r/ - reset history.
+<item><tt/-d INTERVAL/ - <tt/Xstat/ is run in daemon mode collecting
+                statistics. <tt/INTERVAL/ is interval between measurements
+                in seconds.
+<item><tt/-t INTERVAL/ - time interval to average rates. Default value
+                is 60 seconds. 
+<item><tt/-e/ - display extended information about errors (<tt/ifstat/ only).
+</itemize>
+
+<p>
+History is just dump saved in file <tt>/tmp/.Xstat.uUID</tt>
+or in file given by environment variables <tt/NSTAT_HISTORY/,
+<tt/IFSTAT_HISTORY/ and <tt/RTACCT_HISTORY/.
+Each time when you use <tt/Xstat/ values there are updated.
+If you use patterns, only the values which you _really_ see
+are updated. If you want to skip an unintersting period,
+use option <tt/-n/, or just output to <tt>/dev/null</tt>.
+
+<p>
+<tt/Xstat/ understands when history is invalidated by system reboot
+or source of information switched between different instances
+of daemonic <tt/Xstat/ and kernel SNMP tables and does not
+use invalid history.
+
+<p> Beware, <tt/Xstat/ will not produce sane output,
+when many processes use it simultaneously. If several processes
+under single user need this utility they should use environment
+variables to put their history in safe places
+or to use it with options <tt/-a -s/.
+
+<p>
+Well, that's all. The utility is very simple, but nevertheless
+very handy.
+
+<p> <bf/Output of XSTAT/
+<p> The first line of output is <tt/#/ followed by identifier
+of source of information, it may be word <tt/kernel/, when <tt/Xstat/
+gets information from kernel or some dotted decimal number followed
+by parameters, when it obtains information from running <tt/Xstat/ daemon.
+
+<p>In the case of <tt/nstat/ the rest of output consists of three columns:
+SNMP MIB identifier,
+its value (or increment since previous measurement) and average
+rate of increase of the counter per second. <tt/ifstat/ outputs
+interface name followed by pairs of counter and rate of its change.
+
+<p> <bf/Daemonic Xstat/
+<p> <tt/Xstat/ may be started as daemon by any user. This makes sense
+to avoid wrapped counters and to obtain reasonable long counters
+for large time. Also <tt/Xstat/ daemon calculates average rates.
+For the first goal sampling interval (option <tt/-d/) may be large enough,
+f.e. for gigabit rates byte counters overflow not more frequently than
+each 40 seconds and you may select interval of 20 seconds.
+From the other hand, when <tt/Xstat/ is used for estimating rates
+interval should be less than averaging period (option <tt/-t/), otherwise
+estimation loses in quality.
+
+Client <tt/Xstat/, before trying to get information from the kernel,
+contacts daemon started by this user, then it tries system wide
+daemon, which is supposed to be started by superuser. And only if
+none of them replied it gets information from kernel.
+
+<p> <bf/Environment/
+<p> <tt/NSTAT_HISTORY/ - name of history file for <tt/nstat/.
+<p> <tt/IFSTAT_HISTORY/ - name of history file for <tt/ifstat/.
+<p> <tt/RTACCT_HISTORY/ - name of history file for <tt/rtacct/.
+
+</article>
diff --git a/doc/preamble.tex b/doc/preamble.tex
new file mode 100644
index 0000000..80ca508
--- /dev/null
+++ b/doc/preamble.tex
@@ -0,0 +1,26 @@
+\textwidth   6.0in
+\textheight  8.5in
+
+\input SNAPSHOT
+
+\pagestyle{myheadings}
+\markboth{\protect\TITLE}{}
+\markright{{\protect\sc iproute2-ss\Draft}}
+
+% To print it in compact form: both sides on one sheet (psnup -2)
+\evensidemargin=\oddsidemargin
+
+\newenvironment{NB}{\bgroup \vskip 1mm\leftskip 1cm \footnotesize \noindent NB.
+}{\par\egroup \vskip 1mm}
+
+\def\threeonly{[2.3.15+ only] }
+
+\begin{document}
+
+\makeatletter
+\renewcommand{\@oddhead}{{\protect\sc iproute2-ss\Draft} \hfill \protect\arabic{page}}
+\makeatother
+\let\oldthefootnote\thefootnote
+\def\thefootnote{}
+\footnotetext{Copyright \copyright~1999 A.N.Kuznetsov}
+
diff --git a/doc/rtstat.sgml b/doc/rtstat.sgml
new file mode 100644
index 0000000..07391c3
--- /dev/null
+++ b/doc/rtstat.sgml
@@ -0,0 +1,52 @@
+<!doctype linuxdoc system>
+
+<article>
+
+<title>RTACCT Utility
+<author>Robert Olsson
+<date>some_negative_number, 20 Dec 2001
+
+<p>
+Here is some code for monitoring the route cache. For systems handling high
+network load, servers, routers, firewalls etc the route cache and its garbage
+collection is crucial. Linux has a solid implementation.
+
+<p>
+The kernel patch (not required since linux-2.4.7) adds statistics counters
+from route cache process into 
+/proc/net/rt_cache_stat. A companion user mode program presents the statistics
+in a vmstat or iostat manner. The ratio between cache hits and misses gives 
+the flow length.
+
+<p>
+Hopefully it can help understanding performance and DoS and other related
+issues.
+
+<p> An URL where newer versions of this utility can be (probably) found
+is ftp://robur.slu.se/pub/Linux/net-development/rt_cache_stat/
+
+
+<p><bf/Description/
+
+<p>The format of the command is:
+
+<tscreen><verb>
+       rtstat [ OPTIONS ]
+</verb></tscreen>
+
+<p> <tt/OPTIONS/ are:
+
+<itemize>
+
+<item><tt/-h/, <tt/-help/ - show help page and version of the utility.
+
+<item><tt/-i INTERVAL/ - interval between snapshots, default value is
+2 seconds.
+
+<item><tt/-s NUMBER/ - whether to print header line. 0 inhibits header line,
+1 prescribes to print it once and 2 (this is default setting) forces header
+line each 20 lines. 
+
+</itemize>
+
+</article>
diff --git a/doc/ss.sgml b/doc/ss.sgml
new file mode 100644
index 0000000..3024b57
--- /dev/null
+++ b/doc/ss.sgml
@@ -0,0 +1,525 @@
+<!doctype linuxdoc system>
+
+<article>
+
+<title>SS Utility: Quick Intro
+<author>Alexey Kuznetsov, <tt/kuznet@ms2.inr.ac.ru/
+<date>some_negative_number, 20 Sep 2001
+<abstract>
+<tt/ss/ is one another utility to investigate sockets.
+Functionally it is NOT better than <tt/netstat/ combined
+with some perl/awk scripts and though it is surely faster
+it is not enough to make it much better. :-)
+So, stop reading this now and do not waste your time.
+Well, certainly, it proposes some functionality, which current
+netstat is still not able to do, but surely will soon.
+</abstract>
+
+<sect>Why?
+
+<p> <tt>/proc</tt> interface is inadequate, unfortunately.
+When amount of sockets is enough large, <tt/netstat/ or even
+plain <tt>cat /proc/net/tcp/</tt> cause nothing but pains and curses.
+In linux-2.4 the desease became worse: even if amount
+of sockets is small reading <tt>/proc/net/tcp/</tt> is slow enough.
+
+This utility presents a new approach, which is supposed to scale
+well. I am not going to describe technical details here and
+will concentrate on description of the command.
+The only important thing to say is that it is not so bad idea
+to load module <tt/tcp_diag/, which can be found in directory
+<tt/Modules/ of <tt/iproute2/. If you do not make this <tt/ss/
+will work, but it falls back to <tt>/proc</tt> and becomes slow
+like <tt/netstat/, well, a bit faster yet (see section "Some numbers"). 
+
+<sect>Old news
+
+<p>
+In the simplest form <tt/ss/ is equivalent to netstat
+with some small deviations.
+
+<itemize>
+<item><tt/ss -t -a/ dumps all TCP sockets
+<item><tt/ss -u -a/ dumps all UDP sockets
+<item><tt/ss -w -a/ dumps all RAW sockets
+<item><tt/ss -x -a/ dumps all UNIX sockets
+</itemize>
+
+<p>
+Option <tt/-o/ shows TCP timers state.
+Option <tt/-e/ shows some extended information.
+Etc. etc. etc. Seems, all the options of netstat related to sockets
+are supported. Though not AX.25 and other bizarres. :-)
+If someone wants, he can make support for decnet and ipx.
+Some rudimentary support for them is already present in iproute2 libutils,
+and I will be glad to see these new members.
+
+<p>
+However, standard functionality is a bit different:
+
+<p>
+The first: without option <tt/-a/ sockets in states
+<tt/TIME-WAIT/ and <tt/SYN-RECV/ are skipped too.
+It is more reasonable default, I think.
+
+<p>
+The second: format of UNIX sockets is different. It coincides
+with tcp/udp. Though standard kernel still does not allow to
+see write/read queues and peer address of connected UNIX sockets,
+the patch doing this exists.
+
+<p>
+The third: default is to dump only TCP sockets, rather than all of the types.
+
+<p>
+The next: by default it does not resolve numeric host addresses (like <tt/ip/)!
+Resolving is enabled with option <tt/-r/. Service names, usually stored
+in local files, are resolved by default. Also, if service database
+does not contain references to a port, <tt/ss/ queries system
+<tt/rpcbind/. RPC services are prefixed with <tt/rpc./
+Resolution of services may be suppressed with option <tt/-n/.
+
+<p>
+It does not accept "long" options (I dislike them, sorry).
+So, address family is given with family identifier following
+option <tt/-f/ to be algined to iproute2 conventions.
+Mostly, it is to allow option parser to parse
+addresses correctly, but as side effect it really limits dumping
+to sockets supporting only given family. Option <tt/-A/ followed
+by list of socket tables to dump is also supported.
+Logically, id of socket table is different of _address_ family, which is
+another point of incompatibility. So, id is one of
+<tt/all/, <tt/tcp/, <tt/udp/,
+<tt/raw/, <tt/inet/, <tt/unix/, <tt/packet/, <tt/netlink/. See?
+Well, <tt/inet/ is just abbreviation for <tt/tcp|udp|raw/
+and it is not difficult to guess that <tt/packet/ allows
+to look at packet sockets. Actually, there are also some other abbreviations,
+f.e. <tt/unix_dgram/ selects only datagram UNIX sockets.
+
+<p>
+The next: well, I still do not know. :-)
+
+
+
+
+<sect>Time to talk about new functionality.
+
+<p>It is builtin filtering of socket lists. 
+
+<sect1> Filtering by state.
+
+<p>
+<tt/ss/ allows to filter socket states, using keywords
+<tt/state/ and <tt/exclude/, followed by some state
+identifier.
+
+<p>
+State identifier are standard TCP state names (not listed,
+they are useless for you if you already do not know them)
+or abbreviations:
+
+<itemize>
+<item><tt/all/        - for all the states
+<item><tt/bucket/     - for TCP minisockets (<tt/TIME-WAIT|SYN-RECV/)
+<item><tt/big/	      - all except for minisockets
+<item><tt/connected/  - not closed and not listening
+<item><tt/synchronized/ - connected and not <tt/SYN-SENT/
+</itemize>
+
+<p>
+   F.e. to dump all tcp sockets except <tt/SYN-RECV/:
+
+<tscreen><verb>
+   ss exclude SYN-RECV
+</verb></tscreen>
+
+<p>
+   If neither <tt/state/ nor <tt/exclude/ directives
+   are present,
+   state filter defaults to <tt/all/ with option <tt/-a/
+   or to <tt/all/,
+   excluding listening, syn-recv, time-wait and closed sockets.
+
+<sect1> Filtering by addresses and ports.
+
+<p>
+Option list may contain address/port filter.
+It is boolean expression which consists of boolean operation
+<tt/or/, <tt/and/, <tt/not/ and predicates. 
+Actually, all the flavors of names for boolean operations are eaten:
+<tt/&amp/, <tt/&amp&amp/, <tt/|/, <tt/||/, <tt/!/, but do not forget
+about special sense given to these symbols by unix shells and escape
+them correctly, when used from command line.
+
+<p>
+Predicates may be of the folowing kinds:
+
+<itemize>
+<item>A. Address/port match, where address is checked against mask
+      and port is either wildcard or exact. It is one of:
+ 
+<tscreen><verb>
+	dst prefix:port
+	src prefix:port
+	src unix:STRING
+	src link:protocol:ifindex
+	src nl:channel:pid
+</verb></tscreen>
+
+      Both prefix and port may be absent or replaced with <tt/*/,
+      which means wildcard. UNIX socket use more powerful scheme
+      matching to socket names by shell wildcards. Also, prefixes
+      unix: and link: may be omitted, if address family is evident
+      from context (with option <tt/-x/ or with <tt/-f unix/
+      or with <tt/unix/ keyword) 
+
+<p>
+      F.e.
+
+<tscreen><verb>
+	dst 10.0.0.1
+	dst 10.0.0.1:
+	dst 10.0.0.1/32:
+	dst 10.0.0.1:*
+</verb></tscreen>
+   are equivalent and mean socket connected to
+	                 any port on host 10.0.0.1
+
+<tscreen><verb>
+	dst 10.0.0.0/24:22
+</verb></tscreen>
+   sockets connected to port 22 on network
+                          10.0.0.0...255.
+
+<p>
+      Note that port separated of address with colon, which creates
+      troubles with IPv6 addresses. Generally, we interpret the last
+      colon as splitting port. To allow to give IPv6 addresses,
+      trick like used in IPv6 HTTP URLs may be used:
+
+<tscreen><verb>
+      dst [::1]
+</verb></tscreen>
+       are sockets connected to ::1 on any port
+
+<p>
+      Another way is <tt/dst ::1/128/. / helps to understand that
+      colon is part of IPv6 address.
+
+<p>
+      Now we can add another alias for <tt/dst 10.0.0.1/:
+      <tt/dst [10.0.0.1]/. :-)
+
+<p>   Address may be a DNS name. In this case all the addresses are looked
+      up (in all the address families, if it is not limited by option <tt/-f/
+      or special address prefix <tt/inet:/, <tt/inet6/) and resulting
+      expression is <tt/or/ over all of them.  
+
+<item>   B. Port expressions:
+<tscreen><verb>
+      dport &gt= :1024
+      dport != :22
+      sport &lt :32000
+</verb></tscreen>
+      etc.
+
+      All the relations: <tt/&lt/, <tt/&gt/, <tt/=/, <tt/>=/, <tt/=/, <tt/==/,
+      <tt/!=/, <tt/eq/, <tt/ge/, <tt/lt/, <tt/ne/...
+      Use variant which you like more, but not forget to escape special
+      characters when typing them in command line. :-) 
+
+      Note that port number syntactically coincides to the case A!
+      You may even add an IP address, but it will not participate
+      incomparison, except for <tt/==/ and <tt/!=/, which are equivalent
+      to corresponding predicates of type A. F.e.
+<p>
+<tt/dst 10.0.0.1:22/
+    is equivalent to  <tt/dport eq 10.0.0.1:22/
+      and
+      <tt/not dst 10.0.0.1:22/     is equivalent to
+ <tt/dport neq 10.0.0.1:22/
+
+<item>C. Keyword <tt/autobound/. It matches to sockets bound automatically
+      on local system.
+
+</itemize>
+
+
+<sect> Examples
+
+<p>
+<itemize>
+<item>1. List all the tcp sockets in state <tt/FIN-WAIT-1/ for our apache
+   to network 193.233.7/24 and look at their timers:
+
+<tscreen><verb>
+   ss -o state fin-wait-1 \( sport = :http or sport = :https \) \
+                          dst 193.233.7/24
+</verb></tscreen>
+
+   Oops, forgot to say that missing logical operation is
+   equivalent to <tt/and/.
+
+<item> 2. Well, now look at the rest...
+
+<tscreen><verb>
+   ss -o excl fin-wait-1
+   ss state fin-wait-1 \( sport neq :http and sport neq :https \) \
+                       or not dst 193.233.7/24
+</verb></tscreen>
+
+   Note that we have to do _two_ calls of ss to do this.
+   State match is always anded to address/port match.
+   The reason for this is purely technical: ss does fast skip of
+   not matching states before parsing addresses and I consider the
+   ability to skip fastly gobs of time-wait and syn-recv sockets
+   as more important than logical generality.
+
+<item> 3. So, let's look at all our sockets using autobound ports:
+
+<tscreen><verb>
+   ss -a -A all autobound
+</verb></tscreen>
+
+
+<item> 4. And eventually find all the local processes connected
+   to local X servers:
+
+<tscreen><verb>
+   ss -xp dst "/tmp/.X11-unix/*"
+</verb></tscreen>
+
+   Pardon, this does not work with current kernel, patching is required.
+   But we still can look at server side:
+   
+<tscreen><verb>
+   ss -x src "/tmp/.X11-unix/*"
+</verb></tscreen>
+
+</itemize>
+
+
+<sect> Returning to ground: real manual  
+
+<p>
+<sect1> Command arguments
+
+<p> General format of arguments to <tt/ss/ is:
+
+<tscreen><verb>
+       ss [ OPTIONS ] [ STATE-FILTER ] [ ADDRESS-FILTER ]
+</verb></tscreen>
+
+<sect2><tt/OPTIONS/
+<p> <tt/OPTIONS/ is list of single letter options, using common unix
+conventions.
+
+<itemize>
+<item><tt/-h/  - show help page
+<item><tt/-?/  - the same, of course
+<item><tt/-v/, <tt/-V/  - print version of <tt/ss/ and exit
+<item><tt/-s/  - print summary statistics. This option does not parse
+socket lists obtaining summary from various sources. It is useful
+when amount of sockets is so huge that parsing <tt>/proc/net/tcp</tt>
+is painful.
+<item><tt/-D FILE/  - do not display anything, just dump raw information
+about TCP sockets to <tt/FILE/ after applying filters. If <tt/FILE/ is <tt/-/
+<tt/stdout/ is used. 
+<item><tt/-F FILE/  - read continuation of filter from <tt/FILE/.
+Each line of <tt/FILE/ is interpreted like single command line option.
+If <tt/FILE/ is <tt/-/ <tt/stdin/ is used. 
+<item><tt/-r/  - try to resolve numeric address/ports
+<item><tt/-n/  - do not try to resolve ports
+<item><tt/-o/  - show some optional information, f.e. TCP timers
+<item><tt/-i/  - show some infomration specific to TCP (RTO, congestion
+window, slow start threshould etc.)
+<item><tt/-e/  - show even more optional information
+<item><tt/-m/  - show extended information on memory used by the socket.
+It is available only with <tt/tcp_diag/ enabled.
+<item><tt/-p/  - show list of processes owning the socket
+<item><tt/-f FAMILY/ - default address family used for parsing addresses.
+                 Also this option limits listing to sockets supporting
+                 given address family. Currently the following families
+                 are supported: <tt/unix/, <tt/inet/, <tt/inet6/, <tt/link/,
+                 <tt/netlink/.
+<item><tt/-4/ - alias for <tt/-f inet/
+<item><tt/-6/ - alias for <tt/-f inet6/
+<item><tt/-0/ - alias for <tt/-f link/
+<item><tt/-A LIST-OF-TABLES/ - list of socket tables to dump, separated
+                 by commas. The following identifiers are understood:
+                 <tt/all/, <tt/inet/, <tt/tcp/, <tt/udp/, <tt/raw/,
+                 <tt/unix/, <tt/packet/, <tt/netlink/, <tt/unix_dgram/,
+                 <tt/unix_stream/, <tt/packet_raw/, <tt/packet_dgram/.
+<item><tt/-x/ - alias for <tt/-A unix/
+<item><tt/-t/ - alias for <tt/-A tcp/
+<item><tt/-u/ - alias for <tt/-A udp/
+<item><tt/-w/ - alias for <tt/-A raw/
+<item><tt/-a/ - show sockets of all the states. By default sockets
+                in states <tt/LISTEN/, <tt/TIME-WAIT/, <tt/SYN_RECV/
+                and <tt/CLOSE/ are skipped.
+<item><tt/-l/ - show only sockets in state <tt/LISTEN/ 
+</itemize>
+
+<sect2><tt/STATE-FILTER/
+
+<p><tt/STATE-FILTER/ allows to construct arbitrary set of
+states to match. Its syntax is sequence of keywords <tt/state/
+and <tt/exclude/ followed by identifier of state.
+Available identifiers are:
+
+<p>
+<itemize>
+<item> All standard TCP states: <tt/established/, <tt/syn-sent/,
+<tt/syn-recv/, <tt/fin-wait-1/, <tt/fin-wait-2/, <tt/time-wait/,
+<tt/closed/, <tt/close-wait/, <tt/last-ack/, <tt/listen/ and <tt/closing/.
+
+<item><tt/all/ - for all the states 
+<item><tt/connected/ - all the states except for <tt/listen/ and <tt/closed/ 
+<item><tt/synchronized/ - all the <tt/connected/ states except for 
+<tt/syn-sent/
+<item><tt/bucket/ - states, which are maintained as minisockets, i.e.
+<tt/time-wait/ and <tt/syn-recv/.
+<item><tt/big/ - opposite to <tt/bucket/
+</itemize>
+
+<sect2><tt/ADDRESS_FILTER/
+
+<p><tt/ADDRESS_FILTER/ is boolean expression with operations <tt/and/, <tt/or/
+and <tt/not/, which can be abbreviated in C style f.e. as <tt/&amp/,
+<tt/&amp&amp/.
+
+<p>
+Predicates check socket addresses, both local and remote.
+There are the following kinds of predicates:
+
+<itemize>
+<item> <tt/dst ADDRESS_PATTERN/ - matches remote address and port
+<item> <tt/src ADDRESS_PATTERN/ - matches local address and port
+<item> <tt/dport RELOP PORT/    - compares remote port to a number
+<item> <tt/sport RELOP PORT/    - compares local port to a number
+<item> <tt/autobound/           - checks that socket is bound to an ephemeral
+                                  port
+</itemize>
+
+<p><tt/RELOP/ is some of <tt/&lt=/, <tt/&gt=/, <tt/==/ etc.
+To make this more convinient for use in unix shell, alphabetic
+FORTRAN-like notations <tt/le/, <tt/gt/ etc. are accepted as well.
+
+<p>The format and semantics of <tt/ADDRESS_PATTERN/ depends on address
+family.
+
+<itemize>
+<item><tt/inet/ - <tt/ADDRESS_PATTERN/ consists of IP prefix, optionally
+followed by colon and port. If prefix or port part is absent or replaced
+with <tt/*/, this means wildcard match.
+<item><tt/inet6/ - The same as <tt/inet/, only prefix refers to an IPv6
+address. Unlike <tt/inet/ colon becomes ambiguous, so that <tt/ss/ allows
+to use scheme, like used in URLs, where address is suppounded with
+<tt/[/ ... <tt/]/.
+<item><tt/unix/ - <tt/ADDRESS_PATTERN/ is shell-style wildcard.
+<item><tt/packet/ - format looks like <tt/inet/, only interface index
+stays instead of port and link layer protocol id instead of address.
+<item><tt/netlink/ - format looks like <tt/inet/, only socket pid
+stays instead of port and netlink channel instead of address.
+</itemize>
+
+<p><tt/PORT/ is syntactically <tt/ADDRESS_PATTERN/ with wildcard
+address part. Certainly, it is undefined for UNIX sockets. 
+
+<sect1> Environment variables
+
+<p>
+<tt/ss/ allows to change source of information using various
+environment variables:
+
+<p>
+<itemize>
+<item> <tt/PROC_SLABINFO/  to override <tt>/proc/slabinfo</tt>
+<item> <tt/PROC_NET_TCP/  to override <tt>/proc/net/tcp</tt>
+<item> <tt/PROC_NET_UDP/  to override <tt>/proc/net/udp</tt>
+<item> etc.
+</itemize> 
+
+<p>
+Variable <tt/PROC_ROOT/ allows to change root of all the <tt>/proc/</tt>
+hierarchy.
+
+<p>
+Variable <tt/TCPDIAG_FILE/ prescribes to open a file instead of
+requesting kernel to dump information about TCP sockets.
+
+
+<p> This option is used mainly to investigate bug reports,
+when dumps of files usually found in <tt>/proc/</tt> are recevied
+by e-mail.
+
+<sect1> Output format
+
+<p>Six columns. The first is <tt/Netid/, it denotes socket type and
+transport protocol, when it is ambiguous: <tt/tcp/, <tt/udp/, <tt/raw/,
+<tt/u_str/ is abbreviation for <tt/unix_stream/, <tt/u_dgr/ for UNIX
+datagram sockets, <tt/nl/ for netlink, <tt/p_raw/ and <tt/p_dgr/ for
+raw and datagram packet sockets. This column is optional, it will
+be hidden, if filter selects an unique netid.
+
+<p>
+The second column is <tt/State/. Socket state is displayed here.
+The names are standard TCP names, except for <tt/UNCONN/, which
+cannot happen for TCP, but normal for not connected sockets
+of another types. Again, this column can be hidden.
+
+<p>
+Then two columns (<tt/Recv-Q/ and <tt/Send-Q/) showing amount of data
+queued for receive and transmit.
+
+<p>
+And the last two columns display local address and port of the socket
+and its peer address, if the socket is connected.
+
+<p>
+If options <tt/-o/, <tt/-e/ or <tt/-p/ were given, options are
+displayed not in fixed positions but separated by spaces pairs:
+<tt/option:value/. If value is not a single number, it is presented
+as list of values, enclosed to <tt/(/ ... <tt/)/ and separated with
+commas. F.e.
+
+<tscreen><verb>
+   timer:(keepalive,111min,0)
+</verb></tscreen>
+is typical format for TCP timer (option <tt/-o/).
+
+<tscreen><verb>
+   users:((X,113,3))
+</verb></tscreen>
+is typical for list of users (option <tt/-p/).
+
+
+<sect>Some numbers
+
+<p>
+Well, let us use <tt/pidentd/ and a tool <tt/ibench/ to measure
+its performance. It is 30 requests per second here. Nothing to test,
+it is too slow. OK, let us patch pidentd with patch from directory
+Patches. After this it handles about 4300 requests per second
+and becomes handy tool to pollute socket tables with lots of timewait
+buckets.
+
+<p>
+So, each test starts from pollution tables with 30000 sockets
+and then doing full dump of the table piped to wc and measuring
+timings with time:
+
+<p>Results:
+
+<itemize>
+<item> <tt/netstat -at/ - 15.6 seconds
+<item> <tt/ss -atr/, but without <tt/tcp_diag/     - 5.4 seconds
+<item> <tt/ss -atr/ with <tt/tcp_diag/     - 0.47 seconds
+</itemize>
+
+No comments. Though one comment is necessary, most of time
+without <tt/tcp_diag/ is wasted inside kernel with completely
+blocked networking. More than 10 seconds, yes. <tt/tcp_diag/
+does the same work for 100 milliseconds of system time.
+
+</article>
diff --git a/etc/iproute2/ematch_map b/etc/iproute2/ematch_map
index 4d6bb2f..1823983 100644
--- a/etc/iproute2/ematch_map
+++ b/etc/iproute2/ematch_map
@@ -5,4 +5,3 @@
 4	meta
 7	canid
 8	ipset
-9	ipt
diff --git a/etc/iproute2/nl_protos b/etc/iproute2/nl_protos
index 7c17cf0..43418f3 100644
--- a/etc/iproute2/nl_protos
+++ b/etc/iproute2/nl_protos
@@ -12,7 +12,7 @@
 9   audit
 10  fiblookup
 11  connector
-12  nft
+12  nft 
 13  ip6fw
 14  dec-rt
 15  uevent
@@ -20,4 +20,4 @@
 18  scsi-trans
 19  ecryptfs
 20  rdma
-21  crypto
+21  crypto 
diff --git a/etc/iproute2/rt_protos b/etc/iproute2/rt_protos
index b3a0ec8..82cf9c4 100644
--- a/etc/iproute2/rt_protos
+++ b/etc/iproute2/rt_protos
@@ -16,8 +16,16 @@
 15	ntk
 16      dhcp
 42	babel
-186	bgp
-187	isis
-188	ospf
-189	rip
-192	eigrp
+
+#
+#	Used by me for gated
+#
+254	gated/aggr
+253	gated/bgp
+252	gated/ospf
+251	gated/ospfase
+250	gated/rip
+249	gated/static
+248	gated/conn
+247	gated/inet
+246	gated/default
diff --git a/etc/iproute2/rt_protos.d/README b/etc/iproute2/rt_protos.d/README
deleted file mode 100644
index f9c599c..0000000
--- a/etc/iproute2/rt_protos.d/README
+++ /dev/null
@@ -1,2 +0,0 @@
-Each file in this directory is an rt_protos configuration file. iproute2
-commands scan this directory processing all files that end in '.conf'.
diff --git a/etc/iproute2/rt_tables.d/README b/etc/iproute2/rt_tables.d/README
index 0920cb1..79386f8 100644
--- a/etc/iproute2/rt_tables.d/README
+++ b/etc/iproute2/rt_tables.d/README
@@ -1,2 +1,3 @@
 Each file in this directory is an rt_tables configuration file. iproute2
 commands scan this directory processing all files that end in '.conf'.
+
diff --git a/examples/README.cbq b/examples/README.cbq
new file mode 100644
index 0000000..38c1089
--- /dev/null
+++ b/examples/README.cbq
@@ -0,0 +1,122 @@
+# CHANGES
+# -------
+# v0.3a2- fixed bug in "if" operator. Thanks kad@dgtu.donetsk.ua.
+# v0.3a-  added TIME parameter. Example:
+#         TIME=00:00-19:00;64Kbit/6Kbit
+#         So, between 00:00 and 19:00 RATE will be 64Kbit.
+#         Just start "cbq.init timecheck" periodically from cron (every 10
+#         minutes for example).
+#         !!! Anyway you MUST start "cbq.init start" for CBQ initialize.
+# v0.2 -  Some cosmetique changes. Now it more compatible with
+#         old bash version. Thanks to Stanislav V. Voronyi
+#         <stas@cnti.uanet.kharkov.ua>.
+# v0.1 -  First public release
+# 
+# README
+# ------
+# 
+# First of all - this is just a SIMPLE EXAMPLE of CBQ power.
+# Don't ask me "why" and "how" :)
+# 
+# This is an example of using CBQ (Class Based Queueing) and policy-based
+# filter for building smart ethernet shapers. All CBQ parameters are
+# correct only for ETHERNET (eth0,1,2..) linux interfaces. It works for
+# ARCNET too (just set bandwidth parameter to 2Mbit). It was tested
+# on 2.1.125-2.1.129 linux kernels (KSI linux, Nostromo version) and 
+# ip-route utility by A.Kuznetsov (iproute2-ss981101 version). 
+# You can download ip-route from ftp://ftp.inr.ac.ru/ip-routing or
+# get iproute2*.rpm (compiled with glibc) from ftp.ksi-linux.com.
+# 
+# 
+# HOW IT WORKS
+# 
+# Each shaper must be described by config file in $CBQ_PATH
+# (/etc/sysconfig/cbq/) directory - one config file for each CBQ shaper.
+# 
+# Some words about config file name:
+# Each shaper has its personal ID - two byte HEX number. Really ID is 
+# CBQ class.
+# So, filename looks like:
+# 
+# cbq-1280.My_first_shaper
+# ^^^ ^^^  ^^^^^^^^^^^^^
+#  |  |            |______ Shaper name - any word
+#  |  |___________________ ID (0000-FFFF), let ID looks like shaper's rate
+#  |______________________ Filename must begin from "cbq-" 
+# 
+# 
+# Config file describes shaper parameters and source[destination] 
+# address[port].
+# For example let's prepare /etc/sysconfig/cbq/cbq-1280.My_first_shaper:
+# 
+# ----------8<---------------------
+# DEVICE=eth0,10Mbit,1Mbit
+# RATE=128Kbit
+# WEIGHT=10Kbit
+# PRIO=5
+# RULE=192.168.1.0/24
+# ----------8<---------------------
+# 
+# This is minimal configuration, where:
+# DEVICE:  eth0   - device where we do control our traffic
+#          10Mbit - REAL ethernet card bandwidth
+#          1Mbit  - "weight" of :1 class (parent for all shapers for eth0),
+#                   as a rule of thumb weight=batdwidth/10.
+#          100Mbit adapter's example: DEVICE=eth0,100Mbit,10Mbit
+#          *** If you want to build more than one shaper per device it's
+#              enough to describe bandwidth and weight once  - cbq.init
+#              is smart :) You can put only 'DEVICE=eth0' into cbq-* 
+#              config file for eth0.
+# 
+# RATE:    Shaper's speed - Kbit,Mbit or bps (bytes per second)
+# 
+# WEIGHT:  "weight" of shaper (CBQ class). Like for DEVICE - approx. RATE/10
+# 
+# PRIO:    shaper's priority from 1 to 8 where 1 is the highest one.
+#          I do always use "5" for all my shapers.
+# 
+# RULE:    [source addr][:source port],[dest addr][:dest port]
+#          Some examples:
+# RULE=10.1.1.0/24:80         - all traffic for network 10.1.1.0 to port 80
+#                               will be shaped.
+# RULE=10.2.2.5               - shaper works only for IP address 10.2.2.5   
+# RULE=:25,10.2.2.128/25:5000 - all traffic from any address and port 25 to
+#                               address 10.2.2.128 - 10.2.2.255 and port 5000
+#                               will be shaped.
+# RULE=10.5.5.5:80,           - shaper active only for traffic from port 80 of
+#                               address 10.5.5.5
+# Multiple RULE fields per one config file are allowed. For example:
+# RULE=10.1.1.2:80
+# RULE=10.1.1.2:25
+# RULE=10.1.1.2:110
+# 
+# *** ATTENTION!!!
+# All shapers do work only for outgoing traffic!
+# So, if you want to build bidirectional shaper you must set it up for
+# both ethernet card. For example let's build shaper for our linux box like:
+# 
+#                     ---------             192.168.1.1
+# BACKBONE -----eth0-|  linux  |-eth1------*[our client]
+#                     ---------
+# 
+# Let all traffic from backbone to client will be shaped at 28Kbit and
+# traffic from client to backbone - at 128Kbit. We need two config files:
+# 
+# ---8<-----/etc/sysconfig/cbq/cbq-28.client-out----
+# DEVICE=eth1,10Mbit,1Mbit
+# RATE=28Kbit
+# WEIGHT=2Kbit
+# PRIO=5
+# RULE=192.168.1.1
+# ---8<---------------------------------------------
+# 
+# ---8<-----/etc/sysconfig/cbq/cbq-128.client-in----
+# DEVICE=eth0,10Mbit,1Mbit
+# RATE=128Kbit
+# WEIGHT=10Kbit
+# PRIO=5
+# RULE=192.168.1.1,
+# ---8<---------------------------------------------
+#                 ^pay attention to "," - this is source address!
+# 
+# Enjoy.
diff --git a/examples/SYN-DoS.rate.limit b/examples/SYN-DoS.rate.limit
new file mode 100644
index 0000000..8766b67
--- /dev/null
+++ b/examples/SYN-DoS.rate.limit
@@ -0,0 +1,49 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities
+# this script shows how one can rate limit incoming SYNs
+# Useful for TCP-SYN attack protection. You can use
+# IPchains to have more powerful additions to the SYN (eg 
+# in addition the subnet)
+#
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
+INDEV=eth2
+#
+# tag all incoming SYN packets through $INDEV as mark value 1
+############################################################ 
+$IPCHAINS -A input -i $INDEV -y -m 1
+############################################################ 
+#
+# install the ingress qdisc on the ingress interface
+############################################################ 
+$TC qdisc add dev $INDEV handle ffff: ingress
+############################################################ 
+
+#
+# 
+# SYN packets are 40 bytes (320 bits) so three SYNs equals
+# 960 bits (approximately 1kbit); so we rate limit below
+# the incoming SYNs to 3/sec (not very sueful really; but
+#serves to show the point - JHS
+############################################################ 
+$TC filter add dev $INDEV parent ffff: protocol ip prio 50 handle 1 fw \
+police rate 1kbit burst 40 mtu 9k drop flowid :1
+############################################################ 
+
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+#deleting the ingress qdisc
+#$TC qdisc del $INDEV ingress
diff --git a/examples/bpf/README b/examples/bpf/README
index 1bbdda3..4247257 100644
--- a/examples/bpf/README
+++ b/examples/bpf/README
@@ -1,8 +1,13 @@
 eBPF toy code examples (running in kernel) to familiarize yourself
 with syntax and features:
 
+ - bpf_prog.c		-> Classifier examples with using maps
  - bpf_shared.c		-> Ingress/egress map sharing example
  - bpf_tailcall.c	-> Using tail call chains
  - bpf_cyclic.c		-> Simple cycle as tail calls
  - bpf_graft.c		-> Demo on altering runtime behaviour
- - bpf_map_in_map.c     -> Using map in map example
+
+User space code example:
+
+ - bpf_agent.c		-> Counterpart to bpf_prog.c for user
+                           space to transfer/read out map data
diff --git a/examples/bpf/bpf_agent.c b/examples/bpf/bpf_agent.c
new file mode 100644
index 0000000..f9b9ce3
--- /dev/null
+++ b/examples/bpf/bpf_agent.c
@@ -0,0 +1,258 @@
+/*
+ * eBPF user space agent part
+ *
+ * Simple, _self-contained_ user space agent for the eBPF kernel
+ * ebpf_prog.c program, which gets all map fds passed from tc via unix
+ * domain socket in one transaction and can thus keep referencing
+ * them from user space in order to read out (or possibly modify)
+ * map data. Here, just as a minimal example to display counters.
+ *
+ * The agent only uses the bpf(2) syscall API to read or possibly
+ * write to eBPF maps, it doesn't need to be aware of the low-level
+ * bytecode parts and/or ELF parsing bits.
+ *
+ * ! For more details, see header comment in bpf_prog.c !
+ *
+ * gcc bpf_agent.c -o bpf_agent -Wall -O2
+ *
+ * For example, a more complex user space agent could run on each
+ * host, reading and writing into eBPF maps used by tc classifier
+ * and actions. It would thus allow for implementing a distributed
+ * tc architecture, for example, which would push down central
+ * policies into eBPF maps, and thus altering run-time behaviour.
+ *
+ *   -- Happy eBPF hacking! ;)
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <assert.h>
+
+#include <sys/un.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+
+/* Just some misc macros as min(), offsetof(), etc. */
+#include "../../include/utils.h"
+/* Common code from fd passing. */
+#include "../../include/bpf_scm.h"
+/* Common, shared definitions with ebpf_prog.c */
+#include "bpf_shared.h"
+/* Mini syscall wrapper */
+#include "bpf_sys.h"
+
+static void bpf_dump_drops(int fd)
+{
+	int cpu, max;
+
+	max = sysconf(_SC_NPROCESSORS_ONLN);
+
+	printf(" `- number of drops:");
+	for (cpu = 0; cpu < max; cpu++) {
+		long drops;
+
+		assert(bpf_lookup_elem(fd, &cpu, &drops) == 0);
+		printf("\tcpu%d: %5ld", cpu, drops);
+	}
+	printf("\n");
+}
+
+static void bpf_dump_queue(int fd)
+{
+	/* Just for the same of the example. */
+	int max_queue = 4, i;
+
+	printf("  | nic queues:");
+	for (i = 0; i < max_queue; i++) {
+		struct count_queue cq;
+		int ret;
+
+		memset(&cq, 0, sizeof(cq));
+		ret = bpf_lookup_elem(fd, &i, &cq);
+		assert(ret == 0 || (ret < 0 && errno == ENOENT));
+
+		printf("\tq%d:[pkts: %ld, mis: %ld]",
+		       i, cq.total, cq.mismatch);
+	}
+	printf("\n");
+}
+
+static void bpf_dump_proto(int fd)
+{
+	uint8_t protos[] = { IPPROTO_TCP, IPPROTO_UDP, IPPROTO_ICMP };
+	char *names[] = { "tcp", "udp", "icmp" };
+	int i;
+
+	printf("  ` protos:");
+	for (i = 0; i < ARRAY_SIZE(protos); i++) {
+		struct count_tuple ct;
+		int ret;
+
+		memset(&ct, 0, sizeof(ct));
+		ret = bpf_lookup_elem(fd, &protos[i], &ct);
+		assert(ret == 0 || (ret < 0 && errno == ENOENT));
+
+		printf("\t%s:[pkts: %ld, bytes: %ld]",
+		       names[i], ct.packets, ct.bytes);
+	}
+	printf("\n");
+}
+
+static void bpf_dump_map_data(int *tfd)
+{
+	int i;
+
+	for (i = 0; i < 30; i++) {
+		const int period = 5;
+
+		printf("data, period: %dsec\n", period);
+
+		bpf_dump_drops(tfd[BPF_MAP_ID_DROPS]);
+		bpf_dump_queue(tfd[BPF_MAP_ID_QUEUE]);
+		bpf_dump_proto(tfd[BPF_MAP_ID_PROTO]);
+
+		sleep(period);
+	}
+}
+
+static void bpf_info_loop(int *fds, struct bpf_map_aux *aux)
+{
+	int i, tfd[BPF_MAP_ID_MAX];
+
+	printf("ver: %d\nobj: %s\ndev: %lu\nino: %lu\nmaps: %u\n",
+	       aux->uds_ver, aux->obj_name, aux->obj_st.st_dev,
+	       aux->obj_st.st_ino, aux->num_ent);
+
+	for (i = 0; i < aux->num_ent; i++) {
+		printf("map%d:\n", i);
+		printf(" `- fd: %u\n", fds[i]);
+		printf("  | serial: %u\n", aux->ent[i].id);
+		printf("  | type: %u\n", aux->ent[i].type);
+		printf("  | max elem: %u\n", aux->ent[i].max_elem);
+		printf("  | size key: %u\n", aux->ent[i].size_key);
+		printf("  ` size val: %u\n", aux->ent[i].size_value);
+
+		tfd[aux->ent[i].id] = fds[i];
+	}
+
+	bpf_dump_map_data(tfd);
+}
+
+static void bpf_map_get_from_env(int *tfd)
+{
+	char key[64], *val;
+	int i;
+
+	for (i = 0; i < BPF_MAP_ID_MAX; i++) {
+		memset(key, 0, sizeof(key));
+		snprintf(key, sizeof(key), "BPF_MAP%d", i);
+
+		val = getenv(key);
+		assert(val != NULL);
+
+		tfd[i] = atoi(val);
+	}
+}
+
+static int bpf_map_set_recv(int fd, int *fds,  struct bpf_map_aux *aux,
+			    unsigned int entries)
+{
+	struct bpf_map_set_msg msg;
+	int *cmsg_buf, min_fd, i;
+	char *amsg_buf, *mmsg_buf;
+
+	cmsg_buf = bpf_map_set_init(&msg, NULL, 0);
+	amsg_buf = (char *)msg.aux.ent;
+	mmsg_buf = (char *)&msg.aux;
+
+	for (i = 0; i < entries; i += min_fd) {
+		struct cmsghdr *cmsg;
+		int ret;
+
+		min_fd = min(BPF_SCM_MAX_FDS * 1U, entries - i);
+
+		bpf_map_set_init_single(&msg, min_fd);
+
+		ret = recvmsg(fd, &msg.hdr, 0);
+		if (ret <= 0)
+			return ret ? : -1;
+
+		cmsg = CMSG_FIRSTHDR(&msg.hdr);
+		if (!cmsg || cmsg->cmsg_type != SCM_RIGHTS)
+			return -EINVAL;
+		if (msg.hdr.msg_flags & MSG_CTRUNC)
+			return -EIO;
+
+		min_fd = (cmsg->cmsg_len - sizeof(*cmsg)) / sizeof(fd);
+		if (min_fd > entries || min_fd <= 0)
+			return -1;
+
+		memcpy(&fds[i], cmsg_buf, sizeof(fds[0]) * min_fd);
+		memcpy(&aux->ent[i], amsg_buf, sizeof(aux->ent[0]) * min_fd);
+		memcpy(aux, mmsg_buf, offsetof(struct bpf_map_aux, ent));
+
+		if (i + min_fd == aux->num_ent)
+			break;
+	}
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int fds[BPF_SCM_MAX_FDS];
+	struct bpf_map_aux aux;
+	struct sockaddr_un addr;
+	int fd, ret, i;
+
+	/* When arguments are being passed, we take it as a path
+	 * to a Unix domain socket, otherwise we grab the fds
+	 * from the environment to demonstrate both possibilities.
+	 */
+	if (argc == 1) {
+		int tfd[BPF_MAP_ID_MAX];
+
+		bpf_map_get_from_env(tfd);
+		bpf_dump_map_data(tfd);
+
+		return 0;
+	}
+
+	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+	if (fd < 0) {
+		fprintf(stderr, "Cannot open socket: %s\n",
+			strerror(errno));
+		exit(1);
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sun_family = AF_UNIX;
+	strncpy(addr.sun_path, argv[argc - 1], sizeof(addr.sun_path));
+
+	ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
+	if (ret < 0) {
+		fprintf(stderr, "Cannot bind to socket: %s\n",
+			strerror(errno));
+		exit(1);
+	}
+
+	memset(fds, 0, sizeof(fds));
+	memset(&aux, 0, sizeof(aux));
+
+	ret = bpf_map_set_recv(fd, fds, &aux, BPF_SCM_MAX_FDS);
+	if (ret >= 0)
+		bpf_info_loop(fds, &aux);
+
+	for (i = 0; i < aux.num_ent; i++)
+		close(fds[i]);
+
+	close(fd);
+	return 0;
+}
diff --git a/examples/bpf/bpf_cyclic.c b/examples/bpf/bpf_cyclic.c
index 11d1c06..c66cbec 100644
--- a/examples/bpf/bpf_cyclic.c
+++ b/examples/bpf/bpf_cyclic.c
@@ -6,19 +6,14 @@
  */
 #define JMP_MAP_ID	0xabccba
 
-struct bpf_elf_map __section_maps jmp_tc = {
-	.type		= BPF_MAP_TYPE_PROG_ARRAY,
-	.id		= JMP_MAP_ID,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.pinning	= PIN_OBJECT_NS,
-	.max_elem	= 1,
-};
+BPF_PROG_ARRAY(jmp_tc, JMP_MAP_ID, PIN_OBJECT_NS, 1);
 
 __section_tail(JMP_MAP_ID, 0)
 int cls_loop(struct __sk_buff *skb)
 {
-	printt("cb: %u\n", skb->cb[0]++);
+	char fmt[] = "cb: %u\n";
+
+	trace_printk(fmt, sizeof(fmt), skb->cb[0]++);
 	tail_call(skb, &jmp_tc, 0);
 
 	skb->tc_classid = TC_H_MAKE(1, 42);
diff --git a/examples/bpf/bpf_graft.c b/examples/bpf/bpf_graft.c
index 07113d4..f48fd02 100644
--- a/examples/bpf/bpf_graft.c
+++ b/examples/bpf/bpf_graft.c
@@ -33,33 +33,34 @@
  *   [...]
  */
 
-struct bpf_elf_map __section_maps jmp_tc = {
-	.type		= BPF_MAP_TYPE_PROG_ARRAY,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.pinning	= PIN_GLOBAL_NS,
-	.max_elem	= 1,
-};
+BPF_PROG_ARRAY(jmp_tc, 0, PIN_GLOBAL_NS, 1);
 
 __section("aaa")
 int cls_aaa(struct __sk_buff *skb)
 {
-	printt("aaa\n");
+	char fmt[] = "aaa\n";
+
+	trace_printk(fmt, sizeof(fmt));
 	return TC_H_MAKE(1, 42);
 }
 
 __section("bbb")
 int cls_bbb(struct __sk_buff *skb)
 {
-	printt("bbb\n");
+	char fmt[] = "bbb\n";
+
+	trace_printk(fmt, sizeof(fmt));
 	return TC_H_MAKE(1, 43);
 }
 
 __section_cls_entry
 int cls_entry(struct __sk_buff *skb)
 {
+	char fmt[] = "fallthrough\n";
+
 	tail_call(skb, &jmp_tc, 0);
-	printt("fallthrough\n");
+	trace_printk(fmt, sizeof(fmt));
+
 	return BPF_H_DEFAULT;
 }
 
diff --git a/examples/bpf/bpf_map_in_map.c b/examples/bpf/bpf_map_in_map.c
deleted file mode 100644
index ff0e623..0000000
--- a/examples/bpf/bpf_map_in_map.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "../../include/bpf_api.h"
-
-#define MAP_INNER_ID	42
-
-struct bpf_elf_map __section_maps map_inner = {
-	.type		= BPF_MAP_TYPE_ARRAY,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.id		= MAP_INNER_ID,
-	.inner_idx	= 0,
-	.pinning	= PIN_GLOBAL_NS,
-	.max_elem	= 1,
-};
-
-struct bpf_elf_map __section_maps map_outer = {
-	.type		= BPF_MAP_TYPE_ARRAY_OF_MAPS,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.inner_id	= MAP_INNER_ID,
-	.pinning	= PIN_GLOBAL_NS,
-	.max_elem	= 1,
-};
-
-__section("egress")
-int emain(struct __sk_buff *skb)
-{
-	struct bpf_elf_map *map_inner;
-	int key = 0, *val;
-
-	map_inner = map_lookup_elem(&map_outer, &key);
-	if (map_inner) {
-		val = map_lookup_elem(map_inner, &key);
-		if (val)
-			lock_xadd(val, 1);
-	}
-
-	return BPF_H_DEFAULT;
-}
-
-__section("ingress")
-int imain(struct __sk_buff *skb)
-{
-	struct bpf_elf_map *map_inner;
-	int key = 0, *val;
-
-	map_inner = map_lookup_elem(&map_outer, &key);
-	if (map_inner) {
-		val = map_lookup_elem(map_inner, &key);
-		if (val)
-			printt("map val: %d\n", *val);
-	}
-
-	return BPF_H_DEFAULT;
-}
-
-BPF_LICENSE("GPL");
diff --git a/examples/bpf/bpf_prog.c b/examples/bpf/bpf_prog.c
new file mode 100644
index 0000000..4728049
--- /dev/null
+++ b/examples/bpf/bpf_prog.c
@@ -0,0 +1,499 @@
+/*
+ * eBPF kernel space program part
+ *
+ * Toy eBPF program for demonstration purposes, some parts derived from
+ * kernel tree's samples/bpf/sockex2_kern.c example.
+ *
+ * More background on eBPF, kernel tree: Documentation/networking/filter.txt
+ *
+ * Note, this file is rather large, and most classifier and actions are
+ * likely smaller to accomplish one specific use-case and are tailored
+ * for high performance. For performance reasons, you might also have the
+ * classifier and action already merged inside the classifier.
+ *
+ * In order to show various features it serves as a bigger programming
+ * example, which you should feel free to rip apart and experiment with.
+ *
+ * Compilation, configuration example:
+ *
+ *  Note: as long as the BPF backend in LLVM is still experimental,
+ *  you need to build LLVM with LLVM with --enable-experimental-targets=BPF
+ *  Also, make sure your 4.1+ kernel is compiled with CONFIG_BPF_SYSCALL=y,
+ *  and you have libelf.h and gelf.h headers and can link tc against -lelf.
+ *
+ *  In case you need to sync kernel headers, go to your kernel source tree:
+ *  # make headers_install INSTALL_HDR_PATH=/usr/
+ *
+ *  $ export PATH=/home/<...>/llvm/Debug+Asserts/bin/:$PATH
+ *  $ clang -O2 -emit-llvm -c bpf_prog.c -o - | llc -march=bpf -filetype=obj -o bpf.o
+ *  $ objdump -h bpf.o
+ *  [...]
+ *  3 classifier    000007f8  0000000000000000  0000000000000000  00000040  2**3
+ *                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
+ *  4 action-mark   00000088  0000000000000000  0000000000000000  00000838  2**3
+ *                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
+ *  5 action-rand   00000098  0000000000000000  0000000000000000  000008c0  2**3
+ *                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
+ *  6 maps          00000030  0000000000000000  0000000000000000  00000958  2**2
+ *                  CONTENTS, ALLOC, LOAD, DATA
+ *  7 license       00000004  0000000000000000  0000000000000000  00000988  2**0
+ *                  CONTENTS, ALLOC, LOAD, DATA
+ *  [...]
+ *  # echo 1 > /proc/sys/net/core/bpf_jit_enable
+ *  $ gcc bpf_agent.c -o bpf_agent -Wall -O2
+ *  # ./bpf_agent /tmp/bpf-uds      (e.g. on a different terminal)
+ *  # tc filter add dev em1 parent 1: bpf obj bpf.o exp /tmp/bpf-uds flowid 1:1 \
+ *                             action bpf obj bpf.o sec action-mark            \
+ *                             action bpf obj bpf.o sec action-rand ok
+ *  # tc filter show dev em1
+ *  filter parent 1: protocol all pref 49152 bpf
+ *  filter parent 1: protocol all pref 49152 bpf handle 0x1 flowid 1:1 bpf.o:[classifier]
+ *    action order 1: bpf bpf.o:[action-mark] default-action pipe
+ *    index 52 ref 1 bind 1
+ *
+ *    action order 2: bpf bpf.o:[action-rand] default-action pipe
+ *    index 53 ref 1 bind 1
+ *
+ *    action order 3: gact action pass
+ *    random type none pass val 0
+ *    index 38 ref 1 bind 1
+ *
+ * The same program can also be installed on ingress side (as opposed to above
+ * egress configuration), e.g.:
+ *
+ * # tc qdisc add dev em1 handle ffff: ingress
+ * # tc filter add dev em1 parent ffff: bpf obj ...
+ *
+ * Notes on BPF agent:
+ *
+ * In the above example, the bpf_agent creates the unix domain socket
+ * natively. "tc exec" can also spawn a shell and hold the socktes there:
+ *
+ *  # tc exec bpf imp /tmp/bpf-uds
+ *  # tc filter add dev em1 parent 1: bpf obj bpf.o exp /tmp/bpf-uds flowid 1:1 \
+ *                             action bpf obj bpf.o sec action-mark            \
+ *                             action bpf obj bpf.o sec action-rand ok
+ *  sh-4.2# (shell spawned from tc exec)
+ *  sh-4.2# bpf_agent
+ *  [...]
+ *
+ * This will read out fds over environment and produce the same data dump
+ * as below. This has the advantage that the spawned shell owns the fds
+ * and thus if the agent is restarted, it can reattach to the same fds, also
+ * various programs can easily read/modify the data simultaneously from user
+ * space side.
+ *
+ * If the shell is unnecessary, the agent can also just be spawned directly
+ * via tc exec:
+ *
+ *  # tc exec bpf imp /tmp/bpf-uds run bpf_agent
+ *  # tc filter add dev em1 parent 1: bpf obj bpf.o exp /tmp/bpf-uds flowid 1:1 \
+ *                             action bpf obj bpf.o sec action-mark            \
+ *                             action bpf obj bpf.o sec action-rand ok
+ *
+ * BPF agent example output:
+ *
+ * ver: 1
+ * obj: bpf.o
+ * dev: 64770
+ * ino: 6045133
+ * maps: 3
+ * map0:
+ *  `- fd: 4
+ *   | serial: 1
+ *   | type: 1
+ *   | max elem: 256
+ *   | size key: 1
+ *   ` size val: 16
+ * map1:
+ *  `- fd: 5
+ *   | serial: 2
+ *   | type: 1
+ *   | max elem: 1024
+ *   | size key: 4
+ *   ` size val: 16
+ * map2:
+ *  `- fd: 6
+ *   | serial: 3
+ *   | type: 2
+ *   | max elem: 64
+ *   | size key: 4
+ *   ` size val: 8
+ * data, period: 5sec
+ *  `- number of drops:	cpu0:     0	cpu1:     0	cpu2:     0	cpu3:     0
+ *   | nic queues:	q0:[pkts: 0, mis: 0]	q1:[pkts: 0, mis: 0]	q2:[pkts: 0, mis: 0]	q3:[pkts: 0, mis: 0]
+ *   ` protos:	tcp:[pkts: 0, bytes: 0]	udp:[pkts: 0, bytes: 0]	icmp:[pkts: 0, bytes: 0]
+ * data, period: 5sec
+ *  `- number of drops:	cpu0:     5	cpu1:     0	cpu2:     0	cpu3:     1
+ *   | nic queues:	q0:[pkts: 0, mis: 0]	q1:[pkts: 0, mis: 0]	q2:[pkts: 24, mis: 14]	q3:[pkts: 0, mis: 0]
+ *   ` protos:	tcp:[pkts: 13, bytes: 1989]	udp:[pkts: 10, bytes: 710]	icmp:[pkts: 0, bytes: 0]
+ * data, period: 5sec
+ *  `- number of drops:	cpu0:     5	cpu1:     0	cpu2:     3	cpu3:     3
+ *   | nic queues:	q0:[pkts: 0, mis: 0]	q1:[pkts: 0, mis: 0]	q2:[pkts: 39, mis: 21]	q3:[pkts: 0, mis: 0]
+ *   ` protos:	tcp:[pkts: 20, bytes: 3549]	udp:[pkts: 18, bytes: 1278]	icmp:[pkts: 0, bytes: 0]
+ * [...]
+ *
+ * This now means, the below classifier and action pipeline has been loaded
+ * as eBPF bytecode into the kernel, the kernel has verified that the
+ * execution of the bytecode is "safe", and it has JITed the programs
+ * afterwards, so that upon invocation they're running on native speed. tc
+ * has transferred all map file descriptors to the bpf_agent via IPC and
+ * even after tc exits, the agent can read out or modify all map data.
+ *
+ * Note that the export to the uds is done only once in the classifier and
+ * not in the action. It's enough to export the (here) shared descriptors
+ * once.
+ *
+ * If you need to disassemble the generated JIT image (echo with 2), the
+ * kernel tree has under tools/net/ a small helper, you can invoke e.g.
+ * `bpf_jit_disasm -o`.
+ *
+ * Please find in the code below further comments.
+ *
+ *   -- Happy eBPF hacking! ;)
+ */
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <asm/types.h>
+#include <linux/in.h>
+#include <linux/if.h>
+#include <linux/if_ether.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/if_tunnel.h>
+#include <linux/filter.h>
+#include <linux/bpf.h>
+
+/* Common, shared definitions with ebpf_agent.c. */
+#include "bpf_shared.h"
+/* BPF helper functions for our example. */
+#include "../../include/bpf_api.h"
+
+/* Could be defined here as well, or included from the header. */
+#define TC_ACT_UNSPEC		(-1)
+#define TC_ACT_OK		0
+#define TC_ACT_RECLASSIFY	1
+#define TC_ACT_SHOT		2
+#define TC_ACT_PIPE		3
+#define TC_ACT_STOLEN		4
+#define TC_ACT_QUEUED		5
+#define TC_ACT_REPEAT		6
+
+/* Other, misc stuff. */
+#define IP_MF			0x2000
+#define IP_OFFSET		0x1FFF
+
+/* eBPF map definitions, all placed in section "maps". */
+struct bpf_elf_map __section("maps") map_proto = {
+	.type		=	BPF_MAP_TYPE_HASH,
+	.id		=	BPF_MAP_ID_PROTO,
+	.size_key	=	sizeof(uint8_t),
+	.size_value	=	sizeof(struct count_tuple),
+	.max_elem	=	256,
+};
+
+struct bpf_elf_map __section("maps") map_queue = {
+	.type		=	BPF_MAP_TYPE_HASH,
+	.id		=	BPF_MAP_ID_QUEUE,
+	.size_key	=	sizeof(uint32_t),
+	.size_value	=	sizeof(struct count_queue),
+	.max_elem	=	1024,
+};
+
+struct bpf_elf_map __section("maps") map_drops = {
+	.type		=	BPF_MAP_TYPE_ARRAY,
+	.id		=	BPF_MAP_ID_DROPS,
+	.size_key	=	sizeof(uint32_t),
+	.size_value	=	sizeof(long),
+	.max_elem	=	64,
+};
+
+/* Helper functions and definitions for the flow dissector used by the
+ * example classifier. This resembles the kernel's flow dissector to
+ * some extend and is just used as an example to show what's possible
+ * with eBPF.
+ */
+struct sockaddr;
+
+struct vlan_hdr {
+	__be16 h_vlan_TCI;
+	__be16 h_vlan_encapsulated_proto;
+};
+
+struct flow_keys {
+	__u32 src;
+	__u32 dst;
+	union {
+		__u32 ports;
+		__u16 port16[2];
+	};
+	__s32 th_off;
+	__u8 ip_proto;
+};
+
+static inline int flow_ports_offset(__u8 ip_proto)
+{
+	switch (ip_proto) {
+	case IPPROTO_TCP:
+	case IPPROTO_UDP:
+	case IPPROTO_DCCP:
+	case IPPROTO_ESP:
+	case IPPROTO_SCTP:
+	case IPPROTO_UDPLITE:
+	default:
+		return 0;
+	case IPPROTO_AH:
+		return 4;
+	}
+}
+
+static inline bool flow_is_frag(struct __sk_buff *skb, int nh_off)
+{
+	return !!(load_half(skb, nh_off + offsetof(struct iphdr, frag_off)) &
+		  (IP_MF | IP_OFFSET));
+}
+
+static inline int flow_parse_ipv4(struct __sk_buff *skb, int nh_off,
+				  __u8 *ip_proto, struct flow_keys *flow)
+{
+	__u8 ip_ver_len;
+
+	if (unlikely(flow_is_frag(skb, nh_off)))
+		*ip_proto = 0;
+	else
+		*ip_proto = load_byte(skb, nh_off + offsetof(struct iphdr,
+							     protocol));
+	if (*ip_proto != IPPROTO_GRE) {
+		flow->src = load_word(skb, nh_off + offsetof(struct iphdr, saddr));
+		flow->dst = load_word(skb, nh_off + offsetof(struct iphdr, daddr));
+	}
+
+	ip_ver_len = load_byte(skb, nh_off + 0 /* offsetof(struct iphdr, ihl) */);
+	if (likely(ip_ver_len == 0x45))
+		nh_off += 20;
+	else
+		nh_off += (ip_ver_len & 0xF) << 2;
+
+	return nh_off;
+}
+
+static inline __u32 flow_addr_hash_ipv6(struct __sk_buff *skb, int off)
+{
+	__u32 w0 = load_word(skb, off);
+	__u32 w1 = load_word(skb, off + sizeof(w0));
+	__u32 w2 = load_word(skb, off + sizeof(w0) * 2);
+	__u32 w3 = load_word(skb, off + sizeof(w0) * 3);
+
+	return w0 ^ w1 ^ w2 ^ w3;
+}
+
+static inline int flow_parse_ipv6(struct __sk_buff *skb, int nh_off,
+				  __u8 *ip_proto, struct flow_keys *flow)
+{
+	*ip_proto = load_byte(skb, nh_off + offsetof(struct ipv6hdr, nexthdr));
+
+	flow->src = flow_addr_hash_ipv6(skb, nh_off + offsetof(struct ipv6hdr, saddr));
+	flow->dst = flow_addr_hash_ipv6(skb, nh_off + offsetof(struct ipv6hdr, daddr));
+
+	return nh_off + sizeof(struct ipv6hdr);
+}
+
+static inline bool flow_dissector(struct __sk_buff *skb,
+				  struct flow_keys *flow)
+{
+	int poff, nh_off = BPF_LL_OFF + ETH_HLEN;
+	__be16 proto = skb->protocol;
+	__u8 ip_proto;
+
+	/* TODO: check for skb->vlan_tci, skb->vlan_proto first */
+	if (proto == htons(ETH_P_8021AD)) {
+		proto = load_half(skb, nh_off +
+				  offsetof(struct vlan_hdr, h_vlan_encapsulated_proto));
+		nh_off += sizeof(struct vlan_hdr);
+	}
+	if (proto == htons(ETH_P_8021Q)) {
+		proto = load_half(skb, nh_off +
+				  offsetof(struct vlan_hdr, h_vlan_encapsulated_proto));
+		nh_off += sizeof(struct vlan_hdr);
+	}
+
+	if (likely(proto == htons(ETH_P_IP)))
+		nh_off = flow_parse_ipv4(skb, nh_off, &ip_proto, flow);
+	else if (proto == htons(ETH_P_IPV6))
+		nh_off = flow_parse_ipv6(skb, nh_off, &ip_proto, flow);
+	else
+		return false;
+
+	switch (ip_proto) {
+	case IPPROTO_GRE: {
+		struct gre_hdr {
+			__be16 flags;
+			__be16 proto;
+		};
+
+		__u16 gre_flags = load_half(skb, nh_off +
+					    offsetof(struct gre_hdr, flags));
+		__u16 gre_proto = load_half(skb, nh_off +
+					    offsetof(struct gre_hdr, proto));
+
+		if (gre_flags & (GRE_VERSION | GRE_ROUTING))
+			break;
+
+		nh_off += 4;
+		if (gre_flags & GRE_CSUM)
+			nh_off += 4;
+		if (gre_flags & GRE_KEY)
+			nh_off += 4;
+		if (gre_flags & GRE_SEQ)
+			nh_off += 4;
+
+		if (gre_proto == ETH_P_8021Q) {
+			gre_proto = load_half(skb, nh_off +
+					      offsetof(struct vlan_hdr,
+						       h_vlan_encapsulated_proto));
+			nh_off += sizeof(struct vlan_hdr);
+		}
+		if (gre_proto == ETH_P_IP)
+			nh_off = flow_parse_ipv4(skb, nh_off, &ip_proto, flow);
+		else if (gre_proto == ETH_P_IPV6)
+			nh_off = flow_parse_ipv6(skb, nh_off, &ip_proto, flow);
+		else
+			return false;
+		break;
+	}
+	case IPPROTO_IPIP:
+		nh_off = flow_parse_ipv4(skb, nh_off, &ip_proto, flow);
+		break;
+	case IPPROTO_IPV6:
+		nh_off = flow_parse_ipv6(skb, nh_off, &ip_proto, flow);
+	default:
+		break;
+	}
+
+	nh_off += flow_ports_offset(ip_proto);
+
+	flow->ports = load_word(skb, nh_off);
+	flow->th_off = nh_off;
+	flow->ip_proto = ip_proto;
+
+	return true;
+}
+
+static inline void cls_update_proto_map(const struct __sk_buff *skb,
+					const struct flow_keys *flow)
+{
+	uint8_t proto = flow->ip_proto;
+	struct count_tuple *ct, _ct;
+
+	ct = map_lookup_elem(&map_proto, &proto);
+	if (likely(ct)) {
+		lock_xadd(&ct->packets, 1);
+		lock_xadd(&ct->bytes, skb->len);
+		return;
+	}
+
+	/* No hit yet, we need to create a new entry. */
+	_ct.packets = 1;
+	_ct.bytes = skb->len;
+
+	map_update_elem(&map_proto, &proto, &_ct, BPF_ANY);
+}
+
+static inline void cls_update_queue_map(const struct __sk_buff *skb)
+{
+	uint32_t queue = skb->queue_mapping;
+	struct count_queue *cq, _cq;
+	bool mismatch;
+
+	mismatch = skb->queue_mapping != get_smp_processor_id();
+
+	cq = map_lookup_elem(&map_queue, &queue);
+	if (likely(cq)) {
+		lock_xadd(&cq->total, 1);
+		if (mismatch)
+			lock_xadd(&cq->mismatch, 1);
+		return;
+	}
+
+	/* No hit yet, we need to create a new entry. */
+	_cq.total = 1;
+	_cq.mismatch = mismatch ? 1 : 0;
+
+	map_update_elem(&map_queue, &queue, &_cq, BPF_ANY);
+}
+
+/* eBPF program definitions, placed in various sections, which can
+ * have custom section names. If custom names are in use, it's
+ * required to point tc to the correct section, e.g.
+ *
+ *     tc filter add [...] bpf obj cls.o sec cls-tos [...]
+ *
+ * in case the program resides in __section("cls-tos").
+ *
+ * Default section for cls_bpf is: "classifier", for act_bpf is:
+ * "action". Naturally, if for example multiple actions are present
+ * in the same file, they need to have distinct section names.
+ *
+ * It is however not required to have multiple programs sharing
+ * a file.
+ */
+__section("classifier")
+int cls_main(struct __sk_buff *skb)
+{
+	struct flow_keys flow;
+
+	if (!flow_dissector(skb, &flow))
+		return 0; /* No match in cls_bpf. */
+
+	cls_update_proto_map(skb, &flow);
+	cls_update_queue_map(skb);
+
+	return flow.ip_proto;
+}
+
+static inline void act_update_drop_map(void)
+{
+	uint32_t *count, cpu = get_smp_processor_id();
+
+	count = map_lookup_elem(&map_drops, &cpu);
+	if (count)
+		/* Only this cpu is accessing this element. */
+		(*count)++;
+}
+
+__section("action-mark")
+int act_mark_main(struct __sk_buff *skb)
+{
+	/* You could also mangle skb data here with the helper function
+	 * BPF_FUNC_skb_store_bytes, etc. Or, alternatively you could
+	 * do that already in the classifier itself as a merged combination
+	 * of classifier'n'action model.
+	 */
+
+	if (skb->mark == 0xcafe) {
+		act_update_drop_map();
+		return TC_ACT_SHOT;
+	}
+
+	/* Default configured tc opcode. */
+	return TC_ACT_UNSPEC;
+}
+
+__section("action-rand")
+int act_rand_main(struct __sk_buff *skb)
+{
+	/* Sorry, we're near event horizon ... */
+	if ((get_prandom_u32() & 3) == 0) {
+		act_update_drop_map();
+		return TC_ACT_SHOT;
+	}
+
+	return TC_ACT_UNSPEC;
+}
+
+/* Last but not least, the file contains a license. Some future helper
+ * functions may only be available with a GPL license.
+ */
+BPF_LICENSE("GPL");
diff --git a/examples/bpf/bpf_shared.c b/examples/bpf/bpf_shared.c
index 21fe6f1..accc0ad 100644
--- a/examples/bpf/bpf_shared.c
+++ b/examples/bpf/bpf_shared.c
@@ -18,13 +18,7 @@
  * instance is being created.
  */
 
-struct bpf_elf_map __section_maps map_sh = {
-	.type		= BPF_MAP_TYPE_ARRAY,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.pinning	= PIN_OBJECT_NS, /* or PIN_GLOBAL_NS, or PIN_NONE */
-	.max_elem	= 1,
-};
+BPF_ARRAY4(map_sh, 0, PIN_OBJECT_NS, 1); /* or PIN_GLOBAL_NS, or PIN_NONE */
 
 __section("egress")
 int emain(struct __sk_buff *skb)
@@ -41,11 +35,12 @@
 __section("ingress")
 int imain(struct __sk_buff *skb)
 {
+	char fmt[] = "map val: %d\n";
 	int key = 0, *val;
 
 	val = map_lookup_elem(&map_sh, &key);
 	if (val)
-		printt("map val: %d\n", *val);
+		trace_printk(fmt, sizeof(fmt), *val);
 
 	return BPF_H_DEFAULT;
 }
diff --git a/examples/bpf/bpf_shared.h b/examples/bpf/bpf_shared.h
new file mode 100644
index 0000000..a24038d
--- /dev/null
+++ b/examples/bpf/bpf_shared.h
@@ -0,0 +1,22 @@
+#ifndef __BPF_SHARED__
+#define __BPF_SHARED__
+
+enum {
+	BPF_MAP_ID_PROTO,
+	BPF_MAP_ID_QUEUE,
+	BPF_MAP_ID_DROPS,
+	__BPF_MAP_ID_MAX,
+#define BPF_MAP_ID_MAX	__BPF_MAP_ID_MAX
+};
+
+struct count_tuple {
+	long packets; /* type long for lock_xadd() */
+	long bytes;
+};
+
+struct count_queue {
+	long total;
+	long mismatch;
+};
+
+#endif /* __BPF_SHARED__ */
diff --git a/examples/bpf/bpf_sys.h b/examples/bpf/bpf_sys.h
new file mode 100644
index 0000000..6e4f09e
--- /dev/null
+++ b/examples/bpf/bpf_sys.h
@@ -0,0 +1,23 @@
+#ifndef __BPF_SYS__
+#define __BPF_SYS__
+
+#include <sys/syscall.h>
+#include <linux/bpf.h>
+
+static inline __u64 bpf_ptr_to_u64(const void *ptr)
+{
+	return (__u64) (unsigned long) ptr;
+}
+
+static inline int bpf_lookup_elem(int fd, void *key, void *value)
+{
+	union bpf_attr attr = {
+		.map_fd		= fd,
+		.key		= bpf_ptr_to_u64(key),
+		.value		= bpf_ptr_to_u64(value),
+	};
+
+	return syscall(__NR_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
+}
+
+#endif /* __BPF_SYS__ */
diff --git a/examples/bpf/bpf_tailcall.c b/examples/bpf/bpf_tailcall.c
index 161eb60..040790d 100644
--- a/examples/bpf/bpf_tailcall.c
+++ b/examples/bpf/bpf_tailcall.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #include "../../include/bpf_api.h"
 
 #define ENTRY_INIT	3
@@ -27,40 +26,20 @@
  * classifier behaviour.
  */
 
-struct bpf_elf_map __section_maps jmp_tc = {
-	.type		= BPF_MAP_TYPE_PROG_ARRAY,
-	.id		= FOO,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.pinning	= PIN_OBJECT_NS,
-	.max_elem	= MAX_JMP_SIZE,
-};
+BPF_PROG_ARRAY(jmp_tc, FOO, PIN_OBJECT_NS, MAX_JMP_SIZE);
+BPF_PROG_ARRAY(jmp_ex, BAR, PIN_OBJECT_NS, 1);
 
-struct bpf_elf_map __section_maps jmp_ex = {
-	.type		= BPF_MAP_TYPE_PROG_ARRAY,
-	.id		= BAR,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.pinning	= PIN_OBJECT_NS,
-	.max_elem	= 1,
-};
-
-struct bpf_elf_map __section_maps map_sh = {
-	.type		= BPF_MAP_TYPE_ARRAY,
-	.size_key	= sizeof(uint32_t),
-	.size_value	= sizeof(uint32_t),
-	.pinning	= PIN_OBJECT_NS,
-	.max_elem	= 1,
-};
+BPF_ARRAY4(map_sh, 0, PIN_OBJECT_NS, 1);
 
 __section_tail(FOO, ENTRY_0)
 int cls_case1(struct __sk_buff *skb)
 {
+	char fmt[] = "case1: map-val: %d from:%u\n";
 	int key = 0, *val;
 
 	val = map_lookup_elem(&map_sh, &key);
 	if (val)
-		printt("case1: map-val: %d from:%u\n", *val, skb->cb[0]);
+		trace_printk(fmt, sizeof(fmt), *val, skb->cb[0]);
 
 	skb->cb[0] = ENTRY_0;
 	tail_call(skb, &jmp_ex, ENTRY_0);
@@ -71,11 +50,12 @@
 __section_tail(FOO, ENTRY_1)
 int cls_case2(struct __sk_buff *skb)
 {
+	char fmt[] = "case2: map-val: %d from:%u\n";
 	int key = 0, *val;
 
 	val = map_lookup_elem(&map_sh, &key);
 	if (val)
-		printt("case2: map-val: %d from:%u\n", *val, skb->cb[0]);
+		trace_printk(fmt, sizeof(fmt), *val, skb->cb[0]);
 
 	skb->cb[0] = ENTRY_1;
 	tail_call(skb, &jmp_tc, ENTRY_0);
@@ -86,11 +66,12 @@
 __section_tail(BAR, ENTRY_0)
 int cls_exit(struct __sk_buff *skb)
 {
+	char fmt[] = "exit: map-val: %d from:%u\n";
 	int key = 0, *val;
 
 	val = map_lookup_elem(&map_sh, &key);
 	if (val)
-		printt("exit: map-val: %d from:%u\n", *val, skb->cb[0]);
+		trace_printk(fmt, sizeof(fmt), *val, skb->cb[0]);
 
 	/* Termination point. */
 	return BPF_H_DEFAULT;
@@ -99,6 +80,7 @@
 __section_cls_entry
 int cls_entry(struct __sk_buff *skb)
 {
+	char fmt[] = "fallthrough\n";
 	int key = 0, *val;
 
 	/* For transferring state, we can use skb->cb[0] ... skb->cb[4]. */
@@ -110,7 +92,7 @@
 		tail_call(skb, &jmp_tc, skb->hash & (MAX_JMP_SIZE - 1));
 	}
 
-	printt("fallthrough\n");
+	trace_printk(fmt, sizeof(fmt));
 	return BPF_H_DEFAULT;
 }
 
diff --git a/examples/cbq.init-v0.7.3 b/examples/cbq.init-v0.7.3
new file mode 100644
index 0000000..1bc0d44
--- /dev/null
+++ b/examples/cbq.init-v0.7.3
@@ -0,0 +1,983 @@
+#!/bin/bash
+#
+#    cbq.init v0.7.3
+#    Copyright (C) 1999  Pavel Golubev <pg@ksi-linux.com>
+#    Copyright (C) 2001-2004  Lubomir Bulej <pallas@kadan.cz>
+#
+#    chkconfig:   2345 11 89
+#    description: sets up CBQ-based traffic control
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+#    To get the latest version, check on Freshmeat for actual location:
+#
+#		http://freshmeat.net/projects/cbq.init
+#
+#
+# VERSION HISTORY
+# ---------------
+# v0.7.3- Deepak Singhal <singhal at users.sourceforge.net>
+#	  - fix timecheck to not ignore regular TIME rules after
+#	    encountering a TIME rule that spans over midnight
+#	- Nathan Shafer <nicodemus at users.sourceforge.net>
+#	  - allow symlinks to class files
+#	- Seth J. Blank <antifreeze at users.sourceforge.net>
+#	  - replace hardcoded ip/tc location with variables
+#	- Mark Davis <mark.davis at gmx.de>
+#	  - allow setting of PRIO_{MARK,RULE,REALM} in class file
+#	- Fernando Sanch <toptnc at users.sourceforge.net>
+#	  - allow underscores in interface names
+# v0.7.2- Paulo Sedrez
+#	  - fix time2abs to allow hours with leading zero in TIME rules
+#	- Svetlin Simeonov <zvero at yahoo.com>
+#	  - fix cbq_device_list to allow VLAN interfaces
+#	- Mark Davis <mark.davis at gmx.de>
+#	  - ignore *~ backup files when looking for classes
+#	- Mike Boyer <boyer at administrative.com>
+#	  - fix to allow arguments to be passed to "restart" command
+# v0.7.1- Lubomir Bulej <pallas at kadan.cz>
+#	  - default value for PERTURB
+#	  - fixed small bug in RULE parser to correctly parse rules with
+#	    identical source and destination fields
+#	  - faster initial scanning of DEVICE fields
+# v0.7	- Lubomir Bulej <pallas at kadan.cz>
+#	  - lots of various cleanups and reorganizations; the parsing is now
+#	    some 40% faster, but the class ID must be in range 0x0002-0xffff
+#	    (again). Because of the number of internal changes and the above
+#	    class ID restriction, I bumped the version to 0.7 to indicate
+#	    something might have got broken :)
+#	  - changed PRIO_{U32,FW,ROUTE} to PRIO_{RULE,MARK,REALM}
+#	    for consistency with filter keywords
+#	  - exposed "compile" command
+#	- Catalin Petrescu <taz at dntis.ro>
+#	  - support for port masks in RULE (u32) filter
+#	- Jordan Vrtanoski <obeliks at mt.net.mk>
+#	  - support for week days in TIME rules
+# v0.6.4- Lubomir Bulej <pallas at kadan.cz>
+#	  - added PRIO_* variables to allow easy control of filter priorities
+#	  - added caching to speed up CBQ start, the cache is invalidated
+#	    whenever any of the configuration files changes
+#	  - updated the readme section + some cosmetic fixes
+# v0.6.3- Lubomir Bulej <pallas at kadan.cz>
+#	  - removed setup of (unnecessary) class 1:1 - all classes
+#	    now use qdisc's default class 1:0 as their parent
+#	  - minor fix in the timecheck branch - classes
+#	    without leaf qdisc were not updated
+#	  - minor fix to avoid timecheck failure when run
+#	    at time with minutes equal to 08 or 09
+#	  - respect CBQ_PATH setting in environment
+#	  - made PRIO=5 default, rendering it optional in configs
+#	  - added support for route filter, see notes about REALM keyword
+#	  - added support for fw filter, see notes about MARK keyword
+#	  - added filter display to "list" and "stats" commands
+#	  - readme section update + various cosmetic fixes
+# v0.6.2- Catalin Petrescu <taz at dntis.ro>
+#	  - added tunnels interface handling
+# v0.6.1- Pavel Golubev <pg at ksi-linux.com>
+#	  - added sch_prio module loading
+#	    (thanks johan at iglo.virtual.or.id for reminding)
+#	  - resolved errors resulting from stricter syntax checking in bash2
+#	- Lubomir Bulej <pallas at kadan.cz>
+#	  - various cosmetic fixes
+# v0.6	- Lubomir Bulej <pallas at kadan.cz>
+#	  - attempt to limit number of spawned processes by utilizing
+#	    more of sed power (use sed instead of grep+cut)
+#	  - simplified TIME parser, using bash builtins
+#	  - added initial support for SFQ as leaf qdisc
+#	  - reworked the documentation part a little
+#	  - incorporated pending patches and ideas submitted by
+#	    following people for versions 0.3 into version 0.6
+#	- Miguel Freitas <miguel at cetuc.puc-rio.br>
+#	  - in case of overlapping TIME parameters, the last match is taken
+#	- Juanjo Ciarlante <jjo at mendoza.gov.ar>
+#	  - chkconfig tags, list + stats startup parameters
+#	  - optional tc & ip command logging (into /var/run/cbq-*)
+#	- Rafal Maszkowski <rzm at icm.edu.pl>
+#	  - PEAK parameter for setting TBF's burst peak rate
+#	  - fix for many config files (use find instead of ls)
+# v0.5.1- Lubomir Bulej <pallas at kadan.cz>
+#	  - fixed little but serious bug in RULE parser
+# v0.5	- Lubomir Bulej <pallas at kadan.cz>
+#	  - added options PARENT, LEAF, ISOLATED and BOUNDED. This allows
+#	    (with some attention to config file ordering) for creating
+#	    hierarchical structures of shapers with classes able (or unable)
+#	    to borrow bandwidth from their parents.
+#	  - class ID check allows hexadecimal numbers
+#	  - rewritten & simplified RULE parser
+#	  - cosmetic changes to improve readability
+#	  - reorganization to avoid duplicate code (timecheck etc.)
+#	  - timecheck doesn't check classes without TIME fields anymore
+# v0.4  - Lubomir Bulej <pallas at kadan.cz>
+#	  - small bugfix in RULE parsing code
+#	  - simplified configuration parsing code
+#	  - several small cosmetic changes
+#	  - TIME parameter can be now specified more than once allowing you to
+#	    differentiate RATE throughout the whole day. Time overlapping is
+#	    not checked, first match is taken. Midnight wrap (eg. 20:00-6:00)
+#	    is allowed and taken care of.
+# v0.3a4- fixed small bug in IF operator. Thanks to
+#	  Rafal Maszkowski <rzm at icm.edu.pl>
+# v0.3a3- fixed grep bug when using more than 10 eth devices. Thanks to David
+#	  Trcka <trcka at poda.cz>.
+# v0.3a2- fixed bug in "if" operator. Thanks kad at dgtu.donetsk.ua.
+# v0.3a - added TIME parameter. Example: TIME=00:00-19:00;64Kbit/6Kbit
+#	  So, between 00:00 and 19:00 the RATE will be 64Kbit.
+#	  Just start "cbq.init timecheck" periodically from cron
+#	  (every 10 minutes for example). DON'T FORGET though, to run
+#	  "cbq.init start" for CBQ to initialize.
+# v0.2  - Some cosmetic changes. Now it is more compatible with old bash
+#	  version. Thanks to Stanislav V. Voronyi <stas at cnti.uanet.kharkov.ua>.
+# v0.1  - First public release
+#
+#
+# README
+# ------
+#
+# First of all - this is just a SIMPLE EXAMPLE of CBQ power.
+# Don't ask me "why" and "how" :)
+#
+# This script is meant to simplify setup and management of relatively simple
+# CBQ-based traffic control on Linux. Access to advanced networking features
+# of Linux kernel is provided by "ip" and "tc" utilities from A. Kuznetsov's
+# iproute2 package, available at ftp://ftp.inr.ac.ru/ip-routing. Because the
+# utilities serve primarily to translate user wishes to RTNETLINK commands,
+# their interface is rather spartan, intolerant and requires quite a lot of
+# typing. And typing is what this script attempts to reduce :)
+#
+# The advanced networking stuff in Linux is pretty flexible and this script
+# aims to bring some of its features to the not-so-hard-core Linux users. Of
+# course, there is a tradeoff between simplicity and flexibility and you may
+# realize that the flexibility suffered too much for your needs -- time to
+# face "ip" and "tc" interface.
+#
+# To speed up the "start" command, simple caching was introduced in version
+# 0.6.4. The caching works so that the sequence of "tc" commands for given
+# configuration is stored in a file (/var/cache/cbq.init by default) which
+# is used next time the "start" command is run to avoid repeated parsing of
+# configuration files. This cache is invalidated whenever any of the CBQ
+# configuration files changes. If you want to run "cbq.init start" without
+# caching, run it as "cbq.init start nocache". If you want to force cache
+# invalidation, run it as "cbq.init start invalidate". Caching is disabled
+# if you have logging enabled (ie. CBQ_DEBUG is not empty).
+#
+# If you only want cqb.init to translate your configuration to "tc" commands,
+# use "compile" command which will output "tc" commands required to build
+# your configuration. Bear in mind that "compile" does not check if the "tc"
+# commands were successful - this is done (in certain places) only when the
+# "start nocache" command is used, which is also useful when creating the
+# configuration to check whether it is completely valid.
+#
+# All CBQ parameters are valid for Ethernet interfaces only, The script was
+# tested on various Linux kernel versions from series 2.1 to 2.4 and several
+# distributions with KSI Linux (Nostromo version) as the premier one.
+#
+#
+# HOW DOES IT WORK?
+# -----------------
+#
+# Every traffic class must be described by a file in the $CBQ_PATH directory
+# (/etc/sysconfig/cbq by default) - one file per class.
+#
+# The config file names must obey mandatory format: cbq-<clsid>.<name> where
+# <clsid> is two-byte hexadecimal number in range <0002-FFFF> (which in fact
+# is a CBQ class ID) and <name> is the name of the class -- anything to help
+# you distinguish the configuration files. For small amount of classes it is
+# often possible (and convenient) to let <clsid> resemble bandwidth of the
+# class.
+#
+# Example of valid config name:
+#	cbq-1280.My_first_shaper
+#
+#
+# The configuration file may contain the following parameters:
+#
+### Device parameters
+#
+# DEVICE=<ifname>,<bandwidth>[,<weight>]	mandatory
+# DEVICE=eth0,10Mbit,1Mbit
+#
+#	<ifname> is the name of the interface you want to control
+#		traffic on, e.g. eth0
+#	<bandwidth> is the physical bandwidth of the device, e.g. for
+#		ethernet 10Mbit or 100Mbit, for arcnet 2Mbit
+#	<weight> is tuning parameter that should be proportional to
+#		<bandwidth>. As a rule of thumb: <weight> = <bandwidth> / 10
+#
+# When you have more classes on one interface, it is enough to specify
+# <bandwidth> [and <weight>] only once, therefore in other files you only
+# need to set DEVICE=<ifname>.
+#
+### Class parameters
+#
+# RATE=<speed>					mandatory
+# RATE=5Mbit
+#
+#	Bandwidth allocated to the class. Traffic going through the class is
+#	shaped to conform to specified rate. You can use Kbit, Mbit or bps,
+#	Kbps and Mbps as suffices. If you don't specify any unit, bits/sec
+#	are used. Also note that "bps" means "bytes per second", not bits.
+#
+# WEIGHT=<speed> 				mandatory
+# WEIGHT=500Kbit
+#
+#	Tuning parameter that should be proportional to RATE. As a rule
+#	of thumb, use WEIGHT ~= RATE / 10.
+#
+# PRIO=<1-8>					optional, default 5
+# PRIO=5
+#
+#	Priority of class traffic. The higher the number, the lesser
+#	the priority. Priority of 5 is just fine.
+#
+# PARENT=<clsid>				optional, default not set
+# PARENT=1280
+#
+#	Specifies ID of the parent class to which you want this class be
+#	attached. You might want to use LEAF=none for the parent class as
+#	mentioned below. By using this parameter and carefully ordering the
+#	configuration files, it is possible to create simple hierarchical
+#	structures of CBQ classes. The ordering is important so that parent
+#	classes are constructed prior to their children.
+#
+# LEAF=none|tbf|sfq				optional, default "tbf"
+#
+#	Tells the script to attach specified leaf queueing discipline to CBQ
+#	class. By default, TBF is used. Note that attaching TBF to CBQ class
+#	shapes the traffic to conform to TBF parameters and prevents the class
+#	from borrowing bandwidth from its parent even if you have BOUNDED set
+#	to "no". To allow the class to borrow bandwith (provided it is not
+#	bounded), you must set LEAF to "none" or "sfq".
+#
+#	If you want to ensure (approximately) fair sharing of bandwidth among
+#	several hosts in the same class, you might want to specify LEAF=sfq to
+#	attach SFQ as leaf queueing discipline to that class.
+#
+# BOUNDED=yes|no				optional, default "yes"
+#
+#	If set to "yes", the class is not allowed to borrow bandwidth from
+#	its parent class in overlimit situation. If set to "no", the class
+#	will be allowed to borrow bandwidth from its parent.
+#
+# Note:	Don't forget to set LEAF to "none" or "sfq", otherwise the class will
+#	have TBF attached to itself and will not be able to borrow unused
+#	bandwith from its parent.
+#
+# ISOLATED=yes|no				optional, default "no"
+#
+#	If set to "yes", the class will not lend unused bandwidth to
+#	its children.
+#
+### TBF qdisc parameters
+#
+# BUFFER=<bytes>[/<bytes>]			optional, default "10Kb/8"
+#
+#	This parameter controls the depth of the token bucket. In other
+#	words it represents the maximal burst size the class can send.
+#	The optional part of parameter is used to determine the length
+#	of intervals in packet sizes, for which the transmission times
+#	are kept.
+#
+# LIMIT=<bytes>					optional, default "15Kb"
+#
+#	This parameter determines the maximal length of backlog. If
+#	the queue contains more data than specified by LIMIT, the
+#	newly arriving packets are dropped. The length of backlog
+#	determines queue latency in case of congestion.
+#
+# PEAK=<speed>					optional, default not set
+#
+#	Maximal peak rate for short-term burst traffic. This allows you
+#	to control the absolute peak rate the class can send at, because
+#	single TBF that allows 256Kbit/s would of course allow rate of
+#	512Kbit for half a second or 1Mbit for a quarter of second.
+#
+# MTU=<bytes>  					optional, default "1500"
+#
+#	Maximum number of bytes that can be sent at once over the
+#	physical medium. This parameter is required when you specify
+#	PEAK parameter. It defaults to MTU of ethernet - for other
+#	media types you might want to change it.
+#
+# Note: Setting TBF as leaf qdisc will effectively prevent the class from
+#	borrowing bandwidth from the ancestor class, because even if the
+#	class allows more traffic to pass through, it is then shaped to
+#	conform to TBF.
+#
+### SFQ qdisc parameters
+#
+# The SFQ queueing discipline is a cheap way for sharing class bandwidth
+# among several hosts. As it is stochastic, the fairness is approximate but
+# it will do the job in most cases. If you want real fairness, you should
+# probably use WRR (weighted round robin) or WFQ queueing disciplines. Note
+# that SFQ does not do any traffic shaping - the shaping is done by the CBQ
+# class the SFQ is attached to.
+#
+# QUANTUM=<bytes>				optional, default not set
+#
+#	This parameter should not be set lower than link MTU, for ethernet
+#	it is 1500b, or (with MAC header) 1514b which is the value used
+#	in Alexey Kuznetsov's examples.
+#
+# PERTURB=<seconds>				optional, default "10"
+#
+#	Period of hash function perturbation. If unset, hash reconfiguration
+#	will never take place which is what you probably don't want. The
+#	default value of 10 seconds is probably a good one.
+#
+### Filter parameters
+#
+# RULE=[[saddr[/prefix]][:port[/mask]],][daddr[/prefix]][:port[/mask]]
+#
+#	These parameters make up "u32" filter rules that select traffic for
+#	each of the classes. You can use multiple RULE fields per config.
+#
+#	The optional port mask should only be used by advanced users who
+#	understand how the u32 filter works.
+#
+# Some examples:
+#
+#	RULE=10.1.1.0/24:80
+#		selects traffic going to port 80 in network 10.1.1.0
+#
+#	RULE=10.2.2.5
+#		selects traffic going to any port on single host 10.2.2.5
+#
+#	RULE=10.2.2.5:20/0xfffe
+#		selects traffic going to ports 20 and 21 on host 10.2.2.5
+#
+#	RULE=:25,10.2.2.128/26:5000
+#		selects traffic going from anywhere on port 50 to
+#		port 5000 in network 10.2.2.128
+#
+#	RULE=10.5.5.5:80,
+#		selects traffic going from port 80 of single host 10.5.5.5
+#
+#
+#
+# REALM=[srealm,][drealm]
+#
+#	These parameters make up "route" filter rules that classify traffic
+#	according to packet source/destination realms. For information about
+#	realms, see Alexey Kuznetsov's IP Command Reference. This script
+#	does not define any realms, it justs builds "tc filter" commands
+#	for you if you need to classify traffic this way.
+#
+#	Realm is either a decimal number or a string referencing entry in
+#	/etc/iproute2/rt_realms (usually).
+#
+# Some examples:
+#
+#	REALM=russia,internet
+#		selects traffic going from realm "russia" to realm "internet"
+#
+#	REALM=freenet,
+#		selects traffic going from realm "freenet"
+#
+#	REALM=10
+#		selects traffic going to realm 10
+#
+#
+#
+# MARK=<mark>
+#
+#	These parameters make up "fw" filter rules that select traffic for
+#	each of the classes accoring to firewall "mark". Mark is a decimal
+#	number packets are tagged with if firewall rules say so. You can
+#	use multiple MARK fields per config.
+#
+#
+# Note: Rules for different filter types can be combined. Attention must be
+#	paid to the priority of filter rules, which can be set below using
+#	PRIO_{RULE,MARK,REALM} variables.
+#
+### Time ranging parameters
+#
+# TIME=[<dow>,<dow>, ...,<dow>/]<from>-<till>;<rate>/<weight>[/<peak>]
+# TIME=0,1,2,5/18:00-06:00;256Kbit/25Kbit
+# TIME=60123/18:00-06:00;256Kbit/25Kbit
+# TIME=18:00-06:00;256Kbit/25Kbit
+#
+#	This parameter allows you to differentiate the class bandwidth
+#	throughout the day. You can specify multiple TIME parameters, if
+#	the times overlap, last match is taken. The fields <rate>, <weight>
+#	and <peak> correspond to parameters RATE, WEIGHT and PEAK (which
+#	is optional and applies to TBF leaf qdisc only).
+#
+#	You can also specify days of week when the TIME rule applies. <dow>
+#	is numeric, 0 corresponds to sunday, 1 corresponds to monday, etc.
+#
+###
+#
+# Sample configuration file: cbq-1280.My_first_shaper
+#
+# --------------------------------------------------------------------------
+# DEVICE=eth0,10Mbit,1Mbit
+# RATE=128Kbit
+# WEIGHT=10Kbit
+# PRIO=5
+# RULE=192.128.1.0/24
+# --------------------------------------------------------------------------
+#
+# The configuration says that we will control traffic on 10Mbit ethernet
+# device eth0 and the traffic going to network 192.168.1.0 will be
+# processed with priority 5 and shaped to rate of 128Kbit.
+#
+# Note that you can control outgoing traffic only. If you want to control
+# traffic in both directions, you must set up CBQ for both interfaces.
+#
+# Consider the following example:
+#
+#                    +---------+      192.168.1.1
+# BACKBONE -----eth0-|  linux  |-eth1------*-[client]
+#                    +---------+
+#
+# Imagine you want to shape traffic from backbone to the client to 28Kbit
+# and traffic in the opposite direction to 128Kbit. You need to setup CBQ
+# on both eth0 and eth1 interfaces, thus you need two config files:
+#
+# cbq-028.backbone-client
+# --------------------------------------------------------------------------
+# DEVICE=eth1,10Mbit,1Mbit
+# RATE=28Kbit
+# WEIGHT=2Kbit
+# PRIO=5
+# RULE=192.168.1.1
+# --------------------------------------------------------------------------
+#
+# cbq-128.client-backbone
+# --------------------------------------------------------------------------
+# DEVICE=eth0,10Mbit,1Mbit
+# RATE=128Kbit
+# WEIGHT=10Kbit
+# PRIO=5
+# RULE=192.168.1.1,
+# --------------------------------------------------------------------------
+#
+# Pay attention to comma "," in the RULE field - it denotes source address!
+#
+# Enjoy.
+#
+#############################################################################
+
+export LC_ALL=C
+
+### Command locations
+TC=/sbin/tc
+IP=/sbin/ip
+MP=/sbin/modprobe
+
+### Default filter priorities (must be different)
+PRIO_RULE_DEFAULT=${PRIO_RULE:-100}
+PRIO_MARK_DEFAULT=${PRIO_MARK:-200}
+PRIO_REALM_DEFAULT=${PRIO_REALM:-300}
+
+### Default CBQ_PATH & CBQ_CACHE settings
+CBQ_PATH=${CBQ_PATH:-/etc/sysconfig/cbq}
+CBQ_CACHE=${CBQ_CACHE:-/var/cache/cbq.init}
+
+### Uncomment to enable logfile for debugging
+#CBQ_DEBUG="/var/run/cbq-$1"
+
+### Modules to probe for. Uncomment the last CBQ_PROBE
+### line if you have QoS support compiled into kernel
+CBQ_PROBE="sch_cbq sch_tbf sch_sfq sch_prio"
+CBQ_PROBE="$CBQ_PROBE cls_fw cls_u32 cls_route"
+#CBQ_PROBE=""
+
+### Keywords required for qdisc & class configuration
+CBQ_WORDS="DEVICE|RATE|WEIGHT|PRIO|PARENT|LEAF|BOUNDED|ISOLATED"
+CBQ_WORDS="$CBQ_WORDS|PRIO_MARK|PRIO_RULE|PRIO_REALM|BUFFER"
+CBQ_WORDS="$CBQ_WORDS|LIMIT|PEAK|MTU|QUANTUM|PERTURB"
+
+### Source AVPKT if it exists
+[ -r /etc/sysconfig/cbq/avpkt ] && . /etc/sysconfig/cbq/avpkt
+AVPKT=${AVPKT:-3000}
+
+
+#############################################################################
+############################# SUPPORT FUNCTIONS #############################
+#############################################################################
+
+### Get list of network devices
+cbq_device_list () {
+	ip link show| sed -n "/^[0-9]/ \
+		{ s/^[0-9]\+: \([a-z0-9._]\+\)[:@].*/\1/; p; }"
+} # cbq_device_list
+
+
+### Remove root class from device $1
+cbq_device_off () {
+	tc qdisc del dev $1 root 2> /dev/null
+} # cbq_device_off
+
+
+### Remove CBQ from all devices
+cbq_off () {
+	for dev in `cbq_device_list`; do
+		cbq_device_off $dev
+	done
+} # cbq_off
+
+
+### Prefixed message
+cbq_message () {
+	echo -e "**CBQ: $@"
+} # cbq_message
+
+### Failure message
+cbq_failure () {
+	cbq_message "$@"
+	exit 1
+} # cbq_failure
+
+### Failure w/ cbq-off
+cbq_fail_off () {
+	cbq_message "$@"
+	cbq_off
+	exit 1
+} # cbq_fail_off
+
+
+### Convert time to absolute value
+cbq_time2abs () {
+	local min=${1##*:}; min=${min##0}
+	local hrs=${1%%:*}; hrs=${hrs##0}
+	echo $[hrs*60 + min]
+} # cbq_time2abs
+
+
+### Display CBQ setup
+cbq_show () {
+	for dev in `cbq_device_list`; do
+		[ `tc qdisc show dev $dev| wc -l` -eq 0 ] && continue
+		echo -e "### $dev: queueing disciplines\n"
+		tc $1 qdisc show dev $dev; echo
+
+		[ `tc class show dev $dev| wc -l` -eq 0 ] && continue
+		echo -e "### $dev: traffic classes\n"
+		tc $1 class show dev $dev; echo
+
+		[ `tc filter show dev $dev| wc -l` -eq 0 ] && continue
+		echo -e "### $dev: filtering rules\n"
+		tc $1 filter show dev $dev; echo
+	done
+} # cbq_show
+
+
+### Check configuration and load DEVICES, DEVFIELDS and CLASSLIST from $1
+cbq_init () {
+	### Get a list of configured classes
+	CLASSLIST=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \
+		-not -name '*~' -printf "%f\n"| sort`
+	[ -z "$CLASSLIST" ] &&
+		cbq_failure "no configuration files found in $1!"
+
+	### Gather all DEVICE fields from $1/cbq-*
+	DEVFIELDS=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \
+		  -not -name '*~' | xargs sed -n 's/#.*//; \
+		  s/[[:space:]]//g; /^DEVICE=[^,]*,[^,]*\(,[^,]*\)\?/ \
+		  { s/.*=//; p; }'| sort -u`
+	[ -z "$DEVFIELDS" ] &&
+		cbq_failure "no DEVICE field found in $1/cbq-*!"
+
+	### Check for different DEVICE fields for the same device
+	DEVICES=`echo "$DEVFIELDS"| sed 's/,.*//'| sort -u`
+	[ `echo "$DEVICES"| wc -l` -ne `echo "$DEVFIELDS"| wc -l` ] &&
+		cbq_failure "different DEVICE fields for single device!\n$DEVFIELDS"
+} # cbq_init
+
+
+### Load class configuration from $1/$2
+cbq_load_class () {
+	CLASS=`echo $2| sed 's/^cbq-0*//; s/^\([0-9a-fA-F]\+\).*/\1/'`
+	CFILE=`sed -n 's/#.*//; s/[[:space:]]//g; /^[[:alnum:]_]\+=[[:alnum:].,:;/*@-_]\+$/ p' $1/$2`
+
+	### Check class number
+	IDVAL=`/usr/bin/printf "%d" 0x$CLASS 2> /dev/null`
+	[ $? -ne 0 -o $IDVAL -lt 2 -o $IDVAL -gt 65535 ] &&
+		cbq_fail_off "class ID of $2 must be in range <0002-FFFF>!"
+
+	### Set defaults & load class
+	RATE=""; WEIGHT=""; PARENT=""; PRIO=5
+	LEAF=tbf; BOUNDED=yes; ISOLATED=no
+	BUFFER=10Kb/8; LIMIT=15Kb; MTU=1500
+	PEAK=""; PERTURB=10; QUANTUM=""
+
+	PRIO_RULE=$PRIO_RULE_DEFAULT
+	PRIO_MARK=$PRIO_MARK_DEFAULT
+	PRIO_REALM=$PRIO_REALM_DEFAULT
+
+	eval `echo "$CFILE"| grep -E "^($CBQ_WORDS)="`
+
+	### Require RATE/WEIGHT
+	[ -z "$RATE" -o -z "$WEIGHT" ] &&
+		cbq_fail_off "missing RATE or WEIGHT in $2!"
+
+	### Class device
+	DEVICE=${DEVICE%%,*}
+	[ -z "$DEVICE" ] && cbq_fail_off "missing DEVICE field in $2!"
+
+	BANDWIDTH=`echo "$DEVFIELDS"| sed -n "/^$DEVICE,/ \
+		  { s/[^,]*,\([^,]*\).*/\1/; p; q; }"`
+
+	### Convert to "tc" options
+	PEAK=${PEAK:+peakrate $PEAK}
+	PERTURB=${PERTURB:+perturb $PERTURB}
+	QUANTUM=${QUANTUM:+quantum $QUANTUM}
+
+	[ "$BOUNDED" = "no" ] && BOUNDED="" || BOUNDED="bounded"
+	[ "$ISOLATED" = "yes" ] && ISOLATED="isolated" || ISOLATED=""
+} # cbq_load_class
+
+
+#############################################################################
+#################################### INIT ###################################
+#############################################################################
+
+### Check for presence of ip-route2 in usual place
+[ -x $TC -a -x $IP ] ||
+	cbq_failure "ip-route2 utilities not installed or executable!"
+
+
+### ip/tc wrappers
+if [ "$1" = "compile" ]; then
+	### no module probing
+	CBQ_PROBE=""
+
+	ip () {
+		$IP "$@"
+	} # ip
+
+	### echo-only version of "tc" command
+	tc () {
+		echo "$TC $@"
+	} # tc
+
+elif [ -n "$CBQ_DEBUG" ]; then
+	echo -e "# `date`" > $CBQ_DEBUG
+
+	### Logging version of "ip" command
+	ip () {
+		echo -e "\n# ip $@" >> $CBQ_DEBUG
+		$IP "$@" 2>&1 | tee -a $CBQ_DEBUG
+	} # ip
+
+	### Logging version of "tc" command
+	tc () {
+		echo -e "\n# tc $@" >> $CBQ_DEBUG
+		$TC "$@" 2>&1 | tee -a $CBQ_DEBUG
+	} # tc
+else
+	### Default wrappers
+	
+	ip () {
+		$IP "$@"
+	} # ip
+	
+	tc () {
+		$TC "$@"
+	} # tc
+fi # ip/tc wrappers
+
+
+case "$1" in
+
+#############################################################################
+############################### START/COMPILE ###############################
+#############################################################################
+
+start|compile)
+
+### Probe QoS modules (start only)
+for module in $CBQ_PROBE; do
+	$MP $module || cbq_failure "failed to load module $module"
+done
+
+### If we are in compile/nocache/logging mode, don't bother with cache
+if [ "$1" != "compile" -a "$2" != "nocache" -a -z "$CBQ_DEBUG" ]; then
+	VALID=1
+
+	### validate the cache
+	[ "$2" = "invalidate" -o ! -f $CBQ_CACHE ] && VALID=0
+	if [ $VALID -eq 1 ]; then
+		[ `find $CBQ_PATH -maxdepth 1 -newer $CBQ_CACHE| \
+		  wc -l` -gt 0 ] && VALID=0
+	fi
+
+	### compile the config if the cache is invalid
+	if [ $VALID -ne 1 ]; then
+		$0 compile > $CBQ_CACHE ||
+			cbq_fail_off "failed to compile CBQ configuration!"
+	fi
+
+	### run the cached commands
+	exec /bin/sh $CBQ_CACHE 2> /dev/null
+fi
+
+### Load DEVICES, DEVFIELDS and CLASSLIST
+cbq_init $CBQ_PATH
+
+
+### Setup root qdisc on all configured devices
+for dev in $DEVICES; do
+	### Retrieve device bandwidth and, optionally, weight
+	DEVTEMP=`echo "$DEVFIELDS"| sed -n "/^$dev,/ { s/$dev,//; p; q; }"`
+	DEVBWDT=${DEVTEMP%%,*};	DEVWGHT=${DEVTEMP##*,}
+	[ "$DEVBWDT" = "$DEVWGHT" ] && DEVWGHT=""
+
+	### Device bandwidth is required
+	if [ -z "$DEVBWDT" ]; then
+		cbq_message "could not determine bandwidth for device $dev!"
+		cbq_failure "please set up the DEVICE fields properly!"
+	fi
+
+	### Check if the device is there
+	ip link show $dev &> /dev/null ||
+		cbq_fail_off "device $dev not found!"
+
+	### Remove old root qdisc from device
+	cbq_device_off $dev
+
+
+	### Setup root qdisc + class for device
+	tc qdisc add dev $dev root handle 1 cbq \
+	bandwidth $DEVBWDT avpkt $AVPKT cell 8
+
+	### Set weight of the root class if set
+	[ -n "$DEVWGHT" ] &&
+		tc class change dev $dev root cbq weight $DEVWGHT allot 1514
+
+	[ "$1" = "compile" ] && echo
+done # dev
+
+
+### Setup traffic classes
+for classfile in $CLASSLIST; do
+	cbq_load_class $CBQ_PATH $classfile
+
+	### Create the class
+	tc class add dev $DEVICE parent 1:$PARENT classid 1:$CLASS cbq \
+	bandwidth $BANDWIDTH rate $RATE weight $WEIGHT prio $PRIO \
+	allot 1514 cell 8 maxburst 20 avpkt $AVPKT $BOUNDED $ISOLATED ||
+		cbq_fail_off "failed to add class $CLASS with parent $PARENT on $DEVICE!"
+
+	### Create leaf qdisc if set
+	if [ "$LEAF" = "tbf" ]; then
+		tc qdisc add dev $DEVICE parent 1:$CLASS handle $CLASS tbf \
+		rate $RATE buffer $BUFFER limit $LIMIT mtu $MTU $PEAK
+	elif [ "$LEAF" = "sfq" ]; then
+		tc qdisc add dev $DEVICE parent 1:$CLASS handle $CLASS sfq \
+		$PERTURB $QUANTUM
+	fi
+
+
+	### Create fw filter for MARK fields
+	for mark in `echo "$CFILE"| sed -n '/^MARK/ { s/.*=//; p; }'`; do
+		### Attach fw filter to root class
+		tc filter add dev $DEVICE parent 1:0 protocol ip \
+		prio $PRIO_MARK handle $mark fw classid 1:$CLASS
+	done ### mark
+
+	### Create route filter for REALM fields
+	for realm in `echo "$CFILE"| sed -n '/^REALM/ { s/.*=//; p; }'`; do
+		### Split realm into source & destination realms
+		SREALM=${realm%%,*}; DREALM=${realm##*,}
+		[ "$SREALM" = "$DREALM" ] && SREALM=""
+
+		### Convert asterisks to empty strings
+		SREALM=${SREALM#\*}; DREALM=${DREALM#\*}
+
+		### Attach route filter to the root class
+		tc filter add dev $DEVICE parent 1:0 protocol ip \
+		prio $PRIO_REALM route ${SREALM:+from $SREALM} \
+		${DREALM:+to $DREALM} classid 1:$CLASS
+	done ### realm
+
+	### Create u32 filter for RULE fields
+	for rule in `echo "$CFILE"| sed -n '/^RULE/ { s/.*=//; p; }'`; do
+		### Split rule into source & destination
+		SRC=${rule%%,*}; DST=${rule##*,}
+		[ "$SRC" = "$rule" ] && SRC=""
+
+
+		### Split destination into address, port & mask fields
+		DADDR=${DST%%:*}; DTEMP=${DST##*:}
+		[ "$DADDR" = "$DST" ] && DTEMP=""
+
+		DPORT=${DTEMP%%/*}; DMASK=${DTEMP##*/}
+		[ "$DPORT" = "$DTEMP" ] && DMASK="0xffff"
+
+
+		### Split up source (if specified)
+		SADDR=""; SPORT=""
+		if [ -n "$SRC" ]; then
+			SADDR=${SRC%%:*}; STEMP=${SRC##*:}
+			[ "$SADDR" = "$SRC" ] && STEMP=""
+
+			SPORT=${STEMP%%/*}; SMASK=${STEMP##*/}
+			[ "$SPORT" = "$STEMP" ] && SMASK="0xffff"
+		fi
+
+
+		### Convert asterisks to empty strings
+		SADDR=${SADDR#\*}; DADDR=${DADDR#\*}
+
+		### Compose u32 filter rules
+		u32_s="${SPORT:+match ip sport $SPORT $SMASK}"
+		u32_s="${SADDR:+match ip src $SADDR} $u32_s"
+		u32_d="${DPORT:+match ip dport $DPORT $DMASK}"
+		u32_d="${DADDR:+match ip dst $DADDR} $u32_d"
+
+		### Uncomment the following if you want to see parsed rules
+		#echo "$rule: $u32_s $u32_d"
+
+		### Attach u32 filter to the appropriate class
+		tc filter add dev $DEVICE parent 1:0 protocol ip \
+		prio $PRIO_RULE u32 $u32_s $u32_d classid 1:$CLASS
+	done ### rule
+
+	[ "$1" = "compile" ] && echo
+done ### classfile
+;;
+
+
+#############################################################################
+################################# TIME CHECK ################################
+#############################################################################
+
+timecheck)
+
+### Get time + weekday
+TIME_TMP=`date +%w/%k:%M`
+TIME_DOW=${TIME_TMP%%/*}
+TIME_NOW=${TIME_TMP##*/}
+
+### Load DEVICES, DEVFIELDS and CLASSLIST
+cbq_init $CBQ_PATH
+
+### Run through all classes
+for classfile in $CLASSLIST; do
+	### Gather all TIME rules from class config
+	TIMESET=`sed -n 's/#.*//; s/[[:space:]]//g; /^TIME/ { s/.*=//; p; }' \
+		$CBQ_PATH/$classfile`
+	[ -z "$TIMESET" ] && continue
+
+	MATCH=0; CHANGE=0
+	for timerule in $TIMESET; do
+		TIME_ABS=`cbq_time2abs $TIME_NOW`
+		
+		### Split TIME rule to pieces
+		TIMESPEC=${timerule%%;*}; PARAMS=${timerule##*;}
+		WEEKDAYS=${TIMESPEC%%/*}; INTERVAL=${TIMESPEC##*/}
+		BEG_TIME=${INTERVAL%%-*}; END_TIME=${INTERVAL##*-}
+
+		### Check the day-of-week (if present)
+		[ "$WEEKDAYS" != "$INTERVAL" -a \
+		  -n "${WEEKDAYS##*$TIME_DOW*}" ] && continue
+
+		### Compute interval boundaries
+		BEG_ABS=`cbq_time2abs $BEG_TIME`
+		END_ABS=`cbq_time2abs $END_TIME`
+
+		### Midnight wrap fixup
+		if [ $BEG_ABS -gt $END_ABS ]; then
+			[ $TIME_ABS -le $END_ABS ] &&
+				TIME_ABS=$[TIME_ABS + 24*60]
+
+			END_ABS=$[END_ABS + 24*60]
+		fi
+
+		### If the time matches, remember params and set MATCH flag
+		if [ $TIME_ABS -ge $BEG_ABS -a $TIME_ABS -lt $END_ABS ]; then
+			TMP_RATE=${PARAMS%%/*}; PARAMS=${PARAMS#*/}
+			TMP_WGHT=${PARAMS%%/*}; TMP_PEAK=${PARAMS##*/}
+
+			[ "$TMP_PEAK" = "$TMP_WGHT" ] && TMP_PEAK=""
+			TMP_PEAK=${TMP_PEAK:+peakrate $TMP_PEAK}
+
+			MATCH=1
+		fi
+	done ### timerule
+
+
+	cbq_load_class $CBQ_PATH $classfile
+
+	### Get current RATE of CBQ class
+	RATE_NOW=`tc class show dev $DEVICE| sed -n \
+		 "/cbq 1:$CLASS / { s/.*rate //; s/ .*//; p; q; }"`
+	[ -z "$RATE_NOW" ] && continue
+
+	### Time interval matched
+	if [ $MATCH -ne 0 ]; then
+
+		### Check if there is any change in class RATE
+		if [ "$RATE_NOW" != "$TMP_RATE" ]; then
+			NEW_RATE="$TMP_RATE"
+			NEW_WGHT="$TMP_WGHT"
+			NEW_PEAK="$TMP_PEAK"
+			CHANGE=1
+		fi
+
+	### Match not found, reset to default RATE if necessary
+	elif [ "$RATE_NOW" != "$RATE" ]; then
+		NEW_WGHT="$WEIGHT"
+		NEW_RATE="$RATE"
+		NEW_PEAK="$PEAK"
+		CHANGE=1
+	fi
+
+	### If there are no changes, go for next class
+	[ $CHANGE -eq 0 ] && continue
+
+	### Replace CBQ class
+	tc class replace dev $DEVICE classid 1:$CLASS cbq \
+	bandwidth $BANDWIDTH rate $NEW_RATE weight $NEW_WGHT prio $PRIO \
+	allot 1514 cell 8 maxburst 20 avpkt $AVPKT $BOUNDED $ISOLATED
+
+	### Replace leaf qdisc (if any)
+	if [ "$LEAF" = "tbf" ]; then
+		tc qdisc replace dev $DEVICE handle $CLASS tbf \
+		rate $NEW_RATE buffer $BUFFER limit $LIMIT mtu $MTU $NEW_PEAK
+	fi
+
+	cbq_message "$TIME_NOW: class $CLASS on $DEVICE changed rate ($RATE_NOW -> $NEW_RATE)"
+done ### class file
+;;
+
+
+#############################################################################
+################################## THE REST #################################
+#############################################################################
+
+stop)
+	cbq_off
+	;;
+
+list)
+	cbq_show
+	;;
+
+stats)
+	cbq_show -s
+	;;
+
+restart)
+	shift
+	$0 stop
+	$0 start "$@"
+	;;
+
+*)
+	echo "Usage: `basename $0` {start|compile|stop|restart|timecheck|list|stats}"
+esac
diff --git a/examples/cbqinit.eth1 b/examples/cbqinit.eth1
new file mode 100644
index 0000000..226ec1c
--- /dev/null
+++ b/examples/cbqinit.eth1
@@ -0,0 +1,76 @@
+#! /bin/sh
+
+TC=/home/root/tc
+IP=/home/root/ip
+DEVICE=eth1
+BANDWIDTH="bandwidth 10Mbit"
+
+# Attach CBQ on $DEVICE. It will have handle 1:.
+#   $BANDWIDTH is real $DEVICE bandwidth (10Mbit).
+#   avpkt is average packet size.
+#   mpu is minimal packet size.
+
+$TC qdisc add dev $DEVICE  root  handle 1:  cbq \
+$BANDWIDTH avpkt 1000 mpu 64
+
+# Create root class with classid 1:1. This step is not necessary.
+#   bandwidth is the same as on CBQ itself.
+#   rate == all the bandwidth
+#   allot is MTU + MAC header
+#   maxburst measure allowed class burstiness (please,read S.Floyd and VJ papers)
+#   est 1sec 8sec means, that kernel will evaluate average rate
+#                 on this class with period 1sec and time constant 8sec.
+#                 This rate is viewed with "tc -s class ls dev $DEVICE"
+
+$TC class add dev $DEVICE parent 1:0 classid :1 est 1sec 8sec cbq \
+$BANDWIDTH rate 10Mbit allot 1514 maxburst 50 avpkt 1000
+
+# Bulk.
+#    New parameters are: 
+#    weight, which is set to be proportional to
+#            "rate". It is not necessary, weight=1 will work as well.
+#    defmap and split say that best effort ttraffic, not classfied
+#            by another means will fall to this class.
+
+$TC class add dev $DEVICE parent 1:1 classid :2 est 1sec 8sec cbq \
+$BANDWIDTH rate 4Mbit allot 1514 weight 500Kbit \
+prio 6 maxburst 50 avpkt 1000 split 1:0 defmap ff3d
+
+# OPTIONAL.
+# Attach "sfq" qdisc to this class, quantum is MTU, perturb
+# gives period of hash function perturbation in seconds.
+#
+$TC qdisc add dev $DEVICE parent 1:2 sfq quantum 1514b perturb 15
+
+# Interactive-burst class
+
+$TC class add dev $DEVICE parent 1:1 classid :3 est 2sec 16sec cbq \
+$BANDWIDTH rate 1Mbit allot 1514 weight 100Kbit \
+prio 2 maxburst 100 avpkt 1000 split 1:0 defmap c0
+
+$TC qdisc add dev $DEVICE parent 1:3 sfq quantum 1514b perturb 15
+
+# Background.
+
+$TC class add dev $DEVICE parent 1:1 classid :4 est 1sec 8sec cbq \
+  $BANDWIDTH rate 100Kbit allot 1514 weight 10Mbit \
+  prio 7 maxburst 10 avpkt 1000 split 1:0 defmap 2
+
+$TC qdisc add dev $DEVICE parent 1:4 sfq quantum 1514b perturb 15
+
+# Realtime class for RSVP
+
+$TC class add dev $DEVICE parent 1:1 classid 1:7FFE cbq \
+rate 5Mbit $BANDWIDTH allot 1514b avpkt 1000 \
+maxburst 20
+
+# Reclassified realtime traffic
+#
+# New element: split is not 1:0, but 1:7FFE. It means,
+#     that only real-time packets, which violated policing filters
+#     or exceeded reshaping buffers will fall to it.
+
+$TC class add dev $DEVICE parent 1:7FFE classid 1:7FFF  est 4sec 32sec cbq \
+rate 1Mbit $BANDWIDTH allot 1514b avpkt 1000 weight 10Kbit \
+prio 6 maxburst 10 split 1:7FFE defmap ffff
+
diff --git a/examples/dhcp-client-script b/examples/dhcp-client-script
new file mode 100644
index 0000000..f39bc10
--- /dev/null
+++ b/examples/dhcp-client-script
@@ -0,0 +1,446 @@
+#!/bin/bash
+#
+# dhclient-script for Linux.
+#
+#		This program is free software; you can redistribute it and/or
+#		modify it under the terms of the GNU General Public License
+#		as published by the Free Software Foundation; either version
+#		2 of the License, or (at your option) any later version.
+#
+# Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
+#
+# Probably, I did not understand, what this funny feature as "alias"
+# means exactly. For now I suppose, that it is a static address, which
+# we should install and preserve.
+#
+
+exec >> /var/log/DHS.log 2>&1
+
+echo dhc-script $* reason=$reason
+set | grep "^\(old_\|new_\|check_\)"
+
+LOG () {
+    echo LOG $* ;
+}
+
+# convert 8bit mask to length
+# arg: $1 = mask
+#
+Mask8ToLen() {
+	local l=0;
+
+	while [ $l -le 7 ]; do
+		if [ $[ ( 1 << $l ) + $1 ] -eq 256 ]; then
+			return	$[ 8 - $l ]
+		fi
+		l=$[ $l + 1 ]
+	done
+	return 0;
+}
+
+# convert inet dotted quad mask to length
+# arg: $1 = dotquad mask
+#
+MaskToLen() {
+ local masklen=0
+ local mask8=$1
+
+ case $1 in
+ 0.0.0.0)
+	return 0;
+	;;
+ 255.*.0.0)
+	masklen=8
+	mask8=${mask8#255.}
+	mask8=${mask8%.0.0}
+	;;
+ 255.255.*.0)
+	masklen=16
+	mask8=${mask8#255.255.}
+	mask8=${mask8%.0}
+	;;
+ 255.255.255.*)
+	masklen=24
+	mask8=${mask8#255.255.255.}
+	;;
+ *)
+	return 255
+	;;
+ esac
+ Mask8ToLen $mask8
+ return $[ $? + $masklen ]
+}
+
+# calculate ABC "natural" mask
+# arg: $1 = dotquad address
+#
+ABCMask () {
+ local class;
+
+ class=${1%%.*}
+
+ if [ "$1" = "255.255.255.255" ]; then
+    echo $1
+ elif [ "$1" = "0.0.0.0" ]; then
+    echo $1
+ elif [ $class -ge 224 ]; then
+    echo 240.0.0.0
+ elif [ $class -ge 192 ]; then
+    echo 255.255.255.0
+ elif [ $class -ge 128 ]; then
+    echo 255.255.0.0
+ else
+    echo 255.0.0.0
+ fi
+}
+
+# calculate ABC "natural" mask length
+# arg: $1 = dotquad address
+#
+ABCMaskLen () {
+ local class;
+
+ class=${1%%.*}
+
+ if [ "$1" = "255.255.255.255" ]; then
+    return 32
+ elif [ "$1" = "0.0.0.0" ]; then
+    return 0
+ elif [ $class -ge 224 ]; then
+    return 4;
+ elif [ $class -ge 192 ]; then
+    return 24;
+ elif [ $class -ge 128 ]; then
+    return 16;
+ else
+    return 8;
+ fi
+}
+
+# Delete IP address
+# args: $1 = interface
+#       $2 = address
+#       $3 = mask
+#       $4 = broadcast
+#       $5 = label
+#
+DelINETAddr () {
+  local masklen=32
+  local addrid=$1
+
+  LOG DelINETAddr $*
+
+  if [ "$5" ]; then
+    addrid=$addrid:$5
+  fi
+  LOG ifconfig $addrid down
+  ifconfig $addrid down
+}
+
+# Add IP address
+# args: $1 = interface
+#       $2 = address
+#       $3 = mask
+#       $4 = broadcast
+#       $5 = label
+#
+AddINETAddr () {
+  local mask_arg
+  local brd_arg
+  local addrid=$1
+
+  LOG AddINETAddr $*
+
+  if [ "$5" ]; then
+    addrid=$addrid:$5
+  fi
+  if [ "$3" ]; then
+    mask_arg="netmask $3"
+  fi
+  if [ "$4" ]; then
+    brd_arg="broadcast $4"
+  fi
+
+  LOG ifconfig $addrid $2 $mask_arg $brd_arg up
+  ifconfig $addrid $2 $mask_arg $brd_arg up
+}
+
+# Add default routes
+# args: $1 = routers list
+#
+AddDefaultRoutes() {
+    local router
+
+    if [ "$1" ]; then
+      LOG AddDefaultRoutes $*
+      for router in $1; do
+        LOG route add default gw $router
+        route add default gw $router
+      done ;
+    fi
+}
+
+# Delete default routes
+# args: $1 = routers list
+#
+DelDefaultRoutes() {
+    local router
+
+    if [ "$1" ]; then
+      LOG DelDefaultRoutes $*
+
+      for router in $1; do
+        LOG route del default gw $router
+        route del default gw $router
+      done
+    fi
+}
+
+# ping a host
+# args: $1 = dotquad address of the host
+#
+PingNode() {
+    LOG PingNode $*
+    if ping -q -c 1 -w 2 $1 ; then
+	return 0;
+    fi
+    return 1;
+}
+
+# Check (and add route, if alive) default routers
+# args: $1 = routers list
+# returns: 0 if at least one router is alive.
+#
+CheckRouterList() {
+    local router
+    local succeed=1
+
+    LOG CheckRouterList $*
+
+    for router in $1; do
+      if PingNode $router ; then
+	succeed=0
+        route add default gw $router
+      fi
+    done
+    return $succeed
+}
+
+# Delete/create static routes.
+# args: $1 = operation (del/add)
+#       $2 = routes list in format "dst1 nexthop1 dst2 ..."
+#
+# BEWARE: this feature of DHCP is obsolete, because does not
+#         support subnetting.
+#
+X-StaticRouteList() {
+    local op=$1
+    local lst="$2"
+    local masklen
+
+    LOG X-StaticRouteList $*
+
+    if [ "$lst" ]; then
+      set $lst
+      while [ $# -gt 1 ]; do
+	route $op -net $1 netmask `ABCMask "$1"` gw $2
+	shift; shift;
+      done
+   fi
+}
+
+# Create static routes.
+# arg: $1 = routes list in format "dst1 nexthop1 dst2 ..."
+#
+AddStaticRouteList() {
+    LOG AddStaticRouteList $*
+    X-StaticRouteList add "$1"
+}
+
+# Delete static routes.
+# arg: $1 = routes list in format "dst1 nexthop1 dst2 ..."
+#
+DelStaticRouteList() {
+    LOG DelStaticRouteList $*
+    X-StaticRouteList del "$1"
+}
+
+# Broadcast unsolicited ARP to update neighbours' caches.
+# args: $1 = interface
+#       $2 = address
+#
+UnsolicitedARP() {
+    if [ -f /sbin/arping ]; then
+	/sbin/arping -A -c 1 -I "$1" "$2" &
+	(sleep 2 ; /sbin/arping -U -c 1 -I "$1" "$2" ) &
+    fi
+}
+
+# Duplicate address detection.
+# args: $1 = interface
+#       $2 = test address
+# returns: 0, if DAD succeeded.
+DAD() {
+  if [ -f /sbin/arping ]; then
+	/sbin/arping -c 2 -w 3 -D -I "$1" "$2"
+	return $?
+  fi
+  return 0
+}
+
+
+# Setup resolver.
+# args: NO
+#       domain and nameserver list are passed in global variables.
+#
+# NOTE: we try to be careful and not to break user supplied resolv.conf.
+#       The script mangles it, only if it has dhcp magic signature.
+#
+UpdateDNS() {
+    local nameserver
+    local idstring="#### Generated by DHCPCD"
+
+    LOG UpdateDNS $*
+
+    if [ "$new_domain_name" = "" -a "$new_domain_name_servers" = "" ]; then
+	return 0;
+    fi
+
+    echo $idstring > /etc/resolv.conf.dhcp
+    if [ "$new_domain_name" ]; then
+	echo search $new_domain_name >> /etc/resolv.conf.dhcp
+    fi
+    echo options ndots:1 >> /etc/resolv.conf.dhcp
+
+    if [ "$new_domain_name_servers" ]; then
+	for nameserver in $new_domain_name_servers; do
+	    echo nameserver $nameserver >> /etc/resolv.conf.dhcp
+	done
+    else
+	echo nameserver 127.0.0.1 >> /etc/resolv.conf.dhcp
+    fi
+
+    if [ -f /etc/resolv.conf ]; then
+	if [ "`head -1 /etc/resolv.conf`" != "$idstring" ]; then
+	    return 0
+	fi
+	if [ "$old_domain_name" = "$new_domain_name" -a
+	     "$new_domain_name_servers" = "$old_domain_name_servers" ]; then
+	     return 0
+	fi
+    fi
+    mv /etc/resolv.conf.dhcp /etc/resolv.conf
+}
+
+case $reason in
+NBI)
+  exit 1
+  ;;
+
+MEDIUM)
+  exit 0
+  ;;
+
+PREINIT)
+  ifconfig $interface:dhcp down
+  ifconfig $interface:dhcp1 down
+  if [ -d /proc/sys/net/ipv4/conf/$interface ]; then
+    ifconfig $interface:dhcp 10.10.10.10 netmask 255.255.255.255
+    ifconfig $interface:dhcp down
+    if [ -d /proc/sys/net/ipv4/conf/$interface ]; then
+	LOG The interface $interface already configured.
+    fi
+  fi
+  ifconfig $interface:dhcp up
+  exit 0
+  ;;
+
+ARPSEND)
+  exit 0
+  ;;
+
+ARPCHECK)
+  if DAD "$interface" "$check_ip_address" ; then
+    exit 0
+  fi
+  exit 1
+  ;;
+
+BOUND|RENEW|REBIND|REBOOT)
+  if [ "$old_ip_address" -a "$alias_ip_address" -a \
+	"$alias_ip_address" != "$old_ip_address" ]; then
+    DelINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+  fi
+  if [ "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
+    DelINETAddr "$interface" "$old_ip_address" "$old_subnet_mask" "$old_broadcast_address" dhcp
+    DelDefaultRoutes "$old_routers"
+    DelStaticRouteList "$old_static_routes"
+  fi
+  if [ "$old_ip_address" = "" -o "$old_ip_address" != "$new_ip_address" -o \
+       "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
+    AddINETAddr "$interface" "$new_ip_address" "$new_subnet_mask" "$new_broadcast_address" dhcp
+    AddStaticRouteList "$new_static_routes"
+    AddDefaultRoutes "$new_routers"
+    UnsolicitedARP "$interface" "$new_ip_address"
+  fi
+  if [ "$new_ip_address" != "$alias_ip_address" -a "$alias_ip_address" ]; then
+    AddINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+  fi
+  UpdateDNS
+  exit 0
+  ;;
+
+EXPIRE|FAIL)
+  if [ "$alias_ip_address" ]; then
+    DelINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+  fi
+  if [ "$old_ip_address" ]; then
+    DelINETAddr "$interface" "$old_ip_address" "$old_subnet_mask" "$old_broadcast_address" dhcp
+    DelDefaultRoutes "$old_routers"
+    DelStaticRouteList "$old_static_routes"
+  fi
+  if [ "$alias_ip_address" ]; then
+    AddINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+  fi
+  exit 0
+  ;;
+
+TIMEOUT)
+  if [ "$alias_ip_address" ]; then
+    DelINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+  fi
+# Seems, <null address> means, that no more old leases found.
+# Or does it mean bug in dhcpcd? 8) Fail for now.
+  if [ "$new_ip_address" = "<null address>" ]; then
+    if [ "$old_ip_address" ]; then
+	DelINETAddr "$interface" "$old_ip_address" "$old_subnet_mask" "$old_broadcast_address" dhcp
+    fi
+    if [ "$alias_ip_address" ]; then
+        AddINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+    fi
+    exit 1
+  fi
+  if DAD "$interface" "$new_ip_address" ; then
+    AddINETAddr "$interface" "$new_ip_address" "$new_subnet_mask" "$new_broadcast_address" dhcp
+    UnsolicitedARP "$interface" "$new_ip_address"
+    if [ "$alias_ip_address" -a "$alias_ip_address" != "$new_ip_address" ]; then
+      AddINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+      UnsolicitedARP "$interface" "$alias_ip_address"
+    fi
+    if CheckRouterList "$new_routers" ; then
+	AddStaticRouteList "$new_static_routes"
+	UpdateDNS
+	exit 0
+    fi
+  fi
+  DelINETAddr "$interface" "$new_ip_address" "$new_subnet_mask" "$new_broadcast_address" dhcp
+  DelDefaultRoutes "$old_routers"
+  DelStaticRouteList "$old_static_routes"
+  if [ "$alias_ip_address" ]; then
+    AddINETAddr "$interface" "$alias_ip_address" "$alias_subnet_mask" "$alias_broadcast_address" dhcp1
+  fi
+  exit 1
+  ;;
+esac
+
+exit 0
diff --git a/examples/diffserv/Edge1 b/examples/diffserv/Edge1
new file mode 100644
index 0000000..4ddffdd
--- /dev/null
+++ b/examples/diffserv/Edge1
@@ -0,0 +1,68 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities
+# This script just tags on the ingress interfac using Ipchains
+# the result is used for fast classification and re-marking
+# on the egress interface
+#
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
+INDEV=eth2
+EGDEV="dev eth1"
+#
+# tag all incoming packets from host 10.2.0.24 to value 1
+# tag all incoming packets from host 10.2.0.3 to value 2
+# tag the rest of incoming packets from subnet 10.2.0.0/24 to value 3
+#These values are used in the egress
+#
+############################################################ 
+$IPCHAINS -A input -s 10.2.0.4/24 -m 3
+$IPCHAINS -A input -i $INDEV -s 10.2.0.24 -m 1
+$IPCHAINS -A input -i $INDEV -s 10.2.0.3 -m 2
+
+######################## Egress side ########################
+
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64 set_tc_index
+#
+# values of the DSCP to change depending on the class
+#
+#becomes EF
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0xb8
+#becomes AF11
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x28
+#becomes AF21
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x48
+#
+#
+# The class mapping
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 1 fw classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 2 fw classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 3 fw classid 1:3
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent 1:0
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
diff --git a/examples/diffserv/Edge2 b/examples/diffserv/Edge2
new file mode 100644
index 0000000..2f78da2
--- /dev/null
+++ b/examples/diffserv/Edge2
@@ -0,0 +1,87 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities
+# This script tags the fwmark on the ingress interface using IPchains
+# the result is used first for policing on the Ingress interface then
+# for fast classification and re-marking
+# on the egress interface
+#
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
+INDEV=eth2
+EGDEV="dev eth1"
+#
+# tag all incoming packets from host 10.2.0.24 to value 1
+# tag all incoming packets from host 10.2.0.3 to value 2
+# tag the rest of incoming packets from subnet 10.2.0.0/24 to value 3
+#These values are used in the egress
+############################################################ 
+$IPCHAINS -A input -s 10.2.0.0/24 -m 3
+$IPCHAINS -A input -i $INDEV -s 10.2.0.24 -m 1
+$IPCHAINS -A input -i $INDEV -s 10.2.0.3 -m 2
+############################################################ 
+#
+# install the ingress qdisc on the ingress interface
+############################################################ 
+$TC qdisc add dev $INDEV handle ffff: ingress
+############################################################ 
+
+#
+# attach a fw classifier to the ingress which polices anything marked
+# by ipchains to tag value 3 (The rest of the subnet packets -- not
+# tag 1 or 2) to not go beyond 1.5Mbps
+# Allow up to at least 60 packets to burst (assuming maximum packet 
+# size of # 1.5 KB) in the long run and upto about 6 packets in the
+# shot run
+
+############################################################ 
+$TC filter add dev $INDEV parent ffff: protocol ip prio 50 handle 3 fw \
+police rate 1500kbit burst 90k mtu 9k drop flowid :1
+############################################################ 
+
+######################## Egress side ########################
+
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
+#
+# values of the DSCP to change depending on the class
+#
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0xb8
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x28
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x48
+#
+#
+# The class mapping
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 1 fw classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 2 fw classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 3 fw classid 1:3
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
+#
+#deleting the ingress qdisc
+#$TC qdisc del $DEV ingress
diff --git a/examples/diffserv/Edge31-ca-u32 b/examples/diffserv/Edge31-ca-u32
new file mode 100644
index 0000000..25e6c0b
--- /dev/null
+++ b/examples/diffserv/Edge31-ca-u32
@@ -0,0 +1,170 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities using u32 classifier
+# This script tags tcindex based on metering on the ingress 
+# interface the result is used for fast classification and re-marking
+# on the egress interface
+# This is an example of a color aware mode marker with PIR configured
+# based on draft-wahjak-mcm-00.txt (section 3.1)
+#
+# The colors are defined using the Diffserv Fields
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/usr/src/iproute2-current
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+INDEV=eth0
+EGDEV="dev eth1"
+CIR1=1500kbit
+CIR2=1000kbit
+
+#The CBS is about 60 MTU sized packets
+CBS1=90k
+CBS2=90k
+
+############################################################ 
+#
+# install the ingress qdisc on the ingress interface
+$TC qdisc add dev $INDEV handle ffff: ingress
+############################################################ 
+#
+# Create u32 filters 
+$TC filter add dev $INDEV parent ffff: protocol ip prio 4 handle 1: u32 \
+divisor 1
+############################################################ 
+
+# The meters: Note that we have shared meters in this case as identified
+# by the index parameter
+meter1=" police index 1 rate $CIR1 burst $CBS1 "
+meter2=" police index 2 rate $CIR2 burst $CBS1 "
+meter3=" police index 3 rate $CIR2 burst $CBS2 "
+meter4=" police index 4 rate $CIR1 burst $CBS2 "
+meter5=" police index 5 rate $CIR1 burst $CBS2 "
+
+# All packets are marked with a tcindex value which is used on the egress
+# tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
+
+# *********************** AF41 *************************** 
+#AF41 (DSCP 0x22) is passed on with a tcindex value 1
+#if it doesnt exceed its CIR/CBS 
+#policer 1  is used.
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 4 u32 \
+match ip tos 0x88 0xfc \
+$meter1 \
+continue flowid :1
+#
+# if it exceeds the above but not the extra rate/burst below, it gets a 
+# tcindex value  of 2
+# policer 2 is used
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
+match ip tos 0x88 0xfc \
+$meter2 \
+continue flowid :2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3 (policer 3)
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
+match ip tos 0x88 0xfc \
+$meter3 \
+drop flowid :3
+#
+
+# *********************** AF42 *************************** 
+#AF42 (DSCP 0x24) from is passed on with a tcindex value 2
+#if it doesnt exceed its CIR/CBS 
+#policer 2 is used. Note that this is shared with the AF41
+#
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
+match ip tos 0x90 0xfc \
+$meter2 \
+continue flowid :2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3 (policer 3)
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
+match ip tos 0x90 0xfc \
+$meter3 \
+drop flowid :3
+#
+# *********************** AF43 *************************** 
+#
+#AF43 (DSCP 0x26) from is passed on with a tcindex value 3
+#if it doesnt exceed its CIR/CBS
+#policer 3 is used. Note that this is shared with the AF41 and AF42
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
+match ip tos 0x98 0xfc \
+$meter3 \
+drop flowid :3
+#
+# *********************** BE *************************** 
+#
+# Anything else (not from the AF4*) gets discarded if it 
+# exceeds 1Mbps and by default goes to BE if it doesnt
+# Note that the BE class is also used by the AF4* in the worst
+# case
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 7 u32 \
+match ip src 0/0\
+$meter4 \
+drop flowid :4
+
+######################## Egress side ########################
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
+#
+# values of the DSCP to change depending on the class
+#note that the ECN bits are masked out
+#
+#AF41 (0x88 is 0x22 shifted to the right by two bits)
+#
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0x88
+#AF42
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x90
+#AF43
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x98
+#BE
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x0
+#
+#
+# The class mapping
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 1 tcindex classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 2 tcindex  classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 3 tcindex  classid 1:3
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 4 tcindex  classid 1:4
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
+#
+#deleting the ingress qdisc
+#$TC qdisc del $INDEV ingress
diff --git a/examples/diffserv/Edge31-cb-chains b/examples/diffserv/Edge31-cb-chains
new file mode 100644
index 0000000..d7faae9
--- /dev/null
+++ b/examples/diffserv/Edge31-cb-chains
@@ -0,0 +1,132 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities
+# This script fwmark tags(IPchains) based on metering on the ingress 
+# interface the result is used for fast classification and re-marking
+# on the egress interface
+# This is an example of a color blind mode marker with no PIR configured
+# based on draft-wahjak-mcm-00.txt (section 3.1)
+#
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
+INDEV=eth2
+EGDEV="dev eth1"
+CIR1=1500kbit
+CIR2=1000kbit
+
+#The CBS is about 60 MTU sized packets
+CBS1=90k
+CBS2=90k
+
+meter1="police rate $CIR1 burst $CBS1 "
+meter2="police rate $CIR1 burst $CBS2 "
+meter3="police rate $CIR2 burst $CBS1 "
+meter4="police rate $CIR2 burst $CBS2 "
+meter5="police rate $CIR2 burst $CBS2 "
+#
+# tag the rest of incoming packets from subnet 10.2.0.0/24 to fw value 1
+# tag all incoming packets from any other subnet to fw tag 2
+############################################################ 
+$IPCHAINS -A input -i $INDEV -s 0/0 -m 2
+$IPCHAINS -A input -i $INDEV -s 10.2.0.0/24 -m 1
+#
+############################################################ 
+# install the ingress qdisc on the ingress interface
+$TC qdisc add dev $INDEV handle ffff: ingress
+#
+############################################################ 
+
+# All packets are marked with a tcindex value which is used on the egress
+# tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
+#
+############################################################ 
+# 
+# anything with fw tag of 1 is passed on with a tcindex value 1
+#if it doesnt exceed its allocated rate (CIR/CBS)
+# 
+$TC filter add dev $INDEV parent ffff: protocol ip prio 4 handle 1 fw \
+$meter1 \
+continue flowid 4:1
+#
+# if it exceeds the above but not the extra rate/burst below, it gets a 
+#tcindex value  of 2
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 5 handle 1 fw \
+$meter2 \
+continue flowid 4:2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 handle 1 fw \
+$meter3 \
+drop flowid 4:3
+#
+# Anything else (not from the subnet 10.2.0.24/24) gets discarded if it 
+# exceeds 1Mbps and by default goes to BE if it doesnt
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 handle 2 fw \
+$meter5 \
+drop flowid 4:4
+
+
+######################## Egress side ########################
+
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
+#
+# values of the DSCP to change depending on the class
+#note that the ECN bits are masked out
+#
+#AF41 (0x88 is 0x22 shifted to the right by two bits)
+#
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0x88
+#AF42
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x90
+#AF43
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x98
+#BE
+$TC class change $EGDEV classid 1:4 dsmark mask 0x3 \
+       value 0x0
+#
+#
+# The class mapping (using tcindex; could easily have
+# replaced it with the fw classifier instead)
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 1 tcindex classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 2 tcindex  classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 3 tcindex  classid 1:3
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 4 tcindex  classid 1:4
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
+#
+#deleting the ingress qdisc
+#$TC qdisc del $INDEV ingress
diff --git a/examples/diffserv/Edge32-ca-u32 b/examples/diffserv/Edge32-ca-u32
new file mode 100644
index 0000000..edf21e4
--- /dev/null
+++ b/examples/diffserv/Edge32-ca-u32
@@ -0,0 +1,198 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities using u32 classifier
+# This script tags tcindex based on metering on the ingress 
+# interface the result is used for fast classification and re-marking
+# on the egress interface
+# This is an example of a color aware mode marker with PIR configured
+# based on draft-wahjak-mcm-00.txt (section 3.2)
+#
+# The colors are defined using the Diffserv Fields
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
+INDEV=eth2
+EGDEV="dev eth1"
+CIR1=1000kbit
+CIR2=500kbit
+# the PIR is what is in excess of the CIR
+PIR1=1000kbit
+PIR2=500kbit
+
+#The CBS is about 60 MTU sized packets
+CBS1=90k
+CBS2=90k
+#the EBS is about 20 max sized packets
+EBS1=30k
+EBS2=30k
+
+# The meters: Note that we have shared meters in this case as identified
+# by the index parameter
+meter1=" police index 1 rate $CIR1 burst $CBS1 "
+meter1a=" police index 2 rate $PIR1 burst $EBS1 "
+meter2=" police index 3 rate $CIR2 burst $CBS1 "
+meter2a=" police index 4 rate $PIR2 burst $EBS1 "
+meter3=" police index 5 rate $CIR2 burst $CBS2 "
+meter3a=" police index 6 rate $PIR2 burst $EBS2 "
+meter4=" police index 7 rate $CIR1 burst $CBS2 "
+
+############################################################ 
+#
+# install the ingress qdisc on the ingress interface
+$TC qdisc add dev $INDEV handle ffff: ingress
+############################################################ 
+#
+# All packets are marked with a tcindex value which is used on the egress
+# tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
+#
+# *********************** AF41 *************************** 
+#AF41 (DSCP 0x22) from is passed on with a tcindex value 1
+#if it doesnt exceed its CIR/CBS + PIR/EBS
+#policer 1  is used.
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 1 u32 \
+match ip tos 0x88 0xfc \
+$meter1 \
+continue flowid :1
+$TC filter add dev $INDEV parent ffff: protocol ip prio 2 u32 \
+match ip tos 0x88 0xfc \
+$meter1a \
+continue flowid :1
+#
+# if it exceeds the above but not the extra rate/burst below, it gets a 
+# tcindex value  of 2
+# policer 2 is used
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 3 u32 \
+match ip tos 0x88 0xfc \
+$meter2 \
+continue flowid :2
+$TC filter add dev $INDEV parent ffff: protocol ip prio 4 u32 \
+match ip tos 0x88 0xfc \
+$meter2a \
+continue flowid :2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3 (policer 3)
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
+match ip tos 0x88 0xfc \
+$meter3 \
+continue flowid :3
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
+match ip tos 0x88 0xfc \
+$meter3a \
+drop flowid :3
+#
+# *********************** AF42 *************************** 
+#AF42 (DSCP 0x24) from is passed on with a tcindex value 2
+#if it doesnt exceed its CIR/CBS + PIR/EBS
+#policer 2 is used. Note that this is shared with the AF41
+#
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 8 u32 \
+match ip tos 0x90 0xfc \
+$meter2 \
+continue flowid :2
+$TC filter add dev $INDEV parent ffff: protocol ip prio 9 u32 \
+match ip tos 0x90 0xfc \
+$meter2a \
+continue flowid :2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3 (policer 3)
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 10 u32 \
+match ip tos 0x90 0xfc \
+$meter3 \
+continue flowid :3
+$TC filter add dev $INDEV parent ffff: protocol ip prio 11 u32 \
+match ip tos 0x90 0xfc \
+$meter3a \
+drop flowid :3
+
+#
+# *********************** AF43 *************************** 
+#
+#AF43 (DSCP 0x26) from is passed on with a tcindex value 3
+#if it doesnt exceed its CIR/CBS + PIR/EBS
+#policer 3 is used. Note that this is shared with the AF41 and AF42
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 13 u32 \
+match ip tos 0x98 0xfc \
+$meter3 \
+continue flowid :3
+$TC filter add dev $INDEV parent ffff: protocol ip prio 14 u32 \
+match ip tos 0x98 0xfc \
+$meter3a \
+drop flowid :3
+#
+## *********************** BE *************************** 
+##
+## Anything else (not from the AF4*) gets discarded if it 
+## exceeds 1Mbps and by default goes to BE if it doesnt
+## Note that the BE class is also used by the AF4* in the worst
+## case
+##
+$TC filter add dev $INDEV parent ffff: protocol ip prio 16 u32 \
+match ip src 0/0\
+$meter4 \
+drop flowid :4
+
+######################## Egress side ########################
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
+#
+# values of the DSCP to change depending on the class
+#note that the ECN bits are masked out
+#
+#AF41 (0x88 is 0x22 shifted to the right by two bits)
+#
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0x88
+#AF42
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x90
+#AF43
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x98
+#BE
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x0
+#
+#
+# The class mapping
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 1 tcindex classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 2 tcindex  classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 3 tcindex  classid 1:3
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 4 tcindex  classid 1:4
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
+#
+#deleting the ingress qdisc
+#$TC qdisc del $INDEV ingress
diff --git a/examples/diffserv/Edge32-cb-chains b/examples/diffserv/Edge32-cb-chains
new file mode 100644
index 0000000..804fad1
--- /dev/null
+++ b/examples/diffserv/Edge32-cb-chains
@@ -0,0 +1,144 @@
+#! /bin/sh -x
+#
+# sample script on using the ingress capabilities
+# This script fwmark tags(IPchains) based on metering on the ingress 
+# interface the result is used for fast classification and re-marking
+# on the egress interface
+# This is an example of a color blind mode marker with no PIR configured
+# based on draft-wahjak-mcm-00.txt (section 3.1)
+#
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains
+INDEV=eth2
+EGDEV="dev eth1"
+CIR1=1500kbit
+CIR2=500kbit
+
+#The CBS is about 60 MTU sized packets
+CBS1=90k
+CBS2=90k
+
+meter1="police rate $CIR1 burst $CBS1 "
+meter1a="police rate $CIR2 burst $CBS1 "
+meter2="police rate $CIR1 burst $CBS2 "
+meter2a="police rate $CIR2 burst $CBS2 "
+meter3="police rate $CIR2 burst $CBS1 "
+meter3a="police rate $CIR2 burst $CBS1 "
+meter4="police rate $CIR2 burst $CBS2 "
+meter5="police rate $CIR1 burst $CBS2 "
+#
+# tag the rest of incoming packets from subnet 10.2.0.0/24 to fw value 1
+# tag all incoming packets from any other subnet to fw tag 2
+############################################################ 
+$IPCHAINS -A input -i $INDEV -s 0/0 -m 2
+$IPCHAINS -A input -i $INDEV -s 10.2.0.0/24 -m 1
+#
+############################################################ 
+# install the ingress qdisc on the ingress interface
+$TC qdisc add dev $INDEV handle ffff: ingress
+#
+############################################################ 
+
+# All packets are marked with a tcindex value which is used on the egress
+# tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
+#
+############################################################ 
+# 
+# anything with fw tag of 1 is passed on with a tcindex value 1
+#if it doesnt exceed its allocated rate (CIR/CBS)
+# 
+$TC filter add dev $INDEV parent ffff: protocol ip prio 1 handle 1 fw \
+$meter1 \
+continue flowid 4:1
+$TC filter add dev $INDEV parent ffff: protocol ip prio 2 handle 1 fw \
+$meter1a \
+continue flowid 4:1
+#
+# if it exceeds the above but not the extra rate/burst below, it gets a 
+#tcindex value  of 2
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 3 handle 1 fw \
+$meter2 \
+continue flowid 4:2
+$TC filter add dev $INDEV parent ffff: protocol ip prio 4 handle 1 fw \
+$meter2a \
+continue flowid 4:2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 5 handle 1 fw \
+$meter3 \
+continue flowid 4:3
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 handle 1 fw \
+$meter3a \
+drop flowid 4:3
+#
+# Anything else (not from the subnet 10.2.0.24/24) gets discarded if it 
+# exceeds 1Mbps and by default goes to BE if it doesnt
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 7 handle 2 fw \
+$meter5 \
+drop flowid 4:4
+
+
+######################## Egress side ########################
+
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
+#
+# values of the DSCP to change depending on the class
+#note that the ECN bits are masked out
+#
+#AF41 (0x88 is 0x22 shifted to the right by two bits)
+#
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0x88
+#AF42
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x90
+#AF43
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x98
+#BE
+$TC class change $EGDEV classid 1:4 dsmark mask 0x3 \
+       value 0x0
+#
+#
+# The class mapping (using tcindex; could easily have
+# replaced it with the fw classifier instead)
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 1 tcindex classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 2 tcindex  classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 3 tcindex  classid 1:3
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 4 tcindex  classid 1:4
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
+#
+#deleting the ingress qdisc
+#$TC qdisc del $INDEV ingress
diff --git a/examples/diffserv/Edge32-cb-u32 b/examples/diffserv/Edge32-cb-u32
new file mode 100644
index 0000000..cc2ebb4
--- /dev/null
+++ b/examples/diffserv/Edge32-cb-u32
@@ -0,0 +1,145 @@
+#! /bin/sh 
+#
+# sample script on using the ingress capabilities using u32 classifier
+# This script tags tcindex based on metering on the ingress 
+# interface the result is used for fast classification and re-marking
+# on the egress interface
+# This is an example of a color blind mode marker with PIR configured
+# based on draft-wahjak-mcm-00.txt (section 3.2)
+#
+#path to various utilities;
+#change to reflect yours.
+#
+IPROUTE=/root/DS-6-beta/iproute2-990530-dsing
+TC=$IPROUTE/tc/tc
+IP=$IPROUTE/ip/ip
+INDEV=eth2
+EGDEV="dev eth1"
+CIR1=1000kbit
+CIR2=1000kbit
+# The PIR is the excess (in addition to the CIR i.e if always
+# going to the PIR --> average rate is CIR+PIR)
+PIR1=1000kbit
+PIR2=500kbit
+
+#The CBS is about 60 MTU sized packets
+CBS1=90k
+CBS2=90k
+#the EBS is about 10 max sized packets
+EBS1=15k
+EBS2=15k
+# The meters
+meter1=" police rate $CIR1 burst $CBS1 "
+meter1a=" police rate $PIR1 burst $EBS1 "
+meter2=" police rate $CIR2 burst $CBS1 "
+meter2a="police rate $PIR2 burst $CBS1 "
+meter3=" police rate $CIR2 burst $CBS2 "
+meter3a=" police rate $PIR2 burst $EBS2 "
+meter4=" police rate $CIR1 burst $CBS2 "
+meter5=" police rate $CIR1 burst $CBS2 "
+
+
+# install the ingress qdisc on the ingress interface
+############################################################ 
+$TC qdisc add dev $INDEV handle ffff: ingress
+############################################################ 
+#
+############################################################ 
+
+# All packets are marked with a tcindex value which is used on the egress
+# NOTE: tcindex 1 maps to AF41, 2->AF42, 3->AF43, 4->BE
+# 
+#anything from subnet 10.2.0.2/24 is passed on with a tcindex value 1
+#if it doesnt exceed its CIR/CBS + PIR/EBS
+# 
+$TC filter add dev $INDEV parent ffff: protocol ip prio 1 u32 \
+match ip src 10.2.0.0/24 $meter1 \
+continue flowid :1
+$TC filter add dev $INDEV parent ffff: protocol ip prio 2 u32 \
+match ip src 10.2.0.0/24 $meter1a \
+continue flowid :1
+
+#
+# if it exceeds the above but not the extra rate/burst below, it gets a 
+#tcindex value  of 2
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 3 u32 \
+match ip src 10.2.0.0/24 $meter2 \
+continue flowid :2
+$TC filter add dev $INDEV parent ffff: protocol ip prio 4 u32 \
+match ip src 10.2.0.0/24 $meter2a \
+continue flowid :2
+#
+# if it exceeds the above but not the rule below, it gets a tcindex value
+# of 3
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 5 u32 \
+match ip src 10.2.0.0/24 $meter3 \
+continue flowid :3
+$TC filter add dev $INDEV parent ffff: protocol ip prio 6 u32 \
+match ip src 10.2.0.0/24 $meter3a \
+drop flowid :3
+#
+#
+# Anything else (not from the subnet 10.2.0.24/24) gets discarded if it 
+# exceeds 1Mbps and by default goes to BE if it doesnt
+#
+$TC filter add dev $INDEV parent ffff: protocol ip prio 7 u32 \
+match ip src 0/0 $meter5 \
+drop flowid :4
+
+
+######################## Egress side ########################
+
+
+# attach a dsmarker
+#
+$TC qdisc add $EGDEV handle 1:0 root dsmark indices 64
+#
+# values of the DSCP to change depending on the class
+#note that the ECN bits are masked out
+#
+#AF41 (0x88 is 0x22 shifted to the right by two bits)
+#
+$TC class change $EGDEV classid 1:1 dsmark mask 0x3 \
+       value 0x88
+#AF42
+$TC class change $EGDEV classid 1:2 dsmark mask 0x3 \
+       value 0x90
+#AF43
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x98
+#BE
+$TC class change $EGDEV classid 1:3 dsmark mask 0x3 \
+       value 0x0
+#
+#
+# The class mapping
+#
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 1 tcindex classid 1:1
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 2 tcindex  classid 1:2
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 3 tcindex  classid 1:3
+$TC filter add $EGDEV parent 1:0 protocol ip prio 1 \
+          handle 4 tcindex  classid 1:4
+#
+
+#
+echo "---- qdisc parameters Ingress  ----------"
+$TC qdisc ls dev $INDEV
+echo "---- Class parameters Ingress  ----------"
+$TC class ls dev $INDEV
+echo "---- filter parameters Ingress ----------"
+$TC filter ls dev $INDEV parent ffff:
+
+echo "---- qdisc parameters Egress  ----------"
+$TC qdisc ls $EGDEV
+echo "---- Class parameters Egress  ----------"
+$TC class ls $EGDEV
+echo "---- filter parameters Egress ----------"
+$TC filter ls $EGDEV parent 1:0
+#
+#deleting the ingress qdisc
+#$TC qdisc del $INDEV ingress
diff --git a/examples/diffserv/README b/examples/diffserv/README
new file mode 100644
index 0000000..ec91d63
--- /dev/null
+++ b/examples/diffserv/README
@@ -0,0 +1,98 @@
+
+Note all these are mere examples which can be customized to your needs
+
+AFCBQ
+-----
+AF PHB built using CBQ, DSMARK,GRED (default in GRIO mode) ,RED for BE 
+and the tcindex classifier with some algorithmic mapping
+
+EFCBQ
+-----
+EF PHB built using CBQ (for rate control and prioritization), 
+DSMARK( to remark DSCPs), tcindex  classifier and  RED for the BE
+traffic.
+
+EFPRIO
+------
+EF PHB using the PRIO scheduler, Token Bucket to rate control EF,
+tcindex classifier, DSMARK to remark, and RED for the BE traffic
+
+EDGE scripts
+==============
+
+CB-3(1|2)-(u32/chains)
+======================
+
+
+The major differences are that the classifier is u32 on -u32 extension
+and IPchains on the chains extension. CB stands for color Blind
+and 31 is for the mode where only a CIR and CBS are defined whereas
+32 stands for a mode where a CIR/CBS + PIR/EBS are defined.
+
+Color Blind (CB)
+==========-----=
+We look at one special subnet that we are interested in for simplicty
+reasons to demonstrate the capability. We send the packets from that
+subnet to AF4*, BE or end up dropping depending on the metering results. 
+
+
+The algorithm overview is as follows:
+
+*classify:
+
+**case: subnet X
+----------------
+  if !exceed meter1 tag as AF41
+	else
+	    if !exceed meter2  tag as AF42
+	        else
+		  if !exceed meter 3 tag as AF43
+		      else 
+			 drop 
+
+default case: Any other subnet
+-------------------------------
+  if !exceed meter 5 tag as AF43
+      else
+	 drop 
+
+
+One Egress side change the DSCPs of the packets to reflect AF4* and BE
+based on the tags from the ingress.
+
+-------------------------------------------------------------
+
+Color Aware
+===========
+
+Define some meters with + policing and give them IDs eg
+
+meter1=police index 1 rate $CIR1 burst $CBS1  
+meter2=police index 2 rate $CIR2 burst $CBS2   etc 
+
+General overview:
+classify based on the DSCPs and use the policer ids to decide tagging
+
+
+*classify on ingress:
+
+switch (dscp) {
+    case AF41: /* tos&0xfc == 0x88 */
+	if (!exceed meter1) break;
+    case AF42: /* tos&0xfc == 0x90 */
+	if (!exceed meter2) {
+	    tag as AF42;
+	    break;
+	}
+    case AF43: /* tos&0xfc == 0x98 */
+	if (!exceed meter3) {
+	    tag as AF43;
+	    break;
+	} else
+	  drop;
+    default:
+	if (!exceed meter4) tag as BE;
+	else drop;
+}
+
+On the Egress side mark the proper AF tags
diff --git a/examples/diffserv/afcbq b/examples/diffserv/afcbq
new file mode 100644
index 0000000..10d6d93
--- /dev/null
+++ b/examples/diffserv/afcbq
@@ -0,0 +1,105 @@
+#!/usr/bin/perl
+#
+#
+# AF using CBQ for a single interface eth0 
+# 4 AF classes using GRED and one BE using RED
+# Things you might want to change:
+#	- the device bandwidth (set at 10Mbits)
+#	- the bandwidth allocated for each AF class and the BE class	
+#	- the drop probability associated with each AF virtual queue
+#
+# AF DSCP values used (based on AF draft 04)
+# -----------------------------------------
+# AF DSCP values
+# AF1 1. 0x0a 2. 0x0c 3. 0x0e
+# AF2 1. 0x12 2. 0x14 3. 0x16
+# AF3 1. 0x1a 2. 0x1c 3. 0x1e
+# AF4 1. 0x22 2. 0x24 3. 0x26
+
+#
+# 
+# A simple DSCP-class relationship formula used to generate
+# values in the for loop of this script; $drop stands for the
+# DP
+#	$dscp = ($class*8+$drop*2)
+#
+#  if you use GRIO buffer sharing, then GRED priority is set as follows:
+#  $gprio=$drop+1; 
+#
+
+$TC = "/usr/src/iproute2-current/tc/tc";
+$DEV = "dev lo";
+$DEV = "dev eth1";
+$DEV = "dev eth0";
+# the BE-class number
+$beclass = "5";  
+
+#GRIO buffer sharing on or off?
+$GRIO = "";
+$GRIO = "grio";
+# The bandwidth of your device
+$linerate="10Mbit";
+# The BE and AF rates
+%rate_table=();
+$berate="1500Kbit";
+$rate_table{"AF1rate"}="1500Kbit";
+$rate_table{"AF2rate"}="1500Kbit";
+$rate_table{"AF3rate"}="1500Kbit";
+$rate_table{"AF4rate"}="1500Kbit";
+#
+#
+#
+print "\n# --- General setup  ---\n";
+print "$TC qdisc add $DEV handle 1:0 root dsmark indices 64 set_tc_index\n";
+print "$TC filter add $DEV parent 1:0 protocol ip prio 1 tcindex mask 0xfc " .
+   "shift 2 pass_on\n";
+   #"shift 2\n";
+print "$TC qdisc add $DEV parent 1:0 handle 2:0 cbq bandwidth $linerate ".
+  "cell 8 avpkt 1000 mpu 64\n";
+print "$TC filter add $DEV parent 2:0 protocol ip prio 1 tcindex ".
+  "mask 0xf0 shift 4 pass_on\n";
+for $class (1..4) {
+    print "\n# --- AF Class $class specific setup---\n";
+    $AFrate=sprintf("AF%drate",$class);
+    print "$TC class add $DEV parent 2:0 classid 2:$class cbq ".
+      "bandwidth $linerate rate $rate_table{$AFrate} avpkt 1000 prio ".
+      (6-$class)." bounded allot 1514 weight 1 maxburst 21\n";
+    print "$TC filter add $DEV parent 2:0 protocol ip prio 1 handle $class ".
+      "tcindex classid 2:$class\n";
+    print "$TC qdisc add $DEV parent 2:$class gred setup DPs 3 default 2 ".
+      "$GRIO\n";
+# 
+# per DP setup
+#
+    for $drop (1..3) {
+    print "\n# --- AF Class $class DP $drop---\n";
+	$dscp = $class*8+$drop*2;
+	$tcindex = sprintf("1%x%x",$class,$drop);
+	print "$TC filter add $DEV parent 1:0 protocol ip prio 1 ".
+	  "handle $dscp tcindex classid 1:$tcindex\n";
+	$prob = $drop*0.02;
+        if ($GRIO) {
+	$gprio = $drop+1;
+	print "$TC qdisc change $DEV parent 2:$class gred limit 60KB min 15KB ".
+	  "max 45KB burst 20 avpkt 1000 bandwidth $linerate DP $drop ".
+	  "probability $prob ".
+          "prio $gprio\n";
+        } else {
+	print "$TC qdisc change $DEV parent 2:$class gred limit 60KB min 15KB ".
+	  "max 45KB burst 20 avpkt 1000 bandwidth $linerate DP $drop ".
+	  "probability $prob \n";
+	}
+    }
+}
+#
+#
+print "\n#------BE Queue setup------\n";
+print "$TC filter add $DEV parent 1:0 protocol ip prio 2 ".
+          "handle 0 tcindex mask 0 classid 1:1\n";
+print "$TC class add $DEV parent 2:0 classid 2:$beclass cbq ".
+      "bandwidth $linerate rate $berate avpkt 1000 prio 6 " .
+      "bounded allot 1514 weight 1 maxburst 21 \n";
+print "$TC filter add $DEV parent 2:0 protocol ip prio 1 handle 0 tcindex ".
+  "classid 2:5\n";
+print "$TC qdisc add $DEV parent 2:5 red limit 60KB min 15KB max 45KB ".
+  "burst 20 avpkt 1000 bandwidth $linerate probability 0.4\n";
diff --git a/examples/diffserv/ef-prio b/examples/diffserv/ef-prio
new file mode 100644
index 0000000..48611bd
--- /dev/null
+++ b/examples/diffserv/ef-prio
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+$TC = "/root/DS-6-beta/iproute2-990530-dsing/tc/tc";
+$DEV = "dev eth1";
+$efrate="1.5Mbit";
+$MTU="1.5kB";
+print "$TC qdisc add $DEV handle 1:0 root dsmark indices 64 set_tc_index\n";
+print "$TC filter add $DEV parent 1:0 protocol ip prio 1 tcindex ".
+  "mask 0xfc shift 2\n";
+print "$TC qdisc add $DEV parent 1:0 handle 2:0 prio\n";
+#
+# EF class: Maximum about one MTU sized packet allowed on the queue
+#
+print "$TC qdisc add $DEV parent 2:1 tbf rate $efrate burst $MTU limit 1.6kB\n";
+print "$TC filter add $DEV parent 2:0 protocol ip prio 1 ".
+	  "handle 0x2e tcindex classid 2:1 pass_on\n";
+#
+# BE class
+#
+print "#BE class(2:2) \n";
+print "$TC qdisc add $DEV parent 2:2 red limit 60KB ".
+	  "min 15KB max 45KB burst 20 avpkt 1000 bandwidth 10Mbit ".
+	  "probability 0.4\n";
+#
+print "$TC filter add $DEV parent 2:0 protocol ip prio 2 ".
+	  "handle 0 tcindex mask 0 classid 2:2 pass_on\n";
diff --git a/examples/diffserv/efcbq b/examples/diffserv/efcbq
new file mode 100644
index 0000000..bcc437b
--- /dev/null
+++ b/examples/diffserv/efcbq
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+#
+$TC = "/root/DS-6-beta/iproute2-990530-dsing/tc/tc";
+$DEV = "dev eth1";
+print "$TC qdisc add $DEV handle 1:0 root dsmark indices 64 set_tc_index\n";
+print "$TC filter add $DEV parent 1:0 protocol ip prio 1 tcindex ".
+  "mask 0xfc shift 2\n";
+print "$TC qdisc add $DEV parent 1:0 handle 2:0 cbq bandwidth ".
+	"10Mbit cell 8 avpkt 1000 mpu 64\n";
+#
+# EF class
+#
+print "$TC class add $DEV parent 2:0 classid 2:1 cbq bandwidth ". 
+	"10Mbit rate 1500Kbit avpkt 1000 prio 1 bounded isolated ".
+	"allot 1514 weight 1 maxburst 10 \n";
+# packet fifo for EF?
+print "$TC qdisc add $DEV parent 2:1 pfifo limit 5\n";
+print "$TC filter add $DEV parent 2:0 protocol ip prio 1 ".
+	  "handle 0x2e tcindex classid 2:1 pass_on\n";
+#
+# BE class
+#
+print "#BE class(2:2) \n";
+print "$TC class add $DEV parent 2:0 classid 2:2 cbq bandwidth ". 
+	"10Mbit rate 5Mbit avpkt 1000 prio 7 allot 1514 weight 1 ".
+	"maxburst 21 borrow split 2:0 defmap 0xffff \n";
+print "$TC qdisc add $DEV parent 2:2 red limit 60KB ".
+	  "min 15KB max 45KB burst 20 avpkt 1000 bandwidth 10Mbit ".
+	  "probability 0.4\n";
+print "$TC filter add $DEV parent 2:0 protocol ip prio 2 ".
+	  "handle 0 tcindex mask 0 classid 2:2 pass_on\n";
diff --git a/examples/diffserv/regression-testing b/examples/diffserv/regression-testing
new file mode 100644
index 0000000..0ec705c
--- /dev/null
+++ b/examples/diffserv/regression-testing
@@ -0,0 +1,125 @@
+
+These were the tests done to validate the Diffserv scripts.
+This document will be updated continously. If you do more
+thorough validation testing please post the details to the
+diffserv mailing list. 
+Nevertheless, these tests should serve for basic validation.
+
+AFCBQ, EFCBQ, EFPRIO
+----------------------
+
+generate all possible DSCPs and observe that they 
+get sent to the proper classes. In the case of AF also
+to the correct Virtual Queues.
+
+Edge1
+-----
+generate TOS values 0x0,0x10,0xbb each with IP addresses
+10.2.0.24 (mark 1), 10.2.0.3 (mark2) and 10.2.0.30 (mark 3)
+and observe that they get marked as expected.
+
+Edge2
+-----
+
+-Repeat the tests in Edge1
+-ftp with data direction from 10.2.0.2
+	*observe that the metering/policing works correctly (and the marking
+	as well). In this case the mark used will be 3
+
+Edge31-cb-chains
+----------------
+
+-ftp with data direction from 10.2.0.2
+
+	*observe that the metering/policing works correctly (and the marking
+	as well). In this case the mark used will be 1. 
+
+	Metering: The data throughput should not exceed 2*CIR1 + 2*CIR2
+	which is roughly: 5mbps
+
+	Marking: the should be a variation of marked packets:
+	AF41(TOS=0x88) AF42(0x90) AF43(0x98) and BE (0x0)
+
+More tests required to see the interaction of several sources (other
+than subnet 10.2.0.0/24).
+
+Edge31-ca-u32
+--------------
+
+Generate data using modified tcpblast from 10.2.0.2 (behind eth2) to the 
+discard port of 10.1.0.2 (behind eth1)
+
+1) generate with src tos = 0x88
+	Metering: Allocated throughput should not exceed 2*CIR1 + 2*CIR2
+	approximately 5mbps
+	Marking: Should vary between 0x88,0x90,0x98 and 0x0
+
+2) generate with src tos = 0x90
+	Metering: Allocated throughput should not exceed CIR1 + 2*CIR2
+	approximately 3.5mbps
+	Marking: Should vary between 0x90,0x98 and 0x0
+
+3) generate with src tos = 0x98
+	Metering: Allocated throughput should not exceed CIR1 + CIR2
+	approximately 2.5mbps
+	Marking: Should vary between 0x98 and 0x0
+
+4) generate with src tos any other than the above
+	Metering: Allocated throughput should not exceed CIR1 
+	approximately 1.5mbps
+	Marking: Should be consistent at 0x0
+
+TODO: Testing on how each color shares when all 4 types of packets
+are going through the edge device
+
+Edge32-cb-u32, Edge32-cb-chains
+-------------------------------
+
+-ftp with data direction from 10.2.0.2
+
+	*observe that the metering/policing works correctly (and the marking
+	as well). 
+
+	Metering: 
+        The data throughput should not exceed 2*CIR1 + 2*CIR2
+	+ 2*PIR2 + PIR1 for u32 which is roughly: 6mbps
+        The data throughput should not exceed 2*CIR1 + 5*CIR2
+	for chains which is roughly: 6mbps
+
+	Marking: the should be a variation of marked packets:
+	AF41(TOS=0x88) AF42(0x90) AF43(0x98) and BE (0x0)
+
+TODO:
+-More tests required to see the interaction of several sources (other
+than subnet 10.2.0.0/24).
+-More tests needed to capture stats on how many times the CIR was exceeded
+but the data was not remarked etc.
+
+Edge32-ca-u32
+--------------
+
+Generate data using modified tcpblast from 10.2.0.2 (behind eth2) to the 
+discard port of 10.1.0.2 (behind eth1)
+
+1) generate with src tos = 0x88
+	Metering: Allocated throughput should not exceed 2*CIR1 + 2*CIR2
+	+PIR1 -- approximately 4mbps
+	Marking: Should vary between 0x88,0x90,0x98 and 0x0
+
+2) generate with src tos = 0x90
+	Metering: Allocated throughput should not exceed CIR1 + 2*CIR2
+	+ 2* PIR2 approximately 3mbps
+	Marking: Should vary between 0x90,0x98 and 0x0
+
+3) generate with src tos = 0x98
+	Metering: Allocated throughput should not exceed PIR1+ CIR1 + CIR2
+	approximately 2.5mbps
+	Marking: Should vary between 0x98 and 0x0
+
+4) generate with src tos any other than the above
+	Metering: Allocated throughput should not exceed CIR1 
+	approximately 1mbps
+	Marking: Should be consistent at 0x0
+
+TODO: Testing on how each color shares when all 4 types of packets
+are going through the edge device
diff --git a/examples/gaiconf b/examples/gaiconf
new file mode 100644
index 0000000..d75292b
--- /dev/null
+++ b/examples/gaiconf
@@ -0,0 +1,134 @@
+#!/bin/sh
+
+#
+# Setup address label from /etc/gai.conf
+#
+# Written by YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>, 2010.
+#
+
+IP=ip
+DEFAULT_GAICONF=/etc/gai.conf
+verbose=
+debug=
+
+function run ()
+{
+	if [ x"$verbose" != x"" ]; then
+		echo "$@"
+	fi
+	if [ x"$debug" = x"" ]; then
+		"$@"
+	fi
+}
+
+function do_load_config ()
+{
+	file=$1; shift
+	flush=1
+	cat $file | while read command prefix label; do
+		if [ x"$command" = x"#label" ]; then
+			if [ ${flush} = 1 ]; then
+				run ${IP} -6 addrlabel flush
+				flush=0
+			fi
+			run ${IP} -6 addrlabel add prefix $prefix label $label
+		fi
+	done
+}
+
+function do_list_config ()
+{
+	${IP} -6 addrlabel list | while read p pfx l lbl; do
+		echo label ${pfx} ${lbl}
+	done
+}
+
+function help ()
+{
+	echo "Usage: $0 [-v] {--list | --config [ ${DEFAULT_GAICONF} ] | --default}"
+	exit 1
+}
+
+TEMP=`getopt -o c::dlv -l config::,default,list,verbose -n gaiconf -- "$@"`
+
+if [ $? != 0 ]; then
+	echo "Terminating..." >&2
+	exit 1
+fi
+
+TEMPFILE=`mktemp`
+
+eval set -- "$TEMP"
+
+while true ; do
+	case "$1" in
+		-c|--config)
+			if [ x"$cmd" != x"" ]; then
+				help
+			fi
+			case "$2" in
+			"")	gai_conf="${DEFAULT_GAICONF}"
+				shift 2
+				;;
+			*)	gai_conf="$2"
+				shift 2
+			esac
+			cmd=config
+			;;
+		-d|--default)
+			if [ x"$cmd" != x"" ]; then
+				help
+			fi
+			gai_conf=${TEMPFILE}
+			cmd=config
+			;;
+		-l|--list)
+			if [ x"$cmd" != x"" ]; then
+				help
+			fi
+			cmd=list
+			shift
+			;;
+		-v)
+			verbose=1
+			shift
+			;;
+		--)
+			shift;
+			break
+			;;
+		*)
+			echo "Internal error!" >&2
+			exit 1
+			;;
+	esac
+done
+
+case "$cmd" in
+	config)
+		if [ x"$gai_conf" = x"${TEMPFILE}" ]; then
+			sed -e 's/^[[:space:]]*//' <<END_OF_DEFAULT >${TEMPFILE}
+				label ::1/128       0
+				label ::/0          1
+				label 2002::/16     2
+				label ::/96         3
+				label ::ffff:0:0/96 4
+				label fec0::/10     5
+				label fc00::/7      6
+				label 2001:0::/32   7
+END_OF_DEFAULT
+		fi
+		do_load_config "$gai_conf"
+		;;
+	list)
+		do_list_config
+		;;
+	*)
+		help
+		;;
+esac
+
+rm -f "${TEMPFILE}"
+
+exit 0
+
diff --git a/genl/Makefile b/genl/Makefile
index 2b7a45b..03d1f26 100644
--- a/genl/Makefile
+++ b/genl/Makefile
@@ -1,7 +1,6 @@
-# SPDX-License-Identifier: GPL-2.0
 GENLOBJ=genl.o
 
-include ../config.mk
+include ../Config
 SHARED_LIBS ?= y
 
 CFLAGS += -fno-strict-aliasing
@@ -21,7 +20,6 @@
 all: genl
 
 genl: $(GENLOBJ) $(LIBNETLINK) $(LIBUTIL) $(GENLLIB)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
 
 install: all
 	install -m 0755 genl $(DESTDIR)$(SBINDIR)
diff --git a/genl/ctrl.c b/genl/ctrl.c
index 0fb464b..b7a8878 100644
--- a/genl/ctrl.c
+++ b/genl/ctrl.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -38,6 +39,79 @@
 	return -1;
 }
 
+int genl_ctrl_resolve_family(const char *family)
+{
+	struct rtnl_handle rth;
+	struct nlmsghdr *nlh;
+	struct genlmsghdr *ghdr;
+	int ret = 0;
+	struct {
+		struct nlmsghdr         n;
+		char                    buf[4096];
+	} req;
+
+	memset(&req, 0, sizeof(req));
+
+	nlh = &req.n;
+	nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
+	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+	nlh->nlmsg_type = GENL_ID_CTRL;
+
+	ghdr = NLMSG_DATA(&req.n);
+	ghdr->cmd = CTRL_CMD_GETFAMILY;
+
+	if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
+		fprintf(stderr, "Cannot open generic netlink socket\n");
+		exit(1);
+	}
+
+	addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME, family, strlen(family) + 1);
+
+	if (rtnl_talk(&rth, nlh, nlh, sizeof(req)) < 0) {
+		fprintf(stderr, "Error talking to the kernel\n");
+		goto errout;
+	}
+
+	{
+		struct rtattr *tb[CTRL_ATTR_MAX + 1];
+		struct genlmsghdr *ghdr = NLMSG_DATA(nlh);
+		int len = nlh->nlmsg_len;
+		struct rtattr *attrs;
+
+		if (nlh->nlmsg_type !=  GENL_ID_CTRL) {
+			fprintf(stderr, "Not a controller message, nlmsg_len=%d "
+				"nlmsg_type=0x%x\n", nlh->nlmsg_len, nlh->nlmsg_type);
+			goto errout;
+		}
+
+		if (ghdr->cmd != CTRL_CMD_NEWFAMILY) {
+			fprintf(stderr, "Unknown controller command %d\n", ghdr->cmd);
+			goto errout;
+		}
+
+		len -= NLMSG_LENGTH(GENL_HDRLEN);
+
+		if (len < 0) {
+			fprintf(stderr, "wrong controller message len %d\n", len);
+			return -1;
+		}
+
+		attrs = (struct rtattr *) ((char *) ghdr + GENL_HDRLEN);
+		parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len);
+
+		if (tb[CTRL_ATTR_FAMILY_ID] == NULL) {
+			fprintf(stderr, "Missing family id TLV\n");
+			goto errout;
+		}
+
+		ret = rta_getattr_u16(tb[CTRL_ATTR_FAMILY_ID]);
+	}
+
+errout:
+	rtnl_close(&rth);
+	return ret;
+}
+
 static void print_ctrl_cmd_flags(FILE *fp, __u32 fl)
 {
 	fprintf(fp, "\n\t\tCapabilities (0x%x):\n ", fl);
@@ -58,7 +132,7 @@
 
 	fprintf(fp, "\n");
 }
-
+	
 static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
 {
 	struct rtattr *tb[CTRL_ATTR_OP_MAX + 1];
@@ -103,7 +177,8 @@
 /*
  * The controller sends one nlmsg per family
 */
-static int print_ctrl(struct rtnl_ctrl_data *ctrl,
+static int print_ctrl(const struct sockaddr_nl *who,
+		      struct rtnl_ctrl_data *ctrl,
 		      struct nlmsghdr *n, void *arg)
 {
 	struct rtattr *tb[CTRL_ATTR_MAX + 1];
@@ -207,28 +282,33 @@
 	return 0;
 }
 
-static int print_ctrl2(struct nlmsghdr *n, void *arg)
+static int print_ctrl2(const struct sockaddr_nl *who,
+		      struct nlmsghdr *n, void *arg)
 {
-	return print_ctrl(NULL, n, arg);
+	return print_ctrl(who, NULL, n, arg);
 }
 
 static int ctrl_list(int cmd, int argc, char **argv)
 {
 	struct rtnl_handle rth;
+	struct nlmsghdr *nlh;
+	struct genlmsghdr *ghdr;
 	int ret = -1;
 	char d[GENL_NAMSIZ];
 	struct {
 		struct nlmsghdr         n;
-		struct genlmsghdr	g;
 		char                    buf[4096];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN),
-		.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
-		.n.nlmsg_type = GENL_ID_CTRL,
-		.g.cmd = CTRL_CMD_GETFAMILY,
-	};
-	struct nlmsghdr *nlh = &req.n;
-	struct nlmsghdr *answer = NULL;
+	} req;
+
+	memset(&req, 0, sizeof(req));
+
+	nlh = &req.n;
+	nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
+	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+	nlh->nlmsg_type = GENL_ID_CTRL;
+
+	ghdr = NLMSG_DATA(&req.n);
+	ghdr->cmd = CTRL_CMD_GETFAMILY;
 
 	if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
 		fprintf(stderr, "Cannot open generic netlink socket\n");
@@ -243,7 +323,7 @@
 
 		if (matches(*argv, "name") == 0) {
 			NEXT_ARG();
-			strlcpy(d, *argv, sizeof(d));
+			strncpy(d, *argv, sizeof (d) - 1);
 			addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME,
 				  d, strlen(d) + 1);
 		} else if (matches(*argv, "id") == 0) {
@@ -261,12 +341,12 @@
 			goto ctrl_done;
 		}
 
-		if (rtnl_talk(&rth, nlh, &answer) < 0) {
+		if (rtnl_talk(&rth, nlh, nlh, sizeof(req)) < 0) {
 			fprintf(stderr, "Error talking to the kernel\n");
 			goto ctrl_done;
 		}
 
-		if (print_ctrl2(answer, (void *) stdout) < 0) {
+		if (print_ctrl2(NULL, nlh, (void *) stdout) < 0) {
 			fprintf(stderr, "Dump terminated\n");
 			goto ctrl_done;
 		}
@@ -288,7 +368,6 @@
 
 	ret = 0;
 ctrl_done:
-	free(answer);
 	rtnl_close(&rth);
 	return ret;
 }
diff --git a/genl/genl.c b/genl/genl.c
index aba3c13..e33fafd 100644
--- a/genl/genl.c
+++ b/genl/genl.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <dlfcn.h>
 #include <sys/socket.h>
@@ -26,15 +27,17 @@
 #include "utils.h"
 #include "genl_utils.h"
 
-int show_stats;
-int show_details;
-int show_raw;
+int show_stats = 0;
+int show_details = 0;
+int show_raw = 0;
+int resolve_hosts = 0;
 
 static void *BODY;
-static struct genl_util *genl_list;
+static struct genl_util * genl_list;
 
 
-static int print_nofopt(struct nlmsghdr *n, void *arg)
+static int print_nofopt(const struct sockaddr_nl *who, struct nlmsghdr *n,
+			void *arg)
 {
 	fprintf((FILE *) arg, "unknown genl type ..\n");
 	return 0;
@@ -43,9 +46,8 @@
 static int parse_nofopt(struct genl_util *f, int argc, char **argv)
 {
 	if (argc) {
-		fprintf(stderr,
-			"Unknown genl \"%s\", hence option \"%s\" is unparsable\n",
-			f->name, *argv);
+		fprintf(stderr, "Unknown genl \"%s\", hence option \"%s\" "
+			"is unparsable\n", f->name, *argv);
 		return -1;
 	}
 
@@ -84,8 +86,9 @@
 	return f;
 
 noexist:
-	f = calloc(1, sizeof(*f));
+	f = malloc(sizeof(*f));
 	if (f) {
+		memset(f, 0, sizeof(*f));
 		strncpy(f->name, str, 15);
 		f->parse_genlopt = parse_nofopt;
 		f->print_genlopt = print_nofopt;
@@ -98,10 +101,9 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: genl [ OPTIONS ] OBJECT [help] }\n"
-		"where  OBJECT := { ctrl etc }\n"
-		"       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -V[ersion] | -h[elp] }\n");
+	fprintf(stderr, "Usage: genl [ OPTIONS ] OBJECT | help }\n"
+	                "where  OBJECT := { ctrl etc }\n"
+	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] }\n");
 	exit(-1);
 }
 
@@ -123,21 +125,19 @@
 		} else if (matches(argv[1], "-help") == 0) {
 			usage();
 		} else {
-			fprintf(stderr,
-				"Option \"%s\" is unknown, try \"genl -help\".\n",
-				argv[1]);
+			fprintf(stderr, "Option \"%s\" is unknown, try "
+				"\"genl -help\".\n", argv[1]);
 			exit(-1);
 		}
 		argc--;	argv++;
 	}
 
 	if (argc > 1) {
-		struct genl_util *a;
 		int ret;
-
+		struct genl_util *a = NULL;
 		a = get_genl_kind(argv[1]);
 		if (!a) {
-			fprintf(stderr, "bad genl %s\n", argv[1]);
+			fprintf(stderr,"bad genl %s\n", argv[1]);
 			exit(-1);
 		}
 
diff --git a/genl/genl_utils.h b/genl/genl_utils.h
index a8d433a..85b5183 100644
--- a/genl/genl_utils.h
+++ b/genl/genl_utils.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _TC_UTIL_H_
 #define _TC_UTIL_H_ 1
 
@@ -10,7 +9,9 @@
 	struct  genl_util *next;
 	char	name[16];
 	int	(*parse_genlopt)(struct genl_util *fu, int argc, char **argv);
-	int	(*print_genlopt)(struct nlmsghdr *n, void *arg);
+	int	(*print_genlopt)(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
 };
 
+extern int genl_ctrl_resolve_family(const char *family);
+
 #endif
diff --git a/genl/static-syms.c b/genl/static-syms.c
index 47c4092..0bc8074 100644
--- a/genl/static-syms.c
+++ b/genl/static-syms.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * This file creates a dummy version of dynamic loading
  * for environments where dynamic linking
diff --git a/include/SNAPSHOT.h b/include/SNAPSHOT.h
index b98ad50..58d3632 100644
--- a/include/SNAPSHOT.h
+++ b/include/SNAPSHOT.h
@@ -1 +1 @@
-static const char SNAPSHOT[] = "191125";
+static const char SNAPSHOT[] = "160111";
diff --git a/include/bpf_api.h b/include/bpf_api.h
index 89d3488..0666a31 100644
--- a/include/bpf_api.h
+++ b/include/bpf_api.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __BPF_API__
 #define __BPF_API__
 
@@ -57,10 +56,6 @@
 # define ntohl(X)		__constant_ntohl((X))
 #endif
 
-#ifndef __inline__
-# define __inline__		__attribute__((always_inline))
-#endif
-
 /** Section helper macros. */
 
 #ifndef __section
@@ -73,11 +68,6 @@
 	__section(__stringify(ID) "/" __stringify(KEY))
 #endif
 
-#ifndef __section_xdp_entry
-# define __section_xdp_entry						\
-	__section(ELF_SECTION_PROG)
-#endif
-
 #ifndef __section_cls_entry
 # define __section_cls_entry						\
 	__section(ELF_SECTION_CLASSIFIER)
@@ -88,11 +78,6 @@
 	__section(ELF_SECTION_ACTION)
 #endif
 
-#ifndef __section_lwt_entry
-# define __section_lwt_entry						\
-	__section(ELF_SECTION_PROG)
-#endif
-
 #ifndef __section_license
 # define __section_license						\
 	__section(ELF_SECTION_LICENSE)
@@ -110,22 +95,62 @@
 	char ____license[] __section_license = NAME
 #endif
 
+#ifndef __BPF_MAP
+# define __BPF_MAP(NAME, TYPE, ID, SIZE_KEY, SIZE_VALUE, PIN, MAX_ELEM)	\
+	struct bpf_elf_map __section_maps NAME = {			\
+		.type		= (TYPE),				\
+		.id		= (ID),					\
+		.size_key	= (SIZE_KEY),				\
+		.size_value	= (SIZE_VALUE),				\
+		.pinning	= (PIN),				\
+		.max_elem	= (MAX_ELEM),				\
+	}
+#endif
+
+#ifndef BPF_HASH
+# define BPF_HASH(NAME, ID, SIZE_KEY, SIZE_VALUE, PIN, MAX_ELEM)	\
+	__BPF_MAP(NAME, BPF_MAP_TYPE_HASH, ID, SIZE_KEY, SIZE_VALUE,	\
+		  PIN, MAX_ELEM)
+#endif
+
+#ifndef BPF_ARRAY
+# define BPF_ARRAY(NAME, ID, SIZE_VALUE, PIN, MAX_ELEM)			\
+	__BPF_MAP(NAME, BPF_MAP_TYPE_ARRAY, ID, sizeof(uint32_t), 	\
+		  SIZE_VALUE, PIN, MAX_ELEM)
+#endif
+
+#ifndef BPF_ARRAY2
+# define BPF_ARRAY2(NAME, ID, PIN, MAX_ELEM)				\
+	BPF_ARRAY(NAME, ID, sizeof(uint16_t), PIN, MAX_ELEM)
+#endif
+
+#ifndef BPF_ARRAY4
+# define BPF_ARRAY4(NAME, ID, PIN, MAX_ELEM)				\
+	BPF_ARRAY(NAME, ID, sizeof(uint32_t), PIN, MAX_ELEM)
+#endif
+
+#ifndef BPF_ARRAY8
+# define BPF_ARRAY8(NAME, ID, PIN, MAX_ELEM)				\
+	BPF_ARRAY(NAME, ID, sizeof(uint64_t), PIN, MAX_ELEM)
+#endif
+
+#ifndef BPF_PROG_ARRAY
+# define BPF_PROG_ARRAY(NAME, ID, PIN, MAX_ELEM)			\
+	__BPF_MAP(NAME, BPF_MAP_TYPE_PROG_ARRAY, ID, sizeof(uint32_t),	\
+		  sizeof(uint32_t), PIN, MAX_ELEM)
+#endif
+
 /** Classifier helper */
 
 #ifndef BPF_H_DEFAULT
 # define BPF_H_DEFAULT	-1
 #endif
 
-/** BPF helper functions for tc. Individual flags are in linux/bpf.h */
-
-#ifndef __BPF_FUNC
-# define __BPF_FUNC(NAME, ...)						\
-	(* NAME)(__VA_ARGS__) __maybe_unused
-#endif
+/** BPF helper functions for tc. */
 
 #ifndef BPF_FUNC
 # define BPF_FUNC(NAME, ...)						\
-	__BPF_FUNC(NAME, __VA_ARGS__) = (void *) BPF_FUNC_##NAME
+	(* NAME)(__VA_ARGS__) __maybe_unused = (void *) BPF_FUNC_##NAME
 #endif
 
 /* Map access/manipulation */
@@ -138,22 +163,8 @@
 static uint64_t BPF_FUNC(ktime_get_ns);
 
 /* Debugging */
-
-/* FIXME: __attribute__ ((format(printf, 1, 3))) not possible unless
- * llvm bug https://llvm.org/bugs/show_bug.cgi?id=26243 gets resolved.
- * It would require ____fmt to be made const, which generates a reloc
- * entry (non-map).
- */
 static void BPF_FUNC(trace_printk, const char *fmt, int fmt_size, ...);
 
-#ifndef printt
-# define printt(fmt, ...)						\
-	({								\
-		char ____fmt[] = fmt;					\
-		trace_printk(____fmt, sizeof(____fmt), ##__VA_ARGS__);	\
-	})
-#endif
-
 /* Random numbers */
 static uint32_t BPF_FUNC(get_prandom_u32);
 
@@ -163,15 +174,10 @@
 
 /* System helpers */
 static uint32_t BPF_FUNC(get_smp_processor_id);
-static uint32_t BPF_FUNC(get_numa_node_id);
 
 /* Packet misc meta data */
 static uint32_t BPF_FUNC(get_cgroup_classid, struct __sk_buff *skb);
-static int BPF_FUNC(skb_under_cgroup, void *map, uint32_t index);
-
 static uint32_t BPF_FUNC(get_route_realm, struct __sk_buff *skb);
-static uint32_t BPF_FUNC(get_hash_recalc, struct __sk_buff *skb);
-static uint32_t BPF_FUNC(set_hash_invalid, struct __sk_buff *skb);
 
 /* Packet redirection */
 static int BPF_FUNC(redirect, int ifindex, uint32_t flags);
@@ -179,31 +185,16 @@
 		    uint32_t flags);
 
 /* Packet manipulation */
-static int BPF_FUNC(skb_load_bytes, struct __sk_buff *skb, uint32_t off,
-		    void *to, uint32_t len);
-static int BPF_FUNC(skb_store_bytes, struct __sk_buff *skb, uint32_t off,
-		    const void *from, uint32_t len, uint32_t flags);
+#define BPF_PSEUDO_HDR			0x10
+#define BPF_HAS_PSEUDO_HDR(flags)	((flags) & BPF_PSEUDO_HDR)
+#define BPF_HDR_FIELD_SIZE(flags)	((flags) & 0x0f)
 
+static int BPF_FUNC(skb_store_bytes, struct __sk_buff *skb, uint32_t off,
+		    void *from, uint32_t len, uint32_t flags);
 static int BPF_FUNC(l3_csum_replace, struct __sk_buff *skb, uint32_t off,
 		    uint32_t from, uint32_t to, uint32_t flags);
 static int BPF_FUNC(l4_csum_replace, struct __sk_buff *skb, uint32_t off,
 		    uint32_t from, uint32_t to, uint32_t flags);
-static int BPF_FUNC(csum_diff, const void *from, uint32_t from_size,
-		    const void *to, uint32_t to_size, uint32_t seed);
-static int BPF_FUNC(csum_update, struct __sk_buff *skb, uint32_t wsum);
-
-static int BPF_FUNC(skb_change_type, struct __sk_buff *skb, uint32_t type);
-static int BPF_FUNC(skb_change_proto, struct __sk_buff *skb, uint32_t proto,
-		    uint32_t flags);
-static int BPF_FUNC(skb_change_tail, struct __sk_buff *skb, uint32_t nlen,
-		    uint32_t flags);
-
-static int BPF_FUNC(skb_pull_data, struct __sk_buff *skb, uint32_t len);
-
-/* Event notification */
-static int __BPF_FUNC(skb_event_output, struct __sk_buff *skb, void *map,
-		      uint64_t index, const void *data, uint32_t size) =
-		      (void *) BPF_FUNC_perf_event_output;
 
 /* Packet vlan encap/decap */
 static int BPF_FUNC(skb_vlan_push, struct __sk_buff *skb, uint16_t proto,
@@ -214,42 +205,14 @@
 static int BPF_FUNC(skb_get_tunnel_key, struct __sk_buff *skb,
 		    struct bpf_tunnel_key *to, uint32_t size, uint32_t flags);
 static int BPF_FUNC(skb_set_tunnel_key, struct __sk_buff *skb,
-		    const struct bpf_tunnel_key *from, uint32_t size,
-		    uint32_t flags);
+		    struct bpf_tunnel_key *from, uint32_t size, uint32_t flags);
 
-static int BPF_FUNC(skb_get_tunnel_opt, struct __sk_buff *skb,
-		    void *to, uint32_t size);
-static int BPF_FUNC(skb_set_tunnel_opt, struct __sk_buff *skb,
-		    const void *from, uint32_t size);
-
-/** LLVM built-ins, mem*() routines work for constant size */
+/** LLVM built-ins */
 
 #ifndef lock_xadd
 # define lock_xadd(ptr, val)	((void) __sync_fetch_and_add(ptr, val))
 #endif
 
-#ifndef memset
-# define memset(s, c, n)	__builtin_memset((s), (c), (n))
-#endif
-
-#ifndef memcpy
-# define memcpy(d, s, n)	__builtin_memcpy((d), (s), (n))
-#endif
-
-#ifndef memmove
-# define memmove(d, s, n)	__builtin_memmove((d), (s), (n))
-#endif
-
-/* FIXME: __builtin_memcmp() is not yet fully useable unless llvm bug
- * https://llvm.org/bugs/show_bug.cgi?id=26218 gets resolved. Also
- * this one would generate a reloc entry (non-map), otherwise.
- */
-#if 0
-#ifndef memcmp
-# define memcmp(a, b, n)	__builtin_memcmp((a), (b), (n))
-#endif
-#endif
-
 unsigned long long load_byte(void *skb, unsigned long long off)
 	asm ("llvm.bpf.load.byte");
 
diff --git a/include/bpf_elf.h b/include/bpf_elf.h
index 84e8ae0..31a8974 100644
--- a/include/bpf_elf.h
+++ b/include/bpf_elf.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __BPF_ELF__
 #define __BPF_ELF__
 
@@ -16,7 +15,6 @@
 /* ELF section names, etc */
 #define ELF_SECTION_LICENSE	"license"
 #define ELF_SECTION_MAPS	"maps"
-#define ELF_SECTION_PROG	"prog"
 #define ELF_SECTION_CLASSIFIER	"classifier"
 #define ELF_SECTION_ACTION	"action"
 
@@ -34,20 +32,8 @@
 	__u32 size_key;
 	__u32 size_value;
 	__u32 max_elem;
-	__u32 flags;
 	__u32 id;
 	__u32 pinning;
-	__u32 inner_id;
-	__u32 inner_idx;
 };
 
-#define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)		\
-	struct ____btf_map_##name {				\
-		type_key key;					\
-		type_val value;					\
-	};							\
-	struct ____btf_map_##name				\
-	    __attribute__ ((section(".maps." #name), used))	\
-	    ____btf_map_##name = { }
-
 #endif /* __BPF_ELF__ */
diff --git a/include/bpf_scm.h b/include/bpf_scm.h
index 669f053..35117d1 100644
--- a/include/bpf_scm.h
+++ b/include/bpf_scm.h
@@ -1,10 +1,8 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __BPF_SCM__
 #define __BPF_SCM__
 
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/un.h>
 
 #include "utils.h"
 #include "bpf_elf.h"
diff --git a/include/bpf_util.h b/include/bpf_util.h
deleted file mode 100644
index 63db07c..0000000
--- a/include/bpf_util.h
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * bpf_util.h	BPF common code
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Daniel Borkmann <daniel@iogearbox.net>
- *		Jiri Pirko <jiri@resnulli.us>
- */
-
-#ifndef __BPF_UTIL__
-#define __BPF_UTIL__
-
-#include <linux/bpf.h>
-#include <linux/btf.h>
-#include <linux/filter.h>
-#include <linux/magic.h>
-#include <linux/elf-em.h>
-#include <linux/if_alg.h>
-
-#include "utils.h"
-#include "bpf_scm.h"
-
-#define BPF_ENV_UDS	"TC_BPF_UDS"
-#define BPF_ENV_MNT	"TC_BPF_MNT"
-
-#ifndef BPF_MAX_LOG
-# define BPF_MAX_LOG	4096
-#endif
-
-#define BPF_DIR_GLOBALS	"globals"
-
-#ifndef BPF_FS_MAGIC
-# define BPF_FS_MAGIC	0xcafe4a11
-#endif
-
-#define BPF_DIR_MNT	"/sys/fs/bpf"
-
-#ifndef TRACEFS_MAGIC
-# define TRACEFS_MAGIC	0x74726163
-#endif
-
-#define TRACE_DIR_MNT	"/sys/kernel/tracing"
-
-#ifndef AF_ALG
-# define AF_ALG		38
-#endif
-
-#ifndef EM_BPF
-# define EM_BPF		247
-#endif
-
-struct bpf_cfg_ops {
-	void (*cbpf_cb)(void *nl, const struct sock_filter *ops, int ops_len);
-	void (*ebpf_cb)(void *nl, int fd, const char *annotation);
-};
-
-enum bpf_mode {
-	CBPF_BYTECODE,
-	CBPF_FILE,
-	EBPF_OBJECT,
-	EBPF_PINNED,
-	BPF_MODE_MAX,
-};
-
-struct bpf_cfg_in {
-	const char *object;
-	const char *section;
-	const char *uds;
-	enum bpf_prog_type type;
-	enum bpf_mode mode;
-	__u32 ifindex;
-	bool verbose;
-	int argc;
-	char **argv;
-	struct sock_filter opcodes[BPF_MAXINSNS];
-	union {
-		int n_opcodes;
-		int prog_fd;
-	};
-};
-
-/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
-
-#define BPF_ALU64_REG(OP, DST, SRC)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU64 | BPF_OP(OP) | BPF_X,	\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = 0,					\
-		.imm   = 0 })
-
-#define BPF_ALU32_REG(OP, DST, SRC)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU | BPF_OP(OP) | BPF_X,		\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = 0,					\
-		.imm   = 0 })
-
-/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
-
-#define BPF_ALU64_IMM(OP, DST, IMM)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU64 | BPF_OP(OP) | BPF_K,	\
-		.dst_reg = DST,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = IMM })
-
-#define BPF_ALU32_IMM(OP, DST, IMM)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU | BPF_OP(OP) | BPF_K,		\
-		.dst_reg = DST,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = IMM })
-
-/* Short form of mov, dst_reg = src_reg */
-
-#define BPF_MOV64_REG(DST, SRC)					\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU64 | BPF_MOV | BPF_X,		\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = 0,					\
-		.imm   = 0 })
-
-#define BPF_MOV32_REG(DST, SRC)					\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU | BPF_MOV | BPF_X,		\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = 0,					\
-		.imm   = 0 })
-
-/* Short form of mov, dst_reg = imm32 */
-
-#define BPF_MOV64_IMM(DST, IMM)					\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU64 | BPF_MOV | BPF_K,		\
-		.dst_reg = DST,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = IMM })
-
-#define BPF_MOV32_IMM(DST, IMM)					\
-	((struct bpf_insn) {					\
-		.code  = BPF_ALU | BPF_MOV | BPF_K,		\
-		.dst_reg = DST,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = IMM })
-
-/* BPF_LD_IMM64 macro encodes single 'load 64-bit immediate' insn */
-#define BPF_LD_IMM64(DST, IMM)					\
-	BPF_LD_IMM64_RAW(DST, 0, IMM)
-
-#define BPF_LD_IMM64_RAW(DST, SRC, IMM)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_LD | BPF_DW | BPF_IMM,		\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = 0,					\
-		.imm   = (__u32) (IMM) }),			\
-	((struct bpf_insn) {					\
-		.code  = 0, /* zero is reserved opcode */	\
-		.dst_reg = 0,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = ((__u64) (IMM)) >> 32 })
-
-#ifndef BPF_PSEUDO_MAP_FD
-# define BPF_PSEUDO_MAP_FD	1
-#endif
-
-/* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */
-#define BPF_LD_MAP_FD(DST, MAP_FD)				\
-	BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD)
-
-
-/* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
-
-#define BPF_LD_ABS(SIZE, IMM)					\
-	((struct bpf_insn) {					\
-		.code  = BPF_LD | BPF_SIZE(SIZE) | BPF_ABS,	\
-		.dst_reg = 0,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = IMM })
-
-/* Memory load, dst_reg = *(uint *) (src_reg + off16) */
-
-#define BPF_LDX_MEM(SIZE, DST, SRC, OFF)			\
-	((struct bpf_insn) {					\
-		.code  = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM,	\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = OFF,					\
-		.imm   = 0 })
-
-/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
-
-#define BPF_STX_MEM(SIZE, DST, SRC, OFF)			\
-	((struct bpf_insn) {					\
-		.code  = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM,	\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = OFF,					\
-		.imm   = 0 })
-
-/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
-
-#define BPF_ST_MEM(SIZE, DST, OFF, IMM)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM,	\
-		.dst_reg = DST,					\
-		.src_reg = 0,					\
-		.off   = OFF,					\
-		.imm   = IMM })
-
-/* Conditional jumps against registers, if (dst_reg 'op' src_reg) goto pc + off16 */
-
-#define BPF_JMP_REG(OP, DST, SRC, OFF)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_JMP | BPF_OP(OP) | BPF_X,		\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = OFF,					\
-		.imm   = 0 })
-
-/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
-
-#define BPF_JMP_IMM(OP, DST, IMM, OFF)				\
-	((struct bpf_insn) {					\
-		.code  = BPF_JMP | BPF_OP(OP) | BPF_K,		\
-		.dst_reg = DST,					\
-		.src_reg = 0,					\
-		.off   = OFF,					\
-		.imm   = IMM })
-
-/* Raw code statement block */
-
-#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM)			\
-	((struct bpf_insn) {					\
-		.code  = CODE,					\
-		.dst_reg = DST,					\
-		.src_reg = SRC,					\
-		.off   = OFF,					\
-		.imm   = IMM })
-
-/* Program exit */
-
-#define BPF_EXIT_INSN()						\
-	((struct bpf_insn) {					\
-		.code  = BPF_JMP | BPF_EXIT,			\
-		.dst_reg = 0,					\
-		.src_reg = 0,					\
-		.off   = 0,					\
-		.imm   = 0 })
-
-int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops);
-int bpf_load_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops,
-		    void *nl);
-int bpf_parse_and_load_common(struct bpf_cfg_in *cfg,
-			      const struct bpf_cfg_ops *ops, void *nl);
-
-const char *bpf_prog_to_default_section(enum bpf_prog_type type);
-
-int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv);
-int bpf_trace_pipe(void);
-
-void bpf_print_ops(struct rtattr *bpf_ops, __u16 len);
-
-int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		  size_t size_insns, const char *license, char *log,
-		  size_t size_log);
-
-int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type);
-int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type);
-
-int bpf_dump_prog_info(FILE *f, uint32_t id);
-
-#ifdef HAVE_ELF
-int bpf_send_map_fds(const char *path, const char *obj);
-int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
-		     unsigned int entries);
-#else
-static inline int bpf_send_map_fds(const char *path, const char *obj)
-{
-	return 0;
-}
-
-static inline int bpf_recv_map_fds(const char *path, int *fds,
-				   struct bpf_map_aux *aux,
-				   unsigned int entries)
-{
-	return -1;
-}
-#endif /* HAVE_ELF */
-#endif /* __BPF_UTIL__ */
diff --git a/include/color.h b/include/color.h
index 17ec56f..b85003a 100644
--- a/include/color.h
+++ b/include/color.h
@@ -1,29 +1,16 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __COLOR_H__
 #define __COLOR_H__ 1
 
-#include <stdbool.h>
-
 enum color_attr {
 	COLOR_IFNAME,
 	COLOR_MAC,
 	COLOR_INET,
 	COLOR_INET6,
 	COLOR_OPERSTATE_UP,
-	COLOR_OPERSTATE_DOWN,
-	COLOR_NONE
+	COLOR_OPERSTATE_DOWN
 };
 
-enum color_opt {
-	COLOR_OPT_NEVER = 0,
-	COLOR_OPT_AUTO = 1,
-	COLOR_OPT_ALWAYS = 2
-};
-
-bool check_enable_color(int color, int json);
-bool matches_color(const char *arg, int *val);
+void enable_color(void);
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
-enum color_attr ifa_family_color(__u8 ifa_family);
-enum color_attr oper_state_color(__u8 state);
 
 #endif
diff --git a/include/dlfcn.h b/include/dlfcn.h
index 1d8890a..f15bc2c 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Stub dlfcn implementation for systems that lack shared library support
  * but obviously can still reference compiled-in symbols.
diff --git a/include/hlist.h b/include/hlist.h
new file mode 100644
index 0000000..4e8de9e
--- /dev/null
+++ b/include/hlist.h
@@ -0,0 +1,56 @@
+#ifndef __HLIST_H__
+#define __HLIST_H__ 1
+/* Hash list stuff from kernel */
+
+#include <stddef.h>
+
+#define container_of(ptr, type, member) ({			\
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
+	(type *)( (char *)__mptr - offsetof(type,member) );})
+
+struct hlist_head {
+	struct hlist_node *first;
+};
+
+struct hlist_node {
+	struct hlist_node *next, **pprev;
+};
+
+static inline void hlist_del(struct hlist_node *n)
+{
+	struct hlist_node *next = n->next;
+	struct hlist_node **pprev = n->pprev;
+	*pprev = next;
+	if (next)
+		next->pprev = pprev;
+}
+
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+	struct hlist_node *first = h->first;
+	n->next = first;
+	if (first)
+		first->pprev = &n->next;
+	h->first = n;
+	n->pprev = &h->first;
+}
+
+#define hlist_for_each(pos, head) \
+	for (pos = (head)->first; pos ; pos = pos->next)
+
+
+#define hlist_for_each_safe(pos, n, head) \
+	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
+	     pos = n)
+
+#define hlist_entry_safe(ptr, type, member) \
+	({ typeof(ptr) ____ptr = (ptr); \
+	   ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
+	})
+
+#define hlist_for_each_entry(pos, head, member)				\
+	for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
+	     pos;							\
+	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
+
+#endif /* __HLIST_H__ */
diff --git a/include/ip6tables.h b/include/ip6tables.h
index bfb2868..5f1c5b6 100644
--- a/include/ip6tables.h
+++ b/include/ip6tables.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _IP6TABLES_USER_H
 #define _IP6TABLES_USER_H
 
diff --git a/include/iptables.h b/include/iptables.h
index 78bc378..78c10ab 100644
--- a/include/iptables.h
+++ b/include/iptables.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _IPTABLES_USER_H
 #define _IPTABLES_USER_H
 
diff --git a/include/iptables/internal.h b/include/iptables/internal.h
index 1fd1372..62a8ecb 100644
--- a/include/iptables/internal.h
+++ b/include/iptables/internal.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef IPTABLES_INTERNAL_H
 #define IPTABLES_INTERNAL_H 1
 
diff --git a/include/iptables_common.h b/include/iptables_common.h
new file mode 100644
index 0000000..9099667
--- /dev/null
+++ b/include/iptables_common.h
@@ -0,0 +1,51 @@
+#ifndef _IPTABLES_COMMON_H
+#define _IPTABLES_COMMON_H
+/* Shared definitions between ipv4 and ipv6. */
+
+enum exittype {
+	OTHER_PROBLEM = 1,
+	PARAMETER_PROBLEM,
+	VERSION_PROBLEM,
+	RESOURCE_PROBLEM
+};
+
+/* this is a special 64bit data type that is 8-byte aligned */
+#define aligned_u64 unsigned long long __attribute__((aligned(8)))
+
+extern void exit_printhelp(void) __attribute__((noreturn));
+extern void exit_tryhelp(int) __attribute__((noreturn));
+int check_inverse(const char option[], int *invert, int *optind, int argc);
+extern int string_to_number(const char *, 
+			    unsigned int, 
+			    unsigned int,
+			    unsigned int *);
+extern int string_to_number_l(const char *, 
+			    unsigned long int, 
+			    unsigned long int,
+			    unsigned long *);
+extern int string_to_number_ll(const char *, 
+			    unsigned long long int, 
+			    unsigned long long int,
+			    unsigned long long *);
+extern int iptables_insmod(const char *modname, const char *modprobe);
+extern int load_iptables_ko(const char *modprobe);
+void exit_error(enum exittype, char *, ...)__attribute__((noreturn,
+							  format(printf,2,3)));
+extern const char *program_name, *program_version;
+extern char *lib_dir;
+
+#define _init __attribute__((constructor)) my_init
+#ifdef NO_SHARED_LIBS
+# ifdef _INIT
+#  undef _init
+#  define _init _INIT
+# endif
+  extern void init_extensions(void);
+#endif
+
+#define __be32	u_int32_t
+#define __le32	u_int32_t
+#define __be16	u_int16_t
+#define __le16	u_int16_t
+
+#endif /*_IPTABLES_COMMON_H*/
diff --git a/include/json_print.h b/include/json_print.h
deleted file mode 100644
index fe92d14..0000000
--- a/include/json_print.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * json_print.h		"print regular or json output, based on json_writer".
- *
- *             This program is free software; you can redistribute it and/or
- *             modify it under the terms of the GNU General Public License
- *             as published by the Free Software Foundation; either version
- *             2 of the License, or (at your option) any later version.
- *
- * Authors:    Julien Fortin, <julien@cumulusnetworks.com>
- */
-
-#ifndef _JSON_PRINT_H_
-#define _JSON_PRINT_H_
-
-#include "json_writer.h"
-#include "color.h"
-
-json_writer_t *get_json_writer(void);
-
-/*
- * use:
- *      - PRINT_ANY for context based output
- *      - PRINT_FP for non json specific output
- *      - PRINT_JSON for json specific output
- */
-enum output_type {
-	PRINT_FP = 1,
-	PRINT_JSON = 2,
-	PRINT_ANY = 4,
-};
-
-void new_json_obj(int json);
-void delete_json_obj(void);
-
-bool is_json_context(void);
-
-void fflush_fp(void);
-
-void open_json_object(const char *str);
-void close_json_object(void);
-void open_json_array(enum output_type type, const char *delim);
-void close_json_array(enum output_type type, const char *delim);
-
-void print_nl(void);
-
-#define _PRINT_FUNC(type_name, type)					\
-	void print_color_##type_name(enum output_type t,		\
-				     enum color_attr color,		\
-				     const char *key,			\
-				     const char *fmt,			\
-				     type value);			\
-									\
-	static inline void print_##type_name(enum output_type t,	\
-					     const char *key,		\
-					     const char *fmt,		\
-					     type value)		\
-	{								\
-		print_color_##type_name(t, COLOR_NONE, key, fmt, value);	\
-	}
-
-_PRINT_FUNC(int, int)
-_PRINT_FUNC(s64, int64_t)
-_PRINT_FUNC(bool, bool)
-_PRINT_FUNC(null, const char*)
-_PRINT_FUNC(string, const char*)
-_PRINT_FUNC(uint, unsigned int)
-_PRINT_FUNC(u64, uint64_t)
-_PRINT_FUNC(hhu, unsigned char)
-_PRINT_FUNC(hu, unsigned short)
-_PRINT_FUNC(hex, unsigned int)
-_PRINT_FUNC(0xhex, unsigned long long)
-_PRINT_FUNC(luint, unsigned long)
-_PRINT_FUNC(lluint, unsigned long long)
-_PRINT_FUNC(float, double)
-#undef _PRINT_FUNC
-
-#endif /* _JSON_PRINT_H_ */
diff --git a/include/json_writer.h b/include/json_writer.h
index b52dc2d..ab9a008 100644
--- a/include/json_writer.h
+++ b/include/json_writer.h
@@ -1,10 +1,14 @@
-/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
 /*
  * Simple streaming JSON writer
  *
  * This takes care of the annoying bits of JSON syntax like the commas
  * after elements
  *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
  * Authors:	Stephen Hemminger <stephen@networkplumber.org>
  */
 
@@ -29,39 +33,20 @@
 void jsonw_name(json_writer_t *self, const char *name);
 
 /* Add value  */
-__attribute__((format(printf, 2, 3)))
-void jsonw_printf(json_writer_t *self, const char *fmt, ...);
 void jsonw_string(json_writer_t *self, const char *value);
 void jsonw_bool(json_writer_t *self, bool value);
 void jsonw_float(json_writer_t *self, double number);
-void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num);
-void jsonw_uint(json_writer_t *self, unsigned int number);
-void jsonw_u64(json_writer_t *self, uint64_t number);
-void jsonw_xint(json_writer_t *self, uint64_t number);
-void jsonw_hhu(json_writer_t *self, unsigned char num);
-void jsonw_hu(json_writer_t *self, unsigned short number);
-void jsonw_int(json_writer_t *self, int number);
-void jsonw_s64(json_writer_t *self, int64_t number);
+void jsonw_uint(json_writer_t *self, uint64_t number);
+void jsonw_int(json_writer_t *self, int64_t number);
 void jsonw_null(json_writer_t *self);
-void jsonw_luint(json_writer_t *self, unsigned long num);
-void jsonw_lluint(json_writer_t *self, unsigned long long num);
 
 /* Useful Combinations of name and value */
 void jsonw_string_field(json_writer_t *self, const char *prop, const char *val);
 void jsonw_bool_field(json_writer_t *self, const char *prop, bool value);
 void jsonw_float_field(json_writer_t *self, const char *prop, double num);
-void jsonw_uint_field(json_writer_t *self, const char *prop, unsigned int num);
-void jsonw_u64_field(json_writer_t *self, const char *prop, uint64_t num);
-void jsonw_xint_field(json_writer_t *self, const char *prop, uint64_t num);
-void jsonw_hhu_field(json_writer_t *self, const char *prop, unsigned char num);
-void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num);
-void jsonw_int_field(json_writer_t *self, const char *prop, int num);
-void jsonw_s64_field(json_writer_t *self, const char *prop, int64_t num);
+void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num);
+void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num);
 void jsonw_null_field(json_writer_t *self, const char *prop);
-void jsonw_luint_field(json_writer_t *self, const char *prop,
-			unsigned long num);
-void jsonw_lluint_field(json_writer_t *self, const char *prop,
-			unsigned long long num);
 
 /* Collections */
 void jsonw_start_object(json_writer_t *self);
diff --git a/include/libgenl.h b/include/libgenl.h
index 656493a..9db4baf 100644
--- a/include/libgenl.h
+++ b/include/libgenl.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __LIBGENL_H__
 #define __LIBGENL_H__
 
@@ -21,8 +20,6 @@
 	},								\
 }
 
-int genl_resolve_family(struct rtnl_handle *grth, const char *family);
-int genl_init_handle(struct rtnl_handle *grth, const char *family,
-		     int *genl_family);
+extern int genl_resolve_family(struct rtnl_handle *grth, const char *family);
 
 #endif /* __LIBGENL_H__ */
diff --git a/include/libiptc/ipt_kernel_headers.h b/include/libiptc/ipt_kernel_headers.h
index 3d2a2a3..a5963e9 100644
--- a/include/libiptc/ipt_kernel_headers.h
+++ b/include/libiptc/ipt_kernel_headers.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /* This is the userspace/kernel interface for Generic IP Chains,
    required for libc6. */
 #ifndef _FWCHAINS_KERNEL_HEADERS_H
diff --git a/include/libiptc/libip6tc.h b/include/libiptc/libip6tc.h
index cd588de..9aed80a 100644
--- a/include/libiptc/libip6tc.h
+++ b/include/libiptc/libip6tc.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _LIBIP6TC_H
 #define _LIBIP6TC_H
 /* Library which manipulates firewall rules. Version 0.2. */
diff --git a/include/libiptc/libiptc.h b/include/libiptc/libiptc.h
index 1bfe4e1..24cdbdb 100644
--- a/include/libiptc/libiptc.h
+++ b/include/libiptc/libiptc.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _LIBIPTC_H
 #define _LIBIPTC_H
 /* Library which manipulates filtering rules. */
diff --git a/include/libiptc/libxtc.h b/include/libiptc/libxtc.h
index 1e9596a..3701018 100644
--- a/include/libiptc/libxtc.h
+++ b/include/libiptc/libxtc.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _LIBXTC_H
 #define _LIBXTC_H
 /* Library which manipulates filtering rules. */
diff --git a/include/libiptc/xtcshared.h b/include/libiptc/xtcshared.h
index 278a58f..773ebc4 100644
--- a/include/libiptc/xtcshared.h
+++ b/include/libiptc/xtcshared.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _LIBXTC_SHARED_H
 #define _LIBXTC_SHARED_H 1
 
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 8ebdc6d..431189e 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __LIBNETLINK_H__
 #define __LIBNETLINK_H__ 1
 
@@ -11,9 +10,9 @@
 #include <linux/if_addr.h>
 #include <linux/neighbour.h>
 #include <linux/netconf.h>
-#include <arpa/inet.h>
 
-struct rtnl_handle {
+struct rtnl_handle
+{
 	int			fd;
 	struct sockaddr_nl	local;
 	struct sockaddr_nl	peer;
@@ -22,71 +21,23 @@
 	int			proto;
 	FILE		       *dump_fp;
 #define RTNL_HANDLE_F_LISTEN_ALL_NSID		0x01
-#define RTNL_HANDLE_F_SUPPRESS_NLERR		0x02
-#define RTNL_HANDLE_F_STRICT_CHK		0x04
 	int			flags;
 };
 
-struct nlmsg_list {
-	struct nlmsg_list *next;
-	struct nlmsghdr   h;
-};
-
-struct nlmsg_chain {
-	struct nlmsg_list *head;
-	struct nlmsg_list *tail;
-};
-
 extern int rcvbuf;
 
-int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)
+int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
 	__attribute__((warn_unused_result));
 
-int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
+int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
 			     int protocol)
 	__attribute__((warn_unused_result));
-int rtnl_add_nl_group(struct rtnl_handle *rth, unsigned int group)
-	__attribute__((warn_unused_result));
+
 void rtnl_close(struct rtnl_handle *rth);
-void rtnl_set_strict_dump(struct rtnl_handle *rth);
-
-typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
-
-int rtnl_addrdump_req(struct rtnl_handle *rth, int family,
-		      req_filter_fn_t filter_fn)
+int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type)
 	__attribute__((warn_unused_result));
-int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
-	__attribute__((warn_unused_result));
-int rtnl_routedump_req(struct rtnl_handle *rth, int family,
-		       req_filter_fn_t filter_fn)
-	__attribute__((warn_unused_result));
-int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
-	__attribute__((warn_unused_result));
-int rtnl_neighdump_req(struct rtnl_handle *rth, int family,
-		       req_filter_fn_t filter_fn)
-	__attribute__((warn_unused_result));
-int rtnl_neightbldump_req(struct rtnl_handle *rth, int family)
-	__attribute__((warn_unused_result));
-int rtnl_mdbdump_req(struct rtnl_handle *rth, int family)
-	__attribute__((warn_unused_result));
-int rtnl_netconfdump_req(struct rtnl_handle *rth, int family)
-	__attribute__((warn_unused_result));
-
-int rtnl_linkdump_req(struct rtnl_handle *rth, int fam)
-	__attribute__((warn_unused_result));
-int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
-	__attribute__((warn_unused_result));
-
-int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam,
-				req_filter_fn_t fn)
-	__attribute__((warn_unused_result));
-int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth,
-				    req_filter_fn_t filter_fn)
-	__attribute__((warn_unused_result));
-int rtnl_nsiddump_req_filter_fn(struct rtnl_handle *rth, int family,
-				req_filter_fn_t filter_fn)
-	__attribute__((warn_unused_result));
-int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
+int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type,
+				    __u32 filt_mask)
 	__attribute__((warn_unused_result));
 int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req,
 			     int len)
@@ -94,48 +45,38 @@
 int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n)
 	__attribute__((warn_unused_result));
 
-int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family,
-			 req_filter_fn_t filter_fn)
-	__attribute__((warn_unused_result));
-
 struct rtnl_ctrl_data {
 	int	nsid;
 };
 
-typedef int (*rtnl_filter_t)(struct nlmsghdr *n, void *);
+typedef int (*rtnl_filter_t)(const struct sockaddr_nl *,
+			     struct nlmsghdr *n, void *);
 
-typedef int (*rtnl_listen_filter_t)(struct rtnl_ctrl_data *,
+typedef int (*rtnl_listen_filter_t)(const struct sockaddr_nl *,
+				    struct rtnl_ctrl_data *,
 				    struct nlmsghdr *n, void *);
 
-typedef int (*nl_ext_ack_fn_t)(const char *errmsg, uint32_t off,
-			       const struct nlmsghdr *inner_nlh);
-
-struct rtnl_dump_filter_arg {
+struct rtnl_dump_filter_arg
+{
 	rtnl_filter_t filter;
 	void *arg1;
 	__u16 nc_flags;
 };
 
+int rtnl_dump_filter_l(struct rtnl_handle *rth,
+			      const struct rtnl_dump_filter_arg *arg);
 int rtnl_dump_filter_nc(struct rtnl_handle *rth,
 			rtnl_filter_t filter,
 			void *arg, __u16 nc_flags);
 #define rtnl_dump_filter(rth, filter, arg) \
 	rtnl_dump_filter_nc(rth, filter, arg, 0)
 int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
-	      struct nlmsghdr **answer)
-	__attribute__((warn_unused_result));
-int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,
-		  struct nlmsghdr **answer)
-	__attribute__((warn_unused_result));
-int rtnl_talk_suppress_rtnl_errmsg(struct rtnl_handle *rtnl, struct nlmsghdr *n,
-				   struct nlmsghdr **answer)
+	      struct nlmsghdr *answer, size_t len)
 	__attribute__((warn_unused_result));
 int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
 	__attribute__((warn_unused_result));
 int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int)
 	__attribute__((warn_unused_result));
-int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn);
-int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error);
 
 int addattr(struct nlmsghdr *n, int maxlen, int type);
 int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data);
@@ -162,6 +103,8 @@
 int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
 int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,
 			      int len, unsigned short flags);
+int parse_rtattr_byindex(struct rtattr *tb[], int max,
+			 struct rtattr *rta, int len);
 struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);
 int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len);
 
@@ -190,36 +133,16 @@
 {
 	return *(__u16 *)RTA_DATA(rta);
 }
-static inline __be16 rta_getattr_be16(const struct rtattr *rta)
-{
-	return ntohs(rta_getattr_u16(rta));
-}
 static inline __u32 rta_getattr_u32(const struct rtattr *rta)
 {
 	return *(__u32 *)RTA_DATA(rta);
 }
-static inline __be32 rta_getattr_be32(const struct rtattr *rta)
-{
-	return ntohl(rta_getattr_u32(rta));
-}
 static inline __u64 rta_getattr_u64(const struct rtattr *rta)
 {
 	__u64 tmp;
-
 	memcpy(&tmp, RTA_DATA(rta), sizeof(__u64));
 	return tmp;
 }
-static inline __s32 rta_getattr_s32(const struct rtattr *rta)
-{
-	return *(__s32 *)RTA_DATA(rta);
-}
-static inline __s64 rta_getattr_s64(const struct rtattr *rta)
-{
-	__s64 tmp;
-
-	memcpy(&tmp, RTA_DATA(rta), sizeof(tmp));
-	return tmp;
-}
 static inline const char *rta_getattr_str(const struct rtattr *rta)
 {
 	return (const char *)RTA_DATA(rta);
@@ -236,47 +159,42 @@
 
 #ifndef IFA_RTA
 #define IFA_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
+	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
 #endif
 #ifndef IFA_PAYLOAD
-#define IFA_PAYLOAD(n)	NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg))
+#define IFA_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
 #endif
 
 #ifndef IFLA_RTA
 #define IFLA_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
+	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
 #endif
 #ifndef IFLA_PAYLOAD
-#define IFLA_PAYLOAD(n)	NLMSG_PAYLOAD(n, sizeof(struct ifinfomsg))
+#define IFLA_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
 #endif
 
 #ifndef NDA_RTA
 #define NDA_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
+	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
 #endif
 #ifndef NDA_PAYLOAD
-#define NDA_PAYLOAD(n)	NLMSG_PAYLOAD(n, sizeof(struct ndmsg))
+#define NDA_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
 #endif
 
 #ifndef NDTA_RTA
 #define NDTA_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndtmsg))))
+	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndtmsg))))
 #endif
 #ifndef NDTA_PAYLOAD
-#define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ndtmsg))
+#define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg))
 #endif
 
 #ifndef NETNS_RTA
 #define NETNS_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtgenmsg))))
+	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtgenmsg))))
 #endif
 #ifndef NETNS_PAYLOAD
-#define NETNS_PAYLOAD(n)	NLMSG_PAYLOAD(n, sizeof(struct rtgenmsg))
-#endif
-
-#ifndef IFLA_STATS_RTA
-#define IFLA_STATS_RTA(r) \
-	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct if_stats_msg))))
+#define NETNS_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct rtgenmsg))
 #endif
 
 /* User defined nlmsg_type which is used mostly for logging netlink
@@ -284,3 +202,4 @@
 #define NLMSG_TSTAMP	15
 
 #endif /* __LIBNETLINK_H__ */
+
diff --git a/include/uapi/linux/atm.h b/include/linux/atm.h
similarity index 98%
rename from include/uapi/linux/atm.h
rename to include/linux/atm.h
index e33ff6b..08e27be 100644
--- a/include/uapi/linux/atm.h
+++ b/include/linux/atm.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* atm.h - general ATM declarations */
  
 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
diff --git a/include/uapi/linux/atmapi.h b/include/linux/atmapi.h
similarity index 93%
rename from include/uapi/linux/atmapi.h
rename to include/linux/atmapi.h
index c9bf5c2..8fe54d9 100644
--- a/include/uapi/linux/atmapi.h
+++ b/include/linux/atmapi.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* atmapi.h - ATM API user space/kernel compatibility */
  
 /* Written 1999,2000 by Werner Almesberger, EPFL ICA */
diff --git a/include/uapi/linux/atmioc.h b/include/linux/atmioc.h
similarity index 95%
rename from include/uapi/linux/atmioc.h
rename to include/linux/atmioc.h
index cd7655e..37f67aa 100644
--- a/include/uapi/linux/atmioc.h
+++ b/include/linux/atmioc.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* atmioc.h - ranges for ATM-related ioctl numbers */
  
 /* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
diff --git a/include/uapi/linux/atmsap.h b/include/linux/atmsap.h
similarity index 98%
rename from include/uapi/linux/atmsap.h
rename to include/linux/atmsap.h
index fc05248..799b104 100644
--- a/include/uapi/linux/atmsap.h
+++ b/include/linux/atmsap.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* atmsap.h - ATM Service Access Point addressing definitions */
 
 /* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
new file mode 100644
index 0000000..f970f9d
--- /dev/null
+++ b/include/linux/bpf.h
@@ -0,0 +1,326 @@
+/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ */
+#ifndef __LINUX_BPF_H__
+#define __LINUX_BPF_H__
+
+#include <linux/types.h>
+#include <linux/bpf_common.h>
+
+/* Extended instruction set based on top of classic BPF */
+
+/* instruction classes */
+#define BPF_ALU64	0x07	/* alu mode in double word width */
+
+/* ld/ldx fields */
+#define BPF_DW		0x18	/* double word */
+#define BPF_XADD	0xc0	/* exclusive add */
+
+/* alu/jmp fields */
+#define BPF_MOV		0xb0	/* mov reg to reg */
+#define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
+
+/* change endianness of a register */
+#define BPF_END		0xd0	/* flags for endianness conversion: */
+#define BPF_TO_LE	0x00	/* convert to little-endian */
+#define BPF_TO_BE	0x08	/* convert to big-endian */
+#define BPF_FROM_LE	BPF_TO_LE
+#define BPF_FROM_BE	BPF_TO_BE
+
+#define BPF_JNE		0x50	/* jump != */
+#define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
+#define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
+#define BPF_CALL	0x80	/* function call */
+#define BPF_EXIT	0x90	/* function return */
+
+/* Register numbers */
+enum {
+	BPF_REG_0 = 0,
+	BPF_REG_1,
+	BPF_REG_2,
+	BPF_REG_3,
+	BPF_REG_4,
+	BPF_REG_5,
+	BPF_REG_6,
+	BPF_REG_7,
+	BPF_REG_8,
+	BPF_REG_9,
+	BPF_REG_10,
+	__MAX_BPF_REG,
+};
+
+/* BPF has 10 general purpose 64-bit registers and stack frame. */
+#define MAX_BPF_REG	__MAX_BPF_REG
+
+struct bpf_insn {
+	__u8	code;		/* opcode */
+	__u8	dst_reg:4;	/* dest register */
+	__u8	src_reg:4;	/* source register */
+	__s16	off;		/* signed offset */
+	__s32	imm;		/* signed immediate constant */
+};
+
+/* BPF syscall commands, see bpf(2) man-page for details. */
+enum bpf_cmd {
+	BPF_MAP_CREATE,
+	BPF_MAP_LOOKUP_ELEM,
+	BPF_MAP_UPDATE_ELEM,
+	BPF_MAP_DELETE_ELEM,
+	BPF_MAP_GET_NEXT_KEY,
+	BPF_PROG_LOAD,
+	BPF_OBJ_PIN,
+	BPF_OBJ_GET,
+};
+
+enum bpf_map_type {
+	BPF_MAP_TYPE_UNSPEC,
+	BPF_MAP_TYPE_HASH,
+	BPF_MAP_TYPE_ARRAY,
+	BPF_MAP_TYPE_PROG_ARRAY,
+	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
+};
+
+enum bpf_prog_type {
+	BPF_PROG_TYPE_UNSPEC,
+	BPF_PROG_TYPE_SOCKET_FILTER,
+	BPF_PROG_TYPE_KPROBE,
+	BPF_PROG_TYPE_SCHED_CLS,
+	BPF_PROG_TYPE_SCHED_ACT,
+};
+
+#define BPF_PSEUDO_MAP_FD	1
+
+/* flags for BPF_MAP_UPDATE_ELEM command */
+#define BPF_ANY		0 /* create new element or update existing */
+#define BPF_NOEXIST	1 /* create new element if it didn't exist */
+#define BPF_EXIST	2 /* update existing element */
+
+union bpf_attr {
+	struct { /* anonymous struct used by BPF_MAP_CREATE command */
+		__u32	map_type;	/* one of enum bpf_map_type */
+		__u32	key_size;	/* size of key in bytes */
+		__u32	value_size;	/* size of value in bytes */
+		__u32	max_entries;	/* max number of entries in a map */
+	};
+
+	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
+		__u32		map_fd;
+		__aligned_u64	key;
+		union {
+			__aligned_u64 value;
+			__aligned_u64 next_key;
+		};
+		__u64		flags;
+	};
+
+	struct { /* anonymous struct used by BPF_PROG_LOAD command */
+		__u32		prog_type;	/* one of enum bpf_prog_type */
+		__u32		insn_cnt;
+		__aligned_u64	insns;
+		__aligned_u64	license;
+		__u32		log_level;	/* verbosity level of verifier */
+		__u32		log_size;	/* size of user buffer */
+		__aligned_u64	log_buf;	/* user supplied buffer */
+		__u32		kern_version;	/* checked when prog_type=kprobe */
+	};
+
+	struct { /* anonymous struct used by BPF_OBJ_* commands */
+		__aligned_u64	pathname;
+		__u32		bpf_fd;
+	};
+} __attribute__((aligned(8)));
+
+/* integer value in 'imm' field of BPF_CALL instruction selects which helper
+ * function eBPF program intends to call
+ */
+enum bpf_func_id {
+	BPF_FUNC_unspec,
+	BPF_FUNC_map_lookup_elem, /* void *map_lookup_elem(&map, &key) */
+	BPF_FUNC_map_update_elem, /* int map_update_elem(&map, &key, &value, flags) */
+	BPF_FUNC_map_delete_elem, /* int map_delete_elem(&map, &key) */
+	BPF_FUNC_probe_read,      /* int bpf_probe_read(void *dst, int size, void *src) */
+	BPF_FUNC_ktime_get_ns,    /* u64 bpf_ktime_get_ns(void) */
+	BPF_FUNC_trace_printk,    /* int bpf_trace_printk(const char *fmt, int fmt_size, ...) */
+	BPF_FUNC_get_prandom_u32, /* u32 prandom_u32(void) */
+	BPF_FUNC_get_smp_processor_id, /* u32 raw_smp_processor_id(void) */
+
+	/**
+	 * skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet
+	 * @skb: pointer to skb
+	 * @offset: offset within packet from skb->mac_header
+	 * @from: pointer where to copy bytes from
+	 * @len: number of bytes to store into packet
+	 * @flags: bit 0 - if true, recompute skb->csum
+	 *         other bits - reserved
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_skb_store_bytes,
+
+	/**
+	 * l3_csum_replace(skb, offset, from, to, flags) - recompute IP checksum
+	 * @skb: pointer to skb
+	 * @offset: offset within packet where IP checksum is located
+	 * @from: old value of header field
+	 * @to: new value of header field
+	 * @flags: bits 0-3 - size of header field
+	 *         other bits - reserved
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_l3_csum_replace,
+
+	/**
+	 * l4_csum_replace(skb, offset, from, to, flags) - recompute TCP/UDP checksum
+	 * @skb: pointer to skb
+	 * @offset: offset within packet where TCP/UDP checksum is located
+	 * @from: old value of header field
+	 * @to: new value of header field
+	 * @flags: bits 0-3 - size of header field
+	 *         bit 4 - is pseudo header
+	 *         other bits - reserved
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_l4_csum_replace,
+
+	/**
+	 * bpf_tail_call(ctx, prog_array_map, index) - jump into another BPF program
+	 * @ctx: context pointer passed to next program
+	 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
+	 * @index: index inside array that selects specific program to run
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_tail_call,
+
+	/**
+	 * bpf_clone_redirect(skb, ifindex, flags) - redirect to another netdev
+	 * @skb: pointer to skb
+	 * @ifindex: ifindex of the net device
+	 * @flags: bit 0 - if set, redirect to ingress instead of egress
+	 *         other bits - reserved
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_clone_redirect,
+
+	/**
+	 * u64 bpf_get_current_pid_tgid(void)
+	 * Return: current->tgid << 32 | current->pid
+	 */
+	BPF_FUNC_get_current_pid_tgid,
+
+	/**
+	 * u64 bpf_get_current_uid_gid(void)
+	 * Return: current_gid << 32 | current_uid
+	 */
+	BPF_FUNC_get_current_uid_gid,
+
+	/**
+	 * bpf_get_current_comm(char *buf, int size_of_buf)
+	 * stores current->comm into buf
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_get_current_comm,
+
+	/**
+	 * bpf_get_cgroup_classid(skb) - retrieve a proc's classid
+	 * @skb: pointer to skb
+	 * Return: classid if != 0
+	 */
+	BPF_FUNC_get_cgroup_classid,
+	BPF_FUNC_skb_vlan_push, /* bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) */
+	BPF_FUNC_skb_vlan_pop,  /* bpf_skb_vlan_pop(skb) */
+
+	/**
+	 * bpf_skb_[gs]et_tunnel_key(skb, key, size, flags)
+	 * retrieve or populate tunnel metadata
+	 * @skb: pointer to skb
+	 * @key: pointer to 'struct bpf_tunnel_key'
+	 * @size: size of 'struct bpf_tunnel_key'
+	 * @flags: room for future extensions
+	 * Retrun: 0 on success
+	 */
+	BPF_FUNC_skb_get_tunnel_key,
+	BPF_FUNC_skb_set_tunnel_key,
+	BPF_FUNC_perf_event_read,	/* u64 bpf_perf_event_read(&map, index) */
+	/**
+	 * bpf_redirect(ifindex, flags) - redirect to another netdev
+	 * @ifindex: ifindex of the net device
+	 * @flags: bit 0 - if set, redirect to ingress instead of egress
+	 *         other bits - reserved
+	 * Return: TC_ACT_REDIRECT
+	 */
+	BPF_FUNC_redirect,
+
+	/**
+	 * bpf_get_route_realm(skb) - retrieve a dst's tclassid
+	 * @skb: pointer to skb
+	 * Return: realm if != 0
+	 */
+	BPF_FUNC_get_route_realm,
+
+	/**
+	 * bpf_perf_event_output(ctx, map, index, data, size) - output perf raw sample
+	 * @ctx: struct pt_regs*
+	 * @map: pointer to perf_event_array map
+	 * @index: index of event in the map
+	 * @data: data on stack to be output as raw data
+	 * @size: size of data
+	 * Return: 0 on success
+	 */
+	BPF_FUNC_perf_event_output,
+	BPF_FUNC_skb_load_bytes,
+	__BPF_FUNC_MAX_ID,
+};
+
+/* All flags used by eBPF helper functions, placed here. */
+
+/* BPF_FUNC_skb_store_bytes flags. */
+#define BPF_F_RECOMPUTE_CSUM		(1ULL << 0)
+
+/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
+ * First 4 bits are for passing the header field size.
+ */
+#define BPF_F_HDR_FIELD_MASK		0xfULL
+
+/* BPF_FUNC_l4_csum_replace flags. */
+#define BPF_F_PSEUDO_HDR		(1ULL << 4)
+
+/* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
+#define BPF_F_INGRESS			(1ULL << 0)
+
+/* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
+#define BPF_F_TUNINFO_IPV6		(1ULL << 0)
+
+/* user accessible mirror of in-kernel sk_buff.
+ * new fields can only be added to the end of this structure
+ */
+struct __sk_buff {
+	__u32 len;
+	__u32 pkt_type;
+	__u32 mark;
+	__u32 queue_mapping;
+	__u32 protocol;
+	__u32 vlan_present;
+	__u32 vlan_tci;
+	__u32 vlan_proto;
+	__u32 priority;
+	__u32 ingress_ifindex;
+	__u32 ifindex;
+	__u32 tc_index;
+	__u32 cb[5];
+	__u32 hash;
+	__u32 tc_classid;
+};
+
+struct bpf_tunnel_key {
+	__u32 tunnel_id;
+	union {
+		__u32 remote_ipv4;
+		__u32 remote_ipv6[4];
+	};
+	__u8 tunnel_tos;
+	__u8 tunnel_ttl;
+};
+
+#endif /* __LINUX_BPF_H__ */
diff --git a/include/uapi/linux/bpf_common.h b/include/linux/bpf_common.h
similarity index 85%
rename from include/uapi/linux/bpf_common.h
rename to include/linux/bpf_common.h
index f0fe139..afe7433 100644
--- a/include/uapi/linux/bpf_common.h
+++ b/include/linux/bpf_common.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_BPF_COMMON_H__
 #define __LINUX_BPF_COMMON_H__
 
@@ -15,10 +14,9 @@
 
 /* ld/ldx fields */
 #define BPF_SIZE(code)  ((code) & 0x18)
-#define		BPF_W		0x00 /* 32-bit */
-#define		BPF_H		0x08 /* 16-bit */
-#define		BPF_B		0x10 /*  8-bit */
-/* eBPF		BPF_DW		0x18    64-bit */
+#define		BPF_W		0x00
+#define		BPF_H		0x08
+#define		BPF_B		0x10
 #define BPF_MODE(code)  ((code) & 0xe0)
 #define		BPF_IMM		0x00
 #define		BPF_ABS		0x20
diff --git a/include/uapi/linux/can.h b/include/linux/can.h
similarity index 92%
rename from include/uapi/linux/can.h
rename to include/linux/can.h
index 55b6660..4af39b0 100644
--- a/include/uapi/linux/can.h
+++ b/include/linux/can.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */
 /*
  * linux/can.h
  *
@@ -77,7 +76,7 @@
 /*
  * Controller Area Network Error Message Frame Mask structure
  *
- * bit 0-28	: error class mask (see include/uapi/linux/can/error.h)
+ * bit 0-28	: error class mask (see include/linux/can/error.h)
  * bit 29-31	: set to zero
  */
 typedef __u32 can_err_mask_t;
@@ -157,8 +156,7 @@
 #define CAN_TP20	4 /* VAG Transport Protocol v2.0 */
 #define CAN_MCNET	5 /* Bosch MCNet */
 #define CAN_ISOTP	6 /* ISO 15765-2 Transport Protocol */
-#define CAN_J1939	7 /* SAE J1939 */
-#define CAN_NPROTO	8
+#define CAN_NPROTO	7
 
 #define SOL_CAN_BASE 100
 
@@ -175,23 +173,6 @@
 		/* transport protocol class address information (e.g. ISOTP) */
 		struct { canid_t rx_id, tx_id; } tp;
 
-		/* J1939 address information */
-		struct {
-			/* 8 byte name when using dynamic addressing */
-			__u64 name;
-
-			/* pgn:
-			 * 8 bit: PS in PDU2 case, else 0
-			 * 8 bit: PF
-			 * 1 bit: DP
-			 * 1 bit: reserved
-			 */
-			__u32 pgn;
-
-			/* 1 byte address */
-			__u8 addr;
-		} j1939;
-
 		/* reserved for future CAN protocols address information */
 	} can_addr;
 };
@@ -215,6 +196,5 @@
 };
 
 #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
-#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
 
 #endif /* !_UAPI_CAN_H */
diff --git a/include/uapi/linux/can/netlink.h b/include/linux/can/netlink.h
similarity index 88%
rename from include/uapi/linux/can/netlink.h
rename to include/linux/can/netlink.h
index 7159dc6..6d4ec2a 100644
--- a/include/uapi/linux/can/netlink.h
+++ b/include/linux/can/netlink.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
 /*
  * linux/can/netlink.h
  *
@@ -40,15 +39,15 @@
 };
 
 /*
- * CAN hardware-dependent bit-timing constant
+ * CAN harware-dependent bit-timing constant
  *
  * Used for calculating and checking bit-timing parameters
  */
 struct can_bittiming_const {
 	char name[16];		/* Name of the CAN controller hardware */
-	__u32 tseg1_min;	/* Time segment 1 = prop_seg + phase_seg1 */
+	__u32 tseg1_min;	/* Time segement 1 = prop_seg + phase_seg1 */
 	__u32 tseg1_max;
-	__u32 tseg2_min;	/* Time segment 2 = phase_seg2 */
+	__u32 tseg2_min;	/* Time segement 2 = phase_seg2 */
 	__u32 tseg2_max;
 	__u32 sjw_max;		/* Synchronisation jump width */
 	__u32 brp_min;		/* Bit-rate prescaler */
@@ -128,17 +127,9 @@
 	IFLA_CAN_BERR_COUNTER,
 	IFLA_CAN_DATA_BITTIMING,
 	IFLA_CAN_DATA_BITTIMING_CONST,
-	IFLA_CAN_TERMINATION,
-	IFLA_CAN_TERMINATION_CONST,
-	IFLA_CAN_BITRATE_CONST,
-	IFLA_CAN_DATA_BITRATE_CONST,
-	IFLA_CAN_BITRATE_MAX,
 	__IFLA_CAN_MAX
 };
 
 #define IFLA_CAN_MAX	(__IFLA_CAN_MAX - 1)
 
-/* u16 termination range: 1..65535 Ohms */
-#define CAN_TERMINATION_DISABLED 0
-
 #endif /* !_UAPI_CAN_NETLINK_H */
diff --git a/include/uapi/linux/fib_rules.h b/include/linux/fib_rules.h
similarity index 85%
rename from include/uapi/linux/fib_rules.h
rename to include/linux/fib_rules.h
index 232df14..bbf02a6 100644
--- a/include/uapi/linux/fib_rules.h
+++ b/include/linux/fib_rules.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_FIB_RULES_H
 #define __LINUX_FIB_RULES_H
 
@@ -23,7 +22,7 @@
 	__u8		tos;
 
 	__u8		table;
-	__u8		res1;   /* reserved */
+	__u8		res1;	/* reserved */
 	__u8		res2;	/* reserved */
 	__u8		action;
 
@@ -35,11 +34,6 @@
 	__u32		end;
 };
 
-struct fib_rule_port_range {
-	__u16		start;
-	__u16		end;
-};
-
 enum {
 	FRA_UNSPEC,
 	FRA_DST,	/* destination address */
@@ -63,10 +57,6 @@
 	FRA_PAD,
 	FRA_L3MDEV,	/* iif or oif is l3mdev goto its table */
 	FRA_UID_RANGE,	/* UID range */
-	FRA_PROTOCOL,   /* Originator of the rule */
-	FRA_IP_PROTO,	/* ip proto */
-	FRA_SPORT_RANGE, /* sport */
-	FRA_DPORT_RANGE, /* dport */
 	__FRA_MAX
 };
 
diff --git a/include/uapi/linux/filter.h b/include/linux/filter.h
similarity index 96%
rename from include/uapi/linux/filter.h
rename to include/linux/filter.h
index eaef459..e4f2f74 100644
--- a/include/uapi/linux/filter.h
+++ b/include/linux/filter.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /*
  * Linux Socket Filter Data Structures
  */
diff --git a/include/uapi/linux/fou.h b/include/linux/fou.h
similarity index 70%
rename from include/uapi/linux/fou.h
rename to include/linux/fou.h
index 9f91511..744c323 100644
--- a/include/uapi/linux/fou.h
+++ b/include/linux/fou.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* fou.h - FOU Interface */
 
 #ifndef _LINUX_FOU_H
@@ -16,12 +15,6 @@
 	FOU_ATTR_IPPROTO,			/* u8 */
 	FOU_ATTR_TYPE,				/* u8 */
 	FOU_ATTR_REMCSUM_NOPARTIAL,		/* flag */
-	FOU_ATTR_LOCAL_V4,			/* u32 */
-	FOU_ATTR_LOCAL_V6,			/* in6_addr */
-	FOU_ATTR_PEER_V4,			/* u32 */
-	FOU_ATTR_PEER_V6,			/* in6_addr */
-	FOU_ATTR_PEER_PORT,			/* u16 */
-	FOU_ATTR_IFINDEX,			/* s32 */
 
 	__FOU_ATTR_MAX,
 };
diff --git a/include/uapi/linux/gen_stats.h b/include/linux/gen_stats.h
similarity index 93%
rename from include/uapi/linux/gen_stats.h
rename to include/linux/gen_stats.h
index 065408e..6487317 100644
--- a/include/uapi/linux/gen_stats.h
+++ b/include/linux/gen_stats.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_GEN_STATS_H
 #define __LINUX_GEN_STATS_H
 
@@ -11,8 +10,6 @@
 	TCA_STATS_QUEUE,
 	TCA_STATS_APP,
 	TCA_STATS_RATE_EST64,
-	TCA_STATS_PAD,
-	TCA_STATS_BASIC_HW,
 	__TCA_STATS_MAX,
 };
 #define TCA_STATS_MAX (__TCA_STATS_MAX - 1)
diff --git a/include/uapi/linux/genetlink.h b/include/linux/genetlink.h
similarity index 90%
rename from include/uapi/linux/genetlink.h
rename to include/linux/genetlink.h
index 1317119..8a1d500 100644
--- a/include/uapi/linux/genetlink.h
+++ b/include/linux/genetlink.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_GENERIC_NETLINK_H
 #define __LINUX_GENERIC_NETLINK_H
 
@@ -22,16 +21,14 @@
 #define GENL_CMD_CAP_DO		0x02
 #define GENL_CMD_CAP_DUMP	0x04
 #define GENL_CMD_CAP_HASPOL	0x08
-#define GENL_UNS_ADMIN_PERM	0x10
 
 /*
  * List of reserved static generic netlink identifiers:
  */
+#define GENL_ID_GENERATE	0
 #define GENL_ID_CTRL		NLMSG_MIN_TYPE
 #define GENL_ID_VFS_DQUOT	(NLMSG_MIN_TYPE + 1)
 #define GENL_ID_PMCRAID		(NLMSG_MIN_TYPE + 2)
-/* must be last reserved + 1 */
-#define GENL_START_ALLOC	(NLMSG_MIN_TYPE + 3)
 
 /**************************************************************************
  * Controller
diff --git a/include/uapi/linux/hdlc/ioctl.h b/include/linux/hdlc/ioctl.h
similarity index 97%
rename from include/uapi/linux/hdlc/ioctl.h
rename to include/linux/hdlc/ioctl.h
index 0fe4238..04bc027 100644
--- a/include/uapi/linux/hdlc/ioctl.h
+++ b/include/linux/hdlc/ioctl.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __HDLC_IOCTL_H__
 #define __HDLC_IOCTL_H__
 
diff --git a/include/uapi/linux/if.h b/include/linux/if.h
similarity index 86%
rename from include/uapi/linux/if.h
rename to include/linux/if.h
index 495cdd2..a55a9e0 100644
--- a/include/uapi/linux/if.h
+++ b/include/linux/if.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * INET		An implementation of the TCP/IP protocol suite for the LINUX
  *		operating system.  INET is implemented using the  BSD Socket
@@ -20,22 +19,14 @@
 #ifndef _LINUX_IF_H
 #define _LINUX_IF_H
 
-#include <linux/libc-compat.h>          /* for compatibility with glibc */
 #include <linux/types.h>		/* for "__kernel_caddr_t" et al	*/
 #include <linux/socket.h>		/* for "struct sockaddr" et al	*/
 		/* for "__user" et al           */
 
-#include <sys/socket.h>			/* for struct sockaddr.		*/
-
-#if __UAPI_DEF_IF_IFNAMSIZ
 #define	IFNAMSIZ	16
-#endif /* __UAPI_DEF_IF_IFNAMSIZ */
 #define	IFALIASZ	256
 #include <linux/hdlc/ioctl.h>
 
-/* For glibc compatibility. An empty enum does not compile. */
-#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || \
-    __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
 /**
  * enum net_device_flags - &struct net_device flags
  *
@@ -46,7 +37,7 @@
  * are shared for all types of net_devices. The sysfs entries are available
  * via /sys/class/net/<dev>/flags. Flags which can be toggled through sysfs
  * are annotated below, note that only a few flags can be toggled and some
- * other flags are always preserved from the original net_device flags
+ * other flags are always always preserved from the original net_device flags
  * even if you try to set them via sysfs. Flags which are always preserved
  * are kept under the flag grouping @IFF_VOLATILE. Flags which are __volatile__
  * are annotated below as such.
@@ -77,8 +68,6 @@
  * @IFF_ECHO: echo sent packets. Volatile.
  */
 enum net_device_flags {
-/* for compatibility with glibc net/if.h */
-#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
 	IFF_UP				= 1<<0,  /* sysfs */
 	IFF_BROADCAST			= 1<<1,  /* __volatile__ */
 	IFF_DEBUG			= 1<<2,  /* sysfs */
@@ -95,17 +84,11 @@
 	IFF_PORTSEL			= 1<<13, /* sysfs */
 	IFF_AUTOMEDIA			= 1<<14, /* sysfs */
 	IFF_DYNAMIC			= 1<<15, /* sysfs */
-#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
-#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
 	IFF_LOWER_UP			= 1<<16, /* __volatile__ */
 	IFF_DORMANT			= 1<<17, /* __volatile__ */
 	IFF_ECHO			= 1<<18, /* __volatile__ */
-#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
 };
-#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0 */
 
-/* for compatibility with glibc net/if.h */
-#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
 #define IFF_UP				IFF_UP
 #define IFF_BROADCAST			IFF_BROADCAST
 #define IFF_DEBUG			IFF_DEBUG
@@ -122,13 +105,9 @@
 #define IFF_PORTSEL			IFF_PORTSEL
 #define IFF_AUTOMEDIA			IFF_AUTOMEDIA
 #define IFF_DYNAMIC			IFF_DYNAMIC
-#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
-
-#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
 #define IFF_LOWER_UP			IFF_LOWER_UP
 #define IFF_DORMANT			IFF_DORMANT
 #define IFF_ECHO			IFF_ECHO
-#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
 
 #define IFF_VOLATILE	(IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
 		IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
@@ -187,8 +166,6 @@
  *	being very small might be worth keeping for clean configuration.
  */
 
-/* for compatibility with glibc net/if.h */
-#if __UAPI_DEF_IF_IFMAP
 struct ifmap {
 	unsigned long mem_start;
 	unsigned long mem_end;
@@ -198,7 +175,6 @@
 	unsigned char port;
 	/* 3 bytes spare */
 };
-#endif /* __UAPI_DEF_IF_IFMAP */
 
 struct if_settings {
 	unsigned int type;	/* Type of physical device or protocol */
@@ -224,8 +200,6 @@
  * remainder may be interface specific.
  */
 
-/* for compatibility with glibc net/if.h */
-#if __UAPI_DEF_IF_IFREQ
 struct ifreq {
 #define IFHWADDRLEN	6
 	union
@@ -249,7 +223,6 @@
 		struct	if_settings ifru_settings;
 	} ifr_ifru;
 };
-#endif /* __UAPI_DEF_IF_IFREQ */
 
 #define ifr_name	ifr_ifrn.ifrn_name	/* interface name 	*/
 #define ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address 		*/
@@ -276,8 +249,6 @@
  * must know all networks accessible).
  */
 
-/* for compatibility with glibc net/if.h */
-#if __UAPI_DEF_IF_IFCONF
 struct ifconf  {
 	int	ifc_len;			/* size of buffer	*/
 	union {
@@ -285,8 +256,6 @@
 		struct ifreq *ifcu_req;
 	} ifc_ifcu;
 };
-#endif /* __UAPI_DEF_IF_IFCONF */
-
 #define	ifc_buf	ifc_ifcu.ifcu_buf		/* buffer address	*/
 #define	ifc_req	ifc_ifcu.ifcu_req		/* array of structures	*/
 
diff --git a/include/uapi/linux/if_addr.h b/include/linux/if_addr.h
similarity index 91%
rename from include/uapi/linux/if_addr.h
rename to include/linux/if_addr.h
index c4dd87f..26f0ecf 100644
--- a/include/uapi/linux/if_addr.h
+++ b/include/linux/if_addr.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_IF_ADDR_H
 #define __LINUX_IF_ADDR_H
 
@@ -33,8 +32,6 @@
 	IFA_CACHEINFO,
 	IFA_MULTICAST,
 	IFA_FLAGS,
-	IFA_RT_PRIORITY,  /* u32, priority/metric for prefix route */
-	IFA_TARGET_NETNSID,
 	__IFA_MAX,
 };
 
diff --git a/include/uapi/linux/if_addrlabel.h b/include/linux/if_addrlabel.h
similarity index 91%
rename from include/uapi/linux/if_addrlabel.h
rename to include/linux/if_addrlabel.h
index d1f5974..54580c2 100644
--- a/include/uapi/linux/if_addrlabel.h
+++ b/include/linux/if_addrlabel.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /*
  * if_addrlabel.h - netlink interface for address labels
  *
diff --git a/include/uapi/linux/if_arp.h b/include/linux/if_arp.h
similarity index 90%
rename from include/uapi/linux/if_arp.h
rename to include/linux/if_arp.h
index dbfbc22..d001bdb 100644
--- a/include/uapi/linux/if_arp.h
+++ b/include/linux/if_arp.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * INET		An implementation of the TCP/IP protocol suite for the LINUX
  *		operating system.  INET is implemented using the  BSD Socket
@@ -60,7 +59,6 @@
 #define ARPHRD_LAPB	516		/* LAPB				*/
 #define ARPHRD_DDCMP    517		/* Digital's DDCMP protocol     */
 #define ARPHRD_RAWHDLC	518		/* Raw HDLC			*/
-#define ARPHRD_RAWIP    519		/* Raw IP                       */
 
 #define ARPHRD_TUNNEL	768		/* IPIP tunnel			*/
 #define ARPHRD_TUNNEL6	769		/* IP6IP6 tunnel       		*/
@@ -97,7 +95,6 @@
 #define ARPHRD_IP6GRE	823		/* GRE over IPv6		*/
 #define ARPHRD_NETLINK	824		/* Netlink header		*/
 #define ARPHRD_6LOWPAN	825		/* IPv6 over LoWPAN             */
-#define ARPHRD_VSOCKMON	826		/* Vsock monitor header		*/
 
 #define ARPHRD_VOID	  0xFFFF	/* Void type, nothing is known */
 #define ARPHRD_NONE	  0xFFFE	/* zero header length */
@@ -114,18 +111,18 @@
 
 /* ARP ioctl request. */
 struct arpreq {
-	struct sockaddr	arp_pa;		/* protocol address		 */
-	struct sockaddr	arp_ha;		/* hardware address		 */
-	int		arp_flags;	/* flags			 */
-	struct sockaddr arp_netmask;    /* netmask (only for proxy arps) */
-	char		arp_dev[IFNAMSIZ];
+  struct sockaddr	arp_pa;		/* protocol address		*/
+  struct sockaddr	arp_ha;		/* hardware address		*/
+  int			arp_flags;	/* flags			*/
+  struct sockaddr       arp_netmask;    /* netmask (only for proxy arps) */
+  char			arp_dev[16];
 };
 
 struct arpreq_old {
-	struct sockaddr	arp_pa;		/* protocol address		 */
-	struct sockaddr	arp_ha;		/* hardware address		 */
-	int		arp_flags;	/* flags			 */
-	struct sockaddr	arp_netmask;    /* netmask (only for proxy arps) */
+  struct sockaddr	arp_pa;		/* protocol address		*/
+  struct sockaddr	arp_ha;		/* hardware address		*/
+  int			arp_flags;	/* flags			*/
+  struct sockaddr       arp_netmask;    /* netmask (only for proxy arps) */
 };
 
 /* ARP Flag values. */
diff --git a/include/uapi/linux/if_bridge.h b/include/linux/if_bridge.h
similarity index 62%
rename from include/uapi/linux/if_bridge.h
rename to include/linux/if_bridge.h
index 31fc51b..ee197a3 100644
--- a/include/uapi/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  *	Linux ethernet bridge
  *
@@ -119,7 +118,6 @@
 	IFLA_BRIDGE_FLAGS,
 	IFLA_BRIDGE_MODE,
 	IFLA_BRIDGE_VLAN_INFO,
-	IFLA_BRIDGE_VLAN_TUNNEL_INFO,
 	__IFLA_BRIDGE_MAX,
 };
 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
@@ -136,40 +134,14 @@
 	__u16 vid;
 };
 
-enum {
-	IFLA_BRIDGE_VLAN_TUNNEL_UNSPEC,
-	IFLA_BRIDGE_VLAN_TUNNEL_ID,
-	IFLA_BRIDGE_VLAN_TUNNEL_VID,
-	IFLA_BRIDGE_VLAN_TUNNEL_FLAGS,
-	__IFLA_BRIDGE_VLAN_TUNNEL_MAX,
-};
-
-#define IFLA_BRIDGE_VLAN_TUNNEL_MAX (__IFLA_BRIDGE_VLAN_TUNNEL_MAX - 1)
-
-struct bridge_vlan_xstats {
-	__u64 rx_bytes;
-	__u64 rx_packets;
-	__u64 tx_bytes;
-	__u64 tx_packets;
-	__u16 vid;
-	__u16 flags;
-	__u32 pad2;
-};
-
 /* Bridge multicast database attributes
  * [MDBA_MDB] = {
  *     [MDBA_MDB_ENTRY] = {
- *         [MDBA_MDB_ENTRY_INFO] {
- *		struct br_mdb_entry
- *		[MDBA_MDB_EATTR attributes]
- *         }
+ *         [MDBA_MDB_ENTRY_INFO]
  *     }
  * }
  * [MDBA_ROUTER] = {
- *    [MDBA_ROUTER_PORT] = {
- *        u32 ifindex
- *        [MDBA_ROUTER_PATTR attributes]
- *    }
+ *    [MDBA_ROUTER_PORT]
  * }
  */
 enum {
@@ -194,22 +166,6 @@
 };
 #define MDBA_MDB_ENTRY_MAX (__MDBA_MDB_ENTRY_MAX - 1)
 
-/* per mdb entry additional attributes */
-enum {
-	MDBA_MDB_EATTR_UNSPEC,
-	MDBA_MDB_EATTR_TIMER,
-	__MDBA_MDB_EATTR_MAX
-};
-#define MDBA_MDB_EATTR_MAX (__MDBA_MDB_EATTR_MAX - 1)
-
-/* multicast router types */
-enum {
-	MDB_RTR_TYPE_DISABLED,
-	MDB_RTR_TYPE_TEMP_QUERY,
-	MDB_RTR_TYPE_PERM,
-	MDB_RTR_TYPE_TEMP
-};
-
 enum {
 	MDBA_ROUTER_UNSPEC,
 	MDBA_ROUTER_PORT,
@@ -217,15 +173,6 @@
 };
 #define MDBA_ROUTER_MAX (__MDBA_ROUTER_MAX - 1)
 
-/* router port attributes */
-enum {
-	MDBA_ROUTER_PATTR_UNSPEC,
-	MDBA_ROUTER_PATTR_TIMER,
-	MDBA_ROUTER_PATTR_TYPE,
-	__MDBA_ROUTER_PATTR_MAX
-};
-#define MDBA_ROUTER_PATTR_MAX (__MDBA_ROUTER_PATTR_MAX - 1)
-
 struct br_port_msg {
 	__u8  family;
 	__u32 ifindex;
@@ -236,9 +183,6 @@
 #define MDB_TEMPORARY 0
 #define MDB_PERMANENT 1
 	__u8 state;
-#define MDB_FLAGS_OFFLOAD	(1 << 0)
-#define MDB_FLAGS_FAST_LEAVE	(1 << 1)
-	__u8 flags;
 	__u16 vid;
 	struct {
 		union {
@@ -256,62 +200,4 @@
 };
 #define MDBA_SET_ENTRY_MAX (__MDBA_SET_ENTRY_MAX - 1)
 
-/* Embedded inside LINK_XSTATS_TYPE_BRIDGE */
-enum {
-	BRIDGE_XSTATS_UNSPEC,
-	BRIDGE_XSTATS_VLAN,
-	BRIDGE_XSTATS_MCAST,
-	BRIDGE_XSTATS_PAD,
-	__BRIDGE_XSTATS_MAX
-};
-#define BRIDGE_XSTATS_MAX (__BRIDGE_XSTATS_MAX - 1)
-
-enum {
-	BR_MCAST_DIR_RX,
-	BR_MCAST_DIR_TX,
-	BR_MCAST_DIR_SIZE
-};
-
-/* IGMP/MLD statistics */
-struct br_mcast_stats {
-	__u64 igmp_v1queries[BR_MCAST_DIR_SIZE];
-	__u64 igmp_v2queries[BR_MCAST_DIR_SIZE];
-	__u64 igmp_v3queries[BR_MCAST_DIR_SIZE];
-	__u64 igmp_leaves[BR_MCAST_DIR_SIZE];
-	__u64 igmp_v1reports[BR_MCAST_DIR_SIZE];
-	__u64 igmp_v2reports[BR_MCAST_DIR_SIZE];
-	__u64 igmp_v3reports[BR_MCAST_DIR_SIZE];
-	__u64 igmp_parse_errors;
-
-	__u64 mld_v1queries[BR_MCAST_DIR_SIZE];
-	__u64 mld_v2queries[BR_MCAST_DIR_SIZE];
-	__u64 mld_leaves[BR_MCAST_DIR_SIZE];
-	__u64 mld_v1reports[BR_MCAST_DIR_SIZE];
-	__u64 mld_v2reports[BR_MCAST_DIR_SIZE];
-	__u64 mld_parse_errors;
-
-	__u64 mcast_bytes[BR_MCAST_DIR_SIZE];
-	__u64 mcast_packets[BR_MCAST_DIR_SIZE];
-};
-
-/* bridge boolean options
- * BR_BOOLOPT_NO_LL_LEARN - disable learning from link-local packets
- *
- * IMPORTANT: if adding a new option do not forget to handle
- *            it in br_boolopt_toggle/get and bridge sysfs
- */
-enum br_boolopt_id {
-	BR_BOOLOPT_NO_LL_LEARN,
-	BR_BOOLOPT_MAX
-};
-
-/* struct br_boolopt_multi - change multiple bridge boolean options
- *
- * @optval: new option values (bit per option)
- * @optmask: options to change (bit per option)
- */
-struct br_boolopt_multi {
-	__u32 optval;
-	__u32 optmask;
-};
 #endif /* _LINUX_IF_BRIDGE_H */
diff --git a/include/uapi/linux/if_ether.h b/include/linux/if_ether.h
similarity index 85%
rename from include/uapi/linux/if_ether.h
rename to include/linux/if_ether.h
index 728c42d..bf278d6 100644
--- a/include/uapi/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * INET		An implementation of the TCP/IP protocol suite for the LINUX
  *		operating system.  INET is implemented using the  BSD Socket
@@ -30,16 +29,12 @@
  */
 
 #define ETH_ALEN	6		/* Octets in one ethernet addr	 */
-#define ETH_TLEN	2		/* Octets in ethernet type field */
 #define ETH_HLEN	14		/* Total octets in header.	 */
 #define ETH_ZLEN	60		/* Min. octets in frame sans FCS */
 #define ETH_DATA_LEN	1500		/* Max. octets in payload	 */
 #define ETH_FRAME_LEN	1514		/* Max. octets in frame sans FCS */
 #define ETH_FCS_LEN	4		/* Octets in the FCS		 */
 
-#define ETH_MIN_MTU	68		/* Min IPv4 MTU per RFC791	*/
-#define ETH_MAX_MTU	0xFFFFU		/* 65535, same as IP_MAX_MTU	*/
-
 /*
  *	These are the defined Ethernet Protocol ID's.
  */
@@ -48,7 +43,6 @@
 #define ETH_P_PUP	0x0200		/* Xerox PUP packet		*/
 #define ETH_P_PUPAT	0x0201		/* Xerox PUP Addr Trans packet	*/
 #define ETH_P_TSN	0x22F0		/* TSN (IEEE 1722) packet	*/
-#define ETH_P_ERSPAN2	0x22EB		/* ERSPAN version 2 (type III)	*/
 #define ETH_P_IP	0x0800		/* Internet Protocol packet	*/
 #define ETH_P_X25	0x0805		/* CCITT X.25			*/
 #define ETH_P_ARP	0x0806		/* Address Resolution packet	*/
@@ -69,7 +63,6 @@
 #define ETH_P_ATALK	0x809B		/* Appletalk DDP		*/
 #define ETH_P_AARP	0x80F3		/* Appletalk AARP		*/
 #define ETH_P_8021Q	0x8100          /* 802.1Q VLAN Extended Header  */
-#define ETH_P_ERSPAN	0x88BE		/* ERSPAN type II		*/
 #define ETH_P_IPX	0x8137		/* IPX over DIX			*/
 #define ETH_P_IPV6	0x86DD		/* IPv6 over bluebook		*/
 #define ETH_P_PAUSE	0x8808		/* IEEE Pause frames. See 802.3 31B */
@@ -89,29 +82,20 @@
 #define ETH_P_AOE	0x88A2		/* ATA over Ethernet		*/
 #define ETH_P_8021AD	0x88A8          /* 802.1ad Service VLAN		*/
 #define ETH_P_802_EX1	0x88B5		/* 802.1 Local Experimental 1.  */
-#define ETH_P_PREAUTH	0x88C7		/* 802.11 Preauthentication */
 #define ETH_P_TIPC	0x88CA		/* TIPC 			*/
-#define ETH_P_LLDP	0x88CC		/* Link Layer Discovery Protocol */
-#define ETH_P_MACSEC	0x88E5		/* 802.1ae MACsec */
 #define ETH_P_8021AH	0x88E7          /* 802.1ah Backbone Service Tag */
 #define ETH_P_MVRP	0x88F5          /* 802.1Q MVRP                  */
 #define ETH_P_1588	0x88F7		/* IEEE 1588 Timesync */
-#define ETH_P_NCSI	0x88F8		/* NCSI protocol		*/
 #define ETH_P_PRP	0x88FB		/* IEC 62439-3 PRP/HSRv0	*/
 #define ETH_P_FCOE	0x8906		/* Fibre Channel over Ethernet  */
-#define ETH_P_IBOE	0x8915		/* Infiniband over Ethernet	*/
 #define ETH_P_TDLS	0x890D          /* TDLS */
 #define ETH_P_FIP	0x8914		/* FCoE Initialization Protocol */
 #define ETH_P_80221	0x8917		/* IEEE 802.21 Media Independent Handover Protocol */
-#define ETH_P_HSR	0x892F		/* IEC 62439-3 HSRv1	*/
-#define ETH_P_NSH	0x894F		/* Network Service Header */
 #define ETH_P_LOOPBACK	0x9000		/* Ethernet loopback packet, per IEEE 802.3 */
 #define ETH_P_QINQ1	0x9100		/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_QINQ2	0x9200		/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_QINQ3	0x9300		/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_EDSA	0xDADA		/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
-#define ETH_P_DSA_8021Q	0xDADB		/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
-#define ETH_P_IFE	0xED3E		/* ForCES inter-FE LFB type */
 #define ETH_P_AF_IUCV   0xFBFB		/* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
 
 #define ETH_P_802_3_MIN	0x0600		/* If the value in the ethernet type is less than this value
@@ -146,26 +130,16 @@
 #define ETH_P_IEEE802154 0x00F6		/* IEEE802.15.4 frame		*/
 #define ETH_P_CAIF	0x00F7		/* ST-Ericsson CAIF protocol	*/
 #define ETH_P_XDSA	0x00F8		/* Multiplexed DSA protocol	*/
-#define ETH_P_MAP	0x00F9		/* Qualcomm multiplexing and
-					 * aggregation protocol
-					 */
 
 /*
  *	This is an Ethernet frame header.
  */
 
-/* allow libcs like musl to deactivate this, glibc does not implement this. */
-#ifndef __UAPI_DEF_ETHHDR
-#define __UAPI_DEF_ETHHDR		1
-#endif
-
-#if __UAPI_DEF_ETHHDR
 struct ethhdr {
 	unsigned char	h_dest[ETH_ALEN];	/* destination eth addr	*/
 	unsigned char	h_source[ETH_ALEN];	/* source ether addr	*/
 	__be16		h_proto;		/* packet type ID field	*/
 } __attribute__((packed));
-#endif
 
 
 #endif /* _LINUX_IF_ETHER_H */
diff --git a/include/uapi/linux/if_link.h b/include/linux/if_link.h
similarity index 72%
rename from include/uapi/linux/if_link.h
rename to include/linux/if_link.h
index d36919f..d91f2c9 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _LINUX_IF_LINK_H
 #define _LINUX_IF_LINK_H
 
@@ -36,8 +35,6 @@
 	/* for cslip etc */
 	__u32	rx_compressed;
 	__u32	tx_compressed;
-
-	__u32	rx_nohandler;		/* dropped, no handler found	*/
 };
 
 /* The main device statistics structure */
@@ -71,8 +68,6 @@
 	/* for cslip etc */
 	__u64	rx_compressed;
 	__u64	tx_compressed;
-
-	__u64	rx_nohandler;		/* dropped, no handler found	*/
 };
 
 /* The struct should be in sync with struct ifmap */
@@ -154,19 +149,6 @@
 	IFLA_LINK_NETNSID,
 	IFLA_PHYS_PORT_NAME,
 	IFLA_PROTO_DOWN,
-	IFLA_GSO_MAX_SEGS,
-	IFLA_GSO_MAX_SIZE,
-	IFLA_PAD,
-	IFLA_XDP,
-	IFLA_EVENT,
-	IFLA_NEW_NETNSID,
-	IFLA_IF_NETNSID,
-	IFLA_TARGET_NETNSID = IFLA_IF_NETNSID, /* new alias */
-	IFLA_CARRIER_UP_COUNT,
-	IFLA_CARRIER_DOWN_COUNT,
-	IFLA_NEW_IFINDEX,
-	IFLA_MIN_MTU,
-	IFLA_MAX_MTU,
 	__IFLA_MAX
 };
 
@@ -280,13 +262,6 @@
 	IFLA_BR_NF_CALL_IP6TABLES,
 	IFLA_BR_NF_CALL_ARPTABLES,
 	IFLA_BR_VLAN_DEFAULT_PVID,
-	IFLA_BR_PAD,
-	IFLA_BR_VLAN_STATS_ENABLED,
-	IFLA_BR_MCAST_STATS_ENABLED,
-	IFLA_BR_MCAST_IGMP_VERSION,
-	IFLA_BR_MCAST_MLD_VERSION,
-	IFLA_BR_VLAN_STATS_PER_PORT,
-	IFLA_BR_MULTI_BOOLOPT,
 	__IFLA_BR_MAX,
 };
 
@@ -329,15 +304,6 @@
 	IFLA_BRPORT_HOLD_TIMER,
 	IFLA_BRPORT_FLUSH,
 	IFLA_BRPORT_MULTICAST_ROUTER,
-	IFLA_BRPORT_PAD,
-	IFLA_BRPORT_MCAST_FLOOD,
-	IFLA_BRPORT_MCAST_TO_UCAST,
-	IFLA_BRPORT_VLAN_TUNNEL,
-	IFLA_BRPORT_BCAST_FLOOD,
-	IFLA_BRPORT_GROUP_FWD_MASK,
-	IFLA_BRPORT_NEIGH_SUPPRESS,
-	IFLA_BRPORT_ISOLATED,
-	IFLA_BRPORT_BACKUP_PORT,
 	__IFLA_BRPORT_MAX
 };
 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
@@ -433,59 +399,10 @@
 
 #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1)
 
-enum {
-	IFLA_VRF_PORT_UNSPEC,
-	IFLA_VRF_PORT_TABLE,
-	__IFLA_VRF_PORT_MAX
-};
-
-#define IFLA_VRF_PORT_MAX (__IFLA_VRF_PORT_MAX - 1)
-
-/* MACSEC section */
-enum {
-	IFLA_MACSEC_UNSPEC,
-	IFLA_MACSEC_SCI,
-	IFLA_MACSEC_PORT,
-	IFLA_MACSEC_ICV_LEN,
-	IFLA_MACSEC_CIPHER_SUITE,
-	IFLA_MACSEC_WINDOW,
-	IFLA_MACSEC_ENCODING_SA,
-	IFLA_MACSEC_ENCRYPT,
-	IFLA_MACSEC_PROTECT,
-	IFLA_MACSEC_INC_SCI,
-	IFLA_MACSEC_ES,
-	IFLA_MACSEC_SCB,
-	IFLA_MACSEC_REPLAY_PROTECT,
-	IFLA_MACSEC_VALIDATION,
-	IFLA_MACSEC_PAD,
-	__IFLA_MACSEC_MAX,
-};
-
-#define IFLA_MACSEC_MAX (__IFLA_MACSEC_MAX - 1)
-
-/* XFRM section */
-enum {
-	IFLA_XFRM_UNSPEC,
-	IFLA_XFRM_LINK,
-	IFLA_XFRM_IF_ID,
-	__IFLA_XFRM_MAX
-};
-
-#define IFLA_XFRM_MAX (__IFLA_XFRM_MAX - 1)
-
-enum macsec_validation_type {
-	MACSEC_VALIDATE_DISABLED = 0,
-	MACSEC_VALIDATE_CHECK = 1,
-	MACSEC_VALIDATE_STRICT = 2,
-	__MACSEC_VALIDATE_END,
-	MACSEC_VALIDATE_MAX = __MACSEC_VALIDATE_END - 1,
-};
-
 /* IPVLAN section */
 enum {
 	IFLA_IPVLAN_UNSPEC,
 	IFLA_IPVLAN_MODE,
-	IFLA_IPVLAN_FLAGS,
 	__IFLA_IPVLAN_MAX
 };
 
@@ -494,13 +411,9 @@
 enum ipvlan_mode {
 	IPVLAN_MODE_L2 = 0,
 	IPVLAN_MODE_L3,
-	IPVLAN_MODE_L3S,
 	IPVLAN_MODE_MAX
 };
 
-#define IPVLAN_F_PRIVATE	0x01
-#define IPVLAN_F_VEPA		0x02
-
 /* VXLAN section */
 enum {
 	IFLA_VXLAN_UNSPEC,
@@ -529,10 +442,6 @@
 	IFLA_VXLAN_GBP,
 	IFLA_VXLAN_REMCSUM_NOPARTIAL,
 	IFLA_VXLAN_COLLECT_METADATA,
-	IFLA_VXLAN_LABEL,
-	IFLA_VXLAN_GPE,
-	IFLA_VXLAN_TTL_INHERIT,
-	IFLA_VXLAN_DF,
 	__IFLA_VXLAN_MAX
 };
 #define IFLA_VXLAN_MAX	(__IFLA_VXLAN_MAX - 1)
@@ -542,14 +451,6 @@
 	__be16	high;
 };
 
-enum ifla_vxlan_df {
-	VXLAN_DF_UNSET = 0,
-	VXLAN_DF_SET,
-	VXLAN_DF_INHERIT,
-	__VXLAN_DF_END,
-	VXLAN_DF_MAX = __VXLAN_DF_END - 1,
-};
-
 /* GENEVE section */
 enum {
 	IFLA_GENEVE_UNSPEC,
@@ -563,46 +464,10 @@
 	IFLA_GENEVE_UDP_CSUM,
 	IFLA_GENEVE_UDP_ZERO_CSUM6_TX,
 	IFLA_GENEVE_UDP_ZERO_CSUM6_RX,
-	IFLA_GENEVE_LABEL,
-	IFLA_GENEVE_TTL_INHERIT,
-	IFLA_GENEVE_DF,
 	__IFLA_GENEVE_MAX
 };
 #define IFLA_GENEVE_MAX	(__IFLA_GENEVE_MAX - 1)
 
-enum ifla_geneve_df {
-	GENEVE_DF_UNSET = 0,
-	GENEVE_DF_SET,
-	GENEVE_DF_INHERIT,
-	__GENEVE_DF_END,
-	GENEVE_DF_MAX = __GENEVE_DF_END - 1,
-};
-
-/* PPP section */
-enum {
-	IFLA_PPP_UNSPEC,
-	IFLA_PPP_DEV_FD,
-	__IFLA_PPP_MAX
-};
-#define IFLA_PPP_MAX (__IFLA_PPP_MAX - 1)
-
-/* GTP section */
-
-enum ifla_gtp_role {
-	GTP_ROLE_GGSN = 0,
-	GTP_ROLE_SGSN,
-};
-
-enum {
-	IFLA_GTP_UNSPEC,
-	IFLA_GTP_FD0,
-	IFLA_GTP_FD1,
-	IFLA_GTP_PDP_HASHSIZE,
-	IFLA_GTP_ROLE,
-	__IFLA_GTP_MAX,
-};
-#define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1)
-
 /* Bonding section */
 
 enum {
@@ -634,7 +499,6 @@
 	IFLA_BOND_AD_USER_PORT_KEY,
 	IFLA_BOND_AD_ACTOR_SYSTEM,
 	IFLA_BOND_TLB_DYNAMIC_LB,
-	IFLA_BOND_PEER_NOTIF_DELAY,
 	__IFLA_BOND_MAX,
 };
 
@@ -680,7 +544,7 @@
 enum {
 	IFLA_VF_UNSPEC,
 	IFLA_VF_MAC,		/* Hardware queue specific attributes */
-	IFLA_VF_VLAN,		/* VLAN ID and QoS */
+	IFLA_VF_VLAN,
 	IFLA_VF_TX_RATE,	/* Max TX Bandwidth Allocation */
 	IFLA_VF_SPOOFCHK,	/* Spoof Checking on/off switch */
 	IFLA_VF_LINK_STATE,	/* link state enable/disable/auto switch */
@@ -690,10 +554,6 @@
 				 */
 	IFLA_VF_STATS,		/* network device statistics */
 	IFLA_VF_TRUST,		/* Trust VF */
-	IFLA_VF_IB_NODE_GUID,	/* VF Infiniband node GUID */
-	IFLA_VF_IB_PORT_GUID,	/* VF Infiniband port GUID */
-	IFLA_VF_VLAN_LIST,	/* nested list of vlans, option for QinQ */
-	IFLA_VF_BROADCAST,	/* VF broadcast */
 	__IFLA_VF_MAX,
 };
 
@@ -704,32 +564,12 @@
 	__u8 mac[32]; /* MAX_ADDR_LEN */
 };
 
-struct ifla_vf_broadcast {
-	__u8 broadcast[32];
-};
-
 struct ifla_vf_vlan {
 	__u32 vf;
 	__u32 vlan; /* 0 - 4095, 0 disables VLAN filter */
 	__u32 qos;
 };
 
-enum {
-	IFLA_VF_VLAN_INFO_UNSPEC,
-	IFLA_VF_VLAN_INFO,	/* VLAN ID, QoS and VLAN protocol */
-	__IFLA_VF_VLAN_INFO_MAX,
-};
-
-#define IFLA_VF_VLAN_INFO_MAX (__IFLA_VF_VLAN_INFO_MAX - 1)
-#define MAX_VLAN_LIST_LEN 1
-
-struct ifla_vf_vlan_info {
-	__u32 vf;
-	__u32 vlan; /* 0 - 4095, 0 disables VLAN filter */
-	__u32 qos;
-	__be16 vlan_proto; /* VLAN protocol either 802.1Q or 802.1ad */
-};
-
 struct ifla_vf_tx_rate {
 	__u32 vf;
 	__u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */
@@ -746,11 +586,6 @@
 	__u32 setting;
 };
 
-struct ifla_vf_guid {
-	__u32 vf;
-	__u64 guid;
-};
-
 enum {
 	IFLA_VF_LINK_STATE_AUTO,	/* link state of the uplink */
 	IFLA_VF_LINK_STATE_ENABLE,	/* link always up */
@@ -775,9 +610,6 @@
 	IFLA_VF_STATS_TX_BYTES,
 	IFLA_VF_STATS_BROADCAST,
 	IFLA_VF_STATS_MULTICAST,
-	IFLA_VF_STATS_PAD,
-	IFLA_VF_STATS_RX_DROPPED,
-	IFLA_VF_STATS_TX_DROPPED,
 	__IFLA_VF_STATS_MAX,
 };
 
@@ -888,142 +720,9 @@
 	IFLA_HSR_MULTICAST_SPEC,	/* Last byte of supervision addr */
 	IFLA_HSR_SUPERVISION_ADDR,	/* Supervision frame multicast addr */
 	IFLA_HSR_SEQ_NR,
-	IFLA_HSR_VERSION,		/* HSR version */
 	__IFLA_HSR_MAX,
 };
 
 #define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1)
 
-/* STATS section */
-
-struct if_stats_msg {
-	__u8  family;
-	__u8  pad1;
-	__u16 pad2;
-	__u32 ifindex;
-	__u32 filter_mask;
-};
-
-/* A stats attribute can be netdev specific or a global stat.
- * For netdev stats, lets use the prefix IFLA_STATS_LINK_*
- */
-enum {
-	IFLA_STATS_UNSPEC, /* also used as 64bit pad attribute */
-	IFLA_STATS_LINK_64,
-	IFLA_STATS_LINK_XSTATS,
-	IFLA_STATS_LINK_XSTATS_SLAVE,
-	IFLA_STATS_LINK_OFFLOAD_XSTATS,
-	IFLA_STATS_AF_SPEC,
-	__IFLA_STATS_MAX,
-};
-
-#define IFLA_STATS_MAX (__IFLA_STATS_MAX - 1)
-
-#define IFLA_STATS_FILTER_BIT(ATTR)	(1 << (ATTR - 1))
-
-/* These are embedded into IFLA_STATS_LINK_XSTATS:
- * [IFLA_STATS_LINK_XSTATS]
- * -> [LINK_XSTATS_TYPE_xxx]
- *    -> [rtnl link type specific attributes]
- */
-enum {
-	LINK_XSTATS_TYPE_UNSPEC,
-	LINK_XSTATS_TYPE_BRIDGE,
-	LINK_XSTATS_TYPE_BOND,
-	__LINK_XSTATS_TYPE_MAX
-};
-#define LINK_XSTATS_TYPE_MAX (__LINK_XSTATS_TYPE_MAX - 1)
-
-/* These are stats embedded into IFLA_STATS_LINK_OFFLOAD_XSTATS */
-enum {
-	IFLA_OFFLOAD_XSTATS_UNSPEC,
-	IFLA_OFFLOAD_XSTATS_CPU_HIT, /* struct rtnl_link_stats64 */
-	__IFLA_OFFLOAD_XSTATS_MAX
-};
-#define IFLA_OFFLOAD_XSTATS_MAX (__IFLA_OFFLOAD_XSTATS_MAX - 1)
-
-/* XDP section */
-
-#define XDP_FLAGS_UPDATE_IF_NOEXIST	(1U << 0)
-#define XDP_FLAGS_SKB_MODE		(1U << 1)
-#define XDP_FLAGS_DRV_MODE		(1U << 2)
-#define XDP_FLAGS_HW_MODE		(1U << 3)
-#define XDP_FLAGS_MODES			(XDP_FLAGS_SKB_MODE | \
-					 XDP_FLAGS_DRV_MODE | \
-					 XDP_FLAGS_HW_MODE)
-#define XDP_FLAGS_MASK			(XDP_FLAGS_UPDATE_IF_NOEXIST | \
-					 XDP_FLAGS_MODES)
-
-/* These are stored into IFLA_XDP_ATTACHED on dump. */
-enum {
-	XDP_ATTACHED_NONE = 0,
-	XDP_ATTACHED_DRV,
-	XDP_ATTACHED_SKB,
-	XDP_ATTACHED_HW,
-	XDP_ATTACHED_MULTI,
-};
-
-enum {
-	IFLA_XDP_UNSPEC,
-	IFLA_XDP_FD,
-	IFLA_XDP_ATTACHED,
-	IFLA_XDP_FLAGS,
-	IFLA_XDP_PROG_ID,
-	IFLA_XDP_DRV_PROG_ID,
-	IFLA_XDP_SKB_PROG_ID,
-	IFLA_XDP_HW_PROG_ID,
-	__IFLA_XDP_MAX,
-};
-
-#define IFLA_XDP_MAX (__IFLA_XDP_MAX - 1)
-
-enum {
-	IFLA_EVENT_NONE,
-	IFLA_EVENT_REBOOT,		/* internal reset / reboot */
-	IFLA_EVENT_FEATURES,		/* change in offload features */
-	IFLA_EVENT_BONDING_FAILOVER,	/* change in active slave */
-	IFLA_EVENT_NOTIFY_PEERS,	/* re-sent grat. arp/ndisc */
-	IFLA_EVENT_IGMP_RESEND,		/* re-sent IGMP JOIN */
-	IFLA_EVENT_BONDING_OPTIONS,	/* change in bonding options */
-};
-
-/* tun section */
-
-enum {
-	IFLA_TUN_UNSPEC,
-	IFLA_TUN_OWNER,
-	IFLA_TUN_GROUP,
-	IFLA_TUN_TYPE,
-	IFLA_TUN_PI,
-	IFLA_TUN_VNET_HDR,
-	IFLA_TUN_PERSIST,
-	IFLA_TUN_MULTI_QUEUE,
-	IFLA_TUN_NUM_QUEUES,
-	IFLA_TUN_NUM_DISABLED_QUEUES,
-	__IFLA_TUN_MAX,
-};
-
-#define IFLA_TUN_MAX (__IFLA_TUN_MAX - 1)
-
-/* rmnet section */
-
-#define RMNET_FLAGS_INGRESS_DEAGGREGATION         (1U << 0)
-#define RMNET_FLAGS_INGRESS_MAP_COMMANDS          (1U << 1)
-#define RMNET_FLAGS_INGRESS_MAP_CKSUMV4           (1U << 2)
-#define RMNET_FLAGS_EGRESS_MAP_CKSUMV4            (1U << 3)
-
-enum {
-	IFLA_RMNET_UNSPEC,
-	IFLA_RMNET_MUX_ID,
-	IFLA_RMNET_FLAGS,
-	__IFLA_RMNET_MAX,
-};
-
-#define IFLA_RMNET_MAX	(__IFLA_RMNET_MAX - 1)
-
-struct ifla_rmnet_flags {
-	__u32	flags;
-	__u32	mask;
-};
-
 #endif /* _LINUX_IF_LINK_H */
diff --git a/include/uapi/linux/if_tun.h b/include/linux/if_tun.h
similarity index 92%
rename from include/uapi/linux/if_tun.h
rename to include/linux/if_tun.h
index 8489ae0..d5ecb42 100644
--- a/include/uapi/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  *  Universal TUN/TAP device driver.
  *  Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>
@@ -57,16 +56,10 @@
  */
 #define TUNSETVNETBE _IOW('T', 222, int)
 #define TUNGETVNETBE _IOR('T', 223, int)
-#define TUNSETSTEERINGEBPF _IOR('T', 224, int)
-#define TUNSETFILTEREBPF _IOR('T', 225, int)
-#define TUNSETCARRIER _IOW('T', 226, int)
-#define TUNGETDEVNETNS _IO('T', 227)
 
 /* TUNSETIFF ifr flags */
 #define IFF_TUN		0x0001
 #define IFF_TAP		0x0002
-#define IFF_NAPI	0x0010
-#define IFF_NAPI_FRAGS	0x0020
 #define IFF_NO_PI	0x1000
 /* This flag has no real effect */
 #define IFF_ONE_QUEUE	0x2000
diff --git a/include/uapi/linux/if_tunnel.h b/include/linux/if_tunnel.h
similarity index 63%
rename from include/uapi/linux/if_tunnel.h
rename to include/linux/if_tunnel.h
index c7f0a5e..f0201ca 100644
--- a/include/uapi/linux/if_tunnel.h
+++ b/include/linux/if_tunnel.h
@@ -1,11 +1,7 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _IF_TUNNEL_H_
 #define _IF_TUNNEL_H_
 
 #include <linux/types.h>
-#include <linux/if.h>
-#include <linux/ip.h>
-#include <linux/in6.h>
 #include <asm/byteorder.h>
 
 
@@ -28,23 +24,9 @@
 #define GRE_SEQ		__cpu_to_be16(0x1000)
 #define GRE_STRICT	__cpu_to_be16(0x0800)
 #define GRE_REC		__cpu_to_be16(0x0700)
-#define GRE_ACK		__cpu_to_be16(0x0080)
-#define GRE_FLAGS	__cpu_to_be16(0x0078)
+#define GRE_FLAGS	__cpu_to_be16(0x00F8)
 #define GRE_VERSION	__cpu_to_be16(0x0007)
 
-#define GRE_IS_CSUM(f)		((f) & GRE_CSUM)
-#define GRE_IS_ROUTING(f)	((f) & GRE_ROUTING)
-#define GRE_IS_KEY(f)		((f) & GRE_KEY)
-#define GRE_IS_SEQ(f)		((f) & GRE_SEQ)
-#define GRE_IS_STRICT(f)	((f) & GRE_STRICT)
-#define GRE_IS_REC(f)		((f) & GRE_REC)
-#define GRE_IS_ACK(f)		((f) & GRE_ACK)
-
-#define GRE_VERSION_0		__cpu_to_be16(0x0000)
-#define GRE_VERSION_1		__cpu_to_be16(0x0001)
-#define GRE_PROTO_PPP		__cpu_to_be16(0x880b)
-#define GRE_PPTP_KEY_MASK	__cpu_to_be32(0xffff)
-
 struct ip_tunnel_parm {
 	char			name[IFNAMSIZ];
 	int			link;
@@ -75,8 +57,6 @@
 	IFLA_IPTUN_ENCAP_FLAGS,
 	IFLA_IPTUN_ENCAP_SPORT,
 	IFLA_IPTUN_ENCAP_DPORT,
-	IFLA_IPTUN_COLLECT_METADATA,
-	IFLA_IPTUN_FWMARK,
 	__IFLA_IPTUN_MAX,
 };
 #define IFLA_IPTUN_MAX	(__IFLA_IPTUN_MAX - 1)
@@ -85,7 +65,6 @@
 	TUNNEL_ENCAP_NONE,
 	TUNNEL_ENCAP_FOU,
 	TUNNEL_ENCAP_GUE,
-	TUNNEL_ENCAP_MPLS,
 };
 
 #define TUNNEL_ENCAP_FLAG_CSUM		(1<<0)
@@ -134,12 +113,6 @@
 	IFLA_GRE_ENCAP_SPORT,
 	IFLA_GRE_ENCAP_DPORT,
 	IFLA_GRE_COLLECT_METADATA,
-	IFLA_GRE_IGNORE_DF,
-	IFLA_GRE_FWMARK,
-	IFLA_GRE_ERSPAN_INDEX,
-	IFLA_GRE_ERSPAN_VER,
-	IFLA_GRE_ERSPAN_DIR,
-	IFLA_GRE_ERSPAN_HWID,
 	__IFLA_GRE_MAX,
 };
 
@@ -155,29 +128,8 @@
 	IFLA_VTI_OKEY,
 	IFLA_VTI_LOCAL,
 	IFLA_VTI_REMOTE,
-	IFLA_VTI_FWMARK,
 	__IFLA_VTI_MAX,
 };
 
 #define IFLA_VTI_MAX	(__IFLA_VTI_MAX - 1)
-
-#define TUNNEL_CSUM		__cpu_to_be16(0x01)
-#define TUNNEL_ROUTING		__cpu_to_be16(0x02)
-#define TUNNEL_KEY		__cpu_to_be16(0x04)
-#define TUNNEL_SEQ		__cpu_to_be16(0x08)
-#define TUNNEL_STRICT		__cpu_to_be16(0x10)
-#define TUNNEL_REC		__cpu_to_be16(0x20)
-#define TUNNEL_VERSION		__cpu_to_be16(0x40)
-#define TUNNEL_NO_KEY		__cpu_to_be16(0x80)
-#define TUNNEL_DONT_FRAGMENT    __cpu_to_be16(0x0100)
-#define TUNNEL_OAM		__cpu_to_be16(0x0200)
-#define TUNNEL_CRIT_OPT		__cpu_to_be16(0x0400)
-#define TUNNEL_GENEVE_OPT	__cpu_to_be16(0x0800)
-#define TUNNEL_VXLAN_OPT	__cpu_to_be16(0x1000)
-#define TUNNEL_NOCACHE		__cpu_to_be16(0x2000)
-#define TUNNEL_ERSPAN_OPT	__cpu_to_be16(0x4000)
-
-#define TUNNEL_OPTIONS_PRESENT \
-		(TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT | TUNNEL_ERSPAN_OPT)
-
 #endif /* _IF_TUNNEL_H_ */
diff --git a/include/uapi/linux/if_vlan.h b/include/linux/if_vlan.h
similarity index 88%
rename from include/uapi/linux/if_vlan.h
rename to include/linux/if_vlan.h
index 04bca79..24ae007 100644
--- a/include/uapi/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * VLAN		An implementation of 802.1Q VLAN tagging.
  *
@@ -32,11 +31,10 @@
 };
 
 enum vlan_flags {
-	VLAN_FLAG_REORDER_HDR		= 0x1,
-	VLAN_FLAG_GVRP			= 0x2,
-	VLAN_FLAG_LOOSE_BINDING		= 0x4,
-	VLAN_FLAG_MVRP			= 0x8,
-	VLAN_FLAG_BRIDGE_BINDING	= 0x10,
+	VLAN_FLAG_REORDER_HDR	= 0x1,
+	VLAN_FLAG_GVRP		= 0x2,
+	VLAN_FLAG_LOOSE_BINDING	= 0x4,
+	VLAN_FLAG_MVRP		= 0x8,
 };
 
 enum vlan_name_types {
diff --git a/include/linux/ila.h b/include/linux/ila.h
new file mode 100644
index 0000000..4f9e1de
--- /dev/null
+++ b/include/linux/ila.h
@@ -0,0 +1,37 @@
+/* ila.h - ILA Interface */
+
+#ifndef _LINUX_ILA_H
+#define _LINUX_ILA_H
+
+/* NETLINK_GENERIC related info */
+#define ILA_GENL_NAME		"ila"
+#define ILA_GENL_VERSION	0x1
+
+enum {
+	ILA_ATTR_UNSPEC,
+	ILA_ATTR_LOCATOR,			/* u64 */
+	ILA_ATTR_IDENTIFIER,			/* u64 */
+	ILA_ATTR_LOCATOR_MATCH,			/* u64 */
+	ILA_ATTR_IFINDEX,			/* s32 */
+	ILA_ATTR_DIR,				/* u32 */
+
+	__ILA_ATTR_MAX,
+};
+
+#define ILA_ATTR_MAX		(__ILA_ATTR_MAX - 1)
+
+enum {
+	ILA_CMD_UNSPEC,
+	ILA_CMD_ADD,
+	ILA_CMD_DEL,
+	ILA_CMD_GET,
+
+	__ILA_CMD_MAX,
+};
+
+#define ILA_CMD_MAX	(__ILA_CMD_MAX - 1)
+
+#define ILA_DIR_IN	(1 << 0)
+#define ILA_DIR_OUT	(1 << 1)
+
+#endif /* _LINUX_ILA_H */
diff --git a/include/uapi/linux/in.h b/include/linux/in.h
similarity index 92%
rename from include/uapi/linux/in.h
rename to include/linux/in.h
index ac079ab..194b43b 100644
--- a/include/uapi/linux/in.h
+++ b/include/linux/in.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * INET		An implementation of the TCP/IP protocol suite for the LINUX
  *		operating system.  INET is implemented using the  BSD Socket
@@ -118,7 +117,6 @@
 #define IP_NODEFRAG     22
 #define IP_CHECKSUM	23
 #define IP_BIND_ADDRESS_NO_PORT	24
-#define IP_RECVFRAGSIZE	25
 
 /* IP_MTU_DISCOVER values */
 #define IP_PMTUDISC_DONT		0	/* Never send DF frames */
@@ -266,14 +264,10 @@
 
 #define	IN_CLASSD(a)		((((long int) (a)) & 0xf0000000) == 0xe0000000)
 #define	IN_MULTICAST(a)		IN_CLASSD(a)
-#define	IN_MULTICAST_NET	0xe0000000
+#define IN_MULTICAST_NET	0xF0000000
 
-#define	IN_BADCLASS(a)		(((long int) (a) ) == (long int)0xffffffff)
-#define	IN_EXPERIMENTAL(a)	IN_BADCLASS((a))
-
-#define	IN_CLASSE(a)		((((long int) (a)) & 0xf0000000) == 0xf0000000)
-#define	IN_CLASSE_NET		0xffffffff
-#define	IN_CLASSE_NSHIFT	0
+#define	IN_EXPERIMENTAL(a)	((((long int) (a)) & 0xf0000000) == 0xf0000000)
+#define	IN_BADCLASS(a)		IN_EXPERIMENTAL((a))
 
 /* Address to accept any incoming messages. */
 #define	INADDR_ANY		((unsigned long int) 0x00000000)
@@ -292,11 +286,10 @@
 #define	IN_LOOPBACK(a)		((((long int) (a)) & 0xff000000) == 0x7f000000)
 
 /* Defines for Multicast INADDR */
-#define INADDR_UNSPEC_GROUP		0xe0000000U	/* 224.0.0.0   */
-#define INADDR_ALLHOSTS_GROUP		0xe0000001U	/* 224.0.0.1   */
-#define INADDR_ALLRTRS_GROUP		0xe0000002U	/* 224.0.0.2 */
-#define INADDR_ALLSNOOPERS_GROUP	0xe000006aU	/* 224.0.0.106 */
-#define INADDR_MAX_LOCAL_GROUP		0xe00000ffU	/* 224.0.0.255 */
+#define INADDR_UNSPEC_GROUP   	0xe0000000U	/* 224.0.0.0   */
+#define INADDR_ALLHOSTS_GROUP 	0xe0000001U	/* 224.0.0.1   */
+#define INADDR_ALLRTRS_GROUP    0xe0000002U	/* 224.0.0.2 */
+#define INADDR_MAX_LOCAL_GROUP  0xe00000ffU	/* 224.0.0.255 */
 #endif
 
 /* <asm/byteorder.h> contains the htonl type stuff.. */
diff --git a/include/uapi/linux/in6.h b/include/linux/in6.h
similarity index 96%
rename from include/uapi/linux/in6.h
rename to include/linux/in6.h
index d016ac9..aa5b66d 100644
--- a/include/uapi/linux/in6.h
+++ b/include/linux/in6.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  *	Types and definitions for AF_INET6 
  *	Linux INET6 implementation 
@@ -144,7 +143,6 @@
 #define IPV6_TLV_PAD1		0
 #define IPV6_TLV_PADN		1
 #define IPV6_TLV_ROUTERALERT	5
-#define IPV6_TLV_CALIPSO	7	/* RFC 5570 */
 #define IPV6_TLV_JUMBO		194
 #define IPV6_TLV_HAO		201	/* home address option */
 
@@ -177,8 +175,6 @@
 #define IPV6_V6ONLY		26
 #define IPV6_JOIN_ANYCAST	27
 #define IPV6_LEAVE_ANYCAST	28
-#define IPV6_MULTICAST_ALL	29
-#define IPV6_ROUTER_ALERT_ISOLATE	30
 
 /* IPV6_MTU_DISCOVER values */
 #define IPV6_PMTUDISC_DONT		0
@@ -286,8 +282,6 @@
 #define IPV6_RECVORIGDSTADDR    IPV6_ORIGDSTADDR
 #define IPV6_TRANSPARENT        75
 #define IPV6_UNICAST_IF         76
-#define IPV6_RECVFRAGSIZE	77
-#define IPV6_FREEBIND		78
 
 /*
  * Multicast Routing:
diff --git a/include/uapi/linux/inet_diag.h b/include/linux/inet_diag.h
similarity index 65%
rename from include/uapi/linux/inet_diag.h
rename to include/linux/inet_diag.h
index 3dff684..016de88 100644
--- a/include/uapi/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _INET_DIAG_H_
 #define _INET_DIAG_H_
 
@@ -44,23 +43,6 @@
 	struct inet_diag_sockid id;
 };
 
-/*
- * SOCK_RAW sockets require the underlied protocol to be
- * additionally specified so we can use @pad member for
- * this, but we can't rename it because userspace programs
- * still may depend on this name. Instead lets use another
- * structure definition as an alias for struct
- * @inet_diag_req_v2.
- */
-struct inet_diag_req_raw {
-	__u8	sdiag_family;
-	__u8	sdiag_protocol;
-	__u8	idiag_ext;
-	__u8	sdiag_raw_protocol;
-	__u32	idiag_states;
-	struct inet_diag_sockid id;
-};
-
 enum {
 	INET_DIAG_REQ_NONE,
 	INET_DIAG_REQ_BYTECODE,
@@ -92,8 +74,6 @@
 	INET_DIAG_BC_D_COND,
 	INET_DIAG_BC_DEV_COND,   /* u32 ifindex */
 	INET_DIAG_BC_MARK_COND,
-	INET_DIAG_BC_S_EQ,
-	INET_DIAG_BC_D_EQ,
 };
 
 struct inet_diag_hostcond {
@@ -137,36 +117,18 @@
 	INET_DIAG_TCLASS,
 	INET_DIAG_SKMEMINFO,
 	INET_DIAG_SHUTDOWN,
-
-	/*
-	 * Next extenstions cannot be requested in struct inet_diag_req_v2:
-	 * its field idiag_ext has only 8 bits.
-	 */
-
-	INET_DIAG_DCTCPINFO,	/* request as INET_DIAG_VEGASINFO */
-	INET_DIAG_PROTOCOL,	/* response attribute only */
+	INET_DIAG_DCTCPINFO,
+	INET_DIAG_PROTOCOL,  /* response attribute only */
 	INET_DIAG_SKV6ONLY,
 	INET_DIAG_LOCALS,
 	INET_DIAG_PEERS,
 	INET_DIAG_PAD,
-	INET_DIAG_MARK,		/* only with CAP_NET_ADMIN */
-	INET_DIAG_BBRINFO,	/* request as INET_DIAG_VEGASINFO */
-	INET_DIAG_CLASS_ID,	/* request as INET_DIAG_TCLASS */
-	INET_DIAG_MD5SIG,
-	INET_DIAG_ULP_INFO,
+	INET_DIAG_MARK,
 	__INET_DIAG_MAX,
 };
 
 #define INET_DIAG_MAX (__INET_DIAG_MAX - 1)
 
-enum {
-	INET_ULP_INFO_UNSPEC,
-	INET_ULP_INFO_NAME,
-	INET_ULP_INFO_TLS,
-	__INET_ULP_INFO_MAX,
-};
-#define INET_ULP_INFO_MAX (__INET_ULP_INFO_MAX - 1)
-
 /* INET_DIAG_MEM */
 
 struct inet_diag_meminfo {
@@ -195,20 +157,8 @@
 	__u32	dctcp_ab_tot;
 };
 
-/* INET_DIAG_BBRINFO */
-
-struct tcp_bbr_info {
-	/* u64 bw: max-filtered BW (app throughput) estimate in Byte per sec: */
-	__u32	bbr_bw_lo;		/* lower 32 bits of bw */
-	__u32	bbr_bw_hi;		/* upper 32 bits of bw */
-	__u32	bbr_min_rtt;		/* min-filtered RTT in uSec */
-	__u32	bbr_pacing_gain;	/* pacing gain shifted left 8 bits */
-	__u32	bbr_cwnd_gain;		/* cwnd gain shifted left 8 bits */
-};
-
 union tcp_cc_info {
 	struct tcpvegas_info	vegas;
 	struct tcp_dctcp_info	dctcp;
-	struct tcp_bbr_info	bbr;
 };
 #endif /* _INET_DIAG_H_ */
diff --git a/include/uapi/linux/ip6_tunnel.h b/include/linux/ip6_tunnel.h
similarity index 87%
rename from include/uapi/linux/ip6_tunnel.h
rename to include/linux/ip6_tunnel.h
index 0245269..48af63c 100644
--- a/include/uapi/linux/ip6_tunnel.h
+++ b/include/linux/ip6_tunnel.h
@@ -1,10 +1,7 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _IP6_TUNNEL_H
 #define _IP6_TUNNEL_H
 
 #include <linux/types.h>
-#include <linux/if.h>		/* For IFNAMSIZ. */
-#include <linux/in6.h>		/* For struct in6_addr. */
 
 #define IPV6_TLV_TNL_ENCAP_LIMIT 4
 #define IPV6_DEFAULT_TNL_ENCAP_LIMIT 4
@@ -21,8 +18,6 @@
 #define IP6_TNL_F_RCV_DSCP_COPY 0x10
 /* copy fwmark from inner packet */
 #define IP6_TNL_F_USE_ORIG_FWMARK 0x20
-/* allow remote endpoint on the local node */
-#define IP6_TNL_F_ALLOW_LOCAL_REMOTE 0x40
 
 struct ip6_tnl_parm {
 	char name[IFNAMSIZ];	/* name of tunnel device */
diff --git a/include/uapi/linux/l2tp.h b/include/linux/l2tp.h
similarity index 80%
rename from include/uapi/linux/l2tp.h
rename to include/linux/l2tp.h
index 131c3a2..5b0e36d 100644
--- a/include/uapi/linux/l2tp.h
+++ b/include/linux/l2tp.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /*
  * L2TP-over-IP socket for L2TPv3.
  *
@@ -10,8 +9,7 @@
 
 #include <linux/types.h>
 #include <linux/socket.h>
-#include <linux/in.h>
-#include <linux/in6.h>
+#include <netinet/in.h>
 
 #define IPPROTO_L2TP		115
 
@@ -31,7 +29,7 @@
 	__u32		l2tp_conn_id;	/* Connection ID of tunnel */
 
 	/* Pad to size of `struct sockaddr'. */
-	unsigned char	__pad[__SOCK_SIZE__ -
+	unsigned char	__pad[sizeof(struct sockaddr) -
 			      sizeof(__kernel_sa_family_t) -
 			      sizeof(__be16) - sizeof(struct in_addr) -
 			      sizeof(__u32)];
@@ -60,14 +58,14 @@
 /*
  * Commands.
  * Valid TLVs of each command are:-
- * TUNNEL_CREATE	- CONN_ID, pw_type, netns, ifname, ipinfo, udpinfo, udpcsum
+ * TUNNEL_CREATE	- CONN_ID, pw_type, netns, ifname, ipinfo, udpinfo, udpcsum, vlanid
  * TUNNEL_DELETE	- CONN_ID
  * TUNNEL_MODIFY	- CONN_ID, udpcsum
  * TUNNEL_GETSTATS	- CONN_ID, (stats)
  * TUNNEL_GET		- CONN_ID, (...)
- * SESSION_CREATE	- SESSION_ID, PW_TYPE, cookie, peer_cookie, l2spec
+ * SESSION_CREATE	- SESSION_ID, PW_TYPE, offset, data_seq, cookie, peer_cookie, offset, l2spec
  * SESSION_DELETE	- SESSION_ID
- * SESSION_MODIFY	- SESSION_ID
+ * SESSION_MODIFY	- SESSION_ID, data_seq
  * SESSION_GET		- SESSION_ID, (...)
  * SESSION_GETSTATS	- SESSION_ID, (stats)
  *
@@ -94,10 +92,10 @@
 	L2TP_ATTR_NONE,			/* no data */
 	L2TP_ATTR_PW_TYPE,		/* u16, enum l2tp_pwtype */
 	L2TP_ATTR_ENCAP_TYPE,		/* u16, enum l2tp_encap_type */
-	L2TP_ATTR_OFFSET,		/* u16 (not used) */
-	L2TP_ATTR_DATA_SEQ,		/* u16 (not used) */
+	L2TP_ATTR_OFFSET,		/* u16 */
+	L2TP_ATTR_DATA_SEQ,		/* u16 */
 	L2TP_ATTR_L2SPEC_TYPE,		/* u8, enum l2tp_l2spec_type */
-	L2TP_ATTR_L2SPEC_LEN,		/* u8 (not used) */
+	L2TP_ATTR_L2SPEC_LEN,		/* u8, enum l2tp_l2spec_type */
 	L2TP_ATTR_PROTO_VERSION,	/* u8 */
 	L2TP_ATTR_IFNAME,		/* string */
 	L2TP_ATTR_CONN_ID,		/* u32 */
@@ -105,10 +103,10 @@
 	L2TP_ATTR_SESSION_ID,		/* u32 */
 	L2TP_ATTR_PEER_SESSION_ID,	/* u32 */
 	L2TP_ATTR_UDP_CSUM,		/* u8 */
-	L2TP_ATTR_VLAN_ID,		/* u16 (not used) */
+	L2TP_ATTR_VLAN_ID,		/* u16 */
 	L2TP_ATTR_COOKIE,		/* 0, 4 or 8 bytes */
 	L2TP_ATTR_PEER_COOKIE,		/* 0, 4 or 8 bytes */
-	L2TP_ATTR_DEBUG,		/* u32, enum l2tp_debug_flags */
+	L2TP_ATTR_DEBUG,		/* u32 */
 	L2TP_ATTR_RECV_SEQ,		/* u8 */
 	L2TP_ATTR_SEND_SEQ,		/* u8 */
 	L2TP_ATTR_LNS_MODE,		/* u8 */
@@ -119,14 +117,13 @@
 	L2TP_ATTR_IP_DADDR,		/* u32 */
 	L2TP_ATTR_UDP_SPORT,		/* u16 */
 	L2TP_ATTR_UDP_DPORT,		/* u16 */
-	L2TP_ATTR_MTU,			/* u16 (not used) */
-	L2TP_ATTR_MRU,			/* u16 (not used) */
+	L2TP_ATTR_MTU,			/* u16 */
+	L2TP_ATTR_MRU,			/* u16 */
 	L2TP_ATTR_STATS,		/* nested */
 	L2TP_ATTR_IP6_SADDR,		/* struct in6_addr */
 	L2TP_ATTR_IP6_DADDR,		/* struct in6_addr */
-	L2TP_ATTR_UDP_ZERO_CSUM6_TX,	/* flag */
-	L2TP_ATTR_UDP_ZERO_CSUM6_RX,	/* flag */
-	L2TP_ATTR_PAD,
+	L2TP_ATTR_UDP_ZERO_CSUM6_TX,	/* u8 */
+	L2TP_ATTR_UDP_ZERO_CSUM6_RX,	/* u8 */
 	__L2TP_ATTR_MAX,
 };
 
@@ -143,7 +140,6 @@
 	L2TP_ATTR_RX_SEQ_DISCARDS,	/* u64 */
 	L2TP_ATTR_RX_OOS_PACKETS,	/* u64 */
 	L2TP_ATTR_RX_ERRORS,		/* u64 */
-	L2TP_ATTR_STATS_PAD,
 	__L2TP_ATTR_STATS_MAX,
 };
 
@@ -169,28 +165,12 @@
 	L2TP_ENCAPTYPE_IP,
 };
 
-/* For L2TP_ATTR_DATA_SEQ. Unused. */
 enum l2tp_seqmode {
 	L2TP_SEQ_NONE = 0,
 	L2TP_SEQ_IP = 1,
 	L2TP_SEQ_ALL = 2,
 };
 
-/**
- * enum l2tp_debug_flags - debug message categories for L2TP tunnels/sessions
- *
- * @L2TP_MSG_DEBUG: verbose debug (if compiled in)
- * @L2TP_MSG_CONTROL: userspace - kernel interface
- * @L2TP_MSG_SEQ: sequence numbers
- * @L2TP_MSG_DATA: data packets
- */
-enum l2tp_debug_flags {
-	L2TP_MSG_DEBUG		= (1 << 0),
-	L2TP_MSG_CONTROL	= (1 << 1),
-	L2TP_MSG_SEQ		= (1 << 2),
-	L2TP_MSG_DATA		= (1 << 3),
-};
-
 /*
  * NETLINK_GENERIC related info
  */
diff --git a/include/linux/libc-compat.h b/include/linux/libc-compat.h
new file mode 100644
index 0000000..9bed5b6
--- /dev/null
+++ b/include/linux/libc-compat.h
@@ -0,0 +1,143 @@
+/*
+ * Compatibility interface for userspace libc header coordination:
+ *
+ * Define compatibility macros that are used to control the inclusion or
+ * exclusion of UAPI structures and definitions in coordination with another
+ * userspace C library.
+ *
+ * This header is intended to solve the problem of UAPI definitions that
+ * conflict with userspace definitions. If a UAPI header has such conflicting
+ * definitions then the solution is as follows:
+ *
+ * * Synchronize the UAPI header and the libc headers so either one can be
+ *   used and such that the ABI is preserved. If this is not possible then
+ *   no simple compatibility interface exists (you need to write translating
+ *   wrappers and rename things) and you can't use this interface.
+ *
+ * Then follow this process:
+ *
+ * (a) Include libc-compat.h in the UAPI header.
+ *      e.g. #include <linux/libc-compat.h>
+ *     This include must be as early as possible.
+ *
+ * (b) In libc-compat.h add enough code to detect that the comflicting
+ *     userspace libc header has been included first.
+ *
+ * (c) If the userspace libc header has been included first define a set of
+ *     guard macros of the form __UAPI_DEF_FOO and set their values to 1, else
+ *     set their values to 0.
+ *
+ * (d) Back in the UAPI header with the conflicting definitions, guard the
+ *     definitions with:
+ *     #if __UAPI_DEF_FOO
+ *       ...
+ *     #endif
+ *
+ * This fixes the situation where the linux headers are included *after* the
+ * libc headers. To fix the problem with the inclusion in the other order the
+ * userspace libc headers must be fixed like this:
+ *
+ * * For all definitions that conflict with kernel definitions wrap those
+ *   defines in the following:
+ *   #if !__UAPI_DEF_FOO
+ *     ...
+ *   #endif
+ *
+ * This prevents the redefinition of a construct already defined by the kernel.
+ */
+#ifndef _LIBC_COMPAT_H
+#define _LIBC_COMPAT_H
+
+/* We have included glibc headers... */
+#if defined(__GLIBC__)
+
+/* Coordinate with glibc netinet/in.h header. */
+#if defined(_NETINET_IN_H)
+
+/* GLIBC headers included first so don't define anything
+ * that would already be defined. */
+#define __UAPI_DEF_IN_ADDR		0
+#define __UAPI_DEF_IN_IPPROTO		0
+#define __UAPI_DEF_IN_PKTINFO		0
+#define __UAPI_DEF_IP_MREQ		0
+#define __UAPI_DEF_SOCKADDR_IN		0
+#define __UAPI_DEF_IN_CLASS		0
+
+#define __UAPI_DEF_IN6_ADDR		0
+/* The exception is the in6_addr macros which must be defined
+ * if the glibc code didn't define them. This guard matches
+ * the guard in glibc/inet/netinet/in.h which defines the
+ * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
+#if defined(__USE_MISC) || defined (__USE_GNU)
+#define __UAPI_DEF_IN6_ADDR_ALT		0
+#else
+#define __UAPI_DEF_IN6_ADDR_ALT		1
+#endif
+#define __UAPI_DEF_SOCKADDR_IN6		0
+#define __UAPI_DEF_IPV6_MREQ		0
+#define __UAPI_DEF_IPPROTO_V6		0
+#define __UAPI_DEF_IPV6_OPTIONS		0
+#define __UAPI_DEF_IN6_PKTINFO		0
+#define __UAPI_DEF_IP6_MTUINFO		0
+
+#else
+
+/* Linux headers included first, and we must define everything
+ * we need. The expectation is that glibc will check the
+ * __UAPI_DEF_* defines and adjust appropriately. */
+#define __UAPI_DEF_IN_ADDR		1
+#define __UAPI_DEF_IN_IPPROTO		1
+#define __UAPI_DEF_IN_PKTINFO		1
+#define __UAPI_DEF_IP_MREQ		1
+#define __UAPI_DEF_SOCKADDR_IN		1
+#define __UAPI_DEF_IN_CLASS		1
+
+#define __UAPI_DEF_IN6_ADDR		1
+/* We unconditionally define the in6_addr macros and glibc must
+ * coordinate. */
+#define __UAPI_DEF_IN6_ADDR_ALT		1
+#define __UAPI_DEF_SOCKADDR_IN6		1
+#define __UAPI_DEF_IPV6_MREQ		1
+#define __UAPI_DEF_IPPROTO_V6		1
+#define __UAPI_DEF_IPV6_OPTIONS		1
+#define __UAPI_DEF_IN6_PKTINFO		1
+#define __UAPI_DEF_IP6_MTUINFO		1
+
+#endif /* _NETINET_IN_H */
+
+/* Definitions for xattr.h */
+#if defined(_SYS_XATTR_H)
+#define __UAPI_DEF_XATTR		0
+#else
+#define __UAPI_DEF_XATTR		1
+#endif
+
+/* If we did not see any headers from any supported C libraries,
+ * or we are being included in the kernel, then define everything
+ * that we need. */
+#else /* !defined(__GLIBC__) */
+
+/* Definitions for in.h */
+#define __UAPI_DEF_IN_ADDR		1
+#define __UAPI_DEF_IN_IPPROTO		1
+#define __UAPI_DEF_IN_PKTINFO		1
+#define __UAPI_DEF_IP_MREQ		1
+#define __UAPI_DEF_SOCKADDR_IN		1
+#define __UAPI_DEF_IN_CLASS		1
+
+/* Definitions for in6.h */
+#define __UAPI_DEF_IN6_ADDR		1
+#define __UAPI_DEF_IN6_ADDR_ALT		1
+#define __UAPI_DEF_SOCKADDR_IN6		1
+#define __UAPI_DEF_IPV6_MREQ		1
+#define __UAPI_DEF_IPPROTO_V6		1
+#define __UAPI_DEF_IPV6_OPTIONS		1
+#define __UAPI_DEF_IN6_PKTINFO		1
+#define __UAPI_DEF_IP6_MTUINFO		1
+
+/* Definitions for xattr.h */
+#define __UAPI_DEF_XATTR		1
+
+#endif /* __GLIBC__ */
+
+#endif /* _LIBC_COMPAT_H */
diff --git a/include/uapi/linux/lwtunnel.h b/include/linux/lwtunnel.h
similarity index 60%
rename from include/uapi/linux/lwtunnel.h
rename to include/linux/lwtunnel.h
index 3f3fe6f..1d2f4f6 100644
--- a/include/uapi/linux/lwtunnel.h
+++ b/include/linux/lwtunnel.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _LWTUNNEL_H_
 #define _LWTUNNEL_H_
 
@@ -10,9 +9,6 @@
 	LWTUNNEL_ENCAP_IP,
 	LWTUNNEL_ENCAP_ILA,
 	LWTUNNEL_ENCAP_IP6,
-	LWTUNNEL_ENCAP_SEG6,
-	LWTUNNEL_ENCAP_BPF,
-	LWTUNNEL_ENCAP_SEG6_LOCAL,
 	__LWTUNNEL_ENCAP_MAX,
 };
 
@@ -26,7 +22,6 @@
 	LWTUNNEL_IP_TTL,
 	LWTUNNEL_IP_TOS,
 	LWTUNNEL_IP_FLAGS,
-	LWTUNNEL_IP_PAD,
 	__LWTUNNEL_IP_MAX,
 };
 
@@ -40,32 +35,9 @@
 	LWTUNNEL_IP6_HOPLIMIT,
 	LWTUNNEL_IP6_TC,
 	LWTUNNEL_IP6_FLAGS,
-	LWTUNNEL_IP6_PAD,
 	__LWTUNNEL_IP6_MAX,
 };
 
 #define LWTUNNEL_IP6_MAX (__LWTUNNEL_IP6_MAX - 1)
 
-enum {
-	LWT_BPF_PROG_UNSPEC,
-	LWT_BPF_PROG_FD,
-	LWT_BPF_PROG_NAME,
-	__LWT_BPF_PROG_MAX,
-};
-
-#define LWT_BPF_PROG_MAX (__LWT_BPF_PROG_MAX - 1)
-
-enum {
-	LWT_BPF_UNSPEC,
-	LWT_BPF_IN,
-	LWT_BPF_OUT,
-	LWT_BPF_XMIT,
-	LWT_BPF_XMIT_HEADROOM,
-	__LWT_BPF_MAX,
-};
-
-#define LWT_BPF_MAX (__LWT_BPF_MAX - 1)
-
-#define LWT_BPF_MAX_HEADROOM 256
-
 #endif /* _LWTUNNEL_H_ */
diff --git a/include/uapi/linux/mpls.h b/include/linux/mpls.h
similarity index 61%
rename from include/uapi/linux/mpls.h
rename to include/linux/mpls.h
index 9effbf9..a14b54b 100644
--- a/include/uapi/linux/mpls.h
+++ b/include/linux/mpls.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _MPLS_H
 #define _MPLS_H
 
@@ -44,34 +43,4 @@
 
 #define MPLS_LABEL_FIRST_UNRESERVED	16 /* RFC3032 */
 
-/* These are embedded into IFLA_STATS_AF_SPEC:
- * [IFLA_STATS_AF_SPEC]
- * -> [AF_MPLS]
- *    -> [MPLS_STATS_xxx]
- *
- * Attributes:
- * [MPLS_STATS_LINK] = {
- *     struct mpls_link_stats
- * }
- */
-enum {
-	MPLS_STATS_UNSPEC, /* also used as 64bit pad attribute */
-	MPLS_STATS_LINK,
-	__MPLS_STATS_MAX,
-};
-
-#define MPLS_STATS_MAX (__MPLS_STATS_MAX - 1)
-
-struct mpls_link_stats {
-	__u64	rx_packets;		/* total packets received	*/
-	__u64	tx_packets;		/* total packets transmitted	*/
-	__u64	rx_bytes;		/* total bytes received		*/
-	__u64	tx_bytes;		/* total bytes transmitted	*/
-	__u64	rx_errors;		/* bad packets received		*/
-	__u64	tx_errors;		/* packet transmit problems	*/
-	__u64	rx_dropped;		/* packet dropped on receive	*/
-	__u64	tx_dropped;		/* packet dropped on transmit	*/
-	__u64	rx_noroute;		/* no route for packet dest	*/
-};
-
 #endif /* _MPLS_H */
diff --git a/include/uapi/linux/mpls_iptunnel.h b/include/linux/mpls_iptunnel.h
similarity index 85%
rename from include/uapi/linux/mpls_iptunnel.h
rename to include/linux/mpls_iptunnel.h
index 2c69b7d..4132c3c 100644
--- a/include/uapi/linux/mpls_iptunnel.h
+++ b/include/linux/mpls_iptunnel.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  *	mpls tunnel api
  *
@@ -17,13 +16,11 @@
 /* MPLS tunnel attributes
  * [RTA_ENCAP] = {
  *     [MPLS_IPTUNNEL_DST]
- *     [MPLS_IPTUNNEL_TTL]
  * }
  */
 enum {
 	MPLS_IPTUNNEL_UNSPEC,
 	MPLS_IPTUNNEL_DST,
-	MPLS_IPTUNNEL_TTL,
 	__MPLS_IPTUNNEL_MAX,
 };
 #define MPLS_IPTUNNEL_MAX (__MPLS_IPTUNNEL_MAX - 1)
diff --git a/include/uapi/linux/neighbour.h b/include/linux/neighbour.h
similarity index 95%
rename from include/uapi/linux/neighbour.h
rename to include/linux/neighbour.h
index cd144e3..788655b 100644
--- a/include/uapi/linux/neighbour.h
+++ b/include/linux/neighbour.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_NEIGHBOUR_H
 #define __LINUX_NEIGHBOUR_H
 
@@ -27,8 +26,6 @@
 	NDA_IFINDEX,
 	NDA_MASTER,
 	NDA_LINK_NETNSID,
-	NDA_SRC_VNI,
-	NDA_PROTOCOL,  /* Originator of entry */
 	__NDA_MAX
 };
 
@@ -43,8 +40,6 @@
 #define NTF_MASTER	0x04
 #define NTF_PROXY	0x08	/* == ATF_PUBL */
 #define NTF_EXT_LEARNED	0x10
-#define NTF_OFFLOADED   0x20
-#define NTF_STICKY	0x40
 #define NTF_ROUTER	0x80
 
 /*
@@ -133,7 +128,6 @@
 	NDTPA_LOCKTIME,			/* u64, msecs */
 	NDTPA_QUEUE_LENBYTES,		/* u32 */
 	NDTPA_MCAST_REPROBES,		/* u32 */
-	NDTPA_PAD,
 	__NDTPA_MAX
 };
 #define NDTPA_MAX (__NDTPA_MAX - 1)
@@ -166,7 +160,6 @@
 	NDTA_PARMS,			/* nested TLV NDTPA_* */
 	NDTA_STATS,			/* struct ndt_stats, read-only */
 	NDTA_GC_INTERVAL,		/* u64, msecs */
-	NDTA_PAD,
 	__NDTA_MAX
 };
 #define NDTA_MAX (__NDTA_MAX - 1)
diff --git a/include/uapi/linux/net_namespace.h b/include/linux/net_namespace.h
similarity index 85%
rename from include/uapi/linux/net_namespace.h
rename to include/linux/net_namespace.h
index fa81f1e..9a92b7e 100644
--- a/include/uapi/linux/net_namespace.h
+++ b/include/linux/net_namespace.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* Copyright (c) 2015 6WIND S.A.
  * Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
  *
@@ -16,8 +15,6 @@
 	NETNSA_NSID,
 	NETNSA_PID,
 	NETNSA_FD,
-	NETNSA_TARGET_NSID,
-	NETNSA_CURRENT_NSID,
 	__NETNSA_MAX,
 };
 
diff --git a/include/uapi/linux/netconf.h b/include/linux/netconf.h
similarity index 78%
rename from include/uapi/linux/netconf.h
rename to include/linux/netconf.h
index 229e885..7210fe4 100644
--- a/include/uapi/linux/netconf.h
+++ b/include/linux/netconf.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _LINUX_NETCONF_H_
 #define _LINUX_NETCONF_H_
 
@@ -17,12 +16,9 @@
 	NETCONFA_MC_FORWARDING,
 	NETCONFA_PROXY_NEIGH,
 	NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
-	NETCONFA_INPUT,
-	NETCONFA_BC_FORWARDING,
 	__NETCONFA_MAX
 };
 #define NETCONFA_MAX	(__NETCONFA_MAX - 1)
-#define NETCONFA_ALL	-1
 
 #define NETCONFA_IFINDEX_ALL		-1
 #define NETCONFA_IFINDEX_DEFAULT	-2
diff --git a/include/uapi/linux/netdevice.h b/include/linux/netdevice.h
similarity index 96%
rename from include/uapi/linux/netdevice.h
rename to include/linux/netdevice.h
index 86d961c..66fceb4 100644
--- a/include/uapi/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * INET		An implementation of the TCP/IP protocol suite for the LINUX
  *		operating system.  INET is implemented using the  BSD Socket
diff --git a/include/uapi/linux/netfilter.h b/include/linux/netfilter.h
similarity index 88%
rename from include/uapi/linux/netfilter.h
rename to include/linux/netfilter.h
index 899be98..b71b4c9 100644
--- a/include/uapi/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -1,9 +1,9 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_NETFILTER_H
 #define __LINUX_NETFILTER_H
 
 #include <linux/types.h>
 
+#include <linux/sysctl.h>
 #include <linux/in.h>
 #include <linux/in6.h>
 
@@ -13,7 +13,7 @@
 #define NF_STOLEN 2
 #define NF_QUEUE 3
 #define NF_REPEAT 4
-#define NF_STOP 5	/* Deprecated, for userspace nf_queue compatibility. */
+#define NF_STOP 5
 #define NF_MAX_VERDICT NF_STOP
 
 /* we overload the higher bits for encoding auxiliary data such as the queue
@@ -33,6 +33,10 @@
 #define NF_DROP_ERR(x) (((-x) << 16) | NF_DROP)
 
 /* only for userspace compatibility */
+/* Generic cache responses from hook functions.
+   <= 0x2000 is used for protocol-flags. */
+#define NFC_UNKNOWN 0x4000
+#define NFC_ALTERED 0x8000
 
 /* NF_VERDICT_BITS should be 8 now, but userspace might break if this changes */
 #define NF_VERDICT_BITS 16
diff --git a/include/uapi/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
similarity index 98%
rename from include/uapi/linux/netfilter/x_tables.h
rename to include/linux/netfilter/x_tables.h
index ae2fd12..4120970 100644
--- a/include/uapi/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _X_TABLES_H
 #define _X_TABLES_H
 #include <linux/kernel.h>
diff --git a/include/uapi/linux/netfilter/xt_tcpudp.h b/include/linux/netfilter/xt_tcpudp.h
similarity index 94%
rename from include/uapi/linux/netfilter/xt_tcpudp.h
rename to include/linux/netfilter/xt_tcpudp.h
index 658c169..38aa7b3 100644
--- a/include/uapi/linux/netfilter/xt_tcpudp.h
+++ b/include/linux/netfilter/xt_tcpudp.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _XT_TCPUDP_H
 #define _XT_TCPUDP_H
 
diff --git a/include/uapi/linux/netfilter_ipv4.h b/include/linux/netfilter_ipv4.h
similarity index 67%
rename from include/uapi/linux/netfilter_ipv4.h
rename to include/linux/netfilter_ipv4.h
index 96979e3..a5f4dc7 100644
--- a/include/uapi/linux/netfilter_ipv4.h
+++ b/include/linux/netfilter_ipv4.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* IPv4-specific defines for netfilter. 
  * (C)1998 Rusty Russell -- This code is GPL.
  */
@@ -12,6 +11,34 @@
 
 #include <limits.h> /* for INT_MIN, INT_MAX */
 
+/* IP Cache bits. */
+/* Src IP address. */
+#define NFC_IP_SRC		0x0001
+/* Dest IP address. */
+#define NFC_IP_DST		0x0002
+/* Input device. */
+#define NFC_IP_IF_IN		0x0004
+/* Output device. */
+#define NFC_IP_IF_OUT		0x0008
+/* TOS. */
+#define NFC_IP_TOS		0x0010
+/* Protocol. */
+#define NFC_IP_PROTO		0x0020
+/* IP options. */
+#define NFC_IP_OPTIONS		0x0040
+/* Frag & flags. */
+#define NFC_IP_FRAG		0x0080
+
+/* Per-protocol information: only matters if proto match. */
+/* TCP flags. */
+#define NFC_IP_TCPFLAGS		0x0100
+/* Source port. */
+#define NFC_IP_SRC_PT		0x0200
+/* Dest port. */
+#define NFC_IP_DST_PT		0x0400
+/* Something else about the proto */
+#define NFC_IP_PROTO_UNKNOWN	0x2000
+
 /* IP Hooks */
 /* After promisc drops, checksum checks. */
 #define NF_IP_PRE_ROUTING	0
@@ -27,7 +54,6 @@
 
 enum nf_ip_hook_priorities {
 	NF_IP_PRI_FIRST = INT_MIN,
-	NF_IP_PRI_RAW_BEFORE_DEFRAG = -450,
 	NF_IP_PRI_CONNTRACK_DEFRAG = -400,
 	NF_IP_PRI_RAW = -300,
 	NF_IP_PRI_SELINUX_FIRST = -225,
diff --git a/include/uapi/linux/netfilter_ipv4/ip_tables.h b/include/linux/netfilter_ipv4/ip_tables.h
similarity index 98%
rename from include/uapi/linux/netfilter_ipv4/ip_tables.h
rename to include/linux/netfilter_ipv4/ip_tables.h
index 409cff7..38542b4 100644
--- a/include/uapi/linux/netfilter_ipv4/ip_tables.h
+++ b/include/linux/netfilter_ipv4/ip_tables.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /*
  * 25-Jul-1998 Major changes to allow for ip chain table
  *
@@ -18,7 +17,6 @@
 
 #include <linux/types.h>
 
-#include <linux/if.h>
 #include <linux/netfilter_ipv4.h>
 
 #include <linux/netfilter/x_tables.h>
diff --git a/include/uapi/linux/netlink.h b/include/linux/netlink.h
similarity index 70%
rename from include/uapi/linux/netlink.h
rename to include/linux/netlink.h
index 2c28d32..8a7ca5c 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_NETLINK_H
 #define __LINUX_NETLINK_H
 
@@ -28,7 +27,6 @@
 #define NETLINK_ECRYPTFS	19
 #define NETLINK_RDMA		20
 #define NETLINK_CRYPTO		21	/* Crypto layer */
-#define NETLINK_SMC		22	/* SMC monitoring */
 
 #define NETLINK_INET_DIAG	NETLINK_SOCK_DIAG
 
@@ -51,12 +49,12 @@
 
 /* Flags values */
 
-#define NLM_F_REQUEST		0x01	/* It is request message. 	*/
-#define NLM_F_MULTI		0x02	/* Multipart message, terminated by NLMSG_DONE */
-#define NLM_F_ACK		0x04	/* Reply with ack, with zero or error code */
-#define NLM_F_ECHO		0x08	/* Echo this request 		*/
-#define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to sequence change */
-#define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
+#define NLM_F_REQUEST		1	/* It is request message. 	*/
+#define NLM_F_MULTI		2	/* Multipart message, terminated by NLMSG_DONE */
+#define NLM_F_ACK		4	/* Reply with ack, with zero or error code */
+#define NLM_F_ECHO		8	/* Echo this request 		*/
+#define NLM_F_DUMP_INTR		16	/* Dump was inconsistent due to sequence change */
+#define NLM_F_DUMP_FILTERED	32	/* Dump was filtered as requested */
 
 /* Modifiers to GET request */
 #define NLM_F_ROOT	0x100	/* specify tree	root	*/
@@ -70,13 +68,6 @@
 #define NLM_F_CREATE	0x400	/* Create, if it does not exist	*/
 #define NLM_F_APPEND	0x800	/* Add to end of list		*/
 
-/* Modifiers to DELETE request */
-#define NLM_F_NONREC	0x100	/* Do not delete recursively	*/
-
-/* Flags for ACK message */
-#define NLM_F_CAPPED	0x100	/* request was capped */
-#define NLM_F_ACK_TLVS	0x200	/* extended ACK TVLs were included */
-
 /*
    4.4BSD ADD		NLM_F_CREATE|NLM_F_EXCL
    4.4BSD CHANGE	NLM_F_REPLACE
@@ -109,37 +100,6 @@
 struct nlmsgerr {
 	int		error;
 	struct nlmsghdr msg;
-	/*
-	 * followed by the message contents unless NETLINK_CAP_ACK was set
-	 * or the ACK indicates success (error == 0)
-	 * message length is aligned with NLMSG_ALIGN()
-	 */
-	/*
-	 * followed by TLVs defined in enum nlmsgerr_attrs
-	 * if NETLINK_EXT_ACK was set
-	 */
-};
-
-/**
- * enum nlmsgerr_attrs - nlmsgerr attributes
- * @NLMSGERR_ATTR_UNUSED: unused
- * @NLMSGERR_ATTR_MSG: error message string (string)
- * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
- *	 message, counting from the beginning of the header (u32)
- * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
- *	be used - in the success case - to identify a created
- *	object or operation or similar (binary)
- * @__NLMSGERR_ATTR_MAX: number of attributes
- * @NLMSGERR_ATTR_MAX: highest attribute number
- */
-enum nlmsgerr_attrs {
-	NLMSGERR_ATTR_UNUSED,
-	NLMSGERR_ATTR_MSG,
-	NLMSGERR_ATTR_OFFS,
-	NLMSGERR_ATTR_COOKIE,
-
-	__NLMSGERR_ATTR_MAX,
-	NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
 };
 
 #define NETLINK_ADD_MEMBERSHIP		1
@@ -152,8 +112,6 @@
 #define NETLINK_LISTEN_ALL_NSID		8
 #define NETLINK_LIST_MEMBERSHIPS	9
 #define NETLINK_CAP_ACK			10
-#define NETLINK_EXT_ACK			11
-#define NETLINK_GET_STRICT_CHK		12
 
 struct nl_pktinfo {
 	__u32	group;
@@ -227,22 +185,5 @@
 #define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
 #define NLA_HDRLEN		((int) NLA_ALIGN(sizeof(struct nlattr)))
 
-/* Generic 32 bitflags attribute content sent to the kernel.
- *
- * The value is a bitmap that defines the values being set
- * The selector is a bitmask that defines which value is legit
- *
- * Examples:
- *  value = 0x0, and selector = 0x1
- *  implies we are selecting bit 1 and we want to set its value to 0.
- *
- *  value = 0x2, and selector = 0x2
- *  implies we are selecting bit 2 and we want to set its value to 1.
- *
- */
-struct nla_bitfield32 {
-	__u32 value;
-	__u32 selector;
-};
 
 #endif /* __LINUX_NETLINK_H */
diff --git a/include/uapi/linux/netlink_diag.h b/include/linux/netlink_diag.h
similarity index 70%
rename from include/uapi/linux/netlink_diag.h
rename to include/linux/netlink_diag.h
index 4cd0657..f2159d3 100644
--- a/include/uapi/linux/netlink_diag.h
+++ b/include/linux/netlink_diag.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __NETLINK_DIAG_H__
 #define __NETLINK_DIAG_H__
 
@@ -39,7 +38,6 @@
 	NETLINK_DIAG_GROUPS,
 	NETLINK_DIAG_RX_RING,
 	NETLINK_DIAG_TX_RING,
-	NETLINK_DIAG_FLAGS,
 
 	__NETLINK_DIAG_MAX,
 };
@@ -50,16 +48,6 @@
 
 #define NDIAG_SHOW_MEMINFO	0x00000001 /* show memory info of a socket */
 #define NDIAG_SHOW_GROUPS	0x00000002 /* show groups of a netlink socket */
-/* deprecated since 4.6 */
 #define NDIAG_SHOW_RING_CFG	0x00000004 /* show ring configuration */
-#define NDIAG_SHOW_FLAGS	0x00000008 /* show flags of a netlink socket */
-
-/* flags */
-#define NDIAG_FLAG_CB_RUNNING		0x00000001
-#define NDIAG_FLAG_PKTINFO		0x00000002
-#define NDIAG_FLAG_BROADCAST_ERROR	0x00000004
-#define NDIAG_FLAG_NO_ENOBUFS		0x00000008
-#define NDIAG_FLAG_LISTEN_ALL_NSID	0x00000010
-#define NDIAG_FLAG_CAP_ACK		0x00000020
 
 #endif
diff --git a/include/uapi/linux/packet_diag.h b/include/linux/packet_diag.h
similarity index 93%
rename from include/uapi/linux/packet_diag.h
rename to include/linux/packet_diag.h
index 349ddf0..d08c63f 100644
--- a/include/uapi/linux/packet_diag.h
+++ b/include/linux/packet_diag.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __PACKET_DIAG_H__
 #define __PACKET_DIAG_H__
 
@@ -65,7 +64,7 @@
 	__u32	pdmc_count;
 	__u16	pdmc_type;
 	__u16	pdmc_alen;
-	__u8	pdmc_addr[32]; /* MAX_ADDR_LEN */
+	__u8	pdmc_addr[MAX_ADDR_LEN];
 };
 
 struct packet_diag_ring {
diff --git a/include/linux/pkt_cls.h b/include/linux/pkt_cls.h
new file mode 100644
index 0000000..a323146
--- /dev/null
+++ b/include/linux/pkt_cls.h
@@ -0,0 +1,448 @@
+#ifndef __LINUX_PKT_CLS_H
+#define __LINUX_PKT_CLS_H
+
+#include <linux/types.h>
+#include <linux/pkt_sched.h>
+
+
+/* Action attributes */
+enum {
+	TCA_ACT_UNSPEC,
+	TCA_ACT_KIND,
+	TCA_ACT_OPTIONS,
+	TCA_ACT_INDEX,
+	TCA_ACT_STATS,
+	__TCA_ACT_MAX
+};
+
+#define TCA_ACT_MAX __TCA_ACT_MAX
+#define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
+#define TCA_ACT_MAX_PRIO 32
+#define TCA_ACT_BIND	1
+#define TCA_ACT_NOBIND	0
+#define TCA_ACT_UNBIND	1
+#define TCA_ACT_NOUNBIND	0
+#define TCA_ACT_REPLACE		1
+#define TCA_ACT_NOREPLACE	0
+
+#define TC_ACT_UNSPEC	(-1)
+#define TC_ACT_OK		0
+#define TC_ACT_RECLASSIFY	1
+#define TC_ACT_SHOT		2
+#define TC_ACT_PIPE		3
+#define TC_ACT_STOLEN		4
+#define TC_ACT_QUEUED		5
+#define TC_ACT_REPEAT		6
+#define TC_ACT_REDIRECT		7
+#define TC_ACT_JUMP		0x10000000
+
+/* Action type identifiers*/
+enum {
+	TCA_ID_UNSPEC=0,
+	TCA_ID_POLICE=1,
+	/* other actions go here */
+	__TCA_ID_MAX=255
+};
+
+#define TCA_ID_MAX __TCA_ID_MAX
+
+struct tc_police {
+	__u32			index;
+	int			action;
+#define TC_POLICE_UNSPEC	TC_ACT_UNSPEC
+#define TC_POLICE_OK		TC_ACT_OK
+#define TC_POLICE_RECLASSIFY	TC_ACT_RECLASSIFY
+#define TC_POLICE_SHOT		TC_ACT_SHOT
+#define TC_POLICE_PIPE		TC_ACT_PIPE
+
+	__u32			limit;
+	__u32			burst;
+	__u32			mtu;
+	struct tc_ratespec	rate;
+	struct tc_ratespec	peakrate;
+	int 			refcnt;
+	int 			bindcnt;
+	__u32			capab;
+};
+
+struct tcf_t {
+	__u64   install;
+	__u64   lastuse;
+	__u64   expires;
+};
+
+struct tc_cnt {
+	int                   refcnt; 
+	int                   bindcnt;
+};
+
+#define tc_gen \
+	__u32                 index; \
+	__u32                 capab; \
+	int                   action; \
+	int                   refcnt; \
+	int                   bindcnt
+
+enum {
+	TCA_POLICE_UNSPEC,
+	TCA_POLICE_TBF,
+	TCA_POLICE_RATE,
+	TCA_POLICE_PEAKRATE,
+	TCA_POLICE_AVRATE,
+	TCA_POLICE_RESULT,
+	__TCA_POLICE_MAX
+#define TCA_POLICE_RESULT TCA_POLICE_RESULT
+};
+
+#define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
+
+/* U32 filters */
+
+#define TC_U32_HTID(h) ((h)&0xFFF00000)
+#define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
+#define TC_U32_HASH(h) (((h)>>12)&0xFF)
+#define TC_U32_NODE(h) ((h)&0xFFF)
+#define TC_U32_KEY(h) ((h)&0xFFFFF)
+#define TC_U32_UNSPEC	0
+#define TC_U32_ROOT	(0xFFF00000)
+
+enum {
+	TCA_U32_UNSPEC,
+	TCA_U32_CLASSID,
+	TCA_U32_HASH,
+	TCA_U32_LINK,
+	TCA_U32_DIVISOR,
+	TCA_U32_SEL,
+	TCA_U32_POLICE,
+	TCA_U32_ACT,   
+	TCA_U32_INDEV,
+	TCA_U32_PCNT,
+	TCA_U32_MARK,
+	__TCA_U32_MAX
+};
+
+#define TCA_U32_MAX (__TCA_U32_MAX - 1)
+
+struct tc_u32_key {
+	__be32		mask;
+	__be32		val;
+	int		off;
+	int		offmask;
+};
+
+struct tc_u32_sel {
+	unsigned char		flags;
+	unsigned char		offshift;
+	unsigned char		nkeys;
+
+	__be16			offmask;
+	__u16			off;
+	short			offoff;
+
+	short			hoff;
+	__be32			hmask;
+	struct tc_u32_key	keys[0];
+};
+
+struct tc_u32_mark {
+	__u32		val;
+	__u32		mask;
+	__u32		success;
+};
+
+struct tc_u32_pcnt {
+	__u64 rcnt;
+	__u64 rhit;
+	__u64 kcnts[0];
+};
+
+/* Flags */
+
+#define TC_U32_TERMINAL		1
+#define TC_U32_OFFSET		2
+#define TC_U32_VAROFFSET	4
+#define TC_U32_EAT		8
+
+#define TC_U32_MAXDEPTH 8
+
+
+/* RSVP filter */
+
+enum {
+	TCA_RSVP_UNSPEC,
+	TCA_RSVP_CLASSID,
+	TCA_RSVP_DST,
+	TCA_RSVP_SRC,
+	TCA_RSVP_PINFO,
+	TCA_RSVP_POLICE,
+	TCA_RSVP_ACT,
+	__TCA_RSVP_MAX
+};
+
+#define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
+
+struct tc_rsvp_gpi {
+	__u32	key;
+	__u32	mask;
+	int	offset;
+};
+
+struct tc_rsvp_pinfo {
+	struct tc_rsvp_gpi dpi;
+	struct tc_rsvp_gpi spi;
+	__u8	protocol;
+	__u8	tunnelid;
+	__u8	tunnelhdr;
+	__u8	pad;
+};
+
+/* ROUTE filter */
+
+enum {
+	TCA_ROUTE4_UNSPEC,
+	TCA_ROUTE4_CLASSID,
+	TCA_ROUTE4_TO,
+	TCA_ROUTE4_FROM,
+	TCA_ROUTE4_IIF,
+	TCA_ROUTE4_POLICE,
+	TCA_ROUTE4_ACT,
+	__TCA_ROUTE4_MAX
+};
+
+#define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
+
+
+/* FW filter */
+
+enum {
+	TCA_FW_UNSPEC,
+	TCA_FW_CLASSID,
+	TCA_FW_POLICE,
+	TCA_FW_INDEV, /*  used by CONFIG_NET_CLS_IND */
+	TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
+	TCA_FW_MASK,
+	__TCA_FW_MAX
+};
+
+#define TCA_FW_MAX (__TCA_FW_MAX - 1)
+
+/* TC index filter */
+
+enum {
+	TCA_TCINDEX_UNSPEC,
+	TCA_TCINDEX_HASH,
+	TCA_TCINDEX_MASK,
+	TCA_TCINDEX_SHIFT,
+	TCA_TCINDEX_FALL_THROUGH,
+	TCA_TCINDEX_CLASSID,
+	TCA_TCINDEX_POLICE,
+	TCA_TCINDEX_ACT,
+	__TCA_TCINDEX_MAX
+};
+
+#define TCA_TCINDEX_MAX     (__TCA_TCINDEX_MAX - 1)
+
+/* Flow filter */
+
+enum {
+	FLOW_KEY_SRC,
+	FLOW_KEY_DST,
+	FLOW_KEY_PROTO,
+	FLOW_KEY_PROTO_SRC,
+	FLOW_KEY_PROTO_DST,
+	FLOW_KEY_IIF,
+	FLOW_KEY_PRIORITY,
+	FLOW_KEY_MARK,
+	FLOW_KEY_NFCT,
+	FLOW_KEY_NFCT_SRC,
+	FLOW_KEY_NFCT_DST,
+	FLOW_KEY_NFCT_PROTO_SRC,
+	FLOW_KEY_NFCT_PROTO_DST,
+	FLOW_KEY_RTCLASSID,
+	FLOW_KEY_SKUID,
+	FLOW_KEY_SKGID,
+	FLOW_KEY_VLAN_TAG,
+	FLOW_KEY_RXHASH,
+	__FLOW_KEY_MAX,
+};
+
+#define FLOW_KEY_MAX	(__FLOW_KEY_MAX - 1)
+
+enum {
+	FLOW_MODE_MAP,
+	FLOW_MODE_HASH,
+};
+
+enum {
+	TCA_FLOW_UNSPEC,
+	TCA_FLOW_KEYS,
+	TCA_FLOW_MODE,
+	TCA_FLOW_BASECLASS,
+	TCA_FLOW_RSHIFT,
+	TCA_FLOW_ADDEND,
+	TCA_FLOW_MASK,
+	TCA_FLOW_XOR,
+	TCA_FLOW_DIVISOR,
+	TCA_FLOW_ACT,
+	TCA_FLOW_POLICE,
+	TCA_FLOW_EMATCHES,
+	TCA_FLOW_PERTURB,
+	__TCA_FLOW_MAX
+};
+
+#define TCA_FLOW_MAX	(__TCA_FLOW_MAX - 1)
+
+/* Basic filter */
+
+enum {
+	TCA_BASIC_UNSPEC,
+	TCA_BASIC_CLASSID,
+	TCA_BASIC_EMATCHES,
+	TCA_BASIC_ACT,
+	TCA_BASIC_POLICE,
+	__TCA_BASIC_MAX
+};
+
+#define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
+
+
+/* Cgroup classifier */
+
+enum {
+	TCA_CGROUP_UNSPEC,
+	TCA_CGROUP_ACT,
+	TCA_CGROUP_POLICE,
+	TCA_CGROUP_EMATCHES,
+	__TCA_CGROUP_MAX,
+};
+
+#define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
+
+/* BPF classifier */
+
+#define TCA_BPF_FLAG_ACT_DIRECT		(1 << 0)
+
+enum {
+	TCA_BPF_UNSPEC,
+	TCA_BPF_ACT,
+	TCA_BPF_POLICE,
+	TCA_BPF_CLASSID,
+	TCA_BPF_OPS_LEN,
+	TCA_BPF_OPS,
+	TCA_BPF_FD,
+	TCA_BPF_NAME,
+	TCA_BPF_FLAGS,
+	__TCA_BPF_MAX,
+};
+
+#define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
+
+/* Flower classifier */
+
+enum {
+	TCA_FLOWER_UNSPEC,
+	TCA_FLOWER_CLASSID,
+	TCA_FLOWER_INDEV,
+	TCA_FLOWER_ACT,
+	TCA_FLOWER_KEY_ETH_DST,		/* ETH_ALEN */
+	TCA_FLOWER_KEY_ETH_DST_MASK,	/* ETH_ALEN */
+	TCA_FLOWER_KEY_ETH_SRC,		/* ETH_ALEN */
+	TCA_FLOWER_KEY_ETH_SRC_MASK,	/* ETH_ALEN */
+	TCA_FLOWER_KEY_ETH_TYPE,	/* be16 */
+	TCA_FLOWER_KEY_IP_PROTO,	/* u8 */
+	TCA_FLOWER_KEY_IPV4_SRC,	/* be32 */
+	TCA_FLOWER_KEY_IPV4_SRC_MASK,	/* be32 */
+	TCA_FLOWER_KEY_IPV4_DST,	/* be32 */
+	TCA_FLOWER_KEY_IPV4_DST_MASK,	/* be32 */
+	TCA_FLOWER_KEY_IPV6_SRC,	/* struct in6_addr */
+	TCA_FLOWER_KEY_IPV6_SRC_MASK,	/* struct in6_addr */
+	TCA_FLOWER_KEY_IPV6_DST,	/* struct in6_addr */
+	TCA_FLOWER_KEY_IPV6_DST_MASK,	/* struct in6_addr */
+	TCA_FLOWER_KEY_TCP_SRC,		/* be16 */
+	TCA_FLOWER_KEY_TCP_DST,		/* be16 */
+	TCA_FLOWER_KEY_UDP_SRC,		/* be16 */
+	TCA_FLOWER_KEY_UDP_DST,		/* be16 */
+	__TCA_FLOWER_MAX,
+};
+
+#define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
+
+/* Extended Matches */
+
+struct tcf_ematch_tree_hdr {
+	__u16		nmatches;
+	__u16		progid;
+};
+
+enum {
+	TCA_EMATCH_TREE_UNSPEC,
+	TCA_EMATCH_TREE_HDR,
+	TCA_EMATCH_TREE_LIST,
+	__TCA_EMATCH_TREE_MAX
+};
+#define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
+
+struct tcf_ematch_hdr {
+	__u16		matchid;
+	__u16		kind;
+	__u16		flags;
+	__u16		pad; /* currently unused */
+};
+
+/*  0                   1
+ *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 
+ * +-----------------------+-+-+---+
+ * |         Unused        |S|I| R |
+ * +-----------------------+-+-+---+
+ *
+ * R(2) ::= relation to next ematch
+ *          where: 0 0 END (last ematch)
+ *                 0 1 AND
+ *                 1 0 OR
+ *                 1 1 Unused (invalid)
+ * I(1) ::= invert result
+ * S(1) ::= simple payload
+ */
+#define TCF_EM_REL_END	0
+#define TCF_EM_REL_AND	(1<<0)
+#define TCF_EM_REL_OR	(1<<1)
+#define TCF_EM_INVERT	(1<<2)
+#define TCF_EM_SIMPLE	(1<<3)
+
+#define TCF_EM_REL_MASK	3
+#define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
+
+enum {
+	TCF_LAYER_LINK,
+	TCF_LAYER_NETWORK,
+	TCF_LAYER_TRANSPORT,
+	__TCF_LAYER_MAX
+};
+#define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
+
+/* Ematch type assignments
+ *   1..32767		Reserved for ematches inside kernel tree
+ *   32768..65535	Free to use, not reliable
+ */
+#define	TCF_EM_CONTAINER	0
+#define	TCF_EM_CMP		1
+#define	TCF_EM_NBYTE		2
+#define	TCF_EM_U32		3
+#define	TCF_EM_META		4
+#define	TCF_EM_TEXT		5
+#define	TCF_EM_VLAN		6
+#define	TCF_EM_CANID		7
+#define	TCF_EM_IPSET		8
+#define	TCF_EM_MAX		8
+
+enum {
+	TCF_EM_PROG_TC
+};
+
+enum {
+	TCF_EM_OPND_EQ,
+	TCF_EM_OPND_GT,
+	TCF_EM_OPND_LT
+};
+
+#endif
diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
new file mode 100644
index 0000000..8cb18b4
--- /dev/null
+++ b/include/linux/pkt_sched.h
@@ -0,0 +1,857 @@
+#ifndef __LINUX_PKT_SCHED_H
+#define __LINUX_PKT_SCHED_H
+
+#include <linux/types.h>
+
+/* Logical priority bands not depending on specific packet scheduler.
+   Every scheduler will map them to real traffic classes, if it has
+   no more precise mechanism to classify packets.
+
+   These numbers have no special meaning, though their coincidence
+   with obsolete IPv6 values is not occasional :-). New IPv6 drafts
+   preferred full anarchy inspired by diffserv group.
+
+   Note: TC_PRIO_BESTEFFORT does not mean that it is the most unhappy
+   class, actually, as rule it will be handled with more care than
+   filler or even bulk.
+ */
+
+#define TC_PRIO_BESTEFFORT		0
+#define TC_PRIO_FILLER			1
+#define TC_PRIO_BULK			2
+#define TC_PRIO_INTERACTIVE_BULK	4
+#define TC_PRIO_INTERACTIVE		6
+#define TC_PRIO_CONTROL			7
+
+#define TC_PRIO_MAX			15
+
+/* Generic queue statistics, available for all the elements.
+   Particular schedulers may have also their private records.
+ */
+
+struct tc_stats {
+	__u64	bytes;			/* Number of enqueued bytes */
+	__u32	packets;		/* Number of enqueued packets	*/
+	__u32	drops;			/* Packets dropped because of lack of resources */
+	__u32	overlimits;		/* Number of throttle events when this
+					 * flow goes out of allocated bandwidth */
+	__u32	bps;			/* Current flow byte rate */
+	__u32	pps;			/* Current flow packet rate */
+	__u32	qlen;
+	__u32	backlog;
+};
+
+struct tc_estimator {
+	signed char	interval;
+	unsigned char	ewma_log;
+};
+
+/* "Handles"
+   ---------
+
+    All the traffic control objects have 32bit identifiers, or "handles".
+
+    They can be considered as opaque numbers from user API viewpoint,
+    but actually they always consist of two fields: major and
+    minor numbers, which are interpreted by kernel specially,
+    that may be used by applications, though not recommended.
+
+    F.e. qdisc handles always have minor number equal to zero,
+    classes (or flows) have major equal to parent qdisc major, and
+    minor uniquely identifying class inside qdisc.
+
+    Macros to manipulate handles:
+ */
+
+#define TC_H_MAJ_MASK (0xFFFF0000U)
+#define TC_H_MIN_MASK (0x0000FFFFU)
+#define TC_H_MAJ(h) ((h)&TC_H_MAJ_MASK)
+#define TC_H_MIN(h) ((h)&TC_H_MIN_MASK)
+#define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK))
+
+#define TC_H_UNSPEC	(0U)
+#define TC_H_ROOT	(0xFFFFFFFFU)
+#define TC_H_INGRESS    (0xFFFFFFF1U)
+#define TC_H_CLSACT	TC_H_INGRESS
+
+#define TC_H_MIN_INGRESS	0xFFF2U
+#define TC_H_MIN_EGRESS		0xFFF3U
+
+/* Need to corrospond to iproute2 tc/tc_core.h "enum link_layer" */
+enum tc_link_layer {
+	TC_LINKLAYER_UNAWARE, /* Indicate unaware old iproute2 util */
+	TC_LINKLAYER_ETHERNET,
+	TC_LINKLAYER_ATM,
+};
+#define TC_LINKLAYER_MASK 0x0F /* limit use to lower 4 bits */
+
+struct tc_ratespec {
+	unsigned char	cell_log;
+	__u8		linklayer; /* lower 4 bits */
+	unsigned short	overhead;
+	short		cell_align;
+	unsigned short	mpu;
+	__u32		rate;
+};
+
+#define TC_RTAB_SIZE	1024
+
+struct tc_sizespec {
+	unsigned char	cell_log;
+	unsigned char	size_log;
+	short		cell_align;
+	int		overhead;
+	unsigned int	linklayer;
+	unsigned int	mpu;
+	unsigned int	mtu;
+	unsigned int	tsize;
+};
+
+enum {
+	TCA_STAB_UNSPEC,
+	TCA_STAB_BASE,
+	TCA_STAB_DATA,
+	__TCA_STAB_MAX
+};
+
+#define TCA_STAB_MAX (__TCA_STAB_MAX - 1)
+
+/* FIFO section */
+
+struct tc_fifo_qopt {
+	__u32	limit;	/* Queue length: bytes for bfifo, packets for pfifo */
+};
+
+/* PRIO section */
+
+#define TCQ_PRIO_BANDS	16
+#define TCQ_MIN_PRIO_BANDS 2
+
+struct tc_prio_qopt {
+	int	bands;			/* Number of bands */
+	__u8	priomap[TC_PRIO_MAX+1];	/* Map: logical priority -> PRIO band */
+};
+
+/* MULTIQ section */
+
+struct tc_multiq_qopt {
+	__u16	bands;			/* Number of bands */
+	__u16	max_bands;		/* Maximum number of queues */
+};
+
+/* PLUG section */
+
+#define TCQ_PLUG_BUFFER                0
+#define TCQ_PLUG_RELEASE_ONE           1
+#define TCQ_PLUG_RELEASE_INDEFINITE    2
+#define TCQ_PLUG_LIMIT                 3
+
+struct tc_plug_qopt {
+	/* TCQ_PLUG_BUFFER: Inset a plug into the queue and
+	 *  buffer any incoming packets
+	 * TCQ_PLUG_RELEASE_ONE: Dequeue packets from queue head
+	 *   to beginning of the next plug.
+	 * TCQ_PLUG_RELEASE_INDEFINITE: Dequeue all packets from queue.
+	 *   Stop buffering packets until the next TCQ_PLUG_BUFFER
+	 *   command is received (just act as a pass-thru queue).
+	 * TCQ_PLUG_LIMIT: Increase/decrease queue size
+	 */
+	int             action;
+	__u32           limit;
+};
+
+/* TBF section */
+
+struct tc_tbf_qopt {
+	struct tc_ratespec rate;
+	struct tc_ratespec peakrate;
+	__u32		limit;
+	__u32		buffer;
+	__u32		mtu;
+};
+
+enum {
+	TCA_TBF_UNSPEC,
+	TCA_TBF_PARMS,
+	TCA_TBF_RTAB,
+	TCA_TBF_PTAB,
+	TCA_TBF_RATE64,
+	TCA_TBF_PRATE64,
+	TCA_TBF_BURST,
+	TCA_TBF_PBURST,
+	__TCA_TBF_MAX,
+};
+
+#define TCA_TBF_MAX (__TCA_TBF_MAX - 1)
+
+
+/* TEQL section */
+
+/* TEQL does not require any parameters */
+
+/* SFQ section */
+
+struct tc_sfq_qopt {
+	unsigned	quantum;	/* Bytes per round allocated to flow */
+	int		perturb_period;	/* Period of hash perturbation */
+	__u32		limit;		/* Maximal packets in queue */
+	unsigned	divisor;	/* Hash divisor  */
+	unsigned	flows;		/* Maximal number of flows  */
+};
+
+struct tc_sfqred_stats {
+	__u32           prob_drop;      /* Early drops, below max threshold */
+	__u32           forced_drop;	/* Early drops, after max threshold */
+	__u32           prob_mark;      /* Marked packets, below max threshold */
+	__u32           forced_mark;    /* Marked packets, after max threshold */
+	__u32           prob_mark_head; /* Marked packets, below max threshold */
+	__u32           forced_mark_head;/* Marked packets, after max threshold */
+};
+
+struct tc_sfq_qopt_v1 {
+	struct tc_sfq_qopt v0;
+	unsigned int	depth;		/* max number of packets per flow */
+	unsigned int	headdrop;
+/* SFQRED parameters */
+	__u32		limit;		/* HARD maximal flow queue length (bytes) */
+	__u32		qth_min;	/* Min average length threshold (bytes) */
+	__u32		qth_max;	/* Max average length threshold (bytes) */
+	unsigned char   Wlog;		/* log(W)		*/
+	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
+	unsigned char   Scell_log;	/* cell size for idle damping */
+	unsigned char	flags;
+	__u32		max_P;		/* probability, high resolution */
+/* SFQRED stats */
+	struct tc_sfqred_stats stats;
+};
+
+
+struct tc_sfq_xstats {
+	__s32		allot;
+};
+
+/* RED section */
+
+enum {
+	TCA_RED_UNSPEC,
+	TCA_RED_PARMS,
+	TCA_RED_STAB,
+	TCA_RED_MAX_P,
+	__TCA_RED_MAX,
+};
+
+#define TCA_RED_MAX (__TCA_RED_MAX - 1)
+
+struct tc_red_qopt {
+	__u32		limit;		/* HARD maximal queue length (bytes)	*/
+	__u32		qth_min;	/* Min average length threshold (bytes) */
+	__u32		qth_max;	/* Max average length threshold (bytes) */
+	unsigned char   Wlog;		/* log(W)		*/
+	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
+	unsigned char   Scell_log;	/* cell size for idle damping */
+	unsigned char	flags;
+#define TC_RED_ECN		1
+#define TC_RED_HARDDROP		2
+#define TC_RED_ADAPTATIVE	4
+};
+
+struct tc_red_xstats {
+	__u32           early;          /* Early drops */
+	__u32           pdrop;          /* Drops due to queue limits */
+	__u32           other;          /* Drops due to drop() calls */
+	__u32           marked;         /* Marked packets */
+};
+
+/* GRED section */
+
+#define MAX_DPs 16
+
+enum {
+       TCA_GRED_UNSPEC,
+       TCA_GRED_PARMS,
+       TCA_GRED_STAB,
+       TCA_GRED_DPS,
+       TCA_GRED_MAX_P,
+       TCA_GRED_LIMIT,
+       __TCA_GRED_MAX,
+};
+
+#define TCA_GRED_MAX (__TCA_GRED_MAX - 1)
+
+struct tc_gred_qopt {
+	__u32		limit;        /* HARD maximal queue length (bytes)    */
+	__u32		qth_min;      /* Min average length threshold (bytes) */
+	__u32		qth_max;      /* Max average length threshold (bytes) */
+	__u32		DP;           /* up to 2^32 DPs */
+	__u32		backlog;
+	__u32		qave;
+	__u32		forced;
+	__u32		early;
+	__u32		other;
+	__u32		pdrop;
+	__u8		Wlog;         /* log(W)               */
+	__u8		Plog;         /* log(P_max/(qth_max-qth_min)) */
+	__u8		Scell_log;    /* cell size for idle damping */
+	__u8		prio;         /* prio of this VQ */
+	__u32		packets;
+	__u32		bytesin;
+};
+
+/* gred setup */
+struct tc_gred_sopt {
+	__u32		DPs;
+	__u32		def_DP;
+	__u8		grio;
+	__u8		flags;
+	__u16		pad1;
+};
+
+/* CHOKe section */
+
+enum {
+	TCA_CHOKE_UNSPEC,
+	TCA_CHOKE_PARMS,
+	TCA_CHOKE_STAB,
+	TCA_CHOKE_MAX_P,
+	__TCA_CHOKE_MAX,
+};
+
+#define TCA_CHOKE_MAX (__TCA_CHOKE_MAX - 1)
+
+struct tc_choke_qopt {
+	__u32		limit;		/* Hard queue length (packets)	*/
+	__u32		qth_min;	/* Min average threshold (packets) */
+	__u32		qth_max;	/* Max average threshold (packets) */
+	unsigned char   Wlog;		/* log(W)		*/
+	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
+	unsigned char   Scell_log;	/* cell size for idle damping */
+	unsigned char	flags;		/* see RED flags */
+};
+
+struct tc_choke_xstats {
+	__u32		early;          /* Early drops */
+	__u32		pdrop;          /* Drops due to queue limits */
+	__u32		other;          /* Drops due to drop() calls */
+	__u32		marked;         /* Marked packets */
+	__u32		matched;	/* Drops due to flow match */
+};
+
+/* HTB section */
+#define TC_HTB_NUMPRIO		8
+#define TC_HTB_MAXDEPTH		8
+#define TC_HTB_PROTOVER		3 /* the same as HTB and TC's major */
+
+struct tc_htb_opt {
+	struct tc_ratespec 	rate;
+	struct tc_ratespec 	ceil;
+	__u32	buffer;
+	__u32	cbuffer;
+	__u32	quantum;
+	__u32	level;		/* out only */
+	__u32	prio;
+};
+struct tc_htb_glob {
+	__u32 version;		/* to match HTB/TC */
+    	__u32 rate2quantum;	/* bps->quantum divisor */
+    	__u32 defcls;		/* default class number */
+	__u32 debug;		/* debug flags */
+
+	/* stats */
+	__u32 direct_pkts; /* count of non shaped packets */
+};
+enum {
+	TCA_HTB_UNSPEC,
+	TCA_HTB_PARMS,
+	TCA_HTB_INIT,
+	TCA_HTB_CTAB,
+	TCA_HTB_RTAB,
+	TCA_HTB_DIRECT_QLEN,
+	TCA_HTB_RATE64,
+	TCA_HTB_CEIL64,
+	__TCA_HTB_MAX,
+};
+
+#define TCA_HTB_MAX (__TCA_HTB_MAX - 1)
+
+struct tc_htb_xstats {
+	__u32 lends;
+	__u32 borrows;
+	__u32 giants;	/* too big packets (rate will not be accurate) */
+	__u32 tokens;
+	__u32 ctokens;
+};
+
+/* HFSC section */
+
+struct tc_hfsc_qopt {
+	__u16	defcls;		/* default class */
+};
+
+struct tc_service_curve {
+	__u32	m1;		/* slope of the first segment in bps */
+	__u32	d;		/* x-projection of the first segment in us */
+	__u32	m2;		/* slope of the second segment in bps */
+};
+
+struct tc_hfsc_stats {
+	__u64	work;		/* total work done */
+	__u64	rtwork;		/* work done by real-time criteria */
+	__u32	period;		/* current period */
+	__u32	level;		/* class level in hierarchy */
+};
+
+enum {
+	TCA_HFSC_UNSPEC,
+	TCA_HFSC_RSC,
+	TCA_HFSC_FSC,
+	TCA_HFSC_USC,
+	__TCA_HFSC_MAX,
+};
+
+#define TCA_HFSC_MAX (__TCA_HFSC_MAX - 1)
+
+
+/* CBQ section */
+
+#define TC_CBQ_MAXPRIO		8
+#define TC_CBQ_MAXLEVEL		8
+#define TC_CBQ_DEF_EWMA		5
+
+struct tc_cbq_lssopt {
+	unsigned char	change;
+	unsigned char	flags;
+#define TCF_CBQ_LSS_BOUNDED	1
+#define TCF_CBQ_LSS_ISOLATED	2
+	unsigned char  	ewma_log;
+	unsigned char  	level;
+#define TCF_CBQ_LSS_FLAGS	1
+#define TCF_CBQ_LSS_EWMA	2
+#define TCF_CBQ_LSS_MAXIDLE	4
+#define TCF_CBQ_LSS_MINIDLE	8
+#define TCF_CBQ_LSS_OFFTIME	0x10
+#define TCF_CBQ_LSS_AVPKT	0x20
+	__u32		maxidle;
+	__u32		minidle;
+	__u32		offtime;
+	__u32		avpkt;
+};
+
+struct tc_cbq_wrropt {
+	unsigned char	flags;
+	unsigned char	priority;
+	unsigned char	cpriority;
+	unsigned char	__reserved;
+	__u32		allot;
+	__u32		weight;
+};
+
+struct tc_cbq_ovl {
+	unsigned char	strategy;
+#define	TC_CBQ_OVL_CLASSIC	0
+#define	TC_CBQ_OVL_DELAY	1
+#define	TC_CBQ_OVL_LOWPRIO	2
+#define	TC_CBQ_OVL_DROP		3
+#define	TC_CBQ_OVL_RCLASSIC	4
+	unsigned char	priority2;
+	__u16		pad;
+	__u32		penalty;
+};
+
+struct tc_cbq_police {
+	unsigned char	police;
+	unsigned char	__res1;
+	unsigned short	__res2;
+};
+
+struct tc_cbq_fopt {
+	__u32		split;
+	__u32		defmap;
+	__u32		defchange;
+};
+
+struct tc_cbq_xstats {
+	__u32		borrows;
+	__u32		overactions;
+	__s32		avgidle;
+	__s32		undertime;
+};
+
+enum {
+	TCA_CBQ_UNSPEC,
+	TCA_CBQ_LSSOPT,
+	TCA_CBQ_WRROPT,
+	TCA_CBQ_FOPT,
+	TCA_CBQ_OVL_STRATEGY,
+	TCA_CBQ_RATE,
+	TCA_CBQ_RTAB,
+	TCA_CBQ_POLICE,
+	__TCA_CBQ_MAX,
+};
+
+#define TCA_CBQ_MAX	(__TCA_CBQ_MAX - 1)
+
+/* dsmark section */
+
+enum {
+	TCA_DSMARK_UNSPEC,
+	TCA_DSMARK_INDICES,
+	TCA_DSMARK_DEFAULT_INDEX,
+	TCA_DSMARK_SET_TC_INDEX,
+	TCA_DSMARK_MASK,
+	TCA_DSMARK_VALUE,
+	__TCA_DSMARK_MAX,
+};
+
+#define TCA_DSMARK_MAX (__TCA_DSMARK_MAX - 1)
+
+/* ATM  section */
+
+enum {
+	TCA_ATM_UNSPEC,
+	TCA_ATM_FD,		/* file/socket descriptor */
+	TCA_ATM_PTR,		/* pointer to descriptor - later */
+	TCA_ATM_HDR,		/* LL header */
+	TCA_ATM_EXCESS,		/* excess traffic class (0 for CLP)  */
+	TCA_ATM_ADDR,		/* PVC address (for output only) */
+	TCA_ATM_STATE,		/* VC state (ATM_VS_*; for output only) */
+	__TCA_ATM_MAX,
+};
+
+#define TCA_ATM_MAX	(__TCA_ATM_MAX - 1)
+
+/* Network emulator */
+
+enum {
+	TCA_NETEM_UNSPEC,
+	TCA_NETEM_CORR,
+	TCA_NETEM_DELAY_DIST,
+	TCA_NETEM_REORDER,
+	TCA_NETEM_CORRUPT,
+	TCA_NETEM_LOSS,
+	TCA_NETEM_RATE,
+	TCA_NETEM_ECN,
+	TCA_NETEM_RATE64,
+	__TCA_NETEM_MAX,
+};
+
+#define TCA_NETEM_MAX (__TCA_NETEM_MAX - 1)
+
+struct tc_netem_qopt {
+	__u32	latency;	/* added delay (us) */
+	__u32   limit;		/* fifo limit (packets) */
+	__u32	loss;		/* random packet loss (0=none ~0=100%) */
+	__u32	gap;		/* re-ordering gap (0 for none) */
+	__u32   duplicate;	/* random packet dup  (0=none ~0=100%) */
+	__u32	jitter;		/* random jitter in latency (us) */
+};
+
+struct tc_netem_corr {
+	__u32	delay_corr;	/* delay correlation */
+	__u32	loss_corr;	/* packet loss correlation */
+	__u32	dup_corr;	/* duplicate correlation  */
+};
+
+struct tc_netem_reorder {
+	__u32	probability;
+	__u32	correlation;
+};
+
+struct tc_netem_corrupt {
+	__u32	probability;
+	__u32	correlation;
+};
+
+struct tc_netem_rate {
+	__u32	rate;	/* byte/s */
+	__s32	packet_overhead;
+	__u32	cell_size;
+	__s32	cell_overhead;
+};
+
+enum {
+	NETEM_LOSS_UNSPEC,
+	NETEM_LOSS_GI,		/* General Intuitive - 4 state model */
+	NETEM_LOSS_GE,		/* Gilbert Elliot models */
+	__NETEM_LOSS_MAX
+};
+#define NETEM_LOSS_MAX (__NETEM_LOSS_MAX - 1)
+
+/* State transition probabilities for 4 state model */
+struct tc_netem_gimodel {
+	__u32	p13;
+	__u32	p31;
+	__u32	p32;
+	__u32	p14;
+	__u32	p23;
+};
+
+/* Gilbert-Elliot models */
+struct tc_netem_gemodel {
+	__u32 p;
+	__u32 r;
+	__u32 h;
+	__u32 k1;
+};
+
+#define NETEM_DIST_SCALE	8192
+#define NETEM_DIST_MAX		16384
+
+/* DRR */
+
+enum {
+	TCA_DRR_UNSPEC,
+	TCA_DRR_QUANTUM,
+	__TCA_DRR_MAX
+};
+
+#define TCA_DRR_MAX	(__TCA_DRR_MAX - 1)
+
+struct tc_drr_stats {
+	__u32	deficit;
+};
+
+/* MQPRIO */
+#define TC_QOPT_BITMASK 15
+#define TC_QOPT_MAX_QUEUE 16
+
+struct tc_mqprio_qopt {
+	__u8	num_tc;
+	__u8	prio_tc_map[TC_QOPT_BITMASK + 1];
+	__u8	hw;
+	__u16	count[TC_QOPT_MAX_QUEUE];
+	__u16	offset[TC_QOPT_MAX_QUEUE];
+};
+
+/* SFB */
+
+enum {
+	TCA_SFB_UNSPEC,
+	TCA_SFB_PARMS,
+	__TCA_SFB_MAX,
+};
+
+#define TCA_SFB_MAX (__TCA_SFB_MAX - 1)
+
+/*
+ * Note: increment, decrement are Q0.16 fixed-point values.
+ */
+struct tc_sfb_qopt {
+	__u32 rehash_interval;	/* delay between hash move, in ms */
+	__u32 warmup_time;	/* double buffering warmup time in ms (warmup_time < rehash_interval) */
+	__u32 max;		/* max len of qlen_min */
+	__u32 bin_size;		/* maximum queue length per bin */
+	__u32 increment;	/* probability increment, (d1 in Blue) */
+	__u32 decrement;	/* probability decrement, (d2 in Blue) */
+	__u32 limit;		/* max SFB queue length */
+	__u32 penalty_rate;	/* inelastic flows are rate limited to 'rate' pps */
+	__u32 penalty_burst;
+};
+
+struct tc_sfb_xstats {
+	__u32 earlydrop;
+	__u32 penaltydrop;
+	__u32 bucketdrop;
+	__u32 queuedrop;
+	__u32 childdrop; /* drops in child qdisc */
+	__u32 marked;
+	__u32 maxqlen;
+	__u32 maxprob;
+	__u32 avgprob;
+};
+
+#define SFB_MAX_PROB 0xFFFF
+
+/* QFQ */
+enum {
+	TCA_QFQ_UNSPEC,
+	TCA_QFQ_WEIGHT,
+	TCA_QFQ_LMAX,
+	__TCA_QFQ_MAX
+};
+
+#define TCA_QFQ_MAX	(__TCA_QFQ_MAX - 1)
+
+struct tc_qfq_stats {
+	__u32 weight;
+	__u32 lmax;
+};
+
+/* CODEL */
+
+enum {
+	TCA_CODEL_UNSPEC,
+	TCA_CODEL_TARGET,
+	TCA_CODEL_LIMIT,
+	TCA_CODEL_INTERVAL,
+	TCA_CODEL_ECN,
+	TCA_CODEL_CE_THRESHOLD,
+	__TCA_CODEL_MAX
+};
+
+#define TCA_CODEL_MAX	(__TCA_CODEL_MAX - 1)
+
+struct tc_codel_xstats {
+	__u32	maxpacket; /* largest packet we've seen so far */
+	__u32	count;	   /* how many drops we've done since the last time we
+			    * entered dropping state
+			    */
+	__u32	lastcount; /* count at entry to dropping state */
+	__u32	ldelay;    /* in-queue delay seen by most recently dequeued packet */
+	__s32	drop_next; /* time to drop next packet */
+	__u32	drop_overlimit; /* number of time max qdisc packet limit was hit */
+	__u32	ecn_mark;  /* number of packets we ECN marked instead of dropped */
+	__u32	dropping;  /* are we in dropping state ? */
+	__u32	ce_mark;   /* number of CE marked packets because of ce_threshold */
+};
+
+/* FQ_CODEL */
+
+enum {
+	TCA_FQ_CODEL_UNSPEC,
+	TCA_FQ_CODEL_TARGET,
+	TCA_FQ_CODEL_LIMIT,
+	TCA_FQ_CODEL_INTERVAL,
+	TCA_FQ_CODEL_ECN,
+	TCA_FQ_CODEL_FLOWS,
+	TCA_FQ_CODEL_QUANTUM,
+	TCA_FQ_CODEL_CE_THRESHOLD,
+	__TCA_FQ_CODEL_MAX
+};
+
+#define TCA_FQ_CODEL_MAX	(__TCA_FQ_CODEL_MAX - 1)
+
+enum {
+	TCA_FQ_CODEL_XSTATS_QDISC,
+	TCA_FQ_CODEL_XSTATS_CLASS,
+};
+
+struct tc_fq_codel_qd_stats {
+	__u32	maxpacket;	/* largest packet we've seen so far */
+	__u32	drop_overlimit; /* number of time max qdisc
+				 * packet limit was hit
+				 */
+	__u32	ecn_mark;	/* number of packets we ECN marked
+				 * instead of being dropped
+				 */
+	__u32	new_flow_count; /* number of time packets
+				 * created a 'new flow'
+				 */
+	__u32	new_flows_len;	/* count of flows in new list */
+	__u32	old_flows_len;	/* count of flows in old list */
+	__u32	ce_mark;	/* packets above ce_threshold */
+};
+
+struct tc_fq_codel_cl_stats {
+	__s32	deficit;
+	__u32	ldelay;		/* in-queue delay seen by most recently
+				 * dequeued packet
+				 */
+	__u32	count;
+	__u32	lastcount;
+	__u32	dropping;
+	__s32	drop_next;
+};
+
+struct tc_fq_codel_xstats {
+	__u32	type;
+	union {
+		struct tc_fq_codel_qd_stats qdisc_stats;
+		struct tc_fq_codel_cl_stats class_stats;
+	};
+};
+
+/* FQ */
+
+enum {
+	TCA_FQ_UNSPEC,
+
+	TCA_FQ_PLIMIT,		/* limit of total number of packets in queue */
+
+	TCA_FQ_FLOW_PLIMIT,	/* limit of packets per flow */
+
+	TCA_FQ_QUANTUM,		/* RR quantum */
+
+	TCA_FQ_INITIAL_QUANTUM,		/* RR quantum for new flow */
+
+	TCA_FQ_RATE_ENABLE,	/* enable/disable rate limiting */
+
+	TCA_FQ_FLOW_DEFAULT_RATE,/* obsolete, do not use */
+
+	TCA_FQ_FLOW_MAX_RATE,	/* per flow max rate */
+
+	TCA_FQ_BUCKETS_LOG,	/* log2(number of buckets) */
+
+	TCA_FQ_FLOW_REFILL_DELAY,	/* flow credit refill delay in usec */
+
+	TCA_FQ_ORPHAN_MASK,	/* mask applied to orphaned skb hashes */
+
+	__TCA_FQ_MAX
+};
+
+#define TCA_FQ_MAX	(__TCA_FQ_MAX - 1)
+
+struct tc_fq_qd_stats {
+	__u64	gc_flows;
+	__u64	highprio_packets;
+	__u64	tcp_retrans;
+	__u64	throttled;
+	__u64	flows_plimit;
+	__u64	pkts_too_long;
+	__u64	allocation_errors;
+	__s64	time_next_delayed_flow;
+	__u32	flows;
+	__u32	inactive_flows;
+	__u32	throttled_flows;
+	__u32	pad;
+};
+
+/* Heavy-Hitter Filter */
+
+enum {
+	TCA_HHF_UNSPEC,
+	TCA_HHF_BACKLOG_LIMIT,
+	TCA_HHF_QUANTUM,
+	TCA_HHF_HH_FLOWS_LIMIT,
+	TCA_HHF_RESET_TIMEOUT,
+	TCA_HHF_ADMIT_BYTES,
+	TCA_HHF_EVICT_TIMEOUT,
+	TCA_HHF_NON_HH_WEIGHT,
+	__TCA_HHF_MAX
+};
+
+#define TCA_HHF_MAX	(__TCA_HHF_MAX - 1)
+
+struct tc_hhf_xstats {
+	__u32	drop_overlimit; /* number of times max qdisc packet limit
+				 * was hit
+				 */
+	__u32	hh_overlimit;   /* number of times max heavy-hitters was hit */
+	__u32	hh_tot_count;   /* number of captured heavy-hitters so far */
+	__u32	hh_cur_count;   /* number of current heavy-hitters */
+};
+
+/* PIE */
+enum {
+	TCA_PIE_UNSPEC,
+	TCA_PIE_TARGET,
+	TCA_PIE_LIMIT,
+	TCA_PIE_TUPDATE,
+	TCA_PIE_ALPHA,
+	TCA_PIE_BETA,
+	TCA_PIE_ECN,
+	TCA_PIE_BYTEMODE,
+	__TCA_PIE_MAX
+};
+#define TCA_PIE_MAX   (__TCA_PIE_MAX - 1)
+
+struct tc_pie_xstats {
+	__u32 prob;             /* current probability */
+	__u32 delay;            /* current delay in ms */
+	__u32 avg_dq_rate;      /* current average dq_rate in bits/pie_time */
+	__u32 packets_in;       /* total number of packets enqueued */
+	__u32 dropped;          /* packets dropped due to pie_action */
+	__u32 overlimit;        /* dropped due to lack of space in queue */
+	__u32 maxq;             /* maximum queue size */
+	__u32 ecn_mark;         /* packets marked with ecn*/
+};
+#endif
diff --git a/include/uapi/linux/rtnetlink.h b/include/linux/rtnetlink.h
similarity index 86%
rename from include/uapi/linux/rtnetlink.h
rename to include/linux/rtnetlink.h
index 358e83e..5fc9337 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_RTNETLINK_H
 #define __LINUX_RTNETLINK_H
 
@@ -123,8 +122,6 @@
 
 	RTM_NEWNETCONF = 80,
 #define RTM_NEWNETCONF RTM_NEWNETCONF
-	RTM_DELNETCONF,
-#define RTM_DELNETCONF RTM_DELNETCONF
 	RTM_GETNETCONF = 82,
 #define RTM_GETNETCONF RTM_GETNETCONF
 
@@ -142,28 +139,6 @@
 	RTM_GETNSID = 90,
 #define RTM_GETNSID RTM_GETNSID
 
-	RTM_NEWSTATS = 92,
-#define RTM_NEWSTATS RTM_NEWSTATS
-	RTM_GETSTATS = 94,
-#define RTM_GETSTATS RTM_GETSTATS
-
-	RTM_NEWCACHEREPORT = 96,
-#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
-
-	RTM_NEWCHAIN = 100,
-#define RTM_NEWCHAIN RTM_NEWCHAIN
-	RTM_DELCHAIN,
-#define RTM_DELCHAIN RTM_DELCHAIN
-	RTM_GETCHAIN,
-#define RTM_GETCHAIN RTM_GETCHAIN
-
-	RTM_NEWNEXTHOP = 104,
-#define RTM_NEWNEXTHOP	RTM_NEWNEXTHOP
-	RTM_DELNEXTHOP,
-#define RTM_DELNEXTHOP	RTM_DELNEXTHOP
-	RTM_GETNEXTHOP,
-#define RTM_GETNEXTHOP	RTM_GETNEXTHOP
-
 	__RTM_MAX,
 #define RTM_MAX		(((__RTM_MAX + 3) & ~3) - 1)
 };
@@ -268,11 +243,6 @@
 #define RTPROT_DHCP	16      /* DHCP client */
 #define RTPROT_MROUTED	17      /* Multicast daemon */
 #define RTPROT_BABEL	42      /* Babel daemon */
-#define RTPROT_BGP	186     /* BGP Routes */
-#define RTPROT_ISIS	187     /* ISIS Routes */
-#define RTPROT_OSPF	188     /* OSPF Routes */
-#define RTPROT_RIP	189     /* RIP Routes */
-#define RTPROT_EIGRP	192     /* EIGRP Routes */
 
 /* rtm_scope
 
@@ -301,7 +271,6 @@
 #define RTM_F_EQUALIZE		0x400	/* Multipath equalizer: NI	*/
 #define RTM_F_PREFIX		0x800	/* Prefix addresses		*/
 #define RTM_F_LOOKUP_TABLE	0x1000	/* set rtm_table to FIB lookup result */
-#define RTM_F_FIB_MATCH	        0x2000	/* return full fib lookup match */
 
 /* Reserved table identifiers */
 
@@ -345,11 +314,6 @@
 	RTA_EXPIRES,
 	RTA_PAD,
 	RTA_UID,
-	RTA_TTL_PROPAGATE,
-	RTA_IP_PROTO,
-	RTA_SPORT,
-	RTA_DPORT,
-	RTA_NH_ID,
 	__RTA_MAX
 };
 
@@ -381,9 +345,8 @@
 #define RTNH_F_ONLINK		4	/* Gateway is forced on link	*/
 #define RTNH_F_OFFLOAD		8	/* offloaded route */
 #define RTNH_F_LINKDOWN		16	/* carrier-down on nexthop */
-#define RTNH_F_UNRESOLVED	32	/* The entry is unresolved (ipmr) */
 
-#define RTNH_COMPARE_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN | RTNH_F_OFFLOAD)
+#define RTNH_COMPARE_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN)
 
 /* Macros to handle hexthops */
 
@@ -454,8 +417,6 @@
 #define RTAX_QUICKACK RTAX_QUICKACK
 	RTAX_CC_ALGO,
 #define RTAX_CC_ALGO RTAX_CC_ALGO
-	RTAX_FASTOPEN_NO_COOKIE,
-#define RTAX_FASTOPEN_NO_COOKIE RTAX_FASTOPEN_NO_COOKIE
 	__RTAX_MAX
 };
 
@@ -564,19 +525,9 @@
 	int		tcm_ifindex;
 	__u32		tcm_handle;
 	__u32		tcm_parent;
-/* tcm_block_index is used instead of tcm_parent
- * in case tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK
- */
-#define tcm_block_index tcm_parent
 	__u32		tcm_info;
 };
 
-/* For manipulation of filters in shared block, tcm_ifindex is set to
- * TCM_IFINDEX_MAGIC_BLOCK, and tcm_parent is aliased to tcm_block_index
- * which is the block index.
- */
-#define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU)
-
 enum {
 	TCA_UNSPEC,
 	TCA_KIND,
@@ -587,12 +538,6 @@
 	TCA_FCNT,
 	TCA_STATS2,
 	TCA_STAB,
-	TCA_PAD,
-	TCA_DUMP_INVISIBLE,
-	TCA_CHAIN,
-	TCA_HW_OFFLOAD,
-	TCA_INGRESS_BLOCK,
-	TCA_EGRESS_BLOCK,
 	__TCA_MAX
 };
 
@@ -704,14 +649,6 @@
 #define RTNLGRP_MPLS_ROUTE	RTNLGRP_MPLS_ROUTE
 	RTNLGRP_NSID,
 #define RTNLGRP_NSID		RTNLGRP_NSID
-	RTNLGRP_MPLS_NETCONF,
-#define RTNLGRP_MPLS_NETCONF	RTNLGRP_MPLS_NETCONF
-	RTNLGRP_IPV4_MROUTE_R,
-#define RTNLGRP_IPV4_MROUTE_R	RTNLGRP_IPV4_MROUTE_R
-	RTNLGRP_IPV6_MROUTE_R,
-#define RTNLGRP_IPV6_MROUTE_R	RTNLGRP_IPV6_MROUTE_R
-	RTNLGRP_NEXTHOP,
-#define RTNLGRP_NEXTHOP		RTNLGRP_NEXTHOP
 	__RTNLGRP_MAX
 };
 #define RTNLGRP_MAX	(__RTNLGRP_MAX - 1)
@@ -722,29 +659,10 @@
 	unsigned char	tca__pad1;
 	unsigned short	tca__pad2;
 };
-
-enum {
-	TCA_ROOT_UNSPEC,
-	TCA_ROOT_TAB,
-#define TCA_ACT_TAB TCA_ROOT_TAB
-#define TCAA_MAX TCA_ROOT_TAB
-	TCA_ROOT_FLAGS,
-	TCA_ROOT_COUNT,
-	TCA_ROOT_TIME_DELTA, /* in msecs */
-	__TCA_ROOT_MAX,
-#define	TCA_ROOT_MAX (__TCA_ROOT_MAX - 1)
-};
-
 #define TA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
-/* tcamsg flags stored in attribute TCA_ROOT_FLAGS
- *
- * TCA_FLAG_LARGE_DUMP_ON user->kernel to request for larger than TCA_ACT_MAX_PRIO
- * actions in a dump. All dump responses will contain the number of actions
- * being dumped stored in for user app's consumption in TCA_ROOT_COUNT
- *
- */
-#define TCA_FLAG_LARGE_DUMP_ON		(1 << 0)
+#define TCA_ACT_TAB 1 /* attr type must be >=1 */	
+#define TCAA_MAX 1
 
 /* New extended info filters for IFLA_EXT_MASK */
 #define RTEXT_FILTER_VF		(1 << 0)
diff --git a/include/uapi/linux/sock_diag.h b/include/linux/sock_diag.h
similarity index 88%
rename from include/uapi/linux/sock_diag.h
rename to include/linux/sock_diag.h
index a69cf20..dafcb89 100644
--- a/include/uapi/linux/sock_diag.h
+++ b/include/linux/sock_diag.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __SOCK_DIAG_H__
 #define __SOCK_DIAG_H__
 
@@ -21,7 +20,6 @@
 	SK_MEMINFO_WMEM_QUEUED,
 	SK_MEMINFO_OPTMEM,
 	SK_MEMINFO_BACKLOG,
-	SK_MEMINFO_DROPS,
 
 	SK_MEMINFO_VARS,
 };
diff --git a/include/uapi/linux/tc_act/tc_bpf.h b/include/linux/tc_act/tc_bpf.h
similarity index 84%
rename from include/uapi/linux/tc_act/tc_bpf.h
rename to include/linux/tc_act/tc_bpf.h
index 653c4f9..07f17cc 100644
--- a/include/uapi/linux/tc_act/tc_bpf.h
+++ b/include/linux/tc_act/tc_bpf.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * Copyright (c) 2015 Jiri Pirko <jiri@resnulli.us>
  *
@@ -13,6 +12,8 @@
 
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_BPF 13
+
 struct tc_act_bpf {
 	tc_gen;
 };
@@ -25,9 +26,6 @@
 	TCA_ACT_BPF_OPS,
 	TCA_ACT_BPF_FD,
 	TCA_ACT_BPF_NAME,
-	TCA_ACT_BPF_PAD,
-	TCA_ACT_BPF_TAG,
-	TCA_ACT_BPF_ID,
 	__TCA_ACT_BPF_MAX,
 };
 #define TCA_ACT_BPF_MAX (__TCA_ACT_BPF_MAX - 1)
diff --git a/include/uapi/linux/tc_act/tc_connmark.h b/include/linux/tc_act/tc_connmark.h
similarity index 78%
rename from include/uapi/linux/tc_act/tc_connmark.h
rename to include/linux/tc_act/tc_connmark.h
index 9f8f6f7..994b097 100644
--- a/include/uapi/linux/tc_act/tc_connmark.h
+++ b/include/linux/tc_act/tc_connmark.h
@@ -1,10 +1,11 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __UAPI_TC_CONNMARK_H
 #define __UAPI_TC_CONNMARK_H
 
 #include <linux/types.h>
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_CONNMARK 14
+
 struct tc_connmark {
 	tc_gen;
 	__u16 zone;
@@ -14,7 +15,6 @@
 	TCA_CONNMARK_UNSPEC,
 	TCA_CONNMARK_PARMS,
 	TCA_CONNMARK_TM,
-	TCA_CONNMARK_PAD,
 	__TCA_CONNMARK_MAX
 };
 #define TCA_CONNMARK_MAX (__TCA_CONNMARK_MAX - 1)
diff --git a/include/uapi/linux/tc_act/tc_csum.h b/include/linux/tc_act/tc_csum.h
similarity index 76%
rename from include/uapi/linux/tc_act/tc_csum.h
rename to include/linux/tc_act/tc_csum.h
index 94b2044..a047c49 100644
--- a/include/uapi/linux/tc_act/tc_csum.h
+++ b/include/linux/tc_act/tc_csum.h
@@ -1,15 +1,15 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_CSUM_H
 #define __LINUX_TC_CSUM_H
 
 #include <linux/types.h>
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_CSUM 16
+
 enum {
 	TCA_CSUM_UNSPEC,
 	TCA_CSUM_PARMS,
 	TCA_CSUM_TM,
-	TCA_CSUM_PAD,
 	__TCA_CSUM_MAX
 };
 #define TCA_CSUM_MAX (__TCA_CSUM_MAX - 1)
@@ -20,8 +20,7 @@
 	TCA_CSUM_UPDATE_FLAG_IGMP    = 4,
 	TCA_CSUM_UPDATE_FLAG_TCP     = 8,
 	TCA_CSUM_UPDATE_FLAG_UDP     = 16,
-	TCA_CSUM_UPDATE_FLAG_UDPLITE = 32,
-	TCA_CSUM_UPDATE_FLAG_SCTP    = 64,
+	TCA_CSUM_UPDATE_FLAG_UDPLITE = 32
 };
 
 struct tc_csum {
diff --git a/include/uapi/linux/tc_act/tc_defact.h b/include/linux/tc_act/tc_defact.h
similarity index 76%
rename from include/uapi/linux/tc_act/tc_defact.h
rename to include/linux/tc_act/tc_defact.h
index e3ecd8b..17dddb4 100644
--- a/include/uapi/linux/tc_act/tc_defact.h
+++ b/include/linux/tc_act/tc_defact.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_DEF_H
 #define __LINUX_TC_DEF_H
 
@@ -13,7 +12,6 @@
 	TCA_DEF_TM,
 	TCA_DEF_PARMS,
 	TCA_DEF_DATA,
-	TCA_DEF_PAD,
 	__TCA_DEF_MAX
 };
 #define TCA_DEF_MAX (__TCA_DEF_MAX - 1)
diff --git a/include/uapi/linux/tc_act/tc_gact.h b/include/linux/tc_act/tc_gact.h
similarity index 87%
rename from include/uapi/linux/tc_act/tc_gact.h
rename to include/linux/tc_act/tc_gact.h
index 37e5392..f7bf94e 100644
--- a/include/uapi/linux/tc_act/tc_gact.h
+++ b/include/linux/tc_act/tc_gact.h
@@ -1,10 +1,10 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_GACT_H
 #define __LINUX_TC_GACT_H
 
 #include <linux/types.h>
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_GACT 5
 struct tc_gact {
 	tc_gen;
 
@@ -25,7 +25,6 @@
 	TCA_GACT_TM,
 	TCA_GACT_PARMS,
 	TCA_GACT_PROB,
-	TCA_GACT_PAD,
 	__TCA_GACT_MAX
 };
 #define TCA_GACT_MAX (__TCA_GACT_MAX - 1)
diff --git a/include/uapi/linux/tc_act/tc_ipt.h b/include/linux/tc_act/tc_ipt.h
similarity index 81%
rename from include/uapi/linux/tc_act/tc_ipt.h
rename to include/linux/tc_act/tc_ipt.h
index c48d7da..130aaad 100644
--- a/include/uapi/linux/tc_act/tc_ipt.h
+++ b/include/linux/tc_act/tc_ipt.h
@@ -1,9 +1,11 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_IPT_H
 #define __LINUX_TC_IPT_H
 
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_IPT 6
+#define TCA_ACT_XT 10
+
 enum {
 	TCA_IPT_UNSPEC,
 	TCA_IPT_TABLE,
@@ -12,7 +14,6 @@
 	TCA_IPT_CNT,
 	TCA_IPT_TM,
 	TCA_IPT_TARG,
-	TCA_IPT_PAD,
 	__TCA_IPT_MAX
 };
 #define TCA_IPT_MAX (__TCA_IPT_MAX - 1)
diff --git a/include/uapi/linux/tc_act/tc_mirred.h b/include/linux/tc_act/tc_mirred.h
similarity index 70%
rename from include/uapi/linux/tc_act/tc_mirred.h
rename to include/linux/tc_act/tc_mirred.h
index 2500a00..7561750 100644
--- a/include/uapi/linux/tc_act/tc_mirred.h
+++ b/include/linux/tc_act/tc_mirred.h
@@ -1,28 +1,27 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_MIR_H
 #define __LINUX_TC_MIR_H
 
 #include <linux/types.h>
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_MIRRED 8
 #define TCA_EGRESS_REDIR 1  /* packet redirect to EGRESS*/
 #define TCA_EGRESS_MIRROR 2 /* mirror packet to EGRESS */
 #define TCA_INGRESS_REDIR 3  /* packet redirect to INGRESS*/
 #define TCA_INGRESS_MIRROR 4 /* mirror packet to INGRESS */
-
+                                                                                
 struct tc_mirred {
 	tc_gen;
 	int                     eaction;   /* one of IN/EGRESS_MIRROR/REDIR */
 	__u32                   ifindex;  /* ifindex of egress port */
 };
-
+                                                                                
 enum {
 	TCA_MIRRED_UNSPEC,
 	TCA_MIRRED_TM,
 	TCA_MIRRED_PARMS,
-	TCA_MIRRED_PAD,
 	__TCA_MIRRED_MAX
 };
 #define TCA_MIRRED_MAX (__TCA_MIRRED_MAX - 1)
-
+                                                                                
 #endif
diff --git a/include/uapi/linux/tc_act/tc_nat.h b/include/linux/tc_act/tc_nat.h
similarity index 81%
rename from include/uapi/linux/tc_act/tc_nat.h
rename to include/linux/tc_act/tc_nat.h
index 21399c2..6663aeb 100644
--- a/include/uapi/linux/tc_act/tc_nat.h
+++ b/include/linux/tc_act/tc_nat.h
@@ -1,15 +1,15 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_NAT_H
 #define __LINUX_TC_NAT_H
 
 #include <linux/pkt_cls.h>
 #include <linux/types.h>
 
+#define TCA_ACT_NAT 9
+
 enum {
 	TCA_NAT_UNSPEC,
 	TCA_NAT_PARMS,
 	TCA_NAT_TM,
-	TCA_NAT_PAD,
 	__TCA_NAT_MAX
 };
 #define TCA_NAT_MAX (__TCA_NAT_MAX - 1)
diff --git a/include/linux/tc_act/tc_pedit.h b/include/linux/tc_act/tc_pedit.h
new file mode 100644
index 0000000..716cfab
--- /dev/null
+++ b/include/linux/tc_act/tc_pedit.h
@@ -0,0 +1,34 @@
+#ifndef __LINUX_TC_PED_H
+#define __LINUX_TC_PED_H
+
+#include <linux/types.h>
+#include <linux/pkt_cls.h>
+
+#define TCA_ACT_PEDIT 7
+
+enum {
+	TCA_PEDIT_UNSPEC,
+	TCA_PEDIT_TM,
+	TCA_PEDIT_PARMS,
+	__TCA_PEDIT_MAX
+};
+#define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1)
+                                                                                
+struct tc_pedit_key {
+	__u32           mask;  /* AND */
+	__u32           val;   /*XOR */
+	__u32           off;  /*offset */
+	__u32           at;
+	__u32           offmask;
+	__u32           shift;
+};
+                                                                                
+struct tc_pedit_sel {
+	tc_gen;
+	unsigned char           nkeys;
+	unsigned char           flags;
+	struct tc_pedit_key     keys[0];
+};
+#define tc_pedit tc_pedit_sel
+
+#endif
diff --git a/include/uapi/linux/tc_act/tc_skbedit.h b/include/linux/tc_act/tc_skbedit.h
similarity index 83%
rename from include/uapi/linux/tc_act/tc_skbedit.h
rename to include/linux/tc_act/tc_skbedit.h
index 800e933..7a2e910 100644
--- a/include/uapi/linux/tc_act/tc_skbedit.h
+++ b/include/linux/tc_act/tc_skbedit.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /*
  * Copyright (c) 2008, Intel Corporation.
  *
@@ -23,12 +22,11 @@
 
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_SKBEDIT 11
+
 #define SKBEDIT_F_PRIORITY		0x1
 #define SKBEDIT_F_QUEUE_MAPPING		0x2
 #define SKBEDIT_F_MARK			0x4
-#define SKBEDIT_F_PTYPE			0x8
-#define SKBEDIT_F_MASK			0x10
-#define SKBEDIT_F_INHERITDSFIELD	0x20
 
 struct tc_skbedit {
 	tc_gen;
@@ -41,10 +39,6 @@
 	TCA_SKBEDIT_PRIORITY,
 	TCA_SKBEDIT_QUEUE_MAPPING,
 	TCA_SKBEDIT_MARK,
-	TCA_SKBEDIT_PAD,
-	TCA_SKBEDIT_PTYPE,
-	TCA_SKBEDIT_MASK,
-	TCA_SKBEDIT_FLAGS,
 	__TCA_SKBEDIT_MAX
 };
 #define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)
diff --git a/include/uapi/linux/tc_act/tc_vlan.h b/include/linux/tc_act/tc_vlan.h
similarity index 82%
rename from include/uapi/linux/tc_act/tc_vlan.h
rename to include/linux/tc_act/tc_vlan.h
index 168995b..f7b8d44 100644
--- a/include/uapi/linux/tc_act/tc_vlan.h
+++ b/include/linux/tc_act/tc_vlan.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
 /*
  * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
  *
@@ -13,9 +12,10 @@
 
 #include <linux/pkt_cls.h>
 
+#define TCA_ACT_VLAN 12
+
 #define TCA_VLAN_ACT_POP	1
 #define TCA_VLAN_ACT_PUSH	2
-#define TCA_VLAN_ACT_MODIFY	3
 
 struct tc_vlan {
 	tc_gen;
@@ -28,8 +28,6 @@
 	TCA_VLAN_PARMS,
 	TCA_VLAN_PUSH_VLAN_ID,
 	TCA_VLAN_PUSH_VLAN_PROTOCOL,
-	TCA_VLAN_PAD,
-	TCA_VLAN_PUSH_VLAN_PRIORITY,
 	__TCA_VLAN_MAX,
 };
 #define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1)
diff --git a/include/uapi/linux/tc_ematch/tc_em_cmp.h b/include/linux/tc_ematch/tc_em_cmp.h
similarity index 84%
rename from include/uapi/linux/tc_ematch/tc_em_cmp.h
rename to include/linux/tc_ematch/tc_em_cmp.h
index 2549d9d..f34bb1b 100644
--- a/include/uapi/linux/tc_ematch/tc_em_cmp.h
+++ b/include/linux/tc_ematch/tc_em_cmp.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_EM_CMP_H
 #define __LINUX_TC_EM_CMP_H
 
diff --git a/include/uapi/linux/tc_ematch/tc_em_meta.h b/include/linux/tc_ematch/tc_em_meta.h
similarity index 96%
rename from include/uapi/linux/tc_ematch/tc_em_meta.h
rename to include/linux/tc_ematch/tc_em_meta.h
index cf30b5b..b11f8ce 100644
--- a/include/uapi/linux/tc_ematch/tc_em_meta.h
+++ b/include/linux/tc_ematch/tc_em_meta.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_EM_META_H
 #define __LINUX_TC_EM_META_H
 
diff --git a/include/uapi/linux/tc_ematch/tc_em_nbyte.h b/include/linux/tc_ematch/tc_em_nbyte.h
similarity index 75%
rename from include/uapi/linux/tc_ematch/tc_em_nbyte.h
rename to include/linux/tc_ematch/tc_em_nbyte.h
index c76333f..7172cfb 100644
--- a/include/uapi/linux/tc_ematch/tc_em_nbyte.h
+++ b/include/linux/tc_ematch/tc_em_nbyte.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __LINUX_TC_EM_NBYTE_H
 #define __LINUX_TC_EM_NBYTE_H
 
diff --git a/include/linux/tc_ematch/tc_em_text.h b/include/linux/tc_ematch/tc_em_text.h
new file mode 100644
index 0000000..5aac404
--- /dev/null
+++ b/include/linux/tc_ematch/tc_em_text.h
@@ -0,0 +1,19 @@
+#ifndef __LINUX_TC_EM_TEXT_H
+#define __LINUX_TC_EM_TEXT_H
+
+#include <linux/types.h>
+#include <linux/pkt_cls.h>
+
+#define TC_EM_TEXT_ALGOSIZ	16
+
+struct tcf_em_text {
+	char		algo[TC_EM_TEXT_ALGOSIZ];
+	__u16		from_offset;
+	__u16		to_offset;
+	__u16		pattern_len;
+	__u8		from_layer:4;
+	__u8		to_layer:4;
+	__u8		pad;
+};
+
+#endif
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
new file mode 100644
index 0000000..1e9b4a6
--- /dev/null
+++ b/include/linux/tcp.h
@@ -0,0 +1,212 @@
+/*
+ * INET		An implementation of the TCP/IP protocol suite for the LINUX
+ *		operating system.  INET is implemented using the  BSD Socket
+ *		interface as the means of communication with the user level.
+ *
+ *		Definitions for the TCP protocol.
+ *
+ * Version:	@(#)tcp.h	1.0.2	04/28/93
+ *
+ * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
+ *
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ */
+#ifndef _LINUX_TCP_H
+#define _LINUX_TCP_H
+
+#include <linux/types.h>
+#include <asm/byteorder.h>
+#include <linux/socket.h>
+
+struct tcphdr {
+	__be16	source;
+	__be16	dest;
+	__be32	seq;
+	__be32	ack_seq;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+	__u16	res1:4,
+		doff:4,
+		fin:1,
+		syn:1,
+		rst:1,
+		psh:1,
+		ack:1,
+		urg:1,
+		ece:1,
+		cwr:1;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+	__u16	doff:4,
+		res1:4,
+		cwr:1,
+		ece:1,
+		urg:1,
+		ack:1,
+		psh:1,
+		rst:1,
+		syn:1,
+		fin:1;
+#else
+#error	"Adjust your <asm/byteorder.h> defines"
+#endif	
+	__be16	window;
+	__sum16	check;
+	__be16	urg_ptr;
+};
+
+/*
+ *	The union cast uses a gcc extension to avoid aliasing problems
+ *  (union is compatible to any of its members)
+ *  This means this part of the code is -fstrict-aliasing safe now.
+ */
+union tcp_word_hdr { 
+	struct tcphdr hdr;
+	__be32 		  words[5];
+}; 
+
+#define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3]) 
+
+enum { 
+	TCP_FLAG_CWR = __constant_cpu_to_be32(0x00800000),
+	TCP_FLAG_ECE = __constant_cpu_to_be32(0x00400000),
+	TCP_FLAG_URG = __constant_cpu_to_be32(0x00200000),
+	TCP_FLAG_ACK = __constant_cpu_to_be32(0x00100000),
+	TCP_FLAG_PSH = __constant_cpu_to_be32(0x00080000),
+	TCP_FLAG_RST = __constant_cpu_to_be32(0x00040000),
+	TCP_FLAG_SYN = __constant_cpu_to_be32(0x00020000),
+	TCP_FLAG_FIN = __constant_cpu_to_be32(0x00010000),
+	TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0F000000),
+	TCP_DATA_OFFSET = __constant_cpu_to_be32(0xF0000000)
+}; 
+
+/*
+ * TCP general constants
+ */
+#define TCP_MSS_DEFAULT		 536U	/* IPv4 (RFC1122, RFC2581) */
+#define TCP_MSS_DESIRED		1220U	/* IPv6 (tunneled), EDNS0 (RFC3226) */
+
+/* TCP socket options */
+#define TCP_NODELAY		1	/* Turn off Nagle's algorithm. */
+#define TCP_MAXSEG		2	/* Limit MSS */
+#define TCP_CORK		3	/* Never send partially complete segments */
+#define TCP_KEEPIDLE		4	/* Start keeplives after this period */
+#define TCP_KEEPINTVL		5	/* Interval between keepalives */
+#define TCP_KEEPCNT		6	/* Number of keepalives before death */
+#define TCP_SYNCNT		7	/* Number of SYN retransmits */
+#define TCP_LINGER2		8	/* Life time of orphaned FIN-WAIT-2 state */
+#define TCP_DEFER_ACCEPT	9	/* Wake up listener only when data arrive */
+#define TCP_WINDOW_CLAMP	10	/* Bound advertised window */
+#define TCP_INFO		11	/* Information about this connection. */
+#define TCP_QUICKACK		12	/* Block/reenable quick acks */
+#define TCP_CONGESTION		13	/* Congestion control algorithm */
+#define TCP_MD5SIG		14	/* TCP MD5 Signature (RFC2385) */
+#define TCP_THIN_LINEAR_TIMEOUTS 16      /* Use linear timeouts for thin streams*/
+#define TCP_THIN_DUPACK         17      /* Fast retrans. after 1 dupack */
+#define TCP_USER_TIMEOUT	18	/* How long for loss retry before timeout */
+#define TCP_REPAIR		19	/* TCP sock is under repair right now */
+#define TCP_REPAIR_QUEUE	20
+#define TCP_QUEUE_SEQ		21
+#define TCP_REPAIR_OPTIONS	22
+#define TCP_FASTOPEN		23	/* Enable FastOpen on listeners */
+#define TCP_TIMESTAMP		24
+#define TCP_NOTSENT_LOWAT	25	/* limit number of unsent bytes in write queue */
+#define TCP_CC_INFO		26	/* Get Congestion Control (optional) info */
+#define TCP_SAVE_SYN		27	/* Record SYN headers for new connections */
+#define TCP_SAVED_SYN		28	/* Get SYN headers recorded for connection */
+
+struct tcp_repair_opt {
+	__u32	opt_code;
+	__u32	opt_val;
+};
+
+enum {
+	TCP_NO_QUEUE,
+	TCP_RECV_QUEUE,
+	TCP_SEND_QUEUE,
+	TCP_QUEUES_NR,
+};
+
+/* for TCP_INFO socket option */
+#define TCPI_OPT_TIMESTAMPS	1
+#define TCPI_OPT_SACK		2
+#define TCPI_OPT_WSCALE		4
+#define TCPI_OPT_ECN		8 /* ECN was negociated at TCP session init */
+#define TCPI_OPT_ECN_SEEN	16 /* we received at least one packet with ECT */
+#define TCPI_OPT_SYN_DATA	32 /* SYN-ACK acked data in SYN sent or rcvd */
+
+enum tcp_ca_state {
+	TCP_CA_Open = 0,
+#define TCPF_CA_Open	(1<<TCP_CA_Open)
+	TCP_CA_Disorder = 1,
+#define TCPF_CA_Disorder (1<<TCP_CA_Disorder)
+	TCP_CA_CWR = 2,
+#define TCPF_CA_CWR	(1<<TCP_CA_CWR)
+	TCP_CA_Recovery = 3,
+#define TCPF_CA_Recovery (1<<TCP_CA_Recovery)
+	TCP_CA_Loss = 4
+#define TCPF_CA_Loss	(1<<TCP_CA_Loss)
+};
+
+struct tcp_info {
+	__u8	tcpi_state;
+	__u8	tcpi_ca_state;
+	__u8	tcpi_retransmits;
+	__u8	tcpi_probes;
+	__u8	tcpi_backoff;
+	__u8	tcpi_options;
+	__u8	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
+
+	__u32	tcpi_rto;
+	__u32	tcpi_ato;
+	__u32	tcpi_snd_mss;
+	__u32	tcpi_rcv_mss;
+
+	__u32	tcpi_unacked;
+	__u32	tcpi_sacked;
+	__u32	tcpi_lost;
+	__u32	tcpi_retrans;
+	__u32	tcpi_fackets;
+
+	/* Times. */
+	__u32	tcpi_last_data_sent;
+	__u32	tcpi_last_ack_sent;     /* Not remembered, sorry. */
+	__u32	tcpi_last_data_recv;
+	__u32	tcpi_last_ack_recv;
+
+	/* Metrics. */
+	__u32	tcpi_pmtu;
+	__u32	tcpi_rcv_ssthresh;
+	__u32	tcpi_rtt;
+	__u32	tcpi_rttvar;
+	__u32	tcpi_snd_ssthresh;
+	__u32	tcpi_snd_cwnd;
+	__u32	tcpi_advmss;
+	__u32	tcpi_reordering;
+
+	__u32	tcpi_rcv_rtt;
+	__u32	tcpi_rcv_space;
+
+	__u32	tcpi_total_retrans;
+
+	__u64	tcpi_pacing_rate;
+	__u64	tcpi_max_pacing_rate;
+	__u64	tcpi_bytes_acked;    /* RFC4898 tcpEStatsAppHCThruOctetsAcked */
+	__u64	tcpi_bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived */
+	__u32	tcpi_segs_out;	     /* RFC4898 tcpEStatsPerfSegsOut */
+	__u32	tcpi_segs_in;	     /* RFC4898 tcpEStatsPerfSegsIn */
+};
+
+/* for TCP_MD5SIG socket option */
+#define TCP_MD5SIG_MAXKEYLEN	80
+
+struct tcp_md5sig {
+	struct __kernel_sockaddr_storage tcpm_addr;	/* address associated */
+	__u16	__tcpm_pad1;				/* zero */
+	__u16	tcpm_keylen;				/* key length */
+	__u32	__tcpm_pad2;				/* zero */
+	__u8	tcpm_key[TCP_MD5SIG_MAXKEYLEN];		/* key (binary) */
+};
+
+#endif /* _LINUX_TCP_H */
diff --git a/include/uapi/linux/tcp_metrics.h b/include/linux/tcp_metrics.h
similarity index 94%
rename from include/uapi/linux/tcp_metrics.h
rename to include/linux/tcp_metrics.h
index 7cb4a17..9353392 100644
--- a/include/uapi/linux/tcp_metrics.h
+++ b/include/linux/tcp_metrics.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /* tcp_metrics.h - TCP Metrics Interface */
 
 #ifndef _LINUX_TCP_METRICS_H
@@ -41,7 +40,6 @@
 	TCP_METRICS_ATTR_FOPEN_COOKIE,		/* binary */
 	TCP_METRICS_ATTR_SADDR_IPV4,		/* u32 */
 	TCP_METRICS_ATTR_SADDR_IPV6,		/* binary */
-	TCP_METRICS_ATTR_PAD,
 
 	__TCP_METRICS_ATTR_MAX,
 };
diff --git a/include/linux/tipc.h b/include/linux/tipc.h
new file mode 100644
index 0000000..ebd3b63
--- /dev/null
+++ b/include/linux/tipc.h
@@ -0,0 +1,232 @@
+/*
+ * include/uapi/linux/tipc.h: Header for TIPC socket interface
+ *
+ * Copyright (c) 2003-2006, Ericsson AB
+ * Copyright (c) 2005, 2010-2011, Wind River Systems
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_TIPC_H_
+#define _LINUX_TIPC_H_
+
+#include <linux/types.h>
+#include <linux/sockios.h>
+
+/*
+ * TIPC addressing primitives
+ */
+
+struct tipc_portid {
+	__u32 ref;
+	__u32 node;
+};
+
+struct tipc_name {
+	__u32 type;
+	__u32 instance;
+};
+
+struct tipc_name_seq {
+	__u32 type;
+	__u32 lower;
+	__u32 upper;
+};
+
+static __inline__ __u32 tipc_addr(unsigned int zone,
+			      unsigned int cluster,
+			      unsigned int node)
+{
+	return (zone << 24) | (cluster << 12) | node;
+}
+
+static __inline__ unsigned int tipc_zone(__u32 addr)
+{
+	return addr >> 24;
+}
+
+static __inline__ unsigned int tipc_cluster(__u32 addr)
+{
+	return (addr >> 12) & 0xfff;
+}
+
+static __inline__ unsigned int tipc_node(__u32 addr)
+{
+	return addr & 0xfff;
+}
+
+/*
+ * Application-accessible port name types
+ */
+
+#define TIPC_CFG_SRV		0	/* configuration service name type */
+#define TIPC_TOP_SRV		1	/* topology service name type */
+#define TIPC_LINK_STATE		2	/* link state name type */
+#define TIPC_RESERVED_TYPES	64	/* lowest user-publishable name type */
+
+/*
+ * Publication scopes when binding port names and port name sequences
+ */
+
+#define TIPC_ZONE_SCOPE		1
+#define TIPC_CLUSTER_SCOPE	2
+#define TIPC_NODE_SCOPE		3
+
+/*
+ * Limiting values for messages
+ */
+
+#define TIPC_MAX_USER_MSG_SIZE	66000U
+
+/*
+ * Message importance levels
+ */
+
+#define TIPC_LOW_IMPORTANCE		0
+#define TIPC_MEDIUM_IMPORTANCE		1
+#define TIPC_HIGH_IMPORTANCE		2
+#define TIPC_CRITICAL_IMPORTANCE	3
+
+/*
+ * Msg rejection/connection shutdown reasons
+ */
+
+#define TIPC_OK			0
+#define TIPC_ERR_NO_NAME	1
+#define TIPC_ERR_NO_PORT	2
+#define TIPC_ERR_NO_NODE	3
+#define TIPC_ERR_OVERLOAD	4
+#define TIPC_CONN_SHUTDOWN	5
+
+/*
+ * TIPC topology subscription service definitions
+ */
+
+#define TIPC_SUB_PORTS		0x01	/* filter for port availability */
+#define TIPC_SUB_SERVICE	0x02	/* filter for service availability */
+#define TIPC_SUB_CANCEL		0x04	/* cancel a subscription */
+
+#define TIPC_WAIT_FOREVER	(~0)	/* timeout for permanent subscription */
+
+struct tipc_subscr {
+	struct tipc_name_seq seq;	/* name sequence of interest */
+	__u32 timeout;			/* subscription duration (in ms) */
+	__u32 filter;			/* bitmask of filter options */
+	char usr_handle[8];		/* available for subscriber use */
+};
+
+#define TIPC_PUBLISHED		1	/* publication event */
+#define TIPC_WITHDRAWN		2	/* withdraw event */
+#define TIPC_SUBSCR_TIMEOUT	3	/* subscription timeout event */
+
+struct tipc_event {
+	__u32 event;			/* event type */
+	__u32 found_lower;		/* matching name seq instances */
+	__u32 found_upper;		/*    "      "    "     "      */
+	struct tipc_portid port;	/* associated port */
+	struct tipc_subscr s;		/* associated subscription */
+};
+
+/*
+ * Socket API
+ */
+
+#ifndef AF_TIPC
+#define AF_TIPC		30
+#endif
+
+#ifndef PF_TIPC
+#define PF_TIPC		AF_TIPC
+#endif
+
+#ifndef SOL_TIPC
+#define SOL_TIPC	271
+#endif
+
+#define TIPC_ADDR_NAMESEQ	1
+#define TIPC_ADDR_MCAST		1
+#define TIPC_ADDR_NAME		2
+#define TIPC_ADDR_ID		3
+
+struct sockaddr_tipc {
+	unsigned short family;
+	unsigned char  addrtype;
+	signed   char  scope;
+	union {
+		struct tipc_portid id;
+		struct tipc_name_seq nameseq;
+		struct {
+			struct tipc_name name;
+			__u32 domain;
+		} name;
+	} addr;
+};
+
+/*
+ * Ancillary data objects supported by recvmsg()
+ */
+
+#define TIPC_ERRINFO	1	/* error info */
+#define TIPC_RETDATA	2	/* returned data */
+#define TIPC_DESTNAME	3	/* destination name */
+
+/*
+ * TIPC-specific socket option values
+ */
+
+#define TIPC_IMPORTANCE		127	/* Default: TIPC_LOW_IMPORTANCE */
+#define TIPC_SRC_DROPPABLE	128	/* Default: based on socket type */
+#define TIPC_DEST_DROPPABLE	129	/* Default: based on socket type */
+#define TIPC_CONN_TIMEOUT	130	/* Default: 8000 (ms)  */
+#define TIPC_NODE_RECVQ_DEPTH	131	/* Default: none (read only) */
+#define TIPC_SOCK_RECVQ_DEPTH	132	/* Default: none (read only) */
+
+/*
+ * Maximum sizes of TIPC bearer-related names (including terminating NULL)
+ * The string formatting for each name element is:
+ * media: media
+ * interface: media:interface name
+ * link: Z.C.N:interface-Z.C.N:interface
+ *
+ */
+
+#define TIPC_MAX_MEDIA_NAME	16
+#define TIPC_MAX_IF_NAME	16
+#define TIPC_MAX_BEARER_NAME	32
+#define TIPC_MAX_LINK_NAME	60
+
+#define SIOCGETLINKNAME		SIOCPROTOPRIVATE
+
+struct tipc_sioc_ln_req {
+	__u32 peer;
+	__u32 bearer_id;
+	char linkname[TIPC_MAX_LINK_NAME];
+};
+#endif
diff --git a/include/uapi/linux/tipc_netlink.h b/include/linux/tipc_netlink.h
similarity index 75%
rename from include/uapi/linux/tipc_netlink.h
rename to include/linux/tipc_netlink.h
index efb958f..25eb645 100644
--- a/include/uapi/linux/tipc_netlink.h
+++ b/include/linux/tipc_netlink.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
 /*
  * Copyright (c) 2014, Ericsson AB
  * All rights reserved.
@@ -57,12 +56,7 @@
 	TIPC_NL_NET_GET,
 	TIPC_NL_NET_SET,
 	TIPC_NL_NAME_TABLE_GET,
-	TIPC_NL_MON_SET,
-	TIPC_NL_MON_GET,
-	TIPC_NL_MON_PEER_GET,
 	TIPC_NL_PEER_REMOVE,
-	TIPC_NL_BEARER_ADD,
-	TIPC_NL_UDP_GET_REMOTEIP,
 
 	__TIPC_NL_CMD_MAX,
 	TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
@@ -79,8 +73,6 @@
 	TIPC_NLA_NODE,			/* nest */
 	TIPC_NLA_NET,			/* nest */
 	TIPC_NLA_NAME_TABLE,		/* nest */
-	TIPC_NLA_MON,			/* nest */
-	TIPC_NLA_MON_PEER,		/* nest */
 
 	__TIPC_NLA_MAX,
 	TIPC_NLA_MAX = __TIPC_NLA_MAX - 1
@@ -102,7 +94,6 @@
 	TIPC_NLA_UDP_UNSPEC,
 	TIPC_NLA_UDP_LOCAL,		/* sockaddr_storage */
 	TIPC_NLA_UDP_REMOTE,		/* sockaddr_storage */
-	TIPC_NLA_UDP_MULTI_REMOTEIP,	/* flag */
 
 	__TIPC_NLA_UDP_MAX,
 	TIPC_NLA_UDP_MAX = __TIPC_NLA_UDP_MAX - 1
@@ -114,14 +105,6 @@
 	TIPC_NLA_SOCK_REF,		/* u32 */
 	TIPC_NLA_SOCK_CON,		/* nest */
 	TIPC_NLA_SOCK_HAS_PUBL,		/* flag */
-	TIPC_NLA_SOCK_STAT,		/* nest */
-	TIPC_NLA_SOCK_TYPE,		/* u32 */
-	TIPC_NLA_SOCK_INO,		/* u32 */
-	TIPC_NLA_SOCK_UID,		/* u32 */
-	TIPC_NLA_SOCK_TIPC_STATE,	/* u32 */
-	TIPC_NLA_SOCK_COOKIE,		/* u64 */
-	TIPC_NLA_SOCK_PAD,		/* flag */
-	TIPC_NLA_SOCK_GROUP,		/* nest */
 
 	__TIPC_NLA_SOCK_MAX,
 	TIPC_NLA_SOCK_MAX = __TIPC_NLA_SOCK_MAX - 1
@@ -170,8 +153,6 @@
 	TIPC_NLA_NET_UNSPEC,
 	TIPC_NLA_NET_ID,		/* u32 */
 	TIPC_NLA_NET_ADDR,		/* u32 */
-	TIPC_NLA_NET_NODEID,		/* u64 */
-	TIPC_NLA_NET_NODEID_W1,		/* u64 */
 
 	__TIPC_NLA_NET_MAX,
 	TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1
@@ -186,20 +167,6 @@
 	TIPC_NLA_NAME_TABLE_MAX = __TIPC_NLA_NAME_TABLE_MAX - 1
 };
 
-/* Monitor info */
-enum {
-	TIPC_NLA_MON_UNSPEC,
-	TIPC_NLA_MON_ACTIVATION_THRESHOLD,	/* u32 */
-	TIPC_NLA_MON_REF,			/* u32 */
-	TIPC_NLA_MON_ACTIVE,			/* flag */
-	TIPC_NLA_MON_BEARER_NAME,		/* string */
-	TIPC_NLA_MON_PEERCNT,			/* u32 */
-	TIPC_NLA_MON_LISTGEN,			/* u32 */
-
-	__TIPC_NLA_MON_MAX,
-	TIPC_NLA_MON_MAX = __TIPC_NLA_MON_MAX - 1
-};
-
 /* Publication info */
 enum {
 	TIPC_NLA_PUBL_UNSPEC,
@@ -216,37 +183,6 @@
 	TIPC_NLA_PUBL_MAX = __TIPC_NLA_PUBL_MAX - 1
 };
 
-/* Monitor peer info */
-enum {
-	TIPC_NLA_MON_PEER_UNSPEC,
-
-	TIPC_NLA_MON_PEER_ADDR,			/* u32 */
-	TIPC_NLA_MON_PEER_DOMGEN,		/* u32 */
-	TIPC_NLA_MON_PEER_APPLIED,		/* u32 */
-	TIPC_NLA_MON_PEER_UPMAP,		/* u64 */
-	TIPC_NLA_MON_PEER_MEMBERS,		/* tlv */
-	TIPC_NLA_MON_PEER_UP,			/* flag */
-	TIPC_NLA_MON_PEER_HEAD,			/* flag */
-	TIPC_NLA_MON_PEER_LOCAL,		/* flag */
-	TIPC_NLA_MON_PEER_PAD,			/* flag */
-
-	__TIPC_NLA_MON_PEER_MAX,
-	TIPC_NLA_MON_PEER_MAX = __TIPC_NLA_MON_PEER_MAX - 1
-};
-
-/* Nest, socket group info */
-enum {
-	TIPC_NLA_SOCK_GROUP_ID,			/* u32 */
-	TIPC_NLA_SOCK_GROUP_OPEN,		/* flag */
-	TIPC_NLA_SOCK_GROUP_NODE_SCOPE,		/* flag */
-	TIPC_NLA_SOCK_GROUP_CLUSTER_SCOPE,	/* flag */
-	TIPC_NLA_SOCK_GROUP_INSTANCE,		/* u32 */
-	TIPC_NLA_SOCK_GROUP_BC_SEND_NEXT,	/* u32 */
-
-	__TIPC_NLA_SOCK_GROUP_MAX,
-	TIPC_NLA_SOCK_GROUP_MAX = __TIPC_NLA_SOCK_GROUP_MAX - 1
-};
-
 /* Nest, connection info */
 enum {
 	TIPC_NLA_CON_UNSPEC,
@@ -261,18 +197,6 @@
 	TIPC_NLA_CON_MAX = __TIPC_NLA_CON_MAX - 1
 };
 
-/* Nest, socket statistics info */
-enum {
-	TIPC_NLA_SOCK_STAT_RCVQ,	/* u32 */
-	TIPC_NLA_SOCK_STAT_SENDQ,	/* u32 */
-	TIPC_NLA_SOCK_STAT_LINK_CONG,	/* flag */
-	TIPC_NLA_SOCK_STAT_CONN_CONG,	/* flag */
-	TIPC_NLA_SOCK_STAT_DROP,	/* u32 */
-
-	__TIPC_NLA_SOCK_STAT_MAX,
-	TIPC_NLA_SOCK_STAT_MAX = __TIPC_NLA_SOCK_STAT_MAX - 1
-};
-
 /* Nest, link propreties. Valid for link, media and bearer */
 enum {
 	TIPC_NLA_PROP_UNSPEC,
@@ -280,9 +204,6 @@
 	TIPC_NLA_PROP_PRIO,		/* u32 */
 	TIPC_NLA_PROP_TOL,		/* u32 */
 	TIPC_NLA_PROP_WIN,		/* u32 */
-	TIPC_NLA_PROP_MTU,		/* u32 */
-	TIPC_NLA_PROP_BROADCAST,	/* u32 */
-	TIPC_NLA_PROP_BROADCAST_RATIO,	/* u32 */
 
 	__TIPC_NLA_PROP_MAX,
 	TIPC_NLA_PROP_MAX = __TIPC_NLA_PROP_MAX - 1
diff --git a/include/uapi/linux/unix_diag.h b/include/linux/unix_diag.h
similarity index 89%
rename from include/uapi/linux/unix_diag.h
rename to include/linux/unix_diag.h
index a198857..1eb0b8d 100644
--- a/include/uapi/linux/unix_diag.h
+++ b/include/linux/unix_diag.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __UNIX_DIAG_H__
 #define __UNIX_DIAG_H__
 
@@ -20,7 +19,6 @@
 #define UDIAG_SHOW_ICONS	0x00000008	/* show pending connections */
 #define UDIAG_SHOW_RQLEN	0x00000010	/* show skb receive queue len */
 #define UDIAG_SHOW_MEMINFO	0x00000020	/* show memory info of a socket */
-#define UDIAG_SHOW_UID		0x00000040	/* show socket's UID */
 
 struct unix_diag_msg {
 	__u8	udiag_family;
@@ -41,7 +39,6 @@
 	UNIX_DIAG_RQLEN,
 	UNIX_DIAG_MEMINFO,
 	UNIX_DIAG_SHUTDOWN,
-	UNIX_DIAG_UID,
 
 	__UNIX_DIAG_MAX,
 };
diff --git a/include/uapi/linux/veth.h b/include/linux/veth.h
similarity index 71%
rename from include/uapi/linux/veth.h
rename to include/linux/veth.h
index 52b58e5..3354c1e 100644
--- a/include/uapi/linux/veth.h
+++ b/include/linux/veth.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef __NET_VETH_H_
 #define __NET_VETH_H_
 
diff --git a/include/uapi/linux/xfrm.h b/include/linux/xfrm.h
similarity index 95%
rename from include/uapi/linux/xfrm.h
rename to include/linux/xfrm.h
index 5cdda9d..b8f5451 100644
--- a/include/uapi/linux/xfrm.h
+++ b/include/linux/xfrm.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _LINUX_XFRM_H
 #define _LINUX_XFRM_H
 
@@ -299,18 +298,12 @@
 	XFRMA_ALG_AUTH_TRUNC,	/* struct xfrm_algo_auth */
 	XFRMA_MARK,		/* struct xfrm_mark */
 	XFRMA_TFCPAD,		/* __u32 */
-	XFRMA_REPLAY_ESN_VAL,	/* struct xfrm_replay_state_esn */
+	XFRMA_REPLAY_ESN_VAL,	/* struct xfrm_replay_esn */
 	XFRMA_SA_EXTRA_FLAGS,	/* __u32 */
 	XFRMA_PROTO,		/* __u8 */
 	XFRMA_ADDRESS_FILTER,	/* struct xfrm_address_filter */
-	XFRMA_PAD,
-	XFRMA_OFFLOAD_DEV,	/* struct xfrm_state_offload */
-	XFRMA_SET_MARK,		/* __u32 */
-	XFRMA_SET_MARK_MASK,	/* __u32 */
-	XFRMA_IF_ID,		/* __u32 */
 	__XFRMA_MAX
 
-#define XFRMA_OUTPUT_MARK XFRMA_SET_MARK	/* Compatibility */
 #define XFRMA_MAX (__XFRMA_MAX - 1)
 };
 
@@ -500,13 +493,6 @@
 	__u8				dplen;
 };
 
-struct xfrm_user_offload {
-	int				ifindex;
-	__u8				flags;
-};
-#define XFRM_OFFLOAD_IPV6	1
-#define XFRM_OFFLOAD_INBOUND	2
-
 /* backwards compatibility for userspace */
 #define XFRMGRP_ACQUIRE		1
 #define XFRMGRP_EXPIRE		2
diff --git a/include/list.h b/include/list.h
deleted file mode 100644
index 5d86b13..0000000
--- a/include/list.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __LIST_H__
-#define __LIST_H__ 1
-/* List and hash list stuff from kernel */
-
-#include <stddef.h>
-
-#define container_of(ptr, type, member) ({			\
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
-
-struct list_head {
-	struct list_head *next, *prev;
-};
-
-static inline void INIT_LIST_HEAD(struct list_head *list)
-{
-	list->next = list;
-	list->prev = list;
-}
-
-static inline void __list_add(struct list_head *new,
-			      struct list_head *prev,
-			      struct list_head *next)
-{
-	next->prev = new;
-	new->next = next;
-	new->prev = prev;
-	prev->next = new;
-}
-
-static inline void list_add(struct list_head *new, struct list_head *head)
-{
-	__list_add(new, head, head->next);
-}
-
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
-{
-	__list_add(new, head->prev, head);
-}
-
-static inline void __list_del(struct list_head *prev, struct list_head *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-static inline void list_del(struct list_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-}
-
-#define list_entry(ptr, type, member) \
-	container_of(ptr, type, member)
-
-#define list_first_entry(ptr, type, member) \
-	list_entry((ptr)->next, type, member)
-
-#define list_last_entry(ptr, type, member) \
-	list_entry((ptr)->prev, type, member)
-
-#define list_next_entry(pos, member) \
-	list_entry((pos)->member.next, typeof(*(pos)), member)
-
-#define list_prev_entry(pos, member) \
-	list_entry((pos)->member.prev, typeof(*(pos)), member)
-
-#define list_for_each_entry(pos, head, member)				\
-	for (pos = list_first_entry(head, typeof(*pos), member);	\
-	     &pos->member != (head);					\
-	     pos = list_next_entry(pos, member))
-
-#define list_for_each_entry_safe(pos, n, head, member)			\
-	for (pos = list_first_entry(head, typeof(*pos), member),	\
-		n = list_next_entry(pos, member);			\
-	     &pos->member != (head);					\
-	     pos = n, n = list_next_entry(n, member))
-
-#define list_for_each_entry_reverse(pos, head, member)			\
-	for (pos = list_last_entry(head, typeof(*pos), member);		\
-	     &pos->member != (head);					\
-	     pos = list_prev_entry(pos, member))
-
-struct hlist_head {
-	struct hlist_node *first;
-};
-
-struct hlist_node {
-	struct hlist_node *next, **pprev;
-};
-
-static inline void hlist_del(struct hlist_node *n)
-{
-	struct hlist_node *next = n->next;
-	struct hlist_node **pprev = n->pprev;
-	*pprev = next;
-	if (next)
-		next->pprev = pprev;
-}
-
-static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
-{
-	struct hlist_node *first = h->first;
-	n->next = first;
-	if (first)
-		first->pprev = &n->next;
-	h->first = n;
-	n->pprev = &h->first;
-}
-
-static inline int list_empty(const struct list_head *head)
-{
-	return head->next == head;
-}
-
-#define hlist_for_each(pos, head) \
-	for (pos = (head)->first; pos ; pos = pos->next)
-
-
-#define hlist_for_each_safe(pos, n, head) \
-	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
-	     pos = n)
-
-#define hlist_entry_safe(ptr, type, member) \
-	({ typeof(ptr) ____ptr = (ptr); \
-	   ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
-	})
-
-#define hlist_for_each_entry(pos, head, member)				\
-	for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
-	     pos;							\
-	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
-
-#endif /* __LIST_H__ */
diff --git a/include/ll_map.h b/include/ll_map.h
index 4de1041..949bfc3 100644
--- a/include/ll_map.h
+++ b/include/ll_map.h
@@ -1,17 +1,15 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __LL_MAP_H__
 #define __LL_MAP_H__ 1
 
-int ll_remember_index(struct nlmsghdr *n, void *arg);
+int ll_remember_index(const struct sockaddr_nl *who,
+		      struct nlmsghdr *n, void *arg);
 
 void ll_init_map(struct rtnl_handle *rth);
 unsigned ll_name_to_index(const char *name);
 const char *ll_index_to_name(unsigned idx);
+const char *ll_idx_n2a(unsigned idx, char *buf);
 int ll_index_to_type(unsigned idx);
 int ll_index_to_flags(unsigned idx);
-void ll_drop_by_index(unsigned index);
 unsigned namehash(const char *str);
 
-const char *ll_idx_n2a(unsigned int idx);
-
 #endif /* __LL_MAP_H__ */
diff --git a/include/names.h b/include/names.h
index 2fcaacc..6fed581 100644
--- a/include/names.h
+++ b/include/names.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef DB_NAMES_H_
 #define DB_NAMES_H_ 1
 
@@ -22,5 +21,6 @@
 void db_names_free(struct db_names *db);
 
 char *id_to_name(struct db_names *db, int id, char *name);
+int name_to_id(struct db_names *db, int *id, const char *name);
 
 #endif
diff --git a/include/namespace.h b/include/namespace.h
index e47f9b5..51324b2 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __NAMESPACE_H__
 #define __NAMESPACE_H__ 1
 
@@ -8,13 +7,8 @@
 #include <sys/syscall.h>
 #include <errno.h>
 
-#ifndef NETNS_RUN_DIR
 #define NETNS_RUN_DIR "/var/run/netns"
-#endif
-
-#ifndef NETNS_ETC_DIR
 #define NETNS_ETC_DIR "/etc/netns"
-#endif
 
 #ifndef CLONE_NEWNET
 #define CLONE_NEWNET 0x40000000	/* New network namespace (lo, device, names sockets, etc) */
diff --git a/include/rt_names.h b/include/rt_names.h
index 62ebbd6..921be06 100644
--- a/include/rt_names.h
+++ b/include/rt_names.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef RT_NAMES_H_
 #define RT_NAMES_H_ 1
 
diff --git a/include/rtm_map.h b/include/rtm_map.h
index f85e52c..d6e5885 100644
--- a/include/rtm_map.h
+++ b/include/rtm_map.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __RTM_MAP_H__
 #define __RTM_MAP_H__ 1
 
diff --git a/include/uapi/asm-generic/sockios.h b/include/uapi/asm-generic/sockios.h
deleted file mode 100644
index 44fa3ed..0000000
--- a/include/uapi/asm-generic/sockios.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __ASM_GENERIC_SOCKIOS_H
-#define __ASM_GENERIC_SOCKIOS_H
-
-/* Socket-level I/O control calls. */
-#define FIOSETOWN	0x8901
-#define SIOCSPGRP	0x8902
-#define FIOGETOWN	0x8903
-#define SIOCGPGRP	0x8904
-#define SIOCATMARK	0x8905
-#define SIOCGSTAMP_OLD	0x8906		/* Get stamp (timeval) */
-#define SIOCGSTAMPNS_OLD 0x8907		/* Get stamp (timespec) */
-
-#endif /* __ASM_GENERIC_SOCKIOS_H */
diff --git a/include/uapi/linux/atmarp.h b/include/uapi/linux/atmarp.h
deleted file mode 100644
index 8e44d12..0000000
--- a/include/uapi/linux/atmarp.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* atmarp.h - ATM ARP protocol and kernel-demon interface definitions */
- 
-/* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
- 
-
-#ifndef _LINUX_ATMARP_H
-#define _LINUX_ATMARP_H
-
-#include <linux/types.h>
-#include <linux/atmapi.h>
-#include <linux/atmioc.h>
-
-
-#define ATMARP_RETRY_DELAY 30		/* request next resolution or forget
-					   NAK after 30 sec - should go into
-					   atmclip.h */
-#define ATMARP_MAX_UNRES_PACKETS 5	/* queue that many packets while
-					   waiting for the resolver */
-
-
-#define ATMARPD_CTRL	_IO('a',ATMIOC_CLIP+1)	/* become atmarpd ctrl sock */
-#define ATMARP_MKIP	_IO('a',ATMIOC_CLIP+2)	/* attach socket to IP */
-#define ATMARP_SETENTRY	_IO('a',ATMIOC_CLIP+3)	/* fill or hide ARP entry */
-#define ATMARP_ENCAP	_IO('a',ATMIOC_CLIP+5)	/* change encapsulation */
-
-
-enum atmarp_ctrl_type {
-	act_invalid,		/* catch uninitialized structures */
-	act_need,		/* need address resolution */
-	act_up,			/* interface is coming up */
-	act_down,		/* interface is going down */
-	act_change		/* interface configuration has changed */
-};
-
-struct atmarp_ctrl {
-	enum atmarp_ctrl_type	type;	/* message type */
-	int			itf_num;/* interface number (if present) */
-	__be32			ip;	/* IP address (act_need only) */
-};
-
-#endif
diff --git a/include/uapi/linux/atmdev.h b/include/uapi/linux/atmdev.h
deleted file mode 100644
index 9bdb96a..0000000
--- a/include/uapi/linux/atmdev.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* atmdev.h - ATM device driver declarations and various related items */
- 
-/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
- 
-
-#ifndef LINUX_ATMDEV_H
-#define LINUX_ATMDEV_H
-
-
-#include <linux/atmapi.h>
-#include <linux/atm.h>
-#include <linux/atmioc.h>
-
-
-#define ESI_LEN		6
-
-#define ATM_OC3_PCR	(155520000/270*260/8/53)
-			/* OC3 link rate:  155520000 bps
-			   SONET overhead: /270*260 (9 section, 1 path)
-			   bits per cell:  /8/53
-			   max cell rate:  353207.547 cells/sec */
-#define ATM_25_PCR	((25600000/8-8000)/54)
-			/* 25 Mbps ATM cell rate (59111) */
-#define ATM_OC12_PCR	(622080000/1080*1040/8/53)
-			/* OC12 link rate: 622080000 bps
-			   SONET overhead: /1080*1040
-			   bits per cell:  /8/53
-			   max cell rate:  1412830.188 cells/sec */
-#define ATM_DS3_PCR	(8000*12)
-			/* DS3: 12 cells in a 125 usec time slot */
-
-
-#define __AAL_STAT_ITEMS \
-    __HANDLE_ITEM(tx);			/* TX okay */ \
-    __HANDLE_ITEM(tx_err);		/* TX errors */ \
-    __HANDLE_ITEM(rx);			/* RX okay */ \
-    __HANDLE_ITEM(rx_err);		/* RX errors */ \
-    __HANDLE_ITEM(rx_drop);		/* RX out of memory */
-
-struct atm_aal_stats {
-#define __HANDLE_ITEM(i) int i
-	__AAL_STAT_ITEMS
-#undef __HANDLE_ITEM
-};
-
-
-struct atm_dev_stats {
-	struct atm_aal_stats aal0;
-	struct atm_aal_stats aal34;
-	struct atm_aal_stats aal5;
-} __ATM_API_ALIGN;
-
-
-#define ATM_GETLINKRATE	_IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
-					/* get link rate */
-#define ATM_GETNAMES	_IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
-					/* get interface names (numbers) */
-#define ATM_GETTYPE	_IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
-					/* get interface type name */
-#define ATM_GETESI	_IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
-					/* get interface ESI */
-#define ATM_GETADDR	_IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
-					/* get itf's local ATM addr. list */
-#define ATM_RSTADDR	_IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
-					/* reset itf's ATM address list */
-#define ATM_ADDADDR	_IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
-					/* add a local ATM address */
-#define ATM_DELADDR	_IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
-					/* remove a local ATM address */
-#define ATM_GETCIRANGE	_IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
-					/* get connection identifier range */
-#define ATM_SETCIRANGE	_IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
-					/* set connection identifier range */
-#define ATM_SETESI	_IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
-					/* set interface ESI */
-#define ATM_SETESIF	_IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
-					/* force interface ESI */
-#define ATM_ADDLECSADDR	_IOW('a', ATMIOC_ITF+14, struct atmif_sioc)
-					/* register a LECS address */
-#define ATM_DELLECSADDR	_IOW('a', ATMIOC_ITF+15, struct atmif_sioc)
-					/* unregister a LECS address */
-#define ATM_GETLECSADDR	_IOW('a', ATMIOC_ITF+16, struct atmif_sioc)
-					/* retrieve LECS address(es) */
-
-#define ATM_GETSTAT	_IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
-					/* get AAL layer statistics */
-#define ATM_GETSTATZ	_IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
-					/* get AAL layer statistics and zero */
-#define ATM_GETLOOP	_IOW('a',ATMIOC_SARCOM+2,struct atmif_sioc)
-					/* get loopback mode */
-#define ATM_SETLOOP	_IOW('a',ATMIOC_SARCOM+3,struct atmif_sioc)
-					/* set loopback mode */
-#define ATM_QUERYLOOP	_IOW('a',ATMIOC_SARCOM+4,struct atmif_sioc)
-					/* query supported loopback modes */
-#define ATM_SETSC	_IOW('a',ATMIOC_SPECIAL+1,int)
-					/* enable or disable single-copy */
-#define ATM_SETBACKEND	_IOW('a',ATMIOC_SPECIAL+2,atm_backend_t)
-					/* set backend handler */
-#define ATM_NEWBACKENDIF _IOW('a',ATMIOC_SPECIAL+3,atm_backend_t)
-					/* use backend to make new if */
-#define ATM_ADDPARTY  	_IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
- 					/* add party to p2mp call */
-#ifdef CONFIG_COMPAT
-/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
-#define COMPAT_ATM_ADDPARTY  	_IOW('a', ATMIOC_SPECIAL+4,struct compat_atm_iobuf)
-#endif
-#define ATM_DROPPARTY 	_IOW('a', ATMIOC_SPECIAL+5,int)
-					/* drop party from p2mp call */
-
-/*
- * These are backend handkers that can be set via the ATM_SETBACKEND call
- * above.  In the future we may support dynamic loading of these - for now,
- * they're just being used to share the ATMIOC_BACKEND ioctls
- */
-#define ATM_BACKEND_RAW		0	
-#define ATM_BACKEND_PPP		1	/* PPPoATM - RFC2364 */
-#define ATM_BACKEND_BR2684	2	/* Bridged RFC1483/2684 */
-
-/* for ATM_GETTYPE */
-#define ATM_ITFTYP_LEN	8	/* maximum length of interface type name */
-
-/*
- * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
- */
-
-/* Point of loopback				CPU-->SAR-->PHY-->line--> ... */
-#define __ATM_LM_NONE	0	/* no loop back     ^     ^     ^      ^      */
-#define __ATM_LM_AAL	1	/* loop back PDUs --'     |     |      |      */
-#define __ATM_LM_ATM	2	/* loop back ATM cells ---'     |      |      */
-/* RESERVED		4	loop back on PHY side  ---'		      */
-#define __ATM_LM_PHY	8	/* loop back bits (digital) ----'      |      */
-#define __ATM_LM_ANALOG 16	/* loop back the analog signal --------'      */
-
-/* Direction of loopback */
-#define __ATM_LM_MKLOC(n)	((n))	    /* Local (i.e. loop TX to RX) */
-#define __ATM_LM_MKRMT(n)	((n) << 8)  /* Remote (i.e. loop RX to TX) */
-
-#define __ATM_LM_XTLOC(n)	((n) & 0xff)
-#define __ATM_LM_XTRMT(n)	(((n) >> 8) & 0xff)
-
-#define ATM_LM_NONE	0	/* no loopback */
-
-#define ATM_LM_LOC_AAL	__ATM_LM_MKLOC(__ATM_LM_AAL)
-#define ATM_LM_LOC_ATM	__ATM_LM_MKLOC(__ATM_LM_ATM)
-#define ATM_LM_LOC_PHY	__ATM_LM_MKLOC(__ATM_LM_PHY)
-#define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
-
-#define ATM_LM_RMT_AAL	__ATM_LM_MKRMT(__ATM_LM_AAL)
-#define ATM_LM_RMT_ATM	__ATM_LM_MKRMT(__ATM_LM_ATM)
-#define ATM_LM_RMT_PHY	__ATM_LM_MKRMT(__ATM_LM_PHY)
-#define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
-
-/*
- * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
- * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
- */
-
-
-struct atm_iobuf {
-	int length;
-	void *buffer;
-};
-
-/* for ATM_GETCIRANGE / ATM_SETCIRANGE */
-
-#define ATM_CI_MAX      -1              /* use maximum range of VPI/VCI */
- 
-struct atm_cirange {
-	signed char	vpi_bits;	/* 1..8, ATM_CI_MAX (-1) for maximum */
-	signed char	vci_bits;	/* 1..16, ATM_CI_MAX (-1) for maximum */
-};
-
-/* for ATM_SETSC; actually taken from the ATM_VF number space */
-
-#define ATM_SC_RX	1024		/* enable RX single-copy */
-#define ATM_SC_TX	2048		/* enable TX single-copy */
-
-#define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
-				  anyway */
-
-/* MF: change_qos (Modify) flags */
-
-#define ATM_MF_IMMED	 1	/* Block until change is effective */
-#define ATM_MF_INC_RSV	 2	/* Change reservation on increase */
-#define ATM_MF_INC_SHP	 4	/* Change shaping on increase */
-#define ATM_MF_DEC_RSV	 8	/* Change reservation on decrease */
-#define ATM_MF_DEC_SHP	16	/* Change shaping on decrease */
-#define ATM_MF_BWD	32	/* Set the backward direction parameters */
-
-#define ATM_MF_SET	(ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
-			  ATM_MF_DEC_SHP | ATM_MF_BWD)
-
-/*
- * ATM_VS_* are used to express VC state in a human-friendly way.
- */
-
-#define ATM_VS_IDLE	0	/* VC is not used */
-#define ATM_VS_CONNECTED 1	/* VC is connected */
-#define ATM_VS_CLOSING	2	/* VC is closing */
-#define ATM_VS_LISTEN	3	/* VC is listening for incoming setups */
-#define ATM_VS_INUSE	4	/* VC is in use (registered with atmsigd) */
-#define ATM_VS_BOUND	5	/* VC is bound */
-
-#define ATM_VS2TXT_MAP \
-    "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
-
-#define ATM_VF2TXT_MAP \
-    "ADDR",	"READY",	"PARTIAL",	"REGIS", \
-    "RELEASED", "HASQOS",	"LISTEN",	"META", \
-    "256",	"512",		"1024",		"2048", \
-    "SESSION",	"HASSAP",	"BOUND",	"CLOSE"
-
-
-
-#endif /* LINUX_ATMDEV_H */
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
deleted file mode 100644
index f7a7553..0000000
--- a/include/uapi/linux/bpf.h
+++ /dev/null
@@ -1,3616 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- */
-#ifndef __LINUX_BPF_H__
-#define __LINUX_BPF_H__
-
-#include <linux/types.h>
-#include <linux/bpf_common.h>
-
-/* Extended instruction set based on top of classic BPF */
-
-/* instruction classes */
-#define BPF_JMP32	0x06	/* jmp mode in word width */
-#define BPF_ALU64	0x07	/* alu mode in double word width */
-
-/* ld/ldx fields */
-#define BPF_DW		0x18	/* double word (64-bit) */
-#define BPF_XADD	0xc0	/* exclusive add */
-
-/* alu/jmp fields */
-#define BPF_MOV		0xb0	/* mov reg to reg */
-#define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
-
-/* change endianness of a register */
-#define BPF_END		0xd0	/* flags for endianness conversion: */
-#define BPF_TO_LE	0x00	/* convert to little-endian */
-#define BPF_TO_BE	0x08	/* convert to big-endian */
-#define BPF_FROM_LE	BPF_TO_LE
-#define BPF_FROM_BE	BPF_TO_BE
-
-/* jmp encodings */
-#define BPF_JNE		0x50	/* jump != */
-#define BPF_JLT		0xa0	/* LT is unsigned, '<' */
-#define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
-#define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
-#define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
-#define BPF_JSLT	0xc0	/* SLT is signed, '<' */
-#define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
-#define BPF_CALL	0x80	/* function call */
-#define BPF_EXIT	0x90	/* function return */
-
-/* Register numbers */
-enum {
-	BPF_REG_0 = 0,
-	BPF_REG_1,
-	BPF_REG_2,
-	BPF_REG_3,
-	BPF_REG_4,
-	BPF_REG_5,
-	BPF_REG_6,
-	BPF_REG_7,
-	BPF_REG_8,
-	BPF_REG_9,
-	BPF_REG_10,
-	__MAX_BPF_REG,
-};
-
-/* BPF has 10 general purpose 64-bit registers and stack frame. */
-#define MAX_BPF_REG	__MAX_BPF_REG
-
-struct bpf_insn {
-	__u8	code;		/* opcode */
-	__u8	dst_reg:4;	/* dest register */
-	__u8	src_reg:4;	/* source register */
-	__s16	off;		/* signed offset */
-	__s32	imm;		/* signed immediate constant */
-};
-
-/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
-struct bpf_lpm_trie_key {
-	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
-	__u8	data[0];	/* Arbitrary size */
-};
-
-struct bpf_cgroup_storage_key {
-	__u64	cgroup_inode_id;	/* cgroup inode id */
-	__u32	attach_type;		/* program attach type */
-};
-
-/* BPF syscall commands, see bpf(2) man-page for details. */
-enum bpf_cmd {
-	BPF_MAP_CREATE,
-	BPF_MAP_LOOKUP_ELEM,
-	BPF_MAP_UPDATE_ELEM,
-	BPF_MAP_DELETE_ELEM,
-	BPF_MAP_GET_NEXT_KEY,
-	BPF_PROG_LOAD,
-	BPF_OBJ_PIN,
-	BPF_OBJ_GET,
-	BPF_PROG_ATTACH,
-	BPF_PROG_DETACH,
-	BPF_PROG_TEST_RUN,
-	BPF_PROG_GET_NEXT_ID,
-	BPF_MAP_GET_NEXT_ID,
-	BPF_PROG_GET_FD_BY_ID,
-	BPF_MAP_GET_FD_BY_ID,
-	BPF_OBJ_GET_INFO_BY_FD,
-	BPF_PROG_QUERY,
-	BPF_RAW_TRACEPOINT_OPEN,
-	BPF_BTF_LOAD,
-	BPF_BTF_GET_FD_BY_ID,
-	BPF_TASK_FD_QUERY,
-	BPF_MAP_LOOKUP_AND_DELETE_ELEM,
-	BPF_MAP_FREEZE,
-	BPF_BTF_GET_NEXT_ID,
-};
-
-enum bpf_map_type {
-	BPF_MAP_TYPE_UNSPEC,
-	BPF_MAP_TYPE_HASH,
-	BPF_MAP_TYPE_ARRAY,
-	BPF_MAP_TYPE_PROG_ARRAY,
-	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
-	BPF_MAP_TYPE_PERCPU_HASH,
-	BPF_MAP_TYPE_PERCPU_ARRAY,
-	BPF_MAP_TYPE_STACK_TRACE,
-	BPF_MAP_TYPE_CGROUP_ARRAY,
-	BPF_MAP_TYPE_LRU_HASH,
-	BPF_MAP_TYPE_LRU_PERCPU_HASH,
-	BPF_MAP_TYPE_LPM_TRIE,
-	BPF_MAP_TYPE_ARRAY_OF_MAPS,
-	BPF_MAP_TYPE_HASH_OF_MAPS,
-	BPF_MAP_TYPE_DEVMAP,
-	BPF_MAP_TYPE_SOCKMAP,
-	BPF_MAP_TYPE_CPUMAP,
-	BPF_MAP_TYPE_XSKMAP,
-	BPF_MAP_TYPE_SOCKHASH,
-	BPF_MAP_TYPE_CGROUP_STORAGE,
-	BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
-	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
-	BPF_MAP_TYPE_QUEUE,
-	BPF_MAP_TYPE_STACK,
-	BPF_MAP_TYPE_SK_STORAGE,
-	BPF_MAP_TYPE_DEVMAP_HASH,
-};
-
-/* Note that tracing related programs such as
- * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
- * are not subject to a stable API since kernel internal data
- * structures can change from release to release and may
- * therefore break existing tracing BPF programs. Tracing BPF
- * programs correspond to /a/ specific kernel which is to be
- * analyzed, and not /a/ specific kernel /and/ all future ones.
- */
-enum bpf_prog_type {
-	BPF_PROG_TYPE_UNSPEC,
-	BPF_PROG_TYPE_SOCKET_FILTER,
-	BPF_PROG_TYPE_KPROBE,
-	BPF_PROG_TYPE_SCHED_CLS,
-	BPF_PROG_TYPE_SCHED_ACT,
-	BPF_PROG_TYPE_TRACEPOINT,
-	BPF_PROG_TYPE_XDP,
-	BPF_PROG_TYPE_PERF_EVENT,
-	BPF_PROG_TYPE_CGROUP_SKB,
-	BPF_PROG_TYPE_CGROUP_SOCK,
-	BPF_PROG_TYPE_LWT_IN,
-	BPF_PROG_TYPE_LWT_OUT,
-	BPF_PROG_TYPE_LWT_XMIT,
-	BPF_PROG_TYPE_SOCK_OPS,
-	BPF_PROG_TYPE_SK_SKB,
-	BPF_PROG_TYPE_CGROUP_DEVICE,
-	BPF_PROG_TYPE_SK_MSG,
-	BPF_PROG_TYPE_RAW_TRACEPOINT,
-	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
-	BPF_PROG_TYPE_LWT_SEG6LOCAL,
-	BPF_PROG_TYPE_LIRC_MODE2,
-	BPF_PROG_TYPE_SK_REUSEPORT,
-	BPF_PROG_TYPE_FLOW_DISSECTOR,
-	BPF_PROG_TYPE_CGROUP_SYSCTL,
-	BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
-	BPF_PROG_TYPE_CGROUP_SOCKOPT,
-};
-
-enum bpf_attach_type {
-	BPF_CGROUP_INET_INGRESS,
-	BPF_CGROUP_INET_EGRESS,
-	BPF_CGROUP_INET_SOCK_CREATE,
-	BPF_CGROUP_SOCK_OPS,
-	BPF_SK_SKB_STREAM_PARSER,
-	BPF_SK_SKB_STREAM_VERDICT,
-	BPF_CGROUP_DEVICE,
-	BPF_SK_MSG_VERDICT,
-	BPF_CGROUP_INET4_BIND,
-	BPF_CGROUP_INET6_BIND,
-	BPF_CGROUP_INET4_CONNECT,
-	BPF_CGROUP_INET6_CONNECT,
-	BPF_CGROUP_INET4_POST_BIND,
-	BPF_CGROUP_INET6_POST_BIND,
-	BPF_CGROUP_UDP4_SENDMSG,
-	BPF_CGROUP_UDP6_SENDMSG,
-	BPF_LIRC_MODE2,
-	BPF_FLOW_DISSECTOR,
-	BPF_CGROUP_SYSCTL,
-	BPF_CGROUP_UDP4_RECVMSG,
-	BPF_CGROUP_UDP6_RECVMSG,
-	BPF_CGROUP_GETSOCKOPT,
-	BPF_CGROUP_SETSOCKOPT,
-	__MAX_BPF_ATTACH_TYPE
-};
-
-#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
-
-/* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
- *
- * NONE(default): No further bpf programs allowed in the subtree.
- *
- * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
- * the program in this cgroup yields to sub-cgroup program.
- *
- * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
- * that cgroup program gets run in addition to the program in this cgroup.
- *
- * Only one program is allowed to be attached to a cgroup with
- * NONE or BPF_F_ALLOW_OVERRIDE flag.
- * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
- * release old program and attach the new one. Attach flags has to match.
- *
- * Multiple programs are allowed to be attached to a cgroup with
- * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
- * (those that were attached first, run first)
- * The programs of sub-cgroup are executed first, then programs of
- * this cgroup and then programs of parent cgroup.
- * When children program makes decision (like picking TCP CA or sock bind)
- * parent program has a chance to override it.
- *
- * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
- * A cgroup with NONE doesn't allow any programs in sub-cgroups.
- * Ex1:
- * cgrp1 (MULTI progs A, B) ->
- *    cgrp2 (OVERRIDE prog C) ->
- *      cgrp3 (MULTI prog D) ->
- *        cgrp4 (OVERRIDE prog E) ->
- *          cgrp5 (NONE prog F)
- * the event in cgrp5 triggers execution of F,D,A,B in that order.
- * if prog F is detached, the execution is E,D,A,B
- * if prog F and D are detached, the execution is E,A,B
- * if prog F, E and D are detached, the execution is C,A,B
- *
- * All eligible programs are executed regardless of return code from
- * earlier programs.
- */
-#define BPF_F_ALLOW_OVERRIDE	(1U << 0)
-#define BPF_F_ALLOW_MULTI	(1U << 1)
-
-/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
- * verifier will perform strict alignment checking as if the kernel
- * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
- * and NET_IP_ALIGN defined to 2.
- */
-#define BPF_F_STRICT_ALIGNMENT	(1U << 0)
-
-/* If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the
- * verifier will allow any alignment whatsoever.  On platforms
- * with strict alignment requirements for loads ands stores (such
- * as sparc and mips) the verifier validates that all loads and
- * stores provably follow this requirement.  This flag turns that
- * checking and enforcement off.
- *
- * It is mostly used for testing when we want to validate the
- * context and memory access aspects of the verifier, but because
- * of an unaligned access the alignment check would trigger before
- * the one we are interested in.
- */
-#define BPF_F_ANY_ALIGNMENT	(1U << 1)
-
-/* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.
- * Verifier does sub-register def/use analysis and identifies instructions whose
- * def only matters for low 32-bit, high 32-bit is never referenced later
- * through implicit zero extension. Therefore verifier notifies JIT back-ends
- * that it is safe to ignore clearing high 32-bit for these instructions. This
- * saves some back-ends a lot of code-gen. However such optimization is not
- * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends
- * hence hasn't used verifier's analysis result. But, we really want to have a
- * way to be able to verify the correctness of the described optimization on
- * x86_64 on which testsuites are frequently exercised.
- *
- * So, this flag is introduced. Once it is set, verifier will randomize high
- * 32-bit for those instructions who has been identified as safe to ignore them.
- * Then, if verifier is not doing correct analysis, such randomization will
- * regress tests to expose bugs.
- */
-#define BPF_F_TEST_RND_HI32	(1U << 2)
-
-/* The verifier internal test flag. Behavior is undefined */
-#define BPF_F_TEST_STATE_FREQ	(1U << 3)
-
-/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
- * two extensions:
- *
- * insn[0].src_reg:  BPF_PSEUDO_MAP_FD   BPF_PSEUDO_MAP_VALUE
- * insn[0].imm:      map fd              map fd
- * insn[1].imm:      0                   offset into value
- * insn[0].off:      0                   0
- * insn[1].off:      0                   0
- * ldimm64 rewrite:  address of map      address of map[0]+offset
- * verifier type:    CONST_PTR_TO_MAP    PTR_TO_MAP_VALUE
- */
-#define BPF_PSEUDO_MAP_FD	1
-#define BPF_PSEUDO_MAP_VALUE	2
-
-/* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
- * offset to another bpf function
- */
-#define BPF_PSEUDO_CALL		1
-
-/* flags for BPF_MAP_UPDATE_ELEM command */
-#define BPF_ANY		0 /* create new element or update existing */
-#define BPF_NOEXIST	1 /* create new element if it didn't exist */
-#define BPF_EXIST	2 /* update existing element */
-#define BPF_F_LOCK	4 /* spin_lock-ed map_lookup/map_update */
-
-/* flags for BPF_MAP_CREATE command */
-#define BPF_F_NO_PREALLOC	(1U << 0)
-/* Instead of having one common LRU list in the
- * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
- * which can scale and perform better.
- * Note, the LRU nodes (including free nodes) cannot be moved
- * across different LRU lists.
- */
-#define BPF_F_NO_COMMON_LRU	(1U << 1)
-/* Specify numa node during map creation */
-#define BPF_F_NUMA_NODE		(1U << 2)
-
-#define BPF_OBJ_NAME_LEN 16U
-
-/* Flags for accessing BPF object from syscall side. */
-#define BPF_F_RDONLY		(1U << 3)
-#define BPF_F_WRONLY		(1U << 4)
-
-/* Flag for stack_map, store build_id+offset instead of pointer */
-#define BPF_F_STACK_BUILD_ID	(1U << 5)
-
-/* Zero-initialize hash function seed. This should only be used for testing. */
-#define BPF_F_ZERO_SEED		(1U << 6)
-
-/* Flags for accessing BPF object from program side. */
-#define BPF_F_RDONLY_PROG	(1U << 7)
-#define BPF_F_WRONLY_PROG	(1U << 8)
-
-/* Clone map from listener for newly accepted socket */
-#define BPF_F_CLONE		(1U << 9)
-
-/* flags for BPF_PROG_QUERY */
-#define BPF_F_QUERY_EFFECTIVE	(1U << 0)
-
-enum bpf_stack_build_id_status {
-	/* user space need an empty entry to identify end of a trace */
-	BPF_STACK_BUILD_ID_EMPTY = 0,
-	/* with valid build_id and offset */
-	BPF_STACK_BUILD_ID_VALID = 1,
-	/* couldn't get build_id, fallback to ip */
-	BPF_STACK_BUILD_ID_IP = 2,
-};
-
-#define BPF_BUILD_ID_SIZE 20
-struct bpf_stack_build_id {
-	__s32		status;
-	unsigned char	build_id[BPF_BUILD_ID_SIZE];
-	union {
-		__u64	offset;
-		__u64	ip;
-	};
-};
-
-union bpf_attr {
-	struct { /* anonymous struct used by BPF_MAP_CREATE command */
-		__u32	map_type;	/* one of enum bpf_map_type */
-		__u32	key_size;	/* size of key in bytes */
-		__u32	value_size;	/* size of value in bytes */
-		__u32	max_entries;	/* max number of entries in a map */
-		__u32	map_flags;	/* BPF_MAP_CREATE related
-					 * flags defined above.
-					 */
-		__u32	inner_map_fd;	/* fd pointing to the inner map */
-		__u32	numa_node;	/* numa node (effective only if
-					 * BPF_F_NUMA_NODE is set).
-					 */
-		char	map_name[BPF_OBJ_NAME_LEN];
-		__u32	map_ifindex;	/* ifindex of netdev to create on */
-		__u32	btf_fd;		/* fd pointing to a BTF type data */
-		__u32	btf_key_type_id;	/* BTF type_id of the key */
-		__u32	btf_value_type_id;	/* BTF type_id of the value */
-	};
-
-	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
-		__u32		map_fd;
-		__aligned_u64	key;
-		union {
-			__aligned_u64 value;
-			__aligned_u64 next_key;
-		};
-		__u64		flags;
-	};
-
-	struct { /* anonymous struct used by BPF_PROG_LOAD command */
-		__u32		prog_type;	/* one of enum bpf_prog_type */
-		__u32		insn_cnt;
-		__aligned_u64	insns;
-		__aligned_u64	license;
-		__u32		log_level;	/* verbosity level of verifier */
-		__u32		log_size;	/* size of user buffer */
-		__aligned_u64	log_buf;	/* user supplied buffer */
-		__u32		kern_version;	/* not used */
-		__u32		prog_flags;
-		char		prog_name[BPF_OBJ_NAME_LEN];
-		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
-		/* For some prog types expected attach type must be known at
-		 * load time to verify attach type specific parts of prog
-		 * (context accesses, allowed helpers, etc).
-		 */
-		__u32		expected_attach_type;
-		__u32		prog_btf_fd;	/* fd pointing to BTF type data */
-		__u32		func_info_rec_size;	/* userspace bpf_func_info size */
-		__aligned_u64	func_info;	/* func info */
-		__u32		func_info_cnt;	/* number of bpf_func_info records */
-		__u32		line_info_rec_size;	/* userspace bpf_line_info size */
-		__aligned_u64	line_info;	/* line info */
-		__u32		line_info_cnt;	/* number of bpf_line_info records */
-	};
-
-	struct { /* anonymous struct used by BPF_OBJ_* commands */
-		__aligned_u64	pathname;
-		__u32		bpf_fd;
-		__u32		file_flags;
-	};
-
-	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
-		__u32		target_fd;	/* container object to attach to */
-		__u32		attach_bpf_fd;	/* eBPF program to attach */
-		__u32		attach_type;
-		__u32		attach_flags;
-	};
-
-	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
-		__u32		prog_fd;
-		__u32		retval;
-		__u32		data_size_in;	/* input: len of data_in */
-		__u32		data_size_out;	/* input/output: len of data_out
-						 *   returns ENOSPC if data_out
-						 *   is too small.
-						 */
-		__aligned_u64	data_in;
-		__aligned_u64	data_out;
-		__u32		repeat;
-		__u32		duration;
-		__u32		ctx_size_in;	/* input: len of ctx_in */
-		__u32		ctx_size_out;	/* input/output: len of ctx_out
-						 *   returns ENOSPC if ctx_out
-						 *   is too small.
-						 */
-		__aligned_u64	ctx_in;
-		__aligned_u64	ctx_out;
-	} test;
-
-	struct { /* anonymous struct used by BPF_*_GET_*_ID */
-		union {
-			__u32		start_id;
-			__u32		prog_id;
-			__u32		map_id;
-			__u32		btf_id;
-		};
-		__u32		next_id;
-		__u32		open_flags;
-	};
-
-	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
-		__u32		bpf_fd;
-		__u32		info_len;
-		__aligned_u64	info;
-	} info;
-
-	struct { /* anonymous struct used by BPF_PROG_QUERY command */
-		__u32		target_fd;	/* container object to query */
-		__u32		attach_type;
-		__u32		query_flags;
-		__u32		attach_flags;
-		__aligned_u64	prog_ids;
-		__u32		prog_cnt;
-	} query;
-
-	struct {
-		__u64 name;
-		__u32 prog_fd;
-	} raw_tracepoint;
-
-	struct { /* anonymous struct for BPF_BTF_LOAD */
-		__aligned_u64	btf;
-		__aligned_u64	btf_log_buf;
-		__u32		btf_size;
-		__u32		btf_log_size;
-		__u32		btf_log_level;
-	};
-
-	struct {
-		__u32		pid;		/* input: pid */
-		__u32		fd;		/* input: fd */
-		__u32		flags;		/* input: flags */
-		__u32		buf_len;	/* input/output: buf len */
-		__aligned_u64	buf;		/* input/output:
-						 *   tp_name for tracepoint
-						 *   symbol for kprobe
-						 *   filename for uprobe
-						 */
-		__u32		prog_id;	/* output: prod_id */
-		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
-		__u64		probe_offset;	/* output: probe_offset */
-		__u64		probe_addr;	/* output: probe_addr */
-	} task_fd_query;
-} __attribute__((aligned(8)));
-
-/* The description below is an attempt at providing documentation to eBPF
- * developers about the multiple available eBPF helper functions. It can be
- * parsed and used to produce a manual page. The workflow is the following,
- * and requires the rst2man utility:
- *
- *     $ ./scripts/bpf_helpers_doc.py \
- *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
- *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
- *     $ man /tmp/bpf-helpers.7
- *
- * Note that in order to produce this external documentation, some RST
- * formatting is used in the descriptions to get "bold" and "italics" in
- * manual pages. Also note that the few trailing white spaces are
- * intentional, removing them would break paragraphs for rst2man.
- *
- * Start of BPF helper function descriptions:
- *
- * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
- * 	Description
- * 		Perform a lookup in *map* for an entry associated to *key*.
- * 	Return
- * 		Map value associated to *key*, or **NULL** if no entry was
- * 		found.
- *
- * int bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
- * 	Description
- * 		Add or update the value of the entry associated to *key* in
- * 		*map* with *value*. *flags* is one of:
- *
- * 		**BPF_NOEXIST**
- * 			The entry for *key* must not exist in the map.
- * 		**BPF_EXIST**
- * 			The entry for *key* must already exist in the map.
- * 		**BPF_ANY**
- * 			No condition on the existence of the entry for *key*.
- *
- * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
- * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
- * 		elements always exist), the helper would return an error.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_map_delete_elem(struct bpf_map *map, const void *key)
- * 	Description
- * 		Delete entry with *key* from *map*.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_probe_read(void *dst, u32 size, const void *src)
- * 	Description
- * 		For tracing programs, safely attempt to read *size* bytes from
- * 		address *src* and store the data in *dst*.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * u64 bpf_ktime_get_ns(void)
- * 	Description
- * 		Return the time elapsed since system boot, in nanoseconds.
- * 	Return
- * 		Current *ktime*.
- *
- * int bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
- * 	Description
- * 		This helper is a "printk()-like" facility for debugging. It
- * 		prints a message defined by format *fmt* (of size *fmt_size*)
- * 		to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
- * 		available. It can take up to three additional **u64**
- * 		arguments (as an eBPF helpers, the total number of arguments is
- * 		limited to five).
- *
- * 		Each time the helper is called, it appends a line to the trace.
- * 		Lines are discarded while *\/sys/kernel/debug/tracing/trace* is
- * 		open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this.
- * 		The format of the trace is customizable, and the exact output
- * 		one will get depends on the options set in
- * 		*\/sys/kernel/debug/tracing/trace_options* (see also the
- * 		*README* file under the same directory). However, it usually
- * 		defaults to something like:
- *
- * 		::
- *
- * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
- *
- * 		In the above:
- *
- * 			* ``telnet`` is the name of the current task.
- * 			* ``470`` is the PID of the current task.
- * 			* ``001`` is the CPU number on which the task is
- * 			  running.
- * 			* In ``.N..``, each character refers to a set of
- * 			  options (whether irqs are enabled, scheduling
- * 			  options, whether hard/softirqs are running, level of
- * 			  preempt_disabled respectively). **N** means that
- * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
- * 			  are set.
- * 			* ``419421.045894`` is a timestamp.
- * 			* ``0x00000001`` is a fake value used by BPF for the
- * 			  instruction pointer register.
- * 			* ``<formatted msg>`` is the message formatted with
- * 			  *fmt*.
- *
- * 		The conversion specifiers supported by *fmt* are similar, but
- * 		more limited than for printk(). They are **%d**, **%i**,
- * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
- * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
- * 		of field, padding with zeroes, etc.) is available, and the
- * 		helper will return **-EINVAL** (but print nothing) if it
- * 		encounters an unknown specifier.
- *
- * 		Also, note that **bpf_trace_printk**\ () is slow, and should
- * 		only be used for debugging purposes. For this reason, a notice
- * 		bloc (spanning several lines) is printed to kernel logs and
- * 		states that the helper should not be used "for production use"
- * 		the first time this helper is used (or more precisely, when
- * 		**trace_printk**\ () buffers are allocated). For passing values
- * 		to user space, perf events should be preferred.
- * 	Return
- * 		The number of bytes written to the buffer, or a negative error
- * 		in case of failure.
- *
- * u32 bpf_get_prandom_u32(void)
- * 	Description
- * 		Get a pseudo-random number.
- *
- * 		From a security point of view, this helper uses its own
- * 		pseudo-random internal state, and cannot be used to infer the
- * 		seed of other random functions in the kernel. However, it is
- * 		essential to note that the generator used by the helper is not
- * 		cryptographically secure.
- * 	Return
- * 		A random 32-bit unsigned value.
- *
- * u32 bpf_get_smp_processor_id(void)
- * 	Description
- * 		Get the SMP (symmetric multiprocessing) processor id. Note that
- * 		all programs run with preemption disabled, which means that the
- * 		SMP processor id is stable during all the execution of the
- * 		program.
- * 	Return
- * 		The SMP id of the processor running the program.
- *
- * int bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
- * 	Description
- * 		Store *len* bytes from address *from* into the packet
- * 		associated to *skb*, at *offset*. *flags* are a combination of
- * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
- * 		checksum for the packet after storing the bytes) and
- * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
- * 		**->swhash** and *skb*\ **->l4hash** to 0).
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
- * 	Description
- * 		Recompute the layer 3 (e.g. IP) checksum for the packet
- * 		associated to *skb*. Computation is incremental, so the helper
- * 		must know the former value of the header field that was
- * 		modified (*from*), the new value of this field (*to*), and the
- * 		number of bytes (2 or 4) for this field, stored in *size*.
- * 		Alternatively, it is possible to store the difference between
- * 		the previous and the new values of the header field in *to*, by
- * 		setting *from* and *size* to 0. For both methods, *offset*
- * 		indicates the location of the IP checksum within the packet.
- *
- * 		This helper works in combination with **bpf_csum_diff**\ (),
- * 		which does not update the checksum in-place, but offers more
- * 		flexibility and can handle sizes larger than 2 or 4 for the
- * 		checksum to update.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
- * 	Description
- * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
- * 		packet associated to *skb*. Computation is incremental, so the
- * 		helper must know the former value of the header field that was
- * 		modified (*from*), the new value of this field (*to*), and the
- * 		number of bytes (2 or 4) for this field, stored on the lowest
- * 		four bits of *flags*. Alternatively, it is possible to store
- * 		the difference between the previous and the new values of the
- * 		header field in *to*, by setting *from* and the four lowest
- * 		bits of *flags* to 0. For both methods, *offset* indicates the
- * 		location of the IP checksum within the packet. In addition to
- * 		the size of the field, *flags* can be added (bitwise OR) actual
- * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
- * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
- * 		for updates resulting in a null checksum the value is set to
- * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
- * 		the checksum is to be computed against a pseudo-header.
- *
- * 		This helper works in combination with **bpf_csum_diff**\ (),
- * 		which does not update the checksum in-place, but offers more
- * 		flexibility and can handle sizes larger than 2 or 4 for the
- * 		checksum to update.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
- * 	Description
- * 		This special helper is used to trigger a "tail call", or in
- * 		other words, to jump into another eBPF program. The same stack
- * 		frame is used (but values on stack and in registers for the
- * 		caller are not accessible to the callee). This mechanism allows
- * 		for program chaining, either for raising the maximum number of
- * 		available eBPF instructions, or to execute given programs in
- * 		conditional blocks. For security reasons, there is an upper
- * 		limit to the number of successive tail calls that can be
- * 		performed.
- *
- * 		Upon call of this helper, the program attempts to jump into a
- * 		program referenced at index *index* in *prog_array_map*, a
- * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
- * 		*ctx*, a pointer to the context.
- *
- * 		If the call succeeds, the kernel immediately runs the first
- * 		instruction of the new program. This is not a function call,
- * 		and it never returns to the previous program. If the call
- * 		fails, then the helper has no effect, and the caller continues
- * 		to run its subsequent instructions. A call can fail if the
- * 		destination program for the jump does not exist (i.e. *index*
- * 		is superior to the number of entries in *prog_array_map*), or
- * 		if the maximum number of tail calls has been reached for this
- * 		chain of programs. This limit is defined in the kernel by the
- * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
- * 		which is currently set to 32.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
- * 	Description
- * 		Clone and redirect the packet associated to *skb* to another
- * 		net device of index *ifindex*. Both ingress and egress
- * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
- * 		value in *flags* is used to make the distinction (ingress path
- * 		is selected if the flag is present, egress path otherwise).
- * 		This is the only flag supported for now.
- *
- * 		In comparison with **bpf_redirect**\ () helper,
- * 		**bpf_clone_redirect**\ () has the associated cost of
- * 		duplicating the packet buffer, but this can be executed out of
- * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
- * 		efficient, but it is handled through an action code where the
- * 		redirection happens only after the eBPF program has returned.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * u64 bpf_get_current_pid_tgid(void)
- * 	Return
- * 		A 64-bit integer containing the current tgid and pid, and
- * 		created as such:
- * 		*current_task*\ **->tgid << 32 \|**
- * 		*current_task*\ **->pid**.
- *
- * u64 bpf_get_current_uid_gid(void)
- * 	Return
- * 		A 64-bit integer containing the current GID and UID, and
- * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
- *
- * int bpf_get_current_comm(char *buf, u32 size_of_buf)
- * 	Description
- * 		Copy the **comm** attribute of the current task into *buf* of
- * 		*size_of_buf*. The **comm** attribute contains the name of
- * 		the executable (excluding the path) for the current task. The
- * 		*size_of_buf* must be strictly positive. On success, the
- * 		helper makes sure that the *buf* is NUL-terminated. On failure,
- * 		it is filled with zeroes.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
- * 	Description
- * 		Retrieve the classid for the current task, i.e. for the net_cls
- * 		cgroup to which *skb* belongs.
- *
- * 		This helper can be used on TC egress path, but not on ingress.
- *
- * 		The net_cls cgroup provides an interface to tag network packets
- * 		based on a user-provided identifier for all traffic coming from
- * 		the tasks belonging to the related cgroup. See also the related
- * 		kernel documentation, available from the Linux sources in file
- * 		*Documentation/admin-guide/cgroup-v1/net_cls.rst*.
- *
- * 		The Linux kernel has two versions for cgroups: there are
- * 		cgroups v1 and cgroups v2. Both are available to users, who can
- * 		use a mixture of them, but note that the net_cls cgroup is for
- * 		cgroup v1 only. This makes it incompatible with BPF programs
- * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
- * 		only hold data for one version of cgroups at a time).
- *
- * 		This helper is only available is the kernel was compiled with
- * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
- * 		"**y**" or to "**m**".
- * 	Return
- * 		The classid, or 0 for the default unconfigured classid.
- *
- * int bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
- * 	Description
- * 		Push a *vlan_tci* (VLAN tag control information) of protocol
- * 		*vlan_proto* to the packet associated to *skb*, then update
- * 		the checksum. Note that if *vlan_proto* is different from
- * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
- * 		be **ETH_P_8021Q**.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_vlan_pop(struct sk_buff *skb)
- * 	Description
- * 		Pop a VLAN header from the packet associated to *skb*.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
- * 	Description
- * 		Get tunnel metadata. This helper takes a pointer *key* to an
- * 		empty **struct bpf_tunnel_key** of **size**, that will be
- * 		filled with tunnel metadata for the packet associated to *skb*.
- * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
- * 		indicates that the tunnel is based on IPv6 protocol instead of
- * 		IPv4.
- *
- * 		The **struct bpf_tunnel_key** is an object that generalizes the
- * 		principal parameters used by various tunneling protocols into a
- * 		single struct. This way, it can be used to easily make a
- * 		decision based on the contents of the encapsulation header,
- * 		"summarized" in this struct. In particular, it holds the IP
- * 		address of the remote end (IPv4 or IPv6, depending on the case)
- * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
- * 		this struct exposes the *key*\ **->tunnel_id**, which is
- * 		generally mapped to a VNI (Virtual Network Identifier), making
- * 		it programmable together with the **bpf_skb_set_tunnel_key**\
- * 		() helper.
- *
- * 		Let's imagine that the following code is part of a program
- * 		attached to the TC ingress interface, on one end of a GRE
- * 		tunnel, and is supposed to filter out all messages coming from
- * 		remote ends with IPv4 address other than 10.0.0.1:
- *
- * 		::
- *
- * 			int ret;
- * 			struct bpf_tunnel_key key = {};
- * 			
- * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
- * 			if (ret < 0)
- * 				return TC_ACT_SHOT;	// drop packet
- * 			
- * 			if (key.remote_ipv4 != 0x0a000001)
- * 				return TC_ACT_SHOT;	// drop packet
- * 			
- * 			return TC_ACT_OK;		// accept packet
- *
- * 		This interface can also be used with all encapsulation devices
- * 		that can operate in "collect metadata" mode: instead of having
- * 		one network device per specific configuration, the "collect
- * 		metadata" mode only requires a single device where the
- * 		configuration can be extracted from this helper.
- *
- * 		This can be used together with various tunnels such as VXLan,
- * 		Geneve, GRE or IP in IP (IPIP).
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
- * 	Description
- * 		Populate tunnel metadata for packet associated to *skb.* The
- * 		tunnel metadata is set to the contents of *key*, of *size*. The
- * 		*flags* can be set to a combination of the following values:
- *
- * 		**BPF_F_TUNINFO_IPV6**
- * 			Indicate that the tunnel is based on IPv6 protocol
- * 			instead of IPv4.
- * 		**BPF_F_ZERO_CSUM_TX**
- * 			For IPv4 packets, add a flag to tunnel metadata
- * 			indicating that checksum computation should be skipped
- * 			and checksum set to zeroes.
- * 		**BPF_F_DONT_FRAGMENT**
- * 			Add a flag to tunnel metadata indicating that the
- * 			packet should not be fragmented.
- * 		**BPF_F_SEQ_NUMBER**
- * 			Add a flag to tunnel metadata indicating that a
- * 			sequence number should be added to tunnel header before
- * 			sending the packet. This flag was added for GRE
- * 			encapsulation, but might be used with other protocols
- * 			as well in the future.
- *
- * 		Here is a typical usage on the transmit path:
- *
- * 		::
- *
- * 			struct bpf_tunnel_key key;
- * 			     populate key ...
- * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
- * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
- *
- * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
- * 		helper for additional information.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
- * 	Description
- * 		Read the value of a perf event counter. This helper relies on a
- * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
- * 		the perf event counter is selected when *map* is updated with
- * 		perf event file descriptors. The *map* is an array whose size
- * 		is the number of available CPUs, and each cell contains a value
- * 		relative to one CPU. The value to retrieve is indicated by
- * 		*flags*, that contains the index of the CPU to look up, masked
- * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
- * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
- * 		current CPU should be retrieved.
- *
- * 		Note that before Linux 4.13, only hardware perf event can be
- * 		retrieved.
- *
- * 		Also, be aware that the newer helper
- * 		**bpf_perf_event_read_value**\ () is recommended over
- * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
- * 		quirks where error and counter value are used as a return code
- * 		(which is wrong to do since ranges may overlap). This issue is
- * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
- * 		time provides more features over the **bpf_perf_event_read**\
- * 		() interface. Please refer to the description of
- * 		**bpf_perf_event_read_value**\ () for details.
- * 	Return
- * 		The value of the perf event counter read from the map, or a
- * 		negative error code in case of failure.
- *
- * int bpf_redirect(u32 ifindex, u64 flags)
- * 	Description
- * 		Redirect the packet to another net device of index *ifindex*.
- * 		This helper is somewhat similar to **bpf_clone_redirect**\
- * 		(), except that the packet is not cloned, which provides
- * 		increased performance.
- *
- * 		Except for XDP, both ingress and egress interfaces can be used
- * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
- * 		to make the distinction (ingress path is selected if the flag
- * 		is present, egress path otherwise). Currently, XDP only
- * 		supports redirection to the egress interface, and accepts no
- * 		flag at all.
- *
- * 		The same effect can be attained with the more generic
- * 		**bpf_redirect_map**\ (), which requires specific maps to be
- * 		used but offers better performance.
- * 	Return
- * 		For XDP, the helper returns **XDP_REDIRECT** on success or
- * 		**XDP_ABORTED** on error. For other program types, the values
- * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
- * 		error.
- *
- * u32 bpf_get_route_realm(struct sk_buff *skb)
- * 	Description
- * 		Retrieve the realm or the route, that is to say the
- * 		**tclassid** field of the destination for the *skb*. The
- * 		indentifier retrieved is a user-provided tag, similar to the
- * 		one used with the net_cls cgroup (see description for
- * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
- * 		held by a route (a destination entry), not by a task.
- *
- * 		Retrieving this identifier works with the clsact TC egress hook
- * 		(see also **tc-bpf(8)**), or alternatively on conventional
- * 		classful egress qdiscs, but not on TC ingress path. In case of
- * 		clsact TC egress hook, this has the advantage that, internally,
- * 		the destination entry has not been dropped yet in the transmit
- * 		path. Therefore, the destination entry does not need to be
- * 		artificially held via **netif_keep_dst**\ () for a classful
- * 		qdisc until the *skb* is freed.
- *
- * 		This helper is available only if the kernel was compiled with
- * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
- * 	Return
- * 		The realm of the route for the packet associated to *skb*, or 0
- * 		if none was found.
- *
- * int bpf_perf_event_output(struct pt_regs *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
- * 	Description
- * 		Write raw *data* blob into a special BPF perf event held by
- * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
- * 		event must have the following attributes: **PERF_SAMPLE_RAW**
- * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
- * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
- *
- * 		The *flags* are used to indicate the index in *map* for which
- * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
- * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
- * 		to indicate that the index of the current CPU core should be
- * 		used.
- *
- * 		The value to write, of *size*, is passed through eBPF stack and
- * 		pointed by *data*.
- *
- * 		The context of the program *ctx* needs also be passed to the
- * 		helper.
- *
- * 		On user space, a program willing to read the values needs to
- * 		call **perf_event_open**\ () on the perf event (either for
- * 		one or for all CPUs) and to store the file descriptor into the
- * 		*map*. This must be done before the eBPF program can send data
- * 		into it. An example is available in file
- * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
- * 		tree (the eBPF program counterpart is in
- * 		*samples/bpf/trace_output_kern.c*).
- *
- * 		**bpf_perf_event_output**\ () achieves better performance
- * 		than **bpf_trace_printk**\ () for sharing data with user
- * 		space, and is much better suitable for streaming data from eBPF
- * 		programs.
- *
- * 		Note that this helper is not restricted to tracing use cases
- * 		and can be used with programs attached to TC or XDP as well,
- * 		where it allows for passing data to user space listeners. Data
- * 		can be:
- *
- * 		* Only custom structs,
- * 		* Only the packet payload, or
- * 		* A combination of both.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset, void *to, u32 len)
- * 	Description
- * 		This helper was provided as an easy way to load data from a
- * 		packet. It can be used to load *len* bytes from *offset* from
- * 		the packet associated to *skb*, into the buffer pointed by
- * 		*to*.
- *
- * 		Since Linux 4.7, usage of this helper has mostly been replaced
- * 		by "direct packet access", enabling packet data to be
- * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
- * 		pointing respectively to the first byte of packet data and to
- * 		the byte after the last byte of packet data. However, it
- * 		remains useful if one wishes to read large quantities of data
- * 		at once from a packet into the eBPF stack.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_get_stackid(struct pt_regs *ctx, struct bpf_map *map, u64 flags)
- * 	Description
- * 		Walk a user or a kernel stack and return its id. To achieve
- * 		this, the helper needs *ctx*, which is a pointer to the context
- * 		on which the tracing program is executed, and a pointer to a
- * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
- *
- * 		The last argument, *flags*, holds the number of stack frames to
- * 		skip (from 0 to 255), masked with
- * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
- * 		a combination of the following flags:
- *
- * 		**BPF_F_USER_STACK**
- * 			Collect a user space stack instead of a kernel stack.
- * 		**BPF_F_FAST_STACK_CMP**
- * 			Compare stacks by hash only.
- * 		**BPF_F_REUSE_STACKID**
- * 			If two different stacks hash into the same *stackid*,
- * 			discard the old one.
- *
- * 		The stack id retrieved is a 32 bit long integer handle which
- * 		can be further combined with other data (including other stack
- * 		ids) and used as a key into maps. This can be useful for
- * 		generating a variety of graphs (such as flame graphs or off-cpu
- * 		graphs).
- *
- * 		For walking a stack, this helper is an improvement over
- * 		**bpf_probe_read**\ (), which can be used with unrolled loops
- * 		but is not efficient and consumes a lot of eBPF instructions.
- * 		Instead, **bpf_get_stackid**\ () can collect up to
- * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
- * 		this limit can be controlled with the **sysctl** program, and
- * 		that it should be manually increased in order to profile long
- * 		user stacks (such as stacks for Java programs). To do so, use:
- *
- * 		::
- *
- * 			# sysctl kernel.perf_event_max_stack=<new value>
- * 	Return
- * 		The positive or null stack id on success, or a negative error
- * 		in case of failure.
- *
- * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
- * 	Description
- * 		Compute a checksum difference, from the raw buffer pointed by
- * 		*from*, of length *from_size* (that must be a multiple of 4),
- * 		towards the raw buffer pointed by *to*, of size *to_size*
- * 		(same remark). An optional *seed* can be added to the value
- * 		(this can be cascaded, the seed may come from a previous call
- * 		to the helper).
- *
- * 		This is flexible enough to be used in several ways:
- *
- * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
- * 		  checksum, it can be used when pushing new data.
- * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
- * 		  checksum, it can be used when removing data from a packet.
- * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
- * 		  can be used to compute a diff. Note that *from_size* and
- * 		  *to_size* do not need to be equal.
- *
- * 		This helper can be used in combination with
- * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
- * 		which one can feed in the difference computed with
- * 		**bpf_csum_diff**\ ().
- * 	Return
- * 		The checksum result, or a negative error code in case of
- * 		failure.
- *
- * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
- * 	Description
- * 		Retrieve tunnel options metadata for the packet associated to
- * 		*skb*, and store the raw tunnel option data to the buffer *opt*
- * 		of *size*.
- *
- * 		This helper can be used with encapsulation devices that can
- * 		operate in "collect metadata" mode (please refer to the related
- * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
- * 		more details). A particular example where this can be used is
- * 		in combination with the Geneve encapsulation protocol, where it
- * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
- * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
- * 		the eBPF program. This allows for full customization of these
- * 		headers.
- * 	Return
- * 		The size of the option data retrieved.
- *
- * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
- * 	Description
- * 		Set tunnel options metadata for the packet associated to *skb*
- * 		to the option data contained in the raw buffer *opt* of *size*.
- *
- * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
- * 		helper for additional information.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
- * 	Description
- * 		Change the protocol of the *skb* to *proto*. Currently
- * 		supported are transition from IPv4 to IPv6, and from IPv6 to
- * 		IPv4. The helper takes care of the groundwork for the
- * 		transition, including resizing the socket buffer. The eBPF
- * 		program is expected to fill the new headers, if any, via
- * 		**skb_store_bytes**\ () and to recompute the checksums with
- * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
- * 		(). The main case for this helper is to perform NAT64
- * 		operations out of an eBPF program.
- *
- * 		Internally, the GSO type is marked as dodgy so that headers are
- * 		checked and segments are recalculated by the GSO/GRO engine.
- * 		The size for GSO target is adapted as well.
- *
- * 		All values for *flags* are reserved for future usage, and must
- * 		be left at zero.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_change_type(struct sk_buff *skb, u32 type)
- * 	Description
- * 		Change the packet type for the packet associated to *skb*. This
- * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
- * 		the eBPF program does not have a write access to *skb*\
- * 		**->pkt_type** beside this helper. Using a helper here allows
- * 		for graceful handling of errors.
- *
- * 		The major use case is to change incoming *skb*s to
- * 		**PACKET_HOST** in a programmatic way instead of having to
- * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
- * 		example.
- *
- * 		Note that *type* only allows certain values. At this time, they
- * 		are:
- *
- * 		**PACKET_HOST**
- * 			Packet is for us.
- * 		**PACKET_BROADCAST**
- * 			Send packet to all.
- * 		**PACKET_MULTICAST**
- * 			Send packet to group.
- * 		**PACKET_OTHERHOST**
- * 			Send packet to someone else.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
- * 	Description
- * 		Check whether *skb* is a descendant of the cgroup2 held by
- * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
- * 	Return
- * 		The return value depends on the result of the test, and can be:
- *
- * 		* 0, if the *skb* failed the cgroup2 descendant test.
- * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
- * 		* A negative error code, if an error occurred.
- *
- * u32 bpf_get_hash_recalc(struct sk_buff *skb)
- * 	Description
- * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
- * 		not set, in particular if the hash was cleared due to mangling,
- * 		recompute this hash. Later accesses to the hash can be done
- * 		directly with *skb*\ **->hash**.
- *
- * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
- * 		prototype with **bpf_skb_change_proto**\ (), or calling
- * 		**bpf_skb_store_bytes**\ () with the
- * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
- * 		the hash and to trigger a new computation for the next call to
- * 		**bpf_get_hash_recalc**\ ().
- * 	Return
- * 		The 32-bit hash.
- *
- * u64 bpf_get_current_task(void)
- * 	Return
- * 		A pointer to the current task struct.
- *
- * int bpf_probe_write_user(void *dst, const void *src, u32 len)
- * 	Description
- * 		Attempt in a safe way to write *len* bytes from the buffer
- * 		*src* to *dst* in memory. It only works for threads that are in
- * 		user context, and *dst* must be a valid user space address.
- *
- * 		This helper should not be used to implement any kind of
- * 		security mechanism because of TOC-TOU attacks, but rather to
- * 		debug, divert, and manipulate execution of semi-cooperative
- * 		processes.
- *
- * 		Keep in mind that this feature is meant for experiments, and it
- * 		has a risk of crashing the system and running programs.
- * 		Therefore, when an eBPF program using this helper is attached,
- * 		a warning including PID and process name is printed to kernel
- * 		logs.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
- * 	Description
- * 		Check whether the probe is being run is the context of a given
- * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
- * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
- * 	Return
- * 		The return value depends on the result of the test, and can be:
- *
- * 		* 0, if the *skb* task belongs to the cgroup2.
- * 		* 1, if the *skb* task does not belong to the cgroup2.
- * 		* A negative error code, if an error occurred.
- *
- * int bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
- * 	Description
- * 		Resize (trim or grow) the packet associated to *skb* to the
- * 		new *len*. The *flags* are reserved for future usage, and must
- * 		be left at zero.
- *
- * 		The basic idea is that the helper performs the needed work to
- * 		change the size of the packet, then the eBPF program rewrites
- * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
- * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
- * 		and others. This helper is a slow path utility intended for
- * 		replies with control messages. And because it is targeted for
- * 		slow path, the helper itself can afford to be slow: it
- * 		implicitly linearizes, unclones and drops offloads from the
- * 		*skb*.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_pull_data(struct sk_buff *skb, u32 len)
- * 	Description
- * 		Pull in non-linear data in case the *skb* is non-linear and not
- * 		all of *len* are part of the linear section. Make *len* bytes
- * 		from *skb* readable and writable. If a zero value is passed for
- * 		*len*, then the whole length of the *skb* is pulled.
- *
- * 		This helper is only needed for reading and writing with direct
- * 		packet access.
- *
- * 		For direct packet access, testing that offsets to access
- * 		are within packet boundaries (test on *skb*\ **->data_end**) is
- * 		susceptible to fail if offsets are invalid, or if the requested
- * 		data is in non-linear parts of the *skb*. On failure the
- * 		program can just bail out, or in the case of a non-linear
- * 		buffer, use a helper to make the data available. The
- * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
- * 		the data. Another one consists in using **bpf_skb_pull_data**
- * 		to pull in once the non-linear parts, then retesting and
- * 		eventually access the data.
- *
- * 		At the same time, this also makes sure the *skb* is uncloned,
- * 		which is a necessary condition for direct write. As this needs
- * 		to be an invariant for the write part only, the verifier
- * 		detects writes and adds a prologue that is calling
- * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
- * 		the very beginning in case it is indeed cloned.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
- * 	Description
- * 		Add the checksum *csum* into *skb*\ **->csum** in case the
- * 		driver has supplied a checksum for the entire packet into that
- * 		field. Return an error otherwise. This helper is intended to be
- * 		used in combination with **bpf_csum_diff**\ (), in particular
- * 		when the checksum needs to be updated after data has been
- * 		written into the packet through direct packet access.
- * 	Return
- * 		The checksum on success, or a negative error code in case of
- * 		failure.
- *
- * void bpf_set_hash_invalid(struct sk_buff *skb)
- * 	Description
- * 		Invalidate the current *skb*\ **->hash**. It can be used after
- * 		mangling on headers through direct packet access, in order to
- * 		indicate that the hash is outdated and to trigger a
- * 		recalculation the next time the kernel tries to access this
- * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
- *
- * int bpf_get_numa_node_id(void)
- * 	Description
- * 		Return the id of the current NUMA node. The primary use case
- * 		for this helper is the selection of sockets for the local NUMA
- * 		node, when the program is attached to sockets using the
- * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
- * 		but the helper is also available to other eBPF program types,
- * 		similarly to **bpf_get_smp_processor_id**\ ().
- * 	Return
- * 		The id of current NUMA node.
- *
- * int bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
- * 	Description
- * 		Grows headroom of packet associated to *skb* and adjusts the
- * 		offset of the MAC header accordingly, adding *len* bytes of
- * 		space. It automatically extends and reallocates memory as
- * 		required.
- *
- * 		This helper can be used on a layer 3 *skb* to push a MAC header
- * 		for redirection into a layer 2 device.
- *
- * 		All values for *flags* are reserved for future usage, and must
- * 		be left at zero.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
- * 	Description
- * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
- * 		it is possible to use a negative value for *delta*. This helper
- * 		can be used to prepare the packet for pushing or popping
- * 		headers.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
- * 	Description
- * 		Copy a NUL terminated string from an unsafe address
- * 		*unsafe_ptr* to *dst*. The *size* should include the
- * 		terminating NUL byte. In case the string length is smaller than
- * 		*size*, the target is not padded with further NUL bytes. If the
- * 		string length is larger than *size*, just *size*-1 bytes are
- * 		copied and the last byte is set to NUL.
- *
- * 		On success, the length of the copied string is returned. This
- * 		makes this helper useful in tracing programs for reading
- * 		strings, and more importantly to get its length at runtime. See
- * 		the following snippet:
- *
- * 		::
- *
- * 			SEC("kprobe/sys_open")
- * 			void bpf_sys_open(struct pt_regs *ctx)
- * 			{
- * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
- * 			        int res = bpf_probe_read_str(buf, sizeof(buf),
- * 				                             ctx->di);
- *
- * 				// Consume buf, for example push it to
- * 				// userspace via bpf_perf_event_output(); we
- * 				// can use res (the string length) as event
- * 				// size, after checking its boundaries.
- * 			}
- *
- * 		In comparison, using **bpf_probe_read()** helper here instead
- * 		to read the string would require to estimate the length at
- * 		compile time, and would often result in copying more memory
- * 		than necessary.
- *
- * 		Another useful use case is when parsing individual process
- * 		arguments or individual environment variables navigating
- * 		*current*\ **->mm->arg_start** and *current*\
- * 		**->mm->env_start**: using this helper and the return value,
- * 		one can quickly iterate at the right offset of the memory area.
- * 	Return
- * 		On success, the strictly positive length of the string,
- * 		including the trailing NUL character. On error, a negative
- * 		value.
- *
- * u64 bpf_get_socket_cookie(struct sk_buff *skb)
- * 	Description
- * 		If the **struct sk_buff** pointed by *skb* has a known socket,
- * 		retrieve the cookie (generated by the kernel) of this socket.
- * 		If no cookie has been set yet, generate a new cookie. Once
- * 		generated, the socket cookie remains stable for the life of the
- * 		socket. This helper can be useful for monitoring per socket
- * 		networking traffic statistics as it provides a global socket
- * 		identifier that can be assumed unique.
- * 	Return
- * 		A 8-byte long non-decreasing number on success, or 0 if the
- * 		socket field is missing inside *skb*.
- *
- * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
- * 	Description
- * 		Equivalent to bpf_get_socket_cookie() helper that accepts
- * 		*skb*, but gets socket from **struct bpf_sock_addr** context.
- * 	Return
- * 		A 8-byte long non-decreasing number.
- *
- * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
- * 	Description
- * 		Equivalent to bpf_get_socket_cookie() helper that accepts
- * 		*skb*, but gets socket from **struct bpf_sock_ops** context.
- * 	Return
- * 		A 8-byte long non-decreasing number.
- *
- * u32 bpf_get_socket_uid(struct sk_buff *skb)
- * 	Return
- * 		The owner UID of the socket associated to *skb*. If the socket
- * 		is **NULL**, or if it is not a full socket (i.e. if it is a
- * 		time-wait or a request socket instead), **overflowuid** value
- * 		is returned (note that **overflowuid** might also be the actual
- * 		UID value for the socket).
- *
- * u32 bpf_set_hash(struct sk_buff *skb, u32 hash)
- * 	Description
- * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
- * 		to value *hash*.
- * 	Return
- * 		0
- *
- * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
- * 	Description
- * 		Emulate a call to **setsockopt()** on the socket associated to
- * 		*bpf_socket*, which must be a full socket. The *level* at
- * 		which the option resides and the name *optname* of the option
- * 		must be specified, see **setsockopt(2)** for more information.
- * 		The option value of length *optlen* is pointed by *optval*.
- *
- * 		This helper actually implements a subset of **setsockopt()**.
- * 		It supports the following *level*\ s:
- *
- * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
- * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
- * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**.
- * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
- * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
- * 		  **TCP_BPF_SNDCWND_CLAMP**.
- * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
- * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
- * 	Description
- * 		Grow or shrink the room for data in the packet associated to
- * 		*skb* by *len_diff*, and according to the selected *mode*.
- *
- *		There are two supported modes at this time:
- *
- *		* **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
- *		  (room space is added or removed below the layer 2 header).
- *
- * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
- * 		  (room space is added or removed below the layer 3 header).
- *
- *		The following flags are supported at this time:
- *
- *		* **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
- *		  Adjusting mss in this way is not allowed for datagrams.
- *
- *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
- *		  **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
- *		  Any new space is reserved to hold a tunnel header.
- *		  Configure skb offsets and other fields accordingly.
- *
- *		* **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
- *		  **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
- *		  Use with ENCAP_L3 flags to further specify the tunnel type.
- *
- *		* **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
- *		  Use with ENCAP_L3/L4 flags to further specify the tunnel
- *		  type; *len* is the length of the inner MAC header.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)
- * 	Description
- * 		Redirect the packet to the endpoint referenced by *map* at
- * 		index *key*. Depending on its type, this *map* can contain
- * 		references to net devices (for forwarding packets through other
- * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
- * 		but this is only implemented for native XDP (with driver
- * 		support) as of this writing).
- *
- * 		The lower two bits of *flags* are used as the return code if
- * 		the map lookup fails. This is so that the return value can be
- * 		one of the XDP program return codes up to XDP_TX, as chosen by
- * 		the caller. Any higher bits in the *flags* argument must be
- * 		unset.
- *
- * 		When used to redirect packets to net devices, this helper
- * 		provides a high performance increase over **bpf_redirect**\ ().
- * 		This is due to various implementation details of the underlying
- * 		mechanisms, one of which is the fact that **bpf_redirect_map**\
- * 		() tries to send packet as a "bulk" to the device.
- * 	Return
- * 		**XDP_REDIRECT** on success, or **XDP_ABORTED** on error.
- *
- * int bpf_sk_redirect_map(struct bpf_map *map, u32 key, u64 flags)
- * 	Description
- * 		Redirect the packet to the socket referenced by *map* (of type
- * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
- * 		egress interfaces can be used for redirection. The
- * 		**BPF_F_INGRESS** value in *flags* is used to make the
- * 		distinction (ingress path is selected if the flag is present,
- * 		egress path otherwise). This is the only flag supported for now.
- * 	Return
- * 		**SK_PASS** on success, or **SK_DROP** on error.
- *
- * int bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
- * 	Description
- * 		Add an entry to, or update a *map* referencing sockets. The
- * 		*skops* is used as a new value for the entry associated to
- * 		*key*. *flags* is one of:
- *
- * 		**BPF_NOEXIST**
- * 			The entry for *key* must not exist in the map.
- * 		**BPF_EXIST**
- * 			The entry for *key* must already exist in the map.
- * 		**BPF_ANY**
- * 			No condition on the existence of the entry for *key*.
- *
- * 		If the *map* has eBPF programs (parser and verdict), those will
- * 		be inherited by the socket being added. If the socket is
- * 		already attached to eBPF programs, this results in an error.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
- * 	Description
- * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
- * 		*delta* (which can be positive or negative). Note that this
- * 		operation modifies the address stored in *xdp_md*\ **->data**,
- * 		so the latter must be loaded only after the helper has been
- * 		called.
- *
- * 		The use of *xdp_md*\ **->data_meta** is optional and programs
- * 		are not required to use it. The rationale is that when the
- * 		packet is processed with XDP (e.g. as DoS filter), it is
- * 		possible to push further meta data along with it before passing
- * 		to the stack, and to give the guarantee that an ingress eBPF
- * 		program attached as a TC classifier on the same device can pick
- * 		this up for further post-processing. Since TC works with socket
- * 		buffers, it remains possible to set from XDP the **mark** or
- * 		**priority** pointers, or other pointers for the socket buffer.
- * 		Having this scratch space generic and programmable allows for
- * 		more flexibility as the user is free to store whatever meta
- * 		data they need.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
- * 	Description
- * 		Read the value of a perf event counter, and store it into *buf*
- * 		of size *buf_size*. This helper relies on a *map* of type
- * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
- * 		counter is selected when *map* is updated with perf event file
- * 		descriptors. The *map* is an array whose size is the number of
- * 		available CPUs, and each cell contains a value relative to one
- * 		CPU. The value to retrieve is indicated by *flags*, that
- * 		contains the index of the CPU to look up, masked with
- * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
- * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
- * 		current CPU should be retrieved.
- *
- * 		This helper behaves in a way close to
- * 		**bpf_perf_event_read**\ () helper, save that instead of
- * 		just returning the value observed, it fills the *buf*
- * 		structure. This allows for additional data to be retrieved: in
- * 		particular, the enabled and running times (in *buf*\
- * 		**->enabled** and *buf*\ **->running**, respectively) are
- * 		copied. In general, **bpf_perf_event_read_value**\ () is
- * 		recommended over **bpf_perf_event_read**\ (), which has some
- * 		ABI issues and provides fewer functionalities.
- *
- * 		These values are interesting, because hardware PMU (Performance
- * 		Monitoring Unit) counters are limited resources. When there are
- * 		more PMU based perf events opened than available counters,
- * 		kernel will multiplex these events so each event gets certain
- * 		percentage (but not all) of the PMU time. In case that
- * 		multiplexing happens, the number of samples or counter value
- * 		will not reflect the case compared to when no multiplexing
- * 		occurs. This makes comparison between different runs difficult.
- * 		Typically, the counter value should be normalized before
- * 		comparing to other experiments. The usual normalization is done
- * 		as follows.
- *
- * 		::
- *
- * 			normalized_counter = counter * t_enabled / t_running
- *
- * 		Where t_enabled is the time enabled for event and t_running is
- * 		the time running for event since last normalization. The
- * 		enabled and running times are accumulated since the perf event
- * 		open. To achieve scaling factor between two invocations of an
- * 		eBPF program, users can can use CPU id as the key (which is
- * 		typical for perf array usage model) to remember the previous
- * 		value and do the calculation inside the eBPF program.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
- * 	Description
- * 		For en eBPF program attached to a perf event, retrieve the
- * 		value of the event counter associated to *ctx* and store it in
- * 		the structure pointed by *buf* and of size *buf_size*. Enabled
- * 		and running times are also stored in the structure (see
- * 		description of helper **bpf_perf_event_read_value**\ () for
- * 		more details).
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
- * 	Description
- * 		Emulate a call to **getsockopt()** on the socket associated to
- * 		*bpf_socket*, which must be a full socket. The *level* at
- * 		which the option resides and the name *optname* of the option
- * 		must be specified, see **getsockopt(2)** for more information.
- * 		The retrieved value is stored in the structure pointed by
- * 		*opval* and of length *optlen*.
- *
- * 		This helper actually implements a subset of **getsockopt()**.
- * 		It supports the following *level*\ s:
- *
- * 		* **IPPROTO_TCP**, which supports *optname*
- * 		  **TCP_CONGESTION**.
- * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
- * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_override_return(struct pt_regs *regs, u64 rc)
- * 	Description
- * 		Used for error injection, this helper uses kprobes to override
- * 		the return value of the probed function, and to set it to *rc*.
- * 		The first argument is the context *regs* on which the kprobe
- * 		works.
- *
- * 		This helper works by setting setting the PC (program counter)
- * 		to an override function which is run in place of the original
- * 		probed function. This means the probed function is not run at
- * 		all. The replacement function just returns with the required
- * 		value.
- *
- * 		This helper has security implications, and thus is subject to
- * 		restrictions. It is only available if the kernel was compiled
- * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
- * 		option, and in this case it only works on functions tagged with
- * 		**ALLOW_ERROR_INJECTION** in the kernel code.
- *
- * 		Also, the helper is only available for the architectures having
- * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
- * 		x86 architecture is the only one to support this feature.
- * 	Return
- * 		0
- *
- * int bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
- * 	Description
- * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
- * 		for the full TCP socket associated to *bpf_sock_ops* to
- * 		*argval*.
- *
- * 		The primary use of this field is to determine if there should
- * 		be calls to eBPF programs of type
- * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
- * 		code. A program of the same type can change its value, per
- * 		connection and as necessary, when the connection is
- * 		established. This field is directly accessible for reading, but
- * 		this helper must be used for updates in order to return an
- * 		error if an eBPF program tries to set a callback that is not
- * 		supported in the current kernel.
- *
- * 		*argval* is a flag array which can combine these flags:
- *
- * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
- * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
- * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
- * 		* **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
- *
- * 		Therefore, this function can be used to clear a callback flag by
- * 		setting the appropriate bit to zero. e.g. to disable the RTO
- * 		callback:
- *
- * 		**bpf_sock_ops_cb_flags_set(bpf_sock,**
- * 			**bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
- *
- * 		Here are some examples of where one could call such eBPF
- * 		program:
- *
- * 		* When RTO fires.
- * 		* When a packet is retransmitted.
- * 		* When the connection terminates.
- * 		* When a packet is sent.
- * 		* When a packet is received.
- * 	Return
- * 		Code **-EINVAL** if the socket is not a full TCP socket;
- * 		otherwise, a positive number containing the bits that could not
- * 		be set is returned (which comes down to 0 if all bits were set
- * 		as required).
- *
- * int bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
- * 	Description
- * 		This helper is used in programs implementing policies at the
- * 		socket level. If the message *msg* is allowed to pass (i.e. if
- * 		the verdict eBPF program returns **SK_PASS**), redirect it to
- * 		the socket referenced by *map* (of type
- * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
- * 		egress interfaces can be used for redirection. The
- * 		**BPF_F_INGRESS** value in *flags* is used to make the
- * 		distinction (ingress path is selected if the flag is present,
- * 		egress path otherwise). This is the only flag supported for now.
- * 	Return
- * 		**SK_PASS** on success, or **SK_DROP** on error.
- *
- * int bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
- * 	Description
- * 		For socket policies, apply the verdict of the eBPF program to
- * 		the next *bytes* (number of bytes) of message *msg*.
- *
- * 		For example, this helper can be used in the following cases:
- *
- * 		* A single **sendmsg**\ () or **sendfile**\ () system call
- * 		  contains multiple logical messages that the eBPF program is
- * 		  supposed to read and for which it should apply a verdict.
- * 		* An eBPF program only cares to read the first *bytes* of a
- * 		  *msg*. If the message has a large payload, then setting up
- * 		  and calling the eBPF program repeatedly for all bytes, even
- * 		  though the verdict is already known, would create unnecessary
- * 		  overhead.
- *
- * 		When called from within an eBPF program, the helper sets a
- * 		counter internal to the BPF infrastructure, that is used to
- * 		apply the last verdict to the next *bytes*. If *bytes* is
- * 		smaller than the current data being processed from a
- * 		**sendmsg**\ () or **sendfile**\ () system call, the first
- * 		*bytes* will be sent and the eBPF program will be re-run with
- * 		the pointer for start of data pointing to byte number *bytes*
- * 		**+ 1**. If *bytes* is larger than the current data being
- * 		processed, then the eBPF verdict will be applied to multiple
- * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
- * 		consumed.
- *
- * 		Note that if a socket closes with the internal counter holding
- * 		a non-zero value, this is not a problem because data is not
- * 		being buffered for *bytes* and is sent as it is received.
- * 	Return
- * 		0
- *
- * int bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
- * 	Description
- * 		For socket policies, prevent the execution of the verdict eBPF
- * 		program for message *msg* until *bytes* (byte number) have been
- * 		accumulated.
- *
- * 		This can be used when one needs a specific number of bytes
- * 		before a verdict can be assigned, even if the data spans
- * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
- * 		case would be a user calling **sendmsg**\ () repeatedly with
- * 		1-byte long message segments. Obviously, this is bad for
- * 		performance, but it is still valid. If the eBPF program needs
- * 		*bytes* bytes to validate a header, this helper can be used to
- * 		prevent the eBPF program to be called again until *bytes* have
- * 		been accumulated.
- * 	Return
- * 		0
- *
- * int bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
- * 	Description
- * 		For socket policies, pull in non-linear data from user space
- * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
- * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
- * 		respectively.
- *
- * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
- * 		*msg* it can only parse data that the (**data**, **data_end**)
- * 		pointers have already consumed. For **sendmsg**\ () hooks this
- * 		is likely the first scatterlist element. But for calls relying
- * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
- * 		be the range (**0**, **0**) because the data is shared with
- * 		user space and by default the objective is to avoid allowing
- * 		user space to modify data while (or after) eBPF verdict is
- * 		being decided. This helper can be used to pull in data and to
- * 		set the start and end pointer to given values. Data will be
- * 		copied if necessary (i.e. if data was not linear and if start
- * 		and end pointers do not point to the same chunk).
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- *
- * 		All values for *flags* are reserved for future usage, and must
- * 		be left at zero.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
- * 	Description
- * 		Bind the socket associated to *ctx* to the address pointed by
- * 		*addr*, of length *addr_len*. This allows for making outgoing
- * 		connection from the desired IP address, which can be useful for
- * 		example when all processes inside a cgroup should use one
- * 		single IP address on a host that has multiple IP configured.
- *
- * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
- * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
- * 		**AF_INET6**). Looking for a free port to bind to can be
- * 		expensive, therefore binding to port is not permitted by the
- * 		helper: *addr*\ **->sin_port** (or **sin6_port**, respectively)
- * 		must be set to zero.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
- * 	Description
- * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
- * 		only possible to shrink the packet as of this writing,
- * 		therefore *delta* must be a negative integer.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
- * 	Description
- * 		Retrieve the XFRM state (IP transform framework, see also
- * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
- *
- * 		The retrieved value is stored in the **struct bpf_xfrm_state**
- * 		pointed by *xfrm_state* and of length *size*.
- *
- * 		All values for *flags* are reserved for future usage, and must
- * 		be left at zero.
- *
- * 		This helper is available only if the kernel was compiled with
- * 		**CONFIG_XFRM** configuration option.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_get_stack(struct pt_regs *regs, void *buf, u32 size, u64 flags)
- * 	Description
- * 		Return a user or a kernel stack in bpf program provided buffer.
- * 		To achieve this, the helper needs *ctx*, which is a pointer
- * 		to the context on which the tracing program is executed.
- * 		To store the stacktrace, the bpf program provides *buf* with
- * 		a nonnegative *size*.
- *
- * 		The last argument, *flags*, holds the number of stack frames to
- * 		skip (from 0 to 255), masked with
- * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
- * 		the following flags:
- *
- * 		**BPF_F_USER_STACK**
- * 			Collect a user space stack instead of a kernel stack.
- * 		**BPF_F_USER_BUILD_ID**
- * 			Collect buildid+offset instead of ips for user stack,
- * 			only valid if **BPF_F_USER_STACK** is also specified.
- *
- * 		**bpf_get_stack**\ () can collect up to
- * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
- * 		to sufficient large buffer size. Note that
- * 		this limit can be controlled with the **sysctl** program, and
- * 		that it should be manually increased in order to profile long
- * 		user stacks (such as stacks for Java programs). To do so, use:
- *
- * 		::
- *
- * 			# sysctl kernel.perf_event_max_stack=<new value>
- * 	Return
- * 		A non-negative value equal to or less than *size* on success,
- * 		or a negative error in case of failure.
- *
- * int bpf_skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
- * 	Description
- * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
- * 		it provides an easy way to load *len* bytes from *offset*
- * 		from the packet associated to *skb*, into the buffer pointed
- * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
- * 		a fifth argument *start_header* exists in order to select a
- * 		base offset to start from. *start_header* can be one of:
- *
- * 		**BPF_HDR_START_MAC**
- * 			Base offset to load data from is *skb*'s mac header.
- * 		**BPF_HDR_START_NET**
- * 			Base offset to load data from is *skb*'s network header.
- *
- * 		In general, "direct packet access" is the preferred method to
- * 		access packet data, however, this helper is in particular useful
- * 		in socket filters where *skb*\ **->data** does not always point
- * 		to the start of the mac header and where "direct packet access"
- * 		is not available.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
- *	Description
- *		Do FIB lookup in kernel tables using parameters in *params*.
- *		If lookup is successful and result shows packet is to be
- *		forwarded, the neighbor tables are searched for the nexthop.
- *		If successful (ie., FIB lookup shows forwarding and nexthop
- *		is resolved), the nexthop address is returned in ipv4_dst
- *		or ipv6_dst based on family, smac is set to mac address of
- *		egress device, dmac is set to nexthop mac address, rt_metric
- *		is set to metric from route (IPv4/IPv6 only), and ifindex
- *		is set to the device index of the nexthop from the FIB lookup.
- *
- *		*plen* argument is the size of the passed in struct.
- *		*flags* argument can be a combination of one or more of the
- *		following values:
- *
- *		**BPF_FIB_LOOKUP_DIRECT**
- *			Do a direct table lookup vs full lookup using FIB
- *			rules.
- *		**BPF_FIB_LOOKUP_OUTPUT**
- *			Perform lookup from an egress perspective (default is
- *			ingress).
- *
- *		*ctx* is either **struct xdp_md** for XDP programs or
- *		**struct sk_buff** tc cls_act programs.
- *	Return
- *		* < 0 if any input argument is invalid
- *		*   0 on success (packet is forwarded, nexthop neighbor exists)
- *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
- *		  packet is not forwarded or needs assist from full stack
- *
- * int bpf_sock_hash_update(struct bpf_sock_ops_kern *skops, struct bpf_map *map, void *key, u64 flags)
- *	Description
- *		Add an entry to, or update a sockhash *map* referencing sockets.
- *		The *skops* is used as a new value for the entry associated to
- *		*key*. *flags* is one of:
- *
- *		**BPF_NOEXIST**
- *			The entry for *key* must not exist in the map.
- *		**BPF_EXIST**
- *			The entry for *key* must already exist in the map.
- *		**BPF_ANY**
- *			No condition on the existence of the entry for *key*.
- *
- *		If the *map* has eBPF programs (parser and verdict), those will
- *		be inherited by the socket being added. If the socket is
- *		already attached to eBPF programs, this results in an error.
- *	Return
- *		0 on success, or a negative error in case of failure.
- *
- * int bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
- *	Description
- *		This helper is used in programs implementing policies at the
- *		socket level. If the message *msg* is allowed to pass (i.e. if
- *		the verdict eBPF program returns **SK_PASS**), redirect it to
- *		the socket referenced by *map* (of type
- *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
- *		egress interfaces can be used for redirection. The
- *		**BPF_F_INGRESS** value in *flags* is used to make the
- *		distinction (ingress path is selected if the flag is present,
- *		egress path otherwise). This is the only flag supported for now.
- *	Return
- *		**SK_PASS** on success, or **SK_DROP** on error.
- *
- * int bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
- *	Description
- *		This helper is used in programs implementing policies at the
- *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
- *		if the verdeict eBPF program returns **SK_PASS**), redirect it
- *		to the socket referenced by *map* (of type
- *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
- *		egress interfaces can be used for redirection. The
- *		**BPF_F_INGRESS** value in *flags* is used to make the
- *		distinction (ingress path is selected if the flag is present,
- *		egress otherwise). This is the only flag supported for now.
- *	Return
- *		**SK_PASS** on success, or **SK_DROP** on error.
- *
- * int bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
- *	Description
- *		Encapsulate the packet associated to *skb* within a Layer 3
- *		protocol header. This header is provided in the buffer at
- *		address *hdr*, with *len* its size in bytes. *type* indicates
- *		the protocol of the header and can be one of:
- *
- *		**BPF_LWT_ENCAP_SEG6**
- *			IPv6 encapsulation with Segment Routing Header
- *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
- *			the IPv6 header is computed by the kernel.
- *		**BPF_LWT_ENCAP_SEG6_INLINE**
- *			Only works if *skb* contains an IPv6 packet. Insert a
- *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
- *			the IPv6 header.
- *		**BPF_LWT_ENCAP_IP**
- *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
- *			must be IPv4 or IPv6, followed by zero or more
- *			additional headers, up to **LWT_BPF_MAX_HEADROOM**
- *			total bytes in all prepended headers. Please note that
- *			if **skb_is_gso**\ (*skb*) is true, no more than two
- *			headers can be prepended, and the inner header, if
- *			present, should be either GRE or UDP/GUE.
- *
- *		**BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
- *		of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
- *		be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
- *		**BPF_PROG_TYPE_LWT_XMIT**.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- *	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
- *	Description
- *		Store *len* bytes from address *from* into the packet
- *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
- *		inside the outermost IPv6 Segment Routing Header can be
- *		modified through this helper.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- *	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
- *	Description
- *		Adjust the size allocated to TLVs in the outermost IPv6
- *		Segment Routing Header contained in the packet associated to
- *		*skb*, at position *offset* by *delta* bytes. Only offsets
- *		after the segments are accepted. *delta* can be as well
- *		positive (growing) as negative (shrinking).
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- *	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
- *	Description
- *		Apply an IPv6 Segment Routing action of type *action* to the
- *		packet associated to *skb*. Each action takes a parameter
- *		contained at address *param*, and of length *param_len* bytes.
- *		*action* can be one of:
- *
- *		**SEG6_LOCAL_ACTION_END_X**
- *			End.X action: Endpoint with Layer-3 cross-connect.
- *			Type of *param*: **struct in6_addr**.
- *		**SEG6_LOCAL_ACTION_END_T**
- *			End.T action: Endpoint with specific IPv6 table lookup.
- *			Type of *param*: **int**.
- *		**SEG6_LOCAL_ACTION_END_B6**
- *			End.B6 action: Endpoint bound to an SRv6 policy.
- *			Type of *param*: **struct ipv6_sr_hdr**.
- *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
- *			End.B6.Encap action: Endpoint bound to an SRv6
- *			encapsulation policy.
- *			Type of *param*: **struct ipv6_sr_hdr**.
- *
- * 		A call to this helper is susceptible to change the underlying
- * 		packet buffer. Therefore, at load time, all checks on pointers
- * 		previously done by the verifier are invalidated and must be
- * 		performed again, if the helper is used in combination with
- * 		direct packet access.
- *	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_rc_repeat(void *ctx)
- *	Description
- *		This helper is used in programs implementing IR decoding, to
- *		report a successfully decoded repeat key message. This delays
- *		the generation of a key up event for previously generated
- *		key down event.
- *
- *		Some IR protocols like NEC have a special IR message for
- *		repeating last button, for when a button is held down.
- *
- *		The *ctx* should point to the lirc sample as passed into
- *		the program.
- *
- *		This helper is only available is the kernel was compiled with
- *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
- *		"**y**".
- *	Return
- *		0
- *
- * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
- *	Description
- *		This helper is used in programs implementing IR decoding, to
- *		report a successfully decoded key press with *scancode*,
- *		*toggle* value in the given *protocol*. The scancode will be
- *		translated to a keycode using the rc keymap, and reported as
- *		an input key down event. After a period a key up event is
- *		generated. This period can be extended by calling either
- *		**bpf_rc_keydown**\ () again with the same values, or calling
- *		**bpf_rc_repeat**\ ().
- *
- *		Some protocols include a toggle bit, in case the button	was
- *		released and pressed again between consecutive scancodes.
- *
- *		The *ctx* should point to the lirc sample as passed into
- *		the program.
- *
- *		The *protocol* is the decoded protocol number (see
- *		**enum rc_proto** for some predefined values).
- *
- *		This helper is only available is the kernel was compiled with
- *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
- *		"**y**".
- *	Return
- *		0
- *
- * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
- * 	Description
- * 		Return the cgroup v2 id of the socket associated with the *skb*.
- * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
- * 		helper for cgroup v1 by providing a tag resp. identifier that
- * 		can be matched on or used for map lookups e.g. to implement
- * 		policy. The cgroup v2 id of a given path in the hierarchy is
- * 		exposed in user space through the f_handle API in order to get
- * 		to the same 64-bit id.
- *
- * 		This helper can be used on TC egress path, but not on ingress,
- * 		and is available only if the kernel was compiled with the
- * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
- * 	Return
- * 		The id is returned or 0 in case the id could not be retrieved.
- *
- * u64 bpf_get_current_cgroup_id(void)
- * 	Return
- * 		A 64-bit integer containing the current cgroup id based
- * 		on the cgroup within which the current task is running.
- *
- * void *bpf_get_local_storage(void *map, u64 flags)
- *	Description
- *		Get the pointer to the local storage area.
- *		The type and the size of the local storage is defined
- *		by the *map* argument.
- *		The *flags* meaning is specific for each map type,
- *		and has to be 0 for cgroup local storage.
- *
- *		Depending on the BPF program type, a local storage area
- *		can be shared between multiple instances of the BPF program,
- *		running simultaneously.
- *
- *		A user should care about the synchronization by himself.
- *		For example, by using the **BPF_STX_XADD** instruction to alter
- *		the shared data.
- *	Return
- *		A pointer to the local storage area.
- *
- * int bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
- *	Description
- *		Select a **SO_REUSEPORT** socket from a
- *		**BPF_MAP_TYPE_REUSEPORT_ARRAY** *map*.
- *		It checks the selected socket is matching the incoming
- *		request in the socket buffer.
- *	Return
- *		0 on success, or a negative error in case of failure.
- *
- * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
- *	Description
- *		Return id of cgroup v2 that is ancestor of cgroup associated
- *		with the *skb* at the *ancestor_level*.  The root cgroup is at
- *		*ancestor_level* zero and each step down the hierarchy
- *		increments the level. If *ancestor_level* == level of cgroup
- *		associated with *skb*, then return value will be same as that
- *		of **bpf_skb_cgroup_id**\ ().
- *
- *		The helper is useful to implement policies based on cgroups
- *		that are upper in hierarchy than immediate cgroup associated
- *		with *skb*.
- *
- *		The format of returned id and helper limitations are same as in
- *		**bpf_skb_cgroup_id**\ ().
- *	Return
- *		The id is returned or 0 in case the id could not be retrieved.
- *
- * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
- *	Description
- *		Look for TCP socket matching *tuple*, optionally in a child
- *		network namespace *netns*. The return value must be checked,
- *		and if non-**NULL**, released via **bpf_sk_release**\ ().
- *
- *		The *ctx* should point to the context of the program, such as
- *		the skb or socket (depending on the hook in use). This is used
- *		to determine the base network namespace for the lookup.
- *
- *		*tuple_size* must be one of:
- *
- *		**sizeof**\ (*tuple*\ **->ipv4**)
- *			Look for an IPv4 socket.
- *		**sizeof**\ (*tuple*\ **->ipv6**)
- *			Look for an IPv6 socket.
- *
- *		If the *netns* is a negative signed 32-bit integer, then the
- *		socket lookup table in the netns associated with the *ctx* will
- *		will be used. For the TC hooks, this is the netns of the device
- *		in the skb. For socket hooks, this is the netns of the socket.
- *		If *netns* is any other signed 32-bit value greater than or
- *		equal to zero then it specifies the ID of the netns relative to
- *		the netns associated with the *ctx*. *netns* values beyond the
- *		range of 32-bit integers are reserved for future use.
- *
- *		All values for *flags* are reserved for future usage, and must
- *		be left at zero.
- *
- *		This helper is available only if the kernel was compiled with
- *		**CONFIG_NET** configuration option.
- *	Return
- *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
- *		For sockets with reuseport option, the **struct bpf_sock**
- *		result is from *reuse*\ **->socks**\ [] using the hash of the
- *		tuple.
- *
- * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
- *	Description
- *		Look for UDP socket matching *tuple*, optionally in a child
- *		network namespace *netns*. The return value must be checked,
- *		and if non-**NULL**, released via **bpf_sk_release**\ ().
- *
- *		The *ctx* should point to the context of the program, such as
- *		the skb or socket (depending on the hook in use). This is used
- *		to determine the base network namespace for the lookup.
- *
- *		*tuple_size* must be one of:
- *
- *		**sizeof**\ (*tuple*\ **->ipv4**)
- *			Look for an IPv4 socket.
- *		**sizeof**\ (*tuple*\ **->ipv6**)
- *			Look for an IPv6 socket.
- *
- *		If the *netns* is a negative signed 32-bit integer, then the
- *		socket lookup table in the netns associated with the *ctx* will
- *		will be used. For the TC hooks, this is the netns of the device
- *		in the skb. For socket hooks, this is the netns of the socket.
- *		If *netns* is any other signed 32-bit value greater than or
- *		equal to zero then it specifies the ID of the netns relative to
- *		the netns associated with the *ctx*. *netns* values beyond the
- *		range of 32-bit integers are reserved for future use.
- *
- *		All values for *flags* are reserved for future usage, and must
- *		be left at zero.
- *
- *		This helper is available only if the kernel was compiled with
- *		**CONFIG_NET** configuration option.
- *	Return
- *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
- *		For sockets with reuseport option, the **struct bpf_sock**
- *		result is from *reuse*\ **->socks**\ [] using the hash of the
- *		tuple.
- *
- * int bpf_sk_release(struct bpf_sock *sock)
- *	Description
- *		Release the reference held by *sock*. *sock* must be a
- *		non-**NULL** pointer that was returned from
- *		**bpf_sk_lookup_xxx**\ ().
- *	Return
- *		0 on success, or a negative error in case of failure.
- *
- * int bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
- * 	Description
- * 		Push an element *value* in *map*. *flags* is one of:
- *
- * 		**BPF_EXIST**
- * 			If the queue/stack is full, the oldest element is
- * 			removed to make room for this.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_map_pop_elem(struct bpf_map *map, void *value)
- * 	Description
- * 		Pop an element from *map*.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_map_peek_elem(struct bpf_map *map, void *value)
- * 	Description
- * 		Get an element from *map* without removing it.
- * 	Return
- * 		0 on success, or a negative error in case of failure.
- *
- * int bpf_msg_push_data(struct sk_buff *skb, u32 start, u32 len, u64 flags)
- *	Description
- *		For socket policies, insert *len* bytes into *msg* at offset
- *		*start*.
- *
- *		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
- *		*msg* it may want to insert metadata or options into the *msg*.
- *		This can later be read and used by any of the lower layer BPF
- *		hooks.
- *
- *		This helper may fail if under memory pressure (a malloc
- *		fails) in these cases BPF programs will get an appropriate
- *		error and BPF programs will need to handle them.
- *	Return
- *		0 on success, or a negative error in case of failure.
- *
- * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 pop, u64 flags)
- *	Description
- *		Will remove *pop* bytes from a *msg* starting at byte *start*.
- *		This may result in **ENOMEM** errors under certain situations if
- *		an allocation and copy are required due to a full ring buffer.
- *		However, the helper will try to avoid doing the allocation
- *		if possible. Other errors can occur if input parameters are
- *		invalid either due to *start* byte not being valid part of *msg*
- *		payload and/or *pop* value being to large.
- *	Return
- *		0 on success, or a negative error in case of failure.
- *
- * int bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
- *	Description
- *		This helper is used in programs implementing IR decoding, to
- *		report a successfully decoded pointer movement.
- *
- *		The *ctx* should point to the lirc sample as passed into
- *		the program.
- *
- *		This helper is only available is the kernel was compiled with
- *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
- *		"**y**".
- *	Return
- *		0
- *
- * int bpf_spin_lock(struct bpf_spin_lock *lock)
- *	Description
- *		Acquire a spinlock represented by the pointer *lock*, which is
- *		stored as part of a value of a map. Taking the lock allows to
- *		safely update the rest of the fields in that value. The
- *		spinlock can (and must) later be released with a call to
- *		**bpf_spin_unlock**\ (\ *lock*\ ).
- *
- *		Spinlocks in BPF programs come with a number of restrictions
- *		and constraints:
- *
- *		* **bpf_spin_lock** objects are only allowed inside maps of
- *		  types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
- *		  list could be extended in the future).
- *		* BTF description of the map is mandatory.
- *		* The BPF program can take ONE lock at a time, since taking two
- *		  or more could cause dead locks.
- *		* Only one **struct bpf_spin_lock** is allowed per map element.
- *		* When the lock is taken, calls (either BPF to BPF or helpers)
- *		  are not allowed.
- *		* The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
- *		  allowed inside a spinlock-ed region.
- *		* The BPF program MUST call **bpf_spin_unlock**\ () to release
- *		  the lock, on all execution paths, before it returns.
- *		* The BPF program can access **struct bpf_spin_lock** only via
- *		  the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
- *		  helpers. Loading or storing data into the **struct
- *		  bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
- *		* To use the **bpf_spin_lock**\ () helper, the BTF description
- *		  of the map value must be a struct and have **struct
- *		  bpf_spin_lock** *anyname*\ **;** field at the top level.
- *		  Nested lock inside another struct is not allowed.
- *		* The **struct bpf_spin_lock** *lock* field in a map value must
- *		  be aligned on a multiple of 4 bytes in that value.
- *		* Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
- *		  the **bpf_spin_lock** field to user space.
- *		* Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
- *		  a BPF program, do not update the **bpf_spin_lock** field.
- *		* **bpf_spin_lock** cannot be on the stack or inside a
- *		  networking packet (it can only be inside of a map values).
- *		* **bpf_spin_lock** is available to root only.
- *		* Tracing programs and socket filter programs cannot use
- *		  **bpf_spin_lock**\ () due to insufficient preemption checks
- *		  (but this may change in the future).
- *		* **bpf_spin_lock** is not allowed in inner maps of map-in-map.
- *	Return
- *		0
- *
- * int bpf_spin_unlock(struct bpf_spin_lock *lock)
- *	Description
- *		Release the *lock* previously locked by a call to
- *		**bpf_spin_lock**\ (\ *lock*\ ).
- *	Return
- *		0
- *
- * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
- *	Description
- *		This helper gets a **struct bpf_sock** pointer such
- *		that all the fields in this **bpf_sock** can be accessed.
- *	Return
- *		A **struct bpf_sock** pointer on success, or **NULL** in
- *		case of failure.
- *
- * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
- *	Description
- *		This helper gets a **struct bpf_tcp_sock** pointer from a
- *		**struct bpf_sock** pointer.
- *	Return
- *		A **struct bpf_tcp_sock** pointer on success, or **NULL** in
- *		case of failure.
- *
- * int bpf_skb_ecn_set_ce(struct sk_buf *skb)
- *	Description
- *		Set ECN (Explicit Congestion Notification) field of IP header
- *		to **CE** (Congestion Encountered) if current value is **ECT**
- *		(ECN Capable Transport). Otherwise, do nothing. Works with IPv6
- *		and IPv4.
- *	Return
- *		1 if the **CE** flag is set (either by the current helper call
- *		or because it was already present), 0 if it is not set.
- *
- * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
- *	Description
- *		Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
- *		**bpf_sk_release**\ () is unnecessary and not allowed.
- *	Return
- *		A **struct bpf_sock** pointer on success, or **NULL** in
- *		case of failure.
- *
- * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
- *	Description
- *		Look for TCP socket matching *tuple*, optionally in a child
- *		network namespace *netns*. The return value must be checked,
- *		and if non-**NULL**, released via **bpf_sk_release**\ ().
- *
- *		This function is identical to **bpf_sk_lookup_tcp**\ (), except
- *		that it also returns timewait or request sockets. Use
- *		**bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
- *		full structure.
- *
- *		This helper is available only if the kernel was compiled with
- *		**CONFIG_NET** configuration option.
- *	Return
- *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
- *		For sockets with reuseport option, the **struct bpf_sock**
- *		result is from *reuse*\ **->socks**\ [] using the hash of the
- *		tuple.
- *
- * int bpf_tcp_check_syncookie(struct bpf_sock *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
- * 	Description
- * 		Check whether *iph* and *th* contain a valid SYN cookie ACK for
- * 		the listening socket in *sk*.
- *
- * 		*iph* points to the start of the IPv4 or IPv6 header, while
- * 		*iph_len* contains **sizeof**\ (**struct iphdr**) or
- * 		**sizeof**\ (**struct ip6hdr**).
- *
- * 		*th* points to the start of the TCP header, while *th_len*
- * 		contains **sizeof**\ (**struct tcphdr**).
- *
- * 	Return
- * 		0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
- * 		error otherwise.
- *
- * int bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
- *	Description
- *		Get name of sysctl in /proc/sys/ and copy it into provided by
- *		program buffer *buf* of size *buf_len*.
- *
- *		The buffer is always NUL terminated, unless it's zero-sized.
- *
- *		If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
- *		copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
- *		only (e.g. "tcp_mem").
- *	Return
- *		Number of character copied (not including the trailing NUL).
- *
- *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
- *		truncated name in this case).
- *
- * int bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
- *	Description
- *		Get current value of sysctl as it is presented in /proc/sys
- *		(incl. newline, etc), and copy it as a string into provided
- *		by program buffer *buf* of size *buf_len*.
- *
- *		The whole value is copied, no matter what file position user
- *		space issued e.g. sys_read at.
- *
- *		The buffer is always NUL terminated, unless it's zero-sized.
- *	Return
- *		Number of character copied (not including the trailing NUL).
- *
- *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
- *		truncated name in this case).
- *
- *		**-EINVAL** if current value was unavailable, e.g. because
- *		sysctl is uninitialized and read returns -EIO for it.
- *
- * int bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
- *	Description
- *		Get new value being written by user space to sysctl (before
- *		the actual write happens) and copy it as a string into
- *		provided by program buffer *buf* of size *buf_len*.
- *
- *		User space may write new value at file position > 0.
- *
- *		The buffer is always NUL terminated, unless it's zero-sized.
- *	Return
- *		Number of character copied (not including the trailing NUL).
- *
- *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
- *		truncated name in this case).
- *
- *		**-EINVAL** if sysctl is being read.
- *
- * int bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)
- *	Description
- *		Override new value being written by user space to sysctl with
- *		value provided by program in buffer *buf* of size *buf_len*.
- *
- *		*buf* should contain a string in same form as provided by user
- *		space on sysctl write.
- *
- *		User space may write new value at file position > 0. To override
- *		the whole sysctl value file position should be set to zero.
- *	Return
- *		0 on success.
- *
- *		**-E2BIG** if the *buf_len* is too big.
- *
- *		**-EINVAL** if sysctl is being read.
- *
- * int bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)
- *	Description
- *		Convert the initial part of the string from buffer *buf* of
- *		size *buf_len* to a long integer according to the given base
- *		and save the result in *res*.
- *
- *		The string may begin with an arbitrary amount of white space
- *		(as determined by **isspace**\ (3)) followed by a single
- *		optional '**-**' sign.
- *
- *		Five least significant bits of *flags* encode base, other bits
- *		are currently unused.
- *
- *		Base must be either 8, 10, 16 or 0 to detect it automatically
- *		similar to user space **strtol**\ (3).
- *	Return
- *		Number of characters consumed on success. Must be positive but
- *		no more than *buf_len*.
- *
- *		**-EINVAL** if no valid digits were found or unsupported base
- *		was provided.
- *
- *		**-ERANGE** if resulting value was out of range.
- *
- * int bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)
- *	Description
- *		Convert the initial part of the string from buffer *buf* of
- *		size *buf_len* to an unsigned long integer according to the
- *		given base and save the result in *res*.
- *
- *		The string may begin with an arbitrary amount of white space
- *		(as determined by **isspace**\ (3)).
- *
- *		Five least significant bits of *flags* encode base, other bits
- *		are currently unused.
- *
- *		Base must be either 8, 10, 16 or 0 to detect it automatically
- *		similar to user space **strtoul**\ (3).
- *	Return
- *		Number of characters consumed on success. Must be positive but
- *		no more than *buf_len*.
- *
- *		**-EINVAL** if no valid digits were found or unsupported base
- *		was provided.
- *
- *		**-ERANGE** if resulting value was out of range.
- *
- * void *bpf_sk_storage_get(struct bpf_map *map, struct bpf_sock *sk, void *value, u64 flags)
- *	Description
- *		Get a bpf-local-storage from a *sk*.
- *
- *		Logically, it could be thought of getting the value from
- *		a *map* with *sk* as the **key**.  From this
- *		perspective,  the usage is not much different from
- *		**bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
- *		helper enforces the key must be a full socket and the map must
- *		be a **BPF_MAP_TYPE_SK_STORAGE** also.
- *
- *		Underneath, the value is stored locally at *sk* instead of
- *		the *map*.  The *map* is used as the bpf-local-storage
- *		"type". The bpf-local-storage "type" (i.e. the *map*) is
- *		searched against all bpf-local-storages residing at *sk*.
- *
- *		An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
- *		used such that a new bpf-local-storage will be
- *		created if one does not exist.  *value* can be used
- *		together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
- *		the initial value of a bpf-local-storage.  If *value* is
- *		**NULL**, the new bpf-local-storage will be zero initialized.
- *	Return
- *		A bpf-local-storage pointer is returned on success.
- *
- *		**NULL** if not found or there was an error in adding
- *		a new bpf-local-storage.
- *
- * int bpf_sk_storage_delete(struct bpf_map *map, struct bpf_sock *sk)
- *	Description
- *		Delete a bpf-local-storage from a *sk*.
- *	Return
- *		0 on success.
- *
- *		**-ENOENT** if the bpf-local-storage cannot be found.
- *
- * int bpf_send_signal(u32 sig)
- *	Description
- *		Send signal *sig* to the current task.
- *	Return
- *		0 on success or successfully queued.
- *
- *		**-EBUSY** if work queue under nmi is full.
- *
- *		**-EINVAL** if *sig* is invalid.
- *
- *		**-EPERM** if no permission to send the *sig*.
- *
- *		**-EAGAIN** if bpf program can try again.
- *
- * s64 bpf_tcp_gen_syncookie(struct bpf_sock *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
- *	Description
- *		Try to issue a SYN cookie for the packet with corresponding
- *		IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
- *
- *		*iph* points to the start of the IPv4 or IPv6 header, while
- *		*iph_len* contains **sizeof**\ (**struct iphdr**) or
- *		**sizeof**\ (**struct ip6hdr**).
- *
- *		*th* points to the start of the TCP header, while *th_len*
- *		contains the length of the TCP header.
- *
- *	Return
- *		On success, lower 32 bits hold the generated SYN cookie in
- *		followed by 16 bits which hold the MSS value for that cookie,
- *		and the top 16 bits are unused.
- *
- *		On failure, the returned value is one of the following:
- *
- *		**-EINVAL** SYN cookie cannot be issued due to error
- *
- *		**-ENOENT** SYN cookie should not be issued (no SYN flood)
- *
- *		**-EOPNOTSUPP** kernel configuration does not enable SYN cookies
- *
- *		**-EPROTONOSUPPORT** IP packet version is not 4 or 6
- */
-#define __BPF_FUNC_MAPPER(FN)		\
-	FN(unspec),			\
-	FN(map_lookup_elem),		\
-	FN(map_update_elem),		\
-	FN(map_delete_elem),		\
-	FN(probe_read),			\
-	FN(ktime_get_ns),		\
-	FN(trace_printk),		\
-	FN(get_prandom_u32),		\
-	FN(get_smp_processor_id),	\
-	FN(skb_store_bytes),		\
-	FN(l3_csum_replace),		\
-	FN(l4_csum_replace),		\
-	FN(tail_call),			\
-	FN(clone_redirect),		\
-	FN(get_current_pid_tgid),	\
-	FN(get_current_uid_gid),	\
-	FN(get_current_comm),		\
-	FN(get_cgroup_classid),		\
-	FN(skb_vlan_push),		\
-	FN(skb_vlan_pop),		\
-	FN(skb_get_tunnel_key),		\
-	FN(skb_set_tunnel_key),		\
-	FN(perf_event_read),		\
-	FN(redirect),			\
-	FN(get_route_realm),		\
-	FN(perf_event_output),		\
-	FN(skb_load_bytes),		\
-	FN(get_stackid),		\
-	FN(csum_diff),			\
-	FN(skb_get_tunnel_opt),		\
-	FN(skb_set_tunnel_opt),		\
-	FN(skb_change_proto),		\
-	FN(skb_change_type),		\
-	FN(skb_under_cgroup),		\
-	FN(get_hash_recalc),		\
-	FN(get_current_task),		\
-	FN(probe_write_user),		\
-	FN(current_task_under_cgroup),	\
-	FN(skb_change_tail),		\
-	FN(skb_pull_data),		\
-	FN(csum_update),		\
-	FN(set_hash_invalid),		\
-	FN(get_numa_node_id),		\
-	FN(skb_change_head),		\
-	FN(xdp_adjust_head),		\
-	FN(probe_read_str),		\
-	FN(get_socket_cookie),		\
-	FN(get_socket_uid),		\
-	FN(set_hash),			\
-	FN(setsockopt),			\
-	FN(skb_adjust_room),		\
-	FN(redirect_map),		\
-	FN(sk_redirect_map),		\
-	FN(sock_map_update),		\
-	FN(xdp_adjust_meta),		\
-	FN(perf_event_read_value),	\
-	FN(perf_prog_read_value),	\
-	FN(getsockopt),			\
-	FN(override_return),		\
-	FN(sock_ops_cb_flags_set),	\
-	FN(msg_redirect_map),		\
-	FN(msg_apply_bytes),		\
-	FN(msg_cork_bytes),		\
-	FN(msg_pull_data),		\
-	FN(bind),			\
-	FN(xdp_adjust_tail),		\
-	FN(skb_get_xfrm_state),		\
-	FN(get_stack),			\
-	FN(skb_load_bytes_relative),	\
-	FN(fib_lookup),			\
-	FN(sock_hash_update),		\
-	FN(msg_redirect_hash),		\
-	FN(sk_redirect_hash),		\
-	FN(lwt_push_encap),		\
-	FN(lwt_seg6_store_bytes),	\
-	FN(lwt_seg6_adjust_srh),	\
-	FN(lwt_seg6_action),		\
-	FN(rc_repeat),			\
-	FN(rc_keydown),			\
-	FN(skb_cgroup_id),		\
-	FN(get_current_cgroup_id),	\
-	FN(get_local_storage),		\
-	FN(sk_select_reuseport),	\
-	FN(skb_ancestor_cgroup_id),	\
-	FN(sk_lookup_tcp),		\
-	FN(sk_lookup_udp),		\
-	FN(sk_release),			\
-	FN(map_push_elem),		\
-	FN(map_pop_elem),		\
-	FN(map_peek_elem),		\
-	FN(msg_push_data),		\
-	FN(msg_pop_data),		\
-	FN(rc_pointer_rel),		\
-	FN(spin_lock),			\
-	FN(spin_unlock),		\
-	FN(sk_fullsock),		\
-	FN(tcp_sock),			\
-	FN(skb_ecn_set_ce),		\
-	FN(get_listener_sock),		\
-	FN(skc_lookup_tcp),		\
-	FN(tcp_check_syncookie),	\
-	FN(sysctl_get_name),		\
-	FN(sysctl_get_current_value),	\
-	FN(sysctl_get_new_value),	\
-	FN(sysctl_set_new_value),	\
-	FN(strtol),			\
-	FN(strtoul),			\
-	FN(sk_storage_get),		\
-	FN(sk_storage_delete),		\
-	FN(send_signal),		\
-	FN(tcp_gen_syncookie),
-
-/* integer value in 'imm' field of BPF_CALL instruction selects which helper
- * function eBPF program intends to call
- */
-#define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
-enum bpf_func_id {
-	__BPF_FUNC_MAPPER(__BPF_ENUM_FN)
-	__BPF_FUNC_MAX_ID,
-};
-#undef __BPF_ENUM_FN
-
-/* All flags used by eBPF helper functions, placed here. */
-
-/* BPF_FUNC_skb_store_bytes flags. */
-#define BPF_F_RECOMPUTE_CSUM		(1ULL << 0)
-#define BPF_F_INVALIDATE_HASH		(1ULL << 1)
-
-/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
- * First 4 bits are for passing the header field size.
- */
-#define BPF_F_HDR_FIELD_MASK		0xfULL
-
-/* BPF_FUNC_l4_csum_replace flags. */
-#define BPF_F_PSEUDO_HDR		(1ULL << 4)
-#define BPF_F_MARK_MANGLED_0		(1ULL << 5)
-#define BPF_F_MARK_ENFORCE		(1ULL << 6)
-
-/* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
-#define BPF_F_INGRESS			(1ULL << 0)
-
-/* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
-#define BPF_F_TUNINFO_IPV6		(1ULL << 0)
-
-/* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
-#define BPF_F_SKIP_FIELD_MASK		0xffULL
-#define BPF_F_USER_STACK		(1ULL << 8)
-/* flags used by BPF_FUNC_get_stackid only. */
-#define BPF_F_FAST_STACK_CMP		(1ULL << 9)
-#define BPF_F_REUSE_STACKID		(1ULL << 10)
-/* flags used by BPF_FUNC_get_stack only. */
-#define BPF_F_USER_BUILD_ID		(1ULL << 11)
-
-/* BPF_FUNC_skb_set_tunnel_key flags. */
-#define BPF_F_ZERO_CSUM_TX		(1ULL << 1)
-#define BPF_F_DONT_FRAGMENT		(1ULL << 2)
-#define BPF_F_SEQ_NUMBER		(1ULL << 3)
-
-/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
- * BPF_FUNC_perf_event_read_value flags.
- */
-#define BPF_F_INDEX_MASK		0xffffffffULL
-#define BPF_F_CURRENT_CPU		BPF_F_INDEX_MASK
-/* BPF_FUNC_perf_event_output for sk_buff input context. */
-#define BPF_F_CTXLEN_MASK		(0xfffffULL << 32)
-
-/* Current network namespace */
-#define BPF_F_CURRENT_NETNS		(-1L)
-
-/* BPF_FUNC_skb_adjust_room flags. */
-#define BPF_F_ADJ_ROOM_FIXED_GSO	(1ULL << 0)
-
-#define BPF_ADJ_ROOM_ENCAP_L2_MASK	0xff
-#define BPF_ADJ_ROOM_ENCAP_L2_SHIFT	56
-
-#define BPF_F_ADJ_ROOM_ENCAP_L3_IPV4	(1ULL << 1)
-#define BPF_F_ADJ_ROOM_ENCAP_L3_IPV6	(1ULL << 2)
-#define BPF_F_ADJ_ROOM_ENCAP_L4_GRE	(1ULL << 3)
-#define BPF_F_ADJ_ROOM_ENCAP_L4_UDP	(1ULL << 4)
-#define BPF_F_ADJ_ROOM_ENCAP_L2(len)	(((__u64)len & \
-					  BPF_ADJ_ROOM_ENCAP_L2_MASK) \
-					 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
-
-/* BPF_FUNC_sysctl_get_name flags. */
-#define BPF_F_SYSCTL_BASE_NAME		(1ULL << 0)
-
-/* BPF_FUNC_sk_storage_get flags */
-#define BPF_SK_STORAGE_GET_F_CREATE	(1ULL << 0)
-
-/* Mode for BPF_FUNC_skb_adjust_room helper. */
-enum bpf_adj_room_mode {
-	BPF_ADJ_ROOM_NET,
-	BPF_ADJ_ROOM_MAC,
-};
-
-/* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
-enum bpf_hdr_start_off {
-	BPF_HDR_START_MAC,
-	BPF_HDR_START_NET,
-};
-
-/* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
-enum bpf_lwt_encap_mode {
-	BPF_LWT_ENCAP_SEG6,
-	BPF_LWT_ENCAP_SEG6_INLINE,
-	BPF_LWT_ENCAP_IP,
-};
-
-#define __bpf_md_ptr(type, name)	\
-union {					\
-	type name;			\
-	__u64 :64;			\
-} __attribute__((aligned(8)))
-
-/* user accessible mirror of in-kernel sk_buff.
- * new fields can only be added to the end of this structure
- */
-struct __sk_buff {
-	__u32 len;
-	__u32 pkt_type;
-	__u32 mark;
-	__u32 queue_mapping;
-	__u32 protocol;
-	__u32 vlan_present;
-	__u32 vlan_tci;
-	__u32 vlan_proto;
-	__u32 priority;
-	__u32 ingress_ifindex;
-	__u32 ifindex;
-	__u32 tc_index;
-	__u32 cb[5];
-	__u32 hash;
-	__u32 tc_classid;
-	__u32 data;
-	__u32 data_end;
-	__u32 napi_id;
-
-	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
-	__u32 family;
-	__u32 remote_ip4;	/* Stored in network byte order */
-	__u32 local_ip4;	/* Stored in network byte order */
-	__u32 remote_ip6[4];	/* Stored in network byte order */
-	__u32 local_ip6[4];	/* Stored in network byte order */
-	__u32 remote_port;	/* Stored in network byte order */
-	__u32 local_port;	/* stored in host byte order */
-	/* ... here. */
-
-	__u32 data_meta;
-	__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
-	__u64 tstamp;
-	__u32 wire_len;
-	__u32 gso_segs;
-	__bpf_md_ptr(struct bpf_sock *, sk);
-};
-
-struct bpf_tunnel_key {
-	__u32 tunnel_id;
-	union {
-		__u32 remote_ipv4;
-		__u32 remote_ipv6[4];
-	};
-	__u8 tunnel_tos;
-	__u8 tunnel_ttl;
-	__u16 tunnel_ext;	/* Padding, future use. */
-	__u32 tunnel_label;
-};
-
-/* user accessible mirror of in-kernel xfrm_state.
- * new fields can only be added to the end of this structure
- */
-struct bpf_xfrm_state {
-	__u32 reqid;
-	__u32 spi;	/* Stored in network byte order */
-	__u16 family;
-	__u16 ext;	/* Padding, future use. */
-	union {
-		__u32 remote_ipv4;	/* Stored in network byte order */
-		__u32 remote_ipv6[4];	/* Stored in network byte order */
-	};
-};
-
-/* Generic BPF return codes which all BPF program types may support.
- * The values are binary compatible with their TC_ACT_* counter-part to
- * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
- * programs.
- *
- * XDP is handled seprately, see XDP_*.
- */
-enum bpf_ret_code {
-	BPF_OK = 0,
-	/* 1 reserved */
-	BPF_DROP = 2,
-	/* 3-6 reserved */
-	BPF_REDIRECT = 7,
-	/* >127 are reserved for prog type specific return codes.
-	 *
-	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
-	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
-	 *    changed and should be routed based on its new L3 header.
-	 *    (This is an L3 redirect, as opposed to L2 redirect
-	 *    represented by BPF_REDIRECT above).
-	 */
-	BPF_LWT_REROUTE = 128,
-};
-
-struct bpf_sock {
-	__u32 bound_dev_if;
-	__u32 family;
-	__u32 type;
-	__u32 protocol;
-	__u32 mark;
-	__u32 priority;
-	/* IP address also allows 1 and 2 bytes access */
-	__u32 src_ip4;
-	__u32 src_ip6[4];
-	__u32 src_port;		/* host byte order */
-	__u32 dst_port;		/* network byte order */
-	__u32 dst_ip4;
-	__u32 dst_ip6[4];
-	__u32 state;
-};
-
-struct bpf_tcp_sock {
-	__u32 snd_cwnd;		/* Sending congestion window		*/
-	__u32 srtt_us;		/* smoothed round trip time << 3 in usecs */
-	__u32 rtt_min;
-	__u32 snd_ssthresh;	/* Slow start size threshold		*/
-	__u32 rcv_nxt;		/* What we want to receive next		*/
-	__u32 snd_nxt;		/* Next sequence we send		*/
-	__u32 snd_una;		/* First byte we want an ack for	*/
-	__u32 mss_cache;	/* Cached effective mss, not including SACKS */
-	__u32 ecn_flags;	/* ECN status bits.			*/
-	__u32 rate_delivered;	/* saved rate sample: packets delivered */
-	__u32 rate_interval_us;	/* saved rate sample: time elapsed */
-	__u32 packets_out;	/* Packets which are "in flight"	*/
-	__u32 retrans_out;	/* Retransmitted packets out		*/
-	__u32 total_retrans;	/* Total retransmits for entire connection */
-	__u32 segs_in;		/* RFC4898 tcpEStatsPerfSegsIn
-				 * total number of segments in.
-				 */
-	__u32 data_segs_in;	/* RFC4898 tcpEStatsPerfDataSegsIn
-				 * total number of data segments in.
-				 */
-	__u32 segs_out;		/* RFC4898 tcpEStatsPerfSegsOut
-				 * The total number of segments sent.
-				 */
-	__u32 data_segs_out;	/* RFC4898 tcpEStatsPerfDataSegsOut
-				 * total number of data segments sent.
-				 */
-	__u32 lost_out;		/* Lost packets			*/
-	__u32 sacked_out;	/* SACK'd packets			*/
-	__u64 bytes_received;	/* RFC4898 tcpEStatsAppHCThruOctetsReceived
-				 * sum(delta(rcv_nxt)), or how many bytes
-				 * were acked.
-				 */
-	__u64 bytes_acked;	/* RFC4898 tcpEStatsAppHCThruOctetsAcked
-				 * sum(delta(snd_una)), or how many bytes
-				 * were acked.
-				 */
-	__u32 dsack_dups;	/* RFC4898 tcpEStatsStackDSACKDups
-				 * total number of DSACK blocks received
-				 */
-	__u32 delivered;	/* Total data packets delivered incl. rexmits */
-	__u32 delivered_ce;	/* Like the above but only ECE marked packets */
-	__u32 icsk_retransmits;	/* Number of unrecovered [RTO] timeouts */
-};
-
-struct bpf_sock_tuple {
-	union {
-		struct {
-			__be32 saddr;
-			__be32 daddr;
-			__be16 sport;
-			__be16 dport;
-		} ipv4;
-		struct {
-			__be32 saddr[4];
-			__be32 daddr[4];
-			__be16 sport;
-			__be16 dport;
-		} ipv6;
-	};
-};
-
-struct bpf_xdp_sock {
-	__u32 queue_id;
-};
-
-#define XDP_PACKET_HEADROOM 256
-
-/* User return codes for XDP prog type.
- * A valid XDP program must return one of these defined values. All other
- * return codes are reserved for future use. Unknown return codes will
- * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
- */
-enum xdp_action {
-	XDP_ABORTED = 0,
-	XDP_DROP,
-	XDP_PASS,
-	XDP_TX,
-	XDP_REDIRECT,
-};
-
-/* user accessible metadata for XDP packet hook
- * new fields must be added to the end of this structure
- */
-struct xdp_md {
-	__u32 data;
-	__u32 data_end;
-	__u32 data_meta;
-	/* Below access go through struct xdp_rxq_info */
-	__u32 ingress_ifindex; /* rxq->dev->ifindex */
-	__u32 rx_queue_index;  /* rxq->queue_index  */
-};
-
-enum sk_action {
-	SK_DROP = 0,
-	SK_PASS,
-};
-
-/* user accessible metadata for SK_MSG packet hook, new fields must
- * be added to the end of this structure
- */
-struct sk_msg_md {
-	__bpf_md_ptr(void *, data);
-	__bpf_md_ptr(void *, data_end);
-
-	__u32 family;
-	__u32 remote_ip4;	/* Stored in network byte order */
-	__u32 local_ip4;	/* Stored in network byte order */
-	__u32 remote_ip6[4];	/* Stored in network byte order */
-	__u32 local_ip6[4];	/* Stored in network byte order */
-	__u32 remote_port;	/* Stored in network byte order */
-	__u32 local_port;	/* stored in host byte order */
-	__u32 size;		/* Total size of sk_msg */
-};
-
-struct sk_reuseport_md {
-	/*
-	 * Start of directly accessible data. It begins from
-	 * the tcp/udp header.
-	 */
-	__bpf_md_ptr(void *, data);
-	/* End of directly accessible data */
-	__bpf_md_ptr(void *, data_end);
-	/*
-	 * Total length of packet (starting from the tcp/udp header).
-	 * Note that the directly accessible bytes (data_end - data)
-	 * could be less than this "len".  Those bytes could be
-	 * indirectly read by a helper "bpf_skb_load_bytes()".
-	 */
-	__u32 len;
-	/*
-	 * Eth protocol in the mac header (network byte order). e.g.
-	 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
-	 */
-	__u32 eth_protocol;
-	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
-	__u32 bind_inany;	/* Is sock bound to an INANY address? */
-	__u32 hash;		/* A hash of the packet 4 tuples */
-};
-
-#define BPF_TAG_SIZE	8
-
-struct bpf_prog_info {
-	__u32 type;
-	__u32 id;
-	__u8  tag[BPF_TAG_SIZE];
-	__u32 jited_prog_len;
-	__u32 xlated_prog_len;
-	__aligned_u64 jited_prog_insns;
-	__aligned_u64 xlated_prog_insns;
-	__u64 load_time;	/* ns since boottime */
-	__u32 created_by_uid;
-	__u32 nr_map_ids;
-	__aligned_u64 map_ids;
-	char name[BPF_OBJ_NAME_LEN];
-	__u32 ifindex;
-	__u32 gpl_compatible:1;
-	__u32 :31; /* alignment pad */
-	__u64 netns_dev;
-	__u64 netns_ino;
-	__u32 nr_jited_ksyms;
-	__u32 nr_jited_func_lens;
-	__aligned_u64 jited_ksyms;
-	__aligned_u64 jited_func_lens;
-	__u32 btf_id;
-	__u32 func_info_rec_size;
-	__aligned_u64 func_info;
-	__u32 nr_func_info;
-	__u32 nr_line_info;
-	__aligned_u64 line_info;
-	__aligned_u64 jited_line_info;
-	__u32 nr_jited_line_info;
-	__u32 line_info_rec_size;
-	__u32 jited_line_info_rec_size;
-	__u32 nr_prog_tags;
-	__aligned_u64 prog_tags;
-	__u64 run_time_ns;
-	__u64 run_cnt;
-} __attribute__((aligned(8)));
-
-struct bpf_map_info {
-	__u32 type;
-	__u32 id;
-	__u32 key_size;
-	__u32 value_size;
-	__u32 max_entries;
-	__u32 map_flags;
-	char  name[BPF_OBJ_NAME_LEN];
-	__u32 ifindex;
-	__u32 :32;
-	__u64 netns_dev;
-	__u64 netns_ino;
-	__u32 btf_id;
-	__u32 btf_key_type_id;
-	__u32 btf_value_type_id;
-} __attribute__((aligned(8)));
-
-struct bpf_btf_info {
-	__aligned_u64 btf;
-	__u32 btf_size;
-	__u32 id;
-} __attribute__((aligned(8)));
-
-/* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
- * by user and intended to be used by socket (e.g. to bind to, depends on
- * attach attach type).
- */
-struct bpf_sock_addr {
-	__u32 user_family;	/* Allows 4-byte read, but no write. */
-	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
-				 * Stored in network byte order.
-				 */
-	__u32 user_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
-				 * Stored in network byte order.
-				 */
-	__u32 user_port;	/* Allows 4-byte read and write.
-				 * Stored in network byte order
-				 */
-	__u32 family;		/* Allows 4-byte read, but no write */
-	__u32 type;		/* Allows 4-byte read, but no write */
-	__u32 protocol;		/* Allows 4-byte read, but no write */
-	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read and 4-byte write.
-				 * Stored in network byte order.
-				 */
-	__u32 msg_src_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
-				 * Stored in network byte order.
-				 */
-	__bpf_md_ptr(struct bpf_sock *, sk);
-};
-
-/* User bpf_sock_ops struct to access socket values and specify request ops
- * and their replies.
- * Some of this fields are in network (bigendian) byte order and may need
- * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
- * New fields can only be added at the end of this structure
- */
-struct bpf_sock_ops {
-	__u32 op;
-	union {
-		__u32 args[4];		/* Optionally passed to bpf program */
-		__u32 reply;		/* Returned by bpf program	    */
-		__u32 replylong[4];	/* Optionally returned by bpf prog  */
-	};
-	__u32 family;
-	__u32 remote_ip4;	/* Stored in network byte order */
-	__u32 local_ip4;	/* Stored in network byte order */
-	__u32 remote_ip6[4];	/* Stored in network byte order */
-	__u32 local_ip6[4];	/* Stored in network byte order */
-	__u32 remote_port;	/* Stored in network byte order */
-	__u32 local_port;	/* stored in host byte order */
-	__u32 is_fullsock;	/* Some TCP fields are only valid if
-				 * there is a full socket. If not, the
-				 * fields read as zero.
-				 */
-	__u32 snd_cwnd;
-	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
-	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
-	__u32 state;
-	__u32 rtt_min;
-	__u32 snd_ssthresh;
-	__u32 rcv_nxt;
-	__u32 snd_nxt;
-	__u32 snd_una;
-	__u32 mss_cache;
-	__u32 ecn_flags;
-	__u32 rate_delivered;
-	__u32 rate_interval_us;
-	__u32 packets_out;
-	__u32 retrans_out;
-	__u32 total_retrans;
-	__u32 segs_in;
-	__u32 data_segs_in;
-	__u32 segs_out;
-	__u32 data_segs_out;
-	__u32 lost_out;
-	__u32 sacked_out;
-	__u32 sk_txhash;
-	__u64 bytes_received;
-	__u64 bytes_acked;
-	__bpf_md_ptr(struct bpf_sock *, sk);
-};
-
-/* Definitions for bpf_sock_ops_cb_flags */
-#define BPF_SOCK_OPS_RTO_CB_FLAG	(1<<0)
-#define BPF_SOCK_OPS_RETRANS_CB_FLAG	(1<<1)
-#define BPF_SOCK_OPS_STATE_CB_FLAG	(1<<2)
-#define BPF_SOCK_OPS_RTT_CB_FLAG	(1<<3)
-#define BPF_SOCK_OPS_ALL_CB_FLAGS       0xF		/* Mask of all currently
-							 * supported cb flags
-							 */
-
-/* List of known BPF sock_ops operators.
- * New entries can only be added at the end
- */
-enum {
-	BPF_SOCK_OPS_VOID,
-	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
-					 * -1 if default value should be used
-					 */
-	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
-					 * window (in packets) or -1 if default
-					 * value should be used
-					 */
-	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
-					 * active connection is initialized
-					 */
-	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
-						 * active connection is
-						 * established
-						 */
-	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
-						 * passive connection is
-						 * established
-						 */
-	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
-					 * needs ECN
-					 */
-	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
-					 * based on the path and may be
-					 * dependent on the congestion control
-					 * algorithm. In general it indicates
-					 * a congestion threshold. RTTs above
-					 * this indicate congestion
-					 */
-	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
-					 * Arg1: value of icsk_retransmits
-					 * Arg2: value of icsk_rto
-					 * Arg3: whether RTO has expired
-					 */
-	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
-					 * Arg1: sequence number of 1st byte
-					 * Arg2: # segments
-					 * Arg3: return value of
-					 *       tcp_transmit_skb (0 => success)
-					 */
-	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
-					 * Arg1: old_state
-					 * Arg2: new_state
-					 */
-	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
-					 * socket transition to LISTEN state.
-					 */
-	BPF_SOCK_OPS_RTT_CB,		/* Called on every RTT.
-					 */
-};
-
-/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
- * changes between the TCP and BPF versions. Ideally this should never happen.
- * If it does, we need to add code to convert them before calling
- * the BPF sock_ops function.
- */
-enum {
-	BPF_TCP_ESTABLISHED = 1,
-	BPF_TCP_SYN_SENT,
-	BPF_TCP_SYN_RECV,
-	BPF_TCP_FIN_WAIT1,
-	BPF_TCP_FIN_WAIT2,
-	BPF_TCP_TIME_WAIT,
-	BPF_TCP_CLOSE,
-	BPF_TCP_CLOSE_WAIT,
-	BPF_TCP_LAST_ACK,
-	BPF_TCP_LISTEN,
-	BPF_TCP_CLOSING,	/* Now a valid state */
-	BPF_TCP_NEW_SYN_RECV,
-
-	BPF_TCP_MAX_STATES	/* Leave at the end! */
-};
-
-#define TCP_BPF_IW		1001	/* Set TCP initial congestion window */
-#define TCP_BPF_SNDCWND_CLAMP	1002	/* Set sndcwnd_clamp */
-
-struct bpf_perf_event_value {
-	__u64 counter;
-	__u64 enabled;
-	__u64 running;
-};
-
-#define BPF_DEVCG_ACC_MKNOD	(1ULL << 0)
-#define BPF_DEVCG_ACC_READ	(1ULL << 1)
-#define BPF_DEVCG_ACC_WRITE	(1ULL << 2)
-
-#define BPF_DEVCG_DEV_BLOCK	(1ULL << 0)
-#define BPF_DEVCG_DEV_CHAR	(1ULL << 1)
-
-struct bpf_cgroup_dev_ctx {
-	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
-	__u32 access_type;
-	__u32 major;
-	__u32 minor;
-};
-
-struct bpf_raw_tracepoint_args {
-	__u64 args[0];
-};
-
-/* DIRECT:  Skip the FIB rules and go to FIB table associated with device
- * OUTPUT:  Do lookup from egress perspective; default is ingress
- */
-#define BPF_FIB_LOOKUP_DIRECT  (1U << 0)
-#define BPF_FIB_LOOKUP_OUTPUT  (1U << 1)
-
-enum {
-	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
-	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
-	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
-	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
-	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
-	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
-	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
-	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
-	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
-};
-
-struct bpf_fib_lookup {
-	/* input:  network family for lookup (AF_INET, AF_INET6)
-	 * output: network family of egress nexthop
-	 */
-	__u8	family;
-
-	/* set if lookup is to consider L4 data - e.g., FIB rules */
-	__u8	l4_protocol;
-	__be16	sport;
-	__be16	dport;
-
-	/* total length of packet from network header - used for MTU check */
-	__u16	tot_len;
-
-	/* input: L3 device index for lookup
-	 * output: device index from FIB lookup
-	 */
-	__u32	ifindex;
-
-	union {
-		/* inputs to lookup */
-		__u8	tos;		/* AF_INET  */
-		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
-
-		/* output: metric of fib result (IPv4/IPv6 only) */
-		__u32	rt_metric;
-	};
-
-	union {
-		__be32		ipv4_src;
-		__u32		ipv6_src[4];  /* in6_addr; network order */
-	};
-
-	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
-	 * network header. output: bpf_fib_lookup sets to gateway address
-	 * if FIB lookup returns gateway route
-	 */
-	union {
-		__be32		ipv4_dst;
-		__u32		ipv6_dst[4];  /* in6_addr; network order */
-	};
-
-	/* output */
-	__be16	h_vlan_proto;
-	__be16	h_vlan_TCI;
-	__u8	smac[6];     /* ETH_ALEN */
-	__u8	dmac[6];     /* ETH_ALEN */
-};
-
-enum bpf_task_fd_type {
-	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
-	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
-	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
-	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
-	BPF_FD_TYPE_UPROBE,		/* filename + offset */
-	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
-};
-
-#define BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG		(1U << 0)
-#define BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL		(1U << 1)
-#define BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP		(1U << 2)
-
-struct bpf_flow_keys {
-	__u16	nhoff;
-	__u16	thoff;
-	__u16	addr_proto;			/* ETH_P_* of valid addrs */
-	__u8	is_frag;
-	__u8	is_first_frag;
-	__u8	is_encap;
-	__u8	ip_proto;
-	__be16	n_proto;
-	__be16	sport;
-	__be16	dport;
-	union {
-		struct {
-			__be32	ipv4_src;
-			__be32	ipv4_dst;
-		};
-		struct {
-			__u32	ipv6_src[4];	/* in6_addr; network order */
-			__u32	ipv6_dst[4];	/* in6_addr; network order */
-		};
-	};
-	__u32	flags;
-	__be32	flow_label;
-};
-
-struct bpf_func_info {
-	__u32	insn_off;
-	__u32	type_id;
-};
-
-#define BPF_LINE_INFO_LINE_NUM(line_col)	((line_col) >> 10)
-#define BPF_LINE_INFO_LINE_COL(line_col)	((line_col) & 0x3ff)
-
-struct bpf_line_info {
-	__u32	insn_off;
-	__u32	file_name_off;
-	__u32	line_off;
-	__u32	line_col;
-};
-
-struct bpf_spin_lock {
-	__u32	val;
-};
-
-struct bpf_sysctl {
-	__u32	write;		/* Sysctl is being read (= 0) or written (= 1).
-				 * Allows 1,2,4-byte read, but no write.
-				 */
-	__u32	file_pos;	/* Sysctl file position to read from, write to.
-				 * Allows 1,2,4-byte read an 4-byte write.
-				 */
-};
-
-struct bpf_sockopt {
-	__bpf_md_ptr(struct bpf_sock *, sk);
-	__bpf_md_ptr(void *, optval);
-	__bpf_md_ptr(void *, optval_end);
-
-	__s32	level;
-	__s32	optname;
-	__s32	optlen;
-	__s32	retval;
-};
-
-#endif /* __LINUX_BPF_H__ */
diff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h
deleted file mode 100644
index d28dd89..0000000
--- a/include/uapi/linux/btf.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* Copyright (c) 2018 Facebook */
-#ifndef __LINUX_BTF_H__
-#define __LINUX_BTF_H__
-
-#include <linux/types.h>
-
-#define BTF_MAGIC	0xeB9F
-#define BTF_VERSION	1
-
-struct btf_header {
-	__u16	magic;
-	__u8	version;
-	__u8	flags;
-	__u32	hdr_len;
-
-	/* All offsets are in bytes relative to the end of this header */
-	__u32	type_off;	/* offset of type section	*/
-	__u32	type_len;	/* length of type section	*/
-	__u32	str_off;	/* offset of string section	*/
-	__u32	str_len;	/* length of string section	*/
-};
-
-/* Max # of type identifier */
-#define BTF_MAX_TYPE	0x000fffff
-/* Max offset into the string section */
-#define BTF_MAX_NAME_OFFSET	0x00ffffff
-/* Max # of struct/union/enum members or func args */
-#define BTF_MAX_VLEN	0xffff
-
-struct btf_type {
-	__u32 name_off;
-	/* "info" bits arrangement
-	 * bits  0-15: vlen (e.g. # of struct's members)
-	 * bits 16-23: unused
-	 * bits 24-27: kind (e.g. int, ptr, array...etc)
-	 * bits 28-30: unused
-	 * bit     31: kind_flag, currently used by
-	 *             struct, union and fwd
-	 */
-	__u32 info;
-	/* "size" is used by INT, ENUM, STRUCT, UNION and DATASEC.
-	 * "size" tells the size of the type it is describing.
-	 *
-	 * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
-	 * FUNC, FUNC_PROTO and VAR.
-	 * "type" is a type_id referring to another type.
-	 */
-	union {
-		__u32 size;
-		__u32 type;
-	};
-};
-
-#define BTF_INFO_KIND(info)	(((info) >> 24) & 0x0f)
-#define BTF_INFO_VLEN(info)	((info) & 0xffff)
-#define BTF_INFO_KFLAG(info)	((info) >> 31)
-
-#define BTF_KIND_UNKN		0	/* Unknown	*/
-#define BTF_KIND_INT		1	/* Integer	*/
-#define BTF_KIND_PTR		2	/* Pointer	*/
-#define BTF_KIND_ARRAY		3	/* Array	*/
-#define BTF_KIND_STRUCT		4	/* Struct	*/
-#define BTF_KIND_UNION		5	/* Union	*/
-#define BTF_KIND_ENUM		6	/* Enumeration	*/
-#define BTF_KIND_FWD		7	/* Forward	*/
-#define BTF_KIND_TYPEDEF	8	/* Typedef	*/
-#define BTF_KIND_VOLATILE	9	/* Volatile	*/
-#define BTF_KIND_CONST		10	/* Const	*/
-#define BTF_KIND_RESTRICT	11	/* Restrict	*/
-#define BTF_KIND_FUNC		12	/* Function	*/
-#define BTF_KIND_FUNC_PROTO	13	/* Function Proto	*/
-#define BTF_KIND_VAR		14	/* Variable	*/
-#define BTF_KIND_DATASEC	15	/* Section	*/
-#define BTF_KIND_MAX		BTF_KIND_DATASEC
-#define NR_BTF_KINDS		(BTF_KIND_MAX + 1)
-
-/* For some specific BTF_KIND, "struct btf_type" is immediately
- * followed by extra data.
- */
-
-/* BTF_KIND_INT is followed by a u32 and the following
- * is the 32 bits arrangement:
- */
-#define BTF_INT_ENCODING(VAL)	(((VAL) & 0x0f000000) >> 24)
-#define BTF_INT_OFFSET(VAL)	(((VAL) & 0x00ff0000) >> 16)
-#define BTF_INT_BITS(VAL)	((VAL)  & 0x000000ff)
-
-/* Attributes stored in the BTF_INT_ENCODING */
-#define BTF_INT_SIGNED	(1 << 0)
-#define BTF_INT_CHAR	(1 << 1)
-#define BTF_INT_BOOL	(1 << 2)
-
-/* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
- * The exact number of btf_enum is stored in the vlen (of the
- * info in "struct btf_type").
- */
-struct btf_enum {
-	__u32	name_off;
-	__s32	val;
-};
-
-/* BTF_KIND_ARRAY is followed by one "struct btf_array" */
-struct btf_array {
-	__u32	type;
-	__u32	index_type;
-	__u32	nelems;
-};
-
-/* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
- * by multiple "struct btf_member".  The exact number
- * of btf_member is stored in the vlen (of the info in
- * "struct btf_type").
- */
-struct btf_member {
-	__u32	name_off;
-	__u32	type;
-	/* If the type info kind_flag is set, the btf_member offset
-	 * contains both member bitfield size and bit offset. The
-	 * bitfield size is set for bitfield members. If the type
-	 * info kind_flag is not set, the offset contains only bit
-	 * offset.
-	 */
-	__u32	offset;
-};
-
-/* If the struct/union type info kind_flag is set, the
- * following two macros are used to access bitfield_size
- * and bit_offset from btf_member.offset.
- */
-#define BTF_MEMBER_BITFIELD_SIZE(val)	((val) >> 24)
-#define BTF_MEMBER_BIT_OFFSET(val)	((val) & 0xffffff)
-
-/* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param".
- * The exact number of btf_param is stored in the vlen (of the
- * info in "struct btf_type").
- */
-struct btf_param {
-	__u32	name_off;
-	__u32	type;
-};
-
-enum {
-	BTF_VAR_STATIC = 0,
-	BTF_VAR_GLOBAL_ALLOCATED,
-};
-
-/* BTF_KIND_VAR is followed by a single "struct btf_var" to describe
- * additional information related to the variable such as its linkage.
- */
-struct btf_var {
-	__u32	linkage;
-};
-
-/* BTF_KIND_DATASEC is followed by multiple "struct btf_var_secinfo"
- * to describe all BTF_KIND_VAR types it contains along with it's
- * in-section offset as well as size.
- */
-struct btf_var_secinfo {
-	__u32	type;
-	__u32	offset;
-	__u32	size;
-};
-
-#endif /* __LINUX_BTF_H__ */
diff --git a/include/uapi/linux/can/vxcan.h b/include/uapi/linux/can/vxcan.h
deleted file mode 100644
index 3e3d2eb..0000000
--- a/include/uapi/linux/can/vxcan.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
-#ifndef _CAN_VXCAN_H
-#define _CAN_VXCAN_H
-
-enum {
-	VXCAN_INFO_UNSPEC,
-	VXCAN_INFO_PEER,
-
-	__VXCAN_INFO_MAX
-#define VXCAN_INFO_MAX	(__VXCAN_INFO_MAX - 1)
-};
-
-#endif
diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h
deleted file mode 100644
index fd885c7..0000000
--- a/include/uapi/linux/const.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* const.h: Macros for dealing with constants.  */
-
-#ifndef _LINUX_CONST_H
-#define _LINUX_CONST_H
-
-/* Some constant macros are used in both assembler and
- * C code.  Therefore we cannot annotate them always with
- * 'UL' and other type specifiers unilaterally.  We
- * use the following macros to deal with this.
- *
- * Similarly, _AT() will cast an expression with a type in C, but
- * leave it unchanged in asm.
- */
-
-#ifdef __ASSEMBLY__
-#define _AC(X,Y)	X
-#define _AT(T,X)	X
-#else
-#define __AC(X,Y)	(X##Y)
-#define _AC(X,Y)	__AC(X,Y)
-#define _AT(T,X)	((T)(X))
-#endif
-
-#define _UL(x)		(_AC(x, UL))
-#define _ULL(x)		(_AC(x, ULL))
-
-#define _BITUL(x)	(_UL(1) << (x))
-#define _BITULL(x)	(_ULL(1) << (x))
-
-#endif /* _LINUX_CONST_H */
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
deleted file mode 100644
index 84c0caf..0000000
--- a/include/uapi/linux/devlink.h
+++ /dev/null
@@ -1,471 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * include/uapi/linux/devlink.h - Network physical device Netlink interface
- * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
- * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _LINUX_DEVLINK_H_
-#define _LINUX_DEVLINK_H_
-
-#define DEVLINK_GENL_NAME "devlink"
-#define DEVLINK_GENL_VERSION 0x1
-#define DEVLINK_GENL_MCGRP_CONFIG_NAME "config"
-
-enum devlink_command {
-	/* don't change the order or add anything between, this is ABI! */
-	DEVLINK_CMD_UNSPEC,
-
-	DEVLINK_CMD_GET,		/* can dump */
-	DEVLINK_CMD_SET,
-	DEVLINK_CMD_NEW,
-	DEVLINK_CMD_DEL,
-
-	DEVLINK_CMD_PORT_GET,		/* can dump */
-	DEVLINK_CMD_PORT_SET,
-	DEVLINK_CMD_PORT_NEW,
-	DEVLINK_CMD_PORT_DEL,
-
-	DEVLINK_CMD_PORT_SPLIT,
-	DEVLINK_CMD_PORT_UNSPLIT,
-
-	DEVLINK_CMD_SB_GET,		/* can dump */
-	DEVLINK_CMD_SB_SET,
-	DEVLINK_CMD_SB_NEW,
-	DEVLINK_CMD_SB_DEL,
-
-	DEVLINK_CMD_SB_POOL_GET,	/* can dump */
-	DEVLINK_CMD_SB_POOL_SET,
-	DEVLINK_CMD_SB_POOL_NEW,
-	DEVLINK_CMD_SB_POOL_DEL,
-
-	DEVLINK_CMD_SB_PORT_POOL_GET,	/* can dump */
-	DEVLINK_CMD_SB_PORT_POOL_SET,
-	DEVLINK_CMD_SB_PORT_POOL_NEW,
-	DEVLINK_CMD_SB_PORT_POOL_DEL,
-
-	DEVLINK_CMD_SB_TC_POOL_BIND_GET,	/* can dump */
-	DEVLINK_CMD_SB_TC_POOL_BIND_SET,
-	DEVLINK_CMD_SB_TC_POOL_BIND_NEW,
-	DEVLINK_CMD_SB_TC_POOL_BIND_DEL,
-
-	/* Shared buffer occupancy monitoring commands */
-	DEVLINK_CMD_SB_OCC_SNAPSHOT,
-	DEVLINK_CMD_SB_OCC_MAX_CLEAR,
-
-	DEVLINK_CMD_ESWITCH_GET,
-#define DEVLINK_CMD_ESWITCH_MODE_GET /* obsolete, never use this! */ \
-	DEVLINK_CMD_ESWITCH_GET
-
-	DEVLINK_CMD_ESWITCH_SET,
-#define DEVLINK_CMD_ESWITCH_MODE_SET /* obsolete, never use this! */ \
-	DEVLINK_CMD_ESWITCH_SET
-
-	DEVLINK_CMD_DPIPE_TABLE_GET,
-	DEVLINK_CMD_DPIPE_ENTRIES_GET,
-	DEVLINK_CMD_DPIPE_HEADERS_GET,
-	DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
-	DEVLINK_CMD_RESOURCE_SET,
-	DEVLINK_CMD_RESOURCE_DUMP,
-
-	/* Hot driver reload, makes configuration changes take place. The
-	 * devlink instance is not released during the process.
-	 */
-	DEVLINK_CMD_RELOAD,
-
-	DEVLINK_CMD_PARAM_GET,		/* can dump */
-	DEVLINK_CMD_PARAM_SET,
-	DEVLINK_CMD_PARAM_NEW,
-	DEVLINK_CMD_PARAM_DEL,
-
-	DEVLINK_CMD_REGION_GET,
-	DEVLINK_CMD_REGION_SET,
-	DEVLINK_CMD_REGION_NEW,
-	DEVLINK_CMD_REGION_DEL,
-	DEVLINK_CMD_REGION_READ,
-
-	DEVLINK_CMD_PORT_PARAM_GET,	/* can dump */
-	DEVLINK_CMD_PORT_PARAM_SET,
-	DEVLINK_CMD_PORT_PARAM_NEW,
-	DEVLINK_CMD_PORT_PARAM_DEL,
-
-	DEVLINK_CMD_INFO_GET,		/* can dump */
-
-	DEVLINK_CMD_HEALTH_REPORTER_GET,
-	DEVLINK_CMD_HEALTH_REPORTER_SET,
-	DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
-	DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE,
-	DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
-	DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
-
-	DEVLINK_CMD_FLASH_UPDATE,
-	DEVLINK_CMD_FLASH_UPDATE_END,		/* notification only */
-	DEVLINK_CMD_FLASH_UPDATE_STATUS,	/* notification only */
-
-	DEVLINK_CMD_TRAP_GET,		/* can dump */
-	DEVLINK_CMD_TRAP_SET,
-	DEVLINK_CMD_TRAP_NEW,
-	DEVLINK_CMD_TRAP_DEL,
-
-	DEVLINK_CMD_TRAP_GROUP_GET,	/* can dump */
-	DEVLINK_CMD_TRAP_GROUP_SET,
-	DEVLINK_CMD_TRAP_GROUP_NEW,
-	DEVLINK_CMD_TRAP_GROUP_DEL,
-
-	/* add new commands above here */
-	__DEVLINK_CMD_MAX,
-	DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
-};
-
-enum devlink_port_type {
-	DEVLINK_PORT_TYPE_NOTSET,
-	DEVLINK_PORT_TYPE_AUTO,
-	DEVLINK_PORT_TYPE_ETH,
-	DEVLINK_PORT_TYPE_IB,
-};
-
-enum devlink_sb_pool_type {
-	DEVLINK_SB_POOL_TYPE_INGRESS,
-	DEVLINK_SB_POOL_TYPE_EGRESS,
-};
-
-/* static threshold - limiting the maximum number of bytes.
- * dynamic threshold - limiting the maximum number of bytes
- *   based on the currently available free space in the shared buffer pool.
- *   In this mode, the maximum quota is calculated based
- *   on the following formula:
- *     max_quota = alpha / (1 + alpha) * Free_Buffer
- *   While Free_Buffer is the amount of none-occupied buffer associated to
- *   the relevant pool.
- *   The value range which can be passed is 0-20 and serves
- *   for computation of alpha by following formula:
- *     alpha = 2 ^ (passed_value - 10)
- */
-
-enum devlink_sb_threshold_type {
-	DEVLINK_SB_THRESHOLD_TYPE_STATIC,
-	DEVLINK_SB_THRESHOLD_TYPE_DYNAMIC,
-};
-
-#define DEVLINK_SB_THRESHOLD_TO_ALPHA_MAX 20
-
-enum devlink_eswitch_mode {
-	DEVLINK_ESWITCH_MODE_LEGACY,
-	DEVLINK_ESWITCH_MODE_SWITCHDEV,
-};
-
-enum devlink_eswitch_inline_mode {
-	DEVLINK_ESWITCH_INLINE_MODE_NONE,
-	DEVLINK_ESWITCH_INLINE_MODE_LINK,
-	DEVLINK_ESWITCH_INLINE_MODE_NETWORK,
-	DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT,
-};
-
-enum devlink_eswitch_encap_mode {
-	DEVLINK_ESWITCH_ENCAP_MODE_NONE,
-	DEVLINK_ESWITCH_ENCAP_MODE_BASIC,
-};
-
-enum devlink_port_flavour {
-	DEVLINK_PORT_FLAVOUR_PHYSICAL, /* Any kind of a port physically
-					* facing the user.
-					*/
-	DEVLINK_PORT_FLAVOUR_CPU, /* CPU port */
-	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
-				   * interconnect port.
-				   */
-	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
-				      * the PCI PF. It is an internal
-				      * port that faces the PCI PF.
-				      */
-	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
-				      * for the PCI VF. It is an internal
-				      * port that faces the PCI VF.
-				      */
-};
-
-enum devlink_param_cmode {
-	DEVLINK_PARAM_CMODE_RUNTIME,
-	DEVLINK_PARAM_CMODE_DRIVERINIT,
-	DEVLINK_PARAM_CMODE_PERMANENT,
-
-	/* Add new configuration modes above */
-	__DEVLINK_PARAM_CMODE_MAX,
-	DEVLINK_PARAM_CMODE_MAX = __DEVLINK_PARAM_CMODE_MAX - 1
-};
-
-enum devlink_param_fw_load_policy_value {
-	DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_DRIVER,
-	DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_FLASH,
-	DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_DISK,
-	DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_UNKNOWN,
-};
-
-enum devlink_param_reset_dev_on_drv_probe_value {
-	DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_UNKNOWN,
-	DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_ALWAYS,
-	DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_NEVER,
-	DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_DISK,
-};
-
-enum {
-	DEVLINK_ATTR_STATS_RX_PACKETS,		/* u64 */
-	DEVLINK_ATTR_STATS_RX_BYTES,		/* u64 */
-
-	__DEVLINK_ATTR_STATS_MAX,
-	DEVLINK_ATTR_STATS_MAX = __DEVLINK_ATTR_STATS_MAX - 1
-};
-
-/**
- * enum devlink_trap_action - Packet trap action.
- * @DEVLINK_TRAP_ACTION_DROP: Packet is dropped by the device and a copy is not
- *                            sent to the CPU.
- * @DEVLINK_TRAP_ACTION_TRAP: The sole copy of the packet is sent to the CPU.
- */
-enum devlink_trap_action {
-	DEVLINK_TRAP_ACTION_DROP,
-	DEVLINK_TRAP_ACTION_TRAP,
-};
-
-/**
- * enum devlink_trap_type - Packet trap type.
- * @DEVLINK_TRAP_TYPE_DROP: Trap reason is a drop. Trapped packets are only
- *                          processed by devlink and not injected to the
- *                          kernel's Rx path.
- * @DEVLINK_TRAP_TYPE_EXCEPTION: Trap reason is an exception. Packet was not
- *                               forwarded as intended due to an exception
- *                               (e.g., missing neighbour entry) and trapped to
- *                               control plane for resolution. Trapped packets
- *                               are processed by devlink and injected to
- *                               the kernel's Rx path.
- */
-enum devlink_trap_type {
-	DEVLINK_TRAP_TYPE_DROP,
-	DEVLINK_TRAP_TYPE_EXCEPTION,
-};
-
-enum {
-	/* Trap can report input port as metadata */
-	DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT,
-};
-
-enum devlink_attr {
-	/* don't change the order or add anything between, this is ABI! */
-	DEVLINK_ATTR_UNSPEC,
-
-	/* bus name + dev name together are a handle for devlink entity */
-	DEVLINK_ATTR_BUS_NAME,			/* string */
-	DEVLINK_ATTR_DEV_NAME,			/* string */
-
-	DEVLINK_ATTR_PORT_INDEX,		/* u32 */
-	DEVLINK_ATTR_PORT_TYPE,			/* u16 */
-	DEVLINK_ATTR_PORT_DESIRED_TYPE,		/* u16 */
-	DEVLINK_ATTR_PORT_NETDEV_IFINDEX,	/* u32 */
-	DEVLINK_ATTR_PORT_NETDEV_NAME,		/* string */
-	DEVLINK_ATTR_PORT_IBDEV_NAME,		/* string */
-	DEVLINK_ATTR_PORT_SPLIT_COUNT,		/* u32 */
-	DEVLINK_ATTR_PORT_SPLIT_GROUP,		/* u32 */
-	DEVLINK_ATTR_SB_INDEX,			/* u32 */
-	DEVLINK_ATTR_SB_SIZE,			/* u32 */
-	DEVLINK_ATTR_SB_INGRESS_POOL_COUNT,	/* u16 */
-	DEVLINK_ATTR_SB_EGRESS_POOL_COUNT,	/* u16 */
-	DEVLINK_ATTR_SB_INGRESS_TC_COUNT,	/* u16 */
-	DEVLINK_ATTR_SB_EGRESS_TC_COUNT,	/* u16 */
-	DEVLINK_ATTR_SB_POOL_INDEX,		/* u16 */
-	DEVLINK_ATTR_SB_POOL_TYPE,		/* u8 */
-	DEVLINK_ATTR_SB_POOL_SIZE,		/* u32 */
-	DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE,	/* u8 */
-	DEVLINK_ATTR_SB_THRESHOLD,		/* u32 */
-	DEVLINK_ATTR_SB_TC_INDEX,		/* u16 */
-	DEVLINK_ATTR_SB_OCC_CUR,		/* u32 */
-	DEVLINK_ATTR_SB_OCC_MAX,		/* u32 */
-	DEVLINK_ATTR_ESWITCH_MODE,		/* u16 */
-	DEVLINK_ATTR_ESWITCH_INLINE_MODE,	/* u8 */
-
-	DEVLINK_ATTR_DPIPE_TABLES,		/* nested */
-	DEVLINK_ATTR_DPIPE_TABLE,		/* nested */
-	DEVLINK_ATTR_DPIPE_TABLE_NAME,		/* string */
-	DEVLINK_ATTR_DPIPE_TABLE_SIZE,		/* u64 */
-	DEVLINK_ATTR_DPIPE_TABLE_MATCHES,	/* nested */
-	DEVLINK_ATTR_DPIPE_TABLE_ACTIONS,	/* nested */
-	DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED,	/* u8 */
-
-	DEVLINK_ATTR_DPIPE_ENTRIES,		/* nested */
-	DEVLINK_ATTR_DPIPE_ENTRY,		/* nested */
-	DEVLINK_ATTR_DPIPE_ENTRY_INDEX,		/* u64 */
-	DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES,	/* nested */
-	DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES,	/* nested */
-	DEVLINK_ATTR_DPIPE_ENTRY_COUNTER,	/* u64 */
-
-	DEVLINK_ATTR_DPIPE_MATCH,		/* nested */
-	DEVLINK_ATTR_DPIPE_MATCH_VALUE,		/* nested */
-	DEVLINK_ATTR_DPIPE_MATCH_TYPE,		/* u32 */
-
-	DEVLINK_ATTR_DPIPE_ACTION,		/* nested */
-	DEVLINK_ATTR_DPIPE_ACTION_VALUE,	/* nested */
-	DEVLINK_ATTR_DPIPE_ACTION_TYPE,		/* u32 */
-
-	DEVLINK_ATTR_DPIPE_VALUE,
-	DEVLINK_ATTR_DPIPE_VALUE_MASK,
-	DEVLINK_ATTR_DPIPE_VALUE_MAPPING,	/* u32 */
-
-	DEVLINK_ATTR_DPIPE_HEADERS,		/* nested */
-	DEVLINK_ATTR_DPIPE_HEADER,		/* nested */
-	DEVLINK_ATTR_DPIPE_HEADER_NAME,		/* string */
-	DEVLINK_ATTR_DPIPE_HEADER_ID,		/* u32 */
-	DEVLINK_ATTR_DPIPE_HEADER_FIELDS,	/* nested */
-	DEVLINK_ATTR_DPIPE_HEADER_GLOBAL,	/* u8 */
-	DEVLINK_ATTR_DPIPE_HEADER_INDEX,	/* u32 */
-
-	DEVLINK_ATTR_DPIPE_FIELD,		/* nested */
-	DEVLINK_ATTR_DPIPE_FIELD_NAME,		/* string */
-	DEVLINK_ATTR_DPIPE_FIELD_ID,		/* u32 */
-	DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH,	/* u32 */
-	DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE,	/* u32 */
-
-	DEVLINK_ATTR_PAD,
-
-	DEVLINK_ATTR_ESWITCH_ENCAP_MODE,	/* u8 */
-	DEVLINK_ATTR_RESOURCE_LIST,		/* nested */
-	DEVLINK_ATTR_RESOURCE,			/* nested */
-	DEVLINK_ATTR_RESOURCE_NAME,		/* string */
-	DEVLINK_ATTR_RESOURCE_ID,		/* u64 */
-	DEVLINK_ATTR_RESOURCE_SIZE,		/* u64 */
-	DEVLINK_ATTR_RESOURCE_SIZE_NEW,		/* u64 */
-	DEVLINK_ATTR_RESOURCE_SIZE_VALID,	/* u8 */
-	DEVLINK_ATTR_RESOURCE_SIZE_MIN,		/* u64 */
-	DEVLINK_ATTR_RESOURCE_SIZE_MAX,		/* u64 */
-	DEVLINK_ATTR_RESOURCE_SIZE_GRAN,        /* u64 */
-	DEVLINK_ATTR_RESOURCE_UNIT,		/* u8 */
-	DEVLINK_ATTR_RESOURCE_OCC,		/* u64 */
-	DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID,	/* u64 */
-	DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS,/* u64 */
-
-	DEVLINK_ATTR_PORT_FLAVOUR,		/* u16 */
-	DEVLINK_ATTR_PORT_NUMBER,		/* u32 */
-	DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,	/* u32 */
-
-	DEVLINK_ATTR_PARAM,			/* nested */
-	DEVLINK_ATTR_PARAM_NAME,		/* string */
-	DEVLINK_ATTR_PARAM_GENERIC,		/* flag */
-	DEVLINK_ATTR_PARAM_TYPE,		/* u8 */
-	DEVLINK_ATTR_PARAM_VALUES_LIST,		/* nested */
-	DEVLINK_ATTR_PARAM_VALUE,		/* nested */
-	DEVLINK_ATTR_PARAM_VALUE_DATA,		/* dynamic */
-	DEVLINK_ATTR_PARAM_VALUE_CMODE,		/* u8 */
-
-	DEVLINK_ATTR_REGION_NAME,               /* string */
-	DEVLINK_ATTR_REGION_SIZE,               /* u64 */
-	DEVLINK_ATTR_REGION_SNAPSHOTS,          /* nested */
-	DEVLINK_ATTR_REGION_SNAPSHOT,           /* nested */
-	DEVLINK_ATTR_REGION_SNAPSHOT_ID,        /* u32 */
-
-	DEVLINK_ATTR_REGION_CHUNKS,             /* nested */
-	DEVLINK_ATTR_REGION_CHUNK,              /* nested */
-	DEVLINK_ATTR_REGION_CHUNK_DATA,         /* binary */
-	DEVLINK_ATTR_REGION_CHUNK_ADDR,         /* u64 */
-	DEVLINK_ATTR_REGION_CHUNK_LEN,          /* u64 */
-
-	DEVLINK_ATTR_INFO_DRIVER_NAME,		/* string */
-	DEVLINK_ATTR_INFO_SERIAL_NUMBER,	/* string */
-	DEVLINK_ATTR_INFO_VERSION_FIXED,	/* nested */
-	DEVLINK_ATTR_INFO_VERSION_RUNNING,	/* nested */
-	DEVLINK_ATTR_INFO_VERSION_STORED,	/* nested */
-	DEVLINK_ATTR_INFO_VERSION_NAME,		/* string */
-	DEVLINK_ATTR_INFO_VERSION_VALUE,	/* string */
-
-	DEVLINK_ATTR_SB_POOL_CELL_SIZE,		/* u32 */
-
-	DEVLINK_ATTR_FMSG,			/* nested */
-	DEVLINK_ATTR_FMSG_OBJ_NEST_START,	/* flag */
-	DEVLINK_ATTR_FMSG_PAIR_NEST_START,	/* flag */
-	DEVLINK_ATTR_FMSG_ARR_NEST_START,	/* flag */
-	DEVLINK_ATTR_FMSG_NEST_END,		/* flag */
-	DEVLINK_ATTR_FMSG_OBJ_NAME,		/* string */
-	DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE,	/* u8 */
-	DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA,	/* dynamic */
-
-	DEVLINK_ATTR_HEALTH_REPORTER,			/* nested */
-	DEVLINK_ATTR_HEALTH_REPORTER_NAME,		/* string */
-	DEVLINK_ATTR_HEALTH_REPORTER_STATE,		/* u8 */
-	DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT,		/* u64 */
-	DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT,	/* u64 */
-	DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS,		/* u64 */
-	DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD,	/* u64 */
-	DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,	/* u8 */
-
-	DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME,	/* string */
-	DEVLINK_ATTR_FLASH_UPDATE_COMPONENT,	/* string */
-	DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG,	/* string */
-	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
-	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
-
-	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
-	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
-
-	DEVLINK_ATTR_STATS,				/* nested */
-
-	DEVLINK_ATTR_TRAP_NAME,				/* string */
-	/* enum devlink_trap_action */
-	DEVLINK_ATTR_TRAP_ACTION,			/* u8 */
-	/* enum devlink_trap_type */
-	DEVLINK_ATTR_TRAP_TYPE,				/* u8 */
-	DEVLINK_ATTR_TRAP_GENERIC,			/* flag */
-	DEVLINK_ATTR_TRAP_METADATA,			/* nested */
-	DEVLINK_ATTR_TRAP_GROUP_NAME,			/* string */
-
-	DEVLINK_ATTR_RELOAD_FAILED,			/* u8 0 or 1 */
-
-	DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS,	/* u64 */
-	/* add new attributes above here, update the policy in devlink.c */
-
-	__DEVLINK_ATTR_MAX,
-	DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1
-};
-
-/* Mapping between internal resource described by the field and system
- * structure
- */
-enum devlink_dpipe_field_mapping_type {
-	DEVLINK_DPIPE_FIELD_MAPPING_TYPE_NONE,
-	DEVLINK_DPIPE_FIELD_MAPPING_TYPE_IFINDEX,
-};
-
-/* Match type - specify the type of the match */
-enum devlink_dpipe_match_type {
-	DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT,
-};
-
-/* Action type - specify the action type */
-enum devlink_dpipe_action_type {
-	DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY,
-};
-
-enum devlink_dpipe_field_ethernet_id {
-	DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC,
-};
-
-enum devlink_dpipe_field_ipv4_id {
-	DEVLINK_DPIPE_FIELD_IPV4_DST_IP,
-};
-
-enum devlink_dpipe_field_ipv6_id {
-	DEVLINK_DPIPE_FIELD_IPV6_DST_IP,
-};
-
-enum devlink_dpipe_header_id {
-	DEVLINK_DPIPE_HEADER_ETHERNET,
-	DEVLINK_DPIPE_HEADER_IPV4,
-	DEVLINK_DPIPE_HEADER_IPV6,
-};
-
-enum devlink_resource_unit {
-	DEVLINK_RESOURCE_UNIT_ENTRY,
-};
-
-#endif /* _LINUX_DEVLINK_H_ */
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
deleted file mode 100644
index f47e853..0000000
--- a/include/uapi/linux/elf-em.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_ELF_EM_H
-#define _LINUX_ELF_EM_H
-
-/* These constants define the various ELF target machines */
-#define EM_NONE		0
-#define EM_M32		1
-#define EM_SPARC	2
-#define EM_386		3
-#define EM_68K		4
-#define EM_88K		5
-#define EM_486		6	/* Perhaps disused */
-#define EM_860		7
-#define EM_MIPS		8	/* MIPS R3000 (officially, big-endian only) */
-				/* Next two are historical and binaries and
-				   modules of these types will be rejected by
-				   Linux.  */
-#define EM_MIPS_RS3_LE	10	/* MIPS R3000 little-endian */
-#define EM_MIPS_RS4_BE	10	/* MIPS R4000 big-endian */
-
-#define EM_PARISC	15	/* HPPA */
-#define EM_SPARC32PLUS	18	/* Sun's "v8plus" */
-#define EM_PPC		20	/* PowerPC */
-#define EM_PPC64	21	 /* PowerPC64 */
-#define EM_SPU		23	/* Cell BE SPU */
-#define EM_ARM		40	/* ARM 32 bit */
-#define EM_SH		42	/* SuperH */
-#define EM_SPARCV9	43	/* SPARC v9 64-bit */
-#define EM_H8_300	46	/* Renesas H8/300 */
-#define EM_IA_64	50	/* HP/Intel IA-64 */
-#define EM_X86_64	62	/* AMD x86-64 */
-#define EM_S390		22	/* IBM S/390 */
-#define EM_CRIS		76	/* Axis Communications 32-bit embedded processor */
-#define EM_M32R		88	/* Renesas M32R */
-#define EM_MN10300	89	/* Panasonic/MEI MN10300, AM33 */
-#define EM_OPENRISC     92     /* OpenRISC 32-bit embedded processor */
-#define EM_ARCOMPACT	93	/* ARCompact processor */
-#define EM_XTENSA	94	/* Tensilica Xtensa Architecture */
-#define EM_BLACKFIN     106     /* ADI Blackfin Processor */
-#define EM_UNICORE	110	/* UniCore-32 */
-#define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
-#define EM_TI_C6000	140	/* TI C6X DSPs */
-#define EM_HEXAGON	164	/* QUALCOMM Hexagon */
-#define EM_NDS32	167	/* Andes Technology compact code size
-				   embedded RISC processor family */
-#define EM_AARCH64	183	/* ARM 64 bit */
-#define EM_TILEPRO	188	/* Tilera TILEPro */
-#define EM_MICROBLAZE	189	/* Xilinx MicroBlaze */
-#define EM_TILEGX	191	/* Tilera TILE-Gx */
-#define EM_ARCV2	195	/* ARCv2 Cores */
-#define EM_RISCV	243	/* RISC-V */
-#define EM_BPF		247	/* Linux BPF - in-kernel virtual machine */
-#define EM_CSKY		252	/* C-SKY */
-#define EM_FRV		0x5441	/* Fujitsu FR-V */
-
-/*
- * This is an interim value that we will use until the committee comes
- * up with a final number.
- */
-#define EM_ALPHA	0x9026
-
-/* Bogus old m32r magic number, used by old tools. */
-#define EM_CYGNUS_M32R	0x9041
-/* This is the old interim value for S/390 architecture */
-#define EM_S390_OLD	0xA390
-/* Also Panasonic/MEI MN10300, AM33 */
-#define EM_CYGNUS_MN10300 0xbeef
-
-
-#endif /* _LINUX_ELF_EM_H */
diff --git a/include/uapi/linux/icmpv6.h b/include/uapi/linux/icmpv6.h
deleted file mode 100644
index 1dc7cc6..0000000
--- a/include/uapi/linux/icmpv6.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_ICMPV6_H
-#define _LINUX_ICMPV6_H
-
-#include <linux/types.h>
-#include <asm/byteorder.h>
-
-struct icmp6hdr {
-
-	__u8		icmp6_type;
-	__u8		icmp6_code;
-	__sum16		icmp6_cksum;
-
-
-	union {
-		__be32			un_data32[1];
-		__be16			un_data16[2];
-		__u8			un_data8[4];
-
-		struct icmpv6_echo {
-			__be16		identifier;
-			__be16		sequence;
-		} u_echo;
-
-                struct icmpv6_nd_advt {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-                        __u32		reserved:5,
-                        		override:1,
-                        		solicited:1,
-                        		router:1,
-					reserved2:24;
-#elif defined(__BIG_ENDIAN_BITFIELD)
-                        __u32		router:1,
-					solicited:1,
-                        		override:1,
-                        		reserved:29;
-#else
-#error	"Please fix <asm/byteorder.h>"
-#endif						
-                } u_nd_advt;
-
-                struct icmpv6_nd_ra {
-			__u8		hop_limit;
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-			__u8		reserved:3,
-					router_pref:2,
-					home_agent:1,
-					other:1,
-					managed:1;
-
-#elif defined(__BIG_ENDIAN_BITFIELD)
-			__u8		managed:1,
-					other:1,
-					home_agent:1,
-					router_pref:2,
-					reserved:3;
-#else
-#error	"Please fix <asm/byteorder.h>"
-#endif
-			__be16		rt_lifetime;
-                } u_nd_ra;
-
-	} icmp6_dataun;
-
-#define icmp6_identifier	icmp6_dataun.u_echo.identifier
-#define icmp6_sequence		icmp6_dataun.u_echo.sequence
-#define icmp6_pointer		icmp6_dataun.un_data32[0]
-#define icmp6_mtu		icmp6_dataun.un_data32[0]
-#define icmp6_unused		icmp6_dataun.un_data32[0]
-#define icmp6_maxdelay		icmp6_dataun.un_data16[0]
-#define icmp6_router		icmp6_dataun.u_nd_advt.router
-#define icmp6_solicited		icmp6_dataun.u_nd_advt.solicited
-#define icmp6_override		icmp6_dataun.u_nd_advt.override
-#define icmp6_ndiscreserved	icmp6_dataun.u_nd_advt.reserved
-#define icmp6_hop_limit		icmp6_dataun.u_nd_ra.hop_limit
-#define icmp6_addrconf_managed	icmp6_dataun.u_nd_ra.managed
-#define icmp6_addrconf_other	icmp6_dataun.u_nd_ra.other
-#define icmp6_rt_lifetime	icmp6_dataun.u_nd_ra.rt_lifetime
-#define icmp6_router_pref	icmp6_dataun.u_nd_ra.router_pref
-};
-
-
-#define ICMPV6_ROUTER_PREF_LOW		0x3
-#define ICMPV6_ROUTER_PREF_MEDIUM	0x0
-#define ICMPV6_ROUTER_PREF_HIGH		0x1
-#define ICMPV6_ROUTER_PREF_INVALID	0x2
-
-#define ICMPV6_DEST_UNREACH		1
-#define ICMPV6_PKT_TOOBIG		2
-#define ICMPV6_TIME_EXCEED		3
-#define ICMPV6_PARAMPROB		4
-
-#define ICMPV6_ERRMSG_MAX       127
-
-#define ICMPV6_INFOMSG_MASK		0x80
-
-#define ICMPV6_ECHO_REQUEST		128
-#define ICMPV6_ECHO_REPLY		129
-#define ICMPV6_MGM_QUERY		130
-#define ICMPV6_MGM_REPORT       	131
-#define ICMPV6_MGM_REDUCTION    	132
-
-#define ICMPV6_NI_QUERY			139
-#define ICMPV6_NI_REPLY			140
-
-#define ICMPV6_MLD2_REPORT		143
-
-#define ICMPV6_DHAAD_REQUEST		144
-#define ICMPV6_DHAAD_REPLY		145
-#define ICMPV6_MOBILE_PREFIX_SOL	146
-#define ICMPV6_MOBILE_PREFIX_ADV	147
-
-#define ICMPV6_MRDISC_ADV		151
-
-#define ICMPV6_MSG_MAX          255
-
-/*
- *	Codes for Destination Unreachable
- */
-#define ICMPV6_NOROUTE			0
-#define ICMPV6_ADM_PROHIBITED		1
-#define ICMPV6_NOT_NEIGHBOUR		2
-#define ICMPV6_ADDR_UNREACH		3
-#define ICMPV6_PORT_UNREACH		4
-#define ICMPV6_POLICY_FAIL		5
-#define ICMPV6_REJECT_ROUTE		6
-
-/*
- *	Codes for Time Exceeded
- */
-#define ICMPV6_EXC_HOPLIMIT		0
-#define ICMPV6_EXC_FRAGTIME		1
-
-/*
- *	Codes for Parameter Problem
- */
-#define ICMPV6_HDR_FIELD		0
-#define ICMPV6_UNK_NEXTHDR		1
-#define ICMPV6_UNK_OPTION		2
-
-/*
- *	constants for (set|get)sockopt
- */
-
-#define ICMPV6_FILTER			1
-
-/*
- *	ICMPV6 filter
- */
-
-#define ICMPV6_FILTER_BLOCK		1
-#define ICMPV6_FILTER_PASS		2
-#define ICMPV6_FILTER_BLOCKOTHERS	3
-#define ICMPV6_FILTER_PASSONLY		4
-
-struct icmp6_filter {
-	__u32		data[8];
-};
-
-/*
- *	Definitions for MLDv2
- */
-#define MLD2_MODE_IS_INCLUDE	1
-#define MLD2_MODE_IS_EXCLUDE	2
-#define MLD2_CHANGE_TO_INCLUDE	3
-#define MLD2_CHANGE_TO_EXCLUDE	4
-#define MLD2_ALLOW_NEW_SOURCES	5
-#define MLD2_BLOCK_OLD_SOURCES	6
-
-#define MLD2_ALL_MCR_INIT { { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,0x16 } } }
-
-
-#endif /* _LINUX_ICMPV6_H */
diff --git a/include/uapi/linux/if_alg.h b/include/uapi/linux/if_alg.h
deleted file mode 100644
index bc2bcde..0000000
--- a/include/uapi/linux/if_alg.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * if_alg: User-space algorithm interface
- *
- * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- */
-
-#ifndef _LINUX_IF_ALG_H
-#define _LINUX_IF_ALG_H
-
-#include <linux/types.h>
-
-struct sockaddr_alg {
-	__u16	salg_family;
-	__u8	salg_type[14];
-	__u32	salg_feat;
-	__u32	salg_mask;
-	__u8	salg_name[64];
-};
-
-struct af_alg_iv {
-	__u32	ivlen;
-	__u8	iv[0];
-};
-
-/* Socket options */
-#define ALG_SET_KEY			1
-#define ALG_SET_IV			2
-#define ALG_SET_OP			3
-#define ALG_SET_AEAD_ASSOCLEN		4
-#define ALG_SET_AEAD_AUTHSIZE		5
-
-/* Operations */
-#define ALG_OP_DECRYPT			0
-#define ALG_OP_ENCRYPT			1
-
-#endif	/* _LINUX_IF_ALG_H */
diff --git a/include/uapi/linux/if_bonding.h b/include/uapi/linux/if_bonding.h
deleted file mode 100644
index 790585f..0000000
--- a/include/uapi/linux/if_bonding.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */
-/*
- * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
- *
- *
- * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
- * NCM: Network and Communications Management, Inc.
- *
- * BUT, I'm the one who modified it for ethernet, so:
- * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
- *
- *	This software may be used and distributed according to the terms
- *	of the GNU Public License, incorporated herein by reference.
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>
- *	- Added support for getting slave's speed and duplex via ethtool.
- *	  Needed for 802.3ad and other future modes.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *		Shmulik Hen <shmulik.hen at intel dot com>
- *	- Enable support of modes that need to use the unique mac address of
- *	  each slave.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *		Amir Noam <amir.noam at intel dot com>
- *	- Moved driver's private data types to bonding.h
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>,
- *		Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *		Shmulik Hen <shmulik.hen at intel dot com>
- *	- Added support for IEEE 802.3ad Dynamic link aggregation mode.
- *
- * 2003/05/01 - Amir Noam <amir.noam at intel dot com>
- *	- Added ABI version control to restore compatibility between
- *	  new/old ifenslave and new/old bonding.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *	- Code cleanup and style changes
- *
- * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
- *      - added definitions for various XOR hashing policies
- */
-
-#ifndef _LINUX_IF_BONDING_H
-#define _LINUX_IF_BONDING_H
-
-#include <linux/if.h>
-#include <linux/types.h>
-#include <linux/if_ether.h>
-
-/* userland - kernel ABI version (2003/05/08) */
-#define BOND_ABI_VERSION 2
-
-/*
- * We can remove these ioctl definitions in 2.5.  People should use the
- * SIOC*** versions of them instead
- */
-#define BOND_ENSLAVE_OLD		(SIOCDEVPRIVATE)
-#define BOND_RELEASE_OLD		(SIOCDEVPRIVATE + 1)
-#define BOND_SETHWADDR_OLD		(SIOCDEVPRIVATE + 2)
-#define BOND_SLAVE_INFO_QUERY_OLD	(SIOCDEVPRIVATE + 11)
-#define BOND_INFO_QUERY_OLD		(SIOCDEVPRIVATE + 12)
-#define BOND_CHANGE_ACTIVE_OLD		(SIOCDEVPRIVATE + 13)
-
-#define BOND_CHECK_MII_STATUS	(SIOCGMIIPHY)
-
-#define BOND_MODE_ROUNDROBIN	0
-#define BOND_MODE_ACTIVEBACKUP	1
-#define BOND_MODE_XOR		2
-#define BOND_MODE_BROADCAST	3
-#define BOND_MODE_8023AD        4
-#define BOND_MODE_TLB           5
-#define BOND_MODE_ALB		6 /* TLB + RLB (receive load balancing) */
-
-/* each slave's link has 4 states */
-#define BOND_LINK_UP    0           /* link is up and running */
-#define BOND_LINK_FAIL  1           /* link has just gone down */
-#define BOND_LINK_DOWN  2           /* link has been down for too long time */
-#define BOND_LINK_BACK  3           /* link is going back */
-
-/* each slave has several states */
-#define BOND_STATE_ACTIVE       0   /* link is active */
-#define BOND_STATE_BACKUP       1   /* link is backup */
-
-#define BOND_DEFAULT_MAX_BONDS  1   /* Default maximum number of devices to support */
-
-#define BOND_DEFAULT_TX_QUEUES 16   /* Default number of tx queues per device */
-
-#define BOND_DEFAULT_RESEND_IGMP	1 /* Default number of IGMP membership reports */
-
-/* hashing types */
-#define BOND_XMIT_POLICY_LAYER2		0 /* layer 2 (MAC only), default */
-#define BOND_XMIT_POLICY_LAYER34	1 /* layer 3+4 (IP ^ (TCP || UDP)) */
-#define BOND_XMIT_POLICY_LAYER23	2 /* layer 2+3 (IP ^ MAC) */
-#define BOND_XMIT_POLICY_ENCAP23	3 /* encapsulated layer 2+3 */
-#define BOND_XMIT_POLICY_ENCAP34	4 /* encapsulated layer 3+4 */
-
-typedef struct ifbond {
-	__s32 bond_mode;
-	__s32 num_slaves;
-	__s32 miimon;
-} ifbond;
-
-typedef struct ifslave {
-	__s32 slave_id; /* Used as an IN param to the BOND_SLAVE_INFO_QUERY ioctl */
-	char slave_name[IFNAMSIZ];
-	__s8 link;
-	__s8 state;
-	__u32  link_failure_count;
-} ifslave;
-
-struct ad_info {
-	__u16 aggregator_id;
-	__u16 ports;
-	__u16 actor_key;
-	__u16 partner_key;
-	__u8 partner_system[ETH_ALEN];
-};
-
-/* Embedded inside LINK_XSTATS_TYPE_BOND */
-enum {
-	BOND_XSTATS_UNSPEC,
-	BOND_XSTATS_3AD,
-	__BOND_XSTATS_MAX
-};
-#define BOND_XSTATS_MAX (__BOND_XSTATS_MAX - 1)
-
-/* Embedded inside BOND_XSTATS_3AD */
-enum {
-	BOND_3AD_STAT_LACPDU_RX,
-	BOND_3AD_STAT_LACPDU_TX,
-	BOND_3AD_STAT_LACPDU_UNKNOWN_RX,
-	BOND_3AD_STAT_LACPDU_ILLEGAL_RX,
-	BOND_3AD_STAT_MARKER_RX,
-	BOND_3AD_STAT_MARKER_TX,
-	BOND_3AD_STAT_MARKER_RESP_RX,
-	BOND_3AD_STAT_MARKER_RESP_TX,
-	BOND_3AD_STAT_MARKER_UNKNOWN_RX,
-	BOND_3AD_STAT_PAD,
-	__BOND_3AD_STAT_MAX
-};
-#define BOND_3AD_STAT_MAX (__BOND_3AD_STAT_MAX - 1)
-
-#endif /* _LINUX_IF_BONDING_H */
-
-/*
- * Local variables:
- *  version-control: t
- *  kept-new-versions: 5
- *  c-indent-level: 8
- *  c-basic-offset: 8
- *  tab-width: 8
- * End:
- */
-
diff --git a/include/uapi/linux/if_infiniband.h b/include/uapi/linux/if_infiniband.h
deleted file mode 100644
index 0fc33bf..0000000
--- a/include/uapi/linux/if_infiniband.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
-/*
- * This software is available to you under a choice of one of two
- * licenses.  You may choose to be licensed under the terms of the GNU
- * General Public License (GPL) Version 2, available at
- * <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
- * license, available in the LICENSE.TXT file accompanying this
- * software.  These details are also available at
- * <http://www.openfabrics.org/software_license.htm>.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Copyright (c) 2004 Topspin Communications.  All rights reserved.
- *
- * $Id$
- */
-
-#ifndef _LINUX_IF_INFINIBAND_H
-#define _LINUX_IF_INFINIBAND_H
-
-#define INFINIBAND_ALEN		20	/* Octets in IPoIB HW addr	*/
-
-#endif /* _LINUX_IF_INFINIBAND_H */
diff --git a/include/uapi/linux/if_macsec.h b/include/uapi/linux/if_macsec.h
deleted file mode 100644
index 7743993..0000000
--- a/include/uapi/linux/if_macsec.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * include/uapi/linux/if_macsec.h - MACsec device
- *
- * Copyright (c) 2015 Sabrina Dubroca <sd@queasysnail.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef _MACSEC_H
-#define _MACSEC_H
-
-#include <linux/types.h>
-
-#define MACSEC_GENL_NAME "macsec"
-#define MACSEC_GENL_VERSION 1
-
-#define MACSEC_MAX_KEY_LEN 128
-
-#define MACSEC_KEYID_LEN 16
-
-/* cipher IDs as per IEEE802.1AEbn-2011 */
-#define MACSEC_CIPHER_ID_GCM_AES_128 0x0080C20001000001ULL
-#define MACSEC_CIPHER_ID_GCM_AES_256 0x0080C20001000002ULL
-
-/* deprecated cipher ID for GCM-AES-128 */
-#define MACSEC_DEFAULT_CIPHER_ID     0x0080020001000001ULL
-#define MACSEC_DEFAULT_CIPHER_ALT    MACSEC_CIPHER_ID_GCM_AES_128
-
-#define MACSEC_MIN_ICV_LEN 8
-#define MACSEC_MAX_ICV_LEN 32
-/* upper limit for ICV length as recommended by IEEE802.1AE-2006 */
-#define MACSEC_STD_ICV_LEN 16
-
-enum macsec_attrs {
-	MACSEC_ATTR_UNSPEC,
-	MACSEC_ATTR_IFINDEX,     /* u32, ifindex of the MACsec netdevice */
-	MACSEC_ATTR_RXSC_CONFIG, /* config, nested macsec_rxsc_attrs */
-	MACSEC_ATTR_SA_CONFIG,   /* config, nested macsec_sa_attrs */
-	MACSEC_ATTR_SECY,        /* dump, nested macsec_secy_attrs */
-	MACSEC_ATTR_TXSA_LIST,   /* dump, nested, macsec_sa_attrs for each TXSA */
-	MACSEC_ATTR_RXSC_LIST,   /* dump, nested, macsec_rxsc_attrs for each RXSC */
-	MACSEC_ATTR_TXSC_STATS,  /* dump, nested, macsec_txsc_stats_attr */
-	MACSEC_ATTR_SECY_STATS,  /* dump, nested, macsec_secy_stats_attr */
-	__MACSEC_ATTR_END,
-	NUM_MACSEC_ATTR = __MACSEC_ATTR_END,
-	MACSEC_ATTR_MAX = __MACSEC_ATTR_END - 1,
-};
-
-enum macsec_secy_attrs {
-	MACSEC_SECY_ATTR_UNSPEC,
-	MACSEC_SECY_ATTR_SCI,
-	MACSEC_SECY_ATTR_ENCODING_SA,
-	MACSEC_SECY_ATTR_WINDOW,
-	MACSEC_SECY_ATTR_CIPHER_SUITE,
-	MACSEC_SECY_ATTR_ICV_LEN,
-	MACSEC_SECY_ATTR_PROTECT,
-	MACSEC_SECY_ATTR_REPLAY,
-	MACSEC_SECY_ATTR_OPER,
-	MACSEC_SECY_ATTR_VALIDATE,
-	MACSEC_SECY_ATTR_ENCRYPT,
-	MACSEC_SECY_ATTR_INC_SCI,
-	MACSEC_SECY_ATTR_ES,
-	MACSEC_SECY_ATTR_SCB,
-	MACSEC_SECY_ATTR_PAD,
-	__MACSEC_SECY_ATTR_END,
-	NUM_MACSEC_SECY_ATTR = __MACSEC_SECY_ATTR_END,
-	MACSEC_SECY_ATTR_MAX = __MACSEC_SECY_ATTR_END - 1,
-};
-
-enum macsec_rxsc_attrs {
-	MACSEC_RXSC_ATTR_UNSPEC,
-	MACSEC_RXSC_ATTR_SCI,     /* config/dump, u64 */
-	MACSEC_RXSC_ATTR_ACTIVE,  /* config/dump, u8 0..1 */
-	MACSEC_RXSC_ATTR_SA_LIST, /* dump, nested */
-	MACSEC_RXSC_ATTR_STATS,   /* dump, nested, macsec_rxsc_stats_attr */
-	MACSEC_RXSC_ATTR_PAD,
-	__MACSEC_RXSC_ATTR_END,
-	NUM_MACSEC_RXSC_ATTR = __MACSEC_RXSC_ATTR_END,
-	MACSEC_RXSC_ATTR_MAX = __MACSEC_RXSC_ATTR_END - 1,
-};
-
-enum macsec_sa_attrs {
-	MACSEC_SA_ATTR_UNSPEC,
-	MACSEC_SA_ATTR_AN,     /* config/dump, u8 0..3 */
-	MACSEC_SA_ATTR_ACTIVE, /* config/dump, u8 0..1 */
-	MACSEC_SA_ATTR_PN,     /* config/dump, u32 */
-	MACSEC_SA_ATTR_KEY,    /* config, data */
-	MACSEC_SA_ATTR_KEYID,  /* config/dump, 128-bit */
-	MACSEC_SA_ATTR_STATS,  /* dump, nested, macsec_sa_stats_attr */
-	MACSEC_SA_ATTR_PAD,
-	__MACSEC_SA_ATTR_END,
-	NUM_MACSEC_SA_ATTR = __MACSEC_SA_ATTR_END,
-	MACSEC_SA_ATTR_MAX = __MACSEC_SA_ATTR_END - 1,
-};
-
-enum macsec_nl_commands {
-	MACSEC_CMD_GET_TXSC,
-	MACSEC_CMD_ADD_RXSC,
-	MACSEC_CMD_DEL_RXSC,
-	MACSEC_CMD_UPD_RXSC,
-	MACSEC_CMD_ADD_TXSA,
-	MACSEC_CMD_DEL_TXSA,
-	MACSEC_CMD_UPD_TXSA,
-	MACSEC_CMD_ADD_RXSA,
-	MACSEC_CMD_DEL_RXSA,
-	MACSEC_CMD_UPD_RXSA,
-};
-
-/* u64 per-RXSC stats */
-enum macsec_rxsc_stats_attr {
-	MACSEC_RXSC_STATS_ATTR_UNSPEC,
-	MACSEC_RXSC_STATS_ATTR_IN_OCTETS_VALIDATED,
-	MACSEC_RXSC_STATS_ATTR_IN_OCTETS_DECRYPTED,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNCHECKED,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_DELAYED,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_OK,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_INVALID,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_LATE,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_VALID,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_USING_SA,
-	MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNUSED_SA,
-	MACSEC_RXSC_STATS_ATTR_PAD,
-	__MACSEC_RXSC_STATS_ATTR_END,
-	NUM_MACSEC_RXSC_STATS_ATTR = __MACSEC_RXSC_STATS_ATTR_END,
-	MACSEC_RXSC_STATS_ATTR_MAX = __MACSEC_RXSC_STATS_ATTR_END - 1,
-};
-
-/* u32 per-{RX,TX}SA stats */
-enum macsec_sa_stats_attr {
-	MACSEC_SA_STATS_ATTR_UNSPEC,
-	MACSEC_SA_STATS_ATTR_IN_PKTS_OK,
-	MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID,
-	MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID,
-	MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA,
-	MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA,
-	MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED,
-	MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED,
-	__MACSEC_SA_STATS_ATTR_END,
-	NUM_MACSEC_SA_STATS_ATTR = __MACSEC_SA_STATS_ATTR_END,
-	MACSEC_SA_STATS_ATTR_MAX = __MACSEC_SA_STATS_ATTR_END - 1,
-};
-
-/* u64 per-TXSC stats */
-enum macsec_txsc_stats_attr {
-	MACSEC_TXSC_STATS_ATTR_UNSPEC,
-	MACSEC_TXSC_STATS_ATTR_OUT_PKTS_PROTECTED,
-	MACSEC_TXSC_STATS_ATTR_OUT_PKTS_ENCRYPTED,
-	MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_PROTECTED,
-	MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_ENCRYPTED,
-	MACSEC_TXSC_STATS_ATTR_PAD,
-	__MACSEC_TXSC_STATS_ATTR_END,
-	NUM_MACSEC_TXSC_STATS_ATTR = __MACSEC_TXSC_STATS_ATTR_END,
-	MACSEC_TXSC_STATS_ATTR_MAX = __MACSEC_TXSC_STATS_ATTR_END - 1,
-};
-
-/* u64 per-SecY stats */
-enum macsec_secy_stats_attr {
-	MACSEC_SECY_STATS_ATTR_UNSPEC,
-	MACSEC_SECY_STATS_ATTR_OUT_PKTS_UNTAGGED,
-	MACSEC_SECY_STATS_ATTR_IN_PKTS_UNTAGGED,
-	MACSEC_SECY_STATS_ATTR_OUT_PKTS_TOO_LONG,
-	MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_TAG,
-	MACSEC_SECY_STATS_ATTR_IN_PKTS_BAD_TAG,
-	MACSEC_SECY_STATS_ATTR_IN_PKTS_UNKNOWN_SCI,
-	MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_SCI,
-	MACSEC_SECY_STATS_ATTR_IN_PKTS_OVERRUN,
-	MACSEC_SECY_STATS_ATTR_PAD,
-	__MACSEC_SECY_STATS_ATTR_END,
-	NUM_MACSEC_SECY_STATS_ATTR = __MACSEC_SECY_STATS_ATTR_END,
-	MACSEC_SECY_STATS_ATTR_MAX = __MACSEC_SECY_STATS_ATTR_END - 1,
-};
-
-#endif /* _MACSEC_H */
diff --git a/include/uapi/linux/if_packet.h b/include/uapi/linux/if_packet.h
deleted file mode 100644
index 3d884d6..0000000
--- a/include/uapi/linux/if_packet.h
+++ /dev/null
@@ -1,304 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_IF_PACKET_H
-#define __LINUX_IF_PACKET_H
-
-#include <linux/types.h>
-
-struct sockaddr_pkt {
-	unsigned short spkt_family;
-	unsigned char spkt_device[14];
-	__be16 spkt_protocol;
-};
-
-struct sockaddr_ll {
-	unsigned short	sll_family;
-	__be16		sll_protocol;
-	int		sll_ifindex;
-	unsigned short	sll_hatype;
-	unsigned char	sll_pkttype;
-	unsigned char	sll_halen;
-	unsigned char	sll_addr[8];
-};
-
-/* Packet types */
-
-#define PACKET_HOST		0		/* To us		*/
-#define PACKET_BROADCAST	1		/* To all		*/
-#define PACKET_MULTICAST	2		/* To group		*/
-#define PACKET_OTHERHOST	3		/* To someone else 	*/
-#define PACKET_OUTGOING		4		/* Outgoing of any type */
-#define PACKET_LOOPBACK		5		/* MC/BRD frame looped back */
-#define PACKET_USER		6		/* To user space	*/
-#define PACKET_KERNEL		7		/* To kernel space	*/
-/* Unused, PACKET_FASTROUTE and PACKET_LOOPBACK are invisible to user space */
-#define PACKET_FASTROUTE	6		/* Fastrouted frame	*/
-
-/* Packet socket options */
-
-#define PACKET_ADD_MEMBERSHIP		1
-#define PACKET_DROP_MEMBERSHIP		2
-#define PACKET_RECV_OUTPUT		3
-/* Value 4 is still used by obsolete turbo-packet. */
-#define PACKET_RX_RING			5
-#define PACKET_STATISTICS		6
-#define PACKET_COPY_THRESH		7
-#define PACKET_AUXDATA			8
-#define PACKET_ORIGDEV			9
-#define PACKET_VERSION			10
-#define PACKET_HDRLEN			11
-#define PACKET_RESERVE			12
-#define PACKET_TX_RING			13
-#define PACKET_LOSS			14
-#define PACKET_VNET_HDR			15
-#define PACKET_TX_TIMESTAMP		16
-#define PACKET_TIMESTAMP		17
-#define PACKET_FANOUT			18
-#define PACKET_TX_HAS_OFF		19
-#define PACKET_QDISC_BYPASS		20
-#define PACKET_ROLLOVER_STATS		21
-#define PACKET_FANOUT_DATA		22
-#define PACKET_IGNORE_OUTGOING		23
-
-#define PACKET_FANOUT_HASH		0
-#define PACKET_FANOUT_LB		1
-#define PACKET_FANOUT_CPU		2
-#define PACKET_FANOUT_ROLLOVER		3
-#define PACKET_FANOUT_RND		4
-#define PACKET_FANOUT_QM		5
-#define PACKET_FANOUT_CBPF		6
-#define PACKET_FANOUT_EBPF		7
-#define PACKET_FANOUT_FLAG_ROLLOVER	0x1000
-#define PACKET_FANOUT_FLAG_UNIQUEID	0x2000
-#define PACKET_FANOUT_FLAG_DEFRAG	0x8000
-
-struct tpacket_stats {
-	unsigned int	tp_packets;
-	unsigned int	tp_drops;
-};
-
-struct tpacket_stats_v3 {
-	unsigned int	tp_packets;
-	unsigned int	tp_drops;
-	unsigned int	tp_freeze_q_cnt;
-};
-
-struct tpacket_rollover_stats {
-	__aligned_u64	tp_all;
-	__aligned_u64	tp_huge;
-	__aligned_u64	tp_failed;
-};
-
-union tpacket_stats_u {
-	struct tpacket_stats stats1;
-	struct tpacket_stats_v3 stats3;
-};
-
-struct tpacket_auxdata {
-	__u32		tp_status;
-	__u32		tp_len;
-	__u32		tp_snaplen;
-	__u16		tp_mac;
-	__u16		tp_net;
-	__u16		tp_vlan_tci;
-	__u16		tp_vlan_tpid;
-};
-
-/* Rx ring - header status */
-#define TP_STATUS_KERNEL		      0
-#define TP_STATUS_USER			(1 << 0)
-#define TP_STATUS_COPY			(1 << 1)
-#define TP_STATUS_LOSING		(1 << 2)
-#define TP_STATUS_CSUMNOTREADY		(1 << 3)
-#define TP_STATUS_VLAN_VALID		(1 << 4) /* auxdata has valid tp_vlan_tci */
-#define TP_STATUS_BLK_TMO		(1 << 5)
-#define TP_STATUS_VLAN_TPID_VALID	(1 << 6) /* auxdata has valid tp_vlan_tpid */
-#define TP_STATUS_CSUM_VALID		(1 << 7)
-
-/* Tx ring - header status */
-#define TP_STATUS_AVAILABLE	      0
-#define TP_STATUS_SEND_REQUEST	(1 << 0)
-#define TP_STATUS_SENDING	(1 << 1)
-#define TP_STATUS_WRONG_FORMAT	(1 << 2)
-
-/* Rx and Tx ring - header status */
-#define TP_STATUS_TS_SOFTWARE		(1 << 29)
-#define TP_STATUS_TS_SYS_HARDWARE	(1 << 30) /* deprecated, never set */
-#define TP_STATUS_TS_RAW_HARDWARE	(1U << 31)
-
-/* Rx ring - feature request bits */
-#define TP_FT_REQ_FILL_RXHASH	0x1
-
-struct tpacket_hdr {
-	unsigned long	tp_status;
-	unsigned int	tp_len;
-	unsigned int	tp_snaplen;
-	unsigned short	tp_mac;
-	unsigned short	tp_net;
-	unsigned int	tp_sec;
-	unsigned int	tp_usec;
-};
-
-#define TPACKET_ALIGNMENT	16
-#define TPACKET_ALIGN(x)	(((x)+TPACKET_ALIGNMENT-1)&~(TPACKET_ALIGNMENT-1))
-#define TPACKET_HDRLEN		(TPACKET_ALIGN(sizeof(struct tpacket_hdr)) + sizeof(struct sockaddr_ll))
-
-struct tpacket2_hdr {
-	__u32		tp_status;
-	__u32		tp_len;
-	__u32		tp_snaplen;
-	__u16		tp_mac;
-	__u16		tp_net;
-	__u32		tp_sec;
-	__u32		tp_nsec;
-	__u16		tp_vlan_tci;
-	__u16		tp_vlan_tpid;
-	__u8		tp_padding[4];
-};
-
-struct tpacket_hdr_variant1 {
-	__u32	tp_rxhash;
-	__u32	tp_vlan_tci;
-	__u16	tp_vlan_tpid;
-	__u16	tp_padding;
-};
-
-struct tpacket3_hdr {
-	__u32		tp_next_offset;
-	__u32		tp_sec;
-	__u32		tp_nsec;
-	__u32		tp_snaplen;
-	__u32		tp_len;
-	__u32		tp_status;
-	__u16		tp_mac;
-	__u16		tp_net;
-	/* pkt_hdr variants */
-	union {
-		struct tpacket_hdr_variant1 hv1;
-	};
-	__u8		tp_padding[8];
-};
-
-struct tpacket_bd_ts {
-	unsigned int ts_sec;
-	union {
-		unsigned int ts_usec;
-		unsigned int ts_nsec;
-	};
-};
-
-struct tpacket_hdr_v1 {
-	__u32	block_status;
-	__u32	num_pkts;
-	__u32	offset_to_first_pkt;
-
-	/* Number of valid bytes (including padding)
-	 * blk_len <= tp_block_size
-	 */
-	__u32	blk_len;
-
-	/*
-	 * Quite a few uses of sequence number:
-	 * 1. Make sure cache flush etc worked.
-	 *    Well, one can argue - why not use the increasing ts below?
-	 *    But look at 2. below first.
-	 * 2. When you pass around blocks to other user space decoders,
-	 *    you can see which blk[s] is[are] outstanding etc.
-	 * 3. Validate kernel code.
-	 */
-	__aligned_u64	seq_num;
-
-	/*
-	 * ts_last_pkt:
-	 *
-	 * Case 1.	Block has 'N'(N >=1) packets and TMO'd(timed out)
-	 *		ts_last_pkt == 'time-stamp of last packet' and NOT the
-	 *		time when the timer fired and the block was closed.
-	 *		By providing the ts of the last packet we can absolutely
-	 *		guarantee that time-stamp wise, the first packet in the
-	 *		next block will never precede the last packet of the
-	 *		previous block.
-	 * Case 2.	Block has zero packets and TMO'd
-	 *		ts_last_pkt = time when the timer fired and the block
-	 *		was closed.
-	 * Case 3.	Block has 'N' packets and NO TMO.
-	 *		ts_last_pkt = time-stamp of the last pkt in the block.
-	 *
-	 * ts_first_pkt:
-	 *		Is always the time-stamp when the block was opened.
-	 *		Case a)	ZERO packets
-	 *			No packets to deal with but atleast you know the
-	 *			time-interval of this block.
-	 *		Case b) Non-zero packets
-	 *			Use the ts of the first packet in the block.
-	 *
-	 */
-	struct tpacket_bd_ts	ts_first_pkt, ts_last_pkt;
-};
-
-union tpacket_bd_header_u {
-	struct tpacket_hdr_v1 bh1;
-};
-
-struct tpacket_block_desc {
-	__u32 version;
-	__u32 offset_to_priv;
-	union tpacket_bd_header_u hdr;
-};
-
-#define TPACKET2_HDRLEN		(TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll))
-#define TPACKET3_HDRLEN		(TPACKET_ALIGN(sizeof(struct tpacket3_hdr)) + sizeof(struct sockaddr_ll))
-
-enum tpacket_versions {
-	TPACKET_V1,
-	TPACKET_V2,
-	TPACKET_V3
-};
-
-/*
-   Frame structure:
-
-   - Start. Frame must be aligned to TPACKET_ALIGNMENT=16
-   - struct tpacket_hdr
-   - pad to TPACKET_ALIGNMENT=16
-   - struct sockaddr_ll
-   - Gap, chosen so that packet data (Start+tp_net) alignes to TPACKET_ALIGNMENT=16
-   - Start+tp_mac: [ Optional MAC header ]
-   - Start+tp_net: Packet data, aligned to TPACKET_ALIGNMENT=16.
-   - Pad to align to TPACKET_ALIGNMENT=16
- */
-
-struct tpacket_req {
-	unsigned int	tp_block_size;	/* Minimal size of contiguous block */
-	unsigned int	tp_block_nr;	/* Number of blocks */
-	unsigned int	tp_frame_size;	/* Size of frame */
-	unsigned int	tp_frame_nr;	/* Total number of frames */
-};
-
-struct tpacket_req3 {
-	unsigned int	tp_block_size;	/* Minimal size of contiguous block */
-	unsigned int	tp_block_nr;	/* Number of blocks */
-	unsigned int	tp_frame_size;	/* Size of frame */
-	unsigned int	tp_frame_nr;	/* Total number of frames */
-	unsigned int	tp_retire_blk_tov; /* timeout in msecs */
-	unsigned int	tp_sizeof_priv; /* offset to private data area */
-	unsigned int	tp_feature_req_word;
-};
-
-union tpacket_req_u {
-	struct tpacket_req	req;
-	struct tpacket_req3	req3;
-};
-
-struct packet_mreq {
-	int		mr_ifindex;
-	unsigned short	mr_type;
-	unsigned short	mr_alen;
-	unsigned char	mr_address[8];
-};
-
-#define PACKET_MR_MULTICAST	0
-#define PACKET_MR_PROMISC	1
-#define PACKET_MR_ALLMULTI	2
-#define PACKET_MR_UNICAST	3
-
-#endif
diff --git a/include/uapi/linux/ife.h b/include/uapi/linux/ife.h
deleted file mode 100644
index bdd953c..0000000
--- a/include/uapi/linux/ife.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __UAPI_IFE_H
-#define __UAPI_IFE_H
-
-#define IFE_METAHDRLEN 2
-
-enum {
-	IFE_META_SKBMARK = 1,
-	IFE_META_HASHID,
-	IFE_META_PRIO,
-	IFE_META_QMAP,
-	IFE_META_TCINDEX,
-	__IFE_META_MAX
-};
-
-/*Can be overridden at runtime by module option*/
-#define IFE_META_MAX (__IFE_META_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/ila.h b/include/uapi/linux/ila.h
deleted file mode 100644
index 6a6c97c..0000000
--- a/include/uapi/linux/ila.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* ila.h - ILA Interface */
-
-#ifndef _LINUX_ILA_H
-#define _LINUX_ILA_H
-
-/* NETLINK_GENERIC related info */
-#define ILA_GENL_NAME		"ila"
-#define ILA_GENL_VERSION	0x1
-
-enum {
-	ILA_ATTR_UNSPEC,
-	ILA_ATTR_LOCATOR,			/* u64 */
-	ILA_ATTR_IDENTIFIER,			/* u64 */
-	ILA_ATTR_LOCATOR_MATCH,			/* u64 */
-	ILA_ATTR_IFINDEX,			/* s32 */
-	ILA_ATTR_DIR,				/* u32 */
-	ILA_ATTR_PAD,
-	ILA_ATTR_CSUM_MODE,			/* u8 */
-	ILA_ATTR_IDENT_TYPE,			/* u8 */
-	ILA_ATTR_HOOK_TYPE,			/* u8 */
-
-	__ILA_ATTR_MAX,
-};
-
-#define ILA_ATTR_MAX		(__ILA_ATTR_MAX - 1)
-
-enum {
-	ILA_CMD_UNSPEC,
-	ILA_CMD_ADD,
-	ILA_CMD_DEL,
-	ILA_CMD_GET,
-	ILA_CMD_FLUSH,
-
-	__ILA_CMD_MAX,
-};
-
-#define ILA_CMD_MAX	(__ILA_CMD_MAX - 1)
-
-#define ILA_DIR_IN	(1 << 0)
-#define ILA_DIR_OUT	(1 << 1)
-
-enum {
-	ILA_CSUM_ADJUST_TRANSPORT,
-	ILA_CSUM_NEUTRAL_MAP,
-	ILA_CSUM_NO_ACTION,
-	ILA_CSUM_NEUTRAL_MAP_AUTO,
-};
-
-enum {
-	ILA_ATYPE_IID = 0,
-	ILA_ATYPE_LUID,
-	ILA_ATYPE_VIRT_V4,
-	ILA_ATYPE_VIRT_UNI_V6,
-	ILA_ATYPE_VIRT_MULTI_V6,
-	ILA_ATYPE_NONLOCAL_ADDR,
-	ILA_ATYPE_RSVD_1,
-	ILA_ATYPE_RSVD_2,
-
-	ILA_ATYPE_USE_FORMAT = 32, /* Get type from type field in identifier */
-};
-
-enum {
-	ILA_HOOK_ROUTE_OUTPUT,
-	ILA_HOOK_ROUTE_INPUT,
-};
-
-#endif /* _LINUX_ILA_H */
diff --git a/include/uapi/linux/in_route.h b/include/uapi/linux/in_route.h
deleted file mode 100644
index 0cc2c23..0000000
--- a/include/uapi/linux/in_route.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_IN_ROUTE_H
-#define _LINUX_IN_ROUTE_H
-
-/* IPv4 routing cache flags */
-
-#define RTCF_DEAD	RTNH_F_DEAD
-#define RTCF_ONLINK	RTNH_F_ONLINK
-
-/* Obsolete flag. About to be deleted */
-#define RTCF_NOPMTUDISC RTM_F_NOPMTUDISC
-
-#define RTCF_NOTIFY	0x00010000
-#define RTCF_DIRECTDST	0x00020000 /* unused */
-#define RTCF_REDIRECTED	0x00040000
-#define RTCF_TPROXY	0x00080000 /* unused */
-
-#define RTCF_FAST	0x00200000 /* unused */
-#define RTCF_MASQ	0x00400000 /* unused */
-#define RTCF_SNAT	0x00800000 /* unused */
-#define RTCF_DOREDIRECT 0x01000000
-#define RTCF_DIRECTSRC	0x04000000
-#define RTCF_DNAT	0x08000000
-#define RTCF_BROADCAST	0x10000000
-#define RTCF_MULTICAST	0x20000000
-#define RTCF_REJECT	0x40000000 /* unused */
-#define RTCF_LOCAL	0x80000000
-
-#define RTCF_NAT	(RTCF_DNAT|RTCF_SNAT)
-
-#define RT_TOS(tos)	((tos)&IPTOS_TOS_MASK)
-
-#endif /* _LINUX_IN_ROUTE_H */
diff --git a/include/uapi/linux/ip.h b/include/uapi/linux/ip.h
deleted file mode 100644
index f4ecd2f..0000000
--- a/include/uapi/linux/ip.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * INET		An implementation of the TCP/IP protocol suite for the LINUX
- *		operating system.  INET is implemented using the  BSD Socket
- *		interface as the means of communication with the user level.
- *
- *		Definitions for the IP protocol.
- *
- * Version:	@(#)ip.h	1.0.2	04/28/93
- *
- * Authors:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- */
-#ifndef _LINUX_IP_H
-#define _LINUX_IP_H
-#include <linux/types.h>
-#include <asm/byteorder.h>
-
-#define IPTOS_TOS_MASK		0x1E
-#define IPTOS_TOS(tos)		((tos)&IPTOS_TOS_MASK)
-#define	IPTOS_LOWDELAY		0x10
-#define	IPTOS_THROUGHPUT	0x08
-#define	IPTOS_RELIABILITY	0x04
-#define	IPTOS_MINCOST		0x02
-
-#define IPTOS_PREC_MASK		0xE0
-#define IPTOS_PREC(tos)		((tos)&IPTOS_PREC_MASK)
-#define IPTOS_PREC_NETCONTROL           0xe0
-#define IPTOS_PREC_INTERNETCONTROL      0xc0
-#define IPTOS_PREC_CRITIC_ECP           0xa0
-#define IPTOS_PREC_FLASHOVERRIDE        0x80
-#define IPTOS_PREC_FLASH                0x60
-#define IPTOS_PREC_IMMEDIATE            0x40
-#define IPTOS_PREC_PRIORITY             0x20
-#define IPTOS_PREC_ROUTINE              0x00
-
-
-/* IP options */
-#define IPOPT_COPY		0x80
-#define IPOPT_CLASS_MASK	0x60
-#define IPOPT_NUMBER_MASK	0x1f
-
-#define	IPOPT_COPIED(o)		((o)&IPOPT_COPY)
-#define	IPOPT_CLASS(o)		((o)&IPOPT_CLASS_MASK)
-#define	IPOPT_NUMBER(o)		((o)&IPOPT_NUMBER_MASK)
-
-#define	IPOPT_CONTROL		0x00
-#define	IPOPT_RESERVED1		0x20
-#define	IPOPT_MEASUREMENT	0x40
-#define	IPOPT_RESERVED2		0x60
-
-#define IPOPT_END	(0 |IPOPT_CONTROL)
-#define IPOPT_NOOP	(1 |IPOPT_CONTROL)
-#define IPOPT_SEC	(2 |IPOPT_CONTROL|IPOPT_COPY)
-#define IPOPT_LSRR	(3 |IPOPT_CONTROL|IPOPT_COPY)
-#define IPOPT_TIMESTAMP	(4 |IPOPT_MEASUREMENT)
-#define IPOPT_CIPSO	(6 |IPOPT_CONTROL|IPOPT_COPY)
-#define IPOPT_RR	(7 |IPOPT_CONTROL)
-#define IPOPT_SID	(8 |IPOPT_CONTROL|IPOPT_COPY)
-#define IPOPT_SSRR	(9 |IPOPT_CONTROL|IPOPT_COPY)
-#define IPOPT_RA	(20|IPOPT_CONTROL|IPOPT_COPY)
-
-#define IPVERSION	4
-#define MAXTTL		255
-#define IPDEFTTL	64
-
-#define IPOPT_OPTVAL 0
-#define IPOPT_OLEN   1
-#define IPOPT_OFFSET 2
-#define IPOPT_MINOFF 4
-#define MAX_IPOPTLEN 40
-#define IPOPT_NOP IPOPT_NOOP
-#define IPOPT_EOL IPOPT_END
-#define IPOPT_TS  IPOPT_TIMESTAMP
-
-#define	IPOPT_TS_TSONLY		0		/* timestamps only */
-#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
-#define	IPOPT_TS_PRESPEC	3		/* specified modules only */
-
-#define IPV4_BEET_PHMAXLEN 8
-
-struct iphdr {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-	__u8	ihl:4,
-		version:4;
-#elif defined (__BIG_ENDIAN_BITFIELD)
-	__u8	version:4,
-  		ihl:4;
-#else
-#error	"Please fix <asm/byteorder.h>"
-#endif
-	__u8	tos;
-	__be16	tot_len;
-	__be16	id;
-	__be16	frag_off;
-	__u8	ttl;
-	__u8	protocol;
-	__sum16	check;
-	__be32	saddr;
-	__be32	daddr;
-	/*The options start here. */
-};
-
-
-struct ip_auth_hdr {
-	__u8  nexthdr;
-	__u8  hdrlen;		/* This one is measured in 32 bit units! */
-	__be16 reserved;
-	__be32 spi;
-	__be32 seq_no;		/* Sequence number */
-	__u8  auth_data[0];	/* Variable len but >=4. Mind the 64 bit alignment! */
-};
-
-struct ip_esp_hdr {
-	__be32 spi;
-	__be32 seq_no;		/* Sequence number */
-	__u8  enc_data[0];	/* Variable len but >=8. Mind the 64 bit alignment! */
-};
-
-struct ip_comp_hdr {
-	__u8 nexthdr;
-	__u8 flags;
-	__be16 cpi;
-};
-
-struct ip_beet_phdr {
-	__u8 nexthdr;
-	__u8 hdrlen;
-	__u8 padlen;
-	__u8 reserved;
-};
-
-/* index values for the variables in ipv4_devconf */
-enum
-{
-	IPV4_DEVCONF_FORWARDING=1,
-	IPV4_DEVCONF_MC_FORWARDING,
-	IPV4_DEVCONF_PROXY_ARP,
-	IPV4_DEVCONF_ACCEPT_REDIRECTS,
-	IPV4_DEVCONF_SECURE_REDIRECTS,
-	IPV4_DEVCONF_SEND_REDIRECTS,
-	IPV4_DEVCONF_SHARED_MEDIA,
-	IPV4_DEVCONF_RP_FILTER,
-	IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE,
-	IPV4_DEVCONF_BOOTP_RELAY,
-	IPV4_DEVCONF_LOG_MARTIANS,
-	IPV4_DEVCONF_TAG,
-	IPV4_DEVCONF_ARPFILTER,
-	IPV4_DEVCONF_MEDIUM_ID,
-	IPV4_DEVCONF_NOXFRM,
-	IPV4_DEVCONF_NOPOLICY,
-	IPV4_DEVCONF_FORCE_IGMP_VERSION,
-	IPV4_DEVCONF_ARP_ANNOUNCE,
-	IPV4_DEVCONF_ARP_IGNORE,
-	IPV4_DEVCONF_PROMOTE_SECONDARIES,
-	IPV4_DEVCONF_ARP_ACCEPT,
-	IPV4_DEVCONF_ARP_NOTIFY,
-	IPV4_DEVCONF_ACCEPT_LOCAL,
-	IPV4_DEVCONF_SRC_VMARK,
-	IPV4_DEVCONF_PROXY_ARP_PVLAN,
-	IPV4_DEVCONF_ROUTE_LOCALNET,
-	IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL,
-	IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL,
-	IPV4_DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN,
-	IPV4_DEVCONF_DROP_UNICAST_IN_L2_MULTICAST,
-	IPV4_DEVCONF_DROP_GRATUITOUS_ARP,
-	IPV4_DEVCONF_BC_FORWARDING,
-	__IPV4_DEVCONF_MAX
-};
-
-#define IPV4_DEVCONF_MAX (__IPV4_DEVCONF_MAX - 1)
-
-#endif /* _LINUX_IP_H */
diff --git a/include/uapi/linux/ipsec.h b/include/uapi/linux/ipsec.h
deleted file mode 100644
index 50d8ee1..0000000
--- a/include/uapi/linux/ipsec.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_IPSEC_H
-#define _LINUX_IPSEC_H
-
-/* The definitions, required to talk to KAME racoon IKE. */
-
-#include <linux/pfkeyv2.h>
-
-#define IPSEC_PORT_ANY		0
-#define IPSEC_ULPROTO_ANY	255
-#define IPSEC_PROTO_ANY		255
-
-enum {
-	IPSEC_MODE_ANY		= 0,	/* We do not support this for SA */
-	IPSEC_MODE_TRANSPORT	= 1,
-	IPSEC_MODE_TUNNEL	= 2,
-	IPSEC_MODE_BEET         = 3
-};
-
-enum {
-	IPSEC_DIR_ANY		= 0,
-	IPSEC_DIR_INBOUND	= 1,
-	IPSEC_DIR_OUTBOUND	= 2,
-	IPSEC_DIR_FWD		= 3,	/* It is our own */
-	IPSEC_DIR_MAX		= 4,
-	IPSEC_DIR_INVALID	= 5
-};
-
-enum {
-	IPSEC_POLICY_DISCARD	= 0,
-	IPSEC_POLICY_NONE	= 1,
-	IPSEC_POLICY_IPSEC	= 2,
-	IPSEC_POLICY_ENTRUST	= 3,
-	IPSEC_POLICY_BYPASS	= 4
-};
-
-enum {
-	IPSEC_LEVEL_DEFAULT	= 0,
-	IPSEC_LEVEL_USE		= 1,
-	IPSEC_LEVEL_REQUIRE	= 2,
-	IPSEC_LEVEL_UNIQUE	= 3
-};
-
-#define IPSEC_MANUAL_REQID_MAX	0x3fff
-
-#define IPSEC_REPLAYWSIZE  32
-
-#endif	/* _LINUX_IPSEC_H */
diff --git a/include/uapi/linux/kernel.h b/include/uapi/linux/kernel.h
deleted file mode 100644
index d99ffa1..0000000
--- a/include/uapi/linux/kernel.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_KERNEL_H
-#define _LINUX_KERNEL_H
-
-#include <linux/sysinfo.h>
-
-/*
- * 'kernel.h' contains some often-used function prototypes etc
- */
-#define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
-#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
-
-#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
-
-#endif /* _LINUX_KERNEL_H */
diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
deleted file mode 100644
index a159991..0000000
--- a/include/uapi/linux/libc-compat.h
+++ /dev/null
@@ -1,267 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * Compatibility interface for userspace libc header coordination:
- *
- * Define compatibility macros that are used to control the inclusion or
- * exclusion of UAPI structures and definitions in coordination with another
- * userspace C library.
- *
- * This header is intended to solve the problem of UAPI definitions that
- * conflict with userspace definitions. If a UAPI header has such conflicting
- * definitions then the solution is as follows:
- *
- * * Synchronize the UAPI header and the libc headers so either one can be
- *   used and such that the ABI is preserved. If this is not possible then
- *   no simple compatibility interface exists (you need to write translating
- *   wrappers and rename things) and you can't use this interface.
- *
- * Then follow this process:
- *
- * (a) Include libc-compat.h in the UAPI header.
- *      e.g. #include <linux/libc-compat.h>
- *     This include must be as early as possible.
- *
- * (b) In libc-compat.h add enough code to detect that the comflicting
- *     userspace libc header has been included first.
- *
- * (c) If the userspace libc header has been included first define a set of
- *     guard macros of the form __UAPI_DEF_FOO and set their values to 1, else
- *     set their values to 0.
- *
- * (d) Back in the UAPI header with the conflicting definitions, guard the
- *     definitions with:
- *     #if __UAPI_DEF_FOO
- *       ...
- *     #endif
- *
- * This fixes the situation where the linux headers are included *after* the
- * libc headers. To fix the problem with the inclusion in the other order the
- * userspace libc headers must be fixed like this:
- *
- * * For all definitions that conflict with kernel definitions wrap those
- *   defines in the following:
- *   #if !__UAPI_DEF_FOO
- *     ...
- *   #endif
- *
- * This prevents the redefinition of a construct already defined by the kernel.
- */
-#ifndef _LIBC_COMPAT_H
-#define _LIBC_COMPAT_H
-
-/* We have included glibc headers... */
-#if defined(__GLIBC__)
-
-/* Coordinate with glibc net/if.h header. */
-#if defined(_NET_IF_H) && defined(__USE_MISC)
-
-/* GLIBC headers included first so don't define anything
- * that would already be defined. */
-
-#define __UAPI_DEF_IF_IFCONF 0
-#define __UAPI_DEF_IF_IFMAP 0
-#define __UAPI_DEF_IF_IFNAMSIZ 0
-#define __UAPI_DEF_IF_IFREQ 0
-/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
-#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
-/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
-#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
-#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
-#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
-
-#else /* _NET_IF_H */
-
-/* Linux headers included first, and we must define everything
- * we need. The expectation is that glibc will check the
- * __UAPI_DEF_* defines and adjust appropriately. */
-
-#define __UAPI_DEF_IF_IFCONF 1
-#define __UAPI_DEF_IF_IFMAP 1
-#define __UAPI_DEF_IF_IFNAMSIZ 1
-#define __UAPI_DEF_IF_IFREQ 1
-/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
-#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
-/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
-#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
-
-#endif /* _NET_IF_H */
-
-/* Coordinate with glibc netinet/in.h header. */
-#if defined(_NETINET_IN_H)
-
-/* GLIBC headers included first so don't define anything
- * that would already be defined. */
-#define __UAPI_DEF_IN_ADDR		0
-#define __UAPI_DEF_IN_IPPROTO		0
-#define __UAPI_DEF_IN_PKTINFO		0
-#define __UAPI_DEF_IP_MREQ		0
-#define __UAPI_DEF_SOCKADDR_IN		0
-#define __UAPI_DEF_IN_CLASS		0
-
-#define __UAPI_DEF_IN6_ADDR		0
-/* The exception is the in6_addr macros which must be defined
- * if the glibc code didn't define them. This guard matches
- * the guard in glibc/inet/netinet/in.h which defines the
- * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
-#if defined(__USE_MISC) || defined (__USE_GNU)
-#define __UAPI_DEF_IN6_ADDR_ALT		0
-#else
-#define __UAPI_DEF_IN6_ADDR_ALT		1
-#endif
-#define __UAPI_DEF_SOCKADDR_IN6		0
-#define __UAPI_DEF_IPV6_MREQ		0
-#define __UAPI_DEF_IPPROTO_V6		0
-#define __UAPI_DEF_IPV6_OPTIONS		0
-#define __UAPI_DEF_IN6_PKTINFO		0
-#define __UAPI_DEF_IP6_MTUINFO		0
-
-#else
-
-/* Linux headers included first, and we must define everything
- * we need. The expectation is that glibc will check the
- * __UAPI_DEF_* defines and adjust appropriately. */
-#define __UAPI_DEF_IN_ADDR		1
-#define __UAPI_DEF_IN_IPPROTO		1
-#define __UAPI_DEF_IN_PKTINFO		1
-#define __UAPI_DEF_IP_MREQ		1
-#define __UAPI_DEF_SOCKADDR_IN		1
-#define __UAPI_DEF_IN_CLASS		1
-
-#define __UAPI_DEF_IN6_ADDR		1
-/* We unconditionally define the in6_addr macros and glibc must
- * coordinate. */
-#define __UAPI_DEF_IN6_ADDR_ALT		1
-#define __UAPI_DEF_SOCKADDR_IN6		1
-#define __UAPI_DEF_IPV6_MREQ		1
-#define __UAPI_DEF_IPPROTO_V6		1
-#define __UAPI_DEF_IPV6_OPTIONS		1
-#define __UAPI_DEF_IN6_PKTINFO		1
-#define __UAPI_DEF_IP6_MTUINFO		1
-
-#endif /* _NETINET_IN_H */
-
-/* Coordinate with glibc netipx/ipx.h header. */
-#if defined(__NETIPX_IPX_H)
-
-#define __UAPI_DEF_SOCKADDR_IPX			0
-#define __UAPI_DEF_IPX_ROUTE_DEFINITION		0
-#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	0
-#define __UAPI_DEF_IPX_CONFIG_DATA		0
-#define __UAPI_DEF_IPX_ROUTE_DEF		0
-
-#else /* defined(__NETIPX_IPX_H) */
-
-#define __UAPI_DEF_SOCKADDR_IPX			1
-#define __UAPI_DEF_IPX_ROUTE_DEFINITION		1
-#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	1
-#define __UAPI_DEF_IPX_CONFIG_DATA		1
-#define __UAPI_DEF_IPX_ROUTE_DEF		1
-
-#endif /* defined(__NETIPX_IPX_H) */
-
-/* Definitions for xattr.h */
-#if defined(_SYS_XATTR_H)
-#define __UAPI_DEF_XATTR		0
-#else
-#define __UAPI_DEF_XATTR		1
-#endif
-
-/* If we did not see any headers from any supported C libraries,
- * or we are being included in the kernel, then define everything
- * that we need. Check for previous __UAPI_* definitions to give
- * unsupported C libraries a way to opt out of any kernel definition. */
-#else /* !defined(__GLIBC__) */
-
-/* Definitions for if.h */
-#ifndef __UAPI_DEF_IF_IFCONF
-#define __UAPI_DEF_IF_IFCONF 1
-#endif
-#ifndef __UAPI_DEF_IF_IFMAP
-#define __UAPI_DEF_IF_IFMAP 1
-#endif
-#ifndef __UAPI_DEF_IF_IFNAMSIZ
-#define __UAPI_DEF_IF_IFNAMSIZ 1
-#endif
-#ifndef __UAPI_DEF_IF_IFREQ
-#define __UAPI_DEF_IF_IFREQ 1
-#endif
-/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
-#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS
-#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
-#endif
-/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
-#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
-#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
-#endif
-
-/* Definitions for in.h */
-#ifndef __UAPI_DEF_IN_ADDR
-#define __UAPI_DEF_IN_ADDR		1
-#endif
-#ifndef __UAPI_DEF_IN_IPPROTO
-#define __UAPI_DEF_IN_IPPROTO		1
-#endif
-#ifndef __UAPI_DEF_IN_PKTINFO
-#define __UAPI_DEF_IN_PKTINFO		1
-#endif
-#ifndef __UAPI_DEF_IP_MREQ
-#define __UAPI_DEF_IP_MREQ		1
-#endif
-#ifndef __UAPI_DEF_SOCKADDR_IN
-#define __UAPI_DEF_SOCKADDR_IN		1
-#endif
-#ifndef __UAPI_DEF_IN_CLASS
-#define __UAPI_DEF_IN_CLASS		1
-#endif
-
-/* Definitions for in6.h */
-#ifndef __UAPI_DEF_IN6_ADDR
-#define __UAPI_DEF_IN6_ADDR		1
-#endif
-#ifndef __UAPI_DEF_IN6_ADDR_ALT
-#define __UAPI_DEF_IN6_ADDR_ALT		1
-#endif
-#ifndef __UAPI_DEF_SOCKADDR_IN6
-#define __UAPI_DEF_SOCKADDR_IN6		1
-#endif
-#ifndef __UAPI_DEF_IPV6_MREQ
-#define __UAPI_DEF_IPV6_MREQ		1
-#endif
-#ifndef __UAPI_DEF_IPPROTO_V6
-#define __UAPI_DEF_IPPROTO_V6		1
-#endif
-#ifndef __UAPI_DEF_IPV6_OPTIONS
-#define __UAPI_DEF_IPV6_OPTIONS		1
-#endif
-#ifndef __UAPI_DEF_IN6_PKTINFO
-#define __UAPI_DEF_IN6_PKTINFO		1
-#endif
-#ifndef __UAPI_DEF_IP6_MTUINFO
-#define __UAPI_DEF_IP6_MTUINFO		1
-#endif
-
-/* Definitions for ipx.h */
-#ifndef __UAPI_DEF_SOCKADDR_IPX
-#define __UAPI_DEF_SOCKADDR_IPX			1
-#endif
-#ifndef __UAPI_DEF_IPX_ROUTE_DEFINITION
-#define __UAPI_DEF_IPX_ROUTE_DEFINITION		1
-#endif
-#ifndef __UAPI_DEF_IPX_INTERFACE_DEFINITION
-#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	1
-#endif
-#ifndef __UAPI_DEF_IPX_CONFIG_DATA
-#define __UAPI_DEF_IPX_CONFIG_DATA		1
-#endif
-#ifndef __UAPI_DEF_IPX_ROUTE_DEF
-#define __UAPI_DEF_IPX_ROUTE_DEF		1
-#endif
-
-/* Definitions for xattr.h */
-#ifndef __UAPI_DEF_XATTR
-#define __UAPI_DEF_XATTR		1
-#endif
-
-#endif /* __GLIBC__ */
-
-#endif /* _LIBC_COMPAT_H */
diff --git a/include/uapi/linux/limits.h b/include/uapi/linux/limits.h
deleted file mode 100644
index c3547f0..0000000
--- a/include/uapi/linux/limits.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_LIMITS_H
-#define _LINUX_LIMITS_H
-
-#define NR_OPEN	        1024
-
-#define NGROUPS_MAX    65536	/* supplemental group IDs are available */
-#define ARG_MAX       131072	/* # bytes of args + environ for exec() */
-#define LINK_MAX         127	/* # links a file may have */
-#define MAX_CANON        255	/* size of the canonical input queue */
-#define MAX_INPUT        255	/* size of the type-ahead buffer */
-#define NAME_MAX         255	/* # chars in a file name */
-#define PATH_MAX        4096	/* # chars in a path name including nul */
-#define PIPE_BUF        4096	/* # bytes in atomic write to a pipe */
-#define XATTR_NAME_MAX   255	/* # chars in an extended attribute name */
-#define XATTR_SIZE_MAX 65536	/* size of an extended attribute value (64k) */
-#define XATTR_LIST_MAX 65536	/* size of extended attribute namelist (64k) */
-
-#define RTSIG_MAX	  32
-
-#endif
diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h
deleted file mode 100644
index 903cc2d..0000000
--- a/include/uapi/linux/magic.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_MAGIC_H__
-#define __LINUX_MAGIC_H__
-
-#define ADFS_SUPER_MAGIC	0xadf5
-#define AFFS_SUPER_MAGIC	0xadff
-#define AFS_SUPER_MAGIC                0x5346414F
-#define AUTOFS_SUPER_MAGIC	0x0187
-#define CODA_SUPER_MAGIC	0x73757245
-#define CRAMFS_MAGIC		0x28cd3d45	/* some random number */
-#define CRAMFS_MAGIC_WEND	0x453dcd28	/* magic number with the wrong endianess */
-#define DEBUGFS_MAGIC          0x64626720
-#define SECURITYFS_MAGIC	0x73636673
-#define SELINUX_MAGIC		0xf97cff8c
-#define SMACK_MAGIC		0x43415d53	/* "SMAC" */
-#define RAMFS_MAGIC		0x858458f6	/* some random number */
-#define TMPFS_MAGIC		0x01021994
-#define HUGETLBFS_MAGIC 	0x958458f6	/* some random number */
-#define SQUASHFS_MAGIC		0x73717368
-#define ECRYPTFS_SUPER_MAGIC	0xf15f
-#define EFS_SUPER_MAGIC		0x414A53
-#define EROFS_SUPER_MAGIC_V1	0xE0F5E1E2
-#define EXT2_SUPER_MAGIC	0xEF53
-#define EXT3_SUPER_MAGIC	0xEF53
-#define XENFS_SUPER_MAGIC	0xabba1974
-#define EXT4_SUPER_MAGIC	0xEF53
-#define BTRFS_SUPER_MAGIC	0x9123683E
-#define NILFS_SUPER_MAGIC	0x3434
-#define F2FS_SUPER_MAGIC	0xF2F52010
-#define HPFS_SUPER_MAGIC	0xf995e849
-#define ISOFS_SUPER_MAGIC	0x9660
-#define JFFS2_SUPER_MAGIC	0x72b6
-#define XFS_SUPER_MAGIC		0x58465342	/* "XFSB" */
-#define PSTOREFS_MAGIC		0x6165676C
-#define EFIVARFS_MAGIC		0xde5e81e4
-#define HOSTFS_SUPER_MAGIC	0x00c0ffee
-#define OVERLAYFS_SUPER_MAGIC	0x794c7630
-
-#define MINIX_SUPER_MAGIC	0x137F		/* minix v1 fs, 14 char names */
-#define MINIX_SUPER_MAGIC2	0x138F		/* minix v1 fs, 30 char names */
-#define MINIX2_SUPER_MAGIC	0x2468		/* minix v2 fs, 14 char names */
-#define MINIX2_SUPER_MAGIC2	0x2478		/* minix v2 fs, 30 char names */
-#define MINIX3_SUPER_MAGIC	0x4d5a		/* minix v3 fs, 60 char names */
-
-#define MSDOS_SUPER_MAGIC	0x4d44		/* MD */
-#define NCP_SUPER_MAGIC		0x564c		/* Guess, what 0x564c is :-) */
-#define NFS_SUPER_MAGIC		0x6969
-#define OCFS2_SUPER_MAGIC	0x7461636f
-#define OPENPROM_SUPER_MAGIC	0x9fa1
-#define QNX4_SUPER_MAGIC	0x002f		/* qnx4 fs detection */
-#define QNX6_SUPER_MAGIC	0x68191122	/* qnx6 fs detection */
-#define AFS_FS_MAGIC		0x6B414653
-
-#define REISERFS_SUPER_MAGIC	0x52654973	/* used by gcc */
-					/* used by file system utilities that
-	                                   look at the superblock, etc.  */
-#define REISERFS_SUPER_MAGIC_STRING	"ReIsErFs"
-#define REISER2FS_SUPER_MAGIC_STRING	"ReIsEr2Fs"
-#define REISER2FS_JR_SUPER_MAGIC_STRING	"ReIsEr3Fs"
-
-#define SMB_SUPER_MAGIC		0x517B
-#define CGROUP_SUPER_MAGIC	0x27e0eb
-#define CGROUP2_SUPER_MAGIC	0x63677270
-
-#define RDTGROUP_SUPER_MAGIC	0x7655821
-
-#define STACK_END_MAGIC		0x57AC6E9D
-
-#define TRACEFS_MAGIC          0x74726163
-
-#define V9FS_MAGIC		0x01021997
-
-#define BDEVFS_MAGIC            0x62646576
-#define DAXFS_MAGIC             0x64646178
-#define BINFMTFS_MAGIC          0x42494e4d
-#define DEVPTS_SUPER_MAGIC	0x1cd1
-#define BINDERFS_SUPER_MAGIC	0x6c6f6f70
-#define FUTEXFS_SUPER_MAGIC	0xBAD1DEA
-#define PIPEFS_MAGIC            0x50495045
-#define PROC_SUPER_MAGIC	0x9fa0
-#define SOCKFS_MAGIC		0x534F434B
-#define SYSFS_MAGIC		0x62656572
-#define USBDEVICE_SUPER_MAGIC	0x9fa2
-#define MTD_INODE_FS_MAGIC      0x11307854
-#define ANON_INODE_FS_MAGIC	0x09041934
-#define BTRFS_TEST_MAGIC	0x73727279
-#define NSFS_MAGIC		0x6e736673
-#define BPF_FS_MAGIC		0xcafe4a11
-#define AAFS_MAGIC		0x5a3c69f0
-
-/* Since UDF 2.01 is ISO 13346 based... */
-#define UDF_SUPER_MAGIC		0x15013346
-#define BALLOON_KVM_MAGIC	0x13661366
-#define ZSMALLOC_MAGIC		0x58295829
-#define DMA_BUF_MAGIC		0x444d4142	/* "DMAB" */
-#define Z3FOLD_MAGIC		0x33
-
-#endif /* __LINUX_MAGIC_H__ */
diff --git a/include/uapi/linux/net.h b/include/uapi/linux/net.h
deleted file mode 100644
index 4754f70..0000000
--- a/include/uapi/linux/net.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * NET		An implementation of the SOCKET network access protocol.
- *		This is the master header file for the Linux NET layer,
- *		or, in plain English: the networking handling part of the
- *		kernel.
- *
- * Version:	@(#)net.h	1.0.3	05/25/93
- *
- * Authors:	Orest Zborowski, <obz@Kodak.COM>
- *		Ross Biro
- *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- */
-#ifndef _LINUX_NET_H
-#define _LINUX_NET_H
-
-#include <linux/socket.h>
-#include <asm/socket.h>
-
-#define NPROTO		AF_MAX
-
-#define SYS_SOCKET	1		/* sys_socket(2)		*/
-#define SYS_BIND	2		/* sys_bind(2)			*/
-#define SYS_CONNECT	3		/* sys_connect(2)		*/
-#define SYS_LISTEN	4		/* sys_listen(2)		*/
-#define SYS_ACCEPT	5		/* sys_accept(2)		*/
-#define SYS_GETSOCKNAME	6		/* sys_getsockname(2)		*/
-#define SYS_GETPEERNAME	7		/* sys_getpeername(2)		*/
-#define SYS_SOCKETPAIR	8		/* sys_socketpair(2)		*/
-#define SYS_SEND	9		/* sys_send(2)			*/
-#define SYS_RECV	10		/* sys_recv(2)			*/
-#define SYS_SENDTO	11		/* sys_sendto(2)		*/
-#define SYS_RECVFROM	12		/* sys_recvfrom(2)		*/
-#define SYS_SHUTDOWN	13		/* sys_shutdown(2)		*/
-#define SYS_SETSOCKOPT	14		/* sys_setsockopt(2)		*/
-#define SYS_GETSOCKOPT	15		/* sys_getsockopt(2)		*/
-#define SYS_SENDMSG	16		/* sys_sendmsg(2)		*/
-#define SYS_RECVMSG	17		/* sys_recvmsg(2)		*/
-#define SYS_ACCEPT4	18		/* sys_accept4(2)		*/
-#define SYS_RECVMMSG	19		/* sys_recvmmsg(2)		*/
-#define SYS_SENDMMSG	20		/* sys_sendmmsg(2)		*/
-
-typedef enum {
-	SS_FREE = 0,			/* not allocated		*/
-	SS_UNCONNECTED,			/* unconnected to any socket	*/
-	SS_CONNECTING,			/* in process of connecting	*/
-	SS_CONNECTED,			/* connected to socket		*/
-	SS_DISCONNECTING		/* in process of disconnecting	*/
-} socket_state;
-
-#define __SO_ACCEPTCON	(1 << 16)	/* performed a listen		*/
-
-#endif /* _LINUX_NET_H */
diff --git a/include/uapi/linux/netfilter/ipset/ip_set.h b/include/uapi/linux/netfilter/ipset/ip_set.h
deleted file mode 100644
index c512003..0000000
--- a/include/uapi/linux/netfilter/ipset/ip_set.h
+++ /dev/null
@@ -1,310 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
- *                         Patrick Schaaf <bof@bof.de>
- *                         Martin Josefsson <gandalf@wlug.westbo.se>
- * Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@netfilter.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#ifndef _IP_SET_H
-#define _IP_SET_H
-
-#include <linux/types.h>
-
-/* The protocol versions */
-#define IPSET_PROTOCOL		7
-#define IPSET_PROTOCOL_MIN	6
-
-/* The max length of strings including NUL: set and type identifiers */
-#define IPSET_MAXNAMELEN	32
-
-/* The maximum permissible comment length we will accept over netlink */
-#define IPSET_MAX_COMMENT_SIZE	255
-
-/* Message types and commands */
-enum ipset_cmd {
-	IPSET_CMD_NONE,
-	IPSET_CMD_PROTOCOL,	/* 1: Return protocol version */
-	IPSET_CMD_CREATE,	/* 2: Create a new (empty) set */
-	IPSET_CMD_DESTROY,	/* 3: Destroy a (empty) set */
-	IPSET_CMD_FLUSH,	/* 4: Remove all elements from a set */
-	IPSET_CMD_RENAME,	/* 5: Rename a set */
-	IPSET_CMD_SWAP,		/* 6: Swap two sets */
-	IPSET_CMD_LIST,		/* 7: List sets */
-	IPSET_CMD_SAVE,		/* 8: Save sets */
-	IPSET_CMD_ADD,		/* 9: Add an element to a set */
-	IPSET_CMD_DEL,		/* 10: Delete an element from a set */
-	IPSET_CMD_TEST,		/* 11: Test an element in a set */
-	IPSET_CMD_HEADER,	/* 12: Get set header data only */
-	IPSET_CMD_TYPE,		/* 13: Get set type */
-	IPSET_CMD_GET_BYNAME,	/* 14: Get set index by name */
-	IPSET_CMD_GET_BYINDEX,	/* 15: Get set name by index */
-	IPSET_MSG_MAX,		/* Netlink message commands */
-
-	/* Commands in userspace: */
-	IPSET_CMD_RESTORE = IPSET_MSG_MAX, /* 16: Enter restore mode */
-	IPSET_CMD_HELP,		/* 17: Get help */
-	IPSET_CMD_VERSION,	/* 18: Get program version */
-	IPSET_CMD_QUIT,		/* 19: Quit from interactive mode */
-
-	IPSET_CMD_MAX,
-
-	IPSET_CMD_COMMIT = IPSET_CMD_MAX, /* 20: Commit buffered commands */
-};
-
-/* Attributes at command level */
-enum {
-	IPSET_ATTR_UNSPEC,
-	IPSET_ATTR_PROTOCOL,	/* 1: Protocol version */
-	IPSET_ATTR_SETNAME,	/* 2: Name of the set */
-	IPSET_ATTR_TYPENAME,	/* 3: Typename */
-	IPSET_ATTR_SETNAME2 = IPSET_ATTR_TYPENAME, /* Setname at rename/swap */
-	IPSET_ATTR_REVISION,	/* 4: Settype revision */
-	IPSET_ATTR_FAMILY,	/* 5: Settype family */
-	IPSET_ATTR_FLAGS,	/* 6: Flags at command level */
-	IPSET_ATTR_DATA,	/* 7: Nested attributes */
-	IPSET_ATTR_ADT,		/* 8: Multiple data containers */
-	IPSET_ATTR_LINENO,	/* 9: Restore lineno */
-	IPSET_ATTR_PROTOCOL_MIN, /* 10: Minimal supported version number */
-	IPSET_ATTR_REVISION_MIN	= IPSET_ATTR_PROTOCOL_MIN, /* type rev min */
-	IPSET_ATTR_INDEX,	/* 11: Kernel index of set */
-	__IPSET_ATTR_CMD_MAX,
-};
-#define IPSET_ATTR_CMD_MAX	(__IPSET_ATTR_CMD_MAX - 1)
-
-/* CADT specific attributes */
-enum {
-	IPSET_ATTR_IP = IPSET_ATTR_UNSPEC + 1,
-	IPSET_ATTR_IP_FROM = IPSET_ATTR_IP,
-	IPSET_ATTR_IP_TO,	/* 2 */
-	IPSET_ATTR_CIDR,	/* 3 */
-	IPSET_ATTR_PORT,	/* 4 */
-	IPSET_ATTR_PORT_FROM = IPSET_ATTR_PORT,
-	IPSET_ATTR_PORT_TO,	/* 5 */
-	IPSET_ATTR_TIMEOUT,	/* 6 */
-	IPSET_ATTR_PROTO,	/* 7 */
-	IPSET_ATTR_CADT_FLAGS,	/* 8 */
-	IPSET_ATTR_CADT_LINENO = IPSET_ATTR_LINENO,	/* 9 */
-	IPSET_ATTR_MARK,	/* 10 */
-	IPSET_ATTR_MARKMASK,	/* 11 */
-	/* Reserve empty slots */
-	IPSET_ATTR_CADT_MAX = 16,
-	/* Create-only specific attributes */
-	IPSET_ATTR_GC,
-	IPSET_ATTR_HASHSIZE,
-	IPSET_ATTR_MAXELEM,
-	IPSET_ATTR_NETMASK,
-	IPSET_ATTR_PROBES,
-	IPSET_ATTR_RESIZE,
-	IPSET_ATTR_SIZE,
-	/* Kernel-only */
-	IPSET_ATTR_ELEMENTS,
-	IPSET_ATTR_REFERENCES,
-	IPSET_ATTR_MEMSIZE,
-
-	__IPSET_ATTR_CREATE_MAX,
-};
-#define IPSET_ATTR_CREATE_MAX	(__IPSET_ATTR_CREATE_MAX - 1)
-
-/* ADT specific attributes */
-enum {
-	IPSET_ATTR_ETHER = IPSET_ATTR_CADT_MAX + 1,
-	IPSET_ATTR_NAME,
-	IPSET_ATTR_NAMEREF,
-	IPSET_ATTR_IP2,
-	IPSET_ATTR_CIDR2,
-	IPSET_ATTR_IP2_TO,
-	IPSET_ATTR_IFACE,
-	IPSET_ATTR_BYTES,
-	IPSET_ATTR_PACKETS,
-	IPSET_ATTR_COMMENT,
-	IPSET_ATTR_SKBMARK,
-	IPSET_ATTR_SKBPRIO,
-	IPSET_ATTR_SKBQUEUE,
-	IPSET_ATTR_PAD,
-	__IPSET_ATTR_ADT_MAX,
-};
-#define IPSET_ATTR_ADT_MAX	(__IPSET_ATTR_ADT_MAX - 1)
-
-/* IP specific attributes */
-enum {
-	IPSET_ATTR_IPADDR_IPV4 = IPSET_ATTR_UNSPEC + 1,
-	IPSET_ATTR_IPADDR_IPV6,
-	__IPSET_ATTR_IPADDR_MAX,
-};
-#define IPSET_ATTR_IPADDR_MAX	(__IPSET_ATTR_IPADDR_MAX - 1)
-
-/* Error codes */
-enum ipset_errno {
-	IPSET_ERR_PRIVATE = 4096,
-	IPSET_ERR_PROTOCOL,
-	IPSET_ERR_FIND_TYPE,
-	IPSET_ERR_MAX_SETS,
-	IPSET_ERR_BUSY,
-	IPSET_ERR_EXIST_SETNAME2,
-	IPSET_ERR_TYPE_MISMATCH,
-	IPSET_ERR_EXIST,
-	IPSET_ERR_INVALID_CIDR,
-	IPSET_ERR_INVALID_NETMASK,
-	IPSET_ERR_INVALID_FAMILY,
-	IPSET_ERR_TIMEOUT,
-	IPSET_ERR_REFERENCED,
-	IPSET_ERR_IPADDR_IPV4,
-	IPSET_ERR_IPADDR_IPV6,
-	IPSET_ERR_COUNTER,
-	IPSET_ERR_COMMENT,
-	IPSET_ERR_INVALID_MARKMASK,
-	IPSET_ERR_SKBINFO,
-
-	/* Type specific error codes */
-	IPSET_ERR_TYPE_SPECIFIC = 4352,
-};
-
-/* Flags at command level or match/target flags, lower half of cmdattrs*/
-enum ipset_cmd_flags {
-	IPSET_FLAG_BIT_EXIST	= 0,
-	IPSET_FLAG_EXIST	= (1 << IPSET_FLAG_BIT_EXIST),
-	IPSET_FLAG_BIT_LIST_SETNAME = 1,
-	IPSET_FLAG_LIST_SETNAME	= (1 << IPSET_FLAG_BIT_LIST_SETNAME),
-	IPSET_FLAG_BIT_LIST_HEADER = 2,
-	IPSET_FLAG_LIST_HEADER	= (1 << IPSET_FLAG_BIT_LIST_HEADER),
-	IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE = 3,
-	IPSET_FLAG_SKIP_COUNTER_UPDATE =
-		(1 << IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE),
-	IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE = 4,
-	IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE =
-		(1 << IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE),
-	IPSET_FLAG_BIT_MATCH_COUNTERS = 5,
-	IPSET_FLAG_MATCH_COUNTERS = (1 << IPSET_FLAG_BIT_MATCH_COUNTERS),
-	IPSET_FLAG_BIT_RETURN_NOMATCH = 7,
-	IPSET_FLAG_RETURN_NOMATCH = (1 << IPSET_FLAG_BIT_RETURN_NOMATCH),
-	IPSET_FLAG_BIT_MAP_SKBMARK = 8,
-	IPSET_FLAG_MAP_SKBMARK = (1 << IPSET_FLAG_BIT_MAP_SKBMARK),
-	IPSET_FLAG_BIT_MAP_SKBPRIO = 9,
-	IPSET_FLAG_MAP_SKBPRIO = (1 << IPSET_FLAG_BIT_MAP_SKBPRIO),
-	IPSET_FLAG_BIT_MAP_SKBQUEUE = 10,
-	IPSET_FLAG_MAP_SKBQUEUE = (1 << IPSET_FLAG_BIT_MAP_SKBQUEUE),
-	IPSET_FLAG_CMD_MAX = 15,
-};
-
-/* Flags at CADT attribute level, upper half of cmdattrs */
-enum ipset_cadt_flags {
-	IPSET_FLAG_BIT_BEFORE	= 0,
-	IPSET_FLAG_BEFORE	= (1 << IPSET_FLAG_BIT_BEFORE),
-	IPSET_FLAG_BIT_PHYSDEV	= 1,
-	IPSET_FLAG_PHYSDEV	= (1 << IPSET_FLAG_BIT_PHYSDEV),
-	IPSET_FLAG_BIT_NOMATCH	= 2,
-	IPSET_FLAG_NOMATCH	= (1 << IPSET_FLAG_BIT_NOMATCH),
-	IPSET_FLAG_BIT_WITH_COUNTERS = 3,
-	IPSET_FLAG_WITH_COUNTERS = (1 << IPSET_FLAG_BIT_WITH_COUNTERS),
-	IPSET_FLAG_BIT_WITH_COMMENT = 4,
-	IPSET_FLAG_WITH_COMMENT = (1 << IPSET_FLAG_BIT_WITH_COMMENT),
-	IPSET_FLAG_BIT_WITH_FORCEADD = 5,
-	IPSET_FLAG_WITH_FORCEADD = (1 << IPSET_FLAG_BIT_WITH_FORCEADD),
-	IPSET_FLAG_BIT_WITH_SKBINFO = 6,
-	IPSET_FLAG_WITH_SKBINFO = (1 << IPSET_FLAG_BIT_WITH_SKBINFO),
-	IPSET_FLAG_CADT_MAX	= 15,
-};
-
-/* The flag bits which correspond to the non-extension create flags */
-enum ipset_create_flags {
-	IPSET_CREATE_FLAG_BIT_FORCEADD = 0,
-	IPSET_CREATE_FLAG_FORCEADD = (1 << IPSET_CREATE_FLAG_BIT_FORCEADD),
-	IPSET_CREATE_FLAG_BIT_MAX = 7,
-};
-
-/* Commands with settype-specific attributes */
-enum ipset_adt {
-	IPSET_ADD,
-	IPSET_DEL,
-	IPSET_TEST,
-	IPSET_ADT_MAX,
-	IPSET_CREATE = IPSET_ADT_MAX,
-	IPSET_CADT_MAX,
-};
-
-/* Sets are identified by an index in kernel space. Tweak with ip_set_id_t
- * and IPSET_INVALID_ID if you want to increase the max number of sets.
- * Also, IPSET_ATTR_INDEX must be changed.
- */
-typedef __u16 ip_set_id_t;
-
-#define IPSET_INVALID_ID		65535
-
-enum ip_set_dim {
-	IPSET_DIM_ZERO = 0,
-	IPSET_DIM_ONE,
-	IPSET_DIM_TWO,
-	IPSET_DIM_THREE,
-	/* Max dimension in elements.
-	 * If changed, new revision of iptables match/target is required.
-	 */
-	IPSET_DIM_MAX = 6,
-	/* Backward compatibility: set match revision 2 */
-	IPSET_BIT_RETURN_NOMATCH = 7,
-};
-
-/* Option flags for kernel operations */
-enum ip_set_kopt {
-	IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
-	IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
-	IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
-	IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
-	IPSET_RETURN_NOMATCH = (1 << IPSET_BIT_RETURN_NOMATCH),
-};
-
-enum {
-	IPSET_COUNTER_NONE = 0,
-	IPSET_COUNTER_EQ,
-	IPSET_COUNTER_NE,
-	IPSET_COUNTER_LT,
-	IPSET_COUNTER_GT,
-};
-
-/* Backward compatibility for set match v3 */
-struct ip_set_counter_match0 {
-	__u8 op;
-	__u64 value;
-};
-
-struct ip_set_counter_match {
-	__aligned_u64 value;
-	__u8 op;
-};
-
-/* Interface to iptables/ip6tables */
-
-#define SO_IP_SET		83
-
-union ip_set_name_index {
-	char name[IPSET_MAXNAMELEN];
-	ip_set_id_t index;
-};
-
-#define IP_SET_OP_GET_BYNAME	0x00000006	/* Get set index by name */
-struct ip_set_req_get_set {
-	unsigned int op;
-	unsigned int version;
-	union ip_set_name_index set;
-};
-
-#define IP_SET_OP_GET_BYINDEX	0x00000007	/* Get set name by index */
-/* Uses ip_set_req_get_set */
-
-#define IP_SET_OP_GET_FNAME	0x00000008	/* Get set index and family */
-struct ip_set_req_get_set_family {
-	unsigned int op;
-	unsigned int version;
-	unsigned int family;
-	union ip_set_name_index set;
-};
-
-#define IP_SET_OP_VERSION	0x00000100	/* Ask kernel version */
-struct ip_set_req_version {
-	unsigned int op;
-	unsigned int version;
-};
-
-#endif /* _IP_SET_H */
diff --git a/include/uapi/linux/netfilter/xt_set.h b/include/uapi/linux/netfilter/xt_set.h
deleted file mode 100644
index 8c1ca66..0000000
--- a/include/uapi/linux/netfilter/xt_set.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _XT_SET_H
-#define _XT_SET_H
-
-#include <linux/types.h>
-#include <linux/netfilter/ipset/ip_set.h>
-
-/* Revision 0 interface: backward compatible with netfilter/iptables */
-
-/*
- * Option flags for kernel operations (xt_set_info_v0)
- */
-#define IPSET_SRC		0x01	/* Source match/add */
-#define IPSET_DST		0x02	/* Destination match/add */
-#define IPSET_MATCH_INV		0x04	/* Inverse matching */
-
-struct xt_set_info_v0 {
-	ip_set_id_t index;
-	union {
-		__u32 flags[IPSET_DIM_MAX + 1];
-		struct {
-			__u32 __flags[IPSET_DIM_MAX];
-			__u8 dim;
-			__u8 flags;
-		} compat;
-	} u;
-};
-
-/* match and target infos */
-struct xt_set_info_match_v0 {
-	struct xt_set_info_v0 match_set;
-};
-
-struct xt_set_info_target_v0 {
-	struct xt_set_info_v0 add_set;
-	struct xt_set_info_v0 del_set;
-};
-
-/* Revision 1  match and target */
-
-struct xt_set_info {
-	ip_set_id_t index;
-	__u8 dim;
-	__u8 flags;
-};
-
-/* match and target infos */
-struct xt_set_info_match_v1 {
-	struct xt_set_info match_set;
-};
-
-struct xt_set_info_target_v1 {
-	struct xt_set_info add_set;
-	struct xt_set_info del_set;
-};
-
-/* Revision 2 target */
-
-struct xt_set_info_target_v2 {
-	struct xt_set_info add_set;
-	struct xt_set_info del_set;
-	__u32 flags;
-	__u32 timeout;
-};
-
-/* Revision 3 match */
-
-struct xt_set_info_match_v3 {
-	struct xt_set_info match_set;
-	struct ip_set_counter_match0 packets;
-	struct ip_set_counter_match0 bytes;
-	__u32 flags;
-};
-
-/* Revision 3 target */
-
-struct xt_set_info_target_v3 {
-	struct xt_set_info add_set;
-	struct xt_set_info del_set;
-	struct xt_set_info map_set;
-	__u32 flags;
-	__u32 timeout;
-};
-
-/* Revision 4 match */
-
-struct xt_set_info_match_v4 {
-	struct xt_set_info match_set;
-	struct ip_set_counter_match packets;
-	struct ip_set_counter_match bytes;
-	__u32 flags;
-};
-
-#endif /*_XT_SET_H*/
diff --git a/include/uapi/linux/netfilter_ipv6.h b/include/uapi/linux/netfilter_ipv6.h
deleted file mode 100644
index eedf7a2..0000000
--- a/include/uapi/linux/netfilter_ipv6.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* IPv6-specific defines for netfilter. 
- * (C)1998 Rusty Russell -- This code is GPL.
- * (C)1999 David Jeffery
- *   this header was blatantly ripped from netfilter_ipv4.h 
- *   it's amazing what adding a bunch of 6s can do =8^)
- */
-#ifndef __LINUX_IP6_NETFILTER_H
-#define __LINUX_IP6_NETFILTER_H
-
-
-#include <linux/netfilter.h>
-
-/* only for userspace compatibility */
-
-#include <limits.h> /* for INT_MIN, INT_MAX */
-
-/* IP6 Hooks */
-/* After promisc drops, checksum checks. */
-#define NF_IP6_PRE_ROUTING	0
-/* If the packet is destined for this box. */
-#define NF_IP6_LOCAL_IN		1
-/* If the packet is destined for another interface. */
-#define NF_IP6_FORWARD		2
-/* Packets coming from a local process. */
-#define NF_IP6_LOCAL_OUT		3
-/* Packets about to hit the wire. */
-#define NF_IP6_POST_ROUTING	4
-#define NF_IP6_NUMHOOKS		5
-
-
-enum nf_ip6_hook_priorities {
-	NF_IP6_PRI_FIRST = INT_MIN,
-	NF_IP6_PRI_RAW_BEFORE_DEFRAG = -450,
-	NF_IP6_PRI_CONNTRACK_DEFRAG = -400,
-	NF_IP6_PRI_RAW = -300,
-	NF_IP6_PRI_SELINUX_FIRST = -225,
-	NF_IP6_PRI_CONNTRACK = -200,
-	NF_IP6_PRI_MANGLE = -150,
-	NF_IP6_PRI_NAT_DST = -100,
-	NF_IP6_PRI_FILTER = 0,
-	NF_IP6_PRI_SECURITY = 50,
-	NF_IP6_PRI_NAT_SRC = 100,
-	NF_IP6_PRI_SELINUX_LAST = 225,
-	NF_IP6_PRI_CONNTRACK_HELPER = 300,
-	NF_IP6_PRI_LAST = INT_MAX,
-};
-
-
-#endif /* __LINUX_IP6_NETFILTER_H */
diff --git a/include/uapi/linux/netfilter_ipv6/ip6_tables.h b/include/uapi/linux/netfilter_ipv6/ip6_tables.h
deleted file mode 100644
index 7ae314b..0000000
--- a/include/uapi/linux/netfilter_ipv6/ip6_tables.h
+++ /dev/null
@@ -1,270 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * 25-Jul-1998 Major changes to allow for ip chain table
- *
- * 3-Jan-2000 Named tables to allow packet selection for different uses.
- */
-
-/*
- * 	Format of an IP6 firewall descriptor
- *
- * 	src, dst, src_mask, dst_mask are always stored in network byte order.
- * 	flags are stored in host byte order (of course).
- * 	Port numbers are stored in HOST byte order.
- */
-
-#ifndef _IP6_TABLES_H
-#define _IP6_TABLES_H
-
-#include <linux/types.h>
-
-#include <linux/if.h>
-#include <linux/netfilter_ipv6.h>
-
-#include <linux/netfilter/x_tables.h>
-
-#define IP6T_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
-#define IP6T_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
-#define ip6t_match xt_match
-#define ip6t_target xt_target
-#define ip6t_table xt_table
-#define ip6t_get_revision xt_get_revision
-#define ip6t_entry_match xt_entry_match
-#define ip6t_entry_target xt_entry_target
-#define ip6t_standard_target xt_standard_target
-#define ip6t_error_target xt_error_target
-#define ip6t_counters xt_counters
-#define IP6T_CONTINUE XT_CONTINUE
-#define IP6T_RETURN XT_RETURN
-
-/* Pre-iptables-1.4.0 */
-#include <linux/netfilter/xt_tcpudp.h>
-#define ip6t_tcp xt_tcp
-#define ip6t_udp xt_udp
-#define IP6T_TCP_INV_SRCPT	XT_TCP_INV_SRCPT
-#define IP6T_TCP_INV_DSTPT	XT_TCP_INV_DSTPT
-#define IP6T_TCP_INV_FLAGS	XT_TCP_INV_FLAGS
-#define IP6T_TCP_INV_OPTION	XT_TCP_INV_OPTION
-#define IP6T_TCP_INV_MASK	XT_TCP_INV_MASK
-#define IP6T_UDP_INV_SRCPT	XT_UDP_INV_SRCPT
-#define IP6T_UDP_INV_DSTPT	XT_UDP_INV_DSTPT
-#define IP6T_UDP_INV_MASK	XT_UDP_INV_MASK
-
-#define ip6t_counters_info xt_counters_info
-#define IP6T_STANDARD_TARGET XT_STANDARD_TARGET
-#define IP6T_ERROR_TARGET XT_ERROR_TARGET
-#define IP6T_MATCH_ITERATE(e, fn, args...) \
-	XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args)
-#define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
-	XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args)
-
-/* Yes, Virginia, you have to zero the padding. */
-struct ip6t_ip6 {
-	/* Source and destination IP6 addr */
-	struct in6_addr src, dst;		
-	/* Mask for src and dest IP6 addr */
-	struct in6_addr smsk, dmsk;
-	char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
-	unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
-
-	/* Upper protocol number
-	 * - The allowed value is 0 (any) or protocol number of last parsable
-	 *   header, which is 50 (ESP), 59 (No Next Header), 135 (MH), or
-	 *   the non IPv6 extension headers.
-	 * - The protocol numbers of IPv6 extension headers except of ESP and
-	 *   MH do not match any packets.
-	 * - You also need to set IP6T_FLAGS_PROTO to "flags" to check protocol.
-	 */
-	__u16 proto;
-	/* TOS to match iff flags & IP6T_F_TOS */
-	__u8 tos;
-
-	/* Flags word */
-	__u8 flags;
-	/* Inverse flags */
-	__u8 invflags;
-};
-
-/* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
-#define IP6T_F_PROTO		0x01	/* Set if rule cares about upper 
-					   protocols */
-#define IP6T_F_TOS		0x02	/* Match the TOS. */
-#define IP6T_F_GOTO		0x04	/* Set if jump is a goto */
-#define IP6T_F_MASK		0x07	/* All possible flag bits mask. */
-
-/* Values for "inv" field in struct ip6t_ip6. */
-#define IP6T_INV_VIA_IN		0x01	/* Invert the sense of IN IFACE. */
-#define IP6T_INV_VIA_OUT		0x02	/* Invert the sense of OUT IFACE */
-#define IP6T_INV_TOS		0x04	/* Invert the sense of TOS. */
-#define IP6T_INV_SRCIP		0x08	/* Invert the sense of SRC IP. */
-#define IP6T_INV_DSTIP		0x10	/* Invert the sense of DST OP. */
-#define IP6T_INV_FRAG		0x20	/* Invert the sense of FRAG. */
-#define IP6T_INV_PROTO		XT_INV_PROTO
-#define IP6T_INV_MASK		0x7F	/* All possible flag bits mask. */
-
-/* This structure defines each of the firewall rules.  Consists of 3
-   parts which are 1) general IP header stuff 2) match specific
-   stuff 3) the target to perform if the rule matches */
-struct ip6t_entry {
-	struct ip6t_ip6 ipv6;
-
-	/* Mark with fields that we care about. */
-	unsigned int nfcache;
-
-	/* Size of ipt_entry + matches */
-	__u16 target_offset;
-	/* Size of ipt_entry + matches + target */
-	__u16 next_offset;
-
-	/* Back pointer */
-	unsigned int comefrom;
-
-	/* Packet and byte counters. */
-	struct xt_counters counters;
-
-	/* The matches (if any), then the target. */
-	unsigned char elems[0];
-};
-
-/* Standard entry */
-struct ip6t_standard {
-	struct ip6t_entry entry;
-	struct xt_standard_target target;
-};
-
-struct ip6t_error {
-	struct ip6t_entry entry;
-	struct xt_error_target target;
-};
-
-#define IP6T_ENTRY_INIT(__size)						       \
-{									       \
-	.target_offset	= sizeof(struct ip6t_entry),			       \
-	.next_offset	= (__size),					       \
-}
-
-#define IP6T_STANDARD_INIT(__verdict)					       \
-{									       \
-	.entry		= IP6T_ENTRY_INIT(sizeof(struct ip6t_standard)),       \
-	.target		= XT_TARGET_INIT(XT_STANDARD_TARGET,		       \
-					 sizeof(struct xt_standard_target)),   \
-	.target.verdict	= -(__verdict) - 1,				       \
-}
-
-#define IP6T_ERROR_INIT							       \
-{									       \
-	.entry		= IP6T_ENTRY_INIT(sizeof(struct ip6t_error)),	       \
-	.target		= XT_TARGET_INIT(XT_ERROR_TARGET,		       \
-					 sizeof(struct xt_error_target)),      \
-	.target.errorname = "ERROR",					       \
-}
-
-/*
- * New IP firewall options for [gs]etsockopt at the RAW IP level.
- * Unlike BSD Linux inherits IP options so you don't have to use
- * a raw socket for this. Instead we check rights in the calls.
- *
- * ATTENTION: check linux/in6.h before adding new number here.
- */
-#define IP6T_BASE_CTL			64
-
-#define IP6T_SO_SET_REPLACE		(IP6T_BASE_CTL)
-#define IP6T_SO_SET_ADD_COUNTERS	(IP6T_BASE_CTL + 1)
-#define IP6T_SO_SET_MAX			IP6T_SO_SET_ADD_COUNTERS
-
-#define IP6T_SO_GET_INFO		(IP6T_BASE_CTL)
-#define IP6T_SO_GET_ENTRIES		(IP6T_BASE_CTL + 1)
-#define IP6T_SO_GET_REVISION_MATCH	(IP6T_BASE_CTL + 4)
-#define IP6T_SO_GET_REVISION_TARGET	(IP6T_BASE_CTL + 5)
-#define IP6T_SO_GET_MAX			IP6T_SO_GET_REVISION_TARGET
-
-/* obtain original address if REDIRECT'd connection */
-#define IP6T_SO_ORIGINAL_DST            80
-
-/* ICMP matching stuff */
-struct ip6t_icmp {
-	__u8 type;				/* type to match */
-	__u8 code[2];				/* range of code */
-	__u8 invflags;				/* Inverse flags */
-};
-
-/* Values for "inv" field for struct ipt_icmp. */
-#define IP6T_ICMP_INV	0x01	/* Invert the sense of type/code test */
-
-/* The argument to IP6T_SO_GET_INFO */
-struct ip6t_getinfo {
-	/* Which table: caller fills this in. */
-	char name[XT_TABLE_MAXNAMELEN];
-
-	/* Kernel fills these in. */
-	/* Which hook entry points are valid: bitmask */
-	unsigned int valid_hooks;
-
-	/* Hook entry points: one per netfilter hook. */
-	unsigned int hook_entry[NF_INET_NUMHOOKS];
-
-	/* Underflow points. */
-	unsigned int underflow[NF_INET_NUMHOOKS];
-
-	/* Number of entries */
-	unsigned int num_entries;
-
-	/* Size of entries. */
-	unsigned int size;
-};
-
-/* The argument to IP6T_SO_SET_REPLACE. */
-struct ip6t_replace {
-	/* Which table. */
-	char name[XT_TABLE_MAXNAMELEN];
-
-	/* Which hook entry points are valid: bitmask.  You can't
-           change this. */
-	unsigned int valid_hooks;
-
-	/* Number of entries */
-	unsigned int num_entries;
-
-	/* Total size of new entries */
-	unsigned int size;
-
-	/* Hook entry points. */
-	unsigned int hook_entry[NF_INET_NUMHOOKS];
-
-	/* Underflow points. */
-	unsigned int underflow[NF_INET_NUMHOOKS];
-
-	/* Information about old entries: */
-	/* Number of counters (must be equal to current number of entries). */
-	unsigned int num_counters;
-	/* The old entries' counters. */
-	struct xt_counters *counters;
-
-	/* The entries (hang off end: not really an array). */
-	struct ip6t_entry entries[0];
-};
-
-/* The argument to IP6T_SO_GET_ENTRIES. */
-struct ip6t_get_entries {
-	/* Which table: user fills this in. */
-	char name[XT_TABLE_MAXNAMELEN];
-
-	/* User fills this in: total entry size. */
-	unsigned int size;
-
-	/* The entries. */
-	struct ip6t_entry entrytable[0];
-};
-
-/* Helper functions */
-static __inline__ struct xt_entry_target *
-ip6t_get_target(struct ip6t_entry *e)
-{
-	return (void *)e + e->target_offset;
-}
-
-/*
- *	Main firewall chains definitions and global var's definitions.
- */
-
-#endif /* _IP6_TABLES_H */
diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h
deleted file mode 100644
index b56c5b8..0000000
--- a/include/uapi/linux/nexthop.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_NEXTHOP_H
-#define _LINUX_NEXTHOP_H
-
-#include <linux/types.h>
-
-struct nhmsg {
-	unsigned char	nh_family;
-	unsigned char	nh_scope;     /* return only */
-	unsigned char	nh_protocol;  /* Routing protocol that installed nh */
-	unsigned char	resvd;
-	unsigned int	nh_flags;     /* RTNH_F flags */
-};
-
-/* entry in a nexthop group */
-struct nexthop_grp {
-	__u32	id;	  /* nexthop id - must exist */
-	__u8	weight;   /* weight of this nexthop */
-	__u8	resvd1;
-	__u16	resvd2;
-};
-
-enum {
-	NEXTHOP_GRP_TYPE_MPATH,  /* default type if not specified */
-	__NEXTHOP_GRP_TYPE_MAX,
-};
-
-#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
-
-enum {
-	NHA_UNSPEC,
-	NHA_ID,		/* u32; id for nexthop. id == 0 means auto-assign */
-
-	NHA_GROUP,	/* array of nexthop_grp */
-	NHA_GROUP_TYPE,	/* u16 one of NEXTHOP_GRP_TYPE */
-	/* if NHA_GROUP attribute is added, no other attributes can be set */
-
-	NHA_BLACKHOLE,	/* flag; nexthop used to blackhole packets */
-	/* if NHA_BLACKHOLE is added, OIF, GATEWAY, ENCAP can not be set */
-
-	NHA_OIF,	/* u32; nexthop device */
-	NHA_GATEWAY,	/* be32 (IPv4) or in6_addr (IPv6) gw address */
-	NHA_ENCAP_TYPE, /* u16; lwt encap type */
-	NHA_ENCAP,	/* lwt encap data */
-
-	/* NHA_OIF can be appended to dump request to return only
-	 * nexthops using given device
-	 */
-	NHA_GROUPS,	/* flag; only return nexthop groups in dump */
-	NHA_MASTER,	/* u32;  only return nexthops with given master dev */
-
-	__NHA_MAX,
-};
-
-#define NHA_MAX	(__NHA_MAX - 1)
-#endif
diff --git a/include/uapi/linux/param.h b/include/uapi/linux/param.h
deleted file mode 100644
index 94e0c57..0000000
--- a/include/uapi/linux/param.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_PARAM_H
-#define _LINUX_PARAM_H
-
-#include <asm/param.h>
-
-#endif
diff --git a/include/uapi/linux/pfkeyv2.h b/include/uapi/linux/pfkeyv2.h
deleted file mode 100644
index d65b117..0000000
--- a/include/uapi/linux/pfkeyv2.h
+++ /dev/null
@@ -1,384 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* PF_KEY user interface, this is defined by rfc2367 so
- * do not make arbitrary modifications or else this header
- * file will not be compliant.
- */
-
-#ifndef _LINUX_PFKEY2_H
-#define _LINUX_PFKEY2_H
-
-#include <linux/types.h>
-
-#define PF_KEY_V2		2
-#define PFKEYV2_REVISION	199806L
-
-struct sadb_msg {
-	__u8		sadb_msg_version;
-	__u8		sadb_msg_type;
-	__u8		sadb_msg_errno;
-	__u8		sadb_msg_satype;
-	__u16	sadb_msg_len;
-	__u16	sadb_msg_reserved;
-	__u32	sadb_msg_seq;
-	__u32	sadb_msg_pid;
-} __attribute__((packed));
-/* sizeof(struct sadb_msg) == 16 */
-
-struct sadb_ext {
-	__u16	sadb_ext_len;
-	__u16	sadb_ext_type;
-} __attribute__((packed));
-/* sizeof(struct sadb_ext) == 4 */
-
-struct sadb_sa {
-	__u16	sadb_sa_len;
-	__u16	sadb_sa_exttype;
-	__be32		sadb_sa_spi;
-	__u8		sadb_sa_replay;
-	__u8		sadb_sa_state;
-	__u8		sadb_sa_auth;
-	__u8		sadb_sa_encrypt;
-	__u32	sadb_sa_flags;
-} __attribute__((packed));
-/* sizeof(struct sadb_sa) == 16 */
-
-struct sadb_lifetime {
-	__u16	sadb_lifetime_len;
-	__u16	sadb_lifetime_exttype;
-	__u32	sadb_lifetime_allocations;
-	__u64	sadb_lifetime_bytes;
-	__u64	sadb_lifetime_addtime;
-	__u64	sadb_lifetime_usetime;
-} __attribute__((packed));
-/* sizeof(struct sadb_lifetime) == 32 */
-
-struct sadb_address {
-	__u16	sadb_address_len;
-	__u16	sadb_address_exttype;
-	__u8		sadb_address_proto;
-	__u8		sadb_address_prefixlen;
-	__u16	sadb_address_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_address) == 8 */
-
-struct sadb_key {
-	__u16	sadb_key_len;
-	__u16	sadb_key_exttype;
-	__u16	sadb_key_bits;
-	__u16	sadb_key_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_key) == 8 */
-
-struct sadb_ident {
-	__u16	sadb_ident_len;
-	__u16	sadb_ident_exttype;
-	__u16	sadb_ident_type;
-	__u16	sadb_ident_reserved;
-	__u64	sadb_ident_id;
-} __attribute__((packed));
-/* sizeof(struct sadb_ident) == 16 */
-
-struct sadb_sens {
-	__u16	sadb_sens_len;
-	__u16	sadb_sens_exttype;
-	__u32	sadb_sens_dpd;
-	__u8		sadb_sens_sens_level;
-	__u8		sadb_sens_sens_len;
-	__u8		sadb_sens_integ_level;
-	__u8		sadb_sens_integ_len;
-	__u32	sadb_sens_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_sens) == 16 */
-
-/* followed by:
-	__u64	sadb_sens_bitmap[sens_len];
-	__u64	sadb_integ_bitmap[integ_len];  */
-
-struct sadb_prop {
-	__u16	sadb_prop_len;
-	__u16	sadb_prop_exttype;
-	__u8		sadb_prop_replay;
-	__u8		sadb_prop_reserved[3];
-} __attribute__((packed));
-/* sizeof(struct sadb_prop) == 8 */
-
-/* followed by:
-	struct sadb_comb sadb_combs[(sadb_prop_len +
-		sizeof(__u64) - sizeof(struct sadb_prop)) /
-		sizeof(struct sadb_comb)]; */
-
-struct sadb_comb {
-	__u8		sadb_comb_auth;
-	__u8		sadb_comb_encrypt;
-	__u16	sadb_comb_flags;
-	__u16	sadb_comb_auth_minbits;
-	__u16	sadb_comb_auth_maxbits;
-	__u16	sadb_comb_encrypt_minbits;
-	__u16	sadb_comb_encrypt_maxbits;
-	__u32	sadb_comb_reserved;
-	__u32	sadb_comb_soft_allocations;
-	__u32	sadb_comb_hard_allocations;
-	__u64	sadb_comb_soft_bytes;
-	__u64	sadb_comb_hard_bytes;
-	__u64	sadb_comb_soft_addtime;
-	__u64	sadb_comb_hard_addtime;
-	__u64	sadb_comb_soft_usetime;
-	__u64	sadb_comb_hard_usetime;
-} __attribute__((packed));
-/* sizeof(struct sadb_comb) == 72 */
-
-struct sadb_supported {
-	__u16	sadb_supported_len;
-	__u16	sadb_supported_exttype;
-	__u32	sadb_supported_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_supported) == 8 */
-
-/* followed by:
-	struct sadb_alg sadb_algs[(sadb_supported_len +
-		sizeof(__u64) - sizeof(struct sadb_supported)) /
-		sizeof(struct sadb_alg)]; */
-
-struct sadb_alg {
-	__u8		sadb_alg_id;
-	__u8		sadb_alg_ivlen;
-	__u16	sadb_alg_minbits;
-	__u16	sadb_alg_maxbits;
-	__u16	sadb_alg_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_alg) == 8 */
-
-struct sadb_spirange {
-	__u16	sadb_spirange_len;
-	__u16	sadb_spirange_exttype;
-	__u32	sadb_spirange_min;
-	__u32	sadb_spirange_max;
-	__u32	sadb_spirange_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_spirange) == 16 */
-
-struct sadb_x_kmprivate {
-	__u16	sadb_x_kmprivate_len;
-	__u16	sadb_x_kmprivate_exttype;
-	__u32	sadb_x_kmprivate_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_kmprivate) == 8 */
-
-struct sadb_x_sa2 {
-	__u16	sadb_x_sa2_len;
-	__u16	sadb_x_sa2_exttype;
-	__u8		sadb_x_sa2_mode;
-	__u8		sadb_x_sa2_reserved1;
-	__u16	sadb_x_sa2_reserved2;
-	__u32	sadb_x_sa2_sequence;
-	__u32	sadb_x_sa2_reqid;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_sa2) == 16 */
-
-struct sadb_x_policy {
-	__u16	sadb_x_policy_len;
-	__u16	sadb_x_policy_exttype;
-	__u16	sadb_x_policy_type;
-	__u8		sadb_x_policy_dir;
-	__u8		sadb_x_policy_reserved;
-	__u32	sadb_x_policy_id;
-	__u32	sadb_x_policy_priority;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_policy) == 16 */
-
-struct sadb_x_ipsecrequest {
-	__u16	sadb_x_ipsecrequest_len;
-	__u16	sadb_x_ipsecrequest_proto;
-	__u8		sadb_x_ipsecrequest_mode;
-	__u8		sadb_x_ipsecrequest_level;
-	__u16	sadb_x_ipsecrequest_reserved1;
-	__u32	sadb_x_ipsecrequest_reqid;
-	__u32	sadb_x_ipsecrequest_reserved2;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_ipsecrequest) == 16 */
-
-/* This defines the TYPE of Nat Traversal in use.  Currently only one
- * type of NAT-T is supported, draft-ietf-ipsec-udp-encaps-06
- */
-struct sadb_x_nat_t_type {
-	__u16	sadb_x_nat_t_type_len;
-	__u16	sadb_x_nat_t_type_exttype;
-	__u8		sadb_x_nat_t_type_type;
-	__u8		sadb_x_nat_t_type_reserved[3];
-} __attribute__((packed));
-/* sizeof(struct sadb_x_nat_t_type) == 8 */
-
-/* Pass a NAT Traversal port (Source or Dest port) */
-struct sadb_x_nat_t_port {
-	__u16	sadb_x_nat_t_port_len;
-	__u16	sadb_x_nat_t_port_exttype;
-	__be16		sadb_x_nat_t_port_port;
-	__u16	sadb_x_nat_t_port_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_nat_t_port) == 8 */
-
-/* Generic LSM security context */
-struct sadb_x_sec_ctx {
-	__u16	sadb_x_sec_len;
-	__u16	sadb_x_sec_exttype;
-	__u8		sadb_x_ctx_alg;  /* LSMs: e.g., selinux == 1 */
-	__u8		sadb_x_ctx_doi;
-	__u16	sadb_x_ctx_len;
-} __attribute__((packed));
-/* sizeof(struct sadb_sec_ctx) = 8 */
-
-/* Used by MIGRATE to pass addresses IKE will use to perform
- * negotiation with the peer */
-struct sadb_x_kmaddress {
-	__u16	sadb_x_kmaddress_len;
-	__u16	sadb_x_kmaddress_exttype;
-	__u32	sadb_x_kmaddress_reserved;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_kmaddress) == 8 */
-
-/* To specify the SA dump filter */
-struct sadb_x_filter {
-	__u16	sadb_x_filter_len;
-	__u16	sadb_x_filter_exttype;
-	__u32	sadb_x_filter_saddr[4];
-	__u32	sadb_x_filter_daddr[4];
-	__u16	sadb_x_filter_family;
-	__u8	sadb_x_filter_splen;
-	__u8	sadb_x_filter_dplen;
-} __attribute__((packed));
-/* sizeof(struct sadb_x_filter) == 40 */
-
-/* Message types */
-#define SADB_RESERVED		0
-#define SADB_GETSPI		1
-#define SADB_UPDATE		2
-#define SADB_ADD		3
-#define SADB_DELETE		4
-#define SADB_GET		5
-#define SADB_ACQUIRE		6
-#define SADB_REGISTER		7
-#define SADB_EXPIRE		8
-#define SADB_FLUSH		9
-#define SADB_DUMP		10
-#define SADB_X_PROMISC		11
-#define SADB_X_PCHANGE		12
-#define SADB_X_SPDUPDATE	13
-#define SADB_X_SPDADD		14
-#define SADB_X_SPDDELETE	15
-#define SADB_X_SPDGET		16
-#define SADB_X_SPDACQUIRE	17
-#define SADB_X_SPDDUMP		18
-#define SADB_X_SPDFLUSH		19
-#define SADB_X_SPDSETIDX	20
-#define SADB_X_SPDEXPIRE	21
-#define SADB_X_SPDDELETE2	22
-#define SADB_X_NAT_T_NEW_MAPPING	23
-#define SADB_X_MIGRATE		24
-#define SADB_MAX		24
-
-/* Security Association flags */
-#define SADB_SAFLAGS_PFS	1
-#define SADB_SAFLAGS_NOPMTUDISC	0x20000000
-#define SADB_SAFLAGS_DECAP_DSCP	0x40000000
-#define SADB_SAFLAGS_NOECN	0x80000000
-
-/* Security Association states */
-#define SADB_SASTATE_LARVAL	0
-#define SADB_SASTATE_MATURE	1
-#define SADB_SASTATE_DYING	2
-#define SADB_SASTATE_DEAD	3
-#define SADB_SASTATE_MAX	3
-
-/* Security Association types */
-#define SADB_SATYPE_UNSPEC	0
-#define SADB_SATYPE_AH		2
-#define SADB_SATYPE_ESP		3
-#define SADB_SATYPE_RSVP	5
-#define SADB_SATYPE_OSPFV2	6
-#define SADB_SATYPE_RIPV2	7
-#define SADB_SATYPE_MIP		8
-#define SADB_X_SATYPE_IPCOMP	9
-#define SADB_SATYPE_MAX		9
-
-/* Authentication algorithms */
-#define SADB_AALG_NONE			0
-#define SADB_AALG_MD5HMAC		2
-#define SADB_AALG_SHA1HMAC		3
-#define SADB_X_AALG_SHA2_256HMAC	5
-#define SADB_X_AALG_SHA2_384HMAC	6
-#define SADB_X_AALG_SHA2_512HMAC	7
-#define SADB_X_AALG_RIPEMD160HMAC	8
-#define SADB_X_AALG_AES_XCBC_MAC	9
-#define SADB_X_AALG_NULL		251	/* kame */
-#define SADB_AALG_MAX			251
-
-/* Encryption algorithms */
-#define SADB_EALG_NONE			0
-#define SADB_EALG_DESCBC		2
-#define SADB_EALG_3DESCBC		3
-#define SADB_X_EALG_CASTCBC		6
-#define SADB_X_EALG_BLOWFISHCBC		7
-#define SADB_EALG_NULL			11
-#define SADB_X_EALG_AESCBC		12
-#define SADB_X_EALG_AESCTR		13
-#define SADB_X_EALG_AES_CCM_ICV8	14
-#define SADB_X_EALG_AES_CCM_ICV12	15
-#define SADB_X_EALG_AES_CCM_ICV16	16
-#define SADB_X_EALG_AES_GCM_ICV8	18
-#define SADB_X_EALG_AES_GCM_ICV12	19
-#define SADB_X_EALG_AES_GCM_ICV16	20
-#define SADB_X_EALG_CAMELLIACBC		22
-#define SADB_X_EALG_NULL_AES_GMAC	23
-#define SADB_EALG_MAX                   253 /* last EALG */
-/* private allocations should use 249-255 (RFC2407) */
-#define SADB_X_EALG_SERPENTCBC  252     /* draft-ietf-ipsec-ciph-aes-cbc-00 */
-#define SADB_X_EALG_TWOFISHCBC  253     /* draft-ietf-ipsec-ciph-aes-cbc-00 */
-
-/* Compression algorithms */
-#define SADB_X_CALG_NONE		0
-#define SADB_X_CALG_OUI			1
-#define SADB_X_CALG_DEFLATE		2
-#define SADB_X_CALG_LZS			3
-#define SADB_X_CALG_LZJH		4
-#define SADB_X_CALG_MAX			4
-
-/* Extension Header values */
-#define SADB_EXT_RESERVED		0
-#define SADB_EXT_SA			1
-#define SADB_EXT_LIFETIME_CURRENT	2
-#define SADB_EXT_LIFETIME_HARD		3
-#define SADB_EXT_LIFETIME_SOFT		4
-#define SADB_EXT_ADDRESS_SRC		5
-#define SADB_EXT_ADDRESS_DST		6
-#define SADB_EXT_ADDRESS_PROXY		7
-#define SADB_EXT_KEY_AUTH		8
-#define SADB_EXT_KEY_ENCRYPT		9
-#define SADB_EXT_IDENTITY_SRC		10
-#define SADB_EXT_IDENTITY_DST		11
-#define SADB_EXT_SENSITIVITY		12
-#define SADB_EXT_PROPOSAL		13
-#define SADB_EXT_SUPPORTED_AUTH		14
-#define SADB_EXT_SUPPORTED_ENCRYPT	15
-#define SADB_EXT_SPIRANGE		16
-#define SADB_X_EXT_KMPRIVATE		17
-#define SADB_X_EXT_POLICY		18
-#define SADB_X_EXT_SA2			19
-/* The next four entries are for setting up NAT Traversal */
-#define SADB_X_EXT_NAT_T_TYPE		20
-#define SADB_X_EXT_NAT_T_SPORT		21
-#define SADB_X_EXT_NAT_T_DPORT		22
-#define SADB_X_EXT_NAT_T_OA		23
-#define SADB_X_EXT_SEC_CTX		24
-/* Used with MIGRATE to pass @ to IKE for negotiation */
-#define SADB_X_EXT_KMADDRESS		25
-#define SADB_X_EXT_FILTER		26
-#define SADB_EXT_MAX			26
-
-/* Identity Extension values */
-#define SADB_IDENTTYPE_RESERVED	0
-#define SADB_IDENTTYPE_PREFIX	1
-#define SADB_IDENTTYPE_FQDN	2
-#define SADB_IDENTTYPE_USERFQDN	3
-#define SADB_IDENTTYPE_MAX	3
-
-#endif /* !(_LINUX_PFKEY2_H) */
diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
deleted file mode 100644
index a6aa466..0000000
--- a/include/uapi/linux/pkt_cls.h
+++ /dev/null
@@ -1,690 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_PKT_CLS_H
-#define __LINUX_PKT_CLS_H
-
-#include <linux/types.h>
-#include <linux/pkt_sched.h>
-
-#define TC_COOKIE_MAX_SIZE 16
-
-/* Action attributes */
-enum {
-	TCA_ACT_UNSPEC,
-	TCA_ACT_KIND,
-	TCA_ACT_OPTIONS,
-	TCA_ACT_INDEX,
-	TCA_ACT_STATS,
-	TCA_ACT_PAD,
-	TCA_ACT_COOKIE,
-	__TCA_ACT_MAX
-};
-
-#define TCA_ACT_MAX __TCA_ACT_MAX
-#define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
-#define TCA_ACT_MAX_PRIO 32
-#define TCA_ACT_BIND	1
-#define TCA_ACT_NOBIND	0
-#define TCA_ACT_UNBIND	1
-#define TCA_ACT_NOUNBIND	0
-#define TCA_ACT_REPLACE		1
-#define TCA_ACT_NOREPLACE	0
-
-#define TC_ACT_UNSPEC	(-1)
-#define TC_ACT_OK		0
-#define TC_ACT_RECLASSIFY	1
-#define TC_ACT_SHOT		2
-#define TC_ACT_PIPE		3
-#define TC_ACT_STOLEN		4
-#define TC_ACT_QUEUED		5
-#define TC_ACT_REPEAT		6
-#define TC_ACT_REDIRECT		7
-#define TC_ACT_TRAP		8 /* For hw path, this means "trap to cpu"
-				   * and don't further process the frame
-				   * in hardware. For sw path, this is
-				   * equivalent of TC_ACT_STOLEN - drop
-				   * the skb and act like everything
-				   * is alright.
-				   */
-#define TC_ACT_VALUE_MAX	TC_ACT_TRAP
-
-/* There is a special kind of actions called "extended actions",
- * which need a value parameter. These have a local opcode located in
- * the highest nibble, starting from 1. The rest of the bits
- * are used to carry the value. These two parts together make
- * a combined opcode.
- */
-#define __TC_ACT_EXT_SHIFT 28
-#define __TC_ACT_EXT(local) ((local) << __TC_ACT_EXT_SHIFT)
-#define TC_ACT_EXT_VAL_MASK ((1 << __TC_ACT_EXT_SHIFT) - 1)
-#define TC_ACT_EXT_OPCODE(combined) ((combined) & (~TC_ACT_EXT_VAL_MASK))
-#define TC_ACT_EXT_CMP(combined, opcode) (TC_ACT_EXT_OPCODE(combined) == opcode)
-
-#define TC_ACT_JUMP __TC_ACT_EXT(1)
-#define TC_ACT_GOTO_CHAIN __TC_ACT_EXT(2)
-#define TC_ACT_EXT_OPCODE_MAX	TC_ACT_GOTO_CHAIN
-
-/* These macros are put here for binary compatibility with userspace apps that
- * make use of them. For kernel code and new userspace apps, use the TCA_ID_*
- * versions.
- */
-#define TCA_ACT_GACT 5
-#define TCA_ACT_IPT 6
-#define TCA_ACT_PEDIT 7
-#define TCA_ACT_MIRRED 8
-#define TCA_ACT_NAT 9
-#define TCA_ACT_XT 10
-#define TCA_ACT_SKBEDIT 11
-#define TCA_ACT_VLAN 12
-#define TCA_ACT_BPF 13
-#define TCA_ACT_CONNMARK 14
-#define TCA_ACT_SKBMOD 15
-#define TCA_ACT_CSUM 16
-#define TCA_ACT_TUNNEL_KEY 17
-#define TCA_ACT_SIMP 22
-#define TCA_ACT_IFE 25
-#define TCA_ACT_SAMPLE 26
-
-/* Action type identifiers*/
-enum tca_id {
-	TCA_ID_UNSPEC = 0,
-	TCA_ID_POLICE = 1,
-	TCA_ID_GACT = TCA_ACT_GACT,
-	TCA_ID_IPT = TCA_ACT_IPT,
-	TCA_ID_PEDIT = TCA_ACT_PEDIT,
-	TCA_ID_MIRRED = TCA_ACT_MIRRED,
-	TCA_ID_NAT = TCA_ACT_NAT,
-	TCA_ID_XT = TCA_ACT_XT,
-	TCA_ID_SKBEDIT = TCA_ACT_SKBEDIT,
-	TCA_ID_VLAN = TCA_ACT_VLAN,
-	TCA_ID_BPF = TCA_ACT_BPF,
-	TCA_ID_CONNMARK = TCA_ACT_CONNMARK,
-	TCA_ID_SKBMOD = TCA_ACT_SKBMOD,
-	TCA_ID_CSUM = TCA_ACT_CSUM,
-	TCA_ID_TUNNEL_KEY = TCA_ACT_TUNNEL_KEY,
-	TCA_ID_SIMP = TCA_ACT_SIMP,
-	TCA_ID_IFE = TCA_ACT_IFE,
-	TCA_ID_SAMPLE = TCA_ACT_SAMPLE,
-	TCA_ID_CTINFO,
-	TCA_ID_MPLS,
-	TCA_ID_CT,
-	/* other actions go here */
-	__TCA_ID_MAX = 255
-};
-
-#define TCA_ID_MAX __TCA_ID_MAX
-
-struct tc_police {
-	__u32			index;
-	int			action;
-#define TC_POLICE_UNSPEC	TC_ACT_UNSPEC
-#define TC_POLICE_OK		TC_ACT_OK
-#define TC_POLICE_RECLASSIFY	TC_ACT_RECLASSIFY
-#define TC_POLICE_SHOT		TC_ACT_SHOT
-#define TC_POLICE_PIPE		TC_ACT_PIPE
-
-	__u32			limit;
-	__u32			burst;
-	__u32			mtu;
-	struct tc_ratespec	rate;
-	struct tc_ratespec	peakrate;
-	int			refcnt;
-	int			bindcnt;
-	__u32			capab;
-};
-
-struct tcf_t {
-	__u64   install;
-	__u64   lastuse;
-	__u64   expires;
-	__u64   firstuse;
-};
-
-struct tc_cnt {
-	int                   refcnt;
-	int                   bindcnt;
-};
-
-#define tc_gen \
-	__u32                 index; \
-	__u32                 capab; \
-	int                   action; \
-	int                   refcnt; \
-	int                   bindcnt
-
-enum {
-	TCA_POLICE_UNSPEC,
-	TCA_POLICE_TBF,
-	TCA_POLICE_RATE,
-	TCA_POLICE_PEAKRATE,
-	TCA_POLICE_AVRATE,
-	TCA_POLICE_RESULT,
-	TCA_POLICE_TM,
-	TCA_POLICE_PAD,
-	TCA_POLICE_RATE64,
-	TCA_POLICE_PEAKRATE64,
-	__TCA_POLICE_MAX
-#define TCA_POLICE_RESULT TCA_POLICE_RESULT
-};
-
-#define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
-
-/* tca flags definitions */
-#define TCA_CLS_FLAGS_SKIP_HW	(1 << 0) /* don't offload filter to HW */
-#define TCA_CLS_FLAGS_SKIP_SW	(1 << 1) /* don't use filter in SW */
-#define TCA_CLS_FLAGS_IN_HW	(1 << 2) /* filter is offloaded to HW */
-#define TCA_CLS_FLAGS_NOT_IN_HW (1 << 3) /* filter isn't offloaded to HW */
-#define TCA_CLS_FLAGS_VERBOSE	(1 << 4) /* verbose logging */
-
-/* U32 filters */
-
-#define TC_U32_HTID(h) ((h)&0xFFF00000)
-#define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
-#define TC_U32_HASH(h) (((h)>>12)&0xFF)
-#define TC_U32_NODE(h) ((h)&0xFFF)
-#define TC_U32_KEY(h) ((h)&0xFFFFF)
-#define TC_U32_UNSPEC	0
-#define TC_U32_ROOT	(0xFFF00000)
-
-enum {
-	TCA_U32_UNSPEC,
-	TCA_U32_CLASSID,
-	TCA_U32_HASH,
-	TCA_U32_LINK,
-	TCA_U32_DIVISOR,
-	TCA_U32_SEL,
-	TCA_U32_POLICE,
-	TCA_U32_ACT,
-	TCA_U32_INDEV,
-	TCA_U32_PCNT,
-	TCA_U32_MARK,
-	TCA_U32_FLAGS,
-	TCA_U32_PAD,
-	__TCA_U32_MAX
-};
-
-#define TCA_U32_MAX (__TCA_U32_MAX - 1)
-
-struct tc_u32_key {
-	__be32		mask;
-	__be32		val;
-	int		off;
-	int		offmask;
-};
-
-struct tc_u32_sel {
-	unsigned char		flags;
-	unsigned char		offshift;
-	unsigned char		nkeys;
-
-	__be16			offmask;
-	__u16			off;
-	short			offoff;
-
-	short			hoff;
-	__be32			hmask;
-	struct tc_u32_key	keys[0];
-};
-
-struct tc_u32_mark {
-	__u32		val;
-	__u32		mask;
-	__u32		success;
-};
-
-struct tc_u32_pcnt {
-	__u64 rcnt;
-	__u64 rhit;
-	__u64 kcnts[0];
-};
-
-/* Flags */
-
-#define TC_U32_TERMINAL		1
-#define TC_U32_OFFSET		2
-#define TC_U32_VAROFFSET	4
-#define TC_U32_EAT		8
-
-#define TC_U32_MAXDEPTH 8
-
-
-/* RSVP filter */
-
-enum {
-	TCA_RSVP_UNSPEC,
-	TCA_RSVP_CLASSID,
-	TCA_RSVP_DST,
-	TCA_RSVP_SRC,
-	TCA_RSVP_PINFO,
-	TCA_RSVP_POLICE,
-	TCA_RSVP_ACT,
-	__TCA_RSVP_MAX
-};
-
-#define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
-
-struct tc_rsvp_gpi {
-	__u32	key;
-	__u32	mask;
-	int	offset;
-};
-
-struct tc_rsvp_pinfo {
-	struct tc_rsvp_gpi dpi;
-	struct tc_rsvp_gpi spi;
-	__u8	protocol;
-	__u8	tunnelid;
-	__u8	tunnelhdr;
-	__u8	pad;
-};
-
-/* ROUTE filter */
-
-enum {
-	TCA_ROUTE4_UNSPEC,
-	TCA_ROUTE4_CLASSID,
-	TCA_ROUTE4_TO,
-	TCA_ROUTE4_FROM,
-	TCA_ROUTE4_IIF,
-	TCA_ROUTE4_POLICE,
-	TCA_ROUTE4_ACT,
-	__TCA_ROUTE4_MAX
-};
-
-#define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
-
-
-/* FW filter */
-
-enum {
-	TCA_FW_UNSPEC,
-	TCA_FW_CLASSID,
-	TCA_FW_POLICE,
-	TCA_FW_INDEV,
-	TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
-	TCA_FW_MASK,
-	__TCA_FW_MAX
-};
-
-#define TCA_FW_MAX (__TCA_FW_MAX - 1)
-
-/* TC index filter */
-
-enum {
-	TCA_TCINDEX_UNSPEC,
-	TCA_TCINDEX_HASH,
-	TCA_TCINDEX_MASK,
-	TCA_TCINDEX_SHIFT,
-	TCA_TCINDEX_FALL_THROUGH,
-	TCA_TCINDEX_CLASSID,
-	TCA_TCINDEX_POLICE,
-	TCA_TCINDEX_ACT,
-	__TCA_TCINDEX_MAX
-};
-
-#define TCA_TCINDEX_MAX     (__TCA_TCINDEX_MAX - 1)
-
-/* Flow filter */
-
-enum {
-	FLOW_KEY_SRC,
-	FLOW_KEY_DST,
-	FLOW_KEY_PROTO,
-	FLOW_KEY_PROTO_SRC,
-	FLOW_KEY_PROTO_DST,
-	FLOW_KEY_IIF,
-	FLOW_KEY_PRIORITY,
-	FLOW_KEY_MARK,
-	FLOW_KEY_NFCT,
-	FLOW_KEY_NFCT_SRC,
-	FLOW_KEY_NFCT_DST,
-	FLOW_KEY_NFCT_PROTO_SRC,
-	FLOW_KEY_NFCT_PROTO_DST,
-	FLOW_KEY_RTCLASSID,
-	FLOW_KEY_SKUID,
-	FLOW_KEY_SKGID,
-	FLOW_KEY_VLAN_TAG,
-	FLOW_KEY_RXHASH,
-	__FLOW_KEY_MAX,
-};
-
-#define FLOW_KEY_MAX	(__FLOW_KEY_MAX - 1)
-
-enum {
-	FLOW_MODE_MAP,
-	FLOW_MODE_HASH,
-};
-
-enum {
-	TCA_FLOW_UNSPEC,
-	TCA_FLOW_KEYS,
-	TCA_FLOW_MODE,
-	TCA_FLOW_BASECLASS,
-	TCA_FLOW_RSHIFT,
-	TCA_FLOW_ADDEND,
-	TCA_FLOW_MASK,
-	TCA_FLOW_XOR,
-	TCA_FLOW_DIVISOR,
-	TCA_FLOW_ACT,
-	TCA_FLOW_POLICE,
-	TCA_FLOW_EMATCHES,
-	TCA_FLOW_PERTURB,
-	__TCA_FLOW_MAX
-};
-
-#define TCA_FLOW_MAX	(__TCA_FLOW_MAX - 1)
-
-/* Basic filter */
-
-struct tc_basic_pcnt {
-	__u64 rcnt;
-	__u64 rhit;
-};
-
-enum {
-	TCA_BASIC_UNSPEC,
-	TCA_BASIC_CLASSID,
-	TCA_BASIC_EMATCHES,
-	TCA_BASIC_ACT,
-	TCA_BASIC_POLICE,
-	TCA_BASIC_PCNT,
-	TCA_BASIC_PAD,
-	__TCA_BASIC_MAX
-};
-
-#define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
-
-
-/* Cgroup classifier */
-
-enum {
-	TCA_CGROUP_UNSPEC,
-	TCA_CGROUP_ACT,
-	TCA_CGROUP_POLICE,
-	TCA_CGROUP_EMATCHES,
-	__TCA_CGROUP_MAX,
-};
-
-#define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
-
-/* BPF classifier */
-
-#define TCA_BPF_FLAG_ACT_DIRECT		(1 << 0)
-
-enum {
-	TCA_BPF_UNSPEC,
-	TCA_BPF_ACT,
-	TCA_BPF_POLICE,
-	TCA_BPF_CLASSID,
-	TCA_BPF_OPS_LEN,
-	TCA_BPF_OPS,
-	TCA_BPF_FD,
-	TCA_BPF_NAME,
-	TCA_BPF_FLAGS,
-	TCA_BPF_FLAGS_GEN,
-	TCA_BPF_TAG,
-	TCA_BPF_ID,
-	__TCA_BPF_MAX,
-};
-
-#define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
-
-/* Flower classifier */
-
-enum {
-	TCA_FLOWER_UNSPEC,
-	TCA_FLOWER_CLASSID,
-	TCA_FLOWER_INDEV,
-	TCA_FLOWER_ACT,
-	TCA_FLOWER_KEY_ETH_DST,		/* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_DST_MASK,	/* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_SRC,		/* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_SRC_MASK,	/* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_TYPE,	/* be16 */
-	TCA_FLOWER_KEY_IP_PROTO,	/* u8 */
-	TCA_FLOWER_KEY_IPV4_SRC,	/* be32 */
-	TCA_FLOWER_KEY_IPV4_SRC_MASK,	/* be32 */
-	TCA_FLOWER_KEY_IPV4_DST,	/* be32 */
-	TCA_FLOWER_KEY_IPV4_DST_MASK,	/* be32 */
-	TCA_FLOWER_KEY_IPV6_SRC,	/* struct in6_addr */
-	TCA_FLOWER_KEY_IPV6_SRC_MASK,	/* struct in6_addr */
-	TCA_FLOWER_KEY_IPV6_DST,	/* struct in6_addr */
-	TCA_FLOWER_KEY_IPV6_DST_MASK,	/* struct in6_addr */
-	TCA_FLOWER_KEY_TCP_SRC,		/* be16 */
-	TCA_FLOWER_KEY_TCP_DST,		/* be16 */
-	TCA_FLOWER_KEY_UDP_SRC,		/* be16 */
-	TCA_FLOWER_KEY_UDP_DST,		/* be16 */
-
-	TCA_FLOWER_FLAGS,
-	TCA_FLOWER_KEY_VLAN_ID,		/* be16 */
-	TCA_FLOWER_KEY_VLAN_PRIO,	/* u8   */
-	TCA_FLOWER_KEY_VLAN_ETH_TYPE,	/* be16 */
-
-	TCA_FLOWER_KEY_ENC_KEY_ID,	/* be32 */
-	TCA_FLOWER_KEY_ENC_IPV4_SRC,	/* be32 */
-	TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,/* be32 */
-	TCA_FLOWER_KEY_ENC_IPV4_DST,	/* be32 */
-	TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,/* be32 */
-	TCA_FLOWER_KEY_ENC_IPV6_SRC,	/* struct in6_addr */
-	TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,/* struct in6_addr */
-	TCA_FLOWER_KEY_ENC_IPV6_DST,	/* struct in6_addr */
-	TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,/* struct in6_addr */
-
-	TCA_FLOWER_KEY_TCP_SRC_MASK,	/* be16 */
-	TCA_FLOWER_KEY_TCP_DST_MASK,	/* be16 */
-	TCA_FLOWER_KEY_UDP_SRC_MASK,	/* be16 */
-	TCA_FLOWER_KEY_UDP_DST_MASK,	/* be16 */
-	TCA_FLOWER_KEY_SCTP_SRC_MASK,	/* be16 */
-	TCA_FLOWER_KEY_SCTP_DST_MASK,	/* be16 */
-
-	TCA_FLOWER_KEY_SCTP_SRC,	/* be16 */
-	TCA_FLOWER_KEY_SCTP_DST,	/* be16 */
-
-	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,	/* be16 */
-	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,	/* be16 */
-	TCA_FLOWER_KEY_ENC_UDP_DST_PORT,	/* be16 */
-	TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,	/* be16 */
-
-	TCA_FLOWER_KEY_FLAGS,		/* be32 */
-	TCA_FLOWER_KEY_FLAGS_MASK,	/* be32 */
-
-	TCA_FLOWER_KEY_ICMPV4_CODE,	/* u8 */
-	TCA_FLOWER_KEY_ICMPV4_CODE_MASK,/* u8 */
-	TCA_FLOWER_KEY_ICMPV4_TYPE,	/* u8 */
-	TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,/* u8 */
-	TCA_FLOWER_KEY_ICMPV6_CODE,	/* u8 */
-	TCA_FLOWER_KEY_ICMPV6_CODE_MASK,/* u8 */
-	TCA_FLOWER_KEY_ICMPV6_TYPE,	/* u8 */
-	TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,/* u8 */
-
-	TCA_FLOWER_KEY_ARP_SIP,		/* be32 */
-	TCA_FLOWER_KEY_ARP_SIP_MASK,	/* be32 */
-	TCA_FLOWER_KEY_ARP_TIP,		/* be32 */
-	TCA_FLOWER_KEY_ARP_TIP_MASK,	/* be32 */
-	TCA_FLOWER_KEY_ARP_OP,		/* u8 */
-	TCA_FLOWER_KEY_ARP_OP_MASK,	/* u8 */
-	TCA_FLOWER_KEY_ARP_SHA,		/* ETH_ALEN */
-	TCA_FLOWER_KEY_ARP_SHA_MASK,	/* ETH_ALEN */
-	TCA_FLOWER_KEY_ARP_THA,		/* ETH_ALEN */
-	TCA_FLOWER_KEY_ARP_THA_MASK,	/* ETH_ALEN */
-
-	TCA_FLOWER_KEY_MPLS_TTL,	/* u8 - 8 bits */
-	TCA_FLOWER_KEY_MPLS_BOS,	/* u8 - 1 bit */
-	TCA_FLOWER_KEY_MPLS_TC,		/* u8 - 3 bits */
-	TCA_FLOWER_KEY_MPLS_LABEL,	/* be32 - 20 bits */
-
-	TCA_FLOWER_KEY_TCP_FLAGS,	/* be16 */
-	TCA_FLOWER_KEY_TCP_FLAGS_MASK,	/* be16 */
-
-	TCA_FLOWER_KEY_IP_TOS,		/* u8 */
-	TCA_FLOWER_KEY_IP_TOS_MASK,	/* u8 */
-	TCA_FLOWER_KEY_IP_TTL,		/* u8 */
-	TCA_FLOWER_KEY_IP_TTL_MASK,	/* u8 */
-
-	TCA_FLOWER_KEY_CVLAN_ID,	/* be16 */
-	TCA_FLOWER_KEY_CVLAN_PRIO,	/* u8   */
-	TCA_FLOWER_KEY_CVLAN_ETH_TYPE,	/* be16 */
-
-	TCA_FLOWER_KEY_ENC_IP_TOS,	/* u8 */
-	TCA_FLOWER_KEY_ENC_IP_TOS_MASK,	/* u8 */
-	TCA_FLOWER_KEY_ENC_IP_TTL,	/* u8 */
-	TCA_FLOWER_KEY_ENC_IP_TTL_MASK,	/* u8 */
-
-	TCA_FLOWER_KEY_ENC_OPTS,
-	TCA_FLOWER_KEY_ENC_OPTS_MASK,
-
-	TCA_FLOWER_IN_HW_COUNT,
-
-	TCA_FLOWER_KEY_PORT_SRC_MIN,	/* be16 */
-	TCA_FLOWER_KEY_PORT_SRC_MAX,	/* be16 */
-	TCA_FLOWER_KEY_PORT_DST_MIN,	/* be16 */
-	TCA_FLOWER_KEY_PORT_DST_MAX,	/* be16 */
-
-	TCA_FLOWER_KEY_CT_STATE,	/* u16 */
-	TCA_FLOWER_KEY_CT_STATE_MASK,	/* u16 */
-	TCA_FLOWER_KEY_CT_ZONE,		/* u16 */
-	TCA_FLOWER_KEY_CT_ZONE_MASK,	/* u16 */
-	TCA_FLOWER_KEY_CT_MARK,		/* u32 */
-	TCA_FLOWER_KEY_CT_MARK_MASK,	/* u32 */
-	TCA_FLOWER_KEY_CT_LABELS,	/* u128 */
-	TCA_FLOWER_KEY_CT_LABELS_MASK,	/* u128 */
-
-	__TCA_FLOWER_MAX,
-};
-
-#define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
-
-enum {
-	TCA_FLOWER_KEY_CT_FLAGS_NEW = 1 << 0, /* Beginning of a new connection. */
-	TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED = 1 << 1, /* Part of an existing connection. */
-	TCA_FLOWER_KEY_CT_FLAGS_RELATED = 1 << 2, /* Related to an established connection. */
-	TCA_FLOWER_KEY_CT_FLAGS_TRACKED = 1 << 3, /* Conntrack has occurred. */
-};
-
-enum {
-	TCA_FLOWER_KEY_ENC_OPTS_UNSPEC,
-	TCA_FLOWER_KEY_ENC_OPTS_GENEVE, /* Nested
-					 * TCA_FLOWER_KEY_ENC_OPT_GENEVE_
-					 * attributes
-					 */
-	__TCA_FLOWER_KEY_ENC_OPTS_MAX,
-};
-
-#define TCA_FLOWER_KEY_ENC_OPTS_MAX (__TCA_FLOWER_KEY_ENC_OPTS_MAX - 1)
-
-enum {
-	TCA_FLOWER_KEY_ENC_OPT_GENEVE_UNSPEC,
-	TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS,            /* u16 */
-	TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE,             /* u8 */
-	TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA,             /* 4 to 128 bytes */
-
-	__TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX,
-};
-
-#define TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX \
-		(__TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX - 1)
-
-enum {
-	TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
-	TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
-};
-
-#define TCA_FLOWER_MASK_FLAGS_RANGE	(1 << 0) /* Range-based match */
-
-/* Match-all classifier */
-
-struct tc_matchall_pcnt {
-	__u64 rhit;
-};
-
-enum {
-	TCA_MATCHALL_UNSPEC,
-	TCA_MATCHALL_CLASSID,
-	TCA_MATCHALL_ACT,
-	TCA_MATCHALL_FLAGS,
-	TCA_MATCHALL_PCNT,
-	TCA_MATCHALL_PAD,
-	__TCA_MATCHALL_MAX,
-};
-
-#define TCA_MATCHALL_MAX (__TCA_MATCHALL_MAX - 1)
-
-/* Extended Matches */
-
-struct tcf_ematch_tree_hdr {
-	__u16		nmatches;
-	__u16		progid;
-};
-
-enum {
-	TCA_EMATCH_TREE_UNSPEC,
-	TCA_EMATCH_TREE_HDR,
-	TCA_EMATCH_TREE_LIST,
-	__TCA_EMATCH_TREE_MAX
-};
-#define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
-
-struct tcf_ematch_hdr {
-	__u16		matchid;
-	__u16		kind;
-	__u16		flags;
-	__u16		pad; /* currently unused */
-};
-
-/*  0                   1
- *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 
- * +-----------------------+-+-+---+
- * |         Unused        |S|I| R |
- * +-----------------------+-+-+---+
- *
- * R(2) ::= relation to next ematch
- *          where: 0 0 END (last ematch)
- *                 0 1 AND
- *                 1 0 OR
- *                 1 1 Unused (invalid)
- * I(1) ::= invert result
- * S(1) ::= simple payload
- */
-#define TCF_EM_REL_END	0
-#define TCF_EM_REL_AND	(1<<0)
-#define TCF_EM_REL_OR	(1<<1)
-#define TCF_EM_INVERT	(1<<2)
-#define TCF_EM_SIMPLE	(1<<3)
-
-#define TCF_EM_REL_MASK	3
-#define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
-
-enum {
-	TCF_LAYER_LINK,
-	TCF_LAYER_NETWORK,
-	TCF_LAYER_TRANSPORT,
-	__TCF_LAYER_MAX
-};
-#define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
-
-/* Ematch type assignments
- *   1..32767		Reserved for ematches inside kernel tree
- *   32768..65535	Free to use, not reliable
- */
-#define	TCF_EM_CONTAINER	0
-#define	TCF_EM_CMP		1
-#define	TCF_EM_NBYTE		2
-#define	TCF_EM_U32		3
-#define	TCF_EM_META		4
-#define	TCF_EM_TEXT		5
-#define	TCF_EM_VLAN		6
-#define	TCF_EM_CANID		7
-#define	TCF_EM_IPSET		8
-#define	TCF_EM_IPT		9
-#define	TCF_EM_MAX		9
-
-enum {
-	TCF_EM_PROG_TC
-};
-
-enum {
-	TCF_EM_OPND_EQ,
-	TCF_EM_OPND_GT,
-	TCF_EM_OPND_LT
-};
-
-#endif
diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
deleted file mode 100644
index 12b5189..0000000
--- a/include/uapi/linux/pkt_sched.h
+++ /dev/null
@@ -1,1416 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_PKT_SCHED_H
-#define __LINUX_PKT_SCHED_H
-
-#include <linux/const.h>
-#include <linux/types.h>
-
-/* Logical priority bands not depending on specific packet scheduler.
-   Every scheduler will map them to real traffic classes, if it has
-   no more precise mechanism to classify packets.
-
-   These numbers have no special meaning, though their coincidence
-   with obsolete IPv6 values is not occasional :-). New IPv6 drafts
-   preferred full anarchy inspired by diffserv group.
-
-   Note: TC_PRIO_BESTEFFORT does not mean that it is the most unhappy
-   class, actually, as rule it will be handled with more care than
-   filler or even bulk.
- */
-
-#define TC_PRIO_BESTEFFORT		0
-#define TC_PRIO_FILLER			1
-#define TC_PRIO_BULK			2
-#define TC_PRIO_INTERACTIVE_BULK	4
-#define TC_PRIO_INTERACTIVE		6
-#define TC_PRIO_CONTROL			7
-
-#define TC_PRIO_MAX			15
-
-/* Generic queue statistics, available for all the elements.
-   Particular schedulers may have also their private records.
- */
-
-struct tc_stats {
-	__u64	bytes;			/* Number of enqueued bytes */
-	__u32	packets;		/* Number of enqueued packets	*/
-	__u32	drops;			/* Packets dropped because of lack of resources */
-	__u32	overlimits;		/* Number of throttle events when this
-					 * flow goes out of allocated bandwidth */
-	__u32	bps;			/* Current flow byte rate */
-	__u32	pps;			/* Current flow packet rate */
-	__u32	qlen;
-	__u32	backlog;
-};
-
-struct tc_estimator {
-	signed char	interval;
-	unsigned char	ewma_log;
-};
-
-/* "Handles"
-   ---------
-
-    All the traffic control objects have 32bit identifiers, or "handles".
-
-    They can be considered as opaque numbers from user API viewpoint,
-    but actually they always consist of two fields: major and
-    minor numbers, which are interpreted by kernel specially,
-    that may be used by applications, though not recommended.
-
-    F.e. qdisc handles always have minor number equal to zero,
-    classes (or flows) have major equal to parent qdisc major, and
-    minor uniquely identifying class inside qdisc.
-
-    Macros to manipulate handles:
- */
-
-#define TC_H_MAJ_MASK (0xFFFF0000U)
-#define TC_H_MIN_MASK (0x0000FFFFU)
-#define TC_H_MAJ(h) ((h)&TC_H_MAJ_MASK)
-#define TC_H_MIN(h) ((h)&TC_H_MIN_MASK)
-#define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK))
-
-#define TC_H_UNSPEC	(0U)
-#define TC_H_ROOT	(0xFFFFFFFFU)
-#define TC_H_INGRESS    (0xFFFFFFF1U)
-#define TC_H_CLSACT	TC_H_INGRESS
-
-#define TC_H_MIN_PRIORITY	0xFFE0U
-#define TC_H_MIN_INGRESS	0xFFF2U
-#define TC_H_MIN_EGRESS		0xFFF3U
-
-/* Need to corrospond to iproute2 tc/tc_core.h "enum link_layer" */
-enum tc_link_layer {
-	TC_LINKLAYER_UNAWARE, /* Indicate unaware old iproute2 util */
-	TC_LINKLAYER_ETHERNET,
-	TC_LINKLAYER_ATM,
-};
-#define TC_LINKLAYER_MASK 0x0F /* limit use to lower 4 bits */
-
-struct tc_ratespec {
-	unsigned char	cell_log;
-	__u8		linklayer; /* lower 4 bits */
-	unsigned short	overhead;
-	short		cell_align;
-	unsigned short	mpu;
-	__u32		rate;
-};
-
-#define TC_RTAB_SIZE	1024
-
-struct tc_sizespec {
-	unsigned char	cell_log;
-	unsigned char	size_log;
-	short		cell_align;
-	int		overhead;
-	unsigned int	linklayer;
-	unsigned int	mpu;
-	unsigned int	mtu;
-	unsigned int	tsize;
-};
-
-enum {
-	TCA_STAB_UNSPEC,
-	TCA_STAB_BASE,
-	TCA_STAB_DATA,
-	__TCA_STAB_MAX
-};
-
-#define TCA_STAB_MAX (__TCA_STAB_MAX - 1)
-
-/* NSSFIFO section */
-
-enum {
-	TCA_NSSFIFO_UNSPEC,
-	TCA_NSSFIFO_PARMS,
-	__TCA_NSSFIFO_MAX
-};
-
-#define TCA_NSSFIFO_MAX	(__TCA_NSSFIFO_MAX - 1)
-
-struct tc_nssfifo_qopt {
-	__u32	limit;		/* Queue length: bytes for bfifo, packets for pfifo */
-	__u8	set_default;	/* Sets qdisc to be the default qdisc for enqueue */
-};
-
-/* NSSWRED section */
-
-enum {
-	TCA_NSSWRED_UNSPEC,
-	TCA_NSSWRED_PARMS,
-	__TCA_NSSWRED_MAX
-};
-
-#define TCA_NSSWRED_MAX (__TCA_NSSWRED_MAX - 1)
-#define NSSWRED_CLASS_MAX 6
-struct tc_red_alg_parameter {
-	__u32	min;			/* qlen_avg < min: all pkts are enqueued */
-	__u32	max;			/* qlen_avg > max: all pkts are dropped */
-	__u32	probability;		/* Drop probability at qlen_avg = max */
-	__u32	exp_weight_factor;	/* exp_weight_factor for calculate qlen_avg */
-};
-
-struct tc_nsswred_traffic_class {
-	__u32 limit;			/* Queue length */
-	__u32 weight_mode_value;	/* Weight mode value */
-	struct tc_red_alg_parameter rap;/* Parameters for RED alg */
-};
-
-/*
- * Weight modes for WRED
- */
-enum tc_nsswred_weight_modes {
-	TC_NSSWRED_WEIGHT_MODE_DSCP = 0,	/* Weight mode is DSCP */
-	TC_NSSWRED_WEIGHT_MODES,		/* Must be last */
-};
-typedef enum tc_nsswred_weight_modes tc_nsswred_weight_mode_t;
-
-struct tc_nsswred_qopt {
-	__u32	limit;				/* Queue length */
-	tc_nsswred_weight_mode_t weight_mode;	/* Weight mode */
-	__u32	traffic_classes;		/* How many traffic classes: DPs */
-	__u32	def_traffic_class;		/* Default traffic if no match: def_DP */
-	__u32	traffic_id;			/* The traffic id to be configured */
-	__u32	weight_mode_value;		/* Weight mode value */
-	struct tc_red_alg_parameter rap;	/* RED algorithm parameters */
-	struct tc_nsswred_traffic_class tntc[NSSWRED_CLASS_MAX];
-						/* Traffic settings for dumpping */
-	__u8	ecn;				/* Setting ECN bit or dropping */
-	__u8	set_default;			/* Sets qdisc to be the default for enqueue */
-};
-
-/* NSSCODEL section */
-
-enum {
-	TCA_NSSCODEL_UNSPEC,
-	TCA_NSSCODEL_PARMS,
-	__TCA_NSSCODEL_MAX
-};
-
-#define TCA_NSSCODEL_MAX	(__TCA_NSSCODEL_MAX - 1)
-
-struct tc_nsscodel_qopt {
-	__u32	target;		/* Acceptable queueing delay */
-	__u32	limit;		/* Maximum number of packets that can be held in the queue */
-	__u32	interval;	/* Monitoring interval */
-	__u8	set_default;	/* Sets qdisc to be the default qdisc for enqueue */
-};
-
-struct tc_nsscodel_xstats {
-	__u32 peak_queue_delay;	/* Peak delay experienced by a dequeued packet */
-	__u32 peak_drop_delay;	/* Peak delay experienced by a dropped packet */
-};
-
-/* NSSTBL section */
-
-enum {
-	TCA_NSSTBL_UNSPEC,
-	TCA_NSSTBL_PARMS,
-	__TCA_NSSTBL_MAX
-};
-
-#define TCA_NSSTBL_MAX	(__TCA_NSSTBL_MAX - 1)
-
-struct tc_nsstbl_qopt {
-	__u32	burst;		/* Maximum burst size */
-	__u32	rate;		/* Limiting rate of TBF */
-	__u32	peakrate;	/* Maximum rate at which TBF is allowed to send */
-	__u32	mtu;		/* Max size of packet, or minumim burst size */
-};
-
-/* NSSPRIO section */
-
-#define TCA_NSSPRIO_MAX_BANDS 256
-
-enum {
-	TCA_NSSPRIO_UNSPEC,
-	TCA_NSSPRIO_PARMS,
-	__TCA_NSSPRIO_MAX
-};
-
-#define TCA_NSSPRIO_MAX	(__TCA_NSSPRIO_MAX - 1)
-
-struct tc_nssprio_qopt {
-	int	bands;				/* Number of bands */
-};
-
-/* NSSBF section */
-
-enum {
-	TCA_NSSBF_UNSPEC,
-	TCA_NSSBF_CLASS_PARMS,
-	TCA_NSSBF_QDISC_PARMS,
-	__TCA_NSSBF_MAX
-};
-
-#define TCA_NSSBF_MAX	(__TCA_NSSBF_MAX - 1)
-
-struct tc_nssbf_class_qopt {
-	__u32	burst;		/* Maximum burst size */
-	__u32	rate;		/* Allowed bandwidth for this class */
-	__u32	mtu;		/* MTU of the associated interface */
-	__u32	quantum;	/* Quamtum allocation for DRR */
-};
-
-struct tc_nssbf_qopt {
-	__u16	defcls;		/* Default class value */
-};
-
-/* NSSWRR section */
-
-enum {
-	TCA_NSSWRR_UNSPEC,
-	TCA_NSSWRR_CLASS_PARMS,
-	__TCA_NSSWRR_MAX
-};
-
-#define TCA_NSSWRR_MAX	(__TCA_NSSWRR_MAX - 1)
-
-struct tc_nsswrr_class_qopt {
-	__u32	quantum;	/* Weight associated to this class */
-};
-
-/* NSSWFQ section */
-
-enum {
-	TCA_NSSWFQ_UNSPEC,
-	TCA_NSSWFQ_CLASS_PARMS,
-	__TCA_NSSWFQ_MAX
-};
-
-#define TCA_NSSWFQ_MAX	(__TCA_NSSWFQ_MAX - 1)
-
-struct tc_nsswfq_class_qopt {
-	__u32	quantum;	/* Weight associated to this class */
-};
-
-/* NSSHTB section */
-
-enum {
-	TCA_NSSHTB_UNSPEC,
-	TCA_NSSHTB_CLASS_PARMS,
-	TCA_NSSHTB_QDISC_PARMS,
-	__TCA_NSSHTB_MAX
-};
-
-#define TCA_NSSHTB_MAX	(__TCA_NSSHTB_MAX - 1)
-
-struct tc_nsshtb_class_qopt {
-	__u32	burst;		/* Allowed burst size */
-	__u32	rate;		/* Allowed bandwidth for this class */
-	__u32	cburst;		/* Maximum burst size */
-	__u32	crate;		/* Maximum bandwidth for this class */
-	__u32	quantum;	/* Quantum allocation for DRR */
-	__u32	priority;	/* Priority value associated with this class */
-	__u32	overhead;	/* Overhead in bytes per packet */
-};
-
-struct tc_nsshtb_qopt {
-	__u32	r2q;		/* Rate to quantum ratio */
-};
-
-/* NSSBLACKHOLE section */
-
-enum {
-	TCA_NSSBLACKHOLE_UNSPEC,
-	TCA_NSSBLACKHOLE_PARMS,
-	__TCA_NSSBLACKHOLE_MAX
-};
-
-#define TCA_NSSBLACKHOLE_MAX	(__TCA_NSSBLACKHOLE_MAX - 1)
-
-struct tc_nssblackhole_qopt {
-	__u8	set_default;	/* Sets qdisc to be the default qdisc for enqueue */
-};
-
-/* FIFO section */
-
-struct tc_fifo_qopt {
-	__u32	limit;	/* Queue length: bytes for bfifo, packets for pfifo */
-};
-
-/* SKBPRIO section */
-
-/*
- * Priorities go from zero to (SKBPRIO_MAX_PRIORITY - 1).
- * SKBPRIO_MAX_PRIORITY should be at least 64 in order for skbprio to be able
- * to map one to one the DS field of IPV4 and IPV6 headers.
- * Memory allocation grows linearly with SKBPRIO_MAX_PRIORITY.
- */
-
-#define SKBPRIO_MAX_PRIORITY 64
-
-struct tc_skbprio_qopt {
-	__u32	limit;		/* Queue length in packets. */
-};
-
-/* PRIO section */
-
-#define TCQ_PRIO_BANDS	16
-#define TCQ_MIN_PRIO_BANDS 2
-
-struct tc_prio_qopt {
-	int	bands;			/* Number of bands */
-	__u8	priomap[TC_PRIO_MAX+1];	/* Map: logical priority -> PRIO band */
-};
-
-/* MULTIQ section */
-
-struct tc_multiq_qopt {
-	__u16	bands;			/* Number of bands */
-	__u16	max_bands;		/* Maximum number of queues */
-};
-
-/* PLUG section */
-
-#define TCQ_PLUG_BUFFER                0
-#define TCQ_PLUG_RELEASE_ONE           1
-#define TCQ_PLUG_RELEASE_INDEFINITE    2
-#define TCQ_PLUG_LIMIT                 3
-
-struct tc_plug_qopt {
-	/* TCQ_PLUG_BUFFER: Inset a plug into the queue and
-	 *  buffer any incoming packets
-	 * TCQ_PLUG_RELEASE_ONE: Dequeue packets from queue head
-	 *   to beginning of the next plug.
-	 * TCQ_PLUG_RELEASE_INDEFINITE: Dequeue all packets from queue.
-	 *   Stop buffering packets until the next TCQ_PLUG_BUFFER
-	 *   command is received (just act as a pass-thru queue).
-	 * TCQ_PLUG_LIMIT: Increase/decrease queue size
-	 */
-	int             action;
-	__u32           limit;
-};
-
-/* TBF section */
-
-struct tc_tbf_qopt {
-	struct tc_ratespec rate;
-	struct tc_ratespec peakrate;
-	__u32		limit;
-	__u32		buffer;
-	__u32		mtu;
-};
-
-enum {
-	TCA_TBF_UNSPEC,
-	TCA_TBF_PARMS,
-	TCA_TBF_RTAB,
-	TCA_TBF_PTAB,
-	TCA_TBF_RATE64,
-	TCA_TBF_PRATE64,
-	TCA_TBF_BURST,
-	TCA_TBF_PBURST,
-	TCA_TBF_PAD,
-	__TCA_TBF_MAX,
-};
-
-#define TCA_TBF_MAX (__TCA_TBF_MAX - 1)
-
-
-/* TEQL section */
-
-/* TEQL does not require any parameters */
-
-/* SFQ section */
-
-struct tc_sfq_qopt {
-	unsigned	quantum;	/* Bytes per round allocated to flow */
-	int		perturb_period;	/* Period of hash perturbation */
-	__u32		limit;		/* Maximal packets in queue */
-	unsigned	divisor;	/* Hash divisor  */
-	unsigned	flows;		/* Maximal number of flows  */
-};
-
-struct tc_sfqred_stats {
-	__u32           prob_drop;      /* Early drops, below max threshold */
-	__u32           forced_drop;	/* Early drops, after max threshold */
-	__u32           prob_mark;      /* Marked packets, below max threshold */
-	__u32           forced_mark;    /* Marked packets, after max threshold */
-	__u32           prob_mark_head; /* Marked packets, below max threshold */
-	__u32           forced_mark_head;/* Marked packets, after max threshold */
-};
-
-struct tc_sfq_qopt_v1 {
-	struct tc_sfq_qopt v0;
-	unsigned int	depth;		/* max number of packets per flow */
-	unsigned int	headdrop;
-/* SFQRED parameters */
-	__u32		limit;		/* HARD maximal flow queue length (bytes) */
-	__u32		qth_min;	/* Min average length threshold (bytes) */
-	__u32		qth_max;	/* Max average length threshold (bytes) */
-	unsigned char   Wlog;		/* log(W)		*/
-	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
-	unsigned char   Scell_log;	/* cell size for idle damping */
-	unsigned char	flags;
-	__u32		max_P;		/* probability, high resolution */
-/* SFQRED stats */
-	struct tc_sfqred_stats stats;
-};
-
-
-struct tc_sfq_xstats {
-	__s32		allot;
-};
-
-/* RED section */
-
-enum {
-	TCA_RED_UNSPEC,
-	TCA_RED_PARMS,
-	TCA_RED_STAB,
-	TCA_RED_MAX_P,
-	__TCA_RED_MAX,
-};
-
-#define TCA_RED_MAX (__TCA_RED_MAX - 1)
-
-struct tc_red_qopt {
-	__u32		limit;		/* HARD maximal queue length (bytes)	*/
-	__u32		qth_min;	/* Min average length threshold (bytes) */
-	__u32		qth_max;	/* Max average length threshold (bytes) */
-	unsigned char   Wlog;		/* log(W)		*/
-	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
-	unsigned char   Scell_log;	/* cell size for idle damping */
-	unsigned char	flags;
-#define TC_RED_ECN		1
-#define TC_RED_HARDDROP		2
-#define TC_RED_ADAPTATIVE	4
-};
-
-struct tc_red_xstats {
-	__u32           early;          /* Early drops */
-	__u32           pdrop;          /* Drops due to queue limits */
-	__u32           other;          /* Drops due to drop() calls */
-	__u32           marked;         /* Marked packets */
-};
-
-/* GRED section */
-
-#define MAX_DPs 16
-
-enum {
-       TCA_GRED_UNSPEC,
-       TCA_GRED_PARMS,
-       TCA_GRED_STAB,
-       TCA_GRED_DPS,
-       TCA_GRED_MAX_P,
-       TCA_GRED_LIMIT,
-       TCA_GRED_VQ_LIST,	/* nested TCA_GRED_VQ_ENTRY */
-       __TCA_GRED_MAX,
-};
-
-#define TCA_GRED_MAX (__TCA_GRED_MAX - 1)
-
-enum {
-	TCA_GRED_VQ_ENTRY_UNSPEC,
-	TCA_GRED_VQ_ENTRY,	/* nested TCA_GRED_VQ_* */
-	__TCA_GRED_VQ_ENTRY_MAX,
-};
-#define TCA_GRED_VQ_ENTRY_MAX (__TCA_GRED_VQ_ENTRY_MAX - 1)
-
-enum {
-	TCA_GRED_VQ_UNSPEC,
-	TCA_GRED_VQ_PAD,
-	TCA_GRED_VQ_DP,			/* u32 */
-	TCA_GRED_VQ_STAT_BYTES,		/* u64 */
-	TCA_GRED_VQ_STAT_PACKETS,	/* u32 */
-	TCA_GRED_VQ_STAT_BACKLOG,	/* u32 */
-	TCA_GRED_VQ_STAT_PROB_DROP,	/* u32 */
-	TCA_GRED_VQ_STAT_PROB_MARK,	/* u32 */
-	TCA_GRED_VQ_STAT_FORCED_DROP,	/* u32 */
-	TCA_GRED_VQ_STAT_FORCED_MARK,	/* u32 */
-	TCA_GRED_VQ_STAT_PDROP,		/* u32 */
-	TCA_GRED_VQ_STAT_OTHER,		/* u32 */
-	TCA_GRED_VQ_FLAGS,		/* u32 */
-	__TCA_GRED_VQ_MAX
-};
-
-#define TCA_GRED_VQ_MAX (__TCA_GRED_VQ_MAX - 1)
-
-struct tc_gred_qopt {
-	__u32		limit;        /* HARD maximal queue length (bytes)    */
-	__u32		qth_min;      /* Min average length threshold (bytes) */
-	__u32		qth_max;      /* Max average length threshold (bytes) */
-	__u32		DP;           /* up to 2^32 DPs */
-	__u32		backlog;
-	__u32		qave;
-	__u32		forced;
-	__u32		early;
-	__u32		other;
-	__u32		pdrop;
-	__u8		Wlog;         /* log(W)               */
-	__u8		Plog;         /* log(P_max/(qth_max-qth_min)) */
-	__u8		Scell_log;    /* cell size for idle damping */
-	__u8		prio;         /* prio of this VQ */
-	__u32		packets;
-	__u32		bytesin;
-};
-
-/* gred setup */
-struct tc_gred_sopt {
-	__u32		DPs;
-	__u32		def_DP;
-	__u8		grio;
-	__u8		flags;
-	__u16		pad1;
-};
-
-/* CHOKe section */
-
-enum {
-	TCA_CHOKE_UNSPEC,
-	TCA_CHOKE_PARMS,
-	TCA_CHOKE_STAB,
-	TCA_CHOKE_MAX_P,
-	__TCA_CHOKE_MAX,
-};
-
-#define TCA_CHOKE_MAX (__TCA_CHOKE_MAX - 1)
-
-struct tc_choke_qopt {
-	__u32		limit;		/* Hard queue length (packets)	*/
-	__u32		qth_min;	/* Min average threshold (packets) */
-	__u32		qth_max;	/* Max average threshold (packets) */
-	unsigned char   Wlog;		/* log(W)		*/
-	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
-	unsigned char   Scell_log;	/* cell size for idle damping */
-	unsigned char	flags;		/* see RED flags */
-};
-
-struct tc_choke_xstats {
-	__u32		early;          /* Early drops */
-	__u32		pdrop;          /* Drops due to queue limits */
-	__u32		other;          /* Drops due to drop() calls */
-	__u32		marked;         /* Marked packets */
-	__u32		matched;	/* Drops due to flow match */
-};
-
-/* HTB section */
-#define TC_HTB_NUMPRIO		8
-#define TC_HTB_MAXDEPTH		8
-#define TC_HTB_PROTOVER		3 /* the same as HTB and TC's major */
-
-struct tc_htb_opt {
-	struct tc_ratespec 	rate;
-	struct tc_ratespec 	ceil;
-	__u32	buffer;
-	__u32	cbuffer;
-	__u32	quantum;
-	__u32	level;		/* out only */
-	__u32	prio;
-};
-struct tc_htb_glob {
-	__u32 version;		/* to match HTB/TC */
-    	__u32 rate2quantum;	/* bps->quantum divisor */
-    	__u32 defcls;		/* default class number */
-	__u32 debug;		/* debug flags */
-
-	/* stats */
-	__u32 direct_pkts; /* count of non shaped packets */
-};
-enum {
-	TCA_HTB_UNSPEC,
-	TCA_HTB_PARMS,
-	TCA_HTB_INIT,
-	TCA_HTB_CTAB,
-	TCA_HTB_RTAB,
-	TCA_HTB_DIRECT_QLEN,
-	TCA_HTB_RATE64,
-	TCA_HTB_CEIL64,
-	TCA_HTB_PAD,
-	__TCA_HTB_MAX,
-};
-
-#define TCA_HTB_MAX (__TCA_HTB_MAX - 1)
-
-struct tc_htb_xstats {
-	__u32 lends;
-	__u32 borrows;
-	__u32 giants;	/* unused since 'Make HTB scheduler work with TSO.' */
-	__s32 tokens;
-	__s32 ctokens;
-};
-
-/* HFSC section */
-
-struct tc_hfsc_qopt {
-	__u16	defcls;		/* default class */
-};
-
-struct tc_service_curve {
-	__u32	m1;		/* slope of the first segment in bps */
-	__u32	d;		/* x-projection of the first segment in us */
-	__u32	m2;		/* slope of the second segment in bps */
-};
-
-struct tc_hfsc_stats {
-	__u64	work;		/* total work done */
-	__u64	rtwork;		/* work done by real-time criteria */
-	__u32	period;		/* current period */
-	__u32	level;		/* class level in hierarchy */
-};
-
-enum {
-	TCA_HFSC_UNSPEC,
-	TCA_HFSC_RSC,
-	TCA_HFSC_FSC,
-	TCA_HFSC_USC,
-	__TCA_HFSC_MAX,
-};
-
-#define TCA_HFSC_MAX (__TCA_HFSC_MAX - 1)
-
-
-/* CBQ section */
-
-#define TC_CBQ_MAXPRIO		8
-#define TC_CBQ_MAXLEVEL		8
-#define TC_CBQ_DEF_EWMA		5
-
-struct tc_cbq_lssopt {
-	unsigned char	change;
-	unsigned char	flags;
-#define TCF_CBQ_LSS_BOUNDED	1
-#define TCF_CBQ_LSS_ISOLATED	2
-	unsigned char  	ewma_log;
-	unsigned char  	level;
-#define TCF_CBQ_LSS_FLAGS	1
-#define TCF_CBQ_LSS_EWMA	2
-#define TCF_CBQ_LSS_MAXIDLE	4
-#define TCF_CBQ_LSS_MINIDLE	8
-#define TCF_CBQ_LSS_OFFTIME	0x10
-#define TCF_CBQ_LSS_AVPKT	0x20
-	__u32		maxidle;
-	__u32		minidle;
-	__u32		offtime;
-	__u32		avpkt;
-};
-
-struct tc_cbq_wrropt {
-	unsigned char	flags;
-	unsigned char	priority;
-	unsigned char	cpriority;
-	unsigned char	__reserved;
-	__u32		allot;
-	__u32		weight;
-};
-
-struct tc_cbq_ovl {
-	unsigned char	strategy;
-#define	TC_CBQ_OVL_CLASSIC	0
-#define	TC_CBQ_OVL_DELAY	1
-#define	TC_CBQ_OVL_LOWPRIO	2
-#define	TC_CBQ_OVL_DROP		3
-#define	TC_CBQ_OVL_RCLASSIC	4
-	unsigned char	priority2;
-	__u16		pad;
-	__u32		penalty;
-};
-
-struct tc_cbq_police {
-	unsigned char	police;
-	unsigned char	__res1;
-	unsigned short	__res2;
-};
-
-struct tc_cbq_fopt {
-	__u32		split;
-	__u32		defmap;
-	__u32		defchange;
-};
-
-struct tc_cbq_xstats {
-	__u32		borrows;
-	__u32		overactions;
-	__s32		avgidle;
-	__s32		undertime;
-};
-
-enum {
-	TCA_CBQ_UNSPEC,
-	TCA_CBQ_LSSOPT,
-	TCA_CBQ_WRROPT,
-	TCA_CBQ_FOPT,
-	TCA_CBQ_OVL_STRATEGY,
-	TCA_CBQ_RATE,
-	TCA_CBQ_RTAB,
-	TCA_CBQ_POLICE,
-	__TCA_CBQ_MAX,
-};
-
-#define TCA_CBQ_MAX	(__TCA_CBQ_MAX - 1)
-
-/* ARL section */
-
-struct tc_arl_xstats {
-	__u32	max_bw;		/* The maximum bw measured */
-	__u32	min_rate;	/* The lowest base rate */
-	__u32	current_rate;	/* The current rate */
-	__u32	latency;	/* The current latency */
-	__u32	base_rate;	/* The base rate */
-	__u32	current_bw;	/* The current bw measured */
-	__u32	state;		/* The current state */
-};
-
-enum {
-	TCA_ARL_UNSPEC,
-	TCA_ARL_BUFFER,
-	TCA_ARL_MIN_RATE,
-	TCA_ARL_MAX_BW,
-	TCA_ARL_LIMIT,
-	TCA_ARL_MAX_LATENCY,
-	TCA_ARL_LATENCY_HYSTERESIS,
-	TCA_ARL_PAD,
-	TCA_ARL_MODE,
-	TCA_ARL_CODEL_TARGET,
-	__TCA_ARL_MAX,
-};
-#define TCA_ARL_MAX (__TCA_ARL_MAX - 1)
-
-/* dsmark section */
-
-enum {
-	TCA_DSMARK_UNSPEC,
-	TCA_DSMARK_INDICES,
-	TCA_DSMARK_DEFAULT_INDEX,
-	TCA_DSMARK_SET_TC_INDEX,
-	TCA_DSMARK_MASK,
-	TCA_DSMARK_VALUE,
-	__TCA_DSMARK_MAX,
-};
-
-#define TCA_DSMARK_MAX (__TCA_DSMARK_MAX - 1)
-
-/* ATM  section */
-
-enum {
-	TCA_ATM_UNSPEC,
-	TCA_ATM_FD,		/* file/socket descriptor */
-	TCA_ATM_PTR,		/* pointer to descriptor - later */
-	TCA_ATM_HDR,		/* LL header */
-	TCA_ATM_EXCESS,		/* excess traffic class (0 for CLP)  */
-	TCA_ATM_ADDR,		/* PVC address (for output only) */
-	TCA_ATM_STATE,		/* VC state (ATM_VS_*; for output only) */
-	__TCA_ATM_MAX,
-};
-
-#define TCA_ATM_MAX	(__TCA_ATM_MAX - 1)
-
-/* Network emulator */
-
-enum {
-	TCA_NETEM_UNSPEC,
-	TCA_NETEM_CORR,
-	TCA_NETEM_DELAY_DIST,
-	TCA_NETEM_REORDER,
-	TCA_NETEM_CORRUPT,
-	TCA_NETEM_LOSS,
-	TCA_NETEM_RATE,
-	TCA_NETEM_ECN,
-	TCA_NETEM_RATE64,
-	TCA_NETEM_PAD,
-	TCA_NETEM_LATENCY64,
-	TCA_NETEM_JITTER64,
-	TCA_NETEM_SLOT,
-	TCA_NETEM_SLOT_DIST,
-	__TCA_NETEM_MAX,
-};
-
-#define TCA_NETEM_MAX (__TCA_NETEM_MAX - 1)
-
-struct tc_netem_qopt {
-	__u32	latency;	/* added delay (us) */
-	__u32   limit;		/* fifo limit (packets) */
-	__u32	loss;		/* random packet loss (0=none ~0=100%) */
-	__u32	gap;		/* re-ordering gap (0 for none) */
-	__u32   duplicate;	/* random packet dup  (0=none ~0=100%) */
-	__u32	jitter;		/* random jitter in latency (us) */
-};
-
-struct tc_netem_corr {
-	__u32	delay_corr;	/* delay correlation */
-	__u32	loss_corr;	/* packet loss correlation */
-	__u32	dup_corr;	/* duplicate correlation  */
-};
-
-struct tc_netem_reorder {
-	__u32	probability;
-	__u32	correlation;
-};
-
-struct tc_netem_corrupt {
-	__u32	probability;
-	__u32	correlation;
-};
-
-struct tc_netem_rate {
-	__u32	rate;	/* byte/s */
-	__s32	packet_overhead;
-	__u32	cell_size;
-	__s32	cell_overhead;
-};
-
-struct tc_netem_slot {
-	__s64   min_delay; /* nsec */
-	__s64   max_delay;
-	__s32   max_packets;
-	__s32   max_bytes;
-	__s64	dist_delay; /* nsec */
-	__s64	dist_jitter; /* nsec */
-};
-
-enum {
-	NETEM_LOSS_UNSPEC,
-	NETEM_LOSS_GI,		/* General Intuitive - 4 state model */
-	NETEM_LOSS_GE,		/* Gilbert Elliot models */
-	__NETEM_LOSS_MAX
-};
-#define NETEM_LOSS_MAX (__NETEM_LOSS_MAX - 1)
-
-/* State transition probabilities for 4 state model */
-struct tc_netem_gimodel {
-	__u32	p13;
-	__u32	p31;
-	__u32	p32;
-	__u32	p14;
-	__u32	p23;
-};
-
-/* Gilbert-Elliot models */
-struct tc_netem_gemodel {
-	__u32 p;
-	__u32 r;
-	__u32 h;
-	__u32 k1;
-};
-
-#define NETEM_DIST_SCALE	8192
-#define NETEM_DIST_MAX		16384
-
-/* DRR */
-
-enum {
-	TCA_DRR_UNSPEC,
-	TCA_DRR_QUANTUM,
-	__TCA_DRR_MAX
-};
-
-#define TCA_DRR_MAX	(__TCA_DRR_MAX - 1)
-
-struct tc_drr_stats {
-	__u32	deficit;
-};
-
-/* MQPRIO */
-#define TC_QOPT_BITMASK 15
-#define TC_QOPT_MAX_QUEUE 16
-
-enum {
-	TC_MQPRIO_HW_OFFLOAD_NONE,	/* no offload requested */
-	TC_MQPRIO_HW_OFFLOAD_TCS,	/* offload TCs, no queue counts */
-	__TC_MQPRIO_HW_OFFLOAD_MAX
-};
-
-#define TC_MQPRIO_HW_OFFLOAD_MAX (__TC_MQPRIO_HW_OFFLOAD_MAX - 1)
-
-enum {
-	TC_MQPRIO_MODE_DCB,
-	TC_MQPRIO_MODE_CHANNEL,
-	__TC_MQPRIO_MODE_MAX
-};
-
-#define __TC_MQPRIO_MODE_MAX (__TC_MQPRIO_MODE_MAX - 1)
-
-enum {
-	TC_MQPRIO_SHAPER_DCB,
-	TC_MQPRIO_SHAPER_BW_RATE,	/* Add new shapers below */
-	__TC_MQPRIO_SHAPER_MAX
-};
-
-#define __TC_MQPRIO_SHAPER_MAX (__TC_MQPRIO_SHAPER_MAX - 1)
-
-struct tc_mqprio_qopt {
-	__u8	num_tc;
-	__u8	prio_tc_map[TC_QOPT_BITMASK + 1];
-	__u8	hw;
-	__u16	count[TC_QOPT_MAX_QUEUE];
-	__u16	offset[TC_QOPT_MAX_QUEUE];
-};
-
-#define TC_MQPRIO_F_MODE		0x1
-#define TC_MQPRIO_F_SHAPER		0x2
-#define TC_MQPRIO_F_MIN_RATE		0x4
-#define TC_MQPRIO_F_MAX_RATE		0x8
-
-enum {
-	TCA_MQPRIO_UNSPEC,
-	TCA_MQPRIO_MODE,
-	TCA_MQPRIO_SHAPER,
-	TCA_MQPRIO_MIN_RATE64,
-	TCA_MQPRIO_MAX_RATE64,
-	__TCA_MQPRIO_MAX,
-};
-
-#define TCA_MQPRIO_MAX (__TCA_MQPRIO_MAX - 1)
-
-/* SFB */
-
-enum {
-	TCA_SFB_UNSPEC,
-	TCA_SFB_PARMS,
-	__TCA_SFB_MAX,
-};
-
-#define TCA_SFB_MAX (__TCA_SFB_MAX - 1)
-
-/*
- * Note: increment, decrement are Q0.16 fixed-point values.
- */
-struct tc_sfb_qopt {
-	__u32 rehash_interval;	/* delay between hash move, in ms */
-	__u32 warmup_time;	/* double buffering warmup time in ms (warmup_time < rehash_interval) */
-	__u32 max;		/* max len of qlen_min */
-	__u32 bin_size;		/* maximum queue length per bin */
-	__u32 increment;	/* probability increment, (d1 in Blue) */
-	__u32 decrement;	/* probability decrement, (d2 in Blue) */
-	__u32 limit;		/* max SFB queue length */
-	__u32 penalty_rate;	/* inelastic flows are rate limited to 'rate' pps */
-	__u32 penalty_burst;
-};
-
-struct tc_sfb_xstats {
-	__u32 earlydrop;
-	__u32 penaltydrop;
-	__u32 bucketdrop;
-	__u32 queuedrop;
-	__u32 childdrop; /* drops in child qdisc */
-	__u32 marked;
-	__u32 maxqlen;
-	__u32 maxprob;
-	__u32 avgprob;
-};
-
-#define SFB_MAX_PROB 0xFFFF
-
-/* QFQ */
-enum {
-	TCA_QFQ_UNSPEC,
-	TCA_QFQ_WEIGHT,
-	TCA_QFQ_LMAX,
-	__TCA_QFQ_MAX
-};
-
-#define TCA_QFQ_MAX	(__TCA_QFQ_MAX - 1)
-
-struct tc_qfq_stats {
-	__u32 weight;
-	__u32 lmax;
-};
-
-/* CODEL */
-
-enum {
-	TCA_CODEL_UNSPEC,
-	TCA_CODEL_TARGET,
-	TCA_CODEL_LIMIT,
-	TCA_CODEL_INTERVAL,
-	TCA_CODEL_ECN,
-	TCA_CODEL_CE_THRESHOLD,
-	__TCA_CODEL_MAX
-};
-
-#define TCA_CODEL_MAX	(__TCA_CODEL_MAX - 1)
-
-struct tc_codel_xstats {
-	__u32	maxpacket; /* largest packet we've seen so far */
-	__u32	count;	   /* how many drops we've done since the last time we
-			    * entered dropping state
-			    */
-	__u32	lastcount; /* count at entry to dropping state */
-	__u32	ldelay;    /* in-queue delay seen by most recently dequeued packet */
-	__s32	drop_next; /* time to drop next packet */
-	__u32	drop_overlimit; /* number of time max qdisc packet limit was hit */
-	__u32	ecn_mark;  /* number of packets we ECN marked instead of dropped */
-	__u32	dropping;  /* are we in dropping state ? */
-	__u32	ce_mark;   /* number of CE marked packets because of ce_threshold */
-};
-
-/* FQ_CODEL */
-
-enum {
-	TCA_FQ_CODEL_UNSPEC,
-	TCA_FQ_CODEL_TARGET,
-	TCA_FQ_CODEL_LIMIT,
-	TCA_FQ_CODEL_INTERVAL,
-	TCA_FQ_CODEL_ECN,
-	TCA_FQ_CODEL_FLOWS,
-	TCA_FQ_CODEL_QUANTUM,
-	TCA_FQ_CODEL_CE_THRESHOLD,
-	TCA_FQ_CODEL_DROP_BATCH_SIZE,
-	TCA_FQ_CODEL_MEMORY_LIMIT,
-	__TCA_FQ_CODEL_MAX
-};
-
-#define TCA_FQ_CODEL_MAX	(__TCA_FQ_CODEL_MAX - 1)
-
-enum {
-	TCA_FQ_CODEL_XSTATS_QDISC,
-	TCA_FQ_CODEL_XSTATS_CLASS,
-};
-
-struct tc_fq_codel_qd_stats {
-	__u32	maxpacket;	/* largest packet we've seen so far */
-	__u32	drop_overlimit; /* number of time max qdisc
-				 * packet limit was hit
-				 */
-	__u32	ecn_mark;	/* number of packets we ECN marked
-				 * instead of being dropped
-				 */
-	__u32	new_flow_count; /* number of time packets
-				 * created a 'new flow'
-				 */
-	__u32	new_flows_len;	/* count of flows in new list */
-	__u32	old_flows_len;	/* count of flows in old list */
-	__u32	ce_mark;	/* packets above ce_threshold */
-	__u32	memory_usage;	/* in bytes */
-	__u32	drop_overmemory;
-};
-
-struct tc_fq_codel_cl_stats {
-	__s32	deficit;
-	__u32	ldelay;		/* in-queue delay seen by most recently
-				 * dequeued packet
-				 */
-	__u32	count;
-	__u32	lastcount;
-	__u32	dropping;
-	__s32	drop_next;
-};
-
-struct tc_fq_codel_xstats {
-	__u32	type;
-	union {
-		struct tc_fq_codel_qd_stats qdisc_stats;
-		struct tc_fq_codel_cl_stats class_stats;
-	};
-};
-
-/* FQ */
-
-enum {
-	TCA_FQ_UNSPEC,
-
-	TCA_FQ_PLIMIT,		/* limit of total number of packets in queue */
-
-	TCA_FQ_FLOW_PLIMIT,	/* limit of packets per flow */
-
-	TCA_FQ_QUANTUM,		/* RR quantum */
-
-	TCA_FQ_INITIAL_QUANTUM,		/* RR quantum for new flow */
-
-	TCA_FQ_RATE_ENABLE,	/* enable/disable rate limiting */
-
-	TCA_FQ_FLOW_DEFAULT_RATE,/* obsolete, do not use */
-
-	TCA_FQ_FLOW_MAX_RATE,	/* per flow max rate */
-
-	TCA_FQ_BUCKETS_LOG,	/* log2(number of buckets) */
-
-	TCA_FQ_FLOW_REFILL_DELAY,	/* flow credit refill delay in usec */
-
-	TCA_FQ_ORPHAN_MASK,	/* mask applied to orphaned skb hashes */
-
-	TCA_FQ_LOW_RATE_THRESHOLD, /* per packet delay under this rate */
-
-	TCA_FQ_CE_THRESHOLD,	/* DCTCP-like CE-marking threshold */
-
-	__TCA_FQ_MAX
-};
-
-#define TCA_FQ_MAX	(__TCA_FQ_MAX - 1)
-
-struct tc_fq_qd_stats {
-	__u64	gc_flows;
-	__u64	highprio_packets;
-	__u64	tcp_retrans;
-	__u64	throttled;
-	__u64	flows_plimit;
-	__u64	pkts_too_long;
-	__u64	allocation_errors;
-	__s64	time_next_delayed_flow;
-	__u32	flows;
-	__u32	inactive_flows;
-	__u32	throttled_flows;
-	__u32	unthrottle_latency_ns;
-	__u64	ce_mark;		/* packets above ce_threshold */
-};
-
-/* Heavy-Hitter Filter */
-
-enum {
-	TCA_HHF_UNSPEC,
-	TCA_HHF_BACKLOG_LIMIT,
-	TCA_HHF_QUANTUM,
-	TCA_HHF_HH_FLOWS_LIMIT,
-	TCA_HHF_RESET_TIMEOUT,
-	TCA_HHF_ADMIT_BYTES,
-	TCA_HHF_EVICT_TIMEOUT,
-	TCA_HHF_NON_HH_WEIGHT,
-	__TCA_HHF_MAX
-};
-
-#define TCA_HHF_MAX	(__TCA_HHF_MAX - 1)
-
-struct tc_hhf_xstats {
-	__u32	drop_overlimit; /* number of times max qdisc packet limit
-				 * was hit
-				 */
-	__u32	hh_overlimit;   /* number of times max heavy-hitters was hit */
-	__u32	hh_tot_count;   /* number of captured heavy-hitters so far */
-	__u32	hh_cur_count;   /* number of current heavy-hitters */
-};
-
-/* PIE */
-enum {
-	TCA_PIE_UNSPEC,
-	TCA_PIE_TARGET,
-	TCA_PIE_LIMIT,
-	TCA_PIE_TUPDATE,
-	TCA_PIE_ALPHA,
-	TCA_PIE_BETA,
-	TCA_PIE_ECN,
-	TCA_PIE_BYTEMODE,
-	__TCA_PIE_MAX
-};
-#define TCA_PIE_MAX   (__TCA_PIE_MAX - 1)
-
-struct tc_pie_xstats {
-	__u64 prob;             /* current probability */
-	__u32 delay;            /* current delay in ms */
-	__u32 avg_dq_rate;      /* current average dq_rate in bits/pie_time */
-	__u32 packets_in;       /* total number of packets enqueued */
-	__u32 dropped;          /* packets dropped due to pie_action */
-	__u32 overlimit;        /* dropped due to lack of space in queue */
-	__u32 maxq;             /* maximum queue size */
-	__u32 ecn_mark;         /* packets marked with ecn*/
-};
-
-/* CBS */
-struct tc_cbs_qopt {
-	__u8 offload;
-	__u8 _pad[3];
-	__s32 hicredit;
-	__s32 locredit;
-	__s32 idleslope;
-	__s32 sendslope;
-};
-
-enum {
-	TCA_CBS_UNSPEC,
-	TCA_CBS_PARMS,
-	__TCA_CBS_MAX,
-};
-
-#define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
-
-
-/* ETF */
-struct tc_etf_qopt {
-	__s32 delta;
-	__s32 clockid;
-	__u32 flags;
-#define TC_ETF_DEADLINE_MODE_ON	_BITUL(0)
-#define TC_ETF_OFFLOAD_ON	_BITUL(1)
-#define TC_ETF_SKIP_SOCK_CHECK	_BITUL(2)
-};
-
-enum {
-	TCA_ETF_UNSPEC,
-	TCA_ETF_PARMS,
-	__TCA_ETF_MAX,
-};
-
-#define TCA_ETF_MAX (__TCA_ETF_MAX - 1)
-
-
-/* CAKE */
-enum {
-	TCA_CAKE_UNSPEC,
-	TCA_CAKE_PAD,
-	TCA_CAKE_BASE_RATE64,
-	TCA_CAKE_DIFFSERV_MODE,
-	TCA_CAKE_ATM,
-	TCA_CAKE_FLOW_MODE,
-	TCA_CAKE_OVERHEAD,
-	TCA_CAKE_RTT,
-	TCA_CAKE_TARGET,
-	TCA_CAKE_AUTORATE,
-	TCA_CAKE_MEMORY,
-	TCA_CAKE_NAT,
-	TCA_CAKE_RAW,
-	TCA_CAKE_WASH,
-	TCA_CAKE_MPU,
-	TCA_CAKE_INGRESS,
-	TCA_CAKE_ACK_FILTER,
-	TCA_CAKE_SPLIT_GSO,
-	TCA_CAKE_FWMARK,
-	__TCA_CAKE_MAX
-};
-#define TCA_CAKE_MAX	(__TCA_CAKE_MAX - 1)
-
-enum {
-	__TCA_CAKE_STATS_INVALID,
-	TCA_CAKE_STATS_PAD,
-	TCA_CAKE_STATS_CAPACITY_ESTIMATE64,
-	TCA_CAKE_STATS_MEMORY_LIMIT,
-	TCA_CAKE_STATS_MEMORY_USED,
-	TCA_CAKE_STATS_AVG_NETOFF,
-	TCA_CAKE_STATS_MIN_NETLEN,
-	TCA_CAKE_STATS_MAX_NETLEN,
-	TCA_CAKE_STATS_MIN_ADJLEN,
-	TCA_CAKE_STATS_MAX_ADJLEN,
-	TCA_CAKE_STATS_TIN_STATS,
-	TCA_CAKE_STATS_DEFICIT,
-	TCA_CAKE_STATS_COBALT_COUNT,
-	TCA_CAKE_STATS_DROPPING,
-	TCA_CAKE_STATS_DROP_NEXT_US,
-	TCA_CAKE_STATS_P_DROP,
-	TCA_CAKE_STATS_BLUE_TIMER_US,
-	__TCA_CAKE_STATS_MAX
-};
-#define TCA_CAKE_STATS_MAX (__TCA_CAKE_STATS_MAX - 1)
-
-enum {
-	__TCA_CAKE_TIN_STATS_INVALID,
-	TCA_CAKE_TIN_STATS_PAD,
-	TCA_CAKE_TIN_STATS_SENT_PACKETS,
-	TCA_CAKE_TIN_STATS_SENT_BYTES64,
-	TCA_CAKE_TIN_STATS_DROPPED_PACKETS,
-	TCA_CAKE_TIN_STATS_DROPPED_BYTES64,
-	TCA_CAKE_TIN_STATS_ACKS_DROPPED_PACKETS,
-	TCA_CAKE_TIN_STATS_ACKS_DROPPED_BYTES64,
-	TCA_CAKE_TIN_STATS_ECN_MARKED_PACKETS,
-	TCA_CAKE_TIN_STATS_ECN_MARKED_BYTES64,
-	TCA_CAKE_TIN_STATS_BACKLOG_PACKETS,
-	TCA_CAKE_TIN_STATS_BACKLOG_BYTES,
-	TCA_CAKE_TIN_STATS_THRESHOLD_RATE64,
-	TCA_CAKE_TIN_STATS_TARGET_US,
-	TCA_CAKE_TIN_STATS_INTERVAL_US,
-	TCA_CAKE_TIN_STATS_WAY_INDIRECT_HITS,
-	TCA_CAKE_TIN_STATS_WAY_MISSES,
-	TCA_CAKE_TIN_STATS_WAY_COLLISIONS,
-	TCA_CAKE_TIN_STATS_PEAK_DELAY_US,
-	TCA_CAKE_TIN_STATS_AVG_DELAY_US,
-	TCA_CAKE_TIN_STATS_BASE_DELAY_US,
-	TCA_CAKE_TIN_STATS_SPARSE_FLOWS,
-	TCA_CAKE_TIN_STATS_BULK_FLOWS,
-	TCA_CAKE_TIN_STATS_UNRESPONSIVE_FLOWS,
-	TCA_CAKE_TIN_STATS_MAX_SKBLEN,
-	TCA_CAKE_TIN_STATS_FLOW_QUANTUM,
-	__TCA_CAKE_TIN_STATS_MAX
-};
-#define TCA_CAKE_TIN_STATS_MAX (__TCA_CAKE_TIN_STATS_MAX - 1)
-#define TC_CAKE_MAX_TINS (8)
-
-enum {
-	CAKE_FLOW_NONE = 0,
-	CAKE_FLOW_SRC_IP,
-	CAKE_FLOW_DST_IP,
-	CAKE_FLOW_HOSTS,    /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_DST_IP */
-	CAKE_FLOW_FLOWS,
-	CAKE_FLOW_DUAL_SRC, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_FLOWS */
-	CAKE_FLOW_DUAL_DST, /* = CAKE_FLOW_DST_IP | CAKE_FLOW_FLOWS */
-	CAKE_FLOW_TRIPLE,   /* = CAKE_FLOW_HOSTS  | CAKE_FLOW_FLOWS */
-	CAKE_FLOW_MAX,
-};
-
-enum {
-	CAKE_DIFFSERV_DIFFSERV3 = 0,
-	CAKE_DIFFSERV_DIFFSERV4,
-	CAKE_DIFFSERV_DIFFSERV8,
-	CAKE_DIFFSERV_BESTEFFORT,
-	CAKE_DIFFSERV_PRECEDENCE,
-	CAKE_DIFFSERV_MAX
-};
-
-enum {
-	CAKE_ACK_NONE = 0,
-	CAKE_ACK_FILTER,
-	CAKE_ACK_AGGRESSIVE,
-	CAKE_ACK_MAX
-};
-
-enum {
-	CAKE_ATM_NONE = 0,
-	CAKE_ATM_ATM,
-	CAKE_ATM_PTM,
-	CAKE_ATM_MAX
-};
-
-
-/* TAPRIO */
-enum {
-	TC_TAPRIO_CMD_SET_GATES = 0x00,
-	TC_TAPRIO_CMD_SET_AND_HOLD = 0x01,
-	TC_TAPRIO_CMD_SET_AND_RELEASE = 0x02,
-};
-
-enum {
-	TCA_TAPRIO_SCHED_ENTRY_UNSPEC,
-	TCA_TAPRIO_SCHED_ENTRY_INDEX, /* u32 */
-	TCA_TAPRIO_SCHED_ENTRY_CMD, /* u8 */
-	TCA_TAPRIO_SCHED_ENTRY_GATE_MASK, /* u32 */
-	TCA_TAPRIO_SCHED_ENTRY_INTERVAL, /* u32 */
-	__TCA_TAPRIO_SCHED_ENTRY_MAX,
-};
-#define TCA_TAPRIO_SCHED_ENTRY_MAX (__TCA_TAPRIO_SCHED_ENTRY_MAX - 1)
-
-/* The format for schedule entry list is:
- * [TCA_TAPRIO_SCHED_ENTRY_LIST]
- *   [TCA_TAPRIO_SCHED_ENTRY]
- *     [TCA_TAPRIO_SCHED_ENTRY_CMD]
- *     [TCA_TAPRIO_SCHED_ENTRY_GATES]
- *     [TCA_TAPRIO_SCHED_ENTRY_INTERVAL]
- */
-enum {
-	TCA_TAPRIO_SCHED_UNSPEC,
-	TCA_TAPRIO_SCHED_ENTRY,
-	__TCA_TAPRIO_SCHED_MAX,
-};
-
-#define TCA_TAPRIO_SCHED_MAX (__TCA_TAPRIO_SCHED_MAX - 1)
-
-/* The format for the admin sched (dump only):
- * [TCA_TAPRIO_SCHED_ADMIN_SCHED]
- *   [TCA_TAPRIO_ATTR_SCHED_BASE_TIME]
- *   [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]
- *     [TCA_TAPRIO_ATTR_SCHED_ENTRY]
- *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_CMD]
- *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_GATES]
- *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_INTERVAL]
- */
-
-#define TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST	BIT(0)
-#define TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD	BIT(1)
-
-enum {
-	TCA_TAPRIO_ATTR_UNSPEC,
-	TCA_TAPRIO_ATTR_PRIOMAP, /* struct tc_mqprio_qopt */
-	TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST, /* nested of entry */
-	TCA_TAPRIO_ATTR_SCHED_BASE_TIME, /* s64 */
-	TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY, /* single entry */
-	TCA_TAPRIO_ATTR_SCHED_CLOCKID, /* s32 */
-	TCA_TAPRIO_PAD,
-	TCA_TAPRIO_ATTR_ADMIN_SCHED, /* The admin sched, only used in dump */
-	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME, /* s64 */
-	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION, /* s64 */
-	TCA_TAPRIO_ATTR_FLAGS, /* u32 */
-	TCA_TAPRIO_ATTR_TXTIME_DELAY, /* u32 */
-	__TCA_TAPRIO_ATTR_MAX,
-};
-
-#define TCA_TAPRIO_ATTR_MAX (__TCA_TAPRIO_ATTR_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/posix_types.h b/include/uapi/linux/posix_types.h
deleted file mode 100644
index 9a7a740..0000000
--- a/include/uapi/linux/posix_types.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_POSIX_TYPES_H
-#define _LINUX_POSIX_TYPES_H
-
-#include <linux/stddef.h>
-
-/*
- * This allows for 1024 file descriptors: if NR_OPEN is ever grown
- * beyond that you'll have to change this too. But 1024 fd's seem to be
- * enough even for such "real" unices like OSF/1, so hopefully this is
- * one limit that doesn't have to be changed [again].
- *
- * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in
- * <sys/time.h> (and thus <linux/time.h>) - but this is a more logical
- * place for them. Solved by having dummy defines in <sys/time.h>.
- */
-
-/*
- * This macro may have been defined in <gnu/types.h>. But we always
- * use the one here.
- */
-#undef __FD_SETSIZE
-#define __FD_SETSIZE	1024
-
-typedef struct {
-	unsigned long fds_bits[__FD_SETSIZE / (8 * sizeof(long))];
-} __kernel_fd_set;
-
-/* Type of a signal handler.  */
-typedef void (*__kernel_sighandler_t)(int);
-
-/* Type of a SYSV IPC key.  */
-typedef int __kernel_key_t;
-typedef int __kernel_mqd_t;
-
-#include <asm/posix_types.h>
-
-#endif /* _LINUX_POSIX_TYPES_H */
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
deleted file mode 100644
index 0d4c150..0000000
--- a/include/uapi/linux/sctp.h
+++ /dev/null
@@ -1,1174 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/* SCTP kernel implementation
- * (C) Copyright IBM Corp. 2001, 2004
- * Copyright (c) 1999-2000 Cisco, Inc.
- * Copyright (c) 1999-2001 Motorola, Inc.
- * Copyright (c) 2002 Intel Corp.
- *
- * This file is part of the SCTP kernel implementation
- *
- * This header represents the structures and constants needed to support
- * the SCTP Extension to the Sockets API.
- *
- * This SCTP implementation is free software;
- * you can redistribute it and/or modify it under the terms of
- * the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This SCTP implementation is distributed in the hope that it
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied
- *                 ************************
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU CC; see the file COPYING.  If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * Please send any bug reports or fixes you make to the
- * email address(es):
- *    lksctp developers <linux-sctp@vger.kernel.org>
- *
- * Or submit a bug report through the following website:
- *    http://www.sf.net/projects/lksctp
- *
- * Written or modified by:
- *    La Monte H.P. Yarroll    <piggy@acm.org>
- *    R. Stewart               <randall@sctp.chicago.il.us>
- *    K. Morneau               <kmorneau@cisco.com>
- *    Q. Xie                   <qxie1@email.mot.com>
- *    Karl Knutson             <karl@athena.chicago.il.us>
- *    Jon Grimm                <jgrimm@us.ibm.com>
- *    Daisy Chang              <daisyc@us.ibm.com>
- *    Ryan Layer               <rmlayer@us.ibm.com>
- *    Ardelle Fan              <ardelle.fan@intel.com>
- *    Sridhar Samudrala        <sri@us.ibm.com>
- *    Inaky Perez-Gonzalez     <inaky.gonzalez@intel.com>
- *    Vlad Yasevich            <vladislav.yasevich@hp.com>
- *
- * Any bugs reported given to us we will try to fix... any fixes shared will
- * be incorporated into the next SCTP release.
- */
-
-#ifndef _SCTP_H
-#define _SCTP_H
-
-#include <linux/types.h>
-#include <linux/socket.h>
-
-typedef __s32 sctp_assoc_t;
-
-#define SCTP_FUTURE_ASSOC	0
-#define SCTP_CURRENT_ASSOC	1
-#define SCTP_ALL_ASSOC		2
-
-/* The following symbols come from the Sockets API Extensions for
- * SCTP <draft-ietf-tsvwg-sctpsocket-07.txt>.
- */
-#define SCTP_RTOINFO	0
-#define SCTP_ASSOCINFO  1
-#define SCTP_INITMSG	2
-#define SCTP_NODELAY	3		/* Get/set nodelay option. */
-#define SCTP_AUTOCLOSE	4
-#define SCTP_SET_PEER_PRIMARY_ADDR 5
-#define SCTP_PRIMARY_ADDR	6
-#define SCTP_ADAPTATION_LAYER	7
-#define SCTP_DISABLE_FRAGMENTS	8
-#define SCTP_PEER_ADDR_PARAMS	9
-#define SCTP_DEFAULT_SEND_PARAM	10
-#define SCTP_EVENTS	11
-#define SCTP_I_WANT_MAPPED_V4_ADDR 12	/* Turn on/off mapped v4 addresses  */
-#define SCTP_MAXSEG	13		/* Get/set maximum fragment. */
-#define SCTP_STATUS	14
-#define SCTP_GET_PEER_ADDR_INFO	15
-#define SCTP_DELAYED_ACK_TIME	16
-#define SCTP_DELAYED_ACK SCTP_DELAYED_ACK_TIME
-#define SCTP_DELAYED_SACK SCTP_DELAYED_ACK_TIME
-#define SCTP_CONTEXT	17
-#define SCTP_FRAGMENT_INTERLEAVE	18
-#define SCTP_PARTIAL_DELIVERY_POINT	19 /* Set/Get partial delivery point */
-#define SCTP_MAX_BURST	20		/* Set/Get max burst */
-#define SCTP_AUTH_CHUNK	21	/* Set only: add a chunk type to authenticate */
-#define SCTP_HMAC_IDENT	22
-#define SCTP_AUTH_KEY	23
-#define SCTP_AUTH_ACTIVE_KEY	24
-#define SCTP_AUTH_DELETE_KEY	25
-#define SCTP_PEER_AUTH_CHUNKS	26	/* Read only */
-#define SCTP_LOCAL_AUTH_CHUNKS	27	/* Read only */
-#define SCTP_GET_ASSOC_NUMBER	28	/* Read only */
-#define SCTP_GET_ASSOC_ID_LIST	29	/* Read only */
-#define SCTP_AUTO_ASCONF       30
-#define SCTP_PEER_ADDR_THLDS	31
-#define SCTP_RECVRCVINFO	32
-#define SCTP_RECVNXTINFO	33
-#define SCTP_DEFAULT_SNDINFO	34
-#define SCTP_AUTH_DEACTIVATE_KEY	35
-#define SCTP_REUSE_PORT		36
-
-/* Internal Socket Options. Some of the sctp library functions are
- * implemented using these socket options.
- */
-#define SCTP_SOCKOPT_BINDX_ADD	100	/* BINDX requests for adding addrs */
-#define SCTP_SOCKOPT_BINDX_REM	101	/* BINDX requests for removing addrs. */
-#define SCTP_SOCKOPT_PEELOFF	102	/* peel off association. */
-/* Options 104-106 are deprecated and removed. Do not use this space */
-#define SCTP_SOCKOPT_CONNECTX_OLD	107	/* CONNECTX old requests. */
-#define SCTP_GET_PEER_ADDRS	108		/* Get all peer address. */
-#define SCTP_GET_LOCAL_ADDRS	109		/* Get all local address. */
-#define SCTP_SOCKOPT_CONNECTX	110		/* CONNECTX requests. */
-#define SCTP_SOCKOPT_CONNECTX3	111	/* CONNECTX requests (updated) */
-#define SCTP_GET_ASSOC_STATS	112	/* Read only */
-#define SCTP_PR_SUPPORTED	113
-#define SCTP_DEFAULT_PRINFO	114
-#define SCTP_PR_ASSOC_STATUS	115
-#define SCTP_PR_STREAM_STATUS	116
-#define SCTP_RECONFIG_SUPPORTED	117
-#define SCTP_ENABLE_STREAM_RESET	118
-#define SCTP_RESET_STREAMS	119
-#define SCTP_RESET_ASSOC	120
-#define SCTP_ADD_STREAMS	121
-#define SCTP_SOCKOPT_PEELOFF_FLAGS 122
-#define SCTP_STREAM_SCHEDULER	123
-#define SCTP_STREAM_SCHEDULER_VALUE	124
-#define SCTP_INTERLEAVING_SUPPORTED	125
-#define SCTP_SENDMSG_CONNECT	126
-#define SCTP_EVENT	127
-#define SCTP_ASCONF_SUPPORTED	128
-#define SCTP_AUTH_SUPPORTED	129
-#define SCTP_ECN_SUPPORTED	130
-
-/* PR-SCTP policies */
-#define SCTP_PR_SCTP_NONE	0x0000
-#define SCTP_PR_SCTP_TTL	0x0010
-#define SCTP_PR_SCTP_RTX	0x0020
-#define SCTP_PR_SCTP_PRIO	0x0030
-#define SCTP_PR_SCTP_MAX	SCTP_PR_SCTP_PRIO
-#define SCTP_PR_SCTP_MASK	0x0030
-
-#define __SCTP_PR_INDEX(x)	((x >> 4) - 1)
-#define SCTP_PR_INDEX(x)	__SCTP_PR_INDEX(SCTP_PR_SCTP_ ## x)
-
-#define SCTP_PR_POLICY(x)	((x) & SCTP_PR_SCTP_MASK)
-#define SCTP_PR_SET_POLICY(flags, x)	\
-	do {				\
-		flags &= ~SCTP_PR_SCTP_MASK;	\
-		flags |= x;		\
-	} while (0)
-
-#define SCTP_PR_TTL_ENABLED(x)	(SCTP_PR_POLICY(x) == SCTP_PR_SCTP_TTL)
-#define SCTP_PR_RTX_ENABLED(x)	(SCTP_PR_POLICY(x) == SCTP_PR_SCTP_RTX)
-#define SCTP_PR_PRIO_ENABLED(x)	(SCTP_PR_POLICY(x) == SCTP_PR_SCTP_PRIO)
-
-/* For enable stream reset */
-#define SCTP_ENABLE_RESET_STREAM_REQ	0x01
-#define SCTP_ENABLE_RESET_ASSOC_REQ	0x02
-#define SCTP_ENABLE_CHANGE_ASSOC_REQ	0x04
-#define SCTP_ENABLE_STRRESET_MASK	0x07
-
-#define SCTP_STREAM_RESET_INCOMING	0x01
-#define SCTP_STREAM_RESET_OUTGOING	0x02
-
-/* These are bit fields for msghdr->msg_flags.  See section 5.1.  */
-/* On user space Linux, these live in <bits/socket.h> as an enum.  */
-enum sctp_msg_flags {
-	MSG_NOTIFICATION = 0x8000,
-#define MSG_NOTIFICATION MSG_NOTIFICATION
-};
-
-/* 5.3.1 SCTP Initiation Structure (SCTP_INIT)
- *
- *   This cmsghdr structure provides information for initializing new
- *   SCTP associations with sendmsg().  The SCTP_INITMSG socket option
- *   uses this same data structure.  This structure is not used for
- *   recvmsg().
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   ----------------------
- *   IPPROTO_SCTP  SCTP_INIT      struct sctp_initmsg
- */
-struct sctp_initmsg {
-	__u16 sinit_num_ostreams;
-	__u16 sinit_max_instreams;
-	__u16 sinit_max_attempts;
-	__u16 sinit_max_init_timeo;
-};
-
-/* 5.3.2 SCTP Header Information Structure (SCTP_SNDRCV)
- *
- *   This cmsghdr structure specifies SCTP options for sendmsg() and
- *   describes SCTP header information about a received message through
- *   recvmsg().
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   ----------------------
- *   IPPROTO_SCTP  SCTP_SNDRCV    struct sctp_sndrcvinfo
- */
-struct sctp_sndrcvinfo {
-	__u16 sinfo_stream;
-	__u16 sinfo_ssn;
-	__u16 sinfo_flags;
-	__u32 sinfo_ppid;
-	__u32 sinfo_context;
-	__u32 sinfo_timetolive;
-	__u32 sinfo_tsn;
-	__u32 sinfo_cumtsn;
-	sctp_assoc_t sinfo_assoc_id;
-};
-
-/* 5.3.4 SCTP Send Information Structure (SCTP_SNDINFO)
- *
- *   This cmsghdr structure specifies SCTP options for sendmsg().
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   -------------------
- *   IPPROTO_SCTP  SCTP_SNDINFO   struct sctp_sndinfo
- */
-struct sctp_sndinfo {
-	__u16 snd_sid;
-	__u16 snd_flags;
-	__u32 snd_ppid;
-	__u32 snd_context;
-	sctp_assoc_t snd_assoc_id;
-};
-
-/* 5.3.5 SCTP Receive Information Structure (SCTP_RCVINFO)
- *
- *   This cmsghdr structure describes SCTP receive information
- *   about a received message through recvmsg().
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   -------------------
- *   IPPROTO_SCTP  SCTP_RCVINFO   struct sctp_rcvinfo
- */
-struct sctp_rcvinfo {
-	__u16 rcv_sid;
-	__u16 rcv_ssn;
-	__u16 rcv_flags;
-	__u32 rcv_ppid;
-	__u32 rcv_tsn;
-	__u32 rcv_cumtsn;
-	__u32 rcv_context;
-	sctp_assoc_t rcv_assoc_id;
-};
-
-/* 5.3.6 SCTP Next Receive Information Structure (SCTP_NXTINFO)
- *
- *   This cmsghdr structure describes SCTP receive information
- *   of the next message that will be delivered through recvmsg()
- *   if this information is already available when delivering
- *   the current message.
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   -------------------
- *   IPPROTO_SCTP  SCTP_NXTINFO   struct sctp_nxtinfo
- */
-struct sctp_nxtinfo {
-	__u16 nxt_sid;
-	__u16 nxt_flags;
-	__u32 nxt_ppid;
-	__u32 nxt_length;
-	sctp_assoc_t nxt_assoc_id;
-};
-
-/* 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
- *
- *   This cmsghdr structure specifies SCTP options for sendmsg().
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   -------------------
- *   IPPROTO_SCTP  SCTP_PRINFO    struct sctp_prinfo
- */
-struct sctp_prinfo {
-	__u16 pr_policy;
-	__u32 pr_value;
-};
-
-/* 5.3.8 SCTP AUTH Information Structure (SCTP_AUTHINFO)
- *
- *   This cmsghdr structure specifies SCTP options for sendmsg().
- *
- *   cmsg_level    cmsg_type      cmsg_data[]
- *   ------------  ------------   -------------------
- *   IPPROTO_SCTP  SCTP_AUTHINFO  struct sctp_authinfo
- */
-struct sctp_authinfo {
-	__u16 auth_keynumber;
-};
-
-/*
- *  sinfo_flags: 16 bits (unsigned integer)
- *
- *   This field may contain any of the following flags and is composed of
- *   a bitwise OR of these values.
- */
-enum sctp_sinfo_flags {
-	SCTP_UNORDERED		= (1 << 0), /* Send/receive message unordered. */
-	SCTP_ADDR_OVER		= (1 << 1), /* Override the primary destination. */
-	SCTP_ABORT		= (1 << 2), /* Send an ABORT message to the peer. */
-	SCTP_SACK_IMMEDIATELY	= (1 << 3), /* SACK should be sent without delay. */
-	/* 2 bits here have been used by SCTP_PR_SCTP_MASK */
-	SCTP_SENDALL		= (1 << 6),
-	SCTP_PR_SCTP_ALL	= (1 << 7),
-	SCTP_NOTIFICATION	= MSG_NOTIFICATION, /* Next message is not user msg but notification. */
-	SCTP_EOF		= MSG_FIN,  /* Initiate graceful shutdown process. */
-};
-
-typedef union {
-	__u8   			raw;
-	struct sctp_initmsg	init;
-	struct sctp_sndrcvinfo	sndrcv;
-} sctp_cmsg_data_t;
-
-/* These are cmsg_types.  */
-typedef enum sctp_cmsg_type {
-	SCTP_INIT,		/* 5.2.1 SCTP Initiation Structure */
-#define SCTP_INIT	SCTP_INIT
-	SCTP_SNDRCV,		/* 5.2.2 SCTP Header Information Structure */
-#define SCTP_SNDRCV	SCTP_SNDRCV
-	SCTP_SNDINFO,		/* 5.3.4 SCTP Send Information Structure */
-#define SCTP_SNDINFO	SCTP_SNDINFO
-	SCTP_RCVINFO,		/* 5.3.5 SCTP Receive Information Structure */
-#define SCTP_RCVINFO	SCTP_RCVINFO
-	SCTP_NXTINFO,		/* 5.3.6 SCTP Next Receive Information Structure */
-#define SCTP_NXTINFO	SCTP_NXTINFO
-	SCTP_PRINFO,		/* 5.3.7 SCTP PR-SCTP Information Structure */
-#define SCTP_PRINFO	SCTP_PRINFO
-	SCTP_AUTHINFO,		/* 5.3.8 SCTP AUTH Information Structure */
-#define SCTP_AUTHINFO	SCTP_AUTHINFO
-	SCTP_DSTADDRV4,		/* 5.3.9 SCTP Destination IPv4 Address Structure */
-#define SCTP_DSTADDRV4	SCTP_DSTADDRV4
-	SCTP_DSTADDRV6,		/* 5.3.10 SCTP Destination IPv6 Address Structure */
-#define SCTP_DSTADDRV6	SCTP_DSTADDRV6
-} sctp_cmsg_t;
-
-/*
- * 5.3.1.1 SCTP_ASSOC_CHANGE
- *
- *   Communication notifications inform the ULP that an SCTP association
- *   has either begun or ended. The identifier for a new association is
- *   provided by this notificaion. The notification information has the
- *   following format:
- *
- */
-struct sctp_assoc_change {
-	__u16 sac_type;
-	__u16 sac_flags;
-	__u32 sac_length;
-	__u16 sac_state;
-	__u16 sac_error;
-	__u16 sac_outbound_streams;
-	__u16 sac_inbound_streams;
-	sctp_assoc_t sac_assoc_id;
-	__u8 sac_info[0];
-};
-
-/*
- *   sac_state: 32 bits (signed integer)
- *
- *   This field holds one of a number of values that communicate the
- *   event that happened to the association.  They include:
- *
- *   Note:  The following state names deviate from the API draft as
- *   the names clash too easily with other kernel symbols.
- */
-enum sctp_sac_state {
-	SCTP_COMM_UP,
-	SCTP_COMM_LOST,
-	SCTP_RESTART,
-	SCTP_SHUTDOWN_COMP,
-	SCTP_CANT_STR_ASSOC,
-};
-
-/*
- * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
- *
- *   When a destination address on a multi-homed peer encounters a change
- *   an interface details event is sent.  The information has the
- *   following structure:
- */
-struct sctp_paddr_change {
-	__u16 spc_type;
-	__u16 spc_flags;
-	__u32 spc_length;
-	struct sockaddr_storage spc_aaddr;
-	int spc_state;
-	int spc_error;
-	sctp_assoc_t spc_assoc_id;
-} __attribute__((packed, aligned(4)));
-
-/*
- *    spc_state:  32 bits (signed integer)
- *
- *   This field holds one of a number of values that communicate the
- *   event that happened to the address.  They include:
- */
-enum sctp_spc_state {
-	SCTP_ADDR_AVAILABLE,
-	SCTP_ADDR_UNREACHABLE,
-	SCTP_ADDR_REMOVED,
-	SCTP_ADDR_ADDED,
-	SCTP_ADDR_MADE_PRIM,
-	SCTP_ADDR_CONFIRMED,
-};
-
-
-/*
- * 5.3.1.3 SCTP_REMOTE_ERROR
- *
- *   A remote peer may send an Operational Error message to its peer.
- *   This message indicates a variety of error conditions on an
- *   association. The entire error TLV as it appears on the wire is
- *   included in a SCTP_REMOTE_ERROR event.  Please refer to the SCTP
- *   specification [SCTP] and any extensions for a list of possible
- *   error formats. SCTP error TLVs have the format:
- */
-struct sctp_remote_error {
-	__u16 sre_type;
-	__u16 sre_flags;
-	__u32 sre_length;
-	__be16 sre_error;
-	sctp_assoc_t sre_assoc_id;
-	__u8 sre_data[0];
-};
-
-
-/*
- * 5.3.1.4 SCTP_SEND_FAILED
- *
- *   If SCTP cannot deliver a message it may return the message as a
- *   notification.
- */
-struct sctp_send_failed {
-	__u16 ssf_type;
-	__u16 ssf_flags;
-	__u32 ssf_length;
-	__u32 ssf_error;
-	struct sctp_sndrcvinfo ssf_info;
-	sctp_assoc_t ssf_assoc_id;
-	__u8 ssf_data[0];
-};
-
-/*
- *   ssf_flags: 16 bits (unsigned integer)
- *
- *   The flag value will take one of the following values
- *
- *   SCTP_DATA_UNSENT  - Indicates that the data was never put on
- *                       the wire.
- *
- *   SCTP_DATA_SENT    - Indicates that the data was put on the wire.
- *                       Note that this does not necessarily mean that the
- *                       data was (or was not) successfully delivered.
- */
-enum sctp_ssf_flags {
-	SCTP_DATA_UNSENT,
-	SCTP_DATA_SENT,
-};
-
-/*
- * 5.3.1.5 SCTP_SHUTDOWN_EVENT
- *
- *   When a peer sends a SHUTDOWN, SCTP delivers this notification to
- *   inform the application that it should cease sending data.
- */
-struct sctp_shutdown_event {
-	__u16 sse_type;
-	__u16 sse_flags;
-	__u32 sse_length;
-	sctp_assoc_t sse_assoc_id;
-};
-
-/*
- * 5.3.1.6 SCTP_ADAPTATION_INDICATION
- *
- *   When a peer sends a Adaptation Layer Indication parameter , SCTP
- *   delivers this notification to inform the application
- *   that of the peers requested adaptation layer.
- */
-struct sctp_adaptation_event {
-	__u16 sai_type;
-	__u16 sai_flags;
-	__u32 sai_length;
-	__u32 sai_adaptation_ind;
-	sctp_assoc_t sai_assoc_id;
-};
-
-/*
- * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
- *
- *   When a receiver is engaged in a partial delivery of a
- *   message this notification will be used to indicate
- *   various events.
- */
-struct sctp_pdapi_event {
-	__u16 pdapi_type;
-	__u16 pdapi_flags;
-	__u32 pdapi_length;
-	__u32 pdapi_indication;
-	sctp_assoc_t pdapi_assoc_id;
-	__u32 pdapi_stream;
-	__u32 pdapi_seq;
-};
-
-enum { SCTP_PARTIAL_DELIVERY_ABORTED=0, };
-
-/*
- * 5.3.1.8.  SCTP_AUTHENTICATION_EVENT
- *
- *  When a receiver is using authentication this message will provide
- *  notifications regarding new keys being made active as well as errors.
- */
-struct sctp_authkey_event {
-	__u16 auth_type;
-	__u16 auth_flags;
-	__u32 auth_length;
-	__u16 auth_keynumber;
-	__u16 auth_altkeynumber;
-	__u32 auth_indication;
-	sctp_assoc_t auth_assoc_id;
-};
-
-enum {
-	SCTP_AUTH_NEW_KEY,
-#define	SCTP_AUTH_NEWKEY	SCTP_AUTH_NEW_KEY /* compatible with before */
-	SCTP_AUTH_FREE_KEY,
-	SCTP_AUTH_NO_AUTH,
-};
-
-/*
- * 6.1.9. SCTP_SENDER_DRY_EVENT
- *
- * When the SCTP stack has no more user data to send or retransmit, this
- * notification is given to the user. Also, at the time when a user app
- * subscribes to this event, if there is no data to be sent or
- * retransmit, the stack will immediately send up this notification.
- */
-struct sctp_sender_dry_event {
-	__u16 sender_dry_type;
-	__u16 sender_dry_flags;
-	__u32 sender_dry_length;
-	sctp_assoc_t sender_dry_assoc_id;
-};
-
-#define SCTP_STREAM_RESET_INCOMING_SSN	0x0001
-#define SCTP_STREAM_RESET_OUTGOING_SSN	0x0002
-#define SCTP_STREAM_RESET_DENIED	0x0004
-#define SCTP_STREAM_RESET_FAILED	0x0008
-struct sctp_stream_reset_event {
-	__u16 strreset_type;
-	__u16 strreset_flags;
-	__u32 strreset_length;
-	sctp_assoc_t strreset_assoc_id;
-	__u16 strreset_stream_list[];
-};
-
-#define SCTP_ASSOC_RESET_DENIED		0x0004
-#define SCTP_ASSOC_RESET_FAILED		0x0008
-struct sctp_assoc_reset_event {
-	__u16 assocreset_type;
-	__u16 assocreset_flags;
-	__u32 assocreset_length;
-	sctp_assoc_t assocreset_assoc_id;
-	__u32 assocreset_local_tsn;
-	__u32 assocreset_remote_tsn;
-};
-
-#define SCTP_ASSOC_CHANGE_DENIED	0x0004
-#define SCTP_ASSOC_CHANGE_FAILED	0x0008
-#define SCTP_STREAM_CHANGE_DENIED	SCTP_ASSOC_CHANGE_DENIED
-#define SCTP_STREAM_CHANGE_FAILED	SCTP_ASSOC_CHANGE_FAILED
-struct sctp_stream_change_event {
-	__u16 strchange_type;
-	__u16 strchange_flags;
-	__u32 strchange_length;
-	sctp_assoc_t strchange_assoc_id;
-	__u16 strchange_instrms;
-	__u16 strchange_outstrms;
-};
-
-/*
- * Described in Section 7.3
- *   Ancillary Data and Notification Interest Options
- */
-struct sctp_event_subscribe {
-	__u8 sctp_data_io_event;
-	__u8 sctp_association_event;
-	__u8 sctp_address_event;
-	__u8 sctp_send_failure_event;
-	__u8 sctp_peer_error_event;
-	__u8 sctp_shutdown_event;
-	__u8 sctp_partial_delivery_event;
-	__u8 sctp_adaptation_layer_event;
-	__u8 sctp_authentication_event;
-	__u8 sctp_sender_dry_event;
-	__u8 sctp_stream_reset_event;
-	__u8 sctp_assoc_reset_event;
-	__u8 sctp_stream_change_event;
-};
-
-/*
- * 5.3.1 SCTP Notification Structure
- *
- *   The notification structure is defined as the union of all
- *   notification types.
- *
- */
-union sctp_notification {
-	struct {
-		__u16 sn_type;             /* Notification type. */
-		__u16 sn_flags;
-		__u32 sn_length;
-	} sn_header;
-	struct sctp_assoc_change sn_assoc_change;
-	struct sctp_paddr_change sn_paddr_change;
-	struct sctp_remote_error sn_remote_error;
-	struct sctp_send_failed sn_send_failed;
-	struct sctp_shutdown_event sn_shutdown_event;
-	struct sctp_adaptation_event sn_adaptation_event;
-	struct sctp_pdapi_event sn_pdapi_event;
-	struct sctp_authkey_event sn_authkey_event;
-	struct sctp_sender_dry_event sn_sender_dry_event;
-	struct sctp_stream_reset_event sn_strreset_event;
-	struct sctp_assoc_reset_event sn_assocreset_event;
-	struct sctp_stream_change_event sn_strchange_event;
-};
-
-/* Section 5.3.1
- * All standard values for sn_type flags are greater than 2^15.
- * Values from 2^15 and down are reserved.
- */
-
-enum sctp_sn_type {
-	SCTP_SN_TYPE_BASE	= (1<<15),
-	SCTP_DATA_IO_EVENT	= SCTP_SN_TYPE_BASE,
-#define SCTP_DATA_IO_EVENT		SCTP_DATA_IO_EVENT
-	SCTP_ASSOC_CHANGE,
-#define SCTP_ASSOC_CHANGE		SCTP_ASSOC_CHANGE
-	SCTP_PEER_ADDR_CHANGE,
-#define SCTP_PEER_ADDR_CHANGE		SCTP_PEER_ADDR_CHANGE
-	SCTP_SEND_FAILED,
-#define SCTP_SEND_FAILED		SCTP_SEND_FAILED
-	SCTP_REMOTE_ERROR,
-#define SCTP_REMOTE_ERROR		SCTP_REMOTE_ERROR
-	SCTP_SHUTDOWN_EVENT,
-#define SCTP_SHUTDOWN_EVENT		SCTP_SHUTDOWN_EVENT
-	SCTP_PARTIAL_DELIVERY_EVENT,
-#define SCTP_PARTIAL_DELIVERY_EVENT	SCTP_PARTIAL_DELIVERY_EVENT
-	SCTP_ADAPTATION_INDICATION,
-#define SCTP_ADAPTATION_INDICATION	SCTP_ADAPTATION_INDICATION
-	SCTP_AUTHENTICATION_EVENT,
-#define SCTP_AUTHENTICATION_INDICATION	SCTP_AUTHENTICATION_EVENT
-	SCTP_SENDER_DRY_EVENT,
-#define SCTP_SENDER_DRY_EVENT		SCTP_SENDER_DRY_EVENT
-	SCTP_STREAM_RESET_EVENT,
-#define SCTP_STREAM_RESET_EVENT		SCTP_STREAM_RESET_EVENT
-	SCTP_ASSOC_RESET_EVENT,
-#define SCTP_ASSOC_RESET_EVENT		SCTP_ASSOC_RESET_EVENT
-	SCTP_STREAM_CHANGE_EVENT,
-#define SCTP_STREAM_CHANGE_EVENT	SCTP_STREAM_CHANGE_EVENT
-	SCTP_SN_TYPE_MAX	= SCTP_STREAM_CHANGE_EVENT,
-#define SCTP_SN_TYPE_MAX		SCTP_SN_TYPE_MAX
-};
-
-/* Notification error codes used to fill up the error fields in some
- * notifications.
- * SCTP_PEER_ADDRESS_CHAGE 	: spc_error
- * SCTP_ASSOC_CHANGE		: sac_error
- * These names should be potentially included in the draft 04 of the SCTP
- * sockets API specification.
- */
-typedef enum sctp_sn_error {
-	SCTP_FAILED_THRESHOLD,
-	SCTP_RECEIVED_SACK,
-	SCTP_HEARTBEAT_SUCCESS,
-	SCTP_RESPONSE_TO_USER_REQ,
-	SCTP_INTERNAL_ERROR,
-	SCTP_SHUTDOWN_GUARD_EXPIRES,
-	SCTP_PEER_FAULTY,
-} sctp_sn_error_t;
-
-/*
- * 7.1.1 Retransmission Timeout Parameters (SCTP_RTOINFO)
- *
- *   The protocol parameters used to initialize and bound retransmission
- *   timeout (RTO) are tunable.  See [SCTP] for more information on how
- *   these parameters are used in RTO calculation.
- */
-struct sctp_rtoinfo {
-	sctp_assoc_t	srto_assoc_id;
-	__u32		srto_initial;
-	__u32		srto_max;
-	__u32		srto_min;
-};
-
-/*
- * 7.1.2 Association Parameters (SCTP_ASSOCINFO)
- *
- *   This option is used to both examine and set various association and
- *   endpoint parameters.
- */
-struct sctp_assocparams {
-	sctp_assoc_t	sasoc_assoc_id;
-	__u16		sasoc_asocmaxrxt;
-	__u16		sasoc_number_peer_destinations;
-	__u32		sasoc_peer_rwnd;
-	__u32		sasoc_local_rwnd;
-	__u32		sasoc_cookie_life;
-};
-
-/*
- * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)
- *
- *  Requests that the peer mark the enclosed address as the association
- *  primary. The enclosed address must be one of the association's
- *  locally bound addresses. The following structure is used to make a
- *   set primary request:
- */
-struct sctp_setpeerprim {
-	sctp_assoc_t            sspp_assoc_id;
-	struct sockaddr_storage sspp_addr;
-} __attribute__((packed, aligned(4)));
-
-/*
- * 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
- *
- *  Requests that the local SCTP stack use the enclosed peer address as
- *  the association primary. The enclosed address must be one of the
- *  association peer's addresses. The following structure is used to
- *  make a set peer primary request:
- */
-struct sctp_prim {
-	sctp_assoc_t            ssp_assoc_id;
-	struct sockaddr_storage ssp_addr;
-} __attribute__((packed, aligned(4)));
-
-/* For backward compatibility use, define the old name too */
-#define sctp_setprim	sctp_prim
-
-/*
- * 7.1.11 Set Adaptation Layer Indicator (SCTP_ADAPTATION_LAYER)
- *
- * Requests that the local endpoint set the specified Adaptation Layer
- * Indication parameter for all future INIT and INIT-ACK exchanges.
- */
-struct sctp_setadaptation {
-	__u32	ssb_adaptation_ind;
-};
-
-/*
- * 7.1.13 Peer Address Parameters  (SCTP_PEER_ADDR_PARAMS)
- *
- *   Applications can enable or disable heartbeats for any peer address
- *   of an association, modify an address's heartbeat interval, force a
- *   heartbeat to be sent immediately, and adjust the address's maximum
- *   number of retransmissions sent before an address is considered
- *   unreachable. The following structure is used to access and modify an
- *   address's parameters:
- */
-enum  sctp_spp_flags {
-	SPP_HB_ENABLE = 1<<0,		/*Enable heartbeats*/
-	SPP_HB_DISABLE = 1<<1,		/*Disable heartbeats*/
-	SPP_HB = SPP_HB_ENABLE | SPP_HB_DISABLE,
-	SPP_HB_DEMAND = 1<<2,		/*Send heartbeat immediately*/
-	SPP_PMTUD_ENABLE = 1<<3,	/*Enable PMTU discovery*/
-	SPP_PMTUD_DISABLE = 1<<4,	/*Disable PMTU discovery*/
-	SPP_PMTUD = SPP_PMTUD_ENABLE | SPP_PMTUD_DISABLE,
-	SPP_SACKDELAY_ENABLE = 1<<5,	/*Enable SACK*/
-	SPP_SACKDELAY_DISABLE = 1<<6,	/*Disable SACK*/
-	SPP_SACKDELAY = SPP_SACKDELAY_ENABLE | SPP_SACKDELAY_DISABLE,
-	SPP_HB_TIME_IS_ZERO = 1<<7,	/* Set HB delay to 0 */
-	SPP_IPV6_FLOWLABEL = 1<<8,
-	SPP_DSCP = 1<<9,
-};
-
-struct sctp_paddrparams {
-	sctp_assoc_t		spp_assoc_id;
-	struct sockaddr_storage	spp_address;
-	__u32			spp_hbinterval;
-	__u16			spp_pathmaxrxt;
-	__u32			spp_pathmtu;
-	__u32			spp_sackdelay;
-	__u32			spp_flags;
-	__u32			spp_ipv6_flowlabel;
-	__u8			spp_dscp;
-} __attribute__((packed, aligned(4)));
-
-/*
- * 7.1.18.  Add a chunk that must be authenticated (SCTP_AUTH_CHUNK)
- *
- * This set option adds a chunk type that the user is requesting to be
- * received only in an authenticated way.  Changes to the list of chunks
- * will only effect future associations on the socket.
- */
-struct sctp_authchunk {
-	__u8		sauth_chunk;
-};
-
-/*
- * 7.1.19.  Get or set the list of supported HMAC Identifiers (SCTP_HMAC_IDENT)
- *
- * This option gets or sets the list of HMAC algorithms that the local
- * endpoint requires the peer to use.
- */
-/* This here is only used by user space as is. It might not be a good idea
- * to export/reveal the whole structure with reserved fields etc.
- */
-enum {
-	SCTP_AUTH_HMAC_ID_SHA1 = 1,
-	SCTP_AUTH_HMAC_ID_SHA256 = 3,
-};
-
-struct sctp_hmacalgo {
-	__u32		shmac_num_idents;
-	__u16		shmac_idents[];
-};
-
-/* Sadly, user and kernel space have different names for
- * this structure member, so this is to not break anything.
- */
-#define shmac_number_of_idents	shmac_num_idents
-
-/*
- * 7.1.20.  Set a shared key (SCTP_AUTH_KEY)
- *
- * This option will set a shared secret key which is used to build an
- * association shared key.
- */
-struct sctp_authkey {
-	sctp_assoc_t	sca_assoc_id;
-	__u16		sca_keynumber;
-	__u16		sca_keylength;
-	__u8		sca_key[];
-};
-
-/*
- * 7.1.21.  Get or set the active shared key (SCTP_AUTH_ACTIVE_KEY)
- *
- * This option will get or set the active shared key to be used to build
- * the association shared key.
- */
-
-struct sctp_authkeyid {
-	sctp_assoc_t	scact_assoc_id;
-	__u16		scact_keynumber;
-};
-
-
-/*
- * 7.1.23.  Get or set delayed ack timer (SCTP_DELAYED_SACK)
- *
- * This option will effect the way delayed acks are performed.  This
- * option allows you to get or set the delayed ack time, in
- * milliseconds.  It also allows changing the delayed ack frequency.
- * Changing the frequency to 1 disables the delayed sack algorithm.  If
- * the assoc_id is 0, then this sets or gets the endpoints default
- * values.  If the assoc_id field is non-zero, then the set or get
- * effects the specified association for the one to many model (the
- * assoc_id field is ignored by the one to one model).  Note that if
- * sack_delay or sack_freq are 0 when setting this option, then the
- * current values will remain unchanged.
- */
-struct sctp_sack_info {
-	sctp_assoc_t	sack_assoc_id;
-	uint32_t	sack_delay;
-	uint32_t	sack_freq;
-};
-
-struct sctp_assoc_value {
-    sctp_assoc_t            assoc_id;
-    uint32_t                assoc_value;
-};
-
-struct sctp_stream_value {
-	sctp_assoc_t assoc_id;
-	uint16_t stream_id;
-	uint16_t stream_value;
-};
-
-/*
- * 7.2.2 Peer Address Information
- *
- *   Applications can retrieve information about a specific peer address
- *   of an association, including its reachability state, congestion
- *   window, and retransmission timer values.  This information is
- *   read-only. The following structure is used to access this
- *   information:
- */
-struct sctp_paddrinfo {
-	sctp_assoc_t		spinfo_assoc_id;
-	struct sockaddr_storage	spinfo_address;
-	__s32			spinfo_state;
-	__u32			spinfo_cwnd;
-	__u32			spinfo_srtt;
-	__u32			spinfo_rto;
-	__u32			spinfo_mtu;
-} __attribute__((packed, aligned(4)));
-
-/* Peer addresses's state. */
-/* UNKNOWN: Peer address passed by the upper layer in sendmsg or connect[x]
- * calls.
- * UNCONFIRMED: Peer address received in INIT/INIT-ACK address parameters.
- *              Not yet confirmed by a heartbeat and not available for data
- *		transfers.
- * ACTIVE : Peer address confirmed, active and available for data transfers.
- * INACTIVE: Peer address inactive and not available for data transfers.
- */
-enum sctp_spinfo_state {
-	SCTP_INACTIVE,
-	SCTP_PF,
-	SCTP_ACTIVE,
-	SCTP_UNCONFIRMED,
-	SCTP_UNKNOWN = 0xffff  /* Value used for transport state unknown */
-};
-
-/*
- * 7.2.1 Association Status (SCTP_STATUS)
- *
- *   Applications can retrieve current status information about an
- *   association, including association state, peer receiver window size,
- *   number of unacked data chunks, and number of data chunks pending
- *   receipt.  This information is read-only.  The following structure is
- *   used to access this information:
- */
-struct sctp_status {
-	sctp_assoc_t		sstat_assoc_id;
-	__s32			sstat_state;
-	__u32			sstat_rwnd;
-	__u16			sstat_unackdata;
-	__u16			sstat_penddata;
-	__u16			sstat_instrms;
-	__u16			sstat_outstrms;
-	__u32			sstat_fragmentation_point;
-	struct sctp_paddrinfo	sstat_primary;
-};
-
-/*
- * 7.2.3.  Get the list of chunks the peer requires to be authenticated
- *         (SCTP_PEER_AUTH_CHUNKS)
- *
- * This option gets a list of chunks for a specified association that
- * the peer requires to be received authenticated only.
- */
-struct sctp_authchunks {
-	sctp_assoc_t	gauth_assoc_id;
-	__u32		gauth_number_of_chunks;
-	uint8_t		gauth_chunks[];
-};
-
-/* The broken spelling has been released already in lksctp-tools header,
- * so don't break anyone, now that it's fixed.
- */
-#define guth_number_of_chunks	gauth_number_of_chunks
-
-/* Association states.  */
-enum sctp_sstat_state {
-	SCTP_EMPTY                = 0,
-	SCTP_CLOSED               = 1,
-	SCTP_COOKIE_WAIT          = 2,
-	SCTP_COOKIE_ECHOED        = 3,
-	SCTP_ESTABLISHED          = 4,
-	SCTP_SHUTDOWN_PENDING     = 5,
-	SCTP_SHUTDOWN_SENT        = 6,
-	SCTP_SHUTDOWN_RECEIVED    = 7,
-	SCTP_SHUTDOWN_ACK_SENT    = 8,
-};
-
-/*
- * 8.2.6. Get the Current Identifiers of Associations
- *        (SCTP_GET_ASSOC_ID_LIST)
- *
- * This option gets the current list of SCTP association identifiers of
- * the SCTP associations handled by a one-to-many style socket.
- */
-struct sctp_assoc_ids {
-	__u32		gaids_number_of_ids;
-	sctp_assoc_t	gaids_assoc_id[];
-};
-
-/*
- * 8.3, 8.5 get all peer/local addresses in an association.
- * This parameter struct is used by SCTP_GET_PEER_ADDRS and
- * SCTP_GET_LOCAL_ADDRS socket options used internally to implement
- * sctp_getpaddrs() and sctp_getladdrs() API.
- */
-struct sctp_getaddrs_old {
-	sctp_assoc_t            assoc_id;
-	int			addr_num;
-	struct sockaddr		*addrs;
-};
-
-struct sctp_getaddrs {
-	sctp_assoc_t		assoc_id; /*input*/
-	__u32			addr_num; /*output*/
-	__u8			addrs[0]; /*output, variable size*/
-};
-
-/* A socket user request obtained via SCTP_GET_ASSOC_STATS that retrieves
- * association stats. All stats are counts except sas_maxrto and
- * sas_obs_rto_ipaddr. maxrto is the max observed rto + transport since
- * the last call. Will return 0 when RTO was not update since last call
- */
-struct sctp_assoc_stats {
-	sctp_assoc_t	sas_assoc_id;    /* Input */
-					 /* Transport of observed max RTO */
-	struct sockaddr_storage sas_obs_rto_ipaddr;
-	__u64		sas_maxrto;      /* Maximum Observed RTO for period */
-	__u64		sas_isacks;	 /* SACKs received */
-	__u64		sas_osacks;	 /* SACKs sent */
-	__u64		sas_opackets;	 /* Packets sent */
-	__u64		sas_ipackets;	 /* Packets received */
-	__u64		sas_rtxchunks;   /* Retransmitted Chunks */
-	__u64		sas_outofseqtsns;/* TSN received > next expected */
-	__u64		sas_idupchunks;  /* Dups received (ordered+unordered) */
-	__u64		sas_gapcnt;      /* Gap Acknowledgements Received */
-	__u64		sas_ouodchunks;  /* Unordered data chunks sent */
-	__u64		sas_iuodchunks;  /* Unordered data chunks received */
-	__u64		sas_oodchunks;	 /* Ordered data chunks sent */
-	__u64		sas_iodchunks;	 /* Ordered data chunks received */
-	__u64		sas_octrlchunks; /* Control chunks sent */
-	__u64		sas_ictrlchunks; /* Control chunks received */
-};
-
-/*
- * 8.1 sctp_bindx()
- *
- * The flags parameter is formed from the bitwise OR of zero or more of the
- * following currently defined flags:
- */
-#define SCTP_BINDX_ADD_ADDR 0x01
-#define SCTP_BINDX_REM_ADDR 0x02
-
-/* This is the structure that is passed as an argument(optval) to
- * getsockopt(SCTP_SOCKOPT_PEELOFF).
- */
-typedef struct {
-	sctp_assoc_t associd;
-	int sd;
-} sctp_peeloff_arg_t;
-
-typedef struct {
-	sctp_peeloff_arg_t p_arg;
-	unsigned flags;
-} sctp_peeloff_flags_arg_t;
-
-/*
- *  Peer Address Thresholds socket option
- */
-struct sctp_paddrthlds {
-	sctp_assoc_t spt_assoc_id;
-	struct sockaddr_storage spt_address;
-	__u16 spt_pathmaxrxt;
-	__u16 spt_pathpfthld;
-};
-
-/*
- * Socket Option for Getting the Association/Stream-Specific PR-SCTP Status
- */
-struct sctp_prstatus {
-	sctp_assoc_t sprstat_assoc_id;
-	__u16 sprstat_sid;
-	__u16 sprstat_policy;
-	__u64 sprstat_abandoned_unsent;
-	__u64 sprstat_abandoned_sent;
-};
-
-struct sctp_default_prinfo {
-	sctp_assoc_t pr_assoc_id;
-	__u32 pr_value;
-	__u16 pr_policy;
-};
-
-struct sctp_info {
-	__u32	sctpi_tag;
-	__u32	sctpi_state;
-	__u32	sctpi_rwnd;
-	__u16	sctpi_unackdata;
-	__u16	sctpi_penddata;
-	__u16	sctpi_instrms;
-	__u16	sctpi_outstrms;
-	__u32	sctpi_fragmentation_point;
-	__u32	sctpi_inqueue;
-	__u32	sctpi_outqueue;
-	__u32	sctpi_overall_error;
-	__u32	sctpi_max_burst;
-	__u32	sctpi_maxseg;
-	__u32	sctpi_peer_rwnd;
-	__u32	sctpi_peer_tag;
-	__u8	sctpi_peer_capable;
-	__u8	sctpi_peer_sack;
-	__u16	__reserved1;
-
-	/* assoc status info */
-	__u64	sctpi_isacks;
-	__u64	sctpi_osacks;
-	__u64	sctpi_opackets;
-	__u64	sctpi_ipackets;
-	__u64	sctpi_rtxchunks;
-	__u64	sctpi_outofseqtsns;
-	__u64	sctpi_idupchunks;
-	__u64	sctpi_gapcnt;
-	__u64	sctpi_ouodchunks;
-	__u64	sctpi_iuodchunks;
-	__u64	sctpi_oodchunks;
-	__u64	sctpi_iodchunks;
-	__u64	sctpi_octrlchunks;
-	__u64	sctpi_ictrlchunks;
-
-	/* primary transport info */
-	struct sockaddr_storage	sctpi_p_address;
-	__s32	sctpi_p_state;
-	__u32	sctpi_p_cwnd;
-	__u32	sctpi_p_srtt;
-	__u32	sctpi_p_rto;
-	__u32	sctpi_p_hbinterval;
-	__u32	sctpi_p_pathmaxrxt;
-	__u32	sctpi_p_sackdelay;
-	__u32	sctpi_p_sackfreq;
-	__u32	sctpi_p_ssthresh;
-	__u32	sctpi_p_partial_bytes_acked;
-	__u32	sctpi_p_flight_size;
-	__u16	sctpi_p_error;
-	__u16	__reserved2;
-
-	/* sctp sock info */
-	__u32	sctpi_s_autoclose;
-	__u32	sctpi_s_adaptation_ind;
-	__u32	sctpi_s_pd_point;
-	__u8	sctpi_s_nodelay;
-	__u8	sctpi_s_disable_fragments;
-	__u8	sctpi_s_v4mapped;
-	__u8	sctpi_s_frag_interleave;
-	__u32	sctpi_s_type;
-	__u32	__reserved3;
-};
-
-struct sctp_reset_streams {
-	sctp_assoc_t srs_assoc_id;
-	uint16_t srs_flags;
-	uint16_t srs_number_streams;	/* 0 == ALL */
-	uint16_t srs_stream_list[];	/* list if srs_num_streams is not 0 */
-};
-
-struct sctp_add_streams {
-	sctp_assoc_t sas_assoc_id;
-	uint16_t sas_instrms;
-	uint16_t sas_outstrms;
-};
-
-struct sctp_event {
-	sctp_assoc_t se_assoc_id;
-	uint16_t se_type;
-	uint8_t se_on;
-};
-
-/* SCTP Stream schedulers */
-enum sctp_sched_type {
-	SCTP_SS_FCFS,
-	SCTP_SS_DEFAULT = SCTP_SS_FCFS,
-	SCTP_SS_PRIO,
-	SCTP_SS_RR,
-	SCTP_SS_MAX = SCTP_SS_RR
-};
-
-#endif /* _SCTP_H */
diff --git a/include/uapi/linux/seg6.h b/include/uapi/linux/seg6.h
deleted file mode 100644
index 329163e..0000000
--- a/include/uapi/linux/seg6.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- *  SR-IPv6 implementation
- *
- *  Author:
- *  David Lebrun <david.lebrun@uclouvain.be>
- *
- *
- *  This program is free software; you can redistribute it and/or
- *      modify it under the terms of the GNU General Public License
- *      as published by the Free Software Foundation; either version
- *      2 of the License, or (at your option) any later version.
- */
-
-#ifndef _LINUX_SEG6_H
-#define _LINUX_SEG6_H
-
-#include <linux/types.h>
-#include <linux/in6.h>		/* For struct in6_addr. */
-
-/*
- * SRH
- */
-struct ipv6_sr_hdr {
-	__u8	nexthdr;
-	__u8	hdrlen;
-	__u8	type;
-	__u8	segments_left;
-	__u8	first_segment; /* Represents the last_entry field of SRH */
-	__u8	flags;
-	__u16	tag;
-
-	struct in6_addr segments[0];
-};
-
-#define SR6_FLAG1_PROTECTED	(1 << 6)
-#define SR6_FLAG1_OAM		(1 << 5)
-#define SR6_FLAG1_ALERT		(1 << 4)
-#define SR6_FLAG1_HMAC		(1 << 3)
-
-#define SR6_TLV_INGRESS		1
-#define SR6_TLV_EGRESS		2
-#define SR6_TLV_OPAQUE		3
-#define SR6_TLV_PADDING		4
-#define SR6_TLV_HMAC		5
-
-#define sr_has_hmac(srh) ((srh)->flags & SR6_FLAG1_HMAC)
-
-struct sr6_tlv {
-	__u8 type;
-	__u8 len;
-	__u8 data[0];
-};
-
-#endif
diff --git a/include/uapi/linux/seg6_genl.h b/include/uapi/linux/seg6_genl.h
deleted file mode 100644
index 0c23052..0000000
--- a/include/uapi/linux/seg6_genl.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_SEG6_GENL_H
-#define _LINUX_SEG6_GENL_H
-
-#define SEG6_GENL_NAME		"SEG6"
-#define SEG6_GENL_VERSION	0x1
-
-enum {
-	SEG6_ATTR_UNSPEC,
-	SEG6_ATTR_DST,
-	SEG6_ATTR_DSTLEN,
-	SEG6_ATTR_HMACKEYID,
-	SEG6_ATTR_SECRET,
-	SEG6_ATTR_SECRETLEN,
-	SEG6_ATTR_ALGID,
-	SEG6_ATTR_HMACINFO,
-	__SEG6_ATTR_MAX,
-};
-
-#define SEG6_ATTR_MAX (__SEG6_ATTR_MAX - 1)
-
-enum {
-	SEG6_CMD_UNSPEC,
-	SEG6_CMD_SETHMAC,
-	SEG6_CMD_DUMPHMAC,
-	SEG6_CMD_SET_TUNSRC,
-	SEG6_CMD_GET_TUNSRC,
-	__SEG6_CMD_MAX,
-};
-
-#define SEG6_CMD_MAX (__SEG6_CMD_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/seg6_hmac.h b/include/uapi/linux/seg6_hmac.h
deleted file mode 100644
index 3fb3412..0000000
--- a/include/uapi/linux/seg6_hmac.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_SEG6_HMAC_H
-#define _LINUX_SEG6_HMAC_H
-
-#include <linux/types.h>
-#include <linux/seg6.h>
-
-#define SEG6_HMAC_SECRET_LEN	64
-#define SEG6_HMAC_FIELD_LEN	32
-
-struct sr6_tlv_hmac {
-	struct sr6_tlv tlvhdr;
-	__u16 reserved;
-	__be32 hmackeyid;
-	__u8 hmac[SEG6_HMAC_FIELD_LEN];
-};
-
-enum {
-	SEG6_HMAC_ALGO_SHA1 = 1,
-	SEG6_HMAC_ALGO_SHA256 = 2,
-};
-
-#endif
diff --git a/include/uapi/linux/seg6_iptunnel.h b/include/uapi/linux/seg6_iptunnel.h
deleted file mode 100644
index 3004e98..0000000
--- a/include/uapi/linux/seg6_iptunnel.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- *  SR-IPv6 implementation
- *
- *  Author:
- *  David Lebrun <david.lebrun@uclouvain.be>
- *
- *
- *  This program is free software; you can redistribute it and/or
- *      modify it under the terms of the GNU General Public License
- *      as published by the Free Software Foundation; either version
- *      2 of the License, or (at your option) any later version.
- */
-
-#ifndef _LINUX_SEG6_IPTUNNEL_H
-#define _LINUX_SEG6_IPTUNNEL_H
-
-#include <linux/seg6.h>		/* For struct ipv6_sr_hdr. */
-
-enum {
-	SEG6_IPTUNNEL_UNSPEC,
-	SEG6_IPTUNNEL_SRH,
-	__SEG6_IPTUNNEL_MAX,
-};
-#define SEG6_IPTUNNEL_MAX (__SEG6_IPTUNNEL_MAX - 1)
-
-struct seg6_iptunnel_encap {
-	int mode;
-	struct ipv6_sr_hdr srh[0];
-};
-
-#define SEG6_IPTUN_ENCAP_SIZE(x) ((sizeof(*x)) + (((x)->srh->hdrlen + 1) << 3))
-
-enum {
-	SEG6_IPTUN_MODE_INLINE,
-	SEG6_IPTUN_MODE_ENCAP,
-	SEG6_IPTUN_MODE_L2ENCAP,
-};
-
-
-#endif
diff --git a/include/uapi/linux/seg6_local.h b/include/uapi/linux/seg6_local.h
deleted file mode 100644
index 5312de8..0000000
--- a/include/uapi/linux/seg6_local.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- *  SR-IPv6 implementation
- *
- *  Author:
- *  David Lebrun <david.lebrun@uclouvain.be>
- *
- *
- *  This program is free software; you can redistribute it and/or
- *      modify it under the terms of the GNU General Public License
- *      as published by the Free Software Foundation; either version
- *      2 of the License, or (at your option) any later version.
- */
-
-#ifndef _LINUX_SEG6_LOCAL_H
-#define _LINUX_SEG6_LOCAL_H
-
-#include <linux/seg6.h>
-
-enum {
-	SEG6_LOCAL_UNSPEC,
-	SEG6_LOCAL_ACTION,
-	SEG6_LOCAL_SRH,
-	SEG6_LOCAL_TABLE,
-	SEG6_LOCAL_NH4,
-	SEG6_LOCAL_NH6,
-	SEG6_LOCAL_IIF,
-	SEG6_LOCAL_OIF,
-	SEG6_LOCAL_BPF,
-	__SEG6_LOCAL_MAX,
-};
-#define SEG6_LOCAL_MAX (__SEG6_LOCAL_MAX - 1)
-
-enum {
-	SEG6_LOCAL_ACTION_UNSPEC	= 0,
-	/* node segment */
-	SEG6_LOCAL_ACTION_END		= 1,
-	/* adjacency segment (IPv6 cross-connect) */
-	SEG6_LOCAL_ACTION_END_X		= 2,
-	/* lookup of next seg NH in table */
-	SEG6_LOCAL_ACTION_END_T		= 3,
-	/* decap and L2 cross-connect */
-	SEG6_LOCAL_ACTION_END_DX2	= 4,
-	/* decap and IPv6 cross-connect */
-	SEG6_LOCAL_ACTION_END_DX6	= 5,
-	/* decap and IPv4 cross-connect */
-	SEG6_LOCAL_ACTION_END_DX4	= 6,
-	/* decap and lookup of DA in v6 table */
-	SEG6_LOCAL_ACTION_END_DT6	= 7,
-	/* decap and lookup of DA in v4 table */
-	SEG6_LOCAL_ACTION_END_DT4	= 8,
-	/* binding segment with insertion */
-	SEG6_LOCAL_ACTION_END_B6	= 9,
-	/* binding segment with encapsulation */
-	SEG6_LOCAL_ACTION_END_B6_ENCAP	= 10,
-	/* binding segment with MPLS encap */
-	SEG6_LOCAL_ACTION_END_BM	= 11,
-	/* lookup last seg in table */
-	SEG6_LOCAL_ACTION_END_S		= 12,
-	/* forward to SR-unaware VNF with static proxy */
-	SEG6_LOCAL_ACTION_END_AS	= 13,
-	/* forward to SR-unaware VNF with masquerading */
-	SEG6_LOCAL_ACTION_END_AM	= 14,
-	/* custom BPF action */
-	SEG6_LOCAL_ACTION_END_BPF	= 15,
-
-	__SEG6_LOCAL_ACTION_MAX,
-};
-
-#define SEG6_LOCAL_ACTION_MAX (__SEG6_LOCAL_ACTION_MAX - 1)
-
-enum {
-	SEG6_LOCAL_BPF_PROG_UNSPEC,
-	SEG6_LOCAL_BPF_PROG,
-	SEG6_LOCAL_BPF_PROG_NAME,
-	__SEG6_LOCAL_BPF_PROG_MAX,
-};
-
-#define SEG6_LOCAL_BPF_PROG_MAX (__SEG6_LOCAL_BPF_PROG_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/snmp.h b/include/uapi/linux/snmp.h
deleted file mode 100644
index 549a31c..0000000
--- a/include/uapi/linux/snmp.h
+++ /dev/null
@@ -1,326 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * Definitions for MIBs
- *
- * Author: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
- */
-
-#ifndef _LINUX_SNMP_H
-#define _LINUX_SNMP_H
-
-/* ipstats mib definitions */
-/*
- * RFC 1213:  MIB-II
- * RFC 2011 (updates 1213):  SNMPv2-MIB-IP
- * RFC 2863:  Interfaces Group MIB
- * RFC 2465:  IPv6 MIB: General Group
- * draft-ietf-ipv6-rfc2011-update-10.txt: MIB for IP: IP Statistics Tables
- */
-enum
-{
-	IPSTATS_MIB_NUM = 0,
-/* frequently written fields in fast path, kept in same cache line */
-	IPSTATS_MIB_INPKTS,			/* InReceives */
-	IPSTATS_MIB_INOCTETS,			/* InOctets */
-	IPSTATS_MIB_INDELIVERS,			/* InDelivers */
-	IPSTATS_MIB_OUTFORWDATAGRAMS,		/* OutForwDatagrams */
-	IPSTATS_MIB_OUTPKTS,			/* OutRequests */
-	IPSTATS_MIB_OUTOCTETS,			/* OutOctets */
-/* other fields */
-	IPSTATS_MIB_INHDRERRORS,		/* InHdrErrors */
-	IPSTATS_MIB_INTOOBIGERRORS,		/* InTooBigErrors */
-	IPSTATS_MIB_INNOROUTES,			/* InNoRoutes */
-	IPSTATS_MIB_INADDRERRORS,		/* InAddrErrors */
-	IPSTATS_MIB_INUNKNOWNPROTOS,		/* InUnknownProtos */
-	IPSTATS_MIB_INTRUNCATEDPKTS,		/* InTruncatedPkts */
-	IPSTATS_MIB_INDISCARDS,			/* InDiscards */
-	IPSTATS_MIB_OUTDISCARDS,		/* OutDiscards */
-	IPSTATS_MIB_OUTNOROUTES,		/* OutNoRoutes */
-	IPSTATS_MIB_REASMTIMEOUT,		/* ReasmTimeout */
-	IPSTATS_MIB_REASMREQDS,			/* ReasmReqds */
-	IPSTATS_MIB_REASMOKS,			/* ReasmOKs */
-	IPSTATS_MIB_REASMFAILS,			/* ReasmFails */
-	IPSTATS_MIB_FRAGOKS,			/* FragOKs */
-	IPSTATS_MIB_FRAGFAILS,			/* FragFails */
-	IPSTATS_MIB_FRAGCREATES,		/* FragCreates */
-	IPSTATS_MIB_INMCASTPKTS,		/* InMcastPkts */
-	IPSTATS_MIB_OUTMCASTPKTS,		/* OutMcastPkts */
-	IPSTATS_MIB_INBCASTPKTS,		/* InBcastPkts */
-	IPSTATS_MIB_OUTBCASTPKTS,		/* OutBcastPkts */
-	IPSTATS_MIB_INMCASTOCTETS,		/* InMcastOctets */
-	IPSTATS_MIB_OUTMCASTOCTETS,		/* OutMcastOctets */
-	IPSTATS_MIB_INBCASTOCTETS,		/* InBcastOctets */
-	IPSTATS_MIB_OUTBCASTOCTETS,		/* OutBcastOctets */
-	IPSTATS_MIB_CSUMERRORS,			/* InCsumErrors */
-	IPSTATS_MIB_NOECTPKTS,			/* InNoECTPkts */
-	IPSTATS_MIB_ECT1PKTS,			/* InECT1Pkts */
-	IPSTATS_MIB_ECT0PKTS,			/* InECT0Pkts */
-	IPSTATS_MIB_CEPKTS,			/* InCEPkts */
-	IPSTATS_MIB_REASM_OVERLAPS,		/* ReasmOverlaps */
-	__IPSTATS_MIB_MAX
-};
-
-/* icmp mib definitions */
-/*
- * RFC 1213:  MIB-II ICMP Group
- * RFC 2011 (updates 1213):  SNMPv2 MIB for IP: ICMP group
- */
-enum
-{
-	ICMP_MIB_NUM = 0,
-	ICMP_MIB_INMSGS,			/* InMsgs */
-	ICMP_MIB_INERRORS,			/* InErrors */
-	ICMP_MIB_INDESTUNREACHS,		/* InDestUnreachs */
-	ICMP_MIB_INTIMEEXCDS,			/* InTimeExcds */
-	ICMP_MIB_INPARMPROBS,			/* InParmProbs */
-	ICMP_MIB_INSRCQUENCHS,			/* InSrcQuenchs */
-	ICMP_MIB_INREDIRECTS,			/* InRedirects */
-	ICMP_MIB_INECHOS,			/* InEchos */
-	ICMP_MIB_INECHOREPS,			/* InEchoReps */
-	ICMP_MIB_INTIMESTAMPS,			/* InTimestamps */
-	ICMP_MIB_INTIMESTAMPREPS,		/* InTimestampReps */
-	ICMP_MIB_INADDRMASKS,			/* InAddrMasks */
-	ICMP_MIB_INADDRMASKREPS,		/* InAddrMaskReps */
-	ICMP_MIB_OUTMSGS,			/* OutMsgs */
-	ICMP_MIB_OUTERRORS,			/* OutErrors */
-	ICMP_MIB_OUTDESTUNREACHS,		/* OutDestUnreachs */
-	ICMP_MIB_OUTTIMEEXCDS,			/* OutTimeExcds */
-	ICMP_MIB_OUTPARMPROBS,			/* OutParmProbs */
-	ICMP_MIB_OUTSRCQUENCHS,			/* OutSrcQuenchs */
-	ICMP_MIB_OUTREDIRECTS,			/* OutRedirects */
-	ICMP_MIB_OUTECHOS,			/* OutEchos */
-	ICMP_MIB_OUTECHOREPS,			/* OutEchoReps */
-	ICMP_MIB_OUTTIMESTAMPS,			/* OutTimestamps */
-	ICMP_MIB_OUTTIMESTAMPREPS,		/* OutTimestampReps */
-	ICMP_MIB_OUTADDRMASKS,			/* OutAddrMasks */
-	ICMP_MIB_OUTADDRMASKREPS,		/* OutAddrMaskReps */
-	ICMP_MIB_CSUMERRORS,			/* InCsumErrors */
-	__ICMP_MIB_MAX
-};
-
-#define __ICMPMSG_MIB_MAX 512	/* Out+In for all 8-bit ICMP types */
-
-/* icmp6 mib definitions */
-/*
- * RFC 2466:  ICMPv6-MIB
- */
-enum
-{
-	ICMP6_MIB_NUM = 0,
-	ICMP6_MIB_INMSGS,			/* InMsgs */
-	ICMP6_MIB_INERRORS,			/* InErrors */
-	ICMP6_MIB_OUTMSGS,			/* OutMsgs */
-	ICMP6_MIB_OUTERRORS,			/* OutErrors */
-	ICMP6_MIB_CSUMERRORS,			/* InCsumErrors */
-	__ICMP6_MIB_MAX
-};
-
-#define __ICMP6MSG_MIB_MAX 512 /* Out+In for all 8-bit ICMPv6 types */
-
-/* tcp mib definitions */
-/*
- * RFC 1213:  MIB-II TCP group
- * RFC 2012 (updates 1213):  SNMPv2-MIB-TCP
- */
-enum
-{
-	TCP_MIB_NUM = 0,
-	TCP_MIB_RTOALGORITHM,			/* RtoAlgorithm */
-	TCP_MIB_RTOMIN,				/* RtoMin */
-	TCP_MIB_RTOMAX,				/* RtoMax */
-	TCP_MIB_MAXCONN,			/* MaxConn */
-	TCP_MIB_ACTIVEOPENS,			/* ActiveOpens */
-	TCP_MIB_PASSIVEOPENS,			/* PassiveOpens */
-	TCP_MIB_ATTEMPTFAILS,			/* AttemptFails */
-	TCP_MIB_ESTABRESETS,			/* EstabResets */
-	TCP_MIB_CURRESTAB,			/* CurrEstab */
-	TCP_MIB_INSEGS,				/* InSegs */
-	TCP_MIB_OUTSEGS,			/* OutSegs */
-	TCP_MIB_RETRANSSEGS,			/* RetransSegs */
-	TCP_MIB_INERRS,				/* InErrs */
-	TCP_MIB_OUTRSTS,			/* OutRsts */
-	TCP_MIB_CSUMERRORS,			/* InCsumErrors */
-	__TCP_MIB_MAX
-};
-
-/* udp mib definitions */
-/*
- * RFC 1213:  MIB-II UDP group
- * RFC 2013 (updates 1213):  SNMPv2-MIB-UDP
- */
-enum
-{
-	UDP_MIB_NUM = 0,
-	UDP_MIB_INDATAGRAMS,			/* InDatagrams */
-	UDP_MIB_NOPORTS,			/* NoPorts */
-	UDP_MIB_INERRORS,			/* InErrors */
-	UDP_MIB_OUTDATAGRAMS,			/* OutDatagrams */
-	UDP_MIB_RCVBUFERRORS,			/* RcvbufErrors */
-	UDP_MIB_SNDBUFERRORS,			/* SndbufErrors */
-	UDP_MIB_CSUMERRORS,			/* InCsumErrors */
-	UDP_MIB_IGNOREDMULTI,			/* IgnoredMulti */
-	__UDP_MIB_MAX
-};
-
-/* linux mib definitions */
-enum
-{
-	LINUX_MIB_NUM = 0,
-	LINUX_MIB_SYNCOOKIESSENT,		/* SyncookiesSent */
-	LINUX_MIB_SYNCOOKIESRECV,		/* SyncookiesRecv */
-	LINUX_MIB_SYNCOOKIESFAILED,		/* SyncookiesFailed */
-	LINUX_MIB_EMBRYONICRSTS,		/* EmbryonicRsts */
-	LINUX_MIB_PRUNECALLED,			/* PruneCalled */
-	LINUX_MIB_RCVPRUNED,			/* RcvPruned */
-	LINUX_MIB_OFOPRUNED,			/* OfoPruned */
-	LINUX_MIB_OUTOFWINDOWICMPS,		/* OutOfWindowIcmps */
-	LINUX_MIB_LOCKDROPPEDICMPS,		/* LockDroppedIcmps */
-	LINUX_MIB_ARPFILTER,			/* ArpFilter */
-	LINUX_MIB_TIMEWAITED,			/* TimeWaited */
-	LINUX_MIB_TIMEWAITRECYCLED,		/* TimeWaitRecycled */
-	LINUX_MIB_TIMEWAITKILLED,		/* TimeWaitKilled */
-	LINUX_MIB_PAWSACTIVEREJECTED,		/* PAWSActiveRejected */
-	LINUX_MIB_PAWSESTABREJECTED,		/* PAWSEstabRejected */
-	LINUX_MIB_DELAYEDACKS,			/* DelayedACKs */
-	LINUX_MIB_DELAYEDACKLOCKED,		/* DelayedACKLocked */
-	LINUX_MIB_DELAYEDACKLOST,		/* DelayedACKLost */
-	LINUX_MIB_LISTENOVERFLOWS,		/* ListenOverflows */
-	LINUX_MIB_LISTENDROPS,			/* ListenDrops */
-	LINUX_MIB_TCPHPHITS,			/* TCPHPHits */
-	LINUX_MIB_TCPPUREACKS,			/* TCPPureAcks */
-	LINUX_MIB_TCPHPACKS,			/* TCPHPAcks */
-	LINUX_MIB_TCPRENORECOVERY,		/* TCPRenoRecovery */
-	LINUX_MIB_TCPSACKRECOVERY,		/* TCPSackRecovery */
-	LINUX_MIB_TCPSACKRENEGING,		/* TCPSACKReneging */
-	LINUX_MIB_TCPSACKREORDER,		/* TCPSACKReorder */
-	LINUX_MIB_TCPRENOREORDER,		/* TCPRenoReorder */
-	LINUX_MIB_TCPTSREORDER,			/* TCPTSReorder */
-	LINUX_MIB_TCPFULLUNDO,			/* TCPFullUndo */
-	LINUX_MIB_TCPPARTIALUNDO,		/* TCPPartialUndo */
-	LINUX_MIB_TCPDSACKUNDO,			/* TCPDSACKUndo */
-	LINUX_MIB_TCPLOSSUNDO,			/* TCPLossUndo */
-	LINUX_MIB_TCPLOSTRETRANSMIT,		/* TCPLostRetransmit */
-	LINUX_MIB_TCPRENOFAILURES,		/* TCPRenoFailures */
-	LINUX_MIB_TCPSACKFAILURES,		/* TCPSackFailures */
-	LINUX_MIB_TCPLOSSFAILURES,		/* TCPLossFailures */
-	LINUX_MIB_TCPFASTRETRANS,		/* TCPFastRetrans */
-	LINUX_MIB_TCPSLOWSTARTRETRANS,		/* TCPSlowStartRetrans */
-	LINUX_MIB_TCPTIMEOUTS,			/* TCPTimeouts */
-	LINUX_MIB_TCPLOSSPROBES,		/* TCPLossProbes */
-	LINUX_MIB_TCPLOSSPROBERECOVERY,		/* TCPLossProbeRecovery */
-	LINUX_MIB_TCPRENORECOVERYFAIL,		/* TCPRenoRecoveryFail */
-	LINUX_MIB_TCPSACKRECOVERYFAIL,		/* TCPSackRecoveryFail */
-	LINUX_MIB_TCPRCVCOLLAPSED,		/* TCPRcvCollapsed */
-	LINUX_MIB_TCPDSACKOLDSENT,		/* TCPDSACKOldSent */
-	LINUX_MIB_TCPDSACKOFOSENT,		/* TCPDSACKOfoSent */
-	LINUX_MIB_TCPDSACKRECV,			/* TCPDSACKRecv */
-	LINUX_MIB_TCPDSACKOFORECV,		/* TCPDSACKOfoRecv */
-	LINUX_MIB_TCPABORTONDATA,		/* TCPAbortOnData */
-	LINUX_MIB_TCPABORTONCLOSE,		/* TCPAbortOnClose */
-	LINUX_MIB_TCPABORTONMEMORY,		/* TCPAbortOnMemory */
-	LINUX_MIB_TCPABORTONTIMEOUT,		/* TCPAbortOnTimeout */
-	LINUX_MIB_TCPABORTONLINGER,		/* TCPAbortOnLinger */
-	LINUX_MIB_TCPABORTFAILED,		/* TCPAbortFailed */
-	LINUX_MIB_TCPMEMORYPRESSURES,		/* TCPMemoryPressures */
-	LINUX_MIB_TCPMEMORYPRESSURESCHRONO,	/* TCPMemoryPressuresChrono */
-	LINUX_MIB_TCPSACKDISCARD,		/* TCPSACKDiscard */
-	LINUX_MIB_TCPDSACKIGNOREDOLD,		/* TCPSACKIgnoredOld */
-	LINUX_MIB_TCPDSACKIGNOREDNOUNDO,	/* TCPSACKIgnoredNoUndo */
-	LINUX_MIB_TCPSPURIOUSRTOS,		/* TCPSpuriousRTOs */
-	LINUX_MIB_TCPMD5NOTFOUND,		/* TCPMD5NotFound */
-	LINUX_MIB_TCPMD5UNEXPECTED,		/* TCPMD5Unexpected */
-	LINUX_MIB_TCPMD5FAILURE,		/* TCPMD5Failure */
-	LINUX_MIB_SACKSHIFTED,
-	LINUX_MIB_SACKMERGED,
-	LINUX_MIB_SACKSHIFTFALLBACK,
-	LINUX_MIB_TCPBACKLOGDROP,
-	LINUX_MIB_PFMEMALLOCDROP,
-	LINUX_MIB_TCPMINTTLDROP, /* RFC 5082 */
-	LINUX_MIB_TCPDEFERACCEPTDROP,
-	LINUX_MIB_IPRPFILTER, /* IP Reverse Path Filter (rp_filter) */
-	LINUX_MIB_TCPTIMEWAITOVERFLOW,		/* TCPTimeWaitOverflow */
-	LINUX_MIB_TCPREQQFULLDOCOOKIES,		/* TCPReqQFullDoCookies */
-	LINUX_MIB_TCPREQQFULLDROP,		/* TCPReqQFullDrop */
-	LINUX_MIB_TCPRETRANSFAIL,		/* TCPRetransFail */
-	LINUX_MIB_TCPRCVCOALESCE,		/* TCPRcvCoalesce */
-	LINUX_MIB_TCPBACKLOGCOALESCE,		/* TCPBacklogCoalesce */
-	LINUX_MIB_TCPOFOQUEUE,			/* TCPOFOQueue */
-	LINUX_MIB_TCPOFODROP,			/* TCPOFODrop */
-	LINUX_MIB_TCPOFOMERGE,			/* TCPOFOMerge */
-	LINUX_MIB_TCPCHALLENGEACK,		/* TCPChallengeACK */
-	LINUX_MIB_TCPSYNCHALLENGE,		/* TCPSYNChallenge */
-	LINUX_MIB_TCPFASTOPENACTIVE,		/* TCPFastOpenActive */
-	LINUX_MIB_TCPFASTOPENACTIVEFAIL,	/* TCPFastOpenActiveFail */
-	LINUX_MIB_TCPFASTOPENPASSIVE,		/* TCPFastOpenPassive*/
-	LINUX_MIB_TCPFASTOPENPASSIVEFAIL,	/* TCPFastOpenPassiveFail */
-	LINUX_MIB_TCPFASTOPENLISTENOVERFLOW,	/* TCPFastOpenListenOverflow */
-	LINUX_MIB_TCPFASTOPENCOOKIEREQD,	/* TCPFastOpenCookieReqd */
-	LINUX_MIB_TCPFASTOPENBLACKHOLE,		/* TCPFastOpenBlackholeDetect */
-	LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES, /* TCPSpuriousRtxHostQueues */
-	LINUX_MIB_BUSYPOLLRXPACKETS,		/* BusyPollRxPackets */
-	LINUX_MIB_TCPAUTOCORKING,		/* TCPAutoCorking */
-	LINUX_MIB_TCPFROMZEROWINDOWADV,		/* TCPFromZeroWindowAdv */
-	LINUX_MIB_TCPTOZEROWINDOWADV,		/* TCPToZeroWindowAdv */
-	LINUX_MIB_TCPWANTZEROWINDOWADV,		/* TCPWantZeroWindowAdv */
-	LINUX_MIB_TCPSYNRETRANS,		/* TCPSynRetrans */
-	LINUX_MIB_TCPORIGDATASENT,		/* TCPOrigDataSent */
-	LINUX_MIB_TCPHYSTARTTRAINDETECT,	/* TCPHystartTrainDetect */
-	LINUX_MIB_TCPHYSTARTTRAINCWND,		/* TCPHystartTrainCwnd */
-	LINUX_MIB_TCPHYSTARTDELAYDETECT,	/* TCPHystartDelayDetect */
-	LINUX_MIB_TCPHYSTARTDELAYCWND,		/* TCPHystartDelayCwnd */
-	LINUX_MIB_TCPACKSKIPPEDSYNRECV,		/* TCPACKSkippedSynRecv */
-	LINUX_MIB_TCPACKSKIPPEDPAWS,		/* TCPACKSkippedPAWS */
-	LINUX_MIB_TCPACKSKIPPEDSEQ,		/* TCPACKSkippedSeq */
-	LINUX_MIB_TCPACKSKIPPEDFINWAIT2,	/* TCPACKSkippedFinWait2 */
-	LINUX_MIB_TCPACKSKIPPEDTIMEWAIT,	/* TCPACKSkippedTimeWait */
-	LINUX_MIB_TCPACKSKIPPEDCHALLENGE,	/* TCPACKSkippedChallenge */
-	LINUX_MIB_TCPWINPROBE,			/* TCPWinProbe */
-	LINUX_MIB_TCPKEEPALIVE,			/* TCPKeepAlive */
-	LINUX_MIB_TCPMTUPFAIL,			/* TCPMTUPFail */
-	LINUX_MIB_TCPMTUPSUCCESS,		/* TCPMTUPSuccess */
-	LINUX_MIB_TCPDELIVERED,			/* TCPDelivered */
-	LINUX_MIB_TCPDELIVEREDCE,		/* TCPDeliveredCE */
-	LINUX_MIB_TCPACKCOMPRESSED,		/* TCPAckCompressed */
-	LINUX_MIB_TCPZEROWINDOWDROP,		/* TCPZeroWindowDrop */
-	LINUX_MIB_TCPRCVQDROP,			/* TCPRcvQDrop */
-	LINUX_MIB_TCPWQUEUETOOBIG,		/* TCPWqueueTooBig */
-	LINUX_MIB_TCPFASTOPENPASSIVEALTKEY,	/* TCPFastOpenPassiveAltKey */
-	__LINUX_MIB_MAX
-};
-
-/* linux Xfrm mib definitions */
-enum
-{
-	LINUX_MIB_XFRMNUM = 0,
-	LINUX_MIB_XFRMINERROR,			/* XfrmInError */
-	LINUX_MIB_XFRMINBUFFERERROR,		/* XfrmInBufferError */
-	LINUX_MIB_XFRMINHDRERROR,		/* XfrmInHdrError */
-	LINUX_MIB_XFRMINNOSTATES,		/* XfrmInNoStates */
-	LINUX_MIB_XFRMINSTATEPROTOERROR,	/* XfrmInStateProtoError */
-	LINUX_MIB_XFRMINSTATEMODEERROR,		/* XfrmInStateModeError */
-	LINUX_MIB_XFRMINSTATESEQERROR,		/* XfrmInStateSeqError */
-	LINUX_MIB_XFRMINSTATEEXPIRED,		/* XfrmInStateExpired */
-	LINUX_MIB_XFRMINSTATEMISMATCH,		/* XfrmInStateMismatch */
-	LINUX_MIB_XFRMINSTATEINVALID,		/* XfrmInStateInvalid */
-	LINUX_MIB_XFRMINTMPLMISMATCH,		/* XfrmInTmplMismatch */
-	LINUX_MIB_XFRMINNOPOLS,			/* XfrmInNoPols */
-	LINUX_MIB_XFRMINPOLBLOCK,		/* XfrmInPolBlock */
-	LINUX_MIB_XFRMINPOLERROR,		/* XfrmInPolError */
-	LINUX_MIB_XFRMOUTERROR,			/* XfrmOutError */
-	LINUX_MIB_XFRMOUTBUNDLEGENERROR,	/* XfrmOutBundleGenError */
-	LINUX_MIB_XFRMOUTBUNDLECHECKERROR,	/* XfrmOutBundleCheckError */
-	LINUX_MIB_XFRMOUTNOSTATES,		/* XfrmOutNoStates */
-	LINUX_MIB_XFRMOUTSTATEPROTOERROR,	/* XfrmOutStateProtoError */
-	LINUX_MIB_XFRMOUTSTATEMODEERROR,	/* XfrmOutStateModeError */
-	LINUX_MIB_XFRMOUTSTATESEQERROR,		/* XfrmOutStateSeqError */
-	LINUX_MIB_XFRMOUTSTATEEXPIRED,		/* XfrmOutStateExpired */
-	LINUX_MIB_XFRMOUTPOLBLOCK,		/* XfrmOutPolBlock */
-	LINUX_MIB_XFRMOUTPOLDEAD,		/* XfrmOutPolDead */
-	LINUX_MIB_XFRMOUTPOLERROR,		/* XfrmOutPolError */
-	LINUX_MIB_XFRMFWDHDRERROR,		/* XfrmFwdHdrError*/
-	LINUX_MIB_XFRMOUTSTATEINVALID,		/* XfrmOutStateInvalid */
-	LINUX_MIB_XFRMACQUIREERROR,		/* XfrmAcquireError */
-	__LINUX_MIB_XFRMMAX
-};
-
-#endif	/* _LINUX_SNMP_H */
diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
deleted file mode 100644
index debcf26..0000000
--- a/include/uapi/linux/socket.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_SOCKET_H
-#define _LINUX_SOCKET_H
-
-/*
- * Desired design of maximum size and alignment (see RFC2553)
- */
-#define _K_SS_MAXSIZE	128	/* Implementation specific max size */
-
-typedef unsigned short __kernel_sa_family_t;
-
-/*
- * The definition uses anonymous union and struct in order to control the
- * default alignment.
- */
-struct __kernel_sockaddr_storage {
-	union {
-		struct {
-			__kernel_sa_family_t	ss_family; /* address family */
-			/* Following field(s) are implementation specific */
-			char __data[_K_SS_MAXSIZE - sizeof(unsigned short)];
-				/* space to achieve desired size, */
-				/* _SS_MAXSIZE value minus size of ss_family */
-		};
-		void *__align; /* implementation specific desired alignment */
-	};
-};
-
-#endif /* _LINUX_SOCKET_H */
diff --git a/include/uapi/linux/sockios.h b/include/uapi/linux/sockios.h
deleted file mode 100644
index 7d1bccb..0000000
--- a/include/uapi/linux/sockios.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * INET		An implementation of the TCP/IP protocol suite for the LINUX
- *		operating system.  INET is implemented using the  BSD Socket
- *		interface as the means of communication with the user level.
- *
- *		Definitions of the socket-level I/O control calls.
- *
- * Version:	@(#)sockios.h	1.0.2	03/09/93
- *
- * Authors:	Ross Biro
- *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- */
-#ifndef _LINUX_SOCKIOS_H
-#define _LINUX_SOCKIOS_H
-
-#include <asm/bitsperlong.h>
-#include <asm/sockios.h>
-
-/* Linux-specific socket ioctls */
-#define SIOCINQ		FIONREAD
-#define SIOCOUTQ	TIOCOUTQ        /* output queue size (not sent + not acked) */
-
-#define SOCK_IOC_TYPE	0x89
-
-/*
- * the timeval/timespec data structure layout is defined by libc,
- * so we need to cover both possible versions on 32-bit.
- */
-/* Get stamp (timeval) */
-#define SIOCGSTAMP_NEW	 _IOR(SOCK_IOC_TYPE, 0x06, long long[2])
-/* Get stamp (timespec) */
-#define SIOCGSTAMPNS_NEW _IOR(SOCK_IOC_TYPE, 0x07, long long[2])
-
-#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
-/* on 64-bit and x32, avoid the ?: operator */
-#define SIOCGSTAMP	SIOCGSTAMP_OLD
-#define SIOCGSTAMPNS	SIOCGSTAMPNS_OLD
-#else
-#define SIOCGSTAMP	((sizeof(struct timeval))  == 8 ? \
-			 SIOCGSTAMP_OLD   : SIOCGSTAMP_NEW)
-#define SIOCGSTAMPNS	((sizeof(struct timespec)) == 8 ? \
-			 SIOCGSTAMPNS_OLD : SIOCGSTAMPNS_NEW)
-#endif
-
-/* Routing table calls. */
-#define SIOCADDRT	0x890B		/* add routing table entry	*/
-#define SIOCDELRT	0x890C		/* delete routing table entry	*/
-#define SIOCRTMSG	0x890D		/* unused			*/
-
-/* Socket configuration controls. */
-#define SIOCGIFNAME	0x8910		/* get iface name		*/
-#define SIOCSIFLINK	0x8911		/* set iface channel		*/
-#define SIOCGIFCONF	0x8912		/* get iface list		*/
-#define SIOCGIFFLAGS	0x8913		/* get flags			*/
-#define SIOCSIFFLAGS	0x8914		/* set flags			*/
-#define SIOCGIFADDR	0x8915		/* get PA address		*/
-#define SIOCSIFADDR	0x8916		/* set PA address		*/
-#define SIOCGIFDSTADDR	0x8917		/* get remote PA address	*/
-#define SIOCSIFDSTADDR	0x8918		/* set remote PA address	*/
-#define SIOCGIFBRDADDR	0x8919		/* get broadcast PA address	*/
-#define SIOCSIFBRDADDR	0x891a		/* set broadcast PA address	*/
-#define SIOCGIFNETMASK	0x891b		/* get network PA mask		*/
-#define SIOCSIFNETMASK	0x891c		/* set network PA mask		*/
-#define SIOCGIFMETRIC	0x891d		/* get metric			*/
-#define SIOCSIFMETRIC	0x891e		/* set metric			*/
-#define SIOCGIFMEM	0x891f		/* get memory address (BSD)	*/
-#define SIOCSIFMEM	0x8920		/* set memory address (BSD)	*/
-#define SIOCGIFMTU	0x8921		/* get MTU size			*/
-#define SIOCSIFMTU	0x8922		/* set MTU size			*/
-#define SIOCSIFNAME	0x8923		/* set interface name */
-#define	SIOCSIFHWADDR	0x8924		/* set hardware address 	*/
-#define SIOCGIFENCAP	0x8925		/* get/set encapsulations       */
-#define SIOCSIFENCAP	0x8926		
-#define SIOCGIFHWADDR	0x8927		/* Get hardware address		*/
-#define SIOCGIFSLAVE	0x8929		/* Driver slaving support	*/
-#define SIOCSIFSLAVE	0x8930
-#define SIOCADDMULTI	0x8931		/* Multicast address lists	*/
-#define SIOCDELMULTI	0x8932
-#define SIOCGIFINDEX	0x8933		/* name -> if_index mapping	*/
-#define SIOGIFINDEX	SIOCGIFINDEX	/* misprint compatibility :-)	*/
-#define SIOCSIFPFLAGS	0x8934		/* set/get extended flags set	*/
-#define SIOCGIFPFLAGS	0x8935
-#define SIOCDIFADDR	0x8936		/* delete PA address		*/
-#define	SIOCSIFHWBROADCAST	0x8937	/* set hardware broadcast addr	*/
-#define SIOCGIFCOUNT	0x8938		/* get number of devices */
-
-#define SIOCGIFBR	0x8940		/* Bridging support		*/
-#define SIOCSIFBR	0x8941		/* Set bridging options 	*/
-
-#define SIOCGIFTXQLEN	0x8942		/* Get the tx queue length	*/
-#define SIOCSIFTXQLEN	0x8943		/* Set the tx queue length 	*/
-
-/* SIOCGIFDIVERT was:	0x8944		Frame diversion support */
-/* SIOCSIFDIVERT was:	0x8945		Set frame diversion options */
-
-#define SIOCETHTOOL	0x8946		/* Ethtool interface		*/
-
-#define SIOCGMIIPHY	0x8947		/* Get address of MII PHY in use. */
-#define SIOCGMIIREG	0x8948		/* Read MII PHY register.	*/
-#define SIOCSMIIREG	0x8949		/* Write MII PHY register.	*/
-
-#define SIOCWANDEV	0x894A		/* get/set netdev parameters	*/
-
-#define SIOCOUTQNSD	0x894B		/* output queue size (not sent only) */
-#define SIOCGSKNS	0x894C		/* get socket network namespace */
-
-/* ARP cache control calls. */
-		    /*  0x8950 - 0x8952  * obsolete calls, don't re-use */
-#define SIOCDARP	0x8953		/* delete ARP table entry	*/
-#define SIOCGARP	0x8954		/* get ARP table entry		*/
-#define SIOCSARP	0x8955		/* set ARP table entry		*/
-
-/* RARP cache control calls. */
-#define SIOCDRARP	0x8960		/* delete RARP table entry	*/
-#define SIOCGRARP	0x8961		/* get RARP table entry		*/
-#define SIOCSRARP	0x8962		/* set RARP table entry		*/
-
-/* Driver configuration calls */
-
-#define SIOCGIFMAP	0x8970		/* Get device parameters	*/
-#define SIOCSIFMAP	0x8971		/* Set device parameters	*/
-
-/* DLCI configuration calls */
-
-#define SIOCADDDLCI	0x8980		/* Create new DLCI device	*/
-#define SIOCDELDLCI	0x8981		/* Delete DLCI device		*/
-
-#define SIOCGIFVLAN	0x8982		/* 802.1Q VLAN support		*/
-#define SIOCSIFVLAN	0x8983		/* Set 802.1Q VLAN options 	*/
-
-/* bonding calls */
-
-#define SIOCBONDENSLAVE	0x8990		/* enslave a device to the bond */
-#define SIOCBONDRELEASE 0x8991		/* release a slave from the bond*/
-#define SIOCBONDSETHWADDR      0x8992	/* set the hw addr of the bond  */
-#define SIOCBONDSLAVEINFOQUERY 0x8993   /* rtn info about slave state   */
-#define SIOCBONDINFOQUERY      0x8994	/* rtn info about bond state    */
-#define SIOCBONDCHANGEACTIVE   0x8995   /* update to a new active slave */
-			
-/* bridge calls */
-#define SIOCBRADDBR     0x89a0		/* create new bridge device     */
-#define SIOCBRDELBR     0x89a1		/* remove bridge device         */
-#define SIOCBRADDIF	0x89a2		/* add interface to bridge      */
-#define SIOCBRDELIF	0x89a3		/* remove interface from bridge */
-
-/* hardware time stamping: parameters in linux/net_tstamp.h */
-#define SIOCSHWTSTAMP	0x89b0		/* set and get config		*/
-#define SIOCGHWTSTAMP	0x89b1		/* get config			*/
-
-/* Device private ioctl calls */
-
-/*
- *	These 16 ioctls are available to devices via the do_ioctl() device
- *	vector. Each device should include this file and redefine these names
- *	as their own. Because these are device dependent it is a good idea
- *	_NOT_ to issue them to random objects and hope.
- *
- *	THESE IOCTLS ARE _DEPRECATED_ AND WILL DISAPPEAR IN 2.5.X -DaveM
- */
- 
-#define SIOCDEVPRIVATE	0x89F0	/* to 89FF */
-
-/*
- *	These 16 ioctl calls are protocol private
- */
- 
-#define SIOCPROTOPRIVATE 0x89E0 /* to 89EF */
-#endif	/* _LINUX_SOCKIOS_H */
diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
deleted file mode 100644
index 23e025f..0000000
--- a/include/uapi/linux/stddef.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-
-
-#ifndef __always_inline
-#define __always_inline __inline__
-#endif
diff --git a/include/uapi/linux/sysinfo.h b/include/uapi/linux/sysinfo.h
deleted file mode 100644
index 435d5c2..0000000
--- a/include/uapi/linux/sysinfo.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_SYSINFO_H
-#define _LINUX_SYSINFO_H
-
-#include <linux/types.h>
-
-#define SI_LOAD_SHIFT	16
-struct sysinfo {
-	__kernel_long_t uptime;		/* Seconds since boot */
-	__kernel_ulong_t loads[3];	/* 1, 5, and 15 minute load averages */
-	__kernel_ulong_t totalram;	/* Total usable main memory size */
-	__kernel_ulong_t freeram;	/* Available memory size */
-	__kernel_ulong_t sharedram;	/* Amount of shared memory */
-	__kernel_ulong_t bufferram;	/* Memory used by buffers */
-	__kernel_ulong_t totalswap;	/* Total swap space size */
-	__kernel_ulong_t freeswap;	/* swap space still available */
-	__u16 procs;		   	/* Number of current processes */
-	__u16 pad;		   	/* Explicit padding for m68k */
-	__kernel_ulong_t totalhigh;	/* Total high memory size */
-	__kernel_ulong_t freehigh;	/* Available high memory size */
-	__u32 mem_unit;			/* Memory unit size in bytes */
-	char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)];	/* Padding: libc5 uses this.. */
-};
-
-#endif /* _LINUX_SYSINFO_H */
diff --git a/include/uapi/linux/tc_act/tc_ct.h b/include/uapi/linux/tc_act/tc_ct.h
deleted file mode 100644
index 5fb1d7a..0000000
--- a/include/uapi/linux/tc_act/tc_ct.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __UAPI_TC_CT_H
-#define __UAPI_TC_CT_H
-
-#include <linux/types.h>
-#include <linux/pkt_cls.h>
-
-enum {
-	TCA_CT_UNSPEC,
-	TCA_CT_PARMS,
-	TCA_CT_TM,
-	TCA_CT_ACTION,		/* u16 */
-	TCA_CT_ZONE,		/* u16 */
-	TCA_CT_MARK,		/* u32 */
-	TCA_CT_MARK_MASK,	/* u32 */
-	TCA_CT_LABELS,		/* u128 */
-	TCA_CT_LABELS_MASK,	/* u128 */
-	TCA_CT_NAT_IPV4_MIN,	/* be32 */
-	TCA_CT_NAT_IPV4_MAX,	/* be32 */
-	TCA_CT_NAT_IPV6_MIN,	/* struct in6_addr */
-	TCA_CT_NAT_IPV6_MAX,	/* struct in6_addr */
-	TCA_CT_NAT_PORT_MIN,	/* be16 */
-	TCA_CT_NAT_PORT_MAX,	/* be16 */
-	TCA_CT_PAD,
-	__TCA_CT_MAX
-};
-
-#define TCA_CT_MAX (__TCA_CT_MAX - 1)
-
-#define TCA_CT_ACT_COMMIT	(1 << 0)
-#define TCA_CT_ACT_FORCE	(1 << 1)
-#define TCA_CT_ACT_CLEAR	(1 << 2)
-#define TCA_CT_ACT_NAT		(1 << 3)
-#define TCA_CT_ACT_NAT_SRC	(1 << 4)
-#define TCA_CT_ACT_NAT_DST	(1 << 5)
-
-struct tc_ct {
-	tc_gen;
-};
-
-#endif /* __UAPI_TC_CT_H */
diff --git a/include/uapi/linux/tc_act/tc_ctinfo.h b/include/uapi/linux/tc_act/tc_ctinfo.h
deleted file mode 100644
index f5f26d9..0000000
--- a/include/uapi/linux/tc_act/tc_ctinfo.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __UAPI_TC_CTINFO_H
-#define __UAPI_TC_CTINFO_H
-
-#include <linux/types.h>
-#include <linux/pkt_cls.h>
-
-struct tc_ctinfo {
-	tc_gen;
-};
-
-enum {
-	TCA_CTINFO_UNSPEC,
-	TCA_CTINFO_PAD,
-	TCA_CTINFO_TM,
-	TCA_CTINFO_ACT,
-	TCA_CTINFO_ZONE,
-	TCA_CTINFO_PARMS_DSCP_MASK,
-	TCA_CTINFO_PARMS_DSCP_STATEMASK,
-	TCA_CTINFO_PARMS_CPMARK_MASK,
-	TCA_CTINFO_STATS_DSCP_SET,
-	TCA_CTINFO_STATS_DSCP_ERROR,
-	TCA_CTINFO_STATS_CPMARK_SET,
-	__TCA_CTINFO_MAX
-};
-
-#define TCA_CTINFO_MAX (__TCA_CTINFO_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tc_act/tc_ife.h b/include/uapi/linux/tc_act/tc_ife.h
deleted file mode 100644
index 8c401f1..0000000
--- a/include/uapi/linux/tc_act/tc_ife.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __UAPI_TC_IFE_H
-#define __UAPI_TC_IFE_H
-
-#include <linux/types.h>
-#include <linux/pkt_cls.h>
-#include <linux/ife.h>
-
-/* Flag bits for now just encoding/decoding; mutually exclusive */
-#define IFE_ENCODE 1
-#define IFE_DECODE 0
-
-struct tc_ife {
-	tc_gen;
-	__u16 flags;
-};
-
-/*XXX: We need to encode the total number of bytes consumed */
-enum {
-	TCA_IFE_UNSPEC,
-	TCA_IFE_PARMS,
-	TCA_IFE_TM,
-	TCA_IFE_DMAC,
-	TCA_IFE_SMAC,
-	TCA_IFE_TYPE,
-	TCA_IFE_METALST,
-	TCA_IFE_PAD,
-	__TCA_IFE_MAX
-};
-#define TCA_IFE_MAX (__TCA_IFE_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tc_act/tc_mpls.h b/include/uapi/linux/tc_act/tc_mpls.h
deleted file mode 100644
index 9360e95..0000000
--- a/include/uapi/linux/tc_act/tc_mpls.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* Copyright (C) 2019 Netronome Systems, Inc. */
-
-#ifndef __LINUX_TC_MPLS_H
-#define __LINUX_TC_MPLS_H
-
-#include <linux/pkt_cls.h>
-
-#define TCA_MPLS_ACT_POP	1
-#define TCA_MPLS_ACT_PUSH	2
-#define TCA_MPLS_ACT_MODIFY	3
-#define TCA_MPLS_ACT_DEC_TTL	4
-
-struct tc_mpls {
-	tc_gen;		/* generic TC action fields. */
-	int m_action;	/* action of type TCA_MPLS_ACT_*. */
-};
-
-enum {
-	TCA_MPLS_UNSPEC,
-	TCA_MPLS_TM,	/* struct tcf_t; time values associated with action. */
-	TCA_MPLS_PARMS,	/* struct tc_mpls; action type and general TC fields. */
-	TCA_MPLS_PAD,
-	TCA_MPLS_PROTO,	/* be16; eth_type of pushed or next (for pop) header. */
-	TCA_MPLS_LABEL,	/* u32; MPLS label. Lower 20 bits are used. */
-	TCA_MPLS_TC,	/* u8; MPLS TC field. Lower 3 bits are used. */
-	TCA_MPLS_TTL,	/* u8; MPLS TTL field. Must not be 0. */
-	TCA_MPLS_BOS,	/* u8; MPLS BOS field. Either 1 or 0. */
-	__TCA_MPLS_MAX,
-};
-#define TCA_MPLS_MAX (__TCA_MPLS_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tc_act/tc_pedit.h b/include/uapi/linux/tc_act/tc_pedit.h
deleted file mode 100644
index f3e61b0..0000000
--- a/include/uapi/linux/tc_act/tc_pedit.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_TC_PED_H
-#define __LINUX_TC_PED_H
-
-#include <linux/types.h>
-#include <linux/pkt_cls.h>
-
-enum {
-	TCA_PEDIT_UNSPEC,
-	TCA_PEDIT_TM,
-	TCA_PEDIT_PARMS,
-	TCA_PEDIT_PAD,
-	TCA_PEDIT_PARMS_EX,
-	TCA_PEDIT_KEYS_EX,
-	TCA_PEDIT_KEY_EX,
-	__TCA_PEDIT_MAX
-};
-
-#define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1)
-
-enum {
-	TCA_PEDIT_KEY_EX_HTYPE = 1,
-	TCA_PEDIT_KEY_EX_CMD = 2,
-	__TCA_PEDIT_KEY_EX_MAX
-};
-
-#define TCA_PEDIT_KEY_EX_MAX (__TCA_PEDIT_KEY_EX_MAX - 1)
-
- /* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It
-  * means no specific header type - offset is relative to the network layer
-  */
-enum pedit_header_type {
-	TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK = 0,
-	TCA_PEDIT_KEY_EX_HDR_TYPE_ETH = 1,
-	TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 = 2,
-	TCA_PEDIT_KEY_EX_HDR_TYPE_IP6 = 3,
-	TCA_PEDIT_KEY_EX_HDR_TYPE_TCP = 4,
-	TCA_PEDIT_KEY_EX_HDR_TYPE_UDP = 5,
-	__PEDIT_HDR_TYPE_MAX,
-};
-
-#define TCA_PEDIT_HDR_TYPE_MAX (__PEDIT_HDR_TYPE_MAX - 1)
-
-enum pedit_cmd {
-	TCA_PEDIT_KEY_EX_CMD_SET = 0,
-	TCA_PEDIT_KEY_EX_CMD_ADD = 1,
-	__PEDIT_CMD_MAX,
-};
-
-#define TCA_PEDIT_CMD_MAX (__PEDIT_CMD_MAX - 1)
-
-struct tc_pedit_key {
-	__u32           mask;  /* AND */
-	__u32           val;   /*XOR */
-	__u32           off;  /*offset */
-	__u32           at;
-	__u32           offmask;
-	__u32           shift;
-};
-
-struct tc_pedit_sel {
-	tc_gen;
-	unsigned char           nkeys;
-	unsigned char           flags;
-	struct tc_pedit_key     keys[0];
-};
-
-#define tc_pedit tc_pedit_sel
-
-#endif
diff --git a/include/uapi/linux/tc_act/tc_sample.h b/include/uapi/linux/tc_act/tc_sample.h
deleted file mode 100644
index fee1bcc..0000000
--- a/include/uapi/linux/tc_act/tc_sample.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_TC_SAMPLE_H
-#define __LINUX_TC_SAMPLE_H
-
-#include <linux/types.h>
-#include <linux/pkt_cls.h>
-#include <linux/if_ether.h>
-
-struct tc_sample {
-	tc_gen;
-};
-
-enum {
-	TCA_SAMPLE_UNSPEC,
-	TCA_SAMPLE_TM,
-	TCA_SAMPLE_PARMS,
-	TCA_SAMPLE_RATE,
-	TCA_SAMPLE_TRUNC_SIZE,
-	TCA_SAMPLE_PSAMPLE_GROUP,
-	TCA_SAMPLE_PAD,
-	__TCA_SAMPLE_MAX
-};
-#define TCA_SAMPLE_MAX (__TCA_SAMPLE_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tc_act/tc_skbmod.h b/include/uapi/linux/tc_act/tc_skbmod.h
deleted file mode 100644
index c525b35..0000000
--- a/include/uapi/linux/tc_act/tc_skbmod.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * Copyright (c) 2016, Jamal Hadi Salim
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-*/
-
-#ifndef __LINUX_TC_SKBMOD_H
-#define __LINUX_TC_SKBMOD_H
-
-#include <linux/pkt_cls.h>
-
-#define SKBMOD_F_DMAC	0x1
-#define SKBMOD_F_SMAC	0x2
-#define SKBMOD_F_ETYPE	0x4
-#define SKBMOD_F_SWAPMAC 0x8
-
-struct tc_skbmod {
-	tc_gen;
-	__u64 flags;
-};
-
-enum {
-	TCA_SKBMOD_UNSPEC,
-	TCA_SKBMOD_TM,
-	TCA_SKBMOD_PARMS,
-	TCA_SKBMOD_DMAC,
-	TCA_SKBMOD_SMAC,
-	TCA_SKBMOD_ETYPE,
-	TCA_SKBMOD_PAD,
-	__TCA_SKBMOD_MAX
-};
-#define TCA_SKBMOD_MAX (__TCA_SKBMOD_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tc_act/tc_tunnel_key.h b/include/uapi/linux/tc_act/tc_tunnel_key.h
deleted file mode 100644
index 41c8b46..0000000
--- a/include/uapi/linux/tc_act/tc_tunnel_key.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * Copyright (c) 2016, Amir Vadai <amir@vadai.me>
- * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __LINUX_TC_TUNNEL_KEY_H
-#define __LINUX_TC_TUNNEL_KEY_H
-
-#include <linux/pkt_cls.h>
-
-#define TCA_TUNNEL_KEY_ACT_SET	    1
-#define TCA_TUNNEL_KEY_ACT_RELEASE  2
-
-struct tc_tunnel_key {
-	tc_gen;
-	int t_action;
-};
-
-enum {
-	TCA_TUNNEL_KEY_UNSPEC,
-	TCA_TUNNEL_KEY_TM,
-	TCA_TUNNEL_KEY_PARMS,
-	TCA_TUNNEL_KEY_ENC_IPV4_SRC,	/* be32 */
-	TCA_TUNNEL_KEY_ENC_IPV4_DST,	/* be32 */
-	TCA_TUNNEL_KEY_ENC_IPV6_SRC,	/* struct in6_addr */
-	TCA_TUNNEL_KEY_ENC_IPV6_DST,	/* struct in6_addr */
-	TCA_TUNNEL_KEY_ENC_KEY_ID,	/* be64 */
-	TCA_TUNNEL_KEY_PAD,
-	TCA_TUNNEL_KEY_ENC_DST_PORT,	/* be16 */
-	TCA_TUNNEL_KEY_NO_CSUM,		/* u8 */
-	TCA_TUNNEL_KEY_ENC_OPTS,	/* Nested TCA_TUNNEL_KEY_ENC_OPTS_
-					 * attributes
-					 */
-	TCA_TUNNEL_KEY_ENC_TOS,		/* u8 */
-	TCA_TUNNEL_KEY_ENC_TTL,		/* u8 */
-	__TCA_TUNNEL_KEY_MAX,
-};
-
-#define TCA_TUNNEL_KEY_MAX (__TCA_TUNNEL_KEY_MAX - 1)
-
-enum {
-	TCA_TUNNEL_KEY_ENC_OPTS_UNSPEC,
-	TCA_TUNNEL_KEY_ENC_OPTS_GENEVE,		/* Nested
-						 * TCA_TUNNEL_KEY_ENC_OPTS_
-						 * attributes
-						 */
-	__TCA_TUNNEL_KEY_ENC_OPTS_MAX,
-};
-
-#define TCA_TUNNEL_KEY_ENC_OPTS_MAX (__TCA_TUNNEL_KEY_ENC_OPTS_MAX - 1)
-
-enum {
-	TCA_TUNNEL_KEY_ENC_OPT_GENEVE_UNSPEC,
-	TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS,		/* be16 */
-	TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE,		/* u8 */
-	TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA,		/* 4 to 128 bytes */
-
-	__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX,
-};
-
-#define TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX \
-	(__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tc_ematch/tc_em_ipt.h b/include/uapi/linux/tc_ematch/tc_em_ipt.h
deleted file mode 100644
index 49a6553..0000000
--- a/include/uapi/linux/tc_ematch/tc_em_ipt.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __LINUX_TC_EM_IPT_H
-#define __LINUX_TC_EM_IPT_H
-
-#include <linux/types.h>
-#include <linux/pkt_cls.h>
-
-enum {
-	TCA_EM_IPT_UNSPEC,
-	TCA_EM_IPT_HOOK,
-	TCA_EM_IPT_MATCH_NAME,
-	TCA_EM_IPT_MATCH_REVISION,
-	TCA_EM_IPT_NFPROTO,
-	TCA_EM_IPT_MATCH_DATA,
-	__TCA_EM_IPT_MAX
-};
-
-#define TCA_EM_IPT_MAX (__TCA_EM_IPT_MAX - 1)
-
-#endif
diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h
deleted file mode 100644
index d08acf4..0000000
--- a/include/uapi/linux/tcp.h
+++ /dev/null
@@ -1,339 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-/*
- * INET		An implementation of the TCP/IP protocol suite for the LINUX
- *		operating system.  INET is implemented using the  BSD Socket
- *		interface as the means of communication with the user level.
- *
- *		Definitions for the TCP protocol.
- *
- * Version:	@(#)tcp.h	1.0.2	04/28/93
- *
- * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- */
-#ifndef _LINUX_TCP_H
-#define _LINUX_TCP_H
-
-#include <linux/types.h>
-#include <asm/byteorder.h>
-#include <linux/socket.h>
-
-struct tcphdr {
-	__be16	source;
-	__be16	dest;
-	__be32	seq;
-	__be32	ack_seq;
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-	__u16	res1:4,
-		doff:4,
-		fin:1,
-		syn:1,
-		rst:1,
-		psh:1,
-		ack:1,
-		urg:1,
-		ece:1,
-		cwr:1;
-#elif defined(__BIG_ENDIAN_BITFIELD)
-	__u16	doff:4,
-		res1:4,
-		cwr:1,
-		ece:1,
-		urg:1,
-		ack:1,
-		psh:1,
-		rst:1,
-		syn:1,
-		fin:1;
-#else
-#error	"Adjust your <asm/byteorder.h> defines"
-#endif	
-	__be16	window;
-	__sum16	check;
-	__be16	urg_ptr;
-};
-
-/*
- *	The union cast uses a gcc extension to avoid aliasing problems
- *  (union is compatible to any of its members)
- *  This means this part of the code is -fstrict-aliasing safe now.
- */
-union tcp_word_hdr { 
-	struct tcphdr hdr;
-	__be32 		  words[5];
-}; 
-
-#define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3]) 
-
-enum { 
-	TCP_FLAG_CWR = __constant_cpu_to_be32(0x00800000),
-	TCP_FLAG_ECE = __constant_cpu_to_be32(0x00400000),
-	TCP_FLAG_URG = __constant_cpu_to_be32(0x00200000),
-	TCP_FLAG_ACK = __constant_cpu_to_be32(0x00100000),
-	TCP_FLAG_PSH = __constant_cpu_to_be32(0x00080000),
-	TCP_FLAG_RST = __constant_cpu_to_be32(0x00040000),
-	TCP_FLAG_SYN = __constant_cpu_to_be32(0x00020000),
-	TCP_FLAG_FIN = __constant_cpu_to_be32(0x00010000),
-	TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0F000000),
-	TCP_DATA_OFFSET = __constant_cpu_to_be32(0xF0000000)
-}; 
-
-/*
- * TCP general constants
- */
-#define TCP_MSS_DEFAULT		 536U	/* IPv4 (RFC1122, RFC2581) */
-#define TCP_MSS_DESIRED		1220U	/* IPv6 (tunneled), EDNS0 (RFC3226) */
-
-/* TCP socket options */
-#define TCP_NODELAY		1	/* Turn off Nagle's algorithm. */
-#define TCP_MAXSEG		2	/* Limit MSS */
-#define TCP_CORK		3	/* Never send partially complete segments */
-#define TCP_KEEPIDLE		4	/* Start keeplives after this period */
-#define TCP_KEEPINTVL		5	/* Interval between keepalives */
-#define TCP_KEEPCNT		6	/* Number of keepalives before death */
-#define TCP_SYNCNT		7	/* Number of SYN retransmits */
-#define TCP_LINGER2		8	/* Life time of orphaned FIN-WAIT-2 state */
-#define TCP_DEFER_ACCEPT	9	/* Wake up listener only when data arrive */
-#define TCP_WINDOW_CLAMP	10	/* Bound advertised window */
-#define TCP_INFO		11	/* Information about this connection. */
-#define TCP_QUICKACK		12	/* Block/reenable quick acks */
-#define TCP_CONGESTION		13	/* Congestion control algorithm */
-#define TCP_MD5SIG		14	/* TCP MD5 Signature (RFC2385) */
-#define TCP_THIN_LINEAR_TIMEOUTS 16      /* Use linear timeouts for thin streams*/
-#define TCP_THIN_DUPACK         17      /* Fast retrans. after 1 dupack */
-#define TCP_USER_TIMEOUT	18	/* How long for loss retry before timeout */
-#define TCP_REPAIR		19	/* TCP sock is under repair right now */
-#define TCP_REPAIR_QUEUE	20
-#define TCP_QUEUE_SEQ		21
-#define TCP_REPAIR_OPTIONS	22
-#define TCP_FASTOPEN		23	/* Enable FastOpen on listeners */
-#define TCP_TIMESTAMP		24
-#define TCP_NOTSENT_LOWAT	25	/* limit number of unsent bytes in write queue */
-#define TCP_CC_INFO		26	/* Get Congestion Control (optional) info */
-#define TCP_SAVE_SYN		27	/* Record SYN headers for new connections */
-#define TCP_SAVED_SYN		28	/* Get SYN headers recorded for connection */
-#define TCP_REPAIR_WINDOW	29	/* Get/set window parameters */
-#define TCP_FASTOPEN_CONNECT	30	/* Attempt FastOpen with connect */
-#define TCP_ULP			31	/* Attach a ULP to a TCP connection */
-#define TCP_MD5SIG_EXT		32	/* TCP MD5 Signature with extensions */
-#define TCP_FASTOPEN_KEY	33	/* Set the key for Fast Open (cookie) */
-#define TCP_FASTOPEN_NO_COOKIE	34	/* Enable TFO without a TFO cookie */
-#define TCP_ZEROCOPY_RECEIVE	35
-#define TCP_INQ			36	/* Notify bytes available to read as a cmsg on read */
-
-#define TCP_CM_INQ		TCP_INQ
-
-#define TCP_TX_DELAY		37	/* delay outgoing packets by XX usec */
-
-
-#define TCP_REPAIR_ON		1
-#define TCP_REPAIR_OFF		0
-#define TCP_REPAIR_OFF_NO_WP	-1	/* Turn off without window probes */
-
-struct tcp_repair_opt {
-	__u32	opt_code;
-	__u32	opt_val;
-};
-
-struct tcp_repair_window {
-	__u32	snd_wl1;
-	__u32	snd_wnd;
-	__u32	max_window;
-
-	__u32	rcv_wnd;
-	__u32	rcv_wup;
-};
-
-enum {
-	TCP_NO_QUEUE,
-	TCP_RECV_QUEUE,
-	TCP_SEND_QUEUE,
-	TCP_QUEUES_NR,
-};
-
-/* for TCP_INFO socket option */
-#define TCPI_OPT_TIMESTAMPS	1
-#define TCPI_OPT_SACK		2
-#define TCPI_OPT_WSCALE		4
-#define TCPI_OPT_ECN		8 /* ECN was negociated at TCP session init */
-#define TCPI_OPT_ECN_SEEN	16 /* we received at least one packet with ECT */
-#define TCPI_OPT_SYN_DATA	32 /* SYN-ACK acked data in SYN sent or rcvd */
-
-/*
- * Sender's congestion state indicating normal or abnormal situations
- * in the last round of packets sent. The state is driven by the ACK
- * information and timer events.
- */
-enum tcp_ca_state {
-	/*
-	 * Nothing bad has been observed recently.
-	 * No apparent reordering, packet loss, or ECN marks.
-	 */
-	TCP_CA_Open = 0,
-#define TCPF_CA_Open	(1<<TCP_CA_Open)
-	/*
-	 * The sender enters disordered state when it has received DUPACKs or
-	 * SACKs in the last round of packets sent. This could be due to packet
-	 * loss or reordering but needs further information to confirm packets
-	 * have been lost.
-	 */
-	TCP_CA_Disorder = 1,
-#define TCPF_CA_Disorder (1<<TCP_CA_Disorder)
-	/*
-	 * The sender enters Congestion Window Reduction (CWR) state when it
-	 * has received ACKs with ECN-ECE marks, or has experienced congestion
-	 * or packet discard on the sender host (e.g. qdisc).
-	 */
-	TCP_CA_CWR = 2,
-#define TCPF_CA_CWR	(1<<TCP_CA_CWR)
-	/*
-	 * The sender is in fast recovery and retransmitting lost packets,
-	 * typically triggered by ACK events.
-	 */
-	TCP_CA_Recovery = 3,
-#define TCPF_CA_Recovery (1<<TCP_CA_Recovery)
-	/*
-	 * The sender is in loss recovery triggered by retransmission timeout.
-	 */
-	TCP_CA_Loss = 4
-#define TCPF_CA_Loss	(1<<TCP_CA_Loss)
-};
-
-struct tcp_info {
-	__u8	tcpi_state;
-	__u8	tcpi_ca_state;
-	__u8	tcpi_retransmits;
-	__u8	tcpi_probes;
-	__u8	tcpi_backoff;
-	__u8	tcpi_options;
-	__u8	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
-	__u8	tcpi_delivery_rate_app_limited:1;
-
-	__u32	tcpi_rto;
-	__u32	tcpi_ato;
-	__u32	tcpi_snd_mss;
-	__u32	tcpi_rcv_mss;
-
-	__u32	tcpi_unacked;
-	__u32	tcpi_sacked;
-	__u32	tcpi_lost;
-	__u32	tcpi_retrans;
-	__u32	tcpi_fackets;
-
-	/* Times. */
-	__u32	tcpi_last_data_sent;
-	__u32	tcpi_last_ack_sent;     /* Not remembered, sorry. */
-	__u32	tcpi_last_data_recv;
-	__u32	tcpi_last_ack_recv;
-
-	/* Metrics. */
-	__u32	tcpi_pmtu;
-	__u32	tcpi_rcv_ssthresh;
-	__u32	tcpi_rtt;
-	__u32	tcpi_rttvar;
-	__u32	tcpi_snd_ssthresh;
-	__u32	tcpi_snd_cwnd;
-	__u32	tcpi_advmss;
-	__u32	tcpi_reordering;
-
-	__u32	tcpi_rcv_rtt;
-	__u32	tcpi_rcv_space;
-
-	__u32	tcpi_total_retrans;
-
-	__u64	tcpi_pacing_rate;
-	__u64	tcpi_max_pacing_rate;
-	__u64	tcpi_bytes_acked;    /* RFC4898 tcpEStatsAppHCThruOctetsAcked */
-	__u64	tcpi_bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived */
-	__u32	tcpi_segs_out;	     /* RFC4898 tcpEStatsPerfSegsOut */
-	__u32	tcpi_segs_in;	     /* RFC4898 tcpEStatsPerfSegsIn */
-
-	__u32	tcpi_notsent_bytes;
-	__u32	tcpi_min_rtt;
-	__u32	tcpi_data_segs_in;	/* RFC4898 tcpEStatsDataSegsIn */
-	__u32	tcpi_data_segs_out;	/* RFC4898 tcpEStatsDataSegsOut */
-
-	__u64   tcpi_delivery_rate;
-
-	__u64	tcpi_busy_time;      /* Time (usec) busy sending data */
-	__u64	tcpi_rwnd_limited;   /* Time (usec) limited by receive window */
-	__u64	tcpi_sndbuf_limited; /* Time (usec) limited by send buffer */
-
-	__u32	tcpi_delivered;
-	__u32	tcpi_delivered_ce;
-
-	__u64	tcpi_bytes_sent;     /* RFC4898 tcpEStatsPerfHCDataOctetsOut */
-	__u64	tcpi_bytes_retrans;  /* RFC4898 tcpEStatsPerfOctetsRetrans */
-	__u32	tcpi_dsack_dups;     /* RFC4898 tcpEStatsStackDSACKDups */
-	__u32	tcpi_reord_seen;     /* reordering events seen */
-
-	__u32	tcpi_rcv_ooopack;    /* Out-of-order packets received */
-
-	__u32	tcpi_snd_wnd;	     /* peer's advertised receive window after
-				      * scaling (bytes)
-				      */
-};
-
-/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
-enum {
-	TCP_NLA_PAD,
-	TCP_NLA_BUSY,		/* Time (usec) busy sending data */
-	TCP_NLA_RWND_LIMITED,	/* Time (usec) limited by receive window */
-	TCP_NLA_SNDBUF_LIMITED,	/* Time (usec) limited by send buffer */
-	TCP_NLA_DATA_SEGS_OUT,	/* Data pkts sent including retransmission */
-	TCP_NLA_TOTAL_RETRANS,	/* Data pkts retransmitted */
-	TCP_NLA_PACING_RATE,    /* Pacing rate in bytes per second */
-	TCP_NLA_DELIVERY_RATE,  /* Delivery rate in bytes per second */
-	TCP_NLA_SND_CWND,       /* Sending congestion window */
-	TCP_NLA_REORDERING,     /* Reordering metric */
-	TCP_NLA_MIN_RTT,        /* minimum RTT */
-	TCP_NLA_RECUR_RETRANS,  /* Recurring retransmits for the current pkt */
-	TCP_NLA_DELIVERY_RATE_APP_LMT, /* delivery rate application limited ? */
-	TCP_NLA_SNDQ_SIZE,	/* Data (bytes) pending in send queue */
-	TCP_NLA_CA_STATE,	/* ca_state of socket */
-	TCP_NLA_SND_SSTHRESH,	/* Slow start size threshold */
-	TCP_NLA_DELIVERED,	/* Data pkts delivered incl. out-of-order */
-	TCP_NLA_DELIVERED_CE,	/* Like above but only ones w/ CE marks */
-	TCP_NLA_BYTES_SENT,	/* Data bytes sent including retransmission */
-	TCP_NLA_BYTES_RETRANS,	/* Data bytes retransmitted */
-	TCP_NLA_DSACK_DUPS,	/* DSACK blocks received */
-	TCP_NLA_REORD_SEEN,	/* reordering events seen */
-	TCP_NLA_SRTT,		/* smoothed RTT in usecs */
-};
-
-/* for TCP_MD5SIG socket option */
-#define TCP_MD5SIG_MAXKEYLEN	80
-
-/* tcp_md5sig extension flags for TCP_MD5SIG_EXT */
-#define TCP_MD5SIG_FLAG_PREFIX		1	/* address prefix length */
-
-struct tcp_md5sig {
-	struct __kernel_sockaddr_storage tcpm_addr;	/* address associated */
-	__u8	tcpm_flags;				/* extension flags */
-	__u8	tcpm_prefixlen;				/* address prefix */
-	__u16	tcpm_keylen;				/* key length */
-	__u32	__tcpm_pad;				/* zero */
-	__u8	tcpm_key[TCP_MD5SIG_MAXKEYLEN];		/* key (binary) */
-};
-
-/* INET_DIAG_MD5SIG */
-struct tcp_diag_md5sig {
-	__u8	tcpm_family;
-	__u8	tcpm_prefixlen;
-	__u16	tcpm_keylen;
-	__be32	tcpm_addr[4];
-	__u8	tcpm_key[TCP_MD5SIG_MAXKEYLEN];
-};
-
-/* setsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE, ...) */
-
-struct tcp_zerocopy_receive {
-	__u64 address;		/* in: address of mapping */
-	__u32 length;		/* in/out: number of bytes to map/mapped */
-	__u32 recv_skip_hint;	/* out: amount of bytes to skip */
-};
-#endif /* _LINUX_TCP_H */
diff --git a/include/uapi/linux/tipc.h b/include/uapi/linux/tipc.h
deleted file mode 100644
index e16cb4e..0000000
--- a/include/uapi/linux/tipc.h
+++ /dev/null
@@ -1,291 +0,0 @@
-/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
-/*
- * include/uapi/linux/tipc.h: Header for TIPC socket interface
- *
- * Copyright (c) 2003-2006, 2015-2016 Ericsson AB
- * Copyright (c) 2005, 2010-2011, Wind River Systems
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _LINUX_TIPC_H_
-#define _LINUX_TIPC_H_
-
-#include <linux/types.h>
-#include <linux/sockios.h>
-
-/*
- * TIPC addressing primitives
- */
-
-struct tipc_socket_addr {
-	__u32 ref;
-	__u32 node;
-};
-
-struct tipc_service_addr {
-	__u32 type;
-	__u32 instance;
-};
-
-struct tipc_service_range {
-	__u32 type;
-	__u32 lower;
-	__u32 upper;
-};
-
-/*
- * Application-accessible service types
- */
-
-#define TIPC_NODE_STATE		0	/* node state service type */
-#define TIPC_TOP_SRV		1	/* topology server service type */
-#define TIPC_LINK_STATE		2	/* link state service type */
-#define TIPC_RESERVED_TYPES	64	/* lowest user-allowed service type */
-
-/*
- * Publication scopes when binding service / service range
- */
-enum tipc_scope {
-	TIPC_CLUSTER_SCOPE = 2, /* 0 can also be used */
-	TIPC_NODE_SCOPE    = 3
-};
-
-/*
- * Limiting values for messages
- */
-
-#define TIPC_MAX_USER_MSG_SIZE	66000U
-
-/*
- * Message importance levels
- */
-
-#define TIPC_LOW_IMPORTANCE		0
-#define TIPC_MEDIUM_IMPORTANCE		1
-#define TIPC_HIGH_IMPORTANCE		2
-#define TIPC_CRITICAL_IMPORTANCE	3
-
-/*
- * Msg rejection/connection shutdown reasons
- */
-
-#define TIPC_OK			0
-#define TIPC_ERR_NO_NAME	1
-#define TIPC_ERR_NO_PORT	2
-#define TIPC_ERR_NO_NODE	3
-#define TIPC_ERR_OVERLOAD	4
-#define TIPC_CONN_SHUTDOWN	5
-
-/*
- * TIPC topology subscription service definitions
- */
-
-#define TIPC_SUB_PORTS          0x01    /* filter: evt at each match */
-#define TIPC_SUB_SERVICE        0x02    /* filter: evt at first up/last down */
-#define TIPC_SUB_CANCEL         0x04    /* filter: cancel a subscription */
-
-#define TIPC_WAIT_FOREVER	(~0)	/* timeout for permanent subscription */
-
-struct tipc_subscr {
-	struct tipc_service_range seq;	/* range of interest */
-	__u32 timeout;			/* subscription duration (in ms) */
-	__u32 filter;			/* bitmask of filter options */
-	char usr_handle[8];		/* available for subscriber use */
-};
-
-#define TIPC_PUBLISHED		1	/* publication event */
-#define TIPC_WITHDRAWN		2	/* withdrawal event */
-#define TIPC_SUBSCR_TIMEOUT	3	/* subscription timeout event */
-
-struct tipc_event {
-	__u32 event;			/* event type */
-	__u32 found_lower;		/* matching range */
-	__u32 found_upper;		/*    "      "    */
-	struct tipc_socket_addr port;	/* associated socket */
-	struct tipc_subscr s;		/* associated subscription */
-};
-
-/*
- * Socket API
- */
-
-#ifndef AF_TIPC
-#define AF_TIPC		30
-#endif
-
-#ifndef PF_TIPC
-#define PF_TIPC		AF_TIPC
-#endif
-
-#ifndef SOL_TIPC
-#define SOL_TIPC	271
-#endif
-
-#define TIPC_ADDR_MCAST         1
-#define TIPC_SERVICE_RANGE      1
-#define TIPC_SERVICE_ADDR       2
-#define TIPC_SOCKET_ADDR        3
-
-struct sockaddr_tipc {
-	unsigned short family;
-	unsigned char  addrtype;
-	signed   char  scope;
-	union {
-		struct tipc_socket_addr id;
-		struct tipc_service_range nameseq;
-		struct {
-			struct tipc_service_addr name;
-			__u32 domain;
-		} name;
-	} addr;
-};
-
-/*
- * Ancillary data objects supported by recvmsg()
- */
-
-#define TIPC_ERRINFO	1	/* error info */
-#define TIPC_RETDATA	2	/* returned data */
-#define TIPC_DESTNAME	3	/* destination name */
-
-/*
- * TIPC-specific socket option names
- */
-
-#define TIPC_IMPORTANCE		127	/* Default: TIPC_LOW_IMPORTANCE */
-#define TIPC_SRC_DROPPABLE	128	/* Default: based on socket type */
-#define TIPC_DEST_DROPPABLE	129	/* Default: based on socket type */
-#define TIPC_CONN_TIMEOUT	130	/* Default: 8000 (ms)  */
-#define TIPC_NODE_RECVQ_DEPTH	131	/* Default: none (read only) */
-#define TIPC_SOCK_RECVQ_DEPTH	132	/* Default: none (read only) */
-#define TIPC_MCAST_BROADCAST    133     /* Default: TIPC selects. No arg */
-#define TIPC_MCAST_REPLICAST    134     /* Default: TIPC selects. No arg */
-#define TIPC_GROUP_JOIN         135     /* Takes struct tipc_group_req* */
-#define TIPC_GROUP_LEAVE        136     /* No argument */
-#define TIPC_SOCK_RECVQ_USED    137     /* Default: none (read only) */
-
-/*
- * Flag values
- */
-#define TIPC_GROUP_LOOPBACK     0x1  /* Receive copy of sent msg when match */
-#define TIPC_GROUP_MEMBER_EVTS  0x2  /* Receive membership events in socket */
-
-struct tipc_group_req {
-	__u32 type;      /* group id */
-	__u32 instance;  /* member id */
-	__u32 scope;     /* cluster/node */
-	__u32 flags;
-};
-
-/*
- * Maximum sizes of TIPC bearer-related names (including terminating NULL)
- * The string formatting for each name element is:
- * media: media
- * interface: media:interface name
- * link: node:interface-node:interface
- */
-#define TIPC_NODEID_LEN         16
-#define TIPC_MAX_MEDIA_NAME	16
-#define TIPC_MAX_IF_NAME	16
-#define TIPC_MAX_BEARER_NAME	32
-#define TIPC_MAX_LINK_NAME	68
-
-#define SIOCGETLINKNAME        SIOCPROTOPRIVATE
-#define SIOCGETNODEID          (SIOCPROTOPRIVATE + 1)
-
-struct tipc_sioc_ln_req {
-	__u32 peer;
-	__u32 bearer_id;
-	char linkname[TIPC_MAX_LINK_NAME];
-};
-
-struct tipc_sioc_nodeid_req {
-	__u32 peer;
-	char node_id[TIPC_NODEID_LEN];
-};
-
-/* The macros and functions below are deprecated:
- */
-
-#define TIPC_CFG_SRV		0
-#define TIPC_ZONE_SCOPE         1
-
-#define TIPC_ADDR_NAMESEQ	1
-#define TIPC_ADDR_NAME		2
-#define TIPC_ADDR_ID		3
-
-#define TIPC_NODE_BITS          12
-#define TIPC_CLUSTER_BITS       12
-#define TIPC_ZONE_BITS          8
-
-#define TIPC_NODE_OFFSET        0
-#define TIPC_CLUSTER_OFFSET     TIPC_NODE_BITS
-#define TIPC_ZONE_OFFSET        (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
-
-#define TIPC_NODE_SIZE          ((1UL << TIPC_NODE_BITS) - 1)
-#define TIPC_CLUSTER_SIZE       ((1UL << TIPC_CLUSTER_BITS) - 1)
-#define TIPC_ZONE_SIZE          ((1UL << TIPC_ZONE_BITS) - 1)
-
-#define TIPC_NODE_MASK		(TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
-#define TIPC_CLUSTER_MASK	(TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
-#define TIPC_ZONE_MASK		(TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
-
-#define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
-
-#define tipc_portid tipc_socket_addr
-#define tipc_name tipc_service_addr
-#define tipc_name_seq tipc_service_range
-
-static __inline__ __u32 tipc_addr(unsigned int zone,
-			      unsigned int cluster,
-			      unsigned int node)
-{
-	return (zone << TIPC_ZONE_OFFSET) |
-		(cluster << TIPC_CLUSTER_OFFSET) |
-		node;
-}
-
-static __inline__ unsigned int tipc_zone(__u32 addr)
-{
-	return addr >> TIPC_ZONE_OFFSET;
-}
-
-static __inline__ unsigned int tipc_cluster(__u32 addr)
-{
-	return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
-}
-
-static __inline__ unsigned int tipc_node(__u32 addr)
-{
-	return addr & TIPC_NODE_MASK;
-}
-
-#endif
diff --git a/include/uapi/linux/tipc_sockets_diag.h b/include/uapi/linux/tipc_sockets_diag.h
deleted file mode 100644
index 21b766e..0000000
--- a/include/uapi/linux/tipc_sockets_diag.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* AF_TIPC sock_diag interface for querying open sockets */
-
-#ifndef __TIPC_SOCKETS_DIAG_H__
-#define __TIPC_SOCKETS_DIAG_H__
-
-#include <linux/types.h>
-#include <linux/sock_diag.h>
-
-/* Request */
-struct tipc_sock_diag_req {
-	__u8	sdiag_family;	/* must be AF_TIPC */
-	__u8	sdiag_protocol;	/* must be 0 */
-	__u16	pad;		/* must be 0 */
-	__u32	tidiag_states;	/* query*/
-};
-#endif /* __TIPC_SOCKETS_DIAG_H__ */
diff --git a/include/uapi/linux/types.h b/include/uapi/linux/types.h
deleted file mode 100644
index 999cb0f..0000000
--- a/include/uapi/linux/types.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_TYPES_H
-#define _LINUX_TYPES_H
-
-#include <asm/types.h>
-
-#ifndef __ASSEMBLY__
-
-#include <linux/posix_types.h>
-
-
-/*
- * Below are truly Linux-specific types that should never collide with
- * any application/library that wants linux/types.h.
- */
-
-#ifdef __CHECKER__
-#define __bitwise__ __attribute__((bitwise))
-#else
-#define __bitwise__
-#endif
-#define __bitwise __bitwise__
-
-typedef __u16 __bitwise __le16;
-typedef __u16 __bitwise __be16;
-typedef __u32 __bitwise __le32;
-typedef __u32 __bitwise __be32;
-typedef __u64 __bitwise __le64;
-typedef __u64 __bitwise __be64;
-
-typedef __u16 __bitwise __sum16;
-typedef __u32 __bitwise __wsum;
-
-/*
- * aligned_u64 should be used in defining kernel<->userspace ABIs to avoid
- * common 32/64-bit compat problems.
- * 64-bit values align to 4-byte boundaries on x86_32 (and possibly other
- * architectures) and to 8-byte boundaries on 64-bit architectures.  The new
- * aligned_64 type enforces 8-byte alignment so that structs containing
- * aligned_64 values have the same alignment on 32-bit and 64-bit architectures.
- * No conversions are necessary between 32-bit user-space and a 64-bit kernel.
- */
-#define __aligned_u64 __u64 __attribute__((aligned(8)))
-#define __aligned_be64 __be64 __attribute__((aligned(8)))
-#define __aligned_le64 __le64 __attribute__((aligned(8)))
-
-typedef unsigned __bitwise __poll_t;
-
-#endif /*  __ASSEMBLY__ */
-#endif /* _LINUX_TYPES_H */
diff --git a/include/uapi/linux/vm_sockets_diag.h b/include/uapi/linux/vm_sockets_diag.h
deleted file mode 100644
index 6da42f9..0000000
--- a/include/uapi/linux/vm_sockets_diag.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/* AF_VSOCK sock_diag(7) interface for querying open sockets */
-
-#ifndef __VM_SOCKETS_DIAG_H__
-#define __VM_SOCKETS_DIAG_H__
-
-#include <linux/types.h>
-
-/* Request */
-struct vsock_diag_req {
-	__u8	sdiag_family;	/* must be AF_VSOCK */
-	__u8	sdiag_protocol;	/* must be 0 */
-	__u16	pad;		/* must be 0 */
-	__u32	vdiag_states;	/* query bitmap (e.g. 1 << TCP_LISTEN) */
-	__u32	vdiag_ino;	/* must be 0 (reserved) */
-	__u32	vdiag_show;	/* must be 0 (reserved) */
-	__u32	vdiag_cookie[2];
-};
-
-/* Response */
-struct vsock_diag_msg {
-	__u8	vdiag_family;	/* AF_VSOCK */
-	__u8	vdiag_type;	/* SOCK_STREAM or SOCK_DGRAM */
-	__u8	vdiag_state;	/* sk_state (e.g. TCP_LISTEN) */
-	__u8	vdiag_shutdown; /* local RCV_SHUTDOWN | SEND_SHUTDOWN */
-	__u32   vdiag_src_cid;
-	__u32   vdiag_src_port;
-	__u32   vdiag_dst_cid;
-	__u32   vdiag_dst_port;
-	__u32	vdiag_ino;
-	__u32	vdiag_cookie[2];
-};
-
-#endif /* __VM_SOCKETS_DIAG_H__ */
diff --git a/include/uapi/linux/xdp_diag.h b/include/uapi/linux/xdp_diag.h
deleted file mode 100644
index 78b2591..0000000
--- a/include/uapi/linux/xdp_diag.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * xdp_diag: interface for query/monitor XDP sockets
- * Copyright(c) 2019 Intel Corporation.
- */
-
-#ifndef _LINUX_XDP_DIAG_H
-#define _LINUX_XDP_DIAG_H
-
-#include <linux/types.h>
-
-struct xdp_diag_req {
-	__u8	sdiag_family;
-	__u8	sdiag_protocol;
-	__u16	pad;
-	__u32	xdiag_ino;
-	__u32	xdiag_show;
-	__u32	xdiag_cookie[2];
-};
-
-struct xdp_diag_msg {
-	__u8	xdiag_family;
-	__u8	xdiag_type;
-	__u16	pad;
-	__u32	xdiag_ino;
-	__u32	xdiag_cookie[2];
-};
-
-#define XDP_SHOW_INFO		(1 << 0) /* Basic information */
-#define XDP_SHOW_RING_CFG	(1 << 1)
-#define XDP_SHOW_UMEM		(1 << 2)
-#define XDP_SHOW_MEMINFO	(1 << 3)
-
-enum {
-	XDP_DIAG_NONE,
-	XDP_DIAG_INFO,
-	XDP_DIAG_UID,
-	XDP_DIAG_RX_RING,
-	XDP_DIAG_TX_RING,
-	XDP_DIAG_UMEM,
-	XDP_DIAG_UMEM_FILL_RING,
-	XDP_DIAG_UMEM_COMPLETION_RING,
-	XDP_DIAG_MEMINFO,
-	__XDP_DIAG_MAX,
-};
-
-#define XDP_DIAG_MAX (__XDP_DIAG_MAX - 1)
-
-struct xdp_diag_info {
-	__u32	ifindex;
-	__u32	queue_id;
-};
-
-struct xdp_diag_ring {
-	__u32	entries; /*num descs */
-};
-
-#define XDP_DU_F_ZEROCOPY (1 << 0)
-
-struct xdp_diag_umem {
-	__u64	size;
-	__u32	id;
-	__u32	num_pages;
-	__u32	chunk_size;
-	__u32	headroom;
-	__u32	ifindex;
-	__u32	queue_id;
-	__u32	flags;
-	__u32	refs;
-};
-
-#endif /* _LINUX_XDP_DIAG_H */
diff --git a/include/utils.h b/include/utils.h
index 794d360..7310f4e 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __UTILS_H__
 #define __UTILS_H__ 1
 
@@ -7,16 +6,10 @@
 #include <resolv.h>
 #include <stdlib.h>
 #include <stdbool.h>
-#include <time.h>
-
-#ifdef HAVE_LIBBSD
-#include <bsd/string.h>
-#endif
 
 #include "libnetlink.h"
 #include "ll_map.h"
 #include "rtm_map.h"
-#include "json_print.h"
 
 extern int preferred_family;
 extern int human_readable;
@@ -27,16 +20,26 @@
 extern int resolve_hosts;
 extern int oneline;
 extern int brief;
-extern int json;
-extern int pretty;
 extern int timestamp;
 extern int timestamp_short;
 extern const char * _SL_;
 extern int max_flush_loops;
 extern int batch_mode;
-extern int numeric;
 extern bool do_all;
 
+#ifndef IPPROTO_ESP
+#define IPPROTO_ESP	50
+#endif
+#ifndef IPPROTO_AH
+#define IPPROTO_AH	51
+#endif
+#ifndef IPPROTO_COMP
+#define IPPROTO_COMP	108
+#endif
+#ifndef IPSEC_PROTO_ANY
+#define IPSEC_PROTO_ANY	255
+#endif
+
 #ifndef CONFDIR
 #define CONFDIR		"/etc/iproute2"
 #endif
@@ -51,11 +54,6 @@
 #define NEXT_ARG_FWD() do { argv++; argc--; } while(0)
 #define PREV_ARG() do { argv--; argc++; } while(0)
 
-#define TIME_UNITS_PER_SEC	1000000
-#define NSEC_PER_USEC 1000
-#define NSEC_PER_MSEC 1000000
-#define NSEC_PER_SEC 1000000000LL
-
 typedef struct
 {
 	__u16 flags;
@@ -63,48 +61,10 @@
 	__s16 bitlen;
 	/* These next two fields match rtvia */
 	__u16 family;
-	__u32 data[64];
+	__u32 data[8];
 } inet_prefix;
 
-enum {
-	PREFIXLEN_SPECIFIED	= (1 << 0),
-	ADDRTYPE_INET		= (1 << 1),
-	ADDRTYPE_UNSPEC		= (1 << 2),
-	ADDRTYPE_MULTI		= (1 << 3),
-
-	ADDRTYPE_INET_UNSPEC	= ADDRTYPE_INET | ADDRTYPE_UNSPEC,
-	ADDRTYPE_INET_MULTI	= ADDRTYPE_INET | ADDRTYPE_MULTI
-};
-
-static inline void inet_prefix_reset(inet_prefix *p)
-{
-	p->flags = 0;
-}
-
-static inline bool is_addrtype_inet(const inet_prefix *p)
-{
-	return p->flags & ADDRTYPE_INET;
-}
-
-static inline bool is_addrtype_inet_unspec(const inet_prefix *p)
-{
-	return (p->flags & ADDRTYPE_INET_UNSPEC) == ADDRTYPE_INET_UNSPEC;
-}
-
-static inline bool is_addrtype_inet_multi(const inet_prefix *p)
-{
-	return (p->flags & ADDRTYPE_INET_MULTI) == ADDRTYPE_INET_MULTI;
-}
-
-static inline bool is_addrtype_inet_not_unspec(const inet_prefix *p)
-{
-	return (p->flags & ADDRTYPE_INET_UNSPEC) == ADDRTYPE_INET;
-}
-
-static inline bool is_addrtype_inet_not_multi(const inet_prefix *p)
-{
-	return (p->flags & ADDRTYPE_INET_MULTI) == ADDRTYPE_INET;
-}
+#define PREFIXLEN_SPECIFIED 1
 
 #define DN_MAXADDL 20
 #ifndef AF_DECnet
@@ -117,24 +77,19 @@
         unsigned char a_addr[DN_MAXADDL];
 };
 
+#define IPX_NODE_LEN 6
+
+struct ipx_addr {
+	u_int32_t ipx_net;
+	u_int8_t  ipx_node[IPX_NODE_LEN];
+};
+
 #ifndef AF_MPLS
 # define AF_MPLS 28
 #endif
-#ifndef IPPROTO_MPLS
-#define IPPROTO_MPLS	137
-#endif
 
-#ifndef CLOCK_TAI
-# define CLOCK_TAI 11
-#endif
-
-#ifndef AF_XDP
-# define AF_XDP 44
-# if AF_MAX < 45
-#  undef AF_MAX
-#  define AF_MAX 45
-# endif
-#endif
+/* Maximum number of labels the mpls helpers support */
+#define MPLS_MAX_LABELS 8
 
 __u32 get_addr32(const char *name);
 int get_addr_1(inet_prefix *dst, const char *arg, int family);
@@ -142,50 +97,35 @@
 int get_addr(inet_prefix *dst, const char *arg, int family);
 int get_prefix(inet_prefix *dst, char *arg, int family);
 int mask2bits(__u32 netmask);
-int get_addr_rta(inet_prefix *dst, const struct rtattr *rta, int family);
 int get_addr_ila(__u64 *val, const char *arg);
 
-int read_prop(const char *dev, char *prop, long *value);
-int get_hex(char c);
 int get_integer(int *val, const char *arg, int base);
 int get_unsigned(unsigned *val, const char *arg, int base);
 int get_time_rtt(unsigned *val, const char *arg, int *raw);
 #define get_byte get_u8
 #define get_ushort get_u16
 #define get_short get_s16
-int get_s64(__s64 *val, const char *arg, int base);
 int get_u64(__u64 *val, const char *arg, int base);
 int get_u32(__u32 *val, const char *arg, int base);
 int get_s32(__s32 *val, const char *arg, int base);
 int get_u16(__u16 *val, const char *arg, int base);
+int get_s16(__s16 *val, const char *arg, int base);
 int get_u8(__u8 *val, const char *arg, int base);
-int get_be64(__be64 *val, const char *arg, int base);
-int get_be32(__be32 *val, const char *arg, int base);
-int get_be16(__be16 *val, const char *arg, int base);
+int get_s8(__s8 *val, const char *arg, int base);
 int get_addr64(__u64 *ap, const char *cp);
 
-int hex2mem(const char *buf, uint8_t *mem, int count);
-char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen);
-__u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len);
+char* hexstring_n2a(const __u8 *str, int len, char *buf, int blen);
+__u8* hexstring_a2n(const char *str, __u8 *buf, int blen);
 #define ADDR64_BUF_SIZE sizeof("xxxx:xxxx:xxxx:xxxx")
 int addr64_n2a(__u64 addr, char *buff, size_t len);
 
 int af_bit_len(int af);
+int af_byte_len(int af);
 
-const char *format_host_r(int af, int len, const void *addr,
+const char *format_host(int af, int len, const void *addr,
 			       char *buf, int buflen);
-#define format_host_rta_r(af, rta, buf, buflen)	\
-	format_host_r(af, RTA_PAYLOAD(rta), RTA_DATA(rta), \
-		      buf, buflen)
-
-const char *format_host(int af, int lne, const void *addr);
-#define format_host_rta(af, rta) \
-	format_host(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
-const char *rt_addr_n2a_r(int af, int len, const void *addr,
+const char *rt_addr_n2a(int af, int len, const void *addr,
 			       char *buf, int buflen);
-const char *rt_addr_n2a(int af, int len, const void *addr);
-#define rt_addr_n2a_rta(af, rta) \
-	rt_addr_n2a(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
 
 int read_family(const char *name);
 const char *family_name(int family);
@@ -194,16 +134,17 @@
 void invarg(const char *, const char *) __attribute__((noreturn));
 void duparg(const char *, const char *) __attribute__((noreturn));
 void duparg2(const char *, const char *) __attribute__((noreturn));
-int nodev(const char *dev);
-int check_ifname(const char *);
-int get_ifname(char *, const char *);
-const char *get_ifname_rta(int ifindex, const struct rtattr *rta);
-bool matches(const char *prefix, const char *string);
+int matches(const char *arg, const char *pattern);
 int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits);
-int inet_addr_match_rta(const inet_prefix *m, const struct rtattr *rta);
+
+const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
+int dnet_pton(int af, const char *src, void *addr);
+
+const char *ipx_ntop(int af, const void *addr, char *str, size_t len);
+int ipx_pton(int af, const char *src, void *addr);
 
 const char *mpls_ntop(int af, const void *addr, char *str, size_t len);
-int mpls_pton(int af, const char *src, void *addr, size_t alen);
+int mpls_pton(int af, const char *src, void *addr);
 
 extern int __iproute2_hz_internal;
 int __get_hz(void);
@@ -234,35 +175,10 @@
 	return group ? (1 << (group - 1)) : 0;
 }
 
-/* courtesy of bridge-utils */
-static inline unsigned long __tv_to_jiffies(const struct timeval *tv)
-{
-	unsigned long long jif;
-
-	jif = 1000000ULL * tv->tv_sec + tv->tv_usec;
-
-	return jif/10000;
-}
-
-static inline void __jiffies_to_tv(struct timeval *tv, unsigned long jiffies)
-{
-	unsigned long long tvusec;
-
-	tvusec = 10000ULL*jiffies;
-	tv->tv_sec = tvusec/1000000;
-	tv->tv_usec = tvusec - 1000000 * tv->tv_sec;
-}
-
-void print_escape_buf(const __u8 *buf, size_t len, const char *escape);
 
 int print_timestamp(FILE *fp);
 void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n);
 
-unsigned int print_name_and_link(const char *fmt,
-				 const char *name, struct rtattr *tb[]);
-
-#define BIT(nr)                 (1UL << (nr))
-
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 #define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
@@ -293,30 +209,16 @@
 extern int cmdlineno;
 ssize_t getcmdline(char **line, size_t *len, FILE *in);
 int makeargs(char *line, char *argv[], int maxargs);
+int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6);
+
+struct iplink_req;
+int iplink_parse(int argc, char **argv, struct iplink_req *req,
+		char **name, char **type, char **link, char **dev,
+		int *group, int *index);
+
+int do_each_netns(int (*func)(char *nsname, void *arg), void *arg,
+		bool show_label);
 
 char *int_to_str(int val, char *buf);
-int get_guid(__u64 *guid, const char *arg);
-int get_real_family(int rtm_type, int rtm_family);
-
-int cmd_exec(const char *cmd, char **argv, bool do_fork,
-	     int (*setup)(void *), void *arg);
-int make_path(const char *path, mode_t mode);
-char *find_cgroup2_mount(void);
-int get_command_name(const char *pid, char *comm, size_t len);
-
-int get_rtnl_link_stats_rta(struct rtnl_link_stats64 *stats64,
-			    struct rtattr *tb[]);
-
-#ifdef NEED_STRLCPY
-size_t strlcpy(char *dst, const char *src, size_t size);
-size_t strlcat(char *dst, const char *src, size_t size);
-#endif
-
-void drop_cap(void);
-
-int get_time(unsigned int *time, const char *str);
-int get_time64(__s64 *time, const char *str);
-char *sprint_time(__u32 time, char *buf);
-char *sprint_time64(__s64 time, char *buf);
 
 #endif /* __UTILS_H__ */
diff --git a/include/xt-internal.h b/include/xt-internal.h
index 89c73e4..b8ea67d 100644
--- a/include/xt-internal.h
+++ b/include/xt-internal.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _XTABLES_INTERNAL_H
 #define _XTABLES_INTERNAL_H 1
 
diff --git a/include/xtables.h b/include/xtables.h
index 583619f..978ae0d 100644
--- a/include/xtables.h
+++ b/include/xtables.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _XTABLES_H
 #define _XTABLES_H
 
@@ -206,24 +205,6 @@
 	XTABLES_EXT_ALIAS = 1 << 0,
 };
 
-#if XTABLES_VERSION_CODE >= 12
-struct xt_xlate;
-
-struct xt_xlate_mt_params {
-	const void			*ip;
-	const struct xt_entry_match	*match;
-	int				numeric;
-	bool				escape_quotes;
-};
-
-struct xt_xlate_tg_params {
-	const void			*ip;
-	const struct xt_entry_target	*target;
-	int				numeric;
-	bool				escape_quotes;
-};
-#endif
-
 /* Include file for additions: new matches and targets. */
 struct xtables_match
 {
@@ -288,12 +269,6 @@
 	void (*x6_fcheck)(struct xt_fcheck_call *);
 	const struct xt_option_entry *x6_options;
 
-#if XTABLES_VERSION_CODE >= 12
-	/* Translate iptables to nft */
-	int (*xlate)(struct xt_xlate *xl,
-		     const struct xt_xlate_mt_params *params);
-#endif
-
 	/* Size of per-extension instance extra "global" scratch space */
 	size_t udata_size;
 
@@ -371,12 +346,6 @@
 	void (*x6_fcheck)(struct xt_fcheck_call *);
 	const struct xt_option_entry *x6_options;
 
-#if XTABLES_VERSION_CODE >= 12
-	/* Translate iptables to nft */
-	int (*xlate)(struct xt_xlate *xl,
-		     const struct xt_xlate_tg_params *params);
-#endif
-
 	size_t udata_size;
 
 	/* Ignore these men behind the curtain: */
diff --git a/ip/Android.mk b/ip/Android.mk
index 8e6724b..5c45bc7 100644
--- a/ip/Android.mk
+++ b/ip/Android.mk
@@ -1,34 +1,24 @@
 LOCAL_PATH := $(call my-dir)
 
-IPROUTE2_USE_CONFIG ?= no
-
-etc_iproute2_dir := etc/iproute2
-
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := ip.c ipaddress.c ipaddrlabel.c iproute.c iprule.c ipnetns.c \
         rtm_map.c iptunnel.c ip6tunnel.c tunnel.c ipneigh.c ipntable.c iplink.c \
-        ipmaddr.c ipmonitor.c ipmroute.c ipprefix.c iptuntap.c iptoken.c \
-        ipxfrm.c xfrm_state.c xfrm_policy.c xfrm_monitor.c iplink_dummy.c \
-        iplink_vlan.c link_veth.c link_gre.c iplink_can.c iplink_xdp.c \
-        iplink_macvlan.c ipl2tp.c link_vti.c link_vti6.c link_xfrm.c \
-        iplink_vxlan.c tcp_metrics.c iplink_ipoib.c ipnetconf.c link_ip6tnl.c \
-        link_iptnl.c link_gre6.c iplink_bond.c iplink_bond_slave.c iplink_hsr.c \
-        iplink_bridge.c iplink_bridge_slave.c ipfou.c iplink_ipvlan.c \
-        iplink_geneve.c iplink_vrf.c iproute_lwtunnel.c ipmacsec.c ipila.c \
-        ipvrf.c iplink_xstats.c ipseg6.c iplink_netdevsim.c iplink_rmnet.c \
-        ipnexthop.c
+        ipmaddr.c ipmonitor.c ipmroute.c ipprefix.c iptuntap.c \
+        ipxfrm.c xfrm_state.c xfrm_policy.c xfrm_monitor.c \
+        iplink_vlan.c link_veth.c link_gre.c iplink_can.c \
+        iplink_macvlan.c ipl2tp.c \
+        ipfou.c iptoken.c tcp_metrics.c ipnetconf.c \
+        iproute_lwtunnel.c
 
 LOCAL_MODULE := ip
 
-ifeq ($(USE_IP_USER_BUILD),1)
-LOCAL_MODULE_TAGS := user eng
-else
-LOCAL_MODULE_TAGS := eng
-endif
+LOCAL_MODULE_TAGS := optional
 
-LOCAL_STATIC_LIBRARIES += libiprouteutil libnetlink
+LOCAL_SHARED_LIBRARIES := libc libm libdl
 
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
+LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
 
 LOCAL_CFLAGS := \
     -O2 -g \
@@ -39,92 +29,10 @@
     -Wno-sign-compare \
     -Wno-unused-parameter \
     -Werror \
-    -D_GNU_SOURCE
-
-ifeq ($(BUILD_EUREKA),true)
-LOCAL_CFLAGS += -DHAVE_SETNS
-endif
+    -D_GNU_SOURCE \
+    -DHAVE_SETNS \
 
 LOCAL_LDFLAGS := -Wl,-export-dynamic -Wl,--no-gc-sections
 
-ifeq ($(IPROUTE2_USE_CONFIG), yes)
-LOCAL_REQUIRED_MODULES += ematch_map group rt_dsfield rt_protos rt_realms rt_scopes rt_tables
-endif
-
-LOCAL_REQUIRED_MODULES += rtmon
-
 include $(BUILD_EXECUTABLE)
 
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := rtmon.c
-LOCAL_MODULE := rtmon
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
-LOCAL_STATIC_LIBRARIES += libiprouteutil libnetlink
-LOCAL_CFLAGS := \
-    -O2 -g \
-    -W -Wall \
-    -Wno-implicit-function-declaration \
-    -Wno-missing-field-initializers \
-    -Wno-pointer-arith \
-    -Wno-sign-compare \
-    -Wno-unused-parameter \
-    -Werror \
-    -D_GNU_SOURCE
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := ematch_map
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := group
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := rt_dsfield
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := rt_protos
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := rt_realms
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := rt_scopes
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := rt_tables
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT)/$(etc_iproute2_dir)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := ../$(etc_iproute2_dir)/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
diff --git a/ip/Makefile b/ip/Makefile
index 5ab78d7..f3d2987 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -1,21 +1,21 @@
-# SPDX-License-Identifier: GPL-2.0
 IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
     rtm_map.o iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o \
     ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o iptuntap.o iptoken.o \
-    ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o iplink_dummy.o \
-    iplink_ifb.o iplink_nlmon.o iplink_team.o iplink_vcan.o iplink_vxcan.o \
-    iplink_vlan.o link_veth.o link_gre.o iplink_can.o iplink_xdp.o \
-    iplink_macvlan.o ipl2tp.o link_vti.o link_vti6.o link_xfrm.o \
+    ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \
+    iplink_vlan.o link_veth.o link_gre.o iplink_can.o \
+    iplink_macvlan.o ipl2tp.o link_vti.o link_vti6.o \
     iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
     link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o \
     iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o \
-    iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \
-    ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \
-    ipnexthop.o
+    iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o
 
 RTMONOBJ=rtmon.o
 
-include ../config.mk
+include ../Config
+
+ifeq ($(IP_CONFIG_SETNS),y)
+	CFLAGS += -DHAVE_SETNS
+endif
 
 ALLOBJ=$(IPOBJ) $(RTMONOBJ)
 SCRIPTS=ifcfg rtpr routel routef
@@ -24,10 +24,8 @@
 all: $(TARGETS) $(SCRIPTS)
 
 ip: $(IPOBJ) $(LIBNETLINK)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
 
 rtmon: $(RTMONOBJ)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
 
 install: all
 	install -m 0755 $(TARGETS) $(DESTDIR)$(SBINDIR)
diff --git a/ip/ifcfg b/ip/ifcfg
index 5b34dec..083d9df 100644
--- a/ip/ifcfg
+++ b/ip/ifcfg
@@ -1,5 +1,4 @@
-#! /bin/sh
-# SPDX-License-Identifier: GPL-2.0
+#! /bin/bash
 
 CheckForwarding () {
   local sbase fwd
@@ -7,7 +6,7 @@
   fwd=0
   if [ -d $sbase ]; then
     for dir in $sbase/*/forwarding; do
-      fwd=$(( fwd + $(cat "$dir") ))
+      fwd=$[$fwd + `cat $dir`]
     done
   else
     fwd=2
@@ -128,12 +127,12 @@
 arping -q -A -c 1 -I $dev $ipaddr
 noarp=$?
 ( sleep 2 ;
-  arping -q -U -c 1 -I $dev $ipaddr ) >/dev/null 2>&1 </dev/null &
+  arping -q -U -c 1 -I $dev $ipaddr ) >& /dev/null </dev/null &
 
-ip route add unreachable 224.0.0.0/24 >/dev/null 2>&1
-ip route add unreachable 255.255.255.255 >/dev/null 2>&1
-if [ "`ip link ls $dev | grep -c MULTICAST`" -ge 1 ]; then
-  ip route add 224.0.0.0/4 dev $dev scope global >/dev/null 2>&1
+ip route add unreachable 224.0.0.0/24 >& /dev/null
+ip route add unreachable 255.255.255.255 >& /dev/null
+if [ `ip link ls $dev | grep -c MULTICAST` -ge 1 ]; then
+  ip route add 224.0.0.0/4 dev $dev scope global >& /dev/null
 fi
 
 if [ $fwd -eq 0 ]; then
diff --git a/ip/ila_common.h b/ip/ila_common.h
deleted file mode 100644
index f99c267..0000000
--- a/ip/ila_common.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ILA_COMMON_H_
-#define _ILA_COMMON_H_
-
-#include <linux/ila.h>
-#include <string.h>
-
-static inline char *ila_csum_mode2name(__u8 csum_mode)
-{
-	switch (csum_mode) {
-	case ILA_CSUM_ADJUST_TRANSPORT:
-		return "adj-transport";
-	case ILA_CSUM_NEUTRAL_MAP:
-		return "neutral-map";
-	case ILA_CSUM_NO_ACTION:
-		return "no-action";
-	case ILA_CSUM_NEUTRAL_MAP_AUTO:
-		return "neutral-map-auto";
-	default:
-		return "unknown";
-	}
-}
-
-static inline int ila_csum_name2mode(char *name)
-{
-	if (strcmp(name, "adj-transport") == 0)
-		return ILA_CSUM_ADJUST_TRANSPORT;
-	else if (strcmp(name, "neutral-map") == 0)
-		return ILA_CSUM_NEUTRAL_MAP;
-	else if (strcmp(name, "neutral-map-auto") == 0)
-		return ILA_CSUM_NEUTRAL_MAP_AUTO;
-	else if (strcmp(name, "no-action") == 0)
-		return ILA_CSUM_NO_ACTION;
-	else if (strcmp(name, "neutral-map-auto") == 0)
-		return ILA_CSUM_NEUTRAL_MAP_AUTO;
-	else
-		return -1;
-}
-
-static inline char *ila_ident_type2name(__u8 ident_type)
-{
-	switch (ident_type) {
-	case ILA_ATYPE_IID:
-		return "iid";
-	case ILA_ATYPE_LUID:
-		return "luid";
-	case ILA_ATYPE_VIRT_V4:
-		return "virt-v4";
-	case ILA_ATYPE_VIRT_UNI_V6:
-		return "virt-uni-v6";
-	case ILA_ATYPE_VIRT_MULTI_V6:
-		return "virt-multi-v6";
-	case ILA_ATYPE_NONLOCAL_ADDR:
-		return "nonlocal-addr";
-	case ILA_ATYPE_USE_FORMAT:
-		return "use-format";
-	default:
-		return "unknown";
-	}
-}
-
-static inline int ila_ident_name2type(char *name)
-{
-	if (!strcmp(name, "luid"))
-		return ILA_ATYPE_LUID;
-	else if (!strcmp(name, "use-format"))
-		return ILA_ATYPE_USE_FORMAT;
-#if 0 /* No kernel support for configuring these yet */
-	else if (!strcmp(name, "iid"))
-		return ILA_ATYPE_IID;
-	else if (!strcmp(name, "virt-v4"))
-		return ILA_ATYPE_VIRT_V4;
-	else if (!strcmp(name, "virt-uni-v6"))
-		return ILA_ATYPE_VIRT_UNI_V6;
-	else if (!strcmp(name, "virt-multi-v6"))
-		return ILA_ATYPE_VIRT_MULTI_V6;
-	else if (!strcmp(name, "nonlocal-addr"))
-		return ILA_ATYPE_NONLOCAL_ADDR;
-#endif
-	else
-		return -1;
-}
-
-static inline char *ila_hook_type2name(__u8 hook_type)
-{
-	switch (hook_type) {
-	case ILA_HOOK_ROUTE_OUTPUT:
-		return "output";
-	case ILA_HOOK_ROUTE_INPUT:
-		return "input";
-	default:
-		return "unknown";
-	}
-}
-
-static inline int ila_hook_name2type(char *name)
-{
-	if (!strcmp(name, "output"))
-		return ILA_HOOK_ROUTE_OUTPUT;
-	else if (!strcmp(name, "input"))
-		return ILA_HOOK_ROUTE_INPUT;
-	else
-		return -1;
-}
-
-#endif /* _ILA_COMMON_H_ */
diff --git a/ip/ip.c b/ip/ip.c
index fed26f8..5162100 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -29,14 +30,14 @@
 int use_iec;
 int show_stats;
 int show_details;
+int resolve_hosts;
 int oneline;
 int brief;
-int json;
 int timestamp;
+const char *_SL_;
 int force;
 int max_flush_loops = 10;
 int batch_mode;
-int numeric;
 bool do_all;
 
 struct rtnl_handle rth = { .fd = -1 };
@@ -46,20 +47,18 @@
 static void usage(void)
 {
 	fprintf(stderr,
-		"Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n"
-		"       ip [ -force ] -batch filename\n"
-		"where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |\n"
-		"                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |\n"
-		"                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |\n"
-		"                   vrf | sr | nexthop }\n"
-		"       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n"
-		"                    -h[uman-readable] | -iec | -j[son] | -p[retty] |\n"
-		"                    -f[amily] { inet | inet6 | mpls | bridge | link } |\n"
-		"                    -4 | -6 | -I | -D | -M | -B | -0 |\n"
-		"                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |\n"
-		"                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n"
-		"                    -rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |\n"
-		"                    -c[olor]}\n");
+"Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n"
+"       ip [ -force ] -batch filename\n"
+"where  OBJECT := { link | address | addrlabel | route | rule | neighbor | ntable |\n"
+"                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |\n"
+"                   netns | l2tp | fou | tcp_metrics | token | netconf }\n"
+"       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n"
+"                    -h[uman-readable] | -iec |\n"
+"                    -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |\n"
+"                    -4 | -6 | -I | -D | -B | -0 |\n"
+"                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |\n"
+"                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n"
+"                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}\n");
 	exit(-1);
 }
 
@@ -85,8 +84,6 @@
 	{ "link",	do_iplink },
 	{ "l2tp",	do_ipl2tp },
 	{ "fou",	do_ipfou },
-	{ "ila",	do_ipila },
-	{ "macsec",	do_ipmacsec },
 	{ "tunnel",	do_iptunnel },
 	{ "tunl",	do_iptunnel },
 	{ "tuntap",	do_iptuntap },
@@ -100,9 +97,6 @@
 	{ "mrule",	do_multirule },
 	{ "netns",	do_netns },
 	{ "netconf",	do_ipnetconf },
-	{ "vrf",	do_ipvrf},
-	{ "sr",		do_seg6 },
-	{ "nexthop",	do_ipnh },
 	{ "help",	do_help },
 	{ 0 }
 };
@@ -120,6 +114,7 @@
 	return EXIT_FAILURE;
 }
 
+#ifndef ANDROID
 static int batch(const char *name)
 {
 	char *line = NULL;
@@ -168,25 +163,15 @@
 	rtnl_close(&rth);
 	return ret;
 }
+#endif
 
 
 int main(int argc, char **argv)
 {
 	char *basename;
+#ifndef ANDROID
 	char *batch_file = NULL;
-	int color = 0;
-
-	/* to run vrf exec without root, capabilities might be set, drop them
-	 * if not needed as the first thing.
-	 * execv will drop them for the child command.
-	 * vrf exec requires:
-	 * - cap_dac_override to create the cgroup subdir in /sys
-	 * - cap_sys_admin to load the BPF program
-	 * - cap_net_admin to set the socket into the cgroup
-	 */
-	if (argc < 3 || strcmp(argv[1], "vrf") != 0 ||
-			strcmp(argv[2], "exec") != 0)
-		drop_cap();
+#endif
 
 	basename = strrchr(argv[0], '/');
 	if (basename == NULL)
@@ -228,6 +213,8 @@
 			preferred_family = AF_INET6;
 		} else if (strcmp(opt, "-0") == 0) {
 			preferred_family = AF_PACKET;
+		} else if (strcmp(opt, "-I") == 0) {
+			preferred_family = AF_IPX;
 		} else if (strcmp(opt, "-D") == 0) {
 			preferred_family = AF_DECnet;
 		} else if (strcmp(opt, "-M") == 0) {
@@ -253,23 +240,25 @@
 		} else if (matches(opt, "-tshort") == 0) {
 			++timestamp;
 			++timestamp_short;
+#if 0
+		} else if (matches(opt, "-numeric") == 0) {
+			rtnl_names_numeric++;
+#endif
 		} else if (matches(opt, "-Version") == 0) {
 			printf("ip utility, iproute2-ss%s\n", SNAPSHOT);
 			exit(0);
 		} else if (matches(opt, "-force") == 0) {
 			++force;
+#ifndef ANDROID
 		} else if (matches(opt, "-batch") == 0) {
 			argc--;
 			argv++;
 			if (argc <= 1)
 				usage();
 			batch_file = argv[1];
+#endif
 		} else if (matches(opt, "-brief") == 0) {
 			++brief;
-		} else if (matches(opt, "-json") == 0) {
-			++json;
-		} else if (matches(opt, "-pretty") == 0) {
-			++pretty;
 		} else if (matches(opt, "-rcvbuf") == 0) {
 			unsigned int size;
 
@@ -283,15 +272,14 @@
 				exit(-1);
 			}
 			rcvbuf = size;
-		} else if (matches_color(opt, &color)) {
+		} else if (matches(opt, "-color") == 0) {
+			enable_color();
 		} else if (matches(opt, "-help") == 0) {
 			usage();
 		} else if (matches(opt, "-netns") == 0) {
 			NEXT_ARG();
 			if (netns_switch(argv[1]))
 				exit(-1);
-		} else if (matches(opt, "-Numeric") == 0) {
-			++numeric;
 		} else if (matches(opt, "-all") == 0) {
 			do_all = true;
 		} else {
@@ -305,16 +293,14 @@
 
 	_SL_ = oneline ? "\\" : "\n";
 
-	check_enable_color(color, json);
-
+#ifndef ANDROID
 	if (batch_file)
 		return batch(batch_file);
+#endif
 
 	if (rtnl_open(&rth, 0) < 0)
 		exit(1);
 
-	rtnl_set_strict_dump(&rth);
-
 	if (strlen(basename) > 2)
 		return do_cmd(basename+2, argc, argv);
 
diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
index 5399f91..7a3cd04 100644
--- a/ip/ip6tunnel.c
+++ b/ip/ip6tunnel.c
@@ -46,107 +46,96 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip -f inet6 tunnel { add | change | del | show } [ NAME ]\n"
-		"          [ mode { ip6ip6 | ipip6 | ip6gre | vti6 | any } ]\n"
-		"          [ remote ADDR local ADDR ] [ dev PHYS_DEV ]\n"
-		"          [ encaplimit ELIM ]\n"
-		"          [ hoplimit TTL ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n"
-		"          [ dscp inherit ]\n"
-		"          [ [no]allow-localremote ]\n"
-		"          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n"
-		"\n"
-		"Where: NAME      := STRING\n"
-		"       ADDR      := IPV6_ADDRESS\n"
-		"       ELIM      := { none | 0..255 }(default=%d)\n"
-		"       TTL       := 0..255 (default=%d)\n"
-		"       TCLASS    := { 0x0..0xff | inherit }\n"
-		"       FLOWLABEL := { 0x0..0xfffff | inherit }\n"
-		"       KEY       := { DOTTED_QUAD | NUMBER }\n",
-		IPV6_DEFAULT_TNL_ENCAP_LIMIT,
+	fprintf(stderr, "Usage: ip -f inet6 tunnel { add | change | del | show } [ NAME ]\n");
+	fprintf(stderr, "          [ mode { ip6ip6 | ipip6 | ip6gre | vti6 | any } ]\n");
+	fprintf(stderr, "          [ remote ADDR local ADDR ] [ dev PHYS_DEV ]\n");
+	fprintf(stderr, "          [ encaplimit ELIM ]\n");
+	fprintf(stderr ,"          [ hoplimit TTL ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
+	fprintf(stderr, "          [ dscp inherit ]\n");
+	fprintf(stderr, "          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: NAME      := STRING\n");
+	fprintf(stderr, "       ADDR      := IPV6_ADDRESS\n");
+	fprintf(stderr, "       ELIM      := { none | 0..255 }(default=%d)\n",
+		IPV6_DEFAULT_TNL_ENCAP_LIMIT);
+	fprintf(stderr, "       TTL       := 0..255 (default=%d)\n",
 		DEFAULT_TNL_HOP_LIMIT);
+	fprintf(stderr, "       TCLASS    := { 0x0..0xff | inherit }\n");
+	fprintf(stderr, "       FLOWLABEL := { 0x0..0xfffff | inherit }\n");
+	fprintf(stderr, "       KEY       := { DOTTED_QUAD | NUMBER }\n");
 	exit(-1);
 }
 
-static void print_tunnel(const void *t)
+static void print_tunnel(struct ip6_tnl_parm2 *p)
 {
-	const struct ip6_tnl_parm2 *p = t;
-	SPRINT_BUF(b1);
+	char s1[1024];
+	char s2[1024];
 
 	/* Do not use format_host() for local addr,
 	 * symbolic name will not be useful.
 	 */
-	open_json_object(NULL);
-	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", "%s: ", p->name);
-	snprintf(b1, sizeof(b1), "%s/ipv6", tnl_strproto(p->proto));
-	print_string(PRINT_ANY, "mode", "%s ", b1);
-	print_string(PRINT_FP, NULL, "%s", "remote ");
-	print_color_string(PRINT_ANY, COLOR_INET6, "remote", "%s ",
-			   format_host_r(AF_INET6, 16, &p->raddr, b1, sizeof(b1)));
-	print_string(PRINT_FP, NULL, "%s", "local ");
-	print_color_string(PRINT_ANY, COLOR_INET6, "local", "%s",
-			   rt_addr_n2a_r(AF_INET6, 16, &p->laddr, b1, sizeof(b1)));
-
+	printf("%s: %s/ipv6 remote %s local %s",
+	       p->name,
+	       tnl_strproto(p->proto),
+	       format_host(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
+	       rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
 	if (p->link) {
 		const char *n = ll_index_to_name(p->link);
-
 		if (n)
-			print_string(PRINT_ANY, "link", " dev %s", n);
+			printf(" dev %s", n);
 	}
 
 	if (p->flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
-		print_null(PRINT_ANY, "ip6_tnl_f_ign_encap_limit",
-			   " encaplimit none", NULL);
+		printf(" encaplimit none");
 	else
-		print_uint(PRINT_ANY, "encap_limit", " encaplimit %u",
-			   p->encap_limit);
+		printf(" encaplimit %u", p->encap_limit);
 
-	if (p->hop_limit)
-		print_uint(PRINT_ANY, "hoplimit", " hoplimit %u", p->hop_limit);
-	else
-		print_string(PRINT_FP, "hoplimit", " hoplimit %s", "inherit");
+	printf(" hoplimit %u", p->hop_limit);
 
-	if (p->flags & IP6_TNL_F_USE_ORIG_TCLASS) {
-		print_null(PRINT_ANY, "ip6_tnl_f_use_orig_tclass",
-			   " tclass inherit", NULL);
-	} else {
+	if (p->flags & IP6_TNL_F_USE_ORIG_TCLASS)
+		printf(" tclass inherit");
+	else {
 		__u32 val = ntohl(p->flowinfo & IP6_FLOWINFO_TCLASS);
-
-		snprintf(b1, sizeof(b1), "0x%02x", (__u8)(val >> 20));
-		print_string(PRINT_ANY, "tclass", " tclass %s", b1);
+		printf(" tclass 0x%02x", (__u8)(val >> 20));
 	}
 
-	if (p->flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
-		print_null(PRINT_ANY, "ip6_tnl_f_use_orig_flowlabel",
-			   " flowlabel inherit", NULL);
-	} else {
-		__u32 val = ntohl(p->flowinfo & IP6_FLOWINFO_FLOWLABEL);
+	if (p->flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
+		printf(" flowlabel inherit");
+	else
+		printf(" flowlabel 0x%05x", ntohl(p->flowinfo & IP6_FLOWINFO_FLOWLABEL));
 
-		snprintf(b1, sizeof(b1), "0x%05x", val);
-		print_string(PRINT_ANY, "flowlabel", " flowlabel %s", b1);
-	}
-
-	snprintf(b1, sizeof(b1), "0x%08x", ntohl(p->flowinfo));
-	print_string(PRINT_ANY, "flowinfo", " (flowinfo %s)", b1);
+	printf(" (flowinfo 0x%08x)", ntohl(p->flowinfo));
 
 	if (p->flags & IP6_TNL_F_RCV_DSCP_COPY)
-		print_null(PRINT_ANY, "ip6_tnl_f_rcv_dscp_copy",
-			   " dscp inherit", NULL);
+		printf(" dscp inherit");
 
-	if (p->flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
-		print_null(PRINT_ANY, "ip6_tnl_f_allow_local_remote",
-			   " allow-localremote", NULL);
+	if (p->proto == IPPROTO_GRE) {
+		if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
+			printf(" key %u", ntohl(p->i_key));
+		else if ((p->i_flags | p->o_flags) & GRE_KEY) {
+			if (p->i_flags & GRE_KEY)
+				printf(" ikey %u", ntohl(p->i_key));
+			if (p->o_flags & GRE_KEY)
+				printf(" okey %u", ntohl(p->o_key));
+		}
 
-	tnl_print_gre_flags(p->proto, p->i_flags, p->o_flags,
-			    p->i_key, p->o_key);
-
-	close_json_object();
+		if (p->i_flags & GRE_SEQ)
+			printf("%s  Drop packets out of sequence.", _SL_);
+		if (p->i_flags & GRE_CSUM)
+			printf("%s  Checksum in received packet is required.", _SL_);
+		if (p->o_flags & GRE_SEQ)
+			printf("%s  Sequence packets on output.", _SL_);
+		if (p->o_flags & GRE_CSUM)
+			printf("%s  Checksum output packets.", _SL_);
+	}
 }
 
 static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
 {
 	int count = 0;
-	const char *medium = NULL;
+	char medium[IFNAMSIZ];
+
+	memset(medium, 0, sizeof(medium));
 
 	while (argc > 0) {
 		if (strcmp(*argv, "mode") == 0) {
@@ -169,31 +158,32 @@
 				 strcmp(*argv, "any") == 0)
 				p->proto = 0;
 			else {
-				fprintf(stderr, "Unknown tunnel mode \"%s\"\n", *argv);
+				fprintf(stderr,"Unknown tunnel mode \"%s\"\n", *argv);
 				exit(-1);
 			}
 		} else if (strcmp(*argv, "remote") == 0) {
 			inet_prefix raddr;
-
 			NEXT_ARG();
-			get_addr(&raddr, *argv, AF_INET6);
+			get_prefix(&raddr, *argv, preferred_family);
+			if (raddr.family == AF_UNSPEC)
+				invarg("\"remote\" address family is AF_UNSPEC", *argv);
 			memcpy(&p->raddr, &raddr.data, sizeof(p->raddr));
 		} else if (strcmp(*argv, "local") == 0) {
 			inet_prefix laddr;
-
 			NEXT_ARG();
-			get_addr(&laddr, *argv, AF_INET6);
+			get_prefix(&laddr, *argv, preferred_family);
+			if (laddr.family == AF_UNSPEC)
+				invarg("\"local\" address family is AF_UNSPEC", *argv);
 			memcpy(&p->laddr, &laddr.data, sizeof(p->laddr));
 		} else if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
-			medium = *argv;
+			strncpy(medium, *argv, IFNAMSIZ - 1);
 		} else if (strcmp(*argv, "encaplimit") == 0) {
 			NEXT_ARG();
 			if (strcmp(*argv, "none") == 0) {
 				p->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
 			} else {
 				__u8 uval;
-
 				if (get_u8(&uval, *argv, 0) < -1)
 					invarg("invalid ELIM", *argv);
 				p->encap_limit = uval;
@@ -203,7 +193,6 @@
 			   strcmp(*argv, "ttl") == 0 ||
 			   strcmp(*argv, "hlim") == 0) {
 			__u8 uval;
-
 			NEXT_ARG();
 			if (get_u8(&uval, *argv, 0))
 				invarg("invalid TTL", *argv);
@@ -213,7 +202,6 @@
 			   strcmp(*argv, "tos") == 0 ||
 			   matches(*argv, "dsfield") == 0) {
 			__u8 uval;
-
 			NEXT_ARG();
 			p->flowinfo &= ~IP6_FLOWINFO_TCLASS;
 			if (strcmp(*argv, "inherit") == 0)
@@ -227,7 +215,6 @@
 		} else if (strcmp(*argv, "flowlabel") == 0 ||
 			   strcmp(*argv, "fl") == 0) {
 			__u32 uval;
-
 			NEXT_ARG();
 			p->flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
 			if (strcmp(*argv, "inherit") == 0)
@@ -245,10 +232,6 @@
 			if (strcmp(*argv, "inherit") != 0)
 				invarg("not inherit", *argv);
 			p->flags |= IP6_TNL_F_RCV_DSCP_COPY;
-		} else if (strcmp(*argv, "allow-localremote") == 0) {
-			p->flags |= IP6_TNL_F_ALLOW_LOCAL_REMOTE;
-		} else if (strcmp(*argv, "noallow-localremote") == 0) {
-			p->flags &= ~IP6_TNL_F_ALLOW_LOCAL_REMOTE;
 		} else if (strcmp(*argv, "key") == 0) {
 			NEXT_ARG();
 			p->i_flags |= GRE_KEY;
@@ -283,11 +266,10 @@
 				usage();
 			if (p->name[0])
 				duparg2("name", *argv);
-			if (get_ifname(p->name, *argv))
-				invarg("\"name\" not a valid ifname", *argv);
+			strncpy(p->name, *argv, IFNAMSIZ - 1);
 			if (cmd == SIOCCHGTUNNEL && count == 0) {
-				struct ip6_tnl_parm2 old_p = {};
-
+				struct ip6_tnl_parm2 old_p;
+				memset(&old_p, 0, sizeof(old_p));
 				if (tnl_get_ioctl(*argv, &old_p))
 					return -1;
 				*p = old_p;
@@ -296,10 +278,12 @@
 		count++;
 		argc--; argv++;
 	}
-	if (medium) {
+	if (medium[0]) {
 		p->link = ll_name_to_index(medium);
-		if (!p->link)
-			return nodev(medium);
+		if (p->link == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", medium);
+			return -1;
+		}
 	}
 	return 0;
 }
@@ -314,30 +298,19 @@
 	}
 }
 
-static void ip6_tnl_parm_initialize(const struct tnl_print_nlmsg_info *info)
+/*
+ * @p1: user specified parameter
+ * @p2: database entry
+ */
+static int ip6_tnl_parm_match(const struct ip6_tnl_parm2 *p1,
+			      const struct ip6_tnl_parm2 *p2)
 {
-	const struct ifinfomsg *ifi = info->ifi;
-	const struct ip6_tnl_parm2 *p1 = info->p1;
-	struct ip6_tnl_parm2 *p2 = info->p2;
-
-	ip6_tnl_parm_init(p2, 0);
-	if (ifi->ifi_type == ARPHRD_IP6GRE)
-		p2->proto = IPPROTO_GRE;
-	p2->link = ifi->ifi_index;
-	strcpy(p2->name, p1->name);
-}
-
-static bool ip6_tnl_parm_match(const struct tnl_print_nlmsg_info *info)
-{
-	const struct ip6_tnl_parm2 *p1 = info->p1;
-	const struct ip6_tnl_parm2 *p2 = info->p2;
-
 	return ((!p1->link || p1->link == p2->link) &&
 		(!p1->name[0] || strcmp(p1->name, p2->name) == 0) &&
-		(IN6_IS_ADDR_UNSPECIFIED(&p1->laddr) ||
-		 IN6_ARE_ADDR_EQUAL(&p1->laddr, &p2->laddr)) &&
-		(IN6_IS_ADDR_UNSPECIFIED(&p1->raddr) ||
-		 IN6_ARE_ADDR_EQUAL(&p1->raddr, &p2->raddr)) &&
+		(memcmp(&p1->laddr, &in6addr_any, sizeof(p1->laddr)) == 0 ||
+		 memcmp(&p1->laddr, &p2->laddr, sizeof(p1->laddr)) == 0) &&
+		(memcmp(&p1->raddr, &in6addr_any, sizeof(p1->raddr)) == 0 ||
+		 memcmp(&p1->raddr, &p2->raddr, sizeof(p1->raddr)) == 0) &&
 		(!p1->proto || !p2->proto || p1->proto == p2->proto) &&
 		(!p1->encap_limit || p1->encap_limit == p2->encap_limit) &&
 		(!p1->hop_limit || p1->hop_limit == p2->hop_limit) &&
@@ -348,33 +321,91 @@
 		(!p1->flags || (p1->flags & p2->flags)));
 }
 
+static int do_tunnels_list(struct ip6_tnl_parm2 *p)
+{
+	char buf[512];
+	int err = -1;
+	FILE *fp = fopen("/proc/net/dev", "r");
+	if (fp == NULL) {
+		perror("fopen");
+		return -1;
+	}
+
+	/* skip two lines at the begenning of the file */
+	if (!fgets(buf, sizeof(buf), fp) ||
+	    !fgets(buf, sizeof(buf), fp)) {
+		fprintf(stderr, "/proc/net/dev read error\n");
+		goto end;
+	}
+
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
+		char name[IFNAMSIZ];
+		int index, type;
+		struct ip6_tnl_parm2 p1;
+		char *ptr;
+
+		buf[sizeof(buf) - 1] = '\0';
+		if ((ptr = strchr(buf, ':')) == NULL ||
+		    (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
+			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
+			goto end;
+		}
+		if (p->name[0] && strcmp(p->name, name))
+			continue;
+		index = ll_name_to_index(name);
+		if (index == 0)
+			continue;
+		type = ll_index_to_type(index);
+		if (type == -1) {
+			fprintf(stderr, "Failed to get type of \"%s\"\n", name);
+			continue;
+		}
+		if (type != ARPHRD_TUNNEL6 && type != ARPHRD_IP6GRE)
+			continue;
+		memset(&p1, 0, sizeof(p1));
+		ip6_tnl_parm_init(&p1, 0);
+		if (type == ARPHRD_IP6GRE)
+			p1.proto = IPPROTO_GRE;
+		strcpy(p1.name, name);
+		p1.link = ll_name_to_index(p1.name);
+		if (p1.link == 0)
+			continue;
+		if (tnl_get_ioctl(p1.name, &p1))
+			continue;
+		if (!ip6_tnl_parm_match(p, &p1))
+			continue;
+		print_tunnel(&p1);
+		if (show_stats)
+			tnl_print_stats(ptr);
+		printf("\n");
+	}
+	err = 0;
+ end:
+	fclose(fp);
+	return err;
+}
+
 static int do_show(int argc, char **argv)
 {
-	struct ip6_tnl_parm2 p, p1;
+        struct ip6_tnl_parm2 p;
 
+	ll_init_map(&rth);
 	ip6_tnl_parm_init(&p, 0);
 	p.proto = 0;  /* default to any */
 
-	if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
-		return -1;
+        if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
+                return -1;
 
-	if (!p.name[0] || show_stats) {
-		struct tnl_print_nlmsg_info info = {
-			.p1    = &p,
-			.p2    = &p1,
-			.init  = ip6_tnl_parm_initialize,
-			.match = ip6_tnl_parm_match,
-			.print = print_tunnel,
-		};
-
-		return do_tunnels_list(&info);
+	if (!p.name[0] || show_stats)
+		do_tunnels_list(&p);
+	else {
+		if (tnl_get_ioctl(p.name, &p))
+			return -1;
+		print_tunnel(&p);
+		printf("\n");
 	}
 
-	if (tnl_get_ioctl(p.name, &p))
-		return -1;
-
-	print_tunnel(&p);
-	return 0;
+        return 0;
 }
 
 static int do_add(int cmd, int argc, char **argv)
@@ -387,9 +418,6 @@
 	if (parse_args(argc, argv, cmd, &p) < 0)
 		return -1;
 
-	if (!*p.name)
-		fprintf(stderr, "Tunnel interface name not specified\n");
-
 	if (p.proto == IPPROTO_GRE)
 		basedev = "ip6gre0";
 	else if (p.i_flags & VTI_ISVTI)
diff --git a/ip/ip_common.h b/ip/ip_common.h
index 879287e..9a846df 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -1,39 +1,16 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _IP_COMMON_H_
-#define _IP_COMMON_H_
-
-#include <stdbool.h>
-
-#include "json_print.h"
-
-struct link_filter {
-	int ifindex;
-	int family;
-	int oneline;
-	int showqueue;
-	inet_prefix pfx;
-	int scope, scopemask;
-	int flags, flagmask;
-	int up;
-	char *label;
-	int flushed;
-	char *flushb;
-	int flushp;
-	int flushe;
-	int group;
-	int master;
-	char *kind;
-	char *slave_kind;
-	int target_nsid;
-};
-
 int get_operstate(const char *name);
-int print_linkinfo(struct nlmsghdr *n, void *arg);
-int print_addrinfo(struct nlmsghdr *n, void *arg);
-int print_addrlabel(struct nlmsghdr *n, void *arg);
-int print_neigh(struct nlmsghdr *n, void *arg);
+int print_linkinfo(const struct sockaddr_nl *who,
+		   struct nlmsghdr *n, void *arg);
+int print_linkinfo_brief(const struct sockaddr_nl *who,
+			 struct nlmsghdr *n, void *arg);
+int print_addrinfo(const struct sockaddr_nl *who,
+		   struct nlmsghdr *n, void *arg);
+int print_addrlabel(const struct sockaddr_nl *who,
+		    struct nlmsghdr *n, void *arg);
+int print_neigh(const struct sockaddr_nl *who,
+	        struct nlmsghdr *n, void *arg);
 int ipaddr_list_link(int argc, char **argv);
-void ipaddr_get_vf_rate(int, int *, int *, const char *);
+void ipaddr_get_vf_rate(int, int *, int *, int);
 void iplink_usage(void) __attribute__((noreturn));
 
 void iproute_reset_filter(int ifindex);
@@ -42,19 +19,20 @@
 void ipneigh_reset_filter(int ifindex);
 void ipnetconf_reset_filter(int ifindex);
 
-int print_route(struct nlmsghdr *n, void *arg);
-int print_mroute(struct nlmsghdr *n, void *arg);
-int print_prefix(struct nlmsghdr *n, void *arg);
-int print_rule(struct nlmsghdr *n, void *arg);
-int print_netconf(struct rtnl_ctrl_data *ctrl,
+int print_route(const struct sockaddr_nl *who,
+		struct nlmsghdr *n, void *arg);
+int print_mroute(const struct sockaddr_nl *who,
+		 struct nlmsghdr *n, void *arg);
+int print_prefix(const struct sockaddr_nl *who,
+		 struct nlmsghdr *n, void *arg);
+int print_rule(const struct sockaddr_nl *who,
+	       struct nlmsghdr *n, void *arg);
+int print_netconf(const struct sockaddr_nl *who,
+		  struct rtnl_ctrl_data *ctrl,
 		  struct nlmsghdr *n, void *arg);
-int print_nexthop(struct nlmsghdr *n, void *arg);
 void netns_map_init(void);
-void netns_nsid_socket_init(void);
-int print_nsid(struct nlmsghdr *n, void *arg);
-char *get_name_from_nsid(int nsid);
-int get_netnsid_from_name(const char *name);
-int set_netnsid_from_name(const char *name, int nsid);
+int print_nsid(const struct sockaddr_nl *who,
+	       struct nlmsghdr *n, void *arg);
 int do_ipaddr(int argc, char **argv);
 int do_ipaddrlabel(int argc, char **argv);
 int do_iproute(int argc, char **argv);
@@ -65,7 +43,6 @@
 int do_ip6tunnel(int argc, char **argv);
 int do_iptuntap(int argc, char **argv);
 int do_iplink(int argc, char **argv);
-int do_ipmacsec(int argc, char **argv);
 int do_ipmonitor(int argc, char **argv);
 int do_multiaddr(int argc, char **argv);
 int do_multiroute(int argc, char **argv);
@@ -74,26 +51,14 @@
 int do_xfrm(int argc, char **argv);
 int do_ipl2tp(int argc, char **argv);
 int do_ipfou(int argc, char **argv);
-int do_ipila(int argc, char **argv);
 int do_tcp_metrics(int argc, char **argv);
 int do_ipnetconf(int argc, char **argv);
 int do_iptoken(int argc, char **argv);
-int do_ipvrf(int argc, char **argv);
-void vrf_reset(void);
-int netns_identify_pid(const char *pidstr, char *name, int len);
-int do_seg6(int argc, char **argv);
-int do_ipnh(int argc, char **argv);
-
-int iplink_get(char *name, __u32 filt_mask);
-int iplink_ifla_xstats(int argc, char **argv);
-
-int ip_link_list(req_filter_fn_t filter_fn, struct nlmsg_chain *linfo);
-void free_nlmsg_chain(struct nlmsg_chain *info);
+int iplink_get(unsigned int flags, char *name, __u32 filt_mask);
 
 static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
 {
 	__u32 table = r->rtm_table;
-
 	if (tb[RTA_TABLE])
 		table = rta_getattr_u32(tb[RTA_TABLE]);
 	return table;
@@ -101,13 +66,10 @@
 
 extern struct rtnl_handle rth;
 
-struct iplink_req {
-	struct nlmsghdr		n;
-	struct ifinfomsg	i;
-	char			buf[1024];
-};
+#include <stdbool.h>
 
-struct link_util {
+struct link_util
+{
 	struct link_util	*next;
 	const char		*id;
 	int			maxattr;
@@ -116,51 +78,15 @@
 	void			(*print_opt)(struct link_util *, FILE *,
 					     struct rtattr *[]);
 	void			(*print_xstats)(struct link_util *, FILE *,
-						struct rtattr *);
+					     struct rtattr *);
 	void			(*print_help)(struct link_util *, int, char **,
-					      FILE *);
-	int			(*parse_ifla_xstats)(struct link_util *,
-						     int, char **);
-	int			(*print_ifla_xstats)(struct nlmsghdr *, void *);
+					     FILE *);
+	bool			slave;
 };
 
 struct link_util *get_link_kind(const char *kind);
-
-int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type);
-
-/* iplink_bridge.c */
-void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
-int bridge_parse_xstats(struct link_util *lu, int argc, char **argv);
-int bridge_print_xstats(struct nlmsghdr *n, void *arg);
-
-int bond_parse_xstats(struct link_util *lu, int argc, char **argv);
-int bond_print_xstats(struct nlmsghdr *n, void *arg);
-
-/* iproute_lwtunnel.c */
-int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp,
-		    int encap_attr, int encap_type_attr);
-void lwt_print_encap(FILE *fp, struct rtattr *encap_type, struct rtattr *encap);
-
-/* iplink_xdp.c */
-int xdp_parse(int *argc, char ***argv, struct iplink_req *req, const char *ifname,
-	      bool generic, bool drv, bool offload);
-void xdp_dump(FILE *fp, struct rtattr *tb, bool link, bool details);
-
-/* iplink_vrf.c */
-__u32 ipvrf_get_table(const char *name);
-int name_is_vrf(const char *name);
+struct link_util *get_link_slave_kind(const char *slave_kind);
 
 #ifndef	INFINITY_LIFE_TIME
 #define     INFINITY_LIFE_TIME      0xFFFFFFFFU
 #endif
-
-#ifndef LABEL_MAX_MASK
-#define     LABEL_MAX_MASK          0xFFFFFU
-#endif
-
-void print_num(FILE *fp, unsigned int width, uint64_t count);
-void print_rt_flags(FILE *fp, unsigned int flags);
-void print_rta_if(FILE *fp, const struct rtattr *rta, const char *prefix);
-void print_rta_gateway(FILE *fp, unsigned char family,
-		       const struct rtattr *rta);
-#endif /* _IP_COMMON_H_ */
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 0c65f34..9d254d2 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -13,11 +13,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <inttypes.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <sys/param.h>
+#include <sys/ioctl.h>
 #include <errno.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -26,11 +27,9 @@
 
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
-#include <linux/if_infiniband.h>
 #include <linux/sockios.h>
 #include <linux/net_namespace.h>
 
-#include "utils.h"
 #include "rt_names.h"
 #include "utils.h"
 #include "ll_map.h"
@@ -43,57 +42,66 @@
 	IPADD_SAVE,
 };
 
-static struct link_filter filter;
+static struct
+{
+	int ifindex;
+	int family;
+	int oneline;
+	int showqueue;
+	inet_prefix pfx;
+	int scope, scopemask;
+	int flags, flagmask;
+	int up;
+	char *label;
+	int flushed;
+	char *flushb;
+	int flushp;
+	int flushe;
+	int group;
+	int master;
+	char *kind;
+} filter;
+
 static int do_link;
 
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-	if (do_link)
+	if (do_link) {
 		iplink_usage();
-
-	fprintf(stderr,
-		"Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]\n"
-		"                                                      [ CONFFLAG-LIST ]\n"
-		"       ip address del IFADDR dev IFNAME [mngtmpaddr]\n"
-		"       ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]\n"
-		"                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n"
-		"       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n"
-		"                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n"
-		"                         [ label LABEL ] [up] [ vrf NAME ] ]\n"
-		"       ip address {showdump|restore}\n"
-		"IFADDR := PREFIX | ADDR peer PREFIX\n"
-		"          [ broadcast ADDR ] [ anycast ADDR ]\n"
-		"          [ label IFNAME ] [ scope SCOPE-ID ] [ metric METRIC ]\n"
-		"SCOPE-ID := [ host | link | global | NUMBER ]\n"
-		"FLAG-LIST := [ FLAG-LIST ] FLAG\n"
-		"FLAG  := [ permanent | dynamic | secondary | primary |\n"
-		"           [-]tentative | [-]deprecated | [-]dadfailed | temporary |\n"
-		"           CONFFLAG-LIST ]\n"
-		"CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG\n"
-		"CONFFLAG  := [ home | nodad | optimistic | mngtmpaddr | noprefixroute | autojoin ]\n"
-		"LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]\n"
-		"LFT := forever | SECONDS\n"
-		"TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |\n"
-		"          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |\n"
-		"          gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti |\n"
-		"          nlmon | can | bond_slave | ipvlan | geneve | bridge_slave |\n"
-		"          hsr | macsec | netdevsim }\n");
+	}
+	fprintf(stderr, "Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]\n");
+	fprintf(stderr, "                                                      [ CONFFLAG-LIST ]\n");
+	fprintf(stderr, "       ip address del IFADDR dev IFNAME [mngtmpaddr]\n");
+	fprintf(stderr, "       ip address {show|save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]\n");
+	fprintf(stderr, "                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n");
+	fprintf(stderr, "       ip address {showdump|restore}\n");
+	fprintf(stderr, "IFADDR := PREFIX | ADDR peer PREFIX\n");
+	fprintf(stderr, "          [ broadcast ADDR ] [ anycast ADDR ]\n");
+	fprintf(stderr, "          [ label IFNAME ] [ scope SCOPE-ID ]\n");
+	fprintf(stderr, "SCOPE-ID := [ host | link | global | NUMBER ]\n");
+	fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n");
+	fprintf(stderr, "FLAG  := [ permanent | dynamic | secondary | primary |\n");
+	fprintf(stderr, "           [-]tentative | [-]deprecated | [-]dadfailed | temporary |\n");
+	fprintf(stderr, "           CONFFLAG-LIST ]\n");
+	fprintf(stderr, "CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG\n");
+	fprintf(stderr, "CONFFLAG  := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]\n");
+	fprintf(stderr, "LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]\n");
+	fprintf(stderr, "LFT := forever | SECONDS\n");
 
 	exit(-1);
 }
 
-static void print_link_flags(FILE *fp, unsigned int flags, unsigned int mdown)
+static void print_link_flags(FILE *fp, unsigned flags, unsigned mdown)
 {
-	open_json_array(PRINT_ANY, is_json_context() ? "flags" : "<");
+	fprintf(fp, "<");
 	if (flags & IFF_UP && !(flags & IFF_RUNNING))
-		print_string(PRINT_ANY, NULL,
-			     flags ? "%s," : "%s", "NO-CARRIER");
+		fprintf(fp, "NO-CARRIER%s", flags ? "," : "");
 	flags &= ~IFF_RUNNING;
-#define _PF(f) if (flags&IFF_##f) {					\
-		flags &= ~IFF_##f ;					\
-		print_string(PRINT_ANY, NULL, flags ? "%s," : "%s", #f); }
+#define _PF(f) if (flags&IFF_##f) { \
+		  flags &= ~IFF_##f ; \
+		  fprintf(fp, #f "%s", flags ? "," : ""); }
 	_PF(LOOPBACK);
 	_PF(BROADCAST);
 	_PF(POINTOPOINT);
@@ -114,10 +122,10 @@
 	_PF(ECHO);
 #undef _PF
 	if (flags)
-		print_hex(PRINT_ANY, NULL, "%x", flags);
+		fprintf(fp, "%x", flags);
 	if (mdown)
-		print_string(PRINT_ANY, NULL, ",%s", "M-DOWN");
-	close_json_array(PRINT_ANY, "> ");
+		fprintf(fp, ",M-DOWN");
+	fprintf(fp, "> ");
 }
 
 static const char *oper_states[] = {
@@ -127,26 +135,24 @@
 
 static void print_operstate(FILE *f, __u8 state)
 {
-	if (state >= ARRAY_SIZE(oper_states)) {
-		if (is_json_context())
-			print_uint(PRINT_JSON, "operstate_index", NULL, state);
-		else
-			print_0xhex(PRINT_FP, NULL, "state %#llx", state);
-	} else if (brief) {
-		print_color_string(PRINT_ANY,
-				   oper_state_color(state),
-				   "operstate",
-				   "%-14s ",
-				   oper_states[state]);
-	} else {
-		if (is_json_context())
-			print_string(PRINT_JSON,
-				     "operstate",
-				     NULL, oper_states[state]);
-		else {
+	if (state >= sizeof(oper_states)/sizeof(oper_states[0]))
+		fprintf(f, "state %#x ", state);
+	else {
+		if (brief) {
+			if (strcmp(oper_states[state], "UP") == 0)
+				color_fprintf(f, COLOR_OPERSTATE_UP, "%-14s ", oper_states[state]);
+			else if (strcmp(oper_states[state], "DOWN") == 0)
+				color_fprintf(f, COLOR_OPERSTATE_DOWN, "%-14s ", oper_states[state]);
+			else
+				fprintf(f, "%-14s ", oper_states[state]);
+		} else {
 			fprintf(f, "state ");
-			color_fprintf(f, oper_state_color(state),
-				      "%s ", oper_states[state]);
+			if (strcmp(oper_states[state], "UP") == 0)
+				color_fprintf(f, COLOR_OPERSTATE_UP, "%s ", oper_states[state]);
+			else if (strcmp(oper_states[state], "DOWN") == 0)
+				color_fprintf(f, COLOR_OPERSTATE_DOWN, "%s ", oper_states[state]);
+			else
+				fprintf(f, "%s ", oper_states[state]);
 		}
 	}
 }
@@ -155,7 +161,7 @@
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(oper_states); i++)
+	for (i = 0; i < sizeof(oper_states)/sizeof(oper_states[0]); i++)
 		if (strcasecmp(name, oper_states[i]) == 0)
 			return i;
 	return -1;
@@ -166,19 +172,18 @@
 	int qlen;
 
 	if (tb[IFLA_TXQLEN])
-		qlen = rta_getattr_u32(tb[IFLA_TXQLEN]);
+		qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
 	else {
-		struct ifreq ifr = {};
+		struct ifreq ifr;
 		int s = socket(AF_INET, SOCK_STREAM, 0);
 
 		if (s < 0)
 			return;
 
+		memset(&ifr, 0, sizeof(ifr));
 		strcpy(ifr.ifr_name, rta_getattr_str(tb[IFLA_IFNAME]));
 		if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
-			fprintf(stderr,
-				"ioctl(SIOCGIFTXQLEN) failed: %s\n",
-				strerror(errno));
+			fprintf(f, "ioctl(SIOCGIFTXQLEN) failed: %s\n", strerror(errno));
 			close(s);
 			return;
 		}
@@ -186,7 +191,7 @@
 		qlen = ifr.ifr_qlen;
 	}
 	if (qlen)
-		print_int(PRINT_ANY, "txqlen", "qlen %d", qlen);
+		fprintf(f, "qlen %d", qlen);
 }
 
 static const char *link_modes[] = {
@@ -197,55 +202,39 @@
 {
 	unsigned int mode = rta_getattr_u8(tb);
 
-	if (mode >= ARRAY_SIZE(link_modes))
-		print_int(PRINT_ANY,
-			  "linkmode_index",
-			  "mode %d ",
-			  mode);
+	if (mode >= sizeof(link_modes) / sizeof(link_modes[0]))
+		fprintf(f, "mode %d ", mode);
 	else
-		print_string(PRINT_ANY,
-			     "linkmode",
-			     "mode %s "
-			     , link_modes[mode]);
+		fprintf(f, "mode %s ", link_modes[mode]);
 }
 
-static char *parse_link_kind(struct rtattr *tb, bool slave)
+static char *parse_link_kind(struct rtattr *tb)
 {
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
-	int attr = slave ? IFLA_INFO_SLAVE_KIND : IFLA_INFO_KIND;
 
 	parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
 
-	if (linkinfo[attr])
-		return RTA_DATA(linkinfo[attr]);
+	if (linkinfo[IFLA_INFO_KIND])
+		return RTA_DATA(linkinfo[IFLA_INFO_KIND]);
 
 	return "";
 }
 
-static int match_link_kind(struct rtattr **tb, const char *kind, bool slave)
-{
-	if (!tb[IFLA_LINKINFO])
-		return -1;
-
-	return strcmp(parse_link_kind(tb[IFLA_LINKINFO], slave), kind);
-}
-
 static void print_linktype(FILE *fp, struct rtattr *tb)
 {
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct link_util *lu;
 	struct link_util *slave_lu;
-	char slave[32];
+	char *kind;
+	char *slave_kind;
 
 	parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
-	open_json_object("linkinfo");
 
 	if (linkinfo[IFLA_INFO_KIND]) {
-		const char *kind
-			= rta_getattr_str(linkinfo[IFLA_INFO_KIND]);
+		kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
 
-		print_nl();
-		print_string(PRINT_ANY, "info_kind", "    %s ", kind);
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "    %s ", kind);
 
 		lu = get_link_kind(kind);
 		if (lu && lu->print_opt) {
@@ -256,32 +245,21 @@
 						    linkinfo[IFLA_INFO_DATA]);
 				data = attr;
 			}
-			open_json_object("info_data");
 			lu->print_opt(lu, fp, data);
-			close_json_object();
 
 			if (linkinfo[IFLA_INFO_XSTATS] && show_stats &&
-			    lu->print_xstats) {
-				open_json_object("info_xstats");
+			    lu->print_xstats)
 				lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]);
-				close_json_object();
-			}
 		}
 	}
 
 	if (linkinfo[IFLA_INFO_SLAVE_KIND]) {
-		const char *slave_kind
-			= rta_getattr_str(linkinfo[IFLA_INFO_SLAVE_KIND]);
+		slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
 
-		print_nl();
-		print_string(PRINT_ANY,
-			     "info_slave_kind",
-			     "    %s_slave ",
-			     slave_kind);
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "    %s_slave ", slave_kind);
 
-		snprintf(slave, sizeof(slave), "%s_slave", slave_kind);
-
-		slave_lu = get_link_kind(slave);
+		slave_lu = get_link_slave_kind(slave_kind);
 		if (slave_lu && slave_lu->print_opt) {
 			struct rtattr *attr[slave_lu->maxattr+1], **data = NULL;
 
@@ -290,12 +268,9 @@
 						    linkinfo[IFLA_INFO_SLAVE_DATA]);
 				data = attr;
 			}
-			open_json_object("info_slave_data");
 			slave_lu->print_opt(slave_lu, fp, data);
-			close_json_object();
 		}
 	}
-	close_json_object();
 }
 
 static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
@@ -311,39 +286,21 @@
 
 	if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
 		__u8 mode = rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
-		SPRINT_BUF(b1);
-
 		switch (mode) {
 		case IN6_ADDR_GEN_MODE_EUI64:
-			print_string(PRINT_ANY,
-				     "inet6_addr_gen_mode",
-				     "addrgenmode %s ",
-				     "eui64");
+			fprintf(fp, "addrgenmode eui64 ");
 			break;
 		case IN6_ADDR_GEN_MODE_NONE:
-			print_string(PRINT_ANY,
-				     "inet6_addr_gen_mode",
-				     "addrgenmode %s ",
-				     "none");
+			fprintf(fp, "addrgenmode none ");
 			break;
 		case IN6_ADDR_GEN_MODE_STABLE_PRIVACY:
-			print_string(PRINT_ANY,
-				     "inet6_addr_gen_mode",
-				     "addrgenmode %s ",
-				     "stable_secret");
+			fprintf(fp, "addrgenmode stable_secret ");
 			break;
 		case IN6_ADDR_GEN_MODE_RANDOM:
-			print_string(PRINT_ANY,
-				     "inet6_addr_gen_mode",
-				     "addrgenmode %s ",
-				     "random");
+			fprintf(fp, "addrgenmode random ");
 			break;
 		default:
-			snprintf(b1, sizeof(b1), "%#.2hhx", mode);
-			print_string(PRINT_ANY,
-				     "inet6_addr_gen_mode",
-				     "addrgenmode %s ",
-				     b1);
+			fprintf(fp, "addrgenmode %#.2hhx ", mode);
 			break;
 		}
 	}
@@ -351,13 +308,15 @@
 
 static void print_vf_stats64(FILE *fp, struct rtattr *vfstats);
 
-static void print_vfinfo(FILE *fp, struct ifinfomsg *ifi, struct rtattr *vfinfo)
+static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
 {
 	struct ifla_vf_mac *vf_mac;
-	struct ifla_vf_broadcast *vf_broadcast;
+	struct ifla_vf_vlan *vf_vlan;
 	struct ifla_vf_tx_rate *vf_tx_rate;
+	struct ifla_vf_spoofchk *vf_spoofchk;
+	struct ifla_vf_link_state *vf_linkstate;
 	struct rtattr *vf[IFLA_VF_MAX + 1] = {};
-
+	struct rtattr *tmp;
 	SPRINT_BUF(b1);
 
 	if (vfinfo->rta_type != IFLA_VF_INFO) {
@@ -368,170 +327,72 @@
 	parse_rtattr_nested(vf, IFLA_VF_MAX, vfinfo);
 
 	vf_mac = RTA_DATA(vf[IFLA_VF_MAC]);
-	vf_broadcast = RTA_DATA(vf[IFLA_VF_BROADCAST]);
+	vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]);
 	vf_tx_rate = RTA_DATA(vf[IFLA_VF_TX_RATE]);
 
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-	print_int(PRINT_ANY, "vf", "vf %d ", vf_mac->vf);
+	/* Check if the spoof checking vf info type is supported by
+	 * this kernel.
+	 */
+	tmp = (struct rtattr *)((char *)vf[IFLA_VF_TX_RATE] +
+			vf[IFLA_VF_TX_RATE]->rta_len);
 
-	print_string(PRINT_ANY,
-		     "link_type",
-		     "    link/%s ",
-		     ll_type_n2a(ifi->ifi_type, b1, sizeof(b1)));
+	if (tmp->rta_type != IFLA_VF_SPOOFCHK)
+		vf_spoofchk = NULL;
+	else
+		vf_spoofchk = RTA_DATA(vf[IFLA_VF_SPOOFCHK]);
 
-	print_color_string(PRINT_ANY, COLOR_MAC,
-			   "address", "%s",
-			   ll_addr_n2a((unsigned char *) &vf_mac->mac,
-				       ifi->ifi_type == ARPHRD_ETHER ?
-				       ETH_ALEN : INFINIBAND_ALEN,
-				       ifi->ifi_type,
-				       b1, sizeof(b1)));
+	if (vf_spoofchk) {
+		/* Check if the link state vf info type is supported by
+		 * this kernel.
+		 */
+		tmp = (struct rtattr *)((char *)vf[IFLA_VF_SPOOFCHK] +
+				vf[IFLA_VF_SPOOFCHK]->rta_len);
 
-	if (vf[IFLA_VF_BROADCAST]) {
-		if (ifi->ifi_flags&IFF_POINTOPOINT) {
-			print_string(PRINT_FP, NULL, " peer ", NULL);
-			print_bool(PRINT_JSON,
-				   "link_pointtopoint", NULL, true);
-		} else
-			print_string(PRINT_FP, NULL, " brd ", NULL);
+		if (tmp->rta_type != IFLA_VF_LINK_STATE)
+			vf_linkstate = NULL;
+		else
+			vf_linkstate = RTA_DATA(vf[IFLA_VF_LINK_STATE]);
+	} else
+		vf_linkstate = NULL;
 
-		print_color_string(PRINT_ANY, COLOR_MAC,
-				   "broadcast", "%s",
-				   ll_addr_n2a((unsigned char *) &vf_broadcast->broadcast,
-					       ifi->ifi_type == ARPHRD_ETHER ?
-					       ETH_ALEN : INFINIBAND_ALEN,
-					       ifi->ifi_type,
-					       b1, sizeof(b1)));
-	}
-
-	if (vf[IFLA_VF_VLAN_LIST]) {
-		struct rtattr *i, *vfvlanlist = vf[IFLA_VF_VLAN_LIST];
-		int rem = RTA_PAYLOAD(vfvlanlist);
-
-		open_json_array(PRINT_JSON, "vlan_list");
-		for (i = RTA_DATA(vfvlanlist);
-		     RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-			struct ifla_vf_vlan_info *vf_vlan_info = RTA_DATA(i);
-			SPRINT_BUF(b2);
-
-			open_json_object(NULL);
-			if (vf_vlan_info->vlan)
-				print_int(PRINT_ANY,
-					  "vlan",
-					  ", vlan %d",
-					  vf_vlan_info->vlan);
-			if (vf_vlan_info->qos)
-				print_int(PRINT_ANY,
-					  "qos",
-					  ", qos %d",
-					  vf_vlan_info->qos);
-			if (vf_vlan_info->vlan_proto &&
-			    vf_vlan_info->vlan_proto != htons(ETH_P_8021Q))
-				print_string(PRINT_ANY,
-					     "protocol",
-					     ", vlan protocol %s",
-					     ll_proto_n2a(
-						     vf_vlan_info->vlan_proto,
-						     b2, sizeof(b2)));
-			close_json_object();
-		}
-		close_json_array(PRINT_JSON, NULL);
-	} else {
-		struct ifla_vf_vlan *vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]);
-
-		if (vf_vlan->vlan)
-			print_int(PRINT_ANY,
-				  "vlan",
-				  ", vlan %d",
-				  vf_vlan->vlan);
-		if (vf_vlan->qos)
-			print_int(PRINT_ANY, "qos", ", qos %d", vf_vlan->qos);
-	}
-
+	fprintf(fp, "%s    vf %d MAC %s", _SL_, vf_mac->vf,
+		ll_addr_n2a((unsigned char *)&vf_mac->mac,
+		ETH_ALEN, 0, b1, sizeof(b1)));
+	if (vf_vlan->vlan)
+		fprintf(fp, ", vlan %d", vf_vlan->vlan);
+	if (vf_vlan->qos)
+		fprintf(fp, ", qos %d", vf_vlan->qos);
 	if (vf_tx_rate->rate)
-		print_uint(PRINT_ANY,
-			   "tx_rate",
-			   ", tx rate %u (Mbps)",
-			   vf_tx_rate->rate);
+		fprintf(fp, ", tx rate %d (Mbps)", vf_tx_rate->rate);
 
 	if (vf[IFLA_VF_RATE]) {
 		struct ifla_vf_rate *vf_rate = RTA_DATA(vf[IFLA_VF_RATE]);
-		int max_tx = vf_rate->max_tx_rate;
-		int min_tx = vf_rate->min_tx_rate;
 
-		if (is_json_context()) {
-			open_json_object("rate");
-			print_uint(PRINT_JSON, "max_tx", NULL, max_tx);
-			print_uint(PRINT_ANY, "min_tx", NULL, min_tx);
-			close_json_object();
-		} else {
-			if (max_tx)
-				fprintf(fp, ", max_tx_rate %uMbps", max_tx);
-			if (min_tx)
-				fprintf(fp, ", min_tx_rate %uMbps", min_tx);
-		}
+		if (vf_rate->max_tx_rate)
+			fprintf(fp, ", max_tx_rate %dMbps", vf_rate->max_tx_rate);
+		if (vf_rate->min_tx_rate)
+			fprintf(fp, ", min_tx_rate %dMbps", vf_rate->min_tx_rate);
 	}
 
-	if (vf[IFLA_VF_SPOOFCHK]) {
-		struct ifla_vf_spoofchk *vf_spoofchk =
-			RTA_DATA(vf[IFLA_VF_SPOOFCHK]);
-
-		if (vf_spoofchk->setting != -1)
-			print_bool(PRINT_ANY,
-				   "spoofchk",
-				   vf_spoofchk->setting ?
-				   ", spoof checking on" : ", spoof checking off",
-				   vf_spoofchk->setting);
-	}
-
-	if (vf[IFLA_VF_LINK_STATE]) {
-		struct ifla_vf_link_state *vf_linkstate =
-			RTA_DATA(vf[IFLA_VF_LINK_STATE]);
-
-		if (vf_linkstate->link_state == IFLA_VF_LINK_STATE_AUTO)
-			print_string(PRINT_ANY,
-				     "link_state",
-				     ", link-state %s",
-				     "auto");
-		else if (vf_linkstate->link_state == IFLA_VF_LINK_STATE_ENABLE)
-			print_string(PRINT_ANY,
-				     "link_state",
-				     ", link-state %s",
-				     "enable");
+	if (vf_spoofchk && vf_spoofchk->setting != -1) {
+		if (vf_spoofchk->setting)
+			fprintf(fp, ", spoof checking on");
 		else
-			print_string(PRINT_ANY,
-				     "link_state",
-				     ", link-state %s",
-				     "disable");
+			fprintf(fp, ", spoof checking off");
 	}
-
-	if (vf[IFLA_VF_TRUST]) {
-		struct ifla_vf_trust *vf_trust = RTA_DATA(vf[IFLA_VF_TRUST]);
-
-		if (vf_trust->setting != -1)
-			print_bool(PRINT_ANY,
-				   "trust",
-				   vf_trust->setting ? ", trust on" : ", trust off",
-				   vf_trust->setting);
+	if (vf_linkstate) {
+		if (vf_linkstate->link_state == IFLA_VF_LINK_STATE_AUTO)
+			fprintf(fp, ", link-state auto");
+		else if (vf_linkstate->link_state == IFLA_VF_LINK_STATE_ENABLE)
+			fprintf(fp, ", link-state enable");
+		else
+			fprintf(fp, ", link-state disable");
 	}
-
-	if (vf[IFLA_VF_RSS_QUERY_EN]) {
-		struct ifla_vf_rss_query_en *rss_query =
-			RTA_DATA(vf[IFLA_VF_RSS_QUERY_EN]);
-
-		if (rss_query->setting != -1)
-			print_bool(PRINT_ANY,
-				   "query_rss_en",
-				   rss_query->setting ? ", query_rss on"
-				   : ", query_rss off",
-				   rss_query->setting);
-	}
-
 	if (vf[IFLA_VF_STATS] && show_stats)
 		print_vf_stats64(fp, vf[IFLA_VF_STATS]);
 }
 
-void print_num(FILE *fp, unsigned int width, uint64_t count)
+static void print_num(FILE *fp, unsigned width, uint64_t count)
 {
 	const char *prefix = "kMGTPE";
 	const unsigned int base = use_iec ? 1024 : 1000;
@@ -546,9 +407,8 @@
 	}
 
 	/* increase value by a factor of 1000/1024 and print
-	 * if result is something a human can read
-	 */
-	for (;;) {
+	 * if result is something a human can read */
+	for(;;) {
 		powi *= base;
 		if (count / base < powi)
 			break;
@@ -566,309 +426,202 @@
 	}
 
 	snprintf(buf, sizeof(buf), "%.*f%c%s", precision,
-		 (double) count / powi, *prefix, use_iec ? "i" : "");
+		(double) count / powi, *prefix, use_iec ? "i" : "");
 
 	fprintf(fp, "%-*s ", width, buf);
 }
 
 static void print_vf_stats64(FILE *fp, struct rtattr *vfstats)
 {
-	struct rtattr *vf[IFLA_VF_STATS_MAX + 1];
+	struct rtattr *vf[IFLA_VF_STATS_MAX + 1] = {};
 
 	if (vfstats->rta_type != IFLA_VF_STATS) {
 		fprintf(stderr, "BUG: rta type is %d\n", vfstats->rta_type);
 		return;
 	}
 
-	parse_rtattr_nested(vf, IFLA_VF_STATS_MAX, vfstats);
+	parse_rtattr_nested(vf, IFLA_VF_MAX, vfstats);
 
-	if (is_json_context()) {
-		open_json_object("stats");
+	/* RX stats */
+	fprintf(fp, "%s", _SL_);
+	fprintf(fp, "    RX: bytes  packets  mcast   bcast %s", _SL_);
+	fprintf(fp, "    ");
 
-		/* RX stats */
-		open_json_object("rx");
-		print_u64(PRINT_JSON, "bytes", NULL,
-			   rta_getattr_u64(vf[IFLA_VF_STATS_RX_BYTES]));
-		print_u64(PRINT_JSON, "packets", NULL,
-			   rta_getattr_u64(vf[IFLA_VF_STATS_RX_PACKETS]));
-		print_u64(PRINT_JSON, "multicast", NULL,
-			   rta_getattr_u64(vf[IFLA_VF_STATS_MULTICAST]));
-		print_u64(PRINT_JSON, "broadcast", NULL,
-			   rta_getattr_u64(vf[IFLA_VF_STATS_BROADCAST]));
-		if (vf[IFLA_VF_STATS_RX_DROPPED])
-			print_u64(PRINT_JSON, "dropped", NULL,
-				  rta_getattr_u64(vf[IFLA_VF_STATS_RX_DROPPED]));
-		close_json_object();
+	print_num(fp, 10, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_RX_BYTES]));
+	print_num(fp, 8, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_RX_PACKETS]));
+	print_num(fp, 7, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_MULTICAST]));
+	print_num(fp, 7, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_BROADCAST]));
 
-		/* TX stats */
-		open_json_object("tx");
-		print_u64(PRINT_JSON, "tx_bytes", NULL,
-			   rta_getattr_u64(vf[IFLA_VF_STATS_TX_BYTES]));
-		print_u64(PRINT_JSON, "tx_packets", NULL,
-			   rta_getattr_u64(vf[IFLA_VF_STATS_TX_PACKETS]));
-		if (vf[IFLA_VF_STATS_TX_DROPPED])
-			print_u64(PRINT_JSON, "dropped", NULL,
-				  rta_getattr_u64(vf[IFLA_VF_STATS_TX_DROPPED]));
-		close_json_object();
-		close_json_object();
-	} else {
-		/* RX stats */
+	/* TX stats */
+	fprintf(fp, "%s", _SL_);
+	fprintf(fp, "    TX: bytes  packets %s", _SL_);
+	fprintf(fp, "    ");
+
+	print_num(fp, 10, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_TX_BYTES]));
+	print_num(fp, 8, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_TX_PACKETS]));
+}
+
+static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
+                               const struct rtattr *carrier_changes)
+{
+	/* RX stats */
+	fprintf(fp, "    RX: bytes  packets  errors  dropped overrun mcast   %s%s",
+		s->rx_compressed ? "compressed" : "", _SL_);
+
+	fprintf(fp, "    ");
+	print_num(fp, 10, s->rx_bytes);
+	print_num(fp, 8, s->rx_packets);
+	print_num(fp, 7, s->rx_errors);
+	print_num(fp, 7, s->rx_dropped);
+	print_num(fp, 7, s->rx_over_errors);
+	print_num(fp, 7, s->multicast);
+	if (s->rx_compressed)
+		print_num(fp, 7, s->rx_compressed);
+
+	/* RX error stats */
+	if (show_stats > 1) {
 		fprintf(fp, "%s", _SL_);
-		fprintf(fp, "    RX: bytes  packets  mcast   bcast ");
-		if (vf[IFLA_VF_STATS_RX_DROPPED])
-			fprintf(fp, "  dropped ");
-		fprintf(fp, "%s", _SL_);
-		fprintf(fp, "    ");
+		fprintf(fp, "    RX errors: length   crc     frame   fifo    missed%s", _SL_);
 
-		print_num(fp, 10, rta_getattr_u64(vf[IFLA_VF_STATS_RX_BYTES]));
-		print_num(fp, 8, rta_getattr_u64(vf[IFLA_VF_STATS_RX_PACKETS]));
-		print_num(fp, 7, rta_getattr_u64(vf[IFLA_VF_STATS_MULTICAST]));
-		print_num(fp, 7, rta_getattr_u64(vf[IFLA_VF_STATS_BROADCAST]));
-		if (vf[IFLA_VF_STATS_RX_DROPPED])
-			print_num(fp, 8, rta_getattr_u64(vf[IFLA_VF_STATS_RX_DROPPED]));
+		fprintf(fp, "               ");
+		print_num(fp, 8, s->rx_length_errors);
+		print_num(fp, 7, s->rx_crc_errors);
+		print_num(fp, 7, s->rx_frame_errors);
+		print_num(fp, 7, s->rx_fifo_errors);
+		print_num(fp, 7, s->rx_missed_errors);
+	}
+	fprintf(fp, "%s", _SL_);
 
-		/* TX stats */
-		fprintf(fp, "%s", _SL_);
-		fprintf(fp, "    TX: bytes  packets ");
-		if (vf[IFLA_VF_STATS_TX_DROPPED])
-			fprintf(fp, "  dropped ");
-		fprintf(fp, "%s", _SL_);
-		fprintf(fp, "    ");
+	/* TX stats */
+	fprintf(fp, "    TX: bytes  packets  errors  dropped carrier collsns %s%s",
+		s->tx_compressed ? "compressed" : "", _SL_);
 
-		print_num(fp, 10, rta_getattr_u64(vf[IFLA_VF_STATS_TX_BYTES]));
-		print_num(fp, 8, rta_getattr_u64(vf[IFLA_VF_STATS_TX_PACKETS]));
-		if (vf[IFLA_VF_STATS_TX_DROPPED])
-			print_num(fp, 8, rta_getattr_u64(vf[IFLA_VF_STATS_TX_DROPPED]));
+
+	fprintf(fp, "    ");
+	print_num(fp, 10, s->tx_bytes);
+	print_num(fp, 8, s->tx_packets);
+	print_num(fp, 7, s->tx_errors);
+	print_num(fp, 7, s->tx_dropped);
+	print_num(fp, 7, s->tx_carrier_errors);
+	print_num(fp, 7, s->collisions);
+	if (s->tx_compressed)
+		print_num(fp, 7, s->tx_compressed);
+
+	/* TX error stats */
+	if (show_stats > 1) {
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "    TX errors: aborted  fifo   window heartbeat");
+                if (carrier_changes)
+			fprintf(fp, " transns");
+		fprintf(fp, "%s", _SL_);
+
+		fprintf(fp, "               ");
+		print_num(fp, 8, s->tx_aborted_errors);
+		print_num(fp, 7, s->tx_fifo_errors);
+		print_num(fp, 7, s->tx_window_errors);
+		print_num(fp, 7, s->tx_heartbeat_errors);
+		if (carrier_changes)
+			print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes));
 	}
 }
 
-static void __print_link_stats(FILE *fp, struct rtattr *tb[])
+static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
+			       const struct rtattr *carrier_changes)
 {
-	const struct rtattr *carrier_changes = tb[IFLA_CARRIER_CHANGES];
-	struct rtnl_link_stats64 _s, *s = &_s;
-	int ret;
+	/* RX stats */
+	fprintf(fp, "    RX: bytes  packets  errors  dropped overrun mcast   %s%s",
+		s->rx_compressed ? "compressed" : "", _SL_);
 
-	ret = get_rtnl_link_stats_rta(s, tb);
-	if (ret < 0)
-		return;
 
-	if (is_json_context()) {
-		open_json_object((ret == sizeof(*s)) ? "stats64" : "stats");
+	fprintf(fp, "    ");
+	print_num(fp, 10, s->rx_bytes);
+	print_num(fp, 8, s->rx_packets);
+	print_num(fp, 7, s->rx_errors);
+	print_num(fp, 7, s->rx_dropped);
+	print_num(fp, 7, s->rx_over_errors);
+	print_num(fp, 7, s->multicast);
+	if (s->rx_compressed)
+		print_num(fp, 7, s->rx_compressed);
 
-		/* RX stats */
-		open_json_object("rx");
-		print_u64(PRINT_JSON, "bytes", NULL, s->rx_bytes);
-		print_u64(PRINT_JSON, "packets", NULL, s->rx_packets);
-		print_u64(PRINT_JSON, "errors", NULL, s->rx_errors);
-		print_u64(PRINT_JSON, "dropped", NULL, s->rx_dropped);
-		print_u64(PRINT_JSON, "over_errors", NULL, s->rx_over_errors);
-		print_u64(PRINT_JSON, "multicast", NULL, s->multicast);
-		if (s->rx_compressed)
-			print_u64(PRINT_JSON,
-				   "compressed", NULL, s->rx_compressed);
+	/* RX error stats */
+	if (show_stats > 1) {
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "    RX errors: length   crc     frame   fifo    missed%s", _SL_);
+		fprintf(fp, "               ");
+		print_num(fp, 8, s->rx_length_errors);
+		print_num(fp, 7, s->rx_crc_errors);
+		print_num(fp, 7, s->rx_frame_errors);
+		print_num(fp, 7, s->rx_fifo_errors);
+		print_num(fp, 7, s->rx_missed_errors);
+	}
+	fprintf(fp, "%s", _SL_);
 
-		/* RX error stats */
-		if (show_stats > 1) {
-			print_u64(PRINT_JSON,
-				   "length_errors",
-				   NULL, s->rx_length_errors);
-			print_u64(PRINT_JSON,
-				   "crc_errors",
-				   NULL, s->rx_crc_errors);
-			print_u64(PRINT_JSON,
-				   "frame_errors",
-				   NULL, s->rx_frame_errors);
-			print_u64(PRINT_JSON,
-				   "fifo_errors",
-				   NULL, s->rx_fifo_errors);
-			print_u64(PRINT_JSON,
-				   "missed_errors",
-				   NULL, s->rx_missed_errors);
-			if (s->rx_nohandler)
-				print_u64(PRINT_JSON,
-					   "nohandler", NULL, s->rx_nohandler);
-		}
-		close_json_object();
+	/* TX stats */
+	fprintf(fp, "    TX: bytes  packets  errors  dropped carrier collsns %s%s",
+		s->tx_compressed ? "compressed" : "", _SL_);
 
-		/* TX stats */
-		open_json_object("tx");
-		print_u64(PRINT_JSON, "bytes", NULL, s->tx_bytes);
-		print_u64(PRINT_JSON, "packets", NULL, s->tx_packets);
-		print_u64(PRINT_JSON, "errors", NULL, s->tx_errors);
-		print_u64(PRINT_JSON, "dropped", NULL, s->tx_dropped);
-		print_u64(PRINT_JSON,
-			   "carrier_errors",
-			   NULL, s->tx_carrier_errors);
-		print_u64(PRINT_JSON, "collisions", NULL, s->collisions);
-		if (s->tx_compressed)
-			print_u64(PRINT_JSON,
-				   "compressed", NULL, s->tx_compressed);
+	fprintf(fp, "    ");
+	print_num(fp, 10, s->tx_bytes);
+	print_num(fp, 8, s->tx_packets);
+	print_num(fp, 7, s->tx_errors);
+	print_num(fp, 7, s->tx_dropped);
+	print_num(fp, 7, s->tx_carrier_errors);
+	print_num(fp, 7, s->collisions);
+	if (s->tx_compressed)
+		print_num(fp, 7, s->tx_compressed);
 
-		/* TX error stats */
-		if (show_stats > 1) {
-			print_u64(PRINT_JSON,
-				   "aborted_errors",
-				   NULL, s->tx_aborted_errors);
-			print_u64(PRINT_JSON,
-				   "fifo_errors",
-				   NULL, s->tx_fifo_errors);
-			print_u64(PRINT_JSON,
-				   "window_errors",
-				   NULL, s->tx_window_errors);
-			print_u64(PRINT_JSON,
-				   "heartbeat_errors",
-				   NULL, s->tx_heartbeat_errors);
-			if (carrier_changes)
-				print_u64(PRINT_JSON, "carrier_changes", NULL,
-					   rta_getattr_u32(carrier_changes));
-		}
-
-		close_json_object();
-		close_json_object();
-	} else {
-		/* RX stats */
-		fprintf(fp, "    RX: bytes  packets  errors  dropped overrun mcast   %s%s",
-			s->rx_compressed ? "compressed" : "", _SL_);
-
-		fprintf(fp, "    ");
-		print_num(fp, 10, s->rx_bytes);
-		print_num(fp, 8, s->rx_packets);
-		print_num(fp, 7, s->rx_errors);
-		print_num(fp, 7, s->rx_dropped);
-		print_num(fp, 7, s->rx_over_errors);
-		print_num(fp, 7, s->multicast);
-		if (s->rx_compressed)
-			print_num(fp, 7, s->rx_compressed);
-
-		/* RX error stats */
-		if (show_stats > 1) {
-			fprintf(fp, "%s", _SL_);
-			fprintf(fp, "    RX errors: length   crc     frame   fifo    missed%s%s",
-				s->rx_nohandler ? "   nohandler" : "", _SL_);
-			fprintf(fp, "               ");
-			print_num(fp, 8, s->rx_length_errors);
-			print_num(fp, 7, s->rx_crc_errors);
-			print_num(fp, 7, s->rx_frame_errors);
-			print_num(fp, 7, s->rx_fifo_errors);
-			print_num(fp, 7, s->rx_missed_errors);
-			if (s->rx_nohandler)
-				print_num(fp, 7, s->rx_nohandler);
-		}
+	/* TX error stats */
+	if (show_stats > 1) {
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "    TX errors: aborted  fifo   window heartbeat");
+                if (carrier_changes)
+			fprintf(fp, " transns");
 		fprintf(fp, "%s", _SL_);
 
-		/* TX stats */
-		fprintf(fp, "    TX: bytes  packets  errors  dropped carrier collsns %s%s",
-			s->tx_compressed ? "compressed" : "", _SL_);
-
-		fprintf(fp, "    ");
-		print_num(fp, 10, s->tx_bytes);
-		print_num(fp, 8, s->tx_packets);
-		print_num(fp, 7, s->tx_errors);
-		print_num(fp, 7, s->tx_dropped);
-		print_num(fp, 7, s->tx_carrier_errors);
-		print_num(fp, 7, s->collisions);
-		if (s->tx_compressed)
-			print_num(fp, 7, s->tx_compressed);
-
-		/* TX error stats */
-		if (show_stats > 1) {
-			fprintf(fp, "%s", _SL_);
-			fprintf(fp, "    TX errors: aborted  fifo   window heartbeat");
-			if (carrier_changes)
-				fprintf(fp, " transns");
-			fprintf(fp, "%s", _SL_);
-
-			fprintf(fp, "               ");
-			print_num(fp, 8, s->tx_aborted_errors);
-			print_num(fp, 7, s->tx_fifo_errors);
-			print_num(fp, 7, s->tx_window_errors);
-			print_num(fp, 7, s->tx_heartbeat_errors);
-			if (carrier_changes)
-				print_num(fp, 7,
-					  rta_getattr_u32(carrier_changes));
-		}
+		fprintf(fp, "               ");
+		print_num(fp, 8, s->tx_aborted_errors);
+		print_num(fp, 7, s->tx_fifo_errors);
+		print_num(fp, 7, s->tx_window_errors);
+		print_num(fp, 7, s->tx_heartbeat_errors);
+		if (carrier_changes)
+			print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes));
 	}
 }
 
+static void __print_link_stats(FILE *fp, struct rtattr **tb)
+{
+	if (tb[IFLA_STATS64])
+		print_link_stats64(fp, RTA_DATA(tb[IFLA_STATS64]),
+					tb[IFLA_CARRIER_CHANGES]);
+	else if (tb[IFLA_STATS])
+		print_link_stats32(fp, RTA_DATA(tb[IFLA_STATS]),
+					tb[IFLA_CARRIER_CHANGES]);
+}
+
 static void print_link_stats(FILE *fp, struct nlmsghdr *n)
 {
 	struct ifinfomsg *ifi = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
+	struct rtattr * tb[IFLA_MAX+1];
 
 	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi),
 		     n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi)));
 	__print_link_stats(fp, tb);
-	print_nl();
+	fprintf(fp, "%s", _SL_);
 }
 
-static int print_linkinfo_brief(FILE *fp, const char *name,
-				const struct ifinfomsg *ifi,
-				struct rtattr *tb[])
+int print_linkinfo_brief(const struct sockaddr_nl *who,
+				struct nlmsghdr *n, void *arg)
 {
-	unsigned int m_flag = 0;
-
-	m_flag = print_name_and_link("%-16s ", name, tb);
-
-	if (tb[IFLA_OPERSTATE])
-		print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
-
-	if (filter.family == AF_PACKET) {
-		SPRINT_BUF(b1);
-
-		if (tb[IFLA_ADDRESS]) {
-			print_color_string(PRINT_ANY, COLOR_MAC,
-					   "address", "%s ",
-					   ll_addr_n2a(
-						   RTA_DATA(tb[IFLA_ADDRESS]),
-						   RTA_PAYLOAD(tb[IFLA_ADDRESS]),
-						   ifi->ifi_type,
-						   b1, sizeof(b1)));
-		}
-	}
-
-	if (filter.family == AF_PACKET) {
-		print_link_flags(fp, ifi->ifi_flags, m_flag);
-		print_string(PRINT_FP, NULL, "%s", "\n");
-	}
-
-	fflush(fp);
-	return 0;
-}
-
-static const char *link_events[] = {
-	[IFLA_EVENT_NONE] = "NONE",
-	[IFLA_EVENT_REBOOT] = "REBOOT",
-	[IFLA_EVENT_FEATURES] = "FEATURE CHANGE",
-	[IFLA_EVENT_BONDING_FAILOVER] = "BONDING FAILOVER",
-	[IFLA_EVENT_NOTIFY_PEERS] = "NOTIFY PEERS",
-	[IFLA_EVENT_IGMP_RESEND] = "RESEND IGMP",
-	[IFLA_EVENT_BONDING_OPTIONS] = "BONDING OPTION"
-};
-
-static void print_link_event(FILE *f, __u32 event)
-{
-	if (event >= ARRAY_SIZE(link_events))
-		print_int(PRINT_ANY, "event", "event %d ", event);
-	else {
-		if (event)
-			print_string(PRINT_ANY,
-				     "event", "event %s ",
-				     link_events[event]);
-	}
-}
-
-int print_linkinfo(struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct ifinfomsg *ifi = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
+	struct rtattr * tb[IFLA_MAX+1];
 	int len = n->nlmsg_len;
-	const char *name;
-	unsigned int m_flag = 0;
-	SPRINT_BUF(b1);
+	char *name;
+	char buf[32] = { 0, };
+	unsigned m_flag = 0;
 
 	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
-		return 0;
+		return -1;
 
 	len -= NLMSG_LENGTH(sizeof(*ifi));
 	if (len < 0)
@@ -880,63 +633,187 @@
 		return -1;
 
 	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
-
-	name = get_ifname_rta(ifi->ifi_index, tb[IFLA_IFNAME]);
-	if (!name)
+	if (tb[IFLA_IFNAME] == NULL) {
+		fprintf(stderr, "BUG: device with ifindex %d has nil ifname\n", ifi->ifi_index);
+	}
+	if (filter.label &&
+	    (!filter.family || filter.family == AF_PACKET) &&
+	    fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
 		return -1;
 
-	if (filter.label)
-		return 0;
-
 	if (tb[IFLA_GROUP]) {
-		int group = rta_getattr_u32(tb[IFLA_GROUP]);
-
+		int group = *(int*)RTA_DATA(tb[IFLA_GROUP]);
 		if (filter.group != -1 && group != filter.group)
 			return -1;
 	}
 
 	if (tb[IFLA_MASTER]) {
-		int master = rta_getattr_u32(tb[IFLA_MASTER]);
-
+		int master = *(int*)RTA_DATA(tb[IFLA_MASTER]);
 		if (filter.master > 0 && master != filter.master)
 			return -1;
-	} else if (filter.master > 0)
+	}
+	else if (filter.master > 0)
 		return -1;
 
-	if (filter.kind && match_link_kind(tb, filter.kind, 0))
-		return -1;
+	if (filter.kind) {
+		if (tb[IFLA_LINKINFO]) {
+			char *kind = parse_link_kind(tb[IFLA_LINKINFO]);
 
-	if (filter.slave_kind && match_link_kind(tb, filter.slave_kind, 1))
-		return -1;
+			if (strcmp(kind, filter.kind))
+				return -1;
+		} else {
+			return -1;
+		}
+	}
 
 	if (n->nlmsg_type == RTM_DELLINK)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
-	if (brief)
-		return print_linkinfo_brief(fp, name, ifi, tb);
+	name = (char *)(tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
 
-	print_int(PRINT_ANY, "ifindex", "%d: ", ifi->ifi_index);
+	if (tb[IFLA_LINK]) {
+		SPRINT_BUF(b1);
+		int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
+		if (iflink == 0)
+			snprintf(buf, sizeof(buf), "%s@NONE", name);
+		else {
+			snprintf(buf, sizeof(buf),
+				 "%s@%s", name, ll_idx_n2a(iflink, b1));
+			m_flag = ll_index_to_flags(iflink);
+			m_flag = !(m_flag & IFF_UP);
+		}
+	} else
+		snprintf(buf, sizeof(buf), "%s", name);
 
-	m_flag = print_name_and_link("%s: ", name, tb);
+	fprintf(fp, "%-16s ", buf);
+
+	if (tb[IFLA_OPERSTATE])
+		print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
+
+	if (filter.family == AF_PACKET) {
+		SPRINT_BUF(b1);
+		if (tb[IFLA_ADDRESS]) {
+			color_fprintf(fp, COLOR_MAC, "%s ",
+					ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
+						RTA_PAYLOAD(tb[IFLA_ADDRESS]),
+						ifi->ifi_type,
+						b1, sizeof(b1)));
+		}
+	}
+
+	if (filter.family == AF_PACKET)
+		print_link_flags(fp, ifi->ifi_flags, m_flag);
+
+	if (filter.family == AF_PACKET)
+		fprintf(fp, "\n");
+	fflush(fp);
+	return 0;
+}
+
+int print_linkinfo(const struct sockaddr_nl *who,
+		   struct nlmsghdr *n, void *arg)
+{
+	FILE *fp = (FILE*)arg;
+	struct ifinfomsg *ifi = NLMSG_DATA(n);
+	struct rtattr * tb[IFLA_MAX+1];
+	int len = n->nlmsg_len;
+	unsigned m_flag = 0;
+
+	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
+		return 0;
+
+	len -= NLMSG_LENGTH(sizeof(*ifi));
+	if (len < 0)
+		return -1;
+
+	if (filter.ifindex && ifi->ifi_index != filter.ifindex)
+		return 0;
+	if (filter.up && !(ifi->ifi_flags&IFF_UP))
+		return 0;
+
+	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
+	if (tb[IFLA_IFNAME] == NULL) {
+		fprintf(stderr, "BUG: device with ifindex %d has nil ifname\n", ifi->ifi_index);
+	}
+	if (filter.label &&
+	    (!filter.family || filter.family == AF_PACKET) &&
+	    fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
+		return 0;
+
+	if (tb[IFLA_GROUP]) {
+		int group = *(int*)RTA_DATA(tb[IFLA_GROUP]);
+		if (filter.group != -1 && group != filter.group)
+			return -1;
+	}
+
+	if (tb[IFLA_MASTER]) {
+		int master = *(int*)RTA_DATA(tb[IFLA_MASTER]);
+		if (filter.master > 0 && master != filter.master)
+			return -1;
+	}
+	else if (filter.master > 0)
+		return -1;
+
+	if (filter.kind) {
+		if (tb[IFLA_LINKINFO]) {
+			char *kind = parse_link_kind(tb[IFLA_LINKINFO]);
+
+			if (strcmp(kind, filter.kind))
+				return -1;
+		} else {
+			return -1;
+		}
+	}
+
+	if (n->nlmsg_type == RTM_DELLINK)
+		fprintf(fp, "Deleted ");
+
+	fprintf(fp, "%d: ", ifi->ifi_index);
+	color_fprintf(fp, COLOR_IFNAME, "%s",
+		tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
+
+	if (tb[IFLA_LINK]) {
+		SPRINT_BUF(b1);
+		int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
+		if (iflink == 0)
+			fprintf(fp, "@NONE: ");
+		else {
+			if (tb[IFLA_LINK_NETNSID])
+				fprintf(fp, "@if%d: ", iflink);
+			else {
+				fprintf(fp, "@%s: ", ll_idx_n2a(iflink, b1));
+				m_flag = ll_index_to_flags(iflink);
+				m_flag = !(m_flag & IFF_UP);
+			}
+		}
+	} else {
+		fprintf(fp, ": ");
+	}
 	print_link_flags(fp, ifi->ifi_flags, m_flag);
 
 	if (tb[IFLA_MTU])
-		print_int(PRINT_ANY,
-			  "mtu", "mtu %u ",
-			  rta_getattr_u32(tb[IFLA_MTU]));
-	if (tb[IFLA_XDP])
-		xdp_dump(fp, tb[IFLA_XDP], do_link, false);
+		fprintf(fp, "mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
 	if (tb[IFLA_QDISC])
-		print_string(PRINT_ANY,
-			     "qdisc",
-			     "qdisc %s ",
-			     rta_getattr_str(tb[IFLA_QDISC]));
+		fprintf(fp, "qdisc %s ", rta_getattr_str(tb[IFLA_QDISC]));
 	if (tb[IFLA_MASTER]) {
-		int master = rta_getattr_u32(tb[IFLA_MASTER]);
+		SPRINT_BUF(b1);
+		fprintf(fp, "master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1));
+	}
 
-		print_string(PRINT_ANY,
-			     "master", "master %s ",
-			     ll_index_to_name(master));
+	if (tb[IFLA_PHYS_PORT_ID]) {
+		SPRINT_BUF(b1);
+		fprintf(fp, "portid %s ",
+			hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_PORT_ID]),
+				      RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]),
+				      b1, sizeof(b1)));
+	}
+
+	if (tb[IFLA_PHYS_SWITCH_ID]) {
+		SPRINT_BUF(b1);
+		fprintf(fp, "switchid %s ",
+			hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]),
+				      RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]),
+				      b1, sizeof(b1)));
 	}
 
 	if (tb[IFLA_OPERSTATE])
@@ -946,200 +823,80 @@
 		print_linkmode(fp, tb[IFLA_LINKMODE]);
 
 	if (tb[IFLA_GROUP]) {
-		int group = rta_getattr_u32(tb[IFLA_GROUP]);
-
-		print_string(PRINT_ANY,
-			     "group",
-			     "group %s ",
-			     rtnl_group_n2a(group, b1, sizeof(b1)));
+		SPRINT_BUF(b1);
+		int group = *(int*)RTA_DATA(tb[IFLA_GROUP]);
+		fprintf(fp, "group %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
 	}
 
 	if (filter.showqueue)
 		print_queuelen(fp, tb);
 
-	if (tb[IFLA_EVENT])
-		print_link_event(fp, rta_getattr_u32(tb[IFLA_EVENT]));
-
 	if (!filter.family || filter.family == AF_PACKET || show_details) {
-		print_nl();
-		print_string(PRINT_ANY,
-			     "link_type",
-			     "    link/%s ",
-			     ll_type_n2a(ifi->ifi_type, b1, sizeof(b1)));
+		SPRINT_BUF(b1);
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "    link/%s ", ll_type_n2a(ifi->ifi_type, b1, sizeof(b1)));
+
 		if (tb[IFLA_ADDRESS]) {
-			print_color_string(PRINT_ANY,
-					   COLOR_MAC,
-					   "address",
-					   "%s",
-					   ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
-						       RTA_PAYLOAD(tb[IFLA_ADDRESS]),
-						       ifi->ifi_type,
-						       b1, sizeof(b1)));
+			color_fprintf(fp, COLOR_MAC, "%s",
+					ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
+						RTA_PAYLOAD(tb[IFLA_ADDRESS]),
+						ifi->ifi_type,
+						b1, sizeof(b1)));
 		}
 		if (tb[IFLA_BROADCAST]) {
-			if (ifi->ifi_flags&IFF_POINTOPOINT) {
-				print_string(PRINT_FP, NULL, " peer ", NULL);
-				print_bool(PRINT_JSON,
-					   "link_pointtopoint", NULL, true);
-			} else {
-				print_string(PRINT_FP, NULL, " brd ", NULL);
-			}
-			print_color_string(PRINT_ANY,
-					   COLOR_MAC,
-					   "broadcast",
-					   "%s",
-					   ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
-						       RTA_PAYLOAD(tb[IFLA_BROADCAST]),
-						       ifi->ifi_type,
-						       b1, sizeof(b1)));
+			if (ifi->ifi_flags&IFF_POINTOPOINT)
+				fprintf(fp, " peer ");
+			else
+				fprintf(fp, " brd ");
+			fprintf(fp, "%s", ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
+						      RTA_PAYLOAD(tb[IFLA_BROADCAST]),
+						      ifi->ifi_type,
+						      b1, sizeof(b1)));
 		}
 	}
 
 	if (tb[IFLA_LINK_NETNSID]) {
-		int id = rta_getattr_u32(tb[IFLA_LINK_NETNSID]);
+		int id = *(int*)RTA_DATA(tb[IFLA_LINK_NETNSID]);
 
-		if (is_json_context()) {
-			print_int(PRINT_JSON, "link_netnsid", NULL, id);
-		} else {
-			if (id >= 0) {
-				char *name = get_name_from_nsid(id);
-
-				if (name)
-					print_string(PRINT_FP, NULL,
-						     " link-netns %s", name);
-				else
-					print_int(PRINT_FP, NULL,
-						  " link-netnsid %d", id);
-			} else
-				print_string(PRINT_FP, NULL,
-					     " link-netnsid %s", "unknown");
-		}
-	}
-
-	if (tb[IFLA_NEW_NETNSID]) {
-		int id = rta_getattr_u32(tb[IFLA_NEW_NETNSID]);
-		char *name = get_name_from_nsid(id);
-
-		if (name)
-			print_string(PRINT_FP, NULL, " new-netns %s", name);
+		if (id >= 0)
+			fprintf(fp, " link-netnsid %d", id);
 		else
-			print_int(PRINT_FP, NULL, " new-netnsid %d", id);
-	}
-	if (tb[IFLA_NEW_IFINDEX]) {
-		int id = rta_getattr_u32(tb[IFLA_NEW_IFINDEX]);
-
-		print_int(PRINT_FP, NULL, " new-ifindex %d", id);
+			fprintf(fp, " link-netnsid unknown");
 	}
 
 	if (tb[IFLA_PROTO_DOWN]) {
 		if (rta_getattr_u8(tb[IFLA_PROTO_DOWN]))
-			print_bool(PRINT_ANY,
-				   "proto_down", " protodown on ", true);
+			fprintf(fp, " protodown on ");
 	}
 
-	if (show_details) {
-		if (tb[IFLA_PROMISCUITY])
-			print_uint(PRINT_ANY,
-				   "promiscuity",
-				   " promiscuity %u ",
-				   rta_getattr_u32(tb[IFLA_PROMISCUITY]));
+	if (tb[IFLA_PROMISCUITY] && show_details)
+		fprintf(fp, " promiscuity %u ",
+			*(int*)RTA_DATA(tb[IFLA_PROMISCUITY]));
 
-		if (tb[IFLA_MIN_MTU])
-			print_uint(PRINT_ANY,
-				   "min_mtu", "minmtu %u ",
-				   rta_getattr_u32(tb[IFLA_MIN_MTU]));
+	if (tb[IFLA_LINKINFO] && show_details)
+		print_linktype(fp, tb[IFLA_LINKINFO]);
 
-		if (tb[IFLA_MAX_MTU])
-			print_uint(PRINT_ANY,
-				   "max_mtu", "maxmtu %u ",
-				   rta_getattr_u32(tb[IFLA_MAX_MTU]));
-
-		if (tb[IFLA_LINKINFO])
-			print_linktype(fp, tb[IFLA_LINKINFO]);
-
-		if (do_link && tb[IFLA_AF_SPEC])
-			print_af_spec(fp, tb[IFLA_AF_SPEC]);
-
-		if (tb[IFLA_NUM_TX_QUEUES])
-			print_uint(PRINT_ANY,
-				   "num_tx_queues",
-				   "numtxqueues %u ",
-				   rta_getattr_u32(tb[IFLA_NUM_TX_QUEUES]));
-
-		if (tb[IFLA_NUM_RX_QUEUES])
-			print_uint(PRINT_ANY,
-				   "num_rx_queues",
-				   "numrxqueues %u ",
-				   rta_getattr_u32(tb[IFLA_NUM_RX_QUEUES]));
-
-		if (tb[IFLA_GSO_MAX_SIZE])
-			print_uint(PRINT_ANY,
-				   "gso_max_size",
-				   "gso_max_size %u ",
-				   rta_getattr_u32(tb[IFLA_GSO_MAX_SIZE]));
-
-		if (tb[IFLA_GSO_MAX_SEGS])
-			print_uint(PRINT_ANY,
-				   "gso_max_segs",
-				   "gso_max_segs %u ",
-				   rta_getattr_u32(tb[IFLA_GSO_MAX_SEGS]));
-
-		if (tb[IFLA_PHYS_PORT_NAME])
-			print_string(PRINT_ANY,
-				     "phys_port_name",
-				     "portname %s ",
-				     rta_getattr_str(tb[IFLA_PHYS_PORT_NAME]));
-
-		if (tb[IFLA_PHYS_PORT_ID]) {
-			print_string(PRINT_ANY,
-				     "phys_port_id",
-				     "portid %s ",
-				     hexstring_n2a(
-					     RTA_DATA(tb[IFLA_PHYS_PORT_ID]),
-					     RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]),
-					     b1, sizeof(b1)));
-		}
-
-		if (tb[IFLA_PHYS_SWITCH_ID]) {
-			print_string(PRINT_ANY,
-				     "phys_switch_id",
-				     "switchid %s ",
-				     hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]),
-						   RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]),
-						   b1, sizeof(b1)));
-		}
-	}
+	if (do_link && tb[IFLA_AF_SPEC] && show_details)
+		print_af_spec(fp, tb[IFLA_AF_SPEC]);
 
 	if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
-		print_string(PRINT_FP, NULL, "%s    ", _SL_);
-		print_string(PRINT_ANY,
-			     "ifalias",
-			     "alias %s",
-			     rta_getattr_str(tb[IFLA_IFALIAS]));
+		fprintf(fp, "%s    alias %s", _SL_,
+			rta_getattr_str(tb[IFLA_IFALIAS]));
 	}
 
-	if ((do_link || show_details) && tb[IFLA_XDP])
-		xdp_dump(fp, tb[IFLA_XDP], true, true);
-
 	if (do_link && show_stats) {
-		print_nl();
+		fprintf(fp, "%s", _SL_);
 		__print_link_stats(fp, tb);
 	}
 
 	if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) {
 		struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST];
 		int rem = RTA_PAYLOAD(vflist);
-
-		open_json_array(PRINT_JSON, "vfinfo_list");
-		for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-			open_json_object(NULL);
-			print_vfinfo(fp, ifi, i);
-			close_json_object();
-		}
-		close_json_array(PRINT_JSON, NULL);
+		for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem))
+			print_vfinfo(fp, i);
 	}
 
-	print_string(PRINT_FP, NULL, "%s", "\n");
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 1;
 }
@@ -1178,126 +935,20 @@
 				  struct rtattr *ifa_flags_attr)
 {
 	return ifa_flags_attr ? rta_getattr_u32(ifa_flags_attr) :
-		ifa->ifa_flags;
+				ifa->ifa_flags;
 }
 
-/* Mapping from argument to address flag mask */
-static const struct {
-	const char *name;
-	unsigned long value;
-} ifa_flag_names[] = {
-	{ "secondary",		IFA_F_SECONDARY },
-	{ "temporary",		IFA_F_SECONDARY },
-	{ "nodad",		IFA_F_NODAD },
-	{ "optimistic",		IFA_F_OPTIMISTIC },
-	{ "dadfailed",		IFA_F_DADFAILED },
-	{ "home",		IFA_F_HOMEADDRESS },
-	{ "deprecated",		IFA_F_DEPRECATED },
-	{ "tentative",		IFA_F_TENTATIVE },
-	{ "permanent",		IFA_F_PERMANENT },
-	{ "mngtmpaddr",		IFA_F_MANAGETEMPADDR },
-	{ "noprefixroute",	IFA_F_NOPREFIXROUTE },
-	{ "autojoin",		IFA_F_MCAUTOJOIN },
-	{ "stable-privacy",	IFA_F_STABLE_PRIVACY },
-};
-
-static void print_ifa_flags(FILE *fp, const struct ifaddrmsg *ifa,
-			    unsigned int flags)
-{
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
-		unsigned long mask = ifa_flag_names[i].value;
-
-		if (mask == IFA_F_PERMANENT) {
-			if (!(flags & mask))
-				print_bool(PRINT_ANY,
-					   "dynamic", "dynamic ", true);
-		} else if (flags & mask) {
-			if (mask == IFA_F_SECONDARY &&
-			    ifa->ifa_family == AF_INET6) {
-				print_bool(PRINT_ANY,
-					   "temporary", "temporary ", true);
-			} else {
-				print_string(PRINT_FP, NULL,
-					     "%s ", ifa_flag_names[i].name);
-				print_bool(PRINT_JSON,
-					   ifa_flag_names[i].name, NULL, true);
-			}
-		}
-
-		flags &= ~mask;
-	}
-
-	if (flags) {
-		if (is_json_context()) {
-			SPRINT_BUF(b1);
-
-			snprintf(b1, sizeof(b1), "%02x", flags);
-			print_string(PRINT_JSON, "ifa_flags", NULL, b1);
-		} else {
-			fprintf(fp, "flags %02x ", flags);
-		}
-	}
-
-}
-
-static int get_filter(const char *arg)
-{
-	bool inv = false;
-	unsigned int i;
-
-	if (arg[0] == '-') {
-		inv = true;
-		arg++;
-	}
-
-	/* Special cases */
-	if (strcmp(arg, "dynamic") == 0) {
-		inv = !inv;
-		arg = "permanent";
-	} else if (strcmp(arg, "primary") == 0) {
-		inv = !inv;
-		arg = "secondary";
-	}
-
-	for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
-		if (strcmp(arg, ifa_flag_names[i].name))
-			continue;
-
-		if (inv)
-			filter.flags &= ~ifa_flag_names[i].value;
-		else
-			filter.flags |= ifa_flag_names[i].value;
-		filter.flagmask |= ifa_flag_names[i].value;
-		return 0;
-	}
-	return -1;
-}
-
-static int ifa_label_match_rta(int ifindex, const struct rtattr *rta)
-{
-	const char *label;
-
-	if (!filter.label)
-		return 0;
-
-	if (rta)
-		label = RTA_DATA(rta);
-	else
-		label = ll_index_to_name(ifindex);
-
-	return fnmatch(filter.label, label, 0);
-}
-
-int print_addrinfo(struct nlmsghdr *n, void *arg)
+int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		   void *arg)
 {
 	FILE *fp = arg;
 	struct ifaddrmsg *ifa = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
+	int deprecated = 0;
+	/* Use local copy of ifa_flags to not interfere with filtering code */
 	unsigned int ifa_flags;
-	struct rtattr *rta_tb[IFA_MAX+1];
-
+	struct rtattr * rta_tb[IFA_MAX+1];
+	char abuf[256];
 	SPRINT_BUF(b1);
 
 	if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
@@ -1327,175 +978,209 @@
 		return 0;
 	if ((filter.flags ^ ifa_flags) & filter.flagmask)
 		return 0;
+	if (filter.label) {
+		SPRINT_BUF(b1);
+		const char *label;
+		if (rta_tb[IFA_LABEL])
+			label = RTA_DATA(rta_tb[IFA_LABEL]);
+		else
+			label = ll_idx_n2a(ifa->ifa_index, b1);
+		if (fnmatch(filter.label, label, 0) != 0)
+			return 0;
+	}
+	if (filter.pfx.family) {
+		if (rta_tb[IFA_LOCAL]) {
+			inet_prefix dst;
+			memset(&dst, 0, sizeof(dst));
+			dst.family = ifa->ifa_family;
+			memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
+			if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
+				return 0;
+		}
+	}
 
 	if (filter.family && filter.family != ifa->ifa_family)
 		return 0;
 
-	if (ifa_label_match_rta(ifa->ifa_index, rta_tb[IFA_LABEL]))
-		return 0;
-
-	if (inet_addr_match_rta(&filter.pfx, rta_tb[IFA_LOCAL]))
-		return 0;
-
 	if (filter.flushb) {
 		struct nlmsghdr *fn;
-
 		if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
 			if (flush_update())
 				return -1;
 		}
-		fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
+		fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp));
 		memcpy(fn, n, n->nlmsg_len);
 		fn->nlmsg_type = RTM_DELADDR;
 		fn->nlmsg_flags = NLM_F_REQUEST;
 		fn->nlmsg_seq = ++rth.seq;
-		filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
+		filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
 		filter.flushed++;
 		if (show_stats < 2)
 			return 0;
 	}
 
 	if (n->nlmsg_type == RTM_DELADDR)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
 	if (!brief) {
-		const char *name;
-
-		if (filter.oneline || filter.flushb) {
-			const char *dev = ll_index_to_name(ifa->ifa_index);
-
-			if (is_json_context()) {
-				print_int(PRINT_JSON,
-					  "index", NULL, ifa->ifa_index);
-				print_string(PRINT_JSON, "dev", NULL, dev);
-			} else {
-				fprintf(fp, "%u: %s", ifa->ifa_index, dev);
-			}
-		}
-
-		name = family_name(ifa->ifa_family);
-		if (*name != '?') {
-			print_string(PRINT_ANY, "family", "    %s ", name);
-		} else {
-			print_int(PRINT_ANY, "family_index", "    family %d ",
-				  ifa->ifa_family);
-		}
+		if (filter.oneline || filter.flushb)
+			fprintf(fp, "%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index));
+		if (ifa->ifa_family == AF_INET)
+			fprintf(fp, "    inet ");
+		else if (ifa->ifa_family == AF_INET6)
+			fprintf(fp, "    inet6 ");
+		else if (ifa->ifa_family == AF_DECnet)
+			fprintf(fp, "    dnet ");
+		else if (ifa->ifa_family == AF_IPX)
+			fprintf(fp, "     ipx ");
+		else
+			fprintf(fp, "    family %d ", ifa->ifa_family);
 	}
 
 	if (rta_tb[IFA_LOCAL]) {
-		print_color_string(PRINT_ANY,
-				   ifa_family_color(ifa->ifa_family),
-				   "local", "%s",
-				   format_host_rta(ifa->ifa_family,
-						   rta_tb[IFA_LOCAL]));
-		if (rta_tb[IFA_ADDRESS] &&
-		    memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
-			   RTA_DATA(rta_tb[IFA_LOCAL]),
-			   ifa->ifa_family == AF_INET ? 4 : 16)) {
-			print_string(PRINT_FP, NULL, " %s ", "peer");
-			print_color_string(PRINT_ANY,
-					   ifa_family_color(ifa->ifa_family),
-					   "address",
-					   "%s",
-					   format_host_rta(ifa->ifa_family,
-							   rta_tb[IFA_ADDRESS]));
-		}
-		print_int(PRINT_ANY, "prefixlen", "/%d ", ifa->ifa_prefixlen);
+		if (ifa->ifa_family == AF_INET)
+			color_fprintf(fp, COLOR_INET, "%s", format_host(ifa->ifa_family,
+						RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
+						RTA_DATA(rta_tb[IFA_LOCAL]),
+						abuf, sizeof(abuf)));
+		else if (ifa->ifa_family == AF_INET6)
+			color_fprintf(fp, COLOR_INET6, "%s", format_host(ifa->ifa_family,
+						RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
+						RTA_DATA(rta_tb[IFA_LOCAL]),
+						abuf, sizeof(abuf)));
+		else
+			fprintf(fp, "%s", format_host(ifa->ifa_family,
+						RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
+						RTA_DATA(rta_tb[IFA_LOCAL]),
+						abuf, sizeof(abuf)));
 
-		if (rta_tb[IFA_RT_PRIORITY])
-			print_uint(PRINT_ANY, "metric", "metric %u ",
-				   rta_getattr_u32(rta_tb[IFA_RT_PRIORITY]));
+		if (rta_tb[IFA_ADDRESS] == NULL ||
+		    memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]),
+			   ifa->ifa_family == AF_INET ? 4 : 16) == 0) {
+			fprintf(fp, "/%d ", ifa->ifa_prefixlen);
+		} else {
+			fprintf(fp, " peer %s/%d ",
+				format_host(ifa->ifa_family,
+					    RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
+					    RTA_DATA(rta_tb[IFA_ADDRESS]),
+					    abuf, sizeof(abuf)),
+				ifa->ifa_prefixlen);
+		}
 	}
 
 	if (brief)
 		goto brief_exit;
 
 	if (rta_tb[IFA_BROADCAST]) {
-		print_string(PRINT_FP, NULL, "%s ", "brd");
-		print_color_string(PRINT_ANY,
-				   ifa_family_color(ifa->ifa_family),
-				   "broadcast",
-				   "%s ",
-				   format_host_rta(ifa->ifa_family,
-						   rta_tb[IFA_BROADCAST]));
+		fprintf(fp, "brd %s ",
+			format_host(ifa->ifa_family,
+				    RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
+				    RTA_DATA(rta_tb[IFA_BROADCAST]),
+				    abuf, sizeof(abuf)));
 	}
-
 	if (rta_tb[IFA_ANYCAST]) {
-		print_string(PRINT_FP, NULL, "%s ", "any");
-		print_color_string(PRINT_ANY,
-				   ifa_family_color(ifa->ifa_family),
-				   "anycast",
-				   "%s ",
-				   format_host_rta(ifa->ifa_family,
-						   rta_tb[IFA_ANYCAST]));
+		fprintf(fp, "any %s ",
+			format_host(ifa->ifa_family,
+				    RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
+				    RTA_DATA(rta_tb[IFA_ANYCAST]),
+				    abuf, sizeof(abuf)));
 	}
-
-	print_string(PRINT_ANY,
-		     "scope",
-		     "scope %s ",
-		     rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
-
-	print_ifa_flags(fp, ifa, ifa_flags);
-
+	fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
+	if (ifa_flags & IFA_F_SECONDARY) {
+		ifa_flags &= ~IFA_F_SECONDARY;
+		if (ifa->ifa_family == AF_INET6)
+			fprintf(fp, "temporary ");
+		else
+			fprintf(fp, "secondary ");
+	}
+	if (ifa_flags & IFA_F_TENTATIVE) {
+		ifa_flags &= ~IFA_F_TENTATIVE;
+		fprintf(fp, "tentative ");
+	}
+	if (ifa_flags & IFA_F_DEPRECATED) {
+		ifa_flags &= ~IFA_F_DEPRECATED;
+		deprecated = 1;
+		fprintf(fp, "deprecated ");
+	}
+	if (ifa_flags & IFA_F_HOMEADDRESS) {
+		ifa_flags &= ~IFA_F_HOMEADDRESS;
+		fprintf(fp, "home ");
+	}
+	if (ifa_flags & IFA_F_NODAD) {
+		ifa_flags &= ~IFA_F_NODAD;
+		fprintf(fp, "nodad ");
+	}
+	if (ifa_flags & IFA_F_MANAGETEMPADDR) {
+		ifa_flags &= ~IFA_F_MANAGETEMPADDR;
+		fprintf(fp, "mngtmpaddr ");
+	}
+	if (ifa_flags & IFA_F_NOPREFIXROUTE) {
+		ifa_flags &= ~IFA_F_NOPREFIXROUTE;
+		fprintf(fp, "noprefixroute ");
+	}
+	if (ifa_flags & IFA_F_MCAUTOJOIN) {
+		ifa_flags &= ~IFA_F_MCAUTOJOIN;
+		fprintf(fp, "autojoin ");
+	}
+	if (!(ifa_flags & IFA_F_PERMANENT)) {
+		fprintf(fp, "dynamic ");
+	} else
+		ifa_flags &= ~IFA_F_PERMANENT;
+	if (ifa_flags & IFA_F_DADFAILED) {
+		ifa_flags &= ~IFA_F_DADFAILED;
+		fprintf(fp, "dadfailed ");
+	}
+	if (ifa_flags)
+		fprintf(fp, "flags %02x ", ifa_flags);
 	if (rta_tb[IFA_LABEL])
-		print_string(PRINT_ANY,
-			     "label",
-			     "%s",
-			     rta_getattr_str(rta_tb[IFA_LABEL]));
-
+		fprintf(fp, "%s", rta_getattr_str(rta_tb[IFA_LABEL]));
 	if (rta_tb[IFA_CACHEINFO]) {
 		struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
-
-		print_nl();
-		print_string(PRINT_FP, NULL, "       valid_lft ", NULL);
-
-		if (ci->ifa_valid == INFINITY_LIFE_TIME) {
-			print_uint(PRINT_JSON,
-				   "valid_life_time",
-				   NULL, INFINITY_LIFE_TIME);
-			print_string(PRINT_FP, NULL, "%s", "forever");
-		} else {
-			print_uint(PRINT_ANY,
-				   "valid_life_time", "%usec", ci->ifa_valid);
-		}
-
-		print_string(PRINT_FP, NULL, " preferred_lft ", NULL);
-		if (ci->ifa_prefered == INFINITY_LIFE_TIME) {
-			print_uint(PRINT_JSON,
-				   "preferred_life_time",
-				   NULL, INFINITY_LIFE_TIME);
-			print_string(PRINT_FP, NULL, "%s", "forever");
-		} else {
-			if (ifa_flags & IFA_F_DEPRECATED)
-				print_int(PRINT_ANY,
-					  "preferred_life_time",
-					  "%dsec",
-					  ci->ifa_prefered);
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "       valid_lft ");
+		if (ci->ifa_valid == INFINITY_LIFE_TIME)
+			fprintf(fp, "forever");
+		else
+			fprintf(fp, "%usec", ci->ifa_valid);
+		fprintf(fp, " preferred_lft ");
+		if (ci->ifa_prefered == INFINITY_LIFE_TIME)
+			fprintf(fp, "forever");
+		else {
+			if (deprecated)
+				fprintf(fp, "%dsec", ci->ifa_prefered);
 			else
-				print_uint(PRINT_ANY,
-					   "preferred_life_time",
-					   "%usec",
-					   ci->ifa_prefered);
+				fprintf(fp, "%usec", ci->ifa_prefered);
 		}
 	}
-	print_string(PRINT_FP, NULL, "%s", "\n");
+	fprintf(fp, "\n");
 brief_exit:
 	fflush(fp);
 	return 0;
 }
 
+struct nlmsg_list
+{
+	struct nlmsg_list *next;
+	struct nlmsghdr	  h;
+};
+
+struct nlmsg_chain
+{
+	struct nlmsg_list *head;
+	struct nlmsg_list *tail;
+};
+
 static int print_selected_addrinfo(struct ifinfomsg *ifi,
 				   struct nlmsg_list *ainfo, FILE *fp)
 {
-	open_json_array(PRINT_JSON, "addr_info");
-	for ( ; ainfo ;  ainfo = ainfo->next) {
+	for ( ;ainfo ;  ainfo = ainfo->next) {
 		struct nlmsghdr *n = &ainfo->h;
 		struct ifaddrmsg *ifa = NLMSG_DATA(n);
 
 		if (n->nlmsg_type != RTM_NEWADDR)
 			continue;
 
-		if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifa)))
+		if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa)))
 			return -1;
 
 		if (ifa->ifa_index != ifi->ifi_index ||
@@ -1505,26 +1190,23 @@
 		if (filter.up && !(ifi->ifi_flags&IFF_UP))
 			continue;
 
-		open_json_object(NULL);
-		print_addrinfo(n, fp);
-		close_json_object();
+		print_addrinfo(NULL, n, fp);
 	}
-	close_json_array(PRINT_JSON, NULL);
-
 	if (brief) {
-		print_string(PRINT_FP, NULL, "%s", "\n");
+		fprintf(fp, "\n");
 		fflush(fp);
 	}
 	return 0;
 }
 
 
-static int store_nlmsg(struct nlmsghdr *n, void *arg)
+static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		       void *arg)
 {
 	struct nlmsg_chain *lchain = (struct nlmsg_chain *)arg;
 	struct nlmsg_list *h;
 
-	h = malloc(n->nlmsg_len+sizeof(void *));
+	h = malloc(n->nlmsg_len+sizeof(void*));
 	if (h == NULL)
 		return -1;
 
@@ -1537,7 +1219,7 @@
 		lchain->head = h;
 	lchain->tail = h;
 
-	ll_remember_index(n, NULL);
+	ll_remember_index(who, n, NULL);
 	return 0;
 }
 
@@ -1580,7 +1262,8 @@
 	return 0;
 }
 
-static int save_nlmsg(struct nlmsghdr *n, void *arg)
+static int save_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		       void *arg)
 {
 	int ret;
 
@@ -1593,39 +1276,27 @@
 	return ret == n->nlmsg_len ? 0 : ret;
 }
 
-static int show_handler(struct rtnl_ctrl_data *ctrl,
+static int show_handler(const struct sockaddr_nl *nl,
+			struct rtnl_ctrl_data *ctrl,
 			struct nlmsghdr *n, void *arg)
 {
 	struct ifaddrmsg *ifa = NLMSG_DATA(n);
 
-	open_json_object(NULL);
-	print_int(PRINT_ANY, "index", "if%d:\n", ifa->ifa_index);
-	print_addrinfo(n, stdout);
-	close_json_object();
+	printf("if%d:\n", ifa->ifa_index);
+	print_addrinfo(NULL, n, stdout);
 	return 0;
 }
 
 static int ipaddr_showdump(void)
 {
-	int err;
-
 	if (ipadd_dump_check_magic())
 		exit(-1);
 
-	new_json_obj(json);
-	open_json_object(NULL);
-	open_json_array(PRINT_JSON, "addr_info");
-
-	err = rtnl_from_file(stdin, &show_handler, NULL);
-
-	close_json_array(PRINT_JSON, NULL);
-	close_json_object();
-	delete_json_obj();
-
-	exit(err);
+	exit(rtnl_from_file(stdin, &show_handler, NULL));
 }
 
-static int restore_handler(struct rtnl_ctrl_data *ctrl,
+static int restore_handler(const struct sockaddr_nl *nl,
+			   struct rtnl_ctrl_data *ctrl,
 			   struct nlmsghdr *n, void *arg)
 {
 	int ret;
@@ -1634,7 +1305,7 @@
 
 	ll_init_map(&rth);
 
-	ret = rtnl_talk(&rth, n, NULL);
+	ret = rtnl_talk(&rth, n, n, sizeof(*n));
 	if ((ret < 0) && (errno == EEXIST))
 		ret = 0;
 
@@ -1649,7 +1320,7 @@
 	exit(rtnl_from_file(stdin, &restore_handler, NULL));
 }
 
-void free_nlmsg_chain(struct nlmsg_chain *info)
+static void free_nlmsg_chain(struct nlmsg_chain *info)
 {
 	struct nlmsg_list *l, *n;
 
@@ -1664,7 +1335,7 @@
 	struct nlmsg_list *l, **lp;
 
 	lp = &linfo->head;
-	while ((l = *lp) != NULL) {
+	while ( (l = *lp) != NULL) {
 		int ok = 0;
 		int missing_net_address = 1;
 		struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
@@ -1689,14 +1360,29 @@
 
 			if ((filter.flags ^ ifa_flags) & filter.flagmask)
 				continue;
+			if (filter.pfx.family || filter.label) {
+				if (!tb[IFA_LOCAL])
+					tb[IFA_LOCAL] = tb[IFA_ADDRESS];
 
-			if (ifa_label_match_rta(ifa->ifa_index, tb[IFA_LABEL]))
-				continue;
-
-			if (!tb[IFA_LOCAL])
-				tb[IFA_LOCAL] = tb[IFA_ADDRESS];
-			if (inet_addr_match_rta(&filter.pfx, tb[IFA_LOCAL]))
-				continue;
+				if (filter.pfx.family && tb[IFA_LOCAL]) {
+					inet_prefix dst;
+					memset(&dst, 0, sizeof(dst));
+					dst.family = ifa->ifa_family;
+					memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL]));
+					if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
+						continue;
+				}
+				if (filter.label) {
+					SPRINT_BUF(b1);
+					const char *label;
+					if (tb[IFA_LABEL])
+						label = RTA_DATA(tb[IFA_LABEL]);
+					else
+						label = ll_idx_n2a(ifa->ifa_index, b1);
+					if (fnmatch(filter.label, label, 0) != 0)
+						continue;
+				}
+			}
 
 			ok = 1;
 			break;
@@ -1712,15 +1398,6 @@
 	}
 }
 
-static int ipaddr_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	struct ifaddrmsg *ifa = NLMSG_DATA(nlh);
-
-	ifa->ifa_index = filter.ifindex;
-
-	return 0;
-}
-
 static int ipaddr_flush(void)
 {
 	int round = 0;
@@ -1731,8 +1408,7 @@
 	filter.flushe = sizeof(flushb);
 
 	while ((max_flush_loops == 0) || (round < max_flush_loops)) {
-		if (rtnl_addrdump_req(&rth, filter.family,
-				      ipaddr_dump_filter) < 0) {
+		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
 			perror("Cannot send dump request");
 			exit(1);
 		}
@@ -1748,7 +1424,7 @@
 				if (round == 0)
 					printf("Nothing to flush.\n");
 				else
-					printf("*** Flush is complete after %d round%s ***\n", round, round > 1?"s":"");
+					printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
 			}
 			fflush(stdout);
 			return 0;
@@ -1775,105 +1451,10 @@
 	return 1;
 }
 
-static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
-{
-	int err;
-
-	err = addattr32(nlh, reqlen, IFLA_EXT_MASK, RTEXT_FILTER_VF);
-	if (err)
-		return err;
-
-	if (filter.master) {
-		err = addattr32(nlh, reqlen, IFLA_MASTER, filter.master);
-		if (err)
-			return err;
-	}
-
-	if (filter.kind) {
-		struct rtattr *linkinfo;
-
-		linkinfo = addattr_nest(nlh, reqlen, IFLA_LINKINFO);
-
-		err = addattr_l(nlh, reqlen, IFLA_INFO_KIND, filter.kind,
-				strlen(filter.kind));
-		if (err)
-			return err;
-
-		addattr_nest_end(nlh, linkinfo);
-	}
-
-	return 0;
-}
-
-static int ipaddr_link_get(int index, struct nlmsg_chain *linfo)
-{
-	struct iplink_req req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = filter.family,
-		.i.ifi_index = index,
-	};
-	__u32 filt_mask = RTEXT_FILTER_VF;
-	struct nlmsghdr *answer;
-
-	if (!show_stats)
-		filt_mask |= RTEXT_FILTER_SKIP_STATS;
-
-	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
-
-	if (rtnl_talk(&rth, &req.n, &answer) < 0) {
-		perror("Cannot send link request");
-		return 1;
-	}
-
-	if (store_nlmsg(answer, linfo) < 0) {
-		fprintf(stderr, "Failed to process link information\n");
-		return 1;
-	}
-
-	return 0;
-}
-
-/* fills in linfo with link data and optionally ainfo with address info
- * caller can walk lists as desired and must call free_nlmsg_chain for
- * both when done
- */
-int ip_link_list(req_filter_fn_t filter_fn, struct nlmsg_chain *linfo)
-{
-	if (rtnl_linkdump_req_filter_fn(&rth, preferred_family,
-					filter_fn) < 0) {
-		perror("Cannot send dump request");
-		return 1;
-	}
-
-	if (rtnl_dump_filter(&rth, store_nlmsg, linfo) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return 1;
-	}
-
-	return 0;
-}
-
-static int ip_addr_list(struct nlmsg_chain *ainfo)
-{
-	if (rtnl_addrdump_req(&rth, filter.family, ipaddr_dump_filter) < 0) {
-		perror("Cannot send dump request");
-		return 1;
-	}
-
-	if (rtnl_dump_filter(&rth, store_nlmsg, ainfo) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return 1;
-	}
-
-	return 0;
-}
-
 static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
 {
 	struct nlmsg_chain linfo = { NULL, NULL};
-	struct nlmsg_chain _ainfo = { NULL, NULL}, *ainfo = &_ainfo;
+	struct nlmsg_chain ainfo = { NULL, NULL};
 	struct nlmsg_list *l;
 	char *filter_dev = NULL;
 	int no_link = 0;
@@ -1881,6 +1462,7 @@
 	ipaddr_reset_filter(oneline, 0);
 	filter.showqueue = 1;
 	filter.family = preferred_family;
+	filter.group = -1;
 
 	if (action == IPADD_FLUSH) {
 		if (argc <= 0) {
@@ -1897,13 +1479,11 @@
 	while (argc > 0) {
 		if (strcmp(*argv, "to") == 0) {
 			NEXT_ARG();
-			if (get_prefix(&filter.pfx, *argv, filter.family))
-				invarg("invalid \"to\"\n", *argv);
+			get_prefix(&filter.pfx, *argv, filter.family);
 			if (filter.family == AF_UNSPEC)
 				filter.family = filter.pfx.family;
 		} else if (strcmp(*argv, "scope") == 0) {
-			unsigned int scope = 0;
-
+			unsigned scope = 0;
 			NEXT_ARG();
 			filter.scopemask = -1;
 			if (rtnl_rtscope_a2n(&scope, *argv)) {
@@ -1915,8 +1495,52 @@
 			filter.scope = scope;
 		} else if (strcmp(*argv, "up") == 0) {
 			filter.up = 1;
-		} else if (get_filter(*argv) == 0) {
-
+		} else if (strcmp(*argv, "dynamic") == 0) {
+			filter.flags &= ~IFA_F_PERMANENT;
+			filter.flagmask |= IFA_F_PERMANENT;
+		} else if (strcmp(*argv, "permanent") == 0) {
+			filter.flags |= IFA_F_PERMANENT;
+			filter.flagmask |= IFA_F_PERMANENT;
+		} else if (strcmp(*argv, "secondary") == 0 ||
+			   strcmp(*argv, "temporary") == 0) {
+			filter.flags |= IFA_F_SECONDARY;
+			filter.flagmask |= IFA_F_SECONDARY;
+		} else if (strcmp(*argv, "primary") == 0) {
+			filter.flags &= ~IFA_F_SECONDARY;
+			filter.flagmask |= IFA_F_SECONDARY;
+		} else if (strcmp(*argv, "tentative") == 0) {
+			filter.flags |= IFA_F_TENTATIVE;
+			filter.flagmask |= IFA_F_TENTATIVE;
+		} else if (strcmp(*argv, "-tentative") == 0) {
+			filter.flags &= ~IFA_F_TENTATIVE;
+			filter.flagmask |= IFA_F_TENTATIVE;
+		} else if (strcmp(*argv, "deprecated") == 0) {
+			filter.flags |= IFA_F_DEPRECATED;
+			filter.flagmask |= IFA_F_DEPRECATED;
+		} else if (strcmp(*argv, "-deprecated") == 0) {
+			filter.flags &= ~IFA_F_DEPRECATED;
+			filter.flagmask |= IFA_F_DEPRECATED;
+		} else if (strcmp(*argv, "home") == 0) {
+			filter.flags |= IFA_F_HOMEADDRESS;
+			filter.flagmask |= IFA_F_HOMEADDRESS;
+		} else if (strcmp(*argv, "nodad") == 0) {
+			filter.flags |= IFA_F_NODAD;
+			filter.flagmask |= IFA_F_NODAD;
+		} else if (strcmp(*argv, "mngtmpaddr") == 0) {
+			filter.flags |= IFA_F_MANAGETEMPADDR;
+			filter.flagmask |= IFA_F_MANAGETEMPADDR;
+		} else if (strcmp(*argv, "noprefixroute") == 0) {
+			filter.flags |= IFA_F_NOPREFIXROUTE;
+			filter.flagmask |= IFA_F_NOPREFIXROUTE;
+		} else if (strcmp(*argv, "autojoin") == 0) {
+			filter.flags |= IFA_F_MCAUTOJOIN;
+			filter.flagmask |= IFA_F_MCAUTOJOIN;
+		} else if (strcmp(*argv, "dadfailed") == 0) {
+			filter.flags |= IFA_F_DADFAILED;
+			filter.flagmask |= IFA_F_DADFAILED;
+		} else if (strcmp(*argv, "-dadfailed") == 0) {
+			filter.flags &= ~IFA_F_DADFAILED;
+			filter.flagmask |= IFA_F_DADFAILED;
 		} else if (strcmp(*argv, "label") == 0) {
 			NEXT_ARG();
 			filter.label = *argv;
@@ -1926,36 +1550,18 @@
 				invarg("Invalid \"group\" value\n", *argv);
 		} else if (strcmp(*argv, "master") == 0) {
 			int ifindex;
-
 			NEXT_ARG();
 			ifindex = ll_name_to_index(*argv);
 			if (!ifindex)
 				invarg("Device does not exist\n", *argv);
 			filter.master = ifindex;
-		} else if (strcmp(*argv, "vrf") == 0) {
-			int ifindex;
-
+		} else if (do_link && strcmp(*argv, "type") == 0) {
 			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
-			if (!ifindex)
-				invarg("Not a valid VRF name\n", *argv);
-			if (!name_is_vrf(*argv))
-				invarg("Not a valid VRF name\n", *argv);
-			filter.master = ifindex;
-		} else if (strcmp(*argv, "type") == 0) {
-			int soff;
-
-			NEXT_ARG();
-			soff = strlen(*argv) - strlen("_slave");
-			if (!strcmp(*argv + soff, "_slave")) {
-				(*argv)[soff] = '\0';
-				filter.slave_kind = *argv;
-			} else {
-				filter.kind = *argv;
-			}
+			filter.kind = *argv;
 		} else {
-			if (strcmp(*argv, "dev") == 0)
+			if (strcmp(*argv, "dev") == 0) {
 				NEXT_ARG();
+			}
 			else if (matches(*argv, "help") == 0)
 				usage();
 			if (filter_dev)
@@ -1980,8 +1586,7 @@
 		if (ipadd_save_prep())
 			exit(1);
 
-		if (rtnl_addrdump_req(&rth, preferred_family,
-				      ipaddr_dump_filter) < 0) {
+		if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETADDR) < 0) {
 			perror("Cannot send dump request");
 			exit(1);
 		}
@@ -1995,64 +1600,69 @@
 	}
 
 	/*
-	 * Initialize a json_writer and open an array object
-	 * if -json was specified.
-	 */
-	new_json_obj(json);
-
-	/*
 	 * If only filter_dev present and none of the other
 	 * link filters are present, use RTM_GETLINK to get
 	 * the link device
 	 */
 	if (filter_dev && filter.group == -1 && do_link == 1) {
-		if (iplink_get(filter_dev, RTEXT_FILTER_VF) < 0) {
+		if (iplink_get(0, filter_dev, RTEXT_FILTER_VF) < 0) {
 			perror("Cannot send link get request");
-			delete_json_obj();
 			exit(1);
 		}
-		delete_json_obj();
-		goto out;
+		exit(0);
 	}
 
-	if (filter.ifindex) {
-		if (ipaddr_link_get(filter.ifindex, &linfo) != 0)
-			goto out;
-	} else {
-		if (ip_link_list(iplink_filter_req, &linfo) != 0)
-			goto out;
+	if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) {
+		perror("Cannot send dump request");
+		exit(1);
+	}
+
+	if (rtnl_dump_filter(&rth, store_nlmsg, &linfo) < 0) {
+		fprintf(stderr, "Dump terminated\n");
+		exit(1);
 	}
 
 	if (filter.family != AF_PACKET) {
 		if (filter.oneline)
 			no_link = 1;
 
-		if (ip_addr_list(ainfo) != 0)
-			goto out;
+		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
+			perror("Cannot send dump request");
+			exit(1);
+		}
 
-		ipaddr_filter(&linfo, ainfo);
+		if (rtnl_dump_filter(&rth, store_nlmsg, &ainfo) < 0) {
+			fprintf(stderr, "Dump terminated\n");
+			exit(1);
+		}
+
+		ipaddr_filter(&linfo, &ainfo);
 	}
 
 	for (l = linfo.head; l; l = l->next) {
-		struct nlmsghdr *n = &l->h;
-		struct ifinfomsg *ifi = NLMSG_DATA(n);
 		int res = 0;
+		struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
 
-		open_json_object(NULL);
-		if (brief || !no_link)
-			res = print_linkinfo(n, stdout);
-		if (res >= 0 && filter.family != AF_PACKET)
-			print_selected_addrinfo(ifi, ainfo->head, stdout);
-		if (res > 0 && !do_link && show_stats)
-			print_link_stats(stdout, n);
-		close_json_object();
+		if (brief) {
+			if (print_linkinfo_brief(NULL, &l->h, stdout) == 0)
+				if (filter.family != AF_PACKET)
+					print_selected_addrinfo(ifi,
+								ainfo.head,
+								stdout);
+		} else if (no_link ||
+			 (res = print_linkinfo(NULL, &l->h, stdout)) >= 0) {
+			if (filter.family != AF_PACKET)
+				print_selected_addrinfo(ifi,
+							ainfo.head, stdout);
+			if (res > 0 && !do_link && show_stats)
+				print_link_stats(stdout, &l->h);
+		}
 	}
 	fflush(stdout);
 
-out:
-	free_nlmsg_chain(ainfo);
+	free_nlmsg_chain(&ainfo);
 	free_nlmsg_chain(&linfo);
-	delete_json_obj();
+
 	return 0;
 }
 
@@ -2068,12 +1678,6 @@
 
 	for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 		parse_rtattr_nested(vf, IFLA_VF_MAX, i);
-
-		if (!vf[IFLA_VF_RATE]) {
-			fprintf(stderr, "VF min/max rate API not supported\n");
-			exit(1);
-		}
-
 		vf_rate = RTA_DATA(vf[IFLA_VF_RATE]);
 		if (vf_rate->vf == vfnum) {
 			*min = vf_rate->min_tx_rate;
@@ -2085,22 +1689,16 @@
 	exit(1);
 }
 
-void ipaddr_get_vf_rate(int vfnum, int *min, int *max, const char *dev)
+void ipaddr_get_vf_rate(int vfnum, int *min, int *max, int idx)
 {
 	struct nlmsg_chain linfo = { NULL, NULL};
 	struct rtattr *tb[IFLA_MAX+1];
 	struct ifinfomsg *ifi;
 	struct nlmsg_list *l;
 	struct nlmsghdr *n;
-	int idx, len;
+	int len;
 
-	idx = ll_name_to_index(dev);
-	if (idx == 0) {
-		fprintf(stderr, "Device %s does not exist\n", dev);
-		exit(1);
-	}
-
-	if (rtnl_linkdump_req(&rth, AF_UNSPEC) < 0) {
+	if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETLINK) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
@@ -2137,13 +1735,12 @@
 	memset(&filter, 0, sizeof(filter));
 	filter.oneline = oneline;
 	filter.ifindex = ifindex;
-	filter.group = -1;
 }
 
 static int default_scope(inet_prefix *lcl)
 {
 	if (lcl->family == AF_INET) {
-		if (lcl->bytelen >= 1 && *(__u8 *)&lcl->data == 127)
+		if (lcl->bytelen >= 1 && *(__u8*)&lcl->data == 127)
 			return RT_SCOPE_HOST;
 	}
 	return 0;
@@ -2159,34 +1756,19 @@
 		return false;
 }
 
-static bool is_valid_label(const char *dev, const char *label)
-{
-	size_t len = strlen(dev);
-
-	if (strncmp(label, dev, len) != 0)
-		return false;
-
-	return label[len] == '\0' || label[len] == ':';
-}
-
 static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
 		struct nlmsghdr	n;
 		struct ifaddrmsg	ifa;
 		char			buf[256];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.ifa.ifa_family = preferred_family,
-	};
+	} req;
 	char  *d = NULL;
 	char  *l = NULL;
 	char  *lcl_arg = NULL;
 	char  *valid_lftp = NULL;
 	char  *preferred_lftp = NULL;
-	inet_prefix lcl = {};
+	inet_prefix lcl;
 	inet_prefix peer;
 	int local_len = 0;
 	int peer_len = 0;
@@ -2195,8 +1777,16 @@
 	int scoped = 0;
 	__u32 preferred_lft = INFINITY_LIFE_TIME;
 	__u32 valid_lft = INFINITY_LIFE_TIME;
+	struct ifa_cacheinfo cinfo;
 	unsigned int ifa_flags = 0;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST | flags;
+	req.n.nlmsg_type = cmd;
+	req.ifa.ifa_family = preferred_family;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "peer") == 0 ||
 		    strcmp(*argv, "remote") == 0) {
@@ -2213,7 +1803,6 @@
 		} else if (matches(*argv, "broadcast") == 0 ||
 			   strcmp(*argv, "brd") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (brd_len)
 				duparg("broadcast", *argv);
@@ -2230,7 +1819,6 @@
 			}
 		} else if (strcmp(*argv, "anycast") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (any_len)
 				duparg("anycast", *argv);
@@ -2240,8 +1828,7 @@
 			addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
 			any_len = addr.bytelen;
 		} else if (strcmp(*argv, "scope") == 0) {
-			unsigned int scope = 0;
-
+			unsigned scope = 0;
 			NEXT_ARG();
 			if (rtnl_rtscope_a2n(&scope, *argv))
 				invarg("invalid scope value.", *argv);
@@ -2254,15 +1841,6 @@
 			NEXT_ARG();
 			l = *argv;
 			addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
-		} else if (matches(*argv, "metric") == 0 ||
-			   matches(*argv, "priority") == 0 ||
-			   matches(*argv, "preference") == 0) {
-			__u32 metric;
-
-			NEXT_ARG();
-			if (get_u32(&metric, *argv, 0))
-				invarg("\"metric\" value is invalid\n", *argv);
-			addattr32(&req.n, sizeof(req), IFA_RT_PRIORITY, metric);
 		} else if (matches(*argv, "valid_lft") == 0) {
 			if (valid_lftp)
 				duparg("valid_lft", *argv);
@@ -2278,32 +1856,19 @@
 			if (set_lifetime(&preferred_lft, *argv))
 				invarg("preferred_lft value", *argv);
 		} else if (strcmp(*argv, "home") == 0) {
-			if (req.ifa.ifa_family == AF_INET6)
-				ifa_flags |= IFA_F_HOMEADDRESS;
-			else
-				fprintf(stderr, "Warning: home option can be set only for IPv6 addresses\n");
-		} else if (strcmp(*argv, "optimistic") == 0) {
-			if (req.ifa.ifa_family == AF_INET6)
-				ifa_flags |= IFA_F_OPTIMISTIC;
-			else
-				fprintf(stderr, "Warning: optimistic option can be set only for IPv6 addresses\n");
+			ifa_flags |= IFA_F_HOMEADDRESS;
 		} else if (strcmp(*argv, "nodad") == 0) {
-			if (req.ifa.ifa_family == AF_INET6)
-				ifa_flags |= IFA_F_NODAD;
-			else
-				fprintf(stderr, "Warning: nodad option can be set only for IPv6 addresses\n");
+			ifa_flags |= IFA_F_NODAD;
 		} else if (strcmp(*argv, "mngtmpaddr") == 0) {
-			if (req.ifa.ifa_family == AF_INET6)
-				ifa_flags |= IFA_F_MANAGETEMPADDR;
-			else
-				fprintf(stderr, "Warning: mngtmpaddr option can be set only for IPv6 addresses\n");
+			ifa_flags |= IFA_F_MANAGETEMPADDR;
 		} else if (strcmp(*argv, "noprefixroute") == 0) {
 			ifa_flags |= IFA_F_NOPREFIXROUTE;
 		} else if (strcmp(*argv, "autojoin") == 0) {
 			ifa_flags |= IFA_F_MCAUTOJOIN;
 		} else {
-			if (strcmp(*argv, "local") == 0)
+			if (strcmp(*argv, "local") == 0) {
 				NEXT_ARG();
+			}
 			if (matches(*argv, "help") == 0)
 				usage();
 			if (local_len)
@@ -2326,19 +1891,17 @@
 		fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
 		return -1;
 	}
-	if (l && !is_valid_label(d, l)) {
-		fprintf(stderr,
-			"\"label\" (%s) must match \"dev\" (%s) or be prefixed by \"dev\" with a colon.\n",
-			l, d);
+	if (l && matches(d, l) != 0) {
+		fprintf(stderr, "\"dev\" (%s) must match \"label\" (%s).\n", d, l);
 		return -1;
 	}
 
 	if (peer_len == 0 && local_len) {
 		if (cmd == RTM_DELADDR && lcl.family == AF_INET && !(lcl.flags & PREFIXLEN_SPECIFIED)) {
 			fprintf(stderr,
-			    "Warning: Executing wildcard deletion to stay compatible with old scripts.\n"
-			    "         Explicitly specify the prefix length (%s/%d) to avoid this warning.\n"
-			    "         This special behaviour is likely to disappear in further releases,\n"
+			    "Warning: Executing wildcard deletion to stay compatible with old scripts.\n" \
+			    "         Explicitly specify the prefix length (%s/%d) to avoid this warning.\n" \
+			    "         This special behaviour is likely to disappear in further releases,\n" \
 			    "         fix your scripts!\n", lcl_arg, local_len*8);
 		} else {
 			peer = lcl;
@@ -2351,7 +1914,6 @@
 	if (brd_len < 0 && cmd != RTM_DELADDR) {
 		inet_prefix brd;
 		int i;
-
 		if (req.ifa.ifa_family != AF_INET) {
 			fprintf(stderr, "Broadcast can be set only for IPv4 addresses\n");
 			return -1;
@@ -2371,13 +1933,12 @@
 	if (!scoped && cmd != RTM_DELADDR)
 		req.ifa.ifa_scope = default_scope(&lcl);
 
-	req.ifa.ifa_index = ll_name_to_index(d);
-	if (!req.ifa.ifa_index)
-		return nodev(d);
+	if ((req.ifa.ifa_index = ll_name_to_index(d)) == 0) {
+		fprintf(stderr, "Cannot find device \"%s\"\n", d);
+		return -1;
+	}
 
 	if (valid_lftp || preferred_lftp) {
-		struct ifa_cacheinfo cinfo = {};
-
 		if (!valid_lft) {
 			fprintf(stderr, "valid_lft is zero\n");
 			return -1;
@@ -2387,6 +1948,7 @@
 			return -1;
 		}
 
+		memset(&cinfo, 0, sizeof(cinfo));
 		cinfo.ifa_prefered = preferred_lft;
 		cinfo.ifa_valid = valid_lft;
 		addattr_l(&req.n, sizeof(req), IFA_CACHEINFO, &cinfo,
@@ -2398,7 +1960,7 @@
 		return -1;
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index beb08da..f01bc26 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -38,10 +39,9 @@
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
-#define IFAL_RTA(r)	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg))))
-#define IFAL_PAYLOAD(n)	NLMSG_PAYLOAD(n, sizeof(struct ifaddrlblmsg))
+#define IFAL_RTA(r)	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg))))
+#define IFAL_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ifaddrlblmsg))
 
 extern struct rtnl_handle rth;
 
@@ -49,17 +49,17 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip addrlabel { add | del } prefix PREFIX [ dev DEV ] [ label LABEL ]\n"
-		"       ip addrlabel [ list | flush | help ]\n");
+	fprintf(stderr, "Usage: ip addrlabel [ list | add | del | flush ] prefix PREFIX [ dev DEV ] [ label LABEL ]\n");
 	exit(-1);
 }
 
-int print_addrlabel(struct nlmsghdr *n, void *arg)
+int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
+	FILE *fp = (FILE*)arg;
 	struct ifaddrlblmsg *ifal = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	struct rtattr *tb[IFAL_MAX+1];
+	char abuf[256];
 
 	if (n->nlmsg_type != RTM_NEWADDRLABEL && n->nlmsg_type != RTM_DELADDRLABEL)
 		return 0;
@@ -70,40 +70,29 @@
 
 	parse_rtattr(tb, IFAL_MAX, IFAL_RTA(ifal), len);
 
-	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELADDRLABEL)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
 	if (tb[IFAL_ADDRESS]) {
-		const char *host
-			= format_host_rta(ifal->ifal_family,
-					  tb[IFAL_ADDRESS]);
-
-		print_string(PRINT_FP, NULL, "prefix ", NULL);
-		print_color_string(PRINT_ANY,
-				   ifa_family_color(ifal->ifal_family),
-				   "address", "%s", host);
-
-		print_uint(PRINT_ANY, "prefixlen", "/%u ",
-			   ifal->ifal_prefixlen);
+		fprintf(fp, "prefix %s/%u ",
+			format_host(ifal->ifal_family,
+				    RTA_PAYLOAD(tb[IFAL_ADDRESS]),
+				    RTA_DATA(tb[IFAL_ADDRESS]),
+				    abuf, sizeof(abuf)),
+			ifal->ifal_prefixlen);
 	}
 
-	if (ifal->ifal_index) {
-		print_string(PRINT_FP, NULL, "dev ", NULL);
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "ifname", "%s ",
-				   ll_index_to_name(ifal->ifal_index));
-	}
+	if (ifal->ifal_index)
+		fprintf(fp, "dev %s ", ll_index_to_name(ifal->ifal_index));
 
 	if (tb[IFAL_LABEL] && RTA_PAYLOAD(tb[IFAL_LABEL]) == sizeof(uint32_t)) {
-		uint32_t label = rta_getattr_u32(tb[IFAL_LABEL]);
-
-		print_uint(PRINT_ANY,
-			   "label", "label %u ", label);
+		uint32_t label;
+		memcpy(&label, RTA_DATA(tb[IFAL_LABEL]), sizeof(label));
+		fprintf(fp, "label %u ", label);
 	}
-	print_string(PRINT_FP, NULL, "\n", "");
-	close_json_object();
 
+	fprintf(fp, "\n");
+	fflush(fp);
 	return 0;
 }
 
@@ -119,17 +108,15 @@
 		return -1;
 	}
 
-	if (rtnl_addrlbldump_req(&rth, af) < 0) {
+	if (rtnl_wilddump_request(&rth, af, RTM_GETADDRLABEL) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_addrlabel, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return 1;
 	}
-	delete_json_obj();
 
 	return 0;
 }
@@ -140,19 +127,24 @@
 	struct {
 		struct nlmsghdr	n;
 		struct ifaddrlblmsg	ifal;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_type = cmd,
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrlblmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.ifal.ifal_family = preferred_family,
-	};
+		char  			buf[1024];
+	} req;
 
-	inet_prefix prefix = {};
+	inet_prefix prefix;
 	uint32_t label = 0xffffffffUL;
 	char *p = NULL;
 	char *l = NULL;
 
+	memset(&req, 0, sizeof(req));
+	memset(&prefix, 0, sizeof(prefix));
+
+	req.n.nlmsg_type = cmd;
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrlblmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.ifal.ifal_family = preferred_family;
+	req.ifal.ifal_prefixlen = 0;
+	req.ifal.ifal_index = 0;
+
 	if (cmd == RTM_NEWADDRLABEL) {
 		req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
 	}
@@ -190,19 +182,19 @@
 	if (req.ifal.ifal_family == AF_UNSPEC)
 		req.ifal.ifal_family = AF_INET6;
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
 }
 
 
-static int flush_addrlabel(struct nlmsghdr *n, void *arg)
+static int flush_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	struct rtnl_handle rth2;
 	struct rtmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[IFAL_MAX+1];
+	struct rtattr * tb[IFAL_MAX+1];
 
 	len -= NLMSG_LENGTH(sizeof(*r));
 	if (len < 0)
@@ -217,7 +209,7 @@
 		if (rtnl_open(&rth2, 0) < 0)
 			return -1;
 
-		if (rtnl_talk(&rth2, n, NULL) < 0)
+		if (rtnl_talk(&rth2, n, NULL, 0) < 0)
 			return -2;
 
 		rtnl_close(&rth2);
@@ -238,7 +230,7 @@
 		return -1;
 	}
 
-	if (rtnl_addrlbldump_req(&rth, af) < 0) {
+	if (rtnl_wilddump_request(&rth, af, RTM_GETADDRLABEL) < 0) {
 		perror("Cannot send dump request");
 		return -1;
 	}
diff --git a/ip/ipfou.c b/ip/ipfou.c
index ea126b0..8a86b18 100644
--- a/ip/ipfou.c
+++ b/ip/ipfou.c
@@ -22,22 +22,14 @@
 #include "libgenl.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip fou add port PORT { ipproto PROTO  | gue } [ -6 ]\n"
-		"		   [ local IFADDR ] [ peer IFADDR ]\n"
-		"		   [ peer_port PORT ] [ dev IFNAME ]\n"
-		"       ip fou del port PORT [ -6 ] [ local IFADDR ]\n"
-		"		   [ peer IFADDR ] [ peer_port PORT ]\n"
-		"		   [ dev IFNAME ]\n"
-		"       ip fou show\n"
-		"\n"
-		"Where: PROTO { ipproto-name | 1..255 }\n"
-		"       PORT { 1..65535 }\n"
-		"       IFADDR { addr }\n");
+	fprintf(stderr, "Usage: ip fou add port PORT { ipproto PROTO  | gue }\n");
+	fprintf(stderr, "       ip fou del port PORT\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: PROTO { ipproto-name | 1..255 }\n");
+	fprintf(stderr, "       PORT { 1..65535 }\n");
 
 	exit(-1);
 }
@@ -53,21 +45,19 @@
 static int fou_parse_opt(int argc, char **argv, struct nlmsghdr *n,
 			 bool adding)
 {
-	const char *local = NULL, *peer = NULL;
-	__u16 port, peer_port = 0;
-	__u8 family = AF_INET;
+	__u16 port;
+	int port_set = 0;
+	__u8 ipproto, type;
 	bool gue_set = false;
 	int ipproto_set = 0;
-	__u8 ipproto, type;
-	int port_set = 0;
-	int index = 0;
 
 	while (argc > 0) {
 		if (!matches(*argv, "port")) {
 			NEXT_ARG();
 
-			if (get_be16(&port, *argv, 0) || port == 0)
+			if (get_u16(&port, *argv, 0) || port == 0)
 				invarg("invalid port", *argv);
+			port = htons(port);
 			port_set = 1;
 		} else if (!matches(*argv, "ipproto")) {
 			struct protoent *servptr;
@@ -82,42 +72,8 @@
 			ipproto_set = 1;
 		} else if (!matches(*argv, "gue")) {
 			gue_set = true;
-		} else if (!matches(*argv, "-6")) {
-			family = AF_INET6;
-		} else if (!matches(*argv, "local")) {
-			NEXT_ARG();
-
-			local = *argv;
-		} else if (!matches(*argv, "peer")) {
-			NEXT_ARG();
-
-			peer = *argv;
-		} else if (!matches(*argv, "peer_port")) {
-			NEXT_ARG();
-
-			if (get_be16(&peer_port, *argv, 0) || peer_port == 0)
-				invarg("invalid peer port", *argv);
-		} else if (!matches(*argv, "dev")) {
-			const char *ifname;
-
-			NEXT_ARG();
-
-			ifname = *argv;
-
-			if (check_ifname(ifname)) {
-				fprintf(stderr, "fou: invalid device name\n");
-				exit(EXIT_FAILURE);
-			}
-
-			index = ll_name_to_index(ifname);
-
-			if (!index) {
-				fprintf(stderr, "fou: unknown device name\n");
-				exit(EXIT_FAILURE);
-			}
 		} else {
-			fprintf(stderr
-				, "fou: unknown command \"%s\"?\n", *argv);
+			fprintf(stderr, "fou: unknown command \"%s\"?\n", *argv);
 			usage();
 			return -1;
 		}
@@ -139,52 +95,14 @@
 		return -1;
 	}
 
-	if ((peer_port && !peer) || (peer && !peer_port)) {
-		fprintf(stderr, "fou: both peer and peer port must be set\n");
-		return -1;
-	}
-
 	type = gue_set ? FOU_ENCAP_GUE : FOU_ENCAP_DIRECT;
 
 	addattr16(n, 1024, FOU_ATTR_PORT, port);
 	addattr8(n, 1024, FOU_ATTR_TYPE, type);
-	addattr8(n, 1024, FOU_ATTR_AF, family);
 
 	if (ipproto_set)
 		addattr8(n, 1024, FOU_ATTR_IPPROTO, ipproto);
 
-	if (local) {
-		inet_prefix local_addr;
-		__u8 attr_type = family == AF_INET ? FOU_ATTR_LOCAL_V4 :
-						     FOU_ATTR_LOCAL_V6;
-
-		if (get_addr(&local_addr, local, family)) {
-			fprintf(stderr, "fou: parsing local address failed\n");
-			exit(EXIT_FAILURE);
-		}
-		addattr_l(n, 1024, attr_type, &local_addr.data,
-			  local_addr.bytelen);
-	}
-
-	if (peer) {
-		inet_prefix peer_addr;
-		__u8 attr_type = family == AF_INET ? FOU_ATTR_PEER_V4 :
-						     FOU_ATTR_PEER_V6;
-
-		if (get_addr(&peer_addr, peer, family)) {
-			fprintf(stderr, "fou: parsing peer address failed\n");
-			exit(EXIT_FAILURE);
-		}
-		addattr_l(n, 1024, attr_type, &peer_addr.data,
-			  peer_addr.bytelen);
-
-		if (peer_port)
-			addattr16(n, 1024, FOU_ATTR_PEER_PORT, peer_port);
-	}
-
-	if (index)
-		addattr32(n, 1024, FOU_ATTR_IFINDEX, index);
-
 	return 0;
 }
 
@@ -194,7 +112,7 @@
 
 	fou_parse_opt(argc, argv, &req.n, true);
 
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
@@ -206,145 +124,35 @@
 
 	fou_parse_opt(argc, argv, &req.n, false);
 
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
 }
 
-static int print_fou_mapping(struct nlmsghdr *n, void *arg)
-{
-	__u8 family = AF_INET, local_attr_type, peer_attr_type, byte_len;
-	struct rtattr *tb[FOU_ATTR_MAX + 1];
-	__u8 empty_buf[16] = {0};
-	struct genlmsghdr *ghdr;
-	int len = n->nlmsg_len;
-
-	if (n->nlmsg_type != genl_family)
-		return 0;
-
-	len -= NLMSG_LENGTH(GENL_HDRLEN);
-	if (len < 0)
-		return -1;
-
-	ghdr = NLMSG_DATA(n);
-	parse_rtattr(tb, FOU_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
-
-	open_json_object(NULL);
-	if (tb[FOU_ATTR_PORT])
-		print_uint(PRINT_ANY, "port", "port %u",
-			   ntohs(rta_getattr_u16(tb[FOU_ATTR_PORT])));
-
-	if (tb[FOU_ATTR_TYPE] &&
-	    rta_getattr_u8(tb[FOU_ATTR_TYPE]) == FOU_ENCAP_GUE)
-		print_null(PRINT_ANY, "gue", " gue", NULL);
-	else if (tb[FOU_ATTR_IPPROTO])
-		print_uint(PRINT_ANY, "ipproto",
-			   " ipproto %u", rta_getattr_u8(tb[FOU_ATTR_IPPROTO]));
-
-	if (tb[FOU_ATTR_AF]) {
-		family = rta_getattr_u8(tb[FOU_ATTR_AF]);
-
-		print_string(PRINT_JSON, "family", NULL,
-			     family_name(family));
-
-		if (family == AF_INET6)
-			print_string(PRINT_FP, NULL,
-				     " -6", NULL);
-	}
-
-	local_attr_type = family == AF_INET ? FOU_ATTR_LOCAL_V4 :
-					      FOU_ATTR_LOCAL_V6;
-	peer_attr_type = family == AF_INET ? FOU_ATTR_PEER_V4 :
-					     FOU_ATTR_PEER_V6;
-	byte_len = af_bit_len(family) / 8;
-
-	if (tb[local_attr_type] && memcmp(RTA_DATA(tb[local_attr_type]),
-					  empty_buf, byte_len)) {
-		print_string(PRINT_ANY, "local", " local %s",
-			     format_host_rta(family, tb[local_attr_type]));
-	}
-
-	if (tb[peer_attr_type] && memcmp(RTA_DATA(tb[peer_attr_type]),
-					 empty_buf, byte_len)) {
-		print_string(PRINT_ANY, "peer", " peer %s",
-			     format_host_rta(family, tb[peer_attr_type]));
-	}
-
-	if (tb[FOU_ATTR_PEER_PORT]) {
-		__u16 p_port = ntohs(rta_getattr_u16(tb[FOU_ATTR_PEER_PORT]));
-
-		if (p_port)
-			print_uint(PRINT_ANY, "peer_port", " peer_port %u",
-				   p_port);
-
-	}
-
-	if (tb[FOU_ATTR_IFINDEX]) {
-		int index = rta_getattr_s32(tb[FOU_ATTR_IFINDEX]);
-
-		if (index) {
-			const char *ifname;
-
-			ifname = ll_index_to_name(index);
-
-			if (ifname)
-				print_string(PRINT_ANY, "dev", " dev %s",
-					     ifname);
-		}
-	}
-
-	print_string(PRINT_FP, NULL, "\n", NULL);
-	close_json_object();
-
-	return 0;
-}
-
-static int do_show(int argc, char **argv)
-{
-	FOU_REQUEST(req, 4096, FOU_CMD_GET, NLM_F_REQUEST | NLM_F_DUMP);
-
-	if (argc > 0) {
-		fprintf(stderr,
-			"\"ip fou show\" does not take any arguments.\n");
-		return -1;
-	}
-
-	if (rtnl_send(&genl_rth, &req.n, req.n.nlmsg_len) < 0) {
-		perror("Cannot send show request");
-		exit(1);
-	}
-
-	new_json_obj(json);
-	if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return 1;
-	}
-	delete_json_obj();
-	fflush(stdout);
-
-	return 0;
-}
-
 int do_ipfou(int argc, char **argv)
 {
+	if (genl_family < 0) {
+		if (rtnl_open_byproto(&genl_rth, 0, NETLINK_GENERIC) < 0) {
+			fprintf(stderr, "Cannot open generic netlink socket\n");
+			exit(1);
+		}
+
+		genl_family = genl_resolve_family(&genl_rth, FOU_GENL_NAME);
+		if (genl_family < 0)
+			exit(1);
+	}
+
 	if (argc < 1)
 		usage();
 
-	if (matches(*argv, "help") == 0)
-		usage();
-
-	if (genl_init_handle(&genl_rth, FOU_GENL_NAME, &genl_family))
-		exit(1);
-
 	if (matches(*argv, "add") == 0)
 		return do_add(argc-1, argv+1);
 	if (matches(*argv, "delete") == 0)
 		return do_del(argc-1, argv+1);
-	if (matches(*argv, "show") == 0)
-		return do_show(argc-1, argv+1);
+	if (matches(*argv, "help") == 0)
+		usage();
 
-	fprintf(stderr,
-		"Command \"%s\" is unknown, try \"ip fou help\".\n", *argv);
+	fprintf(stderr, "Command \"%s\" is unknown, try \"ip fou help\".\n", *argv);
 	exit(-1);
 }
diff --git a/ip/ipila.c b/ip/ipila.c
deleted file mode 100644
index 739ee4e..0000000
--- a/ip/ipila.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * ipila.c	ILA (Identifier Locator Addressing) support
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:	Tom Herbert <tom@herbertland.com>
- */
-
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <net/if.h>
-#include <linux/ila.h>
-#include <linux/genetlink.h>
-#include <linux/ip.h>
-#include <arpa/inet.h>
-
-#include "libgenl.h"
-#include "utils.h"
-#include "ip_common.h"
-#include "ila_common.h"
-#include "json_print.h"
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage: ip ila add loc_match LOCATOR_MATCH loc LOCATOR [ dev DEV ] OPTIONS\n"
-		"       ip ila del loc_match LOCATOR_MATCH [ loc LOCATOR ] [ dev DEV ]\n"
-		"       ip ila list\n"
-		"OPTIONS := [ csum-mode { adj-transport | neutral-map | neutral-map-auto | no-action } ]\n"
-		"           [ ident-type { luid | use-format } ]\n");
-
-	exit(-1);
-}
-
-/* netlink socket */
-static struct rtnl_handle genl_rth = { .fd = -1 };
-static int genl_family = -1;
-
-#define ILA_REQUEST(_req, _bufsiz, _cmd, _flags)	\
-	GENL_REQUEST(_req, _bufsiz, genl_family, 0,	\
-		     ILA_GENL_VERSION, _cmd, _flags)
-
-#define ILA_RTA(g) ((struct rtattr *)(((char *)(g)) +	\
-	NLMSG_ALIGN(sizeof(struct genlmsghdr))))
-
-static void print_addr64(__u64 addr, char *buff, size_t len)
-{
-	__u16 *words = (__u16 *)&addr;
-	__u16 v;
-	int i, ret;
-	size_t written = 0;
-	char *sep = ":";
-
-	for (i = 0; i < 4; i++) {
-		v = ntohs(words[i]);
-
-		if (i == 3)
-			sep = "";
-
-		ret = snprintf(&buff[written], len - written, "%x%s", v, sep);
-		written += ret;
-	}
-}
-
-static void print_ila_locid(const char *tag, int attr, struct rtattr *tb[])
-{
-	char abuf[256];
-
-	if (tb[attr])
-		print_addr64(rta_getattr_u64(tb[attr]),
-			     abuf, sizeof(abuf));
-	else
-		snprintf(abuf, sizeof(abuf), "-");
-
-	/* 20 = sizeof("xxxx:xxxx:xxxx:xxxx") */
-	print_string(PRINT_ANY, tag, "%-20s", abuf);
-}
-
-static int print_ila_mapping(struct nlmsghdr *n, void *arg)
-{
-	struct genlmsghdr *ghdr;
-	struct rtattr *tb[ILA_ATTR_MAX + 1];
-	int len = n->nlmsg_len;
-
-	if (n->nlmsg_type != genl_family)
-		return 0;
-
-	len -= NLMSG_LENGTH(GENL_HDRLEN);
-	if (len < 0)
-		return -1;
-
-	ghdr = NLMSG_DATA(n);
-	parse_rtattr(tb, ILA_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
-
-	open_json_object(NULL);
-	print_ila_locid("locator_match", ILA_ATTR_LOCATOR_MATCH, tb);
-	print_ila_locid("locator", ILA_ATTR_LOCATOR, tb);
-
-	if (tb[ILA_ATTR_IFINDEX]) {
-		__u32 ifindex
-			= rta_getattr_u32(tb[ILA_ATTR_IFINDEX]);
-
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "interface", "%-16s",
-				   ll_index_to_name(ifindex));
-	} else {
-		print_string(PRINT_FP, NULL, "%-10s ", "-");
-	}
-
-	if (tb[ILA_ATTR_CSUM_MODE]) {
-		__u8 csum = rta_getattr_u8(tb[ILA_ATTR_CSUM_MODE]);
-
-		print_string(PRINT_ANY, "csum_mode", "%s",
-			     ila_csum_mode2name(csum));
-	} else
-		print_string(PRINT_FP, NULL, "%-10s ", "-");
-
-	if (tb[ILA_ATTR_IDENT_TYPE])
-		print_string(PRINT_ANY, "ident_type", "%s",
-			ila_ident_type2name(rta_getattr_u8(
-						tb[ILA_ATTR_IDENT_TYPE])));
-	else
-		print_string(PRINT_FP, NULL, "%s", "-");
-
-	print_nl();
-	close_json_object();
-
-	return 0;
-}
-
-#define NLMSG_BUF_SIZE 4096
-
-static int do_list(int argc, char **argv)
-{
-	ILA_REQUEST(req, 1024, ILA_CMD_GET, NLM_F_REQUEST | NLM_F_DUMP);
-
-	if (argc > 0) {
-		fprintf(stderr, "\"ip ila show\" does not take "
-			"any arguments.\n");
-		return -1;
-	}
-
-	if (rtnl_send(&genl_rth, (void *)&req, req.n.nlmsg_len) < 0) {
-		perror("Cannot send dump request");
-		exit(1);
-	}
-
-	new_json_obj(json);
-	if (rtnl_dump_filter(&genl_rth, print_ila_mapping, stdout) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return 1;
-	}
-	delete_json_obj();
-	fflush(stdout);
-
-	return 0;
-}
-
-static int ila_parse_opt(int argc, char **argv, struct nlmsghdr *n,
-			 bool adding)
-{
-	__u64 locator = 0;
-	__u64 locator_match = 0;
-	int ifindex = 0;
-	int csum_mode = 0;
-	int ident_type = 0;
-	bool loc_set = false;
-	bool loc_match_set = false;
-	bool ifindex_set = false;
-	bool csum_mode_set = false;
-	bool ident_type_set = false;
-
-	while (argc > 0) {
-		if (!matches(*argv, "loc")) {
-			NEXT_ARG();
-
-			if (get_addr64(&locator, *argv) < 0) {
-				fprintf(stderr, "Bad locator: %s\n", *argv);
-				return -1;
-			}
-			loc_set = true;
-		} else if (!matches(*argv, "loc_match")) {
-			NEXT_ARG();
-
-			if (get_addr64(&locator_match, *argv) < 0) {
-				fprintf(stderr, "Bad locator to match: %s\n",
-					*argv);
-				return -1;
-			}
-			loc_match_set = true;
-		} else if (!matches(*argv, "csum-mode")) {
-			NEXT_ARG();
-
-			csum_mode = ila_csum_name2mode(*argv);
-			if (csum_mode < 0) {
-				fprintf(stderr, "Bad csum-mode: %s\n",
-					*argv);
-				return -1;
-			}
-			csum_mode_set = true;
-		} else if (!matches(*argv, "ident-type")) {
-			NEXT_ARG();
-
-			ident_type = ila_ident_name2type(*argv);
-			if (ident_type < 0) {
-				fprintf(stderr, "Bad ident-type: %s\n",
-					*argv);
-				return -1;
-			}
-			ident_type_set = true;
-		} else if (!matches(*argv, "dev")) {
-			NEXT_ARG();
-
-			ifindex = ll_name_to_index(*argv);
-			if (ifindex == 0) {
-				fprintf(stderr, "No such interface: %s\n",
-					*argv);
-				return -1;
-			}
-			ifindex_set = true;
-		} else {
-			usage();
-			return -1;
-		}
-		argc--, argv++;
-	}
-
-	if (adding) {
-		if (!loc_set) {
-			fprintf(stderr, "ila: missing locator\n");
-			return -1;
-		}
-		if (!loc_match_set) {
-			fprintf(stderr, "ila: missing locator0match\n");
-			return -1;
-		}
-	}
-
-	if (loc_match_set)
-		addattr64(n, 1024, ILA_ATTR_LOCATOR_MATCH, locator_match);
-
-	if (loc_set)
-		addattr64(n, 1024, ILA_ATTR_LOCATOR, locator);
-
-	if (ifindex_set)
-		addattr32(n, 1024, ILA_ATTR_IFINDEX, ifindex);
-
-	if (csum_mode_set)
-		addattr8(n, 1024, ILA_ATTR_CSUM_MODE, csum_mode);
-
-	if (ident_type_set)
-		addattr8(n, 1024, ILA_ATTR_IDENT_TYPE, ident_type);
-
-	return 0;
-}
-
-static int do_add(int argc, char **argv)
-{
-	ILA_REQUEST(req, 1024, ILA_CMD_ADD, NLM_F_REQUEST);
-
-	ila_parse_opt(argc, argv, &req.n, true);
-
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
-		return -2;
-
-	return 0;
-}
-
-static int do_del(int argc, char **argv)
-{
-	ILA_REQUEST(req, 1024, ILA_CMD_DEL, NLM_F_REQUEST);
-
-	ila_parse_opt(argc, argv, &req.n, false);
-
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
-		return -2;
-
-	return 0;
-}
-
-int do_ipila(int argc, char **argv)
-{
-	if (argc < 1)
-		usage();
-
-	if (matches(*argv, "help") == 0)
-		usage();
-
-	if (genl_init_handle(&genl_rth, ILA_GENL_NAME, &genl_family))
-		exit(1);
-
-	if (matches(*argv, "add") == 0)
-		return do_add(argc-1, argv+1);
-	if (matches(*argv, "delete") == 0)
-		return do_del(argc-1, argv+1);
-	if (matches(*argv, "list") == 0)
-		return do_list(argc-1, argv+1);
-
-	fprintf(stderr, "Command \"%s\" is unknown, try \"ip ila help\".\n",
-		*argv);
-	exit(-1);
-}
diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
index 77bc324..f050880 100644
--- a/ip/ipl2tp.c
+++ b/ip/ipl2tp.c
@@ -42,6 +42,8 @@
 	uint32_t peer_tunnel_id;
 	uint32_t session_id;
 	uint32_t peer_session_id;
+	uint32_t offset;
+	uint32_t peer_offset;
 	enum l2tp_encap_type encap;
 	uint16_t local_udp_port;
 	uint16_t peer_udp_port;
@@ -53,13 +55,14 @@
 	inet_prefix peer_ip;
 
 	uint16_t pw_type;
-	unsigned int udp6_csum_tx:1;
-	unsigned int udp6_csum_rx:1;
-	unsigned int udp_csum:1;
-	unsigned int recv_seq:1;
-	unsigned int send_seq:1;
-	unsigned int tunnel:1;
-	unsigned int session:1;
+	uint16_t mtu;
+	int udp_csum:1;
+	int recv_seq:1;
+	int send_seq:1;
+	int lns_mode:1;
+	int data_seq:2;
+	int tunnel:1;
+	int session:1;
 	int reorder_timeout;
 	const char *ifname;
 	uint8_t l2spec_type;
@@ -105,26 +108,18 @@
 
 	if (p->local_ip.family == AF_INET6)
 		local_attr = L2TP_ATTR_IP6_SADDR;
-	addattr_l(&req.n, 1024, local_attr, &p->local_ip.data,
-		  p->local_ip.bytelen);
+	addattr_l(&req.n, 1024, local_attr, &p->local_ip.data, p->local_ip.bytelen);
 
 	if (p->peer_ip.family == AF_INET6)
 		peer_attr = L2TP_ATTR_IP6_DADDR;
-	addattr_l(&req.n, 1024, peer_attr, &p->peer_ip.data,
-		  p->peer_ip.bytelen);
+	addattr_l(&req.n, 1024, peer_attr, &p->peer_ip.data, p->peer_ip.bytelen);
 
 	if (p->encap == L2TP_ENCAPTYPE_UDP) {
 		addattr16(&req.n, 1024, L2TP_ATTR_UDP_SPORT, p->local_udp_port);
 		addattr16(&req.n, 1024, L2TP_ATTR_UDP_DPORT, p->peer_udp_port);
-		if (p->udp_csum)
-			addattr8(&req.n, 1024, L2TP_ATTR_UDP_CSUM, 1);
-		if (!p->udp6_csum_tx)
-			addattr(&req.n, 1024, L2TP_ATTR_UDP_ZERO_CSUM6_TX);
-		if (!p->udp6_csum_rx)
-			addattr(&req.n, 1024, L2TP_ATTR_UDP_ZERO_CSUM6_RX);
 	}
 
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
@@ -137,7 +132,7 @@
 
 	addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->tunnel_id);
 
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
@@ -156,23 +151,22 @@
 	addattr8(&req.n, 1024, L2TP_ATTR_L2SPEC_TYPE, p->l2spec_type);
 	addattr8(&req.n, 1024, L2TP_ATTR_L2SPEC_LEN, p->l2spec_len);
 
-	if (p->recv_seq)
-		addattr8(&req.n, 1024, L2TP_ATTR_RECV_SEQ, 1);
-	if (p->send_seq)
-		addattr8(&req.n, 1024, L2TP_ATTR_SEND_SEQ, 1);
-	if (p->reorder_timeout)
-		addattr64(&req.n, 1024, L2TP_ATTR_RECV_TIMEOUT,
+	if (p->mtu)		addattr16(&req.n, 1024, L2TP_ATTR_MTU, p->mtu);
+	if (p->recv_seq)	addattr(&req.n, 1024, L2TP_ATTR_RECV_SEQ);
+	if (p->send_seq)	addattr(&req.n, 1024, L2TP_ATTR_SEND_SEQ);
+	if (p->lns_mode)	addattr(&req.n, 1024, L2TP_ATTR_LNS_MODE);
+	if (p->data_seq)	addattr8(&req.n, 1024, L2TP_ATTR_DATA_SEQ, p->data_seq);
+	if (p->reorder_timeout) addattr64(&req.n, 1024, L2TP_ATTR_RECV_TIMEOUT,
 					  p->reorder_timeout);
-	if (p->cookie_len)
-		addattr_l(&req.n, 1024, L2TP_ATTR_COOKIE,
-			  p->cookie, p->cookie_len);
-	if (p->peer_cookie_len)
-		addattr_l(&req.n, 1024, L2TP_ATTR_PEER_COOKIE,
-			  p->peer_cookie,  p->peer_cookie_len);
-	if (p->ifname)
+	if (p->offset)		addattr16(&req.n, 1024, L2TP_ATTR_OFFSET, p->offset);
+	if (p->cookie_len)	addattr_l(&req.n, 1024, L2TP_ATTR_COOKIE,
+					  p->cookie, p->cookie_len);
+	if (p->peer_cookie_len) addattr_l(&req.n, 1024, L2TP_ATTR_PEER_COOKIE,
+					  p->peer_cookie,  p->peer_cookie_len);
+	if (p->ifname && p->ifname[0])
 		addattrstrz(&req.n, 1024, L2TP_ATTR_IFNAME, p->ifname);
 
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
@@ -185,28 +179,21 @@
 
 	addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
 	addattr32(&req.n, 1024, L2TP_ATTR_SESSION_ID, p->session_id);
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
 }
 
-static void print_cookie(const char *name, const char *fmt,
-			 const uint8_t *cookie, int len)
+static void print_cookie(char *name, const uint8_t *cookie, int len)
 {
-	char abuf[32];
-	size_t n;
-
-	n = snprintf(abuf, sizeof(abuf),
-		     "%02x%02x%02x%02x",
-		     cookie[0], cookie[1], cookie[2], cookie[3]);
+	printf("  %s %02x%02x%02x%02x", name,
+	       cookie[0], cookie[1],
+	       cookie[2], cookie[3]);
 	if (len == 8)
-		snprintf(abuf + n, sizeof(abuf) - n,
-			 "%02x%02x%02x%02x",
-			 cookie[4], cookie[5],
-			 cookie[6], cookie[7]);
-
-	print_string(PRINT_ANY, name, fmt, abuf);
+		printf("%02x%02x%02x%02x",
+		       cookie[4], cookie[5],
+		       cookie[6], cookie[7]);
 }
 
 static void print_tunnel(const struct l2tp_data *data)
@@ -214,117 +201,43 @@
 	const struct l2tp_parm *p = &data->config;
 	char buf[INET6_ADDRSTRLEN];
 
-	open_json_object(NULL);
-	print_uint(PRINT_ANY, "tunnel_id", "Tunnel %u,", p->tunnel_id);
-	print_string(PRINT_ANY, "encap", " encap %s",
-		     p->encap == L2TP_ENCAPTYPE_UDP ? "UDP" :
-		     p->encap == L2TP_ENCAPTYPE_IP ? "IP" : "??");
-	print_nl();
+	printf("Tunnel %u, encap %s\n",
+	       p->tunnel_id,
+	       p->encap == L2TP_ENCAPTYPE_UDP ? "UDP" :
+	       p->encap == L2TP_ENCAPTYPE_IP ? "IP" : "??");
+	printf("  From %s ", inet_ntop(p->local_ip.family, p->local_ip.data, buf, sizeof(buf)));
+	printf("to %s\n", inet_ntop(p->peer_ip.family, p->peer_ip.data, buf, sizeof(buf)));
+	printf("  Peer tunnel %u\n",
+	       p->peer_tunnel_id);
 
-	print_string(PRINT_ANY, "local", "  From %s ",
-		     inet_ntop(p->local_ip.family, p->local_ip.data,
-			       buf, sizeof(buf)));
-	print_string(PRINT_ANY, "peer", "to %s",
-		     inet_ntop(p->peer_ip.family, p->peer_ip.data,
-			       buf, sizeof(buf)));
-	print_nl();
-
-	print_uint(PRINT_ANY, "peer_tunnel", "  Peer tunnel %u",
-		   p->peer_tunnel_id);
-	print_nl();
-
-	if (p->encap == L2TP_ENCAPTYPE_UDP) {
-		print_string(PRINT_FP, NULL,
-			     "  UDP source / dest ports:", NULL);
-
-		print_hu(PRINT_ANY, "local_port", " %hu",
-			   p->local_udp_port);
-		print_hu(PRINT_ANY, "peer_port", "/%hu",
-			   p->peer_udp_port);
-		print_nl();
-
-		switch (p->local_ip.family) {
-		case AF_INET:
-			print_bool(PRINT_JSON, "checksum",
-				   NULL, p->udp_csum);
-			print_string(PRINT_FP, NULL,
-				     "  UDP checksum: %s\n",
-				     p->udp_csum ? "enabled" : "disabled");
-			break;
-		case AF_INET6:
-			if (is_json_context()) {
-				print_bool(PRINT_JSON, "checksum_tx",
-					   NULL, p->udp6_csum_tx);
-
-				print_bool(PRINT_JSON, "checksum_rx",
-					   NULL, p->udp6_csum_tx);
-			} else {
-				printf("  UDP checksum: %s%s%s%s\n",
-				       p->udp6_csum_tx && p->udp6_csum_rx
-				       ? "enabled" : "",
-				       p->udp6_csum_tx && !p->udp6_csum_rx
-				       ? "tx" : "",
-				       !p->udp6_csum_tx && p->udp6_csum_rx
-				       ? "rx" : "",
-				       !p->udp6_csum_tx && !p->udp6_csum_rx
-				       ? "disabled" : "");
-			}
-			break;
-		}
-	}
-	close_json_object();
+	if (p->encap == L2TP_ENCAPTYPE_UDP)
+		printf("  UDP source / dest ports: %hu/%hu\n",
+		       p->local_udp_port, p->peer_udp_port);
 }
 
 static void print_session(struct l2tp_data *data)
 {
 	struct l2tp_parm *p = &data->config;
 
-	open_json_object(NULL);
-
-	print_uint(PRINT_ANY, "session_id", "Session %u", p->session_id);
-	print_uint(PRINT_ANY, "tunnel_id",  " in tunnel %u", p->tunnel_id);
-	print_nl();
-
-	print_uint(PRINT_ANY, "peer_session_id",
-		     "  Peer session %u,", p->peer_session_id);
-	print_uint(PRINT_ANY, "peer_tunnel_id",
-		     " tunnel %u",  p->peer_tunnel_id);
-	print_nl();
+	printf("Session %u in tunnel %u\n",
+	       p->session_id, p->tunnel_id);
+	printf("  Peer session %u, tunnel %u\n",
+	       p->peer_session_id, p->peer_tunnel_id);
 
 	if (p->ifname != NULL) {
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "interface", "  interface name: %s" , p->ifname);
-		print_nl();
+		printf("  interface name: %s\n", p->ifname);
 	}
-
-	/* Show offsets only for plain console output (for legacy scripts) */
-	print_uint(PRINT_FP, "offset", "  offset %u,", 0);
-	print_uint(PRINT_FP, "peer_offset", " peer offset %u\n", 0);
-
+	printf("  offset %u, peer offset %u\n",
+	       p->offset, p->peer_offset);
 	if (p->cookie_len > 0)
-		print_cookie("cookie", "  cookie %s",
-			     p->cookie, p->cookie_len);
-
+		print_cookie("cookie", p->cookie, p->cookie_len);
 	if (p->peer_cookie_len > 0)
-		print_cookie("peer_cookie", "  peer cookie %s",
-			     p->peer_cookie, p->peer_cookie_len);
+		print_cookie("peer cookie", p->peer_cookie, p->peer_cookie_len);
 
 	if (p->reorder_timeout != 0)
-		print_uint(PRINT_ANY, "reorder_timeout",
-			   "  reorder timeout: %u", p->reorder_timeout);
-
-
-	if (p->send_seq || p->recv_seq) {
-		print_string(PRINT_FP, NULL, "%s  sequence numbering:", _SL_);
-
-		if (p->send_seq)
-			print_null(PRINT_ANY, "send_seq", " send", NULL);
-		if (p->recv_seq)
-			print_null(PRINT_ANY, "recv_seq", " recv", NULL);
-
-	}
-	print_string(PRINT_FP, NULL, "\n", NULL);
-	close_json_object();
+		printf("  reorder timeout: %u\n", p->reorder_timeout);
+	else
+		printf("\n");
 }
 
 static int get_response(struct nlmsghdr *n, void *arg)
@@ -333,7 +246,7 @@
 	struct l2tp_data *data = arg;
 	struct l2tp_parm *p = &data->config;
 	struct rtattr *attrs[L2TP_ATTR_MAX + 1];
-	struct rtattr *nla_stats, *rta;
+	struct rtattr *nla_stats;
 	int len;
 
 	/* Validate message and parse attributes */
@@ -351,6 +264,10 @@
 		p->pw_type = rta_getattr_u16(attrs[L2TP_ATTR_PW_TYPE]);
 	if (attrs[L2TP_ATTR_ENCAP_TYPE])
 		p->encap = rta_getattr_u16(attrs[L2TP_ATTR_ENCAP_TYPE]);
+	if (attrs[L2TP_ATTR_OFFSET])
+		p->offset = rta_getattr_u16(attrs[L2TP_ATTR_OFFSET]);
+	if (attrs[L2TP_ATTR_DATA_SEQ])
+		p->data_seq = rta_getattr_u16(attrs[L2TP_ATTR_DATA_SEQ]);
 	if (attrs[L2TP_ATTR_CONN_ID])
 		p->tunnel_id = rta_getattr_u32(attrs[L2TP_ATTR_CONN_ID]);
 	if (attrs[L2TP_ATTR_PEER_CONN_ID])
@@ -364,12 +281,7 @@
 	if (attrs[L2TP_ATTR_L2SPEC_LEN])
 		p->l2spec_len = rta_getattr_u8(attrs[L2TP_ATTR_L2SPEC_LEN]);
 
-	if (attrs[L2TP_ATTR_UDP_CSUM])
-		p->udp_csum = !!rta_getattr_u8(attrs[L2TP_ATTR_UDP_CSUM]);
-
-	p->udp6_csum_tx = !attrs[L2TP_ATTR_UDP_ZERO_CSUM6_TX];
-	p->udp6_csum_rx = !attrs[L2TP_ATTR_UDP_ZERO_CSUM6_RX];
-
+	p->udp_csum = !!attrs[L2TP_ATTR_UDP_CSUM];
 	if (attrs[L2TP_ATTR_COOKIE])
 		memcpy(p->cookie, RTA_DATA(attrs[L2TP_ATTR_COOKIE]),
 		       p->cookie_len = RTA_PAYLOAD(attrs[L2TP_ATTR_COOKIE]));
@@ -378,36 +290,41 @@
 		memcpy(p->peer_cookie, RTA_DATA(attrs[L2TP_ATTR_PEER_COOKIE]),
 		       p->peer_cookie_len = RTA_PAYLOAD(attrs[L2TP_ATTR_PEER_COOKIE]));
 
-	if (attrs[L2TP_ATTR_RECV_SEQ])
-		p->recv_seq = !!rta_getattr_u8(attrs[L2TP_ATTR_RECV_SEQ]);
-	if (attrs[L2TP_ATTR_SEND_SEQ])
-		p->send_seq = !!rta_getattr_u8(attrs[L2TP_ATTR_SEND_SEQ]);
+	p->recv_seq = !!attrs[L2TP_ATTR_RECV_SEQ];
+	p->send_seq = !!attrs[L2TP_ATTR_SEND_SEQ];
 
 	if (attrs[L2TP_ATTR_RECV_TIMEOUT])
 		p->reorder_timeout = rta_getattr_u64(attrs[L2TP_ATTR_RECV_TIMEOUT]);
-
-	rta = attrs[L2TP_ATTR_IP_SADDR];
-	p->local_ip.family = AF_INET;
-	if (!rta) {
-		rta = attrs[L2TP_ATTR_IP6_SADDR];
+	if (attrs[L2TP_ATTR_IP_SADDR]) {
+		p->local_ip.family = AF_INET;
+		p->local_ip.data[0] = rta_getattr_u32(attrs[L2TP_ATTR_IP_SADDR]);
+		p->local_ip.bytelen = 4;
+		p->local_ip.bitlen = -1;
+	}
+	if (attrs[L2TP_ATTR_IP_DADDR]) {
+		p->peer_ip.family = AF_INET;
+		p->peer_ip.data[0] = rta_getattr_u32(attrs[L2TP_ATTR_IP_DADDR]);
+		p->peer_ip.bytelen = 4;
+		p->peer_ip.bitlen = -1;
+	}
+	if (attrs[L2TP_ATTR_IP6_SADDR]) {
 		p->local_ip.family = AF_INET6;
+		memcpy(&p->local_ip.data, RTA_DATA(attrs[L2TP_ATTR_IP6_SADDR]),
+			p->local_ip.bytelen = 16);
+		p->local_ip.bitlen = -1;
 	}
-	if (rta && get_addr_rta(&p->local_ip, rta, p->local_ip.family))
-		return -1;
-
-	rta = attrs[L2TP_ATTR_IP_DADDR];
-	p->peer_ip.family = AF_INET;
-	if (!rta) {
-		rta = attrs[L2TP_ATTR_IP6_DADDR];
+	if (attrs[L2TP_ATTR_IP6_DADDR]) {
 		p->peer_ip.family = AF_INET6;
+		memcpy(&p->peer_ip.data, RTA_DATA(attrs[L2TP_ATTR_IP6_DADDR]),
+			p->peer_ip.bytelen = 16);
+		p->peer_ip.bitlen = -1;
 	}
-	if (rta && get_addr_rta(&p->peer_ip, rta, p->peer_ip.family))
-		return -1;
-
 	if (attrs[L2TP_ATTR_UDP_SPORT])
 		p->local_udp_port = rta_getattr_u16(attrs[L2TP_ATTR_UDP_SPORT]);
 	if (attrs[L2TP_ATTR_UDP_DPORT])
 		p->peer_udp_port = rta_getattr_u16(attrs[L2TP_ATTR_UDP_DPORT]);
+	if (attrs[L2TP_ATTR_MTU])
+		p->mtu = rta_getattr_u16(attrs[L2TP_ATTR_MTU]);
 	if (attrs[L2TP_ATTR_IFNAME])
 		p->ifname = rta_getattr_str(attrs[L2TP_ATTR_IFNAME]);
 
@@ -438,7 +355,7 @@
 	return 0;
 }
 
-static int session_nlmsg(struct nlmsghdr *n, void *arg)
+static int session_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	int ret = get_response(n, arg);
 
@@ -458,25 +375,21 @@
 
 	if (p->config.tunnel_id && p->config.session_id) {
 		addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->config.tunnel_id);
-		addattr32(&req.n, 128, L2TP_ATTR_SESSION_ID,
-			  p->config.session_id);
+		addattr32(&req.n, 128, L2TP_ATTR_SESSION_ID, p->config.session_id);
 	}
 
 	if (rtnl_send(&genl_rth, &req, req.n.nlmsg_len) < 0)
 		return -2;
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&genl_rth, session_nlmsg, p) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
-	fflush(stdout);
 
 	return 0;
 }
 
-static int tunnel_nlmsg(struct nlmsghdr *n, void *arg)
+static int tunnel_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	int ret = get_response(n, arg);
 
@@ -500,13 +413,10 @@
 	if (rtnl_send(&genl_rth, &req, req.n.nlmsg_len) < 0)
 		return -2;
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&genl_rth, tunnel_nlmsg, p) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
-	fflush(stdout);
 
 	return 0;
 }
@@ -515,36 +425,68 @@
  * Command parser
  *****************************************************************************/
 
+static int hex(char ch)
+{
+	if ((ch >= 'a') && (ch <= 'f'))
+		return ch - 'a' + 10;
+	if ((ch >= '0') && (ch <= '9'))
+		return ch - '0';
+	if ((ch >= 'A') && (ch <= 'F'))
+		return ch - 'A' + 10;
+	return -1;
+}
+
+static int hex2mem(const char *buf, uint8_t *mem, int count)
+{
+	int i, j;
+	int c;
+
+	for (i = 0, j = 0; i < count; i++, j += 2) {
+		c = hex(buf[j]);
+		if (c < 0)
+			goto err;
+
+		mem[i] = c << 4;
+
+		c = hex(buf[j + 1]);
+		if (c < 0)
+			goto err;
+
+		mem[i] |= c;
+	}
+
+	return 0;
+
+err:
+	return -1;
+}
+
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr, "Usage: ip l2tp add tunnel\n"
-		"          remote ADDR local ADDR\n"
-		"          tunnel_id ID peer_tunnel_id ID\n"
-		"          [ encap { ip | udp } ]\n"
-		"          [ udp_sport PORT ] [ udp_dport PORT ]\n"
-		"          [ udp_csum { on | off } ]\n"
-		"          [ udp6_csum_tx { on | off } ]\n"
-		"          [ udp6_csum_rx { on | off } ]\n"
-		"Usage: ip l2tp add session [ name NAME ]\n"
-		"          tunnel_id ID\n"
-		"          session_id ID peer_session_id ID\n"
-		"          [ cookie HEXSTR ] [ peer_cookie HEXSTR ]\n"
-		"          [ seq { none | send | recv | both } ]\n"
-		"          [ l2spec_type L2SPEC ]\n"
-		"       ip l2tp del tunnel tunnel_id ID\n"
-		"       ip l2tp del session tunnel_id ID session_id ID\n"
-		"       ip l2tp show tunnel [ tunnel_id ID ]\n"
-		"       ip l2tp show session [ tunnel_id ID ] [ session_id ID ]\n"
-		"\n"
-		"Where: NAME   := STRING\n"
-		"       ADDR   := { IP_ADDRESS | any }\n"
-		"       PORT   := { 0..65535 }\n"
-		"       ID     := { 1..4294967295 }\n"
-		"       HEXSTR := { 8 or 16 hex digits (4 / 8 bytes) }\n"
-		"       L2SPEC := { none | default }\n");
-
+	fprintf(stderr, "Usage: ip l2tp add tunnel\n");
+	fprintf(stderr, "          remote ADDR local ADDR\n");
+	fprintf(stderr, "          tunnel_id ID peer_tunnel_id ID\n");
+	fprintf(stderr, "          [ encap { ip | udp } ]\n");
+	fprintf(stderr, "          [ udp_sport PORT ] [ udp_dport PORT ]\n");
+	fprintf(stderr, "Usage: ip l2tp add session [ name NAME ]\n");
+	fprintf(stderr, "          tunnel_id ID\n");
+	fprintf(stderr, "          session_id ID peer_session_id ID\n");
+	fprintf(stderr, "          [ cookie HEXSTR ] [ peer_cookie HEXSTR ]\n");
+	fprintf(stderr, "          [ offset OFFSET ] [ peer_offset OFFSET ]\n");
+	fprintf(stderr, "          [ l2spec_type L2SPEC ]\n");
+	fprintf(stderr, "       ip l2tp del tunnel tunnel_id ID\n");
+	fprintf(stderr, "       ip l2tp del session tunnel_id ID session_id ID\n");
+	fprintf(stderr, "       ip l2tp show tunnel [ tunnel_id ID ]\n");
+	fprintf(stderr, "       ip l2tp show session [ tunnel_id ID ] [ session_id ID ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: NAME   := STRING\n");
+	fprintf(stderr, "       ADDR   := { IP_ADDRESS | any }\n");
+	fprintf(stderr, "       PORT   := { 0..65535 }\n");
+	fprintf(stderr, "       ID     := { 1..4294967295 }\n");
+	fprintf(stderr, "       HEXSTR := { 8 or 16 hex digits (4 / 8 bytes) }\n");
+	fprintf(stderr, "       L2SPEC := { none | default }\n");
 	exit(-1);
 }
 
@@ -558,8 +500,6 @@
 	/* Defaults */
 	p->l2spec_type = L2TP_L2SPECTYPE_DEFAULT;
 	p->l2spec_len = 4;
-	p->udp6_csum_rx = 1;
-	p->udp6_csum_tx = 1;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "encap") == 0) {
@@ -574,8 +514,6 @@
 			}
 		} else if (strcmp(*argv, "name") == 0) {
 			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"name\" not a valid ifname", *argv);
 			p->ifname = *argv;
 		} else if (strcmp(*argv, "remote") == 0) {
 			NEXT_ARG();
@@ -588,7 +526,6 @@
 		} else if ((strcmp(*argv, "tunnel_id") == 0) ||
 			   (strcmp(*argv, "tid") == 0)) {
 			__u32 uval;
-
 			NEXT_ARG();
 			if (get_u32(&uval, *argv, 0))
 				invarg("invalid ID\n", *argv);
@@ -596,7 +533,6 @@
 		} else if ((strcmp(*argv, "peer_tunnel_id") == 0) ||
 			   (strcmp(*argv, "ptid") == 0)) {
 			__u32 uval;
-
 			NEXT_ARG();
 			if (get_u32(&uval, *argv, 0))
 				invarg("invalid ID\n", *argv);
@@ -604,7 +540,6 @@
 		} else if ((strcmp(*argv, "session_id") == 0) ||
 			   (strcmp(*argv, "sid") == 0)) {
 			__u32 uval;
-
 			NEXT_ARG();
 			if (get_u32(&uval, *argv, 0))
 				invarg("invalid ID\n", *argv);
@@ -612,60 +547,36 @@
 		} else if ((strcmp(*argv, "peer_session_id") == 0) ||
 			   (strcmp(*argv, "psid") == 0)) {
 			__u32 uval;
-
 			NEXT_ARG();
 			if (get_u32(&uval, *argv, 0))
 				invarg("invalid ID\n", *argv);
 			p->peer_session_id = uval;
 		} else if (strcmp(*argv, "udp_sport") == 0) {
 			__u16 uval;
-
 			NEXT_ARG();
 			if (get_u16(&uval, *argv, 0))
 				invarg("invalid port\n", *argv);
 			p->local_udp_port = uval;
 		} else if (strcmp(*argv, "udp_dport") == 0) {
 			__u16 uval;
-
 			NEXT_ARG();
 			if (get_u16(&uval, *argv, 0))
 				invarg("invalid port\n", *argv);
 			p->peer_udp_port = uval;
-		} else if (strcmp(*argv, "udp_csum") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "on") == 0)
-				p->udp_csum = 1;
-			else if (strcmp(*argv, "off") == 0)
-				p->udp_csum = 0;
-			else
-				invarg("invalid option for udp_csum\n", *argv);
-		} else if (strcmp(*argv, "udp6_csum_rx") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "on") == 0)
-				p->udp6_csum_rx = 1;
-			else if (strcmp(*argv, "off") == 0)
-				p->udp6_csum_rx = 0;
-			else
-				invarg("invalid option for udp6_csum_rx\n"
-						, *argv);
-		} else if (strcmp(*argv, "udp6_csum_tx") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "on") == 0)
-				p->udp6_csum_tx = 1;
-			else if (strcmp(*argv, "off") == 0)
-				p->udp6_csum_tx = 0;
-			else
-				invarg("invalid option for udp6_csum_tx\n"
-						, *argv);
 		} else if (strcmp(*argv, "offset") == 0) {
-			fprintf(stderr, "Ignoring option \"offset\"\n");
+			__u8 uval;
 			NEXT_ARG();
+			if (get_u8(&uval, *argv, 0))
+				invarg("invalid offset\n", *argv);
+			p->offset = uval;
 		} else if (strcmp(*argv, "peer_offset") == 0) {
-			fprintf(stderr, "Ignoring option \"peer_offset\"\n");
+			__u8 uval;
 			NEXT_ARG();
+			if (get_u8(&uval, *argv, 0))
+				invarg("invalid offset\n", *argv);
+			p->peer_offset = uval;
 		} else if (strcmp(*argv, "cookie") == 0) {
 			int slen;
-
 			NEXT_ARG();
 			slen = strlen(*argv);
 			if ((slen != 8) && (slen != 16))
@@ -676,7 +587,6 @@
 				invarg("cookie must be a hex string\n", *argv);
 		} else if (strcmp(*argv, "peer_cookie") == 0) {
 			int slen;
-
 			NEXT_ARG();
 			slen = strlen(*argv);
 			if ((slen != 8) && (slen != 16))
@@ -694,26 +604,7 @@
 				p->l2spec_type = L2TP_L2SPECTYPE_NONE;
 				p->l2spec_len = 0;
 			} else {
-				fprintf(stderr,
-					"Unknown layer2specific header type \"%s\"\n",
-					*argv);
-				exit(-1);
-			}
-		} else if (strcmp(*argv, "seq") == 0) {
-			NEXT_ARG();
-			if (strcasecmp(*argv, "both") == 0) {
-				p->recv_seq = 1;
-				p->send_seq = 1;
-			} else if (strcasecmp(*argv, "recv") == 0) {
-				p->recv_seq = 1;
-			} else if (strcasecmp(*argv, "send") == 0) {
-				p->send_seq = 1;
-			} else if (strcasecmp(*argv, "none") == 0) {
-				p->recv_seq = 0;
-				p->send_seq = 0;
-			} else {
-				fprintf(stderr,
-					"Unknown seq value \"%s\"\n", *argv);
+				fprintf(stderr, "Unknown layer2specific header type \"%s\"\n", *argv);
 				exit(-1);
 			}
 		} else if (strcmp(*argv, "tunnel") == 0) {
@@ -829,11 +720,19 @@
 
 int do_ipl2tp(int argc, char **argv)
 {
-	if (argc < 1 || !matches(*argv, "help"))
-		usage();
+	if (genl_family < 0) {
+		if (rtnl_open_byproto(&genl_rth, 0, NETLINK_GENERIC) < 0) {
+			fprintf(stderr, "Cannot open generic netlink socket\n");
+			exit(1);
+		}
 
-	if (genl_init_handle(&genl_rth, L2TP_GENL_NAME, &genl_family))
-		exit(1);
+		genl_family = genl_resolve_family(&genl_rth, L2TP_GENL_NAME);
+		if (genl_family < 0)
+			exit(1);
+	}
+
+	if (argc < 1)
+		usage();
 
 	if (matches(*argv, "add") == 0)
 		return do_add(argc-1, argv+1);
@@ -843,8 +742,9 @@
 	    matches(*argv, "lst") == 0 ||
 	    matches(*argv, "list") == 0)
 		return do_show(argc-1, argv+1);
+	if (matches(*argv, "help") == 0)
+		usage();
 
-	fprintf(stderr,
-		"Command \"%s\" is unknown, try \"ip l2tp help\".\n", *argv);
+	fprintf(stderr, "Command \"%s\" is unknown, try \"ip l2tp help\".\n", *argv);
 	exit(-1);
 }
diff --git a/ip/iplink.c b/ip/iplink.c
index 212a088..5ab9d61 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <dlfcn.h>
 #include <errno.h>
@@ -25,8 +26,8 @@
 #include <arpa/inet.h>
 #include <string.h>
 #include <sys/ioctl.h>
+#include <linux/sockios.h>
 #include <stdbool.h>
-#include <linux/mpls.h>
 
 #include "rt_names.h"
 #include "utils.h"
@@ -38,92 +39,62 @@
 #define LIBDIR "/usr/lib"
 #endif
 
-#ifndef GSO_MAX_SIZE
-#define GSO_MAX_SIZE		65536
-#endif
-#ifndef GSO_MAX_SEGS
-#define GSO_MAX_SEGS		65535
-#endif
-
-
 static void usage(void) __attribute__((noreturn));
 static int iplink_have_newlink(void);
 
 void iplink_usage(void)
 {
 	if (iplink_have_newlink()) {
-		fprintf(stderr,
-			"Usage: ip link add [link DEV] [ name ] NAME\n"
-			"		    [ txqueuelen PACKETS ]\n"
-			"		    [ address LLADDR ]\n"
-			"		    [ broadcast LLADDR ]\n"
-			"		    [ mtu MTU ] [index IDX ]\n"
-			"		    [ numtxqueues QUEUE_COUNT ]\n"
-			"		    [ numrxqueues QUEUE_COUNT ]\n"
-			"		    type TYPE [ ARGS ]\n"
-			"\n"
-			"	ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]\n"
-			"\n"
-			"	ip link set { DEVICE | dev DEVICE | group DEVGROUP }\n"
-			"			[ { up | down } ]\n"
-			"			[ type TYPE ARGS ]\n");
+		fprintf(stderr, "Usage: ip link add [link DEV] [ name ] NAME\n");
+		fprintf(stderr, "                   [ txqueuelen PACKETS ]\n");
+		fprintf(stderr, "                   [ address LLADDR ]\n");
+		fprintf(stderr, "                   [ broadcast LLADDR ]\n");
+		fprintf(stderr, "                   [ mtu MTU ] [index IDX ]\n");
+		fprintf(stderr, "                   [ numtxqueues QUEUE_COUNT ]\n");
+		fprintf(stderr, "                   [ numrxqueues QUEUE_COUNT ]\n");
+		fprintf(stderr, "                   type TYPE [ ARGS ]\n");
+		fprintf(stderr, "       ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]\n");
+		fprintf(stderr, "\n");
+		fprintf(stderr, "       ip link set { DEVICE | dev DEVICE | group DEVGROUP } [ { up | down } ]\n");
 	} else
-		fprintf(stderr,
-			"Usage: ip link set DEVICE [ { up | down } ]\n");
+		fprintf(stderr, "Usage: ip link set DEVICE [ { up | down } ]\n");
 
-	fprintf(stderr,
-		"		[ arp { on | off } ]\n"
-		"		[ dynamic { on | off } ]\n"
-		"		[ multicast { on | off } ]\n"
-		"		[ allmulticast { on | off } ]\n"
-		"		[ promisc { on | off } ]\n"
-		"		[ trailers { on | off } ]\n"
-		"		[ carrier { on | off } ]\n"
-		"		[ txqueuelen PACKETS ]\n"
-		"		[ name NEWNAME ]\n"
-		"		[ address LLADDR ]\n"
-		"		[ broadcast LLADDR ]\n"
-		"		[ mtu MTU ]\n"
-		"		[ netns { PID | NAME } ]\n"
-		"		[ link-netns NAME | link-netnsid ID ]\n"
-		"			[ alias NAME ]\n"
-		"			[ vf NUM [ mac LLADDR ]\n"
-		"				 [ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]\n"
-		"				 [ rate TXRATE ]\n"
-		"				 [ max_tx_rate TXRATE ]\n"
-		"				 [ min_tx_rate TXRATE ]\n"
-		"				 [ spoofchk { on | off} ]\n"
-		"				 [ query_rss { on | off} ]\n"
-		"				 [ state { auto | enable | disable} ] ]\n"
-		"				 [ trust { on | off} ] ]\n"
-		"				 [ node_guid { eui64 } ]\n"
-		"				 [ port_guid { eui64 } ]\n"
-		"			[ { xdp | xdpgeneric | xdpdrv | xdpoffload } { off |\n"
-		"				  object FILE [ section NAME ] [ verbose ] |\n"
-		"				  pinned FILE } ]\n"
-		"			[ master DEVICE ][ vrf NAME ]\n"
-		"			[ nomaster ]\n"
-		"			[ addrgenmode { eui64 | none | stable_secret | random } ]\n"
-		"			[ protodown { on | off } ]\n"
-		"			[ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]\n"
-		"\n"
-		"	ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n"
-		"\n"
-		"	ip link xstats type TYPE [ ARGS ]\n"
-		"\n"
-		"	ip link afstats [ dev DEVICE ]\n");
+	fprintf(stderr, "	                  [ arp { on | off } ]\n");
+	fprintf(stderr, "	                  [ dynamic { on | off } ]\n");
+	fprintf(stderr, "	                  [ multicast { on | off } ]\n");
+	fprintf(stderr, "	                  [ allmulticast { on | off } ]\n");
+	fprintf(stderr, "	                  [ promisc { on | off } ]\n");
+	fprintf(stderr, "	                  [ trailers { on | off } ]\n");
+	fprintf(stderr, "	                  [ txqueuelen PACKETS ]\n");
+	fprintf(stderr, "	                  [ name NEWNAME ]\n");
+	fprintf(stderr, "	                  [ address LLADDR ]\n");
+	fprintf(stderr, "	                  [ broadcast LLADDR ]\n");
+	fprintf(stderr, "	                  [ mtu MTU ]\n");
+	fprintf(stderr, "	                  [ netns PID ]\n");
+	fprintf(stderr, "	                  [ netns NAME ]\n");
+	fprintf(stderr, "	                  [ link-netnsid ID ]\n");
+	fprintf(stderr, "			  [ alias NAME ]\n");
+	fprintf(stderr, "	                  [ vf NUM [ mac LLADDR ]\n");
+	fprintf(stderr, "				   [ vlan VLANID [ qos VLAN-QOS ] ]\n");
+
+	fprintf(stderr, "				   [ rate TXRATE ] ]\n");
+
+	fprintf(stderr, "				   [ spoofchk { on | off} ] ]\n");
+	fprintf(stderr, "				   [ query_rss { on | off} ] ]\n");
+	fprintf(stderr, "				   [ state { auto | enable | disable} ] ]\n");
+	fprintf(stderr, "			  [ master DEVICE ]\n");
+	fprintf(stderr, "			  [ nomaster ]\n");
+	fprintf(stderr, "			  [ addrgenmode { eui64 | none | stable_secret | random } ]\n");
+	fprintf(stderr, "	                  [ protodown { on | off } ]\n");
+	fprintf(stderr, "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]\n");
 
 	if (iplink_have_newlink()) {
-		fprintf(stderr,
-			"\n"
-			"	ip link help [ TYPE ]\n"
-			"\n"
-			"TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |\n"
-			"	   bridge | bond | team | ipoib | ip6tnl | ipip | sit | vxlan |\n"
-			"	   gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan |\n"
-			"	   vti | nlmon | team_slave | bond_slave | bridge_slave |\n"
-			"	   ipvlan | ipvtap | geneve | vrf | macsec | netdevsim | rmnet |\n"
-			"	   xfrm }\n");
+		fprintf(stderr, "       ip link help [ TYPE ]\n");
+		fprintf(stderr, "\n");
+		fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
+		fprintf(stderr, "          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |\n");
+		fprintf(stderr, "          gre | gretap | ip6gre | ip6gretap | vti | nlmon |\n");
+		fprintf(stderr, "          bond_slave | ipvlan | geneve | bridge_slave | vrf }\n");
 	}
 	exit(-1);
 }
@@ -144,14 +115,15 @@
 static void *BODY;		/* cached dlopen(NULL) handle */
 static struct link_util *linkutil_list;
 
-struct link_util *get_link_kind(const char *id)
+static struct link_util *__get_link_kind(const char *id, bool slave)
 {
 	void *dlh;
 	char buf[256];
 	struct link_util *l;
 
 	for (l = linkutil_list; l; l = l->next)
-		if (strcmp(l->id, id) == 0)
+		if (strcmp(l->id, id) == 0 &&
+		    l->slave == slave)
 			return l;
 
 	snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
@@ -166,7 +138,10 @@
 		}
 	}
 
-	snprintf(buf, sizeof(buf), "%s_link_util", id);
+	if (slave)
+		snprintf(buf, sizeof(buf), "%s_slave_link_util", id);
+	else
+		snprintf(buf, sizeof(buf), "%s_link_util", id);
 	l = dlsym(dlh, buf);
 	if (l == NULL)
 		return NULL;
@@ -176,6 +151,16 @@
 	return l;
 }
 
+struct link_util *get_link_kind(const char *id)
+{
+	return __get_link_kind(id, false);
+}
+
+struct link_util *get_link_slave_kind(const char *id)
+{
+	return __get_link_kind(id, true);
+}
+
 static int get_link_mode(const char *mode)
 {
 	if (strcasecmp(mode, "default") == 0)
@@ -201,7 +186,8 @@
 #if IPLINK_IOCTL_COMPAT
 static int have_rtnl_newlink = -1;
 
-static int accept_msg(struct rtnl_ctrl_data *ctrl,
+static int accept_msg(const struct sockaddr_nl *who,
+		      struct rtnl_ctrl_data *ctrl,
 		      struct nlmsghdr *n, void *arg)
 {
 	struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(n);
@@ -220,14 +206,16 @@
 		struct nlmsghdr		n;
 		struct ifinfomsg	i;
 		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
-		.n.nlmsg_type = RTM_NEWLINK,
-		.i.ifi_family = AF_UNSPEC,
-	};
+	} req;
 
 	if (have_rtnl_newlink < 0) {
+		memset(&req, 0, sizeof(req));
+
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+		req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
+		req.n.nlmsg_type = RTM_NEWLINK;
+		req.i.ifi_family = AF_UNSPEC;
+
 		if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
 			perror("request send failed");
 			exit(1);
@@ -243,106 +231,14 @@
 }
 #endif /* ! IPLINK_IOCTL_COMPAT */
 
-static int nl_get_ll_addr_len(const char *ifname)
-{
-	int len;
-	int dev_index = ll_name_to_index(ifname);
-	struct iplink_req req = {
-		.n = {
-			.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-			.nlmsg_type = RTM_GETLINK,
-			.nlmsg_flags = NLM_F_REQUEST
-		},
-		.i = {
-			.ifi_family = preferred_family,
-			.ifi_index = dev_index,
-		}
-	};
-	struct nlmsghdr *answer;
-	struct rtattr *tb[IFLA_MAX+1];
-
-	if (dev_index == 0)
-		return -1;
-
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
-		return -1;
-
-	len = answer->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
-	if (len < 0) {
-		free(answer);
-		return -1;
-	}
-
-	parse_rtattr_flags(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)),
-			   len, NLA_F_NESTED);
-	if (!tb[IFLA_ADDRESS]) {
-		free(answer);
-		return -1;
-	}
-
-	len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
-	free(answer);
-	return len;
-}
-
-static void iplink_parse_vf_vlan_info(int vf, int *argcp, char ***argvp,
-				      struct ifla_vf_vlan_info *ivvip)
-{
-	int argc = *argcp;
-	char **argv = *argvp;
-	unsigned int vci;
-
-	NEXT_ARG();
-	if (get_unsigned(&vci, *argv, 0) || vci > 4095)
-		invarg("Invalid \"vlan\" value\n", *argv);
-
-	ivvip->vlan = vci;
-	ivvip->vf = vf;
-	ivvip->qos = 0;
-	ivvip->vlan_proto = htons(ETH_P_8021Q);
-	if (NEXT_ARG_OK()) {
-		NEXT_ARG();
-		if (matches(*argv, "qos") == 0) {
-			NEXT_ARG();
-			if (get_unsigned(&ivvip->qos, *argv, 0))
-				invarg("Invalid \"qos\" value\n", *argv);
-		} else {
-			/* rewind arg */
-			PREV_ARG();
-		}
-	}
-	if (NEXT_ARG_OK()) {
-		NEXT_ARG();
-		if (matches(*argv, "proto") == 0) {
-			NEXT_ARG();
-			if (ll_proto_a2n(&ivvip->vlan_proto, *argv))
-				invarg("protocol is invalid\n", *argv);
-			if (ivvip->vlan_proto != htons(ETH_P_8021AD) &&
-			    ivvip->vlan_proto != htons(ETH_P_8021Q)) {
-				SPRINT_BUF(b1);
-				SPRINT_BUF(b2);
-				char msg[64 + sizeof(b1) + sizeof(b2)];
-
-				sprintf(msg,
-					"Invalid \"vlan protocol\" value - supported %s, %s\n",
-					ll_proto_n2a(htons(ETH_P_8021Q),
-					     b1, sizeof(b1)),
-					ll_proto_n2a(htons(ETH_P_8021AD),
-					     b2, sizeof(b2)));
-				invarg(msg, *argv);
-			}
-		} else {
-			/* rewind arg */
-			PREV_ARG();
-		}
-	}
-
-	*argcp = argc;
-	*argvp = argv;
-}
+struct iplink_req {
+	struct nlmsghdr		n;
+	struct ifinfomsg	i;
+	char			buf[1024];
+};
 
 static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
-			   struct iplink_req *req, const char *dev)
+			   struct iplink_req *req, int dev_index)
 {
 	char new_rate_api = 0, count = 0, override_legacy_rate = 0;
 	struct ifla_vf_rate tivt;
@@ -377,58 +273,35 @@
 	while (NEXT_ARG_OK()) {
 		NEXT_ARG();
 		if (matches(*argv, "mac") == 0) {
-			struct ifla_vf_mac ivm = { 0 };
-			int halen = nl_get_ll_addr_len(dev);
+			struct ifla_vf_mac ivm;
 
 			NEXT_ARG();
 			ivm.vf = vf;
 			len = ll_addr_a2n((char *)ivm.mac, 32, *argv);
 			if (len < 0)
 				return -1;
-			if (halen > 0 && len != halen) {
-				fprintf(stderr,
-					"Invalid address length %d - must be %d bytes\n",
-					len, halen);
-				return -1;
-			}
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_MAC,
-				  &ivm, sizeof(ivm));
+			addattr_l(&req->n, sizeof(*req), IFLA_VF_MAC, &ivm, sizeof(ivm));
 		} else if (matches(*argv, "vlan") == 0) {
-			struct ifla_vf_vlan_info ivvi;
+			struct ifla_vf_vlan ivv;
 
-			iplink_parse_vf_vlan_info(vf, &argc, &argv, &ivvi);
-			/* support the old interface in case of older kernel*/
-			if (ivvi.vlan_proto == htons(ETH_P_8021Q)) {
-				struct ifla_vf_vlan ivv;
+			NEXT_ARG();
+			if (get_unsigned(&ivv.vlan, *argv, 0))
+				invarg("Invalid \"vlan\" value\n", *argv);
 
-				ivv.vf = ivvi.vf;
-				ivv.vlan = ivvi.vlan;
-				ivv.qos = ivvi.qos;
-				addattr_l(&req->n, sizeof(*req),
-					  IFLA_VF_VLAN, &ivv, sizeof(ivv));
-			} else {
-				struct rtattr *vfvlanlist;
-
-				vfvlanlist = addattr_nest(&req->n, sizeof(*req),
-							  IFLA_VF_VLAN_LIST);
-				addattr_l(&req->n, sizeof(*req),
-					  IFLA_VF_VLAN_INFO, &ivvi,
-					  sizeof(ivvi));
-
-				while (NEXT_ARG_OK()) {
+			ivv.vf = vf;
+			ivv.qos = 0;
+			if (NEXT_ARG_OK()) {
+				NEXT_ARG();
+				if (matches(*argv, "qos") == 0) {
 					NEXT_ARG();
-					if (matches(*argv, "vlan") != 0) {
-						PREV_ARG();
-						break;
-					}
-					iplink_parse_vf_vlan_info(vf, &argc,
-								  &argv, &ivvi);
-					addattr_l(&req->n, sizeof(*req),
-						  IFLA_VF_VLAN_INFO, &ivvi,
-						  sizeof(ivvi));
+					if (get_unsigned(&ivv.qos, *argv, 0))
+						invarg("Invalid \"qos\" value\n", *argv);
+				} else {
+					/* rewind arg */
+					PREV_ARG();
 				}
-				addattr_nest_end(&req->n, vfvlanlist);
 			}
+			addattr_l(&req->n, sizeof(*req), IFLA_VF_VLAN, &ivv, sizeof(ivv));
 		} else if (matches(*argv, "rate") == 0) {
 			struct ifla_vf_tx_rate ivt;
 
@@ -468,8 +341,7 @@
 			else
 				return on_off("spoofchk", *argv);
 			ivs.vf = vf;
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_SPOOFCHK,
-				  &ivs, sizeof(ivs));
+			addattr_l(&req->n, sizeof(*req), IFLA_VF_SPOOFCHK, &ivs, sizeof(ivs));
 
 		} else if (matches(*argv, "query_rss") == 0) {
 			struct ifla_vf_rss_query_en ivs;
@@ -482,22 +354,7 @@
 			else
 				return on_off("query_rss", *argv);
 			ivs.vf = vf;
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_RSS_QUERY_EN,
-				  &ivs, sizeof(ivs));
-
-		} else if (matches(*argv, "trust") == 0) {
-			struct ifla_vf_trust ivt;
-
-			NEXT_ARG();
-			if (matches(*argv, "on") == 0)
-				ivt.setting = 1;
-			else if (matches(*argv, "off") == 0)
-				ivt.setting = 0;
-			else
-				invarg("Invalid \"trust\" value\n", *argv);
-			ivt.vf = vf;
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_TRUST,
-				  &ivt, sizeof(ivt));
+			addattr_l(&req->n, sizeof(*req), IFLA_VF_RSS_QUERY_EN, &ivs, sizeof(ivs));
 
 		} else if (matches(*argv, "state") == 0) {
 			struct ifla_vf_link_state ivl;
@@ -512,30 +369,7 @@
 			else
 				invarg("Invalid \"state\" value\n", *argv);
 			ivl.vf = vf;
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_LINK_STATE,
-				  &ivl, sizeof(ivl));
-		} else if (matches(*argv, "node_guid") == 0) {
-			struct ifla_vf_guid ivg;
-
-			NEXT_ARG();
-			ivg.vf = vf;
-			if (get_guid(&ivg.guid, *argv)) {
-				invarg("Invalid GUID format\n", *argv);
-				return -1;
-			}
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_IB_NODE_GUID,
-				  &ivg, sizeof(ivg));
-		} else if (matches(*argv, "port_guid") == 0) {
-			struct ifla_vf_guid ivg;
-
-			NEXT_ARG();
-			ivg.vf = vf;
-			if (get_guid(&ivg.guid, *argv)) {
-				invarg("Invalid GUID format\n", *argv);
-				return -1;
-			}
-			addattr_l(&req->n, sizeof(*req), IFLA_VF_IB_PORT_GUID,
-				  &ivg, sizeof(ivg));
+			addattr_l(&req->n, sizeof(*req), IFLA_VF_LINK_STATE, &ivl, sizeof(ivl));
 		} else {
 			/* rewind arg */
 			PREV_ARG();
@@ -547,20 +381,12 @@
 		int tmin, tmax;
 
 		if (tivt.min_tx_rate == -1 || tivt.max_tx_rate == -1) {
-			ipaddr_get_vf_rate(tivt.vf, &tmin, &tmax, dev);
+			ipaddr_get_vf_rate(tivt.vf, &tmin, &tmax, dev_index);
 			if (tivt.min_tx_rate == -1)
 				tivt.min_tx_rate = tmin;
 			if (tivt.max_tx_rate == -1)
 				tivt.max_tx_rate = tmax;
 		}
-
-		if (tivt.max_tx_rate && tivt.min_tx_rate > tivt.max_tx_rate) {
-			fprintf(stderr,
-				"Invalid min_tx_rate %d - must be <= max_tx_rate %d\n",
-				tivt.min_tx_rate, tivt.max_tx_rate);
-			return -1;
-		}
-
 		addattr_l(&req->n, sizeof(*req), IFLA_VF_RATE, &tivt,
 			  sizeof(tivt));
 	}
@@ -575,11 +401,10 @@
 	return 0;
 }
 
-int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
+int iplink_parse(int argc, char **argv, struct iplink_req *req,
+		 char **name, char **type, char **link, char **dev,
+		 int *group, int *index)
 {
-	char *name = NULL;
-	char *dev = NULL;
-	char *link = NULL;
 	int ret, len;
 	char abuf[32];
 	int qlen = -1;
@@ -588,11 +413,10 @@
 	int vf = -1;
 	int numtxqueues = -1;
 	int numrxqueues = -1;
+	int dev_index = 0;
 	int link_netnsid = -1;
-	int index = 0;
-	int group = -1;
-	int addr_len = 0;
 
+	*group = -1;
 	ret = argc;
 
 	while (argc > 0) {
@@ -604,38 +428,28 @@
 			req->i.ifi_flags &= ~IFF_UP;
 		} else if (strcmp(*argv, "name") == 0) {
 			NEXT_ARG();
-			if (name)
-				duparg("name", *argv);
-			if (check_ifname(*argv))
-				invarg("\"name\" not a valid ifname", *argv);
-			name = *argv;
-			if (!dev)
-				dev = name;
+			*name = *argv;
 		} else if (strcmp(*argv, "index") == 0) {
 			NEXT_ARG();
-			if (index)
-				duparg("index", *argv);
-			index = atoi(*argv);
-			if (index <= 0)
+			*index = atoi(*argv);
+			if (*index < 0)
 				invarg("Invalid \"index\" value", *argv);
 		} else if (matches(*argv, "link") == 0) {
 			NEXT_ARG();
-			link = *argv;
+			*link = *argv;
 		} else if (matches(*argv, "address") == 0) {
 			NEXT_ARG();
-			addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
-			if (addr_len < 0)
+			len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
+			if (len < 0)
 				return -1;
-			addattr_l(&req->n, sizeof(*req),
-				  IFLA_ADDRESS, abuf, addr_len);
+			addattr_l(&req->n, sizeof(*req), IFLA_ADDRESS, abuf, len);
 		} else if (matches(*argv, "broadcast") == 0 ||
 			   strcmp(*argv, "brd") == 0) {
 			NEXT_ARG();
 			len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
 			if (len < 0)
 				return -1;
-			addattr_l(&req->n, sizeof(*req),
-				  IFLA_BROADCAST, abuf, len);
+			addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len);
 		} else if (matches(*argv, "txqueuelen") == 0 ||
 			   strcmp(*argv, "qlen") == 0 ||
 			   matches(*argv, "txqlen") == 0) {
@@ -644,8 +458,7 @@
 				duparg("txqueuelen", *argv);
 			if (get_integer(&qlen,  *argv, 0))
 				invarg("Invalid \"txqueuelen\" value\n", *argv);
-			addattr_l(&req->n, sizeof(*req),
-				  IFLA_TXQLEN, &qlen, 4);
+			addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4);
 		} else if (strcmp(*argv, "mtu") == 0) {
 			NEXT_ARG();
 			if (mtu != -1)
@@ -653,32 +466,15 @@
 			if (get_integer(&mtu, *argv, 0))
 				invarg("Invalid \"mtu\" value\n", *argv);
 			addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4);
-		} else if (strcmp(*argv, "xdpgeneric") == 0 ||
-			   strcmp(*argv, "xdpdrv") == 0 ||
-			   strcmp(*argv, "xdpoffload") == 0 ||
-			   strcmp(*argv, "xdp") == 0) {
-			bool generic = strcmp(*argv, "xdpgeneric") == 0;
-			bool drv = strcmp(*argv, "xdpdrv") == 0;
-			bool offload = strcmp(*argv, "xdpoffload") == 0;
-
-			NEXT_ARG();
-			if (xdp_parse(&argc, &argv, req, dev,
-				      generic, drv, offload))
-				exit(-1);
-
-			if (offload && name == dev)
-				dev = NULL;
 		} else if (strcmp(*argv, "netns") == 0) {
 			NEXT_ARG();
 			if (netns != -1)
 				duparg("netns", *argv);
 			netns = netns_get_fd(*argv);
 			if (netns >= 0)
-				addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD,
-					  &netns, 4);
+				addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4);
 			else if (get_integer(&netns, *argv, 0) == 0)
-				addattr_l(&req->n, sizeof(*req),
-					  IFLA_NET_NS_PID, &netns, 4);
+				addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
 			else
 				invarg("Invalid \"netns\" value\n", *argv);
 		} else if (strcmp(*argv, "multicast") == 0) {
@@ -731,18 +527,6 @@
 				req->i.ifi_flags |= IFF_NOARP;
 			else
 				return on_off("arp", *argv);
-		} else if (strcmp(*argv, "carrier") == 0) {
-			int carrier;
-
-			NEXT_ARG();
-			if (strcmp(*argv, "on") == 0)
-				carrier = 1;
-			else if (strcmp(*argv, "off") == 0)
-				carrier = 0;
-			else
-				return on_off("carrier", *argv);
-
-			addattr8(&req->n, sizeof(*req), IFLA_CARRIER, carrier);
 		} else if (strcmp(*argv, "vf") == 0) {
 			struct rtattr *vflist;
 
@@ -752,16 +536,13 @@
 
 			vflist = addattr_nest(&req->n, sizeof(*req),
 					      IFLA_VFINFO_LIST);
-			if (!dev)
+			if (dev_index == 0)
 				missarg("dev");
 
-			len = iplink_parse_vf(vf, &argc, &argv, req, dev);
+			len = iplink_parse_vf(vf, &argc, &argv, req, dev_index);
 			if (len < 0)
 				return -1;
 			addattr_nest_end(&req->n, vflist);
-
-			if (name == dev)
-				dev = NULL;
 		} else if (matches(*argv, "master") == 0) {
 			int ifindex;
 
@@ -771,17 +552,6 @@
 				invarg("Device does not exist\n", *argv);
 			addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
 				  &ifindex, 4);
-		} else if (strcmp(*argv, "vrf") == 0) {
-			int ifindex;
-
-			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
-			if (!ifindex)
-				invarg("Not a valid VRF name\n", *argv);
-			if (!name_is_vrf(*argv))
-				invarg("Not a valid VRF name\n", *argv);
-			addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
-				  &ifindex, sizeof(ifindex));
 		} else if (matches(*argv, "nomaster") == 0) {
 			int ifindex = 0;
 
@@ -804,18 +574,16 @@
 			break;
 		} else if (matches(*argv, "alias") == 0) {
 			NEXT_ARG();
-			len = strlen(*argv);
-			if (len >= IFALIASZ)
-				invarg("alias too long\n", *argv);
 			addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS,
-				  *argv, len);
+				  *argv, strlen(*argv));
+			argc--; argv++;
+			break;
 		} else if (strcmp(*argv, "group") == 0) {
 			NEXT_ARG();
-			if (group != -1)
+			if (*group != -1)
 				duparg("group", *argv);
-			if (rtnl_group_a2n(&group, *argv))
+			if (rtnl_group_a2n(group, *argv))
 				invarg("Invalid \"group\" value\n", *argv);
-			addattr32(&req->n, sizeof(*req), IFLA_GROUP, group);
 		} else if (strcmp(*argv, "mode") == 0) {
 			int mode;
 
@@ -838,8 +606,7 @@
 			if (numtxqueues != -1)
 				duparg("numtxqueues", *argv);
 			if (get_integer(&numtxqueues, *argv, 0))
-				invarg("Invalid \"numtxqueues\" value\n",
-				       *argv);
+				invarg("Invalid \"numtxqueues\" value\n", *argv);
 			addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES,
 				  &numtxqueues, 4);
 		} else if (matches(*argv, "numrxqueues") == 0) {
@@ -847,8 +614,7 @@
 			if (numrxqueues != -1)
 				duparg("numrxqueues", *argv);
 			if (get_integer(&numrxqueues, *argv, 0))
-				invarg("Invalid \"numrxqueues\" value\n",
-				       *argv);
+				invarg("Invalid \"numrxqueues\" value\n", *argv);
 			addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES,
 				  &numrxqueues, 4);
 		} else if (matches(*argv, "addrgenmode") == 0) {
@@ -858,35 +624,18 @@
 			NEXT_ARG();
 			mode = get_addr_gen_mode(*argv);
 			if (mode < 0)
-				invarg("Invalid address generation mode\n",
-				       *argv);
+				invarg("Invalid address generation mode\n", *argv);
 			afs = addattr_nest(&req->n, sizeof(*req), IFLA_AF_SPEC);
 			afs6 = addattr_nest(&req->n, sizeof(*req), AF_INET6);
-			addattr8(&req->n, sizeof(*req),
-				 IFLA_INET6_ADDR_GEN_MODE, mode);
+			addattr8(&req->n, sizeof(*req), IFLA_INET6_ADDR_GEN_MODE, mode);
 			addattr_nest_end(&req->n, afs6);
 			addattr_nest_end(&req->n, afs);
-		} else if (matches(*argv, "link-netns") == 0) {
-			NEXT_ARG();
-			if (link_netnsid != -1)
-				duparg("link-netns/link-netnsid", *argv);
-			link_netnsid = get_netnsid_from_name(*argv);
-			/* No nsid? Try to assign one. */
-			if (link_netnsid < 0)
-				set_netnsid_from_name(*argv, -1);
-			link_netnsid = get_netnsid_from_name(*argv);
-			if (link_netnsid < 0)
-				invarg("Invalid \"link-netns\" value\n",
-				       *argv);
-			addattr32(&req->n, sizeof(*req), IFLA_LINK_NETNSID,
-				  link_netnsid);
 		} else if (matches(*argv, "link-netnsid") == 0) {
 			NEXT_ARG();
 			if (link_netnsid != -1)
-				duparg("link-netns/link-netnsid", *argv);
+				duparg("link-netnsid", *argv);
 			if (get_integer(&link_netnsid, *argv, 0))
-				invarg("Invalid \"link-netnsid\" value\n",
-				       *argv);
+				invarg("Invalid \"link-netnsid\" value\n", *argv);
 			addattr32(&req->n, sizeof(*req), IFLA_LINK_NETNSID,
 				  link_netnsid);
 		} else if (strcmp(*argv, "protodown") == 0) {
@@ -901,167 +650,148 @@
 				return on_off("protodown", *argv);
 			addattr8(&req->n, sizeof(*req), IFLA_PROTO_DOWN,
 				 proto_down);
-		} else if (strcmp(*argv, "gso_max_size") == 0) {
-			unsigned int max_size;
-
-			NEXT_ARG();
-			if (get_unsigned(&max_size, *argv, 0) ||
-			    max_size > GSO_MAX_SIZE)
-				invarg("Invalid \"gso_max_size\" value\n",
-				       *argv);
-			addattr32(&req->n, sizeof(*req),
-				  IFLA_GSO_MAX_SIZE, max_size);
-		} else if (strcmp(*argv, "gso_max_segs") == 0) {
-			unsigned int max_segs;
-
-			NEXT_ARG();
-			if (get_unsigned(&max_segs, *argv, 0) ||
-			    max_segs > GSO_MAX_SEGS)
-				invarg("Invalid \"gso_max_segs\" value\n",
-				       *argv);
-			addattr32(&req->n, sizeof(*req),
-				  IFLA_GSO_MAX_SEGS, max_segs);
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
 
 			if (strcmp(*argv, "dev") == 0)
 				NEXT_ARG();
-			if (dev != name)
+			if (*dev)
 				duparg2("dev", *argv);
-			if (check_ifname(*argv))
-				invarg("\"dev\" not a valid ifname", *argv);
-			dev = *argv;
+			*dev = *argv;
+			dev_index = ll_name_to_index(*dev);
 		}
 		argc--; argv++;
 	}
 
-	ret -= argc;
+	return ret - argc;
+}
 
-	/* Allow "ip link add dev" and "ip link add name" */
-	if (!name)
-		name = dev;
-	else if (!dev)
-		dev = name;
-	else if (!strcmp(name, dev))
-		name = dev;
+static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
+{
+	int len;
+	char *dev = NULL;
+	char *name = NULL;
+	char *link = NULL;
+	char *type = NULL;
+	int index = -1;
+	int group;
+	struct link_util *lu = NULL;
+	struct iplink_req req;
+	int ret;
 
-	if (dev && addr_len &&
-	    !(req->n.nlmsg_flags & NLM_F_CREATE)) {
-		int halen = nl_get_ll_addr_len(dev);
+	memset(&req, 0, sizeof(req));
 
-		if (halen >= 0 && halen != addr_len) {
-			fprintf(stderr,
-				"Invalid address length %d - must be %d bytes\n",
-				addr_len, halen);
-			return -1;
-		}
-	}
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.i.ifi_family = preferred_family;
 
-	if (!(req->n.nlmsg_flags & NLM_F_CREATE) && index) {
-		fprintf(stderr,
-			"index can be used only when creating devices.\n");
-		exit(-1);
-	}
+	ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev, &group, &index);
+	if (ret < 0)
+		return ret;
+
+	argc -= ret;
+	argv += ret;
 
 	if (group != -1) {
-		if (!dev) {
+		if (dev)
+			addattr_l(&req.n, sizeof(req), IFLA_GROUP,
+					&group, sizeof(group));
+		else {
 			if (argc) {
-				fprintf(stderr,
-					"Garbage instead of arguments \"%s ...\". Try \"ip link help\".\n",
-					*argv);
-				exit(-1);
+				fprintf(stderr, "Garbage instead of arguments "
+						"\"%s ...\". Try \"ip link "
+						"help\".\n", *argv);
+				return -1;
 			}
-			if (req->n.nlmsg_flags & NLM_F_CREATE) {
-				fprintf(stderr,
-					"group cannot be used when creating devices.\n");
-				exit(-1);
+			if (flags & NLM_F_CREATE) {
+				fprintf(stderr, "group cannot be used when "
+						"creating devices.\n");
+				return -1;
 			}
 
-			*type = NULL;
-			return ret;
+			req.i.ifi_index = 0;
+			addattr32(&req.n, sizeof(req), IFLA_GROUP, group);
+			if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+				return -2;
+			return 0;
 		}
 	}
 
-	if (!(req->n.nlmsg_flags & NLM_F_CREATE)) {
+	if (!(flags & NLM_F_CREATE)) {
 		if (!dev) {
-			fprintf(stderr,
-				"Not enough information: \"dev\" argument is required.\n");
+			fprintf(stderr, "Not enough information: \"dev\" "
+					"argument is required.\n");
+			exit(-1);
+		}
+		if (cmd == RTM_NEWLINK && index != -1) {
+			fprintf(stderr, "index can be used only when "
+					"creating devices.\n");
 			exit(-1);
 		}
 
-		req->i.ifi_index = ll_name_to_index(dev);
-		if (!req->i.ifi_index)
-			return nodev(dev);
-
-		/* Not renaming to the same name */
-		if (name == dev)
-			name = NULL;
+		req.i.ifi_index = ll_name_to_index(dev);
+		if (req.i.ifi_index == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", dev);
+			return -1;
+		}
 	} else {
-		if (name != dev) {
-			fprintf(stderr,
-				"both \"name\" and \"dev\" cannot be used when creating devices.\n");
-			exit(-1);
-		}
+		/* Allow "ip link add dev" and "ip link add name" */
+		if (!name)
+			name = dev;
 
 		if (link) {
 			int ifindex;
 
 			ifindex = ll_name_to_index(link);
-			if (!ifindex)
-				return nodev(link);
-			addattr32(&req->n, sizeof(*req), IFLA_LINK, ifindex);
+			if (ifindex == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n",
+					link);
+				return -1;
+			}
+			addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifindex, 4);
 		}
 
-		req->i.ifi_index = index;
+		if (index == -1)
+			req.i.ifi_index = 0;
+		else
+			req.i.ifi_index = index;
 	}
 
 	if (name) {
-		addattr_l(&req->n, sizeof(*req),
-			  IFLA_IFNAME, name, strlen(name) + 1);
+		len = strlen(name) + 1;
+		if (len == 1)
+			invarg("\"\" is not a valid device identifier\n", "name");
+		if (len > IFNAMSIZ)
+			invarg("\"name\" too long\n", name);
+		addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, len);
 	}
 
-	return ret;
-}
-
-static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
-{
-	char *type = NULL;
-	struct iplink_req req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.i.ifi_family = preferred_family,
-	};
-	int ret;
-
-	ret = iplink_parse(argc, argv, &req, &type);
-	if (ret < 0)
-		return ret;
-
 	if (type) {
-		struct link_util *lu;
 		struct rtattr *linkinfo;
-		char *ulinep = strchr(type, '_');
+		char slavebuf[128], *ulinep = strchr(type, '_');
 		int iflatype;
 
 		linkinfo = addattr_nest(&req.n, sizeof(req), IFLA_LINKINFO);
 		addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type,
 			 strlen(type));
 
-		lu = get_link_kind(type);
-		if (ulinep && !strcmp(ulinep, "_slave"))
+		if (ulinep && !strcmp(ulinep, "_slave")) {
+			strncpy(slavebuf, type, sizeof(slavebuf));
+			slavebuf[sizeof(slavebuf) - 1] = '\0';
+			ulinep = strchr(slavebuf, '_');
+			/* check in case it was after sizeof(slavebuf) - 1*/
+			if (ulinep)
+				*ulinep = '\0';
+			lu = get_link_slave_kind(slavebuf);
 			iflatype = IFLA_INFO_SLAVE_DATA;
-		else
+		} else {
+			lu = get_link_kind(type);
 			iflatype = IFLA_INFO_DATA;
-
-		argc -= ret;
-		argv += ret;
-
+		}
 		if (lu && argc) {
-			struct rtattr *data;
-
-			data = addattr_nest(&req.n, sizeof(req), iflatype);
+			struct rtattr *data = addattr_nest(&req.n, sizeof(req), iflatype);
 
 			if (lu->parse_opt &&
 			    lu->parse_opt(lu, argc, argv, &req.n))
@@ -1071,51 +801,58 @@
 		} else if (argc) {
 			if (matches(*argv, "help") == 0)
 				usage();
-			fprintf(stderr,
-				"Garbage instead of arguments \"%s ...\". Try \"ip link help\".\n",
-				*argv);
+			fprintf(stderr, "Garbage instead of arguments \"%s ...\". "
+					"Try \"ip link help\".\n", *argv);
 			return -1;
 		}
 		addattr_nest_end(&req.n, linkinfo);
 	} else if (flags & NLM_F_CREATE) {
-		fprintf(stderr,
-			"Not enough information: \"type\" argument is required\n");
+		fprintf(stderr, "Not enough information: \"type\" argument "
+				"is required\n");
 		return -1;
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -2;
 
-	/* remove device from cache; next use can refresh with new data */
-	ll_drop_by_index(req.i.ifi_index);
-
 	return 0;
 }
 
-int iplink_get(char *name, __u32 filt_mask)
+int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
 {
-	struct iplink_req req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-	};
-	struct nlmsghdr *answer;
+	int len;
+	struct iplink_req req;
+	struct {
+		struct nlmsghdr n;
+		char buf[16384];
+	} answer;
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = RTM_GETLINK;
+	req.i.ifi_family = preferred_family;
 
 	if (name) {
-		addattr_l(&req.n, sizeof(req),
-			  IFLA_IFNAME, name, strlen(name) + 1);
+		len = strlen(name) + 1;
+		if (len == 1)
+			invarg("\"\" is not a valid device identifier\n",
+				   "name");
+		if (len > IFNAMSIZ)
+			invarg("\"name\" too long\n", name);
+		addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, len);
 	}
 	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk(&rth, &req.n, &answer.n, sizeof(answer)) < 0)
 		return -2;
 
-	open_json_object(NULL);
-	print_linkinfo(answer, stdout);
-	close_json_object();
+	if (brief)
+		print_linkinfo_brief(NULL, &answer.n, stdout);
+	else
+		print_linkinfo(NULL, &answer.n, stdout);
 
-	free(answer);
 	return 0;
 }
 
@@ -1146,7 +883,7 @@
 	int fd;
 	int err;
 
-	strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
+	strncpy(ifr.ifr_name, dev, IFNAMSIZ);
 	fd = get_ctl_fd();
 	if (fd < 0)
 		return -1;
@@ -1173,8 +910,8 @@
 	int fd;
 	int err;
 
-	strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
-	strlcpy(ifr.ifr_newname, newdev, IFNAMSIZ);
+	strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+	strncpy(ifr.ifr_newname, newdev, IFNAMSIZ);
 	fd = get_ctl_fd();
 	if (fd < 0)
 		return -1;
@@ -1190,14 +927,16 @@
 
 static int set_qlen(const char *dev, int qlen)
 {
-	struct ifreq ifr = { .ifr_qlen = qlen };
+	struct ifreq ifr;
 	int s;
 
 	s = get_ctl_fd();
 	if (s < 0)
 		return -1;
 
-	strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+	ifr.ifr_qlen = qlen;
 	if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
 		perror("SIOCSIFXQLEN");
 		close(s);
@@ -1210,14 +949,16 @@
 
 static int set_mtu(const char *dev, int mtu)
 {
-	struct ifreq ifr = { .ifr_mtu = mtu };
+	struct ifreq ifr;
 	int s;
 
 	s = get_ctl_fd();
 	if (s < 0)
 		return -1;
 
-	strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+	ifr.ifr_mtu = mtu;
 	if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
 		perror("SIOCSIFMTU");
 		close(s);
@@ -1230,11 +971,8 @@
 
 static int get_address(const char *dev, int *htype)
 {
-	struct ifreq ifr = {};
-	struct sockaddr_ll me = {
-		.sll_family = AF_PACKET,
-		.sll_protocol = htons(ETH_P_LOOP),
-	};
+	struct ifreq ifr;
+	struct sockaddr_ll me;
 	socklen_t alen;
 	int s;
 
@@ -1244,14 +982,18 @@
 		return -1;
 	}
 
-	strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, dev, IFNAMSIZ);
 	if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
 		perror("SIOCGIFINDEX");
 		close(s);
 		return -1;
 	}
 
+	memset(&me, 0, sizeof(me));
+	me.sll_family = AF_PACKET;
 	me.sll_ifindex = ifr.ifr_ifindex;
+	me.sll_protocol = htons(ETH_P_LOOP);
 	if (bind(s, (struct sockaddr *)&me, sizeof(me)) == -1) {
 		perror("bind");
 		close(s);
@@ -1275,15 +1017,13 @@
 	int alen;
 
 	memset(ifr, 0, sizeof(*ifr));
-	strlcpy(ifr->ifr_name, dev, IFNAMSIZ);
+	strncpy(ifr->ifr_name, dev, IFNAMSIZ);
 	ifr->ifr_hwaddr.sa_family = hatype;
 	alen = ll_addr_a2n(ifr->ifr_hwaddr.sa_data, 14, lla);
 	if (alen < 0)
 		return -1;
 	if (alen != halen) {
-		fprintf(stderr,
-			"Wrong address (%s) length: expected %d bytes\n",
-			lla, halen);
+		fprintf(stderr, "Wrong address (%s) length: expected %d bytes\n", lla, halen);
 		return -1;
 	}
 	return 0;
@@ -1327,8 +1067,6 @@
 			flags &= ~IFF_UP;
 		} else if (strcmp(*argv, "name") == 0) {
 			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"name\" not a valid ifname", *argv);
 			newname = *argv;
 		} else if (matches(*argv, "address") == 0) {
 			NEXT_ARG();
@@ -1419,16 +1157,13 @@
 
 			if (dev)
 				duparg2("dev", *argv);
-			if (check_ifname(*argv))
-				invarg("\"dev\" not a valid ifname", *argv);
 			dev = *argv;
 		}
 		argc--; argv++;
 	}
 
 	if (!dev) {
-		fprintf(stderr,
-			"Not enough of information: \"dev\" argument is required.\n");
+		fprintf(stderr, "Not enough of information: \"dev\" argument is required.\n");
 		exit(-1);
 	}
 
@@ -1437,18 +1172,18 @@
 		if (halen < 0)
 			return -1;
 		if (newaddr) {
-			if (parse_address(dev, htype, halen,
-					  newaddr, &ifr0) < 0)
+			if (parse_address(dev, htype, halen, newaddr, &ifr0) < 0)
 				return -1;
 		}
 		if (newbrd) {
-			if (parse_address(dev, htype, halen,
-					  newbrd, &ifr1) < 0)
+			if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0)
 				return -1;
 		}
 	}
 
 	if (newname && strcmp(dev, newname)) {
+		if (strlen(newname) == 0)
+			invarg("\"\" is not a valid device identifier\n", "name");
 		if (do_changename(dev, newname) < 0)
 			return -1;
 		dev = newname;
@@ -1477,146 +1212,6 @@
 }
 #endif /* IPLINK_IOCTL_COMPAT */
 
-static void print_mpls_stats(FILE *fp, struct rtattr *attr)
-{
-	struct rtattr *mrtb[MPLS_STATS_MAX+1];
-	struct mpls_link_stats *stats;
-
-	parse_rtattr(mrtb, MPLS_STATS_MAX, RTA_DATA(attr),
-		     RTA_PAYLOAD(attr));
-	if (!mrtb[MPLS_STATS_LINK])
-		return;
-
-	stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
-
-	fprintf(fp, "    mpls:\n");
-	fprintf(fp, "        RX: bytes  packets  errors  dropped  noroute\n");
-	fprintf(fp, "        ");
-	print_num(fp, 10, stats->rx_bytes);
-	print_num(fp, 8, stats->rx_packets);
-	print_num(fp, 7, stats->rx_errors);
-	print_num(fp, 8, stats->rx_dropped);
-	print_num(fp, 7, stats->rx_noroute);
-	fprintf(fp, "\n");
-	fprintf(fp, "        TX: bytes  packets  errors  dropped\n");
-	fprintf(fp, "        ");
-	print_num(fp, 10, stats->tx_bytes);
-	print_num(fp, 8, stats->tx_packets);
-	print_num(fp, 7, stats->tx_errors);
-	print_num(fp, 7, stats->tx_dropped);
-	fprintf(fp, "\n");
-}
-
-static void print_af_stats_attr(FILE *fp, int ifindex, struct rtattr *attr)
-{
-	bool if_printed = false;
-	struct rtattr *i;
-	int rem;
-
-	rem = RTA_PAYLOAD(attr);
-	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		if (preferred_family != AF_UNSPEC &&
-		    i->rta_type != preferred_family)
-			continue;
-
-		if (!if_printed) {
-			fprintf(fp, "%u: %s\n", ifindex,
-				ll_index_to_name(ifindex));
-			if_printed = true;
-		}
-
-		switch (i->rta_type) {
-		case AF_MPLS:
-			print_mpls_stats(fp, i);
-			break;
-		default:
-			fprintf(fp, "    unknown af(%d)\n", i->rta_type);
-			break;
-		}
-	}
-}
-
-struct af_stats_ctx {
-	FILE *fp;
-	int ifindex;
-};
-
-static int print_af_stats(struct nlmsghdr *n, void *arg)
-{
-	struct if_stats_msg *ifsm = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_STATS_MAX+1];
-	int len = n->nlmsg_len;
-	struct af_stats_ctx *ctx = arg;
-	FILE *fp = ctx->fp;
-
-	len -= NLMSG_LENGTH(sizeof(*ifsm));
-	if (len < 0) {
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-
-	if (ctx->ifindex && ifsm->ifindex != ctx->ifindex)
-		return 0;
-
-	parse_rtattr(tb, IFLA_STATS_MAX, IFLA_STATS_RTA(ifsm), len);
-
-	if (tb[IFLA_STATS_AF_SPEC])
-		print_af_stats_attr(fp, ifsm->ifindex, tb[IFLA_STATS_AF_SPEC]);
-
-	fflush(fp);
-	return 0;
-}
-
-static int iplink_afstats(int argc, char **argv)
-{
-	__u32 filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_AF_SPEC);
-	const char *filter_dev = NULL;
-	struct af_stats_ctx ctx = {
-		.fp = stdout,
-		.ifindex = 0,
-	};
-
-	while (argc > 0) {
-		if (strcmp(*argv, "dev") == 0) {
-			NEXT_ARG();
-			if (filter_dev)
-				duparg2("dev", *argv);
-			filter_dev = *argv;
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			fprintf(stderr,
-				"Command \"%s\" is unknown, try \"ip link help\".\n",
-				*argv);
-			exit(-1);
-		}
-
-		argv++; argc--;
-	}
-
-	if (filter_dev) {
-		ctx.ifindex = ll_name_to_index(filter_dev);
-		if (ctx.ifindex <= 0) {
-			fprintf(stderr,
-				"Device \"%s\" does not exist.\n",
-				filter_dev);
-			return -1;
-		}
-	}
-
-	if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
-		perror("Cannont send dump request");
-		return 1;
-	}
-
-	if (rtnl_dump_filter(&rth, print_af_stats, &ctx) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return 1;
-	}
-
-	return 0;
-}
-
 static void do_help(int argc, char **argv)
 {
 	struct link_util *lu = NULL;
@@ -1666,14 +1261,6 @@
 	    matches(*argv, "list") == 0)
 		return ipaddr_list_link(argc-1, argv+1);
 
-	if (matches(*argv, "xstats") == 0)
-		return iplink_ifla_xstats(argc-1, argv+1);
-
-	if (matches(*argv, "afstats") == 0) {
-		iplink_afstats(argc-1, argv+1);
-		return 0;
-	}
-
 	if (matches(*argv, "help") == 0) {
 		do_help(argc-1, argv+1);
 		return 0;
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 585b6be..cb2f045 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -13,18 +13,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <linux/if_bonding.h>
+#include <linux/if_link.h>
+#include <linux/if_ether.h>
+#include <net/if.h>
 
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 #define BOND_MAX_ARP_TARGETS    16
 
-static unsigned int xstats_print_attr;
-static int filter_index;
-
 static const char *mode_tbl[] = {
 	"balance-rr",
 	"active-backup",
@@ -120,7 +118,6 @@
 		"Usage: ... bond [ mode BONDMODE ] [ active_slave SLAVE_DEV ]\n"
 		"                [ clear_active_slave ] [ miimon MIIMON ]\n"
 		"                [ updelay UPDELAY ] [ downdelay DOWNDELAY ]\n"
-		"                [ peer_notify_delay DELAY ]\n"
 		"                [ use_carrier USE_CARRIER ]\n"
 		"                [ arp_interval ARP_INTERVAL ]\n"
 		"                [ arp_validate ARP_VALIDATE ]\n"
@@ -136,7 +133,7 @@
 		"                [ min_links MIN_LINKS ]\n"
 		"                [ lp_interval LP_INTERVAL ]\n"
 		"                [ packets_per_slave PACKETS_PER_SLAVE ]\n"
-		"                [ tlb_dynamic_lb TLB_DYNAMIC_LB ]\n"
+		"		 [ tlb_dynamic_lb TLB_DYNAMIC_LB ]\n"
 		"                [ lacp_rate LACP_RATE ]\n"
 		"                [ ad_select AD_SELECT ]\n"
 		"                [ ad_user_port_key PORTKEY ]\n"
@@ -166,10 +163,10 @@
 	__u8 xmit_hash_policy, num_peer_notif, all_slaves_active;
 	__u8 lacp_rate, ad_select, tlb_dynamic_lb;
 	__u16 ad_user_port_key, ad_actor_sys_prio;
-	__u32 miimon, updelay, downdelay, peer_notify_delay, arp_interval, arp_validate;
+	__u32 miimon, updelay, downdelay, arp_interval, arp_validate;
 	__u32 arp_all_targets, resend_igmp, min_links, lp_interval;
 	__u32 packets_per_slave;
-	unsigned int ifindex;
+	unsigned ifindex;
 
 	while (argc > 0) {
 		if (matches(*argv, "mode") == 0) {
@@ -180,9 +177,9 @@
 			addattr8(n, 1024, IFLA_BOND_MODE, mode);
 		} else if (matches(*argv, "active_slave") == 0) {
 			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
+			ifindex = if_nametoindex(*argv);
 			if (!ifindex)
-				return nodev(*argv);
+				return -1;
 			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
 		} else if (matches(*argv, "clear_active_slave") == 0) {
 			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);
@@ -201,11 +198,6 @@
 			if (get_u32(&downdelay, *argv, 0))
 				invarg("invalid downdelay", *argv);
 			addattr32(n, 1024, IFLA_BOND_DOWNDELAY, downdelay);
-		} else if (matches(*argv, "peer_notify_delay") == 0) {
-			NEXT_ARG();
-			if (get_u32(&peer_notify_delay, *argv, 0))
-				invarg("invalid peer_notify_delay", *argv);
-			addattr32(n, 1024, IFLA_BOND_PEER_NOTIF_DELAY, peer_notify_delay);
 		} else if (matches(*argv, "use_carrier") == 0) {
 			NEXT_ARG();
 			if (get_u8(&use_carrier, *argv, 0))
@@ -217,7 +209,7 @@
 				invarg("invalid arp_interval", *argv);
 			addattr32(n, 1024, IFLA_BOND_ARP_INTERVAL, arp_interval);
 		} else if (matches(*argv, "arp_ip_target") == 0) {
-			struct rtattr *nest = addattr_nest(n, 1024,
+			struct rtattr * nest = addattr_nest(n, 1024,
 				IFLA_BOND_ARP_IP_TARGET);
 			if (NEXT_ARG_OK()) {
 				NEXT_ARG();
@@ -225,9 +217,8 @@
 				char *target = strtok(targets, ",");
 				int i;
 
-				for (i = 0; target && i < BOND_MAX_ARP_TARGETS; i++) {
+				for(i = 0; target && i < BOND_MAX_ARP_TARGETS; i++) {
 					__u32 addr = get_addr32(target);
-
 					addattr32(n, 1024, i, addr);
 					target = strtok(NULL, ",");
 				}
@@ -248,9 +239,9 @@
 			addattr32(n, 1024, IFLA_BOND_ARP_ALL_TARGETS, arp_all_targets);
 		} else if (matches(*argv, "primary") == 0) {
 			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
+			ifindex = if_nametoindex(*argv);
 			if (!ifindex)
-				return nodev(*argv);
+				return -1;
 			addattr32(n, 1024, IFLA_BOND_PRIMARY, ifindex);
 		} else if (matches(*argv, "primary_reselect") == 0) {
 			NEXT_ARG();
@@ -377,455 +368,216 @@
 
 static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	unsigned ifindex;
+
 	if (!tb)
 		return;
 
 	if (tb[IFLA_BOND_MODE]) {
 		const char *mode = get_name(mode_tbl,
-					    rta_getattr_u8(tb[IFLA_BOND_MODE]));
-		print_string(PRINT_ANY, "mode", "mode %s ", mode);
+			rta_getattr_u8(tb[IFLA_BOND_MODE]));
+		fprintf(f, "mode %s ", mode);
 	}
 
-	if (tb[IFLA_BOND_ACTIVE_SLAVE]) {
-		unsigned int ifindex =
-			rta_getattr_u32(tb[IFLA_BOND_ACTIVE_SLAVE]);
+	if (tb[IFLA_BOND_ACTIVE_SLAVE] &&
+	    (ifindex = rta_getattr_u32(tb[IFLA_BOND_ACTIVE_SLAVE]))) {
+		char buf[IFNAMSIZ];
+		const char *n = if_indextoname(ifindex, buf);
 
-		if (ifindex) {
-			print_string(PRINT_ANY,
-				     "active_slave",
-				     "active_slave %s ",
-				     ll_index_to_name(ifindex));
-		}
+		if (n)
+			fprintf(f, "active_slave %s ", n);
+		else
+			fprintf(f, "active_slave %u ", ifindex);
 	}
 
 	if (tb[IFLA_BOND_MIIMON])
-		print_uint(PRINT_ANY,
-			   "miimon",
-			   "miimon %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_MIIMON]));
+		fprintf(f, "miimon %u ", rta_getattr_u32(tb[IFLA_BOND_MIIMON]));
 
 	if (tb[IFLA_BOND_UPDELAY])
-		print_uint(PRINT_ANY,
-			   "updelay",
-			   "updelay %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_UPDELAY]));
+		fprintf(f, "updelay %u ", rta_getattr_u32(tb[IFLA_BOND_UPDELAY]));
 
 	if (tb[IFLA_BOND_DOWNDELAY])
-		print_uint(PRINT_ANY,
-			   "downdelay",
-			   "downdelay %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_DOWNDELAY]));
-
-	if (tb[IFLA_BOND_PEER_NOTIF_DELAY])
-		print_uint(PRINT_ANY,
-			   "peer_notify_delay",
-			   "peer_notify_delay %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_PEER_NOTIF_DELAY]));
+		fprintf(f, "downdelay %u ",
+			rta_getattr_u32(tb[IFLA_BOND_DOWNDELAY]));
 
 	if (tb[IFLA_BOND_USE_CARRIER])
-		print_uint(PRINT_ANY,
-			   "use_carrier",
-			   "use_carrier %u ",
-			   rta_getattr_u8(tb[IFLA_BOND_USE_CARRIER]));
+		fprintf(f, "use_carrier %u ",
+			rta_getattr_u8(tb[IFLA_BOND_USE_CARRIER]));
 
 	if (tb[IFLA_BOND_ARP_INTERVAL])
-		print_uint(PRINT_ANY,
-			   "arp_interval",
-			   "arp_interval %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_ARP_INTERVAL]));
+		fprintf(f, "arp_interval %u ",
+			rta_getattr_u32(tb[IFLA_BOND_ARP_INTERVAL]));
 
 	if (tb[IFLA_BOND_ARP_IP_TARGET]) {
 		struct rtattr *iptb[BOND_MAX_ARP_TARGETS + 1];
+		char buf[INET_ADDRSTRLEN];
 		int i;
 
 		parse_rtattr_nested(iptb, BOND_MAX_ARP_TARGETS,
-				    tb[IFLA_BOND_ARP_IP_TARGET]);
+			tb[IFLA_BOND_ARP_IP_TARGET]);
 
-		if (iptb[0]) {
-			open_json_array(PRINT_JSON, "arp_ip_target");
-			print_string(PRINT_FP, NULL, "arp_ip_target ", NULL);
-		}
+		if (iptb[0])
+			fprintf(f, "arp_ip_target ");
 
 		for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
 			if (iptb[i])
-				print_string(PRINT_ANY,
-					     NULL,
-					     "%s",
-					     rt_addr_n2a_rta(AF_INET, iptb[i]));
-			if (!is_json_context()
-			    && i < BOND_MAX_ARP_TARGETS-1
-			    && iptb[i+1])
+				fprintf(f, "%s",
+					rt_addr_n2a(AF_INET,
+						    RTA_PAYLOAD(iptb[i]),
+						    RTA_DATA(iptb[i]),
+						    buf,
+						    INET_ADDRSTRLEN));
+			if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
 				fprintf(f, ",");
 		}
 
-		if (iptb[0]) {
-			print_string(PRINT_FP, NULL, " ", NULL);
-			close_json_array(PRINT_JSON, NULL);
-		}
+		if (iptb[0])
+			fprintf(f, " ");
 	}
 
 	if (tb[IFLA_BOND_ARP_VALIDATE]) {
-		__u32 arp_v = rta_getattr_u32(tb[IFLA_BOND_ARP_VALIDATE]);
-		const char *arp_validate = get_name(arp_validate_tbl, arp_v);
-
-		if (!arp_v && is_json_context())
-			print_null(PRINT_JSON, "arp_validate", NULL, NULL);
-		else
-			print_string(PRINT_ANY,
-				     "arp_validate",
-				     "arp_validate %s ",
-				     arp_validate);
+		const char *arp_validate = get_name(arp_validate_tbl,
+			rta_getattr_u32(tb[IFLA_BOND_ARP_VALIDATE]));
+		fprintf(f, "arp_validate %s ", arp_validate);
 	}
 
 	if (tb[IFLA_BOND_ARP_ALL_TARGETS]) {
 		const char *arp_all_targets = get_name(arp_all_targets_tbl,
-						       rta_getattr_u32(tb[IFLA_BOND_ARP_ALL_TARGETS]));
-		print_string(PRINT_ANY,
-			     "arp_all_targets",
-			     "arp_all_targets %s ",
-			     arp_all_targets);
+			rta_getattr_u32(tb[IFLA_BOND_ARP_ALL_TARGETS]));
+		fprintf(f, "arp_all_targets %s ", arp_all_targets);
 	}
 
-	if (tb[IFLA_BOND_PRIMARY]) {
-		unsigned int ifindex = rta_getattr_u32(tb[IFLA_BOND_PRIMARY]);
+	if (tb[IFLA_BOND_PRIMARY] &&
+	    (ifindex = rta_getattr_u32(tb[IFLA_BOND_PRIMARY]))) {
+		char buf[IFNAMSIZ];
+		const char *n = if_indextoname(ifindex, buf);
 
-		if (ifindex) {
-			print_string(PRINT_ANY,
-				     "primary",
-				     "primary %s ",
-				     ll_index_to_name(ifindex));
-		}
+		if (n)
+			fprintf(f, "primary %s ", n);
+		else
+			fprintf(f, "primary %u ", ifindex);
 	}
 
 	if (tb[IFLA_BOND_PRIMARY_RESELECT]) {
 		const char *primary_reselect = get_name(primary_reselect_tbl,
-							rta_getattr_u8(tb[IFLA_BOND_PRIMARY_RESELECT]));
-		print_string(PRINT_ANY,
-			     "primary_reselect",
-			     "primary_reselect %s ",
-			     primary_reselect);
+			rta_getattr_u8(tb[IFLA_BOND_PRIMARY_RESELECT]));
+		fprintf(f, "primary_reselect %s ", primary_reselect);
 	}
 
 	if (tb[IFLA_BOND_FAIL_OVER_MAC]) {
 		const char *fail_over_mac = get_name(fail_over_mac_tbl,
-						     rta_getattr_u8(tb[IFLA_BOND_FAIL_OVER_MAC]));
-		print_string(PRINT_ANY,
-			     "fail_over_mac",
-			     "fail_over_mac %s ",
-			     fail_over_mac);
+			rta_getattr_u8(tb[IFLA_BOND_FAIL_OVER_MAC]));
+		fprintf(f, "fail_over_mac %s ", fail_over_mac);
 	}
 
 	if (tb[IFLA_BOND_XMIT_HASH_POLICY]) {
 		const char *xmit_hash_policy = get_name(xmit_hash_policy_tbl,
-							rta_getattr_u8(tb[IFLA_BOND_XMIT_HASH_POLICY]));
-		print_string(PRINT_ANY,
-			     "xmit_hash_policy",
-			     "xmit_hash_policy %s ",
-			     xmit_hash_policy);
+			rta_getattr_u8(tb[IFLA_BOND_XMIT_HASH_POLICY]));
+		fprintf(f, "xmit_hash_policy %s ", xmit_hash_policy);
 	}
 
 	if (tb[IFLA_BOND_RESEND_IGMP])
-		print_uint(PRINT_ANY,
-			   "resend_igmp",
-			   "resend_igmp %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_RESEND_IGMP]));
+		fprintf(f, "resend_igmp %u ",
+			rta_getattr_u32(tb[IFLA_BOND_RESEND_IGMP]));
 
 	if (tb[IFLA_BOND_NUM_PEER_NOTIF])
-		print_uint(PRINT_ANY,
-			   "num_peer_notif",
-			   "num_grat_arp %u ",
-			   rta_getattr_u8(tb[IFLA_BOND_NUM_PEER_NOTIF]));
+		fprintf(f, "num_grat_arp %u ",
+			rta_getattr_u8(tb[IFLA_BOND_NUM_PEER_NOTIF]));
 
 	if (tb[IFLA_BOND_ALL_SLAVES_ACTIVE])
-		print_uint(PRINT_ANY,
-			   "all_slaves_active",
-			   "all_slaves_active %u ",
-			   rta_getattr_u8(tb[IFLA_BOND_ALL_SLAVES_ACTIVE]));
+		fprintf(f, "all_slaves_active %u ",
+			rta_getattr_u8(tb[IFLA_BOND_ALL_SLAVES_ACTIVE]));
 
 	if (tb[IFLA_BOND_MIN_LINKS])
-		print_uint(PRINT_ANY,
-			   "min_links",
-			   "min_links %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_MIN_LINKS]));
+		fprintf(f, "min_links %u ",
+			rta_getattr_u32(tb[IFLA_BOND_MIN_LINKS]));
 
 	if (tb[IFLA_BOND_LP_INTERVAL])
-		print_uint(PRINT_ANY,
-			   "lp_interval",
-			   "lp_interval %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_LP_INTERVAL]));
+		fprintf(f, "lp_interval %u ",
+			rta_getattr_u32(tb[IFLA_BOND_LP_INTERVAL]));
 
 	if (tb[IFLA_BOND_PACKETS_PER_SLAVE])
-		print_uint(PRINT_ANY,
-			   "packets_per_slave",
-			   "packets_per_slave %u ",
-			   rta_getattr_u32(tb[IFLA_BOND_PACKETS_PER_SLAVE]));
+		fprintf(f, "packets_per_slave %u ",
+			rta_getattr_u32(tb[IFLA_BOND_PACKETS_PER_SLAVE]));
 
 	if (tb[IFLA_BOND_AD_LACP_RATE]) {
 		const char *lacp_rate = get_name(lacp_rate_tbl,
-						 rta_getattr_u8(tb[IFLA_BOND_AD_LACP_RATE]));
-		print_string(PRINT_ANY,
-			     "ad_lacp_rate",
-			     "lacp_rate %s ",
-			     lacp_rate);
+			rta_getattr_u8(tb[IFLA_BOND_AD_LACP_RATE]));
+		fprintf(f, "lacp_rate %s ", lacp_rate);
 	}
 
 	if (tb[IFLA_BOND_AD_SELECT]) {
 		const char *ad_select = get_name(ad_select_tbl,
-						 rta_getattr_u8(tb[IFLA_BOND_AD_SELECT]));
-		print_string(PRINT_ANY,
-			     "ad_select",
-			     "ad_select %s ",
-			     ad_select);
+			rta_getattr_u8(tb[IFLA_BOND_AD_SELECT]));
+		fprintf(f, "ad_select %s ", ad_select);
 	}
 
 	if (tb[IFLA_BOND_AD_INFO]) {
 		struct rtattr *adtb[IFLA_BOND_AD_INFO_MAX + 1];
 
 		parse_rtattr_nested(adtb, IFLA_BOND_AD_INFO_MAX,
-				    tb[IFLA_BOND_AD_INFO]);
-
-		open_json_object("ad_info");
+			tb[IFLA_BOND_AD_INFO]);
 
 		if (adtb[IFLA_BOND_AD_INFO_AGGREGATOR])
-			print_int(PRINT_ANY,
-				  "aggregator",
-				  "ad_aggregator %d ",
-				  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_AGGREGATOR]));
+			fprintf(f, "ad_aggregator %d ",
+			  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_AGGREGATOR]));
 
 		if (adtb[IFLA_BOND_AD_INFO_NUM_PORTS])
-			print_int(PRINT_ANY,
-				  "num_ports",
-				  "ad_num_ports %d ",
-				  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_NUM_PORTS]));
+			fprintf(f, "ad_num_ports %d ",
+			  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_NUM_PORTS]));
 
 		if (adtb[IFLA_BOND_AD_INFO_ACTOR_KEY])
-			print_int(PRINT_ANY,
-				  "actor_key",
-				  "ad_actor_key %d ",
-				  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_ACTOR_KEY]));
+			fprintf(f, "ad_actor_key %d ",
+			  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_ACTOR_KEY]));
 
 		if (adtb[IFLA_BOND_AD_INFO_PARTNER_KEY])
-			print_int(PRINT_ANY,
-				  "partner_key",
-				  "ad_partner_key %d ",
-				  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_PARTNER_KEY]));
+			fprintf(f, "ad_partner_key %d ",
+			  rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_PARTNER_KEY]));
 
 		if (adtb[IFLA_BOND_AD_INFO_PARTNER_MAC]) {
 			unsigned char *p =
 				RTA_DATA(adtb[IFLA_BOND_AD_INFO_PARTNER_MAC]);
 			SPRINT_BUF(b);
-			print_string(PRINT_ANY,
-				     "partner_mac",
-				     "ad_partner_mac %s ",
-				     ll_addr_n2a(p, ETH_ALEN, 0, b, sizeof(b)));
+			fprintf(f, "ad_partner_mac %s ",
+				ll_addr_n2a(p, ETH_ALEN, 0, b, sizeof(b)));
 		}
-
-		close_json_object();
 	}
 
 	if (tb[IFLA_BOND_AD_ACTOR_SYS_PRIO]) {
-		print_uint(PRINT_ANY,
-			   "ad_actor_sys_prio",
-			   "ad_actor_sys_prio %u ",
-			   rta_getattr_u16(tb[IFLA_BOND_AD_ACTOR_SYS_PRIO]));
+		fprintf(f, "ad_actor_sys_prio %u ",
+			rta_getattr_u16(tb[IFLA_BOND_AD_ACTOR_SYS_PRIO]));
 	}
 
 	if (tb[IFLA_BOND_AD_USER_PORT_KEY]) {
-		print_uint(PRINT_ANY,
-			   "ad_user_port_key",
-			   "ad_user_port_key %u ",
-			   rta_getattr_u16(tb[IFLA_BOND_AD_USER_PORT_KEY]));
+		fprintf(f, "ad_user_port_key %u ",
+			rta_getattr_u16(tb[IFLA_BOND_AD_USER_PORT_KEY]));
 	}
 
 	if (tb[IFLA_BOND_AD_ACTOR_SYSTEM]) {
 		/* We assume the l2 address is an Ethernet MAC address */
 		SPRINT_BUF(b1);
-
-		print_string(PRINT_ANY,
-			     "ad_actor_system",
-			     "ad_actor_system %s ",
-			     ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
-					 RTA_PAYLOAD(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
-					 1 /*ARPHDR_ETHER*/, b1, sizeof(b1)));
+		fprintf(f, "ad_actor_system %s ",
+			ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
+				    RTA_PAYLOAD(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
+				    1 /*ARPHDR_ETHER*/, b1, sizeof(b1)));
 	}
 
 	if (tb[IFLA_BOND_TLB_DYNAMIC_LB]) {
-		print_uint(PRINT_ANY,
-			   "tlb_dynamic_lb",
-			   "tlb_dynamic_lb %u ",
-			   rta_getattr_u8(tb[IFLA_BOND_TLB_DYNAMIC_LB]));
+		fprintf(f, "tlb_dynamic_lb %u ",
+			rta_getattr_u8(tb[IFLA_BOND_TLB_DYNAMIC_LB]));
 	}
 }
 
 static void bond_print_help(struct link_util *lu, int argc, char **argv,
-			    FILE *f)
+	FILE *f)
 {
 	print_explain(f);
 }
 
-static void bond_print_xstats_help(struct link_util *lu, FILE *f)
-{
-	fprintf(f, "Usage: ... %s [ 802.3ad ] [ dev DEVICE ]\n", lu->id);
-}
-
-static void bond_print_3ad_stats(struct rtattr *lacpattr)
-{
-	struct rtattr *lacptb[BOND_3AD_STAT_MAX+1];
-	__u64 val;
-
-	parse_rtattr(lacptb, BOND_3AD_STAT_MAX, RTA_DATA(lacpattr),
-		     RTA_PAYLOAD(lacpattr));
-	open_json_object("802.3ad");
-	if (lacptb[BOND_3AD_STAT_LACPDU_RX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		print_u64(PRINT_ANY, "lacpdu_rx", "LACPDU Rx %llu\n",
-			  rta_getattr_u64(lacptb[BOND_3AD_STAT_LACPDU_RX]));
-	}
-	if (lacptb[BOND_3AD_STAT_LACPDU_TX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		print_u64(PRINT_ANY, "lacpdu_tx", "LACPDU Tx %llu\n",
-			  rta_getattr_u64(lacptb[BOND_3AD_STAT_LACPDU_TX]));
-	}
-	if (lacptb[BOND_3AD_STAT_LACPDU_UNKNOWN_RX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		val = rta_getattr_u64(lacptb[BOND_3AD_STAT_LACPDU_UNKNOWN_RX]);
-		print_u64(PRINT_ANY,
-			  "lacpdu_unknown_rx",
-			  "LACPDU Unknown type Rx %llu\n",
-			  val);
-	}
-	if (lacptb[BOND_3AD_STAT_LACPDU_ILLEGAL_RX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		val = rta_getattr_u64(lacptb[BOND_3AD_STAT_LACPDU_ILLEGAL_RX]);
-		print_u64(PRINT_ANY,
-			  "lacpdu_illegal_rx",
-			  "LACPDU Illegal Rx %llu\n",
-			  val);
-	}
-	if (lacptb[BOND_3AD_STAT_MARKER_RX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		print_u64(PRINT_ANY, "marker_rx", "Marker Rx %llu\n",
-			  rta_getattr_u64(lacptb[BOND_3AD_STAT_MARKER_RX]));
-	}
-	if (lacptb[BOND_3AD_STAT_MARKER_TX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		print_u64(PRINT_ANY, "marker_tx", "Marker Tx %llu\n",
-			  rta_getattr_u64(lacptb[BOND_3AD_STAT_MARKER_TX]));
-	}
-	if (lacptb[BOND_3AD_STAT_MARKER_RESP_RX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		val = rta_getattr_u64(lacptb[BOND_3AD_STAT_MARKER_RESP_RX]);
-		print_u64(PRINT_ANY,
-			  "marker_response_rx",
-			  "Marker response Rx %llu\n",
-			  val);
-	}
-	if (lacptb[BOND_3AD_STAT_MARKER_RESP_TX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		val = rta_getattr_u64(lacptb[BOND_3AD_STAT_MARKER_RESP_TX]);
-		print_u64(PRINT_ANY,
-			  "marker_response_tx",
-			  "Marker response Tx %llu\n",
-			  val);
-	}
-	if (lacptb[BOND_3AD_STAT_MARKER_UNKNOWN_RX]) {
-		print_string(PRINT_FP, NULL, "%-16s    ", "");
-		val = rta_getattr_u64(lacptb[BOND_3AD_STAT_MARKER_UNKNOWN_RX]);
-		print_u64(PRINT_ANY,
-			  "marker_unknown_rx",
-			  "Marker unknown type Rx %llu\n",
-			  val);
-	}
-	close_json_object();
-}
-
-static void bond_print_stats_attr(struct rtattr *attr, int ifindex)
-{
-	struct rtattr *bondtb[LINK_XSTATS_TYPE_MAX+1];
-	struct rtattr *i, *list;
-	const char *ifname = "";
-	int rem;
-
-	parse_rtattr(bondtb, LINK_XSTATS_TYPE_MAX+1, RTA_DATA(attr),
-	RTA_PAYLOAD(attr));
-	if (!bondtb[LINK_XSTATS_TYPE_BOND])
-		return;
-
-	list = bondtb[LINK_XSTATS_TYPE_BOND];
-	rem = RTA_PAYLOAD(list);
-	open_json_object(NULL);
-	ifname = ll_index_to_name(ifindex);
-	print_string(PRINT_ANY, "ifname", "%-16s\n", ifname);
-	for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		if (xstats_print_attr && i->rta_type != xstats_print_attr)
-			continue;
-
-		switch (i->rta_type) {
-		case BOND_XSTATS_3AD:
-			bond_print_3ad_stats(i);
-			break;
-		}
-		break;
-	}
-	close_json_object();
-}
-
-int bond_print_xstats(struct nlmsghdr *n, void *arg)
-{
-	struct if_stats_msg *ifsm = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_STATS_MAX+1];
-	int len = n->nlmsg_len;
-
-	len -= NLMSG_LENGTH(sizeof(*ifsm));
-	if (len < 0) {
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-	if (filter_index && filter_index != ifsm->ifindex)
-		return 0;
-
-	parse_rtattr(tb, IFLA_STATS_MAX, IFLA_STATS_RTA(ifsm), len);
-	if (tb[IFLA_STATS_LINK_XSTATS])
-		bond_print_stats_attr(tb[IFLA_STATS_LINK_XSTATS],
-				      ifsm->ifindex);
-
-	if (tb[IFLA_STATS_LINK_XSTATS_SLAVE])
-		bond_print_stats_attr(tb[IFLA_STATS_LINK_XSTATS_SLAVE],
-				      ifsm->ifindex);
-
-	return 0;
-}
-
-int bond_parse_xstats(struct link_util *lu, int argc, char **argv)
-{
-	while (argc > 0) {
-		if (strcmp(*argv, "lacp") == 0 ||
-		    strcmp(*argv, "802.3ad") == 0) {
-			xstats_print_attr = BOND_XSTATS_3AD;
-		} else if (strcmp(*argv, "dev") == 0) {
-			NEXT_ARG();
-			filter_index = ll_name_to_index(*argv);
-			if (!filter_index)
-				return nodev(*argv);
-		} else if (strcmp(*argv, "help") == 0) {
-			bond_print_xstats_help(lu, stdout);
-			exit(0);
-		} else {
-			invarg("unknown attribute", *argv);
-		}
-		argc--; argv++;
-	}
-
-	return 0;
-}
-
-
 struct link_util bond_link_util = {
 	.id		= "bond",
 	.maxattr	= IFLA_BOND_MAX,
 	.parse_opt	= bond_parse_opt,
 	.print_opt	= bond_print_opt,
 	.print_help	= bond_print_help,
-	.parse_ifla_xstats = bond_parse_xstats,
-	.print_ifla_xstats = bond_print_xstats,
 };
diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c
index 4eaf72b..9b569b1 100644
--- a/ip/iplink_bond_slave.c
+++ b/ip/iplink_bond_slave.c
@@ -17,16 +17,6 @@
 #include "utils.h"
 #include "ip_common.h"
 
-static void print_explain(FILE *f)
-{
-	fprintf(f, "Usage: ... bond_slave [ queue_id ID ]\n");
-}
-
-static void explain(void)
-{
-	print_explain(stderr);
-}
-
 static const char *slave_states[] = {
 	[BOND_STATE_ACTIVE] = "ACTIVE",
 	[BOND_STATE_BACKUP] = "BACKUP",
@@ -36,13 +26,10 @@
 {
 	unsigned int state = rta_getattr_u8(tb);
 
-	if (state >= ARRAY_SIZE(slave_states))
-		print_int(PRINT_ANY, "state_index", "state %d ", state);
+	if (state >= sizeof(slave_states) / sizeof(slave_states[0]))
+		fprintf(f, "state %d ", state);
 	else
-		print_string(PRINT_ANY,
-			     "state",
-			     "state %s ",
-			     slave_states[state]);
+		fprintf(f, "state %s ", slave_states[state]);
 }
 
 static const char *slave_mii_status[] = {
@@ -56,16 +43,10 @@
 {
 	unsigned int status = rta_getattr_u8(tb);
 
-	if (status >= ARRAY_SIZE(slave_mii_status))
-		print_int(PRINT_ANY,
-			  "mii_status_index",
-			  "mii_status %d ",
-			  status);
+	if (status >= sizeof(slave_mii_status) / sizeof(slave_mii_status[0]))
+		fprintf(f, "mii_status %d ", status);
 	else
-		print_string(PRINT_ANY,
-			     "mii_status",
-			     "mii_status %s ",
-			     slave_mii_status[status]);
+		fprintf(f, "mii_status %s ", slave_mii_status[status]);
 }
 
 static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
@@ -81,42 +62,30 @@
 		print_slave_mii_status(f, tb[IFLA_BOND_SLAVE_MII_STATUS]);
 
 	if (tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT])
-		print_int(PRINT_ANY,
-			  "link_failure_count",
-			  "link_failure_count %d ",
-			  rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));
+		fprintf(f, "link_failure_count %d ",
+			rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));
 
 	if (tb[IFLA_BOND_SLAVE_PERM_HWADDR])
-		print_string(PRINT_ANY,
-			     "perm_hwaddr",
-			     "perm_hwaddr %s ",
-			     ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
-					 RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
-					 0, b1, sizeof(b1)));
+		fprintf(f, "perm_hwaddr %s ",
+			ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
+				    RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
+				    0, b1, sizeof(b1)));
 
 	if (tb[IFLA_BOND_SLAVE_QUEUE_ID])
-		print_int(PRINT_ANY,
-			  "queue_id",
-			  "queue_id %d ",
-			  rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));
+		fprintf(f, "queue_id %d ",
+			rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));
 
 	if (tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID])
-		print_int(PRINT_ANY,
-			  "ad_aggregator_id",
-			  "ad_aggregator_id %d ",
-			  rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
+		fprintf(f, "ad_aggregator_id %d ",
+			rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
 
 	if (tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE])
-		print_int(PRINT_ANY,
-			  "ad_actor_oper_port_state",
-			  "ad_actor_oper_port_state %d ",
-			  rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
+		fprintf(f, "ad_actor_oper_port_state %d\n",
+			rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
 
 	if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE])
-		print_int(PRINT_ANY,
-			  "ad_partner_oper_port_state",
-			  "ad_partner_oper_port_state %d ",
-			  rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
+		fprintf(f, "ad_partner_oper_port_state %d\n",
+			rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
 }
 
 static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
@@ -130,13 +99,6 @@
 			if (get_u16(&queue_id, *argv, 0))
 				invarg("queue_id is invalid", *argv);
 			addattr16(n, 1024, IFLA_BOND_SLAVE_QUEUE_ID, queue_id);
-		} else {
-			if (matches(*argv, "help") != 0)
-				fprintf(stderr,
-					"bond_slave: unknown option \"%s\"?\n",
-					*argv);
-			explain();
-			return -1;
 		}
 		argc--, argv++;
 	}
@@ -144,18 +106,10 @@
 	return 0;
 }
 
-static void bond_slave_print_help(struct link_util *lu, int argc, char **argv,
-				  FILE *f)
-{
-	print_explain(f);
-}
-
 struct link_util bond_slave_link_util = {
-	.id		= "bond_slave",
+	.id		= "bond",
 	.maxattr	= IFLA_BOND_SLAVE_MAX,
 	.print_opt	= bond_slave_print_opt,
 	.parse_opt	= bond_slave_parse_opt,
-	.print_help	= bond_slave_print_help,
-	.parse_ifla_xstats = bond_parse_xstats,
-	.print_ifla_xstats = bond_print_xstats,
+	.slave		= true,
 };
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 06f736d..0080409 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -12,56 +12,23 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <netinet/in.h>
-#include <netinet/ether.h>
 #include <linux/if_link.h>
-#include <linux/if_bridge.h>
-#include <net/if.h>
 
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
 
-static unsigned int xstats_print_attr;
-static int filter_index;
-
 static void print_explain(FILE *f)
 {
 	fprintf(f,
-		"Usage: ... bridge [ fdb_flush ]\n"
-		"		  [ forward_delay FORWARD_DELAY ]\n"
-		"		  [ hello_time HELLO_TIME ]\n"
-		"		  [ max_age MAX_AGE ]\n"
-		"		  [ ageing_time AGEING_TIME ]\n"
-		"		  [ stp_state STP_STATE ]\n"
-		"		  [ priority PRIORITY ]\n"
-		"		  [ group_fwd_mask MASK ]\n"
-		"		  [ group_address ADDRESS ]\n"
-		"		  [ vlan_filtering VLAN_FILTERING ]\n"
-		"		  [ vlan_protocol VLAN_PROTOCOL ]\n"
-		"		  [ vlan_default_pvid VLAN_DEFAULT_PVID ]\n"
-		"		  [ vlan_stats_enabled VLAN_STATS_ENABLED ]\n"
-		"		  [ vlan_stats_per_port VLAN_STATS_PER_PORT ]\n"
-		"		  [ mcast_snooping MULTICAST_SNOOPING ]\n"
-		"		  [ mcast_router MULTICAST_ROUTER ]\n"
-		"		  [ mcast_query_use_ifaddr MCAST_QUERY_USE_IFADDR ]\n"
-		"		  [ mcast_querier MULTICAST_QUERIER ]\n"
-		"		  [ mcast_hash_elasticity HASH_ELASTICITY ]\n"
-		"		  [ mcast_hash_max HASH_MAX ]\n"
-		"		  [ mcast_last_member_count LAST_MEMBER_COUNT ]\n"
-		"		  [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n"
-		"		  [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n"
-		"		  [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n"
-		"		  [ mcast_querier_interval QUERIER_INTERVAL ]\n"
-		"		  [ mcast_query_interval QUERY_INTERVAL ]\n"
-		"		  [ mcast_query_response_interval QUERY_RESPONSE_INTERVAL ]\n"
-		"		  [ mcast_startup_query_interval STARTUP_QUERY_INTERVAL ]\n"
-		"		  [ mcast_stats_enabled MCAST_STATS_ENABLED ]\n"
-		"		  [ mcast_igmp_version IGMP_VERSION ]\n"
-		"		  [ mcast_mld_version MLD_VERSION ]\n"
-		"		  [ nf_call_iptables NF_CALL_IPTABLES ]\n"
-		"		  [ nf_call_ip6tables NF_CALL_IP6TABLES ]\n"
-		"		  [ nf_call_arptables NF_CALL_ARPTABLES ]\n"
+		"Usage: ... bridge [ forward_delay FORWARD_DELAY ]\n"
+		"                  [ hello_time HELLO_TIME ]\n"
+		"                  [ max_age MAX_AGE ]\n"
+		"                  [ ageing_time AGEING_TIME ]\n"
+		"                  [ stp_state STP_STATE ]\n"
+		"                  [ priority PRIORITY ]\n"
+		"                  [ vlan_filtering VLAN_FILTERING ]\n"
+		"                  [ vlan_protocol VLAN_PROTOCOL ]\n"
 		"\n"
 		"Where: VLAN_PROTOCOL := { 802.1Q | 802.1ad }\n"
 	);
@@ -72,14 +39,6 @@
 	print_explain(stderr);
 }
 
-void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len)
-{
-	char eaddr[32];
-
-	ether_ntoa_r((const struct ether_addr *)id->addr, eaddr);
-	snprintf(buf, len, "%.2x%.2x.%s", id->prio[0], id->prio[1], eaddr);
-}
-
 static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,
 			    struct nlmsghdr *n)
 {
@@ -128,246 +87,20 @@
 			__u8 vlan_filter;
 
 			NEXT_ARG();
-			if (get_u8(&vlan_filter, *argv, 0))
+			if (get_u8(&vlan_filter, *argv, 0)) {
 				invarg("invalid vlan_filtering", *argv);
-
+				return -1;
+			}
 			addattr8(n, 1024, IFLA_BR_VLAN_FILTERING, vlan_filter);
 		} else if (matches(*argv, "vlan_protocol") == 0) {
 			__u16 vlan_proto;
 
 			NEXT_ARG();
-			if (ll_proto_a2n(&vlan_proto, *argv))
+			if (ll_proto_a2n(&vlan_proto, *argv)) {
 				invarg("invalid vlan_protocol", *argv);
-
-			addattr16(n, 1024, IFLA_BR_VLAN_PROTOCOL, vlan_proto);
-		} else if (matches(*argv, "group_fwd_mask") == 0) {
-			__u16 fwd_mask;
-
-			NEXT_ARG();
-			if (get_u16(&fwd_mask, *argv, 0))
-				invarg("invalid group_fwd_mask", *argv);
-
-			addattr16(n, 1024, IFLA_BR_GROUP_FWD_MASK, fwd_mask);
-		} else if (matches(*argv, "group_address") == 0) {
-			char llabuf[32];
-			int len;
-
-			NEXT_ARG();
-			len = ll_addr_a2n(llabuf, sizeof(llabuf), *argv);
-			if (len < 0)
 				return -1;
-			addattr_l(n, 1024, IFLA_BR_GROUP_ADDR, llabuf, len);
-		} else if (matches(*argv, "fdb_flush") == 0) {
-			addattr(n, 1024, IFLA_BR_FDB_FLUSH);
-		} else if (matches(*argv, "vlan_default_pvid") == 0) {
-			__u16 default_pvid;
-
-			NEXT_ARG();
-			if (get_u16(&default_pvid, *argv, 0))
-				invarg("invalid vlan_default_pvid", *argv);
-
-			addattr16(n, 1024, IFLA_BR_VLAN_DEFAULT_PVID,
-				  default_pvid);
-		} else if (matches(*argv, "vlan_stats_enabled") == 0) {
-			__u8 vlan_stats_enabled;
-
-			NEXT_ARG();
-			if (get_u8(&vlan_stats_enabled, *argv, 0))
-				invarg("invalid vlan_stats_enabled", *argv);
-			addattr8(n, 1024, IFLA_BR_VLAN_STATS_ENABLED,
-				  vlan_stats_enabled);
-		} else if (matches(*argv, "vlan_stats_per_port") == 0) {
-			__u8 vlan_stats_per_port;
-
-			NEXT_ARG();
-			if (get_u8(&vlan_stats_per_port, *argv, 0))
-				invarg("invalid vlan_stats_per_port", *argv);
-			addattr8(n, 1024, IFLA_BR_VLAN_STATS_PER_PORT,
-				 vlan_stats_per_port);
-		} else if (matches(*argv, "mcast_router") == 0) {
-			__u8 mcast_router;
-
-			NEXT_ARG();
-			if (get_u8(&mcast_router, *argv, 0))
-				invarg("invalid mcast_router", *argv);
-
-			addattr8(n, 1024, IFLA_BR_MCAST_ROUTER, mcast_router);
-		} else if (matches(*argv, "mcast_snooping") == 0) {
-			__u8 mcast_snoop;
-
-			NEXT_ARG();
-			if (get_u8(&mcast_snoop, *argv, 0))
-				invarg("invalid mcast_snooping", *argv);
-
-			addattr8(n, 1024, IFLA_BR_MCAST_SNOOPING, mcast_snoop);
-		} else if (matches(*argv, "mcast_query_use_ifaddr") == 0) {
-			__u8 mcast_qui;
-
-			NEXT_ARG();
-			if (get_u8(&mcast_qui, *argv, 0))
-				invarg("invalid mcast_query_use_ifaddr",
-				       *argv);
-
-			addattr8(n, 1024, IFLA_BR_MCAST_QUERY_USE_IFADDR,
-				 mcast_qui);
-		} else if (matches(*argv, "mcast_querier") == 0) {
-			__u8 mcast_querier;
-
-			NEXT_ARG();
-			if (get_u8(&mcast_querier, *argv, 0))
-				invarg("invalid mcast_querier", *argv);
-
-			addattr8(n, 1024, IFLA_BR_MCAST_QUERIER, mcast_querier);
-		} else if (matches(*argv, "mcast_hash_elasticity") == 0) {
-			__u32 mcast_hash_el;
-
-			NEXT_ARG();
-			if (get_u32(&mcast_hash_el, *argv, 0))
-				invarg("invalid mcast_hash_elasticity",
-				       *argv);
-
-			addattr32(n, 1024, IFLA_BR_MCAST_HASH_ELASTICITY,
-				  mcast_hash_el);
-		} else if (matches(*argv, "mcast_hash_max") == 0) {
-			__u32 mcast_hash_max;
-
-			NEXT_ARG();
-			if (get_u32(&mcast_hash_max, *argv, 0))
-				invarg("invalid mcast_hash_max", *argv);
-
-			addattr32(n, 1024, IFLA_BR_MCAST_HASH_MAX,
-				  mcast_hash_max);
-		} else if (matches(*argv, "mcast_last_member_count") == 0) {
-			__u32 mcast_lmc;
-
-			NEXT_ARG();
-			if (get_u32(&mcast_lmc, *argv, 0))
-				invarg("invalid mcast_last_member_count",
-				       *argv);
-
-			addattr32(n, 1024, IFLA_BR_MCAST_LAST_MEMBER_CNT,
-				  mcast_lmc);
-		} else if (matches(*argv, "mcast_startup_query_count") == 0) {
-			__u32 mcast_sqc;
-
-			NEXT_ARG();
-			if (get_u32(&mcast_sqc, *argv, 0))
-				invarg("invalid mcast_startup_query_count",
-				       *argv);
-
-			addattr32(n, 1024, IFLA_BR_MCAST_STARTUP_QUERY_CNT,
-				  mcast_sqc);
-		} else if (matches(*argv, "mcast_last_member_interval") == 0) {
-			__u64 mcast_last_member_intvl;
-
-			NEXT_ARG();
-			if (get_u64(&mcast_last_member_intvl, *argv, 0))
-				invarg("invalid mcast_last_member_interval",
-				       *argv);
-
-			addattr64(n, 1024, IFLA_BR_MCAST_LAST_MEMBER_INTVL,
-				  mcast_last_member_intvl);
-		} else if (matches(*argv, "mcast_membership_interval") == 0) {
-			__u64 mcast_membership_intvl;
-
-			NEXT_ARG();
-			if (get_u64(&mcast_membership_intvl, *argv, 0))
-				invarg("invalid mcast_membership_interval",
-				       *argv);
-
-			addattr64(n, 1024, IFLA_BR_MCAST_MEMBERSHIP_INTVL,
-				  mcast_membership_intvl);
-		} else if (matches(*argv, "mcast_querier_interval") == 0) {
-			__u64 mcast_querier_intvl;
-
-			NEXT_ARG();
-			if (get_u64(&mcast_querier_intvl, *argv, 0))
-				invarg("invalid mcast_querier_interval",
-				       *argv);
-
-			addattr64(n, 1024, IFLA_BR_MCAST_QUERIER_INTVL,
-				  mcast_querier_intvl);
-		} else if (matches(*argv, "mcast_query_interval") == 0) {
-			__u64 mcast_query_intvl;
-
-			NEXT_ARG();
-			if (get_u64(&mcast_query_intvl, *argv, 0))
-				invarg("invalid mcast_query_interval",
-				       *argv);
-
-			addattr64(n, 1024, IFLA_BR_MCAST_QUERY_INTVL,
-				  mcast_query_intvl);
-		} else if (!matches(*argv, "mcast_query_response_interval")) {
-			__u64 mcast_query_resp_intvl;
-
-			NEXT_ARG();
-			if (get_u64(&mcast_query_resp_intvl, *argv, 0))
-				invarg("invalid mcast_query_response_interval",
-				       *argv);
-
-			addattr64(n, 1024, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL,
-				  mcast_query_resp_intvl);
-		} else if (!matches(*argv, "mcast_startup_query_interval")) {
-			__u64 mcast_startup_query_intvl;
-
-			NEXT_ARG();
-			if (get_u64(&mcast_startup_query_intvl, *argv, 0))
-				invarg("invalid mcast_startup_query_interval",
-				       *argv);
-
-			addattr64(n, 1024, IFLA_BR_MCAST_STARTUP_QUERY_INTVL,
-				  mcast_startup_query_intvl);
-		} else if (matches(*argv, "mcast_stats_enabled") == 0) {
-			__u8 mcast_stats_enabled;
-
-			NEXT_ARG();
-			if (get_u8(&mcast_stats_enabled, *argv, 0))
-				invarg("invalid mcast_stats_enabled", *argv);
-			addattr8(n, 1024, IFLA_BR_MCAST_STATS_ENABLED,
-				  mcast_stats_enabled);
-		} else if (matches(*argv, "mcast_igmp_version") == 0) {
-			__u8 igmp_version;
-
-			NEXT_ARG();
-			if (get_u8(&igmp_version, *argv, 0))
-				invarg("invalid mcast_igmp_version", *argv);
-			addattr8(n, 1024, IFLA_BR_MCAST_IGMP_VERSION,
-				  igmp_version);
-		} else if (matches(*argv, "mcast_mld_version") == 0) {
-			__u8 mld_version;
-
-			NEXT_ARG();
-			if (get_u8(&mld_version, *argv, 0))
-				invarg("invalid mcast_mld_version", *argv);
-			addattr8(n, 1024, IFLA_BR_MCAST_MLD_VERSION,
-				  mld_version);
-		} else if (matches(*argv, "nf_call_iptables") == 0) {
-			__u8 nf_call_ipt;
-
-			NEXT_ARG();
-			if (get_u8(&nf_call_ipt, *argv, 0))
-				invarg("invalid nf_call_iptables", *argv);
-
-			addattr8(n, 1024, IFLA_BR_NF_CALL_IPTABLES,
-				 nf_call_ipt);
-		} else if (matches(*argv, "nf_call_ip6tables") == 0) {
-			__u8 nf_call_ip6t;
-
-			NEXT_ARG();
-			if (get_u8(&nf_call_ip6t, *argv, 0))
-				invarg("invalid nf_call_ip6tables", *argv);
-
-			addattr8(n, 1024, IFLA_BR_NF_CALL_IP6TABLES,
-				 nf_call_ip6t);
-		} else if (matches(*argv, "nf_call_arptables") == 0) {
-			__u8 nf_call_arpt;
-
-			NEXT_ARG();
-			if (get_u8(&nf_call_arpt, *argv, 0))
-				invarg("invalid nf_call_arptables", *argv);
-
-			addattr8(n, 1024, IFLA_BR_NF_CALL_ARPTABLES,
-				 nf_call_arpt);
+			}
+			addattr16(n, 1024, IFLA_BR_VLAN_PROTOCOL, vlan_proto);
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -382,490 +115,58 @@
 	return 0;
 }
 
-static void _bridge_print_timer(FILE *f,
-				const char *attr,
-				struct rtattr *timer)
-{
-	struct timeval tv;
-
-	__jiffies_to_tv(&tv, rta_getattr_u64(timer));
-	if (is_json_context()) {
-		json_writer_t *jw = get_json_writer();
-
-		jsonw_name(jw, attr);
-		jsonw_printf(jw, "%i.%.2i",
-			     (int)tv.tv_sec,
-			     (int)tv.tv_usec / 10000);
-	} else {
-		fprintf(f, "%s %4i.%.2i ", attr, (int)tv.tv_sec,
-			(int)tv.tv_usec / 10000);
-	}
-}
-
 static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
 	if (!tb)
 		return;
 
 	if (tb[IFLA_BR_FORWARD_DELAY])
-		print_uint(PRINT_ANY,
-			   "forward_delay",
-			   "forward_delay %u ",
-			   rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
+		fprintf(f, "forward_delay %u ",
+			rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
 
 	if (tb[IFLA_BR_HELLO_TIME])
-		print_uint(PRINT_ANY,
-			   "hello_time",
-			   "hello_time %u ",
-			   rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
+		fprintf(f, "hello_time %u ",
+			rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
 
 	if (tb[IFLA_BR_MAX_AGE])
-		print_uint(PRINT_ANY,
-			   "max_age",
-			   "max_age %u ",
-			   rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
+		fprintf(f, "max_age %u ",
+			rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
 
 	if (tb[IFLA_BR_AGEING_TIME])
-		print_uint(PRINT_ANY,
-			   "ageing_time",
-			   "ageing_time %u ",
-			   rta_getattr_u32(tb[IFLA_BR_AGEING_TIME]));
+		fprintf(f, "ageing_time %u ",
+			rta_getattr_u32(tb[IFLA_BR_AGEING_TIME]));
 
 	if (tb[IFLA_BR_STP_STATE])
-		print_uint(PRINT_ANY,
-			   "stp_state",
-			   "stp_state %u ",
-			   rta_getattr_u32(tb[IFLA_BR_STP_STATE]));
+		fprintf(f, "stp_state %u ",
+			rta_getattr_u32(tb[IFLA_BR_STP_STATE]));
 
 	if (tb[IFLA_BR_PRIORITY])
-		print_uint(PRINT_ANY,
-			   "priority",
-			   "priority %u ",
-			   rta_getattr_u16(tb[IFLA_BR_PRIORITY]));
+		fprintf(f, "priority %u ",
+			rta_getattr_u16(tb[IFLA_BR_PRIORITY]));
 
 	if (tb[IFLA_BR_VLAN_FILTERING])
-		print_uint(PRINT_ANY,
-			   "vlan_filtering",
-			   "vlan_filtering %u ",
-			   rta_getattr_u8(tb[IFLA_BR_VLAN_FILTERING]));
+		fprintf(f, "vlan_filtering %u ",
+			rta_getattr_u8(tb[IFLA_BR_VLAN_FILTERING]));
 
 	if (tb[IFLA_BR_VLAN_PROTOCOL]) {
 		SPRINT_BUF(b1);
 
-		print_string(PRINT_ANY,
-			     "vlan_protocol",
-			     "vlan_protocol %s ",
-			     ll_proto_n2a(rta_getattr_u16(tb[IFLA_BR_VLAN_PROTOCOL]),
-					  b1, sizeof(b1)));
+		fprintf(f, "vlan_protocol %s ",
+			ll_proto_n2a(rta_getattr_u16(tb[IFLA_BR_VLAN_PROTOCOL]),
+				     b1, sizeof(b1)));
 	}
-
-	if (tb[IFLA_BR_BRIDGE_ID]) {
-		char bridge_id[32];
-
-		br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), bridge_id,
-				  sizeof(bridge_id));
-		print_string(PRINT_ANY,
-			     "bridge_id",
-			     "bridge_id %s ",
-			     bridge_id);
-	}
-
-	if (tb[IFLA_BR_ROOT_ID]) {
-		char root_id[32];
-
-		br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), root_id,
-				  sizeof(root_id));
-		print_string(PRINT_ANY,
-			     "root_id",
-			     "designated_root %s ",
-			     root_id);
-	}
-
-	if (tb[IFLA_BR_ROOT_PORT])
-		print_uint(PRINT_ANY,
-			   "root_port",
-			   "root_port %u ",
-			   rta_getattr_u16(tb[IFLA_BR_ROOT_PORT]));
-
-	if (tb[IFLA_BR_ROOT_PATH_COST])
-		print_uint(PRINT_ANY,
-			   "root_path_cost",
-			   "root_path_cost %u ",
-			   rta_getattr_u32(tb[IFLA_BR_ROOT_PATH_COST]));
-
-	if (tb[IFLA_BR_TOPOLOGY_CHANGE])
-		print_uint(PRINT_ANY,
-			   "topology_change",
-			   "topology_change %u ",
-			   rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE]));
-
-	if (tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED])
-		print_uint(PRINT_ANY,
-			   "topology_change_detected",
-			   "topology_change_detected %u ",
-			   rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED]));
-
-	if (tb[IFLA_BR_HELLO_TIMER])
-		_bridge_print_timer(f, "hello_timer", tb[IFLA_BR_HELLO_TIMER]);
-
-	if (tb[IFLA_BR_TCN_TIMER])
-		_bridge_print_timer(f, "tcn_timer", tb[IFLA_BR_TCN_TIMER]);
-
-	if (tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER])
-		_bridge_print_timer(f, "topology_change_timer",
-				    tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER]);
-
-	if (tb[IFLA_BR_GC_TIMER])
-		_bridge_print_timer(f, "gc_timer", tb[IFLA_BR_GC_TIMER]);
-
-	if (tb[IFLA_BR_VLAN_DEFAULT_PVID])
-		print_uint(PRINT_ANY,
-			   "vlan_default_pvid",
-			   "vlan_default_pvid %u ",
-			   rta_getattr_u16(tb[IFLA_BR_VLAN_DEFAULT_PVID]));
-
-	if (tb[IFLA_BR_VLAN_STATS_ENABLED])
-		print_uint(PRINT_ANY,
-			   "vlan_stats_enabled",
-			   "vlan_stats_enabled %u ",
-			   rta_getattr_u8(tb[IFLA_BR_VLAN_STATS_ENABLED]));
-
-	if (tb[IFLA_BR_VLAN_STATS_PER_PORT])
-		print_uint(PRINT_ANY,
-			   "vlan_stats_per_port",
-			   "vlan_stats_per_port %u ",
-			   rta_getattr_u8(tb[IFLA_BR_VLAN_STATS_PER_PORT]));
-
-	if (tb[IFLA_BR_GROUP_FWD_MASK])
-		print_0xhex(PRINT_ANY,
-			    "group_fwd_mask",
-			    "group_fwd_mask %#llx ",
-			    rta_getattr_u16(tb[IFLA_BR_GROUP_FWD_MASK]));
-
-	if (tb[IFLA_BR_GROUP_ADDR]) {
-		SPRINT_BUF(mac);
-
-		print_string(PRINT_ANY,
-			     "group_addr",
-			     "group_address %s ",
-			     ll_addr_n2a(RTA_DATA(tb[IFLA_BR_GROUP_ADDR]),
-					 RTA_PAYLOAD(tb[IFLA_BR_GROUP_ADDR]),
-					 1 /*ARPHDR_ETHER*/, mac, sizeof(mac)));
-	}
-
-	if (tb[IFLA_BR_MCAST_SNOOPING])
-		print_uint(PRINT_ANY,
-			   "mcast_snooping",
-			   "mcast_snooping %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_SNOOPING]));
-
-	if (tb[IFLA_BR_MCAST_ROUTER])
-		print_uint(PRINT_ANY,
-			   "mcast_router",
-			   "mcast_router %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_ROUTER]));
-
-	if (tb[IFLA_BR_MCAST_QUERY_USE_IFADDR])
-		print_uint(PRINT_ANY,
-			   "mcast_query_use_ifaddr",
-			   "mcast_query_use_ifaddr %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_QUERY_USE_IFADDR]));
-
-	if (tb[IFLA_BR_MCAST_QUERIER])
-		print_uint(PRINT_ANY,
-			   "mcast_querier",
-			   "mcast_querier %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_QUERIER]));
-
-	if (tb[IFLA_BR_MCAST_HASH_ELASTICITY])
-		print_uint(PRINT_ANY,
-			   "mcast_hash_elasticity",
-			   "mcast_hash_elasticity %u ",
-			   rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_ELASTICITY]));
-
-	if (tb[IFLA_BR_MCAST_HASH_MAX])
-		print_uint(PRINT_ANY,
-			   "mcast_hash_max",
-			   "mcast_hash_max %u ",
-			   rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_MAX]));
-
-	if (tb[IFLA_BR_MCAST_LAST_MEMBER_CNT])
-		print_uint(PRINT_ANY,
-			   "mcast_last_member_cnt",
-			   "mcast_last_member_count %u ",
-			   rta_getattr_u32(tb[IFLA_BR_MCAST_LAST_MEMBER_CNT]));
-
-	if (tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT])
-		print_uint(PRINT_ANY,
-			   "mcast_startup_query_cnt",
-			   "mcast_startup_query_count %u ",
-			   rta_getattr_u32(tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT]));
-
-	if (tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL])
-		print_lluint(PRINT_ANY,
-			     "mcast_last_member_intvl",
-			     "mcast_last_member_interval %llu ",
-			     rta_getattr_u64(tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL]));
-
-	if (tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL])
-		print_lluint(PRINT_ANY,
-			     "mcast_membership_intvl",
-			     "mcast_membership_interval %llu ",
-			     rta_getattr_u64(tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL]));
-
-	if (tb[IFLA_BR_MCAST_QUERIER_INTVL])
-		print_lluint(PRINT_ANY,
-			     "mcast_querier_intvl",
-			     "mcast_querier_interval %llu ",
-			     rta_getattr_u64(tb[IFLA_BR_MCAST_QUERIER_INTVL]));
-
-	if (tb[IFLA_BR_MCAST_QUERY_INTVL])
-		print_lluint(PRINT_ANY,
-			     "mcast_query_intvl",
-			     "mcast_query_interval %llu ",
-			     rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_INTVL]));
-
-	if (tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL])
-		print_lluint(PRINT_ANY,
-			     "mcast_query_response_intvl",
-			     "mcast_query_response_interval %llu ",
-			     rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]));
-
-	if (tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL])
-		print_lluint(PRINT_ANY,
-			     "mcast_startup_query_intvl",
-			     "mcast_startup_query_interval %llu ",
-			     rta_getattr_u64(tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]));
-
-	if (tb[IFLA_BR_MCAST_STATS_ENABLED])
-		print_uint(PRINT_ANY,
-			   "mcast_stats_enabled",
-			   "mcast_stats_enabled %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_STATS_ENABLED]));
-
-	if (tb[IFLA_BR_MCAST_IGMP_VERSION])
-		print_uint(PRINT_ANY,
-			   "mcast_igmp_version",
-			   "mcast_igmp_version %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_IGMP_VERSION]));
-
-	if (tb[IFLA_BR_MCAST_MLD_VERSION])
-		print_uint(PRINT_ANY,
-			   "mcast_mld_version",
-			   "mcast_mld_version %u ",
-			   rta_getattr_u8(tb[IFLA_BR_MCAST_MLD_VERSION]));
-
-	if (tb[IFLA_BR_NF_CALL_IPTABLES])
-		print_uint(PRINT_ANY,
-			   "nf_call_iptables",
-			   "nf_call_iptables %u ",
-			   rta_getattr_u8(tb[IFLA_BR_NF_CALL_IPTABLES]));
-
-	if (tb[IFLA_BR_NF_CALL_IP6TABLES])
-		print_uint(PRINT_ANY,
-			   "nf_call_ip6tables",
-			   "nf_call_ip6tables %u ",
-			   rta_getattr_u8(tb[IFLA_BR_NF_CALL_IP6TABLES]));
-
-	if (tb[IFLA_BR_NF_CALL_ARPTABLES])
-		print_uint(PRINT_ANY,
-			   "nf_call_arptables",
-			   "nf_call_arptables %u ",
-			   rta_getattr_u8(tb[IFLA_BR_NF_CALL_ARPTABLES]));
 }
 
 static void bridge_print_help(struct link_util *lu, int argc, char **argv,
-			      FILE *f)
+		FILE *f)
 {
 	print_explain(f);
 }
 
-static void bridge_print_xstats_help(struct link_util *lu, FILE *f)
-{
-	fprintf(f, "Usage: ... %s [ igmp ] [ dev DEVICE ]\n", lu->id);
-}
-
-static void bridge_print_stats_attr(struct rtattr *attr, int ifindex)
-{
-	struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1];
-	struct br_mcast_stats *mstats;
-	struct rtattr *i, *list;
-	const char *ifname = "";
-	int rem;
-
-	parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr),
-	RTA_PAYLOAD(attr));
-	if (!brtb[LINK_XSTATS_TYPE_BRIDGE])
-		return;
-
-	list = brtb[LINK_XSTATS_TYPE_BRIDGE];
-	rem = RTA_PAYLOAD(list);
-	open_json_object(NULL);
-	ifname = ll_index_to_name(ifindex);
-	print_string(PRINT_ANY, "ifname", "%-16s\n", ifname);
-	for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		if (xstats_print_attr && i->rta_type != xstats_print_attr)
-			continue;
-		switch (i->rta_type) {
-		case BRIDGE_XSTATS_MCAST:
-			mstats = RTA_DATA(i);
-			open_json_object("multicast");
-			open_json_object("igmp_queries");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP queries:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->igmp_v1queries[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu ",
-				  mstats->igmp_v2queries[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v3", "v3 %llu\n",
-				  mstats->igmp_v3queries[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->igmp_v1queries[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu ",
-				  mstats->igmp_v2queries[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v3", "v3 %llu\n",
-				  mstats->igmp_v3queries[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("igmp_reports");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP reports:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->igmp_v1reports[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu ",
-				  mstats->igmp_v2reports[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v3", "v3 %llu\n",
-				  mstats->igmp_v3reports[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->igmp_v1reports[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu",
-				  mstats->igmp_v2reports[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v3", "v3 %llu\n",
-				  mstats->igmp_v3reports[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("igmp_leaves");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP leaves: ", "");
-			print_u64(PRINT_ANY, "rx", "RX: %llu ",
-				  mstats->igmp_leaves[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "tx", "TX: %llu\n",
-				  mstats->igmp_leaves[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			print_string(PRINT_FP, NULL,
-				     "%-16s    IGMP parse errors: ", "");
-			print_u64(PRINT_ANY, "igmp_parse_errors", "%llu\n",
-				  mstats->igmp_parse_errors);
-
-			open_json_object("mld_queries");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD queries:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->mld_v1queries[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu\n",
-				  mstats->mld_v2queries[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->mld_v1queries[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu\n",
-				  mstats->mld_v2queries[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("mld_reports");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD reports:\n", "");
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "rx_v1", "RX: v1 %llu ",
-				  mstats->mld_v1reports[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "rx_v2", "v2 %llu\n",
-				  mstats->mld_v2reports[BR_MCAST_DIR_RX]);
-			print_string(PRINT_FP, NULL, "%-16s      ", "");
-			print_u64(PRINT_ANY, "tx_v1", "TX: v1 %llu ",
-				  mstats->mld_v1reports[BR_MCAST_DIR_TX]);
-			print_u64(PRINT_ANY, "tx_v2", "v2 %llu\n",
-				  mstats->mld_v2reports[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			open_json_object("mld_leaves");
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD leaves: ", "");
-			print_u64(PRINT_ANY, "rx", "RX: %llu ",
-				  mstats->mld_leaves[BR_MCAST_DIR_RX]);
-			print_u64(PRINT_ANY, "tx", "TX: %llu\n",
-				  mstats->mld_leaves[BR_MCAST_DIR_TX]);
-			close_json_object();
-
-			print_string(PRINT_FP, NULL,
-				     "%-16s    MLD parse errors: ", "");
-			print_u64(PRINT_ANY, "mld_parse_errors", "%llu\n",
-				  mstats->mld_parse_errors);
-			close_json_object();
-			break;
-		}
-	}
-	close_json_object();
-}
-
-int bridge_print_xstats(struct nlmsghdr *n, void *arg)
-{
-	struct if_stats_msg *ifsm = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_STATS_MAX+1];
-	int len = n->nlmsg_len;
-
-	len -= NLMSG_LENGTH(sizeof(*ifsm));
-	if (len < 0) {
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-	if (filter_index && filter_index != ifsm->ifindex)
-		return 0;
-
-	parse_rtattr(tb, IFLA_STATS_MAX, IFLA_STATS_RTA(ifsm), len);
-	if (tb[IFLA_STATS_LINK_XSTATS])
-		bridge_print_stats_attr(tb[IFLA_STATS_LINK_XSTATS],
-					ifsm->ifindex);
-
-	if (tb[IFLA_STATS_LINK_XSTATS_SLAVE])
-		bridge_print_stats_attr(tb[IFLA_STATS_LINK_XSTATS_SLAVE],
-					ifsm->ifindex);
-
-	return 0;
-}
-
-int bridge_parse_xstats(struct link_util *lu, int argc, char **argv)
-{
-	while (argc > 0) {
-		if (strcmp(*argv, "igmp") == 0 || strcmp(*argv, "mcast") == 0) {
-			xstats_print_attr = BRIDGE_XSTATS_MCAST;
-		} else if (strcmp(*argv, "dev") == 0) {
-			NEXT_ARG();
-			filter_index = ll_name_to_index(*argv);
-			if (!filter_index)
-				return nodev(*argv);
-		} else if (strcmp(*argv, "help") == 0) {
-			bridge_print_xstats_help(lu, stdout);
-			exit(0);
-		} else {
-			invarg("unknown attribute", *argv);
-		}
-		argc--; argv++;
-	}
-
-	return 0;
-}
-
 struct link_util bridge_link_util = {
 	.id		= "bridge",
 	.maxattr	= IFLA_BR_MAX,
 	.parse_opt	= bridge_parse_opt,
 	.print_opt	= bridge_print_opt,
 	.print_help     = bridge_print_help,
-	.parse_ifla_xstats = bridge_parse_xstats,
-	.print_ifla_xstats = bridge_print_xstats,
 };
diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c
index 79a1d2f..4593872 100644
--- a/ip/iplink_bridge_slave.c
+++ b/ip/iplink_bridge_slave.c
@@ -22,27 +22,13 @@
 static void print_explain(FILE *f)
 {
 	fprintf(f,
-		"Usage: ... bridge_slave [ fdb_flush ]\n"
-		"			[ state STATE ]\n"
-		"			[ priority PRIO ]\n"
-		"			[ cost COST ]\n"
-		"			[ guard {on | off} ]\n"
-		"			[ hairpin {on | off} ]\n"
-		"			[ fastleave {on | off} ]\n"
-		"			[ root_block {on | off} ]\n"
-		"			[ learning {on | off} ]\n"
-		"			[ flood {on | off} ]\n"
-		"			[ proxy_arp {on | off} ]\n"
-		"			[ proxy_arp_wifi {on | off} ]\n"
-		"			[ mcast_router MULTICAST_ROUTER ]\n"
-		"			[ mcast_fast_leave {on | off} ]\n"
-		"			[ mcast_flood {on | off} ]\n"
-		"			[ mcast_to_unicast {on | off} ]\n"
-		"			[ group_fwd_mask MASK ]\n"
-		"			[ neigh_suppress {on | off} ]\n"
-		"			[ vlan_tunnel {on | off} ]\n"
-		"			[ isolated {on | off} ]\n"
-		"			[ backup_port DEVICE ] [ nobackup_port ]\n"
+		"Usage: ... bridge_slave [ state STATE ] [ priority PRIO ] [cost COST ]\n"
+		"                        [ guard {on | off} ]\n"
+		"                        [ hairpin {on | off} ] \n"
+		"                        [ fastleave {on | off} ]\n"
+		"                        [ root_block {on | off} ]\n"
+		"                        [ learning {on | off} ]\n"
+		"                        [ flood {on | off} ]\n"
 	);
 }
 
@@ -59,68 +45,17 @@
 	[BR_STATE_BLOCKING] = "blocking",
 };
 
-static const char *fwd_mask_tbl[16] = {
-	[0]	= "stp",
-	[2]	= "lacp",
-	[14]	= "lldp"
-};
-
 static void print_portstate(FILE *f, __u8 state)
 {
 	if (state <= BR_STATE_BLOCKING)
-		print_string(PRINT_ANY,
-			     "state",
-			     "state %s ",
-			     port_states[state]);
+		fprintf(f, "state %s ", port_states[state]);
 	else
-		print_int(PRINT_ANY, "state_index", "state (%d) ", state);
+		fprintf(f, "state (%d) ", state);
 }
 
-static void _print_onoff(FILE *f, char *json_flag, char *flag, __u8 val)
+static void print_onoff(FILE *f, char *flag, __u8 val)
 {
-	if (is_json_context())
-		print_bool(PRINT_JSON, flag, NULL, val);
-	else
-		fprintf(f, "%s %s ", flag, val ? "on" : "off");
-}
-
-static void _print_timer(FILE *f, const char *attr, struct rtattr *timer)
-{
-	struct timeval tv;
-
-	__jiffies_to_tv(&tv, rta_getattr_u64(timer));
-	if (is_json_context()) {
-		json_writer_t *jw = get_json_writer();
-
-		jsonw_name(jw, attr);
-		jsonw_printf(jw, "%i.%.2i",
-			     (int)tv.tv_sec, (int)tv.tv_usec / 10000);
-	} else {
-		fprintf(f, "%s %4i.%.2i ", attr, (int)tv.tv_sec,
-			(int)tv.tv_usec / 10000);
-	}
-}
-
-static void _bitmask2str(__u16 bitmask, char *dst, size_t dst_size,
-			 const char **tbl)
-{
-	int len, i;
-
-	for (i = 0, len = 0; bitmask; i++, bitmask >>= 1) {
-		if (bitmask & 0x1) {
-			if (tbl[i])
-				len += snprintf(dst + len, dst_size - len, "%s,",
-						tbl[i]);
-			else
-				len += snprintf(dst + len, dst_size - len, "0x%x,",
-						(1 << i));
-		}
-	}
-
-	if (!len)
-		snprintf(dst, dst_size, "0x0");
-	else
-		dst[len - 1] = 0;
+	fprintf(f, "%s %s ", flag, val ? "on" : "off");
 }
 
 static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
@@ -133,165 +68,36 @@
 		print_portstate(f, rta_getattr_u8(tb[IFLA_BRPORT_STATE]));
 
 	if (tb[IFLA_BRPORT_PRIORITY])
-		print_int(PRINT_ANY,
-			  "priority",
-			  "priority %d ",
-			  rta_getattr_u16(tb[IFLA_BRPORT_PRIORITY]));
+		fprintf(f, "priority %d ",
+			rta_getattr_u16(tb[IFLA_BRPORT_PRIORITY]));
 
 	if (tb[IFLA_BRPORT_COST])
-		print_int(PRINT_ANY,
-			  "cost",
-			  "cost %d ",
-			  rta_getattr_u32(tb[IFLA_BRPORT_COST]));
+		fprintf(f, "cost %d ",
+			rta_getattr_u32(tb[IFLA_BRPORT_COST]));
 
 	if (tb[IFLA_BRPORT_MODE])
-		_print_onoff(f, "mode", "hairpin",
-			     rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
+		print_onoff(f, "hairpin",
+			    rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
 
 	if (tb[IFLA_BRPORT_GUARD])
-		_print_onoff(f, "guard", "guard",
-			     rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
+		print_onoff(f, "guard",
+			    rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
 
 	if (tb[IFLA_BRPORT_PROTECT])
-		_print_onoff(f, "protect", "root_block",
-			     rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
+		print_onoff(f, "root_block",
+			    rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
 
 	if (tb[IFLA_BRPORT_FAST_LEAVE])
-		_print_onoff(f, "fast_leave", "fastleave",
-			     rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
+		print_onoff(f, "fastleave",
+			    rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
 
 	if (tb[IFLA_BRPORT_LEARNING])
-		_print_onoff(f, "learning", "learning",
-			     rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
+		print_onoff(f, "learning",
+			rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
 
 	if (tb[IFLA_BRPORT_UNICAST_FLOOD])
-		_print_onoff(f, "unicast_flood", "flood",
-			     rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
-
-	if (tb[IFLA_BRPORT_ID])
-		print_0xhex(PRINT_ANY, "id", "port_id %#llx ",
-			    rta_getattr_u16(tb[IFLA_BRPORT_ID]));
-
-	if (tb[IFLA_BRPORT_NO])
-		print_0xhex(PRINT_ANY, "no", "port_no %#llx ",
-			   rta_getattr_u16(tb[IFLA_BRPORT_NO]));
-
-	if (tb[IFLA_BRPORT_DESIGNATED_PORT])
-		print_uint(PRINT_ANY,
-			   "designated_port",
-			   "designated_port %u ",
-			   rta_getattr_u16(tb[IFLA_BRPORT_DESIGNATED_PORT]));
-
-	if (tb[IFLA_BRPORT_DESIGNATED_COST])
-		print_uint(PRINT_ANY,
-			   "designated_cost",
-			   "designated_cost %u ",
-			   rta_getattr_u16(tb[IFLA_BRPORT_DESIGNATED_COST]));
-
-	if (tb[IFLA_BRPORT_BRIDGE_ID]) {
-		char bridge_id[32];
-
-		br_dump_bridge_id(RTA_DATA(tb[IFLA_BRPORT_BRIDGE_ID]),
-				  bridge_id, sizeof(bridge_id));
-		print_string(PRINT_ANY,
-			     "bridge_id",
-			     "designated_bridge %s ",
-			     bridge_id);
-	}
-
-	if (tb[IFLA_BRPORT_ROOT_ID]) {
-		char root_id[32];
-
-		br_dump_bridge_id(RTA_DATA(tb[IFLA_BRPORT_ROOT_ID]),
-				  root_id, sizeof(root_id));
-		print_string(PRINT_ANY,
-			     "root_id",
-			     "designated_root %s ", root_id);
-	}
-
-	if (tb[IFLA_BRPORT_HOLD_TIMER])
-		_print_timer(f, "hold_timer", tb[IFLA_BRPORT_HOLD_TIMER]);
-
-	if (tb[IFLA_BRPORT_MESSAGE_AGE_TIMER])
-		_print_timer(f, "message_age_timer",
-			     tb[IFLA_BRPORT_MESSAGE_AGE_TIMER]);
-
-	if (tb[IFLA_BRPORT_FORWARD_DELAY_TIMER])
-		_print_timer(f, "forward_delay_timer",
-			     tb[IFLA_BRPORT_FORWARD_DELAY_TIMER]);
-
-	if (tb[IFLA_BRPORT_TOPOLOGY_CHANGE_ACK])
-		print_uint(PRINT_ANY,
-			   "topology_change_ack",
-			   "topology_change_ack %u ",
-			   rta_getattr_u8(tb[IFLA_BRPORT_TOPOLOGY_CHANGE_ACK]));
-
-	if (tb[IFLA_BRPORT_CONFIG_PENDING])
-		print_uint(PRINT_ANY,
-			   "config_pending",
-			   "config_pending %u ",
-			   rta_getattr_u8(tb[IFLA_BRPORT_CONFIG_PENDING]));
-
-	if (tb[IFLA_BRPORT_PROXYARP])
-		_print_onoff(f, "proxyarp", "proxy_arp",
-			     rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP]));
-
-	if (tb[IFLA_BRPORT_PROXYARP_WIFI])
-		_print_onoff(f, "proxyarp_wifi", "proxy_arp_wifi",
-			     rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP_WIFI]));
-
-	if (tb[IFLA_BRPORT_MULTICAST_ROUTER])
-		print_uint(PRINT_ANY,
-			   "multicast_router",
-			   "mcast_router %u ",
-			   rta_getattr_u8(tb[IFLA_BRPORT_MULTICAST_ROUTER]));
-
-	if (tb[IFLA_BRPORT_FAST_LEAVE])
-		// not printing any json here because
-		// we already printed fast_leave before
-		print_string(PRINT_FP,
-			     NULL,
-			     "mcast_fast_leave %s ",
-			     rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]) ? "on" : "off");
-
-	if (tb[IFLA_BRPORT_MCAST_FLOOD])
-		_print_onoff(f, "mcast_flood", "mcast_flood",
-			     rta_getattr_u8(tb[IFLA_BRPORT_MCAST_FLOOD]));
-
-	if (tb[IFLA_BRPORT_MCAST_TO_UCAST])
-		_print_onoff(f, "mcast_to_unicast", "mcast_to_unicast",
-			     rta_getattr_u8(tb[IFLA_BRPORT_MCAST_TO_UCAST]));
-
-	if (tb[IFLA_BRPORT_NEIGH_SUPPRESS])
-		_print_onoff(f, "neigh_suppress", "neigh_suppress",
-			     rta_getattr_u8(tb[IFLA_BRPORT_NEIGH_SUPPRESS]));
-
-	if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) {
-		char convbuf[256];
-		__u16 fwd_mask;
-
-		fwd_mask = rta_getattr_u16(tb[IFLA_BRPORT_GROUP_FWD_MASK]);
-		print_0xhex(PRINT_ANY, "group_fwd_mask",
-			    "group_fwd_mask %#llx ", fwd_mask);
-		_bitmask2str(fwd_mask, convbuf, sizeof(convbuf), fwd_mask_tbl);
-		print_string(PRINT_ANY, "group_fwd_mask_str",
-			     "group_fwd_mask_str %s ", convbuf);
-	}
-
-	if (tb[IFLA_BRPORT_VLAN_TUNNEL])
-		_print_onoff(f, "vlan_tunnel", "vlan_tunnel",
-			     rta_getattr_u8(tb[IFLA_BRPORT_VLAN_TUNNEL]));
-
-	if (tb[IFLA_BRPORT_ISOLATED])
-		_print_onoff(f, "isolated", "isolated",
-			     rta_getattr_u8(tb[IFLA_BRPORT_ISOLATED]));
-
-	if (tb[IFLA_BRPORT_BACKUP_PORT]) {
-		int backup_p = rta_getattr_u32(tb[IFLA_BRPORT_BACKUP_PORT]);
-
-		print_string(PRINT_ANY, "backup_port", "backup_port %s ",
-			     ll_index_to_name(backup_p));
-	}
+		print_onoff(f, "flood",
+			rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
 }
 
 static void bridge_slave_parse_on_off(char *arg_name, char *arg_val,
@@ -317,9 +123,7 @@
 	__u32 cost;
 
 	while (argc > 0) {
-		if (matches(*argv, "fdb_flush") == 0) {
-			addattr(n, 1024, IFLA_BRPORT_FLUSH);
-		} else if (matches(*argv, "state") == 0) {
+		if (matches(*argv, "state") == 0) {
 			NEXT_ARG();
 			if (get_u8(&state, *argv, 0))
 				invarg("state is invalid", *argv);
@@ -358,63 +162,6 @@
 			NEXT_ARG();
 			bridge_slave_parse_on_off("flood", *argv, n,
 						  IFLA_BRPORT_UNICAST_FLOOD);
-		} else if (matches(*argv, "mcast_flood") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("mcast_flood", *argv, n,
-						  IFLA_BRPORT_MCAST_FLOOD);
-		} else if (matches(*argv, "mcast_to_unicast") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("mcast_to_unicast", *argv, n,
-						  IFLA_BRPORT_MCAST_TO_UCAST);
-		} else if (matches(*argv, "proxy_arp") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("proxy_arp", *argv, n,
-						  IFLA_BRPORT_PROXYARP);
-		} else if (matches(*argv, "proxy_arp_wifi") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("proxy_arp_wifi", *argv, n,
-						  IFLA_BRPORT_PROXYARP_WIFI);
-		} else if (matches(*argv, "mcast_router") == 0) {
-			__u8 mcast_router;
-
-			NEXT_ARG();
-			if (get_u8(&mcast_router, *argv, 0))
-				invarg("invalid mcast_router", *argv);
-			addattr8(n, 1024, IFLA_BRPORT_MULTICAST_ROUTER,
-				 mcast_router);
-		} else if (matches(*argv, "mcast_fast_leave") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("mcast_fast_leave", *argv, n,
-						  IFLA_BRPORT_FAST_LEAVE);
-		} else if (matches(*argv, "neigh_suppress") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("neigh_suppress", *argv, n,
-						  IFLA_BRPORT_NEIGH_SUPPRESS);
-		} else if (matches(*argv, "group_fwd_mask") == 0) {
-			__u16 mask;
-
-			NEXT_ARG();
-			if (get_u16(&mask, *argv, 0))
-				invarg("invalid group_fwd_mask", *argv);
-			addattr16(n, 1024, IFLA_BRPORT_GROUP_FWD_MASK, mask);
-		} else if (matches(*argv, "vlan_tunnel") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("vlan_tunnel", *argv, n,
-						  IFLA_BRPORT_VLAN_TUNNEL);
-		} else if (matches(*argv, "isolated") == 0) {
-			NEXT_ARG();
-			bridge_slave_parse_on_off("isolated", *argv, n,
-						  IFLA_BRPORT_ISOLATED);
-		} else if (matches(*argv, "backup_port") == 0) {
-			int ifindex;
-
-			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
-			if (!ifindex)
-				invarg("Device does not exist\n", *argv);
-			addattr32(n, 1024, IFLA_BRPORT_BACKUP_PORT, ifindex);
-		} else if (matches(*argv, "nobackup_port") == 0) {
-			addattr32(n, 1024, IFLA_BRPORT_BACKUP_PORT, 0);
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -437,11 +184,10 @@
 }
 
 struct link_util bridge_slave_link_util = {
-	.id		= "bridge_slave",
+	.id		= "bridge",
 	.maxattr	= IFLA_BRPORT_MAX,
 	.print_opt	= bridge_slave_print_opt,
 	.parse_opt	= bridge_slave_parse_opt,
 	.print_help     = bridge_slave_print_help,
-	.parse_ifla_xstats = bridge_parse_xstats,
-	.print_ifla_xstats = bridge_print_xstats,
+	.slave		= true,
 };
diff --git a/ip/iplink_can.c b/ip/iplink_can.c
index 735ab94..f1b089d 100644
--- a/ip/iplink_can.c
+++ b/ip/iplink_can.c
@@ -23,11 +23,13 @@
 {
 	fprintf(f,
 		"Usage: ip link set DEVICE type can\n"
-		"\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |\n"
-		"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n \t  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
+		"\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | \n"
+		"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n "
+		"\t  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
 		"\n"
-		"\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |\n"
-		"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n \t  dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
+		"\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | \n"
+		"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n "
+		"\t  dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
 		"\n"
 		"\t[ loopback { on | off } ]\n"
 		"\t[ listen-only { on | off } ]\n"
@@ -41,8 +43,6 @@
 		"\t[ restart-ms TIME-MS ]\n"
 		"\t[ restart ]\n"
 		"\n"
-		"\t[ termination { 0..65535 } ]\n"
-		"\n"
 		"\tWhere: BITRATE	:= { 1..1000000 }\n"
 		"\t	  SAMPLE-POINT	:= { 0.000..0.999 }\n"
 		"\t	  TQ		:= { NUMBER }\n"
@@ -73,7 +73,7 @@
 	return 0;
 }
 
-static void set_ctrlmode(char *name, char *arg,
+static void set_ctrlmode(char* name, char *arg,
 			 struct can_ctrlmode *cm, __u32 flags)
 {
 	if (strcmp(arg, "on") == 0) {
@@ -89,11 +89,11 @@
 
 static void print_ctrlmode(FILE *f, __u32 cm)
 {
-	open_json_array(PRINT_ANY, is_json_context() ? "ctrlmode" : "<");
-#define _PF(cmflag, cmname)						\
-	if (cm & cmflag) {						\
-		cm &= ~cmflag;						\
-		print_string(PRINT_ANY, NULL, cm ? "%s," : "%s", cmname); \
+	fprintf(f, "<");
+#define _PF(cmflag, cmname)					\
+	if (cm & cmflag) {					\
+		cm &= ~cmflag;					\
+		fprintf(f, "%s%s", cmname, cm ? "," : "");	\
 	}
 	_PF(CAN_CTRLMODE_LOOPBACK, "LOOPBACK");
 	_PF(CAN_CTRLMODE_LISTENONLY, "LISTEN-ONLY");
@@ -105,16 +105,18 @@
 	_PF(CAN_CTRLMODE_PRESUME_ACK, "PRESUME-ACK");
 #undef _PF
 	if (cm)
-		print_hex(PRINT_ANY, NULL, "%x", cm);
-	close_json_array(PRINT_ANY, "> ");
+		fprintf(f, "%x", cm);
+	fprintf(f, "> ");
 }
 
 static int can_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
-	struct can_bittiming bt = {}, dbt = {};
+	struct can_bittiming bt, dbt;
 	struct can_ctrlmode cm = {0, 0};
 
+	memset(&bt, 0, sizeof(bt));
+	memset(&dbt, 0, sizeof(dbt));
 	while (argc > 0) {
 		if (matches(*argv, "bitrate") == 0) {
 			NEXT_ARG();
@@ -222,14 +224,6 @@
 			if (get_u32(&val, *argv, 0))
 				invarg("invalid \"restart-ms\" value\n", *argv);
 			addattr32(n, 1024, IFLA_CAN_RESTART_MS, val);
-		} else if (matches(*argv, "termination") == 0) {
-			__u16 val;
-
-			NEXT_ARG();
-			if (get_u16(&val, *argv, 0))
-				invarg("invalid \"termination\" value\n",
-				       *argv);
-			addattr16(n, 1024, IFLA_CAN_TERMINATION, val);
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 			return -1;
@@ -251,7 +245,7 @@
 	return 0;
 }
 
-static const char *can_state_names[CAN_STATE_MAX] = {
+static const char *can_state_names[] = {
 	[CAN_STATE_ERROR_ACTIVE] = "ERROR-ACTIVE",
 	[CAN_STATE_ERROR_WARNING] = "ERROR-WARNING",
 	[CAN_STATE_ERROR_PASSIVE] = "ERROR-PASSIVE",
@@ -260,14 +254,6 @@
 	[CAN_STATE_SLEEPING] = "SLEEPING"
 };
 
-static void can_print_json_timing_min_max(const char *attr, int min, int max)
-{
-	open_json_object(attr);
-	print_int(PRINT_JSON, "min", NULL, min);
-	print_int(PRINT_JSON, "max", NULL, max);
-	close_json_object();
-}
-
 static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
 	if (!tb)
@@ -281,272 +267,79 @@
 	}
 
 	if (tb[IFLA_CAN_STATE]) {
-		uint32_t state = rta_getattr_u32(tb[IFLA_CAN_STATE]);
+		int *state = RTA_DATA(tb[IFLA_CAN_STATE]);
 
-		print_string(PRINT_ANY, "state", "state %s ", state < CAN_STATE_MAX ?
-			can_state_names[state] : "UNKNOWN");
+		fprintf(f, "state %s ", *state <= CAN_STATE_MAX ?
+			can_state_names[*state] : "UNKNOWN");
 	}
 
 	if (tb[IFLA_CAN_BERR_COUNTER]) {
 		struct can_berr_counter *bc =
 			RTA_DATA(tb[IFLA_CAN_BERR_COUNTER]);
 
-		if (is_json_context()) {
-			open_json_object("berr_counter");
-			print_int(PRINT_JSON, "tx", NULL, bc->txerr);
-			print_int(PRINT_JSON, "rx", NULL, bc->rxerr);
-			close_json_object();
-		} else {
-			fprintf(f, "(berr-counter tx %d rx %d) ",
-				bc->txerr, bc->rxerr);
-		}
+		fprintf(f, "(berr-counter tx %d rx %d) ", bc->txerr, bc->rxerr);
 	}
 
 	if (tb[IFLA_CAN_RESTART_MS]) {
 		__u32 *restart_ms = RTA_DATA(tb[IFLA_CAN_RESTART_MS]);
 
-		print_int(PRINT_ANY,
-			  "restart_ms",
-			  "restart-ms %d ",
-			  *restart_ms);
+		fprintf(f, "restart-ms %d ", *restart_ms);
 	}
 
-	/* bittiming is irrelevant if fixed bitrate is defined */
-	if (tb[IFLA_CAN_BITTIMING] && !tb[IFLA_CAN_BITRATE_CONST]) {
+	if (tb[IFLA_CAN_BITTIMING]) {
 		struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
 
-		if (is_json_context()) {
-			json_writer_t *jw;
-
-			open_json_object("bittiming");
-			print_int(PRINT_ANY, "bitrate", NULL, bt->bitrate);
-			jw = get_json_writer();
-			jsonw_name(jw, "sample_point");
-			jsonw_printf(jw, "%.3f",
-				     (float) bt->sample_point / 1000);
-			print_int(PRINT_ANY, "tq", NULL, bt->tq);
-			print_int(PRINT_ANY, "prop_seg", NULL, bt->prop_seg);
-			print_int(PRINT_ANY, "phase_seg1",
-				  NULL, bt->phase_seg1);
-			print_int(PRINT_ANY, "phase_seg2",
-				  NULL, bt->phase_seg2);
-			print_int(PRINT_ANY, "sjw", NULL, bt->sjw);
-			close_json_object();
-		} else {
-			fprintf(f, "\n	  bitrate %d sample-point %.3f ",
-				bt->bitrate, (float) bt->sample_point / 1000.);
-			fprintf(f,
-				"\n	  tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
-				bt->tq, bt->prop_seg,
-				bt->phase_seg1, bt->phase_seg2,
-				bt->sjw);
-		}
+		fprintf(f, "\n	  "
+			"bitrate %d sample-point %.3f ",
+			bt->bitrate, (float)bt->sample_point / 1000.);
+		fprintf(f, "\n	  "
+			"tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
+			bt->tq, bt->prop_seg, bt->phase_seg1, bt->phase_seg2,
+			bt->sjw);
 	}
 
-	/* bittiming const is irrelevant if fixed bitrate is defined */
-	if (tb[IFLA_CAN_BITTIMING_CONST] && !tb[IFLA_CAN_BITRATE_CONST]) {
+	if (tb[IFLA_CAN_BITTIMING_CONST]) {
 		struct can_bittiming_const *btc =
 			RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]);
 
-		if (is_json_context()) {
-			open_json_object("bittiming_const");
-			print_string(PRINT_JSON, "name", NULL, btc->name);
-			can_print_json_timing_min_max("tseg1",
-						      btc->tseg1_min,
-						      btc->tseg1_max);
-			can_print_json_timing_min_max("tseg2",
-						      btc->tseg2_min,
-						      btc->tseg2_max);
-			can_print_json_timing_min_max("sjw", 1, btc->sjw_max);
-			can_print_json_timing_min_max("brp",
-						      btc->brp_min,
-						      btc->brp_max);
-			print_int(PRINT_JSON, "brp_inc", NULL, btc->brp_inc);
-			close_json_object();
-		} else {
-			fprintf(f, "\n	  %s: tseg1 %d..%d tseg2 %d..%d "
-				"sjw 1..%d brp %d..%d brp-inc %d",
-				btc->name, btc->tseg1_min, btc->tseg1_max,
-				btc->tseg2_min, btc->tseg2_max, btc->sjw_max,
-				btc->brp_min, btc->brp_max, btc->brp_inc);
-		}
+		fprintf(f, "\n	  "
+			"%s: tseg1 %d..%d tseg2 %d..%d "
+			"sjw 1..%d brp %d..%d brp-inc %d",
+			btc->name, btc->tseg1_min, btc->tseg1_max,
+			btc->tseg2_min, btc->tseg2_max, btc->sjw_max,
+			btc->brp_min, btc->brp_max, btc->brp_inc);
 	}
 
-	if (tb[IFLA_CAN_BITRATE_CONST]) {
-		__u32 *bitrate_const = RTA_DATA(tb[IFLA_CAN_BITRATE_CONST]);
-		int bitrate_cnt = RTA_PAYLOAD(tb[IFLA_CAN_BITRATE_CONST]) /
-			sizeof(*bitrate_const);
-		int i;
-		__u32 bitrate = 0;
-
-		if (tb[IFLA_CAN_BITTIMING]) {
-			struct can_bittiming *bt =
-				RTA_DATA(tb[IFLA_CAN_BITTIMING]);
-			bitrate = bt->bitrate;
-		}
-
-		if (is_json_context()) {
-			print_uint(PRINT_JSON,
-				   "bittiming_bitrate",
-				   NULL, bitrate);
-			open_json_array(PRINT_JSON, "bitrate_const");
-			for (i = 0; i < bitrate_cnt; ++i)
-				print_uint(PRINT_JSON, NULL, NULL,
-					   bitrate_const[i]);
-			close_json_array(PRINT_JSON, NULL);
-		} else {
-			fprintf(f, "\n	  bitrate %u", bitrate);
-			fprintf(f, "\n	     [");
-
-			for (i = 0; i < bitrate_cnt - 1; ++i) {
-				/* This will keep lines below 80 signs */
-				if (!(i % 6) && i)
-					fprintf(f, "\n	      ");
-
-				fprintf(f, "%8u, ", bitrate_const[i]);
-			}
-
-			if (!(i % 6) && i)
-				fprintf(f, "\n	      ");
-			fprintf(f, "%8u ]", bitrate_const[i]);
-		}
-	}
-
-	/* data bittiming is irrelevant if fixed bitrate is defined */
-	if (tb[IFLA_CAN_DATA_BITTIMING] && !tb[IFLA_CAN_DATA_BITRATE_CONST]) {
+	if (tb[IFLA_CAN_DATA_BITTIMING]) {
 		struct can_bittiming *dbt =
 			RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
 
-		if (is_json_context()) {
-			json_writer_t *jw;
-
-			open_json_object("data_bittiming");
-			print_int(PRINT_JSON, "bitrate", NULL, dbt->bitrate);
-			jw = get_json_writer();
-			jsonw_name(jw, "sample_point");
-			jsonw_printf(jw, "%.3f",
-				     (float) dbt->sample_point / 1000.);
-			print_int(PRINT_JSON, "tq", NULL, dbt->tq);
-			print_int(PRINT_JSON, "prop_seg", NULL, dbt->prop_seg);
-			print_int(PRINT_JSON, "phase_seg1",
-				  NULL, dbt->phase_seg1);
-			print_int(PRINT_JSON, "phase_seg2",
-				  NULL, dbt->phase_seg2);
-			print_int(PRINT_JSON, "sjw", NULL, dbt->sjw);
-			close_json_object();
-		} else {
-			fprintf(f, "\n	  dbitrate %d dsample-point %.3f ",
-				dbt->bitrate,
-				(float) dbt->sample_point / 1000.);
-			fprintf(f, "\n	  dtq %d dprop-seg %d dphase-seg1 %d "
-				"dphase-seg2 %d dsjw %d",
-				dbt->tq, dbt->prop_seg, dbt->phase_seg1,
-				dbt->phase_seg2, dbt->sjw);
-		}
+		fprintf(f, "\n	  "
+			"dbitrate %d dsample-point %.3f ",
+			dbt->bitrate, (float)dbt->sample_point / 1000.);
+		fprintf(f, "\n	  "
+			"dtq %d dprop-seg %d dphase-seg1 %d "
+			"dphase-seg2 %d dsjw %d",
+			dbt->tq, dbt->prop_seg, dbt->phase_seg1,
+			dbt->phase_seg2, dbt->sjw);
 	}
 
-	/* data bittiming const is irrelevant if fixed bitrate is defined */
-	if (tb[IFLA_CAN_DATA_BITTIMING_CONST] &&
-	    !tb[IFLA_CAN_DATA_BITRATE_CONST]) {
+	if (tb[IFLA_CAN_DATA_BITTIMING_CONST]) {
 		struct can_bittiming_const *dbtc =
 			RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]);
 
-		if (is_json_context()) {
-			open_json_object("data_bittiming_const");
-			print_string(PRINT_JSON, "name", NULL, dbtc->name);
-			can_print_json_timing_min_max("tseg1",
-						      dbtc->tseg1_min,
-						      dbtc->tseg1_max);
-			can_print_json_timing_min_max("tseg2",
-						      dbtc->tseg2_min,
-						      dbtc->tseg2_max);
-			can_print_json_timing_min_max("sjw", 1, dbtc->sjw_max);
-			can_print_json_timing_min_max("brp",
-						      dbtc->brp_min,
-						      dbtc->brp_max);
-
-			print_int(PRINT_JSON, "brp_inc", NULL, dbtc->brp_inc);
-			close_json_object();
-		} else {
-			fprintf(f, "\n	  %s: dtseg1 %d..%d dtseg2 %d..%d "
-				"dsjw 1..%d dbrp %d..%d dbrp-inc %d",
-				dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
-				dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
-				dbtc->brp_min, dbtc->brp_max, dbtc->brp_inc);
-		}
-	}
-
-	if (tb[IFLA_CAN_DATA_BITRATE_CONST]) {
-		__u32 *dbitrate_const =
-			RTA_DATA(tb[IFLA_CAN_DATA_BITRATE_CONST]);
-		int dbitrate_cnt =
-			RTA_PAYLOAD(tb[IFLA_CAN_DATA_BITRATE_CONST]) /
-			sizeof(*dbitrate_const);
-		int i;
-		__u32 dbitrate = 0;
-
-		if (tb[IFLA_CAN_DATA_BITTIMING]) {
-			struct can_bittiming *dbt =
-				RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
-			dbitrate = dbt->bitrate;
-		}
-
-		if (is_json_context()) {
-			print_uint(PRINT_JSON, "data_bittiming_bitrate",
-				   NULL, dbitrate);
-			open_json_array(PRINT_JSON, "data_bitrate_const");
-			for (i = 0; i < dbitrate_cnt; ++i)
-				print_uint(PRINT_JSON, NULL, NULL,
-					   dbitrate_const[i]);
-			close_json_array(PRINT_JSON, NULL);
-		} else {
-			fprintf(f, "\n	  dbitrate %u", dbitrate);
-			fprintf(f, "\n	     [");
-
-			for (i = 0; i < dbitrate_cnt - 1; ++i) {
-				/* This will keep lines below 80 signs */
-				if (!(i % 6) && i)
-					fprintf(f, "\n	      ");
-
-				fprintf(f, "%8u, ", dbitrate_const[i]);
-			}
-
-			if (!(i % 6) && i)
-				fprintf(f, "\n	      ");
-			fprintf(f, "%8u ]", dbitrate_const[i]);
-		}
-	}
-
-	if (tb[IFLA_CAN_TERMINATION_CONST] && tb[IFLA_CAN_TERMINATION]) {
-		__u16 *trm = RTA_DATA(tb[IFLA_CAN_TERMINATION]);
-		__u16 *trm_const = RTA_DATA(tb[IFLA_CAN_TERMINATION_CONST]);
-		int trm_cnt = RTA_PAYLOAD(tb[IFLA_CAN_TERMINATION_CONST]) /
-			sizeof(*trm_const);
-		int i;
-
-		if (is_json_context()) {
-			print_hu(PRINT_JSON, "termination", NULL, *trm);
-			open_json_array(PRINT_JSON, "termination_const");
-			for (i = 0; i < trm_cnt; ++i)
-				print_hu(PRINT_JSON, NULL, NULL, trm_const[i]);
-			close_json_array(PRINT_JSON, NULL);
-		} else {
-			fprintf(f, "\n	  termination %hu [ ", *trm);
-
-			for (i = 0; i < trm_cnt - 1; ++i)
-				fprintf(f, "%hu, ", trm_const[i]);
-
-			fprintf(f, "%hu ]", trm_const[i]);
-		}
+		fprintf(f, "\n	  "
+			"%s: dtseg1 %d..%d dtseg2 %d..%d "
+			"dsjw 1..%d dbrp %d..%d dbrp-inc %d",
+			dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
+			dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
+			dbtc->brp_min, dbtc->brp_max, dbtc->brp_inc);
 	}
 
 	if (tb[IFLA_CAN_CLOCK]) {
 		struct can_clock *clock = RTA_DATA(tb[IFLA_CAN_CLOCK]);
 
-		print_int(PRINT_ANY,
-			  "clock",
-			  "\n	  clock %d ",
-			  clock->freq);
+		fprintf(f, "\n	  clock %d", clock->freq);
 	}
 
 }
@@ -558,32 +351,18 @@
 
 	if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) {
 		stats = RTA_DATA(xstats);
-
-		if (is_json_context()) {
-			print_int(PRINT_JSON, "restarts",
-				  NULL, stats->restarts);
-			print_int(PRINT_JSON, "bus_error",
-				  NULL, stats->bus_error);
-			print_int(PRINT_JSON, "arbitration_lost",
-				  NULL, stats->arbitration_lost);
-			print_int(PRINT_JSON, "error_warning",
-				  NULL, stats->error_warning);
-			print_int(PRINT_JSON, "error_passive",
-				  NULL, stats->error_passive);
-			print_int(PRINT_JSON, "bus_off", NULL, stats->bus_off);
-		} else {
-			fprintf(f, "\n	  re-started bus-errors arbit-lost "
-				"error-warn error-pass bus-off");
-			fprintf(f, "\n	  %-10d %-10d %-10d %-10d %-10d %-10d",
-				stats->restarts, stats->bus_error,
-				stats->arbitration_lost, stats->error_warning,
-				stats->error_passive, stats->bus_off);
-		}
+		fprintf(f, "\n	  "
+			"re-started bus-errors arbit-lost "
+			"error-warn error-pass bus-off");
+		fprintf(f, "\n	  %-10d %-10d %-10d %-10d %-10d %-10d",
+			stats->restarts, stats->bus_error,
+			stats->arbitration_lost, stats->error_warning,
+			stats->error_passive, stats->bus_off);
 	}
 }
 
 static void can_print_help(struct link_util *lu, int argc, char **argv,
-			   FILE *f)
+	FILE *f)
 {
 	print_usage(f);
 }
diff --git a/ip/iplink_dummy.c b/ip/iplink_dummy.c
deleted file mode 100644
index cba2295..0000000
--- a/ip/iplink_dummy.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void dummy_print_help(struct link_util *lu,
-			    int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... dummy\n");
-}
-
-struct link_util dummy_link_util = {
-	.id		= "dummy",
-	.print_help	= dummy_print_help,
-};
diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c
index 9299236..1345479 100644
--- a/ip/iplink_geneve.c
+++ b/ip/iplink_geneve.c
@@ -15,30 +15,15 @@
 #include "utils.h"
 #include "ip_common.h"
 
-#define GENEVE_ATTRSET(attrs, type) (((attrs) & (1L << (type))) != 0)
-
 static void print_explain(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... geneve id VNI\n"
-		"		remote ADDR\n"
-		"		[ ttl TTL ]\n"
-		"		[ tos TOS ]\n"
-		"		[ df DF ]\n"
-		"		[ flowlabel LABEL ]\n"
-		"		[ dstport PORT ]\n"
-		"		[ [no]external ]\n"
-		"		[ [no]udpcsum ]\n"
-		"		[ [no]udp6zerocsumtx ]\n"
-		"		[ [no]udp6zerocsumrx ]\n"
-		"\n"
-		"Where:	VNI   := 0-16777215\n"
-		"	ADDR  := IP_ADDRESS\n"
-		"	TOS   := { NUMBER | inherit }\n"
-		"	TTL   := { 1..255 | auto | inherit }\n"
-		"	DF    := { unset | set | inherit }\n"
-		"	LABEL := 0-1048575\n"
-	);
+	fprintf(f, "Usage: ... geneve id VNI remote ADDR\n");
+	fprintf(f, "                 [ ttl TTL ] [ tos TOS ]\n");
+	fprintf(f, "\n");
+	fprintf(f, "Where: VNI  := 0-16777215\n");
+	fprintf(f, "       ADDR := IP_ADDRESS\n");
+	fprintf(f, "       TOS  := { NUMBER | inherit }\n");
+	fprintf(f, "       TTL  := { 1..255 | inherit }\n");
 }
 
 static void explain(void)
@@ -46,59 +31,38 @@
 	print_explain(stderr);
 }
 
-static void check_duparg(__u64 *attrs, int type, const char *key,
-			 const char *argv)
-{
-	if (!GENEVE_ATTRSET(*attrs, type)) {
-		*attrs |= (1L << type);
-		return;
-	}
-	duparg2(key, argv);
-}
-
 static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
 			  struct nlmsghdr *n)
 {
-	inet_prefix daddr;
 	__u32 vni = 0;
-	__u32 label = 0;
+	int vni_set = 0;
+	__u32 daddr = 0;
+	struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
 	__u8 ttl = 0;
 	__u8 tos = 0;
-	__u16 dstport = 0;
-	bool metadata = 0;
-	__u8 udpcsum = 0;
-	__u8 udp6zerocsumtx = 0;
-	__u8 udp6zerocsumrx = 0;
-	__u64 attrs = 0;
-	bool set_op = (n->nlmsg_type == RTM_NEWLINK &&
-		       !(n->nlmsg_flags & NLM_F_CREATE));
-
-	inet_prefix_reset(&daddr);
 
 	while (argc > 0) {
 		if (!matches(*argv, "id") ||
 		    !matches(*argv, "vni")) {
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_ID, "id", *argv);
 			if (get_u32(&vni, *argv, 0) ||
 			    vni >= 1u << 24)
 				invarg("invalid id", *argv);
+			vni_set = 1;
 		} else if (!matches(*argv, "remote")) {
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_REMOTE, "remote",
-				     *argv);
-			get_addr(&daddr, *argv, AF_UNSPEC);
-			if (!is_addrtype_inet_not_multi(&daddr))
+			if (!inet_get_addr(*argv, &daddr, &daddr6)) {
+				fprintf(stderr, "Invalid address \"%s\"\n", *argv);
+				return -1;
+			}
+			if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
 				invarg("invalid remote address", *argv);
 		} else if (!matches(*argv, "ttl") ||
 			   !matches(*argv, "hoplimit")) {
-			unsigned int uval;
+			unsigned uval;
 
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_TTL, "ttl", *argv);
-			if (strcmp(*argv, "inherit") == 0) {
-				addattr8(n, 1024, IFLA_GENEVE_TTL_INHERIT, 1);
-			} else if (strcmp(*argv, "auto") != 0) {
+			if (strcmp(*argv, "inherit") != 0) {
 				if (get_unsigned(&uval, *argv, 0))
 					invarg("invalid TTL", *argv);
 				if (uval > 255)
@@ -110,78 +74,12 @@
 			__u32 uval;
 
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_TOS, "tos", *argv);
 			if (strcmp(*argv, "inherit") != 0) {
 				if (rtnl_dsfield_a2n(&uval, *argv))
 					invarg("bad TOS value", *argv);
 				tos = uval;
 			} else
 				tos = 1;
-		} else if (!matches(*argv, "df")) {
-			enum ifla_geneve_df df;
-
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_DF, "df", *argv);
-			if (strcmp(*argv, "unset") == 0)
-				df = GENEVE_DF_UNSET;
-			else if (strcmp(*argv, "set") == 0)
-				df = GENEVE_DF_SET;
-			else if (strcmp(*argv, "inherit") == 0)
-				df = GENEVE_DF_INHERIT;
-			else
-				invarg("DF must be 'unset', 'set' or 'inherit'",
-				       *argv);
-
-			addattr8(n, 1024, IFLA_GENEVE_DF, df);
-		} else if (!matches(*argv, "label") ||
-			   !matches(*argv, "flowlabel")) {
-			__u32 uval;
-
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_LABEL, "flowlabel",
-				     *argv);
-			if (get_u32(&uval, *argv, 0) ||
-			    (uval & ~LABEL_MAX_MASK))
-				invarg("invalid flowlabel", *argv);
-			label = htonl(uval);
-		} else if (!matches(*argv, "dstport")) {
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_GENEVE_PORT, "dstport",
-				     *argv);
-			if (get_u16(&dstport, *argv, 0))
-				invarg("dstport", *argv);
-		} else if (!matches(*argv, "external")) {
-			check_duparg(&attrs, IFLA_GENEVE_COLLECT_METADATA,
-				     *argv, *argv);
-			metadata = true;
-		} else if (!matches(*argv, "noexternal")) {
-			check_duparg(&attrs, IFLA_GENEVE_COLLECT_METADATA,
-				     *argv, *argv);
-			metadata = false;
-		} else if (!matches(*argv, "udpcsum")) {
-			check_duparg(&attrs, IFLA_GENEVE_UDP_CSUM, *argv,
-				     *argv);
-			udpcsum = 1;
-		} else if (!matches(*argv, "noudpcsum")) {
-			check_duparg(&attrs, IFLA_GENEVE_UDP_CSUM, *argv,
-				     *argv);
-			udpcsum = 0;
-		} else if (!matches(*argv, "udp6zerocsumtx")) {
-			check_duparg(&attrs, IFLA_GENEVE_UDP_ZERO_CSUM6_TX,
-				     *argv, *argv);
-			udp6zerocsumtx = 1;
-		} else if (!matches(*argv, "noudp6zerocsumtx")) {
-			check_duparg(&attrs, IFLA_GENEVE_UDP_ZERO_CSUM6_TX,
-				     *argv, *argv);
-			udp6zerocsumtx = 0;
-		} else if (!matches(*argv, "udp6zerocsumrx")) {
-			check_duparg(&attrs, IFLA_GENEVE_UDP_ZERO_CSUM6_RX,
-				     *argv, *argv);
-			udp6zerocsumrx = 1;
-		} else if (!matches(*argv, "noudp6zerocsumrx")) {
-			check_duparg(&attrs, IFLA_GENEVE_UDP_ZERO_CSUM6_RX,
-				     *argv, *argv);
-			udp6zerocsumrx = 0;
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -193,50 +91,23 @@
 		argc--, argv++;
 	}
 
-	if (metadata && GENEVE_ATTRSET(attrs, IFLA_GENEVE_ID)) {
-		fprintf(stderr, "geneve: both 'external' and vni cannot be specified\n");
+	if (!vni_set) {
+		fprintf(stderr, "geneve: missing virtual network identifier\n");
 		return -1;
 	}
 
-	if (!metadata) {
-		/* parameter checking make sense only for full geneve tunnels */
-		if (!GENEVE_ATTRSET(attrs, IFLA_GENEVE_ID)) {
-			fprintf(stderr, "geneve: missing virtual network identifier\n");
-			return -1;
-		}
-
-		/* If we are modifying the geneve device, then we only need the
-		 * ID (VNI) to identify the geneve device, and we do not need
-		 * the remote IP.
-		 */
-		if (!set_op && !is_addrtype_inet(&daddr)) {
-			fprintf(stderr, "geneve: remote link partner not specified\n");
-			return -1;
-		}
+	if (!daddr && memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) == 0) {
+		fprintf(stderr, "geneve: remote link partner not specified\n");
+		return -1;
 	}
 
 	addattr32(n, 1024, IFLA_GENEVE_ID, vni);
-	if (is_addrtype_inet(&daddr)) {
-		int type = (daddr.family == AF_INET) ? IFLA_GENEVE_REMOTE :
-						       IFLA_GENEVE_REMOTE6;
-		addattr_l(n, 1024, type, daddr.data, daddr.bytelen);
-	}
-	if (!set_op || GENEVE_ATTRSET(attrs, IFLA_GENEVE_LABEL))
-		addattr32(n, 1024, IFLA_GENEVE_LABEL, label);
-	if (!set_op || GENEVE_ATTRSET(attrs, IFLA_GENEVE_TTL))
-		addattr8(n, 1024, IFLA_GENEVE_TTL, ttl);
-	if (!set_op || GENEVE_ATTRSET(attrs, IFLA_GENEVE_TOS))
-		addattr8(n, 1024, IFLA_GENEVE_TOS, tos);
-	if (dstport)
-		addattr16(n, 1024, IFLA_GENEVE_PORT, htons(dstport));
-	if (metadata)
-		addattr(n, 1024, IFLA_GENEVE_COLLECT_METADATA);
-	if (GENEVE_ATTRSET(attrs, IFLA_GENEVE_UDP_CSUM))
-		addattr8(n, 1024, IFLA_GENEVE_UDP_CSUM, udpcsum);
-	if (GENEVE_ATTRSET(attrs, IFLA_GENEVE_UDP_ZERO_CSUM6_TX))
-		addattr8(n, 1024, IFLA_GENEVE_UDP_ZERO_CSUM6_TX, udp6zerocsumtx);
-	if (GENEVE_ATTRSET(attrs, IFLA_GENEVE_UDP_ZERO_CSUM6_RX))
-		addattr8(n, 1024, IFLA_GENEVE_UDP_ZERO_CSUM6_RX, udp6zerocsumrx);
+	if (daddr)
+		addattr_l(n, 1024, IFLA_GENEVE_REMOTE, &daddr, 4);
+	if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0)
+		addattr_l(n, 1024, IFLA_GENEVE_REMOTE6, &daddr6, sizeof(struct in6_addr));
+	addattr8(n, 1024, IFLA_GENEVE_TTL, ttl);
+	addattr8(n, 1024, IFLA_GENEVE_TOS, tos);
 
 	return 0;
 }
@@ -244,130 +115,46 @@
 static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
 	__u32 vni;
-	__u8 ttl = 0;
-	__u8 tos = 0;
+	char s1[1024];
+	__u8 tos;
 
 	if (!tb)
 		return;
 
-	if (tb[IFLA_GENEVE_COLLECT_METADATA]) {
-		print_bool(PRINT_ANY, "external", "external ", true);
-		return;
-	}
-
 	if (!tb[IFLA_GENEVE_ID] ||
 	    RTA_PAYLOAD(tb[IFLA_GENEVE_ID]) < sizeof(__u32))
 		return;
 
 	vni = rta_getattr_u32(tb[IFLA_GENEVE_ID]);
-	print_uint(PRINT_ANY, "id", "id %u ", vni);
+	fprintf(f, "id %u ", vni);
 
 	if (tb[IFLA_GENEVE_REMOTE]) {
 		__be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]);
-
 		if (addr)
-			print_string(PRINT_ANY,
-				     "remote",
-				     "remote %s ",
-				     format_host(AF_INET, 4, &addr));
+			fprintf(f, "remote %s ",
+				format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
 	} else if (tb[IFLA_GENEVE_REMOTE6]) {
 		struct in6_addr addr;
-
 		memcpy(&addr, RTA_DATA(tb[IFLA_GENEVE_REMOTE6]), sizeof(struct in6_addr));
-		if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) {
-			if (!IN6_IS_ADDR_MULTICAST(&addr))
-				print_string(PRINT_ANY,
-					     "remote6",
-					     "remote %s ",
-					     format_host(AF_INET6,
-							 sizeof(struct in6_addr),
-							 &addr));
+		if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
+			if (IN6_IS_ADDR_MULTICAST(&addr))
+				fprintf(f, "remote %s ",
+					format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
 		}
 	}
 
-	if (tb[IFLA_GENEVE_TTL_INHERIT] &&
-	    rta_getattr_u8(tb[IFLA_GENEVE_TTL_INHERIT])) {
-		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
-	} else if (tb[IFLA_GENEVE_TTL]) {
-		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
-		if (is_json_context() || ttl)
-			print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
+	if (tb[IFLA_GENEVE_TTL]) {
+		__u8 ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
+		if (ttl)
+			fprintf(f, "ttl %d ", ttl);
+	}
+
+	if (tb[IFLA_GENEVE_TOS] &&
+	    (tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]))) {
+		if (tos == 1)
+			fprintf(f, "tos inherit ");
 		else
-			print_string(PRINT_FP, NULL, "ttl %s ", "auto");
-	}
-
-	if (tb[IFLA_GENEVE_TOS])
-		tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]);
-	if (tos) {
-		if (is_json_context() || tos != 1)
-			print_0xhex(PRINT_ANY, "tos", "tos %#llx ", tos);
-		else
-			print_string(PRINT_FP, NULL, "tos %s ", "inherit");
-	}
-
-	if (tb[IFLA_GENEVE_DF]) {
-		enum ifla_geneve_df df = rta_getattr_u8(tb[IFLA_GENEVE_DF]);
-
-		if (df == GENEVE_DF_UNSET)
-			print_string(PRINT_JSON, "df", "df %s ", "unset");
-		else if (df == GENEVE_DF_SET)
-			print_string(PRINT_ANY, "df", "df %s ", "set");
-		else if (df == GENEVE_DF_INHERIT)
-			print_string(PRINT_ANY, "df", "df %s ", "inherit");
-	}
-
-	if (tb[IFLA_GENEVE_LABEL]) {
-		__u32 label = rta_getattr_u32(tb[IFLA_GENEVE_LABEL]);
-
-		if (label)
-			print_0xhex(PRINT_ANY,
-				    "label", "flowlabel %#llx ",
-				    ntohl(label));
-	}
-
-	if (tb[IFLA_GENEVE_PORT])
-		print_uint(PRINT_ANY,
-			   "port",
-			   "dstport %u ",
-			   rta_getattr_be16(tb[IFLA_GENEVE_PORT]));
-
-	if (tb[IFLA_GENEVE_UDP_CSUM]) {
-		if (is_json_context()) {
-			print_bool(PRINT_JSON,
-				   "udp_csum",
-				   NULL,
-				   rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM]));
-		} else {
-			if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM]))
-				fputs("no", f);
-			fputs("udpcsum ", f);
-		}
-	}
-
-	if (tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]) {
-		if (is_json_context()) {
-			print_bool(PRINT_JSON,
-				   "udp_zero_csum6_tx",
-				   NULL,
-				   rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]));
-		} else {
-			if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]))
-				fputs("no", f);
-			fputs("udp6zerocsumtx ", f);
-		}
-	}
-
-	if (tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]) {
-		if (is_json_context()) {
-			print_bool(PRINT_JSON,
-				   "udp_zero_csum6_rx",
-				   NULL,
-				   rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]));
-		} else {
-			if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]))
-				fputs("no", f);
-			fputs("udp6zerocsumrx ", f);
-		}
+			fprintf(f, "tos %#x ", tos);
 	}
 }
 
diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c
index 7d9167d..65fbec8 100644
--- a/ip/iplink_hsr.c
+++ b/ip/iplink_hsr.c
@@ -24,18 +24,16 @@
 static void print_usage(FILE *f)
 {
 	fprintf(f,
-		"Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n"
-		"\t[ supervision ADDR-BYTE ] [version VERSION]\n"
-		"\n"
-		"NAME\n"
-		"	name of new hsr device (e.g. hsr0)\n"
-		"SLAVE1-IF, SLAVE2-IF\n"
-		"	the two slave devices bound to the HSR device\n"
-		"ADDR-BYTE\n"
-		"	0-255; the last byte of the multicast address used for HSR supervision\n"
-		"	frames (default = 0)\n"
-		"VERSION\n"
-		"	0,1; the protocol version to be used. (default = 0)\n");
+"Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n"
+"\t[ supervision ADDR-BYTE ]\n"
+"\n"
+"NAME\n"
+"	name of new hsr device (e.g. hsr0)\n"
+"SLAVE1-IF, SLAVE2-IF\n"
+"	the two slave devices bound to the HSR device\n"
+"ADDR-BYTE\n"
+"	0-255; the last byte of the multicast address used for HSR supervision\n"
+"	frames (default = 0)\n");
 }
 
 static void usage(void)
@@ -48,7 +46,6 @@
 {
 	int ifindex;
 	unsigned char multicast_spec;
-	unsigned char protocol_version;
 
 	while (argc > 0) {
 		if (matches(*argv, "supervision") == 0) {
@@ -57,13 +54,6 @@
 				invarg("ADDR-BYTE is invalid", *argv);
 			addattr_l(n, 1024, IFLA_HSR_MULTICAST_SPEC,
 				  &multicast_spec, 1);
-		} else if (matches(*argv, "version") == 0) {
-			NEXT_ARG();
-			if (!(get_u8(&protocol_version, *argv, 0) == 0 ||
-			      get_u8(&protocol_version, *argv, 0) == 1))
-				invarg("version is invalid", *argv);
-			addattr_l(n, 1024, IFLA_HSR_VERSION,
-				  &protocol_version, 1);
 		} else if (matches(*argv, "slave1") == 0) {
 			NEXT_ARG();
 			ifindex = ll_name_to_index(*argv);
@@ -110,36 +100,30 @@
 	    RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]) < ETH_ALEN)
 		return;
 
+	fprintf(f, "slave1 ");
 	if (tb[IFLA_HSR_SLAVE1])
-		print_string(PRINT_ANY,
-			     "slave1",
-			     "slave1 %s ",
-			     ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
+		fprintf(f, "%s ",
+			ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
 	else
-		print_null(PRINT_ANY, "slave1", "slave1 %s ", "<none>");
+		fprintf(f, "<none> ");
 
+	fprintf(f, "slave2 ");
 	if (tb[IFLA_HSR_SLAVE2])
-		print_string(PRINT_ANY,
-			     "slave2",
-			     "slave2 %s ",
-			     ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
+		fprintf(f, "%s ",
+			ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
 	else
-		print_null(PRINT_ANY, "slave2", "slave2 %s ", "<none>");
+		fprintf(f, "<none> ");
 
 	if (tb[IFLA_HSR_SEQ_NR])
-		print_int(PRINT_ANY,
-			  "seq_nr",
-			  "sequence %d ",
-			  rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));
+		fprintf(f, "sequence %d ",
+			rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));
 
 	if (tb[IFLA_HSR_SUPERVISION_ADDR])
-		print_string(PRINT_ANY,
-			     "supervision_addr",
-			     "supervision %s ",
-			     ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
-					 RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
-					 ARPHRD_VOID,
-					 b1, sizeof(b1)));
+		fprintf(f, "supervision %s ",
+			ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
+				    RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
+				    ARPHRD_VOID,
+				    b1, sizeof(b1)));
 }
 
 static void hsr_print_help(struct link_util *lu, int argc, char **argv,
@@ -150,7 +134,7 @@
 
 struct link_util hsr_link_util = {
 	.id		= "hsr",
-	.maxattr	= IFLA_HSR_MAX,
+	.maxattr	= IFLA_VLAN_MAX,
 	.parse_opt	= hsr_parse_opt,
 	.print_opt	= hsr_print_opt,
 	.print_help	= hsr_print_help,
diff --git a/ip/iplink_ifb.c b/ip/iplink_ifb.c
deleted file mode 100644
index a2a7301..0000000
--- a/ip/iplink_ifb.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void ifb_print_help(struct link_util *lu,
-			    int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... ifb\n");
-}
-
-struct link_util ifb_link_util = {
-	.id		= "ifb",
-	.print_help	= ifb_print_help,
-};
diff --git a/ip/iplink_ipoib.c b/ip/iplink_ipoib.c
index 05dba35..6087cbe 100644
--- a/ip/iplink_ipoib.c
+++ b/ip/iplink_ipoib.c
@@ -22,9 +22,8 @@
 static void print_explain(FILE *f)
 {
 	fprintf(f,
-		"Usage: ... ipoib [ pkey PKEY ]\n"
-		"		 [ mode {datagram | connected} ]\n"
-		"		 [ umcast {0|1} ]\n"
+		"Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}]"
+		"[umcast {0|1}]\n"
 		"\n"
 		"PKEY  := 0x8001-0xffff\n"
 	);
@@ -37,7 +36,8 @@
 
 static int mode_arg(void)
 {
-	fprintf(stderr, "Error: argument of \"mode\" must be \"datagram\"or \"connected\"\n");
+	fprintf(stderr, "Error: argument of \"mode\" must be \"datagram\""
+		"or \"connected\"\n");
 	return -1;
 }
 
@@ -91,43 +91,23 @@
 	    RTA_PAYLOAD(tb[IFLA_IPOIB_PKEY]) < sizeof(__u16))
 		return;
 
-	__u16 pkey = rta_getattr_u16(tb[IFLA_IPOIB_PKEY]);
-
-	if (is_json_context()) {
-		SPRINT_BUF(b1);
-
-		snprintf(b1, sizeof(b1), "%#.4x", pkey);
-		print_string(PRINT_JSON, "key", NULL, b1);
-	} else {
-		fprintf(f, "pkey  %#.4x ", pkey);
-	}
+	fprintf(f, "pkey  %#.4x ", rta_getattr_u16(tb[IFLA_IPOIB_PKEY]));
 
 	if (!tb[IFLA_IPOIB_MODE] ||
 	    RTA_PAYLOAD(tb[IFLA_IPOIB_MODE]) < sizeof(__u16))
 		return;
 
 	mode = rta_getattr_u16(tb[IFLA_IPOIB_MODE]);
-
-	const char *mode_str =
+	fprintf(f, "mode  %s ",
 		mode == IPOIB_MODE_DATAGRAM ? "datagram" :
-		mode == IPOIB_MODE_CONNECTED ? "connected" : "unknown";
-
-	print_string(PRINT_ANY, "mode", "mode  %s ", mode_str);
+		mode == IPOIB_MODE_CONNECTED ? "connected" :
+		"unknown");
 
 	if (!tb[IFLA_IPOIB_UMCAST] ||
 	    RTA_PAYLOAD(tb[IFLA_IPOIB_UMCAST]) < sizeof(__u16))
 		return;
 
-	__u16 umcast = rta_getattr_u16(tb[IFLA_IPOIB_UMCAST]);
-
-	if (is_json_context()) {
-		SPRINT_BUF(b1);
-
-		snprintf(b1, sizeof(b1), "%.4x", umcast);
-		print_string(PRINT_JSON, "umcast", NULL, b1);
-	} else {
-		fprintf(f, "umcast  %.4x ", umcast);
-	}
+	fprintf(f, "umcast  %.4x ", rta_getattr_u16(tb[IFLA_IPOIB_UMCAST]));
 }
 
 static void ipoib_print_help(struct link_util *lu, int argc, char **argv,
diff --git a/ip/iplink_ipvlan.c b/ip/iplink_ipvlan.c
index baae767..e08fc39 100644
--- a/ip/iplink_ipvlan.c
+++ b/ip/iplink_ipvlan.c
@@ -1,4 +1,4 @@
-/* iplink_ipvlan.c	IPVLAN/IPVTAP device support
+/* iplink_ipvlan.c	IPVLAN device support
  *
  *              This program is free software; you can redistribute it and/or
  *              modify it under the terms of the GNU General Public License
@@ -18,61 +18,50 @@
 #include "utils.h"
 #include "ip_common.h"
 
-static void print_explain(struct link_util *lu, FILE *f)
+static void ipvlan_explain(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... %s [ mode MODE ] [ FLAGS ]\n"
-		"\n"
-		"MODE: l3 | l3s | l2\n"
-		"FLAGS: bridge | private | vepa\n"
-		"(first values are the defaults if nothing is specified).\n",
-		lu->id);
+	fprintf(f, "Usage: ... ipvlan [ mode { l2 | l3 } ]\n");
+}
+
+static void explain(void)
+{
+	ipvlan_explain(stderr);
+}
+
+static int mode_arg(void)
+{
+	fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", "
+		"or \"l3\"\n");
+	return -1;
 }
 
 static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv,
 			    struct nlmsghdr *n)
 {
-	__u16 flags = 0;
-	bool mflag_given = false;
-
 	while (argc > 0) {
 		if (matches(*argv, "mode") == 0) {
 			__u16 mode = 0;
-
 			NEXT_ARG();
 
 			if (strcmp(*argv, "l2") == 0)
 				mode = IPVLAN_MODE_L2;
 			else if (strcmp(*argv, "l3") == 0)
 				mode = IPVLAN_MODE_L3;
-			else if (strcmp(*argv, "l3s") == 0)
-				mode = IPVLAN_MODE_L3S;
-			else {
-				fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", \"l3\" or \"l3s\"\n");
-				return -1;
-			}
+			else
+				return mode_arg();
+
 			addattr16(n, 1024, IFLA_IPVLAN_MODE, mode);
-		} else if (matches(*argv, "private") == 0 && !mflag_given) {
-			flags |= IPVLAN_F_PRIVATE;
-			mflag_given = true;
-		} else if (matches(*argv, "vepa") == 0 && !mflag_given) {
-			flags |= IPVLAN_F_VEPA;
-			mflag_given = true;
-		} else if (matches(*argv, "bridge") == 0 && !mflag_given) {
-			mflag_given = true;
 		} else if (matches(*argv, "help") == 0) {
-			print_explain(lu, stderr);
+			explain();
 			return -1;
 		} else {
-			fprintf(stderr, "%s: unknown option \"%s\"?\n",
-				lu->id, *argv);
-			print_explain(lu, stderr);
+			fprintf(stderr, "ipvlan: unknown option \"%s\"?\n",
+				*argv);
+			explain();
 			return -1;
 		}
-		argc--;
-		argv++;
+		argc--, argv++;
 	}
-	addattr16(n, 1024, IFLA_IPVLAN_FLAGS, flags);
 
 	return 0;
 }
@@ -86,26 +75,10 @@
 	if (tb[IFLA_IPVLAN_MODE]) {
 		if (RTA_PAYLOAD(tb[IFLA_IPVLAN_MODE]) == sizeof(__u16)) {
 			__u16 mode = rta_getattr_u16(tb[IFLA_IPVLAN_MODE]);
-			const char *mode_str = mode == IPVLAN_MODE_L2 ? "l2" :
-				mode == IPVLAN_MODE_L3 ? "l3" :
-				mode == IPVLAN_MODE_L3S ? "l3s" : "unknown";
 
-			print_string(PRINT_ANY, "mode", " mode %s ", mode_str);
-		}
-	}
-	if (tb[IFLA_IPVLAN_FLAGS]) {
-		if (RTA_PAYLOAD(tb[IFLA_IPVLAN_FLAGS]) == sizeof(__u16)) {
-			__u16 flags = rta_getattr_u16(tb[IFLA_IPVLAN_FLAGS]);
-
-			if (flags & IPVLAN_F_PRIVATE)
-				print_bool(PRINT_ANY, "private", "private ",
-					   true);
-			else if (flags & IPVLAN_F_VEPA)
-				print_bool(PRINT_ANY, "vepa", "vepa ",
-					   true);
-			else
-				print_bool(PRINT_ANY, "bridge", "bridge ",
-					   true);
+			fprintf(f, " mode %s ",
+				mode == IPVLAN_MODE_L2 ? "l2" :
+				mode == IPVLAN_MODE_L3 ? "l3" : "unknown");
 		}
 	}
 }
@@ -113,7 +86,7 @@
 static void ipvlan_print_help(struct link_util *lu, int argc, char **argv,
 			      FILE *f)
 {
-	print_explain(lu, f);
+	ipvlan_explain(f);
 }
 
 struct link_util ipvlan_link_util = {
@@ -123,11 +96,3 @@
 	.print_opt	= ipvlan_print_opt,
 	.print_help	= ipvlan_print_help,
 };
-
-struct link_util ipvtap_link_util = {
-	.id		= "ipvtap",
-	.maxattr	= IFLA_IPVLAN_MAX,
-	.parse_opt	= ipvlan_parse_opt,
-	.print_opt	= ipvlan_print_opt,
-	.print_help	= ipvlan_print_help,
-};
diff --git a/ip/iplink_macvlan.c b/ip/iplink_macvlan.c
index b966a61..f195e81 100644
--- a/ip/iplink_macvlan.c
+++ b/ip/iplink_macvlan.c
@@ -15,7 +15,6 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <linux/if_link.h>
-#include <linux/if_ether.h>
 
 #include "rt_names.h"
 #include "utils.h"
@@ -30,12 +29,7 @@
 static void print_explain(struct link_util *lu, FILE *f)
 {
 	fprintf(f,
-		"Usage: ... %s mode MODE [flag MODE_FLAG] MODE_OPTS\n"
-		"\n"
-		"MODE: private | vepa | bridge | passthru | source\n"
-		"MODE_FLAG: null | nopromisc\n"
-		"MODE_OPTS: for mode \"source\":\n"
-		"\tmacaddr { { add | del } <macaddr> | set [ <macaddr> [ <macaddr>  ... ] ] | flush }\n",
+		"Usage: ... %s mode { private | vepa | bridge | passthru [nopromisc] }\n",
 		lu->id
 	);
 }
@@ -45,21 +39,11 @@
 	print_explain(lu, stderr);
 }
 
-
 static int mode_arg(const char *arg)
 {
-	fprintf(stderr,
-		"Error: argument of \"mode\" must be \"private\", \"vepa\", \"bridge\", \"passthru\" or \"source\", not \"%s\"\n",
-		arg);
-	return -1;
-}
-
-static int flag_arg(const char *arg)
-{
-	fprintf(stderr,
-		"Error: argument of \"flag\" must be \"nopromisc\" or \"null\", not \"%s\"\n",
-		arg);
-	return -1;
+        fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
+		"\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg);
+        return -1;
 }
 
 static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
@@ -67,10 +51,6 @@
 {
 	__u32 mode = 0;
 	__u16 flags = 0;
-	__u32 mac_mode = 0;
-	int has_flags = 0;
-	char mac[ETH_ALEN];
-	struct rtattr *nmac;
 
 	while (argc > 0) {
 		if (matches(*argv, "mode") == 0) {
@@ -84,72 +64,10 @@
 				mode = MACVLAN_MODE_BRIDGE;
 			else if (strcmp(*argv, "passthru") == 0)
 				mode = MACVLAN_MODE_PASSTHRU;
-			else if (strcmp(*argv, "source") == 0)
-				mode = MACVLAN_MODE_SOURCE;
 			else
 				return mode_arg(*argv);
-		} else if (matches(*argv, "flag") == 0) {
-			NEXT_ARG();
-
-			if (strcmp(*argv, "nopromisc") == 0)
-				flags |= MACVLAN_FLAG_NOPROMISC;
-			else if (strcmp(*argv, "null") == 0)
-				flags |= 0;
-			else
-				return flag_arg(*argv);
-
-			has_flags = 1;
-
-		} else if (matches(*argv, "macaddr") == 0) {
-			NEXT_ARG();
-
-			if (strcmp(*argv, "add") == 0) {
-				mac_mode = MACVLAN_MACADDR_ADD;
-			} else if (strcmp(*argv, "del") == 0) {
-				mac_mode = MACVLAN_MACADDR_DEL;
-			} else if (strcmp(*argv, "set") == 0) {
-				mac_mode = MACVLAN_MACADDR_SET;
-			} else if (strcmp(*argv, "flush") == 0) {
-				mac_mode = MACVLAN_MACADDR_FLUSH;
-			} else {
-				explain(lu);
-				return -1;
-			}
-
-			addattr32(n, 1024, IFLA_MACVLAN_MACADDR_MODE, mac_mode);
-
-			if (mac_mode == MACVLAN_MACADDR_ADD ||
-			    mac_mode == MACVLAN_MACADDR_DEL) {
-				NEXT_ARG();
-
-				if (ll_addr_a2n(mac, sizeof(mac),
-						*argv) != ETH_ALEN)
-					return -1;
-
-				addattr_l(n, 1024, IFLA_MACVLAN_MACADDR, &mac,
-					  ETH_ALEN);
-			}
-
-			if (mac_mode == MACVLAN_MACADDR_SET) {
-				nmac = addattr_nest(n, 1024,
-						    IFLA_MACVLAN_MACADDR_DATA);
-				while (NEXT_ARG_OK()) {
-					NEXT_ARG_FWD();
-
-					if (ll_addr_a2n(mac, sizeof(mac),
-							*argv) != ETH_ALEN) {
-						PREV_ARG();
-						break;
-					}
-
-					addattr_l(n, 1024, IFLA_MACVLAN_MACADDR,
-						  &mac, ETH_ALEN);
-				}
-				addattr_nest_end(n, nmac);
-			}
 		} else if (matches(*argv, "nopromisc") == 0) {
 			flags |= MACVLAN_FLAG_NOPROMISC;
-			has_flags = 1;
 		} else if (matches(*argv, "help") == 0) {
 			explain(lu);
 			return -1;
@@ -164,7 +82,7 @@
 	if (mode)
 		addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
 
-	if (has_flags) {
+	if (flags) {
 		if (flags & MACVLAN_FLAG_NOPROMISC &&
 		    mode != MACVLAN_MODE_PASSTHRU) {
 			pfx_err(lu, "nopromisc flag only valid in passthru mode");
@@ -180,10 +98,6 @@
 {
 	__u32 mode;
 	__u16 flags;
-	__u32 count;
-	unsigned char *addr;
-	int len;
-	struct rtattr *rta;
 
 	if (!tb)
 		return;
@@ -193,66 +107,24 @@
 		return;
 
 	mode = rta_getattr_u32(tb[IFLA_MACVLAN_MODE]);
-	print_string(PRINT_ANY,
-		     "mode",
-		     "mode %s ",
-		     mode == MACVLAN_MODE_PRIVATE ? "private"
-		     : mode == MACVLAN_MODE_VEPA    ? "vepa"
-		     : mode == MACVLAN_MODE_BRIDGE  ? "bridge"
-		     : mode == MACVLAN_MODE_PASSTHRU  ? "passthru"
-		     : mode == MACVLAN_MODE_SOURCE  ? "source"
-		     :				 "unknown");
+	fprintf(f, " mode %s ",
+		  mode == MACVLAN_MODE_PRIVATE ? "private"
+		: mode == MACVLAN_MODE_VEPA    ? "vepa"
+		: mode == MACVLAN_MODE_BRIDGE  ? "bridge"
+		: mode == MACVLAN_MODE_PASSTHRU  ? "passthru"
+		:				 "unknown");
 
 	if (!tb[IFLA_MACVLAN_FLAGS] ||
 	    RTA_PAYLOAD(tb[IFLA_MACVLAN_FLAGS]) < sizeof(__u16))
-		flags = 0;
-	else
-		flags = rta_getattr_u16(tb[IFLA_MACVLAN_FLAGS]);
+		return;
 
+	flags = rta_getattr_u16(tb[IFLA_MACVLAN_FLAGS]);
 	if (flags & MACVLAN_FLAG_NOPROMISC)
-		print_bool(PRINT_ANY, "nopromisc", "nopromisc ", true);
-
-	/* in source mode, there are more options to print */
-
-	if (mode != MACVLAN_MODE_SOURCE)
-		return;
-
-	if (!tb[IFLA_MACVLAN_MACADDR_COUNT] ||
-	    RTA_PAYLOAD(tb[IFLA_MACVLAN_MACADDR_COUNT]) < sizeof(__u32))
-		return;
-
-	count = rta_getattr_u32(tb[IFLA_MACVLAN_MACADDR_COUNT]);
-	print_int(PRINT_ANY, "macaddr_count", "remotes (%d) ", count);
-
-	if (!tb[IFLA_MACVLAN_MACADDR_DATA])
-		return;
-
-	rta = RTA_DATA(tb[IFLA_MACVLAN_MACADDR_DATA]);
-	len = RTA_PAYLOAD(tb[IFLA_MACVLAN_MACADDR_DATA]);
-
-	open_json_array(PRINT_JSON, "macaddr_data");
-	for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
-		if (rta->rta_type != IFLA_MACVLAN_MACADDR ||
-		    RTA_PAYLOAD(rta) < 6)
-			continue;
-		addr = RTA_DATA(rta);
-		if (is_json_context()) {
-			SPRINT_BUF(b1);
-
-			snprintf(b1, sizeof(b1),
-				 "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", addr[0],
-				 addr[1], addr[2], addr[3], addr[4], addr[5]);
-			print_string(PRINT_JSON, NULL, NULL, b1);
-		} else {
-			fprintf(f, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", addr[0],
-				addr[1], addr[2], addr[3], addr[4], addr[5]);
-		}
-	}
-	close_json_array(PRINT_JSON, NULL);
+		fprintf(f, "nopromisc ");
 }
 
 static void macvlan_print_help(struct link_util *lu, int argc, char **argv,
-			       FILE *f)
+	FILE *f)
 {
 	print_explain(lu, f);
 }
diff --git a/ip/iplink_netdevsim.c b/ip/iplink_netdevsim.c
deleted file mode 100644
index 3448608..0000000
--- a/ip/iplink_netdevsim.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void netdevsim_print_help(struct link_util *lu,
-				 int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... netdevsim\n");
-}
-
-struct link_util netdevsim_link_util = {
-	.id		= "netdevsim",
-	.print_help	= netdevsim_print_help,
-};
diff --git a/ip/iplink_nlmon.c b/ip/iplink_nlmon.c
deleted file mode 100644
index 6ffb910..0000000
--- a/ip/iplink_nlmon.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void nlmon_print_help(struct link_util *lu,
-			    int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... nlmon\n");
-}
-
-struct link_util nlmon_link_util = {
-	.id		= "nlmon",
-	.print_help	= nlmon_print_help,
-};
diff --git a/ip/iplink_rmnet.c b/ip/iplink_rmnet.c
deleted file mode 100644
index 1d16440..0000000
--- a/ip/iplink_rmnet.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * iplink_rmnet.c	RMNET device support
- *
- * Authors:     Daniele Palmas <dnlplm@gmail.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void print_explain(FILE *f)
-{
-	fprintf(f,
-		"Usage: ... rmnet mux_id MUXID\n"
-		"\n"
-		"MUXID := 1-254\n"
-	);
-}
-
-static void explain(void)
-{
-	print_explain(stderr);
-}
-
-static int rmnet_parse_opt(struct link_util *lu, int argc, char **argv,
-			   struct nlmsghdr *n)
-{
-	__u16 mux_id;
-
-	while (argc > 0) {
-		if (matches(*argv, "mux_id") == 0) {
-			NEXT_ARG();
-			if (get_u16(&mux_id, *argv, 0))
-				invarg("mux_id is invalid", *argv);
-			addattr16(n, 1024, IFLA_RMNET_MUX_ID, mux_id);
-		} else if (matches(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "rmnet: unknown command \"%s\"?\n", *argv);
-			explain();
-			return -1;
-		}
-		argc--, argv++;
-	}
-
-	return 0;
-}
-
-static void rmnet_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
-{
-	if (!tb)
-		return;
-
-	if (!tb[IFLA_RMNET_MUX_ID] ||
-	    RTA_PAYLOAD(tb[IFLA_RMNET_MUX_ID]) < sizeof(__u16))
-		return;
-
-	print_uint(PRINT_ANY,
-		   "mux_id",
-		   "mux_id %u ",
-		   rta_getattr_u16(tb[IFLA_RMNET_MUX_ID]));
-}
-
-static void rmnet_print_help(struct link_util *lu, int argc, char **argv,
-			     FILE *f)
-{
-	print_explain(f);
-}
-
-struct link_util rmnet_link_util = {
-	.id		= "rmnet",
-	.maxattr	= IFLA_RMNET_MAX,
-	.parse_opt	= rmnet_parse_opt,
-	.print_opt	= rmnet_print_opt,
-	.print_help	= rmnet_print_help,
-};
diff --git a/ip/iplink_team.c b/ip/iplink_team.c
deleted file mode 100644
index 58f955a..0000000
--- a/ip/iplink_team.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void team_print_help(struct link_util *lu,
-			    int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... team\n");
-}
-
-static void team_slave_print_help(struct link_util *lu,
-				  int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... team_slave\n");
-}
-
-struct link_util team_link_util = {
-	.id		= "team",
-	.print_help	= team_print_help,
-}, team_slave_link_util = {
-	.id		= "team_slave",
-	.print_help	= team_slave_print_help,
-};
diff --git a/ip/iplink_vcan.c b/ip/iplink_vcan.c
deleted file mode 100644
index 74a1505..0000000
--- a/ip/iplink_vcan.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void vcan_print_help(struct link_util *lu,
-			    int argc, char **argv, FILE *f)
-{
-	fprintf(f, "Usage: ... vcan\n");
-}
-
-struct link_util vcan_link_util = {
-	.id		= "vcan",
-	.print_help	= vcan_print_help,
-};
diff --git a/ip/iplink_vlan.c b/ip/iplink_vlan.c
index 0dfb4a8..5bd766f 100644
--- a/ip/iplink_vlan.c
+++ b/ip/iplink_vlan.c
@@ -21,18 +21,15 @@
 static void print_explain(FILE *f)
 {
 	fprintf(f,
-		"Usage: ... vlan id VLANID\n"
-		"		[ protocol VLANPROTO ]\n"
-		"		[ reorder_hdr { on | off } ]\n"
-		"		[ gvrp { on | off } ]\n"
-		"		[ mvrp { on | off } ]\n"
-		"		[ loose_binding { on | off } ]\n"
-		"		[ bridge_binding { on | off } ]\n"
-		"		[ ingress-qos-map QOS-MAP ]\n"
-		"		[ egress-qos-map QOS-MAP ]\n"
+		"Usage: ... vlan [ protocol VLANPROTO ] id VLANID"
+		"                [ FLAG-LIST ]\n"
+		"                [ ingress-qos-map QOS-MAP ] [ egress-qos-map QOS-MAP ]\n"
 		"\n"
+		"VLANPROTO: [ 802.1Q / 802.1ad ]\n"
 		"VLANID := 0-4095\n"
-		"VLANPROTO: [ 802.1Q | 802.1ad ]\n"
+		"FLAG-LIST := [ FLAG-LIST ] FLAG\n"
+		"FLAG := [ reorder_hdr { on | off } ] [ gvrp { on | off } ] [ mvrp { on | off } ]\n"
+		"        [ loose_binding { on | off } ]\n"
 		"QOS-MAP := [ QOS-MAP ] QOS-MAPPING\n"
 		"QOS-MAPPING := FROM:TO\n"
 	);
@@ -57,7 +54,8 @@
 	struct ifla_vlan_qos_mapping m;
 	struct rtattr *tail;
 
-	tail = addattr_nest(n, 1024, attrtype);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, attrtype, NULL, 0);
 
 	while (argc > 0) {
 		char *colon = strchr(*argv, ':');
@@ -75,7 +73,7 @@
 		addattr_l(n, 1024, IFLA_VLAN_QOS_MAPPING, &m, sizeof(m));
 	}
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail;
 
 	*argcp = argc;
 	*argvp = argv;
@@ -135,15 +133,6 @@
 				flags.flags &= ~VLAN_FLAG_LOOSE_BINDING;
 			else
 				return on_off("loose_binding", *argv);
-		} else if (matches(*argv, "bridge_binding") == 0) {
-			NEXT_ARG();
-			flags.mask |= VLAN_FLAG_BRIDGE_BINDING;
-			if (strcmp(*argv, "on") == 0)
-				flags.flags |= VLAN_FLAG_BRIDGE_BINDING;
-			else if (strcmp(*argv, "off") == 0)
-				flags.flags &= ~VLAN_FLAG_BRIDGE_BINDING;
-			else
-				return on_off("bridge_binding", *argv);
 		} else if (matches(*argv, "ingress-qos-map") == 0) {
 			NEXT_ARG();
 			if (vlan_parse_qos_map(&argc, &argv, n,
@@ -173,58 +162,42 @@
 	return 0;
 }
 
-static void vlan_print_map(FILE *f,
-			   const char *name_json,
-			   const char *name_fp,
-			   struct rtattr *attr)
+static void vlan_print_map(FILE *f, char *name, struct rtattr *attr)
 {
 	struct ifla_vlan_qos_mapping *m;
 	struct rtattr *i;
 	int rem;
 
-	open_json_array(PRINT_JSON, name_json);
-	print_string(PRINT_FP, NULL, "\n      %s { ", name_fp);
+	fprintf(f, "\n      %s { ", name);
 
 	rem = RTA_PAYLOAD(attr);
 	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 		m = RTA_DATA(i);
-
-		if (is_json_context()) {
-			open_json_object(NULL);
-			print_uint(PRINT_JSON, "from", NULL, m->from);
-			print_uint(PRINT_JSON, "to", NULL, m->to);
-			close_json_object();
-		} else {
-			fprintf(f, "%u:%u ", m->from, m->to);
-		}
+		fprintf(f, "%u:%u ", m->from, m->to);
 	}
-
-	close_json_array(PRINT_JSON, NULL);
-	print_string(PRINT_FP, NULL, "%s ", "}");
+	fprintf(f, "} ");
 }
 
 static void vlan_print_flags(FILE *fp, __u32 flags)
 {
-	open_json_array(PRINT_ANY, is_json_context() ? "flags" : "<");
-#define _PF(f)	if (flags & VLAN_FLAG_##f) {				\
-		flags &= ~VLAN_FLAG_##f;				\
-		print_string(PRINT_ANY, NULL, flags ? "%s," : "%s", #f); \
-	}
+	fprintf(fp, "<");
+#define _PF(f)	if (flags & VLAN_FLAG_##f) { \
+			flags &= ~ VLAN_FLAG_##f; \
+			fprintf(fp, #f "%s", flags ? "," : ""); \
+		}
 	_PF(REORDER_HDR);
 	_PF(GVRP);
 	_PF(MVRP);
 	_PF(LOOSE_BINDING);
-	_PF(BRIDGE_BINDING);
 #undef _PF
 	if (flags)
-		print_hex(PRINT_ANY, NULL, "%x", flags);
-	close_json_array(PRINT_ANY, "> ");
+		fprintf(fp, "%x", flags);
+	fprintf(fp, "> ");
 }
 
 static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
 	struct ifla_vlan_flags *flags;
-
 	SPRINT_BUF(b1);
 
 	if (!tb)
@@ -238,19 +211,13 @@
 		return;
 
 	if (tb[IFLA_VLAN_PROTOCOL])
-		print_string(PRINT_ANY,
-			     "protocol",
-			     "protocol %s ",
-			     ll_proto_n2a(
-				     rta_getattr_u16(tb[IFLA_VLAN_PROTOCOL]),
+		fprintf(f, "protocol %s ",
+			ll_proto_n2a(rta_getattr_u16(tb[IFLA_VLAN_PROTOCOL]),
 				     b1, sizeof(b1)));
 	else
-		print_string(PRINT_ANY, "protocol", "protocol %s ", "802.1q");
+		fprintf(f, "protocol 802.1q ");
 
-	print_uint(PRINT_ANY,
-		   "id",
-		   "id %u ",
-		   rta_getattr_u16(tb[IFLA_VLAN_ID]));
+	fprintf(f, "id %u ", rta_getattr_u16(tb[IFLA_VLAN_ID]));
 
 	if (tb[IFLA_VLAN_FLAGS]) {
 		if (RTA_PAYLOAD(tb[IFLA_VLAN_FLAGS]) < sizeof(*flags))
@@ -259,19 +226,13 @@
 		vlan_print_flags(f, flags->flags);
 	}
 	if (tb[IFLA_VLAN_INGRESS_QOS])
-		vlan_print_map(f,
-			       "ingress_qos",
-			       "ingress-qos-map",
-			       tb[IFLA_VLAN_INGRESS_QOS]);
+		vlan_print_map(f, "ingress-qos-map", tb[IFLA_VLAN_INGRESS_QOS]);
 	if (tb[IFLA_VLAN_EGRESS_QOS])
-		vlan_print_map(f,
-			       "egress_qos",
-			       "egress-qos-map",
-			       tb[IFLA_VLAN_EGRESS_QOS]);
+		vlan_print_map(f, "egress-qos-map", tb[IFLA_VLAN_EGRESS_QOS]);
 }
 
 static void vlan_print_help(struct link_util *lu, int argc, char **argv,
-			    FILE *f)
+	FILE *f)
 {
 	print_explain(f);
 }
diff --git a/ip/iplink_vrf.c b/ip/iplink_vrf.c
index 5d20f29..9b4b772 100644
--- a/ip/iplink_vrf.c
+++ b/ip/iplink_vrf.c
@@ -13,7 +13,6 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <linux/if_link.h>
-#include <errno.h>
 
 #include "rt_names.h"
 #include "utils.h"
@@ -21,7 +20,7 @@
 
 static void vrf_explain(FILE *f)
 {
-	fprintf(f, "Usage: ... vrf table TABLEID\n");
+	fprintf(f, "Usage: ... vrf table TABLEID \n");
 }
 
 static void explain(void)
@@ -62,28 +61,11 @@
 		return;
 
 	if (tb[IFLA_VRF_TABLE])
-		print_uint(PRINT_ANY,
-			   "table",
-			   "table %u ",
-			   rta_getattr_u32(tb[IFLA_VRF_TABLE]));
-}
-
-static void vrf_slave_print_opt(struct link_util *lu, FILE *f,
-				struct rtattr *tb[])
-{
-	if (!tb)
-		return;
-
-	if (tb[IFLA_VRF_PORT_TABLE]) {
-		print_uint(PRINT_ANY,
-			   "table",
-			   "table %u ",
-			   rta_getattr_u32(tb[IFLA_VRF_PORT_TABLE]));
-	}
+		fprintf(f, "table %u ", rta_getattr_u32(tb[IFLA_VRF_TABLE]));
 }
 
 static void vrf_print_help(struct link_util *lu, int argc, char **argv,
-			   FILE *f)
+			      FILE *f)
 {
 	vrf_explain(f);
 }
@@ -95,132 +77,3 @@
 	.print_opt	= vrf_print_opt,
 	.print_help	= vrf_print_help,
 };
-
-struct link_util vrf_slave_link_util = {
-	.id             = "vrf_slave",
-	.maxattr        = IFLA_VRF_PORT_MAX,
-	.print_opt	= vrf_slave_print_opt,
-};
-
-/* returns table id if name is a VRF device */
-__u32 ipvrf_get_table(const char *name)
-{
-	struct {
-		struct nlmsghdr		n;
-		struct ifinfomsg	i;
-		char			buf[1024];
-	} req = {
-		.n = {
-			.nlmsg_len   = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-			.nlmsg_flags = NLM_F_REQUEST,
-			.nlmsg_type  = RTM_GETLINK,
-		},
-		.i = {
-			.ifi_family  = preferred_family,
-		},
-	};
-	struct nlmsghdr *answer;
-	struct rtattr *tb[IFLA_MAX+1];
-	struct rtattr *li[IFLA_INFO_MAX+1];
-	struct rtattr *vrf_attr[IFLA_VRF_MAX + 1];
-	struct ifinfomsg *ifi;
-	__u32 tb_id = 0;
-	int len;
-
-	addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, strlen(name) + 1);
-
-	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0) {
-		/* special case "default" vrf to be the main table */
-		if (errno == ENODEV && !strcmp(name, "default"))
-			if (rtnl_rttable_a2n(&tb_id, "main"))
-				fprintf(stderr,
-					"BUG: RTTable \"main\" not found.\n");
-
-		return tb_id;
-	}
-
-	ifi = NLMSG_DATA(answer);
-	len = answer->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi));
-	if (len < 0) {
-		fprintf(stderr, "BUG: Invalid response to link query.\n");
-		goto out;
-	}
-
-	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
-
-	if (!tb[IFLA_LINKINFO])
-		goto out;
-
-	parse_rtattr_nested(li, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
-
-	if (!li[IFLA_INFO_KIND] || !li[IFLA_INFO_DATA])
-		goto out;
-
-	if (strcmp(RTA_DATA(li[IFLA_INFO_KIND]), "vrf"))
-		goto out;
-
-	parse_rtattr_nested(vrf_attr, IFLA_VRF_MAX, li[IFLA_INFO_DATA]);
-	if (vrf_attr[IFLA_VRF_TABLE])
-		tb_id = rta_getattr_u32(vrf_attr[IFLA_VRF_TABLE]);
-
-	if (!tb_id)
-		fprintf(stderr, "BUG: VRF %s is missing table id\n", name);
-
-out:
-	free(answer);
-	return tb_id;
-}
-
-int name_is_vrf(const char *name)
-{
-	struct {
-		struct nlmsghdr		n;
-		struct ifinfomsg	i;
-		char			buf[1024];
-	} req = {
-		.n = {
-			.nlmsg_len   = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-			.nlmsg_flags = NLM_F_REQUEST,
-			.nlmsg_type  = RTM_GETLINK,
-		},
-		.i = {
-			.ifi_family  = preferred_family,
-		},
-	};
-	struct nlmsghdr *answer;
-	struct rtattr *tb[IFLA_MAX+1];
-	struct rtattr *li[IFLA_INFO_MAX+1];
-	struct ifinfomsg *ifi;
-	int ifindex = 0;
-	int len;
-
-	addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, strlen(name) + 1);
-
-	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
-		return 0;
-
-	ifi = NLMSG_DATA(answer);
-	len = answer->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi));
-	if (len < 0) {
-		fprintf(stderr, "BUG: Invalid response to link query.\n");
-		goto out;
-	}
-
-	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
-
-	if (!tb[IFLA_LINKINFO])
-		goto out;
-
-	parse_rtattr_nested(li, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
-
-	if (!li[IFLA_INFO_KIND])
-		goto out;
-
-	if (strcmp(RTA_DATA(li[IFLA_INFO_KIND]), "vrf"))
-		goto out;
-
-	ifindex = ifi->ifi_index;
-out:
-	free(answer);
-	return ifindex;
-}
diff --git a/ip/iplink_vxcan.c b/ip/iplink_vxcan.c
deleted file mode 100644
index 8b08c9a..0000000
--- a/ip/iplink_vxcan.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * iplink_vxcan.c	vxcan device support (Virtual CAN Tunnel)
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Author:	Oliver Hartkopp <socketcan@hartkopp.net>
- * Based on:	link_veth.c from Pavel Emelianov <xemul@openvz.org>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <net/if.h>
-#include <linux/can/vxcan.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void print_usage(FILE *f)
-{
-	printf("Usage: ip link <options> type vxcan [peer <options>]\n"
-	       "To get <options> type 'ip link add help'\n");
-}
-
-static void usage(void)
-{
-	print_usage(stderr);
-}
-
-static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
-			  struct nlmsghdr *n)
-{
-	char *type = NULL;
-	int err;
-	struct rtattr *data;
-	struct ifinfomsg *ifm, *peer_ifm;
-	unsigned int ifi_flags, ifi_change, ifi_index;
-
-	if (strcmp(argv[0], "peer") != 0) {
-		usage();
-		return -1;
-	}
-
-	ifm = NLMSG_DATA(n);
-	ifi_flags = ifm->ifi_flags;
-	ifi_change = ifm->ifi_change;
-	ifi_index = ifm->ifi_index;
-	ifm->ifi_flags = 0;
-	ifm->ifi_change = 0;
-	ifm->ifi_index = 0;
-
-	data = addattr_nest(n, 1024, VXCAN_INFO_PEER);
-
-	n->nlmsg_len += sizeof(struct ifinfomsg);
-
-	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
-	if (err < 0)
-		return err;
-
-	if (type)
-		duparg("type", argv[err]);
-
-	peer_ifm = RTA_DATA(data);
-	peer_ifm->ifi_index = ifm->ifi_index;
-	peer_ifm->ifi_flags = ifm->ifi_flags;
-	peer_ifm->ifi_change = ifm->ifi_change;
-	ifm->ifi_flags = ifi_flags;
-	ifm->ifi_change = ifi_change;
-	ifm->ifi_index = ifi_index;
-
-	addattr_nest_end(n, data);
-	return argc - 1 - err;
-}
-
-static void vxcan_print_help(struct link_util *lu, int argc, char **argv,
-	FILE *f)
-{
-	print_usage(f);
-}
-
-struct link_util vxcan_link_util = {
-	.id = "vxcan",
-	.parse_opt = vxcan_parse_opt,
-	.print_help = vxcan_print_help,
-};
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
index bae9d99..ede8482 100644
--- a/ip/iplink_vxlan.c
+++ b/ip/iplink_vxlan.c
@@ -21,41 +21,22 @@
 #include "utils.h"
 #include "ip_common.h"
 
-#define VXLAN_ATTRSET(attrs, type) (((attrs) & (1L << (type))) != 0)
-
 static void print_explain(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... vxlan id VNI\n"
-		"		[ { group | remote } IP_ADDRESS ]\n"
-		"		[ local ADDR ]\n"
-		"		[ ttl TTL ]\n"
-		"		[ tos TOS ]\n"
-		"		[ df DF ]\n"
-		"		[ flowlabel LABEL ]\n"
-		"		[ dev PHYS_DEV ]\n"
-		"		[ dstport PORT ]\n"
-		"		[ srcport MIN MAX ]\n"
-		"		[ [no]learning ]\n"
-		"		[ [no]proxy ]\n"
-		"		[ [no]rsc ]\n"
-		"		[ [no]l2miss ]\n"
-		"		[ [no]l3miss ]\n"
-		"		[ ageing SECONDS ]\n"
-		"		[ maxaddress NUMBER ]\n"
-		"		[ [no]udpcsum ]\n"
-		"		[ [no]udp6zerocsumtx ]\n"
-		"		[ [no]udp6zerocsumrx ]\n"
-		"		[ [no]remcsumtx ] [ [no]remcsumrx ]\n"
-		"		[ [no]external ] [ gbp ] [ gpe ]\n"
-		"\n"
-		"Where:	VNI	:= 0-16777215\n"
-		"	ADDR	:= { IP_ADDRESS | any }\n"
-		"	TOS	:= { NUMBER | inherit }\n"
-		"	TTL	:= { 1..255 | auto | inherit }\n"
-		"	DF	:= { unset | set | inherit }\n"
-		"	LABEL := 0-1048575\n"
-	);
+	fprintf(f, "Usage: ... vxlan id VNI [ { group | remote } IP_ADDRESS ] [ local ADDR ]\n");
+	fprintf(f, "                 [ ttl TTL ] [ tos TOS ] [ dev PHYS_DEV ]\n");
+	fprintf(f, "                 [ dstport PORT ] [ srcport MIN MAX ]\n");
+	fprintf(f, "                 [ [no]learning ] [ [no]proxy ] [ [no]rsc ]\n");
+	fprintf(f, "                 [ [no]l2miss ] [ [no]l3miss ]\n");
+	fprintf(f, "                 [ ageing SECONDS ] [ maxaddress NUMBER ]\n");
+	fprintf(f, "                 [ [no]udpcsum ] [ [no]udp6zerocsumtx ] [ [no]udp6zerocsumrx ]\n");
+	fprintf(f, "                 [ [no]remcsumtx ] [ [no]remcsumrx ]\n");
+	fprintf(f, "                 [ [no]external ] [ gbp ]\n");
+	fprintf(f, "\n");
+	fprintf(f, "Where: VNI := 0-16777215\n");
+	fprintf(f, "       ADDR := { IP_ADDRESS | any }\n");
+	fprintf(f, "       TOS  := { NUMBER | inherit }\n");
+	fprintf(f, "       TTL  := { 1..255 | inherit }\n");
 }
 
 static void explain(void)
@@ -63,273 +44,179 @@
 	print_explain(stderr);
 }
 
-static void check_duparg(__u64 *attrs, int type, const char *key,
-			 const char *argv)
-{
-	if (!VXLAN_ATTRSET(*attrs, type)) {
-		*attrs |= (1L << type);
-		return;
-	}
-	duparg2(key, argv);
-}
-
 static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
 			  struct nlmsghdr *n)
 {
-	inet_prefix saddr, daddr;
 	__u32 vni = 0;
+	int vni_set = 0;
+	__u32 saddr = 0;
+	__u32 gaddr = 0;
+	__u32 daddr = 0;
+	struct in6_addr saddr6 = IN6ADDR_ANY_INIT;
+	struct in6_addr gaddr6 = IN6ADDR_ANY_INIT;
+	struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
+	unsigned link = 0;
+	__u8 tos = 0;
+	__u8 ttl = 0;
 	__u8 learning = 1;
+	__u8 proxy = 0;
+	__u8 rsc = 0;
+	__u8 l2miss = 0;
+	__u8 l3miss = 0;
+	__u8 noage = 0;
+	__u32 age = 0;
+	__u32 maxaddr = 0;
 	__u16 dstport = 0;
+	__u8 udpcsum = 0;
+	__u8 udp6zerocsumtx = 0;
+	__u8 udp6zerocsumrx = 0;
+	__u8 remcsumtx = 0;
+	__u8 remcsumrx = 0;
 	__u8 metadata = 0;
-	__u64 attrs = 0;
-	bool set_op = (n->nlmsg_type == RTM_NEWLINK &&
-		       !(n->nlmsg_flags & NLM_F_CREATE));
-	bool selected_family = false;
-
-	saddr.family = daddr.family = AF_UNSPEC;
-
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
+	__u8 gbp = 0;
+	int dst_port_set = 0;
+	struct ifla_vxlan_port_range range = { 0, 0 };
 
 	while (argc > 0) {
 		if (!matches(*argv, "id") ||
 		    !matches(*argv, "vni")) {
-			/* We will add ID attribute outside of the loop since we
-			 * need to consider metadata information as well.
-			 */
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_ID, "id", *argv);
 			if (get_u32(&vni, *argv, 0) ||
 			    vni >= 1u << 24)
 				invarg("invalid id", *argv);
+			vni_set = 1;
 		} else if (!matches(*argv, "group")) {
-			if (is_addrtype_inet_not_multi(&daddr)) {
-				fprintf(stderr, "vxlan: both group and remote");
-				fprintf(stderr, " cannot be specified\n");
+			NEXT_ARG();
+			if (!inet_get_addr(*argv, &gaddr, &gaddr6)) {
+				fprintf(stderr, "Invalid address \"%s\"\n", *argv);
 				return -1;
 			}
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_GROUP, "group", *argv);
-			get_addr(&daddr, *argv, saddr.family);
-			if (!is_addrtype_inet_multi(&daddr))
+			if (!IN6_IS_ADDR_MULTICAST(&gaddr6) && !IN_MULTICAST(ntohl(gaddr)))
 				invarg("invalid group address", *argv);
 		} else if (!matches(*argv, "remote")) {
-			if (is_addrtype_inet_multi(&daddr)) {
-				fprintf(stderr, "vxlan: both group and remote");
-				fprintf(stderr, " cannot be specified\n");
+			NEXT_ARG();
+			if (!inet_get_addr(*argv, &daddr, &daddr6)) {
+				fprintf(stderr, "Invalid address \"%s\"\n", *argv);
 				return -1;
 			}
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_GROUP, "remote", *argv);
-			get_addr(&daddr, *argv, saddr.family);
-			if (!is_addrtype_inet_not_multi(&daddr))
+			if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
 				invarg("invalid remote address", *argv);
 		} else if (!matches(*argv, "local")) {
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_LOCAL, "local", *argv);
-			get_addr(&saddr, *argv, daddr.family);
-			if (!is_addrtype_inet_not_multi(&saddr))
+			if (strcmp(*argv, "any")) {
+				if (!inet_get_addr(*argv, &saddr, &saddr6)) {
+					fprintf(stderr, "Invalid address \"%s\"\n", *argv);
+					return -1;
+				}
+			}
+
+			if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6))
 				invarg("invalid local address", *argv);
 		} else if (!matches(*argv, "dev")) {
-			unsigned int link;
-
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_LINK, "dev", *argv);
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
-			addattr32(n, 1024, IFLA_VXLAN_LINK, link);
+			link = if_nametoindex(*argv);
+			if (link == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n",
+					*argv);
+				exit(-1);
+			}
 		} else if (!matches(*argv, "ttl") ||
 			   !matches(*argv, "hoplimit")) {
-			unsigned int uval;
-			__u8 ttl = 0;
+			unsigned uval;
 
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_TTL, "ttl", *argv);
-			if (strcmp(*argv, "inherit") == 0) {
-				addattr(n, 1024, IFLA_VXLAN_TTL_INHERIT);
-			} else if (strcmp(*argv, "auto") == 0) {
-				addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
-			} else {
+			if (strcmp(*argv, "inherit") != 0) {
 				if (get_unsigned(&uval, *argv, 0))
 					invarg("invalid TTL", *argv);
 				if (uval > 255)
 					invarg("TTL must be <= 255", *argv);
 				ttl = uval;
-				addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
 			}
 		} else if (!matches(*argv, "tos") ||
 			   !matches(*argv, "dsfield")) {
 			__u32 uval;
-			__u8 tos;
 
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_TOS, "tos", *argv);
 			if (strcmp(*argv, "inherit") != 0) {
 				if (rtnl_dsfield_a2n(&uval, *argv))
 					invarg("bad TOS value", *argv);
 				tos = uval;
 			} else
 				tos = 1;
-			addattr8(n, 1024, IFLA_VXLAN_TOS, tos);
-		} else if (!matches(*argv, "df")) {
-			enum ifla_vxlan_df df;
-
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_DF, "df", *argv);
-			if (strcmp(*argv, "unset") == 0)
-				df = VXLAN_DF_UNSET;
-			else if (strcmp(*argv, "set") == 0)
-				df = VXLAN_DF_SET;
-			else if (strcmp(*argv, "inherit") == 0)
-				df = VXLAN_DF_INHERIT;
-			else
-				invarg("DF must be 'unset', 'set' or 'inherit'",
-				       *argv);
-
-			addattr8(n, 1024, IFLA_VXLAN_DF, df);
-		} else if (!matches(*argv, "label") ||
-			   !matches(*argv, "flowlabel")) {
-			__u32 uval;
-
-			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_LABEL, "flowlabel",
-				     *argv);
-			if (get_u32(&uval, *argv, 0) ||
-			    (uval & ~LABEL_MAX_MASK))
-				invarg("invalid flowlabel", *argv);
-			addattr32(n, 1024, IFLA_VXLAN_LABEL, htonl(uval));
 		} else if (!matches(*argv, "ageing")) {
-			__u32 age;
-
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_AGEING, "ageing",
-				     *argv);
 			if (strcmp(*argv, "none") == 0)
-				age = 0;
+				noage = 1;
 			else if (get_u32(&age, *argv, 0))
 				invarg("ageing timer", *argv);
-			addattr32(n, 1024, IFLA_VXLAN_AGEING, age);
 		} else if (!matches(*argv, "maxaddress")) {
-			__u32 maxaddr;
-
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_LIMIT,
-				     "maxaddress", *argv);
 			if (strcmp(*argv, "unlimited") == 0)
 				maxaddr = 0;
 			else if (get_u32(&maxaddr, *argv, 0))
 				invarg("max addresses", *argv);
-			addattr32(n, 1024, IFLA_VXLAN_LIMIT, maxaddr);
 		} else if (!matches(*argv, "port") ||
 			   !matches(*argv, "srcport")) {
-			struct ifla_vxlan_port_range range = { 0, 0 };
-
+			__u16 minport, maxport;
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_PORT_RANGE, "srcport",
-				     *argv);
-			if (get_be16(&range.low, *argv, 0))
+			if (get_u16(&minport, *argv, 0))
 				invarg("min port", *argv);
 			NEXT_ARG();
-			if (get_be16(&range.high, *argv, 0))
+			if (get_u16(&maxport, *argv, 0))
 				invarg("max port", *argv);
-			if (range.low || range.high) {
-				addattr_l(n, 1024, IFLA_VXLAN_PORT_RANGE,
-					  &range, sizeof(range));
-			}
-		} else if (!matches(*argv, "dstport")) {
+			range.low = htons(minport);
+			range.high = htons(maxport);
+		} else if (!matches(*argv, "dstport")){
 			NEXT_ARG();
-			check_duparg(&attrs, IFLA_VXLAN_PORT, "dstport", *argv);
 			if (get_u16(&dstport, *argv, 0))
 				invarg("dst port", *argv);
+			dst_port_set = 1;
 		} else if (!matches(*argv, "nolearning")) {
-			check_duparg(&attrs, IFLA_VXLAN_LEARNING, *argv, *argv);
 			learning = 0;
 		} else if (!matches(*argv, "learning")) {
-			check_duparg(&attrs, IFLA_VXLAN_LEARNING, *argv, *argv);
 			learning = 1;
 		} else if (!matches(*argv, "noproxy")) {
-			check_duparg(&attrs, IFLA_VXLAN_PROXY, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_PROXY, 0);
+			proxy = 0;
 		} else if (!matches(*argv, "proxy")) {
-			check_duparg(&attrs, IFLA_VXLAN_PROXY, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_PROXY, 1);
+			proxy = 1;
 		} else if (!matches(*argv, "norsc")) {
-			check_duparg(&attrs, IFLA_VXLAN_RSC, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_RSC, 0);
+			rsc = 0;
 		} else if (!matches(*argv, "rsc")) {
-			check_duparg(&attrs, IFLA_VXLAN_RSC, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_RSC, 1);
+			rsc = 1;
 		} else if (!matches(*argv, "nol2miss")) {
-			check_duparg(&attrs, IFLA_VXLAN_L2MISS, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_L2MISS, 0);
+			l2miss = 0;
 		} else if (!matches(*argv, "l2miss")) {
-			check_duparg(&attrs, IFLA_VXLAN_L2MISS, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_L2MISS, 1);
+			l2miss = 1;
 		} else if (!matches(*argv, "nol3miss")) {
-			check_duparg(&attrs, IFLA_VXLAN_L3MISS, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_L3MISS, 0);
+			l3miss = 0;
 		} else if (!matches(*argv, "l3miss")) {
-			check_duparg(&attrs, IFLA_VXLAN_L3MISS, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_L3MISS, 1);
+			l3miss = 1;
 		} else if (!matches(*argv, "udpcsum")) {
-			check_duparg(&attrs, IFLA_VXLAN_UDP_CSUM, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, 1);
+			udpcsum = 1;
 		} else if (!matches(*argv, "noudpcsum")) {
-			check_duparg(&attrs, IFLA_VXLAN_UDP_CSUM, *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, 0);
+			udpcsum = 0;
 		} else if (!matches(*argv, "udp6zerocsumtx")) {
-			check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, 1);
+			udp6zerocsumtx = 1;
 		} else if (!matches(*argv, "noudp6zerocsumtx")) {
-			check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, 0);
+			udp6zerocsumtx = 0;
 		} else if (!matches(*argv, "udp6zerocsumrx")) {
-			check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 1);
+			udp6zerocsumrx = 1;
 		} else if (!matches(*argv, "noudp6zerocsumrx")) {
-			check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 0);
+			udp6zerocsumrx = 0;
 		} else if (!matches(*argv, "remcsumtx")) {
-			check_duparg(&attrs, IFLA_VXLAN_REMCSUM_TX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, 1);
+			remcsumtx = 1;
 		} else if (!matches(*argv, "noremcsumtx")) {
-			check_duparg(&attrs, IFLA_VXLAN_REMCSUM_TX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, 0);
+			remcsumtx = 0;
 		} else if (!matches(*argv, "remcsumrx")) {
-			check_duparg(&attrs, IFLA_VXLAN_REMCSUM_RX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, 1);
+			remcsumrx = 1;
 		} else if (!matches(*argv, "noremcsumrx")) {
-			check_duparg(&attrs, IFLA_VXLAN_REMCSUM_RX,
-				     *argv, *argv);
-			addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, 0);
+			remcsumrx = 0;
 		} else if (!matches(*argv, "external")) {
-			check_duparg(&attrs, IFLA_VXLAN_COLLECT_METADATA,
-				     *argv, *argv);
 			metadata = 1;
-			learning = 0;
-			/* we will add LEARNING attribute outside of the loop */
-			addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA,
-				 metadata);
 		} else if (!matches(*argv, "noexternal")) {
-			check_duparg(&attrs, IFLA_VXLAN_COLLECT_METADATA,
-				     *argv, *argv);
 			metadata = 0;
-			addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA,
-				 metadata);
 		} else if (!matches(*argv, "gbp")) {
-			check_duparg(&attrs, IFLA_VXLAN_GBP, *argv, *argv);
-			addattr_l(n, 1024, IFLA_VXLAN_GBP, NULL, 0);
-		} else if (!matches(*argv, "gpe")) {
-			check_duparg(&attrs, IFLA_VXLAN_GPE, *argv, *argv);
-			addattr_l(n, 1024, IFLA_VXLAN_GPE, NULL, 0);
+			gbp = 1;
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -341,26 +228,24 @@
 		argc--, argv++;
 	}
 
-	if (metadata && VXLAN_ATTRSET(attrs, IFLA_VXLAN_ID)) {
+	if (metadata && vni_set) {
 		fprintf(stderr, "vxlan: both 'external' and vni cannot be specified\n");
 		return -1;
 	}
 
-	if (!metadata && !VXLAN_ATTRSET(attrs, IFLA_VXLAN_ID) && !set_op) {
+	if (!metadata && !vni_set) {
 		fprintf(stderr, "vxlan: missing virtual network identifier\n");
 		return -1;
 	}
 
-	if (is_addrtype_inet_multi(&daddr) &&
-	    !VXLAN_ATTRSET(attrs, IFLA_VXLAN_LINK)) {
-		fprintf(stderr, "vxlan: 'group' requires 'dev' to be specified\n");
+	if ((gaddr && daddr) ||
+		(memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) &&
+		 memcmp(&daddr6, &in6addr_any, sizeof(daddr6)))) {
+		fprintf(stderr, "vxlan: both group and remote cannot be specified\n");
 		return -1;
 	}
 
-	if (!VXLAN_ATTRSET(attrs, IFLA_VXLAN_PORT) &&
-	    VXLAN_ATTRSET(attrs, IFLA_VXLAN_GPE)) {
-		dstport = 4790;
-	} else if (!VXLAN_ATTRSET(attrs, IFLA_VXLAN_PORT) && !set_op) {
+	if (!dst_port_set) {
 		fprintf(stderr, "vxlan: destination port not specified\n"
 			"Will use Linux kernel default (non-standard value)\n");
 		fprintf(stderr,
@@ -368,282 +253,202 @@
 			"Use 'dstport 0' to get default and quiet this message\n");
 	}
 
-	if (VXLAN_ATTRSET(attrs, IFLA_VXLAN_ID))
-		addattr32(n, 1024, IFLA_VXLAN_ID, vni);
+	addattr32(n, 1024, IFLA_VXLAN_ID, vni);
+	if (gaddr)
+		addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
+	else if (daddr)
+		addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4);
+	if (memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) != 0)
+		addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &gaddr6, sizeof(struct in6_addr));
+	else if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0)
+		addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr));
 
-	if (is_addrtype_inet(&saddr)) {
-		int type = (saddr.family == AF_INET) ? IFLA_VXLAN_LOCAL
-						     : IFLA_VXLAN_LOCAL6;
-		addattr_l(n, 1024, type, saddr.data, saddr.bytelen);
-		selected_family = true;
-	}
+	if (saddr)
+		addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4);
+	else if (memcmp(&saddr6, &in6addr_any, sizeof(saddr6)) != 0)
+		addattr_l(n, 1024, IFLA_VXLAN_LOCAL6, &saddr6, sizeof(struct in6_addr));
 
-	if (is_addrtype_inet(&daddr)) {
-		int type = (daddr.family == AF_INET) ? IFLA_VXLAN_GROUP
-						     : IFLA_VXLAN_GROUP6;
-		addattr_l(n, 1024, type, daddr.data, daddr.bytelen);
-		selected_family = true;
-	}
+	if (link)
+		addattr32(n, 1024, IFLA_VXLAN_LINK, link);
+	addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
+	addattr8(n, 1024, IFLA_VXLAN_TOS, tos);
+	addattr8(n, 1024, IFLA_VXLAN_LEARNING, learning);
+	addattr8(n, 1024, IFLA_VXLAN_PROXY, proxy);
+	addattr8(n, 1024, IFLA_VXLAN_RSC, rsc);
+	addattr8(n, 1024, IFLA_VXLAN_L2MISS, l2miss);
+	addattr8(n, 1024, IFLA_VXLAN_L3MISS, l3miss);
+	addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, udpcsum);
+	addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, udp6zerocsumtx);
+	addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, udp6zerocsumrx);
+	addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, remcsumtx);
+	addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, remcsumrx);
+	addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA, metadata);
 
-	if (!selected_family) {
-		if (preferred_family == AF_INET) {
-			get_addr(&daddr, "default", AF_INET);
-			addattr_l(n, 1024, IFLA_VXLAN_GROUP,
-				  daddr.data, daddr.bytelen);
-		} else if (preferred_family == AF_INET6) {
-			get_addr(&daddr, "default", AF_INET6);
-			addattr_l(n, 1024, IFLA_VXLAN_GROUP6,
-				  daddr.data, daddr.bytelen);
-		}
-	}
-
-	if (!set_op || VXLAN_ATTRSET(attrs, IFLA_VXLAN_LEARNING))
-		addattr8(n, 1024, IFLA_VXLAN_LEARNING, learning);
-
+	if (noage)
+		addattr32(n, 1024, IFLA_VXLAN_AGEING, 0);
+	else if (age)
+		addattr32(n, 1024, IFLA_VXLAN_AGEING, age);
+	if (maxaddr)
+		addattr32(n, 1024, IFLA_VXLAN_LIMIT, maxaddr);
+	if (range.low || range.high)
+		addattr_l(n, 1024, IFLA_VXLAN_PORT_RANGE,
+			  &range, sizeof(range));
 	if (dstport)
 		addattr16(n, 1024, IFLA_VXLAN_PORT, htons(dstport));
 
+	if (gbp)
+		addattr_l(n, 1024, IFLA_VXLAN_GBP, NULL, 0);
+
+
 	return 0;
 }
 
 static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
 	__u32 vni;
-	__u8 ttl = 0;
-	__u8 tos = 0;
+	unsigned link;
+	__u8 tos;
 	__u32 maxaddr;
+	char s1[1024];
+	char s2[64];
 
 	if (!tb)
 		return;
 
-	if (tb[IFLA_VXLAN_COLLECT_METADATA] &&
-	    rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) {
-		print_bool(PRINT_ANY, "external", "external ", true);
-		return;
-	}
-
 	if (!tb[IFLA_VXLAN_ID] ||
 	    RTA_PAYLOAD(tb[IFLA_VXLAN_ID]) < sizeof(__u32))
 		return;
 
 	vni = rta_getattr_u32(tb[IFLA_VXLAN_ID]);
-	print_uint(PRINT_ANY, "id", "id %u ", vni);
+	fprintf(f, "id %u ", vni);
 
 	if (tb[IFLA_VXLAN_GROUP]) {
 		__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]);
-
 		if (addr) {
 			if (IN_MULTICAST(ntohl(addr)))
-				print_string(PRINT_ANY,
-					     "group",
-					     "group %s ",
-					     format_host(AF_INET, 4, &addr));
+				fprintf(f, "group %s ",
+					format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
 			else
-				print_string(PRINT_ANY,
-					     "remote",
-					     "remote %s ",
-					     format_host(AF_INET, 4, &addr));
+				fprintf(f, "remote %s ",
+					format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
 		}
 	} else if (tb[IFLA_VXLAN_GROUP6]) {
 		struct in6_addr addr;
-
 		memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
-		if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) {
+		if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
 			if (IN6_IS_ADDR_MULTICAST(&addr))
-				print_string(PRINT_ANY,
-					     "group6",
-					     "group %s ",
-					     format_host(AF_INET6,
-							 sizeof(struct in6_addr),
-							 &addr));
+				fprintf(f, "group %s ",
+					format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
 			else
-				print_string(PRINT_ANY,
-					     "remote6",
-					     "remote %s ",
-					     format_host(AF_INET6,
-							 sizeof(struct in6_addr),
-							 &addr));
+				fprintf(f, "remote %s ",
+					format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
 		}
 	}
 
 	if (tb[IFLA_VXLAN_LOCAL]) {
 		__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
-
 		if (addr)
-			print_string(PRINT_ANY,
-				     "local",
-				     "local %s ",
-				     format_host(AF_INET, 4, &addr));
+			fprintf(f, "local %s ",
+				format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
 	} else if (tb[IFLA_VXLAN_LOCAL6]) {
 		struct in6_addr addr;
-
 		memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
-		if (!IN6_IS_ADDR_UNSPECIFIED(&addr))
-			print_string(PRINT_ANY,
-				     "local6",
-				     "local %s ",
-				     format_host(AF_INET6,
-						 sizeof(struct in6_addr),
-						 &addr));
+		if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
+			fprintf(f, "local %s ",
+				format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
 	}
 
-	if (tb[IFLA_VXLAN_LINK]) {
-		unsigned int link = rta_getattr_u32(tb[IFLA_VXLAN_LINK]);
+	if (tb[IFLA_VXLAN_LINK] &&
+	    (link = rta_getattr_u32(tb[IFLA_VXLAN_LINK]))) {
+		const char *n = if_indextoname(link, s2);
 
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
+		if (n)
+			fprintf(f, "dev %s ", n);
+		else
+			fprintf(f, "dev %u ", link);
 	}
 
 	if (tb[IFLA_VXLAN_PORT_RANGE]) {
 		const struct ifla_vxlan_port_range *r
 			= RTA_DATA(tb[IFLA_VXLAN_PORT_RANGE]);
-		if (is_json_context()) {
-			open_json_object("port_range");
-			print_uint(PRINT_JSON, "low", NULL, ntohs(r->low));
-			print_uint(PRINT_JSON, "high", NULL, ntohs(r->high));
-			close_json_object();
-		} else {
-			fprintf(f, "srcport %u %u ",
-				ntohs(r->low), ntohs(r->high));
-		}
+		fprintf(f, "srcport %u %u ", ntohs(r->low), ntohs(r->high));
 	}
 
 	if (tb[IFLA_VXLAN_PORT])
-		print_uint(PRINT_ANY,
-			   "port",
-			   "dstport %u ",
-			   rta_getattr_be16(tb[IFLA_VXLAN_PORT]));
+		fprintf(f, "dstport %u ",
+			ntohs(rta_getattr_u16(tb[IFLA_VXLAN_PORT])));
 
-	if (tb[IFLA_VXLAN_LEARNING]) {
-		__u8 learning = rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]);
-
-		print_bool(PRINT_JSON, "learning", NULL, learning);
-		if (!learning)
-			print_bool(PRINT_FP, NULL, "nolearning ", true);
-	}
+	if (tb[IFLA_VXLAN_LEARNING] &&
+	    !rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]))
+		fputs("nolearning ", f);
 
 	if (tb[IFLA_VXLAN_PROXY] && rta_getattr_u8(tb[IFLA_VXLAN_PROXY]))
-		print_bool(PRINT_ANY, "proxy", "proxy ", true);
+		fputs("proxy ", f);
 
 	if (tb[IFLA_VXLAN_RSC] && rta_getattr_u8(tb[IFLA_VXLAN_RSC]))
-		print_bool(PRINT_ANY, "rsc", "rsc ", true);
+		fputs("rsc ", f);
 
 	if (tb[IFLA_VXLAN_L2MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L2MISS]))
-		print_bool(PRINT_ANY, "l2miss", "l2miss ", true);
+		fputs("l2miss ", f);
 
 	if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS]))
-		print_bool(PRINT_ANY, "l3miss", "l3miss ", true);
+		fputs("l3miss ", f);
 
-	if (tb[IFLA_VXLAN_TOS])
-		tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]);
-	if (tos) {
-		if (is_json_context() || tos != 1)
-			print_0xhex(PRINT_ANY, "tos", "tos %#llx ", tos);
+	if (tb[IFLA_VXLAN_TOS] &&
+	    (tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) {
+		if (tos == 1)
+			fprintf(f, "tos inherit ");
 		else
-			print_string(PRINT_FP, NULL, "tos %s ", "inherit");
+			fprintf(f, "tos %#x ", tos);
 	}
 
-	if (tb[IFLA_VXLAN_TTL_INHERIT] &&
-	    rta_getattr_u8(tb[IFLA_VXLAN_TTL_INHERIT])) {
-		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
-	} else if (tb[IFLA_VXLAN_TTL]) {
-		ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
-		if (is_json_context() || ttl)
-			print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
-		else
-			print_string(PRINT_FP, NULL, "ttl %s ", "auto");
-	}
-
-	if (tb[IFLA_VXLAN_DF]) {
-		enum ifla_vxlan_df df = rta_getattr_u8(tb[IFLA_VXLAN_DF]);
-
-		if (df == VXLAN_DF_UNSET)
-			print_string(PRINT_JSON, "df", "df %s ", "unset");
-		else if (df == VXLAN_DF_SET)
-			print_string(PRINT_ANY, "df", "df %s ", "set");
-		else if (df == VXLAN_DF_INHERIT)
-			print_string(PRINT_ANY, "df", "df %s ", "inherit");
-	}
-
-	if (tb[IFLA_VXLAN_LABEL]) {
-		__u32 label = rta_getattr_u32(tb[IFLA_VXLAN_LABEL]);
-
-		if (label)
-			print_0xhex(PRINT_ANY, "label",
-				    "flowlabel %#llx ", ntohl(label));
+	if (tb[IFLA_VXLAN_TTL]) {
+		__u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
+		if (ttl)
+			fprintf(f, "ttl %d ", ttl);
 	}
 
 	if (tb[IFLA_VXLAN_AGEING]) {
 		__u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]);
-
 		if (age == 0)
-			print_uint(PRINT_ANY, "ageing", "ageing none ", 0);
+			fprintf(f, "ageing none ");
 		else
-			print_uint(PRINT_ANY, "ageing", "ageing %u ", age);
+			fprintf(f, "ageing %u ", age);
 	}
 
 	if (tb[IFLA_VXLAN_LIMIT] &&
 	    ((maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT])) != 0))
-		print_uint(PRINT_ANY, "limit", "maxaddr %u ", maxaddr);
+		    fprintf(f, "maxaddr %u ", maxaddr);
 
-	if (tb[IFLA_VXLAN_UDP_CSUM]) {
-		__u8 udp_csum = rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]);
+	if (tb[IFLA_VXLAN_UDP_CSUM] && rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]))
+		fputs("udpcsum ", f);
 
-		if (is_json_context()) {
-			print_bool(PRINT_ANY, "udp_csum", NULL, udp_csum);
-		} else {
-			if (!udp_csum)
-				fputs("no", f);
-			fputs("udpcsum ", f);
-		}
-	}
+	if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX] &&
+	    rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]))
+		fputs("udp6zerocsumtx ", f);
 
-	if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]) {
-		__u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]);
-
-		if (is_json_context()) {
-			print_bool(PRINT_ANY,
-				   "udp_zero_csum6_tx", NULL, csum6);
-		} else {
-			if (!csum6)
-				fputs("no", f);
-			fputs("udp6zerocsumtx ", f);
-		}
-	}
-
-	if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) {
-		__u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]);
-
-		if (is_json_context()) {
-			print_bool(PRINT_ANY,
-				   "udp_zero_csum6_rx",
-				   NULL,
-				   csum6);
-		} else {
-			if (!csum6)
-				fputs("no", f);
-			fputs("udp6zerocsumrx ", f);
-		}
-	}
+	if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX] &&
+	    rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
+		fputs("udp6zerocsumrx ", f);
 
 	if (tb[IFLA_VXLAN_REMCSUM_TX] &&
 	    rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX]))
-		print_bool(PRINT_ANY, "remcsum_tx", "remcsumtx ", true);
+		fputs("remcsumtx ", f);
 
 	if (tb[IFLA_VXLAN_REMCSUM_RX] &&
 	    rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX]))
-		print_bool(PRINT_ANY, "remcsum_rx", "remcsumrx ", true);
+		fputs("remcsumrx ", f);
+
+	if (tb[IFLA_VXLAN_COLLECT_METADATA] &&
+	    rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA]))
+		fputs("external ", f);
 
 	if (tb[IFLA_VXLAN_GBP])
-		print_bool(PRINT_ANY, "gbp", "gbp ", true);
-	if (tb[IFLA_VXLAN_GPE])
-		print_bool(PRINT_ANY, "gpe", "gpe ", true);
+		fputs("gbp ", f);
 }
 
 static void vxlan_print_help(struct link_util *lu, int argc, char **argv,
-			     FILE *f)
+	FILE *f)
 {
 	print_explain(f);
 }
diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c
deleted file mode 100644
index 4a490bc..0000000
--- a/ip/iplink_xdp.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * iplink_xdp.c XDP program loader
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:     Daniel Borkmann <daniel@iogearbox.net>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <linux/bpf.h>
-
-#include "bpf_util.h"
-#include "utils.h"
-#include "ip_common.h"
-
-extern int force;
-
-struct xdp_req {
-	struct iplink_req *req;
-	__u32 flags;
-};
-
-static void xdp_ebpf_cb(void *raw, int fd, const char *annotation)
-{
-	struct xdp_req *xdp = raw;
-	struct iplink_req *req = xdp->req;
-	struct rtattr *xdp_attr;
-
-	xdp_attr = addattr_nest(&req->n, sizeof(*req), IFLA_XDP);
-	addattr32(&req->n, sizeof(*req), IFLA_XDP_FD, fd);
-	if (xdp->flags)
-		addattr32(&req->n, sizeof(*req), IFLA_XDP_FLAGS, xdp->flags);
-	addattr_nest_end(&req->n, xdp_attr);
-}
-
-static const struct bpf_cfg_ops bpf_cb_ops = {
-	.ebpf_cb = xdp_ebpf_cb,
-};
-
-static int xdp_delete(struct xdp_req *xdp)
-{
-	xdp_ebpf_cb(xdp, -1, NULL);
-	return 0;
-}
-
-int xdp_parse(int *argc, char ***argv, struct iplink_req *req,
-	      const char *ifname, bool generic, bool drv, bool offload)
-{
-	struct bpf_cfg_in cfg = {
-		.type = BPF_PROG_TYPE_XDP,
-		.argc = *argc,
-		.argv = *argv,
-	};
-	struct xdp_req xdp = {
-		.req = req,
-	};
-
-	if (offload) {
-		int ifindex = ll_name_to_index(ifname);
-
-		if (!ifindex)
-			incomplete_command();
-		cfg.ifindex = ifindex;
-	}
-
-	if (!force)
-		xdp.flags |= XDP_FLAGS_UPDATE_IF_NOEXIST;
-	if (generic)
-		xdp.flags |= XDP_FLAGS_SKB_MODE;
-	if (drv)
-		xdp.flags |= XDP_FLAGS_DRV_MODE;
-	if (offload)
-		xdp.flags |= XDP_FLAGS_HW_MODE;
-
-	if (*argc == 1) {
-		if (strcmp(**argv, "none") == 0 ||
-		    strcmp(**argv, "off") == 0)
-			return xdp_delete(&xdp);
-	}
-
-	if (bpf_parse_and_load_common(&cfg, &bpf_cb_ops, &xdp))
-		return -1;
-
-	*argc = cfg.argc;
-	*argv = cfg.argv;
-	return 0;
-}
-
-static void xdp_dump_json_one(struct rtattr *tb[IFLA_XDP_MAX + 1], __u32 attr,
-			      __u8 mode)
-{
-	if (!tb[attr])
-		return;
-
-	open_json_object(NULL);
-	print_uint(PRINT_JSON, "mode", NULL, mode);
-	bpf_dump_prog_info(NULL, rta_getattr_u32(tb[attr]));
-	close_json_object();
-}
-
-static void xdp_dump_json(struct rtattr *tb[IFLA_XDP_MAX + 1])
-{
-	__u32 prog_id = 0;
-	__u8 mode;
-
-	mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
-	if (tb[IFLA_XDP_PROG_ID])
-		prog_id = rta_getattr_u32(tb[IFLA_XDP_PROG_ID]);
-
-	open_json_object("xdp");
-	print_uint(PRINT_JSON, "mode", NULL, mode);
-	if (prog_id)
-		bpf_dump_prog_info(NULL, prog_id);
-
-	open_json_array(PRINT_JSON, "attached");
-	if (tb[IFLA_XDP_SKB_PROG_ID] ||
-	    tb[IFLA_XDP_DRV_PROG_ID] ||
-	    tb[IFLA_XDP_HW_PROG_ID]) {
-		xdp_dump_json_one(tb, IFLA_XDP_SKB_PROG_ID, XDP_ATTACHED_SKB);
-		xdp_dump_json_one(tb, IFLA_XDP_DRV_PROG_ID, XDP_ATTACHED_DRV);
-		xdp_dump_json_one(tb, IFLA_XDP_HW_PROG_ID, XDP_ATTACHED_HW);
-	} else if (tb[IFLA_XDP_PROG_ID]) {
-		/* Older kernel - use IFLA_XDP_PROG_ID */
-		xdp_dump_json_one(tb, IFLA_XDP_PROG_ID, mode);
-	}
-	close_json_array(PRINT_JSON, NULL);
-
-	close_json_object();
-}
-
-static void xdp_dump_prog_one(FILE *fp, struct rtattr *tb[IFLA_XDP_MAX + 1],
-			      __u32 attr, bool link, bool details,
-			      const char *pfx)
-{
-	__u32 prog_id;
-
-	if (!tb[attr])
-		return;
-
-	prog_id = rta_getattr_u32(tb[attr]);
-	if (!details) {
-		if (prog_id && !link && attr == IFLA_XDP_PROG_ID)
-			fprintf(fp, "/id:%u", prog_id);
-		return;
-	}
-
-	if (prog_id) {
-		fprintf(fp, "%s    prog/xdp%s ", _SL_, pfx);
-		bpf_dump_prog_info(fp, prog_id);
-	}
-}
-
-void xdp_dump(FILE *fp, struct rtattr *xdp, bool link, bool details)
-{
-	struct rtattr *tb[IFLA_XDP_MAX + 1];
-	__u8 mode;
-
-	parse_rtattr_nested(tb, IFLA_XDP_MAX, xdp);
-
-	if (!tb[IFLA_XDP_ATTACHED])
-		return;
-
-	mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
-	if (mode == XDP_ATTACHED_NONE)
-		return;
-	else if (is_json_context())
-		return details ? (void)0 : xdp_dump_json(tb);
-	else if (details && link)
-		/* don't print mode */;
-	else if (mode == XDP_ATTACHED_DRV)
-		fprintf(fp, "xdp");
-	else if (mode == XDP_ATTACHED_SKB)
-		fprintf(fp, "xdpgeneric");
-	else if (mode == XDP_ATTACHED_HW)
-		fprintf(fp, "xdpoffload");
-	else if (mode == XDP_ATTACHED_MULTI)
-		fprintf(fp, "xdpmulti");
-	else
-		fprintf(fp, "xdp[%u]", mode);
-
-	xdp_dump_prog_one(fp, tb, IFLA_XDP_PROG_ID, link, details, "");
-
-	if (mode == XDP_ATTACHED_MULTI) {
-		xdp_dump_prog_one(fp, tb, IFLA_XDP_SKB_PROG_ID, link, details,
-				  "generic");
-		xdp_dump_prog_one(fp, tb, IFLA_XDP_DRV_PROG_ID, link, details,
-				  "drv");
-		xdp_dump_prog_one(fp, tb, IFLA_XDP_HW_PROG_ID, link, details,
-				  "offload");
-	}
-
-	if (!details || !link)
-		fprintf(fp, " ");
-}
diff --git a/ip/iplink_xstats.c b/ip/iplink_xstats.c
deleted file mode 100644
index c64e688..0000000
--- a/ip/iplink_xstats.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * iplink_stats.c       Extended statistics commands
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:     Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <linux/if_link.h>
-#include <netinet/ether.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static void print_explain(FILE *f)
-{
-	fprintf(f, "Usage: ... xstats type TYPE [ ARGS ]\n");
-}
-
-int iplink_ifla_xstats(int argc, char **argv)
-{
-	struct link_util *lu = NULL;
-	__u32 filt_mask;
-
-	if (!argc) {
-		fprintf(stderr, "xstats: missing argument\n");
-		return -1;
-	}
-
-	if (matches(*argv, "type") == 0) {
-		NEXT_ARG();
-		lu = get_link_kind(*argv);
-		if (!lu)
-			invarg("invalid type", *argv);
-	} else if (matches(*argv, "help") == 0) {
-		print_explain(stdout);
-		return 0;
-	} else {
-		invarg("unknown argument", *argv);
-	}
-
-	if (!lu) {
-		print_explain(stderr);
-		return -1;
-	}
-
-	if (!lu->print_ifla_xstats) {
-		fprintf(stderr, "xstats: link type %s doesn't support xstats\n",
-			lu->id);
-		return -1;
-	}
-
-	if (lu->parse_ifla_xstats &&
-	    lu->parse_ifla_xstats(lu, argc-1, argv+1))
-		return -1;
-
-	if (strstr(lu->id, "_slave"))
-		filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE);
-	else
-		filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS);
-
-	if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) {
-		perror("Cannont send dump request");
-		return -1;
-	}
-
-	new_json_obj(json);
-	if (rtnl_dump_filter(&rth, lu->print_ifla_xstats, stdout) < 0) {
-		delete_json_obj();
-		fprintf(stderr, "Dump terminated\n");
-		return -1;
-	}
-	delete_json_obj();
-
-	return 0;
-}
diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
deleted file mode 100644
index ad6ad7d..0000000
--- a/ip/ipmacsec.c
+++ /dev/null
@@ -1,1381 +0,0 @@
-/*
- * ipmacsec.c		"ip macsec".
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Sabrina Dubroca <sd@queasysnail.net>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <linux/genetlink.h>
-#include <linux/if_ether.h>
-#include <linux/if_macsec.h>
-
-#include "rt_names.h"
-#include "utils.h"
-#include "ip_common.h"
-#include "ll_map.h"
-#include "libgenl.h"
-
-static const char * const values_on_off[] = { "off", "on" };
-
-static const char * const validate_str[] = {
-	[MACSEC_VALIDATE_DISABLED] = "disabled",
-	[MACSEC_VALIDATE_CHECK] = "check",
-	[MACSEC_VALIDATE_STRICT] = "strict",
-};
-
-struct sci {
-	__u64 sci;
-	__u16 port;
-	char abuf[6];
-};
-
-struct sa_desc {
-	__u8 an;
-	__u32 pn;
-	__u8 key_id[MACSEC_KEYID_LEN];
-	__u32 key_len;
-	__u8 key[MACSEC_MAX_KEY_LEN];
-	__u8 active;
-};
-
-struct cipher_args {
-	__u64 id;
-	__u8 icv_len;
-};
-
-struct txsc_desc {
-	int ifindex;
-	__u64 sci;
-	__be16 port;
-	struct cipher_args cipher;
-	__u32 window;
-	enum macsec_validation_type validate;
-	__u8 encoding_sa;
-};
-
-struct rxsc_desc {
-	int ifindex;
-	__u64 sci;
-	__u8 active;
-};
-
-#define MACSEC_BUFLEN 1024
-
-
-/* netlink socket */
-static struct rtnl_handle genl_rth;
-static int genl_family = -1;
-
-#define MACSEC_GENL_REQ(_req, _bufsiz, _cmd, _flags) \
-	GENL_REQUEST(_req, _bufsiz, genl_family, 0, MACSEC_GENL_VERSION, \
-		     _cmd, _flags)
-
-
-static void ipmacsec_usage(void)
-{
-	fprintf(stderr,
-		"Usage: ip macsec add DEV tx sa { 0..3 } [ OPTS ] key ID KEY\n"
-		"       ip macsec set DEV tx sa { 0..3 } [ OPTS ]\n"
-		"       ip macsec del DEV tx sa { 0..3 }\n"
-		"       ip macsec add DEV rx SCI [ on | off ]\n"
-		"       ip macsec set DEV rx SCI [ on | off ]\n"
-		"       ip macsec del DEV rx SCI\n"
-		"       ip macsec add DEV rx SCI sa { 0..3 } [ OPTS ] key ID KEY\n"
-		"       ip macsec set DEV rx SCI sa { 0..3 } [ OPTS ]\n"
-		"       ip macsec del DEV rx SCI sa { 0..3 }\n"
-		"       ip macsec show\n"
-		"       ip macsec show DEV\n"
-		"where  OPTS := [ pn <u32> ] [ on | off ]\n"
-		"       ID   := 128-bit hex string\n"
-		"       KEY  := 128-bit or 256-bit hex string\n"
-		"       SCI  := { sci <u64> | port { 1..2^16-1 } address <lladdr> }\n");
-
-	exit(-1);
-}
-
-static int one_of(const char *msg, const char *realval, const char * const *list,
-		  size_t len, int *index)
-{
-	int i;
-
-	for (i = 0; i < len; i++) {
-		if (matches(realval, list[i]) == 0) {
-			*index = i;
-			return 0;
-		}
-	}
-
-	fprintf(stderr, "Error: argument of \"%s\" must be one of ", msg);
-	for (i = 0; i < len; i++)
-		fprintf(stderr, "\"%s\", ", list[i]);
-	fprintf(stderr, "not \"%s\"\n", realval);
-	return -1;
-}
-
-static int get_an(__u8 *val, const char *arg)
-{
-	int ret = get_u8(val, arg, 0);
-
-	if (ret)
-		return ret;
-
-	if (*val > 3)
-		return -1;
-
-	return 0;
-}
-
-static int get_sci(__u64 *sci, const char *arg)
-{
-	return get_be64(sci, arg, 16);
-}
-
-static int get_port(__be16 *port, const char *arg)
-{
-	return get_be16(port, arg, 0);
-}
-
-#define _STR(a) #a
-#define STR(a) _STR(a)
-
-static void get_icvlen(__u8 *icvlen, char *arg)
-{
-	int ret = get_u8(icvlen, arg, 10);
-
-	if (ret)
-		invarg("expected ICV length", arg);
-
-	if (*icvlen < MACSEC_MIN_ICV_LEN || *icvlen > MACSEC_STD_ICV_LEN)
-		invarg("ICV length must be in the range {"
-		       STR(MACSEC_MIN_ICV_LEN) ".." STR(MACSEC_STD_ICV_LEN)
-		       "}", arg);
-}
-
-static bool get_sa(int *argcp, char ***argvp, __u8 *an)
-{
-	int argc = *argcp;
-	char **argv = *argvp;
-	int ret;
-
-	if (argc <= 0 || strcmp(*argv, "sa") != 0)
-		return false;
-
-	NEXT_ARG();
-	ret = get_an(an, *argv);
-	if (ret)
-		invarg("expected an { 0..3 }", *argv);
-	argc--; argv++;
-
-	*argvp = argv;
-	*argcp = argc;
-	return true;
-}
-
-static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa)
-{
-	int argc = *argcp;
-	char **argv = *argvp;
-	int ret;
-	bool active_set = false;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "pn") == 0) {
-			if (sa->pn != 0)
-				duparg2("pn", "pn");
-			NEXT_ARG();
-			ret = get_u32(&sa->pn, *argv, 0);
-			if (ret)
-				invarg("expected pn", *argv);
-			if (sa->pn == 0)
-				invarg("expected pn != 0", *argv);
-		} else if (strcmp(*argv, "key") == 0) {
-			unsigned int len;
-
-			NEXT_ARG();
-			if (!hexstring_a2n(*argv, sa->key_id, MACSEC_KEYID_LEN,
-					   &len))
-				invarg("expected key id", *argv);
-			NEXT_ARG();
-			if (!hexstring_a2n(*argv, sa->key, MACSEC_MAX_KEY_LEN,
-					   &sa->key_len))
-				invarg("expected key", *argv);
-		} else if (strcmp(*argv, "on") == 0) {
-			if (active_set)
-				duparg2("on/off", "on");
-			sa->active = true;
-			active_set = true;
-		} else if (strcmp(*argv, "off") == 0) {
-			if (active_set)
-				duparg2("on/off", "off");
-			sa->active = false;
-			active_set = true;
-		} else {
-			fprintf(stderr, "macsec: unknown command \"%s\"?\n",
-				*argv);
-			ipmacsec_usage();
-		}
-
-		argv++; argc--;
-	}
-
-	*argvp = argv;
-	*argcp = argc;
-	return 0;
-}
-
-static __u64 make_sci(char *addr, __be16 port)
-{
-	__u64 sci;
-
-	memcpy(&sci, addr, ETH_ALEN);
-	memcpy(((char *)&sci) + ETH_ALEN, &port, sizeof(port));
-
-	return sci;
-}
-
-static bool sci_complete(bool sci, bool port, bool addr, bool port_only)
-{
-	return sci || (port && (addr || port_only));
-}
-
-static int get_sci_portaddr(struct sci *sci, int *argcp, char ***argvp,
-			    bool port_only, bool optional)
-{
-	int argc = *argcp;
-	char **argv = *argvp;
-	int ret;
-	bool p = false, a = false, s = false;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "sci") == 0) {
-			if (p)
-				invarg("expected address", *argv);
-			if (a)
-				invarg("expected port", *argv);
-			NEXT_ARG();
-			ret = get_sci(&sci->sci, *argv);
-			if (ret)
-				invarg("expected sci", *argv);
-			s = true;
-		} else if (strcmp(*argv, "port") == 0) {
-			NEXT_ARG();
-			ret = get_port(&sci->port, *argv);
-			if (ret)
-				invarg("expected port", *argv);
-			if (sci->port == 0)
-				invarg("expected port != 0", *argv);
-			p = true;
-		} else if (strcmp(*argv, "address") == 0) {
-			NEXT_ARG();
-			ret = ll_addr_a2n(sci->abuf, sizeof(sci->abuf), *argv);
-			if (ret < 0)
-				invarg("expected lladdr", *argv);
-			a = true;
-		} else if (optional) {
-			break;
-		} else {
-			invarg("expected sci, port, or address", *argv);
-		}
-
-		argv++; argc--;
-
-		if (sci_complete(s, p, a, port_only))
-			break;
-	}
-
-	if (!optional && !sci_complete(s, p, a, port_only))
-		return -1;
-
-	if (p && a)
-		sci->sci = make_sci(sci->abuf, sci->port);
-
-	*argvp = argv;
-	*argcp = argc;
-
-	return p || a || s;
-}
-
-static bool parse_rxsci(int *argcp, char ***argvp, struct rxsc_desc *rxsc,
-			struct sa_desc *rxsa)
-{
-	struct sci sci = { 0 };
-
-	if (*argcp == 0 ||
-	    get_sci_portaddr(&sci, argcp, argvp, false, false) < 0) {
-		fprintf(stderr, "expected sci\n");
-		ipmacsec_usage();
-	}
-
-	rxsc->sci = sci.sci;
-
-	return get_sa(argcp, argvp, &rxsa->an);
-}
-
-static int parse_rxsci_args(int *argcp, char ***argvp, struct rxsc_desc *rxsc)
-{
-	int argc = *argcp;
-	char **argv = *argvp;
-	bool active_set = false;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "on") == 0) {
-			if (active_set)
-				duparg2("on/off", "on");
-			rxsc->active = true;
-			active_set = true;
-		} else if (strcmp(*argv, "off") == 0) {
-			if (active_set)
-				duparg2("on/off", "off");
-			rxsc->active = false;
-			active_set = true;
-		} else {
-			fprintf(stderr, "macsec: unknown command \"%s\"?\n",
-				*argv);
-			ipmacsec_usage();
-		}
-
-		argv++; argc--;
-	}
-
-	*argvp = argv;
-	*argcp = argc;
-	return 0;
-}
-
-enum cmd {
-	CMD_ADD,
-	CMD_DEL,
-	CMD_UPD,
-	__CMD_MAX
-};
-
-static const enum macsec_nl_commands macsec_commands[__CMD_MAX][2][2] = {
-	[CMD_ADD] = {
-		[0] = {-1, MACSEC_CMD_ADD_RXSC},
-		[1] = {MACSEC_CMD_ADD_TXSA, MACSEC_CMD_ADD_RXSA},
-	},
-	[CMD_UPD] = {
-		[0] = {-1, MACSEC_CMD_UPD_RXSC},
-		[1] = {MACSEC_CMD_UPD_TXSA, MACSEC_CMD_UPD_RXSA},
-	},
-	[CMD_DEL] = {
-		[0] = {-1, MACSEC_CMD_DEL_RXSC},
-		[1] = {MACSEC_CMD_DEL_TXSA, MACSEC_CMD_DEL_RXSA},
-	},
-};
-
-static int do_modify_nl(enum cmd c, enum macsec_nl_commands cmd, int ifindex,
-			struct rxsc_desc *rxsc, struct sa_desc *sa)
-{
-	struct rtattr *attr_sa;
-
-	MACSEC_GENL_REQ(req, MACSEC_BUFLEN, cmd, NLM_F_REQUEST);
-
-	addattr32(&req.n, MACSEC_BUFLEN, MACSEC_ATTR_IFINDEX, ifindex);
-	if (rxsc) {
-		struct rtattr *attr_rxsc;
-
-		attr_rxsc = addattr_nest(&req.n, MACSEC_BUFLEN,
-					 MACSEC_ATTR_RXSC_CONFIG);
-		addattr64(&req.n, MACSEC_BUFLEN,
-			  MACSEC_RXSC_ATTR_SCI, rxsc->sci);
-		if (c != CMD_DEL && rxsc->active != 0xff)
-			addattr8(&req.n, MACSEC_BUFLEN,
-				 MACSEC_RXSC_ATTR_ACTIVE, rxsc->active);
-
-		addattr_nest_end(&req.n, attr_rxsc);
-	}
-
-	if (sa->an == 0xff)
-		goto talk;
-
-	attr_sa = addattr_nest(&req.n, MACSEC_BUFLEN, MACSEC_ATTR_SA_CONFIG);
-
-	addattr8(&req.n, MACSEC_BUFLEN, MACSEC_SA_ATTR_AN, sa->an);
-
-	if (c != CMD_DEL) {
-		if (sa->pn)
-			addattr32(&req.n, MACSEC_BUFLEN, MACSEC_SA_ATTR_PN,
-				  sa->pn);
-
-		if (sa->key_len) {
-			addattr_l(&req.n, MACSEC_BUFLEN, MACSEC_SA_ATTR_KEYID,
-				  sa->key_id, MACSEC_KEYID_LEN);
-			addattr_l(&req.n, MACSEC_BUFLEN, MACSEC_SA_ATTR_KEY,
-				  sa->key, sa->key_len);
-		}
-
-		if (sa->active != 0xff) {
-			addattr8(&req.n, MACSEC_BUFLEN,
-				 MACSEC_SA_ATTR_ACTIVE, sa->active);
-		}
-	}
-
-	addattr_nest_end(&req.n, attr_sa);
-
-talk:
-	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
-		return -2;
-
-	return 0;
-}
-
-static bool check_sa_args(enum cmd c, struct sa_desc *sa)
-{
-	if (c == CMD_ADD) {
-		if (!sa->key_len) {
-			fprintf(stderr, "cannot create SA without key\n");
-			return -1;
-		}
-
-		if (sa->pn == 0) {
-			fprintf(stderr, "must specify a packet number != 0\n");
-			return -1;
-		}
-	} else if (c == CMD_UPD) {
-		if (sa->key_len) {
-			fprintf(stderr, "cannot change key on SA\n");
-			return -1;
-		}
-	}
-
-	return 0;
-}
-
-static int do_modify_txsa(enum cmd c, int argc, char **argv, int ifindex)
-{
-	struct sa_desc txsa = {0};
-	enum macsec_nl_commands cmd;
-
-	txsa.an = 0xff;
-	txsa.active = 0xff;
-
-	if (argc == 0 || !get_sa(&argc, &argv, &txsa.an))
-		ipmacsec_usage();
-
-	if (c == CMD_DEL)
-		goto modify;
-
-	if (parse_sa_args(&argc, &argv, &txsa))
-		return -1;
-
-	if (check_sa_args(c, &txsa))
-		return -1;
-
-modify:
-	cmd = macsec_commands[c][1][0];
-	return do_modify_nl(c, cmd, ifindex, NULL, &txsa);
-}
-
-static int do_modify_rxsci(enum cmd c, int argc, char **argv, int ifindex)
-{
-	struct rxsc_desc rxsc = {0};
-	struct sa_desc rxsa = {0};
-	bool sa_set;
-	enum macsec_nl_commands cmd;
-
-	rxsc.ifindex = ifindex;
-	rxsc.active = 0xff;
-	rxsa.an = 0xff;
-	rxsa.active = 0xff;
-
-	sa_set = parse_rxsci(&argc, &argv, &rxsc, &rxsa);
-
-	if (c == CMD_DEL)
-		goto modify;
-
-	if (sa_set && (parse_sa_args(&argc, &argv, &rxsa) ||
-		       check_sa_args(c, &rxsa)))
-		return -1;
-	if (!sa_set && parse_rxsci_args(&argc, &argv, &rxsc))
-		return -1;
-
-modify:
-	cmd = macsec_commands[c][sa_set][1];
-	return do_modify_nl(c, cmd, rxsc.ifindex, &rxsc, &rxsa);
-}
-
-static int do_modify(enum cmd c, int argc, char **argv)
-{
-	int ifindex;
-
-	if (argc == 0)
-		ipmacsec_usage();
-
-	ifindex = ll_name_to_index(*argv);
-	if (!ifindex) {
-		fprintf(stderr, "Device \"%s\" does not exist.\n", *argv);
-		return -1;
-	}
-	argc--; argv++;
-
-	if (argc == 0)
-		ipmacsec_usage();
-
-	if (strcmp(*argv, "tx") == 0)
-		return do_modify_txsa(c, argc-1, argv+1, ifindex);
-	if (strcmp(*argv, "rx") == 0)
-		return do_modify_rxsci(c, argc-1, argv+1, ifindex);
-
-	ipmacsec_usage();
-	return -1;
-}
-
-/* dump/show */
-static struct {
-	int ifindex;
-	__u64 sci;
-} filter;
-
-static int validate_dump(struct rtattr **attrs)
-{
-	return attrs[MACSEC_ATTR_IFINDEX] && attrs[MACSEC_ATTR_SECY] &&
-	       attrs[MACSEC_ATTR_TXSA_LIST] && attrs[MACSEC_ATTR_RXSC_LIST] &&
-	       attrs[MACSEC_ATTR_TXSC_STATS] && attrs[MACSEC_ATTR_SECY_STATS];
-
-}
-
-static int validate_secy_dump(struct rtattr **attrs)
-{
-	return attrs[MACSEC_SECY_ATTR_SCI] &&
-	       attrs[MACSEC_SECY_ATTR_ENCODING_SA] &&
-	       attrs[MACSEC_SECY_ATTR_CIPHER_SUITE] &&
-	       attrs[MACSEC_SECY_ATTR_ICV_LEN] &&
-	       attrs[MACSEC_SECY_ATTR_PROTECT] &&
-	       attrs[MACSEC_SECY_ATTR_REPLAY] &&
-	       attrs[MACSEC_SECY_ATTR_OPER] &&
-	       attrs[MACSEC_SECY_ATTR_VALIDATE] &&
-	       attrs[MACSEC_SECY_ATTR_ENCRYPT] &&
-	       attrs[MACSEC_SECY_ATTR_INC_SCI] &&
-	       attrs[MACSEC_SECY_ATTR_ES] &&
-	       attrs[MACSEC_SECY_ATTR_SCB];
-}
-
-static void print_flag(struct rtattr *attrs[], const char *desc,
-		       int field)
-{
-	__u8 flag;
-
-	if (!attrs[field])
-		return;
-
-	flag = rta_getattr_u8(attrs[field]);
-	if (is_json_context())
-		print_bool(PRINT_JSON, desc, NULL, flag);
-	else {
-		print_string(PRINT_FP, NULL, "%s ", desc);
-		print_string(PRINT_FP, NULL, "%s ",
-			     flag ? "on" : "off");
-	}
-}
-
-static void print_key(struct rtattr *key)
-{
-	SPRINT_BUF(keyid);
-
-	print_string(PRINT_ANY, "key", " key %s\n",
-		     hexstring_n2a(RTA_DATA(key), RTA_PAYLOAD(key),
-				   keyid, sizeof(keyid)));
-}
-
-#define CIPHER_NAME_GCM_AES_128 "GCM-AES-128"
-#define CIPHER_NAME_GCM_AES_256 "GCM-AES-256"
-#define DEFAULT_CIPHER_NAME CIPHER_NAME_GCM_AES_128
-
-static const char *cs_id_to_name(__u64 cid)
-{
-	switch (cid) {
-	case MACSEC_DEFAULT_CIPHER_ID:
-		return DEFAULT_CIPHER_NAME;
-	case MACSEC_CIPHER_ID_GCM_AES_128:
-	     /* MACSEC_DEFAULT_CIPHER_ALT: */
-		return CIPHER_NAME_GCM_AES_128;
-	case MACSEC_CIPHER_ID_GCM_AES_256:
-		return CIPHER_NAME_GCM_AES_256;
-	default:
-		return "(unknown)";
-	}
-}
-
-static void print_attrs(struct rtattr *attrs[])
-{
-	print_flag(attrs, "protect", MACSEC_SECY_ATTR_PROTECT);
-
-	if (attrs[MACSEC_SECY_ATTR_VALIDATE]) {
-		__u8 val = rta_getattr_u8(attrs[MACSEC_SECY_ATTR_VALIDATE]);
-
-		print_string(PRINT_ANY, "validate",
-			     "validate %s ", validate_str[val]);
-	}
-
-	print_flag(attrs, "sc", MACSEC_RXSC_ATTR_ACTIVE);
-	print_flag(attrs, "sa", MACSEC_SA_ATTR_ACTIVE);
-	print_flag(attrs, "encrypt", MACSEC_SECY_ATTR_ENCRYPT);
-	print_flag(attrs, "send_sci", MACSEC_SECY_ATTR_INC_SCI);
-	print_flag(attrs, "end_station", MACSEC_SECY_ATTR_ES);
-	print_flag(attrs, "scb", MACSEC_SECY_ATTR_SCB);
-	print_flag(attrs, "replay", MACSEC_SECY_ATTR_REPLAY);
-
-	if (attrs[MACSEC_SECY_ATTR_WINDOW]) {
-		__u32 win = rta_getattr_u32(attrs[MACSEC_SECY_ATTR_WINDOW]);
-
-		print_uint(PRINT_ANY, "window", "window %u ", win);
-	}
-
-	if (attrs[MACSEC_SECY_ATTR_CIPHER_SUITE]) {
-		__u64 cid = rta_getattr_u64(attrs[MACSEC_SECY_ATTR_CIPHER_SUITE]);
-
-		print_nl();
-		print_string(PRINT_ANY, "cipher_suite",
-			     "    cipher suite: %s,", cs_id_to_name(cid));
-	}
-
-	if (attrs[MACSEC_SECY_ATTR_ICV_LEN]) {
-		__u8 icv_len = rta_getattr_u8(attrs[MACSEC_SECY_ATTR_ICV_LEN]);
-
-		print_uint(PRINT_ANY, "icv_length",
-		     " using ICV length %u\n", icv_len);
-	}
-}
-
-static __u64 getattr_u64(const struct rtattr *stat)
-{
-	size_t len = RTA_PAYLOAD(stat);
-
-	switch (len) {
-	case sizeof(__u64):
-		return rta_getattr_u64(stat);
-	case sizeof(__u32):
-		return rta_getattr_u32(stat);
-	case sizeof(__u16):
-		return rta_getattr_u16(stat);
-	case sizeof(__u8):
-		return rta_getattr_u8(stat);
-	default:
-		fprintf(stderr, "invalid attribute length %zu\n",
-			len);
-		exit(-1);
-	}
-}
-
-static void print_fp_stats(const char *prefix,
-			   const char *names[], unsigned int num,
-			   struct rtattr *stats[])
-{
-	unsigned int i;
-	int pad;
-
-	printf("%sstats:", prefix);
-
-	for (i = 1; i < num; i++) {
-		if (!names[i])
-			continue;
-		printf(" %s", names[i]);
-	}
-
-	printf("\n%s      ", prefix);
-
-	for (i = 1; i < num; i++) {
-		if (!names[i])
-			continue;
-
-		pad = strlen(names[i]) + 1;
-		if (stats[i])
-			printf("%*llu", pad, getattr_u64(stats[i]));
-		else
-			printf("%*c", pad, '-');
-	}
-	printf("\n");
-}
-
-static void print_json_stats(const char *names[], unsigned int num,
-			     struct rtattr *stats[])
-{
-	unsigned int i;
-
-	for (i = 1; i < num; i++) {
-		if (!names[i] || !stats[i])
-			continue;
-
-		print_u64(PRINT_JSON, names[i],
-			   NULL, getattr_u64(stats[i]));
-	}
-}
-
-static void print_stats(const char *prefix,
-			const char *names[], unsigned int num,
-			struct rtattr *stats[])
-{
-
-	if (is_json_context())
-		print_json_stats(names, num, stats);
-	else
-		print_fp_stats(prefix, names, num, stats);
-}
-
-static const char *txsc_stats_names[NUM_MACSEC_TXSC_STATS_ATTR] = {
-	[MACSEC_TXSC_STATS_ATTR_OUT_PKTS_PROTECTED] = "OutPktsProtected",
-	[MACSEC_TXSC_STATS_ATTR_OUT_PKTS_ENCRYPTED] = "OutPktsEncrypted",
-	[MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_PROTECTED] = "OutOctetsProtected",
-	[MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_ENCRYPTED] = "OutOctetsEncrypted",
-};
-
-static void print_txsc_stats(const char *prefix, struct rtattr *attr)
-{
-	struct rtattr *stats[MACSEC_TXSC_STATS_ATTR_MAX + 1];
-
-	if (!attr || show_stats == 0)
-		return;
-
-	parse_rtattr_nested(stats, MACSEC_TXSC_STATS_ATTR_MAX, attr);
-
-	print_stats(prefix, txsc_stats_names, NUM_MACSEC_TXSC_STATS_ATTR,
-		    stats);
-}
-
-static const char *secy_stats_names[NUM_MACSEC_SECY_STATS_ATTR] = {
-	[MACSEC_SECY_STATS_ATTR_OUT_PKTS_UNTAGGED] = "OutPktsUntagged",
-	[MACSEC_SECY_STATS_ATTR_IN_PKTS_UNTAGGED] = "InPktsUntagged",
-	[MACSEC_SECY_STATS_ATTR_OUT_PKTS_TOO_LONG] = "OutPktsTooLong",
-	[MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_TAG] = "InPktsNoTag",
-	[MACSEC_SECY_STATS_ATTR_IN_PKTS_BAD_TAG] = "InPktsBadTag",
-	[MACSEC_SECY_STATS_ATTR_IN_PKTS_UNKNOWN_SCI] = "InPktsUnknownSCI",
-	[MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_SCI] = "InPktsNoSCI",
-	[MACSEC_SECY_STATS_ATTR_IN_PKTS_OVERRUN] = "InPktsOverrun",
-};
-
-static void print_secy_stats(const char *prefix, struct rtattr *attr)
-{
-	struct rtattr *stats[MACSEC_SECY_STATS_ATTR_MAX + 1];
-
-	if (!attr || show_stats == 0)
-		return;
-
-	parse_rtattr_nested(stats, MACSEC_SECY_STATS_ATTR_MAX, attr);
-
-	print_stats(prefix, secy_stats_names,
-		    NUM_MACSEC_SECY_STATS_ATTR, stats);
-}
-
-static const char *rxsa_stats_names[NUM_MACSEC_SA_STATS_ATTR] = {
-	[MACSEC_SA_STATS_ATTR_IN_PKTS_OK] = "InPktsOK",
-	[MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID] = "InPktsInvalid",
-	[MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID] = "InPktsNotValid",
-	[MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA] = "InPktsNotUsingSA",
-	[MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA] = "InPktsUnusedSA",
-};
-
-static void print_rxsa_stats(const char *prefix, struct rtattr *attr)
-{
-	struct rtattr *stats[MACSEC_SA_STATS_ATTR_MAX + 1];
-
-	if (!attr || show_stats == 0)
-		return;
-
-	parse_rtattr_nested(stats, MACSEC_SA_STATS_ATTR_MAX, attr);
-
-	print_stats(prefix, rxsa_stats_names, NUM_MACSEC_SA_STATS_ATTR, stats);
-}
-
-static const char *txsa_stats_names[NUM_MACSEC_SA_STATS_ATTR] = {
-	[MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED] = "OutPktsProtected",
-	[MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED] = "OutPktsEncrypted",
-};
-
-static void print_txsa_stats(const char *prefix, struct rtattr *attr)
-{
-	struct rtattr *stats[MACSEC_SA_STATS_ATTR_MAX + 1];
-
-	if (!attr || show_stats == 0)
-		return;
-
-	parse_rtattr_nested(stats, MACSEC_SA_STATS_ATTR_MAX, attr);
-
-	print_stats(prefix, txsa_stats_names, NUM_MACSEC_SA_STATS_ATTR, stats);
-}
-
-static void print_tx_sc(const char *prefix, __u64 sci, __u8 encoding_sa,
-			struct rtattr *txsc_stats, struct rtattr *secy_stats,
-			struct rtattr *sa)
-{
-	struct rtattr *sa_attr[MACSEC_SA_ATTR_MAX + 1];
-	struct rtattr *a;
-	int rem;
-
-	print_string(PRINT_FP, NULL, "%s", prefix);
-	print_0xhex(PRINT_ANY, "sci",
-		    "TXSC: %016llx", ntohll(sci));
-	print_uint(PRINT_ANY, "encoding_sa",
-		   " on SA %d\n", encoding_sa);
-
-	print_secy_stats(prefix, secy_stats);
-	print_txsc_stats(prefix, txsc_stats);
-
-	open_json_array(PRINT_JSON, "sa_list");
-	rem = RTA_PAYLOAD(sa);
-	for (a = RTA_DATA(sa); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) {
-		bool state;
-
-		open_json_object(NULL);
-		parse_rtattr_nested(sa_attr, MACSEC_SA_ATTR_MAX, a);
-		state = rta_getattr_u8(sa_attr[MACSEC_SA_ATTR_ACTIVE]);
-
-		print_string(PRINT_FP, NULL, "%s", prefix);
-		print_string(PRINT_FP, NULL, "%s", prefix);
-		print_uint(PRINT_ANY, "an", "%d:",
-			   rta_getattr_u8(sa_attr[MACSEC_SA_ATTR_AN]));
-		print_uint(PRINT_ANY, "pn", " PN %u,",
-			   rta_getattr_u32(sa_attr[MACSEC_SA_ATTR_PN]));
-
-		print_bool(PRINT_JSON, "active", NULL, state);
-		print_string(PRINT_FP, NULL,
-			     " state %s,", state ? "on" : "off");
-		print_key(sa_attr[MACSEC_SA_ATTR_KEYID]);
-
-		print_txsa_stats(prefix, sa_attr[MACSEC_SA_ATTR_STATS]);
-		close_json_object();
-	}
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static const char *rxsc_stats_names[NUM_MACSEC_RXSC_STATS_ATTR] = {
-	[MACSEC_RXSC_STATS_ATTR_IN_OCTETS_VALIDATED] = "InOctetsValidated",
-	[MACSEC_RXSC_STATS_ATTR_IN_OCTETS_DECRYPTED] = "InOctetsDecrypted",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNCHECKED] = "InPktsUnchecked",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_DELAYED] = "InPktsDelayed",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_OK] = "InPktsOK",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_INVALID] = "InPktsInvalid",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_LATE] = "InPktsLate",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_VALID] = "InPktsNotValid",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_USING_SA] = "InPktsNotUsingSA",
-	[MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNUSED_SA] = "InPktsUnusedSA",
-};
-
-static void print_rxsc_stats(const char *prefix, struct rtattr *attr)
-{
-	struct rtattr *stats[MACSEC_RXSC_STATS_ATTR_MAX + 1];
-
-	if (!attr || show_stats == 0)
-		return;
-
-	parse_rtattr_nested(stats, MACSEC_RXSC_STATS_ATTR_MAX, attr);
-
-	print_stats(prefix, rxsc_stats_names,
-		    NUM_MACSEC_RXSC_STATS_ATTR, stats);
-}
-
-static void print_rx_sc(const char *prefix, __be64 sci, __u8 active,
-			struct rtattr *rxsc_stats, struct rtattr *sa)
-{
-	struct rtattr *sa_attr[MACSEC_SA_ATTR_MAX + 1];
-	struct rtattr *a;
-	int rem;
-
-	print_string(PRINT_FP, NULL, "%s", prefix);
-	print_0xhex(PRINT_ANY, "sci",
-		    "RXSC: %016llx,", ntohll(sci));
-	print_bool(PRINT_JSON, "active", NULL, active);
-	print_string(PRINT_FP, NULL,
-		     " state %s\n", active ? "on" : "off");
-	print_rxsc_stats(prefix, rxsc_stats);
-
-	open_json_array(PRINT_JSON, "sa_list");
-	rem = RTA_PAYLOAD(sa);
-	for (a = RTA_DATA(sa); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) {
-		bool state;
-
-		open_json_object(NULL);
-		parse_rtattr_nested(sa_attr, MACSEC_SA_ATTR_MAX, a);
-		state = rta_getattr_u8(sa_attr[MACSEC_SA_ATTR_ACTIVE]);
-
-		print_string(PRINT_FP, NULL, "%s", prefix);
-		print_string(PRINT_FP, NULL, "%s", prefix);
-		print_uint(PRINT_ANY, "an", "%u:",
-			   rta_getattr_u8(sa_attr[MACSEC_SA_ATTR_AN]));
-		print_uint(PRINT_ANY, "pn", " PN %u,",
-			   rta_getattr_u32(sa_attr[MACSEC_SA_ATTR_PN]));
-
-		print_bool(PRINT_JSON, "active", NULL, state);
-		print_string(PRINT_FP, NULL, " state %s,",
-			     state ? "on" : "off");
-
-		print_key(sa_attr[MACSEC_SA_ATTR_KEYID]);
-
-		print_rxsa_stats(prefix, sa_attr[MACSEC_SA_ATTR_STATS]);
-		close_json_object();
-	}
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void print_rxsc_list(struct rtattr *sc)
-{
-	int rem = RTA_PAYLOAD(sc);
-	struct rtattr *c;
-
-	open_json_array(PRINT_JSON, "rx_sc");
-	for (c = RTA_DATA(sc); RTA_OK(c, rem); c = RTA_NEXT(c, rem)) {
-		struct rtattr *sc_attr[MACSEC_RXSC_ATTR_MAX + 1];
-
-		open_json_object(NULL);
-
-		parse_rtattr_nested(sc_attr, MACSEC_RXSC_ATTR_MAX, c);
-		print_rx_sc("    ",
-			    rta_getattr_u64(sc_attr[MACSEC_RXSC_ATTR_SCI]),
-			    rta_getattr_u32(sc_attr[MACSEC_RXSC_ATTR_ACTIVE]),
-			    sc_attr[MACSEC_RXSC_ATTR_STATS],
-			    sc_attr[MACSEC_RXSC_ATTR_SA_LIST]);
-		close_json_object();
-	}
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static int process(struct nlmsghdr *n, void *arg)
-{
-	struct genlmsghdr *ghdr;
-	struct rtattr *attrs[MACSEC_ATTR_MAX + 1];
-	struct rtattr *attrs_secy[MACSEC_SECY_ATTR_MAX + 1];
-	int len = n->nlmsg_len;
-	int ifindex;
-	__u64 sci;
-	__u8 encoding_sa;
-
-	if (n->nlmsg_type != genl_family)
-		return -1;
-
-	len -= NLMSG_LENGTH(GENL_HDRLEN);
-	if (len < 0)
-		return -1;
-
-	ghdr = NLMSG_DATA(n);
-	if (ghdr->cmd != MACSEC_CMD_GET_TXSC)
-		return 0;
-
-	parse_rtattr(attrs, MACSEC_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
-	if (!validate_dump(attrs)) {
-		fprintf(stderr, "incomplete dump message\n");
-		return -1;
-	}
-
-	ifindex = rta_getattr_u32(attrs[MACSEC_ATTR_IFINDEX]);
-	parse_rtattr_nested(attrs_secy, MACSEC_SECY_ATTR_MAX,
-			    attrs[MACSEC_ATTR_SECY]);
-
-	if (!validate_secy_dump(attrs_secy)) {
-		fprintf(stderr, "incomplete dump message\n");
-		return -1;
-	}
-
-	sci = rta_getattr_u64(attrs_secy[MACSEC_SECY_ATTR_SCI]);
-	encoding_sa = rta_getattr_u8(attrs_secy[MACSEC_SECY_ATTR_ENCODING_SA]);
-
-	if (filter.ifindex && ifindex != filter.ifindex)
-		return 0;
-
-	if (filter.sci && sci != filter.sci)
-		return 0;
-
-	open_json_object(NULL);
-	print_uint(PRINT_ANY, "ifindex", "%u: ", ifindex);
-	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname",
-			   "%s: ", ll_index_to_name(ifindex));
-
-	print_attrs(attrs_secy);
-
-	print_tx_sc("    ", sci, encoding_sa,
-		    attrs[MACSEC_ATTR_TXSC_STATS],
-		    attrs[MACSEC_ATTR_SECY_STATS],
-		    attrs[MACSEC_ATTR_TXSA_LIST]);
-
-	if (attrs[MACSEC_ATTR_RXSC_LIST])
-		print_rxsc_list(attrs[MACSEC_ATTR_RXSC_LIST]);
-
-	close_json_object();
-
-	return 0;
-}
-
-static int do_dump(int ifindex)
-{
-	MACSEC_GENL_REQ(req, MACSEC_BUFLEN, MACSEC_CMD_GET_TXSC,
-			NLM_F_REQUEST | NLM_F_DUMP);
-
-	memset(&filter, 0, sizeof(filter));
-	filter.ifindex = ifindex;
-
-	req.n.nlmsg_seq = genl_rth.dump = ++genl_rth.seq;
-	if (rtnl_send(&genl_rth, &req, req.n.nlmsg_len) < 0) {
-		perror("Failed to send dump request");
-		exit(1);
-	}
-
-	new_json_obj(json);
-	if (rtnl_dump_filter(&genl_rth, process, stdout) < 0) {
-		delete_json_obj();
-		fprintf(stderr, "Dump terminated\n");
-		exit(1);
-	}
-	delete_json_obj();
-
-	return 0;
-}
-
-static int do_show(int argc, char **argv)
-{
-	int ifindex;
-
-	if (argc == 0)
-		return do_dump(0);
-
-	ifindex = ll_name_to_index(*argv);
-	if (ifindex == 0) {
-		fprintf(stderr, "Device \"%s\" does not exist.\n", *argv);
-		return -1;
-	}
-
-	argc--, argv++;
-	if (argc == 0)
-		return do_dump(ifindex);
-
-	ipmacsec_usage();
-	return -1;
-}
-
-int do_ipmacsec(int argc, char **argv)
-{
-	if (argc < 1)
-		ipmacsec_usage();
-
-	if (matches(*argv, "help") == 0)
-		ipmacsec_usage();
-
-	if (genl_init_handle(&genl_rth, MACSEC_GENL_NAME, &genl_family))
-		exit(1);
-
-	if (matches(*argv, "show") == 0)
-		return do_show(argc-1, argv+1);
-
-	if (matches(*argv, "add") == 0)
-		return do_modify(CMD_ADD, argc-1, argv+1);
-	if (matches(*argv, "set") == 0)
-		return do_modify(CMD_UPD, argc-1, argv+1);
-	if (matches(*argv, "delete") == 0)
-		return do_modify(CMD_DEL, argc-1, argv+1);
-
-	fprintf(stderr, "Command \"%s\" is unknown, try \"ip macsec help\".\n",
-		*argv);
-	exit(-1);
-}
-
-/* device creation */
-static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
-{
-	if (!tb)
-		return;
-
-	if (tb[IFLA_MACSEC_SCI]) {
-		if (is_json_context()) {
-			SPRINT_BUF(b1);
-
-			snprintf(b1, sizeof(b1), "%016llx",
-				 ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
-			print_string(PRINT_JSON, "sci", NULL, b1);
-		} else {
-			fprintf(f, "sci %016llx ",
-				ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
-		}
-	}
-
-	print_flag(tb, "protect", IFLA_MACSEC_PROTECT);
-
-	if (tb[IFLA_MACSEC_CIPHER_SUITE]) {
-		__u64 csid
-			= rta_getattr_u64(tb[IFLA_MACSEC_CIPHER_SUITE]);
-
-		print_string(PRINT_ANY,
-			     "cipher_suite",
-			     "cipher %s ",
-			     cs_id_to_name(csid));
-	}
-
-	if (tb[IFLA_MACSEC_ICV_LEN]) {
-		if (is_json_context()) {
-			char b2[4];
-
-			snprintf(b2, sizeof(b2), "%hhu",
-				 rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
-			print_uint(PRINT_JSON, "icv_len", NULL, atoi(b2));
-		} else {
-			fprintf(f, "icvlen %hhu ",
-				rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
-		}
-	}
-
-	if (tb[IFLA_MACSEC_ENCODING_SA]) {
-		if (is_json_context()) {
-			char b2[4];
-
-			snprintf(b2, sizeof(b2), "%hhu",
-				 rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
-			print_uint(PRINT_JSON, "encoding_sa", NULL, atoi(b2));
-		} else {
-			fprintf(f, "encodingsa %hhu ",
-				rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
-		}
-	}
-
-	if (tb[IFLA_MACSEC_VALIDATION]) {
-		__u8 val = rta_getattr_u8(tb[IFLA_MACSEC_VALIDATION]);
-
-		print_string(PRINT_ANY,
-			     "validation",
-			     "validate %s ",
-			     validate_str[val]);
-	}
-
-	const char *inc_sci, *es, *replay;
-
-	if (is_json_context()) {
-		inc_sci = "inc_sci";
-		replay = "replay_protect";
-		es = "es";
-	} else {
-		inc_sci = "send_sci";
-		es = "end_station";
-		replay = "replay";
-	}
-
-	print_flag(tb, "encrypt", IFLA_MACSEC_ENCRYPT);
-	print_flag(tb, inc_sci, IFLA_MACSEC_INC_SCI);
-	print_flag(tb, es, IFLA_MACSEC_ES);
-	print_flag(tb, "scb", IFLA_MACSEC_SCB);
-	print_flag(tb, replay, IFLA_MACSEC_REPLAY_PROTECT);
-
-	if (tb[IFLA_MACSEC_WINDOW])
-		print_int(PRINT_ANY,
-			  "window",
-			  "window %d ",
-			  rta_getattr_u32(tb[IFLA_MACSEC_WINDOW]));
-}
-
-static bool check_txsc_flags(bool es, bool scb, bool sci)
-{
-	if (sci && (es || scb))
-		return false;
-	if (es && scb)
-		return false;
-	return true;
-}
-
-static void usage(FILE *f)
-{
-	fprintf(f,
-		"Usage: ... macsec [ [ address <lladdr> ] port { 1..2^16-1 } | sci <u64> ]\n"
-		"                  [ cipher { default | gcm-aes-128 | gcm-aes-256 } ]\n"
-		"                  [ icvlen { 8..16 } ]\n"
-		"                  [ encrypt { on | off } ]\n"
-		"                  [ send_sci { on | off } ]\n"
-		"                  [ end_station { on | off } ]\n"
-		"                  [ scb { on | off } ]\n"
-		"                  [ protect { on | off } ]\n"
-		"                  [ replay { on | off} window { 0..2^32-1 } ]\n"
-		"                  [ validate { strict | check | disabled } ]\n"
-		"                  [ encodingsa { 0..3 } ]\n"
-		);
-}
-
-static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
-			    struct nlmsghdr *n)
-{
-	int ret;
-	__u8 encoding_sa = 0xff;
-	__u32 window = -1;
-	struct cipher_args cipher = {0};
-	enum macsec_validation_type validate;
-	bool es = false, scb = false, send_sci = false;
-	int replay_protect = -1;
-	struct sci sci = { 0 };
-
-	ret = get_sci_portaddr(&sci, &argc, &argv, true, true);
-	if (ret < 0) {
-		fprintf(stderr, "expected sci\n");
-		return -1;
-	}
-
-	if (ret > 0) {
-		if (sci.sci)
-			addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_SCI,
-				  &sci.sci, sizeof(sci.sci));
-		else
-			addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_PORT,
-				  &sci.port, sizeof(sci.port));
-	}
-
-	while (argc > 0) {
-		if (strcmp(*argv, "cipher") == 0) {
-			NEXT_ARG();
-			if (cipher.id)
-				duparg("cipher", *argv);
-			if (strcmp(*argv, "default") == 0)
-				cipher.id = MACSEC_DEFAULT_CIPHER_ID;
-			else if (strcmp(*argv, "gcm-aes-128") == 0 ||
-			         strcmp(*argv, "GCM-AES-128") == 0)
-				cipher.id = MACSEC_CIPHER_ID_GCM_AES_128;
-			else if (strcmp(*argv, "gcm-aes-256") == 0 ||
-			         strcmp(*argv, "GCM-AES-256") == 0)
-				cipher.id = MACSEC_CIPHER_ID_GCM_AES_256;
-			else
-				invarg("expected: default, gcm-aes-128 or"
-				       " gcm-aes-256", *argv);
-		} else if (strcmp(*argv, "icvlen") == 0) {
-			NEXT_ARG();
-			if (cipher.icv_len)
-				duparg("icvlen", *argv);
-			get_icvlen(&cipher.icv_len, *argv);
-		} else if (strcmp(*argv, "encrypt") == 0) {
-			NEXT_ARG();
-			int i;
-
-			ret = one_of("encrypt", *argv, values_on_off,
-				     ARRAY_SIZE(values_on_off), &i);
-			if (ret != 0)
-				return ret;
-			addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCRYPT, i);
-		} else if (strcmp(*argv, "send_sci") == 0) {
-			NEXT_ARG();
-			int i;
-
-			ret = one_of("send_sci", *argv, values_on_off,
-				     ARRAY_SIZE(values_on_off), &i);
-			if (ret != 0)
-				return ret;
-			send_sci = i;
-			addattr8(n, MACSEC_BUFLEN,
-				 IFLA_MACSEC_INC_SCI, send_sci);
-		} else if (strcmp(*argv, "end_station") == 0) {
-			NEXT_ARG();
-			int i;
-
-			ret = one_of("end_station", *argv, values_on_off,
-				     ARRAY_SIZE(values_on_off), &i);
-			if (ret != 0)
-				return ret;
-			es = i;
-			addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ES, es);
-		} else if (strcmp(*argv, "scb") == 0) {
-			NEXT_ARG();
-			int i;
-
-			ret = one_of("scb", *argv, values_on_off,
-				     ARRAY_SIZE(values_on_off), &i);
-			if (ret != 0)
-				return ret;
-			scb = i;
-			addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb);
-		} else if (strcmp(*argv, "protect") == 0) {
-			NEXT_ARG();
-			int i;
-
-			ret = one_of("protect", *argv, values_on_off,
-				     ARRAY_SIZE(values_on_off), &i);
-			if (ret != 0)
-				return ret;
-			addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i);
-		} else if (strcmp(*argv, "replay") == 0) {
-			NEXT_ARG();
-			int i;
-
-			ret = one_of("replay", *argv, values_on_off,
-				     ARRAY_SIZE(values_on_off), &i);
-			if (ret != 0)
-				return ret;
-			replay_protect = !!i;
-		} else if (strcmp(*argv, "window") == 0) {
-			NEXT_ARG();
-			ret = get_u32(&window, *argv, 0);
-			if (ret)
-				invarg("expected replay window size", *argv);
-		} else if (strcmp(*argv, "validate") == 0) {
-			NEXT_ARG();
-			ret = one_of("validate", *argv,
-				     validate_str, ARRAY_SIZE(validate_str),
-				     (int *)&validate);
-			if (ret != 0)
-				return ret;
-			addattr8(n, MACSEC_BUFLEN,
-				 IFLA_MACSEC_VALIDATION, validate);
-		} else if (strcmp(*argv, "encodingsa") == 0) {
-			if (encoding_sa != 0xff)
-				duparg2("encodingsa", "encodingsa");
-			NEXT_ARG();
-			ret = get_an(&encoding_sa, *argv);
-			if (ret)
-				invarg("expected an { 0..3 }", *argv);
-		} else {
-			fprintf(stderr, "macsec: unknown command \"%s\"?\n",
-				*argv);
-			usage(stderr);
-			return -1;
-		}
-
-		argv++; argc--;
-	}
-
-	if (!check_txsc_flags(es, scb, send_sci)) {
-		fprintf(stderr,
-			"invalid combination of send_sci/end_station/scb\n");
-		return -1;
-	}
-
-	if (window != -1 && replay_protect == -1) {
-		fprintf(stderr,
-			"replay window set, but replay protection not enabled. did you mean 'replay on window %u'?\n",
-			window);
-		return -1;
-	} else if (window == -1 && replay_protect == 1) {
-		fprintf(stderr,
-			"replay protection enabled, but no window set. did you mean 'replay on window VALUE'?\n");
-		return -1;
-	}
-
-	if (cipher.id)
-		addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_CIPHER_SUITE,
-			  &cipher.id, sizeof(cipher.id));
-	if (cipher.icv_len)
-		addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ICV_LEN,
-			  &cipher.icv_len, sizeof(cipher.icv_len));
-
-	if (replay_protect != -1) {
-		addattr32(n, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window);
-		addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT,
-			 replay_protect);
-	}
-
-	if (encoding_sa != 0xff) {
-		addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCODING_SA,
-			  &encoding_sa, sizeof(encoding_sa));
-	}
-
-	return 0;
-}
-
-static void macsec_print_help(struct link_util *lu, int argc, char **argv,
-			      FILE *f)
-{
-	usage(f);
-}
-
-struct link_util macsec_link_util = {
-	.id = "macsec",
-	.maxattr = IFLA_MACSEC_MAX,
-	.parse_opt = macsec_parse_opt,
-	.print_help = macsec_print_help,
-	.print_opt = macsec_print_opt,
-};
diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 3400e05..cbd6d11 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -28,7 +29,6 @@
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 static struct {
 	char *dev;
@@ -39,9 +39,8 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip maddr [ add | del ] MULTIADDR dev STRING\n"
-		"       ip maddr show [ dev STRING ]\n");
+	fprintf(stderr, "Usage: ip maddr [ add | del ] MULTIADDR dev STRING\n");
+	fprintf(stderr, "       ip maddr show [ dev STRING ]\n");
 	exit(-1);
 }
 
@@ -51,7 +50,6 @@
 
 	while (*str && (len < 2 * size)) {
 		int tmp;
-
 		if (str[1] == 0)
 			return -1;
 		if (sscanf(str, "%02x", &tmp) != 1)
@@ -63,7 +61,8 @@
 	return len;
 }
 
-struct ma_info {
+struct ma_info
+{
 	struct ma_info *next;
 	int		index;
 	int		users;
@@ -94,16 +93,19 @@
 
 	while (fgets(buf, sizeof(buf), fp)) {
 		char hexa[256];
-		struct ma_info m = { .addr.family = AF_PACKET };
+		struct ma_info m;
 		int len;
 		int st;
 
+		memset(&m, 0, sizeof(m));
 		sscanf(buf, "%d%s%d%d%s", &m.index, m.name, &m.users, &st,
 		       hexa);
 		if (filter.dev && strcmp(filter.dev, m.name))
 			continue;
 
-		len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data));
+		m.addr.family = AF_PACKET;
+
+		len = parse_hex(hexa, (unsigned char*)&m.addr.data, sizeof (m.addr.data));
 		if (len >= 0) {
 			struct ma_info *ma = malloc(sizeof(m));
 
@@ -120,38 +122,34 @@
 
 static void read_igmp(struct ma_info **result_p)
 {
-	struct ma_info m = {
-		.addr.family = AF_INET,
-		.addr.bitlen = 32,
-		.addr.bytelen = 4,
-	};
+	struct ma_info m;
 	char buf[256];
 	FILE *fp = fopen("/proc/net/igmp", "r");
 
 	if (!fp)
 		return;
+	memset(&m, 0, sizeof(m));
 	if (!fgets(buf, sizeof(buf), fp)) {
 		fclose(fp);
 		return;
 	}
 
+	m.addr.family = AF_INET;
+	m.addr.bitlen = 32;
+	m.addr.bytelen = 4;
+
 	while (fgets(buf, sizeof(buf), fp)) {
 		struct ma_info *ma;
 
 		if (buf[0] != '\t') {
-			size_t len;
-
 			sscanf(buf, "%d%s", &m.index, m.name);
-			len = strlen(m.name);
-			if (m.name[len - 1] == ':')
-				m.name[len - 1] = '\0';
 			continue;
 		}
 
 		if (filter.dev && strcmp(filter.dev, m.name))
 			continue;
 
-		sscanf(buf, "%08x%d", (__u32 *)&m.addr.data, &m.users);
+		sscanf(buf, "%08x%d", (__u32*)&m.addr.data, &m.users);
 
 		ma = malloc(sizeof(m));
 		memcpy(ma, &m, sizeof(m));
@@ -171,15 +169,18 @@
 
 	while (fgets(buf, sizeof(buf), fp)) {
 		char hexa[256];
-		struct ma_info m = { .addr.family = AF_INET6 };
+		struct ma_info m;
 		int len;
 
+		memset(&m, 0, sizeof(m));
 		sscanf(buf, "%d%s%s%d", &m.index, m.name, hexa, &m.users);
 
 		if (filter.dev && strcmp(filter.dev, m.name))
 			continue;
 
-		len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data));
+		m.addr.family = AF_INET6;
+
+		len = parse_hex(hexa, (unsigned char*)&m.addr.data, sizeof (m.addr.data));
 		if (len >= 0) {
 			struct ma_info *ma = malloc(sizeof(m));
 
@@ -195,66 +196,53 @@
 
 static void print_maddr(FILE *fp, struct ma_info *list)
 {
-	print_string(PRINT_FP, NULL, "\t", NULL);
+	fprintf(fp, "\t");
 
-	open_json_object(NULL);
 	if (list->addr.family == AF_PACKET) {
 		SPRINT_BUF(b1);
-
-		print_string(PRINT_FP, NULL, "link  ", NULL);
-		print_color_string(PRINT_ANY, COLOR_MAC, "link", "%s",
-				   ll_addr_n2a((void *)list->addr.data, list->addr.bytelen,
-					       0, b1, sizeof(b1)));
+		fprintf(fp, "link  %s", ll_addr_n2a((unsigned char*)list->addr.data,
+						    list->addr.bytelen, 0,
+						    b1, sizeof(b1)));
 	} else {
-		print_string(PRINT_ANY, "family", "%-5s ",
-			     family_name(list->addr.family));
-		print_color_string(PRINT_ANY, ifa_family_color(list->addr.family),
-				   "address", "%s",
-				   format_host(list->addr.family,
-					       -1, list->addr.data));
+		char abuf[256];
+		switch(list->addr.family) {
+		case AF_INET:
+			fprintf(fp, "inet  ");
+			break;
+		case AF_INET6:
+			fprintf(fp, "inet6 ");
+			break;
+		default:
+			fprintf(fp, "family %d ", list->addr.family);
+			break;
+		}
+		fprintf(fp, "%s",
+			format_host(list->addr.family,
+				    -1,
+				    list->addr.data,
+				    abuf, sizeof(abuf)));
 	}
-
 	if (list->users != 1)
-		print_uint(PRINT_ANY, "users", " users %u", list->users);
-
+		fprintf(fp, " users %d", list->users);
 	if (list->features)
-		print_string(PRINT_ANY, "features", " %s", list->features);
-
-	print_string(PRINT_FP, NULL, "\n", NULL);
-	close_json_object();
+		fprintf(fp, " %s", list->features);
+	fprintf(fp, "\n");
 }
 
 static void print_mlist(FILE *fp, struct ma_info *list)
 {
 	int cur_index = 0;
 
-	new_json_obj(json);
 	for (; list; list = list->next) {
-
-		if (list->index != cur_index || oneline) {
-			if (cur_index) {
-				close_json_array(PRINT_JSON, NULL);
-				close_json_object();
-			}
-			open_json_object(NULL);
-
-			print_uint(PRINT_ANY, "ifindex", "%d:", list->index);
-			print_color_string(PRINT_ANY, COLOR_IFNAME,
-					   "ifname", "\t%s", list->name);
-			print_nl();
+		if (oneline) {
 			cur_index = list->index;
-
-			open_json_array(PRINT_JSON, "maddr");
+			fprintf(fp, "%d:\t%s%s", cur_index, list->name, _SL_);
+		} else if (cur_index != list->index) {
+			cur_index = list->index;
+			fprintf(fp, "%d:\t%s\n", cur_index, list->name);
 		}
-
 		print_maddr(fp, list);
 	}
-	if (cur_index) {
-		close_json_array(PRINT_JSON, NULL);
-		close_json_object();
-	}
-
-	delete_json_obj();
 }
 
 static int multiaddr_list(int argc, char **argv)
@@ -268,7 +256,8 @@
 		if (1) {
 			if (strcmp(*argv, "dev") == 0) {
 				NEXT_ARG();
-			} else if (matches(*argv, "help") == 0)
+			}
+			else if (matches(*argv, "help") == 0)
 				usage();
 			if (filter.dev)
 				duparg2("dev", *argv);
@@ -289,10 +278,11 @@
 
 static int multiaddr_modify(int cmd, int argc, char **argv)
 {
-	struct ifreq ifr = {};
-	int family;
+	struct ifreq ifr;
 	int fd;
 
+	memset(&ifr, 0, sizeof(ifr));
+
 	if (cmd == RTM_NEWADDR)
 		cmd = SIOCADDMULTI;
 	else
@@ -303,8 +293,7 @@
 			NEXT_ARG();
 			if (ifr.ifr_name[0])
 				duparg("dev", *argv);
-			if (get_ifname(ifr.ifr_name, *argv))
-				invarg("\"dev\" not a valid ifname", *argv);
+			strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
 		} else {
 			if (matches(*argv, "address") == 0) {
 				NEXT_ARG();
@@ -326,22 +315,12 @@
 		exit(-1);
 	}
 
-	switch (preferred_family) {
-	case AF_INET6:
-	case AF_PACKET:
-	case AF_INET:
-		family = preferred_family;
-		break;
-	default:
-		family = AF_INET;
-	}
-
-	fd = socket(family, SOCK_DGRAM, 0);
+	fd = socket(AF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
 		perror("Cannot create socket");
 		exit(1);
 	}
-	if (ioctl(fd, cmd, (char *)&ifr) != 0) {
+	if (ioctl(fd, cmd, (char*)&ifr) != 0) {
 		perror("ioctl");
 		exit(1);
 	}
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 685be52..99a237f 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -24,16 +25,16 @@
 #include "ip_common.h"
 
 static void usage(void) __attribute__((noreturn));
-static int prefix_banner;
+int prefix_banner;
 int listen_all_nsid;
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] [ label ] [all-nsid] [dev DEVICE]\n"
-		"LISTofOBJECTS := link | address | route | mroute | prefix |\n"
-		"		 neigh | netconf | rule | nsid\n"
-		"FILE := file FILENAME\n");
+	fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] "
+			"[ label ] [all-nsid] [dev DEVICE]\n");
+	fprintf(stderr, "LISTofOBJECTS := link | address | route | mroute | prefix |\n");
+	fprintf(stderr, "                 neigh | netconf | rule | nsid\n");
+	fprintf(stderr, "FILE := file FILENAME\n");
 	exit(-1);
 }
 
@@ -53,14 +54,13 @@
 		fprintf(fp, "%s", label);
 }
 
-static int accept_msg(struct rtnl_ctrl_data *ctrl,
+static int accept_msg(const struct sockaddr_nl *who,
+		      struct rtnl_ctrl_data *ctrl,
 		      struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 
-	switch (n->nlmsg_type) {
-	case RTM_NEWROUTE:
-	case RTM_DELROUTE: {
+	if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) {
 		struct rtmsg *r = NLMSG_DATA(n);
 		int len = n->nlmsg_len - NLMSG_LENGTH(sizeof(*r));
 
@@ -75,43 +75,33 @@
 		if (r->rtm_family == RTNL_FAMILY_IPMR ||
 		    r->rtm_family == RTNL_FAMILY_IP6MR) {
 			print_headers(fp, "[MROUTE]", ctrl);
-			print_mroute(n, arg);
+			print_mroute(who, n, arg);
 			return 0;
 		} else {
 			print_headers(fp, "[ROUTE]", ctrl);
-			print_route(n, arg);
+			print_route(who, n, arg);
 			return 0;
 		}
 	}
 
-	case RTM_NEWNEXTHOP:
-	case RTM_DELNEXTHOP:
-		print_headers(fp, "[NEXTHOP]", ctrl);
-		print_nexthop(n, arg);
-		return 0;
-
-	case RTM_NEWLINK:
-	case RTM_DELLINK:
-		ll_remember_index(n, NULL);
+	if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) {
+		ll_remember_index(who, n, NULL);
 		print_headers(fp, "[LINK]", ctrl);
-		print_linkinfo(n, arg);
+		print_linkinfo(who, n, arg);
 		return 0;
-
-	case RTM_NEWADDR:
-	case RTM_DELADDR:
+	}
+	if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
 		print_headers(fp, "[ADDR]", ctrl);
-		print_addrinfo(n, arg);
+		print_addrinfo(who, n, arg);
 		return 0;
-
-	case RTM_NEWADDRLABEL:
-	case RTM_DELADDRLABEL:
+	}
+	if (n->nlmsg_type == RTM_NEWADDRLABEL || n->nlmsg_type == RTM_DELADDRLABEL) {
 		print_headers(fp, "[ADDRLABEL]", ctrl);
-		print_addrlabel(n, arg);
+		print_addrlabel(who, n, arg);
 		return 0;
-
-	case RTM_NEWNEIGH:
-	case RTM_DELNEIGH:
-	case RTM_GETNEIGH:
+	}
+	if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH ||
+	    n->nlmsg_type == RTM_GETNEIGH) {
 		if (preferred_family) {
 			struct ndmsg *r = NLMSG_DATA(n);
 
@@ -120,45 +110,37 @@
 		}
 
 		print_headers(fp, "[NEIGH]", ctrl);
-		print_neigh(n, arg);
+		print_neigh(who, n, arg);
 		return 0;
-
-	case RTM_NEWPREFIX:
+	}
+	if (n->nlmsg_type == RTM_NEWPREFIX) {
 		print_headers(fp, "[PREFIX]", ctrl);
-		print_prefix(n, arg);
+		print_prefix(who, n, arg);
 		return 0;
-
-	case RTM_NEWRULE:
-	case RTM_DELRULE:
+	}
+	if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) {
 		print_headers(fp, "[RULE]", ctrl);
-		print_rule(n, arg);
+		print_rule(who, n, arg);
 		return 0;
-
-	case NLMSG_TSTAMP:
+	}
+	if (n->nlmsg_type == RTM_NEWNETCONF) {
+		print_headers(fp, "[NETCONF]", ctrl);
+		print_netconf(who, ctrl, n, arg);
+		return 0;
+	}
+	if (n->nlmsg_type == NLMSG_TSTAMP) {
 		print_nlmsg_timestamp(fp, n);
 		return 0;
-
-	case RTM_NEWNETCONF:
-	case RTM_DELNETCONF:
-		print_headers(fp, "[NETCONF]", ctrl);
-		print_netconf(ctrl, n, arg);
-		return 0;
-
-	case RTM_DELNSID:
-	case RTM_NEWNSID:
+	}
+	if (n->nlmsg_type == RTM_NEWNSID || n->nlmsg_type == RTM_DELNSID) {
 		print_headers(fp, "[NSID]", ctrl);
-		print_nsid(n, arg);
+		print_nsid(who, n, arg);
 		return 0;
-
-	case NLMSG_ERROR:
-	case NLMSG_NOOP:
-	case NLMSG_DONE:
-		break;	/* ignore */
-
-	default:
-		fprintf(stderr,
-			"Unknown message: type=0x%08x(%d) flags=0x%08x(%d) len=0x%08x(%d)\n",
-			n->nlmsg_type, n->nlmsg_type,
+	}
+	if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
+	    n->nlmsg_type != NLMSG_DONE) {
+		fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)"
+			"len=0x%08x(%d)\n", n->nlmsg_type, n->nlmsg_type,
 			n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
 			n->nlmsg_len);
 	}
@@ -167,19 +149,18 @@
 
 int do_ipmonitor(int argc, char **argv)
 {
-	int lnexthop = 0, nh_set = 1;
 	char *file = NULL;
-	unsigned int groups = 0;
-	int llink = 0;
-	int laddr = 0;
-	int lroute = 0;
-	int lmroute = 0;
-	int lprefix = 0;
-	int lneigh = 0;
-	int lnetconf = 0;
-	int lrule = 0;
-	int lnsid = 0;
-	int ifindex = 0;
+	unsigned groups = 0;
+	int llink=0;
+	int laddr=0;
+	int lroute=0;
+	int lmroute=0;
+	int lprefix=0;
+	int lneigh=0;
+	int lnetconf=0;
+	int lrule=0;
+	int lnsid=0;
+	int ifindex=0;
 
 	groups |= nl_mgrp(RTNLGRP_LINK);
 	groups |= nl_mgrp(RTNLGRP_IPV4_IFADDR);
@@ -196,7 +177,6 @@
 	groups |= nl_mgrp(RTNLGRP_IPV4_RULE);
 	groups |= nl_mgrp(RTNLGRP_IPV6_RULE);
 	groups |= nl_mgrp(RTNLGRP_NSID);
-	groups |= nl_mgrp(RTNLGRP_MPLS_NETCONF);
 
 	rtnl_close(&rth);
 
@@ -206,49 +186,37 @@
 			file = *argv;
 		} else if (matches(*argv, "label") == 0) {
 			prefix_banner = 1;
+		} else if (matches(*argv, "all-nsid") == 0) {
+			listen_all_nsid = 1;
 		} else if (matches(*argv, "link") == 0) {
-			llink = 1;
+			llink=1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "address") == 0) {
-			laddr = 1;
+			laddr=1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "route") == 0) {
-			lroute = 1;
+			lroute=1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "mroute") == 0) {
-			lmroute = 1;
+			lmroute=1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "prefix") == 0) {
-			lprefix = 1;
+			lprefix=1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "neigh") == 0) {
 			lneigh = 1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "netconf") == 0) {
 			lnetconf = 1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "rule") == 0) {
 			lrule = 1;
 			groups = 0;
-			nh_set = 0;
 		} else if (matches(*argv, "nsid") == 0) {
 			lnsid = 1;
 			groups = 0;
-			nh_set = 0;
-		} else if (matches(*argv, "nexthop") == 0) {
-			lnexthop = 1;
-			groups = 0;
 		} else if (strcmp(*argv, "all") == 0) {
-			prefix_banner = 1;
-		} else if (matches(*argv, "all-nsid") == 0) {
-			listen_all_nsid = 1;
+			prefix_banner=1;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else if (strcmp(*argv, "dev") == 0) {
@@ -304,8 +272,6 @@
 			groups |= nl_mgrp(RTNLGRP_IPV4_NETCONF);
 		if (!preferred_family || preferred_family == AF_INET6)
 			groups |= nl_mgrp(RTNLGRP_IPV6_NETCONF);
-		if (!preferred_family || preferred_family == AF_MPLS)
-			groups |= nl_mgrp(RTNLGRP_MPLS_NETCONF);
 	}
 	if (lrule) {
 		if (!preferred_family || preferred_family == AF_INET)
@@ -316,9 +282,6 @@
 	if (lnsid) {
 		groups |= nl_mgrp(RTNLGRP_NSID);
 	}
-	if (nh_set)
-		lnexthop = 1;
-
 	if (file) {
 		FILE *fp;
 		int err;
@@ -335,17 +298,10 @@
 
 	if (rtnl_open(&rth, groups) < 0)
 		exit(1);
-
-	if (lnexthop && rtnl_add_nl_group(&rth, RTNLGRP_NEXTHOP) < 0) {
-		fprintf(stderr, "Failed to add nexthop group to list\n");
-		exit(1);
-	}
-
 	if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
 		exit(1);
 
 	ll_init_map(&rth);
-	netns_nsid_socket_init();
 	netns_map_init();
 
 	if (rtnl_listen(&rth, accept_msg, stdout) < 0)
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index 656ea0d..fffa9e2 100644
--- a/ip/ipmroute.c
+++ b/ip/ipmroute.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <inttypes.h>
 #include <sys/ioctl.h>
@@ -29,24 +30,22 @@
 #include <rt_names.h>
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip mroute show [ [ to ] PREFIX ] [ from PREFIX ] [ iif DEVICE ]\n"
-	"			[ table TABLE_ID ]\n"
-	"TABLE_ID := [ local | main | default | all | NUMBER ]\n"
+	fprintf(stderr, "Usage: ip mroute show [ [ to ] PREFIX ] [ from PREFIX ] [ iif DEVICE ]\n");
+	fprintf(stderr, "                      [ table TABLE_ID ]\n");
+	fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
 #if 0
-	"Usage: ip mroute [ add | del ] DESTINATION from SOURCE [ iif DEVICE ] [ oif DEVICE ]\n"
+	fprintf(stderr, "Usage: ip mroute [ add | del ] DESTINATION from SOURCE [ iif DEVICE ] [ oif DEVICE ]\n");
 #endif
-	);
 	exit(-1);
 }
 
-static struct rtfilter {
+struct rtfilter
+{
 	int tb;
 	int af;
 	int iif;
@@ -54,15 +53,15 @@
 	inet_prefix msrc;
 } filter;
 
-int print_mroute(struct nlmsghdr *n, void *arg)
+int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
+	FILE *fp = (FILE*)arg;
 	struct rtmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[RTA_MAX+1];
-	FILE *fp = arg;
-	const char *src, *dst;
+	struct rtattr * tb[RTA_MAX+1];
+	char abuf[256];
+	char obuf[256];
 	SPRINT_BUF(b1);
-	SPRINT_BUF(b2);
 	__u32 table;
 	int iif = 0;
 	int family;
@@ -78,11 +77,10 @@
 		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
 		return -1;
 	}
-
 	if (r->rtm_type != RTN_MULTICAST) {
-		fprintf(stderr,
-			"Non multicast route received, kernel does support IP multicast?\n");
-		return -1;
+		fprintf(stderr, "Not a multicast route (type: %s)\n",
+			rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
+		return 0;
 	}
 
 	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
@@ -92,59 +90,65 @@
 		return 0;
 
 	if (tb[RTA_IIF])
-		iif = rta_getattr_u32(tb[RTA_IIF]);
+		iif = *(int*)RTA_DATA(tb[RTA_IIF]);
 	if (filter.iif && filter.iif != iif)
 		return 0;
 
 	if (filter.af && filter.af != r->rtm_family)
 		return 0;
 
-	if (inet_addr_match_rta(&filter.mdst, tb[RTA_DST]))
-		return 0;
+	if (tb[RTA_DST] && filter.mdst.bitlen > 0) {
+		inet_prefix dst;
 
-	if (inet_addr_match_rta(&filter.msrc, tb[RTA_SRC]))
-		return 0;
-
-	family = get_real_family(r->rtm_type, r->rtm_family);
-
-	open_json_object(NULL);
-	if (n->nlmsg_type == RTM_DELROUTE)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
-
-	if (tb[RTA_SRC])
-		src = rt_addr_n2a_r(family, RTA_PAYLOAD(tb[RTA_SRC]),
-				    RTA_DATA(tb[RTA_SRC]), b1, sizeof(b1));
-	else
-		src = "unknown";
-
-	if (tb[RTA_DST])
-		dst = rt_addr_n2a_r(family, RTA_PAYLOAD(tb[RTA_DST]),
-				    RTA_DATA(tb[RTA_DST]), b2, sizeof(b2));
-	else
-		dst = "unknown";
-
-	if (is_json_context()) {
-		print_string(PRINT_JSON, "src", NULL, src);
-		print_string(PRINT_JSON, "dst", NULL, dst);
-	} else {
-		char obuf[256];
-
-		snprintf(obuf, sizeof(obuf), "(%s,%s)", src, dst);
-		print_string(PRINT_FP, NULL,
-			     "%-32s Iif: ", obuf);
+		memset(&dst, 0, sizeof(dst));
+		dst.family = r->rtm_family;
+		memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), RTA_PAYLOAD(tb[RTA_DST]));
+		if (inet_addr_match(&dst, &filter.mdst, filter.mdst.bitlen))
+			return 0;
 	}
 
-	if (iif)
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "iif", "%-10s ", ll_index_to_name(iif));
+	if (tb[RTA_SRC] && filter.msrc.bitlen > 0) {
+		inet_prefix src;
+
+		memset(&src, 0, sizeof(src));
+		src.family = r->rtm_family;
+		memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), RTA_PAYLOAD(tb[RTA_SRC]));
+		if (inet_addr_match(&src, &filter.msrc, filter.msrc.bitlen))
+			return 0;
+	}
+
+	family = r->rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+
+	if (n->nlmsg_type == RTM_DELROUTE)
+		fprintf(fp, "Deleted ");
+
+	if (tb[RTA_SRC])
+		len = snprintf(obuf, sizeof(obuf),
+			       "(%s, ", rt_addr_n2a(family,
+						    RTA_PAYLOAD(tb[RTA_SRC]),
+						    RTA_DATA(tb[RTA_SRC]),
+						    abuf, sizeof(abuf)));
 	else
-		print_string(PRINT_ANY,"iif", "%s ", "unresolved");
+		len = sprintf(obuf, "(unknown, ");
+	if (tb[RTA_DST])
+		snprintf(obuf + len, sizeof(obuf) - len,
+			 "%s)", rt_addr_n2a(family,
+					    RTA_PAYLOAD(tb[RTA_DST]),
+					    RTA_DATA(tb[RTA_DST]),
+					    abuf, sizeof(abuf)));
+	else
+		snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
+
+	fprintf(fp, "%-32s Iif: ", obuf);
+	if (iif)
+		fprintf(fp, "%-10s ", ll_index_to_name(iif));
+	else
+		fprintf(fp, "unresolved ");
 
 	if (tb[RTA_MULTIPATH]) {
 		struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]);
 		int first = 1;
 
-		open_json_array(PRINT_JSON, "multipath");
 		len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
 
 		for (;;) {
@@ -153,65 +157,30 @@
 			if (nh->rtnh_len > len)
 				break;
 
-			open_json_object(NULL);
 			if (first) {
-				print_string(PRINT_FP, NULL, "Oifs: ", NULL);
+				fprintf(fp, "Oifs: ");
 				first = 0;
 			}
-
-			print_color_string(PRINT_ANY, COLOR_IFNAME,
-					   "oif", "%s", ll_index_to_name(nh->rtnh_ifindex));
-
+			fprintf(fp, "%s", ll_index_to_name(nh->rtnh_ifindex));
 			if (nh->rtnh_hops > 1)
-				print_uint(PRINT_ANY,
-					   "ttl", "(ttl %u) ", nh->rtnh_hops);
+				fprintf(fp, "(ttl %d) ", nh->rtnh_hops);
 			else
-				print_string(PRINT_FP, NULL, " ", NULL);
-
-			close_json_object();
+				fprintf(fp, " ");
 			len -= NLMSG_ALIGN(nh->rtnh_len);
 			nh = RTNH_NEXT(nh);
 		}
-		close_json_array(PRINT_JSON, NULL);
 	}
-
-	print_string(PRINT_ANY, "state", " State: %s",
-		     (r->rtm_flags & RTNH_F_UNRESOLVED) ? "unresolved" : "resolved");
-
-	if (r->rtm_flags & RTNH_F_OFFLOAD)
-		print_null(PRINT_ANY, "offload", " offload", NULL);
-
 	if (show_stats && tb[RTA_MFC_STATS]) {
 		struct rta_mfc_stats *mfcs = RTA_DATA(tb[RTA_MFC_STATS]);
 
-		print_nl();
-		print_u64(PRINT_ANY, "packets", "  %"PRIu64" packets,",
-			   mfcs->mfcs_packets);
-		print_u64(PRINT_ANY, "bytes", " %"PRIu64" bytes", mfcs->mfcs_bytes);
-
+		fprintf(fp, "%s  %"PRIu64" packets, %"PRIu64" bytes", _SL_,
+			(uint64_t)mfcs->mfcs_packets,
+			(uint64_t)mfcs->mfcs_bytes);
 		if (mfcs->mfcs_wrong_if)
-			print_u64(PRINT_ANY, "wrong_if",
-				   ", %"PRIu64" arrived on wrong iif.",
-				   mfcs->mfcs_wrong_if);
+			fprintf(fp, ", %"PRIu64" arrived on wrong iif.",
+				(uint64_t)mfcs->mfcs_wrong_if);
 	}
-
-	if (show_stats && tb[RTA_EXPIRES]) {
-		struct timeval tv;
-		double age;
-
-		__jiffies_to_tv(&tv, rta_getattr_u64(tb[RTA_EXPIRES]));
-		age = tv.tv_sec;
-		age += tv.tv_usec / 1000000.;
-		print_float(PRINT_ANY, "expires",
-			    ", Age %.2f", age);
-	}
-
-	if (table && (table != RT_TABLE_MAIN || show_details > 0) && !filter.tb)
-		print_string(PRINT_ANY, "table", " Table: %s",
-			     rtnl_rttable_n2a(table, b1, sizeof(b1)));
-
-	print_string(PRINT_FP, NULL, "\n", NULL);
-	close_json_object();
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
@@ -224,43 +193,25 @@
 	filter.iif = ifindex;
 }
 
-static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	int err;
-
-	if (filter.tb) {
-		err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
 static int mroute_list(int argc, char **argv)
 {
 	char *id = NULL;
-	int family = preferred_family;
+	int family;
 
 	ipmroute_reset_filter(0);
-	if (family == AF_INET || family == AF_UNSPEC) {
-		family = RTNL_FAMILY_IPMR;
+	if (preferred_family == AF_UNSPEC)
+		family = AF_INET;
+	else
+		family = AF_INET6;
+	if (family == AF_INET) {
 		filter.af = RTNL_FAMILY_IPMR;
 		filter.tb = RT_TABLE_DEFAULT;  /* for backward compatibility */
-	} else if (family == AF_INET6) {
-		family = RTNL_FAMILY_IP6MR;
+	} else
 		filter.af = RTNL_FAMILY_IP6MR;
-	} else {
-		/* family does not have multicast routing */
-		return 0;
-	}
-
-	filter.msrc.family = filter.mdst.family = family;
 
 	while (argc > 0) {
 		if (matches(*argv, "table") == 0) {
 			__u32 tid;
-
 			NEXT_ARG();
 			if (rtnl_rttable_a2n(&tid, *argv)) {
 				if (strcmp(*argv, "all") == 0) {
@@ -277,16 +228,14 @@
 			id = *argv;
 		} else if (matches(*argv, "from") == 0) {
 			NEXT_ARG();
-			if (get_prefix(&filter.msrc, *argv, family))
-				invarg("from value is invalid\n", *argv);
+			get_prefix(&filter.msrc, *argv, family);
 		} else {
 			if (strcmp(*argv, "to") == 0) {
 				NEXT_ARG();
 			}
 			if (matches(*argv, "help") == 0)
 				usage();
-			if (get_prefix(&filter.mdst, *argv, family))
-				invarg("to value is invalid\n", *argv);
+			get_prefix(&filter.mdst, *argv, family);
 		}
 		argc--; argv++;
 	}
@@ -296,26 +245,24 @@
 	if (id)  {
 		int idx;
 
-		idx = ll_name_to_index(id);
-		if (!idx)
-			return nodev(id);
+		if ((idx = ll_name_to_index(id)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", id);
+			return -1;
+		}
 		filter.iif = idx;
 	}
 
-	if (rtnl_routedump_req(&rth, filter.af, iproute_dump_filter) < 0) {
+	if (rtnl_wilddump_request(&rth, filter.af, RTM_GETROUTE) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_mroute, stdout) < 0) {
-		delete_json_obj();
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
 
-	return 0;
+	exit(0);
 }
 
 int do_multiroute(int argc, char **argv)
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index a3869c8..92b7cd6 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/time.h>
@@ -23,7 +24,6 @@
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 #define NUD_VALID	(NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
 #define MAX_ROUNDS	10
@@ -31,7 +31,7 @@
 static struct
 {
 	int family;
-	int index;
+        int index;
 	int state;
 	int unused_only;
 	inet_prefix pfx;
@@ -40,28 +40,20 @@
 	int flushp;
 	int flushe;
 	int master;
-	int protocol;
-	__u8 ndm_flags;
 } filter;
 
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip neigh { add | del | change | replace }\n"
-		"		{ ADDR [ lladdr LLADDR ] [ nud STATE ] | proxy ADDR } [ dev DEV ]\n"
-		"		[ router ] [ extern_learn ] [ protocol PROTO ]\n"
-		"\n"
-		"	ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n"
-		"				  [ vrf NAME ]\n"
-		"\n"
-		"STATE := { permanent | noarp | stale | reachable | none |\n"
-		"           incomplete | delay | probe | failed }\n");
+	fprintf(stderr, "Usage: ip neigh { add | del | change | replace } { ADDR [ lladdr LLADDR ]\n"
+		        "          [ nud { permanent | noarp | stale | reachable } ]\n"
+		        "          | proxy ADDR } [ dev DEV ]\n");
+	fprintf(stderr, "       ip neigh {show|flush} [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n");
 	exit(-1);
 }
 
-static int nud_state_a2n(unsigned int *state, const char *arg)
+static int nud_state_a2n(unsigned *state, const char *arg)
 {
 	if (matches(arg, "permanent") == 0)
 		*state = NUD_PERMANENT;
@@ -84,7 +76,7 @@
 	else {
 		if (get_unsigned(state, arg, 0))
 			return -1;
-		if (*state >= 0x100 || (*state&((*state)-1)))
+		if (*state>=0x100 || (*state&((*state)-1)))
 			return -1;
 	}
 	return 0;
@@ -106,21 +98,23 @@
 	struct {
 		struct nlmsghdr	n;
 		struct ndmsg		ndm;
-		char			buf[256];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.ndm.ndm_family = preferred_family,
-		.ndm.ndm_state = NUD_PERMANENT,
-	};
+		char  			buf[256];
+	} req;
 	char  *dev = NULL;
 	int dst_ok = 0;
 	int dev_ok = 0;
 	int lladdr_ok = 0;
-	char *lla = NULL;
+	char * lla = NULL;
 	inet_prefix dst;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.ndm.ndm_family = preferred_family;
+	req.ndm.ndm_state = NUD_PERMANENT;
+
 	while (argc > 0) {
 		if (matches(*argv, "lladdr") == 0) {
 			NEXT_ARG();
@@ -129,8 +123,7 @@
 			lla = *argv;
 			lladdr_ok = 1;
 		} else if (strcmp(*argv, "nud") == 0) {
-			unsigned int state;
-
+			unsigned state;
 			NEXT_ARG();
 			if (nud_state_a2n(&state, *argv))
 				invarg("nud state is bad", *argv);
@@ -145,22 +138,10 @@
 			dst_ok = 1;
 			dev_ok = 1;
 			req.ndm.ndm_flags |= NTF_PROXY;
-		} else if (strcmp(*argv, "router") == 0) {
-			req.ndm.ndm_flags |= NTF_ROUTER;
-		} else if (matches(*argv, "extern_learn") == 0) {
-			req.ndm.ndm_flags |= NTF_EXT_LEARNED;
 		} else if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			dev = *argv;
 			dev_ok = 1;
-		} else if (matches(*argv, "protocol") == 0) {
-			__u32 proto;
-
-			NEXT_ARG();
-			if (rtnl_rtprot_a2n(&proto, *argv))
-				invarg("\"protocol\" value is invalid\n", *argv);
-			if (addattr8(&req.n, sizeof(req), NDA_PROTOCOL, proto))
-				return -1;
 		} else {
 			if (strcmp(*argv, "to") == 0) {
 				NEXT_ARG();
@@ -197,67 +178,26 @@
 
 	ll_init_map(&rth);
 
-	if (dev) {
-		req.ndm.ndm_ifindex = ll_name_to_index(dev);
-		if (!req.ndm.ndm_ifindex)
-			return nodev(dev);
+	if (dev && (req.ndm.ndm_ifindex = ll_name_to_index(dev)) == 0) {
+		fprintf(stderr, "Cannot find device \"%s\"\n", dev);
+		return -1;
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	return 0;
 }
 
-static void print_cacheinfo(const struct nda_cacheinfo *ci)
+
+int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
-	static int hz;
-
-	if (!hz)
-		hz = get_user_hz();
-
-	if (ci->ndm_refcnt)
-		print_uint(PRINT_ANY, "refcnt",
-				" ref %u", ci->ndm_refcnt);
-
-	print_uint(PRINT_ANY, "used", " used %u", ci->ndm_used / hz);
-	print_uint(PRINT_ANY, "confirmed", "/%u", ci->ndm_confirmed / hz);
-	print_uint(PRINT_ANY, "updated", "/%u", ci->ndm_updated / hz);
-}
-
-static void print_neigh_state(unsigned int nud)
-{
-
-	open_json_array(PRINT_JSON,
-			is_json_context() ?  "state" : "");
-
-#define PRINT_FLAG(f)						\
-	if (nud & NUD_##f) {					\
-		nud &= ~NUD_##f;				\
-		print_string(PRINT_ANY, NULL, " %s", #f);	\
-	}
-
-	PRINT_FLAG(INCOMPLETE);
-	PRINT_FLAG(REACHABLE);
-	PRINT_FLAG(STALE);
-	PRINT_FLAG(DELAY);
-	PRINT_FLAG(PROBE);
-	PRINT_FLAG(FAILED);
-	PRINT_FLAG(NOARP);
-	PRINT_FLAG(PERMANENT);
-#undef PRINT_FLAG
-
-	close_json_array(PRINT_JSON, NULL);
-}
-
-int print_neigh(struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct ndmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[NDA_MAX+1];
+	struct rtattr * tb[NDA_MAX+1];
+	char abuf[256];
 	static int logit = 1;
-	__u8 protocol = 0;
 
 	if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH &&
 	    n->nlmsg_type != RTM_GETNEIGH) {
@@ -281,9 +221,8 @@
 		return 0;
 	if (!(filter.state&r->ndm_state) &&
 	    !(r->ndm_flags & NTF_PROXY) &&
-	    !(r->ndm_flags & NTF_EXT_LEARNED) &&
 	    (r->ndm_state || !(filter.state&0x100)) &&
-	    (r->ndm_family != AF_DECnet))
+             (r->ndm_family != AF_DECnet))
 		return 0;
 
 	if (filter.master && !(n->nlmsg_flags & NLM_F_DUMP_FILTERED)) {
@@ -296,123 +235,99 @@
 
 	parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
-	if (inet_addr_match_rta(&filter.pfx, tb[NDA_DST]))
-		return 0;
-
-	if (tb[NDA_PROTOCOL])
-		protocol = rta_getattr_u8(tb[NDA_PROTOCOL]);
-
-	if (filter.protocol && filter.protocol != protocol)
-		return 0;
-
+	if (tb[NDA_DST]) {
+		if (filter.pfx.family) {
+			inet_prefix dst;
+			memset(&dst, 0, sizeof(dst));
+			dst.family = r->ndm_family;
+			memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]));
+			if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
+				return 0;
+		}
+	}
 	if (filter.unused_only && tb[NDA_CACHEINFO]) {
 		struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
-
 		if (ci->ndm_refcnt)
 			return 0;
 	}
 
 	if (filter.flushb) {
 		struct nlmsghdr *fn;
-
 		if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
 			if (flush_update())
 				return -1;
 		}
-		fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
+		fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp));
 		memcpy(fn, n, n->nlmsg_len);
 		fn->nlmsg_type = RTM_DELNEIGH;
 		fn->nlmsg_flags = NLM_F_REQUEST;
 		fn->nlmsg_seq = ++rth.seq;
-		filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
+		filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
 		filter.flushed++;
 		if (show_stats < 2)
 			return 0;
 	}
 
-	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELNEIGH)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 	else if (n->nlmsg_type == RTM_GETNEIGH)
-		print_null(PRINT_ANY, "miss", "%s ", "miss");
-
+		fprintf(fp, "miss ");
 	if (tb[NDA_DST]) {
-		const char *dst;
-		int family = r->ndm_family;
-
-		if (family == AF_BRIDGE) {
-			if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
-				family = AF_INET6;
-			else
-				family = AF_INET;
-		}
-
-		dst = format_host_rta(family, tb[NDA_DST]);
-		print_color_string(PRINT_ANY,
-				   ifa_family_color(family),
-				   "dst", "%s ", dst);
+		fprintf(fp, "%s ",
+			format_host(r->ndm_family,
+				    RTA_PAYLOAD(tb[NDA_DST]),
+				    RTA_DATA(tb[NDA_DST]),
+				    abuf, sizeof(abuf)));
 	}
-
-	if (!filter.index && r->ndm_ifindex) {
-		if (!is_json_context())
-			fprintf(fp, "dev ");
-
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "dev", "%s ",
-				   ll_index_to_name(r->ndm_ifindex));
-	}
-
+	if (!filter.index && r->ndm_ifindex)
+		fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
 	if (tb[NDA_LLADDR]) {
-		const char *lladdr;
 		SPRINT_BUF(b1);
+		fprintf(fp, "lladdr %s", ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
+					      RTA_PAYLOAD(tb[NDA_LLADDR]),
+					      ll_index_to_type(r->ndm_ifindex),
+					      b1, sizeof(b1)));
+	}
+	if (r->ndm_flags & NTF_ROUTER) {
+		fprintf(fp, " router");
+	}
+	if (r->ndm_flags & NTF_PROXY) {
+		fprintf(fp, " proxy");
+	}
+	if (tb[NDA_CACHEINFO] && show_stats) {
+		struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
+		int hz = get_user_hz();
 
-		lladdr = ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
-				     RTA_PAYLOAD(tb[NDA_LLADDR]),
-				     ll_index_to_type(r->ndm_ifindex),
-				     b1, sizeof(b1));
-
-		if (!is_json_context())
-			fprintf(fp, "lladdr ");
-
-		print_color_string(PRINT_ANY, COLOR_MAC,
-				   "lladdr", "%s", lladdr);
+		if (ci->ndm_refcnt)
+			printf(" ref %d", ci->ndm_refcnt);
+		fprintf(fp, " used %d/%d/%d", ci->ndm_used/hz,
+		       ci->ndm_confirmed/hz, ci->ndm_updated/hz);
 	}
 
-	if (r->ndm_flags & NTF_ROUTER)
-		print_null(PRINT_ANY, "router", " %s", "router");
-
-	if (r->ndm_flags & NTF_PROXY)
-		print_null(PRINT_ANY, "proxy", " %s", "proxy");
-
-	if (r->ndm_flags & NTF_EXT_LEARNED)
-		print_null(PRINT_ANY, "extern_learn", " %s ", "extern_learn");
-
-	if (r->ndm_flags & NTF_OFFLOADED)
-		print_null(PRINT_ANY, "offload", " %s", "offload");
-
-	if (show_stats) {
-		if (tb[NDA_CACHEINFO])
-			print_cacheinfo(RTA_DATA(tb[NDA_CACHEINFO]));
-
-		if (tb[NDA_PROBES])
-			print_uint(PRINT_ANY, "probes", " probes %u",
-				   rta_getattr_u32(tb[NDA_PROBES]));
+	if (tb[NDA_PROBES] && show_stats) {
+		__u32 p = rta_getattr_u32(tb[NDA_PROBES]);
+		fprintf(fp, " probes %u", p);
 	}
 
-	if (r->ndm_state)
-		print_neigh_state(r->ndm_state);
+	if (r->ndm_state) {
+		int nud = r->ndm_state;
+		fprintf(fp, " ");
 
-	if (protocol) {
-		SPRINT_BUF(b1);
-
-		print_string(PRINT_ANY, "protocol", " proto %s ",
-			     rtnl_rtprot_n2a(protocol, b1, sizeof(b1)));
+#define PRINT_FLAG(f) if (nud & NUD_##f) { \
+	nud &= ~NUD_##f; fprintf(fp, #f "%s", nud ? "," : ""); }
+		PRINT_FLAG(INCOMPLETE);
+		PRINT_FLAG(REACHABLE);
+		PRINT_FLAG(STALE);
+		PRINT_FLAG(DELAY);
+		PRINT_FLAG(PROBE);
+		PRINT_FLAG(FAILED);
+		PRINT_FLAG(NOARP);
+		PRINT_FLAG(PERMANENT);
+#undef PRINT_FLAG
 	}
+	fprintf(fp, "\n");
 
-	print_string(PRINT_FP, NULL, "\n", "");
-	close_json_object();
-	fflush(stdout);
-
+	fflush(fp);
 	return 0;
 }
 
@@ -423,32 +338,21 @@
 	filter.index = ifindex;
 }
 
-static int ipneigh_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	struct ndmsg *ndm = NLMSG_DATA(nlh);
-	int err;
-
-	ndm->ndm_flags = filter.ndm_flags;
-
-	if (filter.index) {
-		err = addattr32(nlh, reqlen, NDA_IFINDEX, filter.index);
-		if (err)
-			return err;
-	}
-	if (filter.master) {
-		err = addattr32(nlh, reqlen, NDA_MASTER, filter.master);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
 static int do_show_or_flush(int argc, char **argv, int flush)
 {
+	struct {
+		struct nlmsghdr	n;
+		struct ndmsg		ndm;
+		char  			buf[256];
+	} req;
 	char *filter_dev = NULL;
 	int state_given = 0;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_type = RTM_GETNEIGH;
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
+
 	ipneigh_reset_filter(0);
 
 	if (!filter.family)
@@ -471,27 +375,16 @@
 			filter_dev = *argv;
 		} else if (strcmp(*argv, "master") == 0) {
 			int ifindex;
-
 			NEXT_ARG();
 			ifindex = ll_name_to_index(*argv);
 			if (!ifindex)
 				invarg("Device does not exist\n", *argv);
-			filter.master = ifindex;
-		} else if (strcmp(*argv, "vrf") == 0) {
-			int ifindex;
-
-			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
-			if (!ifindex)
-				invarg("Not a valid VRF name\n", *argv);
-			if (!name_is_vrf(*argv))
-				invarg("Not a valid VRF name\n", *argv);
+			addattr32(&req.n, sizeof(req), NDA_MASTER, ifindex);
 			filter.master = ifindex;
 		} else if (strcmp(*argv, "unused") == 0) {
 			filter.unused_only = 1;
 		} else if (strcmp(*argv, "nud") == 0) {
-			unsigned int state;
-
+			unsigned state;
 			NEXT_ARG();
 			if (!state_given) {
 				state_given = 1;
@@ -507,26 +400,15 @@
 			if (state == 0)
 				state = 0x100;
 			filter.state |= state;
-		} else if (strcmp(*argv, "proxy") == 0) {
-			filter.ndm_flags = NTF_PROXY;
-		} else if (matches(*argv, "protocol") == 0) {
-			__u32 prot;
-
-			NEXT_ARG();
-			if (rtnl_rtprot_a2n(&prot, *argv)) {
-				if (strcmp(*argv, "all"))
-					invarg("invalid \"protocol\"\n", *argv);
-				prot = 0;
-			}
-			filter.protocol = prot;
-		} else {
+		} else if (strcmp(*argv, "proxy") == 0)
+			req.ndm.ndm_flags = NTF_PROXY;
+		else {
 			if (strcmp(*argv, "to") == 0) {
 				NEXT_ARG();
 			}
 			if (matches(*argv, "help") == 0)
 				usage();
-			if (get_prefix(&filter.pfx, *argv, filter.family))
-				invarg("to value is invalid\n", *argv);
+			get_prefix(&filter.pfx, *argv, filter.family);
 			if (filter.family == AF_UNSPEC)
 				filter.family = filter.pfx.family;
 		}
@@ -536,9 +418,11 @@
 	ll_init_map(&rth);
 
 	if (filter_dev) {
-		filter.index = ll_name_to_index(filter_dev);
-		if (!filter.index)
-			return nodev(filter_dev);
+		if ((filter.index = ll_name_to_index(filter_dev)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev);
+			return -1;
+		}
+		addattr32(&req.n, sizeof(req), NDA_IFINDEX, filter.index);
 	}
 
 	if (flush) {
@@ -548,10 +432,10 @@
 		filter.flushb = flushb;
 		filter.flushp = 0;
 		filter.flushe = sizeof(flushb);
+		filter.state &= ~NUD_FAILED;
 
 		while (round < MAX_ROUNDS) {
-			if (rtnl_neighdump_req(&rth, filter.family,
-					       ipneigh_dump_filter) < 0) {
+			if (rtnl_wilddump_request(&rth, filter.family, RTM_GETNEIGH) < 0) {
 				perror("Cannot send dump request");
 				exit(1);
 			}
@@ -565,7 +449,7 @@
 					if (round == 0)
 						printf("Nothing to flush.\n");
 					else
-						printf("*** Flush is complete after %d round%s ***\n", round, round > 1?"s":"");
+						printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
 				}
 				fflush(stdout);
 				return 0;
@@ -577,24 +461,23 @@
 				printf("\n*** Round %d, deleting %d entries ***\n", round, filter.flushed);
 				fflush(stdout);
 			}
-			filter.state &= ~NUD_FAILED;
 		}
 		printf("*** Flush not complete bailing out after %d rounds\n",
 			MAX_ROUNDS);
 		return 1;
 	}
 
-	if (rtnl_neighdump_req(&rth, filter.family, ipneigh_dump_filter) < 0) {
+	req.ndm.ndm_family = filter.family;
+
+	if (rtnl_dump_request_n(&rth, &req.n) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_neigh, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
 
 	return 0;
 }
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 0e946ca..eca6eee 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -13,26 +13,23 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <errno.h>
 
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
 
-static struct {
+static struct
+{
 	int family;
 	int ifindex;
 } filter;
 
-static const char * const rp_filter_names[] = {
-	"off", "strict", "loose"
-};
-
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
@@ -41,34 +38,20 @@
 	exit(-1);
 }
 
-static void print_onoff(FILE *fp, const char *flag, __u32 val)
-{
-	if (is_json_context())
-		print_bool(PRINT_JSON, flag, NULL, val);
-	else
-		fprintf(fp, "%s %s ", flag, val ? "on" : "off");
-}
+#define NETCONF_RTA(r)	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct netconfmsg))))
 
-static struct rtattr *netconf_rta(struct netconfmsg *ncm)
+int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
+		  struct nlmsghdr *n, void *arg)
 {
-	return (struct rtattr *)((char *)ncm
-				 + NLMSG_ALIGN(sizeof(struct netconfmsg)));
-}
-
-int print_netconf(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct netconfmsg *ncm = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	struct rtattr *tb[NETCONFA_MAX+1];
-	int ifindex = 0;
 
 	if (n->nlmsg_type == NLMSG_ERROR)
 		return -1;
-
-	if (n->nlmsg_type != RTM_NEWNETCONF &&
-	    n->nlmsg_type != RTM_DELNETCONF) {
-		fprintf(stderr, "Not a netconf message: %08x %08x %08x\n",
+	if (n->nlmsg_type != RTM_NEWNETCONF) {
+		fprintf(stderr, "Not RTM_NEWNETCONF: %08x %08x %08x\n",
 			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
 
 		return -1;
@@ -82,80 +65,69 @@
 	if (filter.family && filter.family != ncm->ncm_family)
 		return 0;
 
-	parse_rtattr(tb, NETCONFA_MAX, netconf_rta(ncm),
+	parse_rtattr(tb, NETCONFA_MAX, NETCONF_RTA(ncm),
 		     NLMSG_PAYLOAD(n, sizeof(*ncm)));
 
-	if (tb[NETCONFA_IFINDEX])
-		ifindex = rta_getattr_u32(tb[NETCONFA_IFINDEX]);
-
-	if (filter.ifindex && filter.ifindex != ifindex)
-		return 0;
-
-	open_json_object(NULL);
-	if (n->nlmsg_type == RTM_DELNETCONF)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
-
-	print_string(PRINT_ANY, "family",
-		     "%s ", family_name(ncm->ncm_family));
+	switch (ncm->ncm_family) {
+	case AF_INET:
+		fprintf(fp, "ipv4 ");
+		break;
+	case AF_INET6:
+		fprintf(fp, "ipv6 ");
+		break;
+	default:
+		fprintf(fp, "unknown ");
+		break;
+	}
 
 	if (tb[NETCONFA_IFINDEX]) {
-		const char *dev;
+		int *ifindex = (int *)RTA_DATA(tb[NETCONFA_IFINDEX]);
 
-		switch (ifindex) {
+		switch (*ifindex) {
 		case NETCONFA_IFINDEX_ALL:
-			dev = "all";
+			fprintf(fp, "all ");
 			break;
 		case NETCONFA_IFINDEX_DEFAULT:
-			dev = "default";
+			fprintf(fp, "default ");
 			break;
 		default:
-			dev = ll_index_to_name(ifindex);
+			fprintf(fp, "dev %s ", ll_index_to_name(*ifindex));
 			break;
 		}
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "interface", "%s ", dev);
 	}
 
 	if (tb[NETCONFA_FORWARDING])
-		print_onoff(fp, "forwarding",
-				rta_getattr_u32(tb[NETCONFA_FORWARDING]));
-
+		fprintf(fp, "forwarding %s ",
+			*(int *)RTA_DATA(tb[NETCONFA_FORWARDING])?"on":"off");
 	if (tb[NETCONFA_RP_FILTER]) {
-		__u32 rp_filter = rta_getattr_u32(tb[NETCONFA_RP_FILTER]);
+		int rp_filter = *(int *)RTA_DATA(tb[NETCONFA_RP_FILTER]);
 
-		if (rp_filter < ARRAY_SIZE(rp_filter_names))
-			print_string(PRINT_ANY, "rp_filter",
-				     "rp_filter %s ",
-				     rp_filter_names[rp_filter]);
+		if (rp_filter == 0)
+			fprintf(fp, "rp_filter off ");
+		else if (rp_filter == 1)
+			fprintf(fp, "rp_filter strict ");
+		else if (rp_filter == 2)
+			fprintf(fp, "rp_filter loose ");
 		else
-			print_uint(PRINT_ANY, "rp_filter",
-				   "rp_filter %u ", rp_filter);
+			fprintf(fp, "rp_filter unknown mode ");
 	}
-
 	if (tb[NETCONFA_MC_FORWARDING])
-		print_onoff(fp, "mc_forwarding",
-				rta_getattr_u32(tb[NETCONFA_MC_FORWARDING]));
+		fprintf(fp, "mc_forwarding %d ",
+			*(int *)RTA_DATA(tb[NETCONFA_MC_FORWARDING]));
 
 	if (tb[NETCONFA_PROXY_NEIGH])
-		print_onoff(fp, "proxy_neigh",
-				rta_getattr_u32(tb[NETCONFA_PROXY_NEIGH]));
+		fprintf(fp, "proxy_neigh %s ",
+			*(int *)RTA_DATA(tb[NETCONFA_PROXY_NEIGH])?"on":"off");
 
-	if (tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN])
-		print_onoff(fp, "ignore_routes_with_linkdown",
-		     rta_getattr_u32(tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN]));
-
-	if (tb[NETCONFA_INPUT])
-		print_onoff(fp, "input", rta_getattr_u32(tb[NETCONFA_INPUT]));
-
-	close_json_object();
-	print_string(PRINT_FP, NULL, "\n", NULL);
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
 
-static int print_netconf2(struct nlmsghdr *n, void *arg)
+static int print_netconf2(const struct sockaddr_nl *who,
+			  struct nlmsghdr *n, void *arg)
 {
-	return print_netconf(NULL, n, arg);
+	return print_netconf(who, NULL, n, arg);
 }
 
 void ipnetconf_reset_filter(int ifindex)
@@ -170,22 +142,19 @@
 		struct nlmsghdr		n;
 		struct netconfmsg	ncm;
 		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct netconfmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
-		.n.nlmsg_type = RTM_GETNETCONF,
-	};
+	} req;
 
 	ipnetconf_reset_filter(0);
 	filter.family = preferred_family;
+	if (filter.family == AF_UNSPEC)
+		filter.family = AF_INET;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			filter.ifindex = ll_name_to_index(*argv);
 			if (filter.ifindex <= 0) {
-				fprintf(stderr,
-					"Device \"%s\" does not exist.\n",
+				fprintf(stderr, "Device \"%s\" does not exist.\n",
 					*argv);
 				return -1;
 			}
@@ -194,11 +163,15 @@
 	}
 
 	ll_init_map(&rth);
-
-	if (filter.ifindex && filter.family != AF_UNSPEC) {
+	if (filter.ifindex) {
+		memset(&req, 0, sizeof(req));
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct netconfmsg));
+		req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
+		req.n.nlmsg_type = RTM_GETNETCONF;
 		req.ncm.ncm_family = filter.family;
-		addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,
-			  &filter.ifindex, sizeof(filter.ifindex));
+		if (filter.ifindex)
+			addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,
+				  &filter.ifindex, sizeof(filter.ifindex));
 
 		if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
 			perror("Can not send request");
@@ -206,29 +179,16 @@
 		}
 		rtnl_listen(&rth, print_netconf, stdout);
 	} else {
-		rth.flags = RTNL_HANDLE_F_SUPPRESS_NLERR;
 dump:
-		if (rtnl_netconfdump_req(&rth, filter.family) < 0) {
+		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETNETCONF) < 0) {
 			perror("Cannot send dump request");
 			exit(1);
 		}
-
-		new_json_obj(json);
 		if (rtnl_dump_filter(&rth, print_netconf2, stdout) < 0) {
-			/* kernel does not support netconf dump on AF_UNSPEC;
-			 * fall back to requesting by family
-			 */
-			if (errno == EOPNOTSUPP &&
-			    filter.family == AF_UNSPEC) {
-				filter.family = AF_INET;
-				goto dump;
-			}
-			perror("RTNETLINK answers");
 			fprintf(stderr, "Dump terminated\n");
 			exit(1);
 		}
-		delete_json_obj();
-		if (preferred_family == AF_UNSPEC && filter.family == AF_INET) {
+		if (preferred_family == AF_UNSPEC) {
 			preferred_family = AF_INET6;
 			filter.family = AF_INET6;
 			goto dump;
@@ -249,8 +209,6 @@
 	} else
 		return do_show(0, NULL);
 
-	fprintf(stderr,
-		"Command \"%s\" is unknown, try \"ip netconf help\".\n",
-		*argv);
+	fprintf(stderr, "Command \"%s\" is unknown, try \"ip netconf help\".\n", *argv);
 	exit(-1);
 }
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index fc58a04..088096f 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #define _ATFILE_SOURCE
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -19,25 +18,21 @@
 #include <linux/net_namespace.h>
 
 #include "utils.h"
-#include "list.h"
+#include "hlist.h"
 #include "ip_common.h"
 #include "namespace.h"
-#include "json_print.h"
 
 static int usage(void)
 {
-	fprintf(stderr,
-		"Usage:	ip netns list\n"
-		"	ip netns add NAME\n"
-		"	ip netns attach NAME PID\n"
-		"	ip netns set NAME NETNSID\n"
-		"	ip [-all] netns delete [NAME]\n"
-		"	ip netns identify [PID]\n"
-		"	ip netns pids NAME\n"
-		"	ip [-all] netns exec [NAME] cmd ...\n"
-		"	ip netns monitor\n"
-		"	ip netns list-id [target-nsid POSITIVE-INT] [nsid POSITIVE-INT]\n"
-		"NETNSID := auto | POSITIVE-INT\n");
+	fprintf(stderr, "Usage: ip netns list\n");
+	fprintf(stderr, "       ip netns add NAME\n");
+	fprintf(stderr, "       ip netns set NAME NETNSID\n");
+	fprintf(stderr, "       ip [-all] netns delete [NAME]\n");
+	fprintf(stderr, "       ip netns identify [PID]\n");
+	fprintf(stderr, "       ip netns pids NAME\n");
+	fprintf(stderr, "       ip [-all] netns exec [NAME] cmd ...\n");
+	fprintf(stderr, "       ip netns monitor\n");
+	fprintf(stderr, "       ip netns list-id\n");
 	exit(-1);
 }
 
@@ -45,10 +40,9 @@
 static struct rtnl_handle rtnsh = { .fd = -1 };
 
 static int have_rtnl_getnsid = -1;
-static int saved_netns = -1;
-static struct link_filter filter;
 
-static int ipnetns_accept_msg(struct rtnl_ctrl_data *ctrl,
+static int ipnetns_accept_msg(const struct sockaddr_nl *who,
+			      struct rtnl_ctrl_data *ctrl,
 			      struct nlmsghdr *n, void *arg)
 {
 	struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(n);
@@ -67,19 +61,20 @@
 		struct nlmsghdr n;
 		struct rtgenmsg g;
 		char            buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETNSID,
-		.g.rtgen_family = AF_UNSPEC,
-	};
+	} req;
 	int fd;
 
 	if (have_rtnl_getnsid < 0) {
+		memset(&req, 0, sizeof(req));
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETNSID;
+		req.g.rtgen_family = AF_UNSPEC;
+
 		fd = open("/proc/self/ns/net", O_RDONLY);
 		if (fd < 0) {
-			have_rtnl_getnsid = 0;
-			return 0;
+			perror("open(\"/proc/self/ns/net\")");
+			exit(1);
 		}
 
 		addattr32(&req.n, 1024, NETNSA_FD, fd);
@@ -95,54 +90,49 @@
 	return have_rtnl_getnsid;
 }
 
-int get_netnsid_from_name(const char *name)
+static int get_netnsid_from_name(const char *name)
 {
 	struct {
 		struct nlmsghdr n;
 		struct rtgenmsg g;
 		char            buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETNSID,
-		.g.rtgen_family = AF_UNSPEC,
-	};
-	struct nlmsghdr *answer;
+	} req, answer;
 	struct rtattr *tb[NETNSA_MAX + 1];
 	struct rtgenmsg *rthdr;
-	int len, fd, ret = -1;
+	int len, fd;
 
-	netns_nsid_socket_init();
+	memset(&req, 0, sizeof(req));
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = RTM_GETNSID;
+	req.g.rtgen_family = AF_UNSPEC;
 
 	fd = netns_get_fd(name);
 	if (fd < 0)
 		return fd;
 
 	addattr32(&req.n, 1024, NETNSA_FD, fd);
-	if (rtnl_talk(&rtnsh, &req.n, &answer) < 0) {
+	if (rtnl_talk(&rtnsh, &req.n, &answer.n, sizeof(answer)) < 0) {
 		close(fd);
 		return -2;
 	}
 	close(fd);
 
 	/* Validate message and parse attributes */
-	if (answer->nlmsg_type == NLMSG_ERROR)
-		goto out;
+	if (answer.n.nlmsg_type == NLMSG_ERROR)
+		return -1;
 
-	rthdr = NLMSG_DATA(answer);
-	len = answer->nlmsg_len - NLMSG_SPACE(sizeof(*rthdr));
+	rthdr = NLMSG_DATA(&answer.n);
+	len = answer.n.nlmsg_len - NLMSG_SPACE(sizeof(*rthdr));
 	if (len < 0)
-		goto out;
+		return -1;
 
 	parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rthdr), len);
 
-	if (tb[NETNSA_NSID]) {
-		ret = rta_getattr_u32(tb[NETNSA_NSID]);
-	}
+	if (tb[NETNSA_NSID])
+		return rta_getattr_u32(tb[NETNSA_NSID]);
 
-out:
-	free(answer);
-	return ret;
+	return -1;
 }
 
 struct nsid_cache {
@@ -174,20 +164,6 @@
 	return NULL;
 }
 
-char *get_name_from_nsid(int nsid)
-{
-	struct nsid_cache *c;
-
-	netns_nsid_socket_init();
-	netns_map_init();
-
-	c = netns_map_get_by_nsid(nsid);
-	if (c)
-		return c->name;
-
-	return NULL;
-}
-
 static int netns_map_add(int nsid, const char *name)
 {
 	struct nsid_cache *c;
@@ -196,7 +172,7 @@
 	if (netns_map_get_by_nsid(nsid) != NULL)
 		return -EEXIST;
 
-	c = malloc(sizeof(*c) + strlen(name) + 1);
+	c = malloc(sizeof(*c) + strlen(name));
 	if (c == NULL) {
 		perror("malloc");
 		return -ENOMEM;
@@ -220,18 +196,6 @@
 	free(c);
 }
 
-void netns_nsid_socket_init(void)
-{
-	if (rtnsh.fd > -1 || !ipnetns_have_nsid())
-		return;
-
-	if (rtnl_open(&rtnsh, 0) < 0) {
-		fprintf(stderr, "Cannot open rtnetlink\n");
-		exit(1);
-	}
-
-}
-
 void netns_map_init(void)
 {
 	static int initialized;
@@ -242,6 +206,11 @@
 	if (initialized || !ipnetns_have_nsid())
 		return;
 
+	if (rtnl_open(&rtnsh, 0) < 0) {
+		fprintf(stderr, "Cannot open rtnetlink\n");
+		exit(1);
+	}
+
 	dir = opendir(NETNS_RUN_DIR);
 	if (!dir)
 		return;
@@ -287,7 +256,7 @@
 	return -ENOENT;
 }
 
-int print_nsid(struct nlmsghdr *n, void *arg)
+int print_nsid(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	struct rtgenmsg *rthdr = NLMSG_DATA(n);
 	struct rtattr *tb[NETNSA_MAX+1];
@@ -295,7 +264,7 @@
 	FILE *fp = (FILE *)arg;
 	struct nsid_cache *c;
 	char name[NAME_MAX];
-	int nsid, current;
+	int nsid;
 
 	if (n->nlmsg_type != RTM_NEWNSID && n->nlmsg_type != RTM_DELNSID)
 		return 0;
@@ -313,158 +282,46 @@
 		return -1;
 	}
 
-	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELNSID)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
 	nsid = rta_getattr_u32(tb[NETNSA_NSID]);
-	if (nsid < 0)
-		print_string(PRINT_ANY, "nsid", "nsid %s ", "not-assigned");
-	else
-		print_uint(PRINT_ANY, "nsid", "nsid %u ", nsid);
+	fprintf(fp, "nsid %u ", nsid);
 
-	if (tb[NETNSA_CURRENT_NSID]) {
-		current = rta_getattr_u32(tb[NETNSA_CURRENT_NSID]);
-		if (current < 0)
-			print_string(PRINT_ANY, "current-nsid",
-				     "current-nsid %s ", "not-assigned");
-		else
-			print_uint(PRINT_ANY, "current-nsid",
-				   "current-nsid %u ", current);
-	}
-
-	c = netns_map_get_by_nsid(tb[NETNSA_CURRENT_NSID] ? current : nsid);
+	c = netns_map_get_by_nsid(nsid);
 	if (c != NULL) {
-		print_string(PRINT_ANY, "name",
-			     "(iproute2 netns name: %s)", c->name);
+		fprintf(fp, "(iproute2 netns name: %s)", c->name);
 		netns_map_del(c);
 	}
 
 	/* During 'ip monitor nsid', no chance to have new nsid in cache. */
 	if (c == NULL && n->nlmsg_type == RTM_NEWNSID)
 		if (netns_get_name(nsid, name) == 0) {
-			print_string(PRINT_ANY, "name",
-				     "(iproute2 netns name: %s)", name);
+			fprintf(fp, "(iproute2 netns name: %s)", name);
 			netns_map_add(nsid, name);
 		}
 
-	print_string(PRINT_FP, NULL, "\n", NULL);
-	close_json_object();
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
 
-static int get_netnsid_from_netnsid(int nsid)
-{
-	struct {
-		struct nlmsghdr n;
-		struct rtgenmsg g;
-		char            buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct rtgenmsg))),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETNSID,
-		.g.rtgen_family = AF_UNSPEC,
-	};
-	struct nlmsghdr *answer;
-	int err;
-
-	netns_nsid_socket_init();
-
-	err = addattr32(&req.n, sizeof(req), NETNSA_NSID, nsid);
-	if (err)
-		return err;
-
-	if (filter.target_nsid >= 0) {
-		err = addattr32(&req.n, sizeof(req), NETNSA_TARGET_NSID,
-				filter.target_nsid);
-		if (err)
-			return err;
-	}
-
-	if (rtnl_talk(&rtnsh, &req.n, &answer) < 0)
-		return -2;
-
-	/* Validate message and parse attributes */
-	if (answer->nlmsg_type == NLMSG_ERROR)
-		goto err_out;
-
-	new_json_obj(json);
-	err = print_nsid(answer, stdout);
-	delete_json_obj();
-err_out:
-	free(answer);
-	return err;
-}
-
-static int netns_filter_req(struct nlmsghdr *nlh, int reqlen)
-{
-	int err;
-
-	if (filter.target_nsid >= 0) {
-		err = addattr32(nlh, reqlen, NETNSA_TARGET_NSID,
-				filter.target_nsid);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
 static int netns_list_id(int argc, char **argv)
 {
-	int nsid = -1;
-
 	if (!ipnetns_have_nsid()) {
 		fprintf(stderr,
 			"RTM_GETNSID is not supported by the kernel.\n");
 		return -ENOTSUP;
 	}
 
-	filter.target_nsid = -1;
-	while (argc > 0) {
-		if (strcmp(*argv, "target-nsid") == 0) {
-			if (filter.target_nsid >= 0)
-				duparg("target-nsid", *argv);
-			NEXT_ARG();
-
-			if (get_integer(&filter.target_nsid, *argv, 0))
-				invarg("\"target-nsid\" value is invalid\n",
-				       *argv);
-			else if (filter.target_nsid < 0)
-				invarg("\"target-nsid\" value should be >= 0\n",
-				       argv[1]);
-		} else if (strcmp(*argv, "nsid") == 0) {
-			if (nsid >= 0)
-				duparg("nsid", *argv);
-			NEXT_ARG();
-
-			if (get_integer(&nsid, *argv, 0))
-				invarg("\"nsid\" value is invalid\n", *argv);
-			else if (nsid < 0)
-				invarg("\"nsid\" value should be >= 0\n",
-				       argv[1]);
-		} else
-			usage();
-		argc--; argv++;
-	}
-
-	if (nsid >= 0)
-		return get_netnsid_from_netnsid(nsid);
-
-	if (rtnl_nsiddump_req_filter_fn(&rth, AF_UNSPEC,
-					netns_filter_req) < 0) {
+	if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETNSID) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
-
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_nsid, stdout) < 0) {
-		delete_json_obj();
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
 	return 0;
 }
 
@@ -478,48 +335,61 @@
 	if (!dir)
 		return 0;
 
-	new_json_obj(json);
 	while ((entry = readdir(dir)) != NULL) {
 		if (strcmp(entry->d_name, ".") == 0)
 			continue;
 		if (strcmp(entry->d_name, "..") == 0)
 			continue;
-
-		open_json_object(NULL);
-		print_string(PRINT_ANY, "name",
-			     "%s", entry->d_name);
+		printf("%s", entry->d_name);
 		if (ipnetns_have_nsid()) {
 			id = get_netnsid_from_name(entry->d_name);
 			if (id >= 0)
-				print_uint(PRINT_ANY, "id",
-					   " (id: %d)", id);
+				printf(" (id: %d)", id);
 		}
-		print_string(PRINT_FP, NULL, "\n", NULL);
-		close_json_object();
+		printf("\n");
 	}
 	closedir(dir);
-	delete_json_obj();
 	return 0;
 }
 
-static int do_switch(void *arg)
+static int cmd_exec(const char *cmd, char **argv, bool do_fork)
 {
-	char *netns = arg;
+	fflush(stdout);
+	if (do_fork) {
+		int status;
+		pid_t pid;
 
-	/* we just changed namespaces. clear any vrf association
-	 * with prior namespace before exec'ing command
-	 */
-	vrf_reset();
+		pid = fork();
+		if (pid < 0) {
+			perror("fork");
+			exit(1);
+		}
 
-	return netns_switch(netns);
+		if (pid != 0) {
+			/* Parent  */
+			if (waitpid(pid, &status, 0) < 0) {
+				perror("waitpid");
+				exit(1);
+			}
+
+			if (WIFEXITED(status)) {
+				return WEXITSTATUS(status);
+			}
+
+			exit(1);
+		}
+	}
+
+	if (execvp(cmd, argv)  < 0)
+		fprintf(stderr, "exec of \"%s\" failed: %s\n",
+				cmd, strerror(errno));
+	_exit(1);
 }
 
 static int on_netns_exec(char *nsname, void *arg)
 {
 	char **argv = arg;
-
-	printf("\nnetns: %s\n", nsname);
-	cmd_exec(argv[0], argv, true, do_switch, nsname);
+	cmd_exec(argv[1], argv + 1, true);
 	return 0;
 }
 
@@ -528,6 +398,8 @@
 	/* Setup the proper environment for apps that are not netns
 	 * aware, and execute a program in that environment.
 	 */
+	const char *cmd;
+
 	if (argc < 1 && !do_all) {
 		fprintf(stderr, "No netns name specified\n");
 		return -1;
@@ -538,19 +410,22 @@
 	}
 
 	if (do_all)
-		return netns_foreach(on_netns_exec, argv);
+		return do_each_netns(on_netns_exec, --argv, 1);
+
+	if (netns_switch(argv[0]))
+		return -1;
 
 	/* ip must return the status of the child,
 	 * but do_cmd() will add a minus to this,
 	 * so let's add another one here to cancel it.
 	 */
-	return -cmd_exec(argv[1], argv + 1, !!batch_mode, do_switch, argv[0]);
+	cmd = argv[1];
+	return -cmd_exec(cmd, argv + 1, !!batch_mode);
 }
 
 static int is_pid(const char *str)
 {
 	int ch;
-
 	for (; (ch = *str); str++) {
 		if (!isdigit(ch))
 			return 0;
@@ -595,10 +470,9 @@
 			strerror(errno));
 		return -1;
 	}
-	while ((entry = readdir(dir))) {
+	while((entry = readdir(dir))) {
 		char pid_net_path[PATH_MAX];
 		struct stat st;
-
 		if (!is_pid(entry->d_name))
 			continue;
 		snprintf(pid_net_path, sizeof(pid_net_path), "/proc/%s/ns/net",
@@ -615,15 +489,28 @@
 
 }
 
-int netns_identify_pid(const char *pidstr, char *name, int len)
+static int netns_identify(int argc, char **argv)
 {
+	const char *pidstr;
 	char net_path[PATH_MAX];
 	int netns;
 	struct stat netst;
 	DIR *dir;
 	struct dirent *entry;
 
-	name[0] = '\0';
+	if (argc < 1) {
+		pidstr = "self";
+	} else if (argc > 1) {
+		fprintf(stderr, "extra arguments specified\n");
+		return -1;
+	} else {
+		pidstr = argv[0];
+		if (!is_pid(pidstr)) {
+			fprintf(stderr, "Specified string '%s' is not a pid\n",
+					pidstr);
+			return -1;
+		}
+	}
 
 	snprintf(net_path, sizeof(net_path), "/proc/%s/ns/net", pidstr);
 	netns = open(net_path, O_RDONLY);
@@ -648,7 +535,7 @@
 		return -1;
 	}
 
-	while ((entry = readdir(dir))) {
+	while((entry = readdir(dir))) {
 		char name_path[PATH_MAX];
 		struct stat st;
 
@@ -665,7 +552,7 @@
 
 		if ((st.st_dev == netst.st_dev) &&
 		    (st.st_ino == netst.st_ino)) {
-			strlcpy(name, entry->d_name, len);
+			printf("%s\n", entry->d_name);
 		}
 	}
 	closedir(dir);
@@ -673,33 +560,6 @@
 
 }
 
-static int netns_identify(int argc, char **argv)
-{
-	const char *pidstr;
-	char name[256];
-	int rc;
-
-	if (argc < 1) {
-		pidstr = "self";
-	} else if (argc > 1) {
-		fprintf(stderr, "extra arguments specified\n");
-		return -1;
-	} else {
-		pidstr = argv[0];
-		if (!is_pid(pidstr)) {
-			fprintf(stderr, "Specified string '%s' is not a pid\n",
-					pidstr);
-			return -1;
-		}
-	}
-
-	rc = netns_identify_pid(pidstr, name, sizeof(name));
-	if (!rc)
-		printf("%s\n", name);
-
-	return rc;
-}
-
 static int on_netns_del(char *nsname, void *arg)
 {
 	char netns_path[PATH_MAX];
@@ -741,67 +601,24 @@
 	return 0;
 }
 
-/* Obtain a FD for the current namespace, so we can reenter it later */
-static void netns_save(void)
-{
-	if (saved_netns != -1)
-		return;
-
-	saved_netns = open("/proc/self/ns/net", O_RDONLY | O_CLOEXEC);
-	if (saved_netns == -1) {
-		perror("Cannot open init namespace");
-		exit(1);
-	}
-}
-
-static void netns_restore(void)
-{
-	if (saved_netns == -1)
-		return;
-
-	if (setns(saved_netns, CLONE_NEWNET)) {
-		perror("setns");
-		exit(1);
-	}
-
-	close(saved_netns);
-	saved_netns = -1;
-}
-
-static int netns_add(int argc, char **argv, bool create)
+static int netns_add(int argc, char **argv)
 {
 	/* This function creates a new network namespace and
 	 * a new mount namespace and bind them into a well known
 	 * location in the filesystem based on the name provided.
 	 *
-	 * If create is true, a new namespace will be created,
-	 * otherwise an existing one will be attached to the file.
-	 *
 	 * The mount namespace is created so that any necessary
 	 * userspace tweaks like remounting /sys, or bind mounting
-	 * a new /etc/resolv.conf can be shared between users.
+	 * a new /etc/resolv.conf can be shared between uers.
 	 */
-	char netns_path[PATH_MAX], proc_path[PATH_MAX];
+	char netns_path[PATH_MAX];
 	const char *name;
-	pid_t pid;
 	int fd;
 	int made_netns_run_dir_mount = 0;
 
-	if (create) {
-		if (argc < 1) {
-			fprintf(stderr, "No netns name specified\n");
-			return -1;
-		}
-	} else {
-		if (argc < 2) {
-			fprintf(stderr, "No netns name and PID specified\n");
-			return -1;
-		}
-
-		if (get_s32(&pid, argv[1], 0) || !pid) {
-			fprintf(stderr, "Invalid PID: %s\n", argv[1]);
-			return -1;
-		}
+	if (argc < 1) {
+		fprintf(stderr, "No netns name specified\n");
+		return -1;
 	}
 	name = argv[0];
 
@@ -825,7 +642,7 @@
 		}
 
 		/* Upgrade NETNS_RUN_DIR to a mount point */
-		if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none", MS_BIND | MS_REC, NULL)) {
+		if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none", MS_BIND, NULL)) {
 			fprintf(stderr, "mount --bind %s %s failed: %s\n",
 				NETNS_RUN_DIR, NETNS_RUN_DIR, strerror(errno));
 			return -1;
@@ -841,55 +658,38 @@
 		return -1;
 	}
 	close(fd);
-
-	if (create) {
-		netns_save();
-		if (unshare(CLONE_NEWNET) < 0) {
-			fprintf(stderr, "Failed to create a new network namespace \"%s\": %s\n",
-				name, strerror(errno));
-			goto out_delete;
-		}
-
-		strcpy(proc_path, "/proc/self/ns/net");
-	} else {
-		snprintf(proc_path, sizeof(proc_path), "/proc/%d/ns/net", pid);
+	if (unshare(CLONE_NEWNET) < 0) {
+		fprintf(stderr, "Failed to create a new network namespace \"%s\": %s\n",
+			name, strerror(errno));
+		goto out_delete;
 	}
 
 	/* Bind the netns last so I can watch for it */
-	if (mount(proc_path, netns_path, "none", MS_BIND, NULL) < 0) {
-		fprintf(stderr, "Bind %s -> %s failed: %s\n",
-			proc_path, netns_path, strerror(errno));
+	if (mount("/proc/self/ns/net", netns_path, "none", MS_BIND, NULL) < 0) {
+		fprintf(stderr, "Bind /proc/self/ns/net -> %s failed: %s\n",
+			netns_path, strerror(errno));
 		goto out_delete;
 	}
-	netns_restore();
-
 	return 0;
 out_delete:
-	if (create) {
-		netns_restore();
-		netns_delete(argc, argv);
-	} else if (unlink(netns_path) < 0) {
-		fprintf(stderr, "Cannot remove namespace file \"%s\": %s\n",
-			netns_path, strerror(errno));
-	}
+	netns_delete(argc, argv);
 	return -1;
 }
 
-int set_netnsid_from_name(const char *name, int nsid)
+static int set_netnsid_from_name(const char *name, int nsid)
 {
 	struct {
 		struct nlmsghdr n;
 		struct rtgenmsg g;
 		char            buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_NEWNSID,
-		.g.rtgen_family = AF_UNSPEC,
-	};
+	} req;
 	int fd, err = 0;
 
-	netns_nsid_socket_init();
+	memset(&req, 0, sizeof(req));
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = RTM_NEWNSID;
+	req.g.rtgen_family = AF_UNSPEC;
 
 	fd = netns_get_fd(name);
 	if (fd < 0)
@@ -897,7 +697,7 @@
 
 	addattr32(&req.n, 1024, NETNSA_FD, fd);
 	addattr32(&req.n, 1024, NETNSA_NSID, nsid);
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		err = -2;
 
 	close(fd);
@@ -919,13 +719,7 @@
 		return -1;
 	}
 	name = argv[0];
-	/* If a negative nsid is specified the kernel will select the nsid. */
-	if (strcmp(argv[1], "auto") == 0)
-		nsid = -1;
-	else if (get_integer(&nsid, argv[1], 0))
-		invarg("Invalid \"netnsid\" value\n", argv[1]);
-	else if (nsid < 0)
-		invarg("\"netnsid\" value should be >= 0\n", argv[1]);
+	nsid = atoi(argv[1]);
 
 	snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name);
 	netns = open(netns_path, O_RDONLY | O_CLOEXEC);
@@ -943,7 +737,6 @@
 	char buf[4096];
 	struct inotify_event *event;
 	int fd;
-
 	fd = inotify_init();
 	if (fd < 0) {
 		fprintf(stderr, "inotify_init failed: %s\n",
@@ -959,9 +752,8 @@
 			strerror(errno));
 		return -1;
 	}
-	for (;;) {
+	for(;;) {
 		ssize_t len = read(fd, buf, sizeof(buf));
-
 		if (len < 0) {
 			fprintf(stderr, "read failed: %s\n",
 				strerror(errno));
@@ -979,42 +771,25 @@
 	return 0;
 }
 
-static int invalid_name(const char *name)
-{
-	return !*name || strlen(name) > NAME_MAX ||
-		strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
-}
-
 int do_netns(int argc, char **argv)
 {
-	netns_nsid_socket_init();
+	netns_map_init();
 
-	if (argc < 1) {
-		netns_map_init();
+	if (argc < 1)
 		return netns_list(0, NULL);
-	}
-
-	if (!do_all && argc > 1 && invalid_name(argv[1])) {
-		fprintf(stderr, "Invalid netns name \"%s\"\n", argv[1]);
-		exit(-1);
-	}
 
 	if ((matches(*argv, "list") == 0) || (matches(*argv, "show") == 0) ||
-	    (matches(*argv, "lst") == 0)) {
-		netns_map_init();
+	    (matches(*argv, "lst") == 0))
 		return netns_list(argc-1, argv+1);
-	}
 
-	if ((matches(*argv, "list-id") == 0)) {
-		netns_map_init();
+	if ((matches(*argv, "list-id") == 0))
 		return netns_list_id(argc-1, argv+1);
-	}
 
 	if (matches(*argv, "help") == 0)
 		return usage();
 
 	if (matches(*argv, "add") == 0)
-		return netns_add(argc-1, argv+1, true);
+		return netns_add(argc-1, argv+1);
 
 	if (matches(*argv, "set") == 0)
 		return netns_set(argc-1, argv+1);
@@ -1034,9 +809,6 @@
 	if (matches(*argv, "monitor") == 0)
 		return netns_monitor(argc-1, argv+1);
 
-	if (matches(*argv, "attach") == 0)
-		return netns_add(argc-1, argv+1, false);
-
 	fprintf(stderr, "Command \"%s\" is unknown, try \"ip netns help\".\n", *argv);
 	exit(-1);
 }
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
deleted file mode 100644
index 9f860c8..0000000
--- a/ip/ipnexthop.c
+++ /dev/null
@@ -1,573 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * ip nexthop
- *
- * Copyright (c) 2017-19 David Ahern <dsahern@gmail.com>
- */
-
-#include <linux/nexthop.h>
-#include <stdio.h>
-#include <string.h>
-#include <rt_names.h>
-#include <errno.h>
-
-#include "utils.h"
-#include "ip_common.h"
-
-static struct {
-	unsigned int flushed;
-	unsigned int groups;
-	unsigned int ifindex;
-	unsigned int master;
-	unsigned int proto;
-} filter;
-
-enum {
-	IPNH_LIST,
-	IPNH_FLUSH,
-};
-
-#define RTM_NHA(h)  ((struct rtattr *)(((char *)(h)) + \
-			NLMSG_ALIGN(sizeof(struct nhmsg))))
-
-static void usage(void) __attribute__((noreturn));
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage: ip nexthop { list | flush } [ protocol ID ] SELECTOR\n"
-		"       ip nexthop { add | replace } id ID NH [ protocol ID ]\n"
-		"       ip nexthop { get| del } id ID\n"
-		"SELECTOR := [ id ID ] [ dev DEV ] [ vrf NAME ] [ master DEV ]\n"
-		"            [ groups ]\n"
-		"NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ]\n"
-		"      [ encap ENCAPTYPE ENCAPHDR ] | group GROUP ] }\n"
-		"GROUP := [ id[,weight]>/<id[,weight]>/... ]\n"
-		"ENCAPTYPE := [ mpls ]\n"
-		"ENCAPHDR := [ MPLSLABEL ]\n");
-	exit(-1);
-}
-
-static int nh_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	int err;
-
-	if (filter.ifindex) {
-		err = addattr32(nlh, reqlen, NHA_OIF, filter.ifindex);
-		if (err)
-			return err;
-	}
-
-	if (filter.groups) {
-		addattr_l(nlh, reqlen, NHA_GROUPS, NULL, 0);
-		if (err)
-			return err;
-	}
-
-	if (filter.master) {
-		addattr32(nlh, reqlen, NHA_MASTER, filter.master);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
-static struct rtnl_handle rth_del = { .fd = -1 };
-
-static int delete_nexthop(__u32 id)
-{
-	struct {
-		struct nlmsghdr	n;
-		struct nhmsg	nhm;
-		char		buf[64];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_DELNEXTHOP,
-		.nhm.nh_family = AF_UNSPEC,
-	};
-
-	req.n.nlmsg_seq = ++rth_del.seq;
-
-	addattr32(&req.n, sizeof(req), NHA_ID, id);
-
-	if (rtnl_talk(&rth_del, &req.n, NULL) < 0)
-		return -1;
-	return 0;
-}
-
-static int flush_nexthop(struct nlmsghdr *nlh, void *arg)
-{
-	struct nhmsg *nhm = NLMSG_DATA(nlh);
-	struct rtattr *tb[NHA_MAX+1];
-	__u32 id = 0;
-	int len;
-
-	len = nlh->nlmsg_len - NLMSG_SPACE(sizeof(*nhm));
-	if (len < 0) {
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-
-	if (filter.proto && nhm->nh_protocol != filter.proto)
-		return 0;
-
-	parse_rtattr(tb, NHA_MAX, RTM_NHA(nhm), len);
-	if (tb[NHA_ID])
-		id = rta_getattr_u32(tb[NHA_ID]);
-
-	if (id && !delete_nexthop(id))
-		filter.flushed++;
-
-	return 0;
-}
-
-static int ipnh_flush(unsigned int all)
-{
-	int rc = -2;
-
-	if (all) {
-		filter.groups = 1;
-		filter.ifindex = 0;
-		filter.master = 0;
-	}
-
-	if (rtnl_open(&rth_del, 0) < 0) {
-		fprintf(stderr, "Cannot open rtnetlink\n");
-		return EXIT_FAILURE;
-	}
-again:
-	if (rtnl_nexthopdump_req(&rth, preferred_family, nh_dump_filter) < 0) {
-		perror("Cannot send dump request");
-		goto out;
-	}
-
-	if (rtnl_dump_filter(&rth, flush_nexthop, stdout) < 0) {
-		fprintf(stderr, "Dump terminated. Failed to flush nexthops\n");
-		goto out;
-	}
-
-	/* if deleting all, then remove groups first */
-	if (all && filter.groups) {
-		filter.groups = 0;
-		goto again;
-	}
-
-	rc = 0;
-out:
-	rtnl_close(&rth_del);
-	if (!filter.flushed)
-		printf("Nothing to flush\n");
-	else
-		printf("Flushed %d nexthops\n", filter.flushed);
-
-	return rc;
-}
-
-static void print_nh_group(FILE *fp, const struct rtattr *grps_attr)
-{
-	struct nexthop_grp *nhg = RTA_DATA(grps_attr);
-	int num = RTA_PAYLOAD(grps_attr) / sizeof(*nhg);
-	int i;
-
-	if (!num || num * sizeof(*nhg) != RTA_PAYLOAD(grps_attr)) {
-		fprintf(fp, "<invalid nexthop group>");
-		return;
-	}
-
-	open_json_array(PRINT_JSON, "group");
-	print_string(PRINT_FP, NULL, "%s", "group ");
-	for (i = 0; i < num; ++i) {
-		open_json_object(NULL);
-
-		if (i)
-			print_string(PRINT_FP, NULL, "%s", "/");
-
-		print_uint(PRINT_ANY, "id", "%u", nhg[i].id);
-		if (nhg[i].weight)
-			print_uint(PRINT_ANY, "weight", ",%u", nhg[i].weight + 1);
-
-		close_json_object();
-	}
-	print_string(PRINT_FP, NULL, "%s", " ");
-	close_json_array(PRINT_JSON, NULL);
-}
-
-int print_nexthop(struct nlmsghdr *n, void *arg)
-{
-	struct nhmsg *nhm = NLMSG_DATA(n);
-	struct rtattr *tb[NHA_MAX+1];
-	FILE *fp = (FILE *)arg;
-	int len;
-
-	SPRINT_BUF(b1);
-
-	if (n->nlmsg_type != RTM_DELNEXTHOP &&
-	    n->nlmsg_type != RTM_NEWNEXTHOP) {
-		fprintf(stderr, "Not a nexthop: %08x %08x %08x\n",
-			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
-		return -1;
-	}
-
-	len = n->nlmsg_len - NLMSG_SPACE(sizeof(*nhm));
-	if (len < 0) {
-		close_json_object();
-		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
-		return -1;
-	}
-
-	if (filter.proto && filter.proto != nhm->nh_protocol)
-		return 0;
-
-	parse_rtattr(tb, NHA_MAX, RTM_NHA(nhm), len);
-
-	open_json_object(NULL);
-
-	if (n->nlmsg_type == RTM_DELROUTE)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
-
-	if (tb[NHA_ID])
-		print_uint(PRINT_ANY, "id", "id %u ",
-			   rta_getattr_u32(tb[NHA_ID]));
-
-	if (tb[NHA_GROUP])
-		print_nh_group(fp, tb[NHA_GROUP]);
-
-	if (tb[NHA_ENCAP])
-		lwt_print_encap(fp, tb[NHA_ENCAP_TYPE], tb[NHA_ENCAP]);
-
-	if (tb[NHA_GATEWAY])
-		print_rta_gateway(fp, nhm->nh_family, tb[NHA_GATEWAY]);
-
-	if (tb[NHA_OIF])
-		print_rta_if(fp, tb[NHA_OIF], "dev");
-
-	if (nhm->nh_scope != RT_SCOPE_UNIVERSE || show_details > 0) {
-		print_string(PRINT_ANY, "scope", "scope %s ",
-			     rtnl_rtscope_n2a(nhm->nh_scope, b1, sizeof(b1)));
-	}
-
-	if (tb[NHA_BLACKHOLE])
-		print_null(PRINT_ANY, "blackhole", "blackhole ", NULL);
-
-	if (nhm->nh_protocol != RTPROT_UNSPEC || show_details > 0) {
-		print_string(PRINT_ANY, "protocol", "proto %s ",
-			     rtnl_rtprot_n2a(nhm->nh_protocol, b1, sizeof(b1)));
-	}
-
-	if (tb[NHA_OIF])
-		print_rt_flags(fp, nhm->nh_flags);
-
-	print_string(PRINT_FP, NULL, "%s", "\n");
-	close_json_object();
-	fflush(fp);
-
-	return 0;
-}
-
-static int add_nh_group_attr(struct nlmsghdr *n, int maxlen, char *argv)
-{
-	struct nexthop_grp *grps;
-	int count = 0, i;
-	char *sep, *wsep;
-
-	if (*argv != '\0')
-		count = 1;
-
-	/* separator is '/' */
-	sep = strchr(argv, '/');
-	while (sep) {
-		count++;
-		sep = strchr(sep + 1, '/');
-	}
-
-	if (count == 0)
-		return -1;
-
-	grps = calloc(count, sizeof(*grps));
-	if (!grps)
-		return -1;
-
-	for (i = 0; i < count; ++i) {
-		sep = strchr(argv, '/');
-		if (sep)
-			*sep = '\0';
-
-		wsep = strchr(argv, ',');
-		if (wsep)
-			*wsep = '\0';
-
-		if (get_unsigned(&grps[i].id, argv, 0))
-			return -1;
-		if (wsep) {
-			unsigned int w;
-
-			wsep++;
-			if (get_unsigned(&w, wsep, 0) || w == 0 || w > 256)
-				invarg("\"weight\" is invalid\n", wsep);
-			grps[i].weight = w - 1;
-		}
-
-		if (!sep)
-			break;
-
-		argv = sep + 1;
-	}
-
-	return addattr_l(n, maxlen, NHA_GROUP, grps, count * sizeof(*grps));
-}
-
-static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv)
-{
-	struct {
-		struct nlmsghdr	n;
-		struct nhmsg	nhm;
-		char		buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.nhm.nh_family = preferred_family,
-	};
-	__u32 nh_flags = 0;
-
-	while (argc > 0) {
-		if (!strcmp(*argv, "id")) {
-			__u32 id;
-
-			NEXT_ARG();
-			if (get_unsigned(&id, *argv, 0))
-				invarg("invalid id value", *argv);
-			addattr32(&req.n, sizeof(req), NHA_ID, id);
-		} else if (!strcmp(*argv, "dev")) {
-			int ifindex;
-
-			NEXT_ARG();
-			ifindex = ll_name_to_index(*argv);
-			if (!ifindex)
-				invarg("Device does not exist\n", *argv);
-			addattr32(&req.n, sizeof(req), NHA_OIF, ifindex);
-			if (req.nhm.nh_family == AF_UNSPEC)
-				req.nhm.nh_family = AF_INET;
-		} else if (strcmp(*argv, "via") == 0) {
-			inet_prefix addr;
-			int family;
-
-			NEXT_ARG();
-			family = read_family(*argv);
-			if (family == AF_UNSPEC)
-				family = req.nhm.nh_family;
-			else
-				NEXT_ARG();
-			get_addr(&addr, *argv, family);
-			if (req.nhm.nh_family == AF_UNSPEC)
-				req.nhm.nh_family = addr.family;
-			else if (req.nhm.nh_family != addr.family)
-				invarg("address family mismatch\n", *argv);
-			addattr_l(&req.n, sizeof(req), NHA_GATEWAY,
-				  &addr.data, addr.bytelen);
-		} else if (strcmp(*argv, "encap") == 0) {
-			char buf[1024];
-			struct rtattr *rta = (void *)buf;
-
-			rta->rta_type = NHA_ENCAP;
-			rta->rta_len = RTA_LENGTH(0);
-
-			lwt_parse_encap(rta, sizeof(buf), &argc, &argv,
-					NHA_ENCAP, NHA_ENCAP_TYPE);
-
-			if (rta->rta_len > RTA_LENGTH(0)) {
-				addraw_l(&req.n, 1024, RTA_DATA(rta),
-					 RTA_PAYLOAD(rta));
-			}
-		} else if (!strcmp(*argv, "blackhole")) {
-			addattr_l(&req.n, sizeof(req), NHA_BLACKHOLE, NULL, 0);
-			if (req.nhm.nh_family == AF_UNSPEC)
-				req.nhm.nh_family = AF_INET;
-		} else if (!strcmp(*argv, "onlink")) {
-			nh_flags |= RTNH_F_ONLINK;
-		} else if (!strcmp(*argv, "group")) {
-			NEXT_ARG();
-
-			if (add_nh_group_attr(&req.n, sizeof(req), *argv))
-				invarg("\"group\" value is invalid\n", *argv);
-		} else if (matches(*argv, "protocol") == 0) {
-			__u32 prot;
-
-			NEXT_ARG();
-			if (rtnl_rtprot_a2n(&prot, *argv))
-				invarg("\"protocol\" value is invalid\n", *argv);
-			req.nhm.nh_protocol = prot;
-		} else if (strcmp(*argv, "help") == 0) {
-			usage();
-		} else {
-			invarg("", *argv);
-		}
-		argc--; argv++;
-	}
-
-	req.nhm.nh_flags = nh_flags;
-
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
-		return -2;
-
-	return 0;
-}
-
-static int ipnh_get_id(__u32 id)
-{
-	struct {
-		struct nlmsghdr	n;
-		struct nhmsg	nhm;
-		char		buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type  = RTM_GETNEXTHOP,
-		.nhm.nh_family = preferred_family,
-	};
-	struct nlmsghdr *answer;
-
-	addattr32(&req.n, sizeof(req), NHA_ID, id);
-
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
-		return -2;
-
-	new_json_obj(json);
-
-	if (print_nexthop(answer, (void *)stdout) < 0) {
-		free(answer);
-		return -1;
-	}
-
-	delete_json_obj();
-	fflush(stdout);
-
-	free(answer);
-
-	return 0;
-}
-
-static int ipnh_list_flush(int argc, char **argv, int action)
-{
-	unsigned int all = (argc == 0);
-
-	while (argc > 0) {
-		if (!matches(*argv, "dev")) {
-			NEXT_ARG();
-			filter.ifindex = ll_name_to_index(*argv);
-			if (!filter.ifindex)
-				invarg("Device does not exist\n", *argv);
-		} else if (!matches(*argv, "groups")) {
-			filter.groups = 1;
-		} else if (!matches(*argv, "master")) {
-			NEXT_ARG();
-			filter.master = ll_name_to_index(*argv);
-			if (!filter.master)
-				invarg("Device does not exist\n", *argv);
-		} else if (matches(*argv, "vrf") == 0) {
-			NEXT_ARG();
-			if (!name_is_vrf(*argv))
-				invarg("Invalid VRF\n", *argv);
-			filter.master = ll_name_to_index(*argv);
-			if (!filter.master)
-				invarg("VRF does not exist\n", *argv);
-		} else if (!strcmp(*argv, "id")) {
-			__u32 id;
-
-			NEXT_ARG();
-			if (get_unsigned(&id, *argv, 0))
-				invarg("invalid id value", *argv);
-			return ipnh_get_id(id);
-		} else if (!matches(*argv, "protocol")) {
-			__u32 proto;
-
-			NEXT_ARG();
-			if (get_unsigned(&proto, *argv, 0))
-				invarg("invalid protocol value", *argv);
-			filter.proto = proto;
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			invarg("", *argv);
-		}
-		argc--; argv++;
-	}
-
-	if (action == IPNH_FLUSH)
-		return ipnh_flush(all);
-
-	if (rtnl_nexthopdump_req(&rth, preferred_family, nh_dump_filter) < 0) {
-		perror("Cannot send dump request");
-		return -2;
-	}
-
-	new_json_obj(json);
-
-	if (rtnl_dump_filter(&rth, print_nexthop, stdout) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return -2;
-	}
-
-	delete_json_obj();
-	fflush(stdout);
-
-	return 0;
-}
-
-static int ipnh_get(int argc, char **argv)
-{
-	__u32 id = 0;
-
-	while (argc > 0) {
-		if (!strcmp(*argv, "id")) {
-			NEXT_ARG();
-			if (get_unsigned(&id, *argv, 0))
-				invarg("invalid id value", *argv);
-		} else  {
-			usage();
-		}
-		argc--; argv++;
-	}
-
-	if (!id) {
-		usage();
-		return -1;
-	}
-
-	return ipnh_get_id(id);
-}
-
-int do_ipnh(int argc, char **argv)
-{
-	if (argc < 1)
-		return ipnh_list_flush(0, NULL, IPNH_LIST);
-
-	if (!matches(*argv, "add"))
-		return ipnh_modify(RTM_NEWNEXTHOP, NLM_F_CREATE|NLM_F_EXCL,
-				   argc-1, argv+1);
-	if (!matches(*argv, "replace"))
-		return ipnh_modify(RTM_NEWNEXTHOP, NLM_F_CREATE|NLM_F_REPLACE,
-				   argc-1, argv+1);
-	if (!matches(*argv, "delete"))
-		return ipnh_modify(RTM_DELNEXTHOP, 0, argc-1, argv+1);
-
-	if (!matches(*argv, "list") ||
-	    !matches(*argv, "show") ||
-	    !matches(*argv, "lst"))
-		return ipnh_list_flush(argc-1, argv+1, IPNH_LIST);
-
-	if (!matches(*argv, "get"))
-		return ipnh_get(argc-1, argv+1);
-
-	if (!matches(*argv, "flush"))
-		return ipnh_list_flush(argc-1, argv+1, IPNH_FLUSH);
-
-	if (!matches(*argv, "help"))
-		usage();
-
-	fprintf(stderr,
-		"Command \"%s\" is unknown, try \"ip nexthop help\".\n", *argv);
-	exit(-1);
-}
diff --git a/ip/ipntable.c b/ip/ipntable.c
index ddee490..6eb84e7 100644
--- a/ip/ipntable.c
+++ b/ip/ipntable.c
@@ -31,14 +31,13 @@
 
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 static struct
 {
 	int family;
-	int index;
+        int index;
 #define NONE_DEV	(-1)
-	const char *name;
+	char name[1024];
 } filter;
 
 static void usage(void) __attribute__((noreturn));
@@ -47,15 +46,15 @@
 {
 	fprintf(stderr,
 		"Usage: ip ntable change name NAME [ dev DEV ]\n"
-		"	 [ thresh1 VAL ] [ thresh2 VAL ] [ thresh3 VAL ] [ gc_int MSEC ]\n"
-		"	 [ PARMS ]\n"
+		"          [ thresh1 VAL ] [ thresh2 VAL ] [ thresh3 VAL ] [ gc_int MSEC ]\n"
+		"          [ PARMS ]\n"
 		"Usage: ip ntable show [ dev DEV ] [ name NAME ]\n"
 
 		"PARMS := [ base_reachable MSEC ] [ retrans MSEC ] [ gc_stale MSEC ]\n"
-		"	 [ delay_probe MSEC ] [ queue LEN ]\n"
-		"	 [ app_probes VAL ] [ ucast_probes VAL ] [ mcast_probes VAL ]\n"
-		"	 [ anycast_delay MSEC ] [ proxy_delay MSEC ] [ proxy_queue LEN ]\n"
-		"	 [ locktime MSEC ]\n"
+		"         [ delay_probe MSEC ] [ queue LEN ]\n"
+		"         [ app_probs VAL ] [ ucast_probes VAL ] [ mcast_probes VAL ]\n"
+		"         [ anycast_delay MSEC ] [ proxy_delay MSEC ] [ proxy_queue LEN ]\n"
+		"         [ locktime MSEC ]\n"
 		);
 
 	exit(-1);
@@ -66,20 +65,27 @@
 	struct {
 		struct nlmsghdr	n;
 		struct ndtmsg		ndtm;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.ndtm.ndtm_family = preferred_family,
-	};
+		char  			buf[1024];
+	} req;
 	char *namep = NULL;
 	char *threshsp = NULL;
 	char *gc_intp = NULL;
-	char parms_buf[1024] = {};
+	char parms_buf[1024];
 	struct rtattr *parms_rta = (struct rtattr *)parms_buf;
 	int parms_change = 0;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+
+	req.ndtm.ndtm_family = preferred_family;
+	req.ndtm.ndtm_pad1 = 0;
+	req.ndtm.ndtm_pad2 = 0;
+
+	memset(&parms_buf, 0, sizeof(parms_buf));
+
 	parms_rta->rta_type = NDTA_PARMS;
 	parms_rta->rta_len = RTA_LENGTH(0);
 
@@ -140,8 +146,10 @@
 
 			NEXT_ARG();
 			ifindex = ll_name_to_index(*argv);
-			if (!ifindex)
-				return nodev(*argv);
+			if (ifindex == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
+				return -1;
+			}
 
 			rta_addattr32(parms_rta, sizeof(parms_buf),
 				      NDTPA_IFINDEX, ifindex);
@@ -201,6 +209,8 @@
 			if (get_u32(&queue, *argv, 0))
 				invarg("\"queue\" value is invalid", *argv);
 
+			if (!parms_rta)
+				parms_rta = (struct rtattr *)&parms_buf;
 			rta_addattr32(parms_rta, sizeof(parms_buf),
 				      NDTPA_QUEUE_LEN, queue);
 			parms_change = 1;
@@ -303,7 +313,7 @@
 			  RTA_PAYLOAD(parms_rta));
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	return 0;
@@ -312,13 +322,15 @@
 static const char *ntable_strtime_delta(__u32 msec)
 {
 	static char str[32];
-	struct timeval now = {};
+	struct timeval now;
 	time_t t;
 	struct tm *tp;
 
 	if (msec == 0)
 		goto error;
 
+	memset(&now, 0, sizeof(now));
+
 	if (gettimeofday(&now, NULL) < 0) {
 		perror("gettimeofday");
 		goto error;
@@ -337,192 +349,9 @@
 	return str;
 }
 
-static void print_ndtconfig(const struct ndt_config *ndtc)
+static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
-
-	print_uint(PRINT_ANY, "key_length",
-		   "    config key_len %u ", ndtc->ndtc_key_len);
-	print_uint(PRINT_ANY, "entry_size",
-		   "entry_size %u ", ndtc->ndtc_entry_size);
-	print_uint(PRINT_ANY, "entries", "entries %u ", ndtc->ndtc_entries);
-
-	print_nl();
-
-	print_string(PRINT_ANY, "last_flush",
-		     "        last_flush %s ",
-		     ntable_strtime_delta(ndtc->ndtc_last_flush));
-	print_string(PRINT_ANY, "last_rand",
-		     "last_rand %s ",
-		     ntable_strtime_delta(ndtc->ndtc_last_rand));
-
-	print_nl();
-
-	print_uint(PRINT_ANY, "hash_rnd",
-		   "        hash_rnd %u ", ndtc->ndtc_hash_rnd);
-	print_0xhex(PRINT_ANY, "hash_mask",
-		    "hash_mask %08llx ", ndtc->ndtc_hash_mask);
-
-	print_uint(PRINT_ANY, "hash_chain_gc",
-		   "hash_chain_gc %u ", ndtc->ndtc_hash_chain_gc);
-	print_uint(PRINT_ANY, "proxy_qlen",
-		   "proxy_qlen %u ", ndtc->ndtc_proxy_qlen);
-
-	print_nl();
-}
-
-static void print_ndtparams(struct rtattr *tpb[])
-{
-
-	if (tpb[NDTPA_IFINDEX]) {
-		__u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
-
-		print_string(PRINT_FP, NULL, "    dev ", NULL);
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "dev", "%s ", ll_index_to_name(ifindex));
-		print_nl();
-	}
-
-	print_string(PRINT_FP, NULL, "    ", NULL);
-	if (tpb[NDTPA_REFCNT]) {
-		__u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]);
-
-		print_uint(PRINT_ANY, "refcnt", "refcnt %u ", refcnt);
-	}
-
-	if (tpb[NDTPA_REACHABLE_TIME]) {
-		__u64 reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
-
-		print_u64(PRINT_ANY, "reachable",
-			   "reachable %llu ", reachable);
-	}
-
-	if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
-		__u64 breachable
-			= rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
-
-		print_u64(PRINT_ANY, "base_reachable",
-			   "base_reachable %llu ", breachable);
-	}
-
-	if (tpb[NDTPA_RETRANS_TIME]) {
-		__u64 retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
-
-		print_u64(PRINT_ANY, "retrans", "retrans %llu ", retrans);
-	}
-
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-
-	if (tpb[NDTPA_GC_STALETIME]) {
-		__u64 gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
-
-		print_u64(PRINT_ANY, "gc_stale", "gc_stale %llu ", gc_stale);
-	}
-
-	if (tpb[NDTPA_DELAY_PROBE_TIME]) {
-		__u64 delay_probe
-			= rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
-
-		print_u64(PRINT_ANY, "delay_probe",
-			   "delay_probe %llu ", delay_probe);
-	}
-
-	if (tpb[NDTPA_QUEUE_LEN]) {
-		__u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
-
-		print_uint(PRINT_ANY, "queue", "queue %u ", queue);
-	}
-
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-
-	if (tpb[NDTPA_APP_PROBES]) {
-		__u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]);
-
-		print_uint(PRINT_ANY, "app_probes", "app_probes %u ", aprobe);
-	}
-
-	if (tpb[NDTPA_UCAST_PROBES]) {
-		__u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]);
-
-		print_uint(PRINT_ANY, "ucast_probes",
-			   "ucast_probes %u ", uprobe);
-	}
-
-	if (tpb[NDTPA_MCAST_PROBES]) {
-		__u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]);
-
-		print_uint(PRINT_ANY, "mcast_probes",
-			   "mcast_probes %u ", mprobe);
-	}
-
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-
-	if (tpb[NDTPA_ANYCAST_DELAY]) {
-		__u64 anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
-
-		print_u64(PRINT_ANY, "anycast_delay",
-			   "anycast_delay %llu ", anycast_delay);
-	}
-
-	if (tpb[NDTPA_PROXY_DELAY]) {
-		__u64 proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
-
-		print_u64(PRINT_ANY, "proxy_delay",
-			   "proxy_delay %llu ", proxy_delay);
-	}
-
-	if (tpb[NDTPA_PROXY_QLEN]) {
-		__u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
-
-		print_uint(PRINT_ANY, "proxy_queue", "proxy_queue %u ", pqueue);
-	}
-
-	if (tpb[NDTPA_LOCKTIME]) {
-		__u64 locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
-
-		print_u64(PRINT_ANY, "locktime", "locktime %llu ", locktime);
-	}
-
-	print_nl();
-}
-
-static void print_ndtstats(const struct ndt_stats *ndts)
-{
-
-	print_string(PRINT_FP, NULL, "    stats ", NULL);
-
-	print_u64(PRINT_ANY, "allocs", "allocs %llu ", ndts->ndts_allocs);
-	print_u64(PRINT_ANY, "destroys", "destroys %llu ",
-		   ndts->ndts_destroys);
-	print_u64(PRINT_ANY, "hash_grows", "hash_grows %llu ",
-		   ndts->ndts_hash_grows);
-
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-
-	print_u64(PRINT_ANY, "res_failed", "res_failed %llu ",
-		   ndts->ndts_res_failed);
-	print_u64(PRINT_ANY, "lookups", "lookups %llu ", ndts->ndts_lookups);
-	print_u64(PRINT_ANY, "hits", "hits %llu ", ndts->ndts_hits);
-
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-
-	print_u64(PRINT_ANY, "rcv_probes_mcast", "rcv_probes_mcast %llu ",
-		   ndts->ndts_rcv_probes_mcast);
-	print_u64(PRINT_ANY, "rcv_probes_ucast", "rcv_probes_ucast %llu ",
-		   ndts->ndts_rcv_probes_ucast);
-
-	print_string(PRINT_FP, NULL, "%s    ", _SL_);
-
-	print_u64(PRINT_ANY, "periodic_gc_runs", "periodic_gc_runs %llu ",
-		   ndts->ndts_periodic_gc_runs);
-	print_u64(PRINT_ANY, "forced_gc_runs", "forced_gc_runs %llu ",
-		   ndts->ndts_forced_gc_runs);
-
-	print_nl();
-}
-
-static int print_ntable(struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct ndtmsg *ndtm = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	struct rtattr *tb[NDTA_MAX+1];
@@ -549,10 +378,9 @@
 	if (tb[NDTA_NAME]) {
 		const char *name = rta_getattr_str(tb[NDTA_NAME]);
 
-		if (filter.name && strcmp(filter.name, name))
+		if (strlen(filter.name) > 0 && strcmp(filter.name, name))
 			return 0;
 	}
-
 	if (tb[NDTA_PARMS]) {
 		parse_rtattr(tpb, NDTPA_MAX, RTA_DATA(tb[NDTA_PARMS]),
 			     RTA_PAYLOAD(tb[NDTA_PARMS]));
@@ -568,63 +396,208 @@
 		}
 	}
 
-	open_json_object(NULL);
-	print_string(PRINT_ANY, "family",
-		     "%s ", family_name(ndtm->ndtm_family));
+	if (ndtm->ndtm_family == AF_INET)
+		fprintf(fp, "inet ");
+	else if (ndtm->ndtm_family == AF_INET6)
+		fprintf(fp, "inet6 ");
+	else if (ndtm->ndtm_family == AF_DECnet)
+		fprintf(fp, "dnet ");
+	else
+		fprintf(fp, "(%d) ", ndtm->ndtm_family);
 
 	if (tb[NDTA_NAME]) {
 		const char *name = rta_getattr_str(tb[NDTA_NAME]);
-
-		print_string(PRINT_ANY, "name", "%s ", name);
+		fprintf(fp, "%s ", name);
 	}
 
-	print_nl();
+	fprintf(fp, "%s", _SL_);
 
 	ret = (tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || tb[NDTA_THRESH3] ||
 	       tb[NDTA_GC_INTERVAL]);
 	if (ret)
-		print_string(PRINT_FP, NULL, "    ", NULL);
+		fprintf(fp, "    ");
 
 	if (tb[NDTA_THRESH1]) {
 		__u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);
-
-		print_uint(PRINT_ANY, "thresh1", "thresh1 %u ", thresh1);
+		fprintf(fp, "thresh1 %u ", thresh1);
 	}
-
 	if (tb[NDTA_THRESH2]) {
 		__u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);
-
-		print_uint(PRINT_ANY, "thresh2", "thresh2 %u ", thresh2);
+		fprintf(fp, "thresh2 %u ", thresh2);
 	}
-
 	if (tb[NDTA_THRESH3]) {
 		__u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);
-
-		print_uint(PRINT_ANY, "thresh3", "thresh3 %u ", thresh3);
+		fprintf(fp, "thresh3 %u ", thresh3);
 	}
-
 	if (tb[NDTA_GC_INTERVAL]) {
-		__u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
-
-		print_u64(PRINT_ANY, "gc_interval", "gc_int %llu ", gc_int);
+		unsigned long long gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
+		fprintf(fp, "gc_int %llu ", gc_int);
 	}
 
 	if (ret)
-		print_nl();
+		fprintf(fp, "%s", _SL_);
 
-	if (tb[NDTA_CONFIG] && show_stats)
-		print_ndtconfig(RTA_DATA(tb[NDTA_CONFIG]));
+	if (tb[NDTA_CONFIG] && show_stats) {
+		struct ndt_config *ndtc = RTA_DATA(tb[NDTA_CONFIG]);
 
-	if (tb[NDTA_PARMS])
-		print_ndtparams(tpb);
+		fprintf(fp, "    ");
+		fprintf(fp, "config ");
 
-	if (tb[NDTA_STATS] && show_stats)
-		print_ndtstats(RTA_DATA(tb[NDTA_STATS]));
+		fprintf(fp, "key_len %u ", ndtc->ndtc_key_len);
+		fprintf(fp, "entry_size %u ", ndtc->ndtc_entry_size);
+		fprintf(fp, "entries %u ", ndtc->ndtc_entries);
 
-	print_string(PRINT_FP, NULL, "\n", "");
-	close_json_object();
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "        ");
+
+		fprintf(fp, "last_flush %s ",
+			ntable_strtime_delta(ndtc->ndtc_last_flush));
+		fprintf(fp, "last_rand %s ",
+			ntable_strtime_delta(ndtc->ndtc_last_rand));
+
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "        ");
+
+		fprintf(fp, "hash_rnd %u ", ndtc->ndtc_hash_rnd);
+		fprintf(fp, "hash_mask %08x ", ndtc->ndtc_hash_mask);
+
+		fprintf(fp, "hash_chain_gc %u ", ndtc->ndtc_hash_chain_gc);
+		fprintf(fp, "proxy_qlen %u ", ndtc->ndtc_proxy_qlen);
+
+		fprintf(fp, "%s", _SL_);
+	}
+
+	if (tb[NDTA_PARMS]) {
+		if (tpb[NDTPA_IFINDEX]) {
+			__u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
+
+			fprintf(fp, "    ");
+			fprintf(fp, "dev %s ", ll_index_to_name(ifindex));
+			fprintf(fp, "%s", _SL_);
+		}
+
+		fprintf(fp, "    ");
+
+		if (tpb[NDTPA_REFCNT]) {
+			__u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]);
+			fprintf(fp, "refcnt %u ", refcnt);
+		}
+		if (tpb[NDTPA_REACHABLE_TIME]) {
+			unsigned long long reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
+			fprintf(fp, "reachable %llu ", reachable);
+		}
+		if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
+			unsigned long long breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
+			fprintf(fp, "base_reachable %llu ", breachable);
+		}
+		if (tpb[NDTPA_RETRANS_TIME]) {
+			unsigned long long retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
+			fprintf(fp, "retrans %llu ", retrans);
+		}
+
+		fprintf(fp, "%s", _SL_);
+
+		fprintf(fp, "    ");
+
+		if (tpb[NDTPA_GC_STALETIME]) {
+			unsigned long long gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
+			fprintf(fp, "gc_stale %llu ", gc_stale);
+		}
+		if (tpb[NDTPA_DELAY_PROBE_TIME]) {
+			unsigned long long delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
+			fprintf(fp, "delay_probe %llu ", delay_probe);
+		}
+		if (tpb[NDTPA_QUEUE_LEN]) {
+			__u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
+			fprintf(fp, "queue %u ", queue);
+		}
+
+		fprintf(fp, "%s", _SL_);
+
+		fprintf(fp, "    ");
+
+		if (tpb[NDTPA_APP_PROBES]) {
+			__u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]);
+			fprintf(fp, "app_probes %u ", aprobe);
+		}
+		if (tpb[NDTPA_UCAST_PROBES]) {
+			__u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]);
+			fprintf(fp, "ucast_probes %u ", uprobe);
+		}
+		if (tpb[NDTPA_MCAST_PROBES]) {
+			__u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]);
+			fprintf(fp, "mcast_probes %u ", mprobe);
+		}
+
+		fprintf(fp, "%s", _SL_);
+
+		fprintf(fp, "    ");
+
+		if (tpb[NDTPA_ANYCAST_DELAY]) {
+			unsigned long long anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
+			fprintf(fp, "anycast_delay %llu ", anycast_delay);
+		}
+		if (tpb[NDTPA_PROXY_DELAY]) {
+			unsigned long long proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
+			fprintf(fp, "proxy_delay %llu ", proxy_delay);
+		}
+		if (tpb[NDTPA_PROXY_QLEN]) {
+			__u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
+			fprintf(fp, "proxy_queue %u ", pqueue);
+		}
+		if (tpb[NDTPA_LOCKTIME]) {
+			unsigned long long locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
+			fprintf(fp, "locktime %llu ", locktime);
+		}
+
+		fprintf(fp, "%s", _SL_);
+	}
+
+	if (tb[NDTA_STATS] && show_stats) {
+		struct ndt_stats *ndts = RTA_DATA(tb[NDTA_STATS]);
+
+		fprintf(fp, "    ");
+		fprintf(fp, "stats ");
+
+		fprintf(fp, "allocs %llu ",
+			(unsigned long long) ndts->ndts_allocs);
+		fprintf(fp, "destroys %llu ",
+			(unsigned long long) ndts->ndts_destroys);
+		fprintf(fp, "hash_grows %llu ",
+			(unsigned long long) ndts->ndts_hash_grows);
+
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "        ");
+
+		fprintf(fp, "res_failed %llu ",
+			(unsigned long long) ndts->ndts_res_failed);
+		fprintf(fp, "lookups %llu ",
+			(unsigned long long) ndts->ndts_lookups);
+		fprintf(fp, "hits %llu ",
+			(unsigned long long) ndts->ndts_hits);
+
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "        ");
+
+		fprintf(fp, "rcv_probes_mcast %llu ",
+			(unsigned long long) ndts->ndts_rcv_probes_mcast);
+		fprintf(fp, "rcv_probes_ucast %llu ",
+			(unsigned long long) ndts->ndts_rcv_probes_ucast);
+
+		fprintf(fp, "%s", _SL_);
+		fprintf(fp, "        ");
+
+		fprintf(fp, "periodic_gc_runs %llu ",
+			(unsigned long long) ndts->ndts_periodic_gc_runs);
+		fprintf(fp, "forced_gc_runs %llu ",
+			(unsigned long long) ndts->ndts_forced_gc_runs);
+
+		fprintf(fp, "%s", _SL_);
+	}
+
+	fprintf(fp, "\n");
+
 	fflush(fp);
-
 	return 0;
 }
 
@@ -650,24 +623,22 @@
 		} else if (strcmp(*argv, "name") == 0) {
 			NEXT_ARG();
 
-			filter.name = *argv;
+			strncpy(filter.name, *argv, sizeof(filter.name));
 		} else
 			invarg("unknown", *argv);
 
 		argc--; argv++;
 	}
 
-	if (rtnl_neightbldump_req(&rth, preferred_family) < 0) {
+	if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETNEIGHTBL) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_ntable, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		exit(1);
 	}
-	delete_json_obj();
 
 	return 0;
 }
diff --git a/ip/ipprefix.c b/ip/ipprefix.c
index 466af20..ee51f04 100644
--- a/ip/ipprefix.c
+++ b/ip/ipprefix.c
@@ -35,12 +35,12 @@
 #define IF_PREFIX_ONLINK	0x01
 #define IF_PREFIX_AUTOCONF	0x02
 
-int print_prefix(struct nlmsghdr *n, void *arg)
+int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct prefixmsg *prefix = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[RTA_MAX+1];
+	struct rtattr * tb[RTA_MAX+1];
 	int family = preferred_family;
 
 	if (n->nlmsg_type != RTM_NEWPREFIX) {
@@ -71,11 +71,22 @@
 
 	parse_rtattr(tb, RTA_MAX, RTM_RTA(prefix), len);
 
+	fprintf(fp, "prefix ");
+
 	if (tb[PREFIX_ADDRESS]) {
-		fprintf(fp, "prefix %s/%u",
-		        rt_addr_n2a_rta(family, tb[PREFIX_ADDRESS]),
-			prefix->prefix_len);
+		struct in6_addr *pfx;
+		char abuf[256];
+
+		pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
+
+		memset(abuf, '\0', sizeof(abuf));
+		fprintf(fp, "%s", rt_addr_n2a(family,
+					      RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
+					      pfx,
+					      abuf, sizeof(abuf)));
 	}
+	fprintf(fp, "/%u ", prefix->prefix_len);
+
 	fprintf(fp, "dev %s ", ll_index_to_name(prefix->prefix_ifindex));
 
 	if (prefix->prefix_flags & IF_PREFIX_ONLINK)
@@ -84,8 +95,8 @@
 		fprintf(fp, "autoconf ");
 
 	if (tb[PREFIX_CACHEINFO]) {
-		const struct prefix_cacheinfo *pc
-			 = RTA_DATA(tb[PREFIX_CACHEINFO]);
+		struct prefix_cacheinfo *pc;
+		pc = (struct prefix_cacheinfo *)RTA_DATA(tb[PREFIX_CACHEINFO]);
 
 		fprintf(fp, "valid %u ", pc->valid_time);
 		fprintf(fp, "preferred %u ", pc->preferred_time);
diff --git a/ip/iproute.c b/ip/iproute.c
index 32bb52d..7f81145 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <time.h>
@@ -28,6 +29,7 @@
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
+#include "iproute_lwtunnel.h"
 
 #ifndef RTAX_RTTVAR
 #define RTAX_RTTVAR RTAX_HOPS
@@ -39,73 +41,64 @@
 	IPROUTE_SAVE,
 };
 static const char *mx_names[RTAX_MAX+1] = {
-	[RTAX_MTU]			= "mtu",
-	[RTAX_WINDOW]			= "window",
-	[RTAX_RTT]			= "rtt",
-	[RTAX_RTTVAR]			= "rttvar",
-	[RTAX_SSTHRESH]			= "ssthresh",
-	[RTAX_CWND]			= "cwnd",
-	[RTAX_ADVMSS]			= "advmss",
-	[RTAX_REORDERING]		= "reordering",
-	[RTAX_HOPLIMIT]			= "hoplimit",
-	[RTAX_INITCWND]			= "initcwnd",
-	[RTAX_FEATURES]			= "features",
-	[RTAX_RTO_MIN]			= "rto_min",
-	[RTAX_INITRWND]			= "initrwnd",
-	[RTAX_QUICKACK]			= "quickack",
-	[RTAX_CC_ALGO]			= "congctl",
-	[RTAX_FASTOPEN_NO_COOKIE]	= "fastopen_no_cookie"
+	[RTAX_MTU]	= "mtu",
+	[RTAX_WINDOW]	= "window",
+	[RTAX_RTT]	= "rtt",
+	[RTAX_RTTVAR]	= "rttvar",
+	[RTAX_SSTHRESH] = "ssthresh",
+	[RTAX_CWND]	= "cwnd",
+	[RTAX_ADVMSS]	= "advmss",
+	[RTAX_REORDERING]="reordering",
+	[RTAX_HOPLIMIT] = "hoplimit",
+	[RTAX_INITCWND] = "initcwnd",
+	[RTAX_FEATURES] = "features",
+	[RTAX_RTO_MIN]	= "rto_min",
+	[RTAX_INITRWND]	= "initrwnd",
+	[RTAX_QUICKACK]	= "quickack",
+	[RTAX_CC_ALGO]	= "congctl",
 };
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip route { list | flush } SELECTOR\n"
-		"       ip route save SELECTOR\n"
-		"       ip route restore\n"
-		"       ip route showdump\n"
-		"       ip route get [ ROUTE_GET_FLAGS ] ADDRESS\n"
-		"                            [ from ADDRESS iif STRING ]\n"
-		"                            [ oif STRING ] [ tos TOS ]\n"
-		"                            [ mark NUMBER ] [ vrf NAME ]\n"
-		"                            [ uid NUMBER ] [ ipproto PROTOCOL ]\n"
-		"                            [ sport NUMBER ] [ dport NUMBER ]\n"
-		"       ip route { add | del | change | append | replace } ROUTE\n"
-		"SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n"
-		"            [ table TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ]\n"
-		"            [ type TYPE ] [ scope SCOPE ]\n"
-		"ROUTE := NODE_SPEC [ INFO_SPEC ]\n"
-		"NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ]\n"
-		"             [ table TABLE_ID ] [ proto RTPROTO ]\n"
-		"             [ scope SCOPE ] [ metric METRIC ]\n"
-		"             [ ttl-propagate { enabled | disabled } ]\n"
-		"INFO_SPEC := { NH | nhid ID } OPTIONS FLAGS [ nexthop NH ]...\n"
-		"NH := [ encap ENCAPTYPE ENCAPHDR ] [ via [ FAMILY ] ADDRESS ]\n"
-		"	    [ dev STRING ] [ weight NUMBER ] NHFLAGS\n"
-		"FAMILY := [ inet | inet6 | mpls | bridge | link ]\n"
-		"OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ]\n"
-		"           [ rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ]\n"
-		"           [ window NUMBER ] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n"
-		"           [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n"
-		"           [ rto_min TIME ] [ hoplimit NUMBER ] [ initrwnd NUMBER ]\n"
-		"           [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ]\n"
-		"           [ pref PREF ] [ expires TIME ] [ fastopen_no_cookie BOOL ]\n"
-		"TYPE := { unicast | local | broadcast | multicast | throw |\n"
-		"          unreachable | prohibit | blackhole | nat }\n"
-		"TABLE_ID := [ local | main | default | all | NUMBER ]\n"
-		"SCOPE := [ host | link | global | NUMBER ]\n"
-		"NHFLAGS := [ onlink | pervasive ]\n"
-		"RTPROTO := [ kernel | boot | static | NUMBER ]\n"
-		"PREF := [ low | medium | high ]\n"
-		"TIME := NUMBER[s|ms]\n"
-		"BOOL := [1|0]\n"
-		"FEATURES := ecn\n"
-		"ENCAPTYPE := [ mpls | ip | ip6 | seg6 | seg6local ]\n"
-		"ENCAPHDR := [ MPLSLABEL | SEG6HDR ]\n"
-		"SEG6HDR := [ mode SEGMODE ] segs ADDR1,ADDRi,ADDRn [hmac HMACKEYID] [cleanup]\n"
-		"SEGMODE := [ encap | inline ]\n"
-		"ROUTE_GET_FLAGS := [ fibmatch ]\n");
+	fprintf(stderr, "Usage: ip route { list | flush } SELECTOR\n");
+	fprintf(stderr, "       ip route save SELECTOR\n");
+	fprintf(stderr, "       ip route restore\n");
+	fprintf(stderr, "       ip route showdump\n");
+	fprintf(stderr, "       ip route get ADDRESS [ from ADDRESS iif STRING ]\n");
+	fprintf(stderr, "                            [ oif STRING ] [ tos TOS ]\n");
+	fprintf(stderr, "                            [ mark NUMBER ] [ uid NUMBER ]\n");
+	fprintf(stderr, "       ip route { add | del | change | append | replace } ROUTE\n");
+	fprintf(stderr, "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n");
+	fprintf(stderr, "            [ table TABLE_ID ] [ proto RTPROTO ]\n");
+	fprintf(stderr, "            [ type TYPE ] [ scope SCOPE ]\n");
+	fprintf(stderr, "ROUTE := NODE_SPEC [ INFO_SPEC ]\n");
+	fprintf(stderr, "NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ]\n");
+	fprintf(stderr, "             [ table TABLE_ID ] [ proto RTPROTO ]\n");
+	fprintf(stderr, "             [ scope SCOPE ] [ metric METRIC ]\n");
+	fprintf(stderr, "INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]...\n");
+	fprintf(stderr, "NH := [ encap ENCAPTYPE ENCAPHDR ] [ via [ FAMILY ] ADDRESS ]\n");
+	fprintf(stderr, "	    [ dev STRING ] [ weight NUMBER ] NHFLAGS\n");
+	fprintf(stderr, "FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]\n");
+	fprintf(stderr, "OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ]\n");
+	fprintf(stderr, "           [ rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ]\n");
+	fprintf(stderr, "           [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n");
+	fprintf(stderr, "           [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n");
+	fprintf(stderr, "           [ rto_min TIME ] [ hoplimit NUMBER ] [ initrwnd NUMBER ]\n");
+	fprintf(stderr, "           [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ]\n");
+	fprintf(stderr, "           [ pref PREF ] [ expires TIME ]\n");
+	fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
+	fprintf(stderr, "          unreachable | prohibit | blackhole | nat ]\n");
+	fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
+	fprintf(stderr, "SCOPE := [ host | link | global | NUMBER ]\n");
+	fprintf(stderr, "NHFLAGS := [ onlink | pervasive ]\n");
+	fprintf(stderr, "RTPROTO := [ kernel | boot | static | NUMBER ]\n");
+	fprintf(stderr, "PREF := [ low | medium | high ]\n");
+	fprintf(stderr, "TIME := NUMBER[s|ms]\n");
+	fprintf(stderr, "BOOL := [1|0]\n");
+	fprintf(stderr, "FEATURES := ecn\n");
+	fprintf(stderr, "ENCAPTYPE := [ mpls | ip | ip6 ]\n");
+	fprintf(stderr, "ENCAPHDR := [ MPLSLABEL ]\n");
 	exit(-1);
 }
 
@@ -120,13 +113,12 @@
 	int flushe;
 	int protocol, protocolmask;
 	int scope, scopemask;
-	__u64 typemask;
+	int type, typemask;
 	int tos, tosmask;
 	int iif, iifmask;
 	int oif, oifmask;
 	int mark, markmask;
 	int realm, realmmask;
-	__u32 metric, metricmask;
 	inet_prefix rprefsrc;
 	inet_prefix rvia;
 	inet_prefix rdst;
@@ -139,7 +131,7 @@
 {
 	if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) {
 		perror("Failed to send flush request");
-		return -2;
+		return -1;
 	}
 	filter.flushp = 0;
 	return 0;
@@ -148,10 +140,10 @@
 static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
 {
 	struct rtmsg *r = NLMSG_DATA(n);
-	inet_prefix dst = { .family = r->rtm_family };
-	inet_prefix src = { .family = r->rtm_family };
-	inet_prefix via = { .family = r->rtm_family };
-	inet_prefix prefsrc = { .family = r->rtm_family };
+	inet_prefix dst;
+	inet_prefix src;
+	inet_prefix via;
+	inet_prefix prefsrc;
 	__u32 table;
 	static int ip6_multiple_tables;
 
@@ -163,7 +155,7 @@
 	if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN)
 		ip6_multiple_tables = 1;
 
-	if (filter.cloned == !(r->rtm_flags & RTM_F_CLONED))
+	if (filter.cloned == !(r->rtm_flags&RTM_F_CLONED))
 		return 0;
 
 	if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) {
@@ -186,53 +178,28 @@
 		return 0;
 	if ((filter.scope^r->rtm_scope)&filter.scopemask)
 		return 0;
-
-	if (filter.typemask && !(filter.typemask & (1 << r->rtm_type)))
+	if ((filter.type^r->rtm_type)&filter.typemask)
 		return 0;
 	if ((filter.tos^r->rtm_tos)&filter.tosmask)
 		return 0;
-	if (filter.rdst.family) {
-		if (r->rtm_family != filter.rdst.family ||
-		    filter.rdst.bitlen > r->rtm_dst_len)
-			return 0;
-	} else if (filter.rdst.flags & PREFIXLEN_SPECIFIED) {
-		if (filter.rdst.bitlen > r->rtm_dst_len)
-			return 0;
-	}
-	if (filter.mdst.family) {
-		if (r->rtm_family != filter.mdst.family ||
-		    (filter.mdst.bitlen >= 0 &&
-		     filter.mdst.bitlen < r->rtm_dst_len))
-			return 0;
-	} else if (filter.mdst.flags & PREFIXLEN_SPECIFIED) {
-		if (filter.mdst.bitlen >= 0 &&
-		    filter.mdst.bitlen < r->rtm_dst_len)
-			return 0;
-	}
-	if (filter.rsrc.family) {
-		if (r->rtm_family != filter.rsrc.family ||
-		    filter.rsrc.bitlen > r->rtm_src_len)
-			return 0;
-	} else if (filter.rsrc.flags & PREFIXLEN_SPECIFIED) {
-		if (filter.rsrc.bitlen > r->rtm_src_len)
-			return 0;
-	}
-	if (filter.msrc.family) {
-		if (r->rtm_family != filter.msrc.family ||
-		    (filter.msrc.bitlen >= 0 &&
-		     filter.msrc.bitlen < r->rtm_src_len))
-			return 0;
-	} else if (filter.msrc.flags & PREFIXLEN_SPECIFIED) {
-		if (filter.msrc.bitlen >= 0 &&
-		    filter.msrc.bitlen < r->rtm_src_len)
-			return 0;
-	}
+	if (filter.rdst.family &&
+	    (r->rtm_family != filter.rdst.family || filter.rdst.bitlen > r->rtm_dst_len))
+		return 0;
+	if (filter.mdst.family &&
+	    (r->rtm_family != filter.mdst.family ||
+	     (filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len)))
+		return 0;
+	if (filter.rsrc.family &&
+	    (r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > r->rtm_src_len))
+		return 0;
+	if (filter.msrc.family &&
+	    (r->rtm_family != filter.msrc.family ||
+	     (filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len)))
+		return 0;
 	if (filter.rvia.family) {
 		int family = r->rtm_family;
-
 		if (tb[RTA_VIA]) {
 			struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
-
 			family = via->rtvia_family;
 		}
 		if (family != filter.rvia.family)
@@ -241,42 +208,44 @@
 	if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family)
 		return 0;
 
+	memset(&dst, 0, sizeof(dst));
+	dst.family = r->rtm_family;
 	if (tb[RTA_DST])
 		memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8);
-	if (filter.rsrc.family || filter.msrc.family ||
-	    filter.rsrc.flags & PREFIXLEN_SPECIFIED ||
-	    filter.msrc.flags & PREFIXLEN_SPECIFIED) {
+	if (filter.rsrc.family || filter.msrc.family) {
+		memset(&src, 0, sizeof(src));
+		src.family = r->rtm_family;
 		if (tb[RTA_SRC])
 			memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8);
 	}
-	if (filter.rvia.bitlen > 0) {
+	if (filter.rvia.bitlen>0) {
+		memset(&via, 0, sizeof(via));
+		via.family = r->rtm_family;
 		if (tb[RTA_GATEWAY])
 			memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
 		if (tb[RTA_VIA]) {
 			size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
 			struct rtvia *rtvia = RTA_DATA(tb[RTA_VIA]);
-
 			via.family = rtvia->rtvia_family;
 			memcpy(&via.data, rtvia->rtvia_addr, len);
 		}
 	}
-	if (filter.rprefsrc.bitlen > 0) {
+	if (filter.rprefsrc.bitlen>0) {
+		memset(&prefsrc, 0, sizeof(prefsrc));
+		prefsrc.family = r->rtm_family;
 		if (tb[RTA_PREFSRC])
 			memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8);
 	}
 
-	if ((filter.rdst.family || filter.rdst.flags & PREFIXLEN_SPECIFIED) &&
-	    inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen))
+	if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen))
 		return 0;
-	if ((filter.mdst.family || filter.mdst.flags & PREFIXLEN_SPECIFIED) &&
+	if (filter.mdst.family && filter.mdst.bitlen >= 0 &&
 	    inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len))
 		return 0;
 
-	if ((filter.rsrc.family || filter.rsrc.flags & PREFIXLEN_SPECIFIED) &&
-	    inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen))
+	if (filter.rsrc.family && inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen))
 		return 0;
-	if ((filter.msrc.family || filter.msrc.flags & PREFIXLEN_SPECIFIED) &&
-	    filter.msrc.bitlen >= 0 &&
+	if (filter.msrc.family && filter.msrc.bitlen >= 0 &&
 	    inet_addr_match(&src, &filter.msrc, r->rtm_src_len))
 		return 0;
 
@@ -286,7 +255,6 @@
 		return 0;
 	if (filter.realmmask) {
 		__u32 realms = 0;
-
 		if (tb[RTA_FLOW])
 			realms = rta_getattr_u32(tb[RTA_FLOW]);
 		if ((realms^filter.realm)&filter.realmmask)
@@ -294,42 +262,31 @@
 	}
 	if (filter.iifmask) {
 		int iif = 0;
-
 		if (tb[RTA_IIF])
-			iif = rta_getattr_u32(tb[RTA_IIF]);
+			iif = *(int*)RTA_DATA(tb[RTA_IIF]);
 		if ((iif^filter.iif)&filter.iifmask)
 			return 0;
 	}
 	if (filter.oifmask) {
 		int oif = 0;
-
 		if (tb[RTA_OIF])
-			oif = rta_getattr_u32(tb[RTA_OIF]);
+			oif = *(int*)RTA_DATA(tb[RTA_OIF]);
 		if ((oif^filter.oif)&filter.oifmask)
 			return 0;
 	}
 	if (filter.markmask) {
 		int mark = 0;
-
 		if (tb[RTA_MARK])
-			mark = rta_getattr_u32(tb[RTA_MARK]);
+			mark = *(int *)RTA_DATA(tb[RTA_MARK]);
 		if ((mark ^ filter.mark) & filter.markmask)
 			return 0;
 	}
-	if (filter.metricmask) {
-		__u32 metric = 0;
-
-		if (tb[RTA_PRIORITY])
-			metric = rta_getattr_u32(tb[RTA_PRIORITY]);
-		if ((metric ^ filter.metric) & filter.metricmask)
-			return 0;
-	}
 	if (filter.flushb &&
 	    r->rtm_family == AF_INET6 &&
 	    r->rtm_dst_len == 0 &&
 	    r->rtm_type == RTN_UNREACHABLE &&
 	    tb[RTA_PRIORITY] &&
-	    rta_getattr_u32(tb[RTA_PRIORITY]) == -1)
+	    *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1)
 		return 0;
 
 	return 1;
@@ -340,399 +297,30 @@
 	unsigned int of = features;
 
 	if (features & RTAX_FEATURE_ECN) {
-		print_null(PRINT_ANY, "ecn", "ecn ", NULL);
+		fprintf(fp, " ecn");
 		features &= ~RTAX_FEATURE_ECN;
 	}
 
 	if (features)
-		print_0xhex(PRINT_ANY,
-			    "features", "%#llx ", of);
+		fprintf(fp, " 0x%x", of);
 }
 
-void print_rt_flags(FILE *fp, unsigned int flags)
+int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
-	open_json_array(PRINT_JSON,
-			is_json_context() ?  "flags" : "");
-
-	if (flags & RTNH_F_DEAD)
-		print_string(PRINT_ANY, NULL, "%s ", "dead");
-	if (flags & RTNH_F_ONLINK)
-		print_string(PRINT_ANY, NULL, "%s ", "onlink");
-	if (flags & RTNH_F_PERVASIVE)
-		print_string(PRINT_ANY, NULL, "%s ", "pervasive");
-	if (flags & RTNH_F_OFFLOAD)
-		print_string(PRINT_ANY, NULL, "%s ", "offload");
-	if (flags & RTM_F_NOTIFY)
-		print_string(PRINT_ANY, NULL, "%s ", "notify");
-	if (flags & RTNH_F_LINKDOWN)
-		print_string(PRINT_ANY, NULL, "%s ", "linkdown");
-	if (flags & RTNH_F_UNRESOLVED)
-		print_string(PRINT_ANY, NULL, "%s ", "unresolved");
-
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void print_rt_pref(FILE *fp, unsigned int pref)
-{
-
-	switch (pref) {
-	case ICMPV6_ROUTER_PREF_LOW:
-		print_string(PRINT_ANY,
-			     "pref", "pref %s", "low");
-		break;
-	case ICMPV6_ROUTER_PREF_MEDIUM:
-		print_string(PRINT_ANY,
-			     "pref", "pref %s", "medium");
-		break;
-	case ICMPV6_ROUTER_PREF_HIGH:
-		print_string(PRINT_ANY,
-			     "pref", "pref %s", "high");
-		break;
-	default:
-		print_uint(PRINT_ANY,
-			   "pref", "%u", pref);
-	}
-}
-
-void print_rta_if(FILE *fp, const struct rtattr *rta, const char *prefix)
-{
-	const char *ifname = ll_index_to_name(rta_getattr_u32(rta));
-
-	if (is_json_context())
-		print_string(PRINT_JSON, prefix, NULL, ifname);
-	else {
-		fprintf(fp, "%s ", prefix);
-		color_fprintf(fp, COLOR_IFNAME, "%s ", ifname);
-	}
-}
-
-static void print_cache_flags(FILE *fp, __u32 flags)
-{
-	json_writer_t *jw = get_json_writer();
-	flags &= ~0xFFFF;
-
-	if (jw) {
-		jsonw_name(jw, "cache");
-		jsonw_start_array(jw);
-	} else {
-		fprintf(fp, "%s    cache ", _SL_);
-		if (flags == 0)
-			return;
-		putc('<', fp);
-	}
-
-#define PRTFL(fl, flname)						\
-	if (flags & RTCF_##fl) {					\
-		flags &= ~RTCF_##fl;					\
-		if (jw)							\
-			jsonw_string(jw, flname);			\
-		else							\
-			fprintf(fp, "%s%s", flname, flags ? "," : "> "); \
-	}
-
-	PRTFL(LOCAL, "local");
-	PRTFL(REJECT, "reject");
-	PRTFL(MULTICAST, "mc");
-	PRTFL(BROADCAST, "brd");
-	PRTFL(DNAT, "dst-nat");
-	PRTFL(SNAT, "src-nat");
-	PRTFL(MASQ, "masq");
-	PRTFL(DIRECTDST, "dst-direct");
-	PRTFL(DIRECTSRC, "src-direct");
-	PRTFL(REDIRECTED, "redirected");
-	PRTFL(DOREDIRECT, "redirect");
-	PRTFL(FAST, "fastroute");
-	PRTFL(NOTIFY, "notify");
-	PRTFL(TPROXY, "proxy");
-#undef PRTFL
-
-	if (flags)
-		print_hex(PRINT_ANY, "flags", "%x>", flags);
-
-	if (jw)
-		jsonw_end_array(jw);
-}
-
-static void print_rta_cacheinfo(FILE *fp, const struct rta_cacheinfo *ci)
-{
-	static int hz;
-
-	if (!hz)
-		hz = get_user_hz();
-
-	if (ci->rta_expires != 0)
-		print_int(PRINT_ANY, "expires",
-			   "expires %dsec ", ci->rta_expires/hz);
-	if (ci->rta_error != 0)
-		print_uint(PRINT_ANY, "error",
-			   "error %u ", ci->rta_error);
-
-	if (show_stats) {
-		if (ci->rta_clntref)
-			print_uint(PRINT_ANY, "users",
-				   "users %u ", ci->rta_clntref);
-		if (ci->rta_used != 0)
-			print_uint(PRINT_ANY, "used",
-				   "used %u ", ci->rta_used);
-		if (ci->rta_lastuse != 0)
-			print_uint(PRINT_ANY, "age",
-				   "age %usec ", ci->rta_lastuse/hz);
-	}
-	if (ci->rta_id)
-		print_0xhex(PRINT_ANY, "ipid",
-			    "ipid 0x%04llx ", ci->rta_id);
-	if (ci->rta_ts || ci->rta_tsage) {
-		print_0xhex(PRINT_ANY, "ts",
-			    "ts 0x%llx", ci->rta_ts);
-		print_uint(PRINT_ANY, "tsage",
-			   "tsage %usec ", ci->rta_tsage);
-	}
-}
-
-static void print_rta_flow(FILE *fp, const struct rtattr *rta)
-{
-	__u32 to = rta_getattr_u32(rta);
-	__u32 from = to >> 16;
-	SPRINT_BUF(b1);
-
-	to &= 0xFFFF;
-	if (is_json_context()) {
-		open_json_object("flow");
-
-		if (from)
-			print_string(PRINT_JSON, "from", NULL,
-				     rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
-		print_string(PRINT_JSON, "to", NULL,
-			     rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
-		close_json_object();
-	} else {
-		fprintf(fp, "realm%s ", from ? "s" : "");
-
-		if (from)
-			print_string(PRINT_FP, NULL, "%s/",
-				     rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
-		print_string(PRINT_FP, NULL, "%s ",
-			     rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
-	}
-}
-
-static void print_rta_newdst(FILE *fp, const struct rtmsg *r,
-			     const struct rtattr *rta)
-{
-	const char *newdst = format_host_rta(r->rtm_family, rta);
-
-	if (is_json_context())
-		print_string(PRINT_JSON, "to", NULL, newdst);
-	else {
-		fprintf(fp, "as to ");
-		print_color_string(PRINT_FP,
-				   ifa_family_color(r->rtm_family),
-				   NULL, "%s ", newdst);
-	}
-}
-
-void print_rta_gateway(FILE *fp, unsigned char family, const struct rtattr *rta)
-{
-	const char *gateway = format_host_rta(family, rta);
-
-	if (is_json_context())
-		print_string(PRINT_JSON, "gateway", NULL, gateway);
-	else {
-		fprintf(fp, "via ");
-		print_color_string(PRINT_FP,
-				   ifa_family_color(family),
-				   NULL, "%s ", gateway);
-	}
-}
-
-static void print_rta_via(FILE *fp, const struct rtattr *rta)
-{
-	size_t len = RTA_PAYLOAD(rta) - 2;
-	const struct rtvia *via = RTA_DATA(rta);
-
-	if (is_json_context()) {
-		open_json_object("via");
-		print_string(PRINT_JSON, "family", NULL,
-			     family_name(via->rtvia_family));
-		print_string(PRINT_JSON, "host", NULL,
-			     format_host(via->rtvia_family, len,
-					 via->rtvia_addr));
-		close_json_object();
-	} else {
-		print_string(PRINT_FP, NULL, "via %s ",
-			     family_name(via->rtvia_family));
-		print_color_string(PRINT_FP,
-				   ifa_family_color(via->rtvia_family),
-				   NULL, "%s ",
-				   format_host(via->rtvia_family,
-					       len, via->rtvia_addr));
-	}
-}
-
-static void print_rta_metrics(FILE *fp, const struct rtattr *rta)
-{
-	struct rtattr *mxrta[RTAX_MAX+1];
-	unsigned int mxlock = 0;
-	int i;
-
-	open_json_array(PRINT_JSON, "metrics");
-	open_json_object(NULL);
-
-	parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(rta), RTA_PAYLOAD(rta));
-
-	if (mxrta[RTAX_LOCK])
-		mxlock = rta_getattr_u32(mxrta[RTAX_LOCK]);
-
-	for (i = 2; i <= RTAX_MAX; i++) {
-		__u32 val = 0U;
-
-		if (mxrta[i] == NULL && !(mxlock & (1 << i)))
-			continue;
-
-		if (mxrta[i] != NULL && i != RTAX_CC_ALGO)
-			val = rta_getattr_u32(mxrta[i]);
-
-		if (i == RTAX_HOPLIMIT && (int)val == -1)
-			continue;
-
-		if (!is_json_context()) {
-			if (i < sizeof(mx_names)/sizeof(char *) && mx_names[i])
-				fprintf(fp, "%s ", mx_names[i]);
-			else
-				fprintf(fp, "metric %d ", i);
-
-			if (mxlock & (1<<i))
-				fprintf(fp, "lock ");
-		}
-
-		switch (i) {
-		case RTAX_FEATURES:
-			print_rtax_features(fp, val);
-			break;
-		default:
-			print_uint(PRINT_ANY, mx_names[i], "%u ", val);
-			break;
-
-		case RTAX_RTT:
-		case RTAX_RTTVAR:
-		case RTAX_RTO_MIN:
-			if (i == RTAX_RTT)
-				val /= 8;
-			else if (i == RTAX_RTTVAR)
-				val /= 4;
-
-			if (is_json_context())
-				print_uint(PRINT_JSON, mx_names[i],
-					   NULL, val);
-			else {
-				if (val >= 1000)
-					fprintf(fp, "%gs ", val/1e3);
-				else
-					fprintf(fp, "%ums ", val);
-			}
-			break;
-		case RTAX_CC_ALGO:
-			print_string(PRINT_ANY, "congestion",
-				     "%s ", rta_getattr_str(mxrta[i]));
-			break;
-		}
-	}
-
-	close_json_object();
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void print_rta_multipath(FILE *fp, const struct rtmsg *r,
-				struct rtattr *rta)
-{
-	const struct rtnexthop *nh = RTA_DATA(rta);
-	int len = RTA_PAYLOAD(rta);
-	int first = 1;
-
-	open_json_array(PRINT_JSON, "nexthops");
-
-	while (len >= sizeof(*nh)) {
-		struct rtattr *tb[RTA_MAX + 1];
-
-		if (nh->rtnh_len > len)
-			break;
-
-		open_json_object(NULL);
-
-		if ((r->rtm_flags & RTM_F_CLONED) &&
-		    r->rtm_type == RTN_MULTICAST) {
-			if (first) {
-				print_string(PRINT_FP, NULL, "Oifs: ", NULL);
-				first = 0;
-			} else {
-				print_string(PRINT_FP, NULL, " ", NULL);
-			}
-		} else
-			print_string(PRINT_FP, NULL, "%s\tnexthop ", _SL_);
-
-		if (nh->rtnh_len > sizeof(*nh)) {
-			parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh),
-				     nh->rtnh_len - sizeof(*nh));
-
-			if (tb[RTA_ENCAP])
-				lwt_print_encap(fp,
-						tb[RTA_ENCAP_TYPE],
-						tb[RTA_ENCAP]);
-			if (tb[RTA_NEWDST])
-				print_rta_newdst(fp, r, tb[RTA_NEWDST]);
-			if (tb[RTA_GATEWAY])
-				print_rta_gateway(fp, r->rtm_family,
-						  tb[RTA_GATEWAY]);
-			if (tb[RTA_VIA])
-				print_rta_via(fp, tb[RTA_VIA]);
-			if (tb[RTA_FLOW])
-				print_rta_flow(fp, tb[RTA_FLOW]);
-		}
-
-		if ((r->rtm_flags & RTM_F_CLONED) &&
-		    r->rtm_type == RTN_MULTICAST) {
-			print_string(PRINT_ANY, "dev",
-				     "%s", ll_index_to_name(nh->rtnh_ifindex));
-
-			if (nh->rtnh_hops != 1)
-				print_int(PRINT_ANY, "ttl", "(ttl>%d)", nh->rtnh_hops);
-
-			print_string(PRINT_FP, NULL, " ", NULL);
-		} else {
-			print_string(PRINT_ANY, "dev",
-				     "dev %s ", ll_index_to_name(nh->rtnh_ifindex));
-
-			if (r->rtm_family != AF_MPLS)
-				print_int(PRINT_ANY, "weight",
-					  "weight %d ", nh->rtnh_hops + 1);
-		}
-
-		print_rt_flags(fp, nh->rtnh_flags);
-
-		len -= NLMSG_ALIGN(nh->rtnh_len);
-		nh = RTNH_NEXT(nh);
-
-		close_json_object();
-	}
-	close_json_array(PRINT_JSON, NULL);
-}
-
-int print_route(struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct rtmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[RTA_MAX+1];
-	int family, color, host_len;
+	struct rtattr * tb[RTA_MAX+1];
+	char abuf[256];
+	int host_len;
 	__u32 table;
-	int ret;
-
 	SPRINT_BUF(b1);
+	static int hz;
 
 	if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
 		fprintf(stderr, "Not a route: %08x %08x %08x\n",
 			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
-		return -1;
+		return 0;
 	}
 	if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE)
 		return 0;
@@ -752,209 +340,390 @@
 
 	if (filter.flushb) {
 		struct nlmsghdr *fn;
-
 		if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
-			ret = flush_update();
-			if (ret < 0)
-				return ret;
+			if (flush_update())
+				return -1;
 		}
-		fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
+		fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp));
 		memcpy(fn, n, n->nlmsg_len);
 		fn->nlmsg_type = RTM_DELROUTE;
 		fn->nlmsg_flags = NLM_F_REQUEST;
 		fn->nlmsg_seq = ++rth.seq;
-		filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
+		filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
 		filter.flushed++;
 		if (show_stats < 2)
 			return 0;
 	}
 
-	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELROUTE)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
+	if ((r->rtm_type != RTN_UNICAST || show_details > 0) && !filter.type)
+		fprintf(fp, "%s ", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
 
-	if ((r->rtm_type != RTN_UNICAST || show_details > 0) &&
-	    (!filter.typemask || (filter.typemask & (1 << r->rtm_type))))
-		print_string(PRINT_ANY, "type", "%s ",
-			     rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
-
-	color = COLOR_NONE;
 	if (tb[RTA_DST]) {
-		family = get_real_family(r->rtm_type, r->rtm_family);
-		color = ifa_family_color(family);
-
 		if (r->rtm_dst_len != host_len) {
-			snprintf(b1, sizeof(b1),
-				 "%s/%u", rt_addr_n2a_rta(family, tb[RTA_DST]),
-				 r->rtm_dst_len);
+			fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
+						       RTA_PAYLOAD(tb[RTA_DST]),
+						       RTA_DATA(tb[RTA_DST]),
+						       abuf, sizeof(abuf)),
+				r->rtm_dst_len
+				);
 		} else {
-			format_host_rta_r(family, tb[RTA_DST],
-					  b1, sizeof(b1));
-
+			fprintf(fp, "%s ", format_host(r->rtm_family,
+						       RTA_PAYLOAD(tb[RTA_DST]),
+						       RTA_DATA(tb[RTA_DST]),
+						       abuf, sizeof(abuf))
+				);
 		}
 	} else if (r->rtm_dst_len) {
-		snprintf(b1, sizeof(b1), "0/%d ", r->rtm_dst_len);
+		fprintf(fp, "0/%d ", r->rtm_dst_len);
 	} else {
-		strncpy(b1, "default", sizeof(b1));
+		fprintf(fp, "default ");
 	}
-	print_color_string(PRINT_ANY, color,
-			   "dst", "%s ", b1);
-
 	if (tb[RTA_SRC]) {
-		family = get_real_family(r->rtm_type, r->rtm_family);
-		color = ifa_family_color(family);
-
 		if (r->rtm_src_len != host_len) {
-			snprintf(b1, sizeof(b1),
-				 "%s/%u",
-				 rt_addr_n2a_rta(family, tb[RTA_SRC]),
-				 r->rtm_src_len);
+			fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
+						       RTA_PAYLOAD(tb[RTA_SRC]),
+						       RTA_DATA(tb[RTA_SRC]),
+						       abuf, sizeof(abuf)),
+				r->rtm_src_len
+				);
 		} else {
-			format_host_rta_r(family, tb[RTA_SRC],
-					  b1, sizeof(b1));
+			fprintf(fp, "from %s ", format_host(r->rtm_family,
+						       RTA_PAYLOAD(tb[RTA_SRC]),
+						       RTA_DATA(tb[RTA_SRC]),
+						       abuf, sizeof(abuf))
+				);
 		}
-		print_color_string(PRINT_ANY, color,
-				   "from", "from %s ", b1);
 	} else if (r->rtm_src_len) {
-		snprintf(b1, sizeof(b1), "0/%u", r->rtm_src_len);
-
-		print_string(PRINT_ANY, "src", "from %s ", b1);
+		fprintf(fp, "from 0/%u ", r->rtm_src_len);
 	}
-
-	if (tb[RTA_NH_ID])
-		print_uint(PRINT_ANY, "nhid", "nhid %u ",
-			   rta_getattr_u32(tb[RTA_NH_ID]));
-
-	if (tb[RTA_NEWDST])
-		print_rta_newdst(fp, r, tb[RTA_NEWDST]);
+	if (tb[RTA_NEWDST]) {
+		fprintf(fp, "as to %s ", format_host(r->rtm_family,
+						  RTA_PAYLOAD(tb[RTA_NEWDST]),
+						  RTA_DATA(tb[RTA_NEWDST]),
+						  abuf, sizeof(abuf))
+			);
+	}
 
 	if (tb[RTA_ENCAP])
 		lwt_print_encap(fp, tb[RTA_ENCAP_TYPE], tb[RTA_ENCAP]);
 
 	if (r->rtm_tos && filter.tosmask != -1) {
-		print_string(PRINT_ANY, "tos", "tos %s ",
-			     rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
+		SPRINT_BUF(b1);
+		fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
 	}
 
-	if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len)
-		print_rta_gateway(fp, r->rtm_family, tb[RTA_GATEWAY]);
-
-	if (tb[RTA_VIA])
-		print_rta_via(fp, tb[RTA_VIA]);
-
+	if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) {
+		fprintf(fp, "via %s ",
+			format_host(r->rtm_family,
+				    RTA_PAYLOAD(tb[RTA_GATEWAY]),
+				    RTA_DATA(tb[RTA_GATEWAY]),
+				    abuf, sizeof(abuf)));
+	}
+	if (tb[RTA_VIA]) {
+		size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
+		struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
+		fprintf(fp, "via %s %s ",
+			family_name(via->rtvia_family),
+			format_host(via->rtvia_family, len, via->rtvia_addr,
+				    abuf, sizeof(abuf)));
+	}
 	if (tb[RTA_OIF] && filter.oifmask != -1)
-		print_rta_if(fp, tb[RTA_OIF], "dev");
+		fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
 
 	if (table && (table != RT_TABLE_MAIN || show_details > 0) && !filter.tb)
-		print_string(PRINT_ANY,
-			     "table", "table %s ",
-			     rtnl_rttable_n2a(table, b1, sizeof(b1)));
-
-	if (!(r->rtm_flags & RTM_F_CLONED)) {
-		if ((r->rtm_protocol != RTPROT_BOOT || show_details > 0) &&
-		    filter.protocolmask != -1)
-			print_string(PRINT_ANY,
-				     "protocol", "proto %s ",
-				     rtnl_rtprot_n2a(r->rtm_protocol,
-						     b1, sizeof(b1)));
-
-		if ((r->rtm_scope != RT_SCOPE_UNIVERSE || show_details > 0) &&
-		    filter.scopemask != -1)
-			print_string(PRINT_ANY,
-				     "scope", "scope %s ",
-				     rtnl_rtscope_n2a(r->rtm_scope,
-						      b1, sizeof(b1)));
+		fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
+	if (!(r->rtm_flags&RTM_F_CLONED)) {
+		if ((r->rtm_protocol != RTPROT_BOOT || show_details > 0) && filter.protocolmask != -1)
+			fprintf(fp, " proto %s ", rtnl_rtprot_n2a(r->rtm_protocol, b1, sizeof(b1)));
+		if ((r->rtm_scope != RT_SCOPE_UNIVERSE || show_details > 0) && filter.scopemask != -1)
+			fprintf(fp, " scope %s ", rtnl_rtscope_n2a(r->rtm_scope, b1, sizeof(b1)));
 	}
-
 	if (tb[RTA_PREFSRC] && filter.rprefsrc.bitlen != host_len) {
-		const char *psrc
-			= rt_addr_n2a_rta(r->rtm_family, tb[RTA_PREFSRC]);
-
 		/* Do not use format_host(). It is our local addr
 		   and symbolic name will not be useful.
-		*/
-		if (is_json_context())
-			print_string(PRINT_JSON, "prefsrc", NULL, psrc);
-		else {
-			fprintf(fp, "src ");
-			print_color_string(PRINT_FP,
-					   ifa_family_color(r->rtm_family),
-					   NULL, "%s ", psrc);
-		}
-
+		 */
+		fprintf(fp, " src %s ",
+			rt_addr_n2a(r->rtm_family,
+				    RTA_PAYLOAD(tb[RTA_PREFSRC]),
+				    RTA_DATA(tb[RTA_PREFSRC]),
+				    abuf, sizeof(abuf)));
 	}
-
-	if (tb[RTA_PRIORITY] && filter.metricmask != -1)
-		print_uint(PRINT_ANY, "metric", "metric %u ",
-			   rta_getattr_u32(tb[RTA_PRIORITY]));
-
-	print_rt_flags(fp, r->rtm_flags);
-
+	if (tb[RTA_PRIORITY])
+		fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
+	if (r->rtm_flags & RTNH_F_DEAD)
+		fprintf(fp, "dead ");
+	if (r->rtm_flags & RTNH_F_ONLINK)
+		fprintf(fp, "onlink ");
+	if (r->rtm_flags & RTNH_F_PERVASIVE)
+		fprintf(fp, "pervasive ");
+	if (r->rtm_flags & RTNH_F_OFFLOAD)
+		fprintf(fp, "offload ");
+	if (r->rtm_flags & RTM_F_NOTIFY)
+		fprintf(fp, "notify ");
+	if (r->rtm_flags & RTNH_F_LINKDOWN)
+		fprintf(fp, "linkdown ");
 	if (tb[RTA_MARK]) {
-		unsigned int mark = rta_getattr_u32(tb[RTA_MARK]);
-
+		unsigned int mark = *(unsigned int*)RTA_DATA(tb[RTA_MARK]);
 		if (mark) {
-			if (is_json_context())
-				print_uint(PRINT_JSON, "mark", NULL, mark);
-			else if (mark >= 16)
-				print_0xhex(PRINT_FP, NULL,
-					    "mark 0x%llx ", mark);
+			if (mark >= 16)
+				fprintf(fp, " mark 0x%x", mark);
 			else
-				print_uint(PRINT_FP, NULL,
-					   "mark %u ", mark);
+				fprintf(fp, " mark %u", mark);
 		}
 	}
 
-	if (tb[RTA_FLOW] && filter.realmmask != ~0U)
-		print_rta_flow(fp, tb[RTA_FLOW]);
+	if (tb[RTA_FLOW] && filter.realmmask != ~0U) {
+		__u32 to = rta_getattr_u32(tb[RTA_FLOW]);
+		__u32 from = to>>16;
+		to &= 0xFFFF;
+		fprintf(fp, "realm%s ", from ? "s" : "");
+		if (from) {
+			fprintf(fp, "%s/",
+				rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
+		}
+		fprintf(fp, "%s ",
+			rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
+	}
 
 	if (tb[RTA_UID])
-		print_uint(PRINT_ANY, "uid", "uid %u ",
-			   rta_getattr_u32(tb[RTA_UID]));
+		fprintf(fp, "uid %u ", rta_getattr_u32(tb[RTA_UID]));
 
-	if (r->rtm_family == AF_INET) {
-		if (r->rtm_flags & RTM_F_CLONED)
-			print_cache_flags(fp, r->rtm_flags);
+	if ((r->rtm_flags&RTM_F_CLONED) && r->rtm_family == AF_INET) {
+		__u32 flags = r->rtm_flags&~0xFFFF;
+		int first = 1;
 
-		if (tb[RTA_CACHEINFO])
-			print_rta_cacheinfo(fp, RTA_DATA(tb[RTA_CACHEINFO]));
+		fprintf(fp, "%s    cache ", _SL_);
+
+#define PRTFL(fl,flname) if (flags&RTCF_##fl) { \
+  flags &= ~RTCF_##fl; \
+  fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \
+  first = 0; }
+		PRTFL(LOCAL, "local");
+		PRTFL(REJECT, "reject");
+		PRTFL(MULTICAST, "mc");
+		PRTFL(BROADCAST, "brd");
+		PRTFL(DNAT, "dst-nat");
+		PRTFL(SNAT, "src-nat");
+		PRTFL(MASQ, "masq");
+		PRTFL(DIRECTDST, "dst-direct");
+		PRTFL(DIRECTSRC, "src-direct");
+		PRTFL(REDIRECTED, "redirected");
+		PRTFL(DOREDIRECT, "redirect");
+		PRTFL(FAST, "fastroute");
+		PRTFL(NOTIFY, "notify");
+		PRTFL(TPROXY, "proxy");
+
+		if (flags)
+			fprintf(fp, "%s%x> ", first ? "<" : "", flags);
+		if (tb[RTA_CACHEINFO]) {
+			struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
+			if (!hz)
+				hz = get_user_hz();
+			if (ci->rta_expires != 0)
+				fprintf(fp, " expires %dsec", ci->rta_expires/hz);
+			if (ci->rta_error != 0)
+				fprintf(fp, " error %d", ci->rta_error);
+			if (show_stats) {
+				if (ci->rta_clntref)
+					fprintf(fp, " users %d", ci->rta_clntref);
+				if (ci->rta_used != 0)
+					fprintf(fp, " used %d", ci->rta_used);
+				if (ci->rta_lastuse != 0)
+					fprintf(fp, " age %dsec", ci->rta_lastuse/hz);
+			}
+			if (ci->rta_id)
+				fprintf(fp, " ipid 0x%04x", ci->rta_id);
+			if (ci->rta_ts || ci->rta_tsage)
+				fprintf(fp, " ts 0x%x tsage %dsec",
+					ci->rta_ts, ci->rta_tsage);
+		}
 	} else if (r->rtm_family == AF_INET6) {
+		struct rta_cacheinfo *ci = NULL;
 		if (tb[RTA_CACHEINFO])
-			print_rta_cacheinfo(fp, RTA_DATA(tb[RTA_CACHEINFO]));
+			ci = RTA_DATA(tb[RTA_CACHEINFO]);
+		if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) {
+			if (!hz)
+				hz = get_user_hz();
+			if (r->rtm_flags & RTM_F_CLONED)
+				fprintf(fp, "%s    cache ", _SL_);
+			if (ci->rta_expires)
+				fprintf(fp, " expires %dsec", ci->rta_expires/hz);
+			if (ci->rta_error != 0)
+				fprintf(fp, " error %d", ci->rta_error);
+			if (show_stats) {
+				if (ci->rta_clntref)
+					fprintf(fp, " users %d", ci->rta_clntref);
+				if (ci->rta_used != 0)
+					fprintf(fp, " used %d", ci->rta_used);
+				if (ci->rta_lastuse != 0)
+					fprintf(fp, " age %dsec", ci->rta_lastuse/hz);
+			}
+		} else if (ci) {
+			if (ci->rta_error != 0)
+				fprintf(fp, " error %d", ci->rta_error);
+		}
 	}
+	if (tb[RTA_METRICS]) {
+		int i;
+		unsigned mxlock = 0;
+		struct rtattr *mxrta[RTAX_MAX+1];
 
-	if (tb[RTA_METRICS])
-		print_rta_metrics(fp, tb[RTA_METRICS]);
+		parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
+			    RTA_PAYLOAD(tb[RTA_METRICS]));
+		if (mxrta[RTAX_LOCK])
+			mxlock = *(unsigned*)RTA_DATA(mxrta[RTAX_LOCK]);
 
-	if (tb[RTA_IIF] && filter.iifmask != -1)
-		print_rta_if(fp, tb[RTA_IIF], "iif");
+		for (i=2; i<= RTAX_MAX; i++) {
+			__u32 val;
 
-	if (tb[RTA_MULTIPATH])
-		print_rta_multipath(fp, r, tb[RTA_MULTIPATH]);
+			if (mxrta[i] == NULL)
+				continue;
 
-	if (tb[RTA_PREF])
-		print_rt_pref(fp, rta_getattr_u8(tb[RTA_PREF]));
+			if (i != RTAX_CC_ALGO)
+				val = rta_getattr_u32(mxrta[i]);
 
-	if (tb[RTA_TTL_PROPAGATE]) {
-		bool propagate = rta_getattr_u8(tb[RTA_TTL_PROPAGATE]);
+			if (i == RTAX_HOPLIMIT && (int)val == -1)
+				continue;
 
-		if (is_json_context())
-			print_bool(PRINT_JSON, "ttl-propogate", NULL,
-				   propagate);
-		else
-			print_string(PRINT_FP, NULL,
-				     "ttl-propogate %s",
-				     propagate ? "enabled" : "disabled");
+			if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i])
+				fprintf(fp, " %s", mx_names[i]);
+			else
+				fprintf(fp, " metric %d", i);
+
+			if (mxlock & (1<<i))
+				fprintf(fp, " lock");
+
+			switch (i) {
+			case RTAX_FEATURES:
+				print_rtax_features(fp, val);
+				break;
+			default:
+				fprintf(fp, " %u", val);
+				break;
+
+			case RTAX_RTT:
+			case RTAX_RTTVAR:
+			case RTAX_RTO_MIN:
+				if (i == RTAX_RTT)
+					val /= 8;
+				else if (i == RTAX_RTTVAR)
+					val /= 4;
+
+				if (val >= 1000)
+					fprintf(fp, " %gs", val/1e3);
+				else
+					fprintf(fp, " %ums", val);
+				break;
+			case RTAX_CC_ALGO:
+				fprintf(fp, " %s", rta_getattr_str(mxrta[i]));
+				break;
+			}
+		}
 	}
+	if (tb[RTA_IIF] && filter.iifmask != -1) {
+		fprintf(fp, " iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF])));
+	}
+	if (tb[RTA_MULTIPATH]) {
+		struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]);
+		int first = 0;
 
-	print_string(PRINT_FP, NULL, "\n", NULL);
-	close_json_object();
+		len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
+
+		for (;;) {
+			if (len < sizeof(*nh))
+				break;
+			if (nh->rtnh_len > len)
+				break;
+			if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) {
+				if (first)
+					fprintf(fp, " Oifs:");
+				else
+					fprintf(fp, " ");
+			} else
+				fprintf(fp, "%s\tnexthop", _SL_);
+			if (nh->rtnh_len > sizeof(*nh)) {
+				parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh));
+
+				if (tb[RTA_ENCAP])
+					lwt_print_encap(fp,
+							tb[RTA_ENCAP_TYPE],
+							tb[RTA_ENCAP]);
+
+				if (tb[RTA_GATEWAY]) {
+					fprintf(fp, " via %s ",
+						format_host(r->rtm_family,
+							    RTA_PAYLOAD(tb[RTA_GATEWAY]),
+							    RTA_DATA(tb[RTA_GATEWAY]),
+							    abuf, sizeof(abuf)));
+				}
+				if (tb[RTA_VIA]) {
+					size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
+					struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
+					fprintf(fp, "via %s %s ",
+						family_name(via->rtvia_family),
+						format_host(via->rtvia_family, len, via->rtvia_addr,
+							    abuf, sizeof(abuf)));
+				}
+				if (tb[RTA_FLOW]) {
+					__u32 to = rta_getattr_u32(tb[RTA_FLOW]);
+					__u32 from = to>>16;
+					to &= 0xFFFF;
+					fprintf(fp, " realm%s ", from ? "s" : "");
+					if (from) {
+						fprintf(fp, "%s/",
+							rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
+					}
+					fprintf(fp, "%s",
+						rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
+				}
+			}
+			if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) {
+				fprintf(fp, " %s", ll_index_to_name(nh->rtnh_ifindex));
+				if (nh->rtnh_hops != 1)
+					fprintf(fp, "(ttl>%d)", nh->rtnh_hops);
+			} else {
+				fprintf(fp, " dev %s", ll_index_to_name(nh->rtnh_ifindex));
+				fprintf(fp, " weight %d", nh->rtnh_hops+1);
+			}
+			if (nh->rtnh_flags & RTNH_F_DEAD)
+				fprintf(fp, " dead");
+			if (nh->rtnh_flags & RTNH_F_ONLINK)
+				fprintf(fp, " onlink");
+			if (nh->rtnh_flags & RTNH_F_PERVASIVE)
+				fprintf(fp, " pervasive");
+			if (nh->rtnh_flags & RTNH_F_LINKDOWN)
+				fprintf(fp, " linkdown");
+			len -= NLMSG_ALIGN(nh->rtnh_len);
+			nh = RTNH_NEXT(nh);
+		}
+	}
+	if (tb[RTA_PREF]) {
+		unsigned int pref = rta_getattr_u8(tb[RTA_PREF]);
+		fprintf(fp, " pref ");
+
+		switch (pref) {
+		case ICMPV6_ROUTER_PREF_LOW:
+			fprintf(fp, "low");
+			break;
+		case ICMPV6_ROUTER_PREF_MEDIUM:
+			fprintf(fp, "medium");
+			break;
+		case ICMPV6_ROUTER_PREF_HIGH:
+			fprintf(fp, "high");
+			break;
+		default:
+			fprintf(fp, "%u", pref);
+		}
+	}
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
 
 static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
-			struct rtattr *rta, size_t len, struct rtnexthop *rtnh,
+			struct rtattr *rta, struct rtnexthop *rtnh,
 			int *argcp, char ***argvp)
 {
 	int argc = *argcp;
@@ -964,7 +733,6 @@
 		if (strcmp(*argv, "via") == 0) {
 			inet_prefix addr;
 			int family;
-
 			NEXT_ARG();
 			family = read_family(*argv);
 			if (family == AF_UNSPEC)
@@ -975,25 +743,20 @@
 			if (r->rtm_family == AF_UNSPEC)
 				r->rtm_family = addr.family;
 			if (addr.family == r->rtm_family) {
-				if (rta_addattr_l(rta, len, RTA_GATEWAY,
-						  &addr.data, addr.bytelen))
-					return -1;
-				rtnh->rtnh_len += sizeof(struct rtattr)
-						  + addr.bytelen;
+				rta_addattr_l(rta, 4096, RTA_GATEWAY, &addr.data, addr.bytelen);
+				rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen;
 			} else {
-				if (rta_addattr_l(rta, len, RTA_VIA,
-						  &addr.family, addr.bytelen + 2))
-					return -1;
-				rtnh->rtnh_len += RTA_SPACE(addr.bytelen + 2);
+				rta_addattr_l(rta, 4096, RTA_VIA, &addr.family, addr.bytelen+2);
+				rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen+2;
 			}
 		} else if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
-			rtnh->rtnh_ifindex = ll_name_to_index(*argv);
-			if (!rtnh->rtnh_ifindex)
-				return nodev(*argv);
+			if ((rtnh->rtnh_ifindex = ll_name_to_index(*argv)) == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
+				exit(1);
+			}
 		} else if (strcmp(*argv, "weight") == 0) {
-			unsigned int w;
-
+			unsigned w;
 			NEXT_ARG();
 			if (get_unsigned(&w, *argv, 0) || w == 0 || w > 256)
 				invarg("\"weight\" is invalid\n", *argv);
@@ -1002,31 +765,16 @@
 			rtnh->rtnh_flags |= RTNH_F_ONLINK;
 		} else if (matches(*argv, "realms") == 0) {
 			__u32 realm;
-
 			NEXT_ARG();
 			if (get_rt_realms_or_raw(&realm, *argv))
 				invarg("\"realm\" value is invalid\n", *argv);
-			if (rta_addattr32(rta, len, RTA_FLOW, realm))
-				return -1;
+			rta_addattr32(rta, 4096, RTA_FLOW, realm);
 			rtnh->rtnh_len += sizeof(struct rtattr) + 4;
 		} else if (strcmp(*argv, "encap") == 0) {
-			int old_len = rta->rta_len;
+			int len = rta->rta_len;
 
-			if (lwt_parse_encap(rta, len, &argc, &argv,
-					    RTA_ENCAP, RTA_ENCAP_TYPE))
-				return -1;
-			rtnh->rtnh_len += rta->rta_len - old_len;
-		} else if (strcmp(*argv, "as") == 0) {
-			inet_prefix addr;
-
-			NEXT_ARG();
-			if (strcmp(*argv, "to") == 0)
-				NEXT_ARG();
-			get_addr(&addr, *argv, r->rtm_family);
-			if (rta_addattr_l(rta, len, RTA_NEWDST,
-					  &addr.data, addr.bytelen))
-				return -1;
-			rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen;
+			lwt_parse_encap(rta, 4096, &argc, &argv);
+			rtnh->rtnh_len += rta->rta_len - len;
 		} else
 			break;
 	}
@@ -1038,8 +786,8 @@
 static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
 			  int argc, char **argv)
 {
-	char buf[4096];
-	struct rtattr *rta = (void *)buf;
+	char buf[1024];
+	struct rtattr *rta = (void*)buf;
 	struct rtnexthop *rtnh;
 
 	rta->rta_type = RTA_MULTIPATH;
@@ -1058,36 +806,25 @@
 		memset(rtnh, 0, sizeof(*rtnh));
 		rtnh->rtnh_len = sizeof(*rtnh);
 		rta->rta_len += rtnh->rtnh_len;
-		if (parse_one_nh(n, r, rta, 4096, rtnh, &argc, &argv)) {
-			fprintf(stderr, "Error: cannot parse nexthop\n");
-			exit(-1);
-		}
+		parse_one_nh(n, r, rta, rtnh, &argc, &argv);
 		rtnh = RTNH_NEXT(rtnh);
 	}
 
 	if (rta->rta_len > RTA_LENGTH(0))
-		return addattr_l(n, 4096, RTA_MULTIPATH,
-				 RTA_DATA(rta), RTA_PAYLOAD(rta));
+		addattr_l(n, 1024, RTA_MULTIPATH, RTA_DATA(rta), RTA_PAYLOAD(rta));
 	return 0;
 }
 
-static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
+static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
 {
 	struct {
 		struct nlmsghdr	n;
 		struct rtmsg		r;
-		char			buf[4096];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.r.rtm_family = preferred_family,
-		.r.rtm_table = RT_TABLE_MAIN,
-		.r.rtm_scope = RT_SCOPE_NOWHERE,
-	};
+		char  			buf[1024];
+	} req;
 	char  mxbuf[256];
-	struct rtattr *mxrta = (void *)mxbuf;
-	unsigned int mxlock = 0;
+	struct rtattr * mxrta = (void*)mxbuf;
+	unsigned mxlock = 0;
 	char  *d = NULL;
 	int gw_ok = 0;
 	int dst_ok = 0;
@@ -1096,7 +833,16 @@
 	int table_ok = 0;
 	int raw = 0;
 	int type_ok = 0;
-	__u32 nhid = 0;
+	static int hz;
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.r.rtm_family = preferred_family;
+	req.r.rtm_table = RT_TABLE_MAIN;
+	req.r.rtm_scope = RT_SCOPE_NOWHERE;
 
 	if (cmd != RTM_DELROUTE) {
 		req.r.rtm_protocol = RTPROT_BOOT;
@@ -1110,16 +856,13 @@
 	while (argc > 0) {
 		if (strcmp(*argv, "src") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			get_addr(&addr, *argv, req.r.rtm_family);
 			if (req.r.rtm_family == AF_UNSPEC)
 				req.r.rtm_family = addr.family;
-			addattr_l(&req.n, sizeof(req),
-				  RTA_PREFSRC, &addr.data, addr.bytelen);
+			addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &addr.data, addr.bytelen);
 		} else if (strcmp(*argv, "as") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (strcmp(*argv, "to") == 0) {
 				NEXT_ARG();
@@ -1127,16 +870,10 @@
 			get_addr(&addr, *argv, req.r.rtm_family);
 			if (req.r.rtm_family == AF_UNSPEC)
 				req.r.rtm_family = addr.family;
-			addattr_l(&req.n, sizeof(req),
-				  RTA_NEWDST, &addr.data, addr.bytelen);
+			addattr_l(&req.n, sizeof(req), RTA_NEWDST, &addr.data, addr.bytelen);
 		} else if (strcmp(*argv, "via") == 0) {
 			inet_prefix addr;
 			int family;
-
-			if (gw_ok) {
-				invarg("use nexthop syntax to specify multiple via\n",
-				       *argv);
-			}
 			gw_ok = 1;
 			NEXT_ARG();
 			family = read_family(*argv);
@@ -1148,14 +885,11 @@
 			if (req.r.rtm_family == AF_UNSPEC)
 				req.r.rtm_family = addr.family;
 			if (addr.family == req.r.rtm_family)
-				addattr_l(&req.n, sizeof(req), RTA_GATEWAY,
-					  &addr.data, addr.bytelen);
+				addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &addr.data, addr.bytelen);
 			else
-				addattr_l(&req.n, sizeof(req), RTA_VIA,
-					  &addr.family, addr.bytelen+2);
+				addattr_l(&req.n, sizeof(req), RTA_VIA, &addr.family, addr.bytelen+2);
 		} else if (strcmp(*argv, "from") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			get_prefix(&addr, *argv, req.r.rtm_family);
 			if (req.r.rtm_family == AF_UNSPEC)
@@ -1166,38 +900,35 @@
 		} else if (strcmp(*argv, "tos") == 0 ||
 			   matches(*argv, "dsfield") == 0) {
 			__u32 tos;
-
 			NEXT_ARG();
 			if (rtnl_dsfield_a2n(&tos, *argv))
 				invarg("\"tos\" value is invalid\n", *argv);
 			req.r.rtm_tos = tos;
-		} else if (strcmp(*argv, "expires") == 0) {
+		} else if (strcmp(*argv, "expires") == 0 ) {
 			__u32 expires;
-
 			NEXT_ARG();
 			if (get_u32(&expires, *argv, 0))
 				invarg("\"expires\" value is invalid\n", *argv);
-			addattr32(&req.n, sizeof(req), RTA_EXPIRES, expires);
+			if (!hz)
+				hz = get_user_hz();
+			addattr32(&req.n, sizeof(req), RTA_EXPIRES, expires*hz);
 		} else if (matches(*argv, "metric") == 0 ||
 			   matches(*argv, "priority") == 0 ||
 			   strcmp(*argv, "preference") == 0) {
 			__u32 metric;
-
 			NEXT_ARG();
 			if (get_u32(&metric, *argv, 0))
 				invarg("\"metric\" value is invalid\n", *argv);
 			addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric);
 		} else if (strcmp(*argv, "scope") == 0) {
 			__u32 scope = 0;
-
 			NEXT_ARG();
 			if (rtnl_rtscope_a2n(&scope, *argv))
 				invarg("invalid \"scope\" value\n", *argv);
 			req.r.rtm_scope = scope;
 			scope_ok = 1;
 		} else if (strcmp(*argv, "mtu") == 0) {
-			unsigned int mtu;
-
+			unsigned mtu;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_MTU);
@@ -1207,8 +938,7 @@
 				invarg("\"mtu\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
 		} else if (strcmp(*argv, "hoplimit") == 0) {
-			unsigned int hoplimit;
-
+			unsigned hoplimit;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_HOPLIMIT);
@@ -1218,8 +948,7 @@
 				invarg("\"hoplimit\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
 		} else if (strcmp(*argv, "advmss") == 0) {
-			unsigned int mss;
-
+			unsigned mss;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_ADVMSS);
@@ -1229,8 +958,7 @@
 				invarg("\"mss\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_ADVMSS, mss);
 		} else if (matches(*argv, "reordering") == 0) {
-			unsigned int reord;
-
+			unsigned reord;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_REORDERING);
@@ -1240,8 +968,7 @@
 				invarg("\"reordering\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord);
 		} else if (strcmp(*argv, "rtt") == 0) {
-			unsigned int rtt;
-
+			unsigned rtt;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_RTT);
@@ -1252,8 +979,7 @@
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT,
 				(raw) ? rtt : rtt * 8);
 		} else if (strcmp(*argv, "rto_min") == 0) {
-			unsigned int rto_min;
-
+			unsigned rto_min;
 			NEXT_ARG();
 			mxlock |= (1<<RTAX_RTO_MIN);
 			if (get_time_rtt(&rto_min, *argv, &raw))
@@ -1262,8 +988,7 @@
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN,
 				      rto_min);
 		} else if (matches(*argv, "window") == 0) {
-			unsigned int win;
-
+			unsigned win;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_WINDOW);
@@ -1273,8 +998,7 @@
 				invarg("\"window\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_WINDOW, win);
 		} else if (matches(*argv, "cwnd") == 0) {
-			unsigned int win;
-
+			unsigned win;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_CWND);
@@ -1284,8 +1008,7 @@
 				invarg("\"cwnd\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win);
 		} else if (matches(*argv, "initcwnd") == 0) {
-			unsigned int win;
-
+			unsigned win;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_INITCWND);
@@ -1293,11 +1016,9 @@
 			}
 			if (get_unsigned(&win, *argv, 0))
 				invarg("\"initcwnd\" value is invalid\n", *argv);
-			rta_addattr32(mxrta, sizeof(mxbuf),
-				      RTAX_INITCWND, win);
+			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win);
 		} else if (matches(*argv, "initrwnd") == 0) {
-			unsigned int win;
-
+			unsigned win;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_INITRWND);
@@ -1305,8 +1026,7 @@
 			}
 			if (get_unsigned(&win, *argv, 0))
 				invarg("\"initrwnd\" value is invalid\n", *argv);
-			rta_addattr32(mxrta, sizeof(mxbuf),
-				      RTAX_INITRWND, win);
+			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITRWND, win);
 		} else if (matches(*argv, "features") == 0) {
 			unsigned int features = 0;
 
@@ -1320,18 +1040,15 @@
 				break;
 			}
 
-			rta_addattr32(mxrta, sizeof(mxbuf),
-				      RTAX_FEATURES, features);
+			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FEATURES, features);
 		} else if (matches(*argv, "quickack") == 0) {
-			unsigned int quickack;
-
+			unsigned quickack;
 			NEXT_ARG();
 			if (get_unsigned(&quickack, *argv, 0))
 				invarg("\"quickack\" value is invalid\n", *argv);
 			if (quickack != 1 && quickack != 0)
 				invarg("\"quickack\" value should be 0 or 1\n", *argv);
-			rta_addattr32(mxrta, sizeof(mxbuf),
-				      RTAX_QUICKACK, quickack);
+			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_QUICKACK, quickack);
 		} else if (matches(*argv, "congctl") == 0) {
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
@@ -1341,8 +1058,7 @@
 			rta_addattr_l(mxrta, sizeof(mxbuf), RTAX_CC_ALGO, *argv,
 				      strlen(*argv));
 		} else if (matches(*argv, "rttvar") == 0) {
-			unsigned int win;
-
+			unsigned win;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_RTTVAR);
@@ -1353,8 +1069,7 @@
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR,
 				(raw) ? win : win * 4);
 		} else if (matches(*argv, "ssthresh") == 0) {
-			unsigned int win;
-
+			unsigned win;
 			NEXT_ARG();
 			if (strcmp(*argv, "lock") == 0) {
 				mxlock |= (1<<RTAX_SSTHRESH);
@@ -1365,7 +1080,6 @@
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win);
 		} else if (matches(*argv, "realms") == 0) {
 			__u32 realm;
-
 			NEXT_ARG();
 			if (get_rt_realms_or_raw(&realm, *argv))
 				invarg("\"realm\" value is invalid\n", *argv);
@@ -1375,21 +1089,14 @@
 		} else if (strcmp(*argv, "nexthop") == 0) {
 			nhs_ok = 1;
 			break;
-		} else if (!strcmp(*argv, "nhid")) {
-			NEXT_ARG();
-			if (get_u32(&nhid, *argv, 0))
-				invarg("\"id\" value is invalid\n", *argv);
-			addattr32(&req.n, sizeof(req), RTA_NH_ID, nhid);
 		} else if (matches(*argv, "protocol") == 0) {
 			__u32 prot;
-
 			NEXT_ARG();
 			if (rtnl_rtprot_a2n(&prot, *argv))
 				invarg("\"protocol\" value is invalid\n", *argv);
 			req.r.rtm_protocol = prot;
 		} else if (matches(*argv, "table") == 0) {
 			__u32 tid;
-
 			NEXT_ARG();
 			if (rtnl_rttable_a2n(&tid, *argv))
 				invarg("\"table\" value is invalid\n", *argv);
@@ -1400,27 +1107,12 @@
 				addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
 			}
 			table_ok = 1;
-		} else if (matches(*argv, "vrf") == 0) {
-			__u32 tid;
-
-			NEXT_ARG();
-			tid = ipvrf_get_table(*argv);
-			if (tid == 0)
-				invarg("Invalid VRF\n", *argv);
-			if (tid < 256)
-				req.r.rtm_table = tid;
-			else {
-				req.r.rtm_table = RT_TABLE_UNSPEC;
-				addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
-			}
-			table_ok = 1;
 		} else if (strcmp(*argv, "dev") == 0 ||
 			   strcmp(*argv, "oif") == 0) {
 			NEXT_ARG();
 			d = *argv;
 		} else if (matches(*argv, "pref") == 0) {
 			__u8 pref;
-
 			NEXT_ARG();
 			if (strcmp(*argv, "low") == 0)
 				pref = ICMPV6_ROUTER_PREF_LOW;
@@ -1433,40 +1125,15 @@
 			addattr8(&req.n, sizeof(req), RTA_PREF, pref);
 		} else if (strcmp(*argv, "encap") == 0) {
 			char buf[1024];
-			struct rtattr *rta = (void *)buf;
+			struct rtattr *rta = (void*)buf;
 
 			rta->rta_type = RTA_ENCAP;
 			rta->rta_len = RTA_LENGTH(0);
 
-			lwt_parse_encap(rta, sizeof(buf), &argc, &argv,
-					RTA_ENCAP, RTA_ENCAP_TYPE);
+			lwt_parse_encap(rta, sizeof(buf), &argc, &argv);
 
 			if (rta->rta_len > RTA_LENGTH(0))
-				addraw_l(&req.n, 1024
-					 , RTA_DATA(rta), RTA_PAYLOAD(rta));
-		} else if (strcmp(*argv, "ttl-propagate") == 0) {
-			__u8 ttl_prop;
-
-			NEXT_ARG();
-			if (matches(*argv, "enabled") == 0)
-				ttl_prop = 1;
-			else if (matches(*argv, "disabled") == 0)
-				ttl_prop = 0;
-			else
-				invarg("\"ttl-propagate\" value is invalid\n",
-				       *argv);
-
-			addattr8(&req.n, sizeof(req), RTA_TTL_PROPAGATE,
-				 ttl_prop);
-		} else if (matches(*argv, "fastopen_no_cookie") == 0) {
-			unsigned int fastopen_no_cookie;
-
-			NEXT_ARG();
-			if (get_unsigned(&fastopen_no_cookie, *argv, 0))
-				invarg("\"fastopen_no_cookie\" value is invalid\n", *argv);
-			if (fastopen_no_cookie != 1 && fastopen_no_cookie != 0)
-				invarg("\"fastopen_no_cookie\" value should be 0 or 1\n", *argv);
-			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FASTOPEN_NO_COOKIE, fastopen_no_cookie);
+				addraw_l(&req.n, 1024, RTA_DATA(rta), RTA_PAYLOAD(rta));
 		} else {
 			int type;
 			inet_prefix dst;
@@ -1491,8 +1158,7 @@
 			req.r.rtm_dst_len = dst.bitlen;
 			dst_ok = 1;
 			if (dst.bytelen)
-				addattr_l(&req.n, sizeof(req),
-					  RTA_DST, &dst.data, dst.bytelen);
+				addattr_l(&req.n, sizeof(req), RTA_DST, &dst.data, dst.bytelen);
 		}
 		argc--; argv++;
 	}
@@ -1500,12 +1166,16 @@
 	if (!dst_ok)
 		usage();
 
-	if (d) {
-		int idx = ll_name_to_index(d);
+	if (d || nhs_ok)  {
+		int idx;
 
-		if (!idx)
-			return nodev(d);
-		addattr32(&req.n, sizeof(req), RTA_OIF, idx);
+		if (d) {
+			if ((idx = ll_name_to_index(d)) == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", d);
+				return -1;
+			}
+			addattr32(&req.n, sizeof(req), RTA_OIF, idx);
+		}
 	}
 
 	if (mxrta->rta_len > RTA_LENGTH(0)) {
@@ -1514,8 +1184,8 @@
 		addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta));
 	}
 
-	if (nhs_ok && parse_nexthops(&req.n, &req.r, argc, argv))
-		return -1;
+	if (nhs_ok)
+		parse_nexthops(&req.n, &req.r, argc, argv);
 
 	if (req.r.rtm_family == AF_UNSPEC)
 		req.r.rtm_family = AF_INET;
@@ -1542,7 +1212,7 @@
 			 req.r.rtm_type == RTN_UNSPEC) {
 			if (cmd == RTM_DELROUTE)
 				req.r.rtm_scope = RT_SCOPE_NOWHERE;
-			else if (!gw_ok && !nhs_ok && !nhid)
+			else if (!gw_ok && !nhs_ok)
 				req.r.rtm_scope = RT_SCOPE_LINK;
 		}
 	}
@@ -1550,30 +1220,53 @@
 	if (!type_ok && req.r.rtm_family == AF_MPLS)
 		req.r.rtm_type = RTN_UNICAST;
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
 }
 
+static int rtnl_rtcache_request(struct rtnl_handle *rth, int family)
+{
+	struct {
+		struct nlmsghdr nlh;
+		struct rtmsg rtm;
+	} req;
+	struct sockaddr_nl nladdr;
+
+	memset(&nladdr, 0, sizeof(nladdr));
+	memset(&req, 0, sizeof(req));
+	nladdr.nl_family = AF_NETLINK;
+
+	req.nlh.nlmsg_len = sizeof(req);
+	req.nlh.nlmsg_type = RTM_GETROUTE;
+	req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_REQUEST;
+	req.nlh.nlmsg_pid = 0;
+	req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
+	req.rtm.rtm_family = family;
+	req.rtm.rtm_flags |= RTM_F_CLONED;
+
+	return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr));
+}
+
 static int iproute_flush_cache(void)
 {
 #define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
 
 	int len;
-	int flush_fd = open(ROUTE_FLUSH_PATH, O_WRONLY);
+	int flush_fd = open (ROUTE_FLUSH_PATH, O_WRONLY);
 	char *buffer = "-1";
 
 	if (flush_fd < 0) {
-		fprintf(stderr, "Cannot open \"%s\": %s\n",
+		fprintf (stderr, "Cannot open \"%s\": %s\n",
 				ROUTE_FLUSH_PATH, strerror(errno));
 		return -1;
 	}
 
-	len = strlen(buffer);
+	len = strlen (buffer);
 
-	if ((write(flush_fd, (void *)buffer, len)) < len) {
-		fprintf(stderr, "Cannot flush routing cache\n");
+	if ((write (flush_fd, (void *)buffer, len)) < len) {
+		fprintf (stderr, "Cannot flush routing cache\n");
 		close(flush_fd);
 		return -1;
 	}
@@ -1583,7 +1276,8 @@
 
 static __u32 route_dump_magic = 0x45311224;
 
-static int save_route(struct nlmsghdr *n, void *arg)
+static int save_route(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		      void *arg)
 {
 	int ret;
 	int len = n->nlmsg_len;
@@ -1625,95 +1319,9 @@
 	return 0;
 }
 
-static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	struct rtmsg *rtm = NLMSG_DATA(nlh);
-	int err;
-
-	rtm->rtm_protocol = filter.protocol;
-	if (filter.cloned)
-		rtm->rtm_flags |= RTM_F_CLONED;
-
-	if (filter.tb) {
-		err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
-		if (err)
-			return err;
-	}
-
-	if (filter.oif) {
-		err = addattr32(nlh, reqlen, RTA_OIF, filter.oif);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
-static int iproute_flush(int family, rtnl_filter_t filter_fn)
-{
-	time_t start = time(0);
-	char flushb[4096-512];
-	int round = 0;
-	int ret;
-
-	if (filter.cloned) {
-		if (family != AF_INET6) {
-			iproute_flush_cache();
-			if (show_stats)
-				printf("*** IPv4 routing cache is flushed.\n");
-		}
-		if (family == AF_INET)
-			return 0;
-	}
-
-	filter.flushb = flushb;
-	filter.flushp = 0;
-	filter.flushe = sizeof(flushb);
-
-	for (;;) {
-		if (rtnl_routedump_req(&rth, family, iproute_dump_filter) < 0) {
-			perror("Cannot send dump request");
-			return -2;
-		}
-		filter.flushed = 0;
-		if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
-			fprintf(stderr, "Flush terminated\n");
-			return -2;
-		}
-		if (filter.flushed == 0) {
-			if (show_stats) {
-				if (round == 0 &&
-				    (!filter.cloned || family == AF_INET6))
-					printf("Nothing to flush.\n");
-				else
-					printf("*** Flush is complete after %d round%s ***\n",
-					       round, round > 1 ? "s" : "");
-			}
-			fflush(stdout);
-			return 0;
-		}
-		round++;
-		ret = flush_update();
-		if (ret < 0)
-			return ret;
-
-		if (time(0) - start > 30) {
-			printf("\n*** Flush not completed after %ld seconds, %d entries remain ***\n",
-			       (long)(time(0) - start), filter.flushed);
-			return -1;
-		}
-
-		if (show_stats) {
-			printf("\n*** Round %d, deleting %d entries ***\n",
-			       round, filter.flushed);
-			fflush(stdout);
-		}
-	}
-}
-
 static int iproute_list_flush_or_save(int argc, char **argv, int action)
 {
-	int dump_family = preferred_family;
+	int do_ipv6 = preferred_family;
 	char *id = NULL;
 	char *od = NULL;
 	unsigned int mark = 0;
@@ -1738,7 +1346,6 @@
 	while (argc > 0) {
 		if (matches(*argv, "table") == 0) {
 			__u32 tid;
-
 			NEXT_ARG();
 			if (rtnl_rttable_a2n(&tid, *argv)) {
 				if (strcmp(*argv, "all") == 0) {
@@ -1752,22 +1359,12 @@
 				}
 			} else
 				filter.tb = tid;
-		} else if (matches(*argv, "vrf") == 0) {
-			__u32 tid;
-
-			NEXT_ARG();
-			tid = ipvrf_get_table(*argv);
-			if (tid == 0)
-				invarg("Invalid VRF\n", *argv);
-			filter.tb = tid;
-			filter.typemask = ~(1 << RTN_LOCAL | 1<<RTN_BROADCAST);
 		} else if (matches(*argv, "cached") == 0 ||
 			   matches(*argv, "cloned") == 0) {
 			filter.cloned = 1;
 		} else if (strcmp(*argv, "tos") == 0 ||
 			   matches(*argv, "dsfield") == 0) {
 			__u32 tos;
-
 			NEXT_ARG();
 			if (rtnl_dsfield_a2n(&tos, *argv))
 				invarg("TOS value is invalid\n", *argv);
@@ -1775,7 +1372,6 @@
 			filter.tosmask = -1;
 		} else if (matches(*argv, "protocol") == 0) {
 			__u32 prot = 0;
-
 			NEXT_ARG();
 			filter.protocolmask = -1;
 			if (rtnl_rtprot_a2n(&prot, *argv)) {
@@ -1787,7 +1383,6 @@
 			filter.protocol = prot;
 		} else if (matches(*argv, "scope") == 0) {
 			__u32 scope = 0;
-
 			NEXT_ARG();
 			filter.scopemask = -1;
 			if (rtnl_rtscope_a2n(&scope, *argv)) {
@@ -1799,11 +1394,11 @@
 			filter.scope = scope;
 		} else if (matches(*argv, "type") == 0) {
 			int type;
-
 			NEXT_ARG();
+			filter.typemask = -1;
 			if (rtnl_rtntype_a2n(&type, *argv))
 				invarg("node type value is invalid\n", *argv);
-			filter.typemask = (1<<type);
+			filter.type = type;
 		} else if (strcmp(*argv, "dev") == 0 ||
 			   strcmp(*argv, "oif") == 0) {
 			NEXT_ARG();
@@ -1813,35 +1408,22 @@
 			id = *argv;
 		} else if (strcmp(*argv, "mark") == 0) {
 			NEXT_ARG();
-			if (get_unsigned(&mark, *argv, 0))
-				invarg("invalid mark value", *argv);
+			get_unsigned(&mark, *argv, 0);
 			filter.markmask = -1;
-		} else if (matches(*argv, "metric") == 0 ||
-			   matches(*argv, "priority") == 0 ||
-			   strcmp(*argv, "preference") == 0) {
-			__u32 metric;
-
-			NEXT_ARG();
-			if (get_u32(&metric, *argv, 0))
-				invarg("\"metric\" value is invalid\n", *argv);
-			filter.metric = metric;
-			filter.metricmask = -1;
 		} else if (strcmp(*argv, "via") == 0) {
 			int family;
-
 			NEXT_ARG();
 			family = read_family(*argv);
 			if (family == AF_UNSPEC)
-				family = dump_family;
+				family = do_ipv6;
 			else
 				NEXT_ARG();
 			get_prefix(&filter.rvia, *argv, family);
 		} else if (strcmp(*argv, "src") == 0) {
 			NEXT_ARG();
-			get_prefix(&filter.rprefsrc, *argv, dump_family);
+			get_prefix(&filter.rprefsrc, *argv, do_ipv6);
 		} else if (matches(*argv, "realms") == 0) {
 			__u32 realm;
-
 			NEXT_ARG();
 			if (get_rt_realms_or_raw(&realm, *argv))
 				invarg("invalid realms\n", *argv);
@@ -1858,15 +1440,15 @@
 			NEXT_ARG();
 			if (matches(*argv, "root") == 0) {
 				NEXT_ARG();
-				get_prefix(&filter.rsrc, *argv, dump_family);
+				get_prefix(&filter.rsrc, *argv, do_ipv6);
 			} else if (matches(*argv, "match") == 0) {
 				NEXT_ARG();
-				get_prefix(&filter.msrc, *argv, dump_family);
+				get_prefix(&filter.msrc, *argv, do_ipv6);
 			} else {
 				if (matches(*argv, "exact") == 0) {
 					NEXT_ARG();
 				}
-				get_prefix(&filter.msrc, *argv, dump_family);
+				get_prefix(&filter.msrc, *argv, do_ipv6);
 				filter.rsrc = filter.msrc;
 			}
 		} else {
@@ -1875,62 +1457,120 @@
 			}
 			if (matches(*argv, "root") == 0) {
 				NEXT_ARG();
-				get_prefix(&filter.rdst, *argv, dump_family);
+				get_prefix(&filter.rdst, *argv, do_ipv6);
 			} else if (matches(*argv, "match") == 0) {
 				NEXT_ARG();
-				get_prefix(&filter.mdst, *argv, dump_family);
+				get_prefix(&filter.mdst, *argv, do_ipv6);
 			} else {
 				if (matches(*argv, "exact") == 0) {
 					NEXT_ARG();
 				}
-				get_prefix(&filter.mdst, *argv, dump_family);
+				get_prefix(&filter.mdst, *argv, do_ipv6);
 				filter.rdst = filter.mdst;
 			}
 		}
 		argc--; argv++;
 	}
 
-	if (dump_family == AF_UNSPEC && filter.tb)
-		dump_family = AF_INET;
+	if (do_ipv6 == AF_UNSPEC && filter.tb)
+		do_ipv6 = AF_INET;
 
 	if (id || od)  {
 		int idx;
 
 		if (id) {
-			idx = ll_name_to_index(id);
-			if (!idx)
-				return nodev(id);
+			if ((idx = ll_name_to_index(id)) == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", id);
+				return -1;
+			}
 			filter.iif = idx;
 			filter.iifmask = -1;
 		}
 		if (od) {
-			idx = ll_name_to_index(od);
-			if (!idx)
-				return nodev(od);
+			if ((idx = ll_name_to_index(od)) == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", od);
+				return -1;
+			}
 			filter.oif = idx;
 			filter.oifmask = -1;
 		}
 	}
 	filter.mark = mark;
 
-	if (action == IPROUTE_FLUSH)
-		return iproute_flush(dump_family, filter_fn);
+	if (action == IPROUTE_FLUSH) {
+		int round = 0;
+		char flushb[4096-512];
+		time_t start = time(0);
 
-	if (rtnl_routedump_req(&rth, dump_family, iproute_dump_filter) < 0) {
-		perror("Cannot send dump request");
-		return -2;
+		if (filter.cloned) {
+			if (do_ipv6 != AF_INET6) {
+				iproute_flush_cache();
+				if (show_stats)
+					printf("*** IPv4 routing cache is flushed.\n");
+			}
+			if (do_ipv6 == AF_INET)
+				return 0;
+		}
+
+		filter.flushb = flushb;
+		filter.flushp = 0;
+		filter.flushe = sizeof(flushb);
+
+		for (;;) {
+			if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
+				perror("Cannot send dump request");
+				exit(1);
+			}
+			filter.flushed = 0;
+			if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
+				fprintf(stderr, "Flush terminated\n");
+				exit(1);
+			}
+			if (filter.flushed == 0) {
+				if (show_stats) {
+					if (round == 0 && (!filter.cloned || do_ipv6 == AF_INET6))
+						printf("Nothing to flush.\n");
+					else
+						printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
+				}
+				fflush(stdout);
+				return 0;
+			}
+			round++;
+			if (flush_update() < 0)
+				exit(1);
+
+			if (time(0) - start > 30) {
+				printf("\n*** Flush not completed after %ld seconds, %d entries remain ***\n",
+				       (long)(time(0) - start), filter.flushed);
+				exit(1);
+			}
+
+			if (show_stats) {
+				printf("\n*** Round %d, deleting %d entries ***\n", round, filter.flushed);
+				fflush(stdout);
+			}
+		}
 	}
 
-	new_json_obj(json);
+	if (!filter.cloned) {
+		if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
+			perror("Cannot send dump request");
+			exit(1);
+		}
+	} else {
+		if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
+			perror("Cannot send dump request");
+			exit(1);
+		}
+	}
 
 	if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
-		return -2;
+		exit(1);
 	}
 
-	delete_json_obj();
-	fflush(stdout);
-	return 0;
+	exit(0);
 }
 
 
@@ -1939,37 +1579,41 @@
 	struct {
 		struct nlmsghdr	n;
 		struct rtmsg		r;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETROUTE,
-		.r.rtm_family = preferred_family,
-	};
+		char  			buf[1024];
+	} req;
 	char  *idev = NULL;
 	char  *odev = NULL;
-	struct nlmsghdr *answer;
 	int connected = 0;
-	int fib_match = 0;
 	int from_ok = 0;
 	unsigned int mark = 0;
-	bool address_found = false;
+
+	memset(&req, 0, sizeof(req));
 
 	iproute_reset_filter(0);
 	filter.cloned = 2;
 
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = RTM_GETROUTE;
+	req.r.rtm_family = preferred_family;
+	req.r.rtm_table = 0;
+	req.r.rtm_protocol = 0;
+	req.r.rtm_scope = 0;
+	req.r.rtm_type = 0;
+	req.r.rtm_src_len = 0;
+	req.r.rtm_dst_len = 0;
+	req.r.rtm_tos = 0;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "tos") == 0 ||
 		    matches(*argv, "dsfield") == 0) {
 			__u32 tos;
-
 			NEXT_ARG();
 			if (rtnl_dsfield_a2n(&tos, *argv))
 				invarg("TOS value is invalid\n", *argv);
 			req.r.rtm_tos = tos;
 		} else if (matches(*argv, "from") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -1978,16 +1622,14 @@
 			if (req.r.rtm_family == AF_UNSPEC)
 				req.r.rtm_family = addr.family;
 			if (addr.bytelen)
-				addattr_l(&req.n, sizeof(req), RTA_SRC,
-					  &addr.data, addr.bytelen);
+				addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen);
 			req.r.rtm_src_len = addr.bitlen;
 		} else if (matches(*argv, "iif") == 0) {
 			NEXT_ARG();
 			idev = *argv;
 		} else if (matches(*argv, "mark") == 0) {
 			NEXT_ARG();
-			if (get_unsigned(&mark, *argv, 0))
-				invarg("invalid mark value", *argv);
+			get_unsigned(&mark, *argv, 0);
 		} else if (matches(*argv, "oif") == 0 ||
 			   strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
@@ -1996,11 +1638,6 @@
 			req.r.rtm_flags |= RTM_F_NOTIFY;
 		} else if (matches(*argv, "connected") == 0) {
 			connected = 1;
-		} else if (matches(*argv, "vrf") == 0) {
-			NEXT_ARG();
-			if (!name_is_vrf(*argv))
-				invarg("Invalid VRF\n", *argv);
-			odev = *argv;
 		} else if (matches(*argv, "uid") == 0) {
 			uid_t uid;
 
@@ -2008,45 +1645,8 @@
 			if (get_unsigned(&uid, *argv, 0))
 				invarg("invalid UID\n", *argv);
 			addattr32(&req.n, sizeof(req), RTA_UID, uid);
-		} else if (matches(*argv, "fibmatch") == 0) {
-			fib_match = 1;
-		} else if (strcmp(*argv, "as") == 0) {
-			inet_prefix addr;
-
-			NEXT_ARG();
-			if (strcmp(*argv, "to") == 0)
-				NEXT_ARG();
-			get_addr(&addr, *argv, req.r.rtm_family);
-			if (req.r.rtm_family == AF_UNSPEC)
-				req.r.rtm_family = addr.family;
-			addattr_l(&req.n, sizeof(req), RTA_NEWDST,
-				  &addr.data, addr.bytelen);
-		} else if (matches(*argv, "sport") == 0) {
-			__be16 sport;
-
-			NEXT_ARG();
-			if (get_be16(&sport, *argv, 0))
-				invarg("invalid sport\n", *argv);
-			addattr16(&req.n, sizeof(req), RTA_SPORT, sport);
-		} else if (matches(*argv, "dport") == 0) {
-			__be16 dport;
-
-			NEXT_ARG();
-			if (get_be16(&dport, *argv, 0))
-				invarg("invalid dport\n", *argv);
-			addattr16(&req.n, sizeof(req), RTA_DPORT, dport);
-		} else if (matches(*argv, "ipproto") == 0) {
-			int ipproto;
-
-			NEXT_ARG();
-			ipproto = inet_proto_a2n(*argv);
-			if (ipproto < 0)
-				invarg("Invalid \"ipproto\" value\n",
-				       *argv);
-			addattr8(&req.n, sizeof(req), RTA_IP_PROTO, ipproto);
 		} else {
 			inet_prefix addr;
-
 			if (strcmp(*argv, "to") == 0) {
 				NEXT_ARG();
 			}
@@ -2056,32 +1656,32 @@
 			if (req.r.rtm_family == AF_UNSPEC)
 				req.r.rtm_family = addr.family;
 			if (addr.bytelen)
-				addattr_l(&req.n, sizeof(req),
-					  RTA_DST, &addr.data, addr.bytelen);
+				addattr_l(&req.n, sizeof(req), RTA_DST, &addr.data, addr.bytelen);
 			req.r.rtm_dst_len = addr.bitlen;
-			address_found = true;
 		}
 		argc--; argv++;
 	}
 
-	if (!address_found) {
+	if (req.r.rtm_dst_len == 0) {
 		fprintf(stderr, "need at least a destination address\n");
-		return -1;
+		exit(1);
 	}
 
 	if (idev || odev)  {
 		int idx;
 
 		if (idev) {
-			idx = ll_name_to_index(idev);
-			if (!idx)
-				return nodev(idev);
+			if ((idx = ll_name_to_index(idev)) == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", idev);
+				return -1;
+			}
 			addattr32(&req.n, sizeof(req), RTA_IIF, idx);
 		}
 		if (odev) {
-			idx = ll_name_to_index(odev);
-			if (!idx)
-				return nodev(odev);
+			if ((idx = ll_name_to_index(odev)) == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n", odev);
+				return -1;
+			}
 			addattr32(&req.n, sizeof(req), RTA_OIF, idx);
 		}
 	}
@@ -2091,37 +1691,28 @@
 	if (req.r.rtm_family == AF_UNSPEC)
 		req.r.rtm_family = AF_INET;
 
-	/* Only IPv4 supports the RTM_F_LOOKUP_TABLE flag */
-	if (req.r.rtm_family == AF_INET)
-		req.r.rtm_flags |= RTM_F_LOOKUP_TABLE;
-	if (fib_match)
-		req.r.rtm_flags |= RTM_F_FIB_MATCH;
+	req.r.rtm_flags |= RTM_F_LOOKUP_TABLE;
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
 		return -2;
 
-	new_json_obj(json);
-
 	if (connected && !from_ok) {
-		struct rtmsg *r = NLMSG_DATA(answer);
-		int len = answer->nlmsg_len;
-		struct rtattr *tb[RTA_MAX+1];
+		struct rtmsg *r = NLMSG_DATA(&req.n);
+		int len = req.n.nlmsg_len;
+		struct rtattr * tb[RTA_MAX+1];
 
-		if (print_route(answer, (void *)stdout) < 0) {
+		if (print_route(NULL, &req.n, (void*)stdout) < 0) {
 			fprintf(stderr, "An error :-)\n");
-			free(answer);
-			return -1;
+			exit(1);
 		}
 
-		if (answer->nlmsg_type != RTM_NEWROUTE) {
+		if (req.n.nlmsg_type != RTM_NEWROUTE) {
 			fprintf(stderr, "Not a route?\n");
-			free(answer);
 			return -1;
 		}
 		len -= NLMSG_LENGTH(sizeof(*r));
 		if (len < 0) {
 			fprintf(stderr, "Wrong len %d\n", len);
-			free(answer);
 			return -1;
 		}
 
@@ -2132,7 +1723,6 @@
 			r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]);
 		} else if (!tb[RTA_SRC]) {
 			fprintf(stderr, "Failed to connect the route\n");
-			free(answer);
 			return -1;
 		}
 		if (!odev && tb[RTA_OIF])
@@ -2146,63 +1736,29 @@
 		req.n.nlmsg_flags = NLM_F_REQUEST;
 		req.n.nlmsg_type = RTM_GETROUTE;
 
-		delete_json_obj();
-		free(answer);
-		if (rtnl_talk(&rth, &req.n, &answer) < 0)
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
 			return -2;
 	}
 
-	if (print_route(answer, (void *)stdout) < 0) {
+	if (print_route(NULL, &req.n, (void*)stdout) < 0) {
 		fprintf(stderr, "An error :-)\n");
-		free(answer);
 		return -1;
 	}
 
-	delete_json_obj();
-	free(answer);
 	return 0;
 }
 
-static int rtattr_cmp(const struct rtattr *rta1, const struct rtattr *rta2)
-{
-	if (!rta1 || !rta2 || rta1->rta_len != rta2->rta_len)
-		return 1;
-
-	return memcmp(RTA_DATA(rta1), RTA_DATA(rta2), RTA_PAYLOAD(rta1));
-}
-
-static int restore_handler(struct rtnl_ctrl_data *ctrl,
+static int restore_handler(const struct sockaddr_nl *nl,
+			   struct rtnl_ctrl_data *ctrl,
 			   struct nlmsghdr *n, void *arg)
 {
-	struct rtmsg *r = NLMSG_DATA(n);
-	struct rtattr *tb[RTA_MAX+1];
-	int len = n->nlmsg_len - NLMSG_LENGTH(sizeof(*r));
-	int ret, prio = *(int *)arg;
+	int ret;
 
-	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
-
-	/* Restore routes in correct order:
-	 * 0. ones for local addresses,
-	 * 1. ones for local networks,
-	 * 2. others (remote networks/hosts).
-	 */
-	if (!prio && !tb[RTA_GATEWAY] && (!tb[RTA_PREFSRC] ||
-	    !rtattr_cmp(tb[RTA_PREFSRC], tb[RTA_DST])))
-		goto restore;
-	else if (prio == 1 && !tb[RTA_GATEWAY] && tb[RTA_PREFSRC] &&
-		 rtattr_cmp(tb[RTA_PREFSRC], tb[RTA_DST]))
-		goto restore;
-	else if (prio == 2 && tb[RTA_GATEWAY])
-		goto restore;
-
-	return 0;
-
-restore:
 	n->nlmsg_flags |= NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
 
 	ll_init_map(&rth);
 
-	ret = rtnl_talk(&rth, n, NULL);
+	ret = rtnl_talk(&rth, n, n, sizeof(*n));
 	if ((ret < 0) && (errno == EEXIST))
 		ret = 0;
 
@@ -2230,49 +1786,26 @@
 
 static int iproute_restore(void)
 {
-	int pos, prio;
-
 	if (route_dump_check_magic())
-		return -1;
+		exit(-1);
 
-	pos = ftell(stdin);
-	if (pos == -1) {
-		perror("Failed to restore: ftell");
-		return -1;
-	}
-
-	for (prio = 0; prio < 3; prio++) {
-		int err;
-
-		err = rtnl_from_file(stdin, &restore_handler, &prio);
-		if (err)
-			return -2;
-
-		if (fseek(stdin, pos, SEEK_SET) == -1) {
-			perror("Failed to restore: fseek");
-			return -1;
-		}
-	}
-
-	return 0;
+	exit(rtnl_from_file(stdin, &restore_handler, NULL));
 }
 
-static int show_handler(struct rtnl_ctrl_data *ctrl,
+static int show_handler(const struct sockaddr_nl *nl,
+			struct rtnl_ctrl_data *ctrl,
 			struct nlmsghdr *n, void *arg)
 {
-	print_route(n, stdout);
+	print_route(nl, n, stdout);
 	return 0;
 }
 
 static int iproute_showdump(void)
 {
 	if (route_dump_check_magic())
-		return -1;
+		exit(-1);
 
-	if (rtnl_from_file(stdin, &show_handler, NULL))
-		return -2;
-
-	return 0;
+	exit(rtnl_from_file(stdin, &show_handler, NULL));
 }
 
 void iproute_reset_filter(int ifindex)
@@ -2326,8 +1859,6 @@
 		return iproute_showdump();
 	if (matches(*argv, "help") == 0)
 		usage();
-
-	fprintf(stderr,
-		"Command \"%s\" is unknown, try \"ip route help\".\n", *argv);
+	fprintf(stderr, "Command \"%s\" is unknown, try \"ip route help\".\n", *argv);
 	exit(-1);
 }
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 60f34a3..7074906 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -7,7 +7,7 @@
  *		2 of the License, or (at your option) any later version.
  *
  * Authors:	Roopa Prabhu, <roopa@cumulusnetworks.com>
- *		Thomas Graf <tgraf@suug.ch>
+ * 		Thomas Graf <tgraf@suug.ch>
  *
  */
 
@@ -22,16 +22,22 @@
 #include <errno.h>
 
 #include "rt_names.h"
-#include "bpf_util.h"
 #include "utils.h"
-#include "ip_common.h"
-#include "ila_common.h"
+#include "iproute_lwtunnel.h"
 
-#include <linux/seg6.h>
-#include <linux/seg6_iptunnel.h>
-#include <linux/seg6_hmac.h>
-#include <linux/seg6_local.h>
-#include <linux/if_tunnel.h>
+static int read_encap_type(const char *name)
+{
+	if (strcmp(name, "mpls") == 0)
+		return LWTUNNEL_ENCAP_MPLS;
+	else if (strcmp(name, "ip") == 0)
+		return LWTUNNEL_ENCAP_IP;
+	else if (strcmp(name, "ip6") == 0)
+		return LWTUNNEL_ENCAP_IP6;
+	else if (strcmp(name, "ila") == 0)
+		return LWTUNNEL_ENCAP_ILA;
+	else
+		return LWTUNNEL_ENCAP_NONE;
+}
 
 static const char *format_encap_type(int type)
 {
@@ -44,291 +50,54 @@
 		return "ip6";
 	case LWTUNNEL_ENCAP_ILA:
 		return "ila";
-	case LWTUNNEL_ENCAP_BPF:
-		return "bpf";
-	case LWTUNNEL_ENCAP_SEG6:
-		return "seg6";
-	case LWTUNNEL_ENCAP_SEG6_LOCAL:
-		return "seg6local";
 	default:
 		return "unknown";
 	}
 }
 
-static void encap_type_usage(void)
-{
-	int i;
-
-	fprintf(stderr, "Usage: ip route ... encap TYPE [ OPTIONS ] [...]\n");
-
-	for (i = 1; i <= LWTUNNEL_ENCAP_MAX; i++)
-		fprintf(stderr, "%s %s\n", format_encap_type(i),
-			i == 1 ? "TYPE := " : "      ");
-
-	exit(-1);
-}
-
-static int read_encap_type(const char *name)
-{
-	if (strcmp(name, "mpls") == 0)
-		return LWTUNNEL_ENCAP_MPLS;
-	else if (strcmp(name, "ip") == 0)
-		return LWTUNNEL_ENCAP_IP;
-	else if (strcmp(name, "ip6") == 0)
-		return LWTUNNEL_ENCAP_IP6;
-	else if (strcmp(name, "ila") == 0)
-		return LWTUNNEL_ENCAP_ILA;
-	else if (strcmp(name, "bpf") == 0)
-		return LWTUNNEL_ENCAP_BPF;
-	else if (strcmp(name, "seg6") == 0)
-		return LWTUNNEL_ENCAP_SEG6;
-	else if (strcmp(name, "seg6local") == 0)
-		return LWTUNNEL_ENCAP_SEG6_LOCAL;
-	else if (strcmp(name, "help") == 0)
-		encap_type_usage();
-
-	return LWTUNNEL_ENCAP_NONE;
-}
-
-static void print_srh(FILE *fp, struct ipv6_sr_hdr *srh)
-{
-	int i;
-
-	if (is_json_context())
-		open_json_array(PRINT_JSON, "segs");
-	else
-		fprintf(fp, "segs %d [ ", srh->first_segment + 1);
-
-	for (i = srh->first_segment; i >= 0; i--)
-		print_color_string(PRINT_ANY, COLOR_INET6,
-				   NULL, "%s ",
-				   rt_addr_n2a(AF_INET6, 16, &srh->segments[i]));
-
-	if (is_json_context())
-		close_json_array(PRINT_JSON, NULL);
-	else
-		fprintf(fp, "] ");
-
-	if (sr_has_hmac(srh)) {
-		unsigned int offset = ((srh->hdrlen + 1) << 3) - 40;
-		struct sr6_tlv_hmac *tlv;
-
-		tlv = (struct sr6_tlv_hmac *)((char *)srh + offset);
-		print_0xhex(PRINT_ANY, "hmac",
-			    "hmac %llX ", ntohl(tlv->hmackeyid));
-	}
-}
-
-static const char *seg6_mode_types[] = {
-	[SEG6_IPTUN_MODE_INLINE]	= "inline",
-	[SEG6_IPTUN_MODE_ENCAP]		= "encap",
-	[SEG6_IPTUN_MODE_L2ENCAP]	= "l2encap",
-};
-
-static const char *format_seg6mode_type(int mode)
-{
-	if (mode < 0 || mode > ARRAY_SIZE(seg6_mode_types))
-		return "<unknown>";
-
-	return seg6_mode_types[mode];
-}
-
-static int read_seg6mode_type(const char *mode)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(seg6_mode_types); i++) {
-		if (strcmp(mode, seg6_mode_types[i]) == 0)
-			return i;
-	}
-
-	return -1;
-}
-
-static void print_encap_seg6(FILE *fp, struct rtattr *encap)
-{
-	struct rtattr *tb[SEG6_IPTUNNEL_MAX+1];
-	struct seg6_iptunnel_encap *tuninfo;
-
-	parse_rtattr_nested(tb, SEG6_IPTUNNEL_MAX, encap);
-
-	if (!tb[SEG6_IPTUNNEL_SRH])
-		return;
-
-	tuninfo = RTA_DATA(tb[SEG6_IPTUNNEL_SRH]);
-	print_string(PRINT_ANY, "mode",
-		     "mode %s ", format_seg6mode_type(tuninfo->mode));
-
-	print_srh(fp, tuninfo->srh);
-}
-
-static const char *seg6_action_names[SEG6_LOCAL_ACTION_MAX + 1] = {
-	[SEG6_LOCAL_ACTION_END]			= "End",
-	[SEG6_LOCAL_ACTION_END_X]		= "End.X",
-	[SEG6_LOCAL_ACTION_END_T]		= "End.T",
-	[SEG6_LOCAL_ACTION_END_DX2]		= "End.DX2",
-	[SEG6_LOCAL_ACTION_END_DX6]		= "End.DX6",
-	[SEG6_LOCAL_ACTION_END_DX4]		= "End.DX4",
-	[SEG6_LOCAL_ACTION_END_DT6]		= "End.DT6",
-	[SEG6_LOCAL_ACTION_END_DT4]		= "End.DT4",
-	[SEG6_LOCAL_ACTION_END_B6]		= "End.B6",
-	[SEG6_LOCAL_ACTION_END_B6_ENCAP]	= "End.B6.Encaps",
-	[SEG6_LOCAL_ACTION_END_BM]		= "End.BM",
-	[SEG6_LOCAL_ACTION_END_S]		= "End.S",
-	[SEG6_LOCAL_ACTION_END_AS]		= "End.AS",
-	[SEG6_LOCAL_ACTION_END_AM]		= "End.AM",
-	[SEG6_LOCAL_ACTION_END_BPF]		= "End.BPF",
-};
-
-static const char *format_action_type(int action)
-{
-	if (action < 0 || action > SEG6_LOCAL_ACTION_MAX)
-		return "<invalid>";
-
-	return seg6_action_names[action] ?: "<unknown>";
-}
-
-static int read_action_type(const char *name)
-{
-	int i;
-
-	for (i = 0; i < SEG6_LOCAL_ACTION_MAX + 1; i++) {
-		if (!seg6_action_names[i])
-			continue;
-
-		if (strcmp(seg6_action_names[i], name) == 0)
-			return i;
-	}
-
-	return SEG6_LOCAL_ACTION_UNSPEC;
-}
-
-static void print_encap_bpf_prog(FILE *fp, struct rtattr *encap,
-				 const char *str)
-{
-	struct rtattr *tb[LWT_BPF_PROG_MAX+1];
-	const char *progname = NULL;
-
-	parse_rtattr_nested(tb, LWT_BPF_PROG_MAX, encap);
-
-	if (tb[LWT_BPF_PROG_NAME])
-		progname = rta_getattr_str(tb[LWT_BPF_PROG_NAME]);
-
-	if (is_json_context())
-		print_string(PRINT_JSON, str, NULL,
-			     progname ? : "<unknown>");
-	else {
-		fprintf(fp, "%s ", str);
-		if (progname)
-			fprintf(fp, "%s ", progname);
-	}
-}
-
-static void print_encap_seg6local(FILE *fp, struct rtattr *encap)
-{
-	struct rtattr *tb[SEG6_LOCAL_MAX + 1];
-	int action;
-
-	parse_rtattr_nested(tb, SEG6_LOCAL_MAX, encap);
-
-	if (!tb[SEG6_LOCAL_ACTION])
-		return;
-
-	action = rta_getattr_u32(tb[SEG6_LOCAL_ACTION]);
-
-	print_string(PRINT_ANY, "action",
-		     "action %s ", format_action_type(action));
-
-	if (tb[SEG6_LOCAL_SRH]) {
-		open_json_object("srh");
-		print_srh(fp, RTA_DATA(tb[SEG6_LOCAL_SRH]));
-		close_json_object();
-	}
-
-	if (tb[SEG6_LOCAL_TABLE])
-		print_uint(PRINT_ANY, "table",
-			   "table %u ", rta_getattr_u32(tb[SEG6_LOCAL_TABLE]));
-
-	if (tb[SEG6_LOCAL_NH4]) {
-		print_string(PRINT_ANY, "nh4",
-			     "nh4 %s ", rt_addr_n2a_rta(AF_INET, tb[SEG6_LOCAL_NH4]));
-	}
-
-	if (tb[SEG6_LOCAL_NH6]) {
-		print_string(PRINT_ANY, "nh6",
-			     "nh6 %s ", rt_addr_n2a_rta(AF_INET6, tb[SEG6_LOCAL_NH6]));
-	}
-
-	if (tb[SEG6_LOCAL_IIF]) {
-		int iif = rta_getattr_u32(tb[SEG6_LOCAL_IIF]);
-
-		print_string(PRINT_ANY, "iif",
-			     "iif %s ", ll_index_to_name(iif));
-	}
-
-	if (tb[SEG6_LOCAL_OIF]) {
-		int oif = rta_getattr_u32(tb[SEG6_LOCAL_OIF]);
-
-		print_string(PRINT_ANY, "oif",
-			     "oif %s ", ll_index_to_name(oif));
-	}
-
-	if (tb[SEG6_LOCAL_BPF])
-		print_encap_bpf_prog(fp, tb[SEG6_LOCAL_BPF], "endpoint");
-}
-
 static void print_encap_mpls(FILE *fp, struct rtattr *encap)
 {
 	struct rtattr *tb[MPLS_IPTUNNEL_MAX+1];
+	char abuf[256];
 
 	parse_rtattr_nested(tb, MPLS_IPTUNNEL_MAX, encap);
 
 	if (tb[MPLS_IPTUNNEL_DST])
-		print_string(PRINT_ANY, "dst", " %s ",
-			format_host_rta(AF_MPLS, tb[MPLS_IPTUNNEL_DST]));
-	if (tb[MPLS_IPTUNNEL_TTL])
-		print_uint(PRINT_ANY, "ttl", "ttl %u ",
-			rta_getattr_u8(tb[MPLS_IPTUNNEL_TTL]));
+		fprintf(fp, " %s ", format_host(AF_MPLS,
+			RTA_PAYLOAD(tb[MPLS_IPTUNNEL_DST]),
+			RTA_DATA(tb[MPLS_IPTUNNEL_DST]),
+			abuf, sizeof(abuf)));
 }
 
 static void print_encap_ip(FILE *fp, struct rtattr *encap)
 {
 	struct rtattr *tb[LWTUNNEL_IP_MAX+1];
-	__u16 flags;
+	char abuf[256];
 
 	parse_rtattr_nested(tb, LWTUNNEL_IP_MAX, encap);
 
 	if (tb[LWTUNNEL_IP_ID])
-		print_u64(PRINT_ANY, "id", "id %llu ",
-			   ntohll(rta_getattr_u64(tb[LWTUNNEL_IP_ID])));
+		fprintf(fp, "id %llu ", ntohll(rta_getattr_u64(tb[LWTUNNEL_IP_ID])));
 
 	if (tb[LWTUNNEL_IP_SRC])
-		print_color_string(PRINT_ANY, COLOR_INET,
-				   "src", "src %s ",
-				   rt_addr_n2a_rta(AF_INET, tb[LWTUNNEL_IP_SRC]));
+		fprintf(fp, "src %s ",
+			rt_addr_n2a(AF_INET,
+				    RTA_PAYLOAD(tb[LWTUNNEL_IP_SRC]),
+				    RTA_DATA(tb[LWTUNNEL_IP_SRC]),
+				    abuf, sizeof(abuf)));
 
 	if (tb[LWTUNNEL_IP_DST])
-		print_color_string(PRINT_ANY, COLOR_INET,
-				   "dst", "dst %s ",
-				   rt_addr_n2a_rta(AF_INET, tb[LWTUNNEL_IP_DST]));
+		fprintf(fp, "dst %s ",
+			rt_addr_n2a(AF_INET,
+				    RTA_PAYLOAD(tb[LWTUNNEL_IP_DST]),
+				    RTA_DATA(tb[LWTUNNEL_IP_DST]),
+				    abuf, sizeof(abuf)));
 
 	if (tb[LWTUNNEL_IP_TTL])
-		print_uint(PRINT_ANY, "ttl",
-			   "ttl %u ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
+		fprintf(fp, "ttl %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
 
 	if (tb[LWTUNNEL_IP_TOS])
-		print_uint(PRINT_ANY, "tos",
-			   "tos %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TOS]));
-
-	if (tb[LWTUNNEL_IP_FLAGS]) {
-		flags = rta_getattr_u16(tb[LWTUNNEL_IP_FLAGS]);
-		if (flags & TUNNEL_KEY)
-			print_bool(PRINT_ANY, "key", "key ", true);
-		if (flags & TUNNEL_CSUM)
-			print_bool(PRINT_ANY, "csum", "csum ", true);
-		if (flags & TUNNEL_SEQ)
-			print_bool(PRINT_ANY, "seq", "seq ", true);
-	}
+		fprintf(fp, "tos %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TOS]));
 }
 
 static void print_encap_ila(FILE *fp, struct rtattr *encap)
@@ -340,84 +109,41 @@
 	if (tb[ILA_ATTR_LOCATOR]) {
 		char abuf[ADDR64_BUF_SIZE];
 
-		addr64_n2a(rta_getattr_u64(tb[ILA_ATTR_LOCATOR]),
+		addr64_n2a(*(__u64 *)RTA_DATA(tb[ILA_ATTR_LOCATOR]),
 			   abuf, sizeof(abuf));
-		print_string(PRINT_ANY, "locator",
-			     " %s ", abuf);
+		fprintf(fp, " %s ", abuf);
 	}
-
-	if (tb[ILA_ATTR_CSUM_MODE])
-		print_string(PRINT_ANY, "csum_mode",
-			     " csum-mode %s ",
-			     ila_csum_mode2name(rta_getattr_u8(tb[ILA_ATTR_CSUM_MODE])));
-
-	if (tb[ILA_ATTR_IDENT_TYPE])
-		print_string(PRINT_ANY, "ident_type",
-			     " ident-type %s ",
-			     ila_ident_type2name(rta_getattr_u8(tb[ILA_ATTR_IDENT_TYPE])));
-
-	if (tb[ILA_ATTR_HOOK_TYPE])
-		print_string(PRINT_ANY, "hook_type",
-			     " hook-type %s ",
-			     ila_hook_type2name(rta_getattr_u8(tb[ILA_ATTR_HOOK_TYPE])));
 }
 
 static void print_encap_ip6(FILE *fp, struct rtattr *encap)
 {
 	struct rtattr *tb[LWTUNNEL_IP6_MAX+1];
-	__u16 flags;
+	char abuf[256];
 
 	parse_rtattr_nested(tb, LWTUNNEL_IP6_MAX, encap);
 
 	if (tb[LWTUNNEL_IP6_ID])
-		print_u64(PRINT_ANY, "id", "id %llu ",
-			    ntohll(rta_getattr_u64(tb[LWTUNNEL_IP6_ID])));
+		fprintf(fp, "id %llu ", ntohll(rta_getattr_u64(tb[LWTUNNEL_IP6_ID])));
 
 	if (tb[LWTUNNEL_IP6_SRC])
-		print_color_string(PRINT_ANY, COLOR_INET6,
-				   "src", "src %s ",
-				   rt_addr_n2a_rta(AF_INET6, tb[LWTUNNEL_IP6_SRC]));
+		fprintf(fp, "src %s ",
+			rt_addr_n2a(AF_INET6,
+				    RTA_PAYLOAD(tb[LWTUNNEL_IP6_SRC]),
+				    RTA_DATA(tb[LWTUNNEL_IP6_SRC]),
+				    abuf, sizeof(abuf)));
 
 	if (tb[LWTUNNEL_IP6_DST])
-		print_color_string(PRINT_ANY, COLOR_INET6,
-				   "dst", "dst %s ",
-				   rt_addr_n2a_rta(AF_INET6, tb[LWTUNNEL_IP6_DST]));
+		fprintf(fp, "dst %s ",
+			rt_addr_n2a(AF_INET6,
+				    RTA_PAYLOAD(tb[LWTUNNEL_IP6_DST]),
+				    RTA_DATA(tb[LWTUNNEL_IP6_DST]),
+				    abuf, sizeof(abuf)));
 
 	if (tb[LWTUNNEL_IP6_HOPLIMIT])
-		print_u64(PRINT_ANY, "hoplimit",
-			   "hoplimit %u ",
-			   rta_getattr_u8(tb[LWTUNNEL_IP6_HOPLIMIT]));
+		fprintf(fp, "hoplimit %d ", rta_getattr_u8(tb[LWTUNNEL_IP6_HOPLIMIT]));
 
 	if (tb[LWTUNNEL_IP6_TC])
-		print_uint(PRINT_ANY, "tc",
-			   "tc %u ", rta_getattr_u8(tb[LWTUNNEL_IP6_TC]));
-
-	if (tb[LWTUNNEL_IP6_FLAGS]) {
-		flags = rta_getattr_u16(tb[LWTUNNEL_IP6_FLAGS]);
-		if (flags & TUNNEL_KEY)
-			print_bool(PRINT_ANY, "key", "key ", true);
-		if (flags & TUNNEL_CSUM)
-			print_bool(PRINT_ANY, "csum", "csum ", true);
-		if (flags & TUNNEL_SEQ)
-			print_bool(PRINT_ANY, "seq", "seq ", true);
-	}
-}
-
-static void print_encap_bpf(FILE *fp, struct rtattr *encap)
-{
-	struct rtattr *tb[LWT_BPF_MAX+1];
-
-	parse_rtattr_nested(tb, LWT_BPF_MAX, encap);
-
-	if (tb[LWT_BPF_IN])
-		print_encap_bpf_prog(fp, tb[LWT_BPF_IN], "in");
-	if (tb[LWT_BPF_OUT])
-		print_encap_bpf_prog(fp, tb[LWT_BPF_OUT], "out");
-	if (tb[LWT_BPF_XMIT])
-		print_encap_bpf_prog(fp, tb[LWT_BPF_XMIT], "xmit");
-	if (tb[LWT_BPF_XMIT_HEADROOM])
-		print_uint(PRINT_ANY, "headroom",
-			   " %u ", rta_getattr_u32(tb[LWT_BPF_XMIT_HEADROOM]));
+		fprintf(fp, "tc %d ", rta_getattr_u8(tb[LWTUNNEL_IP6_TC]));
 }
 
 void lwt_print_encap(FILE *fp, struct rtattr *encap_type,
@@ -430,7 +156,7 @@
 
 	et = rta_getattr_u16(encap_type);
 
-	print_string(PRINT_ANY, "encap", " encap %s ", format_encap_type(et));
+	fprintf(fp, " encap %s ", format_encap_type(et));
 
 	switch (et) {
 	case LWTUNNEL_ENCAP_MPLS:
@@ -445,443 +171,80 @@
 	case LWTUNNEL_ENCAP_IP6:
 		print_encap_ip6(fp, encap);
 		break;
-	case LWTUNNEL_ENCAP_BPF:
-		print_encap_bpf(fp, encap);
-		break;
-	case LWTUNNEL_ENCAP_SEG6:
-		print_encap_seg6(fp, encap);
-		break;
-	case LWTUNNEL_ENCAP_SEG6_LOCAL:
-		print_encap_seg6local(fp, encap);
-		break;
 	}
 }
 
-static struct ipv6_sr_hdr *parse_srh(char *segbuf, int hmac, bool encap)
-{
-	struct ipv6_sr_hdr *srh;
-	int nsegs = 0;
-	int srhlen;
-	char *s;
-	int i;
-
-	s = segbuf;
-	for (i = 0; *s; *s++ == ',' ? i++ : *s);
-	nsegs = i + 1;
-
-	if (!encap)
-		nsegs++;
-
-	srhlen = 8 + 16*nsegs;
-
-	if (hmac)
-		srhlen += 40;
-
-	srh = malloc(srhlen);
-	memset(srh, 0, srhlen);
-
-	srh->hdrlen = (srhlen >> 3) - 1;
-	srh->type = 4;
-	srh->segments_left = nsegs - 1;
-	srh->first_segment = nsegs - 1;
-
-	if (hmac)
-		srh->flags |= SR6_FLAG1_HMAC;
-
-	i = srh->first_segment;
-	for (s = strtok(segbuf, ","); s; s = strtok(NULL, ",")) {
-		inet_prefix addr;
-
-		get_addr(&addr, s, AF_INET6);
-		memcpy(&srh->segments[i], addr.data, sizeof(struct in6_addr));
-		i--;
-	}
-
-	if (hmac) {
-		struct sr6_tlv_hmac *tlv;
-
-		tlv = (struct sr6_tlv_hmac *)((char *)srh + srhlen - 40);
-		tlv->tlvhdr.type = SR6_TLV_HMAC;
-		tlv->tlvhdr.len = 38;
-		tlv->hmackeyid = htonl(hmac);
-	}
-
-	return srh;
-}
-
-static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
-			    char ***argvp)
-{
-	int mode_ok = 0, segs_ok = 0, hmac_ok = 0;
-	struct seg6_iptunnel_encap *tuninfo;
-	struct ipv6_sr_hdr *srh;
-	char **argv = *argvp;
-	char segbuf[1024] = "";
-	int argc = *argcp;
-	int encap = -1;
-	__u32 hmac = 0;
-	int ret = 0;
-	int srhlen;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "mode") == 0) {
-			NEXT_ARG();
-			if (mode_ok++)
-				duparg2("mode", *argv);
-			encap = read_seg6mode_type(*argv);
-			if (encap < 0)
-				invarg("\"mode\" value is invalid\n", *argv);
-		} else if (strcmp(*argv, "segs") == 0) {
-			NEXT_ARG();
-			if (segs_ok++)
-				duparg2("segs", *argv);
-			if (encap == -1)
-				invarg("\"segs\" provided before \"mode\"\n",
-				       *argv);
-
-			strlcpy(segbuf, *argv, 1024);
-		} else if (strcmp(*argv, "hmac") == 0) {
-			NEXT_ARG();
-			if (hmac_ok++)
-				duparg2("hmac", *argv);
-			get_u32(&hmac, *argv, 0);
-		} else {
-			break;
-		}
-		argc--; argv++;
-	}
-
-	srh = parse_srh(segbuf, hmac, encap);
-	srhlen = (srh->hdrlen + 1) << 3;
-
-	tuninfo = malloc(sizeof(*tuninfo) + srhlen);
-	memset(tuninfo, 0, sizeof(*tuninfo) + srhlen);
-
-	tuninfo->mode = encap;
-
-	memcpy(tuninfo->srh, srh, srhlen);
-
-	if (rta_addattr_l(rta, len, SEG6_IPTUNNEL_SRH, tuninfo,
-			  sizeof(*tuninfo) + srhlen)) {
-		ret = -1;
-		goto out;
-	}
-
-	*argcp = argc + 1;
-	*argvp = argv - 1;
-
-out:
-	free(tuninfo);
-	free(srh);
-
-	return ret;
-}
-
-struct lwt_x {
-	struct rtattr *rta;
-	size_t len;
-};
-
-static void bpf_lwt_cb(void *lwt_ptr, int fd, const char *annotation)
-{
-	struct lwt_x *x = lwt_ptr;
-
-	rta_addattr32(x->rta, x->len, LWT_BPF_PROG_FD, fd);
-	rta_addattr_l(x->rta, x->len, LWT_BPF_PROG_NAME, annotation,
-		      strlen(annotation) + 1);
-}
-
-static const struct bpf_cfg_ops bpf_cb_ops = {
-	.ebpf_cb = bpf_lwt_cb,
-};
-
-static int lwt_parse_bpf(struct rtattr *rta, size_t len,
-			 int *argcp, char ***argvp,
-			 int attr, const enum bpf_prog_type bpf_type)
-{
-	struct bpf_cfg_in cfg = {
-		.type = bpf_type,
-		.argc = *argcp,
-		.argv = *argvp,
-	};
-	struct lwt_x x = {
-		.rta = rta,
-		.len = len,
-	};
-	struct rtattr *nest;
-	int err;
-
-	nest = rta_nest(rta, len, attr);
-	err = bpf_parse_and_load_common(&cfg, &bpf_cb_ops, &x);
-	if (err < 0) {
-		fprintf(stderr, "Failed to parse eBPF program: %s\n",
-			strerror(-err));
-		return -1;
-	}
-	rta_nest_end(rta, nest);
-
-	*argcp = cfg.argc;
-	*argvp = cfg.argv;
-
-	return 0;
-}
-
-static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
-				 char ***argvp)
-{
-	int segs_ok = 0, hmac_ok = 0, table_ok = 0, nh4_ok = 0, nh6_ok = 0;
-	int iif_ok = 0, oif_ok = 0, action_ok = 0, srh_ok = 0, bpf_ok = 0;
-	__u32 action = 0, table, iif, oif;
-	struct ipv6_sr_hdr *srh;
-	char **argv = *argvp;
-	int argc = *argcp;
-	char segbuf[1024];
-	inet_prefix addr;
-	__u32 hmac = 0;
-	int ret = 0;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "action") == 0) {
-			NEXT_ARG();
-			if (action_ok++)
-				duparg2("action", *argv);
-			action = read_action_type(*argv);
-			if (!action)
-				invarg("\"action\" value is invalid\n", *argv);
-			ret = rta_addattr32(rta, len, SEG6_LOCAL_ACTION,
-					    action);
-		} else if (strcmp(*argv, "table") == 0) {
-			NEXT_ARG();
-			if (table_ok++)
-				duparg2("table", *argv);
-			get_u32(&table, *argv, 0);
-			ret = rta_addattr32(rta, len, SEG6_LOCAL_TABLE, table);
-		} else if (strcmp(*argv, "nh4") == 0) {
-			NEXT_ARG();
-			if (nh4_ok++)
-				duparg2("nh4", *argv);
-			get_addr(&addr, *argv, AF_INET);
-			ret = rta_addattr_l(rta, len, SEG6_LOCAL_NH4,
-					    &addr.data, addr.bytelen);
-		} else if (strcmp(*argv, "nh6") == 0) {
-			NEXT_ARG();
-			if (nh6_ok++)
-				duparg2("nh6", *argv);
-			get_addr(&addr, *argv, AF_INET6);
-			ret = rta_addattr_l(rta, len, SEG6_LOCAL_NH6,
-					    &addr.data, addr.bytelen);
-		} else if (strcmp(*argv, "iif") == 0) {
-			NEXT_ARG();
-			if (iif_ok++)
-				duparg2("iif", *argv);
-			iif = ll_name_to_index(*argv);
-			if (!iif)
-				exit(nodev(*argv));
-			ret = rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif);
-		} else if (strcmp(*argv, "oif") == 0) {
-			NEXT_ARG();
-			if (oif_ok++)
-				duparg2("oif", *argv);
-			oif = ll_name_to_index(*argv);
-			if (!oif)
-				exit(nodev(*argv));
-			ret = rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif);
-		} else if (strcmp(*argv, "srh") == 0) {
-			NEXT_ARG();
-			if (srh_ok++)
-				duparg2("srh", *argv);
-			if (strcmp(*argv, "segs") != 0)
-				invarg("missing \"segs\" attribute for srh\n",
-					*argv);
-			NEXT_ARG();
-			if (segs_ok++)
-				duparg2("segs", *argv);
-			strncpy(segbuf, *argv, 1024);
-			segbuf[1023] = 0;
-			if (!NEXT_ARG_OK())
-				break;
-			NEXT_ARG();
-			if (strcmp(*argv, "hmac") == 0) {
-				NEXT_ARG();
-				if (hmac_ok++)
-					duparg2("hmac", *argv);
-				get_u32(&hmac, *argv, 0);
-			} else {
-				continue;
-			}
-		} else if (strcmp(*argv, "endpoint") == 0) {
-			NEXT_ARG();
-			if (bpf_ok++)
-				duparg2("endpoint", *argv);
-
-			if (lwt_parse_bpf(rta, len, &argc, &argv, SEG6_LOCAL_BPF,
-			    BPF_PROG_TYPE_LWT_SEG6LOCAL) < 0)
-				exit(-1);
-		} else {
-			break;
-		}
-		if (ret)
-			return ret;
-		argc--; argv++;
-	}
-
-	if (!action) {
-		fprintf(stderr, "Missing action type\n");
-		exit(-1);
-	}
-
-	if (srh_ok) {
-		int srhlen;
-
-		srh = parse_srh(segbuf, hmac,
-				action == SEG6_LOCAL_ACTION_END_B6_ENCAP);
-		srhlen = (srh->hdrlen + 1) << 3;
-		ret = rta_addattr_l(rta, len, SEG6_LOCAL_SRH, srh, srhlen);
-		free(srh);
-	}
-
-	*argcp = argc + 1;
-	*argvp = argv - 1;
-
-	return ret;
-}
-
-static int parse_encap_mpls(struct rtattr *rta, size_t len,
-			    int *argcp, char ***argvp)
+static int parse_encap_mpls(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
 {
 	inet_prefix addr;
 	int argc = *argcp;
 	char **argv = *argvp;
-	int ttl_ok = 0;
 
 	if (get_addr(&addr, *argv, AF_MPLS)) {
-		fprintf(stderr,
-			"Error: an inet address is expected rather than \"%s\".\n",
-			*argv);
+		fprintf(stderr, "Error: an inet address is expected rather than \"%s\".\n", *argv);
 		exit(1);
 	}
 
-	if (rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST,
-			  &addr.data, addr.bytelen))
-		return -1;
+	rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST, &addr.data,
+		      addr.bytelen);
 
-	argc--;
-	argv++;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "ttl") == 0) {
-			__u8 ttl;
-
-			NEXT_ARG();
-			if (ttl_ok++)
-				duparg2("ttl", *argv);
-			if (get_u8(&ttl, *argv, 0))
-				invarg("\"ttl\" value is invalid\n", *argv);
-			if (rta_addattr8(rta, len, MPLS_IPTUNNEL_TTL, ttl))
-				return -1;
-		} else {
-			break;
-		}
-		argc--; argv++;
-	}
-
-	/* argv is currently the first unparsed argument,
-	 * but the lwt_parse_encap() caller will move to the next,
-	 * so step back
-	 */
-	*argcp = argc + 1;
-	*argvp = argv - 1;
+	*argcp = argc;
+	*argvp = argv;
 
 	return 0;
 }
 
-static int parse_encap_ip(struct rtattr *rta, size_t len,
-			  int *argcp, char ***argvp)
+static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
 {
-	int id_ok = 0, dst_ok = 0, src_ok = 0, tos_ok = 0, ttl_ok = 0;
-	int key_ok = 0, csum_ok = 0, seq_ok = 0;
+	int id_ok = 0, dst_ok = 0, tos_ok = 0, ttl_ok = 0;
 	char **argv = *argvp;
 	int argc = *argcp;
-	int ret = 0;
-	__u16 flags = 0;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "id") == 0) {
 			__u64 id;
-
 			NEXT_ARG();
 			if (id_ok++)
 				duparg2("id", *argv);
-			if (get_be64(&id, *argv, 0))
+			if (get_u64(&id, *argv, 0))
 				invarg("\"id\" value is invalid\n", *argv);
-			ret = rta_addattr64(rta, len, LWTUNNEL_IP_ID, id);
+			rta_addattr64(rta, len, LWTUNNEL_IP_ID, htonll(id));
 		} else if (strcmp(*argv, "dst") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (dst_ok++)
 				duparg2("dst", *argv);
 			get_addr(&addr, *argv, AF_INET);
-			ret = rta_addattr_l(rta, len, LWTUNNEL_IP_DST,
-					    &addr.data, addr.bytelen);
-		} else if (strcmp(*argv, "src") == 0) {
-			inet_prefix addr;
-
-			NEXT_ARG();
-			if (src_ok++)
-				duparg2("src", *argv);
-			get_addr(&addr, *argv, AF_INET);
-			ret = rta_addattr_l(rta, len, LWTUNNEL_IP_SRC,
-					    &addr.data, addr.bytelen);
+			rta_addattr_l(rta, len, LWTUNNEL_IP_DST, &addr.data, addr.bytelen);
 		} else if (strcmp(*argv, "tos") == 0) {
 			__u32 tos;
-
 			NEXT_ARG();
 			if (tos_ok++)
 				duparg2("tos", *argv);
 			if (rtnl_dsfield_a2n(&tos, *argv))
 				invarg("\"tos\" value is invalid\n", *argv);
-			ret = rta_addattr8(rta, len, LWTUNNEL_IP_TOS, tos);
+			rta_addattr8(rta, len, LWTUNNEL_IP_TOS, tos);
 		} else if (strcmp(*argv, "ttl") == 0) {
 			__u8 ttl;
-
 			NEXT_ARG();
 			if (ttl_ok++)
 				duparg2("ttl", *argv);
 			if (get_u8(&ttl, *argv, 0))
 				invarg("\"ttl\" value is invalid\n", *argv);
-			ret = rta_addattr8(rta, len, LWTUNNEL_IP_TTL, ttl);
-		} else if (strcmp(*argv, "key") == 0) {
-			if (key_ok++)
-				duparg2("key", *argv);
-			flags |= TUNNEL_KEY;
-		} else if (strcmp(*argv, "csum") == 0) {
-			if (csum_ok++)
-				duparg2("csum", *argv);
-			flags |= TUNNEL_CSUM;
-		} else if (strcmp(*argv, "seq") == 0) {
-			if (seq_ok++)
-				duparg2("seq", *argv);
-			flags |= TUNNEL_SEQ;
+			rta_addattr8(rta, len, LWTUNNEL_IP_TTL, ttl);
 		} else {
 			break;
 		}
-		if (ret)
-			break;
 		argc--; argv++;
 	}
 
-	if (flags)
-		ret = rta_addattr16(rta, len,  LWTUNNEL_IP_FLAGS, flags);
-
 	/* argv is currently the first unparsed argument,
 	 * but the lwt_parse_encap() caller will move to the next,
-	 * so step back
-	 */
+	 * so step back */
 	*argcp = argc + 1;
 	*argvp = argv - 1;
 
-	return ret;
+	return 0;
 }
 
 static int parse_encap_ila(struct rtattr *rta, size_t len,
@@ -890,235 +253,79 @@
 	__u64 locator;
 	int argc = *argcp;
 	char **argv = *argvp;
-	int ret = 0;
 
 	if (get_addr64(&locator, *argv) < 0) {
 		fprintf(stderr, "Bad locator: %s\n", *argv);
 		exit(1);
 	}
 
-	argc--; argv++;
+	rta_addattr64(rta, 1024, ILA_ATTR_LOCATOR, locator);
 
-	if (rta_addattr64(rta, len, ILA_ATTR_LOCATOR, locator))
-		return -1;
+	*argcp = argc;
+	*argvp = argv;
 
-	while (argc > 0) {
-		if (strcmp(*argv, "csum-mode") == 0) {
-			int csum_mode;
-
-			NEXT_ARG();
-
-			csum_mode = ila_csum_name2mode(*argv);
-			if (csum_mode < 0)
-				invarg("\"csum-mode\" value is invalid\n",
-				       *argv);
-
-			ret = rta_addattr8(rta, len, ILA_ATTR_CSUM_MODE,
-					   (__u8)csum_mode);
-
-			argc--; argv++;
-		} else if (strcmp(*argv, "ident-type") == 0) {
-			int ident_type;
-
-			NEXT_ARG();
-
-			ident_type = ila_ident_name2type(*argv);
-			if (ident_type < 0)
-				invarg("\"ident-type\" value is invalid\n",
-				       *argv);
-
-			ret = rta_addattr8(rta, len, ILA_ATTR_IDENT_TYPE,
-					   (__u8)ident_type);
-
-			argc--; argv++;
-		} else if (strcmp(*argv, "hook-type") == 0) {
-			int hook_type;
-
-			NEXT_ARG();
-
-			hook_type = ila_hook_name2type(*argv);
-			if (hook_type < 0)
-				invarg("\"hook-type\" value is invalid\n",
-				       *argv);
-
-			ret = rta_addattr8(rta, len, ILA_ATTR_HOOK_TYPE,
-					   (__u8)hook_type);
-
-			argc--; argv++;
-		} else {
-			break;
-		}
-		if (ret)
-			break;
-	}
-
-	/* argv is currently the first unparsed argument,
-	 * but the lwt_parse_encap() caller will move to the next,
-	 * so step back
-	 */
-	*argcp = argc + 1;
-	*argvp = argv - 1;
-
-	return ret;
+	return 0;
 }
 
-static int parse_encap_ip6(struct rtattr *rta, size_t len,
-			   int *argcp, char ***argvp)
+static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
 {
-	int id_ok = 0, dst_ok = 0, src_ok = 0, tos_ok = 0, ttl_ok = 0;
-	int key_ok = 0, csum_ok = 0, seq_ok = 0;
+	int id_ok = 0, dst_ok = 0, tos_ok = 0, ttl_ok = 0;
 	char **argv = *argvp;
 	int argc = *argcp;
-	int ret = 0;
-	__u16 flags = 0;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "id") == 0) {
 			__u64 id;
-
 			NEXT_ARG();
 			if (id_ok++)
 				duparg2("id", *argv);
-			if (get_be64(&id, *argv, 0))
+			if (get_u64(&id, *argv, 0))
 				invarg("\"id\" value is invalid\n", *argv);
-			ret = rta_addattr64(rta, len, LWTUNNEL_IP6_ID, id);
+			rta_addattr64(rta, len, LWTUNNEL_IP6_ID, htonll(id));
 		} else if (strcmp(*argv, "dst") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (dst_ok++)
 				duparg2("dst", *argv);
 			get_addr(&addr, *argv, AF_INET6);
-			ret = rta_addattr_l(rta, len, LWTUNNEL_IP6_DST,
-					    &addr.data, addr.bytelen);
-		} else if (strcmp(*argv, "src") == 0) {
-			inet_prefix addr;
-
-			NEXT_ARG();
-			if (src_ok++)
-				duparg2("src", *argv);
-			get_addr(&addr, *argv, AF_INET6);
-			ret = rta_addattr_l(rta, len, LWTUNNEL_IP6_SRC,
-					    &addr.data, addr.bytelen);
+			rta_addattr_l(rta, len, LWTUNNEL_IP6_DST, &addr.data, addr.bytelen);
 		} else if (strcmp(*argv, "tc") == 0) {
 			__u32 tc;
-
 			NEXT_ARG();
 			if (tos_ok++)
 				duparg2("tc", *argv);
 			if (rtnl_dsfield_a2n(&tc, *argv))
 				invarg("\"tc\" value is invalid\n", *argv);
-			ret = rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc);
+			rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc);
 		} else if (strcmp(*argv, "hoplimit") == 0) {
 			__u8 hoplimit;
-
 			NEXT_ARG();
 			if (ttl_ok++)
 				duparg2("hoplimit", *argv);
 			if (get_u8(&hoplimit, *argv, 0))
-				invarg("\"hoplimit\" value is invalid\n",
-				       *argv);
-			ret = rta_addattr8(rta, len, LWTUNNEL_IP6_HOPLIMIT,
-					   hoplimit);
-		} else if (strcmp(*argv, "key") == 0) {
-			if (key_ok++)
-				duparg2("key", *argv);
-			flags |= TUNNEL_KEY;
-		} else if (strcmp(*argv, "csum") == 0) {
-			if (csum_ok++)
-				duparg2("csum", *argv);
-			flags |= TUNNEL_CSUM;
-		} else if (strcmp(*argv, "seq") == 0) {
-			if (seq_ok++)
-				duparg2("seq", *argv);
-			flags |= TUNNEL_SEQ;
+				invarg("\"hoplimit\" value is invalid\n", *argv);
+			rta_addattr8(rta, len, LWTUNNEL_IP6_HOPLIMIT, hoplimit);
 		} else {
 			break;
 		}
-		if (ret)
-			break;
 		argc--; argv++;
 	}
 
-	if (flags)
-		ret = rta_addattr16(rta, len,  LWTUNNEL_IP6_FLAGS, flags);
-
 	/* argv is currently the first unparsed argument,
 	 * but the lwt_parse_encap() caller will move to the next,
-	 * so step back
-	 */
-	*argcp = argc + 1;
-	*argvp = argv - 1;
-
-	return ret;
-}
-
-static void lwt_bpf_usage(void)
-{
-	fprintf(stderr, "Usage: ip route ... encap bpf [ in BPF ] [ out BPF ] [ xmit BPF ] [...]\n");
-	fprintf(stderr, "BPF := obj FILE [ section NAME ] [ verbose ]\n");
-	exit(-1);
-}
-
-static int parse_encap_bpf(struct rtattr *rta, size_t len, int *argcp,
-			   char ***argvp)
-{
-	char **argv = *argvp;
-	int argc = *argcp;
-	int headroom_set = 0;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "in") == 0) {
-			NEXT_ARG();
-			if (lwt_parse_bpf(rta, len, &argc, &argv, LWT_BPF_IN,
-					  BPF_PROG_TYPE_LWT_IN) < 0)
-				return -1;
-		} else if (strcmp(*argv, "out") == 0) {
-			NEXT_ARG();
-			if (lwt_parse_bpf(rta, len, &argc, &argv, LWT_BPF_OUT,
-					  BPF_PROG_TYPE_LWT_OUT) < 0)
-				return -1;
-		} else if (strcmp(*argv, "xmit") == 0) {
-			NEXT_ARG();
-			if (lwt_parse_bpf(rta, len, &argc, &argv, LWT_BPF_XMIT,
-					  BPF_PROG_TYPE_LWT_XMIT) < 0)
-				return -1;
-		} else if (strcmp(*argv, "headroom") == 0) {
-			unsigned int headroom;
-
-			NEXT_ARG();
-			if (get_unsigned(&headroom, *argv, 0) || headroom == 0)
-				invarg("headroom is invalid\n", *argv);
-			if (!headroom_set)
-				rta_addattr32(rta, len, LWT_BPF_XMIT_HEADROOM,
-					      headroom);
-			headroom_set = 1;
-		} else if (strcmp(*argv, "help") == 0) {
-			lwt_bpf_usage();
-		} else {
-			break;
-		}
-		NEXT_ARG_FWD();
-	}
-
-	/* argv is currently the first unparsed argument,
-	 * but the lwt_parse_encap() caller will move to the next,
-	 * so step back
-	 */
+	 * so step back */
 	*argcp = argc + 1;
 	*argvp = argv - 1;
 
 	return 0;
 }
 
-int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp,
-		    int encap_attr, int encap_type_attr)
+int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
 {
 	struct rtattr *nest;
 	int argc = *argcp;
 	char **argv = *argvp;
 	__u16 type;
-	int ret = 0;
 
 	NEXT_ARG();
 	type = read_encap_type(*argv);
@@ -1127,48 +334,34 @@
 
 	NEXT_ARG();
 	if (argc <= 1) {
-		fprintf(stderr,
-			"Error: unexpected end of line after \"encap\"\n");
+		fprintf(stderr, "Error: unexpected end of line after \"encap\"\n");
 		exit(-1);
 	}
 
-	nest = rta_nest(rta, len, encap_attr);
+	nest = rta_nest(rta, 1024, RTA_ENCAP);
 	switch (type) {
 	case LWTUNNEL_ENCAP_MPLS:
-		ret = parse_encap_mpls(rta, len, &argc, &argv);
+		parse_encap_mpls(rta, len, &argc, &argv);
 		break;
 	case LWTUNNEL_ENCAP_IP:
-		ret = parse_encap_ip(rta, len, &argc, &argv);
+		parse_encap_ip(rta, len, &argc, &argv);
 		break;
 	case LWTUNNEL_ENCAP_ILA:
-		ret = parse_encap_ila(rta, len, &argc, &argv);
+		parse_encap_ila(rta, len, &argc, &argv);
 		break;
 	case LWTUNNEL_ENCAP_IP6:
-		ret = parse_encap_ip6(rta, len, &argc, &argv);
-		break;
-	case LWTUNNEL_ENCAP_BPF:
-		if (parse_encap_bpf(rta, len, &argc, &argv) < 0)
-			exit(-1);
-		break;
-	case LWTUNNEL_ENCAP_SEG6:
-		ret = parse_encap_seg6(rta, len, &argc, &argv);
-		break;
-	case LWTUNNEL_ENCAP_SEG6_LOCAL:
-		ret = parse_encap_seg6local(rta, len, &argc, &argv);
+		parse_encap_ip6(rta, len, &argc, &argv);
 		break;
 	default:
 		fprintf(stderr, "Error: unsupported encap type\n");
 		break;
 	}
-	if (ret)
-		return ret;
-
 	rta_nest_end(rta, nest);
 
-	ret = rta_addattr16(rta, len, encap_type_attr, type);
+	rta_addattr16(rta, 1024, RTA_ENCAP_TYPE, type);
 
 	*argcp = argc;
 	*argvp = argv;
 
-	return ret;
+	return 0;
 }
diff --git a/ip/iproute_lwtunnel.h b/ip/iproute_lwtunnel.h
new file mode 100644
index 0000000..b82b58a
--- /dev/null
+++ b/ip/iproute_lwtunnel.h
@@ -0,0 +1,8 @@
+#ifndef __LWTUNNEL_H__
+#define __LETUNNEL_H__ 1
+
+int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp);
+void lwt_print_encap(FILE *fp, struct rtattr *encap_type,
+		     struct rtattr *encap);
+
+#endif
diff --git a/ip/iprule.c b/ip/iprule.c
index 9f5d998..ac835ab 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -13,26 +13,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <arpa/inet.h>
 #include <string.h>
-#include <linux/if.h>
 #include <linux/fib_rules.h>
 #include <errno.h>
 
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
-
-enum list_action {
-	IPRULE_LIST,
-	IPRULE_FLUSH,
-	IPRULE_SAVE,
-};
 
 extern struct rtnl_handle rth;
 
@@ -40,264 +33,95 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip rule { add | del } SELECTOR ACTION\n"
-		"       ip rule { flush | save | restore }\n"
-		"       ip rule [ list [ SELECTOR ]]\n"
-		"SELECTOR := [ not ] [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ]\n"
-		"            [ iif STRING ] [ oif STRING ] [ pref NUMBER ] [ l3mdev ]\n"
-		"            [ uidrange NUMBER-NUMBER ]\n"
-		"            [ ipproto PROTOCOL ]\n"
-		"            [ sport [ NUMBER | NUMBER-NUMBER ]\n"
-		"            [ dport [ NUMBER | NUMBER-NUMBER ] ]\n"
-		"ACTION := [ table TABLE_ID ]\n"
-		"          [ protocol PROTO ]\n"
-		"          [ nat ADDRESS ]\n"
-		"          [ realms [SRCREALM/]DSTREALM ]\n"
-		"          [ goto NUMBER ]\n"
-		"          SUPPRESSOR\n"
-		"SUPPRESSOR := [ suppress_prefixlength NUMBER ]\n"
-		"              [ suppress_ifgroup DEVGROUP ]\n"
-		"TABLE_ID := [ local | main | default | NUMBER ]\n");
+	fprintf(stderr, "Usage: ip rule [ list | add | del | flush | save ] SELECTOR ACTION\n");
+	fprintf(stderr, "       ip rule restore\n");
+	fprintf(stderr, "SELECTOR := [ not ] [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ]\n");
+	fprintf(stderr, "            [ iif STRING ] [ oif STRING ] [ pref NUMBER ] [ uidrange UID1-UID2 ]\n");
+	fprintf(stderr, "ACTION := [ table TABLE_ID ]\n");
+	fprintf(stderr, "          [ realms [SRCREALM/]DSTREALM ]\n");
+	fprintf(stderr, "          [ goto NUMBER ]\n");
+	fprintf(stderr, "          SUPPRESSOR\n");
+	fprintf(stderr, "SUPPRESSOR := [ suppress_prefixlength NUMBER ]\n");
+	fprintf(stderr, "              [ suppress_ifgroup DEVGROUP ]\n");
+	fprintf(stderr, "TABLE_ID := [ local | main | default | NUMBER ]\n");
 	exit(-1);
 }
 
-static struct
+int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
-	int not;
-	int l3mdev;
-	int iifmask, oifmask, uidrange;
-	unsigned int tb;
-	unsigned int tos, tosmask;
-	unsigned int pref, prefmask;
-	unsigned int fwmark, fwmask;
-	uint64_t tun_id;
-	char iif[IFNAMSIZ];
-	char oif[IFNAMSIZ];
-	struct fib_rule_uid_range range;
-	inet_prefix src;
-	inet_prefix dst;
-	int protocol;
-	int protocolmask;
-	struct fib_rule_port_range sport;
-	struct fib_rule_port_range dport;
-	__u8 ipproto;
-} filter;
-
-static inline int frh_get_table(struct fib_rule_hdr *frh, struct rtattr **tb)
-{
-	__u32 table = frh->table;
-	if (tb[RTA_TABLE])
-		table = rta_getattr_u32(tb[RTA_TABLE]);
-	return table;
-}
-
-static bool filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
-{
-	struct fib_rule_hdr *frh = NLMSG_DATA(n);
-	__u32 table;
-
-	if (preferred_family != AF_UNSPEC && frh->family != preferred_family)
-		return false;
-
-	if (filter.prefmask &&
-	    filter.pref ^ (tb[FRA_PRIORITY] ? rta_getattr_u32(tb[FRA_PRIORITY]) : 0))
-		return false;
-	if (filter.not && !(frh->flags & FIB_RULE_INVERT))
-		return false;
-
-	if (filter.src.family) {
-		inet_prefix *f_src = &filter.src;
-
-		if (f_src->family != frh->family ||
-		    f_src->bitlen > frh->src_len)
-			return false;
-
-		if (inet_addr_match_rta(f_src, tb[FRA_SRC]))
-			return false;
-	}
-
-	if (filter.dst.family) {
-		inet_prefix *f_dst = &filter.dst;
-
-		if (f_dst->family != frh->family ||
-		    f_dst->bitlen > frh->dst_len)
-			return false;
-
-		if (inet_addr_match_rta(f_dst, tb[FRA_DST]))
-			return false;
-	}
-
-	if (filter.tosmask && filter.tos ^ frh->tos)
-		return false;
-
-	if (filter.fwmark) {
-		__u32 mark = 0;
-
-		if (tb[FRA_FWMARK])
-			mark = rta_getattr_u32(tb[FRA_FWMARK]);
-		if (filter.fwmark ^ mark)
-			return false;
-	}
-	if (filter.fwmask) {
-		__u32 mask = 0;
-
-		if (tb[FRA_FWMASK])
-			mask = rta_getattr_u32(tb[FRA_FWMASK]);
-		if (filter.fwmask ^ mask)
-			return false;
-	}
-
-	if (filter.iifmask) {
-		if (tb[FRA_IFNAME]) {
-			if (strcmp(filter.iif, rta_getattr_str(tb[FRA_IFNAME])) != 0)
-				return false;
-		} else {
-			return false;
-		}
-	}
-
-	if (filter.oifmask) {
-		if (tb[FRA_OIFNAME]) {
-			if (strcmp(filter.oif, rta_getattr_str(tb[FRA_OIFNAME])) != 0)
-				return false;
-		} else {
-			return false;
-		}
-	}
-
-	if (filter.l3mdev && !(tb[FRA_L3MDEV] && rta_getattr_u8(tb[FRA_L3MDEV])))
-		return false;
-
-	if (filter.uidrange) {
-		struct fib_rule_uid_range *r = RTA_DATA(tb[FRA_UID_RANGE]);
-
-		if (!tb[FRA_UID_RANGE] ||
-		    r->start != filter.range.start ||
-		    r->end != filter.range.end)
-			return false;
-	}
-
-	if (filter.ipproto) {
-		__u8 ipproto = 0;
-
-		if (tb[FRA_IP_PROTO])
-			ipproto = rta_getattr_u8(tb[FRA_IP_PROTO]);
-		if (filter.ipproto != ipproto)
-			return false;
-	}
-
-	if (filter.sport.start) {
-		const struct fib_rule_port_range *r;
-
-		if (!tb[FRA_SPORT_RANGE])
-			return false;
-
-		r = RTA_DATA(tb[FRA_SPORT_RANGE]);
-		if (r->start != filter.sport.start ||
-		    r->end != filter.sport.end)
-			return false;
-	}
-
-	if (filter.dport.start) {
-		const struct fib_rule_port_range *r;
-
-		if (!tb[FRA_DPORT_RANGE])
-			return false;
-
-		r = RTA_DATA(tb[FRA_DPORT_RANGE]);
-		if (r->start != filter.dport.start ||
-		    r->end != filter.dport.end)
-			return false;
-	}
-
-	if (filter.tun_id) {
-		__u64 tun_id = 0;
-
-		if (tb[FRA_TUN_ID]) {
-			tun_id = ntohll(rta_getattr_u64(tb[FRA_TUN_ID]));
-			if (filter.tun_id != tun_id)
-				return false;
-		} else {
-			return false;
-		}
-	}
-
-	table = frh_get_table(frh, tb);
-	if (filter.tb > 0 && filter.tb ^ table)
-		return false;
-
-	return true;
-}
-
-int print_rule(struct nlmsghdr *n, void *arg)
-{
-	FILE *fp = arg;
-	struct fib_rule_hdr *frh = NLMSG_DATA(n);
+	FILE *fp = (FILE*)arg;
+	struct rtmsg *r = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	int host_len = -1;
-	__u32 table, prio = 0;
-	struct rtattr *tb[FRA_MAX+1];
+	__u32 table;
+	struct rtattr * tb[FRA_MAX+1];
+	char abuf[256];
 	SPRINT_BUF(b1);
 
 	if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
 		return 0;
 
-	len -= NLMSG_LENGTH(sizeof(*frh));
+	len -= NLMSG_LENGTH(sizeof(*r));
 	if (len < 0)
 		return -1;
 
-	parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len);
+	parse_rtattr(tb, FRA_MAX, RTM_RTA(r), len);
 
-	host_len = af_bit_len(frh->family);
+	host_len = af_bit_len(r->rtm_family);
 
-	if (!filter_nlmsg(n, tb, host_len))
-		return 0;
-
-	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELRULE)
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
 	if (tb[FRA_PRIORITY])
-		prio = rta_getattr_u32(tb[FRA_PRIORITY]);
+		fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[FRA_PRIORITY]));
+	else
+		fprintf(fp, "0:\t");
 
-	print_uint(PRINT_ANY, "priority", "%u:\t", prio);
-
-	if (frh->flags & FIB_RULE_INVERT)
-		print_null(PRINT_ANY, "not", "not ", NULL);
+	if (r->rtm_flags & FIB_RULE_INVERT)
+		fprintf(fp, "not ");
 
 	if (tb[FRA_SRC]) {
-		const char *src = rt_addr_n2a_rta(frh->family, tb[FRA_SRC]);
-
-		print_string(PRINT_FP, NULL, "from ", NULL);
-		print_color_string(PRINT_ANY, ifa_family_color(frh->family),
-				   "src", "%s", src);
-		if (frh->src_len != host_len)
-			print_uint(PRINT_ANY, "srclen", "/%u", frh->src_len);
-	} else if (frh->src_len) {
-		print_string(PRINT_ANY, "src", "from %s", "0");
-		print_uint(PRINT_ANY, "srclen", "/%u", frh->src_len);
+		if (r->rtm_src_len != host_len) {
+			fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
+						       RTA_PAYLOAD(tb[FRA_SRC]),
+						       RTA_DATA(tb[FRA_SRC]),
+						       abuf, sizeof(abuf)),
+				r->rtm_src_len
+				);
+		} else {
+			fprintf(fp, "from %s ", format_host(r->rtm_family,
+						       RTA_PAYLOAD(tb[FRA_SRC]),
+						       RTA_DATA(tb[FRA_SRC]),
+						       abuf, sizeof(abuf))
+				);
+		}
+	} else if (r->rtm_src_len) {
+		fprintf(fp, "from 0/%d ", r->rtm_src_len);
 	} else {
-		print_string(PRINT_ANY, "src", "from %s", "all");
+		fprintf(fp, "from all ");
 	}
 
 	if (tb[FRA_DST]) {
-		const char *dst = rt_addr_n2a_rta(frh->family, tb[FRA_DST]);
-
-		print_string(PRINT_FP, NULL, " to ", NULL);
-		print_color_string(PRINT_ANY, ifa_family_color(frh->family),
-				   "dst", "%s", dst);
-		if (frh->dst_len != host_len)
-			print_uint(PRINT_ANY, "dstlen", "/%u", frh->dst_len);
-	} else if (frh->dst_len) {
-		print_string(PRINT_ANY, "dst", " to %s", "0");
-		print_uint(PRINT_ANY, "dstlen", "/%u", frh->dst_len);
+		if (r->rtm_dst_len != host_len) {
+			fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
+						       RTA_PAYLOAD(tb[FRA_DST]),
+						       RTA_DATA(tb[FRA_DST]),
+						       abuf, sizeof(abuf)),
+				r->rtm_dst_len
+				);
+		} else {
+			fprintf(fp, "to %s ", format_host(r->rtm_family,
+						       RTA_PAYLOAD(tb[FRA_DST]),
+						       RTA_DATA(tb[FRA_DST]),
+						       abuf, sizeof(abuf)));
+		}
+	} else if (r->rtm_dst_len) {
+		fprintf(fp, "to 0/%d ", r->rtm_dst_len);
 	}
 
-	if (frh->tos) {
-		print_string(PRINT_ANY, "tos",
-			     " tos %s",
-			     rtnl_dsfield_n2a(frh->tos, b1, sizeof(b1)));
+	if (r->rtm_tos) {
+		SPRINT_BUF(b1);
+		fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
 	}
 
 	if (tb[FRA_FWMARK] || tb[FRA_FWMASK]) {
@@ -307,113 +131,45 @@
 			mark = rta_getattr_u32(tb[FRA_FWMARK]);
 
 		if (tb[FRA_FWMASK] &&
-		    (mask = rta_getattr_u32(tb[FRA_FWMASK])) != 0xFFFFFFFF) {
-			print_0xhex(PRINT_ANY, "fwmark", " fwmark %#llx", mark);
-			print_0xhex(PRINT_ANY, "fwmask", "/%#llx", mask);
-		} else {
-			print_0xhex(PRINT_ANY, "fwmark", " fwmark %#llx", mark);
-		}
+		    (mask = rta_getattr_u32(tb[FRA_FWMASK])) != 0xFFFFFFFF)
+			fprintf(fp, "fwmark 0x%x/0x%x ", mark, mask);
+		else
+			fprintf(fp, "fwmark 0x%x ", mark);
 	}
 
 	if (tb[FRA_IFNAME]) {
-		if (!is_json_context())
-			fprintf(fp, " iif ");
-		print_color_string(PRINT_ANY, COLOR_IFNAME,
-				   "iif", "%s",
-				   rta_getattr_str(tb[FRA_IFNAME]));
-
-		if (frh->flags & FIB_RULE_IIF_DETACHED)
-			print_null(PRINT_ANY, "iif_detached", " [detached]",
-				   NULL);
+		fprintf(fp, "iif %s ", rta_getattr_str(tb[FRA_IFNAME]));
+		if (r->rtm_flags & FIB_RULE_IIF_DETACHED)
+			fprintf(fp, "[detached] ");
 	}
 
 	if (tb[FRA_OIFNAME]) {
-		if (!is_json_context())
-			fprintf(fp, " oif ");
-
-		print_color_string(PRINT_ANY, COLOR_IFNAME, "oif", "%s",
-				   rta_getattr_str(tb[FRA_OIFNAME]));
-
-		if (frh->flags & FIB_RULE_OIF_DETACHED)
-			print_null(PRINT_ANY, "oif_detached", " [detached]",
-				   NULL);
-	}
-
-	if (tb[FRA_L3MDEV]) {
-		__u8 mdev = rta_getattr_u8(tb[FRA_L3MDEV]);
-
-		if (mdev)
-			print_null(PRINT_ANY, "l3mdev",
-				   " lookup [l3mdev-table]", NULL);
+		fprintf(fp, "oif %s ", rta_getattr_str(tb[FRA_OIFNAME]));
+		if (r->rtm_flags & FIB_RULE_OIF_DETACHED)
+			fprintf(fp, "[detached] ");
 	}
 
 	if (tb[FRA_UID_RANGE]) {
 		struct fib_rule_uid_range *r = RTA_DATA(tb[FRA_UID_RANGE]);
 
-		print_uint(PRINT_ANY, "uid_start", " uidrange %u", r->start);
-		print_uint(PRINT_ANY, "uid_end", "-%u", r->end);
+		fprintf(fp, "uidrange %u-%u ", r->start, r->end);
 	}
 
-	if (tb[FRA_IP_PROTO]) {
-		SPRINT_BUF(pbuf);
-		print_string(PRINT_ANY, "ipproto", " ipproto %s",
-			     inet_proto_n2a(rta_getattr_u8(tb[FRA_IP_PROTO]),
-					    pbuf, sizeof(pbuf)));
-	}
-
-	if (tb[FRA_SPORT_RANGE]) {
-		struct fib_rule_port_range *r = RTA_DATA(tb[FRA_SPORT_RANGE]);
-
-		if (r->start == r->end) {
-			print_uint(PRINT_ANY, "sport", " sport %u", r->start);
-		} else {
-			print_uint(PRINT_ANY, "sport_start", " sport %u",
-				   r->start);
-			print_uint(PRINT_ANY, "sport_end", "-%u", r->end);
-		}
-	}
-
-	if (tb[FRA_DPORT_RANGE]) {
-		struct fib_rule_port_range *r = RTA_DATA(tb[FRA_DPORT_RANGE]);
-
-		if (r->start == r->end) {
-			print_uint(PRINT_ANY, "dport", " dport %u", r->start);
-		} else {
-			print_uint(PRINT_ANY, "dport_start", " dport %u",
-				   r->start);
-			print_uint(PRINT_ANY, "dport_end", "-%u", r->end);
-		}
-	}
-
-	if (tb[FRA_TUN_ID]) {
-		__u64 tun_id = ntohll(rta_getattr_u64(tb[FRA_TUN_ID]));
-
-		print_u64(PRINT_ANY, "tun_id", " tun_id %llu", tun_id);
-	}
-
-	table = frh_get_table(frh, tb);
+	table = rtm_get_table(r, tb);
 	if (table) {
-		print_string(PRINT_ANY, "table",
-			     " lookup %s",
-			     rtnl_rttable_n2a(table, b1, sizeof(b1)));
+		fprintf(fp, "lookup %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
 
 		if (tb[FRA_SUPPRESS_PREFIXLEN]) {
 			int pl = rta_getattr_u32(tb[FRA_SUPPRESS_PREFIXLEN]);
-
-			if (pl != -1)
-				print_int(PRINT_ANY, "suppress_prefixlen",
-					  " suppress_prefixlength %d", pl);
+			if (pl != -1) {
+				fprintf(fp, "suppress_prefixlength %d ", pl);
+			}
 		}
-
 		if (tb[FRA_SUPPRESS_IFGROUP]) {
 			int group = rta_getattr_u32(tb[FRA_SUPPRESS_IFGROUP]);
-
 			if (group != -1) {
-				const char *grname
-					= rtnl_group_n2a(group, b1, sizeof(b1));
-
-				print_string(PRINT_ANY, "suppress_ifgroup",
-					     " suppress_ifgroup %s", grname);
+				SPRINT_BUF(b1);
+				fprintf(fp, "suppress_ifgroup %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
 			}
 		}
 	}
@@ -421,57 +177,38 @@
 	if (tb[FRA_FLOW]) {
 		__u32 to = rta_getattr_u32(tb[FRA_FLOW]);
 		__u32 from = to>>16;
-
 		to &= 0xFFFF;
-		if (from)
-			print_string(PRINT_ANY,
-				     "flow_from", " realms %s/",
-				     rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
-		else
-			print_string(PRINT_FP, NULL, " realms ", NULL);
-
-		print_string(PRINT_ANY, "flow_to", "%s",
-			     rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
+		if (from) {
+			fprintf(fp, "realms %s/",
+				rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
+		}
+		fprintf(fp, "%s ",
+			rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
 	}
 
-	if (frh->action == RTN_NAT) {
+	if (r->rtm_type == RTN_NAT) {
 		if (tb[RTA_GATEWAY]) {
-			const char *gateway;
-
-			gateway = format_host_rta(frh->family, tb[RTA_GATEWAY]);
-
-			print_string(PRINT_ANY, "nat_gateway",
-				     " map-to %s", gateway);
-		} else {
-			print_null(PRINT_ANY, "masquerade", " masquerade", NULL);
-		}
-	} else if (frh->action == FR_ACT_GOTO) {
+			fprintf(fp, "map-to %s ",
+				format_host(r->rtm_family,
+					    RTA_PAYLOAD(tb[RTA_GATEWAY]),
+					    RTA_DATA(tb[RTA_GATEWAY]),
+					    abuf, sizeof(abuf)));
+		} else
+			fprintf(fp, "masquerade");
+	} else if (r->rtm_type == FR_ACT_GOTO) {
+		fprintf(fp, "goto ");
 		if (tb[FRA_GOTO])
-			print_uint(PRINT_ANY, "goto", " goto %u",
-				   rta_getattr_u32(tb[FRA_GOTO]));
+			fprintf(fp, "%u", rta_getattr_u32(tb[FRA_GOTO]));
 		else
-			print_string(PRINT_ANY, "goto", " goto %s", "none");
+			fprintf(fp, "none");
+		if (r->rtm_flags & FIB_RULE_UNRESOLVED)
+			fprintf(fp, " [unresolved]");
+	} else if (r->rtm_type == FR_ACT_NOP)
+		fprintf(fp, "nop");
+	else if (r->rtm_type != RTN_UNICAST)
+		fprintf(fp, "%s", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
 
-		if (frh->flags & FIB_RULE_UNRESOLVED)
-			print_null(PRINT_ANY, "unresolved",
-				   " [unresolved]", NULL);
-	} else if (frh->action == FR_ACT_NOP) {
-		print_null(PRINT_ANY, "nop", " nop", NULL);
-	} else if (frh->action != FR_ACT_TO_TBL) {
-		print_string(PRINT_ANY, "action", " %s",
-			     rtnl_rtntype_n2a(frh->action, b1, sizeof(b1)));
-	}
-
-	if (tb[FRA_PROTOCOL]) {
-		__u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]);
-
-		if ((protocol && protocol != RTPROT_KERNEL) || show_details > 0) {
-			print_string(PRINT_ANY, "protocol", " proto %s",
-				     rtnl_rtprot_n2a(protocol, b1, sizeof(b1)));
-		}
-	}
-	print_string(PRINT_FP, NULL, "\n", "");
-	close_json_object();
+	fprintf(fp, "\n");
 	fflush(fp);
 	return 0;
 }
@@ -496,7 +233,7 @@
 	return 0;
 }
 
-static int save_rule(struct nlmsghdr *n, void *arg)
+static int save_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	int ret;
 
@@ -509,217 +246,35 @@
 	return ret == n->nlmsg_len ? 0 : ret;
 }
 
-static int flush_rule(struct nlmsghdr *n, void *arg)
+static int iprule_list_or_save(int argc, char **argv, int save)
 {
-	struct rtnl_handle rth2;
-	struct fib_rule_hdr *frh = NLMSG_DATA(n);
-	int len = n->nlmsg_len;
-	struct rtattr *tb[FRA_MAX+1];
-	int host_len = -1;
-
-	len -= NLMSG_LENGTH(sizeof(*frh));
-	if (len < 0)
-		return -1;
-
-	parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len);
-
-	host_len = af_bit_len(frh->family);
-	if (!filter_nlmsg(n, tb, host_len))
-		return 0;
-
-	if (tb[FRA_PROTOCOL]) {
-		__u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]);
-
-		if ((filter.protocol ^ protocol) & filter.protocolmask)
-			return 0;
-	}
-
-	if (tb[FRA_PRIORITY]) {
-		n->nlmsg_type = RTM_DELRULE;
-		n->nlmsg_flags = NLM_F_REQUEST;
-
-		if (rtnl_open(&rth2, 0) < 0)
-			return -1;
-
-		if (rtnl_talk(&rth2, n, NULL) < 0)
-			return -2;
-
-		rtnl_close(&rth2);
-	}
-
-	return 0;
-}
-
-static int iprule_list_flush_or_save(int argc, char **argv, int action)
-{
-	rtnl_filter_t filter_fn;
+	rtnl_filter_t filter = print_rule;
 	int af = preferred_family;
 
 	if (af == AF_UNSPEC)
 		af = AF_INET;
 
-	if (action == IPRULE_SAVE && argc > 0) {
-		fprintf(stderr, "\"ip rule save\" does not take any arguments.\n");
+	if (argc > 0) {
+		fprintf(stderr, "\"ip rule %s\" does not take any arguments.\n",
+				save ? "save" : "show");
 		return -1;
 	}
 
-	switch (action) {
-	case IPRULE_SAVE:
+	if (save) {
 		if (save_rule_prep())
 			return -1;
-		filter_fn = save_rule;
-		break;
-	case IPRULE_FLUSH:
-		filter_fn = flush_rule;
-		break;
-	default:
-		filter_fn = print_rule;
+		filter = save_rule;
 	}
 
-	memset(&filter, 0, sizeof(filter));
-
-	while (argc > 0) {
-		if (matches(*argv, "preference") == 0 ||
-		    matches(*argv, "order") == 0 ||
-		    matches(*argv, "priority") == 0) {
-			__u32 pref;
-
-			NEXT_ARG();
-			if (get_u32(&pref, *argv, 0))
-				invarg("preference value is invalid\n", *argv);
-			filter.pref = pref;
-			filter.prefmask = 1;
-		} else if (strcmp(*argv, "not") == 0) {
-			filter.not = 1;
-		} else if (strcmp(*argv, "tos") == 0) {
-			__u32 tos;
-
-			NEXT_ARG();
-			if (rtnl_dsfield_a2n(&tos, *argv))
-				invarg("TOS value is invalid\n", *argv);
-			filter.tos = tos;
-			filter.tosmask = 1;
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			char *slash;
-			__u32 fwmark, fwmask;
-
-			NEXT_ARG();
-			slash = strchr(*argv, '/');
-			if (slash != NULL)
-				*slash = '\0';
-			if (get_u32(&fwmark, *argv, 0))
-				invarg("fwmark value is invalid\n", *argv);
-			filter.fwmark = fwmark;
-			if (slash) {
-				if (get_u32(&fwmask, slash+1, 0))
-					invarg("fwmask value is invalid\n",
-					       slash+1);
-				filter.fwmask = fwmask;
-			}
-		} else if (strcmp(*argv, "dev") == 0 ||
-			   strcmp(*argv, "iif") == 0) {
-			NEXT_ARG();
-			if (get_ifname(filter.iif, *argv))
-				invarg("\"iif\"/\"dev\" not a valid ifname", *argv);
-			filter.iifmask = 1;
-		} else if (strcmp(*argv, "oif") == 0) {
-			NEXT_ARG();
-			if (get_ifname(filter.oif, *argv))
-				invarg("\"oif\" not a valid ifname", *argv);
-			filter.oifmask = 1;
-		} else if (strcmp(*argv, "l3mdev") == 0) {
-			filter.l3mdev = 1;
-		} else if (strcmp(*argv, "uidrange") == 0) {
-			NEXT_ARG();
-			filter.uidrange = 1;
-			if (sscanf(*argv, "%u-%u",
-				   &filter.range.start,
-				   &filter.range.end) != 2)
-				invarg("invalid UID range\n", *argv);
-
-		} else if (matches(*argv, "tun_id") == 0) {
-			__u64 tun_id;
-
-			NEXT_ARG();
-			if (get_u64(&tun_id, *argv, 0))
-				invarg("\"tun_id\" value is invalid\n", *argv);
-			filter.tun_id = tun_id;
-		} else if (matches(*argv, "lookup") == 0 ||
-			   matches(*argv, "table") == 0) {
-			__u32 tid;
-
-			NEXT_ARG();
-			if (rtnl_rttable_a2n(&tid, *argv))
-				invarg("table id value is invalid\n", *argv);
-			filter.tb = tid;
-		} else if (matches(*argv, "from") == 0 ||
-			   matches(*argv, "src") == 0) {
-			NEXT_ARG();
-			if (get_prefix(&filter.src, *argv, af))
-				invarg("from value is invalid\n", *argv);
-		} else if (matches(*argv, "protocol") == 0) {
-			__u32 prot;
-			NEXT_ARG();
-			filter.protocolmask = -1;
-			if (rtnl_rtprot_a2n(&prot, *argv)) {
-				if (strcmp(*argv, "all") != 0)
-					invarg("invalid \"protocol\"\n", *argv);
-				prot = 0;
-				filter.protocolmask = 0;
-			}
-			filter.protocol = prot;
-		} else if (strcmp(*argv, "ipproto") == 0) {
-			int ipproto;
-
-			NEXT_ARG();
-			ipproto = inet_proto_a2n(*argv);
-			if (ipproto < 0)
-				invarg("Invalid \"ipproto\" value\n", *argv);
-			filter.ipproto = ipproto;
-		} else if (strcmp(*argv, "sport") == 0) {
-			struct fib_rule_port_range r;
-			int ret;
-
-			NEXT_ARG();
-			ret = sscanf(*argv, "%hu-%hu", &r.start, &r.end);
-			if (ret == 1)
-				r.end = r.start;
-			else if (ret != 2)
-				invarg("invalid port range\n", *argv);
-			filter.sport = r;
-		} else if (strcmp(*argv, "dport") == 0) {
-			struct fib_rule_port_range r;
-			int ret;
-
-			NEXT_ARG();
-			ret = sscanf(*argv, "%hu-%hu", &r.start, &r.end);
-			if (ret == 1)
-				r.end = r.start;
-			else if (ret != 2)
-				invarg("invalid dport range\n", *argv);
-			filter.dport = r;
-		} else{
-			if (matches(*argv, "dst") == 0 ||
-			    matches(*argv, "to") == 0) {
-				NEXT_ARG();
-			}
-			if (get_prefix(&filter.dst, *argv, af))
-				invarg("to value is invalid\n", *argv);
-		}
-		argc--; argv++;
-	}
-
-	if (rtnl_ruledump_req(&rth, af) < 0) {
+	if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
 
-	new_json_obj(json);
-	if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
+	if (rtnl_dump_filter(&rth, filter, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return 1;
 	}
-	delete_json_obj();
 
 	return 0;
 }
@@ -736,15 +291,15 @@
 
 	ret = fread(&magic, sizeof(magic), 1, stdin);
 	if (magic != rule_dump_magic) {
-		fprintf(stderr, "Magic mismatch (%d elems, %x magic)\n",
-			ret, magic);
+		fprintf(stderr, "Magic mismatch (%d elems, %x magic)\n", ret, magic);
 		return -1;
 	}
 
 	return 0;
 }
 
-static int restore_handler(struct rtnl_ctrl_data *ctrl,
+static int restore_handler(const struct sockaddr_nl *nl,
+			   struct rtnl_ctrl_data *ctrl,
 			   struct nlmsghdr *n, void *arg)
 {
 	int ret;
@@ -753,7 +308,7 @@
 
 	ll_init_map(&rth);
 
-	ret = rtnl_talk(&rth, n, NULL);
+	ret = rtnl_talk(&rth, n, n, sizeof(*n));
 	if ((ret < 0) && (errno == EEXIST))
 		ret = 0;
 
@@ -771,60 +326,49 @@
 
 static int iprule_modify(int cmd, int argc, char **argv)
 {
-	int l3mdev_rule = 0;
 	int table_ok = 0;
-	__u32 tid = 0;
 	struct {
 		struct nlmsghdr	n;
-		struct fib_rule_hdr	frh;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_type = cmd,
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.frh.family = preferred_family,
-		.frh.action = FR_ACT_UNSPEC,
-	};
+		struct rtmsg		r;
+		char  			buf[1024];
+	} req;
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_type = cmd;
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.r.rtm_family = preferred_family;
+	req.r.rtm_protocol = RTPROT_BOOT;
+	req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+	req.r.rtm_table = 0;
+	req.r.rtm_type = RTN_UNSPEC;
+	req.r.rtm_flags = 0;
 
 	if (cmd == RTM_NEWRULE) {
-		if (argc == 0) {
-			fprintf(stderr,
-				"\"ip rule add\" requires arguments.\n");
-			return -1;
-		}
 		req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
-		req.frh.action = FR_ACT_TO_TBL;
-	}
-
-	if (cmd == RTM_DELRULE && argc == 0) {
-		fprintf(stderr, "\"ip rule del\" requires arguments.\n");
-		return -1;
+		req.r.rtm_type = RTN_UNICAST;
 	}
 
 	while (argc > 0) {
 		if (strcmp(*argv, "not") == 0) {
-			req.frh.flags |= FIB_RULE_INVERT;
+			req.r.rtm_flags |= FIB_RULE_INVERT;
 		} else if (strcmp(*argv, "from") == 0) {
 			inet_prefix dst;
-
 			NEXT_ARG();
-			get_prefix(&dst, *argv, req.frh.family);
-			req.frh.src_len = dst.bitlen;
-			addattr_l(&req.n, sizeof(req), FRA_SRC,
-				  &dst.data, dst.bytelen);
+			get_prefix(&dst, *argv, req.r.rtm_family);
+			req.r.rtm_src_len = dst.bitlen;
+			addattr_l(&req.n, sizeof(req), FRA_SRC, &dst.data, dst.bytelen);
 		} else if (strcmp(*argv, "to") == 0) {
 			inet_prefix dst;
-
 			NEXT_ARG();
-			get_prefix(&dst, *argv, req.frh.family);
-			req.frh.dst_len = dst.bitlen;
-			addattr_l(&req.n, sizeof(req), FRA_DST,
-				  &dst.data, dst.bytelen);
+			get_prefix(&dst, *argv, req.r.rtm_family);
+			req.r.rtm_dst_len = dst.bitlen;
+			addattr_l(&req.n, sizeof(req), FRA_DST, &dst.data, dst.bytelen);
 		} else if (matches(*argv, "preference") == 0 ||
 			   matches(*argv, "order") == 0 ||
 			   matches(*argv, "priority") == 0) {
 			__u32 pref;
-
 			NEXT_ARG();
 			if (get_u32(&pref, *argv, 0))
 				invarg("preference value is invalid\n", *argv);
@@ -832,100 +376,64 @@
 		} else if (strcmp(*argv, "tos") == 0 ||
 			   matches(*argv, "dsfield") == 0) {
 			__u32 tos;
-
 			NEXT_ARG();
 			if (rtnl_dsfield_a2n(&tos, *argv))
 				invarg("TOS value is invalid\n", *argv);
-			req.frh.tos = tos;
+			req.r.rtm_tos = tos;
 		} else if (strcmp(*argv, "fwmark") == 0) {
 			char *slash;
 			__u32 fwmark, fwmask;
-
 			NEXT_ARG();
-
-			slash = strchr(*argv, '/');
-			if (slash != NULL)
+			if ((slash = strchr(*argv, '/')) != NULL)
 				*slash = '\0';
 			if (get_u32(&fwmark, *argv, 0))
 				invarg("fwmark value is invalid\n", *argv);
 			addattr32(&req.n, sizeof(req), FRA_FWMARK, fwmark);
 			if (slash) {
 				if (get_u32(&fwmask, slash+1, 0))
-					invarg("fwmask value is invalid\n",
-					       slash+1);
-				addattr32(&req.n, sizeof(req),
-					  FRA_FWMASK, fwmask);
+					invarg("fwmask value is invalid\n", slash+1);
+				addattr32(&req.n, sizeof(req), FRA_FWMASK, fwmask);
 			}
 		} else if (matches(*argv, "realms") == 0) {
 			__u32 realm;
-
 			NEXT_ARG();
 			if (get_rt_realms_or_raw(&realm, *argv))
 				invarg("invalid realms\n", *argv);
 			addattr32(&req.n, sizeof(req), FRA_FLOW, realm);
-		} else if (matches(*argv, "protocol") == 0) {
-			__u32 proto;
-
-			NEXT_ARG();
-			if (rtnl_rtprot_a2n(&proto, *argv))
-				invarg("\"protocol\" value is invalid\n", *argv);
-			addattr8(&req.n, sizeof(req), FRA_PROTOCOL, proto);
-		} else if (matches(*argv, "tun_id") == 0) {
-			__u64 tun_id;
-
-			NEXT_ARG();
-			if (get_be64(&tun_id, *argv, 0))
-				invarg("\"tun_id\" value is invalid\n", *argv);
-			addattr64(&req.n, sizeof(req), FRA_TUN_ID, tun_id);
 		} else if (matches(*argv, "table") == 0 ||
 			   strcmp(*argv, "lookup") == 0) {
+			__u32 tid;
 			NEXT_ARG();
 			if (rtnl_rttable_a2n(&tid, *argv))
 				invarg("invalid table ID\n", *argv);
 			if (tid < 256)
-				req.frh.table = tid;
+				req.r.rtm_table = tid;
 			else {
-				req.frh.table = RT_TABLE_UNSPEC;
+				req.r.rtm_table = RT_TABLE_UNSPEC;
 				addattr32(&req.n, sizeof(req), FRA_TABLE, tid);
 			}
 			table_ok = 1;
 		} else if (matches(*argv, "suppress_prefixlength") == 0 ||
 			   strcmp(*argv, "sup_pl") == 0) {
 			int pl;
-
 			NEXT_ARG();
 			if (get_s32(&pl, *argv, 0) || pl < 0)
-				invarg("suppress_prefixlength value is invalid\n",
-				       *argv);
-			addattr32(&req.n, sizeof(req),
-				  FRA_SUPPRESS_PREFIXLEN, pl);
+				invarg("suppress_prefixlength value is invalid\n", *argv);
+			addattr32(&req.n, sizeof(req), FRA_SUPPRESS_PREFIXLEN, pl);
 		} else if (matches(*argv, "suppress_ifgroup") == 0 ||
 			   strcmp(*argv, "sup_group") == 0) {
 			NEXT_ARG();
 			int group;
-
 			if (rtnl_group_a2n(&group, *argv))
-				invarg("Invalid \"suppress_ifgroup\" value\n",
-				       *argv);
-			addattr32(&req.n, sizeof(req),
-				  FRA_SUPPRESS_IFGROUP, group);
+				invarg("Invalid \"suppress_ifgroup\" value\n", *argv);
+			addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, group);
 		} else if (strcmp(*argv, "dev") == 0 ||
 			   strcmp(*argv, "iif") == 0) {
 			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"iif\"/\"dev\" not a valid ifname", *argv);
-			addattr_l(&req.n, sizeof(req), FRA_IFNAME,
-				  *argv, strlen(*argv)+1);
+			addattr_l(&req.n, sizeof(req), FRA_IFNAME, *argv, strlen(*argv)+1);
 		} else if (strcmp(*argv, "oif") == 0) {
 			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"oif\" not a valid ifname", *argv);
-			addattr_l(&req.n, sizeof(req), FRA_OIFNAME,
-				  *argv, strlen(*argv)+1);
-		} else if (strcmp(*argv, "l3mdev") == 0) {
-			addattr8(&req.n, sizeof(req), FRA_L3MDEV, 1);
-			table_ok = 1;
-			l3mdev_rule = 1;
+			addattr_l(&req.n, sizeof(req), FRA_OIFNAME, *argv, strlen(*argv)+1);
 		} else if (strcmp(*argv, "uidrange") == 0) {
 			struct fib_rule_uid_range r;
 
@@ -938,98 +446,111 @@
 			   matches(*argv, "map-to") == 0) {
 			NEXT_ARG();
 			fprintf(stderr, "Warning: route NAT is deprecated\n");
-			addattr32(&req.n, sizeof(req), RTA_GATEWAY,
-				  get_addr32(*argv));
-			req.frh.action = RTN_NAT;
-		} else if (strcmp(*argv, "ipproto") == 0) {
-			int ipproto;
-
-			NEXT_ARG();
-			ipproto = inet_proto_a2n(*argv);
-			if (ipproto < 0)
-				invarg("Invalid \"ipproto\" value\n",
-				       *argv);
-			addattr8(&req.n, sizeof(req), FRA_IP_PROTO, ipproto);
-		} else if (strcmp(*argv, "sport") == 0) {
-			struct fib_rule_port_range r;
-			int ret = 0;
-
-			NEXT_ARG();
-			ret = sscanf(*argv, "%hu-%hu", &r.start, &r.end);
-			if (ret == 1)
-				r.end = r.start;
-			else if (ret != 2)
-				invarg("invalid port range\n", *argv);
-			addattr_l(&req.n, sizeof(req), FRA_SPORT_RANGE, &r,
-				  sizeof(r));
-		} else if (strcmp(*argv, "dport") == 0) {
-			struct fib_rule_port_range r;
-			int ret = 0;
-
-			NEXT_ARG();
-			ret = sscanf(*argv, "%hu-%hu", &r.start, &r.end);
-			if (ret == 1)
-				r.end = r.start;
-			else if (ret != 2)
-				invarg("invalid dport range\n", *argv);
-			addattr_l(&req.n, sizeof(req), FRA_DPORT_RANGE, &r,
-				  sizeof(r));
+			addattr32(&req.n, sizeof(req), RTA_GATEWAY, get_addr32(*argv));
+			req.r.rtm_type = RTN_NAT;
 		} else {
 			int type;
 
-			if (strcmp(*argv, "type") == 0)
+			if (strcmp(*argv, "type") == 0) {
 				NEXT_ARG();
-
+			}
 			if (matches(*argv, "help") == 0)
 				usage();
 			else if (matches(*argv, "goto") == 0) {
 				__u32 target;
-
 				type = FR_ACT_GOTO;
 				NEXT_ARG();
 				if (get_u32(&target, *argv, 0))
 					invarg("invalid target\n", *argv);
-				addattr32(&req.n, sizeof(req),
-					  FRA_GOTO, target);
+				addattr32(&req.n, sizeof(req), FRA_GOTO, target);
 			} else if (matches(*argv, "nop") == 0)
 				type = FR_ACT_NOP;
 			else if (rtnl_rtntype_a2n(&type, *argv))
 				invarg("Failed to parse rule type", *argv);
-			req.frh.action = type;
+			req.r.rtm_type = type;
 			table_ok = 1;
 		}
 		argc--;
 		argv++;
 	}
 
-	if (l3mdev_rule && tid != 0) {
-		fprintf(stderr,
-			"table can not be specified for l3mdev rules\n");
-		return -EINVAL;
-	}
-
-	if (req.frh.family == AF_UNSPEC)
-		req.frh.family = AF_INET;
+	if (req.r.rtm_family == AF_UNSPEC)
+		req.r.rtm_family = AF_INET;
 
 	if (!table_ok && cmd == RTM_NEWRULE)
-		req.frh.table = RT_TABLE_MAIN;
+		req.r.rtm_table = RT_TABLE_MAIN;
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
 }
 
+
+static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
+{
+	struct rtnl_handle rth2;
+	struct rtmsg *r = NLMSG_DATA(n);
+	int len = n->nlmsg_len;
+	struct rtattr * tb[FRA_MAX+1];
+
+	len -= NLMSG_LENGTH(sizeof(*r));
+	if (len < 0)
+		return -1;
+
+	parse_rtattr(tb, FRA_MAX, RTM_RTA(r), len);
+
+	if (tb[FRA_PRIORITY]) {
+		n->nlmsg_type = RTM_DELRULE;
+		n->nlmsg_flags = NLM_F_REQUEST;
+
+		if (rtnl_open(&rth2, 0) < 0)
+			return -1;
+
+		if (rtnl_talk(&rth2, n, NULL, 0) < 0)
+			return -2;
+
+		rtnl_close(&rth2);
+	}
+
+	return 0;
+}
+
+static int iprule_flush(int argc, char **argv)
+{
+	int af = preferred_family;
+
+	if (af == AF_UNSPEC)
+		af = AF_INET;
+
+	if (argc > 0) {
+		fprintf(stderr, "\"ip rule flush\" does not allow arguments\n");
+		return -1;
+	}
+
+	if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
+		perror("Cannot send dump request");
+		return 1;
+	}
+
+	if (rtnl_dump_filter(&rth, flush_rule, NULL) < 0) {
+		fprintf(stderr, "Flush terminated\n");
+		return 1;
+	}
+
+	return 0;
+}
+
 int do_iprule(int argc, char **argv)
 {
 	if (argc < 1) {
-		return iprule_list_flush_or_save(0, NULL, IPRULE_LIST);
+		return iprule_list_or_save(0, NULL, 0);
 	} else if (matches(argv[0], "list") == 0 ||
 		   matches(argv[0], "lst") == 0 ||
 		   matches(argv[0], "show") == 0) {
-		return iprule_list_flush_or_save(argc-1, argv+1, IPRULE_LIST);
+		return iprule_list_or_save(argc-1, argv+1, 0);
 	} else if (matches(argv[0], "save") == 0) {
-		return iprule_list_flush_or_save(argc-1, argv+1, IPRULE_SAVE);
+		return iprule_list_or_save(argc-1, argv+1, 1);
 	} else if (matches(argv[0], "restore") == 0) {
 		return iprule_restore();
 	} else if (matches(argv[0], "add") == 0) {
@@ -1037,12 +558,11 @@
 	} else if (matches(argv[0], "delete") == 0) {
 		return iprule_modify(RTM_DELRULE, argc-1, argv+1);
 	} else if (matches(argv[0], "flush") == 0) {
-		return iprule_list_flush_or_save(argc-1, argv+1, IPRULE_FLUSH);
+		return iprule_flush(argc-1, argv+1);
 	} else if (matches(argv[0], "help") == 0)
 		usage();
 
-	fprintf(stderr,
-		"Command \"%s\" is unknown, try \"ip rule help\".\n", *argv);
+	fprintf(stderr, "Command \"%s\" is unknown, try \"ip rule help\".\n", *argv);
 	exit(-1);
 }
 
@@ -1060,8 +580,7 @@
 	case RTNL_FAMILY_IP6MR:
 		break;
 	default:
-		fprintf(stderr,
-			"Multicast rules are only supported for IPv4/IPv6, was: %i\n",
+		fprintf(stderr, "Multicast rules are only supported for IPv4/IPv6, was: %i\n",
 			preferred_family);
 		exit(-1);
 	}
diff --git a/ip/ipseg6.c b/ip/ipseg6.c
deleted file mode 100644
index 56a7699..0000000
--- a/ip/ipseg6.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * seg6.c "ip sr/seg6"
- *
- *	  This program is free software; you can redistribute it and/or
- *	  modify it under the terms of the GNU General Public License
- *	  version 2 as published by the Free Software Foundation;
- *
- * Author: David Lebrun <david.lebrun@uclouvain.be>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <sys/ioctl.h>
-#include <linux/if.h>
-
-#include <linux/genetlink.h>
-#include <linux/seg6_genl.h>
-#include <linux/seg6_hmac.h>
-
-#include "utils.h"
-#include "ip_common.h"
-#include "libgenl.h"
-#include "json_print.h"
-
-#define HMAC_KEY_PROMPT "Enter secret for HMAC key ID (blank to delete): "
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage: ip sr { COMMAND | help }\n"
-		"	   ip sr hmac show\n"
-		"	   ip sr hmac set KEYID ALGO\n"
-		"	   ip sr tunsrc show\n"
-		"	   ip sr tunsrc set ADDRESS\n"
-		"where  ALGO := { sha1 | sha256 }\n");
-	exit(-1);
-}
-
-static struct rtnl_handle grth = { .fd = -1 };
-static int genl_family = -1;
-
-#define SEG6_REQUEST(_req, _bufsiz, _cmd, _flags) \
-	GENL_REQUEST(_req, _bufsiz, genl_family, 0, \
-				SEG6_GENL_VERSION, _cmd, _flags)
-
-static struct {
-	unsigned int cmd;
-	inet_prefix addr;
-	__u32 keyid;
-	const char *pass;
-	__u8 alg_id;
-} opts;
-
-static void print_dumphmac(struct rtattr *attrs[])
-{
-	char secret[64];
-	char *algstr;
-	__u8 slen = rta_getattr_u8(attrs[SEG6_ATTR_SECRETLEN]);
-	__u8 alg_id = rta_getattr_u8(attrs[SEG6_ATTR_ALGID]);
-
-	memset(secret, 0, 64);
-
-	if (slen > 63) {
-		fprintf(stderr, "HMAC secret length %d > 63, truncated\n", slen);
-		slen = 63;
-	}
-
-	memcpy(secret, RTA_DATA(attrs[SEG6_ATTR_SECRET]), slen);
-
-	switch (alg_id) {
-	case SEG6_HMAC_ALGO_SHA1:
-		algstr = "sha1";
-		break;
-	case SEG6_HMAC_ALGO_SHA256:
-		algstr = "sha256";
-		break;
-	default:
-		algstr = "<unknown>";
-	}
-
-	print_uint(PRINT_ANY, "hmac", "hmac %u ",
-		   rta_getattr_u32(attrs[SEG6_ATTR_HMACKEYID]));
-	print_string(PRINT_ANY, "algo", "algo %s ", algstr);
-	print_string(PRINT_ANY, "secret", "secret \"%s\"\n", secret);
-}
-
-static void print_tunsrc(struct rtattr *attrs[])
-{
-	const char *dst
-		= rt_addr_n2a(AF_INET6, 16,
-			      RTA_DATA(attrs[SEG6_ATTR_DST]));
-
-	print_string(PRINT_ANY, "tunsrc",
-		     "tunsrc addr %s\n", dst);
-}
-
-static int process_msg(struct nlmsghdr *n, void *arg)
-{
-	struct rtattr *attrs[SEG6_ATTR_MAX + 1];
-	struct genlmsghdr *ghdr;
-	int len = n->nlmsg_len;
-
-	if (n->nlmsg_type != genl_family)
-		return -1;
-
-	len -= NLMSG_LENGTH(GENL_HDRLEN);
-	if (len < 0)
-		return -1;
-
-	ghdr = NLMSG_DATA(n);
-
-	parse_rtattr(attrs, SEG6_ATTR_MAX, (void *)ghdr + GENL_HDRLEN, len);
-
-	open_json_object(NULL);
-	switch (ghdr->cmd) {
-	case SEG6_CMD_DUMPHMAC:
-		print_dumphmac(attrs);
-		break;
-
-	case SEG6_CMD_GET_TUNSRC:
-		print_tunsrc(attrs);
-		break;
-	}
-	close_json_object();
-
-	return 0;
-}
-
-static int seg6_do_cmd(void)
-{
-	SEG6_REQUEST(req, 1024, opts.cmd, NLM_F_REQUEST);
-	struct nlmsghdr *answer;
-	int repl = 0, dump = 0;
-
-	if (genl_family < 0) {
-		if (rtnl_open_byproto(&grth, 0, NETLINK_GENERIC) < 0) {
-			fprintf(stderr, "Cannot open generic netlink socket\n");
-			exit(1);
-		}
-		genl_family = genl_resolve_family(&grth, SEG6_GENL_NAME);
-		if (genl_family < 0)
-			exit(1);
-		req.n.nlmsg_type = genl_family;
-	}
-
-	switch (opts.cmd) {
-	case SEG6_CMD_SETHMAC:
-	{
-		addattr32(&req.n, sizeof(req), SEG6_ATTR_HMACKEYID, opts.keyid);
-		addattr8(&req.n, sizeof(req), SEG6_ATTR_SECRETLEN,
-			 strlen(opts.pass));
-		addattr8(&req.n, sizeof(req), SEG6_ATTR_ALGID, opts.alg_id);
-		if (strlen(opts.pass))
-			addattr_l(&req.n, sizeof(req), SEG6_ATTR_SECRET,
-				  opts.pass, strlen(opts.pass));
-		break;
-	}
-	case SEG6_CMD_SET_TUNSRC:
-		addattr_l(&req.n, sizeof(req), SEG6_ATTR_DST, opts.addr.data,
-			  sizeof(struct in6_addr));
-		break;
-	case SEG6_CMD_DUMPHMAC:
-		dump = 1;
-		break;
-	case SEG6_CMD_GET_TUNSRC:
-		repl = 1;
-		break;
-	}
-
-	if (!repl && !dump) {
-		if (rtnl_talk(&grth, &req.n, NULL) < 0)
-			return -1;
-	} else if (repl) {
-		if (rtnl_talk(&grth, &req.n, &answer) < 0)
-			return -2;
-		new_json_obj(json);
-		if (process_msg(answer, stdout) < 0) {
-			fprintf(stderr, "Error parsing reply\n");
-			exit(1);
-		}
-		delete_json_obj();
-		free(answer);
-	} else {
-		req.n.nlmsg_flags |= NLM_F_DUMP;
-		req.n.nlmsg_seq = grth.dump = ++grth.seq;
-		if (rtnl_send(&grth, &req, req.n.nlmsg_len) < 0) {
-			perror("Failed to send dump request");
-			exit(1);
-		}
-
-		new_json_obj(json);
-		if (rtnl_dump_filter(&grth, process_msg, stdout) < 0) {
-			fprintf(stderr, "Dump terminated\n");
-			exit(1);
-		}
-		delete_json_obj();
-		fflush(stdout);
-	}
-
-	return 0;
-}
-
-int do_seg6(int argc, char **argv)
-{
-	if (argc < 1 || matches(*argv, "help") == 0)
-		usage();
-
-	memset(&opts, 0, sizeof(opts));
-
-	if (matches(*argv, "hmac") == 0) {
-		NEXT_ARG();
-		if (matches(*argv, "show") == 0) {
-			opts.cmd = SEG6_CMD_DUMPHMAC;
-		} else if (matches(*argv, "set") == 0) {
-			NEXT_ARG();
-			if (get_u32(&opts.keyid, *argv, 0) || opts.keyid == 0)
-				invarg("hmac KEYID value is invalid", *argv);
-			NEXT_ARG();
-			if (strcmp(*argv, "sha1") == 0) {
-				opts.alg_id = SEG6_HMAC_ALGO_SHA1;
-			} else if (strcmp(*argv, "sha256") == 0) {
-				opts.alg_id = SEG6_HMAC_ALGO_SHA256;
-			} else {
-				invarg("hmac ALGO value is invalid", *argv);
-			}
-			opts.cmd = SEG6_CMD_SETHMAC;
-			opts.pass = getpass(HMAC_KEY_PROMPT);
-		} else {
-			invarg("unknown", *argv);
-		}
-	} else if (matches(*argv, "tunsrc") == 0) {
-		NEXT_ARG();
-		if (matches(*argv, "show") == 0) {
-			opts.cmd = SEG6_CMD_GET_TUNSRC;
-		} else if (matches(*argv, "set") == 0) {
-			NEXT_ARG();
-			opts.cmd = SEG6_CMD_SET_TUNSRC;
-			get_addr(&opts.addr, *argv, AF_INET6);
-		} else {
-			invarg("unknown", *argv);
-		}
-	} else {
-		invarg("unknown", *argv);
-	}
-
-	return seg6_do_cmd();
-}
diff --git a/ip/iptoken.c b/ip/iptoken.c
index 9f35689..428f133 100644
--- a/ip/iptoken.c
+++ b/ip/iptoken.c
@@ -13,6 +13,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -25,7 +26,6 @@
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
-#include "json_print.h"
 
 extern struct rtnl_handle rth;
 
@@ -38,11 +38,11 @@
 
 static void usage(void)
 {
-	fprintf(stderr, "Usage: ip token [ list | set | del | get ] [ TOKEN ] [ dev DEV ]\n");
+	fprintf(stderr, "Usage: ip token [ list | set | get ] [ TOKEN ] [ dev DEV ]\n");
 	exit(-1);
 }
 
-static int print_token(struct nlmsghdr *n, void *arg)
+static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	struct rtnl_dump_args *args = arg;
 	FILE *fp = args->fp;
@@ -51,6 +51,7 @@
 	int len = n->nlmsg_len;
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *ltb[IFLA_INET6_MAX + 1];
+	char abuf[256];
 
 	if (n->nlmsg_type != RTM_NEWLINK)
 		return -1;
@@ -60,9 +61,9 @@
 		return -1;
 
 	if (ifi->ifi_family != AF_INET6)
-		return 0;
+		return -1;
 	if (ifi->ifi_index == 0)
-		return 0;
+		return -1;
 	if (ifindex > 0 && ifi->ifi_index != ifindex)
 		return 0;
 	if (ifi->ifi_flags & (IFF_LOOPBACK | IFF_NOARP))
@@ -78,17 +79,13 @@
 		return -1;
 	}
 
-	open_json_object(NULL);
-	print_string(PRINT_FP, NULL, "token ", NULL);
-	print_color_string(PRINT_ANY,
-			   ifa_family_color(ifi->ifi_family),
-			   "token", "%s",
-			   format_host_rta(ifi->ifi_family, ltb[IFLA_INET6_TOKEN]));
-	print_string(PRINT_FP, NULL, " dev ", NULL);
-	print_color_string(PRINT_ANY, COLOR_IFNAME,
-			   "ifname", "%s\n",
-			   ll_index_to_name(ifi->ifi_index));
-	close_json_object();
+	fprintf(fp, "token %s ",
+		format_host(ifi->ifi_family,
+			    RTA_PAYLOAD(ltb[IFLA_INET6_TOKEN]),
+			    RTA_DATA(ltb[IFLA_INET6_TOKEN]),
+			    abuf, sizeof(abuf)));
+	fprintf(fp, "dev %s ", ll_index_to_name(ifi->ifi_index));
+	fprintf(fp, "\n");
 	fflush(fp);
 
 	return 0;
@@ -97,7 +94,10 @@
 static int iptoken_list(int argc, char **argv)
 {
 	int af = AF_INET6;
-	struct rtnl_dump_args da = { .fp = stdout };
+	struct rtnl_dump_args da;
+
+	memset(&da, 0, sizeof(da));
+	da.fp = stdout;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -109,37 +109,37 @@
 		argc--; argv++;
 	}
 
-	if (rtnl_linkdump_req(&rth, af) < 0) {
+	if (rtnl_wilddump_request(&rth, af, RTM_GETLINK) < 0) {
 		perror("Cannot send dump request");
 		return -1;
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_token, &da) < 0) {
-		delete_json_obj();
 		fprintf(stderr, "Dump terminated\n");
 		return -1;
 	}
-	delete_json_obj();
 
 	return 0;
 }
 
-static int iptoken_set(int argc, char **argv, bool delete)
+static int iptoken_set(int argc, char **argv)
 {
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg ifi;
 		char buf[512];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_SETLINK,
-		.ifi.ifi_family = AF_INET6,
-	};
+	} req;
 	struct rtattr *afs, *afs6;
-	bool have_token = delete, have_dev = false;
-	inet_prefix addr = { .bytelen = 16, };
+	bool have_token = false, have_dev = false;
+	inet_prefix addr;
+
+	memset(&addr, 0, sizeof(addr));
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = RTM_SETLINK;
+	req.ifi.ifi_family = AF_INET6;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -154,7 +154,13 @@
 			if (matches(*argv, "help") == 0)
 				usage();
 			if (!have_token) {
+				afs = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC);
+				afs6 = addattr_nest(&req.n, sizeof(req), AF_INET6);
 				get_prefix(&addr, *argv, req.ifi.ifi_family);
+				addattr_l(&req.n, sizeof(req), IFLA_INET6_TOKEN,
+					  &addr.data, addr.bytelen);
+				addattr_nest_end(&req.n, afs6);
+				addattr_nest_end(&req.n, afs);
 				have_token = true;
 			}
 		}
@@ -162,22 +168,17 @@
 	}
 
 	if (!have_token) {
-		fprintf(stderr, "Not enough information: token is required.\n");
+		fprintf(stderr, "Not enough information: token "
+			"is required.\n");
 		return -1;
 	}
 	if (!have_dev) {
-		fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
+		fprintf(stderr, "Not enough information: \"dev\" "
+			"argument is required.\n");
 		return -1;
 	}
 
-	afs = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC);
-	afs6 = addattr_nest(&req.n, sizeof(req), AF_INET6);
-	addattr_l(&req.n, sizeof(req), IFLA_INET6_TOKEN,
-		  &addr.data, addr.bytelen);
-	addattr_nest_end(&req.n, afs6);
-	addattr_nest_end(&req.n, afs);
-
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return -2;
 
 	return 0;
@@ -195,9 +196,7 @@
 		return iptoken_list(argc - 1, argv + 1);
 	} else if (matches(argv[0], "set") == 0 ||
 		   matches(argv[0], "add") == 0) {
-		return iptoken_set(argc - 1, argv + 1, false);
-	} else if (matches(argv[0], "delete") == 0) {
-		return iptoken_set(argc - 1, argv + 1, true);
+		return iptoken_set(argc - 1, argv + 1);
 	} else if (matches(argv[0], "get") == 0) {
 		return iptoken_list(argc - 1, argv + 1);
 	} else if (matches(argv[0], "help") == 0)
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index 696f3b9..65a4e6e 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -32,19 +32,18 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip tunnel { add | change | del | show | prl | 6rd } [ NAME ]\n"
-		"	 [ mode { ipip | gre | sit | isatap | vti } ] [ remote ADDR ] [ local ADDR ]\n"
-		"	 [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n"
-		"	 [ prl-default ADDR ] [ prl-nodefault ADDR ] [ prl-delete ADDR ]\n"
-		"	 [ 6rd-prefix ADDR ] [ 6rd-relay_prefix ADDR ] [ 6rd-reset ]\n"
-		"	 [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n"
-		"\n"
-		"Where:	NAME := STRING\n"
-		"	ADDR := { IP_ADDRESS | any }\n"
-		"	TOS  := { STRING | 00..ff | inherit | inherit/STRING | inherit/00..ff }\n"
-		"	TTL  := { 1..255 | inherit }\n"
-		"	KEY  := { DOTTED_QUAD | NUMBER }\n");
+	fprintf(stderr, "Usage: ip tunnel { add | change | del | show | prl | 6rd } [ NAME ]\n");
+	fprintf(stderr, "          [ mode { ipip | gre | sit | isatap | vti } ] [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(stderr, "          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
+	fprintf(stderr, "          [ prl-default ADDR ] [ prl-nodefault ADDR ] [ prl-delete ADDR ]\n");
+	fprintf(stderr, "          [ 6rd-prefix ADDR ] [ 6rd-relay_prefix ADDR ] [ 6rd-reset ]\n");
+	fprintf(stderr, "          [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: NAME := STRING\n");
+	fprintf(stderr, "       ADDR := { IP_ADDRESS | any }\n");
+	fprintf(stderr, "       TOS  := { STRING | 00..ff | inherit | inherit/STRING | inherit/00..ff }\n");
+	fprintf(stderr, "       TTL  := { 1..255 | inherit }\n");
+	fprintf(stderr, "       KEY  := { DOTTED_QUAD | NUMBER }\n");
 	exit(-1);
 }
 
@@ -61,10 +60,12 @@
 static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
 {
 	int count = 0;
-	const char *medium = NULL;
+	char medium[IFNAMSIZ];
 	int isatap = 0;
 
 	memset(p, 0, sizeof(*p));
+	memset(&medium, 0, sizeof(medium));
+
 	p->iph.version = 4;
 	p->iph.ihl = 5;
 #ifndef IP_DF
@@ -128,13 +129,19 @@
 			p->iph.frag_off = htons(IP_DF);
 		} else if (strcmp(*argv, "remote") == 0) {
 			NEXT_ARG();
-			p->iph.daddr = get_addr32(*argv);
+			if (strcmp(*argv, "any"))
+				p->iph.daddr = get_addr32(*argv);
+			else
+				p->iph.daddr = htonl(INADDR_ANY);
 		} else if (strcmp(*argv, "local") == 0) {
 			NEXT_ARG();
-			p->iph.saddr = get_addr32(*argv);
+			if (strcmp(*argv, "any"))
+				p->iph.saddr = get_addr32(*argv);
+			else
+				p->iph.saddr = htonl(INADDR_ANY);
 		} else if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
-			medium = *argv;
+			strncpy(medium, *argv, IFNAMSIZ - 1);
 		} else if (strcmp(*argv, "ttl") == 0 ||
 			   strcmp(*argv, "hoplimit") == 0 ||
 			   strcmp(*argv, "hlim") == 0) {
@@ -173,11 +180,11 @@
 
 			if (p->name[0])
 				duparg2("name", *argv);
-			if (get_ifname(p->name, *argv))
-				invarg("\"name\" not a valid ifname", *argv);
+			strncpy(p->name, *argv, IFNAMSIZ - 1);
 			if (cmd == SIOCCHGTUNNEL && count == 0) {
-				struct ip_tunnel_parm old_p = {};
+				struct ip_tunnel_parm old_p;
 
+				memset(&old_p, 0, sizeof(old_p));
 				if (tnl_get_ioctl(*argv, &old_p))
 					return -1;
 				*p = old_p;
@@ -212,10 +219,12 @@
 		}
 	}
 
-	if (medium) {
+	if (medium[0]) {
 		p->link = ll_name_to_index(medium);
-		if (!p->link)
-			return nodev(medium);
+		if (p->link == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", medium);
+			return -1;
+		}
 	}
 
 	if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
@@ -285,158 +294,190 @@
 	return tnl_del_ioctl(tnl_defname(&p) ? : p.name, p.name, &p);
 }
 
-static void print_tunnel(const void *t)
+static void print_tunnel(struct ip_tunnel_parm *p)
 {
-	const struct ip_tunnel_parm *p = t;
-	struct ip_tunnel_6rd ip6rd = {};
-	SPRINT_BUF(b1);
+	struct ip_tunnel_6rd ip6rd;
+	char s1[1024];
+	char s2[1024];
+
+	memset(&ip6rd, 0, sizeof(ip6rd));
 
 	/* Do not use format_host() for local addr,
 	 * symbolic name will not be useful.
 	 */
-	open_json_object(NULL);
-	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", "%s: ", p->name);
-	snprintf(b1, sizeof(b1), "%s/ip", tnl_strproto(p->iph.protocol));
-	print_string(PRINT_ANY, "mode", "%s ", b1);
-	print_null(PRINT_FP, NULL, "remote ", NULL);
-	print_color_string(PRINT_ANY, COLOR_INET, "remote", "%s ",
-			   p->iph.daddr || is_json_context()
-				? format_host_r(AF_INET, 4, &p->iph.daddr, b1, sizeof(b1))
-				: "any");
-	print_null(PRINT_FP, NULL, "local ", NULL);
-	print_color_string(PRINT_ANY, COLOR_INET, "local", "%s",
-			   p->iph.saddr || is_json_context()
-				? rt_addr_n2a_r(AF_INET, 4, &p->iph.saddr, b1, sizeof(b1))
-				: "any");
+	printf("%s: %s/ip remote %s local %s",
+	       p->name,
+	       tnl_strproto(p->iph.protocol),
+	       p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
+	       p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
 
 	if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
-		struct ip_tunnel_prl prl[16] = {};
+		struct ip_tunnel_prl prl[16];
 		int i;
 
+		memset(prl, 0, sizeof(prl));
 		prl[0].datalen = sizeof(prl) - sizeof(prl[0]);
 		prl[0].addr = htonl(INADDR_ANY);
 
-		if (!tnl_prl_ioctl(SIOCGETPRL, p->name, prl)) {
+		if (!tnl_prl_ioctl(SIOCGETPRL, p->name, prl))
 			for (i = 1; i < ARRAY_SIZE(prl); i++) {
-				if (prl[i].addr == htonl(INADDR_ANY))
-					continue;
-				if (prl[i].flags & PRL_DEFAULT)
-					print_string(PRINT_ANY, "pdr",
-						     " pdr %s",
-						     format_host(AF_INET, 4, &prl[i].addr));
-				else
-					print_string(PRINT_ANY, "pr", " pr %s",
-						     format_host(AF_INET, 4, &prl[i].addr));
+				if (prl[i].addr != htonl(INADDR_ANY)) {
+					printf(" %s %s ",
+					       (prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr",
+					       format_host(AF_INET, 4, &prl[i].addr, s1, sizeof(s1)));
+				}
 			}
-		}
 	}
 
 	if (p->link) {
 		const char *n = ll_index_to_name(p->link);
 
 		if (n)
-			print_string(PRINT_ANY, "dev", " dev %s", n);
+			printf(" dev %s", n);
 	}
 
 	if (p->iph.ttl)
-		print_uint(PRINT_ANY, "ttl", " ttl %u", p->iph.ttl);
+		printf(" ttl %d", p->iph.ttl);
 	else
-		print_string(PRINT_FP, "ttl", " ttl %s", "inherit");
+		printf(" ttl inherit");
 
 	if (p->iph.tos) {
-		SPRINT_BUF(b2);
-
-		if (p->iph.tos != 1) {
-			if (!is_json_context() && p->iph.tos & 1)
-				snprintf(b2, sizeof(b2), "%s%s",
-					 p->iph.tos & 1 ? "inherit/" : "",
-					 rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1)));
-			else
-				snprintf(b2, sizeof(b2), "%s",
-					 rtnl_dsfield_n2a(p->iph.tos, b1, sizeof(b1)));
-			print_string(PRINT_ANY, "tos", " tos %s", b2);
-		} else {
-			print_string(PRINT_FP, NULL, " tos %s", "inherit");
-		}
+		SPRINT_BUF(b1);
+		printf(" tos");
+		if (p->iph.tos & 1)
+			printf(" inherit");
+		if (p->iph.tos & ~1)
+			printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
+			       rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1)));
 	}
 
 	if (!(p->iph.frag_off & htons(IP_DF)))
-		print_null(PRINT_ANY, "nopmtudisc", " nopmtudisc", NULL);
+		printf(" nopmtudisc");
 
 	if (p->iph.protocol == IPPROTO_IPV6 && !tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
-		print_string(PRINT_ANY, "6rd-prefix", " 6rd-prefix %s",
-			     inet_ntop(AF_INET6, &ip6rd.prefix, b1, sizeof(b1)));
-		print_uint(PRINT_ANY, "6rd-prefixlen", "/%u", ip6rd.prefixlen);
+		printf(" 6rd-prefix %s/%u",
+		       inet_ntop(AF_INET6, &ip6rd.prefix, s1, sizeof(s1)),
+		       ip6rd.prefixlen);
 		if (ip6rd.relay_prefix) {
-			print_string(PRINT_ANY, "6rd-relay_prefix",
-				     " 6rd-relay_prefix %s",
-				     format_host(AF_INET, 4, &ip6rd.relay_prefix));
-			print_uint(PRINT_ANY, "6rd-relay_prefixlen", "/%u",
-				   ip6rd.relay_prefixlen);
+			printf(" 6rd-relay_prefix %s/%u",
+			       format_host(AF_INET, 4, &ip6rd.relay_prefix, s1, sizeof(s1)),
+			       ip6rd.relay_prefixlen);
 		}
 	}
 
-	tnl_print_gre_flags(p->iph.protocol, p->i_flags, p->o_flags,
-			    p->i_key, p->o_key);
+	if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
+		printf(" key %u", ntohl(p->i_key));
+	else if ((p->i_flags | p->o_flags) & GRE_KEY) {
+		if (p->i_flags & GRE_KEY)
+			printf(" ikey %u", ntohl(p->i_key));
+		if (p->o_flags & GRE_KEY)
+			printf(" okey %u", ntohl(p->o_key));
+	}
 
-	close_json_object();
+	if (p->i_flags & GRE_SEQ)
+		printf("%s  Drop packets out of sequence.", _SL_);
+	if (p->i_flags & GRE_CSUM)
+		printf("%s  Checksum in received packet is required.", _SL_);
+	if (p->o_flags & GRE_SEQ)
+		printf("%s  Sequence packets on output.", _SL_);
+	if (p->o_flags & GRE_CSUM)
+		printf("%s  Checksum output packets.", _SL_);
 }
 
-
-static void ip_tunnel_parm_initialize(const struct tnl_print_nlmsg_info *info)
+static int do_tunnels_list(struct ip_tunnel_parm *p)
 {
-	struct ip_tunnel_parm *p2 = info->p2;
+	char buf[512];
+	int err = -1;
+	FILE *fp = fopen("/proc/net/dev", "r");
 
-	memset(p2, 0, sizeof(*p2));
-}
+	if (fp == NULL) {
+		perror("fopen");
+		return -1;
+	}
 
-static bool ip_tunnel_parm_match(const struct tnl_print_nlmsg_info *info)
-{
-	const struct ip_tunnel_parm *p1 = info->p1;
-	const struct ip_tunnel_parm *p2 = info->p2;
+	/* skip header lines */
+	if (!fgets(buf, sizeof(buf), fp) ||
+	    !fgets(buf, sizeof(buf), fp)) {
+		fprintf(stderr, "/proc/net/dev read error\n");
+		goto end;
+	}
 
-	return ((!p1->link || p1->link == p2->link) &&
-		(!p1->name[0] || strcmp(p1->name, p2->name) == 0) &&
-		(!p1->iph.daddr || p1->iph.daddr == p2->iph.daddr) &&
-		(!p1->iph.saddr || p1->iph.saddr == p2->iph.saddr) &&
-		(!p1->i_key || p1->i_key == p2->i_key));
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
+		char name[IFNAMSIZ];
+		int index, type;
+		struct ip_tunnel_parm p1;
+		char *ptr;
+
+		buf[sizeof(buf) - 1] = 0;
+		ptr = strchr(buf, ':');
+		if (ptr == NULL ||
+		    (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
+			fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
+			goto end;
+		}
+		if (p->name[0] && strcmp(p->name, name))
+			continue;
+		index = ll_name_to_index(name);
+		if (index == 0)
+			continue;
+		type = ll_index_to_type(index);
+		if (type == -1) {
+			fprintf(stderr, "Failed to get type of \"%s\"\n", name);
+			continue;
+		}
+		if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT)
+			continue;
+		memset(&p1, 0, sizeof(p1));
+		if (tnl_get_ioctl(name, &p1))
+			continue;
+		if ((p->link && p1.link != p->link) ||
+		    (p->name[0] && strcmp(p1.name, p->name)) ||
+		    (p->iph.daddr && p1.iph.daddr != p->iph.daddr) ||
+		    (p->iph.saddr && p1.iph.saddr != p->iph.saddr) ||
+		    (p->i_key && p1.i_key != p->i_key))
+			continue;
+		print_tunnel(&p1);
+		if (show_stats)
+			tnl_print_stats(ptr);
+		printf("\n");
+	}
+	err = 0;
+ end:
+	fclose(fp);
+	return err;
 }
 
 static int do_show(int argc, char **argv)
 {
-	struct ip_tunnel_parm p, p1;
+	struct ip_tunnel_parm p;
 	const char *basedev;
 
+	ll_init_map(&rth);
 	if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
 		return -1;
 
 	basedev = tnl_defname(&p);
-	if (!basedev) {
-		struct tnl_print_nlmsg_info info = {
-			.p1    = &p,
-			.p2    = &p1,
-			.init  = ip_tunnel_parm_initialize,
-			.match = ip_tunnel_parm_match,
-			.print = print_tunnel,
-		};
-
-		return do_tunnels_list(&info);
-	}
+	if (!basedev)
+		return do_tunnels_list(&p);
 
 	if (tnl_get_ioctl(p.name[0] ? p.name : basedev, &p))
 		return -1;
 
 	print_tunnel(&p);
-	fputc('\n', stdout);
+	printf("\n");
 	return 0;
 }
 
 static int do_prl(int argc, char **argv)
 {
-	struct ip_tunnel_prl p = {};
+	struct ip_tunnel_prl p;
 	int count = 0;
+	int devname = 0;
 	int cmd = 0;
-	const char *medium = NULL;
+	char medium[IFNAMSIZ];
+
+	memset(&p, 0, sizeof(p));
+	memset(&medium, 0, sizeof(medium));
 
 	while (argc > 0) {
 		if (strcmp(*argv, "prl-default") == 0) {
@@ -457,9 +498,8 @@
 			count++;
 		} else if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"dev\" not a valid ifname", *argv);
-			medium = *argv;
+			strncpy(medium, *argv, IFNAMSIZ-1);
+			devname++;
 		} else {
 			fprintf(stderr,
 				"Invalid PRL parameter \"%s\"\n", *argv);
@@ -472,7 +512,7 @@
 		}
 		argc--; argv++;
 	}
-	if (!medium) {
+	if (devname == 0) {
 		fprintf(stderr, "Must specify device\n");
 		exit(-1);
 	}
@@ -482,11 +522,15 @@
 
 static int do_6rd(int argc, char **argv)
 {
-	struct ip_tunnel_6rd ip6rd = {};
+	struct ip_tunnel_6rd ip6rd;
+	int devname = 0;
 	int cmd = 0;
-	const char *medium = NULL;
+	char medium[IFNAMSIZ];
 	inet_prefix prefix;
 
+	memset(&ip6rd, 0, sizeof(ip6rd));
+	memset(&medium, 0, sizeof(medium));
+
 	while (argc > 0) {
 		if (strcmp(*argv, "6rd-prefix") == 0) {
 			NEXT_ARG();
@@ -506,9 +550,8 @@
 			cmd = SIOCDEL6RD;
 		} else if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"dev\" not a valid ifname", *argv);
-			medium = *argv;
+			strncpy(medium, *argv, IFNAMSIZ-1);
+			devname++;
 		} else {
 			fprintf(stderr,
 				"Invalid 6RD parameter \"%s\"\n", *argv);
@@ -516,7 +559,7 @@
 		}
 		argc--; argv++;
 	}
-	if (!medium) {
+	if (devname == 0) {
 		fprintf(stderr, "Must specify device\n");
 		exit(-1);
 	}
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index 82e3849..b9b28a1 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -20,33 +20,28 @@
 #include <sys/ioctl.h>
 #include <linux/if.h>
 #include <linux/if_tun.h>
-#include <linux/if_arp.h>
 #include <pwd.h>
 #include <grp.h>
 #include <fcntl.h>
 #include <dirent.h>
 #include <errno.h>
-#include <glob.h>
 
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
 
-static const char drv_name[] = "tun";
-
 #define TUNDEV "/dev/net/tun"
 
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ]\n"
-		"	[ mode { tun | tap } ] [ user USER ] [ group GROUP ]\n"
-		"	[ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ] [ name NAME ]\n"
-		"\n"
-		"Where:	USER  := { STRING | NUMBER }\n"
-		"	GROUP := { STRING | NUMBER }\n");
+	fprintf(stderr, "Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ] \n");
+	fprintf(stderr, "          [ mode { tun | tap } ] [ user USER ] [ group GROUP ]\n");
+	fprintf(stderr, "          [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: USER  := { STRING | NUMBER }\n");
+	fprintf(stderr, "       GROUP := { STRING | NUMBER }\n");
 	exit(-1);
 }
 
@@ -109,8 +104,7 @@
 	return ret;
 
 }
-static int parse_args(int argc, char **argv,
-		      struct ifreq *ifr, uid_t *uid, gid_t *gid)
+static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_t *gid)
 {
 	int count = 0;
 
@@ -123,18 +117,18 @@
 			NEXT_ARG();
 			if (matches(*argv, "tun") == 0) {
 				if (ifr->ifr_flags & IFF_TAP) {
-					fprintf(stderr, "You managed to ask for more than one tunnel mode.\n");
+					fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
 					exit(-1);
 				}
 				ifr->ifr_flags |= IFF_TUN;
 			} else if (matches(*argv, "tap") == 0) {
 				if (ifr->ifr_flags & IFF_TUN) {
-					fprintf(stderr, "You managed to ask for more than one tunnel mode.\n");
+					fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
 					exit(-1);
 				}
 				ifr->ifr_flags |= IFF_TAP;
 			} else {
-				fprintf(stderr, "Unknown tunnel mode \"%s\"\n", *argv);
+				fprintf(stderr,"Unknown tunnel mode \"%s\"\n", *argv);
 				exit(-1);
 			}
 		} else if (uid && matches(*argv, "user") == 0) {
@@ -146,7 +140,6 @@
 				*uid = user;
 			else {
 				struct passwd *pw = getpwnam(*argv);
-
 				if (!pw) {
 					fprintf(stderr, "invalid user \"%s\"\n", *argv);
 					exit(-1);
@@ -163,7 +156,6 @@
 				*gid = group;
 			else {
 				struct group *gr = getgrnam(*argv);
-
 				if (!gr) {
 					fprintf(stderr, "invalid group \"%s\"\n", *argv);
 					exit(-1);
@@ -180,8 +172,7 @@
 			ifr->ifr_flags |= IFF_MULTI_QUEUE;
 		} else if (matches(*argv, "dev") == 0) {
 			NEXT_ARG();
-			if (get_ifname(ifr->ifr_name, *argv))
-				invarg("\"dev\" not a valid ifname", *argv);
+			strncpy(ifr->ifr_name, *argv, IFNAMSIZ-1);
 		} else {
 			if (matches(*argv, "name") == 0) {
 				NEXT_ARG();
@@ -189,8 +180,7 @@
 				usage();
 			if (ifr->ifr_name[0])
 				duparg2("name", *argv);
-			if (get_ifname(ifr->ifr_name, *argv))
-				invarg("\"name\" not a valid ifname", *argv);
+			strncpy(ifr->ifr_name, *argv, IFNAMSIZ);
 		}
 		count++;
 		argc--; argv++;
@@ -227,254 +217,91 @@
 	return tap_del_ioctl(&ifr);
 }
 
+static int read_prop(char *dev, char *prop, long *value)
+{
+	char fname[IFNAMSIZ+25], buf[80], *endp;
+	ssize_t len;
+	int fd;
+	long result;
+
+	sprintf(fname, "/sys/class/net/%s/%s", dev, prop);
+	fd = open(fname, O_RDONLY);
+	if (fd < 0) {
+		if (strcmp(prop, "tun_flags"))
+			fprintf(stderr, "open %s: %s\n", fname,
+				strerror(errno));
+		return -1;
+	}
+	len = read(fd, buf, sizeof(buf)-1);
+	close(fd);
+	if (len < 0) {
+		fprintf(stderr, "read %s: %s", fname, strerror(errno));
+		return -1;
+	}
+
+	buf[len] = 0;
+	result = strtol(buf, &endp, 0);
+	if (*endp != '\n') {
+		fprintf(stderr, "Failed to parse %s\n", fname);
+		return -1;
+	}
+	*value = result;
+	return 0;
+}
+
 static void print_flags(long flags)
 {
-	open_json_array(PRINT_JSON, "flags");
-
 	if (flags & IFF_TUN)
-		print_string(PRINT_ANY, NULL, " %s", "tun");
+		printf(" tun");
 
 	if (flags & IFF_TAP)
-		print_string(PRINT_ANY, NULL, " %s", "tap");
+		printf(" tap");
 
 	if (!(flags & IFF_NO_PI))
-		print_string(PRINT_ANY, NULL, " %s", "pi");
+		printf(" pi");
 
 	if (flags & IFF_ONE_QUEUE)
-		print_string(PRINT_ANY, NULL, " %s", "one_queue");
+		printf(" one_queue");
 
 	if (flags & IFF_VNET_HDR)
-		print_string(PRINT_ANY, NULL, " %s", "vnet_hdr");
+		printf(" vnet_hdr");
 
-	if (flags & IFF_PERSIST)
-		print_string(PRINT_ANY, NULL, " %s", "persist");
-
-	if (!(flags & IFF_NOFILTER))
-		print_string(PRINT_ANY, NULL, " %s", "filter");
-
-	flags &= ~(IFF_TUN | IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE |
-		   IFF_VNET_HDR | IFF_PERSIST | IFF_NOFILTER);
+	flags &= ~(IFF_TUN|IFF_TAP|IFF_NO_PI|IFF_ONE_QUEUE|IFF_VNET_HDR);
 	if (flags)
-		print_0xhex(PRINT_ANY, NULL, "%#llx", flags);
-
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static char *pid_name(pid_t pid)
-{
-	char *comm;
-	FILE *f;
-	int err;
-
-	err = asprintf(&comm, "/proc/%d/comm", pid);
-	if (err < 0)
-		return NULL;
-
-	f = fopen(comm, "r");
-	free(comm);
-	if (!f) {
-		perror("fopen");
-		return NULL;
-	}
-
-	if (fscanf(f, "%ms\n", &comm) != 1) {
-		perror("fscanf");
-		comm = NULL;
-	}
-
-
-	if (fclose(f))
-		perror("fclose");
-
-	return comm;
-}
-
-static void show_processes(const char *name)
-{
-	glob_t globbuf = { };
-	char **fd_path;
-	int err;
-
-	err = glob("/proc/[0-9]*/fd/[0-9]*", GLOB_NOSORT,
-		   NULL, &globbuf);
-	if (err)
-		return;
-
-	open_json_array(PRINT_JSON, "processes");
-
-	fd_path = globbuf.gl_pathv;
-	while (*fd_path) {
-		const char *dev_net_tun = "/dev/net/tun";
-		const size_t linkbuf_len = strlen(dev_net_tun) + 2;
-		char linkbuf[linkbuf_len], *fdinfo;
-		int pid, fd;
-		FILE *f;
-
-		if (sscanf(*fd_path, "/proc/%d/fd/%d", &pid, &fd) != 2)
-			goto next;
-
-		if (pid == getpid())
-			goto next;
-
-		err = readlink(*fd_path, linkbuf, linkbuf_len - 1);
-		if (err < 0) {
-			perror("readlink");
-			goto next;
-		}
-		linkbuf[err] = '\0';
-		if (strcmp(dev_net_tun, linkbuf))
-			goto next;
-
-		if (asprintf(&fdinfo, "/proc/%d/fdinfo/%d", pid, fd) < 0)
-			goto next;
-
-		f = fopen(fdinfo, "r");
-		free(fdinfo);
-		if (!f) {
-			perror("fopen");
-			goto next;
-		}
-
-		while (!feof(f)) {
-			char *key = NULL, *value = NULL;
-
-			err = fscanf(f, "%m[^:]: %ms\n", &key, &value);
-			if (err == EOF) {
-				if (ferror(f))
-					perror("fscanf");
-				break;
-			} else if (err == 2 &&
-				   !strcmp("iff", key) &&
-				   !strcmp(name, value)) {
-				char *pname = pid_name(pid);
-
-				print_string(PRINT_ANY, "name",
-					     "%s", pname ? : "<NULL>");
-
-				print_uint(PRINT_ANY, "pid",
-					   "(%d)", pid);
-				free(pname);
-			}
-
-			free(key);
-			free(value);
-		}
-		if (fclose(f))
-			perror("fclose");
-
-next:
-		++fd_path;
-	}
-	close_json_array(PRINT_JSON, NULL);
-
-	globfree(&globbuf);
-}
-
-static int tuntap_filter_req(struct nlmsghdr *nlh, int reqlen)
-{
-	struct rtattr *linkinfo;
-	int err;
-
-	linkinfo = addattr_nest(nlh, reqlen, IFLA_LINKINFO);
-
-	err = addattr_l(nlh, reqlen, IFLA_INFO_KIND,
-			drv_name, sizeof(drv_name) - 1);
-	if (err)
-		return err;
-
-	addattr_nest_end(nlh, linkinfo);
-
-	return 0;
-}
-
-static int print_tuntap(struct nlmsghdr *n, void *arg)
-{
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
-	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
-	const char *name, *kind;
-	long flags, owner = -1, group = -1;
-
-	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
-		return 0;
-
-	if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifi)))
-		return -1;
-
-	switch (ifi->ifi_type) {
-	case ARPHRD_NONE:
-	case ARPHRD_ETHER:
-		break;
-	default:
-		return 0;
-	}
-
-	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
-
-	if (!tb[IFLA_IFNAME])
-		return 0;
-
-	if (!tb[IFLA_LINKINFO])
-		return 0;
-
-	parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
-
-	if (!linkinfo[IFLA_INFO_KIND])
-		return 0;
-
-	kind = rta_getattr_str(linkinfo[IFLA_INFO_KIND]);
-	if (strcmp(kind, drv_name))
-		return 0;
-
-	name = rta_getattr_str(tb[IFLA_IFNAME]);
-
-	if (read_prop(name, "tun_flags", &flags))
-		return 0;
-	if (read_prop(name, "owner", &owner))
-		return 0;
-	if (read_prop(name, "group", &group))
-		return 0;
-
-	open_json_object(NULL);
-	print_color_string(PRINT_ANY, COLOR_IFNAME,
-			   "ifname", "%s:", name);
-	print_flags(flags);
-	if (owner != -1)
-		print_u64(PRINT_ANY, "user",
-			   " user %ld", owner);
-	if (group != -1)
-		print_u64(PRINT_ANY, "group",
-			   " group %ld", group);
-
-	if (show_details) {
-		print_string(PRINT_FP, NULL,
-			     "%s\tAttached to processes:", _SL_);
-		show_processes(name);
-	}
-	close_json_object();
-	print_string(PRINT_FP, NULL, "%s", "\n");
-
-	return 0;
+		printf(" UNKNOWN_FLAGS:%lx", flags);
 }
 
 static int do_show(int argc, char **argv)
 {
-	if (rtnl_linkdump_req_filter_fn(&rth, AF_UNSPEC,
-					tuntap_filter_req) < 0) {
-		perror("Cannot send dump request\n");
+	DIR *dir;
+	struct dirent *d;
+	long flags, owner = -1, group = -1;
+
+	dir = opendir("/sys/class/net");
+	if (!dir) {
+		perror("opendir");
 		return -1;
 	}
+	while ((d = readdir(dir))) {
+		if (d->d_name[0] == '.' &&
+		    (d->d_name[1] == 0 || d->d_name[1] == '.'))
+			continue;
 
-	new_json_obj(json);
+		if (read_prop(d->d_name, "tun_flags", &flags))
+			continue;
 
-	if (rtnl_dump_filter(&rth, print_tuntap, NULL) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return -1;
+		read_prop(d->d_name, "owner", &owner);
+		read_prop(d->d_name, "group", &group);
+
+		printf("%s:", d->d_name);
+		print_flags(flags);
+		if (owner != -1)
+			printf(" user %ld", owner);
+		if (group != -1)
+			printf(" group %ld", group);
+		printf("\n");
 	}
-
-	delete_json_obj();
-	fflush(stdout);
-
+	closedir(dir);
 	return 0;
 }
 
@@ -486,9 +313,9 @@
 		if (matches(*argv, "delete") == 0)
 			return do_del(argc-1, argv+1);
 		if (matches(*argv, "show") == 0 ||
-		    matches(*argv, "lst") == 0 ||
-		    matches(*argv, "list") == 0)
-			return do_show(argc-1, argv+1);
+                    matches(*argv, "lst") == 0 ||
+                    matches(*argv, "list") == 0)
+                        return do_show(argc-1, argv+1);
 		if (matches(*argv, "help") == 0)
 			usage();
 	} else
@@ -498,102 +325,3 @@
 		*argv);
 	exit(-1);
 }
-
-static void print_owner(FILE *f, uid_t uid)
-{
-	struct passwd *pw = getpwuid(uid);
-
-	if (pw)
-		print_string(PRINT_ANY, "user", "user %s ", pw->pw_name);
-	else
-		print_uint(PRINT_ANY, "user", "user %u ", uid);
-}
-
-static void print_group(FILE *f, gid_t gid)
-{
-	struct group *group = getgrgid(gid);
-
-	if (group)
-		print_string(PRINT_ANY, "group", "group %s ", group->gr_name);
-	else
-		print_uint(PRINT_ANY, "group", "group %u ", gid);
-}
-
-static void print_mq(FILE *f, struct rtattr *tb[])
-{
-	if (!tb[IFLA_TUN_MULTI_QUEUE] ||
-	    !rta_getattr_u8(tb[IFLA_TUN_MULTI_QUEUE])) {
-		if (is_json_context())
-			print_bool(PRINT_JSON, "multi_queue", NULL, false);
-		return;
-	}
-
-	print_bool(PRINT_ANY, "multi_queue", "multi_queue ", true);
-
-	if (tb[IFLA_TUN_NUM_QUEUES]) {
-		print_uint(PRINT_ANY, "numqueues", "numqueues %u ",
-			   rta_getattr_u32(tb[IFLA_TUN_NUM_QUEUES]));
-	}
-
-	if (tb[IFLA_TUN_NUM_DISABLED_QUEUES]) {
-		print_uint(PRINT_ANY, "numdisabled", "numdisabled %u ",
-			   rta_getattr_u32(tb[IFLA_TUN_NUM_DISABLED_QUEUES]));
-	}
-}
-
-static void print_onoff(FILE *f, const char *flag, __u8 val)
-{
-	if (is_json_context())
-		print_bool(PRINT_JSON, flag, NULL, !!val);
-	else
-		fprintf(f, "%s %s ", flag, val ? "on" : "off");
-}
-
-static void print_type(FILE *f, __u8 type)
-{
-	SPRINT_BUF(buf);
-	const char *str = buf;
-
-	if (type == IFF_TUN)
-		str = "tun";
-	else if (type == IFF_TAP)
-		str = "tap";
-	else
-		snprintf(buf, sizeof(buf), "UNKNOWN:%hhu", type);
-
-	print_string(PRINT_ANY, "type", "type %s ", str);
-}
-
-static void tun_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
-{
-	if (!tb)
-		return;
-
-	if (tb[IFLA_TUN_TYPE])
-		print_type(f, rta_getattr_u8(tb[IFLA_TUN_TYPE]));
-
-	if (tb[IFLA_TUN_PI])
-		print_onoff(f, "pi", rta_getattr_u8(tb[IFLA_TUN_PI]));
-
-	if (tb[IFLA_TUN_VNET_HDR]) {
-		print_onoff(f, "vnet_hdr",
-			    rta_getattr_u8(tb[IFLA_TUN_VNET_HDR]));
-	}
-
-	print_mq(f, tb);
-
-	if (tb[IFLA_TUN_PERSIST])
-		print_onoff(f, "persist", rta_getattr_u8(tb[IFLA_TUN_PERSIST]));
-
-	if (tb[IFLA_TUN_OWNER])
-		print_owner(f, rta_getattr_u32(tb[IFLA_TUN_OWNER]));
-
-	if (tb[IFLA_TUN_GROUP])
-		print_group(f, rta_getattr_u32(tb[IFLA_TUN_GROUP]));
-}
-
-struct link_util tun_link_util = {
-	.id = "tun",
-	.maxattr = IFLA_TUN_MAX,
-	.print_opt = tun_print_opt,
-};
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
deleted file mode 100644
index 43366f6..0000000
--- a/ip/ipvrf.c
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * ipvrf.c	"ip vrf"
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	David Ahern <dsa@cumulusnetworks.com>
- *
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/mount.h>
-#include <linux/bpf.h>
-#include <linux/if.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <limits.h>
-
-#include "rt_names.h"
-#include "utils.h"
-#include "ip_common.h"
-#include "bpf_util.h"
-
-#define CGRP_PROC_FILE  "/cgroup.procs"
-
-static struct link_filter vrf_filter;
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage:	ip vrf show [NAME] ...\n"
-		"	ip vrf exec [NAME] cmd ...\n"
-		"	ip vrf identify [PID]\n"
-		"	ip vrf pids [NAME]\n");
-
-	exit(-1);
-}
-
-/*
- * parse process based cgroup file looking for PATH/vrf/NAME where
- * NAME is the name of the vrf the process is associated with
- */
-static int vrf_identify(pid_t pid, char *name, size_t len)
-{
-	char path[PATH_MAX];
-	char buf[4096];
-	char *vrf, *end;
-	FILE *fp;
-
-	snprintf(path, sizeof(path), "/proc/%d/cgroup", pid);
-	fp = fopen(path, "r");
-	if (!fp)
-		return -1;
-
-	memset(name, 0, len);
-
-	while (fgets(buf, sizeof(buf), fp)) {
-		/* want the controller-less cgroup */
-		if (strstr(buf, "::/") == NULL)
-			continue;
-
-		vrf = strstr(buf, "/vrf/");
-		if (vrf) {
-			vrf += 5;  /* skip past "/vrf/" */
-			end = strchr(vrf, '\n');
-			if (end)
-				*end = '\0';
-
-			strlcpy(name, vrf, len);
-			break;
-		}
-	}
-
-	fclose(fp);
-
-	return 0;
-}
-
-static int ipvrf_identify(int argc, char **argv)
-{
-	char vrf[32];
-	int rc;
-	unsigned int pid;
-
-	if (argc < 1)
-		pid = getpid();
-	else if (argc > 1)
-		invarg("Extra arguments specified\n", argv[1]);
-	else if (get_unsigned(&pid, argv[0], 10))
-		invarg("Invalid pid\n", argv[0]);
-
-	rc = vrf_identify(pid, vrf, sizeof(vrf));
-	if (!rc) {
-		if (vrf[0] != '\0')
-			printf("%s\n", vrf);
-	} else {
-		fprintf(stderr, "Failed to lookup vrf association: %s\n",
-			strerror(errno));
-	}
-
-	return rc;
-}
-
-/* read PATH/vrf/NAME/cgroup.procs file */
-static void read_cgroup_pids(const char *base_path, char *name)
-{
-	char path[PATH_MAX];
-	char buf[4096];
-	FILE *fp;
-
-	if (snprintf(path, sizeof(path), "%s/vrf/%s%s",
-		     base_path, name, CGRP_PROC_FILE) >= sizeof(path))
-		return;
-
-	fp = fopen(path, "r");
-	if (!fp)
-		return; /* no cgroup file, nothing to show */
-
-	/* dump contents (pids) of cgroup.procs */
-	while (fgets(buf, sizeof(buf), fp)) {
-		char *nl, comm[32];
-
-		nl = strchr(buf, '\n');
-		if (nl)
-			*nl = '\0';
-
-		if (get_command_name(buf, comm, sizeof(comm)))
-			strcpy(comm, "<terminated?>");
-
-		printf("%5s  %s\n", buf, comm);
-	}
-
-	fclose(fp);
-}
-
-/* recurse path looking for PATH[/NETNS]/vrf/NAME */
-static int recurse_dir(char *base_path, char *name, const char *netns)
-{
-	char path[PATH_MAX];
-	struct dirent *de;
-	struct stat fstat;
-	int rc;
-	DIR *d;
-
-	d = opendir(base_path);
-	if (!d)
-		return -1;
-
-	while ((de = readdir(d)) != NULL) {
-		if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
-			continue;
-
-		if (!strcmp(de->d_name, "vrf")) {
-			const char *pdir = strrchr(base_path, '/');
-
-			/* found a 'vrf' directory. if it is for the given
-			 * namespace then dump the cgroup pids
-			 */
-			if (*netns == '\0' ||
-			    (pdir && !strcmp(pdir+1, netns)))
-				read_cgroup_pids(base_path, name);
-
-			continue;
-		}
-
-		/* is this a subdir that needs to be walked */
-		if (snprintf(path, sizeof(path), "%s/%s",
-			     base_path, de->d_name) >= sizeof(path))
-			continue;
-
-		if (lstat(path, &fstat) < 0)
-			continue;
-
-		if (S_ISDIR(fstat.st_mode)) {
-			rc = recurse_dir(path, name, netns);
-			if (rc != 0)
-				goto out;
-		}
-	}
-
-	rc = 0;
-out:
-	closedir(d);
-
-	return rc;
-}
-
-static int ipvrf_get_netns(char *netns, int len)
-{
-	if (netns_identify_pid("self", netns, len-3)) {
-		fprintf(stderr, "Failed to get name of network namespace: %s\n",
-			strerror(errno));
-		return -1;
-	}
-
-	if (*netns != '\0')
-		strcat(netns, "-ns");
-
-	return 0;
-}
-
-static int ipvrf_pids(int argc, char **argv)
-{
-	char *mnt, *vrf;
-	char netns[256];
-	int ret = -1;
-
-	if (argc != 1) {
-		fprintf(stderr, "Invalid arguments\n");
-		return -1;
-	}
-
-	vrf = argv[0];
-	if (!name_is_vrf(vrf)) {
-		fprintf(stderr, "Invalid VRF name\n");
-		return -1;
-	}
-
-	mnt = find_cgroup2_mount();
-	if (!mnt)
-		return -1;
-
-	if (ipvrf_get_netns(netns, sizeof(netns)) < 0)
-		goto out;
-
-	ret = recurse_dir(mnt, vrf, netns);
-
-out:
-	free(mnt);
-
-	return ret;
-}
-
-/* load BPF program to set sk_bound_dev_if for sockets */
-static char bpf_log_buf[256*1024];
-
-static int prog_load(int idx)
-{
-	struct bpf_insn prog[] = {
-		BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
-		BPF_MOV64_IMM(BPF_REG_3, idx),
-		BPF_MOV64_IMM(BPF_REG_2,
-			      offsetof(struct bpf_sock, bound_dev_if)),
-		BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_3,
-			    offsetof(struct bpf_sock, bound_dev_if)),
-		BPF_MOV64_IMM(BPF_REG_0, 1), /* r0 = verdict */
-		BPF_EXIT_INSN(),
-	};
-
-	return bpf_prog_load(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
-			     "GPL", bpf_log_buf, sizeof(bpf_log_buf));
-}
-
-static int vrf_configure_cgroup(const char *path, int ifindex)
-{
-	int rc = -1, cg_fd, prog_fd = -1;
-
-	cg_fd = open(path, O_DIRECTORY | O_RDONLY);
-	if (cg_fd < 0) {
-		fprintf(stderr,
-			"Failed to open cgroup path: '%s'\n",
-			strerror(errno));
-		goto out;
-	}
-
-	/*
-	 * Load bpf program into kernel and attach to cgroup to affect
-	 * socket creates
-	 */
-	prog_fd = prog_load(ifindex);
-	if (prog_fd < 0) {
-		fprintf(stderr, "Failed to load BPF prog: '%s'\n",
-			strerror(errno));
-
-		if (errno != EPERM) {
-			fprintf(stderr,
-				"Kernel compiled with CGROUP_BPF enabled?\n");
-		}
-		goto out;
-	}
-
-	if (bpf_prog_attach_fd(prog_fd, cg_fd, BPF_CGROUP_INET_SOCK_CREATE)) {
-		fprintf(stderr, "Failed to attach prog to cgroup: '%s'\n",
-			strerror(errno));
-		goto out;
-	}
-
-	rc = 0;
-out:
-	close(cg_fd);
-	close(prog_fd);
-
-	return rc;
-}
-
-/* get base path for controller-less cgroup for a process.
- * path returned does not include /vrf/NAME if it exists
- */
-static int vrf_path(char *vpath, size_t len)
-{
-	char path[PATH_MAX];
-	char buf[4096];
-	char *vrf;
-	FILE *fp;
-
-	snprintf(path, sizeof(path), "/proc/%d/cgroup", getpid());
-	fp = fopen(path, "r");
-	if (!fp)
-		return -1;
-
-	vpath[0] = '\0';
-
-	while (fgets(buf, sizeof(buf), fp)) {
-		char *start, *nl;
-
-		start = strstr(buf, "::/");
-		if (!start)
-			continue;
-
-		/* advance past '::' */
-		start += 2;
-
-		nl = strchr(start, '\n');
-		if (nl)
-			*nl = '\0';
-
-		vrf = strstr(start, "/vrf");
-		if (vrf)
-			*vrf = '\0';
-
-		strlcpy(vpath, start, len);
-
-		/* if vrf path is just / then return nothing */
-		if (!strcmp(vpath, "/"))
-			vpath[0] = '\0';
-
-		break;
-	}
-
-	fclose(fp);
-
-	return 0;
-}
-
-static int vrf_switch(const char *name)
-{
-	char path[PATH_MAX], *mnt, pid[16];
-	char vpath[PATH_MAX], netns[256];
-	int ifindex = 0;
-	int rc = -1, len, fd = -1;
-
-	if (strcmp(name, "default")) {
-		ifindex = name_is_vrf(name);
-		if (!ifindex) {
-			fprintf(stderr, "Invalid VRF name\n");
-			return -1;
-		}
-	}
-
-	mnt = find_cgroup2_mount();
-	if (!mnt)
-		return -1;
-
-	/* -1 on length to add '/' to the end */
-	if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
-		goto out;
-
-	if (vrf_path(vpath, sizeof(vpath)) < 0) {
-		fprintf(stderr, "Failed to get base cgroup path: %s\n",
-			strerror(errno));
-		goto out;
-	}
-
-	/* if path already ends in netns then don't add it again */
-	if (*netns != '\0') {
-		char *pdir = strrchr(vpath, '/');
-
-		if (!pdir)
-			pdir = vpath;
-		else
-			pdir++;
-
-		if (strcmp(pdir, netns) == 0)
-			*pdir = '\0';
-
-		strcat(netns, "/");
-	}
-
-	/* path to cgroup; make sure buffer has room to cat "/cgroup.procs"
-	 * to the end of the path
-	 */
-	len = snprintf(path, sizeof(path) - sizeof(CGRP_PROC_FILE),
-		       "%s%s/%svrf/%s",
-		       mnt, vpath, netns, ifindex ? name : "");
-	if (len > sizeof(path) - sizeof(CGRP_PROC_FILE)) {
-		fprintf(stderr, "Invalid path to cgroup2 mount\n");
-		goto out;
-	}
-
-	if (make_path(path, 0755)) {
-		fprintf(stderr, "Failed to setup vrf cgroup2 directory\n");
-		goto out;
-	}
-
-	if (ifindex && vrf_configure_cgroup(path, ifindex))
-		goto out;
-
-	/*
-	 * write pid to cgroup.procs making process part of cgroup
-	 */
-	strcat(path, CGRP_PROC_FILE);
-	fd = open(path, O_RDWR | O_APPEND);
-	if (fd < 0) {
-		fprintf(stderr, "Failed to open cgroups.procs file: %s.\n",
-			strerror(errno));
-		goto out;
-	}
-
-	snprintf(pid, sizeof(pid), "%d", getpid());
-	if (write(fd, pid, strlen(pid)) < 0) {
-		fprintf(stderr, "Failed to join cgroup\n");
-		goto out2;
-	}
-
-	rc = 0;
-out2:
-	close(fd);
-out:
-	free(mnt);
-
-	drop_cap();
-
-	return rc;
-}
-
-static int do_switch(void *arg)
-{
-	char *vrf = arg;
-
-	return vrf_switch(vrf);
-}
-
-static int ipvrf_exec(int argc, char **argv)
-{
-	if (argc < 1) {
-		fprintf(stderr, "No VRF name specified\n");
-		return -1;
-	}
-	if (argc < 2) {
-		fprintf(stderr, "No command specified\n");
-		return -1;
-	}
-
-	return -cmd_exec(argv[1], argv + 1, !!batch_mode, do_switch, argv[0]);
-}
-
-/* reset VRF association of current process to default VRF;
- * used by netns_exec
- */
-void vrf_reset(void)
-{
-	char vrf[32];
-
-	if (vrf_identify(getpid(), vrf, sizeof(vrf)) ||
-	    (vrf[0] == '\0'))
-		return;
-
-	vrf_switch("default");
-}
-
-static int ipvrf_filter_req(struct nlmsghdr *nlh, int reqlen)
-{
-	struct rtattr *linkinfo;
-	int err;
-
-	if (vrf_filter.kind) {
-		linkinfo = addattr_nest(nlh, reqlen, IFLA_LINKINFO);
-
-		err = addattr_l(nlh, reqlen, IFLA_INFO_KIND, vrf_filter.kind,
-				strlen(vrf_filter.kind));
-		if (err)
-			return err;
-
-		addattr_nest_end(nlh, linkinfo);
-	}
-
-	return 0;
-}
-
-/* input arg is linkinfo */
-static __u32 vrf_table_linkinfo(struct rtattr *li[])
-{
-	struct rtattr *attr[IFLA_VRF_MAX + 1];
-
-	if (li[IFLA_INFO_DATA]) {
-		parse_rtattr_nested(attr, IFLA_VRF_MAX, li[IFLA_INFO_DATA]);
-
-		if (attr[IFLA_VRF_TABLE])
-			return rta_getattr_u32(attr[IFLA_VRF_TABLE]);
-	}
-
-	return 0;
-}
-
-static int ipvrf_print(struct nlmsghdr *n)
-{
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
-	struct rtattr *li[IFLA_INFO_MAX+1];
-	int len = n->nlmsg_len;
-	const char *name;
-	__u32 tb_id;
-
-	len -= NLMSG_LENGTH(sizeof(*ifi));
-	if (len < 0)
-		return 0;
-
-	if (vrf_filter.ifindex && vrf_filter.ifindex != ifi->ifi_index)
-		return 0;
-
-	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
-
-	/* kernel does not support filter by master device */
-	if (tb[IFLA_MASTER]) {
-		int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
-
-		if (vrf_filter.master && master != vrf_filter.master)
-			return 0;
-	}
-
-	if (!tb[IFLA_IFNAME]) {
-		fprintf(stderr,
-			"BUG: device with ifindex %d has nil ifname\n",
-			ifi->ifi_index);
-		return 0;
-	}
-	name = rta_getattr_str(tb[IFLA_IFNAME]);
-
-	/* missing LINKINFO means not VRF. e.g., kernel does not
-	 * support filtering on kind, so userspace needs to handle
-	 */
-	if (!tb[IFLA_LINKINFO])
-		return 0;
-
-	parse_rtattr_nested(li, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
-
-	if (!li[IFLA_INFO_KIND])
-		return 0;
-
-	if (strcmp(RTA_DATA(li[IFLA_INFO_KIND]), "vrf"))
-		return 0;
-
-	tb_id = vrf_table_linkinfo(li);
-	if (!tb_id) {
-		fprintf(stderr,
-			"BUG: VRF %s is missing table id\n", name);
-		return 0;
-	}
-
-	printf("%-16s %5u", name, tb_id);
-
-	printf("\n");
-	return 1;
-}
-
-static int ipvrf_show(int argc, char **argv)
-{
-	struct nlmsg_chain linfo = { NULL, NULL};
-	int rc = 0;
-
-	vrf_filter.kind = "vrf";
-
-	if (argc > 1)
-		usage();
-
-	if (argc == 1) {
-		__u32 tb_id;
-
-		tb_id = ipvrf_get_table(argv[0]);
-		if (!tb_id) {
-			fprintf(stderr, "Invalid VRF\n");
-			return 1;
-		}
-		printf("%s %u\n", argv[0], tb_id);
-		return 0;
-	}
-
-	if (ip_link_list(ipvrf_filter_req, &linfo) == 0) {
-		struct nlmsg_list *l;
-		unsigned nvrf = 0;
-		int n;
-
-		n = printf("%-16s  %5s\n", "Name", "Table");
-		printf("%.*s\n", n-1, "-----------------------");
-		for (l = linfo.head; l; l = l->next)
-			nvrf += ipvrf_print(&l->h);
-
-		if (!nvrf)
-			printf("No VRF has been configured\n");
-	} else
-		rc = 1;
-
-	free_nlmsg_chain(&linfo);
-
-	return rc;
-}
-
-int do_ipvrf(int argc, char **argv)
-{
-	if (argc == 0)
-		return ipvrf_show(0, NULL);
-
-	if (matches(*argv, "identify") == 0)
-		return ipvrf_identify(argc-1, argv+1);
-
-	if (matches(*argv, "pids") == 0)
-		return ipvrf_pids(argc-1, argv+1);
-
-	if (matches(*argv, "exec") == 0)
-		return ipvrf_exec(argc-1, argv+1);
-
-	if (matches(*argv, "show") == 0 ||
-	    matches(*argv, "lst") == 0 ||
-	    matches(*argv, "list") == 0)
-		return ipvrf_show(argc-1, argv+1);
-
-	if (matches(*argv, "help") == 0)
-		usage();
-
-	fprintf(stderr, "Command \"%s\" is unknown, try \"ip vrf help\".\n",
-		*argv);
-
-	exit(-1);
-}
diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 32f5609..e583abf 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -40,6 +40,17 @@
 #include "ip_common.h"
 
 #define STRBUF_SIZE	(128)
+#define STRBUF_CAT(buf, str) \
+	do { \
+		int rest = sizeof(buf) - 1 - strlen(buf); \
+		if (rest > 0) { \
+			int len = strlen(str); \
+			if (len > rest) \
+				len = rest; \
+			strncat(buf, str, len); \
+			buf[sizeof(buf) - 1] = '\0'; \
+		} \
+	} while(0);
 
 struct xfrm_filter filter;
 
@@ -100,7 +111,7 @@
 	int t_type;
 };
 
-static const struct typeent xfrmproto_types[] = {
+static const struct typeent xfrmproto_types[]= {
 	{ "esp", IPPROTO_ESP }, { "ah", IPPROTO_AH }, { "comp", IPPROTO_COMP },
 	{ "route2", IPPROTO_ROUTING }, { "hao", IPPROTO_DSTOPTS },
 	{ "ipsec-any", IPSEC_PROTO_ANY },
@@ -113,7 +124,6 @@
 
 	for (i = 0; ; i++) {
 		const struct typeent *t = &xfrmproto_types[i];
-
 		if (!t->t_name || t->t_type == -1)
 			break;
 
@@ -131,7 +141,6 @@
 
 	for (i = 0; ; i++) {
 		const struct typeent *t = &xfrmproto_types[i];
-
 		if (!t->t_name || t->t_type == -1)
 			break;
 
@@ -143,7 +152,7 @@
 	return str;
 }
 
-static const struct typeent algo_types[] = {
+static const struct typeent algo_types[]= {
 	{ "enc", XFRMA_ALG_CRYPT }, { "auth", XFRMA_ALG_AUTH },
 	{ "comp", XFRMA_ALG_COMP }, { "aead", XFRMA_ALG_AEAD },
 	{ "auth-trunc", XFRMA_ALG_AUTH_TRUNC },
@@ -156,7 +165,6 @@
 
 	for (i = 0; ; i++) {
 		const struct typeent *t = &algo_types[i];
-
 		if (!t->t_name || t->t_type == -1)
 			break;
 
@@ -174,7 +182,6 @@
 
 	for (i = 0; ; i++) {
 		const struct typeent *t = &algo_types[i];
-
 		if (!t->t_name || t->t_type == -1)
 			break;
 
@@ -186,7 +193,7 @@
 	return str;
 }
 
-static const char *strxf_mask8(__u8 mask)
+const char *strxf_mask8(__u8 mask)
 {
 	static char str[16];
 	const int sn = sizeof(mask) * 8 - 1;
@@ -209,7 +216,7 @@
 	return str;
 }
 
-static const char *strxf_share(__u8 share)
+const char *strxf_share(__u8 share)
 {
 	static char str[32];
 
@@ -270,15 +277,21 @@
 	return str;
 }
 
-static void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
+void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
 			__u8 mode, __u32 reqid, __u16 family, int force_spi,
 			FILE *fp, const char *prefix, const char *title)
 {
+	char abuf[256];
+
 	if (title)
 		fputs(title, fp);
 
-	fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr), saddr));
-	fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr), &id->daddr));
+	memset(abuf, '\0', sizeof(abuf));
+	fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr),
+					   saddr, abuf, sizeof(abuf)));
+	memset(abuf, '\0', sizeof(abuf));
+	fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr),
+					  &id->daddr, abuf, sizeof(abuf)));
 	fprintf(fp, "%s", _SL_);
 
 	if (prefix)
@@ -289,7 +302,6 @@
 
 	if (show_stats > 0 || force_spi || id->spi) {
 		__u32 spi = ntohl(id->spi);
-
 		fprintf(fp, "spi 0x%08x", spi);
 		if (show_stats > 0)
 			fprintf(fp, "(%u)", spi);
@@ -328,7 +340,6 @@
 static const char *strxf_limit(__u64 limit)
 {
 	static char str[32];
-
 	if (limit == XFRM_INF)
 		strcpy(str, "(INF)");
 	else
@@ -337,8 +348,7 @@
 	return str;
 }
 
-static void xfrm_stats_print(struct xfrm_stats *s, FILE *fp,
-			     const char *prefix)
+void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix)
 {
 	if (prefix)
 		fputs(prefix, fp);
@@ -372,14 +382,14 @@
 	return str;
 }
 
-static void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
+void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
 			 struct xfrm_lifetime_cur *cur,
 			 FILE *fp, const char *prefix)
 {
 	if (cfg) {
 		if (prefix)
 			fputs(prefix, fp);
-		fprintf(fp, "lifetime config:%s", _SL_);
+		fprintf(fp, "lifetime config:%s",_SL_);
 
 		if (prefix)
 			fputs(prefix, fp);
@@ -431,6 +441,7 @@
 void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
 			 FILE *fp, const char *prefix)
 {
+	char abuf[256];
 	__u16 f;
 
 	f = sel->family;
@@ -442,12 +453,16 @@
 	if (prefix)
 		fputs(prefix, fp);
 
+	memset(abuf, '\0', sizeof(abuf));
 	fprintf(fp, "src %s/%u ",
-		rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr),
+		rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr,
+			    abuf, sizeof(abuf)),
 		sel->prefixlen_s);
 
+	memset(abuf, '\0', sizeof(abuf));
 	fprintf(fp, "dst %s/%u ",
-		rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr),
+		rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr,
+			    abuf, sizeof(abuf)),
 		sel->prefixlen_d);
 
 	if (sel->proto)
@@ -497,8 +512,7 @@
 }
 
 static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
-			      FILE *fp, const char *prefix, int newline,
-			      bool nokeys)
+			      FILE *fp, const char *prefix, int newline)
 {
 	int keylen;
 	int i;
@@ -522,11 +536,9 @@
 		goto fin;
 	}
 
-	if (nokeys)
-		fprintf(fp, "<<Keys hidden>>");
-	else if (keylen > 0) {
+	if (keylen > 0) {
 		fprintf(fp, "0x");
-		for (i = 0; i < keylen; i++)
+		for (i = 0; i < keylen; i ++)
 			fprintf(fp, "%.2x", (unsigned char)algo->alg_key[i]);
 
 		if (show_stats > 0)
@@ -539,13 +551,13 @@
 }
 
 static inline void xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
-				   FILE *fp, const char *prefix, bool nokeys)
+				   FILE *fp, const char *prefix)
 {
-	return __xfrm_algo_print(algo, type, len, fp, prefix, 1, nokeys);
+	return __xfrm_algo_print(algo, type, len, fp, prefix, 1);
 }
 
 static void xfrm_aead_print(struct xfrm_algo_aead *algo, int len,
-			    FILE *fp, const char *prefix, bool nokeys)
+			    FILE *fp, const char *prefix)
 {
 	struct xfrm_algo *base_algo = alloca(sizeof(*base_algo) + algo->alg_key_len / 8);
 
@@ -553,8 +565,7 @@
 	base_algo->alg_key_len = algo->alg_key_len;
 	memcpy(base_algo->alg_key, algo->alg_key, algo->alg_key_len / 8);
 
-	__xfrm_algo_print(base_algo, XFRMA_ALG_AEAD, len, fp, prefix, 0,
-			  nokeys);
+	__xfrm_algo_print(base_algo, XFRMA_ALG_AEAD, len, fp, prefix, 0);
 
 	fprintf(fp, " %d", algo->alg_icv_len);
 
@@ -562,7 +573,7 @@
 }
 
 static void xfrm_auth_trunc_print(struct xfrm_algo_auth *algo, int len,
-				  FILE *fp, const char *prefix, bool nokeys)
+				  FILE *fp, const char *prefix)
 {
 	struct xfrm_algo *base_algo = alloca(sizeof(*base_algo) + algo->alg_key_len / 8);
 
@@ -570,8 +581,7 @@
 	base_algo->alg_key_len = algo->alg_key_len;
 	memcpy(base_algo->alg_key, algo->alg_key, algo->alg_key_len / 8);
 
-	__xfrm_algo_print(base_algo, XFRMA_ALG_AUTH_TRUNC, len, fp, prefix, 0,
-			  nokeys);
+	__xfrm_algo_print(base_algo, XFRMA_ALG_AUTH_TRUNC, len, fp, prefix, 0);
 
 	fprintf(fp, " %d", algo->alg_trunc_len);
 
@@ -643,13 +653,6 @@
 	}
 }
 
-static void xfrm_output_mark_print(struct rtattr *tb[], FILE *fp)
-{
-	__u32 output_mark = rta_getattr_u32(tb[XFRMA_OUTPUT_MARK]);
-
-	fprintf(fp, "output-mark 0x%x", output_mark);
-}
-
 int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp)
 {
 	int argc = *argcp;
@@ -684,61 +687,48 @@
 }
 
 void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
-		      FILE *fp, const char *prefix, bool nokeys)
+		      FILE *fp, const char *prefix)
 {
 	if (tb[XFRMA_MARK]) {
 		struct rtattr *rta = tb[XFRMA_MARK];
-		struct xfrm_mark *m = RTA_DATA(rta);
-
-		fprintf(fp, "\tmark %#x/%#x ", m->v, m->m);
-
-		if (tb[XFRMA_OUTPUT_MARK])
-			xfrm_output_mark_print(tb, fp);
-		fprintf(fp, "%s", _SL_);
-	} else if (tb[XFRMA_OUTPUT_MARK]) {
-		fprintf(fp, "\t");
-
-		xfrm_output_mark_print(tb, fp);
+		struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta);
+		fprintf(fp, "\tmark %#x/%#x", m->v, m->m);
 		fprintf(fp, "%s", _SL_);
 	}
 
 	if (tb[XFRMA_ALG_AUTH] && !tb[XFRMA_ALG_AUTH_TRUNC]) {
 		struct rtattr *rta = tb[XFRMA_ALG_AUTH];
-
-		xfrm_algo_print(RTA_DATA(rta), XFRMA_ALG_AUTH, RTA_PAYLOAD(rta),
-				fp, prefix, nokeys);
+		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
+				XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
 	}
 
 	if (tb[XFRMA_ALG_AUTH_TRUNC]) {
 		struct rtattr *rta = tb[XFRMA_ALG_AUTH_TRUNC];
-
-		xfrm_auth_trunc_print(RTA_DATA(rta), RTA_PAYLOAD(rta), fp,
-				      prefix, nokeys);
+		xfrm_auth_trunc_print((struct xfrm_algo_auth *) RTA_DATA(rta),
+				      RTA_PAYLOAD(rta), fp, prefix);
 	}
 
 	if (tb[XFRMA_ALG_AEAD]) {
 		struct rtattr *rta = tb[XFRMA_ALG_AEAD];
-
-		xfrm_aead_print(RTA_DATA(rta), RTA_PAYLOAD(rta), fp, prefix,
-				nokeys);
+		xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
+				RTA_PAYLOAD(rta), fp, prefix);
 	}
 
 	if (tb[XFRMA_ALG_CRYPT]) {
 		struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
-
-		xfrm_algo_print(RTA_DATA(rta), XFRMA_ALG_CRYPT,
-				RTA_PAYLOAD(rta), fp, prefix, nokeys);
+		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
+				XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
 	}
 
 	if (tb[XFRMA_ALG_COMP]) {
 		struct rtattr *rta = tb[XFRMA_ALG_COMP];
-
-		xfrm_algo_print(RTA_DATA(rta), XFRMA_ALG_COMP, RTA_PAYLOAD(rta),
-				fp, prefix, nokeys);
+		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
+				XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
 	}
 
 	if (tb[XFRMA_ENCAP]) {
 		struct xfrm_encap_tmpl *e;
+		char abuf[256];
 
 		if (prefix)
 			fputs(prefix, fp);
@@ -749,7 +739,7 @@
 			fprintf(fp, "%s", _SL_);
 			return;
 		}
-		e = RTA_DATA(tb[XFRMA_ENCAP]);
+		e = (struct xfrm_encap_tmpl *) RTA_DATA(tb[XFRMA_ENCAP]);
 
 		fprintf(fp, "type ");
 		switch (e->encap_type) {
@@ -766,34 +756,39 @@
 		fprintf(fp, "sport %u ", ntohs(e->encap_sport));
 		fprintf(fp, "dport %u ", ntohs(e->encap_dport));
 
+		memset(abuf, '\0', sizeof(abuf));
 		fprintf(fp, "addr %s",
-			rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa));
+			rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa,
+				    abuf, sizeof(abuf)));
 		fprintf(fp, "%s", _SL_);
 	}
 
 	if (tb[XFRMA_TMPL]) {
 		struct rtattr *rta = tb[XFRMA_TMPL];
-
-		xfrm_tmpl_print(RTA_DATA(rta),
+		xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
 				RTA_PAYLOAD(rta), fp, prefix);
 	}
 
 	if (tb[XFRMA_COADDR]) {
-		const xfrm_address_t *coa;
+		char abuf[256];
+		xfrm_address_t *coa;
 
 		if (prefix)
 			fputs(prefix, fp);
 		fprintf(fp, "coa ");
 
-		coa = RTA_DATA(tb[XFRMA_COADDR]);
+		coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);
+
 		if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
 			fprintf(fp, "(ERROR truncated)");
 			fprintf(fp, "%s", _SL_);
 			return;
 		}
 
+		memset(abuf, '\0', sizeof(abuf));
 		fprintf(fp, "%s",
-			rt_addr_n2a(family, sizeof(*coa), coa));
+			rt_addr_n2a(family, sizeof(*coa), coa,
+				    abuf, sizeof(abuf)));
 		fprintf(fp, "%s", _SL_);
 	}
 
@@ -829,7 +824,7 @@
 			return;
 		}
 
-		replay = RTA_DATA(tb[XFRMA_REPLAY_VAL]);
+		replay = (struct xfrm_replay_state *)RTA_DATA(tb[XFRMA_REPLAY_VAL]);
 		fprintf(fp, "seq 0x%x, oseq 0x%x, bitmap 0x%08x",
 			replay->seq, replay->oseq, replay->bitmap);
 		fprintf(fp, "%s", _SL_);
@@ -850,7 +845,7 @@
 		}
 		fprintf(fp, "%s", _SL_);
 
-		replay = RTA_DATA(tb[XFRMA_REPLAY_ESN_VAL]);
+		replay = (struct xfrm_replay_state_esn *)RTA_DATA(tb[XFRMA_REPLAY_ESN_VAL]);
 		if (prefix)
 			fputs(prefix, fp);
 		fprintf(fp, " seq-hi 0x%x, seq 0x%x, oseq-hi 0x%0x, oseq 0x%0x",
@@ -872,56 +867,33 @@
 		}
 		fprintf(fp, "%s", _SL_);
 	}
-	if (tb[XFRMA_OFFLOAD_DEV]) {
-		struct xfrm_user_offload *xuo;
-
-		if (prefix)
-			fputs(prefix, fp);
-		fprintf(fp, "crypto offload parameters: ");
-
-		if (RTA_PAYLOAD(tb[XFRMA_OFFLOAD_DEV]) < sizeof(*xuo)) {
-			fprintf(fp, "(ERROR truncated)");
-			fprintf(fp, "%s", _SL_);
-			return;
-		}
-
-		xuo = (struct xfrm_user_offload *)
-			RTA_DATA(tb[XFRMA_OFFLOAD_DEV]);
-		fprintf(fp, "dev %s dir %s", ll_index_to_name(xuo->ifindex),
-			(xuo->flags & XFRM_OFFLOAD_INBOUND) ? "in" : "out");
-		fprintf(fp, "%s", _SL_);
-	}
-	if (tb[XFRMA_IF_ID]) {
-		__u32 if_id = rta_getattr_u32(tb[XFRMA_IF_ID]);
-
-		if (prefix)
-			fputs(prefix, fp);
-		fprintf(fp, "if_id %#x", if_id);
-		fprintf(fp, "%s", _SL_);
-	}
 }
 
 static int xfrm_selector_iszero(struct xfrm_selector *s)
 {
-	struct xfrm_selector s0 = {};
+	struct xfrm_selector s0;
+
+	memset(&s0, 0, sizeof(s0));
 
 	return (memcmp(&s0, s, sizeof(s0)) == 0);
 }
 
 void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
 			    struct rtattr *tb[], FILE *fp, const char *prefix,
-			    const char *title, bool nokeys)
+			    const char *title)
 {
-	char buf[STRBUF_SIZE] = {};
+	char buf[STRBUF_SIZE];
 	int force_spi = xfrm_xfrmproto_is_ipsec(xsinfo->id.proto);
 
+	memset(buf, '\0', sizeof(buf));
+
 	xfrm_id_info_print(&xsinfo->saddr, &xsinfo->id, xsinfo->mode,
 			   xsinfo->reqid, xsinfo->family, force_spi, fp,
 			   prefix, title);
 
 	if (prefix)
-		strlcat(buf, prefix, sizeof(buf));
-	strlcat(buf, "\t", sizeof(buf));
+		STRBUF_CAT(buf, prefix);
+	STRBUF_CAT(buf, "\t");
 
 	fputs(buf, fp);
 	fprintf(fp, "replay-window %u ", xsinfo->replay_window);
@@ -943,7 +915,7 @@
 			fprintf(fp, "%x", flags);
 	}
 	if (show_stats > 0 && tb[XFRMA_SA_EXTRA_FLAGS]) {
-		__u32 extra_flags = rta_getattr_u32(tb[XFRMA_SA_EXTRA_FLAGS]);
+		__u32 extra_flags = *(__u32 *)RTA_DATA(tb[XFRMA_SA_EXTRA_FLAGS]);
 
 		fprintf(fp, "extra_flag ");
 		XFRM_FLAG_PRINT(fp, extra_flags,
@@ -956,13 +928,13 @@
 		fprintf(fp, " (0x%s)", strxf_mask8(xsinfo->flags));
 	fprintf(fp, "%s", _SL_);
 
-	xfrm_xfrma_print(tb, xsinfo->family, fp, buf, nokeys);
+	xfrm_xfrma_print(tb, xsinfo->family, fp, buf);
 
 	if (!xfrm_selector_iszero(&xsinfo->sel)) {
 		char sbuf[STRBUF_SIZE];
 
 		memcpy(sbuf, buf, sizeof(sbuf));
-		strlcat(sbuf, "sel ", sizeof(sbuf));
+		STRBUF_CAT(sbuf, "sel ");
 
 		xfrm_selector_print(&xsinfo->sel, xsinfo->family, fp, sbuf);
 	}
@@ -980,7 +952,7 @@
 		if (RTA_PAYLOAD(tb[XFRMA_SEC_CTX]) < sizeof(*sctx))
 			fprintf(fp, "(ERROR truncated)");
 
-		sctx = RTA_DATA(tb[XFRMA_SEC_CTX]);
+		sctx = (struct xfrm_user_sec_ctx *)RTA_DATA(tb[XFRMA_SEC_CTX]);
 
 		fprintf(fp, "%s %s", (char *)(sctx + 1), _SL_);
 	}
@@ -991,7 +963,9 @@
 			    struct rtattr *tb[], FILE *fp, const char *prefix,
 			    const char *title)
 {
-	char buf[STRBUF_SIZE] = {};
+	char buf[STRBUF_SIZE];
+
+	memset(buf, '\0', sizeof(buf));
 
 	xfrm_selector_print(&xpinfo->sel, preferred_family, fp, title);
 
@@ -1003,15 +977,15 @@
 		if (RTA_PAYLOAD(tb[XFRMA_SEC_CTX]) < sizeof(*sctx))
 			fprintf(fp, "(ERROR truncated)");
 
-		sctx = RTA_DATA(tb[XFRMA_SEC_CTX]);
+		sctx = (struct xfrm_user_sec_ctx *)RTA_DATA(tb[XFRMA_SEC_CTX]);
 
 		fprintf(fp, "%s ", (char *)(sctx + 1));
 		fprintf(fp, "%s", _SL_);
 	}
 
 	if (prefix)
-		strlcat(buf, prefix, sizeof(buf));
-	strlcat(buf, "\t", sizeof(buf));
+		STRBUF_CAT(buf, prefix);
+	STRBUF_CAT(buf, "\t");
 
 	fputs(buf, fp);
 	if (xpinfo->dir >= XFRM_POLICY_MAX) {
@@ -1061,7 +1035,7 @@
 		if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
 			fprintf(fp, "(ERROR truncated)");
 
-		upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
+		upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
 		fprintf(fp, "%s ", strxf_ptype(upt->type));
 	}
 
@@ -1084,7 +1058,7 @@
 	if (show_stats > 0)
 		xfrm_lifetime_print(&xpinfo->lft, &xpinfo->curlft, fp, buf);
 
-	xfrm_xfrma_print(tb, xpinfo->sel.family, fp, buf, false);
+	xfrm_xfrma_print(tb, xpinfo->sel.family, fp, buf);
 }
 
 int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
@@ -1092,8 +1066,11 @@
 {
 	int argc = *argcp;
 	char **argv = *argvp;
-	inet_prefix dst = {};
-	inet_prefix src = {};
+	inet_prefix dst;
+	inet_prefix src;
+
+	memset(&dst, 0, sizeof(dst));
+	memset(&src, 0, sizeof(src));
 
 	while (1) {
 		if (strcmp(*argv, "src") == 0) {
@@ -1136,10 +1113,15 @@
 			filter.id_proto_mask = XFRM_FILTER_MASK_FULL;
 
 		} else if (strcmp(*argv, "spi") == 0) {
+			__u32 spi;
+
 			NEXT_ARG();
-			if (get_be32(&id->spi, *argv, 0))
+			if (get_u32(&spi, *argv, 0))
 				invarg("SPI value is invalid", *argv);
 
+			spi = htonl(spi);
+			id->spi = spi;
+
 			filter.id_spi_mask = XFRM_FILTER_MASK_FULL;
 
 		} else {
@@ -1158,11 +1140,11 @@
 	if (id->spi && id->proto) {
 		if (xfrm_xfrmproto_is_ro(id->proto)) {
 			fprintf(stderr, "\"spi\" is invalid with XFRM-PROTO value \"%s\"\n",
-				strxf_xfrmproto(id->proto));
+			        strxf_xfrmproto(id->proto));
 			exit(1);
 		} else if (id->proto == IPPROTO_COMP && ntohl(id->spi) >= 0x10000) {
 			fprintf(stderr, "SPI value is too large with XFRM-PROTO value \"%s\"\n",
-				strxf_xfrmproto(id->proto));
+			        strxf_xfrmproto(id->proto));
 			exit(1);
 		}
 	}
@@ -1256,7 +1238,6 @@
 				upspec = 0;
 			else {
 				struct protoent *pp;
-
 				pp = getprotobyname(*argv);
 				if (pp)
 					upspec = pp->p_proto;
@@ -1274,8 +1255,9 @@
 
 			NEXT_ARG();
 
-			if (get_be16(&sel->sport, *argv, 0))
+			if (get_u16(&sel->sport, *argv, 0))
 				invarg("value after \"sport\" is invalid", *argv);
+			sel->sport = htons(sel->sport);
 			if (sel->sport)
 				sel->sport_mask = ~((__u16)0);
 
@@ -1286,8 +1268,9 @@
 
 			NEXT_ARG();
 
-			if (get_be16(&sel->dport, *argv, 0))
+			if (get_u16(&sel->dport, *argv, 0))
 				invarg("value after \"dport\" is invalid", *argv);
+			sel->dport = htons(sel->dport);
 			if (sel->dport)
 				sel->dport_mask = ~((__u16)0);
 
@@ -1321,7 +1304,7 @@
 			filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
 
 		} else if (strcmp(*argv, "key") == 0) {
-			unsigned int uval;
+			unsigned uval;
 
 			grekey = *argv;
 
@@ -1330,7 +1313,7 @@
 			if (strchr(*argv, '.'))
 				uval = htonl(get_addr32(*argv));
 			else {
-				if (get_unsigned(&uval, *argv, 0) < 0) {
+				if (get_unsigned(&uval, *argv, 0)<0) {
 					fprintf(stderr, "value after \"key\" is invalid\n");
 					exit(-1);
 				}
@@ -1398,10 +1381,13 @@
 {
 	int argc = *argcp;
 	char **argv = *argvp;
-	inet_prefix dst = {};
-	inet_prefix src = {};
+	inet_prefix dst;
+	inet_prefix src;
 	char *upspecp = NULL;
 
+	memset(&dst, 0, sizeof(dst));
+	memset(&src, 0, sizeof(src));
+
 	while (1) {
 		if (strcmp(*argv, "src") == 0) {
 			NEXT_ARG();
diff --git a/ip/link_gre.c b/ip/link_gre.c
index 15beb73..c85741f 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -23,100 +23,81 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-static void gre_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
+static void print_usage(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... %-9s	[ remote ADDR ]\n"
-		"			[ local ADDR ]\n"
-		"			[ [no][i|o]seq ]\n"
-		"			[ [i|o]key KEY | no[i|o]key ]\n"
-		"			[ [no][i|o]csum ]\n"
-		"			[ ttl TTL ]\n"
-		"			[ tos TOS ]\n"
-		"			[ [no]pmtudisc ]\n"
-		"			[ [no]ignore-df ]\n"
-		"			[ dev PHYS_DEV ]\n"
-		"			[ fwmark MARK ]\n"
-		"			[ external ]\n"
-		"			[ noencap ]\n"
-		"			[ encap { fou | gue | none } ]\n"
-		"			[ encap-sport PORT ]\n"
-		"			[ encap-dport PORT ]\n"
-		"			[ [no]encap-csum ]\n"
-		"			[ [no]encap-csum6 ]\n"
-		"			[ [no]encap-remcsum ]\n"
-		"			[ erspan_ver version ]\n"
-		"			[ erspan IDX ]\n"
-		"			[ erspan_dir { ingress | egress } ]\n"
-		"			[ erspan_hwid hwid ]\n"
-		"\n"
-		"Where:	ADDR := { IP_ADDRESS | any }\n"
-		"	TOS  := { NUMBER | inherit }\n"
-		"	TTL  := { 1..255 | inherit }\n"
-		"	KEY  := { DOTTED_QUAD | NUMBER }\n"
-		"	MARK := { 0x0..0xffffffff }\n",
-		lu->id);
+	fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
+	fprintf(f, "          type { gre | gretap } [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(f, "          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
+	fprintf(f, "          [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n");
+	fprintf(f, "          [ noencap ] [ encap { fou | gue | none } ]\n");
+	fprintf(f, "          [ encap-sport PORT ] [ encap-dport PORT ]\n");
+	fprintf(f, "          [ [no]encap-csum ] [ [no]encap-csum6 ] [ [no]encap-remcsum ]\n");
+	fprintf(f, "\n");
+	fprintf(f, "Where: NAME := STRING\n");
+	fprintf(f, "       ADDR := { IP_ADDRESS | any }\n");
+	fprintf(f, "       TOS  := { NUMBER | inherit }\n");
+	fprintf(f, "       TTL  := { 1..255 | inherit }\n");
+	fprintf(f, "       KEY  := { DOTTED_QUAD | NUMBER }\n");
+}
+
+static void usage(void) __attribute__((noreturn));
+static void usage(void)
+{
+	print_usage(stderr);
+	exit(-1);
 }
 
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg i;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-		.i.ifi_index = ifi->ifi_index,
-	};
-	struct nlmsghdr *answer;
+		char buf[16384];
+	} req;
+	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct rtattr *greinfo[IFLA_GRE_MAX + 1];
-	int len;
 	__u16 iflags = 0;
 	__u16 oflags = 0;
-	__be32 ikey = 0;
-	__be32 okey = 0;
-	inet_prefix saddr, daddr;
+	unsigned ikey = 0;
+	unsigned okey = 0;
+	unsigned saddr = 0;
+	unsigned daddr = 0;
+	unsigned link = 0;
 	__u8 pmtudisc = 1;
-	__u8 ignore_df = 0;
-	__u8 tos = 0;
 	__u8 ttl = 0;
-	__u32 link = 0;
+	__u8 tos = 0;
+	int len;
 	__u16 encaptype = 0;
 	__u16 encapflags = 0;
 	__u16 encapsport = 0;
 	__u16 encapdport = 0;
 	__u8 metadata = 0;
-	__u32 fwmark = 0;
-	__u32 erspan_idx = 0;
-	__u8 erspan_ver = 0;
-	__u8 erspan_dir = 0;
-	__u16 erspan_hwid = 0;
-
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
 
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-		const struct rtattr *rta;
+		memset(&req, 0, sizeof(req));
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETLINK;
+		req.i.ifi_family = preferred_family;
+		req.i.ifi_index = ifi->ifi_index;
+
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
 get_failed:
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
 		}
 
-		len = answer->nlmsg_len;
+		len = req.n.nlmsg_len;
 		len -= NLMSG_LENGTH(sizeof(*ifi));
 		if (len < 0)
 			goto get_failed;
 
-		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
+		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
 
 		if (!tb[IFLA_LINKINFO])
 			goto get_failed;
@@ -129,14 +110,6 @@
 		parse_rtattr_nested(greinfo, IFLA_GRE_MAX,
 				    linkinfo[IFLA_INFO_DATA]);
 
-		rta = greinfo[IFLA_GRE_LOCAL];
-		if (rta && get_addr_rta(&saddr, rta, AF_INET))
-			goto get_failed;
-
-		rta = greinfo[IFLA_GRE_REMOTE];
-		if (rta && get_addr_rta(&daddr, rta, AF_INET))
-			goto get_failed;
-
 		if (greinfo[IFLA_GRE_IKEY])
 			ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
 
@@ -149,132 +122,133 @@
 		if (greinfo[IFLA_GRE_OFLAGS])
 			oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
 
+		if (greinfo[IFLA_GRE_LOCAL])
+			saddr = rta_getattr_u32(greinfo[IFLA_GRE_LOCAL]);
+
+		if (greinfo[IFLA_GRE_REMOTE])
+			daddr = rta_getattr_u32(greinfo[IFLA_GRE_REMOTE]);
+
 		if (greinfo[IFLA_GRE_PMTUDISC])
 			pmtudisc = rta_getattr_u8(
 				greinfo[IFLA_GRE_PMTUDISC]);
 
-		if (greinfo[IFLA_GRE_IGNORE_DF])
-			ignore_df =
-				!!rta_getattr_u8(greinfo[IFLA_GRE_IGNORE_DF]);
+		if (greinfo[IFLA_GRE_TTL])
+			ttl = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
 
 		if (greinfo[IFLA_GRE_TOS])
 			tos = rta_getattr_u8(greinfo[IFLA_GRE_TOS]);
 
-		if (greinfo[IFLA_GRE_TTL])
-			ttl = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
-
 		if (greinfo[IFLA_GRE_LINK])
-			link = rta_getattr_u32(greinfo[IFLA_GRE_LINK]);
+			link = rta_getattr_u8(greinfo[IFLA_GRE_LINK]);
 
 		if (greinfo[IFLA_GRE_ENCAP_TYPE])
 			encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
-
 		if (greinfo[IFLA_GRE_ENCAP_FLAGS])
 			encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
-
 		if (greinfo[IFLA_GRE_ENCAP_SPORT])
 			encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
-
 		if (greinfo[IFLA_GRE_ENCAP_DPORT])
 			encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
 
 		if (greinfo[IFLA_GRE_COLLECT_METADATA])
 			metadata = 1;
-
-		if (greinfo[IFLA_GRE_FWMARK])
-			fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_INDEX])
-			erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_VER])
-			erspan_ver = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_VER]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_DIR])
-			erspan_dir = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_DIR]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_HWID])
-			erspan_hwid = rta_getattr_u16(greinfo[IFLA_GRE_ERSPAN_HWID]);
-
-		free(answer);
 	}
 
 	while (argc > 0) {
 		if (!matches(*argv, "key")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			iflags |= GRE_KEY;
 			oflags |= GRE_KEY;
-			ikey = okey = tnl_parse_key("key", *argv);
-		} else if (!matches(*argv, "nokey")) {
-			iflags &= ~GRE_KEY;
-			oflags &= ~GRE_KEY;
-			ikey = okey = 0;
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr,
+						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+
+			ikey = okey = uval;
 		} else if (!matches(*argv, "ikey")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			iflags |= GRE_KEY;
-			ikey = tnl_parse_key("ikey", *argv);
-		} else if (!matches(*argv, "noikey")) {
-			iflags &= ~GRE_KEY;
-			ikey = 0;
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0)<0) {
+					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			ikey = uval;
 		} else if (!matches(*argv, "okey")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			oflags |= GRE_KEY;
-			okey = tnl_parse_key("okey", *argv);
-		} else if (!matches(*argv, "nookey")) {
-			oflags &= ~GRE_KEY;
-			okey = 0;
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0)<0) {
+					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			okey = uval;
 		} else if (!matches(*argv, "seq")) {
 			iflags |= GRE_SEQ;
 			oflags |= GRE_SEQ;
-		} else if (!matches(*argv, "noseq")) {
-			iflags &= ~GRE_SEQ;
-			oflags &= ~GRE_SEQ;
 		} else if (!matches(*argv, "iseq")) {
 			iflags |= GRE_SEQ;
-		} else if (!matches(*argv, "noiseq")) {
-			iflags &= ~GRE_SEQ;
 		} else if (!matches(*argv, "oseq")) {
 			oflags |= GRE_SEQ;
-		} else if (!matches(*argv, "nooseq")) {
-			oflags &= ~GRE_SEQ;
 		} else if (!matches(*argv, "csum")) {
 			iflags |= GRE_CSUM;
 			oflags |= GRE_CSUM;
-		} else if (!matches(*argv, "nocsum")) {
-			iflags &= ~GRE_CSUM;
-			oflags &= ~GRE_CSUM;
 		} else if (!matches(*argv, "icsum")) {
 			iflags |= GRE_CSUM;
-		} else if (!matches(*argv, "noicsum")) {
-			iflags &= ~GRE_CSUM;
 		} else if (!matches(*argv, "ocsum")) {
 			oflags |= GRE_CSUM;
-		} else if (!matches(*argv, "noocsum")) {
-			oflags &= ~GRE_CSUM;
 		} else if (!matches(*argv, "nopmtudisc")) {
 			pmtudisc = 0;
 		} else if (!matches(*argv, "pmtudisc")) {
 			pmtudisc = 1;
 		} else if (!matches(*argv, "remote")) {
 			NEXT_ARG();
-			get_addr(&daddr, *argv, AF_INET);
+			if (strcmp(*argv, "any"))
+				daddr = get_addr32(*argv);
 		} else if (!matches(*argv, "local")) {
 			NEXT_ARG();
-			get_addr(&saddr, *argv, AF_INET);
+			if (strcmp(*argv, "any"))
+				saddr = get_addr32(*argv);
 		} else if (!matches(*argv, "dev")) {
 			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
+			link = if_nametoindex(*argv);
+			if (link == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n",
+					*argv);
+				exit(-1);
+			}
 		} else if (!matches(*argv, "ttl") ||
-			   !matches(*argv, "hoplimit") ||
-			   !matches(*argv, "hlim")) {
+			   !matches(*argv, "hoplimit")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			if (strcmp(*argv, "inherit") != 0) {
-				if (get_u8(&ttl, *argv, 0))
+				if (get_unsigned(&uval, *argv, 0))
 					invarg("invalid TTL\n", *argv);
-			} else
-				ttl = 0;
+				if (uval > 255)
+					invarg("TTL must be <= 255\n", *argv);
+				ttl = uval;
+			}
 		} else if (!matches(*argv, "tos") ||
 			   !matches(*argv, "tclass") ||
 			   !matches(*argv, "dsfield")) {
@@ -316,162 +290,111 @@
 		} else if (strcmp(*argv, "encap-udp6-csum") == 0) {
 			encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
 		} else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
+			encapflags |= ~TUNNEL_ENCAP_FLAG_CSUM6;
 		} else if (strcmp(*argv, "encap-remcsum") == 0) {
 			encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
 		} else if (strcmp(*argv, "noencap-remcsum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
+			encapflags |= ~TUNNEL_ENCAP_FLAG_REMCSUM;
 		} else if (strcmp(*argv, "external") == 0) {
 			metadata = 1;
-		} else if (strcmp(*argv, "ignore-df") == 0) {
-			ignore_df = 1;
-		} else if (strcmp(*argv, "noignore-df") == 0) {
-			/*
-			 *only the lsb is significant, use 2 for presence
-			 */
-			ignore_df = 2;
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			NEXT_ARG();
-			if (get_u32(&fwmark, *argv, 0))
-				invarg("invalid fwmark\n", *argv);
-		} else if (strcmp(*argv, "erspan") == 0) {
-			NEXT_ARG();
-			if (get_u32(&erspan_idx, *argv, 0))
-				invarg("invalid erspan index\n", *argv);
-			if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0)
-				invarg("erspan index must be > 0 and <= 20-bit\n", *argv);
-		} else if (strcmp(*argv, "erspan_ver") == 0) {
-			NEXT_ARG();
-			if (get_u8(&erspan_ver, *argv, 0))
-				invarg("invalid erspan version\n", *argv);
-			if (erspan_ver != 1 && erspan_ver != 2)
-				invarg("erspan version must be 1 or 2\n", *argv);
-		} else if (strcmp(*argv, "erspan_dir") == 0) {
-			NEXT_ARG();
-			if (matches(*argv, "ingress") == 0)
-				erspan_dir = 0;
-			else if (matches(*argv, "egress") == 0)
-				erspan_dir = 1;
-			else
-				invarg("Invalid erspan direction.", *argv);
-		} else if (strcmp(*argv, "erspan_hwid") == 0) {
-			NEXT_ARG();
-			if (get_u16(&erspan_hwid, *argv, 0))
-				invarg("invalid erspan hwid\n", *argv);
-		} else {
-			gre_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
+		} else
+			usage();
 		argc--; argv++;
 	}
 
-	if (is_addrtype_inet_multi(&daddr)) {
-		if (!ikey) {
-			ikey = daddr.data[0];
-			iflags |= GRE_KEY;
-		}
-		if (!okey) {
-			okey = daddr.data[0];
-			oflags |= GRE_KEY;
-		}
-		if (!is_addrtype_inet_not_unspec(&saddr)) {
-			fprintf(stderr,
-				"A broadcast tunnel requires a source address.\n");
-			return -1;
-		}
+	if (!ikey && IN_MULTICAST(ntohl(daddr))) {
+		ikey = daddr;
+		iflags |= GRE_KEY;
 	}
-
-	if (metadata) {
-		addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0);
-		return 0;
+	if (!okey && IN_MULTICAST(ntohl(daddr))) {
+		okey = daddr;
+		oflags |= GRE_KEY;
+	}
+	if (IN_MULTICAST(ntohl(daddr)) && !saddr) {
+		fprintf(stderr, "A broadcast tunnel requires a source address.\n");
+		return -1;
 	}
 
 	addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
 	addattr32(n, 1024, IFLA_GRE_OKEY, okey);
 	addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
 	addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
-	if (is_addrtype_inet_not_unspec(&saddr))
-		addattr_l(n, 1024, IFLA_GRE_LOCAL, saddr.data, saddr.bytelen);
-	if (is_addrtype_inet_not_unspec(&daddr))
-		addattr_l(n, 1024, IFLA_GRE_REMOTE, daddr.data, daddr.bytelen);
+	addattr_l(n, 1024, IFLA_GRE_LOCAL, &saddr, 4);
+	addattr_l(n, 1024, IFLA_GRE_REMOTE, &daddr, 4);
 	addattr_l(n, 1024, IFLA_GRE_PMTUDISC, &pmtudisc, 1);
-	if (ignore_df)
-		addattr8(n, 1024, IFLA_GRE_IGNORE_DF, ignore_df & 1);
-	addattr_l(n, 1024, IFLA_GRE_TOS, &tos, 1);
 	if (link)
 		addattr32(n, 1024, IFLA_GRE_LINK, link);
 	addattr_l(n, 1024, IFLA_GRE_TTL, &ttl, 1);
-	addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark);
-	if (erspan_ver) {
-		addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver);
-		if (erspan_ver == 1 && erspan_idx != 0) {
-			addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx);
-		} else if (erspan_ver == 2) {
-			addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir);
-			addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid);
-		}
-	}
+	addattr_l(n, 1024, IFLA_GRE_TOS, &tos, 1);
+
 	addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
 	addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
 	addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
 	addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
+	if (metadata)
+		addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0);
 
 	return 0;
 }
 
 static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	char s1[1024];
 	char s2[64];
-	__u16 iflags = 0;
-	__u16 oflags = 0;
-	__u8 ttl = 0;
-	__u8 tos = 0;
+	const char *local = "any";
+	const char *remote = "any";
+	unsigned iflags = 0;
+	unsigned oflags = 0;
 
 	if (!tb)
 		return;
 
-	if (tb[IFLA_GRE_COLLECT_METADATA]) {
-		print_bool(PRINT_ANY, "external", "external ", true);
-		return;
+	if (tb[IFLA_GRE_REMOTE]) {
+		unsigned addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
+
+		if (addr)
+			remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
 	}
 
-	tnl_print_endpoint("remote", tb[IFLA_GRE_REMOTE], AF_INET);
-	tnl_print_endpoint("local", tb[IFLA_GRE_LOCAL], AF_INET);
+	fprintf(f, "remote %s ", remote);
 
-	if (tb[IFLA_GRE_LINK]) {
-		__u32 link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
+	if (tb[IFLA_GRE_LOCAL]) {
+		unsigned addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
 
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
+		if (addr)
+			local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
 	}
 
-	if (tb[IFLA_GRE_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
+	fprintf(f, "local %s ", local);
+
+	if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
+		unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
+		const char *n = if_indextoname(link, s2);
+
+		if (n)
+			fprintf(f, "dev %s ", n);
+		else
+			fprintf(f, "dev %u ", link);
+	}
+
+	if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
+		fprintf(f, "ttl %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
 	else
-		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+		fprintf(f, "ttl inherit ");
 
-	if (tb[IFLA_GRE_TOS])
-		tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
-	if (tos) {
-		if (is_json_context() || tos != 1)
-			print_0xhex(PRINT_ANY, "tos", "tos %#llx ", tos);
+	if (tb[IFLA_GRE_TOS] && rta_getattr_u8(tb[IFLA_GRE_TOS])) {
+		int tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
+
+		fputs("tos ", f);
+		if (tos == 1)
+			fputs("inherit ", f);
 		else
-			print_string(PRINT_FP, NULL, "tos %s ", "inherit");
+			fprintf(f, "0x%x ", tos);
 	}
 
-	if (tb[IFLA_GRE_PMTUDISC]) {
-		if (!rta_getattr_u8(tb[IFLA_GRE_PMTUDISC]))
-			print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false);
-		else
-			print_bool(PRINT_JSON, "pmtudisc", NULL, true);
-	}
-
-	if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF]))
-		print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true);
+	if (tb[IFLA_GRE_PMTUDISC] &&
+	    !rta_getattr_u8(tb[IFLA_GRE_PMTUDISC]))
+		fputs("nopmtudisc ", f);
 
 	if (tb[IFLA_GRE_IFLAGS])
 		iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
@@ -481,69 +404,74 @@
 
 	if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
 		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
-		print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
+		fprintf(f, "ikey %s ", s2);
 	}
 
 	if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
 		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
-		print_string(PRINT_ANY, "okey", "okey %s ", s2);
+		fprintf(f, "okey %s ", s2);
 	}
 
 	if (iflags & GRE_SEQ)
-		print_bool(PRINT_ANY, "iseq", "iseq ", true);
+		fputs("iseq ", f);
 	if (oflags & GRE_SEQ)
-		print_bool(PRINT_ANY, "oseq", "oseq ", true);
+		fputs("oseq ", f);
 	if (iflags & GRE_CSUM)
-		print_bool(PRINT_ANY, "icsum", "icsum ", true);
+		fputs("icsum ", f);
 	if (oflags & GRE_CSUM)
-		print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
+		fputs("ocsum ", f);
 
-	if (tb[IFLA_GRE_FWMARK]) {
-		__u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
+	if (tb[IFLA_GRE_COLLECT_METADATA])
+		fputs("external ", f);
 
-		if (fwmark) {
-			print_0xhex(PRINT_ANY,
-				    "fwmark", "fwmark %#llx ", fwmark);
+	if (tb[IFLA_GRE_ENCAP_TYPE] &&
+	    *(__u16 *)RTA_DATA(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
+		__u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
+		__u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
+		__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
+		__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
+
+		fputs("encap ", f);
+		switch (type) {
+		case TUNNEL_ENCAP_FOU:
+			fputs("fou ", f);
+			break;
+		case TUNNEL_ENCAP_GUE:
+			fputs("gue ", f);
+			break;
+		default:
+			fputs("unknown ", f);
+			break;
 		}
-	}
 
-	if (tb[IFLA_GRE_ERSPAN_INDEX]) {
-		__u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]);
-
-		print_uint(PRINT_ANY,
-			   "erspan_index", "erspan_index %u ", erspan_idx);
-	}
-
-	if (tb[IFLA_GRE_ERSPAN_VER]) {
-		__u8 erspan_ver = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_VER]);
-
-		print_uint(PRINT_ANY,
-			   "erspan_ver", "erspan_ver %u ", erspan_ver);
-	}
-
-	if (tb[IFLA_GRE_ERSPAN_DIR]) {
-		__u8 erspan_dir = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_DIR]);
-
-		if (erspan_dir == 0)
-			print_string(PRINT_ANY, "erspan_dir",
-				     "erspan_dir ingress ", NULL);
+		if (sport == 0)
+			fputs("encap-sport auto ", f);
 		else
-			print_string(PRINT_ANY, "erspan_dir",
-				     "erspan_dir egress ", NULL);
+			fprintf(f, "encap-sport %u", ntohs(sport));
+
+		fprintf(f, "encap-dport %u ", ntohs(dport));
+
+		if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+			fputs("encap-csum ", f);
+		else
+			fputs("noencap-csum ", f);
+
+		if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+			fputs("encap-csum6 ", f);
+		else
+			fputs("noencap-csum6 ", f);
+
+		if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+			fputs("encap-remcsum ", f);
+		else
+			fputs("noencap-remcsum ", f);
 	}
+}
 
-	if (tb[IFLA_GRE_ERSPAN_HWID]) {
-		__u16 erspan_hwid = rta_getattr_u16(tb[IFLA_GRE_ERSPAN_HWID]);
-
-		print_0xhex(PRINT_ANY,
-			    "erspan_hwid", "erspan_hwid %#llx ", erspan_hwid);
-	}
-
-	tnl_print_encap(tb,
-			IFLA_GRE_ENCAP_TYPE,
-			IFLA_GRE_ENCAP_FLAGS,
-			IFLA_GRE_ENCAP_SPORT,
-			IFLA_GRE_ENCAP_DPORT);
+static void gre_print_help(struct link_util *lu, int argc, char **argv,
+	FILE *f)
+{
+	print_usage(f);
 }
 
 struct link_util gre_link_util = {
@@ -561,11 +489,3 @@
 	.print_opt = gre_print_opt,
 	.print_help = gre_print_help,
 };
-
-struct link_util erspan_link_util = {
-	.id = "erspan",
-	.maxattr = IFLA_GRE_MAX,
-	.parse_opt = gre_parse_opt,
-	.print_opt = gre_print_opt,
-	.print_help = gre_print_help,
-};
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 9d1741b..e00ea09 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -30,105 +30,80 @@
 
 #define DEFAULT_TNL_HOP_LIMIT	(64)
 
-static void gre_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
+static void print_usage(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... %-9s	[ remote ADDR ]\n"
-		"			[ local ADDR ]\n"
-		"			[ [no][i|o]seq ]\n"
-		"			[ [i|o]key KEY | no[i|o]key ]\n"
-		"			[ [no][i|o]csum ]\n"
-		"			[ hoplimit TTL ]\n"
-		"			[ encaplimit ELIM ]\n"
-		"			[ tclass TCLASS ]\n"
-		"			[ flowlabel FLOWLABEL ]\n"
-		"			[ dscp inherit ]\n"
-		"			[ dev PHYS_DEV ]\n"
-		"			[ fwmark MARK ]\n"
-		"			[ [no]allow-localremote ]\n"
-		"			[ external ]\n"
-		"			[ noencap ]\n"
-		"			[ encap { fou | gue | none } ]\n"
-		"			[ encap-sport PORT ]\n"
-		"			[ encap-dport PORT ]\n"
-		"			[ [no]encap-csum ]\n"
-		"			[ [no]encap-csum6 ]\n"
-		"			[ [no]encap-remcsum ]\n"
-		"			[ erspan_ver version ]\n"
-		"			[ erspan IDX ]\n"
-		"			[ erspan_dir { ingress | egress } ]\n"
-		"			[ erspan_hwid hwid ]\n"
-		"\n"
-		"Where:	ADDR	  := IPV6_ADDRESS\n"
-		"	TTL	  := { 0..255 } (default=%d)\n"
-		"	KEY	  := { DOTTED_QUAD | NUMBER }\n"
-		"	ELIM	  := { none | 0..255 }(default=%d)\n"
-		"	TCLASS	  := { 0x0..0xff | inherit }\n"
-		"	FLOWLABEL := { 0x0..0xfffff | inherit }\n"
-		"	MARK	  := { 0x0..0xffffffff | inherit }\n",
-		lu->id,
-		DEFAULT_TNL_HOP_LIMIT, IPV6_DEFAULT_TNL_ENCAP_LIMIT);
+	fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
+	fprintf(f, "          type { ip6gre | ip6gretap } [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(f, "          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
+	fprintf(f, "          [ hoplimit TTL ] [ encaplimit ELIM ]\n");
+	fprintf(f, "          [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
+	fprintf(f, "          [ dscp inherit ] [ dev PHYS_DEV ]\n");
+	fprintf(f, "\n");
+	fprintf(f, "Where: NAME      := STRING\n");
+	fprintf(f, "       ADDR      := IPV6_ADDRESS\n");
+	fprintf(f, "       TTL       := { 0..255 } (default=%d)\n",
+		DEFAULT_TNL_HOP_LIMIT);
+	fprintf(f, "       KEY       := { DOTTED_QUAD | NUMBER }\n");
+	fprintf(f, "       ELIM      := { none | 0..255 }(default=%d)\n",
+		IPV6_DEFAULT_TNL_ENCAP_LIMIT);
+	fprintf(f, "       TCLASS    := { 0x0..0xff | inherit }\n");
+	fprintf(f, "       FLOWLABEL := { 0x0..0xfffff | inherit }\n");
+}
+
+static void usage(void) __attribute__((noreturn));
+static void usage(void)
+{
+	print_usage(stderr);
+	exit(-1);
 }
 
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg i;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-		.i.ifi_index = ifi->ifi_index,
-	};
-	struct nlmsghdr *answer;
+		char buf[1024];
+	} req;
+	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct rtattr *greinfo[IFLA_GRE_MAX + 1];
-	int len;
 	__u16 iflags = 0;
 	__u16 oflags = 0;
-	__be32 ikey = 0;
-	__be32 okey = 0;
-	inet_prefix saddr, daddr;
+	unsigned ikey = 0;
+	unsigned okey = 0;
+	struct in6_addr raddr = IN6ADDR_ANY_INIT;
+	struct in6_addr laddr = IN6ADDR_ANY_INIT;
+	unsigned link = 0;
+	unsigned flowinfo = 0;
+	unsigned flags = 0;
 	__u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
 	__u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
-	__u32 flowinfo = 0;
-	__u32 flags = 0;
-	__u32 link = 0;
-	__u16 encaptype = 0;
-	__u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
-	__u16 encapsport = 0;
-	__u16 encapdport = 0;
-	__u8 metadata = 0;
-	__u32 fwmark = 0;
-	__u32 erspan_idx = 0;
-	__u8 erspan_ver = 0;
-	__u8 erspan_dir = 0;
-	__u16 erspan_hwid = 0;
-
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
+	int len;
 
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-		const struct rtattr *rta;
+		memset(&req, 0, sizeof(req));
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETLINK;
+		req.i.ifi_family = preferred_family;
+		req.i.ifi_index = ifi->ifi_index;
+
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
 get_failed:
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
 		}
 
-		len = answer->nlmsg_len;
+		len = req.n.nlmsg_len;
 		len -= NLMSG_LENGTH(sizeof(*ifi));
 		if (len < 0)
 			goto get_failed;
 
-		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
+		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
 
 		if (!tb[IFLA_LINKINFO])
 			goto get_failed;
@@ -141,14 +116,6 @@
 		parse_rtattr_nested(greinfo, IFLA_GRE_MAX,
 				    linkinfo[IFLA_INFO_DATA]);
 
-		rta = greinfo[IFLA_GRE_LOCAL];
-		if (rta && get_addr_rta(&saddr, rta, AF_INET6))
-			goto get_failed;
-
-		rta = greinfo[IFLA_GRE_REMOTE];
-		if (rta && get_addr_rta(&daddr, rta, AF_INET6))
-			goto get_failed;
-
 		if (greinfo[IFLA_GRE_IKEY])
 			ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
 
@@ -161,6 +128,12 @@
 		if (greinfo[IFLA_GRE_OFLAGS])
 			oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
 
+		if (greinfo[IFLA_GRE_LOCAL])
+			memcpy(&laddr, RTA_DATA(greinfo[IFLA_GRE_LOCAL]), sizeof(laddr));
+
+		if (greinfo[IFLA_GRE_REMOTE])
+			memcpy(&raddr, RTA_DATA(greinfo[IFLA_GRE_REMOTE]), sizeof(raddr));
+
 		if (greinfo[IFLA_GRE_TTL])
 			hop_limit = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
 
@@ -175,119 +148,105 @@
 
 		if (greinfo[IFLA_GRE_FLAGS])
 			flags = rta_getattr_u32(greinfo[IFLA_GRE_FLAGS]);
-
-		if (greinfo[IFLA_GRE_ENCAP_TYPE])
-			encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
-
-		if (greinfo[IFLA_GRE_ENCAP_FLAGS])
-			encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
-
-		if (greinfo[IFLA_GRE_ENCAP_SPORT])
-			encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
-
-		if (greinfo[IFLA_GRE_ENCAP_DPORT])
-			encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
-
-		if (greinfo[IFLA_GRE_COLLECT_METADATA])
-			metadata = 1;
-
-		if (greinfo[IFLA_GRE_FWMARK])
-			fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_INDEX])
-			erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_VER])
-			erspan_ver = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_VER]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_DIR])
-			erspan_dir = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_DIR]);
-
-		if (greinfo[IFLA_GRE_ERSPAN_HWID])
-			erspan_hwid = rta_getattr_u16(greinfo[IFLA_GRE_ERSPAN_HWID]);
-
-		free(answer);
 	}
 
 	while (argc > 0) {
 		if (!matches(*argv, "key")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			iflags |= GRE_KEY;
 			oflags |= GRE_KEY;
-			ikey = okey = tnl_parse_key("key", *argv);
-		} else if (!matches(*argv, "nokey")) {
-			iflags &= ~GRE_KEY;
-			oflags &= ~GRE_KEY;
-			ikey = okey = 0;
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr,
+						"Invalid value for \"key\"\n");
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+
+			ikey = okey = uval;
 		} else if (!matches(*argv, "ikey")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			iflags |= GRE_KEY;
-			ikey = tnl_parse_key("ikey", *argv);
-		} else if (!matches(*argv, "noikey")) {
-			iflags &= ~GRE_KEY;
-			ikey = 0;
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0)<0) {
+					fprintf(stderr, "invalid value of \"ikey\"\n");
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			ikey = uval;
 		} else if (!matches(*argv, "okey")) {
+			unsigned uval;
+
 			NEXT_ARG();
 			oflags |= GRE_KEY;
-			okey = tnl_parse_key("okey", *argv);
-		} else if (!matches(*argv, "nookey")) {
-			oflags &= ~GRE_KEY;
-			okey = 0;
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0)<0) {
+					fprintf(stderr, "invalid value of \"okey\"\n");
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			okey = uval;
 		} else if (!matches(*argv, "seq")) {
 			iflags |= GRE_SEQ;
 			oflags |= GRE_SEQ;
-		} else if (!matches(*argv, "noseq")) {
-			iflags &= ~GRE_SEQ;
-			oflags &= ~GRE_SEQ;
 		} else if (!matches(*argv, "iseq")) {
 			iflags |= GRE_SEQ;
-		} else if (!matches(*argv, "noiseq")) {
-			iflags &= ~GRE_SEQ;
 		} else if (!matches(*argv, "oseq")) {
 			oflags |= GRE_SEQ;
-		} else if (!matches(*argv, "nooseq")) {
-			oflags &= ~GRE_SEQ;
 		} else if (!matches(*argv, "csum")) {
 			iflags |= GRE_CSUM;
 			oflags |= GRE_CSUM;
-		} else if (!matches(*argv, "nocsum")) {
-			iflags &= ~GRE_CSUM;
-			oflags &= ~GRE_CSUM;
 		} else if (!matches(*argv, "icsum")) {
 			iflags |= GRE_CSUM;
-		} else if (!matches(*argv, "noicsum")) {
-			iflags &= ~GRE_CSUM;
 		} else if (!matches(*argv, "ocsum")) {
 			oflags |= GRE_CSUM;
-		} else if (!matches(*argv, "noocsum")) {
-			oflags &= ~GRE_CSUM;
 		} else if (!matches(*argv, "remote")) {
+			inet_prefix addr;
 			NEXT_ARG();
-			get_addr(&daddr, *argv, AF_INET6);
+			get_prefix(&addr, *argv, preferred_family);
+			if (addr.family == AF_UNSPEC)
+				invarg("\"remote\" address family is AF_UNSPEC", *argv);
+			memcpy(&raddr, &addr.data, sizeof(raddr));
 		} else if (!matches(*argv, "local")) {
+			inet_prefix addr;
 			NEXT_ARG();
-			get_addr(&saddr, *argv, AF_INET6);
+			get_prefix(&addr, *argv, preferred_family);
+			if (addr.family == AF_UNSPEC)
+				invarg("\"local\" address family is AF_UNSPEC", *argv);
+			memcpy(&laddr, &addr.data, sizeof(laddr));
 		} else if (!matches(*argv, "dev")) {
 			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
+			link = if_nametoindex(*argv);
+			if (link == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n",
+					*argv);
+				exit(-1);
+			}
 		} else if (!matches(*argv, "ttl") ||
-			   !matches(*argv, "hoplimit") ||
-			   !matches(*argv, "hlim")) {
+			   !matches(*argv, "hoplimit")) {
+			__u8 uval;
 			NEXT_ARG();
-			if (strcmp(*argv, "inherit") != 0) {
-				if (get_u8(&hop_limit, *argv, 0))
-					invarg("invalid HLIM\n", *argv);
-			} else
-				hop_limit = 0;
+			if (get_u8(&uval, *argv, 0))
+				invarg("invalid TTL", *argv);
+			hop_limit = uval;
 		} else if (!matches(*argv, "tos") ||
 			   !matches(*argv, "tclass") ||
 			   !matches(*argv, "dsfield")) {
 			__u8 uval;
-
 			NEXT_ARG();
-			flowinfo &= ~IP6_FLOWINFO_TCLASS;
 			if (strcmp(*argv, "inherit") == 0)
 				flags |= IP6_TNL_F_USE_ORIG_TCLASS;
 			else {
@@ -299,9 +258,7 @@
 		} else if (strcmp(*argv, "flowlabel") == 0 ||
 			   strcmp(*argv, "fl") == 0) {
 			__u32 uval;
-
 			NEXT_ARG();
-			flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
 			if (strcmp(*argv, "inherit") == 0)
 				flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
 			else {
@@ -317,218 +274,96 @@
 			if (strcmp(*argv, "inherit") != 0)
 				invarg("not inherit", *argv);
 			flags |= IP6_TNL_F_RCV_DSCP_COPY;
-		} else if (strcmp(*argv, "noencap") == 0) {
-			encaptype = TUNNEL_ENCAP_NONE;
-		} else if (strcmp(*argv, "encap") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "fou") == 0)
-				encaptype = TUNNEL_ENCAP_FOU;
-			else if (strcmp(*argv, "gue") == 0)
-				encaptype = TUNNEL_ENCAP_GUE;
-			else if (strcmp(*argv, "none") == 0)
-				encaptype = TUNNEL_ENCAP_NONE;
-			else
-				invarg("Invalid encap type.", *argv);
-		} else if (strcmp(*argv, "encap-sport") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "auto") == 0)
-				encapsport = 0;
-			else if (get_u16(&encapsport, *argv, 0))
-				invarg("Invalid source port.", *argv);
-		} else if (strcmp(*argv, "encap-dport") == 0) {
-			NEXT_ARG();
-			if (get_u16(&encapdport, *argv, 0))
-				invarg("Invalid destination port.", *argv);
-		} else if (strcmp(*argv, "encap-csum") == 0) {
-			encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
-		} else if (strcmp(*argv, "noencap-csum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
-		} else if (strcmp(*argv, "encap-udp6-csum") == 0) {
-			encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
-		} else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
-		} else if (strcmp(*argv, "encap-remcsum") == 0) {
-			encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
-		} else if (strcmp(*argv, "noencap-remcsum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
-		} else if (strcmp(*argv, "external") == 0) {
-			metadata = 1;
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "inherit") == 0) {
-				flags |= IP6_TNL_F_USE_ORIG_FWMARK;
-				fwmark = 0;
-			} else {
-				if (get_u32(&fwmark, *argv, 0))
-					invarg("invalid fwmark\n", *argv);
-				flags &= ~IP6_TNL_F_USE_ORIG_FWMARK;
-			}
-		} else if (strcmp(*argv, "allow-localremote") == 0) {
-			flags |= IP6_TNL_F_ALLOW_LOCAL_REMOTE;
-		} else if (strcmp(*argv, "noallow-localremote") == 0) {
-			flags &= ~IP6_TNL_F_ALLOW_LOCAL_REMOTE;
-		} else if (strcmp(*argv, "encaplimit") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "none") == 0) {
-				flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
-			} else {
-				__u8 uval;
-
-				if (get_u8(&uval, *argv, 0))
-					invarg("invalid ELIM", *argv);
-				encap_limit = uval;
-				flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
-			}
-		} else if (strcmp(*argv, "erspan") == 0) {
-			NEXT_ARG();
-			if (get_u32(&erspan_idx, *argv, 0))
-				invarg("invalid erspan index\n", *argv);
-			if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0)
-				invarg("erspan index must be > 0 and <= 20-bit\n", *argv);
-		} else if (strcmp(*argv, "erspan_ver") == 0) {
-			NEXT_ARG();
-			if (get_u8(&erspan_ver, *argv, 0))
-				invarg("invalid erspan version\n", *argv);
-			if (erspan_ver != 1 && erspan_ver != 2)
-				invarg("erspan version must be 1 or 2\n", *argv);
-		} else if (strcmp(*argv, "erspan_dir") == 0) {
-			NEXT_ARG();
-			if (matches(*argv, "ingress") == 0)
-				erspan_dir = 0;
-			else if (matches(*argv, "egress") == 0)
-				erspan_dir = 1;
-			else
-				invarg("Invalid erspan direction.", *argv);
-		} else if (strcmp(*argv, "erspan_hwid") == 0) {
-			NEXT_ARG();
-			if (get_u16(&erspan_hwid, *argv, 0))
-				invarg("invalid erspan hwid\n", *argv);
-		} else {
-			gre_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
+		} else
+			usage();
 		argc--; argv++;
 	}
 
-	if (metadata) {
-		addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0);
-		return 0;
-	}
-
 	addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
 	addattr32(n, 1024, IFLA_GRE_OKEY, okey);
 	addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
 	addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
-	if (is_addrtype_inet_not_unspec(&saddr))
-		addattr_l(n, 1024, IFLA_GRE_LOCAL, saddr.data, saddr.bytelen);
-	if (is_addrtype_inet_not_unspec(&daddr))
-		addattr_l(n, 1024, IFLA_GRE_REMOTE, daddr.data, daddr.bytelen);
+	addattr_l(n, 1024, IFLA_GRE_LOCAL, &laddr, sizeof(laddr));
+	addattr_l(n, 1024, IFLA_GRE_REMOTE, &raddr, sizeof(raddr));
 	if (link)
 		addattr32(n, 1024, IFLA_GRE_LINK, link);
 	addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
 	addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
 	addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
-	addattr32(n, 1024, IFLA_GRE_FLAGS, flags);
-	addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark);
-	if (erspan_ver) {
-		addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver);
-		if (erspan_ver == 1 && erspan_idx != 0) {
-			addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx);
-		} else if (erspan_ver == 2) {
-			addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir);
-			addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid);
-		}
-	}
-	addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
-	addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
-	addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
-	addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
+	addattr_l(n, 1024, IFLA_GRE_FLAGS, &flowinfo, 4);
 
 	return 0;
 }
 
 static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	char s1[1024];
 	char s2[64];
-	__u16 iflags = 0;
-	__u16 oflags = 0;
-	__u32 flags = 0;
-	__u32 flowinfo = 0;
-	__u8 ttl = 0;
+	const char *local = "any";
+	const char *remote = "any";
+	unsigned iflags = 0;
+	unsigned oflags = 0;
+	unsigned flags = 0;
+	unsigned flowinfo = 0;
+	struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
 
 	if (!tb)
 		return;
 
-	if (tb[IFLA_GRE_COLLECT_METADATA]) {
-		print_bool(PRINT_ANY, "external", "external ", true);
-		return;
-	}
-
 	if (tb[IFLA_GRE_FLAGS])
 		flags = rta_getattr_u32(tb[IFLA_GRE_FLAGS]);
 
 	if (tb[IFLA_GRE_FLOWINFO])
-		flowinfo = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
+		flags = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
 
-	tnl_print_endpoint("remote", tb[IFLA_GRE_REMOTE], AF_INET6);
-	tnl_print_endpoint("local", tb[IFLA_GRE_LOCAL], AF_INET6);
+	if (tb[IFLA_GRE_REMOTE]) {
+		struct in6_addr addr;
+		memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
 
-	if (tb[IFLA_GRE_LINK]) {
-		__u32 link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
-
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
+		if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
+			remote = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1));
 	}
 
-	if (tb[IFLA_GRE_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "hoplimit %u ", ttl);
+	fprintf(f, "remote %s ", remote);
+
+	if (tb[IFLA_GRE_LOCAL]) {
+		struct in6_addr addr;
+		memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
+
+		if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
+			local = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1));
+	}
+
+	fprintf(f, "local %s ", local);
+
+	if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
+		unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
+		const char *n = if_indextoname(link, s2);
+
+		if (n)
+			fprintf(f, "dev %s ", n);
+		else
+			fprintf(f, "dev %u ", link);
+	}
+
+	if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
+		fprintf(f, "hoplimit %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
+
+	if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
+		fprintf(f, "encaplimit none ");
+	else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
+		int encap_limit = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
+
+		fprintf(f, "encaplimit %d ", encap_limit);
+	}
+
+	if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
+		fprintf(f, "flowlabel inherit ");
 	else
-		print_string(PRINT_FP, NULL, "hoplimit %s ", "inherit");
-
-	if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_ign_encap_limit",
-			   "encaplimit none ",
-			   true);
-	} else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
-		__u8 val = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
-
-		print_uint(PRINT_ANY, "encap_limit", "encaplimit %u ", val);
-	}
-
-	if (flags & IP6_TNL_F_USE_ORIG_TCLASS) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_use_orig_tclass",
-			   "tclass inherit ",
-			   true);
-	} else if (tb[IFLA_GRE_FLOWINFO]) {
-		__u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20;
-
-		snprintf(s2, sizeof(s2), "0x%02x", val);
-		print_string(PRINT_ANY, "tclass", "tclass %s ", s2);
-	}
-
-	if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_use_orig_flowlabel",
-			   "flowlabel inherit ",
-			   true);
-	} else if (tb[IFLA_GRE_FLOWINFO]) {
-		__u32 val = ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL);
-
-		snprintf(s2, sizeof(s2), "0x%05x", val);
-		print_string(PRINT_ANY, "flowlabel", "flowlabel %s ", s2);
-	}
+		fprintf(f, "flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
 
 	if (flags & IP6_TNL_F_RCV_DSCP_COPY)
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_rcv_dscp_copy",
-			   "dscp inherit ",
-			   true);
+		fprintf(f, "dscp inherit ");
 
 	if (tb[IFLA_GRE_IFLAGS])
 		iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
@@ -538,80 +373,28 @@
 
 	if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
 		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
-		print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
+		fprintf(f, "ikey %s ", s2);
 	}
 
 	if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
 		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
-		print_string(PRINT_ANY, "okey", "okey %s ", s2);
+		fprintf(f, "okey %s ", s2);
 	}
 
 	if (iflags & GRE_SEQ)
-		print_bool(PRINT_ANY, "iseq", "iseq ", true);
+		fputs("iseq ", f);
 	if (oflags & GRE_SEQ)
-		print_bool(PRINT_ANY, "oseq", "oseq ", true);
+		fputs("oseq ", f);
 	if (iflags & GRE_CSUM)
-		print_bool(PRINT_ANY, "icsum", "icsum ", true);
+		fputs("icsum ", f);
 	if (oflags & GRE_CSUM)
-		print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
+		fputs("ocsum ", f);
+}
 
-	if (flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_allow_local_remote",
-			   "allow-localremote ",
-			   true);
-
-	if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_use_orig_fwmark",
-			   "fwmark inherit ",
-			   true);
-	} else if (tb[IFLA_GRE_FWMARK]) {
-		__u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
-
-		if (fwmark) {
-			print_0xhex(PRINT_ANY,
-				    "fwmark", "fwmark %#llx ", fwmark);
-		}
-	}
-
-	if (tb[IFLA_GRE_ERSPAN_INDEX]) {
-		__u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]);
-
-		print_uint(PRINT_ANY,
-			   "erspan_index", "erspan_index %u ", erspan_idx);
-	}
-
-	if (tb[IFLA_GRE_ERSPAN_VER]) {
-		__u8 erspan_ver = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_VER]);
-
-		print_uint(PRINT_ANY,
-			   "erspan_ver", "erspan_ver %u ", erspan_ver);
-	}
-
-	if (tb[IFLA_GRE_ERSPAN_DIR]) {
-		__u8 erspan_dir = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_DIR]);
-
-		if (erspan_dir == 0)
-			print_string(PRINT_ANY, "erspan_dir",
-				     "erspan_dir ingress ", NULL);
-		else
-			print_string(PRINT_ANY, "erspan_dir",
-				     "erspan_dir egress ", NULL);
-	}
-
-	if (tb[IFLA_GRE_ERSPAN_HWID]) {
-		__u16 erspan_hwid = rta_getattr_u16(tb[IFLA_GRE_ERSPAN_HWID]);
-
-		print_0xhex(PRINT_ANY,
-			    "erspan_hwid", "erspan_hwid %#llx ", erspan_hwid);
-	}
-
-	tnl_print_encap(tb,
-			IFLA_GRE_ENCAP_TYPE,
-			IFLA_GRE_ENCAP_FLAGS,
-			IFLA_GRE_ENCAP_SPORT,
-			IFLA_GRE_ENCAP_DPORT);
+static void gre_print_help(struct link_util *lu, int argc, char **argv,
+	FILE *f)
+{
+	print_usage(f);
 }
 
 struct link_util ip6gre_link_util = {
@@ -629,11 +412,3 @@
 	.print_opt = gre_print_opt,
 	.print_help = gre_print_help,
 };
-
-struct link_util ip6erspan_link_util = {
-	.id = "ip6erspan",
-	.maxattr = IFLA_GRE_MAX,
-	.parse_opt = gre_parse_opt,
-	.print_opt = gre_print_opt,
-	.print_help = gre_print_help,
-};
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index c7b49b0..f771c75 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -29,92 +29,79 @@
 
 #define DEFAULT_TNL_HOP_LIMIT	(64)
 
-static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
-				 FILE *f)
+static void print_usage(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... %-6s	[ remote ADDR ]\n"
-		"			[ local ADDR ]\n"
-		"			[ encaplimit ELIM ]\n"
-		"			[ hoplimit HLIM ]\n"
-		"			[ tclass TCLASS ]\n"
-		"			[ flowlabel FLOWLABEL ]\n"
-		"			[ dscp inherit ]\n"
-		"			[ [no]allow-localremote ]\n"
-		"			[ dev PHYS_DEV ]\n"
-		"			[ fwmark MARK ]\n"
-		"			[ external ]\n"
-		"			[ noencap ]\n"
-		"			[ encap { fou | gue | none } ]\n"
-		"			[ encap-sport PORT ]\n"
-		"			[ encap-dport PORT ]\n"
-		"			[ [no]encap-csum ]\n"
-		"			[ [no]encap-csum6 ]\n"
-		"			[ [no]encap-remcsum ]\n"
-		"			[ mode { ip6ip6 | ipip6 | any } ]\n"
-		"\n"
-		"Where:	ADDR	  := IPV6_ADDRESS\n"
-		"	ELIM	  := { none | 0..255 }(default=%d)\n"
-		"	HLIM	  := 0..255 (default=%d)\n"
-		"	TCLASS    := { 0x0..0xff | inherit }\n"
-		"	FLOWLABEL := { 0x0..0xfffff | inherit }\n"
-		"	MARK	  := { 0x0..0xffffffff | inherit }\n",
-		lu->id,
-		IPV6_DEFAULT_TNL_ENCAP_LIMIT, DEFAULT_TNL_HOP_LIMIT);
+	fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
+	fprintf(f, "          [ mode { ip6ip6 | ipip6 | any } ]\n");
+	fprintf(f, "          type ip6tnl [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(f, "          [ dev PHYS_DEV ] [ encaplimit ELIM ]\n");
+	fprintf(f ,"          [ hoplimit HLIM ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
+	fprintf(f, "          [ dscp inherit ] [ fwmark inherit ]\n");
+	fprintf(f, "\n");
+	fprintf(f, "Where: NAME      := STRING\n");
+	fprintf(f, "       ADDR      := IPV6_ADDRESS\n");
+	fprintf(f, "       ELIM      := { none | 0..255 }(default=%d)\n",
+		IPV6_DEFAULT_TNL_ENCAP_LIMIT);
+	fprintf(f, "       HLIM      := 0..255 (default=%d)\n",
+		DEFAULT_TNL_HOP_LIMIT);
+	fprintf(f, "       TCLASS    := { 0x0..0xff | inherit }\n");
+	fprintf(f, "       FLOWLABEL := { 0x0..0xfffff | inherit }\n");
+}
+
+static void usage(void) __attribute__((noreturn));
+static void usage(void)
+{
+	print_usage(stderr);
+	exit(-1);
 }
 
 static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
 			       struct nlmsghdr *n)
 {
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg i;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-		.i.ifi_index = ifi->ifi_index,
-	};
-	struct nlmsghdr *answer;
+		char buf[2048];
+	} req;
+	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
 	int len;
-	inet_prefix saddr, daddr;
+	struct in6_addr laddr;
+	struct in6_addr raddr;
 	__u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
 	__u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
 	__u32 flowinfo = 0;
 	__u32 flags = 0;
-	__u8 proto = 0;
 	__u32 link = 0;
-	__u16 encaptype = 0;
-	__u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
-	__u16 encapsport = 0;
-	__u16 encapdport = 0;
-	__u8 metadata = 0;
-	__u32 fwmark = 0;
+	__u8 proto = 0;
 
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
+	memset(&laddr, 0, sizeof(laddr));
+	memset(&raddr, 0, sizeof(raddr));
 
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-		const struct rtattr *rta;
+		memset(&req, 0, sizeof(req));
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETLINK;
+		req.i.ifi_family = preferred_family;
+		req.i.ifi_index = ifi->ifi_index;
+
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
 get_failed:
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
 		}
 
-		len = answer->nlmsg_len;
+		len = req.n.nlmsg_len;
 		len -= NLMSG_LENGTH(sizeof(*ifi));
 		if (len < 0)
 			goto get_failed;
 
-		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
+		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
 
 		if (!tb[IFLA_LINKINFO])
 			goto get_failed;
@@ -127,13 +114,13 @@
 		parse_rtattr_nested(iptuninfo, IFLA_IPTUN_MAX,
 				    linkinfo[IFLA_INFO_DATA]);
 
-		rta = iptuninfo[IFLA_IPTUN_LOCAL];
-		if (rta && get_addr_rta(&saddr, rta, AF_INET6))
-			goto get_failed;
+		if (iptuninfo[IFLA_IPTUN_LOCAL])
+			memcpy(&laddr, RTA_DATA(iptuninfo[IFLA_IPTUN_LOCAL]),
+			       sizeof(laddr));
 
-		rta = iptuninfo[IFLA_IPTUN_REMOTE];
-		if (rta && get_addr_rta(&daddr, rta, AF_INET6))
-			goto get_failed;
+		if (iptuninfo[IFLA_IPTUN_REMOTE])
+			memcpy(&raddr, RTA_DATA(iptuninfo[IFLA_IPTUN_REMOTE]),
+			       sizeof(raddr));
 
 		if (iptuninfo[IFLA_IPTUN_TTL])
 			hop_limit = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TTL]);
@@ -152,17 +139,10 @@
 
 		if (iptuninfo[IFLA_IPTUN_PROTO])
 			proto = rta_getattr_u8(iptuninfo[IFLA_IPTUN_PROTO]);
-		if (iptuninfo[IFLA_IPTUN_COLLECT_METADATA])
-			metadata = 1;
-
-		if (iptuninfo[IFLA_IPTUN_FWMARK])
-			fwmark = rta_getattr_u32(iptuninfo[IFLA_IPTUN_FWMARK]);
-
-		free(answer);
 	}
 
 	while (argc > 0) {
-		if (strcmp(*argv, "mode") == 0) {
+		if (matches(*argv, "mode") == 0) {
 			NEXT_ARG();
 			if (strcmp(*argv, "ipv6/ipv6") == 0 ||
 			    strcmp(*argv, "ip6ip6") == 0)
@@ -178,43 +158,48 @@
 			else
 				invarg("Cannot guess tunnel mode.", *argv);
 		} else if (strcmp(*argv, "remote") == 0) {
+			inet_prefix addr;
 			NEXT_ARG();
-			get_addr(&daddr, *argv, AF_INET6);
+			get_prefix(&addr, *argv, preferred_family);
+			if (addr.family == AF_UNSPEC)
+				invarg("\"remote\" address family is AF_UNSPEC", *argv);
+			memcpy(&raddr, addr.data, addr.bytelen);
 		} else if (strcmp(*argv, "local") == 0) {
+			inet_prefix addr;
 			NEXT_ARG();
-			get_addr(&saddr, *argv, AF_INET6);
+			get_prefix(&addr, *argv, preferred_family);
+			if (addr.family == AF_UNSPEC)
+				invarg("\"local\" address family is AF_UNSPEC", *argv);
+			memcpy(&laddr, addr.data, addr.bytelen);
 		} else if (matches(*argv, "dev") == 0) {
 			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
-		} else if (strcmp(*argv, "ttl") == 0 ||
-			   strcmp(*argv, "hoplimit") == 0 ||
+			link = if_nametoindex(*argv);
+			if (link == 0)
+				invarg("\"dev\" is invalid", *argv);
+		} else if (strcmp(*argv, "hoplimit") == 0 ||
+			   strcmp(*argv, "ttl") == 0 ||
 			   strcmp(*argv, "hlim") == 0) {
+			__u8 uval;
 			NEXT_ARG();
-			if (strcmp(*argv, "inherit") != 0) {
-				if (get_u8(&hop_limit, *argv, 0))
-					invarg("invalid HLIM\n", *argv);
-			} else
-				hop_limit = 0;
-		} else if (strcmp(*argv, "encaplimit") == 0) {
+			if (get_u8(&uval, *argv, 0))
+				invarg("invalid HLIM", *argv);
+			hop_limit = uval;
+		} else if (matches(*argv, "encaplimit") == 0) {
 			NEXT_ARG();
 			if (strcmp(*argv, "none") == 0) {
 				flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
 			} else {
 				__u8 uval;
-
 				if (get_u8(&uval, *argv, 0) < -1)
 					invarg("invalid ELIM", *argv);
 				encap_limit = uval;
 				flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
 			}
-		} else if (strcmp(*argv, "tos") == 0 ||
-			   strcmp(*argv, "tclass") == 0 ||
+		} else if (strcmp(*argv, "tclass") == 0 ||
 			   strcmp(*argv, "tc") == 0 ||
+			   strcmp(*argv, "tos") == 0 ||
 			   matches(*argv, "dsfield") == 0) {
 			__u8 uval;
-
 			NEXT_ARG();
 			flowinfo &= ~IP6_FLOWINFO_TCLASS;
 			if (strcmp(*argv, "inherit") == 0)
@@ -228,7 +213,6 @@
 		} else if (strcmp(*argv, "flowlabel") == 0 ||
 			   strcmp(*argv, "fl") == 0) {
 			__u32 uval;
-
 			NEXT_ARG();
 			flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
 			if (strcmp(*argv, "inherit") == 0)
@@ -248,105 +232,36 @@
 			flags |= IP6_TNL_F_RCV_DSCP_COPY;
 		} else if (strcmp(*argv, "fwmark") == 0) {
 			NEXT_ARG();
-			if (strcmp(*argv, "inherit") == 0) {
-				flags |= IP6_TNL_F_USE_ORIG_FWMARK;
-				fwmark = 0;
-			} else {
-				if (get_u32(&fwmark, *argv, 0))
-					invarg("invalid fwmark\n", *argv);
-				flags &= ~IP6_TNL_F_USE_ORIG_FWMARK;
-			}
-		} else if (strcmp(*argv, "allow-localremote") == 0) {
-			flags |= IP6_TNL_F_ALLOW_LOCAL_REMOTE;
-		} else if (strcmp(*argv, "noallow-localremote") == 0) {
-			flags &= ~IP6_TNL_F_ALLOW_LOCAL_REMOTE;
-		} else if (strcmp(*argv, "noencap") == 0) {
-			encaptype = TUNNEL_ENCAP_NONE;
-		} else if (strcmp(*argv, "encap") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "fou") == 0)
-				encaptype = TUNNEL_ENCAP_FOU;
-			else if (strcmp(*argv, "gue") == 0)
-				encaptype = TUNNEL_ENCAP_GUE;
-			else if (strcmp(*argv, "none") == 0)
-				encaptype = TUNNEL_ENCAP_NONE;
-			else
-				invarg("Invalid encap type.", *argv);
-		} else if (strcmp(*argv, "encap-sport") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "auto") == 0)
-				encapsport = 0;
-			else if (get_u16(&encapsport, *argv, 0))
-				invarg("Invalid source port.", *argv);
-		} else if (strcmp(*argv, "encap-dport") == 0) {
-			NEXT_ARG();
-			if (get_u16(&encapdport, *argv, 0))
-				invarg("Invalid destination port.", *argv);
-		} else if (strcmp(*argv, "encap-csum") == 0) {
-			encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
-		} else if (strcmp(*argv, "noencap-csum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
-		} else if (strcmp(*argv, "encap-udp6-csum") == 0) {
-			encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
-		} else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
-		} else if (strcmp(*argv, "encap-remcsum") == 0) {
-			encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
-		} else if (strcmp(*argv, "noencap-remcsum") == 0) {
-			encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
-		} else if (strcmp(*argv, "external") == 0) {
-			metadata = 1;
-		} else {
-			ip6tunnel_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
+			if (strcmp(*argv, "inherit") != 0)
+				invarg("not inherit", *argv);
+			flags |= IP6_TNL_F_USE_ORIG_FWMARK;
+		} else
+			usage();
 		argc--, argv++;
 	}
 
 	addattr8(n, 1024, IFLA_IPTUN_PROTO, proto);
-	if (metadata) {
-		addattr_l(n, 1024, IFLA_IPTUN_COLLECT_METADATA, NULL, 0);
-		return 0;
-	}
-
-	if (is_addrtype_inet_not_unspec(&saddr)) {
-		addattr_l(n, 1024, IFLA_IPTUN_LOCAL,
-			  saddr.data, saddr.bytelen);
-	}
-	if (is_addrtype_inet_not_unspec(&daddr)) {
-		addattr_l(n, 1024, IFLA_IPTUN_REMOTE,
-			  daddr.data, daddr.bytelen);
-	}
+	addattr_l(n, 1024, IFLA_IPTUN_LOCAL, &laddr, sizeof(laddr));
+	addattr_l(n, 1024, IFLA_IPTUN_REMOTE, &raddr, sizeof(raddr));
 	addattr8(n, 1024, IFLA_IPTUN_TTL, hop_limit);
 	addattr8(n, 1024, IFLA_IPTUN_ENCAP_LIMIT, encap_limit);
 	addattr32(n, 1024, IFLA_IPTUN_FLOWINFO, flowinfo);
 	addattr32(n, 1024, IFLA_IPTUN_FLAGS, flags);
 	addattr32(n, 1024, IFLA_IPTUN_LINK, link);
-	addattr32(n, 1024, IFLA_IPTUN_FWMARK, fwmark);
-
-	addattr16(n, 1024, IFLA_IPTUN_ENCAP_TYPE, encaptype);
-	addattr16(n, 1024, IFLA_IPTUN_ENCAP_FLAGS, encapflags);
-	addattr16(n, 1024, IFLA_IPTUN_ENCAP_SPORT, htons(encapsport));
-	addattr16(n, 1024, IFLA_IPTUN_ENCAP_DPORT, htons(encapdport));
 
 	return 0;
 }
 
 static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	char s1[256];
 	char s2[64];
-	__u32 flags = 0;
+	int flags = 0;
 	__u32 flowinfo = 0;
-	__u8 ttl = 0;
 
 	if (!tb)
 		return;
 
-	if (tb[IFLA_IPTUN_COLLECT_METADATA]) {
-		print_bool(PRINT_ANY, "external", "external ", true);
-		return;
-	}
-
 	if (tb[IFLA_IPTUN_FLAGS])
 		flags = rta_getattr_u32(tb[IFLA_IPTUN_FLAGS]);
 
@@ -356,105 +271,81 @@
 	if (tb[IFLA_IPTUN_PROTO]) {
 		switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
 		case IPPROTO_IPIP:
-			print_string(PRINT_ANY, "proto", "%s ", "ipip6");
+			fprintf(f, "ipip6 ");
 			break;
 		case IPPROTO_IPV6:
-			print_string(PRINT_ANY, "proto", "%s ", "ip6ip6");
+			fprintf(f, "ip6ip6 ");
 			break;
 		case 0:
-			print_string(PRINT_ANY, "proto", "%s ", "any");
+			fprintf(f, "any ");
 			break;
 		}
 	}
 
-	tnl_print_endpoint("remote", tb[IFLA_IPTUN_REMOTE], AF_INET6);
-	tnl_print_endpoint("local", tb[IFLA_IPTUN_LOCAL], AF_INET6);
-
-	if (tb[IFLA_IPTUN_LINK]) {
-		__u32 link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
-
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
+	if (tb[IFLA_IPTUN_REMOTE]) {
+		fprintf(f, "remote %s ",
+			rt_addr_n2a(AF_INET6,
+				    RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
+				    RTA_DATA(tb[IFLA_IPTUN_REMOTE]),
+				    s1, sizeof(s1)));
 	}
 
+	if (tb[IFLA_IPTUN_LOCAL]) {
+		fprintf(f, "local %s ",
+			rt_addr_n2a(AF_INET6,
+				    RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
+				    RTA_DATA(tb[IFLA_IPTUN_LOCAL]),
+				    s1, sizeof(s1)));
+	}
+
+	if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
+		unsigned link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
+		const char *n = if_indextoname(link, s2);
+
+		if (n)
+			fprintf(f, "dev %s ", n);
+		else
+			fprintf(f, "dev %u ", link);
+	}
+
+	if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
+		printf("encaplimit none ");
+	else if (tb[IFLA_IPTUN_ENCAP_LIMIT])
+		fprintf(f, "encaplimit %u ",
+			rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]));
+
 	if (tb[IFLA_IPTUN_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_IPTUN_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "hoplimit %u ", ttl);
+		fprintf(f, "hoplimit %u ", rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
+
+	if (flags & IP6_TNL_F_USE_ORIG_TCLASS)
+		printf("tclass inherit ");
+	else if (tb[IFLA_IPTUN_FLOWINFO]) {
+		__u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS);
+
+		printf("tclass 0x%02x ", (__u8)(val >> 20));
+	}
+
+	if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
+		printf("flowlabel inherit ");
 	else
-		print_string(PRINT_FP, NULL, "hoplimit %s ", "inherit");
+		printf("flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
 
-	if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_ign_encap_limit",
-			   "encaplimit none ",
-			   true);
-	} else if (tb[IFLA_IPTUN_ENCAP_LIMIT]) {
-		__u8 val = rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]);
-
-		print_uint(PRINT_ANY, "encap_limit", "encaplimit %u ", val);
-	}
-
-	if (flags & IP6_TNL_F_USE_ORIG_TCLASS) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_use_orig_tclass",
-			   "tclass inherit ",
-			   true);
-	} else if (tb[IFLA_IPTUN_FLOWINFO]) {
-		__u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20;
-
-		snprintf(s2, sizeof(s2), "0x%02x", val);
-		print_string(PRINT_ANY, "tclass", "tclass %s ", s2);
-	}
-
-	if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_use_orig_flowlabel",
-			   "flowlabel inherit ",
-			   true);
-	} else if (tb[IFLA_IPTUN_FLOWINFO]) {
-		__u32 val = ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL);
-
-		snprintf(s2, sizeof(s2), "0x%05x", val);
-		print_string(PRINT_ANY, "flowlabel", "flowlabel %s ", s2);
-	}
+	printf("(flowinfo 0x%08x) ", ntohl(flowinfo));
 
 	if (flags & IP6_TNL_F_RCV_DSCP_COPY)
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_rcv_dscp_copy",
-			   "dscp inherit ",
-			   true);
+		printf("dscp inherit ");
 
 	if (flags & IP6_TNL_F_MIP6_DEV)
-		print_bool(PRINT_ANY, "ip6_tnl_f_mip6_dev", "mip6 ", true);
+		fprintf(f, "mip6 ");
 
-	if (flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_allow_local_remote",
-			   "allow-localremote ",
-			   true);
+	if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
+		fprintf(f, "fwmark inherit ");
+}
 
-	if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
-		print_bool(PRINT_ANY,
-			   "ip6_tnl_f_use_orig_fwmark",
-			   "fwmark inherit ",
-			   true);
-	} else if (tb[IFLA_IPTUN_FWMARK]) {
-		__u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
-
-		if (fwmark) {
-			print_0xhex(PRINT_ANY,
-				    "fwmark", "fwmark %#llx ", fwmark);
-		}
-	}
-
-	tnl_print_encap(tb,
-			IFLA_IPTUN_ENCAP_TYPE,
-			IFLA_IPTUN_ENCAP_FLAGS,
-			IFLA_IPTUN_ENCAP_SPORT,
-			IFLA_IPTUN_ENCAP_DPORT);
+static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
+	FILE *f)
+{
+	print_usage(f);
 }
 
 struct link_util ip6tnl_link_util = {
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index 636cdb2..9d6bc98 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -16,7 +16,6 @@
 #include <sys/socket.h>
 #include <arpa/inet.h>
 
-#include <linux/in.h>
 #include <linux/ip.h>
 #include <linux/if_tunnel.h>
 #include "rt_names.h"
@@ -24,101 +23,87 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
-				FILE *f)
+static void print_usage(FILE *f, int sit)
 {
-	const char *mode;
-
-	if (strcmp(lu->id, "sit") == 0) {
-		mode =	"{ ip6ip | ipip | mplsip | any } ]\n"
-			"			[ isatap";
-	} else {
-		mode = "{ ipip | mplsip | any }";
+	fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
+	fprintf(f, "          type { ipip | sit } [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(f, "          [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n");
+	fprintf(f, "          [ 6rd-prefix ADDR ] [ 6rd-relay_prefix ADDR ] [ 6rd-reset ]\n");
+	fprintf(f, "          [ noencap ] [ encap { fou | gue | none } ]\n");
+	fprintf(f, "          [ encap-sport PORT ] [ encap-dport PORT ]\n");
+	fprintf(f, "          [ [no]encap-csum ] [ [no]encap-csum6 ] [ [no]encap-remcsum ]\n");
+	if (sit) {
+		fprintf(f, "          [ mode { ip6ip | ipip | any } ]\n");
+		fprintf(f, "          [ isatap ]\n");
 	}
+	fprintf(f, "\n");
+	fprintf(f, "Where: NAME := STRING\n");
+	fprintf(f, "       ADDR := { IP_ADDRESS | any }\n");
+	fprintf(f, "       TOS  := { NUMBER | inherit }\n");
+	fprintf(f, "       TTL  := { 1..255 | inherit }\n");
+}
 
-	fprintf(f,
-		"Usage: ... %-6s	[ remote ADDR ]\n"
-		"			[ local ADDR ]\n"
-		"			[ ttl TTL ]\n"
-		"			[ tos TOS ]\n"
-		"			[ [no]pmtudisc ]\n"
-		"			[ 6rd-prefix ADDR ]\n"
-		"			[ 6rd-relay_prefix ADDR ]\n"
-		"			[ 6rd-reset ]\n"
-		"			[ dev PHYS_DEV ]\n"
-		"			[ fwmark MARK ]\n"
-		"			[ external ]\n"
-		"			[ noencap ]\n"
-		"			[ encap { fou | gue | none } ]\n"
-		"			[ encap-sport PORT ]\n"
-		"			[ encap-dport PORT ]\n"
-		"			[ [no]encap-csum ]\n"
-		"			[ [no]encap-csum6 ]\n"
-		"			[ [no]encap-remcsum ]\n"
-		"			[ mode %s ]\n"
-		"\n"
-		"Where:	ADDR := { IP_ADDRESS | any }\n"
-		"	TOS  := { NUMBER | inherit }\n"
-		"	TTL  := { 1..255 | inherit }\n"
-		"	MARK := { 0x0..0xffffffff }\n",
-		lu->id, mode);
+static void usage(int sit) __attribute__((noreturn));
+static void usage(int sit)
+{
+	print_usage(stderr, sit);
+	exit(-1);
 }
 
 static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
 			      struct nlmsghdr *n)
 {
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg i;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-		.i.ifi_index = ifi->ifi_index,
-	};
-	struct nlmsghdr *answer;
+		char buf[2048];
+	} req;
+	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
 	int len;
-	inet_prefix saddr, daddr, ip6rdprefix, ip6rdrelayprefix;
-	__u8 pmtudisc = 1;
-	__u8 tos = 0;
-	__u16 iflags = 0;
-	__u8 ttl = 0;
-	__u8 proto = 0;
 	__u32 link = 0;
+	__u32 laddr = 0;
+	__u32 raddr = 0;
+	__u8 ttl = 0;
+	__u8 tos = 0;
+	__u8 pmtudisc = 1;
+	__u16 iflags = 0;
+	__u8 proto = 0;
+	struct in6_addr ip6rdprefix;
+	__u16 ip6rdprefixlen = 0;
+	__u32 ip6rdrelayprefix = 0;
+	__u16 ip6rdrelayprefixlen = 0;
 	__u16 encaptype = 0;
 	__u16 encapflags = 0;
 	__u16 encapsport = 0;
 	__u16 encapdport = 0;
-	__u8 metadata = 0;
-	__u32 fwmark = 0;
 
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
-
-	inet_prefix_reset(&ip6rdprefix);
-	inet_prefix_reset(&ip6rdrelayprefix);
+	memset(&ip6rdprefix, 0, sizeof(ip6rdprefix));
 
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-		const struct rtattr *rta;
+		memset(&req, 0, sizeof(req));
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETLINK;
+		req.i.ifi_family = preferred_family;
+		req.i.ifi_index = ifi->ifi_index;
+
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
 get_failed:
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
 		}
 
-		len = answer->nlmsg_len;
+		len = req.n.nlmsg_len;
 		len -= NLMSG_LENGTH(sizeof(*ifi));
 		if (len < 0)
 			goto get_failed;
 
-		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
+		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
 
 		if (!tb[IFLA_LINKINFO])
 			goto get_failed;
@@ -131,38 +116,22 @@
 		parse_rtattr_nested(iptuninfo, IFLA_IPTUN_MAX,
 				    linkinfo[IFLA_INFO_DATA]);
 
-		rta = iptuninfo[IFLA_IPTUN_LOCAL];
-		if (rta && get_addr_rta(&saddr, rta, AF_INET))
-			goto get_failed;
+		if (iptuninfo[IFLA_IPTUN_LOCAL])
+			laddr = rta_getattr_u32(iptuninfo[IFLA_IPTUN_LOCAL]);
 
-		rta = iptuninfo[IFLA_IPTUN_REMOTE];
-		if (rta && get_addr_rta(&daddr, rta, AF_INET))
-			goto get_failed;
-
-		rta = iptuninfo[IFLA_IPTUN_6RD_PREFIX];
-		if (rta && get_addr_rta(&ip6rdprefix, rta, AF_INET6))
-			goto get_failed;
-
-		rta = iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIX];
-		if (rta && get_addr_rta(&ip6rdrelayprefix, rta, AF_INET))
-			goto get_failed;
-
-		rta = iptuninfo[IFLA_IPTUN_6RD_PREFIXLEN];
-		ip6rdprefix.bitlen = rta ? rta_getattr_u16(rta) : 0;
-
-		rta = iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIXLEN];
-		ip6rdrelayprefix.bitlen = rta ? rta_getattr_u16(rta) : 0;
+		if (iptuninfo[IFLA_IPTUN_REMOTE])
+			raddr = rta_getattr_u32(iptuninfo[IFLA_IPTUN_REMOTE]);
 
 		if (iptuninfo[IFLA_IPTUN_TTL])
 			ttl = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TTL]);
 
+		if (iptuninfo[IFLA_IPTUN_TOS])
+			tos = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TOS]);
+
 		if (iptuninfo[IFLA_IPTUN_PMTUDISC])
 			pmtudisc =
 				rta_getattr_u8(iptuninfo[IFLA_IPTUN_PMTUDISC]);
 
-		if (iptuninfo[IFLA_IPTUN_TOS])
-			tos = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TOS]);
-
 		if (iptuninfo[IFLA_IPTUN_FLAGS])
 			iflags = rta_getattr_u16(iptuninfo[IFLA_IPTUN_FLAGS]);
 
@@ -180,49 +149,44 @@
 			encapsport = rta_getattr_u16(iptuninfo[IFLA_IPTUN_ENCAP_SPORT]);
 		if (iptuninfo[IFLA_IPTUN_ENCAP_DPORT])
 			encapdport = rta_getattr_u16(iptuninfo[IFLA_IPTUN_ENCAP_DPORT]);
+		if (iptuninfo[IFLA_IPTUN_6RD_PREFIX])
+			memcpy(&ip6rdprefix,
+			       RTA_DATA(iptuninfo[IFLA_IPTUN_6RD_PREFIX]),
+			       sizeof(laddr));
 
-		if (iptuninfo[IFLA_IPTUN_COLLECT_METADATA])
-			metadata = 1;
+		if (iptuninfo[IFLA_IPTUN_6RD_PREFIXLEN])
+			ip6rdprefixlen =
+				rta_getattr_u16(iptuninfo[IFLA_IPTUN_6RD_PREFIXLEN]);
 
-		if (iptuninfo[IFLA_IPTUN_FWMARK])
-			fwmark = rta_getattr_u32(iptuninfo[IFLA_IPTUN_FWMARK]);
+		if (iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIX])
+			ip6rdrelayprefix =
+				rta_getattr_u32(iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIX]);
 
-		free(answer);
+		if (iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIXLEN])
+			ip6rdrelayprefixlen =
+				rta_getattr_u16(iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]);
 	}
 
 	while (argc > 0) {
-		if (strcmp(*argv, "mode") == 0) {
+		if (strcmp(*argv, "remote") == 0) {
 			NEXT_ARG();
-			if (strcmp(lu->id, "sit") == 0 &&
-			    (strcmp(*argv, "ipv6/ipv4") == 0 ||
-			     strcmp(*argv, "ip6ip") == 0))
-				proto = IPPROTO_IPV6;
-			else if (strcmp(*argv, "ipv4/ipv4") == 0 ||
-				 strcmp(*argv, "ipip") == 0 ||
-				 strcmp(*argv, "ip4ip4") == 0)
-				proto = IPPROTO_IPIP;
-			else if (strcmp(*argv, "mpls/ipv4") == 0 ||
-				   strcmp(*argv, "mplsip") == 0)
-				proto = IPPROTO_MPLS;
-			else if (strcmp(*argv, "any/ipv4") == 0 ||
-				 strcmp(*argv, "any") == 0)
-				proto = 0;
+			if (strcmp(*argv, "any"))
+				raddr = get_addr32(*argv);
 			else
-				invarg("Cannot guess tunnel mode.", *argv);
-		} else if (strcmp(*argv, "remote") == 0) {
-			NEXT_ARG();
-			get_addr(&daddr, *argv, AF_INET);
+				raddr = 0;
 		} else if (strcmp(*argv, "local") == 0) {
 			NEXT_ARG();
-			get_addr(&saddr, *argv, AF_INET);
+			if (strcmp(*argv, "any"))
+				laddr = get_addr32(*argv);
+			else
+				laddr = 0;
 		} else if (matches(*argv, "dev") == 0) {
 			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
+			link = if_nametoindex(*argv);
+			if (link == 0)
+				invarg("\"dev\" is invalid", *argv);
 		} else if (strcmp(*argv, "ttl") == 0 ||
-			   strcmp(*argv, "hoplimit") == 0 ||
-			   strcmp(*argv, "hlim") == 0) {
+			   strcmp(*argv, "hoplimit") == 0) {
 			NEXT_ARG();
 			if (strcmp(*argv, "inherit") != 0) {
 				if (get_u8(&ttl, *argv, 0))
@@ -231,10 +195,8 @@
 				ttl = 0;
 		} else if (strcmp(*argv, "tos") == 0 ||
 			   strcmp(*argv, "tclass") == 0 ||
-			   strcmp(*argv, "tc") == 0 ||
 			   matches(*argv, "dsfield") == 0) {
 			__u32 uval;
-
 			NEXT_ARG();
 			if (strcmp(*argv, "inherit") != 0) {
 				if (rtnl_dsfield_a2n(&uval, *argv))
@@ -249,6 +211,21 @@
 		} else if (strcmp(lu->id, "sit") == 0 &&
 			   strcmp(*argv, "isatap") == 0) {
 			iflags |= SIT_ISATAP;
+		} else if (strcmp(lu->id, "sit") == 0 &&
+			   strcmp(*argv, "mode") == 0) {
+			NEXT_ARG();
+			if (strcmp(*argv, "ipv6/ipv4") == 0 ||
+			    strcmp(*argv, "ip6ip") == 0)
+				proto = IPPROTO_IPV6;
+			else if (strcmp(*argv, "ipv4/ipv4") == 0 ||
+				 strcmp(*argv, "ipip") == 0 ||
+				 strcmp(*argv, "ip4ip4") == 0)
+				proto = IPPROTO_IPIP;
+			else if (strcmp(*argv, "any/ipv4") == 0 ||
+				 strcmp(*argv, "any") == 0)
+				proto = 0;
+			else
+				invarg("Cannot guess tunnel mode.", *argv);
 		} else if (strcmp(*argv, "noencap") == 0) {
 			encaptype = TUNNEL_ENCAP_NONE;
 		} else if (strcmp(*argv, "encap") == 0) {
@@ -283,27 +260,29 @@
 			encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
 		} else if (strcmp(*argv, "noencap-remcsum") == 0) {
 			encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
-		} else if (strcmp(*argv, "external") == 0) {
-			metadata = 1;
 		} else if (strcmp(*argv, "6rd-prefix") == 0) {
+			inet_prefix prefix;
 			NEXT_ARG();
-			if (get_prefix(&ip6rdprefix, *argv, AF_INET6))
+			if (get_prefix(&prefix, *argv, AF_INET6))
 				invarg("invalid 6rd_prefix\n", *argv);
+			memcpy(&ip6rdprefix, prefix.data, 16);
+			ip6rdprefixlen = prefix.bitlen;
 		} else if (strcmp(*argv, "6rd-relay_prefix") == 0) {
+			inet_prefix prefix;
 			NEXT_ARG();
-			if (get_prefix(&ip6rdrelayprefix, *argv, AF_INET))
+			if (get_prefix(&prefix, *argv, AF_INET))
 				invarg("invalid 6rd-relay_prefix\n", *argv);
+			memcpy(&ip6rdrelayprefix, prefix.data, 4);
+			ip6rdrelayprefixlen = prefix.bitlen;
 		} else if (strcmp(*argv, "6rd-reset") == 0) {
-			get_prefix(&ip6rdprefix, "2002::/16", AF_INET6);
-			inet_prefix_reset(&ip6rdrelayprefix);
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			NEXT_ARG();
-			if (get_u32(&fwmark, *argv, 0))
-				invarg("invalid fwmark\n", *argv);
-		} else {
-			iptunnel_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
+			inet_prefix prefix;
+			get_prefix(&prefix, "2002::", AF_INET6);
+			memcpy(&ip6rdprefix, prefix.data, 16);
+			ip6rdprefixlen = 16;
+			ip6rdrelayprefix = 0;
+			ip6rdrelayprefixlen = 0;
+		} else
+			usage(strcmp(lu->id, "sit") == 0);
 		argc--, argv++;
 	}
 
@@ -312,25 +291,12 @@
 		exit(-1);
 	}
 
-	addattr8(n, 1024, IFLA_IPTUN_PROTO, proto);
-	if (metadata) {
-		addattr_l(n, 1024, IFLA_IPTUN_COLLECT_METADATA, NULL, 0);
-		return 0;
-	}
-
-	if (is_addrtype_inet_not_unspec(&saddr)) {
-		addattr_l(n, 1024, IFLA_IPTUN_LOCAL,
-			  saddr.data, saddr.bytelen);
-	}
-	if (is_addrtype_inet_not_unspec(&daddr)) {
-		addattr_l(n, 1024, IFLA_IPTUN_REMOTE,
-			  daddr.data, daddr.bytelen);
-	}
-	addattr8(n, 1024, IFLA_IPTUN_PMTUDISC, pmtudisc);
-	addattr8(n, 1024, IFLA_IPTUN_TOS, tos);
-	addattr8(n, 1024, IFLA_IPTUN_TTL, ttl);
 	addattr32(n, 1024, IFLA_IPTUN_LINK, link);
-	addattr32(n, 1024, IFLA_IPTUN_FWMARK, fwmark);
+	addattr32(n, 1024, IFLA_IPTUN_LOCAL, laddr);
+	addattr32(n, 1024, IFLA_IPTUN_REMOTE, raddr);
+	addattr8(n, 1024, IFLA_IPTUN_TTL, ttl);
+	addattr8(n, 1024, IFLA_IPTUN_TOS, tos);
+	addattr8(n, 1024, IFLA_IPTUN_PMTUDISC, pmtudisc);
 
 	addattr16(n, 1024, IFLA_IPTUN_ENCAP_TYPE, encaptype);
 	addattr16(n, 1024, IFLA_IPTUN_ENCAP_FLAGS, encapflags);
@@ -339,17 +305,16 @@
 
 	if (strcmp(lu->id, "sit") == 0) {
 		addattr16(n, 1024, IFLA_IPTUN_FLAGS, iflags);
-		if (is_addrtype_inet(&ip6rdprefix)) {
+		addattr8(n, 1024, IFLA_IPTUN_PROTO, proto);
+		if (ip6rdprefixlen) {
 			addattr_l(n, 1024, IFLA_IPTUN_6RD_PREFIX,
-				  ip6rdprefix.data, ip6rdprefix.bytelen);
+				  &ip6rdprefix, sizeof(ip6rdprefix));
 			addattr16(n, 1024, IFLA_IPTUN_6RD_PREFIXLEN,
-				  ip6rdprefix.bitlen);
-		}
-		if (is_addrtype_inet(&ip6rdrelayprefix)) {
+				  ip6rdprefixlen);
 			addattr32(n, 1024, IFLA_IPTUN_6RD_RELAY_PREFIX,
-				  ip6rdrelayprefix.data[0]);
+				  ip6rdrelayprefix);
 			addattr16(n, 1024, IFLA_IPTUN_6RD_RELAY_PREFIXLEN,
-				  ip6rdrelayprefix.bitlen);
+				  ip6rdrelayprefixlen);
 		}
 	}
 
@@ -358,126 +323,137 @@
 
 static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	char s1[1024];
 	char s2[64];
-	__u16 prefixlen;
-	__u8 ttl = 0;
-	__u8 tos = 0;
+	const char *local = "any";
+	const char *remote = "any";
 
 	if (!tb)
 		return;
 
-	if (tb[IFLA_IPTUN_COLLECT_METADATA]) {
-		print_bool(PRINT_ANY, "external", "external ", true);
-		return;
+	if (tb[IFLA_IPTUN_REMOTE]) {
+		unsigned addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
+
+		if (addr)
+			remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
 	}
 
-	if (tb[IFLA_IPTUN_PROTO]) {
-		switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
-		case IPPROTO_IPIP:
-			print_string(PRINT_ANY, "proto", "%s ", "ipip");
-			break;
-		case IPPROTO_IPV6:
-			print_string(PRINT_ANY, "proto", "%s ", "ip6ip");
-			break;
-		case IPPROTO_MPLS:
-			print_string(PRINT_ANY, "proto", "%s ", "mplsip");
-			break;
-		case 0:
-			print_string(PRINT_ANY, "proto", "%s ", "any");
-			break;
-		}
+	fprintf(f, "remote %s ", remote);
+
+	if (tb[IFLA_IPTUN_LOCAL]) {
+		unsigned addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]);
+
+		if (addr)
+			local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
 	}
 
-	tnl_print_endpoint("remote", tb[IFLA_IPTUN_REMOTE], AF_INET);
-	tnl_print_endpoint("local", tb[IFLA_IPTUN_LOCAL], AF_INET);
+	fprintf(f, "local %s ", local);
 
-	if (tb[IFLA_IPTUN_LINK]) {
-		__u32 link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
+	if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
+		unsigned link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
+		const char *n = if_indextoname(link, s2);
 
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
-	}
-
-	if (tb[IFLA_IPTUN_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_IPTUN_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
-	else
-		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
-
-	if (tb[IFLA_IPTUN_TOS])
-		tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]);
-	if (tos) {
-		if (is_json_context() || tos != 1)
-			print_0xhex(PRINT_ANY, "tos", "tos %#llx ", tos);
+		if (n)
+			fprintf(f, "dev %s ", n);
 		else
-			print_string(PRINT_FP, NULL, "tos %s ", "inherit");
+			fprintf(f, "dev %u ", link);
+	}
+
+	if (tb[IFLA_IPTUN_TTL] && rta_getattr_u8(tb[IFLA_IPTUN_TTL]))
+		fprintf(f, "ttl %d ", rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
+	else
+		fprintf(f, "ttl inherit ");
+
+	if (tb[IFLA_IPTUN_TOS] && rta_getattr_u8(tb[IFLA_IPTUN_TOS])) {
+		int tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]);
+
+		fputs("tos ", f);
+		if (tos == 1)
+			fputs("inherit ", f);
+		else
+			fprintf(f, "0x%x ", tos);
 	}
 
 	if (tb[IFLA_IPTUN_PMTUDISC] && rta_getattr_u8(tb[IFLA_IPTUN_PMTUDISC]))
-		print_bool(PRINT_ANY, "pmtudisc", "pmtudisc ", true);
+		fprintf(f, "pmtudisc ");
 	else
-		print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false);
+		fprintf(f, "nopmtudisc ");
 
 	if (tb[IFLA_IPTUN_FLAGS]) {
 		__u16 iflags = rta_getattr_u16(tb[IFLA_IPTUN_FLAGS]);
 
 		if (iflags & SIT_ISATAP)
-			print_bool(PRINT_ANY, "isatap", "isatap ", true);
+			fprintf(f, "isatap ");
 	}
 
 	if (tb[IFLA_IPTUN_6RD_PREFIXLEN] &&
-	    (prefixlen = rta_getattr_u16(tb[IFLA_IPTUN_6RD_PREFIXLEN]))) {
+	    *(__u16 *)RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIXLEN])) {
+		__u16 prefixlen = rta_getattr_u16(tb[IFLA_IPTUN_6RD_PREFIXLEN]);
 		__u16 relayprefixlen =
 			rta_getattr_u16(tb[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]);
 		__u32 relayprefix =
 			rta_getattr_u32(tb[IFLA_IPTUN_6RD_RELAY_PREFIX]);
 
-		const char *prefix = inet_ntop(AF_INET6,
-					       RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]),
-					       s2, sizeof(s2));
-
-		if (is_json_context()) {
-			print_string(PRINT_JSON, "prefix", NULL, prefix);
-			print_int(PRINT_JSON, "prefixlen", NULL, prefixlen);
-			if (relayprefix) {
-				print_string(PRINT_JSON,
-					     "relay_prefix",
-					     NULL,
-					     format_host(AF_INET,
-							 4,
-							 &relayprefix));
-				print_int(PRINT_JSON,
-					  "relay_prefixlen",
-					  NULL,
-					  relayprefixlen);
-			}
-		} else {
-			printf("6rd-prefix %s/%u ", prefix, prefixlen);
-			if (relayprefix) {
-				printf("6rd-relay_prefix %s/%u ",
-				       format_host(AF_INET, 4, &relayprefix),
-				       relayprefixlen);
-			}
+		printf("6rd-prefix %s/%u ",
+		       inet_ntop(AF_INET6, RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]),
+				 s1, sizeof(s1)),
+		       prefixlen);
+		if (relayprefix) {
+			printf("6rd-relay_prefix %s/%u ",
+			       format_host(AF_INET, 4, &relayprefix, s1,
+					   sizeof(s1)),
+			       relayprefixlen);
 		}
 	}
 
-	if (tb[IFLA_IPTUN_FWMARK]) {
-		__u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
+	if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
+	    *(__u16 *)RTA_DATA(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
+		__u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
+		__u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
+		__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
+		__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
 
-		if (fwmark) {
-			print_0xhex(PRINT_ANY,
-				    "fwmark", "fwmark %#llx ", fwmark);
+		fputs("encap ", f);
+		switch (type) {
+		case TUNNEL_ENCAP_FOU:
+			fputs("fou ", f);
+			break;
+		case TUNNEL_ENCAP_GUE:
+			fputs("gue ", f);
+			break;
+		default:
+			fputs("unknown ", f);
+			break;
 		}
-	}
 
-	tnl_print_encap(tb,
-			IFLA_IPTUN_ENCAP_TYPE,
-			IFLA_IPTUN_ENCAP_FLAGS,
-			IFLA_IPTUN_ENCAP_SPORT,
-			IFLA_IPTUN_ENCAP_DPORT);
+		if (sport == 0)
+			fputs("encap-sport auto ", f);
+		else
+			fprintf(f, "encap-sport %u", ntohs(sport));
+
+		fprintf(f, "encap-dport %u ", ntohs(dport));
+
+		if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+			fputs("encap-csum ", f);
+		else
+			fputs("noencap-csum ", f);
+
+		if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+			fputs("encap-csum6 ", f);
+		else
+			fputs("noencap-csum6 ", f);
+
+		if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+			fputs("encap-remcsum ", f);
+		else
+			fputs("noencap-remcsum ", f);
+	}
+}
+
+static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
+	FILE *f)
+{
+	print_usage(f, strcmp(lu->id, "sit") == 0);
 }
 
 struct link_util ipip_link_util = {
diff --git a/ip/link_veth.c b/ip/link_veth.c
index 33e8f2b..314216c 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -29,47 +29,58 @@
 }
 
 static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
-			  struct nlmsghdr *n)
+			  struct nlmsghdr *hdr)
 {
+	char *dev = NULL;
+	char *name = NULL;
+	char *link = NULL;
 	char *type = NULL;
-	int err;
-	struct rtattr *data;
+	int index = 0;
+	int err, len;
+	struct rtattr * data;
+	int group;
 	struct ifinfomsg *ifm, *peer_ifm;
-	unsigned int ifi_flags, ifi_change, ifi_index;
+	unsigned int ifi_flags, ifi_change;
 
 	if (strcmp(argv[0], "peer") != 0) {
 		usage();
 		return -1;
 	}
 
-	ifm = NLMSG_DATA(n);
+	ifm = NLMSG_DATA(hdr);
 	ifi_flags = ifm->ifi_flags;
 	ifi_change = ifm->ifi_change;
-	ifi_index = ifm->ifi_index;
 	ifm->ifi_flags = 0;
 	ifm->ifi_change = 0;
-	ifm->ifi_index = 0;
 
-	data = addattr_nest(n, 1024, VETH_INFO_PEER);
+	data = NLMSG_TAIL(hdr);
+	addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
 
-	n->nlmsg_len += sizeof(struct ifinfomsg);
+	hdr->nlmsg_len += sizeof(struct ifinfomsg);
 
-	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
+	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
+			   &name, &type, &link, &dev, &group, &index);
 	if (err < 0)
 		return err;
 
-	if (type)
-		duparg("type", argv[err]);
+	if (name) {
+		len = strlen(name) + 1;
+		if (len > IFNAMSIZ)
+			invarg("\"name\" too long\n", *argv);
+		addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
+	}
 
 	peer_ifm = RTA_DATA(data);
-	peer_ifm->ifi_index = ifm->ifi_index;
+	peer_ifm->ifi_index = index;
 	peer_ifm->ifi_flags = ifm->ifi_flags;
 	peer_ifm->ifi_change = ifm->ifi_change;
 	ifm->ifi_flags = ifi_flags;
 	ifm->ifi_change = ifi_change;
-	ifm->ifi_index = ifi_index;
 
-	addattr_nest_end(n, data);
+	if (group != -1)
+		addattr32(hdr, 1024, IFLA_GROUP, group);
+
+	data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
 	return argc - 1 - err;
 }
 
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 3a52ea8..f3fea33 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -23,65 +23,67 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-static void vti_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
+
+static void print_usage(FILE *f)
 {
-	fprintf(f,
-		"Usage: ... %-4s	[ remote ADDR ]\n"
-		"		[ local ADDR ]\n"
-		"		[ [i|o]key KEY ]\n"
-		"		[ dev PHYS_DEV ]\n"
-		"		[ fwmark MARK ]\n"
-		"\n"
-		"Where:	ADDR := { IP_ADDRESS }\n"
-		"	KEY  := { DOTTED_QUAD | NUMBER }\n"
-		"	MARK := { 0x0..0xffffffff }\n",
-		lu->id);
+	fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
+	fprintf(f, "          type { vti } [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(f, "          [ [i|o]key KEY ]\n");
+	fprintf(f, "          [ dev PHYS_DEV ]\n");
+	fprintf(f, "\n");
+	fprintf(f, "Where: NAME := STRING\n");
+	fprintf(f, "       ADDR := { IP_ADDRESS }\n");
+	fprintf(f, "       KEY  := { DOTTED_QUAD | NUMBER }\n");
+}
+
+static void usage(void) __attribute__((noreturn));
+static void usage(void)
+{
+	print_usage(stderr);
+	exit(-1);
 }
 
 static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg i;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-		.i.ifi_index = ifi->ifi_index,
-	};
-	struct nlmsghdr *answer;
+		char buf[1024];
+	} req;
+	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
-	__be32 ikey = 0;
-	__be32 okey = 0;
-	inet_prefix saddr, daddr;
-	unsigned int link = 0;
-	__u32 fwmark = 0;
+	unsigned ikey = 0;
+	unsigned okey = 0;
+	unsigned saddr = 0;
+	unsigned daddr = 0;
+	unsigned link = 0;
 	int len;
 
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
-
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-		const struct rtattr *rta;
+		memset(&req, 0, sizeof(req));
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETLINK;
+		req.i.ifi_family = preferred_family;
+		req.i.ifi_index = ifi->ifi_index;
+
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
 get_failed:
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
 		}
 
-		len = answer->nlmsg_len;
+		len = req.n.nlmsg_len;
 		len -= NLMSG_LENGTH(sizeof(*ifi));
 		if (len < 0)
 			goto get_failed;
 
-		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
+		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
 
 		if (!tb[IFLA_LINKINFO])
 			goto get_failed;
@@ -94,68 +96,100 @@
 		parse_rtattr_nested(vtiinfo, IFLA_VTI_MAX,
 				    linkinfo[IFLA_INFO_DATA]);
 
-		rta = vtiinfo[IFLA_VTI_LOCAL];
-		if (rta && get_addr_rta(&saddr, rta, AF_INET))
-			goto get_failed;
-
-		rta = vtiinfo[IFLA_VTI_REMOTE];
-		if (rta && get_addr_rta(&daddr, rta, AF_INET))
-			goto get_failed;
-
 		if (vtiinfo[IFLA_VTI_IKEY])
-			ikey = rta_getattr_u32(vtiinfo[IFLA_VTI_IKEY]);
+			ikey = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_IKEY]);
 
 		if (vtiinfo[IFLA_VTI_OKEY])
-			okey = rta_getattr_u32(vtiinfo[IFLA_VTI_OKEY]);
+			okey = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_OKEY]);
+
+		if (vtiinfo[IFLA_VTI_LOCAL])
+			saddr = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_LOCAL]);
+
+		if (vtiinfo[IFLA_VTI_REMOTE])
+			daddr = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_REMOTE]);
 
 		if (vtiinfo[IFLA_VTI_LINK])
-			link = rta_getattr_u8(vtiinfo[IFLA_VTI_LINK]);
-
-		if (vtiinfo[IFLA_VTI_FWMARK])
-			fwmark = rta_getattr_u32(vtiinfo[IFLA_VTI_FWMARK]);
-
-		free(answer);
+			link = *(__u8 *)RTA_DATA(vtiinfo[IFLA_VTI_LINK]);
 	}
 
 	while (argc > 0) {
 		if (!matches(*argv, "key")) {
+			unsigned uval;
+
 			NEXT_ARG();
-			ikey = okey = tnl_parse_key("key", *argv);
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr,
+						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+
+			ikey = okey = uval;
 		} else if (!matches(*argv, "ikey")) {
+			unsigned uval;
+
 			NEXT_ARG();
-			ikey = tnl_parse_key("ikey", *argv);
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			ikey = uval;
 		} else if (!matches(*argv, "okey")) {
+			unsigned uval;
+
 			NEXT_ARG();
-			okey = tnl_parse_key("okey", *argv);
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			okey = uval;
 		} else if (!matches(*argv, "remote")) {
 			NEXT_ARG();
-			get_addr(&daddr, *argv, AF_INET);
+			if (!strcmp(*argv, "any")) {
+				fprintf(stderr, "invalid value for \"remote\": \"%s\"\n", *argv);
+				exit(-1);
+			} else {
+				daddr = get_addr32(*argv);
+			}
 		} else if (!matches(*argv, "local")) {
 			NEXT_ARG();
-			get_addr(&saddr, *argv, AF_INET);
+			if (!strcmp(*argv, "any")) {
+				fprintf(stderr, "invalid value for \"local\": \"%s\"\n", *argv);
+				exit(-1);
+			} else {
+				saddr = get_addr32(*argv);
+			}
 		} else if (!matches(*argv, "dev")) {
 			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			NEXT_ARG();
-			if (get_u32(&fwmark, *argv, 0))
-				invarg("invalid fwmark\n", *argv);
-		} else {
-			vti_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
+			link = if_nametoindex(*argv);
+			if (link == 0) {
+				fprintf(stderr, "Cannot find device \"%s\"\n",
+					*argv);
+				exit(-1);
+			}
+		} else
+			usage();
 		argc--; argv++;
 	}
 
 	addattr32(n, 1024, IFLA_VTI_IKEY, ikey);
 	addattr32(n, 1024, IFLA_VTI_OKEY, okey);
-	if (is_addrtype_inet_not_unspec(&saddr))
-		addattr_l(n, 1024, IFLA_VTI_LOCAL, saddr.data, saddr.bytelen);
-	if (is_addrtype_inet_not_unspec(&daddr))
-		addattr_l(n, 1024, IFLA_VTI_REMOTE, daddr.data, daddr.bytelen);
-	addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark);
+	addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, 4);
+	addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, 4);
 	if (link)
 		addattr32(n, 1024, IFLA_VTI_LINK, link);
 
@@ -164,47 +198,57 @@
 
 static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	char s1[1024];
 	char s2[64];
+	const char *local = "any";
+	const char *remote = "any";
 
 	if (!tb)
 		return;
 
-	tnl_print_endpoint("remote", tb[IFLA_VTI_REMOTE], AF_INET);
-	tnl_print_endpoint("local", tb[IFLA_VTI_LOCAL], AF_INET);
+	if (tb[IFLA_VTI_REMOTE]) {
+		unsigned addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]);
 
-	if (tb[IFLA_VTI_LINK]) {
-		__u32 link = rta_getattr_u32(tb[IFLA_VTI_LINK]);
+		if (addr)
+			remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+	}
 
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
+	fprintf(f, "remote %s ", remote);
+
+	if (tb[IFLA_VTI_LOCAL]) {
+		unsigned addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]);
+
+		if (addr)
+			local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+	}
+
+	fprintf(f, "local %s ", local);
+
+	if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) {
+		unsigned link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]);
+		const char *n = if_indextoname(link, s2);
+
+		if (n)
+			fprintf(f, "dev %s ", n);
+		else
+			fprintf(f, "dev %u ", link);
 	}
 
 	if (tb[IFLA_VTI_IKEY]) {
-		struct rtattr *rta = tb[IFLA_VTI_IKEY];
-		__u32 key = rta_getattr_u32(rta);
-
-		if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2)))
-			print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
+		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_IKEY]), s2, sizeof(s2));
+		fprintf(f, "ikey %s ", s2);
 	}
 
 	if (tb[IFLA_VTI_OKEY]) {
-		struct rtattr *rta = tb[IFLA_VTI_OKEY];
-		__u32 key = rta_getattr_u32(rta);
-
-		if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2)))
-			print_string(PRINT_ANY, "okey", "okey %s ", s2);
+		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_OKEY]), s2, sizeof(s2));
+		fprintf(f, "okey %s ", s2);
 	}
+}
 
-	if (tb[IFLA_VTI_FWMARK]) {
-		__u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
-
-		if (fwmark) {
-			print_0xhex(PRINT_ANY,
-				    "fwmark", "fwmark %#llx ", fwmark);
-		}
-	}
+static void vti_print_help(struct link_util *lu, int argc, char **argv,
+	FILE *f)
+{
+	print_usage(f);
 }
 
 struct link_util vti_link_util = {
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index 0b080fa..c146f79 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -24,66 +24,62 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-static void vti6_print_help(struct link_util *lu, int argc, char **argv,
-			    FILE *f)
+
+static void usage(void) __attribute__((noreturn));
+static void usage(void)
 {
-	fprintf(f,
-		"Usage: ... %-4s	[ remote ADDR ]\n"
-		"		[ local ADDR ]\n"
-		"		[ [i|o]key KEY ]\n"
-		"		[ dev PHYS_DEV ]\n"
-		"		[ fwmark MARK ]\n"
-		"\n"
-		"Where:	ADDR := { IPV6_ADDRESS }\n"
-		"	KEY  := { DOTTED_QUAD | NUMBER }\n"
-		"	MARK := { 0x0..0xffffffff }\n",
-		lu->id);
+	fprintf(stderr, "Usage: ip link { add | set | change | replace | del } NAME\n");
+	fprintf(stderr, "          type { vti6 } [ remote ADDR ] [ local ADDR ]\n");
+	fprintf(stderr, "          [ [i|o]key KEY ]\n");
+	fprintf(stderr, "          [ dev PHYS_DEV ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: NAME := STRING\n");
+	fprintf(stderr, "       ADDR := { IPV6_ADDRESS }\n");
+	fprintf(stderr, "       KEY  := { DOTTED_QUAD | NUMBER }\n");
+	exit(-1);
 }
 
 static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
 			  struct nlmsghdr *n)
 {
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
 	struct {
 		struct nlmsghdr n;
 		struct ifinfomsg i;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.i.ifi_family = preferred_family,
-		.i.ifi_index = ifi->ifi_index,
-	};
-	struct nlmsghdr *answer;
+		char buf[1024];
+	} req;
+	struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
 	struct rtattr *tb[IFLA_MAX + 1];
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
 	struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
-	__be32 ikey = 0;
-	__be32 okey = 0;
-	inet_prefix saddr, daddr;
-	unsigned int link = 0;
-	__u32 fwmark = 0;
+	struct in6_addr saddr;
+	struct in6_addr daddr;
+	unsigned ikey = 0;
+	unsigned okey = 0;
+	unsigned link = 0;
 	int len;
 
-	inet_prefix_reset(&saddr);
-	inet_prefix_reset(&daddr);
-
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-		const struct rtattr *rta;
+		memset(&req, 0, sizeof(req));
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
+		req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
+		req.n.nlmsg_flags = NLM_F_REQUEST;
+		req.n.nlmsg_type = RTM_GETLINK;
+		req.i.ifi_family = preferred_family;
+		req.i.ifi_index = ifi->ifi_index;
+
+		if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
 get_failed:
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
 		}
 
-		len = answer->nlmsg_len;
+		len = req.n.nlmsg_len;
 		len -= NLMSG_LENGTH(sizeof(*ifi));
 		if (len < 0)
 			goto get_failed;
 
-		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
+		parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
 
 		if (!tb[IFLA_LINKINFO])
 			goto get_failed;
@@ -96,68 +92,101 @@
 		parse_rtattr_nested(vtiinfo, IFLA_VTI_MAX,
 				    linkinfo[IFLA_INFO_DATA]);
 
-		rta = vtiinfo[IFLA_VTI_LOCAL];
-		if (rta && get_addr_rta(&saddr, rta, AF_INET6))
-			goto get_failed;
-
-		rta = vtiinfo[IFLA_VTI_REMOTE];
-		if (rta && get_addr_rta(&daddr, rta, AF_INET6))
-			goto get_failed;
-
 		if (vtiinfo[IFLA_VTI_IKEY])
 			ikey = rta_getattr_u32(vtiinfo[IFLA_VTI_IKEY]);
 
 		if (vtiinfo[IFLA_VTI_OKEY])
 			okey = rta_getattr_u32(vtiinfo[IFLA_VTI_OKEY]);
 
+		if (vtiinfo[IFLA_VTI_LOCAL])
+			memcpy(&saddr, RTA_DATA(vtiinfo[IFLA_VTI_LOCAL]), sizeof(saddr));
+
+		if (vtiinfo[IFLA_VTI_REMOTE])
+			memcpy(&daddr, RTA_DATA(vtiinfo[IFLA_VTI_REMOTE]), sizeof(daddr));
+
 		if (vtiinfo[IFLA_VTI_LINK])
 			link = rta_getattr_u8(vtiinfo[IFLA_VTI_LINK]);
-
-		if (vtiinfo[IFLA_VTI_FWMARK])
-			fwmark = rta_getattr_u32(vtiinfo[IFLA_VTI_FWMARK]);
-
-		free(answer);
 	}
 
 	while (argc > 0) {
 		if (!matches(*argv, "key")) {
+			unsigned uval;
+
 			NEXT_ARG();
-			ikey = okey = tnl_parse_key("key", *argv);
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr,
+						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+
+			ikey = okey = uval;
 		} else if (!matches(*argv, "ikey")) {
+			unsigned uval;
+
 			NEXT_ARG();
-			ikey = tnl_parse_key("ikey", *argv);
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			ikey = uval;
 		} else if (!matches(*argv, "okey")) {
+			unsigned uval;
+
 			NEXT_ARG();
-			okey = tnl_parse_key("okey", *argv);
+			if (strchr(*argv, '.'))
+				uval = get_addr32(*argv);
+			else {
+				if (get_unsigned(&uval, *argv, 0) < 0) {
+					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
+					exit(-1);
+				}
+				uval = htonl(uval);
+			}
+			okey = uval;
 		} else if (!matches(*argv, "remote")) {
 			NEXT_ARG();
-			get_addr(&daddr, *argv, AF_INET6);
+			if (!strcmp(*argv, "any")) {
+				fprintf(stderr, "invalid value for \"remote\": \"%s\"\n", *argv);
+				exit(-1);
+			} else {
+				inet_prefix addr;
+				get_prefix(&addr, *argv, AF_INET6);
+				memcpy(&daddr, addr.data, addr.bytelen);
+			}
 		} else if (!matches(*argv, "local")) {
 			NEXT_ARG();
-			get_addr(&saddr, *argv, AF_INET6);
+			if (!strcmp(*argv, "any")) {
+				fprintf(stderr, "invalid value for \"local\": \"%s\"\n", *argv);
+				exit(-1);
+			} else {
+				inet_prefix addr;
+				get_prefix(&addr, *argv, AF_INET6);
+				memcpy(&saddr, addr.data, addr.bytelen);
+			}
 		} else if (!matches(*argv, "dev")) {
 			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			NEXT_ARG();
-			if (get_u32(&fwmark, *argv, 0))
-				invarg("invalid fwmark\n", *argv);
-		} else {
-			vti6_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
+			link = if_nametoindex(*argv);
+			if (link == 0)
+				exit(-1);
+		} else
+			usage();
 		argc--; argv++;
 	}
 
 	addattr32(n, 1024, IFLA_VTI_IKEY, ikey);
 	addattr32(n, 1024, IFLA_VTI_OKEY, okey);
-	if (is_addrtype_inet_not_unspec(&saddr))
-		addattr_l(n, 1024, IFLA_VTI_LOCAL, saddr.data, saddr.bytelen);
-	if (is_addrtype_inet_not_unspec(&daddr))
-		addattr_l(n, 1024, IFLA_VTI_REMOTE, daddr.data, daddr.bytelen);
-	addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark);
+	addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, sizeof(saddr));
+	addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, sizeof(daddr));
 	if (link)
 		addattr32(n, 1024, IFLA_VTI_LINK, link);
 
@@ -166,46 +195,50 @@
 
 static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	char s1[1024];
 	char s2[64];
+	const char *local = "any";
+	const char *remote = "any";
+	struct in6_addr saddr;
+	struct in6_addr daddr;
 
 	if (!tb)
 		return;
 
-	tnl_print_endpoint("remote", tb[IFLA_VTI_REMOTE], AF_INET6);
-	tnl_print_endpoint("local", tb[IFLA_VTI_LOCAL], AF_INET6);
+	if (tb[IFLA_VTI_REMOTE]) {
+		memcpy(&daddr, RTA_DATA(tb[IFLA_VTI_REMOTE]), sizeof(daddr));
 
-	if (tb[IFLA_VTI_LINK]) {
-		__u32 link = rta_getattr_u32(tb[IFLA_VTI_LINK]);
+		remote = format_host(AF_INET6, 16, &daddr, s1, sizeof(s1));
+	}
 
-		if (link) {
-			print_string(PRINT_ANY, "link", "dev %s ",
-				     ll_index_to_name(link));
-		}
+	fprintf(f, "remote %s ", remote);
+
+	if (tb[IFLA_VTI_LOCAL]) {
+		memcpy(&saddr, RTA_DATA(tb[IFLA_VTI_LOCAL]), sizeof(saddr));
+
+		local = format_host(AF_INET6, 16, &saddr, s1, sizeof(s1));
+	}
+
+	fprintf(f, "local %s ", local);
+
+	if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) {
+		unsigned link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]);
+		const char *n = if_indextoname(link, s2);
+
+		if (n)
+			fprintf(f, "dev %s ", n);
+		else
+			fprintf(f, "dev %u ", link);
 	}
 
 	if (tb[IFLA_VTI_IKEY]) {
-		struct rtattr *rta = tb[IFLA_VTI_IKEY];
-		__u32 key = rta_getattr_u32(rta);
-
-		if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2)))
-			print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
+		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_IKEY]), s2, sizeof(s2));
+		fprintf(f, "ikey %s ", s2);
 	}
 
 	if (tb[IFLA_VTI_OKEY]) {
-		struct rtattr *rta = tb[IFLA_VTI_OKEY];
-		__u32 key = rta_getattr_u32(rta);
-
-		if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2)))
-			print_string(PRINT_ANY, "okey", "okey %s ", s2);
-	}
-
-	if (tb[IFLA_VTI_FWMARK]) {
-		__u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
-
-		if (fwmark) {
-			print_0xhex(PRINT_ANY,
-				    "fwmark", "fwmark %#llx ", fwmark);
-		}
+		inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_OKEY]), s2, sizeof(s2));
+		fprintf(f, "okey %s ", s2);
 	}
 }
 
@@ -214,5 +247,4 @@
 	.maxattr = IFLA_VTI_MAX,
 	.parse_opt = vti6_parse_opt,
 	.print_opt = vti6_print_opt,
-	.print_help = vti6_print_help,
 };
diff --git a/ip/link_xfrm.c b/ip/link_xfrm.c
deleted file mode 100644
index a28f308..0000000
--- a/ip/link_xfrm.c
+++ /dev/null
@@ -1,76 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * link_xfrm.c	Virtual XFRM Interface driver module
- *
- * Authors:	Matt Ellison <matt@arroyo.io>
- */
-
-#include <string.h>
-#include <linux/if_link.h>
-
-#include "rt_names.h"
-#include "utils.h"
-#include "ip_common.h"
-#include "tunnel.h"
-
-static void xfrm_print_help(struct link_util *lu, int argc, char **argv,
-			    FILE *f)
-{
-	fprintf(f,
-		"Usage: ... %-4s dev [ PHYS_DEV ] [ if_id IF-ID ]\n"
-		"\n"
-		"Where: IF-ID := { 0x0..0xffffffff }\n",
-		lu->id);
-}
-
-static int xfrm_parse_opt(struct link_util *lu, int argc, char **argv,
-			  struct nlmsghdr *n)
-{
-	unsigned int link = 0;
-	__u32 if_id = 0;
-
-	while (argc > 0) {
-		if (!matches(*argv, "dev")) {
-			NEXT_ARG();
-			link = ll_name_to_index(*argv);
-			if (!link)
-				exit(nodev(*argv));
-		} else if (!matches(*argv, "if_id")) {
-			NEXT_ARG();
-			if (!get_u32(&if_id, *argv, 0))
-				addattr32(n, 1024, IFLA_XFRM_IF_ID, if_id);
-		} else {
-			xfrm_print_help(lu, argc, argv, stderr);
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (link)
-		addattr32(n, 1024, IFLA_XFRM_LINK, link);
-
-	return 0;
-}
-
-static void xfrm_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
-{
-
-	if (!tb)
-		return;
-
-	if (tb[IFLA_XFRM_IF_ID]) {
-		__u32 id = rta_getattr_u32(tb[IFLA_XFRM_IF_ID]);
-
-		print_0xhex(PRINT_ANY, "if_id", "if_id %#llx ", id);
-
-	}
-
-}
-
-struct link_util xfrm_link_util = {
-	.id = "xfrm",
-	.maxattr = IFLA_XFRM_MAX,
-	.parse_opt = xfrm_parse_opt,
-	.print_opt = xfrm_print_opt,
-	.print_help = xfrm_print_help,
-};
diff --git a/ip/routef b/ip/routef
index c251e7b..d266e2d 100644
--- a/ip/routef
+++ b/ip/routef
@@ -1,5 +1,4 @@
 #! /bin/sh
-# SPDX-License-Identifier: GPL-2.0
 
 if [ -z "$*" ] ; then
 	exec ip -4 ro flush  scope global  type unicast
diff --git a/ip/routel b/ip/routel
index 7056886..8d1d352 100644
--- a/ip/routel
+++ b/ip/routel
@@ -1,5 +1,5 @@
 #!/bin/sh
-# SPDX-License-Identifier: GPL-2.0
+#$Id$
 
 #
 # Script created by: Stephen R. van den Berg <srb@cuci.nl>, 1999/04/18
@@ -32,22 +32,10 @@
     esac
     while test $# != 0
     do
-       case "$1" in
-          proto|via|dev|scope|src|table)
-             key=$1
-             val=$2
-             eval "$key='$val'"
-             shift 2
-             ;;
-          dead|onlink|pervasive|offload|notify|linkdown|unresolved)
-             shift
-             ;;
-          *)
-             # avoid infinite loop on unknown keyword without value at line end
-             shift
-             shift
-             ;;
-       esac
+       key=$1
+       val=$2
+       eval "$key=$val"
+       shift 2
     done
     echo "$network	$via	$src	$proto	$scope	$dev	$table"
  done | awk -F '	' '
diff --git a/ip/rtm_map.c b/ip/rtm_map.c
index 8d8eafe..1d7d2c7 100644
--- a/ip/rtm_map.c
+++ b/ip/rtm_map.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -23,12 +24,6 @@
 
 char *rtnl_rtntype_n2a(int id, char *buf, int len)
 {
-
-	if (numeric) {
-		snprintf(buf, len, "%d", id);
-		return buf;
-	}
-
 	switch (id) {
 	case RTN_UNSPEC:
 		return "none";
diff --git a/ip/rtmon.c b/ip/rtmon.c
index bccdded..42b24fb 100644
--- a/ip/rtmon.c
+++ b/ip/rtmon.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/time.h>
@@ -24,12 +25,13 @@
 #include "utils.h"
 #include "libnetlink.h"
 
+int resolve_hosts = 0;
 static int init_phase = 1;
 
 static void write_stamp(FILE *fp)
 {
 	char buf[128];
-	struct nlmsghdr *n1 = (void *)buf;
+	struct nlmsghdr *n1 = (void*)buf;
 	struct timeval tv;
 
 	n1->nlmsg_type = NLMSG_TSTAMP;
@@ -38,35 +40,32 @@
 	n1->nlmsg_pid = 0;
 	n1->nlmsg_len = NLMSG_LENGTH(4*2);
 	gettimeofday(&tv, NULL);
-	((__u32 *)NLMSG_DATA(n1))[0] = tv.tv_sec;
-	((__u32 *)NLMSG_DATA(n1))[1] = tv.tv_usec;
-	fwrite((void *)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp);
+	((__u32*)NLMSG_DATA(n1))[0] = tv.tv_sec;
+	((__u32*)NLMSG_DATA(n1))[1] = tv.tv_usec;
+	fwrite((void*)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp);
 }
 
-static int dump_msg(struct rtnl_ctrl_data *ctrl,
+static int dump_msg(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
 		    struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
-
+	FILE *fp = (FILE*)arg;
 	if (!init_phase)
 		write_stamp(fp);
-	fwrite((void *)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp);
+	fwrite((void*)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp);
 	fflush(fp);
 	return 0;
 }
 
-static int dump_msg2(struct nlmsghdr *n, void *arg)
+static int dump_msg2(const struct sockaddr_nl *who,
+		     struct nlmsghdr *n, void *arg)
 {
-	return dump_msg(NULL, n, arg);
+	return dump_msg(who, NULL, n, arg);
 }
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: rtmon [ OPTIONS ] file FILE [ all | LISTofOBJECTS ]\n"
-		"OPTIONS := { -f[amily] { inet | inet6 | link | help } |\n"
-		"	     -4 | -6 | -0 | -V[ersion] }\n"
-		"LISTofOBJECTS := [ link ] [ address ] [ route ]\n");
+	fprintf(stderr, "Usage: rtmon file FILE [ all | LISTofOBJECTS]\n");
+	fprintf(stderr, "LISTofOBJECTS := [ link ] [ address ] [ route ]\n");
 	exit(-1);
 }
 
@@ -76,7 +75,7 @@
 	FILE *fp;
 	struct rtnl_handle rth;
 	int family = AF_UNSPEC;
-	unsigned int groups = ~0U;
+	unsigned groups = ~0U;
 	int llink = 0;
 	int laddr = 0;
 	int lroute = 0;
@@ -116,13 +115,13 @@
 				usage();
 			file = argv[1];
 		} else if (matches(argv[1], "link") == 0) {
-			llink = 1;
+			llink=1;
 			groups = 0;
 		} else if (matches(argv[1], "address") == 0) {
-			laddr = 1;
+			laddr=1;
 			groups = 0;
 		} else if (matches(argv[1], "route") == 0) {
-			lroute = 1;
+			lroute=1;
 			groups = 0;
 		} else if (strcmp(argv[1], "all") == 0) {
 			groups = ~0U;
@@ -163,7 +162,7 @@
 	if (rtnl_open(&rth, groups) < 0)
 		exit(1);
 
-	if (rtnl_linkdump_req(&rth, AF_UNSPEC) < 0) {
+	if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETLINK) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
@@ -177,7 +176,7 @@
 
 	init_phase = 0;
 
-	if (rtnl_listen(&rth, dump_msg, (void *)fp) < 0)
+	if (rtnl_listen(&rth, dump_msg, (void*)fp) < 0)
 		exit(2);
 
 	exit(0);
diff --git a/ip/rtpr b/ip/rtpr
index 7e48674..c3629fd 100644
--- a/ip/rtpr
+++ b/ip/rtpr
@@ -1,5 +1,4 @@
-#! /bin/sh
-# SPDX-License-Identifier: GPL-2.0
+#! /bin/bash
 
 exec tr "[\\\\]" "[
 ]"
diff --git a/ip/static-syms.c b/ip/static-syms.c
index 47c4092..0bc8074 100644
--- a/ip/static-syms.c
+++ b/ip/static-syms.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * This file creates a dummy version of dynamic loading
  * for environments where dynamic linking
diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
index acbd745..57b605f 100644
--- a/ip/tcp_metrics.c
+++ b/ip/tcp_metrics.c
@@ -28,18 +28,16 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage:	ip tcp_metrics/tcpmetrics { COMMAND | help }\n"
-		"	ip tcp_metrics { show | flush } SELECTOR\n"
-		"	ip tcp_metrics delete [ address ] ADDRESS\n"
-		"SELECTOR := [ [ address ] PREFIX ]\n");
+	fprintf(stderr, "Usage: ip tcp_metrics/tcpmetrics { COMMAND | help }\n");
+	fprintf(stderr, "       ip tcp_metrics { show | flush } SELECTOR\n");
+	fprintf(stderr, "       ip tcp_metrics delete [ address ] ADDRESS\n");
+	fprintf(stderr, "SELECTOR := [ [ address ] PREFIX ]\n");
 	exit(-1);
 }
 
 /* netlink socket */
 static struct rtnl_handle grth = { .fd = -1 };
 static int genl_family = -1;
-static const double usec_per_sec = 1000000.;
 
 #define TCPM_REQUEST(_req, _bufsiz, _cmd, _flags) \
 	GENL_REQUEST(_req, _bufsiz, genl_family, 0, \
@@ -49,8 +47,8 @@
 #define CMD_DEL		0x0002	/* delete, remove		*/
 #define CMD_FLUSH	0x0004	/* flush			*/
 
-static const struct {
-	const char *name;
+static struct {
+	char	*name;
 	int	code;
 } cmds[] = {
 	{	"list",		CMD_LIST	},
@@ -61,7 +59,7 @@
 	{	"flush",	CMD_FLUSH	},
 };
 
-static const char *metric_name[TCP_METRIC_MAX + 1] = {
+static char *metric_name[TCP_METRIC_MAX + 1] = {
 	[TCP_METRIC_RTT]		= "rtt",
 	[TCP_METRIC_RTTVAR]		= "rttvar",
 	[TCP_METRIC_SSTHRESH]		= "ssthresh",
@@ -69,7 +67,8 @@
 	[TCP_METRIC_REORDERING]		= "reordering",
 };
 
-static struct {
+static struct
+{
 	int flushed;
 	char *flushb;
 	int flushp;
@@ -89,83 +88,16 @@
 	return 0;
 }
 
-static void print_tcp_metrics(struct rtattr *a)
-{
-	struct rtattr *m[TCP_METRIC_MAX + 1 + 1];
-	unsigned long rtt = 0, rttvar = 0;
-	int i;
-
-	parse_rtattr_nested(m, TCP_METRIC_MAX + 1, a);
-
-	for (i = 0; i < TCP_METRIC_MAX + 1; i++) {
-		const char *name;
-		__u32 val;
-		SPRINT_BUF(b1);
-
-		a = m[i + 1];
-		if (!a)
-			continue;
-
-		val = rta_getattr_u32(a);
-
-		switch (i) {
-		case TCP_METRIC_RTT:
-			if (!rtt)
-				rtt = (val * 1000UL) >> 3;
-			continue;
-		case TCP_METRIC_RTTVAR:
-			if (!rttvar)
-				rttvar = (val * 1000UL) >> 2;
-			continue;
-		case TCP_METRIC_RTT_US:
-			rtt = val >> 3;
-			continue;
-
-		case TCP_METRIC_RTTVAR_US:
-			rttvar = val >> 2;
-			continue;
-
-		case TCP_METRIC_SSTHRESH:
-		case TCP_METRIC_CWND:
-		case TCP_METRIC_REORDERING:
-			name = metric_name[i];
-			break;
-
-		default:
-			snprintf(b1, sizeof(b1),
-				 " metric_%d ", i);
-			name = b1;
-		}
-
-
-		print_uint(PRINT_JSON, name, NULL, val);
-		print_string(PRINT_FP, NULL, " %s ", name);
-		print_uint(PRINT_FP, NULL, "%u", val);
-	}
-
-	if (rtt) {
-		print_float(PRINT_JSON, "rtt", NULL,
-			    (double)rtt / usec_per_sec);
-		print_u64(PRINT_FP, NULL,
-			   " rtt %luus", rtt);
-	}
-	if (rttvar) {
-		print_float(PRINT_JSON, "rttvar", NULL,
-			    (double) rttvar / usec_per_sec);
-		print_u64(PRINT_FP, NULL,
-			   " rttvar %luus", rttvar);
-	}
-}
-
-static int process_msg(struct nlmsghdr *n, void *arg)
+static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		       void *arg)
 {
 	FILE *fp = (FILE *) arg;
 	struct genlmsghdr *ghdr;
 	struct rtattr *attrs[TCP_METRICS_ATTR_MAX + 1], *a;
-	const char *h;
 	int len = n->nlmsg_len;
+	char abuf[256];
 	inet_prefix daddr, saddr;
-	int atype, stype;
+	int family, i, atype, stype, dlen = 0, slen = 0;
 
 	if (n->nlmsg_type != genl_family)
 		return -1;
@@ -181,65 +113,67 @@
 	parse_rtattr(attrs, TCP_METRICS_ATTR_MAX, (void *) ghdr + GENL_HDRLEN,
 		     len);
 
-	if (attrs[TCP_METRICS_ATTR_ADDR_IPV4]) {
+	a = attrs[TCP_METRICS_ATTR_ADDR_IPV4];
+	if (a) {
 		if (f.daddr.family && f.daddr.family != AF_INET)
 			return 0;
-		a = attrs[TCP_METRICS_ATTR_ADDR_IPV4];
-		daddr.family = AF_INET;
+		memcpy(&daddr.data, RTA_DATA(a), 4);
+		daddr.bytelen = 4;
+		family = AF_INET;
 		atype = TCP_METRICS_ATTR_ADDR_IPV4;
-	} else if (attrs[TCP_METRICS_ATTR_ADDR_IPV6]) {
-		if (f.daddr.family && f.daddr.family != AF_INET6)
-			return 0;
-		a = attrs[TCP_METRICS_ATTR_ADDR_IPV6];
-		daddr.family = AF_INET6;
-		atype = TCP_METRICS_ATTR_ADDR_IPV6;
+		dlen = RTA_PAYLOAD(a);
 	} else {
-		return 0;
+		a = attrs[TCP_METRICS_ATTR_ADDR_IPV6];
+		if (a) {
+			if (f.daddr.family && f.daddr.family != AF_INET6)
+				return 0;
+			memcpy(&daddr.data, RTA_DATA(a), 16);
+			daddr.bytelen = 16;
+			family = AF_INET6;
+			atype = TCP_METRICS_ATTR_ADDR_IPV6;
+			dlen = RTA_PAYLOAD(a);
+		} else
+			return 0;
 	}
 
-	if (get_addr_rta(&daddr, a, daddr.family))
-		return 0;
+	a = attrs[TCP_METRICS_ATTR_SADDR_IPV4];
+	if (a) {
+		if (f.saddr.family && f.saddr.family != AF_INET)
+			return 0;
+		memcpy(&saddr.data, RTA_DATA(a), 4);
+		saddr.bytelen = 4;
+		stype = TCP_METRICS_ATTR_SADDR_IPV4;
+		slen = RTA_PAYLOAD(a);
+	} else {
+		a = attrs[TCP_METRICS_ATTR_SADDR_IPV6];
+		if (a) {
+			if (f.saddr.family && f.saddr.family != AF_INET6)
+				return 0;
+			memcpy(&saddr.data, RTA_DATA(a), 16);
+			saddr.bytelen = 16;
+			stype = TCP_METRICS_ATTR_SADDR_IPV6;
+			slen = RTA_PAYLOAD(a);
+		}
+	}
 
 	if (f.daddr.family && f.daddr.bitlen >= 0 &&
 	    inet_addr_match(&daddr, &f.daddr, f.daddr.bitlen))
+	       return 0;
+	/* Only check for the source-address if the kernel supports it,
+	 * meaning slen != 0.
+	 */
+	if (slen && f.saddr.family && f.saddr.bitlen >= 0 &&
+	    inet_addr_match(&saddr, &f.saddr, f.saddr.bitlen))
 		return 0;
 
-	if (attrs[TCP_METRICS_ATTR_SADDR_IPV4]) {
-		if (f.saddr.family && f.saddr.family != AF_INET)
-			return 0;
-		a = attrs[TCP_METRICS_ATTR_SADDR_IPV4];
-		saddr.family = AF_INET;
-		stype = TCP_METRICS_ATTR_SADDR_IPV4;
-	} else if (attrs[TCP_METRICS_ATTR_SADDR_IPV6]) {
-		if (f.saddr.family && f.saddr.family != AF_INET6)
-			return 0;
-		a = attrs[TCP_METRICS_ATTR_SADDR_IPV6];
-		saddr.family = AF_INET6;
-		stype = TCP_METRICS_ATTR_SADDR_IPV6;
-	} else {
-		saddr.family = AF_UNSPEC;
-		stype = 0;
-	}
-
-	/* Only get/check for the source-address if the kernel supports it. */
-	if (saddr.family) {
-		if (get_addr_rta(&saddr, a, saddr.family))
-			return 0;
-
-		if (f.saddr.family && f.saddr.bitlen >= 0 &&
-		    inet_addr_match(&saddr, &f.saddr, f.saddr.bitlen))
-			return 0;
-	}
-
 	if (f.flushb) {
 		struct nlmsghdr *fn;
-
 		TCPM_REQUEST(req2, 128, TCP_METRICS_CMD_DEL, NLM_F_REQUEST);
 
-		addattr_l(&req2.n, sizeof(req2), atype, daddr.data,
+		addattr_l(&req2.n, sizeof(req2), atype, &daddr.data,
 			  daddr.bytelen);
-		if (saddr.family)
-			addattr_l(&req2.n, sizeof(req2), stype, saddr.data,
+		if (slen)
+			addattr_l(&req2.n, sizeof(req2), stype, &saddr.data,
 				  saddr.bytelen);
 
 		if (NLMSG_ALIGN(f.flushp) + req2.n.nlmsg_len > f.flushe) {
@@ -255,60 +189,96 @@
 			return 0;
 	}
 
-	open_json_object(NULL);
 	if (f.cmd & (CMD_DEL | CMD_FLUSH))
-		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+		fprintf(fp, "Deleted ");
 
-	h = format_host(daddr.family, daddr.bytelen, daddr.data);
-	print_color_string(PRINT_ANY,
-			   ifa_family_color(daddr.family),
-			   "dst", "%s", h);
+	fprintf(fp, "%s",
+		format_host(family, dlen, &daddr.data, abuf, sizeof(abuf)));
 
 	a = attrs[TCP_METRICS_ATTR_AGE];
 	if (a) {
-		__u64 val = rta_getattr_u64(a);
-		double age = val / 1000.;
+		unsigned long long val = rta_getattr_u64(a);
 
-		print_float(PRINT_ANY, "age",
-			     " age %.03fsec", age);
+		fprintf(fp, " age %llu.%03llusec",
+			val / 1000, val % 1000);
 	}
 
 	a = attrs[TCP_METRICS_ATTR_TW_TS_STAMP];
 	if (a) {
 		__s32 val = (__s32) rta_getattr_u32(a);
 		__u32 tsval;
-		char tw_ts[64];
 
 		a = attrs[TCP_METRICS_ATTR_TW_TSVAL];
 		tsval = a ? rta_getattr_u32(a) : 0;
-		snprintf(tw_ts, sizeof(tw_ts),
-			 "%u/%d", tsval, val);
-		print_string(PRINT_ANY, "tw_ts_stamp",
-		     " tw_ts %s ago", tw_ts);
+		fprintf(fp, " tw_ts %u/%dsec ago", tsval, val);
 	}
 
-	if (attrs[TCP_METRICS_ATTR_VALS])
-		print_tcp_metrics(attrs[TCP_METRICS_ATTR_VALS]);
+	a = attrs[TCP_METRICS_ATTR_VALS];
+	if (a) {
+		struct rtattr *m[TCP_METRIC_MAX + 1 + 1];
+		unsigned long rtt = 0, rttvar = 0;
+
+		parse_rtattr_nested(m, TCP_METRIC_MAX + 1, a);
+
+		for (i = 0; i < TCP_METRIC_MAX + 1; i++) {
+			unsigned long val;
+
+			a = m[i + 1];
+			if (!a)
+				continue;
+			if (i != TCP_METRIC_RTT &&
+			    i != TCP_METRIC_RTT_US &&
+			    i != TCP_METRIC_RTTVAR &&
+			    i != TCP_METRIC_RTTVAR_US) {
+				if (metric_name[i])
+					fprintf(fp, " %s ", metric_name[i]);
+				else
+					fprintf(fp, " metric_%d ", i);
+			}
+			val = rta_getattr_u32(a);
+			switch (i) {
+			case TCP_METRIC_RTT:
+				if (!rtt)
+					rtt = (val * 1000UL) >> 3;
+				break;
+			case TCP_METRIC_RTTVAR:
+				if (!rttvar)
+					rttvar = (val * 1000UL) >> 2;
+				break;
+			case TCP_METRIC_RTT_US:
+				rtt = val >> 3;
+				break;
+			case TCP_METRIC_RTTVAR_US:
+				rttvar = val >> 2;
+				break;
+			case TCP_METRIC_SSTHRESH:
+			case TCP_METRIC_CWND:
+			case TCP_METRIC_REORDERING:
+			default:
+				fprintf(fp, "%lu", val);
+				break;
+			}
+		}
+		if (rtt)
+			fprintf(fp, " rtt %luus", rtt);
+		if (rttvar)
+			fprintf(fp, " rttvar %luus", rttvar);
+	}
 
 	a = attrs[TCP_METRICS_ATTR_FOPEN_MSS];
-	if (a) {
-		print_uint(PRINT_ANY, "fopen_miss", " fo_mss %u",
-			   rta_getattr_u16(a));
-	}
+	if (a)
+		fprintf(fp, " fo_mss %u", rta_getattr_u16(a));
 
 	a = attrs[TCP_METRICS_ATTR_FOPEN_SYN_DROPS];
 	if (a) {
 		__u16 syn_loss = rta_getattr_u16(a);
-		double ts;
+		unsigned long long ts;
 
 		a = attrs[TCP_METRICS_ATTR_FOPEN_SYN_DROP_TS];
 		ts = a ? rta_getattr_u64(a) : 0;
 
-		print_uint(PRINT_ANY, "fopen_syn_drops",
-			   " fo_syn_drops %u", syn_loss);
-		print_float(PRINT_ANY, "fopen_syn_drop_ts",
-			     "/%.03fusec ago",
-			     ts / 1000000.);
+		fprintf(fp, " fo_syn_drops %u/%llu.%03llusec ago",
+			syn_loss, ts / 1000, ts % 1000);
 	}
 
 	a = attrs[TCP_METRICS_ATTR_FOPEN_COOKIE];
@@ -322,21 +292,17 @@
 		cookie[0] = 0;
 		for (i = 0; i < max; i++)
 			sprintf(cookie + i + i, "%02x", ptr[i]);
-
-		print_string(PRINT_ANY, "fo_cookie",
-			     " fo_cookie %s", cookie);
+		fprintf(fp, " fo_cookie %s", cookie);
 	}
 
-	if (saddr.family) {
-		const char *src;
-
-		src = format_host(saddr.family, saddr.bytelen, saddr.data);
-		print_string(PRINT_ANY, "source",
-			     " source %s", src);
+	if (slen) {
+		fprintf(fp, " source %s",
+			format_host(family, slen, &saddr.data, abuf,
+				    sizeof(abuf)));
 	}
 
-	print_string(PRINT_FP, NULL, "\n", "");
-	close_json_object();
+	fprintf(fp, "\n");
+
 	fflush(fp);
 	return 0;
 }
@@ -344,7 +310,6 @@
 static int tcpm_do_cmd(int cmd, int argc, char **argv)
 {
 	TCPM_REQUEST(req, 1024, TCP_METRICS_CMD_GET, NLM_F_REQUEST);
-	struct nlmsghdr *answer;
 	int atype = -1, stype = -1;
 	int ack;
 
@@ -368,7 +333,6 @@
 		if (strcmp(*argv, "src") == 0 ||
 		    strcmp(*argv, "source") == 0) {
 			char *who = *argv;
-
 			NEXT_ARG();
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -390,7 +354,6 @@
 			}
 		} else {
 			char *who = "address";
-
 			if (strcmp(*argv, "addr") == 0 ||
 			    strcmp(*argv, "address") == 0) {
 				who = *argv;
@@ -437,9 +400,17 @@
 		ack = 0;
 	}
 
-	if (genl_init_handle(&grth, TCP_METRICS_GENL_NAME, &genl_family))
-		exit(1);
-	req.n.nlmsg_type = genl_family;
+	if (genl_family < 0) {
+		if (rtnl_open_byproto(&grth, 0, NETLINK_GENERIC) < 0) {
+			fprintf(stderr, "Cannot open generic netlink socket\n");
+			exit(1);
+		}
+		genl_family = genl_resolve_family(&grth,
+						  TCP_METRICS_GENL_NAME);
+		if (genl_family < 0)
+			exit(1);
+		req.n.nlmsg_type = genl_family;
+	}
 
 	if (!(cmd & CMD_FLUSH) && (atype >= 0 || (cmd & CMD_DEL))) {
 		if (ack)
@@ -496,16 +467,15 @@
 	}
 
 	if (ack) {
-		if (rtnl_talk(&grth, &req.n, NULL) < 0)
+		if (rtnl_talk(&grth, &req.n, NULL, 0) < 0)
 			return -2;
 	} else if (atype >= 0) {
-		if (rtnl_talk(&grth, &req.n, &answer) < 0)
+		if (rtnl_talk(&grth, &req.n, &req.n, sizeof(req)) < 0)
 			return -2;
-		if (process_msg(answer, stdout) < 0) {
+		if (process_msg(NULL, &req.n, stdout) < 0) {
 			fprintf(stderr, "Dump terminated\n");
 			exit(1);
 		}
-		free(answer);
 	} else {
 		req.n.nlmsg_seq = grth.dump = ++grth.seq;
 		if (rtnl_send(&grth, &req, req.n.nlmsg_len) < 0) {
@@ -513,12 +483,10 @@
 			exit(1);
 		}
 
-		new_json_obj(json);
 		if (rtnl_dump_filter(&grth, process_msg, stdout) < 0) {
 			fprintf(stderr, "Dump terminated\n");
 			exit(1);
 		}
-		delete_json_obj();
 	}
 	return 0;
 }
@@ -536,7 +504,7 @@
 	if (matches(argv[0], "help") == 0)
 		usage();
 
-	fprintf(stderr, "Command \"%s\" is unknown, try \"ip tcp_metrics help\".\n",
-			*argv);
+	fprintf(stderr, "Command \"%s\" is unknown, "
+			"try \"ip tcp_metrics help\".\n", *argv);
 	exit(-1);
 }
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 88585cf..39f825b 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -33,30 +33,36 @@
 #include <linux/if.h>
 #include <linux/ip.h>
 #include <linux/if_tunnel.h>
-#include <linux/if_arp.h>
 
 #include "utils.h"
 #include "tunnel.h"
-#include "json_print.h"
 
 const char *tnl_strproto(__u8 proto)
 {
+	static char buf[16];
+
 	switch (proto) {
 	case IPPROTO_IPIP:
-		return "ip";
+		strcpy(buf, "ip");
+		break;
 	case IPPROTO_GRE:
-		return "gre";
+		strcpy(buf, "gre");
+		break;
 	case IPPROTO_IPV6:
-		return "ipv6";
+		strcpy(buf, "ipv6");
+		break;
 	case IPPROTO_ESP:
-		return "esp";
-	case IPPROTO_MPLS:
-		return "mpls";
+		strcpy(buf, "esp");
+		break;
 	case 0:
-		return "any";
+		strcpy(buf, "any");
+		break;
 	default:
-		return "unknown";
+		strcpy(buf, "unknown");
+		break;
 	}
+
+	return buf;
 }
 
 int tnl_get_ioctl(const char *basedev, void *p)
@@ -65,8 +71,8 @@
 	int fd;
 	int err;
 
-	strlcpy(ifr.ifr_name, basedev, IFNAMSIZ);
-	ifr.ifr_ifru.ifru_data = (void *)p;
+	strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
+	ifr.ifr_ifru.ifru_data = (void*)p;
 
 	fd = socket(preferred_family, SOCK_DGRAM, 0);
 	if (fd < 0) {
@@ -90,9 +96,9 @@
 	int err;
 
 	if (cmd == SIOCCHGTUNNEL && name[0])
-		strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+		strncpy(ifr.ifr_name, name, IFNAMSIZ);
 	else
-		strlcpy(ifr.ifr_name, basedev, IFNAMSIZ);
+		strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
 	ifr.ifr_ifru.ifru_data = p;
 
 	fd = socket(preferred_family, SOCK_DGRAM, 0);
@@ -116,9 +122,9 @@
 	int err;
 
 	if (name[0])
-		strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+		strncpy(ifr.ifr_name, name, IFNAMSIZ);
 	else
-		strlcpy(ifr.ifr_name, basedev, IFNAMSIZ);
+		strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
 
 	ifr.ifr_ifru.ifru_data = p;
 
@@ -143,7 +149,7 @@
 	int fd;
 	int err;
 
-	strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+	strncpy(ifr.ifr_name, name, IFNAMSIZ);
 	ifr.ifr_ifru.ifru_data = p;
 
 	fd = socket(preferred_family, SOCK_DGRAM, 0);
@@ -177,276 +183,43 @@
 
 __be32 tnl_parse_key(const char *name, const char *key)
 {
-	unsigned int uval;
+	unsigned uval;
 
 	if (strchr(key, '.'))
 		return get_addr32(key);
 
 	if (get_unsigned(&uval, key, 0) < 0) {
-		fprintf(stderr,
-			"invalid value for \"%s\": \"%s\"; it should be an unsigned integer\n",
-			name, key);
+		fprintf(stderr, "invalid value for \"%s\": \"%s\";", name, key);
+		fprintf(stderr, " it should be an unsigned integer\n");
 		exit(-1);
 	}
 	return htonl(uval);
 }
 
-static const char *tnl_encap_str(const char *name, int enabled, int port)
+/* tnl_print_stats - print tunnel statistics
+ *
+ * @buf - tunnel interface's line in /proc/net/dev,
+ *        starting past the interface name and following colon
+ */
+void tnl_print_stats(const char *buf)
 {
-	static const char ne[][sizeof("no")] = {
-		[0] = "no",
-		[1] = "",
-	};
-	static char buf[32];
-	char b1[16];
-	const char *val;
+	unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
+		      rx_fifo, rx_frame,
+		      tx_bytes, tx_packets, tx_errs, tx_drops,
+		      tx_fifo, tx_colls, tx_carrier, rx_multi;
 
-	if (!port) {
-		val = "auto ";
-	} else if (port < 0) {
-		val = "";
-	} else {
-		snprintf(b1, sizeof(b1), "%u ", port - 1);
-		val = b1;
-	}
-
-	snprintf(buf, sizeof(buf), "%sencap-%s %s", ne[!!enabled], name, val);
-	return buf;
-}
-
-void tnl_print_encap(struct rtattr *tb[],
-		     int encap_type, int encap_flags,
-		     int encap_sport, int encap_dport)
-{
-	__u16 type, flags, sport, dport;
-
-	if (!tb[encap_type])
+	if (sscanf(buf, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
+	           &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
+	           &rx_fifo, &rx_frame, &rx_multi,
+	           &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
+	           &tx_fifo, &tx_colls, &tx_carrier) != 14)
 		return;
 
-	type = rta_getattr_u16(tb[encap_type]);
-	if (type == TUNNEL_ENCAP_NONE)
-		return;
-
-	flags = rta_getattr_u16(tb[encap_flags]);
-	sport = rta_getattr_u16(tb[encap_sport]);
-	dport = rta_getattr_u16(tb[encap_dport]);
-
-	open_json_object("encap");
-	print_string(PRINT_FP, NULL, "encap ", NULL);
-
-	switch (type) {
-	case TUNNEL_ENCAP_FOU:
-		print_string(PRINT_ANY, "type", "%s ", "fou");
-		break;
-	case TUNNEL_ENCAP_GUE:
-		print_string(PRINT_ANY, "type", "%s ", "gue");
-		break;
-	default:
-		print_null(PRINT_ANY, "type", "%s ", "unknown");
-		break;
-	}
-
-	if (is_json_context()) {
-		print_uint(PRINT_JSON, "sport", NULL, ntohs(sport));
-		print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
-		print_bool(PRINT_JSON, "csum", NULL,
-			   flags & TUNNEL_ENCAP_FLAG_CSUM);
-		print_bool(PRINT_JSON, "csum6", NULL,
-			   flags & TUNNEL_ENCAP_FLAG_CSUM6);
-		print_bool(PRINT_JSON, "remcsum", NULL,
-			   flags & TUNNEL_ENCAP_FLAG_REMCSUM);
-		close_json_object();
-	} else {
-		int t;
-
-		t = sport ? ntohs(sport) + 1 : 0;
-		print_string(PRINT_FP, NULL, "%s",
-			     tnl_encap_str("sport", 1, t));
-
-		t = ntohs(dport) + 1;
-		print_string(PRINT_FP, NULL, "%s",
-			     tnl_encap_str("dport", 1, t));
-
-		t = flags & TUNNEL_ENCAP_FLAG_CSUM;
-		print_string(PRINT_FP, NULL, "%s",
-			     tnl_encap_str("csum", t, -1));
-
-		t = flags & TUNNEL_ENCAP_FLAG_CSUM6;
-		print_string(PRINT_FP, NULL, "%s",
-			     tnl_encap_str("csum6", t, -1));
-
-		t = flags & TUNNEL_ENCAP_FLAG_REMCSUM;
-		print_string(PRINT_FP, NULL, "%s",
-			     tnl_encap_str("remcsum", t, -1));
-	}
-}
-
-void tnl_print_endpoint(const char *name, const struct rtattr *rta, int family)
-{
-	const char *value;
-	inet_prefix dst;
-
-	if (!rta) {
-		value = "any";
-	} else if (get_addr_rta(&dst, rta, family)) {
-		value = "unknown";
-	} else if (dst.flags & ADDRTYPE_UNSPEC) {
-		value = "any";
-	} else {
-		value = format_host(family, dst.bytelen, dst.data);
-		if (!value)
-			value = "unknown";
-	}
-
-	if (is_json_context()) {
-		print_string(PRINT_JSON, name, NULL, value);
-	} else {
-		SPRINT_BUF(b1);
-
-		snprintf(b1, sizeof(b1), "%s %%s ", name);
-		print_string(PRINT_FP, NULL, b1, value);
-	}
-}
-
-void tnl_print_gre_flags(__u8 proto,
-			 __be16 i_flags, __be16 o_flags,
-			 __be32 i_key, __be32 o_key)
-{
-	if ((i_flags & GRE_KEY) && (o_flags & GRE_KEY) &&
-	    o_key == i_key) {
-		print_uint(PRINT_ANY, "key", " key %u", ntohl(i_key));
-	} else {
-		if (i_flags & GRE_KEY)
-			print_uint(PRINT_ANY, "ikey", " ikey %u", ntohl(i_key));
-		if (o_flags & GRE_KEY)
-			print_uint(PRINT_ANY, "okey", " okey %u", ntohl(o_key));
-	}
-
-	if (proto != IPPROTO_GRE)
-		return;
-
-	open_json_array(PRINT_JSON, "flags");
-	if (i_flags & GRE_SEQ) {
-		if (is_json_context())
-			print_string(PRINT_JSON, NULL, "%s", "rx_drop_ooseq");
-		else
-			printf("%s  Drop packets out of sequence.", _SL_);
-	}
-	if (i_flags & GRE_CSUM) {
-		if (is_json_context())
-			print_string(PRINT_JSON, NULL, "%s", "rx_csum");
-		else
-			printf("%s  Checksum in received packet is required.", _SL_);
-	}
-	if (o_flags & GRE_SEQ) {
-		if (is_json_context())
-			print_string(PRINT_JSON, NULL, "%s", "tx_seq");
-		else
-			printf("%s  Sequence packets on output.", _SL_);
-	}
-	if (o_flags & GRE_CSUM) {
-		if (is_json_context())
-			print_string(PRINT_JSON, NULL, "%s", "tx_csum");
-		else
-			printf("%s  Checksum output packets.", _SL_);
-	}
-	close_json_array(PRINT_JSON, NULL);
-}
-
-static void tnl_print_stats(const struct rtnl_link_stats64 *s)
-{
 	printf("%s", _SL_);
 	printf("RX: Packets    Bytes        Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
-	printf("    %-10lld %-12lld %-6lld %-8lld %-8lld %-8lld%s",
-	       s->rx_packets, s->rx_bytes, s->rx_errors, s->rx_frame_errors,
-	       s->rx_fifo_errors, s->multicast, _SL_);
+	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
+	       rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
 	printf("TX: Packets    Bytes        Errors DeadLoop NoRoute  NoBufs%s", _SL_);
-	printf("    %-10lld %-12lld %-6lld %-8lld %-8lld %-6lld",
-	       s->tx_packets, s->tx_bytes, s->tx_errors, s->collisions,
-	       s->tx_carrier_errors, s->tx_dropped);
-}
-
-static int print_nlmsg_tunnel(struct nlmsghdr *n, void *arg)
-{
-	struct tnl_print_nlmsg_info *info = arg;
-	struct ifinfomsg *ifi = NLMSG_DATA(n);
-	struct rtattr *tb[IFLA_MAX+1];
-	const char *name, *n1;
-
-	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
-		return 0;
-
-	if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifi)))
-		return -1;
-
-	if (preferred_family == AF_INET) {
-		switch (ifi->ifi_type) {
-		case ARPHRD_TUNNEL:
-		case ARPHRD_IPGRE:
-		case ARPHRD_SIT:
-			break;
-		default:
-			return 0;
-		}
-	} else {
-		switch (ifi->ifi_type) {
-		case ARPHRD_TUNNEL6:
-		case ARPHRD_IP6GRE:
-			break;
-		default:
-			return 0;
-		}
-	}
-
-	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
-
-	if (!tb[IFLA_IFNAME])
-		return 0;
-
-	name = rta_getattr_str(tb[IFLA_IFNAME]);
-
-	/* Assume p1->name[IFNAMSIZ] is first field of structure */
-	n1 = info->p1;
-	if (n1[0] && strcmp(n1, name))
-		return 0;
-
-	info->ifi = ifi;
-	info->init(info);
-
-	/* TODO: parse netlink attributes */
-	if (tnl_get_ioctl(name, info->p2))
-		return 0;
-
-	if (!info->match(info))
-		return 0;
-
-	info->print(info->p2);
-	if (show_stats) {
-		struct rtnl_link_stats64 s;
-
-		if (get_rtnl_link_stats_rta(&s, tb) <= 0)
-			return -1;
-
-		tnl_print_stats(&s);
-	}
-	fputc('\n', stdout);
-
-	return 0;
-}
-
-int do_tunnels_list(struct tnl_print_nlmsg_info *info)
-{
-	new_json_obj(json);
-	if (rtnl_linkdump_req(&rth, preferred_family) < 0) {
-		perror("Cannot send dump request\n");
-		return -1;
-	}
-
-	if (rtnl_dump_filter(&rth, print_nlmsg_tunnel, info) < 0) {
-		fprintf(stderr, "Dump terminated\n");
-		return -1;
-	}
-	delete_json_obj();
-
-	return 0;
+	printf("    %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
+	       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
 }
diff --git a/ip/tunnel.h b/ip/tunnel.h
index 604f8cb..9a03c0d 100644
--- a/ip/tunnel.h
+++ b/ip/tunnel.h
@@ -21,26 +21,8 @@
 #ifndef __TUNNEL_H__
 #define __TUNNEL_H__ 1
 
-#include <stdbool.h>
 #include <linux/types.h>
 
-struct rtattr;
-struct ifinfomsg;
-
-extern struct rtnl_handle rth;
-
-struct tnl_print_nlmsg_info {
-	const struct ifinfomsg *ifi;
-	const void *p1;
-	void *p2;
-
-	void (*init)(const struct tnl_print_nlmsg_info *info);
-	bool (*match)(const struct tnl_print_nlmsg_info *info);
-	void (*print)(const void *t);
-};
-
-int do_tunnels_list(struct tnl_print_nlmsg_info *info);
-
 const char *tnl_strproto(__u8 proto);
 
 int tnl_get_ioctl(const char *basedev, void *p);
@@ -50,13 +32,6 @@
 int tnl_6rd_ioctl(int cmd, const char *name, void *p);
 int tnl_ioctl_get_6rd(const char *name, void *p);
 __be32 tnl_parse_key(const char *name, const char *key);
-void tnl_print_encap(struct rtattr *tb[],
-		     int encap_type, int encap_flags,
-		     int encap_sport, int encap_dport);
-void tnl_print_endpoint(const char *name,
-			const struct rtattr *rta, int family);
-void tnl_print_gre_flags(__u8 proto,
-			 __be16 i_flags, __be16 o_flags,
-			 __be32 i_key, __be32 o_key);
+void tnl_print_stats(const char *buf);
 
 #endif
diff --git a/ip/xfrm.h b/ip/xfrm.h
index 9ba5ca6..773c92e 100644
--- a/ip/xfrm.h
+++ b/ip/xfrm.h
@@ -26,12 +26,16 @@
 
 #include <stdio.h>
 #include <sys/socket.h>
-#include <linux/in.h>
 #include <linux/xfrm.h>
-#include <linux/ipsec.h>
 
+#ifndef IPPROTO_SCTP
+# define IPPROTO_SCTP	132
+#endif
+#ifndef IPPROTO_DCCP
+# define IPPROTO_DCCP	33
+#endif
 #ifndef IPPROTO_MH
-#define IPPROTO_MH              135
+# define IPPROTO_MH	135
 #endif
 
 #define XFRMS_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
@@ -94,7 +98,6 @@
 	__u8 action_mask;
 	__u32 priority_mask;
 	__u8 policy_flags_mask;
-	__u8 filter_socket;
 
 	__u8 ptype;
 	__u8 ptype_mask;
@@ -104,9 +107,10 @@
 
 extern struct xfrm_filter filter;
 
-int xfrm_state_print(struct nlmsghdr *n, void *arg);
-int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg);
-int xfrm_policy_print(struct nlmsghdr *n, void *arg);
+int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		     void *arg);
+int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		      void *arg);
 int do_xfrm_state(int argc, char **argv);
 int do_xfrm_policy(int argc, char **argv);
 int do_xfrm_monitor(int argc, char **argv);
@@ -119,16 +123,25 @@
 int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp);
 const char *strxf_xfrmproto(__u8 proto);
 const char *strxf_algotype(int type);
+const char *strxf_mask8(__u8 mask);
 const char *strxf_mask32(__u32 mask);
+const char *strxf_share(__u8 share);
 const char *strxf_proto(__u8 proto);
 const char *strxf_ptype(__u8 ptype);
+void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
+			__u8 mode, __u32 reqid, __u16 family, int force_spi,
+			FILE *fp, const char *prefix, const char *title);
+void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix);
+void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
+			 struct xfrm_lifetime_cur *cur,
+			 FILE *fp, const char *prefix);
 void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
 			 FILE *fp, const char *prefix);
 void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
-		      FILE *fp, const char *prefix, bool nokeys);
+		      FILE *fp, const char *prefix);
 void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
 			    struct rtattr *tb[], FILE *fp, const char *prefix,
-			   const char *title, bool nokeys);
+			   const char *title);
 void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
 			    struct rtattr *tb[], FILE *fp, const char *prefix,
 			    const char *title);
diff --git a/ip/xfrm_monitor.c b/ip/xfrm_monitor.c
index e34b5fb..e6e991a 100644
--- a/ip/xfrm_monitor.c
+++ b/ip/xfrm_monitor.c
@@ -34,23 +34,22 @@
 #include "ip_common.h"
 
 static void usage(void) __attribute__((noreturn));
-static int listen_all_nsid;
-static bool nokeys;
+int listen_all_nsid;
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip xfrm monitor [ nokeys ] [ all-nsid ] [ all | OBJECTS | help ]\n"
-		"OBJECTS := { acquire | expire | SA | aevent | policy | report }\n");
+	fprintf(stderr, "Usage: ip xfrm monitor [all-nsid] [ all | OBJECTS | help ]\n");
+	fprintf(stderr, "OBJECTS := { acquire | expire | SA | aevent | policy | report }\n");
 	exit(-1);
 }
 
-static int xfrm_acquire_print(struct nlmsghdr *n, void *arg)
+static int xfrm_acquire_print(const struct sockaddr_nl *who,
+			      struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct xfrm_user_acquire *xacq = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[XFRMA_MAX+1];
+	struct rtattr * tb[XFRMA_MAX+1];
 	__u16 family;
 
 	len -= NLMSG_LENGTH(sizeof(*xacq));
@@ -72,7 +71,6 @@
 	fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto));
 	if (show_stats > 0 || xacq->id.spi) {
 		__u32 spi = ntohl(xacq->id.spi);
-
 		fprintf(fp, "spi 0x%08x", spi);
 		if (show_stats > 0)
 			fprintf(fp, "(%u)", spi);
@@ -106,9 +104,10 @@
 	return 0;
 }
 
-static int xfrm_state_flush_print(struct nlmsghdr *n, void *arg)
+static int xfrm_state_flush_print(const struct sockaddr_nl *who,
+				  struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct xfrm_usersa_flush *xsf = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
 	const char *str;
@@ -135,10 +134,11 @@
 	return 0;
 }
 
-static int xfrm_policy_flush_print(struct nlmsghdr *n, void *arg)
+static int xfrm_policy_flush_print(const struct sockaddr_nl *who,
+				   struct nlmsghdr *n, void *arg)
 {
-	struct rtattr *tb[XFRMA_MAX+1];
-	FILE *fp = (FILE *)arg;
+	struct rtattr * tb[XFRMA_MAX+1];
+	FILE *fp = (FILE*)arg;
 	int len = n->nlmsg_len;
 
 	len -= NLMSG_SPACE(0);
@@ -159,7 +159,7 @@
 		if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
 			fprintf(fp, "(ERROR truncated)");
 
-		upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
+		upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
 		fprintf(fp, "%s ", strxf_ptype(upt->type));
 	}
 
@@ -172,12 +172,13 @@
 	return 0;
 }
 
-static int xfrm_report_print(struct nlmsghdr *n, void *arg)
+static int xfrm_report_print(const struct sockaddr_nl *who,
+			     struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct xfrm_user_report *xrep = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[XFRMA_MAX+1];
+	struct rtattr * tb[XFRMA_MAX+1];
 	__u16 family;
 
 	len -= NLMSG_LENGTH(sizeof(*xrep));
@@ -199,7 +200,7 @@
 
 	parse_rtattr(tb, XFRMA_MAX, XFRMREP_RTA(xrep), len);
 
-	xfrm_xfrma_print(tb, family, fp, "  ", nokeys);
+	xfrm_xfrma_print(tb, family, fp, "  ");
 
 	if (oneline)
 		fprintf(fp, "\n");
@@ -209,8 +210,7 @@
 
 static void xfrm_ae_flags_print(__u32 flags, void *arg)
 {
-	FILE *fp = (FILE *)arg;
-
+	FILE *fp = (FILE*)arg;
 	fprintf(fp, " (0x%x) ", flags);
 	if (!flags)
 		return;
@@ -225,8 +225,12 @@
 
 static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp)
 {
+	char buf[256];
+
+	buf[0] = 0;
 	fprintf(fp, "dst %s ",
-		rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr));
+		rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr,
+			    buf, sizeof(buf)));
 
 	fprintf(fp, " reqid 0x%x", reqid);
 
@@ -234,16 +238,20 @@
 	fprintf(fp, " SPI 0x%x", ntohl(sa_id->spi));
 }
 
-static int xfrm_ae_print(struct nlmsghdr *n, void *arg)
+static int xfrm_ae_print(const struct sockaddr_nl *who,
+			     struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct xfrm_aevent_id *id = NLMSG_DATA(n);
+	char abuf[256];
 
 	fprintf(fp, "Async event ");
 	xfrm_ae_flags_print(id->flags, arg);
-	fprintf(fp, "\n\t");
+	fprintf(fp,"\n\t");
+	memset(abuf, '\0', sizeof(abuf));
 	fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
-					   sizeof(id->saddr), &id->saddr));
+					   sizeof(id->saddr), &id->saddr,
+					   abuf, sizeof(abuf)));
 
 	xfrm_usersa_print(&id->sa_id, id->reqid, fp);
 
@@ -255,12 +263,16 @@
 
 static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
 {
-	fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a));
+	char buf[256];
+
+	buf[0] = 0;
+	fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a, buf, sizeof(buf)));
 }
 
-static int xfrm_mapping_print(struct nlmsghdr *n, void *arg)
+static int xfrm_mapping_print(const struct sockaddr_nl *who,
+			     struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct xfrm_user_mapping *map = NLMSG_DATA(n);
 
 	fprintf(fp, "Mapping change ");
@@ -277,10 +289,11 @@
 	return 0;
 }
 
-static int xfrm_accept_msg(struct rtnl_ctrl_data *ctrl,
+static int xfrm_accept_msg(const struct sockaddr_nl *who,
+			   struct rtnl_ctrl_data *ctrl,
 			   struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 
 	if (timestamp)
 		print_timestamp(fp);
@@ -297,31 +310,31 @@
 	case XFRM_MSG_DELSA:
 	case XFRM_MSG_UPDSA:
 	case XFRM_MSG_EXPIRE:
-		xfrm_state_print(n, arg);
+		xfrm_state_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_NEWPOLICY:
 	case XFRM_MSG_DELPOLICY:
 	case XFRM_MSG_UPDPOLICY:
 	case XFRM_MSG_POLEXPIRE:
-		xfrm_policy_print(n, arg);
+		xfrm_policy_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_ACQUIRE:
-		xfrm_acquire_print(n, arg);
+		xfrm_acquire_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_FLUSHSA:
-		xfrm_state_flush_print(n, arg);
+		xfrm_state_flush_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_FLUSHPOLICY:
-		xfrm_policy_flush_print(n, arg);
+		xfrm_policy_flush_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_REPORT:
-		xfrm_report_print(n, arg);
+		xfrm_report_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_NEWAE:
-		xfrm_ae_print(n, arg);
+		xfrm_ae_print(who, n, arg);
 		return 0;
 	case XFRM_MSG_MAPPING:
-		xfrm_mapping_print(n, arg);
+		xfrm_mapping_print(who, n, arg);
 		return 0;
 	default:
 		break;
@@ -340,13 +353,13 @@
 int do_xfrm_monitor(int argc, char **argv)
 {
 	char *file = NULL;
-	unsigned int groups = ~((unsigned)0); /* XXX */
-	int lacquire = 0;
-	int lexpire = 0;
-	int laevent = 0;
-	int lpolicy = 0;
-	int lsa = 0;
-	int lreport = 0;
+	unsigned groups = ~((unsigned)0); /* XXX */
+	int lacquire=0;
+	int lexpire=0;
+	int laevent=0;
+	int lpolicy=0;
+	int lsa=0;
+	int lreport=0;
 
 	rtnl_close(&rth);
 
@@ -354,33 +367,29 @@
 		if (matches(*argv, "file") == 0) {
 			NEXT_ARG();
 			file = *argv;
-		} else if (strcmp(*argv, "nokeys") == 0) {
-			nokeys = true;
-		} else if (strcmp(*argv, "all") == 0) {
-			/* fall out */
 		} else if (matches(*argv, "all-nsid") == 0) {
 			listen_all_nsid = 1;
 		} else if (matches(*argv, "acquire") == 0) {
-			lacquire = 1;
+			lacquire=1;
 			groups = 0;
 		} else if (matches(*argv, "expire") == 0) {
-			lexpire = 1;
+			lexpire=1;
 			groups = 0;
 		} else if (matches(*argv, "SA") == 0) {
-			lsa = 1;
+			lsa=1;
 			groups = 0;
 		} else if (matches(*argv, "aevent") == 0) {
-			laevent = 1;
+			laevent=1;
 			groups = 0;
 		} else if (matches(*argv, "policy") == 0) {
-			lpolicy = 1;
+			lpolicy=1;
 			groups = 0;
 		} else if (matches(*argv, "report") == 0) {
-			lreport = 1;
+			lreport=1;
 			groups = 0;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
-		} else {
+		} else if (strcmp(*argv, "all")) {
 			fprintf(stderr, "Argument \"%s\" is unknown, try \"ip xfrm monitor help\".\n", *argv);
 			exit(-1);
 		}
@@ -419,7 +428,7 @@
 	if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
 		exit(1);
 
-	if (rtnl_listen(&rth, xfrm_accept_msg, (void *)stdout) < 0)
+	if (rtnl_listen(&rth, xfrm_accept_msg, (void*)stdout) < 0)
 		exit(2);
 
 	return 0;
diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c
index 7c0233c..efea1e8 100644
--- a/ip/xfrm_policy.c
+++ b/ip/xfrm_policy.c
@@ -33,7 +33,7 @@
 #include "xfrm.h"
 #include "ip_common.h"
 
-/* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
+//#define NLMSG_DELETEALL_BUF_SIZE (4096-512)
 #define NLMSG_DELETEALL_BUF_SIZE 8192
 
 /*
@@ -52,60 +52,51 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip xfrm policy { add | update } SELECTOR dir DIR [ ctx CTX ]\n"
-		"	[ mark MARK [ mask MASK ] ] [ index INDEX ] [ ptype PTYPE ]\n"
-		"	[ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ]\n"
-		"	[ if_id IF_ID ] [ LIMIT-LIST ] [ TMPL-LIST ]\n"
-		"Usage: ip xfrm policy { delete | get } { SELECTOR | index INDEX } dir DIR\n"
-		"	[ ctx CTX ] [ mark MARK [ mask MASK ] ] [ ptype PTYPE ]\n"
-		"Usage: ip xfrm policy { deleteall | list } [ nosock ] [ SELECTOR ] [ dir DIR ]\n"
-		"	[ index INDEX ] [ ptype PTYPE ] [ action ACTION ] [ priority PRIORITY ]\n"
-		"	[ flag FLAG-LIST ]\n"
-		"Usage: ip xfrm policy flush [ ptype PTYPE ]\n"
-		"Usage: ip xfrm policy count\n"
-		"Usage: ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]\n"
-		"SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n"
-		"UPSPEC := proto { { ");
-	fprintf(stderr, "%s | %s | %s | %s } ",
-		strxf_proto(IPPROTO_TCP),
-		strxf_proto(IPPROTO_UDP),
-		strxf_proto(IPPROTO_SCTP),
-		strxf_proto(IPPROTO_DCCP));
-	fprintf(stderr,
-		"[ sport PORT ] [ dport PORT ] |\n"
-		"                  { %s | %s | %s } ",
-		strxf_proto(IPPROTO_ICMP),
-		strxf_proto(IPPROTO_ICMPV6),
-		strxf_proto(IPPROTO_MH));
-	fprintf(stderr,
-		"[ type NUMBER ] [ code NUMBER ] |\n"
-		"                  %s",
-		strxf_proto(IPPROTO_GRE));
-	fprintf(stderr,
-		" [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n"
-		"DIR := in | out | fwd\n"
-		"PTYPE := main | sub\n"
-		"ACTION := allow | block\n"
-		"FLAG-LIST := [ FLAG-LIST ] FLAG\n"
-		"FLAG := localok | icmp\n"
-		"LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n"
-		"LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n"
-		"         { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n"
-		"TMPL-LIST := [ TMPL-LIST ] tmpl TMPL\n"
-		"TMPL := ID [ mode MODE ] [ reqid REQID ] [ level LEVEL ]\n"
-		"ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n"
-		"XFRM-PROTO := ");
-	fprintf(stderr,
-		"%s | %s | %s | %s | %s\n",
-		strxf_xfrmproto(IPPROTO_ESP),
-		strxf_xfrmproto(IPPROTO_AH),
-		strxf_xfrmproto(IPPROTO_COMP),
-		strxf_xfrmproto(IPPROTO_ROUTING),
-		strxf_xfrmproto(IPPROTO_DSTOPTS));
-	fprintf(stderr,
-		"MODE := transport | tunnel | beet | ro | in_trigger\n"
-		"LEVEL := required | use\n");
+	fprintf(stderr, "Usage: ip xfrm policy { add | update } SELECTOR dir DIR [ ctx CTX ]\n");
+	fprintf(stderr, "        [ mark MARK [ mask MASK ] ] [ index INDEX ] [ ptype PTYPE ]\n");
+	fprintf(stderr, "        [ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ]\n");
+	fprintf(stderr, "        [ LIMIT-LIST ] [ TMPL-LIST ]\n");
+	fprintf(stderr, "Usage: ip xfrm policy { delete | get } { SELECTOR | index INDEX } dir DIR\n");
+	fprintf(stderr, "        [ ctx CTX ] [ mark MARK [ mask MASK ] ] [ ptype PTYPE ]\n");
+	fprintf(stderr, "Usage: ip xfrm policy { deleteall | list } [ SELECTOR ] [ dir DIR ]\n");
+	fprintf(stderr, "        [ index INDEX ] [ ptype PTYPE ] [ action ACTION ] [ priority PRIORITY ]\n");
+	fprintf(stderr, "        [ flag FLAG-LIST ]\n");
+	fprintf(stderr, "Usage: ip xfrm policy flush [ ptype PTYPE ]\n");
+	fprintf(stderr, "Usage: ip xfrm policy count\n");
+	fprintf(stderr, "Usage: ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]\n");
+	fprintf(stderr, "SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n");
+	fprintf(stderr, "UPSPEC := proto { { ");
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_TCP));
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_UDP));
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_SCTP));
+	fprintf(stderr, "%s", strxf_proto(IPPROTO_DCCP));
+	fprintf(stderr, " } [ sport PORT ] [ dport PORT ] |\n");
+	fprintf(stderr, "                  { ");
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMP));
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMPV6));
+	fprintf(stderr, "%s", strxf_proto(IPPROTO_MH));
+	fprintf(stderr, " } [ type NUMBER ] [ code NUMBER ] |\n");
+	fprintf(stderr, "                  %s", strxf_proto(IPPROTO_GRE));
+	fprintf(stderr, " [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n");
+	fprintf(stderr, "DIR := in | out | fwd\n");
+	fprintf(stderr, "PTYPE := main | sub\n");
+	fprintf(stderr, "ACTION := allow | block\n");
+	fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n");
+	fprintf(stderr, "FLAG := localok | icmp\n");
+	fprintf(stderr, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n");
+	fprintf(stderr, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n");
+	fprintf(stderr, "         { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n");
+	fprintf(stderr, "TMPL-LIST := [ TMPL-LIST ] tmpl TMPL\n");
+	fprintf(stderr, "TMPL := ID [ mode MODE ] [ reqid REQID ] [ level LEVEL ]\n");
+	fprintf(stderr, "ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n");
+	fprintf(stderr, "XFRM-PROTO := ");
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ESP));
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_AH));
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_COMP));
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ROUTING));
+	fprintf(stderr, "%s\n", strxf_xfrmproto(IPPROTO_DSTOPTS));
+	fprintf(stderr, "MODE := transport | tunnel | beet | ro | in_trigger\n");
+	fprintf(stderr, "LEVEL := required | use\n");
 
 	exit(-1);
 }
@@ -250,37 +241,41 @@
 	return 0;
 }
 
-static int xfrm_policy_modify(int cmd, unsigned int flags, int argc, char **argv)
+static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
 {
 	struct rtnl_handle rth;
 	struct {
 		struct nlmsghdr			n;
 		struct xfrm_userpolicy_info	xpinfo;
 		char				buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpinfo)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.xpinfo.sel.family = preferred_family,
-		.xpinfo.lft.soft_byte_limit = XFRM_INF,
-		.xpinfo.lft.hard_byte_limit = XFRM_INF,
-		.xpinfo.lft.soft_packet_limit = XFRM_INF,
-		.xpinfo.lft.hard_packet_limit = XFRM_INF,
-	};
+	} req;
 	char *dirp = NULL;
 	char *selp = NULL;
 	char *ptypep = NULL;
 	char *sctxp = NULL;
-	struct xfrm_userpolicy_type upt = {};
-	char tmpls_buf[XFRM_TMPLS_BUF_SIZE] = {};
+	struct xfrm_userpolicy_type upt;
+	char tmpls_buf[XFRM_TMPLS_BUF_SIZE];
 	int tmpls_len = 0;
 	struct xfrm_mark mark = {0, 0};
 	struct {
 		struct xfrm_user_sec_ctx sctx;
 		char	str[CTX_BUF_SIZE];
-	} ctx = {};
-	bool is_if_id_set = false;
-	__u32 if_id = 0;
+	} ctx;
+
+	memset(&req, 0, sizeof(req));
+	memset(&upt, 0, sizeof(upt));
+	memset(&tmpls_buf, 0, sizeof(tmpls_buf));
+	memset(&ctx, 0, sizeof(ctx));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpinfo));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.xpinfo.sel.family = preferred_family;
+
+	req.xpinfo.lft.soft_byte_limit = XFRM_INF;
+	req.xpinfo.lft.hard_byte_limit = XFRM_INF;
+	req.xpinfo.lft.soft_packet_limit = XFRM_INF;
+	req.xpinfo.lft.hard_packet_limit = XFRM_INF;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dir") == 0) {
@@ -349,11 +344,6 @@
 			xfrm_tmpl_parse(tmpl, &argc, &argv);
 
 			tmpls_len += sizeof(*tmpl);
-		} else if (strcmp(*argv, "if_id") == 0) {
-			NEXT_ARG();
-			if (get_u32(&if_id, *argv, 0))
-				invarg("IF_ID value is invalid", *argv);
-			is_if_id_set = true;
 		} else {
 			if (selp)
 				duparg("unknown", *argv);
@@ -386,7 +376,7 @@
 		int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK,
 				  (void *)&mark, sizeof(mark));
 		if (r < 0) {
-			fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
+			fprintf(stderr, "%s: XFRMA_MARK failed\n",__func__);
 			exit(1);
 		}
 	}
@@ -396,16 +386,13 @@
 			  (void *)&ctx, ctx.sctx.len);
 	}
 
-	if (is_if_id_set)
-		addattr32(&req.n, sizeof(req.buf), XFRMA_IF_ID, if_id);
-
 	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
 		exit(1);
 
 	if (req.xpinfo.sel.family == AF_UNSPEC)
 		req.xpinfo.sel.family = AF_INET;
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	rtnl_close(&rth);
@@ -419,16 +406,9 @@
 	if (!filter.use)
 		return 1;
 
-	if (filter.xpinfo.sel.family != AF_UNSPEC &&
-	    filter.xpinfo.sel.family != xpinfo->sel.family)
-		return 0;
-
 	if ((xpinfo->dir^filter.xpinfo.dir)&filter.dir_mask)
 		return 0;
 
-	if (filter.filter_socket && (xpinfo->dir >= XFRM_POLICY_MAX))
-		return 0;
-
 	if ((ptype^filter.ptype)&filter.ptype_mask)
 		return 0;
 
@@ -476,15 +456,16 @@
 	return 1;
 }
 
-int xfrm_policy_print(struct nlmsghdr *n, void *arg)
+int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		      void *arg)
 {
-	struct rtattr *tb[XFRMA_MAX+1];
-	struct rtattr *rta;
+	struct rtattr * tb[XFRMA_MAX+1];
+	struct rtattr * rta;
 	struct xfrm_userpolicy_info *xpinfo = NULL;
 	struct xfrm_user_polexpire *xpexp = NULL;
 	struct xfrm_userpolicy_id *xpid = NULL;
 	__u8 ptype = XFRM_POLICY_TYPE_MAIN;
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	int len = n->nlmsg_len;
 
 	if (n->nlmsg_type != XFRM_MSG_NEWPOLICY &&
@@ -530,7 +511,7 @@
 			fprintf(stderr, "too short XFRMA_POLICY_TYPE len\n");
 			return -1;
 		}
-		upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
+		upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
 		ptype = upt->type;
 	}
 
@@ -545,7 +526,7 @@
 		fprintf(fp, "Expired ");
 
 	if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
-		/* xfrm_policy_id_print(); */
+		//xfrm_policy_id_print();
 		if (!tb[XFRMA_POLICY]) {
 			fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n");
 			return -1;
@@ -554,7 +535,7 @@
 			fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
 			return -1;
 		}
-		xpinfo = RTA_DATA(tb[XFRMA_POLICY]);
+		xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]);
 	}
 
 	xfrm_policy_info_print(xpinfo, tb, fp, NULL, NULL);
@@ -573,30 +554,34 @@
 }
 
 static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
-				     struct nlmsghdr **answer)
+				     void *res_nlbuf, size_t res_size)
 {
 	struct rtnl_handle rth;
 	struct {
 		struct nlmsghdr			n;
 		struct xfrm_userpolicy_id	xpid;
 		char				buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpid)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = delete ? XFRM_MSG_DELPOLICY
-				       : XFRM_MSG_GETPOLICY,
-	};
+	} req;
 	char *dirp = NULL;
 	char *selp = NULL;
 	char *indexp = NULL;
 	char *ptypep = NULL;
 	char *sctxp = NULL;
-	struct xfrm_userpolicy_type upt = {};
+	struct xfrm_userpolicy_type upt;
 	struct xfrm_mark mark = {0, 0};
 	struct {
 		struct xfrm_user_sec_ctx sctx;
 		char    str[CTX_BUF_SIZE];
-	} ctx = {};
+	} ctx;
+
+
+	memset(&req, 0, sizeof(req));
+	memset(&upt, 0, sizeof(upt));
+	memset(&ctx, 0, sizeof(ctx));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpid));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = delete ? XFRM_MSG_DELPOLICY : XFRM_MSG_GETPOLICY;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dir") == 0) {
@@ -674,7 +659,7 @@
 		int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK,
 				  (void *)&mark, sizeof(mark));
 		if (r < 0) {
-			fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
+			fprintf(stderr, "%s: XFRMA_MARK failed\n",__func__);
 			exit(1);
 		}
 	}
@@ -684,7 +669,7 @@
 			  (void *)&ctx, ctx.sctx.len);
 	}
 
-	if (rtnl_talk(&rth, &req.n, answer) < 0)
+	if (rtnl_talk(&rth, &req.n, res_nlbuf, res_size) < 0)
 		exit(2);
 
 	rtnl_close(&rth);
@@ -694,21 +679,23 @@
 
 static int xfrm_policy_delete(int argc, char **argv)
 {
-	return xfrm_policy_get_or_delete(argc, argv, 1, NULL);
+	return xfrm_policy_get_or_delete(argc, argv, 1, NULL, 0);
 }
 
 static int xfrm_policy_get(int argc, char **argv)
 {
-	struct nlmsghdr *n = NULL;
+	char buf[NLMSG_BUF_SIZE];
+	struct nlmsghdr *n = (struct nlmsghdr *)buf;
 
-	xfrm_policy_get_or_delete(argc, argv, 0, &n);
+	memset(buf, 0, sizeof(buf));
 
-	if (xfrm_policy_print(n, (void *)stdout) < 0) {
+	xfrm_policy_get_or_delete(argc, argv, 0, n, sizeof(buf));
+
+	if (xfrm_policy_print(NULL, n, (void*)stdout) < 0) {
 		fprintf(stderr, "An error :-)\n");
 		exit(1);
 	}
 
-	free(n);
 	return 0;
 }
 
@@ -716,7 +703,9 @@
  * With an existing policy of nlmsg, make new nlmsg for deleting the policy
  * and store it to buffer.
  */
-static int xfrm_policy_keep(struct nlmsghdr *n, void *arg)
+static int xfrm_policy_keep(const struct sockaddr_nl *who,
+			    struct nlmsghdr *n,
+			    void *arg)
 {
 	struct xfrm_buffer *xb = (struct xfrm_buffer *)arg;
 	struct rtnl_handle *rth = xb->rth;
@@ -748,19 +737,17 @@
 			fprintf(stderr, "too short XFRMA_POLICY_TYPE len\n");
 			return -1;
 		}
-		upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
+		upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
 		ptype = upt->type;
 	}
 
 	if (!xfrm_policy_filter_match(xpinfo, ptype))
 		return 0;
 
-	/* can't delete socket policies */
-	if (xpinfo->dir >= XFRM_POLICY_MAX)
-		return 0;
-
-	if (xb->offset + NLMSG_LENGTH(sizeof(*xpid)) > xb->size)
-		return 0;
+	if (xb->offset > xb->size) {
+		fprintf(stderr, "Policy buffer overflow\n");
+		return -1;
+	}
 
 	new_n = (struct nlmsghdr *)(xb->buf + xb->offset);
 	new_n->nlmsg_len = NLMSG_LENGTH(sizeof(*xpid));
@@ -773,17 +760,8 @@
 	xpid->dir = xpinfo->dir;
 	xpid->index = xpinfo->index;
 
-	if (tb[XFRMA_MARK]) {
-		int r = addattr_l(new_n, xb->size, XFRMA_MARK,
-				(void *)RTA_DATA(tb[XFRMA_MARK]), tb[XFRMA_MARK]->rta_len);
-		if (r < 0) {
-			fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
-			exit(1);
-		}
-	}
-
 	xb->offset += new_n->nlmsg_len;
-	xb->nlmsg_count++;
+	xb->nlmsg_count ++;
 
 	return 0;
 }
@@ -793,7 +771,7 @@
 	char *selp = NULL;
 	struct rtnl_handle rth;
 
-	if (argc > 0 || preferred_family != AF_UNSPEC)
+	if (argc > 0)
 		filter.use = 1;
 	filter.xpinfo.sel.family = preferred_family;
 
@@ -842,9 +820,6 @@
 
 			filter.policy_flags_mask = XFRM_FILTER_MASK_FULL;
 
-		} else if (strcmp(*argv, "nosock") == 0) {
-			/* filter all socket-based policies */
-			filter.filter_socket = 1;
 		} else {
 			if (selp)
 				invarg("unknown", *argv);
@@ -940,12 +915,12 @@
 	exit(0);
 }
 
-static int print_spdinfo(struct nlmsghdr *n, void *arg)
+static int print_spdinfo( struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	__u32 *f = NLMSG_DATA(n);
-	struct rtattr *tb[XFRMA_SPD_MAX+1];
-	struct rtattr *rta;
+	struct rtattr * tb[XFRMA_SPD_MAX+1];
+	struct rtattr * rta;
 
 	int len = n->nlmsg_len;
 
@@ -958,7 +933,7 @@
 	rta = XFRMSAPD_RTA(f);
 	parse_rtattr(tb, XFRMA_SPD_MAX, rta, len);
 
-	fprintf(fp, "\t SPD");
+	fprintf(fp,"\t SPD");
 	if (tb[XFRMA_SPD_INFO]) {
 		struct xfrmu_spdinfo *si;
 
@@ -967,16 +942,16 @@
 			return -1;
 		}
 		si = RTA_DATA(tb[XFRMA_SPD_INFO]);
-		fprintf(fp, " IN  %d", si->incnt);
-		fprintf(fp, " OUT %d", si->outcnt);
-		fprintf(fp, " FWD %d", si->fwdcnt);
+		fprintf(fp," IN  %d", si->incnt);
+		fprintf(fp," OUT %d", si->outcnt);
+		fprintf(fp," FWD %d", si->fwdcnt);
 
 		if (show_stats) {
-			fprintf(fp, " (Sock:");
-			fprintf(fp, " IN %d", si->inscnt);
-			fprintf(fp, " OUT %d", si->outscnt);
-			fprintf(fp, " FWD %d", si->fwdscnt);
-			fprintf(fp, ")");
+			fprintf(fp," (Sock:");
+			fprintf(fp," IN %d", si->inscnt);
+			fprintf(fp," OUT %d", si->outscnt);
+			fprintf(fp," FWD %d", si->fwdscnt);
+			fprintf(fp,")");
 		}
 
 		fprintf(fp, "%s", _SL_);
@@ -990,36 +965,34 @@
 				return -1;
 			}
 			sh = RTA_DATA(tb[XFRMA_SPD_HINFO]);
-			fprintf(fp, "\t SPD buckets:");
-			fprintf(fp, " count %d", sh->spdhcnt);
-			fprintf(fp, " Max %d", sh->spdhmcnt);
+			fprintf(fp,"\t SPD buckets:");
+			fprintf(fp," count %d", sh->spdhcnt);
+			fprintf(fp," Max %d", sh->spdhmcnt);
 			fprintf(fp, "%s", _SL_);
 		}
 		if (tb[XFRMA_SPD_IPV4_HTHRESH]) {
 			struct xfrmu_spdhthresh *th;
-
 			if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV4_HTHRESH]) < sizeof(*th)) {
 				fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
 				return -1;
 			}
 			th = RTA_DATA(tb[XFRMA_SPD_IPV4_HTHRESH]);
-			fprintf(fp, "\t SPD IPv4 thresholds:");
-			fprintf(fp, " local %d", th->lbits);
-			fprintf(fp, " remote %d", th->rbits);
+			fprintf(fp,"\t SPD IPv4 thresholds:");
+			fprintf(fp," local %d", th->lbits);
+			fprintf(fp," remote %d", th->rbits);
 			fprintf(fp, "%s", _SL_);
 
 		}
 		if (tb[XFRMA_SPD_IPV6_HTHRESH]) {
 			struct xfrmu_spdhthresh *th;
-
 			if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV6_HTHRESH]) < sizeof(*th)) {
 				fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
 				return -1;
 			}
 			th = RTA_DATA(tb[XFRMA_SPD_IPV6_HTHRESH]);
-			fprintf(fp, "\t SPD IPv6 thresholds:");
-			fprintf(fp, " local %d", th->lbits);
-			fprintf(fp, " remote %d", th->rbits);
+			fprintf(fp,"\t SPD IPv6 thresholds:");
+			fprintf(fp," local %d", th->lbits);
+			fprintf(fp," remote %d", th->rbits);
 			fprintf(fp, "%s", _SL_);
 		}
 	}
@@ -1027,7 +1000,7 @@
 	if (oneline)
 		fprintf(fp, "\n");
 
-	return 0;
+        return 0;
 }
 
 static int xfrm_spd_setinfo(int argc, char **argv)
@@ -1037,16 +1010,18 @@
 		struct nlmsghdr			n;
 		__u32				flags;
 		char				buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = XFRM_MSG_NEWSPDINFO,
-		.flags = 0XFFFFFFFF,
-	};
+	} req;
 
 	char *thr4 = NULL;
 	char *thr6 = NULL;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = XFRM_MSG_NEWSPDINFO;
+	req.flags = 0XFFFFFFFF;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "hthresh4") == 0) {
 			struct xfrmu_spdhthresh thr;
@@ -1088,7 +1063,7 @@
 	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
 		exit(1);
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	rtnl_close(&rth);
@@ -1102,23 +1077,24 @@
 	struct {
 		struct nlmsghdr			n;
 		__u32				flags;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = XFRM_MSG_GETSPDINFO,
-		.flags = 0XFFFFFFFF,
-	};
-	struct nlmsghdr *answer;
+		char				ans[128];
+	} req;
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = XFRM_MSG_GETSPDINFO;
+	req.flags = 0XFFFFFFFF;
 
 	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
 		exit(1);
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
 		exit(2);
 
-	print_spdinfo(answer, (void *)stdout);
+	print_spdinfo(&req.n, (void*)stdout);
 
-	free(answer);
 	rtnl_close(&rth);
 
 	return 0;
@@ -1130,13 +1106,16 @@
 	struct {
 		struct nlmsghdr	n;
 		char		buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(0), /* nlmsg data is nothing */
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = XFRM_MSG_FLUSHPOLICY,
-	};
+	} req;
 	char *ptypep = NULL;
-	struct xfrm_userpolicy_type upt = {};
+	struct xfrm_userpolicy_type upt;
+
+	memset(&req, 0, sizeof(req));
+	memset(&upt, 0, sizeof(upt));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(0); /* nlmsg data is nothing */
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = XFRM_MSG_FLUSHPOLICY;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "ptype") == 0) {
@@ -1163,7 +1142,7 @@
 	if (show_stats > 1)
 		fprintf(stderr, "Flush policy\n");
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	rtnl_close(&rth);
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
index b03ccc5..b5734da 100644
--- a/ip/xfrm_state.c
+++ b/ip/xfrm_state.c
@@ -32,7 +32,7 @@
 #include "xfrm.h"
 #include "ip_common.h"
 
-/* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
+//#define NLMSG_DELETEALL_BUF_SIZE (4096-512)
 #define NLMSG_DELETEALL_BUF_SIZE 8192
 
 /*
@@ -54,84 +54,60 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ip xfrm state { add | update } ID [ ALGO-LIST ] [ mode MODE ]\n"
-		"        [ mark MARK [ mask MASK ] ] [ reqid REQID ] [ seq SEQ ]\n"
-		"        [ replay-window SIZE ] [ replay-seq SEQ ] [ replay-oseq SEQ ]\n"
-		"        [ replay-seq-hi SEQ ] [ replay-oseq-hi SEQ ]\n"
-		"        [ flag FLAG-LIST ] [ sel SELECTOR ] [ LIMIT-LIST ] [ encap ENCAP ]\n"
-		"        [ coa ADDR[/PLEN] ] [ ctx CTX ] [ extra-flag EXTRA-FLAG-LIST ]\n"
-		"        [ offload [dev DEV] dir DIR ]\n"
-		"        [ output-mark OUTPUT-MARK ]\n"
-		"        [ if_id IF_ID ]\n"
-		"Usage: ip xfrm state allocspi ID [ mode MODE ] [ mark MARK [ mask MASK ] ]\n"
-		"        [ reqid REQID ] [ seq SEQ ] [ min SPI max SPI ]\n"
-		"Usage: ip xfrm state { delete | get } ID [ mark MARK [ mask MASK ] ]\n"
-		"Usage: ip xfrm state deleteall [ ID ] [ mode MODE ] [ reqid REQID ]\n"
-		"        [ flag FLAG-LIST ]\n"
-		"Usage: ip xfrm state list [ nokeys ] [ ID ] [ mode MODE ] [ reqid REQID ]\n"
-		"        [ flag FLAG-LIST ]\n"
-		"Usage: ip xfrm state flush [ proto XFRM-PROTO ]\n"
-		"Usage: ip xfrm state count\n"
-		"ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n"
-		"XFRM-PROTO := ");
-	fprintf(stderr,
-		"%s | %s | %s | %s | %s\n",
-		strxf_xfrmproto(IPPROTO_ESP),
-		strxf_xfrmproto(IPPROTO_AH),
-		strxf_xfrmproto(IPPROTO_COMP),
-		strxf_xfrmproto(IPPROTO_ROUTING),
-		strxf_xfrmproto(IPPROTO_DSTOPTS));
-	fprintf(stderr,
-		"ALGO-LIST := [ ALGO-LIST ] ALGO\n"
-		"ALGO := { ");
-	fprintf(stderr,
-		"%s | %s",
-		strxf_algotype(XFRMA_ALG_CRYPT),
-		strxf_algotype(XFRMA_ALG_AUTH));
-	fprintf(stderr,
-		" } ALGO-NAME ALGO-KEYMAT |\n"
-		"        %s", strxf_algotype(XFRMA_ALG_AUTH_TRUNC));
-	fprintf(stderr,
-		" ALGO-NAME ALGO-KEYMAT ALGO-TRUNC-LEN |\n"
-		"        %s", strxf_algotype(XFRMA_ALG_AEAD));
-	fprintf(stderr,
-		" ALGO-NAME ALGO-KEYMAT ALGO-ICV-LEN |\n"
-		"        %s", strxf_algotype(XFRMA_ALG_COMP));
-	fprintf(stderr,
-		" ALGO-NAME\n"
-		"MODE := transport | tunnel | beet | ro | in_trigger\n"
-		"FLAG-LIST := [ FLAG-LIST ] FLAG\n"
-		"FLAG := noecn | decap-dscp | nopmtudisc | wildrecv | icmp | af-unspec | align4 | esn\n"
-		"EXTRA-FLAG-LIST := [ EXTRA-FLAG-LIST ] EXTRA-FLAG\n"
-		"EXTRA-FLAG := dont-encap-dscp\n"
-		"SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n"
-		"UPSPEC := proto { { ");
-	fprintf(stderr,
-		"%s | %s | %s | %s",
-		strxf_proto(IPPROTO_TCP),
-		strxf_proto(IPPROTO_UDP),
-		strxf_proto(IPPROTO_SCTP),
-		strxf_proto(IPPROTO_DCCP));
-	fprintf(stderr,
-		" } [ sport PORT ] [ dport PORT ] |\n"
-		"                  { ");
-	fprintf(stderr,
-		"%s | %s | %s",
-		strxf_proto(IPPROTO_ICMP),
-		strxf_proto(IPPROTO_ICMPV6),
-		strxf_proto(IPPROTO_MH));
-	fprintf(stderr,
-		" } [ type NUMBER ] [ code NUMBER ] |\n");
-	fprintf(stderr,
-		"                  %s", strxf_proto(IPPROTO_GRE));
-	fprintf(stderr,
-		" [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n"
-		"LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n"
-		"LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n"
-		"         { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n"
-		"ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR\n"
-		"DIR := in | out\n");
+	fprintf(stderr, "Usage: ip xfrm state { add | update } ID [ ALGO-LIST ] [ mode MODE ]\n");
+	fprintf(stderr, "        [ mark MARK [ mask MASK ] ] [ reqid REQID ] [ seq SEQ ]\n");
+	fprintf(stderr, "        [ replay-window SIZE ] [ replay-seq SEQ ] [ replay-oseq SEQ ]\n");
+	fprintf(stderr, "        [ replay-seq-hi SEQ ] [ replay-oseq-hi SEQ ]\n");
+	fprintf(stderr, "        [ flag FLAG-LIST ] [ sel SELECTOR ] [ LIMIT-LIST ] [ encap ENCAP ]\n");
+	fprintf(stderr, "        [ coa ADDR[/PLEN] ] [ ctx CTX ] [ extra-flag EXTRA-FLAG-LIST ]\n");
+	fprintf(stderr, "Usage: ip xfrm state allocspi ID [ mode MODE ] [ mark MARK [ mask MASK ] ]\n");
+	fprintf(stderr, "        [ reqid REQID ] [ seq SEQ ] [ min SPI max SPI ]\n");
+	fprintf(stderr, "Usage: ip xfrm state { delete | get } ID [ mark MARK [ mask MASK ] ]\n");
+	fprintf(stderr, "Usage: ip xfrm state { deleteall | list } [ ID ] [ mode MODE ] [ reqid REQID ]\n");
+	fprintf(stderr, "        [ flag FLAG-LIST ]\n");
+	fprintf(stderr, "Usage: ip xfrm state flush [ proto XFRM-PROTO ]\n");
+	fprintf(stderr, "Usage: ip xfrm state count\n");
+	fprintf(stderr, "ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n");
+	fprintf(stderr, "XFRM-PROTO := ");
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ESP));
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_AH));
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_COMP));
+	fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ROUTING));
+	fprintf(stderr, "%s\n", strxf_xfrmproto(IPPROTO_DSTOPTS));
+	fprintf(stderr, "ALGO-LIST := [ ALGO-LIST ] ALGO\n");
+	fprintf(stderr, "ALGO := { ");
+	fprintf(stderr, "%s | ", strxf_algotype(XFRMA_ALG_CRYPT));
+	fprintf(stderr, "%s", strxf_algotype(XFRMA_ALG_AUTH));
+	fprintf(stderr, " } ALGO-NAME ALGO-KEYMAT |\n");
+	fprintf(stderr, "        %s", strxf_algotype(XFRMA_ALG_AUTH_TRUNC));
+	fprintf(stderr, " ALGO-NAME ALGO-KEYMAT ALGO-TRUNC-LEN |\n");
+	fprintf(stderr, "        %s", strxf_algotype(XFRMA_ALG_AEAD));
+	fprintf(stderr, " ALGO-NAME ALGO-KEYMAT ALGO-ICV-LEN |\n");
+	fprintf(stderr, "        %s", strxf_algotype(XFRMA_ALG_COMP));
+	fprintf(stderr, " ALGO-NAME\n");
+	fprintf(stderr, "MODE := transport | tunnel | beet | ro | in_trigger\n");
+	fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n");
+	fprintf(stderr, "FLAG := noecn | decap-dscp | nopmtudisc | wildrecv | icmp | af-unspec | align4 | esn\n");
+	fprintf(stderr, "EXTRA-FLAG-LIST := [ EXTRA-FLAG-LIST ] EXTRA-FLAG\n");
+	fprintf(stderr, "EXTRA-FLAG := dont-encap-dscp\n");
+	fprintf(stderr, "SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n");
+	fprintf(stderr, "UPSPEC := proto { { ");
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_TCP));
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_UDP));
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_SCTP));
+	fprintf(stderr, "%s", strxf_proto(IPPROTO_DCCP));
+	fprintf(stderr, " } [ sport PORT ] [ dport PORT ] |\n");
+	fprintf(stderr, "                  { ");
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMP));
+	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMPV6));
+	fprintf(stderr, "%s", strxf_proto(IPPROTO_MH));
+	fprintf(stderr, " } [ type NUMBER ] [ code NUMBER ] |\n");
+	fprintf(stderr, "                  %s", strxf_proto(IPPROTO_GRE));
+	fprintf(stderr, " [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n");
+	fprintf(stderr, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n");
+	fprintf(stderr, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n");
+	fprintf(stderr, "         { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n");
+        fprintf(stderr, "ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR\n");
 
 	exit(-1);
 }
@@ -147,7 +123,7 @@
 	fprintf(stderr, "warning: ALGO-NAME/ALGO-KEYMAT values will be sent to the kernel promiscuously! (verifying them isn't implemented yet)\n");
 #endif
 
-	strlcpy(alg->alg_name, name, sizeof(alg->alg_name));
+	strncpy(alg->alg_name, name, sizeof(alg->alg_name));
 
 	if (slen > 2 && strncmp(key, "0x", 2) == 0) {
 		/* split two chars "0x" from the top */
@@ -166,7 +142,7 @@
 		if (len > max)
 			invarg("ALGO-KEYMAT value makes buffer overflow\n", key);
 
-		for (i = -(plen % 2), j = 0; j < len; i += 2, j++) {
+		for (i = - (plen % 2), j = 0; j < len; i += 2, j++) {
 			char vbuf[3];
 			__u8 val;
 
@@ -199,9 +175,11 @@
 	int argc = *argcp;
 	char **argv = *argvp;
 
-	if (get_be32(seq, *argv, 0))
+	if (get_u32(seq, *argv, 0))
 		invarg("SEQ value is invalid", *argv);
 
+	*seq = htonl(*seq);
+
 	*argcp = argc;
 	*argvp = argv;
 
@@ -288,47 +266,16 @@
 	return 0;
 }
 
-static int xfrm_offload_dir_parse(__u8 *dir, int *argcp, char ***argvp)
-{
-	int argc = *argcp;
-	char **argv = *argvp;
-
-	if (strcmp(*argv, "in") == 0)
-		*dir = XFRM_OFFLOAD_INBOUND;
-	else if (strcmp(*argv, "out") == 0)
-		*dir = 0;
-	else
-		invarg("DIR value is invalid", *argv);
-
-	*argcp = argc;
-	*argvp = argv;
-
-	return 0;
-}
-
-static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
+static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
 {
 	struct rtnl_handle rth;
 	struct {
 		struct nlmsghdr	n;
 		struct xfrm_usersa_info xsinfo;
-		char			buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsinfo)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.xsinfo.family = preferred_family,
-		.xsinfo.lft.soft_byte_limit = XFRM_INF,
-		.xsinfo.lft.hard_byte_limit = XFRM_INF,
-		.xsinfo.lft.soft_packet_limit = XFRM_INF,
-		.xsinfo.lft.hard_packet_limit = XFRM_INF,
-	};
-	struct xfrm_replay_state replay = {};
-	struct xfrm_replay_state_esn replay_esn = {};
-	struct xfrm_user_offload xuo = {};
-	unsigned int ifindex = 0;
-	__u8 dir = 0;
-	bool is_offload = false;
+		char  			buf[RTA_BUF_SIZE];
+	} req;
+	struct xfrm_replay_state replay;
+	struct xfrm_replay_state_esn replay_esn;
 	__u32 replay_window = 0;
 	__u32 seq = 0, oseq = 0, seq_hi = 0, oseq_hi = 0;
 	char *idp = NULL;
@@ -343,10 +290,22 @@
 	struct {
 		struct xfrm_user_sec_ctx sctx;
 		char    str[CTX_BUF_SIZE];
-	} ctx = {};
-	__u32 output_mark = 0;
-	bool is_if_id_set = false;
-	__u32 if_id = 0;
+	} ctx;
+
+	memset(&req, 0, sizeof(req));
+	memset(&replay, 0, sizeof(replay));
+	memset(&replay_esn, 0, sizeof(replay_esn));
+	memset(&ctx, 0, sizeof(ctx));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsinfo));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.xsinfo.family = preferred_family;
+
+	req.xsinfo.lft.soft_byte_limit = XFRM_INF;
+	req.xsinfo.lft.hard_byte_limit = XFRM_INF;
+	req.xsinfo.lft.soft_packet_limit = XFRM_INF;
+	req.xsinfo.lft.hard_packet_limit = XFRM_INF;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "mode") == 0) {
@@ -397,14 +356,16 @@
 		} else if (strcmp(*argv, "encap") == 0) {
 			struct xfrm_encap_tmpl encap;
 			inet_prefix oa;
-			NEXT_ARG();
+		        NEXT_ARG();
 			xfrm_encap_type_parse(&encap.encap_type, &argc, &argv);
 			NEXT_ARG();
-			if (get_be16(&encap.encap_sport, *argv, 0))
+			if (get_u16(&encap.encap_sport, *argv, 0))
 				invarg("SPORT value after \"encap\" is invalid", *argv);
+			encap.encap_sport = htons(encap.encap_sport);
 			NEXT_ARG();
-			if (get_be16(&encap.encap_dport, *argv, 0))
+			if (get_u16(&encap.encap_dport, *argv, 0))
 				invarg("DPORT value after \"encap\" is invalid", *argv);
+			encap.encap_dport = htons(encap.encap_dport);
 			NEXT_ARG();
 			get_addr(&oa, *argv, AF_UNSPEC);
 			memcpy(&encap.encap_oa, &oa.data, sizeof(encap.encap_oa));
@@ -412,7 +373,7 @@
 				  (void *)&encap, sizeof(encap));
 		} else if (strcmp(*argv, "coa") == 0) {
 			inet_prefix coa;
-			xfrm_address_t xcoa = {};
+			xfrm_address_t xcoa;
 
 			if (coap)
 				duparg("coa", *argv);
@@ -426,6 +387,7 @@
 			if (coa.bytelen > sizeof(xcoa))
 				invarg("value after \"coa\" is too large", *argv);
 
+			memset(&xcoa, 0, sizeof(xcoa));
 			memcpy(&xcoa, &coa.data, coa.bytelen);
 
 			addattr_l(&req.n, sizeof(req.buf), XFRMA_COADDR,
@@ -443,38 +405,9 @@
 			xfrm_sctx_parse((char *)&ctx.str, context, &ctx.sctx);
 			addattr_l(&req.n, sizeof(req.buf), XFRMA_SEC_CTX,
 				  (void *)&ctx, ctx.sctx.len);
-		} else if (strcmp(*argv, "offload") == 0) {
-			is_offload = true;
-			NEXT_ARG();
-			if (strcmp(*argv, "dev") == 0) {
-				NEXT_ARG();
-				ifindex = ll_name_to_index(*argv);
-				if (!ifindex) {
-					invarg("value after \"offload dev\" is invalid", *argv);
-					is_offload = false;
-				}
-				NEXT_ARG();
-			}
-			if (strcmp(*argv, "dir") == 0) {
-				NEXT_ARG();
-				xfrm_offload_dir_parse(&dir, &argc, &argv);
-			} else {
-				invarg("value after \"offload dir\" is invalid", *argv);
-				is_offload = false;
-			}
-		} else if (strcmp(*argv, "output-mark") == 0) {
-			NEXT_ARG();
-			if (get_u32(&output_mark, *argv, 0))
-				invarg("value after \"output-mark\" is invalid", *argv);
-		} else if (strcmp(*argv, "if_id") == 0) {
-			NEXT_ARG();
-			if (get_u32(&if_id, *argv, 0))
-				invarg("value after \"if_id\" is invalid", *argv);
-			is_if_id_set = true;
 		} else {
 			/* try to assume ALGO */
 			int type = xfrm_algotype_getbyname(*argv);
-
 			switch (type) {
 			case XFRMA_ALG_AEAD:
 			case XFRMA_ALG_CRYPT:
@@ -573,7 +506,7 @@
 
 				xfrm_algo_parse((void *)&alg, type, name, key,
 						buf, sizeof(alg.buf));
-				len += alg.u.alg.alg_key_len / 8;
+				len += alg.u.alg.alg_key_len;
 
 				addattr_l(&req.n, sizeof(req.buf), type,
 					  (void *)&alg, len);
@@ -608,12 +541,6 @@
 		exit(-1);
 	}
 
-	if (is_offload) {
-		xuo.ifindex = ifindex;
-		xuo.flags = dir;
-		addattr_l(&req.n, sizeof(req.buf), XFRMA_OFFLOAD_DEV, &xuo,
-			  sizeof(xuo));
-	}
 	if (req.xsinfo.flags & XFRM_STATE_ESN ||
 	    replay_window > (sizeof(replay.bitmap) * 8)) {
 		replay_esn.seq = seq;
@@ -653,9 +580,6 @@
 		}
 	}
 
-	if (is_if_id_set)
-		addattr32(&req.n, sizeof(req.buf), XFRMA_IF_ID, if_id);
-
 	if (xfrm_xfrmproto_is_ipsec(req.xsinfo.id.proto)) {
 		switch (req.xsinfo.mode) {
 		case XFRM_MODE_TRANSPORT:
@@ -757,16 +681,13 @@
 		}
 	}
 
-	if (output_mark)
-		addattr32(&req.n, sizeof(req.buf), XFRMA_OUTPUT_MARK, output_mark);
-
 	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
 		exit(1);
 
 	if (req.xsinfo.family == AF_UNSPEC)
 		req.xsinfo.family = AF_INET;
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	rtnl_close(&rth);
@@ -780,24 +701,30 @@
 	struct {
 		struct nlmsghdr	n;
 		struct xfrm_userspi_info xspi;
-		char			buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xspi)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = XFRM_MSG_ALLOCSPI,
-		.xspi.info.family = preferred_family,
-#if 0
-		.xspi.lft.soft_byte_limit = XFRM_INF,
-		.xspi.lft.hard_byte_limit = XFRM_INF,
-		.xspi.lft.soft_packet_limit = XFRM_INF,
-		.xspi.lft.hard_packet_limit = XFRM_INF,
-#endif
-	};
+		char  			buf[RTA_BUF_SIZE];
+	} req;
 	char *idp = NULL;
 	char *minp = NULL;
 	char *maxp = NULL;
 	struct xfrm_mark mark = {0, 0};
-	struct nlmsghdr *answer;
+	char res_buf[NLMSG_BUF_SIZE];
+	struct nlmsghdr *res_n = (struct nlmsghdr *)res_buf;
+
+	memset(res_buf, 0, sizeof(res_buf));
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xspi));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = XFRM_MSG_ALLOCSPI;
+	req.xspi.info.family = preferred_family;
+
+#if 0
+	req.xsinfo.lft.soft_byte_limit = XFRM_INF;
+	req.xsinfo.lft.hard_byte_limit = XFRM_INF;
+	req.xsinfo.lft.soft_packet_limit = XFRM_INF;
+	req.xsinfo.lft.hard_packet_limit = XFRM_INF;
+#endif
 
 	while (argc > 0) {
 		if (strcmp(*argv, "mode") == 0) {
@@ -897,15 +824,14 @@
 		req.xspi.info.family = AF_INET;
 
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk(&rth, &req.n, res_n, sizeof(res_buf)) < 0)
 		exit(2);
 
-	if (xfrm_state_print(answer, (void *)stdout) < 0) {
+	if (xfrm_state_print(NULL, res_n, (void*)stdout) < 0) {
 		fprintf(stderr, "An error :-)\n");
 		exit(1);
 	}
 
-	free(answer);
 	rtnl_close(&rth);
 
 	return 0;
@@ -916,10 +842,6 @@
 	if (!filter.use)
 		return 1;
 
-	if (filter.xsinfo.family != AF_UNSPEC &&
-	    filter.xsinfo.family != xsinfo->family)
-		return 0;
-
 	if (filter.id_src_mask)
 		if (xfrm_addr_match(&xsinfo->saddr, &filter.xsinfo.saddr,
 				    filter.id_src_mask))
@@ -943,11 +865,12 @@
 	return 1;
 }
 
-static int __do_xfrm_state_print(struct nlmsghdr *n, void *arg, bool nokeys)
+int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
+		     void *arg)
 {
-	FILE *fp = (FILE *)arg;
-	struct rtattr *tb[XFRMA_MAX+1];
-	struct rtattr *rta;
+	FILE *fp = (FILE*)arg;
+	struct rtattr * tb[XFRMA_MAX+1];
+	struct rtattr * rta;
 	struct xfrm_usersa_info *xsinfo = NULL;
 	struct xfrm_user_expire *xexp = NULL;
 	struct xfrm_usersa_id	*xsid = NULL;
@@ -963,7 +886,7 @@
 	}
 
 	if (n->nlmsg_type == XFRM_MSG_DELSA) {
-		/* Don't blame me for this .. Herbert made me do it */
+		/* Dont blame me for this .. Herbert made me do it */
 		xsid = NLMSG_DATA(n);
 		len -= NLMSG_SPACE(sizeof(*xsid));
 	} else if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
@@ -1001,7 +924,7 @@
 	parse_rtattr(tb, XFRMA_MAX, rta, len);
 
 	if (n->nlmsg_type == XFRM_MSG_DELSA) {
-		/* xfrm_policy_id_print(); */
+		//xfrm_policy_id_print();
 
 		if (!tb[XFRMA_SA]) {
 			fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n");
@@ -1014,7 +937,7 @@
 		xsinfo = RTA_DATA(tb[XFRMA_SA]);
 	}
 
-	xfrm_state_info_print(xsinfo, tb, fp, NULL, NULL, nokeys);
+	xfrm_state_info_print(xsinfo, tb, fp, NULL, NULL);
 
 	if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
 		fprintf(fp, "\t");
@@ -1029,33 +952,25 @@
 	return 0;
 }
 
-int xfrm_state_print(struct nlmsghdr *n, void *arg)
-{
-	return __do_xfrm_state_print(n, arg, false);
-}
-
-int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg)
-{
-	return __do_xfrm_state_print(n, arg, true);
-}
-
 static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
 {
 	struct rtnl_handle rth;
 	struct {
 		struct nlmsghdr	n;
 		struct xfrm_usersa_id	xsid;
-		char			buf[RTA_BUF_SIZE];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsid)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = delete ? XFRM_MSG_DELSA : XFRM_MSG_GETSA,
-		.xsid.family = preferred_family,
-	};
+		char  			buf[RTA_BUF_SIZE];
+	} req;
 	struct xfrm_id id;
 	char *idp = NULL;
 	struct xfrm_mark mark = {0, 0};
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsid));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = delete ? XFRM_MSG_DELSA : XFRM_MSG_GETSA;
+	req.xsid.family = preferred_family;
+
 	while (argc > 0) {
 		xfrm_address_t saddr;
 
@@ -1099,20 +1014,21 @@
 		req.xsid.family = AF_INET;
 
 	if (delete) {
-		if (rtnl_talk(&rth, &req.n, NULL) < 0)
+		if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 			exit(2);
 	} else {
-		struct nlmsghdr *answer;
+		char buf[NLMSG_BUF_SIZE];
+		struct nlmsghdr *res_n = (struct nlmsghdr *)buf;
 
-		if (rtnl_talk(&rth, &req.n, &answer) < 0)
+		memset(buf, 0, sizeof(buf));
+
+		if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0)
 			exit(2);
 
-		if (xfrm_state_print(answer, (void *)stdout) < 0) {
+		if (xfrm_state_print(NULL, res_n, (void*)stdout) < 0) {
 			fprintf(stderr, "An error :-)\n");
 			exit(1);
 		}
-
-		free(answer);
 	}
 
 	rtnl_close(&rth);
@@ -1124,7 +1040,9 @@
  * With an existing state of nlmsg, make new nlmsg for deleting the state
  * and store it to buffer.
  */
-static int xfrm_state_keep(struct nlmsghdr *n, void *arg)
+static int xfrm_state_keep(const struct sockaddr_nl *who,
+			   struct nlmsghdr *n,
+			   void *arg)
 {
 	struct xfrm_buffer *xb = (struct xfrm_buffer *)arg;
 	struct rtnl_handle *rth = xb->rth;
@@ -1132,7 +1050,6 @@
 	int len = n->nlmsg_len;
 	struct nlmsghdr *new_n;
 	struct xfrm_usersa_id *xsid;
-	struct rtattr *tb[XFRMA_MAX+1];
 
 	if (n->nlmsg_type != XFRM_MSG_NEWSA) {
 		fprintf(stderr, "Not a state: %08x %08x %08x\n",
@@ -1169,19 +1086,8 @@
 	addattr_l(new_n, xb->size, XFRMA_SRCADDR, &xsinfo->saddr,
 		  sizeof(xsid->daddr));
 
-	parse_rtattr(tb, XFRMA_MAX, XFRMS_RTA(xsinfo), len);
-
-	if (tb[XFRMA_MARK]) {
-		int r = addattr_l(new_n, xb->size, XFRMA_MARK,
-				(void *)RTA_DATA(tb[XFRMA_MARK]), tb[XFRMA_MARK]->rta_len);
-		if (r < 0) {
-			fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
-			exit(1);
-		}
-	}
-
 	xb->offset += new_n->nlmsg_len;
-	xb->nlmsg_count++;
+	xb->nlmsg_count ++;
 
 	return 0;
 }
@@ -1190,16 +1096,13 @@
 {
 	char *idp = NULL;
 	struct rtnl_handle rth;
-	bool nokeys = false;
 
-	if (argc > 0 || preferred_family != AF_UNSPEC)
+	if(argc > 0)
 		filter.use = 1;
 	filter.xsinfo.family = preferred_family;
 
 	while (argc > 0) {
-		if (strcmp(*argv, "nokeys") == 0) {
-			nokeys = true;
-		} else if (strcmp(*argv, "mode") == 0) {
+		if (strcmp(*argv, "mode") == 0) {
 			NEXT_ARG();
 			xfrm_mode_parse(&filter.xsinfo.mode, &argc, &argv);
 
@@ -1315,9 +1218,7 @@
 			exit(1);
 		}
 
-		rtnl_filter_t filter = nokeys ?
-				xfrm_state_print_nokeys : xfrm_state_print;
-		if (rtnl_dump_filter(&rth, filter, stdout) < 0) {
+		if (rtnl_dump_filter(&rth, xfrm_state_print, stdout) < 0) {
 			fprintf(stderr, "Dump terminated\n");
 			exit(1);
 		}
@@ -1330,10 +1231,12 @@
 
 static int print_sadinfo(struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	__u32 *f = NLMSG_DATA(n);
 	struct rtattr *tb[XFRMA_SAD_MAX+1];
 	struct rtattr *rta;
+	__u32 *cnt;
+
 	int len = n->nlmsg_len;
 
 	len -= NLMSG_LENGTH(sizeof(__u32));
@@ -1346,13 +1249,11 @@
 	parse_rtattr(tb, XFRMA_SAD_MAX, rta, len);
 
 	if (tb[XFRMA_SAD_CNT]) {
-		__u32 cnt;
-
-		fprintf(fp, "\t SAD");
-		cnt = rta_getattr_u32(tb[XFRMA_SAD_CNT]);
-		fprintf(fp, " count %u", cnt);
+		fprintf(fp,"\t SAD");
+		cnt = (__u32 *)RTA_DATA(tb[XFRMA_SAD_CNT]);
+		fprintf(fp," count %d", *cnt);
 	} else {
-		fprintf(fp, "BAD SAD info returned\n");
+		fprintf(fp,"BAD SAD info returned\n");
 		return -1;
 	}
 
@@ -1361,20 +1262,20 @@
 			struct xfrmu_sadhinfo *si;
 
 			if (RTA_PAYLOAD(tb[XFRMA_SAD_HINFO]) < sizeof(*si)) {
-				fprintf(fp, "BAD SAD length returned\n");
+				fprintf(fp,"BAD SAD length returned\n");
 				return -1;
 			}
 
 			si = RTA_DATA(tb[XFRMA_SAD_HINFO]);
-			fprintf(fp, " (buckets ");
-			fprintf(fp, "count %d", si->sadhcnt);
-			fprintf(fp, " Max %d", si->sadhmcnt);
-			fprintf(fp, ")");
+			fprintf(fp," (buckets ");
+			fprintf(fp,"count %d", si->sadhcnt);
+			fprintf(fp," Max %d", si->sadhmcnt);
+			fprintf(fp,")");
 		}
 	}
-	fprintf(fp, "\n");
+	fprintf(fp,"\n");
 
-	return 0;
+        return 0;
 }
 
 static int xfrm_sad_getinfo(int argc, char **argv)
@@ -1383,23 +1284,23 @@
 	struct {
 		struct nlmsghdr			n;
 		__u32				flags;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.flags)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = XFRM_MSG_GETSADINFO,
-		.flags = 0XFFFFFFFF,
-	};
-	struct nlmsghdr *answer;
+		char				ans[64];
+	} req;
+
+	memset(&req, 0, sizeof(req));
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.flags));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = XFRM_MSG_GETSADINFO;
+	req.flags = 0XFFFFFFFF;
 
 	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
 		exit(1);
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
 		exit(2);
 
-	print_sadinfo(answer, (void *)stdout);
+	print_sadinfo(&req.n, (void*)stdout);
 
-	free(answer);
 	rtnl_close(&rth);
 
 	return 0;
@@ -1411,13 +1312,16 @@
 	struct {
 		struct nlmsghdr			n;
 		struct xfrm_usersa_flush	xsf;
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsf)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = XFRM_MSG_FLUSHSA,
-	};
+	} req;
 	char *protop = NULL;
 
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsf));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = XFRM_MSG_FLUSHSA;
+	req.xsf.proto = 0;
+
 	while (argc > 0) {
 		if (strcmp(*argv, "proto") == 0) {
 			int ret;
@@ -1446,7 +1350,7 @@
 		fprintf(stderr, "Flush state with XFRM-PROTO value \"%s\"\n",
 			strxf_xfrmproto(req.xsf.proto));
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		exit(2);
 
 	rtnl_close(&rth);
diff --git a/lib/Android.mk b/lib/Android.mk
index b6bcb6f..3fa5a5e 100644
--- a/lib/Android.mk
+++ b/lib/Android.mk
@@ -1,13 +1,14 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
-LOCAL_SRC_FILES := utils.c rt_names.c ll_map.c ll_types.c ll_proto.c ll_addr.c i\
-                   inet_proto.c namespace.c json_writer.c json_print.c \
-                   names.c color.c bpf.c exec.c fs.c mpls_ntop.c mpls_pton.c
+LOCAL_SRC_FILES := \
+    color.c utils.c rt_names.c ll_types.c ll_proto.c ll_addr.c inet_proto.c \
+    mpls_pton.c namespace.c names.c libgenl.c libnetlink.c
 LOCAL_MODULE := libiprouteutil
-LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
 LOCAL_CFLAGS := -O2 -g -W -Wall \
+	-DCONFDIR=\"/data/misc/net\" \
 	-DHAVE_UNISTD_H \
 	-DHAVE_ERRNO_H \
 	-DHAVE_NETINET_IN_H \
@@ -30,22 +31,22 @@
 	-DHAVE_LINUX_FD_H \
 	-DHAVE_TYPE_SSIZE_T \
 	-DHAVE_SETNS \
-	-DNEED_STRLCPY \
+	-D_GNU_SOURCE \
 	-Wno-pointer-arith \
 	-Wno-sign-compare \
 	-Wno-unused-parameter \
 	-Werror
 
-include $(BUILD_STATIC_LIBRARY)
+# This is a work around for b/18403920
+LOCAL_LDFLAGS := -Wl,--no-gc-sections
+
+include $(BUILD_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
-LOCAL_SRC_FILES := libgenl.c libnetlink.c
+LOCAL_SRC_FILES := ll_map.c libnetlink.c
 LOCAL_MODULE := libnetlink
-LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES := \
-        $(LOCAL_PATH)/../include \
-        $(LOCAL_PATH)/../include/uapi
-
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
 LOCAL_CFLAGS := -O2 -g -W -Wall \
 	-DHAVE_UNISTD_H \
 	-DHAVE_ERRNO_H \
@@ -71,7 +72,6 @@
 	-Wno-pointer-arith \
 	-Wno-sign-compare \
 	-Wno-unused-parameter \
-	-Werror \
-	-Wno-\#warnings
+	-Werror
 
-include $(BUILD_STATIC_LIBRARY)
+include $(BUILD_SHARED_LIBRARY)
diff --git a/lib/Makefile b/lib/Makefile
index bab8cbf..9d1307d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,23 +1,27 @@
-# SPDX-License-Identifier: GPL-2.0
-include ../config.mk
+include ../Config
+
+ifeq ($(IP_CONFIG_SETNS),y)
+	CFLAGS += -DHAVE_SETNS
+endif
 
 CFLAGS += -fPIC
 
-UTILOBJ = utils.o rt_names.o ll_map.o ll_types.o ll_proto.o ll_addr.o \
-	inet_proto.o namespace.o json_writer.o json_print.o \
-	names.o color.o bpf.o exec.o fs.o
+UTILOBJ = utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o \
+	inet_proto.o namespace.o json_writer.o \
+	names.o color.o
 
-NLOBJ=libgenl.o libnetlink.o
+NLOBJ=libgenl.o ll_map.o libnetlink.o
 
 all: libnetlink.a libutil.a
 
 libnetlink.a: $(NLOBJ)
-	$(QUIET_AR)$(AR) rcs $@ $^
+	$(AR) rcs $@ $(NLOBJ)
 
 libutil.a: $(UTILOBJ) $(ADDLIB)
-	$(QUIET_AR)$(AR) rcs $@ $^
+	$(AR) rcs $@ $(UTILOBJ) $(ADDLIB)
 
 install:
 
 clean:
 	rm -f $(NLOBJ) $(UTILOBJ) $(ADDLIB) libnetlink.a libutil.a
+
diff --git a/lib/bpf.c b/lib/bpf.c
deleted file mode 100644
index 10cf9bf..0000000
--- a/lib/bpf.c
+++ /dev/null
@@ -1,3240 +0,0 @@
-/*
- * bpf.c	BPF common code
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Daniel Borkmann <daniel@iogearbox.net>
- *		Jiri Pirko <jiri@resnulli.us>
- *		Alexei Starovoitov <ast@kernel.org>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <limits.h>
-#include <assert.h>
-
-#ifdef HAVE_ELF
-#include <libelf.h>
-#include <gelf.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/un.h>
-#include <sys/vfs.h>
-#include <sys/mount.h>
-#include <sys/syscall.h>
-#include <sys/sendfile.h>
-#include <sys/resource.h>
-
-#include <arpa/inet.h>
-
-#include "utils.h"
-#include "json_print.h"
-
-#include "bpf_util.h"
-#include "bpf_elf.h"
-#include "bpf_scm.h"
-
-struct bpf_prog_meta {
-	const char *type;
-	const char *subdir;
-	const char *section;
-	bool may_uds_export;
-};
-
-static const enum bpf_prog_type __bpf_types[] = {
-	BPF_PROG_TYPE_SCHED_CLS,
-	BPF_PROG_TYPE_SCHED_ACT,
-	BPF_PROG_TYPE_XDP,
-	BPF_PROG_TYPE_LWT_IN,
-	BPF_PROG_TYPE_LWT_OUT,
-	BPF_PROG_TYPE_LWT_XMIT,
-};
-
-static const struct bpf_prog_meta __bpf_prog_meta[] = {
-	[BPF_PROG_TYPE_SCHED_CLS] = {
-		.type		= "cls",
-		.subdir		= "tc",
-		.section	= ELF_SECTION_CLASSIFIER,
-		.may_uds_export	= true,
-	},
-	[BPF_PROG_TYPE_SCHED_ACT] = {
-		.type		= "act",
-		.subdir		= "tc",
-		.section	= ELF_SECTION_ACTION,
-		.may_uds_export	= true,
-	},
-	[BPF_PROG_TYPE_XDP] = {
-		.type		= "xdp",
-		.subdir		= "xdp",
-		.section	= ELF_SECTION_PROG,
-	},
-	[BPF_PROG_TYPE_LWT_IN] = {
-		.type		= "lwt_in",
-		.subdir		= "ip",
-		.section	= ELF_SECTION_PROG,
-	},
-	[BPF_PROG_TYPE_LWT_OUT] = {
-		.type		= "lwt_out",
-		.subdir		= "ip",
-		.section	= ELF_SECTION_PROG,
-	},
-	[BPF_PROG_TYPE_LWT_XMIT] = {
-		.type		= "lwt_xmit",
-		.subdir		= "ip",
-		.section	= ELF_SECTION_PROG,
-	},
-	[BPF_PROG_TYPE_LWT_SEG6LOCAL] = {
-		.type		= "lwt_seg6local",
-		.subdir		= "ip",
-		.section	= ELF_SECTION_PROG,
-	},
-};
-
-static const char *bpf_prog_to_subdir(enum bpf_prog_type type)
-{
-	assert(type < ARRAY_SIZE(__bpf_prog_meta) &&
-	       __bpf_prog_meta[type].subdir);
-	return __bpf_prog_meta[type].subdir;
-}
-
-const char *bpf_prog_to_default_section(enum bpf_prog_type type)
-{
-	assert(type < ARRAY_SIZE(__bpf_prog_meta) &&
-	       __bpf_prog_meta[type].section);
-	return __bpf_prog_meta[type].section;
-}
-
-#ifdef HAVE_ELF
-static int bpf_obj_open(const char *path, enum bpf_prog_type type,
-			const char *sec, __u32 ifindex, bool verbose);
-#else
-static int bpf_obj_open(const char *path, enum bpf_prog_type type,
-			const char *sec, __u32 ifindex, bool verbose)
-{
-	fprintf(stderr, "No ELF library support compiled in.\n");
-	errno = ENOSYS;
-	return -1;
-}
-#endif
-
-static inline __u64 bpf_ptr_to_u64(const void *ptr)
-{
-	return (__u64)(unsigned long)ptr;
-}
-
-static int bpf(int cmd, union bpf_attr *attr, unsigned int size)
-{
-#ifdef __NR_bpf
-	return syscall(__NR_bpf, cmd, attr, size);
-#else
-	fprintf(stderr, "No bpf syscall, kernel headers too old?\n");
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
-static int bpf_map_update(int fd, const void *key, const void *value,
-			  uint64_t flags)
-{
-	union bpf_attr attr = {};
-
-	attr.map_fd = fd;
-	attr.key = bpf_ptr_to_u64(key);
-	attr.value = bpf_ptr_to_u64(value);
-	attr.flags = flags;
-
-	return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
-}
-
-static int bpf_prog_fd_by_id(uint32_t id)
-{
-	union bpf_attr attr = {};
-
-	attr.prog_id = id;
-
-	return bpf(BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr));
-}
-
-static int bpf_prog_info_by_fd(int fd, struct bpf_prog_info *info,
-			       uint32_t *info_len)
-{
-	union bpf_attr attr = {};
-	int ret;
-
-	attr.info.bpf_fd = fd;
-	attr.info.info = bpf_ptr_to_u64(info);
-	attr.info.info_len = *info_len;
-
-	*info_len = 0;
-	ret = bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr));
-	if (!ret)
-		*info_len = attr.info.info_len;
-
-	return ret;
-}
-
-int bpf_dump_prog_info(FILE *f, uint32_t id)
-{
-	struct bpf_prog_info info = {};
-	uint32_t len = sizeof(info);
-	int fd, ret, dump_ok = 0;
-	SPRINT_BUF(tmp);
-
-	open_json_object("prog");
-	print_uint(PRINT_ANY, "id", "id %u ", id);
-
-	fd = bpf_prog_fd_by_id(id);
-	if (fd < 0)
-		goto out;
-
-	ret = bpf_prog_info_by_fd(fd, &info, &len);
-	if (!ret && len) {
-		int jited = !!info.jited_prog_len;
-
-		print_string(PRINT_ANY, "tag", "tag %s ",
-			     hexstring_n2a(info.tag, sizeof(info.tag),
-					   tmp, sizeof(tmp)));
-		print_uint(PRINT_JSON, "jited", NULL, jited);
-		if (jited && !is_json_context())
-			fprintf(f, "jited ");
-		dump_ok = 1;
-	}
-
-	close(fd);
-out:
-	close_json_object();
-	return dump_ok;
-}
-
-static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
-			    char **bpf_string, bool *need_release,
-			    const char separator)
-{
-	char sp;
-
-	if (from_file) {
-		size_t tmp_len, op_len = sizeof("65535 255 255 4294967295,");
-		char *tmp_string, *pos, c_prev = ' ';
-		FILE *fp;
-		int c;
-
-		tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len;
-		tmp_string = pos = calloc(1, tmp_len);
-		if (tmp_string == NULL)
-			return -ENOMEM;
-
-		fp = fopen(arg, "r");
-		if (fp == NULL) {
-			perror("Cannot fopen");
-			free(tmp_string);
-			return -ENOENT;
-		}
-
-		while ((c = fgetc(fp)) != EOF) {
-			switch (c) {
-			case '\n':
-				if (c_prev != ',')
-					*(pos++) = ',';
-				c_prev = ',';
-				break;
-			case ' ':
-			case '\t':
-				if (c_prev != ' ')
-					*(pos++) = c;
-				c_prev = ' ';
-				break;
-			default:
-				*(pos++) = c;
-				c_prev = c;
-			}
-			if (pos - tmp_string == tmp_len)
-				break;
-		}
-
-		if (!feof(fp)) {
-			free(tmp_string);
-			fclose(fp);
-			return -E2BIG;
-		}
-
-		fclose(fp);
-		*pos = 0;
-
-		*need_release = true;
-		*bpf_string = tmp_string;
-	} else {
-		*need_release = false;
-		*bpf_string = arg;
-	}
-
-	if (sscanf(*bpf_string, "%hu%c", bpf_len, &sp) != 2 ||
-	    sp != separator) {
-		if (*need_release)
-			free(*bpf_string);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int bpf_ops_parse(int argc, char **argv, struct sock_filter *bpf_ops,
-			 bool from_file)
-{
-	char *bpf_string, *token, separator = ',';
-	int ret = 0, i = 0;
-	bool need_release;
-	__u16 bpf_len = 0;
-
-	if (argc < 1)
-		return -EINVAL;
-	if (bpf_parse_string(argv[0], from_file, &bpf_len, &bpf_string,
-			     &need_release, separator))
-		return -EINVAL;
-	if (bpf_len == 0 || bpf_len > BPF_MAXINSNS) {
-		ret = -EINVAL;
-		goto out;
-	}
-
-	token = bpf_string;
-	while ((token = strchr(token, separator)) && (++token)[0]) {
-		if (i >= bpf_len) {
-			fprintf(stderr, "Real program length exceeds encoded length parameter!\n");
-			ret = -EINVAL;
-			goto out;
-		}
-
-		if (sscanf(token, "%hu %hhu %hhu %u,",
-			   &bpf_ops[i].code, &bpf_ops[i].jt,
-			   &bpf_ops[i].jf, &bpf_ops[i].k) != 4) {
-			fprintf(stderr, "Error at instruction %d!\n", i);
-			ret = -EINVAL;
-			goto out;
-		}
-
-		i++;
-	}
-
-	if (i != bpf_len) {
-		fprintf(stderr, "Parsed program length is less than encoded length parameter!\n");
-		ret = -EINVAL;
-		goto out;
-	}
-	ret = bpf_len;
-out:
-	if (need_release)
-		free(bpf_string);
-
-	return ret;
-}
-
-void bpf_print_ops(struct rtattr *bpf_ops, __u16 len)
-{
-	struct sock_filter *ops = RTA_DATA(bpf_ops);
-	int i;
-
-	if (len == 0)
-		return;
-
-	open_json_object("bytecode");
-	print_uint(PRINT_ANY, "length", "bytecode \'%u,", len);
-	open_json_array(PRINT_JSON, "insns");
-
-	for (i = 0; i < len; i++) {
-		open_json_object(NULL);
-		print_hu(PRINT_ANY, "code", "%hu ", ops[i].code);
-		print_hhu(PRINT_ANY, "jt", "%hhu ", ops[i].jt);
-		print_hhu(PRINT_ANY, "jf", "%hhu ", ops[i].jf);
-		if (i == len - 1)
-			print_uint(PRINT_ANY, "k", "%u\'", ops[i].k);
-		else
-			print_uint(PRINT_ANY, "k", "%u,", ops[i].k);
-		close_json_object();
-	}
-
-	close_json_array(PRINT_JSON, NULL);
-	close_json_object();
-}
-
-static void bpf_map_pin_report(const struct bpf_elf_map *pin,
-			       const struct bpf_elf_map *obj)
-{
-	fprintf(stderr, "Map specification differs from pinned file!\n");
-
-	if (obj->type != pin->type)
-		fprintf(stderr, " - Type:         %u (obj) != %u (pin)\n",
-			obj->type, pin->type);
-	if (obj->size_key != pin->size_key)
-		fprintf(stderr, " - Size key:     %u (obj) != %u (pin)\n",
-			obj->size_key, pin->size_key);
-	if (obj->size_value != pin->size_value)
-		fprintf(stderr, " - Size value:   %u (obj) != %u (pin)\n",
-			obj->size_value, pin->size_value);
-	if (obj->max_elem != pin->max_elem)
-		fprintf(stderr, " - Max elems:    %u (obj) != %u (pin)\n",
-			obj->max_elem, pin->max_elem);
-	if (obj->flags != pin->flags)
-		fprintf(stderr, " - Flags:        %#x (obj) != %#x (pin)\n",
-			obj->flags, pin->flags);
-
-	fprintf(stderr, "\n");
-}
-
-struct bpf_prog_data {
-	unsigned int type;
-	unsigned int jited;
-};
-
-struct bpf_map_ext {
-	struct bpf_prog_data owner;
-	unsigned int btf_id_key;
-	unsigned int btf_id_val;
-};
-
-static int bpf_derive_elf_map_from_fdinfo(int fd, struct bpf_elf_map *map,
-					  struct bpf_map_ext *ext)
-{
-	unsigned int val, owner_type = 0, owner_jited = 0;
-	char *file = NULL;
-	char buff[4096];
-	FILE *fp;
-	int ret;
-
-	ret = asprintf(&file, "/proc/%d/fdinfo/%d", getpid(), fd);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		free(file);
-		return ret;
-	}
-	memset(map, 0, sizeof(*map));
-
-	fp = fopen(file, "r");
-	free(file);
-	if (!fp) {
-		fprintf(stderr, "No procfs support?!\n");
-		return -EIO;
-	}
-
-	while (fgets(buff, sizeof(buff), fp)) {
-		if (sscanf(buff, "map_type:\t%u", &val) == 1)
-			map->type = val;
-		else if (sscanf(buff, "key_size:\t%u", &val) == 1)
-			map->size_key = val;
-		else if (sscanf(buff, "value_size:\t%u", &val) == 1)
-			map->size_value = val;
-		else if (sscanf(buff, "max_entries:\t%u", &val) == 1)
-			map->max_elem = val;
-		else if (sscanf(buff, "map_flags:\t%i", &val) == 1)
-			map->flags = val;
-		else if (sscanf(buff, "owner_prog_type:\t%i", &val) == 1)
-			owner_type = val;
-		else if (sscanf(buff, "owner_jited:\t%i", &val) == 1)
-			owner_jited = val;
-	}
-
-	fclose(fp);
-	if (ext) {
-		memset(ext, 0, sizeof(*ext));
-		ext->owner.type  = owner_type;
-		ext->owner.jited = owner_jited;
-	}
-
-	return 0;
-}
-
-static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
-				    struct bpf_map_ext *ext, int length,
-				    enum bpf_prog_type type)
-{
-	struct bpf_elf_map tmp, zero = {};
-	int ret;
-
-	ret = bpf_derive_elf_map_from_fdinfo(fd, &tmp, ext);
-	if (ret < 0)
-		return ret;
-
-	/* The decision to reject this is on kernel side eventually, but
-	 * at least give the user a chance to know what's wrong.
-	 */
-	if (ext->owner.type && ext->owner.type != type)
-		fprintf(stderr, "Program array map owner types differ: %u (obj) != %u (pin)\n",
-			type, ext->owner.type);
-
-	if (!memcmp(&tmp, map, length)) {
-		return 0;
-	} else {
-		/* If kernel doesn't have eBPF-related fdinfo, we cannot do much,
-		 * so just accept it. We know we do have an eBPF fd and in this
-		 * case, everything is 0. It is guaranteed that no such map exists
-		 * since map type of 0 is unloadable BPF_MAP_TYPE_UNSPEC.
-		 */
-		if (!memcmp(&tmp, &zero, length))
-			return 0;
-
-		bpf_map_pin_report(&tmp, map);
-		return -EINVAL;
-	}
-}
-
-static int bpf_mnt_fs(const char *target)
-{
-	bool bind_done = false;
-
-	while (mount("", target, "none", MS_PRIVATE | MS_REC, NULL)) {
-		if (errno != EINVAL || bind_done) {
-			fprintf(stderr, "mount --make-private %s failed: %s\n",
-				target,	strerror(errno));
-			return -1;
-		}
-
-		if (mount(target, target, "none", MS_BIND, NULL)) {
-			fprintf(stderr, "mount --bind %s %s failed: %s\n",
-				target,	target, strerror(errno));
-			return -1;
-		}
-
-		bind_done = true;
-	}
-
-	if (mount("bpf", target, "bpf", 0, "mode=0700")) {
-		fprintf(stderr, "mount -t bpf bpf %s failed: %s\n",
-			target,	strerror(errno));
-		return -1;
-	}
-
-	return 0;
-}
-
-static int bpf_mnt_check_target(const char *target)
-{
-	struct stat sb = {};
-	int ret;
-
-	ret = stat(target, &sb);
-	if (ret) {
-		ret = mkdir(target, S_IRWXU);
-		if (ret) {
-			fprintf(stderr, "mkdir %s failed: %s\n", target,
-				strerror(errno));
-			return ret;
-		}
-	}
-
-	return 0;
-}
-
-static int bpf_valid_mntpt(const char *mnt, unsigned long magic)
-{
-	struct statfs st_fs;
-
-	if (statfs(mnt, &st_fs) < 0)
-		return -ENOENT;
-	if ((unsigned long)st_fs.f_type != magic)
-		return -ENOENT;
-
-	return 0;
-}
-
-static const char *bpf_find_mntpt_single(unsigned long magic, char *mnt,
-					 int len, const char *mntpt)
-{
-	int ret;
-
-	ret = bpf_valid_mntpt(mntpt, magic);
-	if (!ret) {
-		strlcpy(mnt, mntpt, len);
-		return mnt;
-	}
-
-	return NULL;
-}
-
-static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
-				  char *mnt, int len,
-				  const char * const *known_mnts)
-{
-	const char * const *ptr;
-	char type[100];
-	FILE *fp;
-
-	if (known_mnts) {
-		ptr = known_mnts;
-		while (*ptr) {
-			if (bpf_find_mntpt_single(magic, mnt, len, *ptr))
-				return mnt;
-			ptr++;
-		}
-	}
-
-	if (len != PATH_MAX)
-		return NULL;
-
-	fp = fopen("/proc/mounts", "r");
-	if (fp == NULL)
-		return NULL;
-
-	while (fscanf(fp, "%*s %" textify(PATH_MAX) "s %99s %*s %*d %*d\n",
-		      mnt, type) == 2) {
-		if (strcmp(type, fstype) == 0)
-			break;
-	}
-
-	fclose(fp);
-	if (strcmp(type, fstype) != 0)
-		return NULL;
-
-	return mnt;
-}
-
-int bpf_trace_pipe(void)
-{
-	char tracefs_mnt[PATH_MAX] = TRACE_DIR_MNT;
-	static const char * const tracefs_known_mnts[] = {
-		TRACE_DIR_MNT,
-		"/sys/kernel/debug/tracing",
-		"/tracing",
-		"/trace",
-		0,
-	};
-	int fd_in, fd_out = STDERR_FILENO;
-	char *tpipe = NULL;
-	const char *mnt;
-	int ret;
-
-	mnt = bpf_find_mntpt("tracefs", TRACEFS_MAGIC, tracefs_mnt,
-			     sizeof(tracefs_mnt), tracefs_known_mnts);
-	if (!mnt) {
-		fprintf(stderr, "tracefs not mounted?\n");
-		return -1;
-	}
-
-	ret = asprintf(&tpipe, "%s/trace_pipe", mnt);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		free(tpipe);
-		return ret;
-	}
-
-	fd_in = open(tpipe, O_RDONLY);
-	free(tpipe);
-	if (fd_in < 0)
-		return -1;
-
-	fprintf(stderr, "Running! Hang up with ^C!\n\n");
-	while (1) {
-		static char buff[4096];
-		ssize_t ret;
-
-		ret = read(fd_in, buff, sizeof(buff));
-		if (ret > 0 && write(fd_out, buff, ret) == ret)
-			continue;
-		break;
-	}
-
-	close(fd_in);
-	return -1;
-}
-
-static int bpf_gen_global(const char *bpf_sub_dir)
-{
-	char *bpf_glo_dir = NULL;
-	int ret;
-
-	ret = asprintf(&bpf_glo_dir, "%s/%s/", bpf_sub_dir, BPF_DIR_GLOBALS);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	ret = mkdir(bpf_glo_dir, S_IRWXU);
-	if (ret && errno != EEXIST) {
-		fprintf(stderr, "mkdir %s failed: %s\n", bpf_glo_dir,
-			strerror(errno));
-		goto out;
-	}
-
-	ret = 0;
-out:
-	free(bpf_glo_dir);
-	return ret;
-}
-
-static int bpf_gen_master(const char *base, const char *name)
-{
-	char *bpf_sub_dir = NULL;
-	int ret;
-
-	ret = asprintf(&bpf_sub_dir, "%s%s/", base, name);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	ret = mkdir(bpf_sub_dir, S_IRWXU);
-	if (ret && errno != EEXIST) {
-		fprintf(stderr, "mkdir %s failed: %s\n", bpf_sub_dir,
-			strerror(errno));
-		goto out;
-	}
-
-	ret = bpf_gen_global(bpf_sub_dir);
-out:
-	free(bpf_sub_dir);
-	return ret;
-}
-
-static int bpf_slave_via_bind_mnt(const char *full_name,
-				  const char *full_link)
-{
-	int ret;
-
-	ret = mkdir(full_name, S_IRWXU);
-	if (ret) {
-		assert(errno != EEXIST);
-		fprintf(stderr, "mkdir %s failed: %s\n", full_name,
-			strerror(errno));
-		return ret;
-	}
-
-	ret = mount(full_link, full_name, "none", MS_BIND, NULL);
-	if (ret) {
-		rmdir(full_name);
-		fprintf(stderr, "mount --bind %s %s failed: %s\n",
-			full_link, full_name, strerror(errno));
-	}
-
-	return ret;
-}
-
-static int bpf_gen_slave(const char *base, const char *name,
-			 const char *link)
-{
-	char *bpf_lnk_dir = NULL;
-	char *bpf_sub_dir = NULL;
-	struct stat sb = {};
-	int ret;
-
-	ret = asprintf(&bpf_lnk_dir, "%s%s/", base, link);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	ret = asprintf(&bpf_sub_dir, "%s%s",  base, name);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	ret = symlink(bpf_lnk_dir, bpf_sub_dir);
-	if (ret) {
-		if (errno != EEXIST) {
-			if (errno != EPERM) {
-				fprintf(stderr, "symlink %s failed: %s\n",
-					bpf_sub_dir, strerror(errno));
-				goto out;
-			}
-
-			ret = bpf_slave_via_bind_mnt(bpf_sub_dir, bpf_lnk_dir);
-			goto out;
-		}
-
-		ret = lstat(bpf_sub_dir, &sb);
-		if (ret) {
-			fprintf(stderr, "lstat %s failed: %s\n",
-				bpf_sub_dir, strerror(errno));
-			goto out;
-		}
-
-		if ((sb.st_mode & S_IFMT) != S_IFLNK) {
-			ret = bpf_gen_global(bpf_sub_dir);
-			goto out;
-		}
-	}
-
-out:
-	free(bpf_lnk_dir);
-	free(bpf_sub_dir);
-	return ret;
-}
-
-static int bpf_gen_hierarchy(const char *base)
-{
-	int ret, i;
-
-	ret = bpf_gen_master(base, bpf_prog_to_subdir(__bpf_types[0]));
-	for (i = 1; i < ARRAY_SIZE(__bpf_types) && !ret; i++)
-		ret = bpf_gen_slave(base,
-				    bpf_prog_to_subdir(__bpf_types[i]),
-				    bpf_prog_to_subdir(__bpf_types[0]));
-	return ret;
-}
-
-static const char *bpf_get_work_dir(enum bpf_prog_type type)
-{
-	static char bpf_tmp[PATH_MAX] = BPF_DIR_MNT;
-	static char *bpf_wrk_dir;
-	static const char *mnt;
-	static bool bpf_mnt_cached;
-	const char *mnt_env = getenv(BPF_ENV_MNT);
-	static const char * const bpf_known_mnts[] = {
-		BPF_DIR_MNT,
-		"/bpf",
-		0,
-	};
-	int ret;
-
-	if (bpf_mnt_cached) {
-		const char *out = mnt;
-
-		if (out && type) {
-			snprintf(bpf_tmp, sizeof(bpf_tmp), "%s%s/",
-				 out, bpf_prog_to_subdir(type));
-			out = bpf_tmp;
-		}
-		return out;
-	}
-
-	if (mnt_env)
-		mnt = bpf_find_mntpt_single(BPF_FS_MAGIC, bpf_tmp,
-					    sizeof(bpf_tmp), mnt_env);
-	else
-		mnt = bpf_find_mntpt("bpf", BPF_FS_MAGIC, bpf_tmp,
-				     sizeof(bpf_tmp), bpf_known_mnts);
-	if (!mnt) {
-		mnt = mnt_env ? : BPF_DIR_MNT;
-		ret = bpf_mnt_check_target(mnt);
-		if (!ret)
-			ret = bpf_mnt_fs(mnt);
-		if (ret) {
-			mnt = NULL;
-			goto out;
-		}
-	}
-
-	ret = asprintf(&bpf_wrk_dir, "%s/", mnt);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		free(bpf_wrk_dir);
-		goto out;
-	}
-
-	ret = bpf_gen_hierarchy(bpf_wrk_dir);
-	if (ret) {
-		mnt = NULL;
-		goto out;
-	}
-
-	mnt = bpf_wrk_dir;
-out:
-	bpf_mnt_cached = true;
-	return mnt;
-}
-
-static int bpf_obj_get(const char *pathname, enum bpf_prog_type type)
-{
-	union bpf_attr attr = {};
-	char tmp[PATH_MAX];
-
-	if (strlen(pathname) > 2 && pathname[0] == 'm' &&
-	    pathname[1] == ':' && bpf_get_work_dir(type)) {
-		snprintf(tmp, sizeof(tmp), "%s/%s",
-			 bpf_get_work_dir(type), pathname + 2);
-		pathname = tmp;
-	}
-
-	attr.pathname = bpf_ptr_to_u64(pathname);
-
-	return bpf(BPF_OBJ_GET, &attr, sizeof(attr));
-}
-
-static int bpf_obj_pinned(const char *pathname, enum bpf_prog_type type)
-{
-	int prog_fd = bpf_obj_get(pathname, type);
-
-	if (prog_fd < 0)
-		fprintf(stderr, "Couldn\'t retrieve pinned program \'%s\': %s\n",
-			pathname, strerror(errno));
-	return prog_fd;
-}
-
-static int bpf_do_parse(struct bpf_cfg_in *cfg, const bool *opt_tbl)
-{
-	const char *file, *section, *uds_name;
-	bool verbose = false;
-	int i, ret, argc;
-	char **argv;
-
-	argv = cfg->argv;
-	argc = cfg->argc;
-
-	if (opt_tbl[CBPF_BYTECODE] &&
-	    (matches(*argv, "bytecode") == 0 ||
-	     strcmp(*argv, "bc") == 0)) {
-		cfg->mode = CBPF_BYTECODE;
-	} else if (opt_tbl[CBPF_FILE] &&
-		   (matches(*argv, "bytecode-file") == 0 ||
-		    strcmp(*argv, "bcf") == 0)) {
-		cfg->mode = CBPF_FILE;
-	} else if (opt_tbl[EBPF_OBJECT] &&
-		   (matches(*argv, "object-file") == 0 ||
-		    strcmp(*argv, "obj") == 0)) {
-		cfg->mode = EBPF_OBJECT;
-	} else if (opt_tbl[EBPF_PINNED] &&
-		   (matches(*argv, "object-pinned") == 0 ||
-		    matches(*argv, "pinned") == 0 ||
-		    matches(*argv, "fd") == 0)) {
-		cfg->mode = EBPF_PINNED;
-	} else {
-		fprintf(stderr, "What mode is \"%s\"?\n", *argv);
-		return -1;
-	}
-
-	NEXT_ARG();
-	file = section = uds_name = NULL;
-	if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
-		file = *argv;
-		NEXT_ARG_FWD();
-
-		if (cfg->type == BPF_PROG_TYPE_UNSPEC) {
-			if (argc > 0 && matches(*argv, "type") == 0) {
-				NEXT_ARG();
-				for (i = 0; i < ARRAY_SIZE(__bpf_prog_meta);
-				     i++) {
-					if (!__bpf_prog_meta[i].type)
-						continue;
-					if (!matches(*argv,
-						     __bpf_prog_meta[i].type)) {
-						cfg->type = i;
-						break;
-					}
-				}
-
-				if (cfg->type == BPF_PROG_TYPE_UNSPEC) {
-					fprintf(stderr, "What type is \"%s\"?\n",
-						*argv);
-					return -1;
-				}
-				NEXT_ARG_FWD();
-			} else {
-				cfg->type = BPF_PROG_TYPE_SCHED_CLS;
-			}
-		}
-
-		section = bpf_prog_to_default_section(cfg->type);
-		if (argc > 0 && matches(*argv, "section") == 0) {
-			NEXT_ARG();
-			section = *argv;
-			NEXT_ARG_FWD();
-		}
-
-		if (__bpf_prog_meta[cfg->type].may_uds_export) {
-			uds_name = getenv(BPF_ENV_UDS);
-			if (argc > 0 && !uds_name &&
-			    matches(*argv, "export") == 0) {
-				NEXT_ARG();
-				uds_name = *argv;
-				NEXT_ARG_FWD();
-			}
-		}
-
-		if (argc > 0 && matches(*argv, "verbose") == 0) {
-			verbose = true;
-			NEXT_ARG_FWD();
-		}
-
-		PREV_ARG();
-	}
-
-	if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE) {
-		ret = bpf_ops_parse(argc, argv, cfg->opcodes,
-				    cfg->mode == CBPF_FILE);
-		cfg->n_opcodes = ret;
-	} else if (cfg->mode == EBPF_OBJECT) {
-		ret = 0; /* program will be loaded by load stage */
-	} else if (cfg->mode == EBPF_PINNED) {
-		ret = bpf_obj_pinned(file, cfg->type);
-		cfg->prog_fd = ret;
-	} else {
-		return -1;
-	}
-
-	cfg->object  = file;
-	cfg->section = section;
-	cfg->uds     = uds_name;
-	cfg->argc    = argc;
-	cfg->argv    = argv;
-	cfg->verbose = verbose;
-
-	return ret;
-}
-
-static int bpf_do_load(struct bpf_cfg_in *cfg)
-{
-	if (cfg->mode == EBPF_OBJECT) {
-		cfg->prog_fd = bpf_obj_open(cfg->object, cfg->type,
-					    cfg->section, cfg->ifindex,
-					    cfg->verbose);
-		return cfg->prog_fd;
-	}
-	return 0;
-}
-
-int bpf_load_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops,
-		    void *nl)
-{
-	char annotation[256];
-	int ret;
-
-	ret = bpf_do_load(cfg);
-	if (ret < 0)
-		return ret;
-
-	if (cfg->mode == CBPF_BYTECODE || cfg->mode == CBPF_FILE)
-		ops->cbpf_cb(nl, cfg->opcodes, cfg->n_opcodes);
-	if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
-		snprintf(annotation, sizeof(annotation), "%s:[%s]",
-			 basename(cfg->object), cfg->mode == EBPF_PINNED ?
-			 "*fsobj" : cfg->section);
-		ops->ebpf_cb(nl, cfg->prog_fd, annotation);
-	}
-
-	return 0;
-}
-
-int bpf_parse_common(struct bpf_cfg_in *cfg, const struct bpf_cfg_ops *ops)
-{
-	bool opt_tbl[BPF_MODE_MAX] = {};
-
-	if (ops->cbpf_cb) {
-		opt_tbl[CBPF_BYTECODE] = true;
-		opt_tbl[CBPF_FILE]     = true;
-	}
-
-	if (ops->ebpf_cb) {
-		opt_tbl[EBPF_OBJECT]   = true;
-		opt_tbl[EBPF_PINNED]   = true;
-	}
-
-	return bpf_do_parse(cfg, opt_tbl);
-}
-
-int bpf_parse_and_load_common(struct bpf_cfg_in *cfg,
-			      const struct bpf_cfg_ops *ops, void *nl)
-{
-	int ret;
-
-	ret = bpf_parse_common(cfg, ops);
-	if (ret < 0)
-		return ret;
-
-	return bpf_load_common(cfg, ops, nl);
-}
-
-int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv)
-{
-	const bool opt_tbl[BPF_MODE_MAX] = {
-		[EBPF_OBJECT]	= true,
-		[EBPF_PINNED]	= true,
-	};
-	const struct bpf_elf_map test = {
-		.type		= BPF_MAP_TYPE_PROG_ARRAY,
-		.size_key	= sizeof(int),
-		.size_value	= sizeof(int),
-	};
-	struct bpf_cfg_in cfg = {
-		.type		= BPF_PROG_TYPE_UNSPEC,
-		.argc		= argc,
-		.argv		= argv,
-	};
-	struct bpf_map_ext ext = {};
-	int ret, prog_fd, map_fd;
-	uint32_t map_key;
-
-	ret = bpf_do_parse(&cfg, opt_tbl);
-	if (ret < 0)
-		return ret;
-
-	ret = bpf_do_load(&cfg);
-	if (ret < 0)
-		return ret;
-
-	prog_fd = cfg.prog_fd;
-
-	if (key) {
-		map_key = *key;
-	} else {
-		ret = sscanf(cfg.section, "%*i/%i", &map_key);
-		if (ret != 1) {
-			fprintf(stderr, "Couldn\'t infer map key from section name! Please provide \'key\' argument!\n");
-			ret = -EINVAL;
-			goto out_prog;
-		}
-	}
-
-	map_fd = bpf_obj_get(map_path, cfg.type);
-	if (map_fd < 0) {
-		fprintf(stderr, "Couldn\'t retrieve pinned map \'%s\': %s\n",
-			map_path, strerror(errno));
-		ret = map_fd;
-		goto out_prog;
-	}
-
-	ret = bpf_map_selfcheck_pinned(map_fd, &test, &ext,
-				       offsetof(struct bpf_elf_map, max_elem),
-				       cfg.type);
-	if (ret < 0) {
-		fprintf(stderr, "Map \'%s\' self-check failed!\n", map_path);
-		goto out_map;
-	}
-
-	ret = bpf_map_update(map_fd, &map_key, &prog_fd, BPF_ANY);
-	if (ret < 0)
-		fprintf(stderr, "Map update failed: %s\n", strerror(errno));
-out_map:
-	close(map_fd);
-out_prog:
-	close(prog_fd);
-	return ret;
-}
-
-int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type)
-{
-	union bpf_attr attr = {};
-
-	attr.target_fd = target_fd;
-	attr.attach_bpf_fd = prog_fd;
-	attr.attach_type = type;
-
-	return bpf(BPF_PROG_ATTACH, &attr, sizeof(attr));
-}
-
-int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type)
-{
-	union bpf_attr attr = {};
-
-	attr.target_fd = target_fd;
-	attr.attach_type = type;
-
-	return bpf(BPF_PROG_DETACH, &attr, sizeof(attr));
-}
-
-static int bpf_prog_load_dev(enum bpf_prog_type type,
-			     const struct bpf_insn *insns, size_t size_insns,
-			     const char *license, __u32 ifindex,
-			     char *log, size_t size_log)
-{
-	union bpf_attr attr = {};
-
-	attr.prog_type = type;
-	attr.insns = bpf_ptr_to_u64(insns);
-	attr.insn_cnt = size_insns / sizeof(struct bpf_insn);
-	attr.license = bpf_ptr_to_u64(license);
-	attr.prog_ifindex = ifindex;
-
-	if (size_log > 0) {
-		attr.log_buf = bpf_ptr_to_u64(log);
-		attr.log_size = size_log;
-		attr.log_level = 1;
-	}
-
-	return bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-}
-
-int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		  size_t size_insns, const char *license, char *log,
-		  size_t size_log)
-{
-	return bpf_prog_load_dev(type, insns, size_insns, license, 0,
-				 log, size_log);
-}
-
-#ifdef HAVE_ELF
-struct bpf_elf_prog {
-	enum bpf_prog_type	type;
-	struct bpf_insn		*insns;
-	unsigned int		insns_num;
-	size_t			size;
-	const char		*license;
-};
-
-struct bpf_hash_entry {
-	unsigned int		pinning;
-	const char		*subpath;
-	struct bpf_hash_entry	*next;
-};
-
-struct bpf_config {
-	unsigned int		jit_enabled;
-};
-
-struct bpf_btf {
-	const struct btf_header	*hdr;
-	const void		*raw;
-	const char		*strings;
-	const struct btf_type	**types;
-	int			types_num;
-};
-
-struct bpf_elf_ctx {
-	struct bpf_config	cfg;
-	Elf			*elf_fd;
-	GElf_Ehdr		elf_hdr;
-	Elf_Data		*sym_tab;
-	Elf_Data		*str_tab;
-	Elf_Data		*btf_data;
-	char			obj_uid[64];
-	int			obj_fd;
-	int			btf_fd;
-	int			map_fds[ELF_MAX_MAPS];
-	struct bpf_elf_map	maps[ELF_MAX_MAPS];
-	struct bpf_map_ext	maps_ext[ELF_MAX_MAPS];
-	struct bpf_elf_prog	prog_text;
-	struct bpf_btf		btf;
-	int			sym_num;
-	int			map_num;
-	int			map_len;
-	bool			*sec_done;
-	int			sec_maps;
-	int			sec_text;
-	int			sec_btf;
-	char			license[ELF_MAX_LICENSE_LEN];
-	enum bpf_prog_type	type;
-	__u32			ifindex;
-	bool			verbose;
-	bool			noafalg;
-	struct bpf_elf_st	stat;
-	struct bpf_hash_entry	*ht[256];
-	char			*log;
-	size_t			log_size;
-};
-
-struct bpf_elf_sec_data {
-	GElf_Shdr		sec_hdr;
-	Elf_Data		*sec_data;
-	const char		*sec_name;
-};
-
-struct bpf_map_data {
-	int			*fds;
-	const char		*obj;
-	struct bpf_elf_st	*st;
-	struct bpf_elf_map	*ent;
-};
-
-static bool bpf_log_has_data(struct bpf_elf_ctx *ctx)
-{
-	return ctx->log && ctx->log[0];
-}
-
-static __check_format_string(2, 3) void
-bpf_dump_error(struct bpf_elf_ctx *ctx, const char *format, ...)
-{
-	va_list vl;
-
-	va_start(vl, format);
-	vfprintf(stderr, format, vl);
-	va_end(vl);
-
-	if (bpf_log_has_data(ctx)) {
-		if (ctx->verbose) {
-			fprintf(stderr, "%s\n", ctx->log);
-		} else {
-			unsigned int off = 0, len = strlen(ctx->log);
-
-			if (len > BPF_MAX_LOG) {
-				off = len - BPF_MAX_LOG;
-				fprintf(stderr, "Skipped %u bytes, use \'verb\' option for the full verbose log.\n[...]\n",
-					off);
-			}
-			fprintf(stderr, "%s\n", ctx->log + off);
-		}
-
-		memset(ctx->log, 0, ctx->log_size);
-	}
-}
-
-static int bpf_log_realloc(struct bpf_elf_ctx *ctx)
-{
-	const size_t log_max = UINT_MAX >> 8;
-	size_t log_size = ctx->log_size;
-	char *ptr;
-
-	if (!ctx->log) {
-		log_size = 65536;
-	} else if (log_size < log_max) {
-		log_size <<= 1;
-		if (log_size > log_max)
-			log_size = log_max;
-	} else {
-		return -EINVAL;
-	}
-
-	ptr = realloc(ctx->log, log_size);
-	if (!ptr)
-		return -ENOMEM;
-
-	ptr[0] = 0;
-	ctx->log = ptr;
-	ctx->log_size = log_size;
-
-	return 0;
-}
-
-static int bpf_map_create(enum bpf_map_type type, uint32_t size_key,
-			  uint32_t size_value, uint32_t max_elem,
-			  uint32_t flags, int inner_fd, int btf_fd,
-			  uint32_t ifindex, uint32_t btf_id_key,
-			  uint32_t btf_id_val)
-{
-	union bpf_attr attr = {};
-
-	attr.map_type = type;
-	attr.key_size = size_key;
-	attr.value_size = inner_fd ? sizeof(int) : size_value;
-	attr.max_entries = max_elem;
-	attr.map_flags = flags;
-	attr.inner_map_fd = inner_fd;
-	attr.map_ifindex = ifindex;
-	attr.btf_fd = btf_fd;
-	attr.btf_key_type_id = btf_id_key;
-	attr.btf_value_type_id = btf_id_val;
-
-	return bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-static int bpf_btf_load(void *btf, size_t size_btf,
-			char *log, size_t size_log)
-{
-	union bpf_attr attr = {};
-
-	attr.btf = bpf_ptr_to_u64(btf);
-	attr.btf_size = size_btf;
-
-	if (size_log > 0) {
-		attr.btf_log_buf = bpf_ptr_to_u64(log);
-		attr.btf_log_size = size_log;
-		attr.btf_log_level = 1;
-	}
-
-	return bpf(BPF_BTF_LOAD, &attr, sizeof(attr));
-}
-
-static int bpf_obj_pin(int fd, const char *pathname)
-{
-	union bpf_attr attr = {};
-
-	attr.pathname = bpf_ptr_to_u64(pathname);
-	attr.bpf_fd = fd;
-
-	return bpf(BPF_OBJ_PIN, &attr, sizeof(attr));
-}
-
-static int bpf_obj_hash(const char *object, uint8_t *out, size_t len)
-{
-	struct sockaddr_alg alg = {
-		.salg_family	= AF_ALG,
-		.salg_type	= "hash",
-		.salg_name	= "sha1",
-	};
-	int ret, cfd, ofd, ffd;
-	struct stat stbuff;
-	ssize_t size;
-
-	if (!object || len != 20)
-		return -EINVAL;
-
-	cfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
-	if (cfd < 0)
-		return cfd;
-
-	ret = bind(cfd, (struct sockaddr *)&alg, sizeof(alg));
-	if (ret < 0)
-		goto out_cfd;
-
-	ofd = accept(cfd, NULL, 0);
-	if (ofd < 0) {
-		ret = ofd;
-		goto out_cfd;
-	}
-
-	ffd = open(object, O_RDONLY);
-	if (ffd < 0) {
-		fprintf(stderr, "Error opening object %s: %s\n",
-			object, strerror(errno));
-		ret = ffd;
-		goto out_ofd;
-	}
-
-	ret = fstat(ffd, &stbuff);
-	if (ret < 0) {
-		fprintf(stderr, "Error doing fstat: %s\n",
-			strerror(errno));
-		goto out_ffd;
-	}
-
-	size = sendfile(ofd, ffd, NULL, stbuff.st_size);
-	if (size != stbuff.st_size) {
-		fprintf(stderr, "Error from sendfile (%zd vs %zu bytes): %s\n",
-			size, stbuff.st_size, strerror(errno));
-		ret = -1;
-		goto out_ffd;
-	}
-
-	size = read(ofd, out, len);
-	if (size != len) {
-		fprintf(stderr, "Error from read (%zd vs %zu bytes): %s\n",
-			size, len, strerror(errno));
-		ret = -1;
-	} else {
-		ret = 0;
-	}
-out_ffd:
-	close(ffd);
-out_ofd:
-	close(ofd);
-out_cfd:
-	close(cfd);
-	return ret;
-}
-
-static void bpf_init_env(void)
-{
-	struct rlimit limit = {
-		.rlim_cur = RLIM_INFINITY,
-		.rlim_max = RLIM_INFINITY,
-	};
-
-	/* Don't bother in case we fail! */
-	setrlimit(RLIMIT_MEMLOCK, &limit);
-
-	if (!bpf_get_work_dir(BPF_PROG_TYPE_UNSPEC))
-		fprintf(stderr, "Continuing without mounted eBPF fs. Too old kernel?\n");
-}
-
-static const char *bpf_custom_pinning(const struct bpf_elf_ctx *ctx,
-				      uint32_t pinning)
-{
-	struct bpf_hash_entry *entry;
-
-	entry = ctx->ht[pinning & (ARRAY_SIZE(ctx->ht) - 1)];
-	while (entry && entry->pinning != pinning)
-		entry = entry->next;
-
-	return entry ? entry->subpath : NULL;
-}
-
-static bool bpf_no_pinning(const struct bpf_elf_ctx *ctx,
-			   uint32_t pinning)
-{
-	switch (pinning) {
-	case PIN_OBJECT_NS:
-	case PIN_GLOBAL_NS:
-		return false;
-	case PIN_NONE:
-		return true;
-	default:
-		return !bpf_custom_pinning(ctx, pinning);
-	}
-}
-
-static void bpf_make_pathname(char *pathname, size_t len, const char *name,
-			      const struct bpf_elf_ctx *ctx, uint32_t pinning)
-{
-	switch (pinning) {
-	case PIN_OBJECT_NS:
-		snprintf(pathname, len, "%s/%s/%s",
-			 bpf_get_work_dir(ctx->type),
-			 ctx->obj_uid, name);
-		break;
-	case PIN_GLOBAL_NS:
-		snprintf(pathname, len, "%s/%s/%s",
-			 bpf_get_work_dir(ctx->type),
-			 BPF_DIR_GLOBALS, name);
-		break;
-	default:
-		snprintf(pathname, len, "%s/../%s/%s",
-			 bpf_get_work_dir(ctx->type),
-			 bpf_custom_pinning(ctx, pinning), name);
-		break;
-	}
-}
-
-static int bpf_probe_pinned(const char *name, const struct bpf_elf_ctx *ctx,
-			    uint32_t pinning)
-{
-	char pathname[PATH_MAX];
-
-	if (bpf_no_pinning(ctx, pinning) || !bpf_get_work_dir(ctx->type))
-		return 0;
-
-	bpf_make_pathname(pathname, sizeof(pathname), name, ctx, pinning);
-	return bpf_obj_get(pathname, ctx->type);
-}
-
-static int bpf_make_obj_path(const struct bpf_elf_ctx *ctx)
-{
-	char *tmp = NULL;
-	int ret;
-
-	ret = asprintf(&tmp, "%s/%s", bpf_get_work_dir(ctx->type), ctx->obj_uid);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	ret = mkdir(tmp, S_IRWXU);
-	if (ret && errno != EEXIST) {
-		fprintf(stderr, "mkdir %s failed: %s\n", tmp, strerror(errno));
-		goto out;
-	}
-
-	ret = 0;
-out:
-	free(tmp);
-	return ret;
-}
-
-static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx,
-				const char *todo)
-{
-	char *tmp = NULL;
-	char *rem = NULL;
-	char *sub;
-	int ret;
-
-	ret = asprintf(&tmp, "%s/../", bpf_get_work_dir(ctx->type));
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	ret = asprintf(&rem, "%s/", todo);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
-	}
-
-	sub = strtok(rem, "/");
-	while (sub) {
-		if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX)
-			return -EINVAL;
-
-		strcat(tmp, sub);
-		strcat(tmp, "/");
-
-		ret = mkdir(tmp, S_IRWXU);
-		if (ret && errno != EEXIST) {
-			fprintf(stderr, "mkdir %s failed: %s\n", tmp,
-				strerror(errno));
-			goto out;
-		}
-
-		sub = strtok(NULL, "/");
-	}
-
-	ret = 0;
-out:
-	free(rem);
-	free(tmp);
-	return ret;
-}
-
-static int bpf_place_pinned(int fd, const char *name,
-			    const struct bpf_elf_ctx *ctx, uint32_t pinning)
-{
-	char pathname[PATH_MAX];
-	const char *tmp;
-	int ret = 0;
-
-	if (bpf_no_pinning(ctx, pinning) || !bpf_get_work_dir(ctx->type))
-		return 0;
-
-	if (pinning == PIN_OBJECT_NS)
-		ret = bpf_make_obj_path(ctx);
-	else if ((tmp = bpf_custom_pinning(ctx, pinning)))
-		ret = bpf_make_custom_path(ctx, tmp);
-	if (ret < 0)
-		return ret;
-
-	bpf_make_pathname(pathname, sizeof(pathname), name, ctx, pinning);
-	return bpf_obj_pin(fd, pathname);
-}
-
-static void bpf_prog_report(int fd, const char *section,
-			    const struct bpf_elf_prog *prog,
-			    struct bpf_elf_ctx *ctx)
-{
-	unsigned int insns = prog->size / sizeof(struct bpf_insn);
-
-	fprintf(stderr, "\nProg section \'%s\' %s%s (%d)!\n", section,
-		fd < 0 ? "rejected: " : "loaded",
-		fd < 0 ? strerror(errno) : "",
-		fd < 0 ? errno : fd);
-
-	fprintf(stderr, " - Type:         %u\n", prog->type);
-	fprintf(stderr, " - Instructions: %u (%u over limit)\n",
-		insns, insns > BPF_MAXINSNS ? insns - BPF_MAXINSNS : 0);
-	fprintf(stderr, " - License:      %s\n\n", prog->license);
-
-	bpf_dump_error(ctx, "Verifier analysis:\n\n");
-}
-
-static int bpf_prog_attach(const char *section,
-			   const struct bpf_elf_prog *prog,
-			   struct bpf_elf_ctx *ctx)
-{
-	int tries = 0, fd;
-retry:
-	errno = 0;
-	fd = bpf_prog_load_dev(prog->type, prog->insns, prog->size,
-			       prog->license, ctx->ifindex,
-			       ctx->log, ctx->log_size);
-	if (fd < 0 || ctx->verbose) {
-		/* The verifier log is pretty chatty, sometimes so chatty
-		 * on larger programs, that we could fail to dump everything
-		 * into our buffer. Still, try to give a debuggable error
-		 * log for the user, so enlarge it and re-fail.
-		 */
-		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
-			if (tries++ < 10 && !bpf_log_realloc(ctx))
-				goto retry;
-
-			fprintf(stderr, "Log buffer too small to dump verifier log %zu bytes (%d tries)!\n",
-				ctx->log_size, tries);
-			return fd;
-		}
-
-		bpf_prog_report(fd, section, prog, ctx);
-	}
-
-	return fd;
-}
-
-static void bpf_map_report(int fd, const char *name,
-			   const struct bpf_elf_map *map,
-			   struct bpf_elf_ctx *ctx, int inner_fd)
-{
-	fprintf(stderr, "Map object \'%s\' %s%s (%d)!\n", name,
-		fd < 0 ? "rejected: " : "loaded",
-		fd < 0 ? strerror(errno) : "",
-		fd < 0 ? errno : fd);
-
-	fprintf(stderr, " - Type:         %u\n", map->type);
-	fprintf(stderr, " - Identifier:   %u\n", map->id);
-	fprintf(stderr, " - Pinning:      %u\n", map->pinning);
-	fprintf(stderr, " - Size key:     %u\n", map->size_key);
-	fprintf(stderr, " - Size value:   %u\n",
-		inner_fd ? (int)sizeof(int) : map->size_value);
-	fprintf(stderr, " - Max elems:    %u\n", map->max_elem);
-	fprintf(stderr, " - Flags:        %#x\n\n", map->flags);
-}
-
-static int bpf_find_map_id(const struct bpf_elf_ctx *ctx, uint32_t id)
-{
-	int i;
-
-	for (i = 0; i < ctx->map_num; i++) {
-		if (ctx->maps[i].id != id)
-			continue;
-		if (ctx->map_fds[i] < 0)
-			return -EINVAL;
-
-		return ctx->map_fds[i];
-	}
-
-	return -ENOENT;
-}
-
-static void bpf_report_map_in_map(int outer_fd, uint32_t idx)
-{
-	struct bpf_elf_map outer_map;
-	int ret;
-
-	fprintf(stderr, "Cannot insert map into map! ");
-
-	ret = bpf_derive_elf_map_from_fdinfo(outer_fd, &outer_map, NULL);
-	if (!ret) {
-		if (idx >= outer_map.max_elem &&
-		    outer_map.type == BPF_MAP_TYPE_ARRAY_OF_MAPS) {
-			fprintf(stderr, "Outer map has %u elements, index %u is invalid!\n",
-				outer_map.max_elem, idx);
-			return;
-		}
-	}
-
-	fprintf(stderr, "Different map specs used for outer and inner map?\n");
-}
-
-static bool bpf_is_map_in_map_type(const struct bpf_elf_map *map)
-{
-	return map->type == BPF_MAP_TYPE_ARRAY_OF_MAPS ||
-	       map->type == BPF_MAP_TYPE_HASH_OF_MAPS;
-}
-
-static bool bpf_map_offload_neutral(enum bpf_map_type type)
-{
-	return type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
-}
-
-static int bpf_map_attach(const char *name, struct bpf_elf_ctx *ctx,
-			  const struct bpf_elf_map *map, struct bpf_map_ext *ext,
-			  int *have_map_in_map)
-{
-	int fd, ifindex, ret, map_inner_fd = 0;
-	bool retried = false;
-
-probe:
-	fd = bpf_probe_pinned(name, ctx, map->pinning);
-	if (fd > 0) {
-		ret = bpf_map_selfcheck_pinned(fd, map, ext,
-					       offsetof(struct bpf_elf_map,
-							id), ctx->type);
-		if (ret < 0) {
-			close(fd);
-			fprintf(stderr, "Map \'%s\' self-check failed!\n",
-				name);
-			return ret;
-		}
-		if (ctx->verbose)
-			fprintf(stderr, "Map \'%s\' loaded as pinned!\n",
-				name);
-		return fd;
-	}
-
-	if (have_map_in_map && bpf_is_map_in_map_type(map)) {
-		(*have_map_in_map)++;
-		if (map->inner_id)
-			return 0;
-		fprintf(stderr, "Map \'%s\' cannot be created since no inner map ID defined!\n",
-			name);
-		return -EINVAL;
-	}
-
-	if (!have_map_in_map && bpf_is_map_in_map_type(map)) {
-		map_inner_fd = bpf_find_map_id(ctx, map->inner_id);
-		if (map_inner_fd < 0) {
-			fprintf(stderr, "Map \'%s\' cannot be loaded. Inner map with ID %u not found!\n",
-				name, map->inner_id);
-			return -EINVAL;
-		}
-	}
-
-	ifindex = bpf_map_offload_neutral(map->type) ? 0 : ctx->ifindex;
-	errno = 0;
-	fd = bpf_map_create(map->type, map->size_key, map->size_value,
-			    map->max_elem, map->flags, map_inner_fd, ctx->btf_fd,
-			    ifindex, ext->btf_id_key, ext->btf_id_val);
-
-	if (fd < 0 || ctx->verbose) {
-		bpf_map_report(fd, name, map, ctx, map_inner_fd);
-		if (fd < 0)
-			return fd;
-	}
-
-	ret = bpf_place_pinned(fd, name, ctx, map->pinning);
-	if (ret < 0) {
-		close(fd);
-		if (!retried && errno == EEXIST) {
-			retried = true;
-			goto probe;
-		}
-		fprintf(stderr, "Could not pin %s map: %s\n", name,
-			strerror(errno));
-		return ret;
-	}
-
-	return fd;
-}
-
-static const char *bpf_str_tab_name(const struct bpf_elf_ctx *ctx,
-				    const GElf_Sym *sym)
-{
-	return ctx->str_tab->d_buf + sym->st_name;
-}
-
-static int bpf_btf_find(struct bpf_elf_ctx *ctx, const char *name)
-{
-	const struct btf_type *type;
-	const char *res;
-	int id;
-
-	for (id = 1; id < ctx->btf.types_num; id++) {
-		type = ctx->btf.types[id];
-		if (type->name_off >= ctx->btf.hdr->str_len)
-			continue;
-		res = &ctx->btf.strings[type->name_off];
-		if (!strcmp(res, name))
-			return id;
-	}
-
-	return -ENOENT;
-}
-
-static int bpf_btf_find_kv(struct bpf_elf_ctx *ctx, const struct bpf_elf_map *map,
-			   const char *name, uint32_t *id_key, uint32_t *id_val)
-{
-	const struct btf_member *key, *val;
-	const struct btf_type *type;
-	char btf_name[512];
-	const char *res;
-	int id;
-
-	snprintf(btf_name, sizeof(btf_name), "____btf_map_%s", name);
-	id = bpf_btf_find(ctx, btf_name);
-	if (id < 0)
-		return id;
-
-	type = ctx->btf.types[id];
-	if (BTF_INFO_KIND(type->info) != BTF_KIND_STRUCT)
-		return -EINVAL;
-	if (BTF_INFO_VLEN(type->info) != 2)
-		return -EINVAL;
-
-	key = ((void *) type) + sizeof(*type);
-	val = key + 1;
-	if (!key->type || key->type >= ctx->btf.types_num ||
-	    !val->type || val->type >= ctx->btf.types_num)
-		return -EINVAL;
-
-	if (key->name_off >= ctx->btf.hdr->str_len ||
-	    val->name_off >= ctx->btf.hdr->str_len)
-		return -EINVAL;
-
-	res = &ctx->btf.strings[key->name_off];
-	if (strcmp(res, "key"))
-		return -EINVAL;
-
-	res = &ctx->btf.strings[val->name_off];
-	if (strcmp(res, "value"))
-		return -EINVAL;
-
-	*id_key = key->type;
-	*id_val = val->type;
-	return 0;
-}
-
-static void bpf_btf_annotate(struct bpf_elf_ctx *ctx, int which, const char *name)
-{
-	uint32_t id_key = 0, id_val = 0;
-
-	if (!bpf_btf_find_kv(ctx, &ctx->maps[which], name, &id_key, &id_val)) {
-		ctx->maps_ext[which].btf_id_key = id_key;
-		ctx->maps_ext[which].btf_id_val = id_val;
-	}
-}
-
-static const char *bpf_map_fetch_name(struct bpf_elf_ctx *ctx, int which)
-{
-	const char *name;
-	GElf_Sym sym;
-	int i;
-
-	for (i = 0; i < ctx->sym_num; i++) {
-		int type;
-
-		if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
-			continue;
-
-		type = GELF_ST_TYPE(sym.st_info);
-		if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
-		    (type != STT_NOTYPE && type != STT_OBJECT) ||
-		    sym.st_shndx != ctx->sec_maps ||
-		    sym.st_value / ctx->map_len != which)
-			continue;
-
-		name = bpf_str_tab_name(ctx, &sym);
-		bpf_btf_annotate(ctx, which, name);
-		return name;
-	}
-
-	return NULL;
-}
-
-static int bpf_maps_attach_all(struct bpf_elf_ctx *ctx)
-{
-	int i, j, ret, fd, inner_fd, inner_idx, have_map_in_map = 0;
-	const char *map_name;
-
-	for (i = 0; i < ctx->map_num; i++) {
-		if (ctx->maps[i].pinning == PIN_OBJECT_NS &&
-		    ctx->noafalg) {
-			fprintf(stderr, "Missing kernel AF_ALG support for PIN_OBJECT_NS!\n");
-			return -ENOTSUP;
-		}
-
-		map_name = bpf_map_fetch_name(ctx, i);
-		if (!map_name)
-			return -EIO;
-
-		fd = bpf_map_attach(map_name, ctx, &ctx->maps[i],
-				    &ctx->maps_ext[i], &have_map_in_map);
-		if (fd < 0)
-			return fd;
-
-		ctx->map_fds[i] = !fd ? -1 : fd;
-	}
-
-	for (i = 0; have_map_in_map && i < ctx->map_num; i++) {
-		if (ctx->map_fds[i] >= 0)
-			continue;
-
-		map_name = bpf_map_fetch_name(ctx, i);
-		if (!map_name)
-			return -EIO;
-
-		fd = bpf_map_attach(map_name, ctx, &ctx->maps[i],
-				    &ctx->maps_ext[i], NULL);
-		if (fd < 0)
-			return fd;
-
-		ctx->map_fds[i] = fd;
-	}
-
-	for (i = 0; have_map_in_map && i < ctx->map_num; i++) {
-		if (!ctx->maps[i].id ||
-		    ctx->maps[i].inner_id ||
-		    ctx->maps[i].inner_idx == -1)
-			continue;
-
-		inner_fd  = ctx->map_fds[i];
-		inner_idx = ctx->maps[i].inner_idx;
-
-		for (j = 0; j < ctx->map_num; j++) {
-			if (!bpf_is_map_in_map_type(&ctx->maps[j]))
-				continue;
-			if (ctx->maps[j].inner_id != ctx->maps[i].id)
-				continue;
-
-			ret = bpf_map_update(ctx->map_fds[j], &inner_idx,
-					     &inner_fd, BPF_ANY);
-			if (ret < 0) {
-				bpf_report_map_in_map(ctx->map_fds[j],
-						      inner_idx);
-				return ret;
-			}
-		}
-	}
-
-	return 0;
-}
-
-static int bpf_map_num_sym(struct bpf_elf_ctx *ctx)
-{
-	int i, num = 0;
-	GElf_Sym sym;
-
-	for (i = 0; i < ctx->sym_num; i++) {
-		int type;
-
-		if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
-			continue;
-
-		type = GELF_ST_TYPE(sym.st_info);
-		if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
-		    (type != STT_NOTYPE && type != STT_OBJECT) ||
-		    sym.st_shndx != ctx->sec_maps)
-			continue;
-		num++;
-	}
-
-	return num;
-}
-
-static int bpf_fill_section_data(struct bpf_elf_ctx *ctx, int section,
-				 struct bpf_elf_sec_data *data)
-{
-	Elf_Data *sec_edata;
-	GElf_Shdr sec_hdr;
-	Elf_Scn *sec_fd;
-	char *sec_name;
-
-	memset(data, 0, sizeof(*data));
-
-	sec_fd = elf_getscn(ctx->elf_fd, section);
-	if (!sec_fd)
-		return -EINVAL;
-	if (gelf_getshdr(sec_fd, &sec_hdr) != &sec_hdr)
-		return -EIO;
-
-	sec_name = elf_strptr(ctx->elf_fd, ctx->elf_hdr.e_shstrndx,
-			      sec_hdr.sh_name);
-	if (!sec_name || !sec_hdr.sh_size)
-		return -ENOENT;
-
-	sec_edata = elf_getdata(sec_fd, NULL);
-	if (!sec_edata || elf_getdata(sec_fd, sec_edata))
-		return -EIO;
-
-	memcpy(&data->sec_hdr, &sec_hdr, sizeof(sec_hdr));
-
-	data->sec_name = sec_name;
-	data->sec_data = sec_edata;
-	return 0;
-}
-
-struct bpf_elf_map_min {
-	__u32 type;
-	__u32 size_key;
-	__u32 size_value;
-	__u32 max_elem;
-};
-
-static int bpf_fetch_maps_begin(struct bpf_elf_ctx *ctx, int section,
-				struct bpf_elf_sec_data *data)
-{
-	ctx->map_num = data->sec_data->d_size;
-	ctx->sec_maps = section;
-	ctx->sec_done[section] = true;
-
-	if (ctx->map_num > sizeof(ctx->maps)) {
-		fprintf(stderr, "Too many BPF maps in ELF section!\n");
-		return -ENOMEM;
-	}
-
-	memcpy(ctx->maps, data->sec_data->d_buf, ctx->map_num);
-	return 0;
-}
-
-static int bpf_map_verify_all_offs(struct bpf_elf_ctx *ctx, int end)
-{
-	GElf_Sym sym;
-	int off, i;
-
-	for (off = 0; off < end; off += ctx->map_len) {
-		/* Order doesn't need to be linear here, hence we walk
-		 * the table again.
-		 */
-		for (i = 0; i < ctx->sym_num; i++) {
-			int type;
-
-			if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
-				continue;
-
-			type = GELF_ST_TYPE(sym.st_info);
-			if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
-			    (type != STT_NOTYPE && type != STT_OBJECT) ||
-			    sym.st_shndx != ctx->sec_maps)
-				continue;
-			if (sym.st_value == off)
-				break;
-			if (i == ctx->sym_num - 1)
-				return -1;
-		}
-	}
-
-	return off == end ? 0 : -1;
-}
-
-static int bpf_fetch_maps_end(struct bpf_elf_ctx *ctx)
-{
-	struct bpf_elf_map fixup[ARRAY_SIZE(ctx->maps)] = {};
-	int i, sym_num = bpf_map_num_sym(ctx);
-	__u8 *buff;
-
-	if (sym_num == 0 || sym_num > ARRAY_SIZE(ctx->maps)) {
-		fprintf(stderr, "%u maps not supported in current map section!\n",
-			sym_num);
-		return -EINVAL;
-	}
-
-	if (ctx->map_num % sym_num != 0 ||
-	    ctx->map_num % sizeof(__u32) != 0) {
-		fprintf(stderr, "Number BPF map symbols are not multiple of struct bpf_elf_map!\n");
-		return -EINVAL;
-	}
-
-	ctx->map_len = ctx->map_num / sym_num;
-	if (bpf_map_verify_all_offs(ctx, ctx->map_num)) {
-		fprintf(stderr, "Different struct bpf_elf_map in use!\n");
-		return -EINVAL;
-	}
-
-	if (ctx->map_len == sizeof(struct bpf_elf_map)) {
-		ctx->map_num = sym_num;
-		return 0;
-	} else if (ctx->map_len > sizeof(struct bpf_elf_map)) {
-		fprintf(stderr, "struct bpf_elf_map not supported, coming from future version?\n");
-		return -EINVAL;
-	} else if (ctx->map_len < sizeof(struct bpf_elf_map_min)) {
-		fprintf(stderr, "struct bpf_elf_map too small, not supported!\n");
-		return -EINVAL;
-	}
-
-	ctx->map_num = sym_num;
-	for (i = 0, buff = (void *)ctx->maps; i < ctx->map_num;
-	     i++, buff += ctx->map_len) {
-		/* The fixup leaves the rest of the members as zero, which
-		 * is fine currently, but option exist to set some other
-		 * default value as well when needed in future.
-		 */
-		memcpy(&fixup[i], buff, ctx->map_len);
-	}
-
-	memcpy(ctx->maps, fixup, sizeof(fixup));
-	if (ctx->verbose)
-		printf("%zu bytes struct bpf_elf_map fixup performed due to size mismatch!\n",
-		       sizeof(struct bpf_elf_map) - ctx->map_len);
-	return 0;
-}
-
-static int bpf_fetch_license(struct bpf_elf_ctx *ctx, int section,
-			     struct bpf_elf_sec_data *data)
-{
-	if (data->sec_data->d_size > sizeof(ctx->license))
-		return -ENOMEM;
-
-	memcpy(ctx->license, data->sec_data->d_buf, data->sec_data->d_size);
-	ctx->sec_done[section] = true;
-	return 0;
-}
-
-static int bpf_fetch_symtab(struct bpf_elf_ctx *ctx, int section,
-			    struct bpf_elf_sec_data *data)
-{
-	ctx->sym_tab = data->sec_data;
-	ctx->sym_num = data->sec_hdr.sh_size / data->sec_hdr.sh_entsize;
-	ctx->sec_done[section] = true;
-	return 0;
-}
-
-static int bpf_fetch_strtab(struct bpf_elf_ctx *ctx, int section,
-			    struct bpf_elf_sec_data *data)
-{
-	ctx->str_tab = data->sec_data;
-	ctx->sec_done[section] = true;
-	return 0;
-}
-
-static int bpf_fetch_text(struct bpf_elf_ctx *ctx, int section,
-			  struct bpf_elf_sec_data *data)
-{
-	ctx->sec_text = section;
-	ctx->sec_done[section] = true;
-	return 0;
-}
-
-static void bpf_btf_report(int fd, struct bpf_elf_ctx *ctx)
-{
-	fprintf(stderr, "\nBTF debug data section \'.BTF\' %s%s (%d)!\n",
-		fd < 0 ? "rejected: " : "loaded",
-		fd < 0 ? strerror(errno) : "",
-		fd < 0 ? errno : fd);
-
-	fprintf(stderr, " - Length:       %zu\n", ctx->btf_data->d_size);
-
-	bpf_dump_error(ctx, "Verifier analysis:\n\n");
-}
-
-static int bpf_btf_attach(struct bpf_elf_ctx *ctx)
-{
-	int tries = 0, fd;
-retry:
-	errno = 0;
-	fd = bpf_btf_load(ctx->btf_data->d_buf, ctx->btf_data->d_size,
-			  ctx->log, ctx->log_size);
-	if (fd < 0 || ctx->verbose) {
-		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
-			if (tries++ < 10 && !bpf_log_realloc(ctx))
-				goto retry;
-
-			fprintf(stderr, "Log buffer too small to dump verifier log %zu bytes (%d tries)!\n",
-				ctx->log_size, tries);
-			return fd;
-		}
-
-		if (bpf_log_has_data(ctx))
-			bpf_btf_report(fd, ctx);
-	}
-
-	return fd;
-}
-
-static int bpf_fetch_btf_begin(struct bpf_elf_ctx *ctx, int section,
-			       struct bpf_elf_sec_data *data)
-{
-	ctx->btf_data = data->sec_data;
-	ctx->sec_btf = section;
-	ctx->sec_done[section] = true;
-	return 0;
-}
-
-static int bpf_btf_check_header(struct bpf_elf_ctx *ctx)
-{
-	const struct btf_header *hdr = ctx->btf_data->d_buf;
-	const char *str_start, *str_end;
-	unsigned int data_len;
-
-	if (hdr->magic != BTF_MAGIC) {
-		fprintf(stderr, "Object has wrong BTF magic: %x, expected: %x!\n",
-			hdr->magic, BTF_MAGIC);
-		return -EINVAL;
-	}
-
-	if (hdr->version != BTF_VERSION) {
-		fprintf(stderr, "Object has wrong BTF version: %u, expected: %u!\n",
-			hdr->version, BTF_VERSION);
-		return -EINVAL;
-	}
-
-	if (hdr->flags) {
-		fprintf(stderr, "Object has unsupported BTF flags %x!\n",
-			hdr->flags);
-		return -EINVAL;
-	}
-
-	data_len = ctx->btf_data->d_size - sizeof(*hdr);
-	if (data_len < hdr->type_off ||
-	    data_len < hdr->str_off ||
-	    data_len < hdr->type_len + hdr->str_len ||
-	    hdr->type_off >= hdr->str_off ||
-	    hdr->type_off + hdr->type_len != hdr->str_off ||
-	    hdr->str_off + hdr->str_len != data_len ||
-	    (hdr->type_off & (sizeof(uint32_t) - 1))) {
-		fprintf(stderr, "Object has malformed BTF data!\n");
-		return -EINVAL;
-	}
-
-	ctx->btf.hdr = hdr;
-	ctx->btf.raw = hdr + 1;
-
-	str_start = ctx->btf.raw + hdr->str_off;
-	str_end = str_start + hdr->str_len;
-	if (!hdr->str_len ||
-	    hdr->str_len - 1 > BTF_MAX_NAME_OFFSET ||
-	    str_start[0] || str_end[-1]) {
-		fprintf(stderr, "Object has malformed BTF string data!\n");
-		return -EINVAL;
-	}
-
-	ctx->btf.strings = str_start;
-	return 0;
-}
-
-static int bpf_btf_register_type(struct bpf_elf_ctx *ctx,
-				 const struct btf_type *type)
-{
-	int cur = ctx->btf.types_num, num = cur + 1;
-	const struct btf_type **types;
-
-	types = realloc(ctx->btf.types, num * sizeof(type));
-	if (!types) {
-		free(ctx->btf.types);
-		ctx->btf.types = NULL;
-		ctx->btf.types_num = 0;
-		return -ENOMEM;
-	}
-
-	ctx->btf.types = types;
-	ctx->btf.types[cur] = type;
-	ctx->btf.types_num = num;
-	return 0;
-}
-
-static struct btf_type btf_type_void;
-
-static int bpf_btf_prep_type_data(struct bpf_elf_ctx *ctx)
-{
-	const void *type_cur = ctx->btf.raw + ctx->btf.hdr->type_off;
-	const void *type_end = ctx->btf.raw + ctx->btf.hdr->str_off;
-	const struct btf_type *type;
-	uint16_t var_len;
-	int ret, kind;
-
-	ret = bpf_btf_register_type(ctx, &btf_type_void);
-	if (ret < 0)
-		return ret;
-
-	while (type_cur < type_end) {
-		type = type_cur;
-		type_cur += sizeof(*type);
-
-		var_len = BTF_INFO_VLEN(type->info);
-		kind = BTF_INFO_KIND(type->info);
-
-		switch (kind) {
-		case BTF_KIND_INT:
-			type_cur += sizeof(int);
-			break;
-		case BTF_KIND_ARRAY:
-			type_cur += sizeof(struct btf_array);
-			break;
-		case BTF_KIND_STRUCT:
-		case BTF_KIND_UNION:
-			type_cur += var_len * sizeof(struct btf_member);
-			break;
-		case BTF_KIND_ENUM:
-			type_cur += var_len * sizeof(struct btf_enum);
-			break;
-		case BTF_KIND_FUNC_PROTO:
-			type_cur += var_len * sizeof(struct btf_param);
-			break;
-		case BTF_KIND_TYPEDEF:
-		case BTF_KIND_PTR:
-		case BTF_KIND_FWD:
-		case BTF_KIND_VOLATILE:
-		case BTF_KIND_CONST:
-		case BTF_KIND_RESTRICT:
-		case BTF_KIND_FUNC:
-			break;
-		default:
-			fprintf(stderr, "Object has unknown BTF type: %u!\n", kind);
-			return -EINVAL;
-		}
-
-		ret = bpf_btf_register_type(ctx, type);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
-static int bpf_btf_prep_data(struct bpf_elf_ctx *ctx)
-{
-	int ret = bpf_btf_check_header(ctx);
-
-	if (!ret)
-		return bpf_btf_prep_type_data(ctx);
-	return ret;
-}
-
-static void bpf_fetch_btf_end(struct bpf_elf_ctx *ctx)
-{
-	int fd = bpf_btf_attach(ctx);
-
-	if (fd < 0)
-		return;
-	ctx->btf_fd = fd;
-	if (bpf_btf_prep_data(ctx) < 0) {
-		close(ctx->btf_fd);
-		ctx->btf_fd = 0;
-	}
-}
-
-static bool bpf_has_map_data(const struct bpf_elf_ctx *ctx)
-{
-	return ctx->sym_tab && ctx->str_tab && ctx->sec_maps;
-}
-
-static bool bpf_has_btf_data(const struct bpf_elf_ctx *ctx)
-{
-	return ctx->sec_btf;
-}
-
-static bool bpf_has_call_data(const struct bpf_elf_ctx *ctx)
-{
-	return ctx->sec_text;
-}
-
-static int bpf_fetch_ancillary(struct bpf_elf_ctx *ctx, bool check_text_sec)
-{
-	struct bpf_elf_sec_data data;
-	int i, ret = -1;
-
-	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
-		ret = bpf_fill_section_data(ctx, i, &data);
-		if (ret < 0)
-			continue;
-
-		if (data.sec_hdr.sh_type == SHT_PROGBITS &&
-		    !strcmp(data.sec_name, ELF_SECTION_MAPS))
-			ret = bpf_fetch_maps_begin(ctx, i, &data);
-		else if (data.sec_hdr.sh_type == SHT_PROGBITS &&
-			 !strcmp(data.sec_name, ELF_SECTION_LICENSE))
-			ret = bpf_fetch_license(ctx, i, &data);
-		else if (data.sec_hdr.sh_type == SHT_PROGBITS &&
-			 (data.sec_hdr.sh_flags & SHF_EXECINSTR) &&
-			 !strcmp(data.sec_name, ".text") &&
-			 check_text_sec)
-			ret = bpf_fetch_text(ctx, i, &data);
-		else if (data.sec_hdr.sh_type == SHT_SYMTAB &&
-			 !strcmp(data.sec_name, ".symtab"))
-			ret = bpf_fetch_symtab(ctx, i, &data);
-		else if (data.sec_hdr.sh_type == SHT_STRTAB &&
-			 !strcmp(data.sec_name, ".strtab"))
-			ret = bpf_fetch_strtab(ctx, i, &data);
-		else if (data.sec_hdr.sh_type == SHT_PROGBITS &&
-			 !strcmp(data.sec_name, ".BTF"))
-			ret = bpf_fetch_btf_begin(ctx, i, &data);
-		if (ret < 0) {
-			fprintf(stderr, "Error parsing section %d! Perhaps check with readelf -a?\n",
-				i);
-			return ret;
-		}
-	}
-
-	if (bpf_has_btf_data(ctx))
-		bpf_fetch_btf_end(ctx);
-	if (bpf_has_map_data(ctx)) {
-		ret = bpf_fetch_maps_end(ctx);
-		if (ret < 0) {
-			fprintf(stderr, "Error fixing up map structure, incompatible struct bpf_elf_map used?\n");
-			return ret;
-		}
-
-		ret = bpf_maps_attach_all(ctx);
-		if (ret < 0) {
-			fprintf(stderr, "Error loading maps into kernel!\n");
-			return ret;
-		}
-	}
-
-	return ret;
-}
-
-static int bpf_fetch_prog(struct bpf_elf_ctx *ctx, const char *section,
-			  bool *sseen)
-{
-	struct bpf_elf_sec_data data;
-	struct bpf_elf_prog prog;
-	int ret, i, fd = -1;
-
-	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
-		if (ctx->sec_done[i])
-			continue;
-
-		ret = bpf_fill_section_data(ctx, i, &data);
-		if (ret < 0 ||
-		    !(data.sec_hdr.sh_type == SHT_PROGBITS &&
-		      (data.sec_hdr.sh_flags & SHF_EXECINSTR) &&
-		      !strcmp(data.sec_name, section)))
-			continue;
-
-		*sseen = true;
-
-		memset(&prog, 0, sizeof(prog));
-		prog.type      = ctx->type;
-		prog.license   = ctx->license;
-		prog.size      = data.sec_data->d_size;
-		prog.insns_num = prog.size / sizeof(struct bpf_insn);
-		prog.insns     = data.sec_data->d_buf;
-
-		fd = bpf_prog_attach(section, &prog, ctx);
-		if (fd < 0)
-			return fd;
-
-		ctx->sec_done[i] = true;
-		break;
-	}
-
-	return fd;
-}
-
-struct bpf_relo_props {
-	struct bpf_tail_call {
-		unsigned int total;
-		unsigned int jited;
-	} tc;
-	int main_num;
-};
-
-static int bpf_apply_relo_map(struct bpf_elf_ctx *ctx, struct bpf_elf_prog *prog,
-			      GElf_Rel *relo, GElf_Sym *sym,
-			      struct bpf_relo_props *props)
-{
-	unsigned int insn_off = relo->r_offset / sizeof(struct bpf_insn);
-	unsigned int map_idx = sym->st_value / ctx->map_len;
-
-	if (insn_off >= prog->insns_num)
-		return -EINVAL;
-	if (prog->insns[insn_off].code != (BPF_LD | BPF_IMM | BPF_DW)) {
-		fprintf(stderr, "ELF contains relo data for non ld64 instruction at offset %u! Compiler bug?!\n",
-			insn_off);
-		return -EINVAL;
-	}
-
-	if (map_idx >= ARRAY_SIZE(ctx->map_fds))
-		return -EINVAL;
-	if (!ctx->map_fds[map_idx])
-		return -EINVAL;
-	if (ctx->maps[map_idx].type == BPF_MAP_TYPE_PROG_ARRAY) {
-		props->tc.total++;
-		if (ctx->maps_ext[map_idx].owner.jited ||
-		    (ctx->maps_ext[map_idx].owner.type == 0 &&
-		     ctx->cfg.jit_enabled))
-			props->tc.jited++;
-	}
-
-	prog->insns[insn_off].src_reg = BPF_PSEUDO_MAP_FD;
-	prog->insns[insn_off].imm = ctx->map_fds[map_idx];
-	return 0;
-}
-
-static int bpf_apply_relo_call(struct bpf_elf_ctx *ctx, struct bpf_elf_prog *prog,
-			       GElf_Rel *relo, GElf_Sym *sym,
-			       struct bpf_relo_props *props)
-{
-	unsigned int insn_off = relo->r_offset / sizeof(struct bpf_insn);
-	struct bpf_elf_prog *prog_text = &ctx->prog_text;
-
-	if (insn_off >= prog->insns_num)
-		return -EINVAL;
-	if (prog->insns[insn_off].code != (BPF_JMP | BPF_CALL) &&
-	    prog->insns[insn_off].src_reg != BPF_PSEUDO_CALL) {
-		fprintf(stderr, "ELF contains relo data for non call instruction at offset %u! Compiler bug?!\n",
-			insn_off);
-		return -EINVAL;
-	}
-
-	if (!props->main_num) {
-		struct bpf_insn *insns = realloc(prog->insns,
-						 prog->size + prog_text->size);
-		if (!insns)
-			return -ENOMEM;
-
-		memcpy(insns + prog->insns_num, prog_text->insns,
-		       prog_text->size);
-		props->main_num = prog->insns_num;
-		prog->insns = insns;
-		prog->insns_num += prog_text->insns_num;
-		prog->size += prog_text->size;
-	}
-
-	prog->insns[insn_off].imm += props->main_num - insn_off;
-	return 0;
-}
-
-static int bpf_apply_relo_data(struct bpf_elf_ctx *ctx,
-			       struct bpf_elf_sec_data *data_relo,
-			       struct bpf_elf_prog *prog,
-			       struct bpf_relo_props *props)
-{
-	GElf_Shdr *rhdr = &data_relo->sec_hdr;
-	int relo_ent, relo_num = rhdr->sh_size / rhdr->sh_entsize;
-
-	for (relo_ent = 0; relo_ent < relo_num; relo_ent++) {
-		GElf_Rel relo;
-		GElf_Sym sym;
-		int ret = -EIO;
-
-		if (gelf_getrel(data_relo->sec_data, relo_ent, &relo) != &relo)
-			return -EIO;
-		if (gelf_getsym(ctx->sym_tab, GELF_R_SYM(relo.r_info), &sym) != &sym)
-			return -EIO;
-
-		if (sym.st_shndx == ctx->sec_maps)
-			ret = bpf_apply_relo_map(ctx, prog, &relo, &sym, props);
-		else if (sym.st_shndx == ctx->sec_text)
-			ret = bpf_apply_relo_call(ctx, prog, &relo, &sym, props);
-		else
-			fprintf(stderr, "ELF contains non-{map,call} related relo data in entry %u pointing to section %u! Compiler bug?!\n",
-				relo_ent, sym.st_shndx);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
-static int bpf_fetch_prog_relo(struct bpf_elf_ctx *ctx, const char *section,
-			       bool *lderr, bool *sseen, struct bpf_elf_prog *prog)
-{
-	struct bpf_elf_sec_data data_relo, data_insn;
-	int ret, idx, i, fd = -1;
-
-	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
-		struct bpf_relo_props props = {};
-
-		ret = bpf_fill_section_data(ctx, i, &data_relo);
-		if (ret < 0 || data_relo.sec_hdr.sh_type != SHT_REL)
-			continue;
-
-		idx = data_relo.sec_hdr.sh_info;
-
-		ret = bpf_fill_section_data(ctx, idx, &data_insn);
-		if (ret < 0 ||
-		    !(data_insn.sec_hdr.sh_type == SHT_PROGBITS &&
-		      (data_insn.sec_hdr.sh_flags & SHF_EXECINSTR) &&
-		      !strcmp(data_insn.sec_name, section)))
-			continue;
-		if (sseen)
-			*sseen = true;
-
-		memset(prog, 0, sizeof(*prog));
-		prog->type = ctx->type;
-		prog->license = ctx->license;
-		prog->size = data_insn.sec_data->d_size;
-		prog->insns_num = prog->size / sizeof(struct bpf_insn);
-		prog->insns = malloc(prog->size);
-		if (!prog->insns) {
-			*lderr = true;
-			return -ENOMEM;
-		}
-
-		memcpy(prog->insns, data_insn.sec_data->d_buf, prog->size);
-
-		ret = bpf_apply_relo_data(ctx, &data_relo, prog, &props);
-		if (ret < 0) {
-			*lderr = true;
-			if (ctx->sec_text != idx)
-				free(prog->insns);
-			return ret;
-		}
-		if (ctx->sec_text == idx) {
-			fd = 0;
-			goto out;
-		}
-
-		fd = bpf_prog_attach(section, prog, ctx);
-		free(prog->insns);
-		if (fd < 0) {
-			*lderr = true;
-			if (props.tc.total) {
-				if (ctx->cfg.jit_enabled &&
-				    props.tc.total != props.tc.jited)
-					fprintf(stderr, "JIT enabled, but only %u/%u tail call maps in the program have JITed owner!\n",
-						props.tc.jited, props.tc.total);
-				if (!ctx->cfg.jit_enabled &&
-				    props.tc.jited)
-					fprintf(stderr, "JIT disabled, but %u/%u tail call maps in the program have JITed owner!\n",
-						props.tc.jited, props.tc.total);
-			}
-			return fd;
-		}
-out:
-		ctx->sec_done[i]   = true;
-		ctx->sec_done[idx] = true;
-		break;
-	}
-
-	return fd;
-}
-
-static int bpf_fetch_prog_sec(struct bpf_elf_ctx *ctx, const char *section)
-{
-	bool lderr = false, sseen = false;
-	struct bpf_elf_prog prog;
-	int ret = -1;
-
-	if (bpf_has_call_data(ctx)) {
-		ret = bpf_fetch_prog_relo(ctx, ".text", &lderr, NULL,
-					  &ctx->prog_text);
-		if (ret < 0)
-			return ret;
-	}
-
-	if (bpf_has_map_data(ctx) || bpf_has_call_data(ctx))
-		ret = bpf_fetch_prog_relo(ctx, section, &lderr, &sseen, &prog);
-	if (ret < 0 && !lderr)
-		ret = bpf_fetch_prog(ctx, section, &sseen);
-	if (ret < 0 && !sseen)
-		fprintf(stderr, "Program section \'%s\' not found in ELF file!\n",
-			section);
-	return ret;
-}
-
-static int bpf_find_map_by_id(struct bpf_elf_ctx *ctx, uint32_t id)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(ctx->map_fds); i++)
-		if (ctx->map_fds[i] && ctx->maps[i].id == id &&
-		    ctx->maps[i].type == BPF_MAP_TYPE_PROG_ARRAY)
-			return i;
-	return -1;
-}
-
-struct bpf_jited_aux {
-	int prog_fd;
-	int map_fd;
-	struct bpf_prog_data prog;
-	struct bpf_map_ext map;
-};
-
-static int bpf_derive_prog_from_fdinfo(int fd, struct bpf_prog_data *prog)
-{
-	char *file = NULL;
-	char buff[4096];
-	unsigned int val;
-	FILE *fp;
-	int ret;
-
-	ret = asprintf(&file, "/proc/%d/fdinfo/%d", getpid(), fd);
-	if (ret < 0) {
-		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		free(file);
-		return ret;
-	}
-
-	memset(prog, 0, sizeof(*prog));
-
-	fp = fopen(file, "r");
-	free(file);
-	if (!fp) {
-		fprintf(stderr, "No procfs support?!\n");
-		return -EIO;
-	}
-
-	while (fgets(buff, sizeof(buff), fp)) {
-		if (sscanf(buff, "prog_type:\t%u", &val) == 1)
-			prog->type = val;
-		else if (sscanf(buff, "prog_jited:\t%u", &val) == 1)
-			prog->jited = val;
-	}
-
-	fclose(fp);
-	return 0;
-}
-
-static int bpf_tail_call_get_aux(struct bpf_jited_aux *aux)
-{
-	struct bpf_elf_map tmp;
-	int ret;
-
-	ret = bpf_derive_elf_map_from_fdinfo(aux->map_fd, &tmp, &aux->map);
-	if (!ret)
-		ret = bpf_derive_prog_from_fdinfo(aux->prog_fd, &aux->prog);
-
-	return ret;
-}
-
-static int bpf_fill_prog_arrays(struct bpf_elf_ctx *ctx)
-{
-	struct bpf_elf_sec_data data;
-	uint32_t map_id, key_id;
-	int fd, i, ret, idx;
-
-	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
-		if (ctx->sec_done[i])
-			continue;
-
-		ret = bpf_fill_section_data(ctx, i, &data);
-		if (ret < 0)
-			continue;
-
-		ret = sscanf(data.sec_name, "%i/%i", &map_id, &key_id);
-		if (ret != 2)
-			continue;
-
-		idx = bpf_find_map_by_id(ctx, map_id);
-		if (idx < 0)
-			continue;
-
-		fd = bpf_fetch_prog_sec(ctx, data.sec_name);
-		if (fd < 0)
-			return -EIO;
-
-		ret = bpf_map_update(ctx->map_fds[idx], &key_id,
-				     &fd, BPF_ANY);
-		if (ret < 0) {
-			struct bpf_jited_aux aux = {};
-
-			ret = -errno;
-			if (errno == E2BIG) {
-				fprintf(stderr, "Tail call key %u for map %u out of bounds?\n",
-					key_id, map_id);
-				return ret;
-			}
-
-			aux.map_fd  = ctx->map_fds[idx];
-			aux.prog_fd = fd;
-
-			if (bpf_tail_call_get_aux(&aux))
-				return ret;
-			if (!aux.map.owner.type)
-				return ret;
-
-			if (aux.prog.type != aux.map.owner.type)
-				fprintf(stderr, "Tail call map owned by prog type %u, but prog type is %u!\n",
-					aux.map.owner.type, aux.prog.type);
-			if (aux.prog.jited != aux.map.owner.jited)
-				fprintf(stderr, "Tail call map %s jited, but prog %s!\n",
-					aux.map.owner.jited ? "is" : "not",
-					aux.prog.jited ? "is" : "not");
-			return ret;
-		}
-
-		ctx->sec_done[i] = true;
-	}
-
-	return 0;
-}
-
-static void bpf_save_finfo(struct bpf_elf_ctx *ctx)
-{
-	struct stat st;
-	int ret;
-
-	memset(&ctx->stat, 0, sizeof(ctx->stat));
-
-	ret = fstat(ctx->obj_fd, &st);
-	if (ret < 0) {
-		fprintf(stderr, "Stat of elf file failed: %s\n",
-			strerror(errno));
-		return;
-	}
-
-	ctx->stat.st_dev = st.st_dev;
-	ctx->stat.st_ino = st.st_ino;
-}
-
-static int bpf_read_pin_mapping(FILE *fp, uint32_t *id, char *path)
-{
-	char buff[PATH_MAX];
-
-	while (fgets(buff, sizeof(buff), fp)) {
-		char *ptr = buff;
-
-		while (*ptr == ' ' || *ptr == '\t')
-			ptr++;
-
-		if (*ptr == '#' || *ptr == '\n' || *ptr == 0)
-			continue;
-
-		if (sscanf(ptr, "%i %s\n", id, path) != 2 &&
-		    sscanf(ptr, "%i %s #", id, path) != 2) {
-			strcpy(path, ptr);
-			return -1;
-		}
-
-		return 1;
-	}
-
-	return 0;
-}
-
-static bool bpf_pinning_reserved(uint32_t pinning)
-{
-	switch (pinning) {
-	case PIN_NONE:
-	case PIN_OBJECT_NS:
-	case PIN_GLOBAL_NS:
-		return true;
-	default:
-		return false;
-	}
-}
-
-static void bpf_hash_init(struct bpf_elf_ctx *ctx, const char *db_file)
-{
-	struct bpf_hash_entry *entry;
-	char subpath[PATH_MAX] = {};
-	uint32_t pinning;
-	FILE *fp;
-	int ret;
-
-	fp = fopen(db_file, "r");
-	if (!fp)
-		return;
-
-	while ((ret = bpf_read_pin_mapping(fp, &pinning, subpath))) {
-		if (ret == -1) {
-			fprintf(stderr, "Database %s is corrupted at: %s\n",
-				db_file, subpath);
-			fclose(fp);
-			return;
-		}
-
-		if (bpf_pinning_reserved(pinning)) {
-			fprintf(stderr, "Database %s, id %u is reserved - ignoring!\n",
-				db_file, pinning);
-			continue;
-		}
-
-		entry = malloc(sizeof(*entry));
-		if (!entry) {
-			fprintf(stderr, "No memory left for db entry!\n");
-			continue;
-		}
-
-		entry->pinning = pinning;
-		entry->subpath = strdup(subpath);
-		if (!entry->subpath) {
-			fprintf(stderr, "No memory left for db entry!\n");
-			free(entry);
-			continue;
-		}
-
-		entry->next = ctx->ht[pinning & (ARRAY_SIZE(ctx->ht) - 1)];
-		ctx->ht[pinning & (ARRAY_SIZE(ctx->ht) - 1)] = entry;
-	}
-
-	fclose(fp);
-}
-
-static void bpf_hash_destroy(struct bpf_elf_ctx *ctx)
-{
-	struct bpf_hash_entry *entry;
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(ctx->ht); i++) {
-		while ((entry = ctx->ht[i]) != NULL) {
-			ctx->ht[i] = entry->next;
-			free((char *)entry->subpath);
-			free(entry);
-		}
-	}
-}
-
-static int bpf_elf_check_ehdr(const struct bpf_elf_ctx *ctx)
-{
-	if (ctx->elf_hdr.e_type != ET_REL ||
-	    (ctx->elf_hdr.e_machine != EM_NONE &&
-	     ctx->elf_hdr.e_machine != EM_BPF) ||
-	    ctx->elf_hdr.e_version != EV_CURRENT) {
-		fprintf(stderr, "ELF format error, ELF file not for eBPF?\n");
-		return -EINVAL;
-	}
-
-	switch (ctx->elf_hdr.e_ident[EI_DATA]) {
-	default:
-		fprintf(stderr, "ELF format error, wrong endianness info?\n");
-		return -EINVAL;
-	case ELFDATA2LSB:
-		if (htons(1) == 1) {
-			fprintf(stderr,
-				"We are big endian, eBPF object is little endian!\n");
-			return -EIO;
-		}
-		break;
-	case ELFDATA2MSB:
-		if (htons(1) != 1) {
-			fprintf(stderr,
-				"We are little endian, eBPF object is big endian!\n");
-			return -EIO;
-		}
-		break;
-	}
-
-	return 0;
-}
-
-static void bpf_get_cfg(struct bpf_elf_ctx *ctx)
-{
-	static const char *path_jit = "/proc/sys/net/core/bpf_jit_enable";
-	int fd;
-
-	fd = open(path_jit, O_RDONLY);
-	if (fd > 0) {
-		char tmp[16] = {};
-
-		if (read(fd, tmp, sizeof(tmp)) > 0)
-			ctx->cfg.jit_enabled = atoi(tmp);
-		close(fd);
-	}
-}
-
-static int bpf_elf_ctx_init(struct bpf_elf_ctx *ctx, const char *pathname,
-			    enum bpf_prog_type type, __u32 ifindex,
-			    bool verbose)
-{
-	uint8_t tmp[20];
-	int ret;
-
-	if (elf_version(EV_CURRENT) == EV_NONE)
-		return -EINVAL;
-
-	bpf_init_env();
-
-	memset(ctx, 0, sizeof(*ctx));
-	bpf_get_cfg(ctx);
-
-	ret = bpf_obj_hash(pathname, tmp, sizeof(tmp));
-	if (ret)
-		ctx->noafalg = true;
-	else
-		hexstring_n2a(tmp, sizeof(tmp), ctx->obj_uid,
-			      sizeof(ctx->obj_uid));
-
-	ctx->verbose = verbose;
-	ctx->type    = type;
-	ctx->ifindex = ifindex;
-
-	ctx->obj_fd = open(pathname, O_RDONLY);
-	if (ctx->obj_fd < 0)
-		return ctx->obj_fd;
-
-	ctx->elf_fd = elf_begin(ctx->obj_fd, ELF_C_READ, NULL);
-	if (!ctx->elf_fd) {
-		ret = -EINVAL;
-		goto out_fd;
-	}
-
-	if (elf_kind(ctx->elf_fd) != ELF_K_ELF) {
-		ret = -EINVAL;
-		goto out_fd;
-	}
-
-	if (gelf_getehdr(ctx->elf_fd, &ctx->elf_hdr) !=
-	    &ctx->elf_hdr) {
-		ret = -EIO;
-		goto out_elf;
-	}
-
-	ret = bpf_elf_check_ehdr(ctx);
-	if (ret < 0)
-		goto out_elf;
-
-	ctx->sec_done = calloc(ctx->elf_hdr.e_shnum,
-			       sizeof(*(ctx->sec_done)));
-	if (!ctx->sec_done) {
-		ret = -ENOMEM;
-		goto out_elf;
-	}
-
-	if (ctx->verbose && bpf_log_realloc(ctx)) {
-		ret = -ENOMEM;
-		goto out_free;
-	}
-
-	bpf_save_finfo(ctx);
-	bpf_hash_init(ctx, CONFDIR "/bpf_pinning");
-
-	return 0;
-out_free:
-	free(ctx->sec_done);
-out_elf:
-	elf_end(ctx->elf_fd);
-out_fd:
-	close(ctx->obj_fd);
-	return ret;
-}
-
-static int bpf_maps_count(struct bpf_elf_ctx *ctx)
-{
-	int i, count = 0;
-
-	for (i = 0; i < ARRAY_SIZE(ctx->map_fds); i++) {
-		if (!ctx->map_fds[i])
-			break;
-		count++;
-	}
-
-	return count;
-}
-
-static void bpf_maps_teardown(struct bpf_elf_ctx *ctx)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(ctx->map_fds); i++) {
-		if (ctx->map_fds[i])
-			close(ctx->map_fds[i]);
-	}
-
-	if (ctx->btf_fd)
-		close(ctx->btf_fd);
-	free(ctx->btf.types);
-}
-
-static void bpf_elf_ctx_destroy(struct bpf_elf_ctx *ctx, bool failure)
-{
-	if (failure)
-		bpf_maps_teardown(ctx);
-
-	bpf_hash_destroy(ctx);
-
-	free(ctx->prog_text.insns);
-	free(ctx->sec_done);
-	free(ctx->log);
-
-	elf_end(ctx->elf_fd);
-	close(ctx->obj_fd);
-}
-
-static struct bpf_elf_ctx __ctx;
-
-static int bpf_obj_open(const char *pathname, enum bpf_prog_type type,
-			const char *section, __u32 ifindex, bool verbose)
-{
-	struct bpf_elf_ctx *ctx = &__ctx;
-	int fd = 0, ret;
-
-	ret = bpf_elf_ctx_init(ctx, pathname, type, ifindex, verbose);
-	if (ret < 0) {
-		fprintf(stderr, "Cannot initialize ELF context!\n");
-		return ret;
-	}
-
-	ret = bpf_fetch_ancillary(ctx, strcmp(section, ".text"));
-	if (ret < 0) {
-		fprintf(stderr, "Error fetching ELF ancillary data!\n");
-		goto out;
-	}
-
-	fd = bpf_fetch_prog_sec(ctx, section);
-	if (fd < 0) {
-		fprintf(stderr, "Error fetching program/map!\n");
-		ret = fd;
-		goto out;
-	}
-
-	ret = bpf_fill_prog_arrays(ctx);
-	if (ret < 0)
-		fprintf(stderr, "Error filling program arrays!\n");
-out:
-	bpf_elf_ctx_destroy(ctx, ret < 0);
-	if (ret < 0) {
-		if (fd)
-			close(fd);
-		return ret;
-	}
-
-	return fd;
-}
-
-static int
-bpf_map_set_send(int fd, struct sockaddr_un *addr, unsigned int addr_len,
-		 const struct bpf_map_data *aux, unsigned int entries)
-{
-	struct bpf_map_set_msg msg = {
-		.aux.uds_ver = BPF_SCM_AUX_VER,
-		.aux.num_ent = entries,
-	};
-	int *cmsg_buf, min_fd;
-	char *amsg_buf;
-	int i;
-
-	strlcpy(msg.aux.obj_name, aux->obj, sizeof(msg.aux.obj_name));
-	memcpy(&msg.aux.obj_st, aux->st, sizeof(msg.aux.obj_st));
-
-	cmsg_buf = bpf_map_set_init(&msg, addr, addr_len);
-	amsg_buf = (char *)msg.aux.ent;
-
-	for (i = 0; i < entries; i += min_fd) {
-		int ret;
-
-		min_fd = min(BPF_SCM_MAX_FDS * 1U, entries - i);
-		bpf_map_set_init_single(&msg, min_fd);
-
-		memcpy(cmsg_buf, &aux->fds[i], sizeof(aux->fds[0]) * min_fd);
-		memcpy(amsg_buf, &aux->ent[i], sizeof(aux->ent[0]) * min_fd);
-
-		ret = sendmsg(fd, &msg.hdr, 0);
-		if (ret <= 0)
-			return ret ? : -1;
-	}
-
-	return 0;
-}
-
-static int
-bpf_map_set_recv(int fd, int *fds,  struct bpf_map_aux *aux,
-		 unsigned int entries)
-{
-	struct bpf_map_set_msg msg;
-	int *cmsg_buf, min_fd;
-	char *amsg_buf, *mmsg_buf;
-	unsigned int needed = 1;
-	int i;
-
-	cmsg_buf = bpf_map_set_init(&msg, NULL, 0);
-	amsg_buf = (char *)msg.aux.ent;
-	mmsg_buf = (char *)&msg.aux;
-
-	for (i = 0; i < min(entries, needed); i += min_fd) {
-		struct cmsghdr *cmsg;
-		int ret;
-
-		min_fd = min(entries, entries - i);
-		bpf_map_set_init_single(&msg, min_fd);
-
-		ret = recvmsg(fd, &msg.hdr, 0);
-		if (ret <= 0)
-			return ret ? : -1;
-
-		cmsg = CMSG_FIRSTHDR(&msg.hdr);
-		if (!cmsg || cmsg->cmsg_type != SCM_RIGHTS)
-			return -EINVAL;
-		if (msg.hdr.msg_flags & MSG_CTRUNC)
-			return -EIO;
-		if (msg.aux.uds_ver != BPF_SCM_AUX_VER)
-			return -ENOSYS;
-
-		min_fd = (cmsg->cmsg_len - sizeof(*cmsg)) / sizeof(fd);
-		if (min_fd > entries || min_fd <= 0)
-			return -EINVAL;
-
-		memcpy(&fds[i], cmsg_buf, sizeof(fds[0]) * min_fd);
-		memcpy(&aux->ent[i], amsg_buf, sizeof(aux->ent[0]) * min_fd);
-		memcpy(aux, mmsg_buf, offsetof(struct bpf_map_aux, ent));
-
-		needed = aux->num_ent;
-	}
-
-	return 0;
-}
-
-int bpf_send_map_fds(const char *path, const char *obj)
-{
-	struct bpf_elf_ctx *ctx = &__ctx;
-	struct sockaddr_un addr = { .sun_family = AF_UNIX };
-	struct bpf_map_data bpf_aux = {
-		.fds = ctx->map_fds,
-		.ent = ctx->maps,
-		.st  = &ctx->stat,
-		.obj = obj,
-	};
-	int fd, ret;
-
-	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
-	if (fd < 0) {
-		fprintf(stderr, "Cannot open socket: %s\n",
-			strerror(errno));
-		return -1;
-	}
-
-	strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
-
-	ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
-	if (ret < 0) {
-		fprintf(stderr, "Cannot connect to %s: %s\n",
-			path, strerror(errno));
-		return -1;
-	}
-
-	ret = bpf_map_set_send(fd, &addr, sizeof(addr), &bpf_aux,
-			       bpf_maps_count(ctx));
-	if (ret < 0)
-		fprintf(stderr, "Cannot send fds to %s: %s\n",
-			path, strerror(errno));
-
-	bpf_maps_teardown(ctx);
-	close(fd);
-	return ret;
-}
-
-int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
-		     unsigned int entries)
-{
-	struct sockaddr_un addr = { .sun_family = AF_UNIX };
-	int fd, ret;
-
-	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
-	if (fd < 0) {
-		fprintf(stderr, "Cannot open socket: %s\n",
-			strerror(errno));
-		return -1;
-	}
-
-	strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
-
-	ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
-	if (ret < 0) {
-		fprintf(stderr, "Cannot bind to socket: %s\n",
-			strerror(errno));
-		return -1;
-	}
-
-	ret = bpf_map_set_recv(fd, fds, aux, entries);
-	if (ret < 0)
-		fprintf(stderr, "Cannot recv fds from %s: %s\n",
-			path, strerror(errno));
-
-	unlink(addr.sun_path);
-	close(fd);
-	return ret;
-}
-#endif /* HAVE_ELF */
diff --git a/lib/color.c b/lib/color.c
index 5997684..8c9a48b 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -1,17 +1,7 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #include <stdio.h>
 #include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <linux/if.h>
 
 #include "color.h"
-#include "utils.h"
-
-static void set_color_palette(void);
 
 enum color {
 	C_RED,
@@ -21,13 +11,6 @@
 	C_MAGENTA,
 	C_CYAN,
 	C_WHITE,
-	C_BOLD_RED,
-	C_BOLD_GREEN,
-	C_BOLD_YELLOW,
-	C_BOLD_BLUE,
-	C_BOLD_MAGENTA,
-	C_BOLD_CYAN,
-	C_BOLD_WHITE,
 	C_CLEAR
 };
 
@@ -39,102 +22,26 @@
 	"\e[35m",
 	"\e[36m",
 	"\e[37m",
-	"\e[1;31m",
-	"\e[1;32m",
-	"\e[1;33m",
-	"\e[1;34m",
-	"\e[1;35m",
-	"\e[1;36m",
-	"\e[1;37m",
 	"\e[0m",
 	NULL,
 };
 
-/* light background */
-static enum color attr_colors_light[] = {
+static enum color attr_colors[] = {
 	C_CYAN,
 	C_YELLOW,
 	C_MAGENTA,
 	C_BLUE,
 	C_GREEN,
-	C_RED,
-	C_CLEAR,
+	C_RED
 };
 
-/* dark background */
-static enum color attr_colors_dark[] = {
-	C_BOLD_CYAN,
-	C_BOLD_YELLOW,
-	C_BOLD_MAGENTA,
-	C_BOLD_BLUE,
-	C_BOLD_GREEN,
-	C_BOLD_RED,
-	C_CLEAR
-};
-
-static int is_dark_bg;
 static int color_is_enabled;
 
-static void enable_color(void)
+void enable_color(void)
 {
 	color_is_enabled = 1;
-	set_color_palette();
 }
 
-bool check_enable_color(int color, int json)
-{
-	if (json || color == COLOR_OPT_NEVER)
-		return false;
-
-	if (color == COLOR_OPT_ALWAYS || isatty(fileno(stdout))) {
-		enable_color();
-		return true;
-	}
-	return false;
-}
-
-bool matches_color(const char *arg, int *val)
-{
-	char *dup, *p;
-
-	if (!val)
-		return false;
-
-	dup = strdupa(arg);
-	p = strchrnul(dup, '=');
-	if (*p)
-		*(p++) = '\0';
-
-	if (matches(dup, "-color"))
-		return false;
-
-	if (*p == '\0' || !strcmp(p, "always"))
-		*val = COLOR_OPT_ALWAYS;
-	else if (!strcmp(p, "auto"))
-		*val = COLOR_OPT_AUTO;
-	else if (!strcmp(p, "never"))
-		*val = COLOR_OPT_NEVER;
-	else
-		return false;
-	return true;
-}
-
-static void set_color_palette(void)
-{
-	char *p = getenv("COLORFGBG");
-
-	/*
-	 * COLORFGBG environment variable usually contains either two or three
-	 * values separated by semicolons; we want the last value in either case.
-	 * If this value is 0-6 or 8, background is dark.
-	 */
-	if (p && (p = strrchr(p, ';')) != NULL
-		&& ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
-		&& p[2] == '\0')
-		is_dark_bg = 1;
-}
-
-__attribute__((format(printf, 3, 4)))
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 {
 	int ret = 0;
@@ -142,14 +49,12 @@
 
 	va_start(args, fmt);
 
-	if (!color_is_enabled || attr == COLOR_NONE) {
+	if (!color_is_enabled) {
 		ret = vfprintf(fp, fmt, args);
 		goto end;
 	}
 
-	ret += fprintf(fp, "%s", color_codes[is_dark_bg ?
-		attr_colors_dark[attr] : attr_colors_light[attr]]);
-
+	ret += fprintf(fp, "%s", color_codes[attr_colors[attr]]);
 	ret += vfprintf(fp, fmt, args);
 	ret += fprintf(fp, "%s", color_codes[C_CLEAR]);
 
@@ -157,27 +62,3 @@
 	va_end(args);
 	return ret;
 }
-
-enum color_attr ifa_family_color(__u8 ifa_family)
-{
-	switch (ifa_family) {
-	case AF_INET:
-		return COLOR_INET;
-	case AF_INET6:
-		return COLOR_INET6;
-	default:
-		return COLOR_NONE;
-	}
-}
-
-enum color_attr oper_state_color(__u8 state)
-{
-	switch (state) {
-	case IF_OPER_UP:
-		return COLOR_OPERSTATE_UP;
-	case IF_OPER_DOWN:
-		return COLOR_OPERSTATE_DOWN;
-	default:
-		return COLOR_NONE;
-	}
-}
diff --git a/lib/coverity_model.c b/lib/coverity_model.c
index 1321fe8..c896302 100644
--- a/lib/coverity_model.c
+++ b/lib/coverity_model.c
@@ -15,3 +15,5 @@
  * Coverity Scan doesn't pick up modifications automatically. The model file
  * must be uploaded by an admin.
  */
+
+
diff --git a/lib/dnet_ntop.c b/lib/dnet_ntop.c
new file mode 100644
index 0000000..507a7eb
--- /dev/null
+++ b/lib/dnet_ntop.c
@@ -0,0 +1,102 @@
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#include "utils.h"
+
+static __inline__ u_int16_t dn_ntohs(u_int16_t addr)
+{
+	union {
+		u_int8_t byte[2];
+		u_int16_t word;
+	} u;
+
+	u.word = addr;
+	return ((u_int16_t)u.byte[0]) | (((u_int16_t)u.byte[1]) << 8);
+}
+
+static __inline__ int do_digit(char *str, u_int16_t *addr, u_int16_t scale, size_t *pos, size_t len, int *started)
+{
+	u_int16_t tmp = *addr / scale;
+
+	if (*pos == len)
+		return 1;
+
+	if (((tmp) > 0) || *started || (scale == 1)) {
+		*str = tmp + '0';
+		*started = 1;
+		(*pos)++;
+		*addr -= (tmp * scale);
+	}
+
+	return 0;
+}
+
+
+static const char *dnet_ntop1(const struct dn_naddr *dna, char *str, size_t len)
+{
+	u_int16_t addr, area;
+	size_t pos = 0;
+	int started = 0;
+
+	memcpy(&addr, dna->a_addr, sizeof(addr));
+	addr = dn_ntohs(addr);
+	area = addr >> 10;
+
+	if (dna->a_len != 2)
+		return NULL;
+
+	addr &= 0x03ff;
+
+	if (len == 0)
+		return str;
+
+	if (do_digit(str + pos, &area, 10, &pos, len, &started))
+		return str;
+
+	if (do_digit(str + pos, &area, 1, &pos, len, &started))
+		return str;
+
+	if (pos == len)
+		return str;
+
+	*(str + pos) = '.';
+	pos++;
+	started = 0;
+
+	if (do_digit(str + pos, &addr, 1000, &pos, len, &started))
+		return str;
+
+	if (do_digit(str + pos, &addr, 100, &pos, len, &started))
+		return str;
+
+	if (do_digit(str + pos, &addr, 10, &pos, len, &started))
+		return str;
+
+	if (do_digit(str + pos, &addr, 1, &pos, len, &started))
+		return str;
+
+	if (pos == len)
+		return str;
+
+	*(str + pos) = 0;
+
+	return str;
+}
+
+
+const char *dnet_ntop(int af, const void *addr, char *str, size_t len)
+{
+	switch(af) {
+		case AF_DECnet:
+			errno = 0;
+			return dnet_ntop1((struct dn_naddr *)addr, str, len);
+		default:
+			errno = EAFNOSUPPORT;
+	}
+
+	return NULL;
+}
+
+
diff --git a/lib/dnet_pton.c b/lib/dnet_pton.c
new file mode 100644
index 0000000..7385756
--- /dev/null
+++ b/lib/dnet_pton.c
@@ -0,0 +1,74 @@
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#include "utils.h"
+
+static __inline__ u_int16_t dn_htons(u_int16_t addr)
+{
+        union {
+                u_int8_t byte[2];
+                u_int16_t word;
+        } u;
+
+        u.word = addr;
+        return ((u_int16_t)u.byte[0]) | (((u_int16_t)u.byte[1]) << 8);
+}
+
+
+static int dnet_num(const char *src, u_int16_t * dst)
+{
+	int rv = 0;
+	int tmp;
+	*dst = 0;
+
+	while ((tmp = *src++) != 0) {
+		tmp -= '0';
+		if ((tmp < 0) || (tmp > 9))
+			return rv;
+
+		rv++;
+		(*dst) *= 10;
+		(*dst) += tmp;
+	}
+
+	return rv;
+}
+
+static int dnet_pton1(const char *src, struct dn_naddr *dna)
+{
+	u_int16_t addr;
+	u_int16_t area = 0;
+	u_int16_t node = 0;
+	int pos;
+
+	pos = dnet_num(src, &area);
+	if ((pos == 0) || (area > 63) || (*(src + pos) != '.'))
+		return 0;
+	pos = dnet_num(src + pos + 1, &node);
+	if ((pos == 0) || (node > 1023))
+		return 0;
+	dna->a_len = 2;
+	addr = dn_htons((area << 10) | node);
+	memcpy(dna->a_addr, &addr, sizeof(addr));
+
+	return 1;
+}
+
+int dnet_pton(int af, const char *src, void *addr)
+{
+	int err;
+
+	switch (af) {
+	case AF_DECnet:
+		errno = 0;
+		err = dnet_pton1(src, (struct dn_naddr *)addr);
+		break;
+	default:
+		errno = EAFNOSUPPORT;
+		err = -1;
+	}
+
+	return err;
+}
diff --git a/lib/exec.c b/lib/exec.c
deleted file mode 100644
index 9b1c8f4..0000000
--- a/lib/exec.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "utils.h"
-#include "namespace.h"
-
-int cmd_exec(const char *cmd, char **argv, bool do_fork,
-	     int (*setup)(void *), void *arg)
-{
-	fflush(stdout);
-	if (do_fork) {
-		int status;
-		pid_t pid;
-
-		pid = fork();
-		if (pid < 0) {
-			perror("fork");
-			exit(1);
-		}
-
-		if (pid != 0) {
-			/* Parent  */
-			if (waitpid(pid, &status, 0) < 0) {
-				perror("waitpid");
-				exit(1);
-			}
-
-			if (WIFEXITED(status)) {
-				return WEXITSTATUS(status);
-			}
-
-			exit(1);
-		}
-	}
-
-	if (setup && setup(arg))
-		return -1;
-
-	if (execvp(cmd, argv)  < 0)
-		fprintf(stderr, "exec of \"%s\" failed: %s\n",
-				cmd, strerror(errno));
-	_exit(1);
-}
diff --git a/lib/fs.c b/lib/fs.c
deleted file mode 100644
index 86efd4e..0000000
--- a/lib/fs.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * fs.c         filesystem APIs
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	David Ahern <dsa@cumulusnetworks.com>
- *
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/mount.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-
-#include "utils.h"
-
-#define CGROUP2_FS_NAME "cgroup2"
-
-/* if not already mounted cgroup2 is mounted here for iproute2's use */
-#define MNT_CGRP2_PATH  "/var/run/cgroup2"
-
-/* return mount path of first occurrence of given fstype */
-static char *find_fs_mount(const char *fs_to_find)
-{
-	char path[4096];
-	char fstype[128];    /* max length of any filesystem name */
-	char *mnt = NULL;
-	FILE *fp;
-
-	fp = fopen("/proc/mounts", "r");
-	if (!fp) {
-		fprintf(stderr,
-			"Failed to open mounts file: %s\n", strerror(errno));
-		return NULL;
-	}
-
-	while (fscanf(fp, "%*s %4095s %127s %*s %*d %*d\n",
-		      path, fstype) == 2) {
-		if (strcmp(fstype, fs_to_find) == 0) {
-			mnt = strdup(path);
-			break;
-		}
-	}
-
-	fclose(fp);
-
-	return mnt;
-}
-
-/* caller needs to free string returned */
-char *find_cgroup2_mount(void)
-{
-	char *mnt = find_fs_mount(CGROUP2_FS_NAME);
-
-	if (mnt)
-		return mnt;
-
-	mnt = strdup(MNT_CGRP2_PATH);
-	if (!mnt) {
-		fprintf(stderr, "Failed to allocate memory for cgroup2 path\n");
-		return NULL;
-
-	}
-
-	if (make_path(mnt, 0755)) {
-		fprintf(stderr, "Failed to setup vrf cgroup2 directory\n");
-		free(mnt);
-		return NULL;
-	}
-
-	if (mount("none", mnt, CGROUP2_FS_NAME, 0, NULL)) {
-		/* EBUSY means already mounted */
-		if (errno == EBUSY)
-			goto out;
-
-		if (errno == ENODEV) {
-			fprintf(stderr,
-				"Failed to mount cgroup2. Are CGROUPS enabled in your kernel?\n");
-		} else {
-			fprintf(stderr,
-				"Failed to mount cgroup2: %s\n",
-				strerror(errno));
-		}
-		free(mnt);
-		return NULL;
-	}
-out:
-	return mnt;
-}
-
-int make_path(const char *path, mode_t mode)
-{
-	char *dir, *delim;
-	int rc = -1;
-
-	delim = dir = strdup(path);
-	if (dir == NULL) {
-		fprintf(stderr, "strdup failed copying path");
-		return -1;
-	}
-
-	/* skip '/' -- it had better exist */
-	if (*delim == '/')
-		delim++;
-
-	while (1) {
-		delim = strchr(delim, '/');
-		if (delim)
-			*delim = '\0';
-
-		rc = mkdir(dir, mode);
-		if (mkdir(dir, mode) != 0 && errno != EEXIST) {
-			fprintf(stderr, "mkdir failed for %s: %s\n",
-				dir, strerror(errno));
-			goto out;
-		}
-
-		if (delim == NULL)
-			break;
-
-		*delim = '/';
-		delim++;
-		if (*delim == '\0')
-			break;
-	}
-	rc = 0;
-out:
-	free(dir);
-
-	return rc;
-}
-
-int get_command_name(const char *pid, char *comm, size_t len)
-{
-	char path[PATH_MAX];
-	char line[128];
-	FILE *fp;
-
-	if (snprintf(path, sizeof(path),
-		     "/proc/%s/status", pid) >= sizeof(path)) {
-		return -1;
-	}
-
-	fp = fopen(path, "r");
-	if (!fp)
-		return -1;
-
-	comm[0] = '\0';
-	while (fgets(line, sizeof(line), fp)) {
-		char *nl, *name;
-
-		name = strstr(line, "Name:");
-		if (!name)
-			continue;
-
-		name += 5;
-		while (isspace(*name))
-			name++;
-
-		nl = strchr(name, '\n');
-		if (nl)
-			*nl = '\0';
-
-		strlcpy(comm, name, len);
-		break;
-	}
-
-	fclose(fp);
-
-	return 0;
-}
diff --git a/lib/inet_proto.c b/lib/inet_proto.c
index 41e2e8b..57a8351 100644
--- a/lib/inet_proto.c
+++ b/lib/inet_proto.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -24,7 +25,7 @@
 
 const char *inet_proto_n2a(int proto, char *buf, int len)
 {
-	static char *ncache;
+	static char ncache[16];
 	static int icache = -1;
 	struct protoent *pe;
 
@@ -32,12 +33,10 @@
 		return ncache;
 
 	pe = getprotobynumber(proto);
-	if (pe && !numeric) {
-		if (icache != -1)
-			free(ncache);
+	if (pe) {
 		icache = proto;
-		ncache = strdup(pe->p_name);
-		strlcpy(buf, pe->p_name, len);
+		strncpy(ncache, pe->p_name, 16);
+		strncpy(buf, pe->p_name, len);
 		return buf;
 	}
 	snprintf(buf, len, "ipproto-%d", proto);
@@ -46,24 +45,27 @@
 
 int inet_proto_a2n(const char *buf)
 {
-	static char *ncache;
+	static char ncache[16];
 	static int icache = -1;
 	struct protoent *pe;
-	__u8 ret;
 
-	if (icache != -1 && strcmp(ncache, buf) == 0)
+	if (icache>=0 && strcmp(ncache, buf) == 0)
 		return icache;
 
-	if (!get_u8(&ret, buf, 10))
+	if (buf[0] >= '0' && buf[0] <= '9') {
+		__u8 ret;
+		if (get_u8(&ret, buf, 10))
+			return -1;
 		return ret;
+	}
 
 	pe = getprotobyname(buf);
 	if (pe) {
-		if (icache != -1)
-			free(ncache);
 		icache = pe->p_proto;
-		ncache = strdup(pe->p_name);
+		strncpy(ncache, pe->p_name, 16);
 		return pe->p_proto;
 	}
 	return -1;
 }
+
+
diff --git a/lib/ipx_ntop.c b/lib/ipx_ntop.c
new file mode 100644
index 0000000..1e46bc2
--- /dev/null
+++ b/lib/ipx_ntop.c
@@ -0,0 +1,72 @@
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "utils.h"
+
+static __inline__ int do_digit(char *str, u_int32_t addr, u_int32_t scale, size_t *pos, size_t len)
+{
+	u_int32_t tmp = addr >> (scale * 4);
+
+	if (*pos == len)
+		return 1;
+
+	tmp &= 0x0f;
+	if (tmp > 9)
+		*str = tmp + 'A' - 10;
+	else
+		*str = tmp + '0';
+	(*pos)++;
+
+	return 0;
+}
+
+static const char *ipx_ntop1(const struct ipx_addr *addr, char *str, size_t len)
+{
+	int i;
+	size_t pos = 0;
+
+	if (len == 0)
+		return str;
+
+	for(i = 7; i >= 0; i--)
+		if (do_digit(str + pos, ntohl(addr->ipx_net), i, &pos, len))
+			return str;
+
+	if (pos == len)
+		return str;
+
+	*(str + pos) = '.';
+	pos++;
+
+	for(i = 0; i < 6; i++) {
+		if (do_digit(str + pos, addr->ipx_node[i], 1, &pos, len))
+			return str;
+		if (do_digit(str + pos, addr->ipx_node[i], 0, &pos, len))
+			return str;
+	}
+
+	if (pos == len)
+		return str;
+
+	*(str + pos) = 0;
+
+	return str;
+}
+
+
+const char *ipx_ntop(int af, const void *addr, char *str, size_t len)
+{
+	switch(af) {
+		case AF_IPX:
+			errno = 0;
+			return ipx_ntop1((struct ipx_addr *)addr, str, len);
+		default:
+			errno = EAFNOSUPPORT;
+	}
+
+	return NULL;
+}
+
+
diff --git a/lib/ipx_pton.c b/lib/ipx_pton.c
new file mode 100644
index 0000000..3dca271
--- /dev/null
+++ b/lib/ipx_pton.c
@@ -0,0 +1,108 @@
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "utils.h"
+
+static u_int32_t hexget(char c)
+{
+	if (c >= 'A' && c <= 'F')
+		return c - 'A' + 10;
+	if (c >= 'a' && c <= 'f')
+		return c - 'a' + 10;
+	if (c >= '0' && c <= '9')
+		return c - '0';
+
+	return 0xf0;
+}
+
+static int ipx_getnet(u_int32_t *net, const char *str)
+{
+	int i;
+	u_int32_t tmp;
+
+	for(i = 0; *str && (i < 8); i++) {
+
+		if ((tmp = hexget(*str)) & 0xf0) {
+			if (*str == '.')
+				return 0;
+			else
+				return -1;
+		}
+
+		str++;
+		(*net) <<= 4;
+		(*net) |= tmp;
+	}
+
+	if (*str == 0)
+		return 0;
+
+	return -1;
+}
+
+static int ipx_getnode(u_int8_t *node, const char *str)
+{
+	int i;
+	u_int32_t tmp;
+
+	for(i = 0; i < 6; i++) {
+		if ((tmp = hexget(*str++)) & 0xf0)
+			return -1;
+		node[i] = (u_int8_t)tmp;
+		node[i] <<= 4;
+		if ((tmp = hexget(*str++)) & 0xf0)
+			return -1;
+		node[i] |= (u_int8_t)tmp;
+		if (*str == ':')
+			str++;
+	}
+
+	return 0;
+}
+
+static int ipx_pton1(const char *src, struct ipx_addr *addr)
+{
+	char *sep = (char *)src;
+	int no_node = 0;
+
+	memset(addr, 0, sizeof(struct ipx_addr));
+
+	while(*sep && (*sep != '.'))
+		sep++;
+
+	if (*sep != '.')
+		no_node = 1;
+
+	if (ipx_getnet(&addr->ipx_net, src))
+		return 0;
+
+	addr->ipx_net = htonl(addr->ipx_net);
+
+	if (no_node)
+		return 1;
+
+	if (ipx_getnode(addr->ipx_node, sep + 1))
+		return 0;
+
+	return 1;
+}
+
+int ipx_pton(int af, const char *src, void *addr)
+{
+	int err;
+
+	switch (af) {
+	case AF_IPX:
+		errno = 0;
+		err = ipx_pton1(src, (struct ipx_addr *)addr);
+		break;
+	default:
+		errno = EAFNOSUPPORT;
+		err = -1;
+	}
+
+	return err;
+}
diff --git a/lib/json_print.c b/lib/json_print.c
deleted file mode 100644
index 43ea69b..0000000
--- a/lib/json_print.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * json_print.c		"print regular or json output, based on json_writer".
- *
- *             This program is free software; you can redistribute it and/or
- *             modify it under the terms of the GNU General Public License
- *             as published by the Free Software Foundation; either version
- *             2 of the License, or (at your option) any later version.
- *
- * Authors:    Julien Fortin, <julien@cumulusnetworks.com>
- */
-
-#include <stdarg.h>
-#include <stdio.h>
-
-#include "utils.h"
-#include "json_print.h"
-
-static json_writer_t *_jw;
-
-#define _IS_JSON_CONTEXT(type) ((type & PRINT_JSON || type & PRINT_ANY) && _jw)
-#define _IS_FP_CONTEXT(type) (!_jw && (type & PRINT_FP || type & PRINT_ANY))
-
-void new_json_obj(int json)
-{
-	if (json) {
-		_jw = jsonw_new(stdout);
-		if (!_jw) {
-			perror("json object");
-			exit(1);
-		}
-		if (pretty)
-			jsonw_pretty(_jw, true);
-		jsonw_start_array(_jw);
-	}
-}
-
-void delete_json_obj(void)
-{
-	if (_jw) {
-		jsonw_end_array(_jw);
-		jsonw_destroy(&_jw);
-	}
-}
-
-bool is_json_context(void)
-{
-	return _jw != NULL;
-}
-
-json_writer_t *get_json_writer(void)
-{
-	return _jw;
-}
-
-void open_json_object(const char *str)
-{
-	if (_IS_JSON_CONTEXT(PRINT_JSON)) {
-		if (str)
-			jsonw_name(_jw, str);
-		jsonw_start_object(_jw);
-	}
-}
-
-void close_json_object(void)
-{
-	if (_IS_JSON_CONTEXT(PRINT_JSON))
-		jsonw_end_object(_jw);
-}
-
-/*
- * Start json array or string array using
- * the provided string as json key (if not null)
- * or as array delimiter in non-json context.
- */
-void open_json_array(enum output_type type, const char *str)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		if (str)
-			jsonw_name(_jw, str);
-		jsonw_start_array(_jw);
-	} else if (_IS_FP_CONTEXT(type)) {
-		printf("%s", str);
-	}
-}
-
-/*
- * End json array or string array
- */
-void close_json_array(enum output_type type, const char *str)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		jsonw_end_array(_jw);
-	} else if (_IS_FP_CONTEXT(type)) {
-		printf("%s", str);
-	}
-}
-
-/*
- * pre-processor directive to generate similar
- * functions handling different types
- */
-#define _PRINT_FUNC(type_name, type)					\
-	__attribute__((format(printf, 4, 0)))				\
-	void print_color_##type_name(enum output_type t,		\
-				     enum color_attr color,		\
-				     const char *key,			\
-				     const char *fmt,			\
-				     type value)			\
-	{								\
-		if (_IS_JSON_CONTEXT(t)) {				\
-			if (!key)					\
-				jsonw_##type_name(_jw, value);		\
-			else						\
-				jsonw_##type_name##_field(_jw, key, value); \
-		} else if (_IS_FP_CONTEXT(t)) {				\
-			color_fprintf(stdout, color, fmt, value);          \
-		}							\
-	}
-_PRINT_FUNC(int, int);
-_PRINT_FUNC(s64, int64_t);
-_PRINT_FUNC(hhu, unsigned char);
-_PRINT_FUNC(hu, unsigned short);
-_PRINT_FUNC(uint, unsigned int);
-_PRINT_FUNC(u64, uint64_t);
-_PRINT_FUNC(luint, unsigned long);
-_PRINT_FUNC(lluint, unsigned long long);
-_PRINT_FUNC(float, double);
-#undef _PRINT_FUNC
-
-void print_color_string(enum output_type type,
-			enum color_attr color,
-			const char *key,
-			const char *fmt,
-			const char *value)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		if (key && !value)
-			jsonw_name(_jw, key);
-		else if (!key && value)
-			jsonw_string(_jw, value);
-		else
-			jsonw_string_field(_jw, key, value);
-	} else if (_IS_FP_CONTEXT(type)) {
-		color_fprintf(stdout, color, fmt, value);
-	}
-}
-
-/*
- * value's type is bool. When using this function in FP context you can't pass
- * a value to it, you will need to use "is_json_context()" to have different
- * branch for json and regular output. grep -r "print_bool" for example
- */
-void print_color_bool(enum output_type type,
-		      enum color_attr color,
-		      const char *key,
-		      const char *fmt,
-		      bool value)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		if (key)
-			jsonw_bool_field(_jw, key, value);
-		else
-			jsonw_bool(_jw, value);
-	} else if (_IS_FP_CONTEXT(type)) {
-		color_fprintf(stdout, color, fmt, value ? "true" : "false");
-	}
-}
-
-/*
- * In JSON context uses hardcode %#x format: 42 -> 0x2a
- */
-void print_color_0xhex(enum output_type type,
-		       enum color_attr color,
-		       const char *key,
-		       const char *fmt,
-		       unsigned long long hex)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		SPRINT_BUF(b1);
-
-		snprintf(b1, sizeof(b1), "%#llx", hex);
-		print_string(PRINT_JSON, key, NULL, b1);
-	} else if (_IS_FP_CONTEXT(type)) {
-		color_fprintf(stdout, color, fmt, hex);
-	}
-}
-
-void print_color_hex(enum output_type type,
-		     enum color_attr color,
-		     const char *key,
-		     const char *fmt,
-		     unsigned int hex)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		SPRINT_BUF(b1);
-
-		snprintf(b1, sizeof(b1), "%x", hex);
-		if (key)
-			jsonw_string_field(_jw, key, b1);
-		else
-			jsonw_string(_jw, b1);
-	} else if (_IS_FP_CONTEXT(type)) {
-		color_fprintf(stdout, color, fmt, hex);
-	}
-}
-
-/*
- * In JSON context we don't use the argument "value" we simply call jsonw_null
- * whereas FP context can use "value" to output anything
- */
-void print_color_null(enum output_type type,
-		      enum color_attr color,
-		      const char *key,
-		      const char *fmt,
-		      const char *value)
-{
-	if (_IS_JSON_CONTEXT(type)) {
-		if (key)
-			jsonw_null_field(_jw, key);
-		else
-			jsonw_null(_jw);
-	} else if (_IS_FP_CONTEXT(type)) {
-		color_fprintf(stdout, color, fmt, value);
-	}
-}
-
-/* Print line separator (if not in JSON mode) */
-void print_nl(void)
-{
-	if (!_jw)
-		printf("%s", _SL_);
-}
diff --git a/lib/json_writer.c b/lib/json_writer.c
index 88c5eb8..2af16e1 100644
--- a/lib/json_writer.c
+++ b/lib/json_writer.c
@@ -1,10 +1,14 @@
-/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
 /*
  * Simple streaming JSON writer
  *
  * This takes care of the annoying bits of JSON syntax like the commas
  * after elements
  *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
  * Authors:	Stephen Hemminger <stephen@networkplumber.org>
  */
 
@@ -29,7 +33,7 @@
 static void jsonw_indent(json_writer_t *self)
 {
 	unsigned i;
-	for (i = 0; i < self->depth; ++i)
+	for (i = 0; i <= self->depth; ++i)
 		fputs("    ", self->out);
 }
 
@@ -75,7 +79,7 @@
 			fputs("\\b", self->out);
 			break;
 		case '\\':
-			fputs("\\\\", self->out);
+			fputs("\\n", self->out);
 			break;
 		case '"':
 			fputs("\\\"", self->out);
@@ -98,6 +102,7 @@
 		self->depth = 0;
 		self->pretty = false;
 		self->sep = '\0';
+		putc('{', self->out);
 	}
 	return self;
 }
@@ -108,7 +113,8 @@
 	json_writer_t *self = *self_p;
 
 	assert(self->depth == 0);
-	fputs("\n", self->out);
+	jsonw_eol(self);
+	fputs("}\n", self->out);
 	fflush(self->out);
 	free(self);
 	*self_p = NULL;
@@ -152,8 +158,7 @@
 		putc(' ', self->out);
 }
 
-__attribute__((format(printf, 2, 3)))
-void jsonw_printf(json_writer_t *self, const char *fmt, ...)
+static void jsonw_printf(json_writer_t *self, const char *fmt, ...)
 {
 	va_list ap;
 
@@ -177,15 +182,10 @@
 void jsonw_start_array(json_writer_t *self)
 {
 	jsonw_begin(self, '[');
-	if (self->pretty)
-		putc(' ', self->out);
 }
 
 void jsonw_end_array(json_writer_t *self)
 {
-	if (self->pretty && self->sep)
-		putc(' ', self->out);
-	self->sep = '\0';
 	jsonw_end(self, ']');
 }
 
@@ -201,6 +201,7 @@
 	jsonw_printf(self, "%s", val ? "true" : "false");
 }
 
+#ifdef notused
 void jsonw_null(json_writer_t *self)
 {
 	jsonw_printf(self, "null");
@@ -210,48 +211,14 @@
 {
 	jsonw_printf(self, "%g", num);
 }
+#endif
 
-void jsonw_hhu(json_writer_t *self, unsigned char num)
-{
-	jsonw_printf(self, "%hhu", num);
-}
-
-void jsonw_hu(json_writer_t *self, unsigned short num)
-{
-	jsonw_printf(self, "%hu", num);
-}
-
-void jsonw_uint(json_writer_t *self, unsigned int num)
-{
-	jsonw_printf(self, "%u", num);
-}
-
-void jsonw_u64(json_writer_t *self, uint64_t num)
+void jsonw_uint(json_writer_t *self, uint64_t num)
 {
 	jsonw_printf(self, "%"PRIu64, num);
 }
 
-void jsonw_xint(json_writer_t *self, uint64_t num)
-{
-	jsonw_printf(self, "%"PRIx64, num);
-}
-
-void jsonw_luint(json_writer_t *self, unsigned long num)
-{
-	jsonw_printf(self, "%lu", num);
-}
-
-void jsonw_lluint(json_writer_t *self, unsigned long long num)
-{
-	jsonw_printf(self, "%llu", num);
-}
-
-void jsonw_int(json_writer_t *self, int num)
-{
-	jsonw_printf(self, "%d", num);
-}
-
-void jsonw_s64(json_writer_t *self, int64_t num)
+void jsonw_int(json_writer_t *self, int64_t num)
 {
 	jsonw_printf(self, "%"PRId64, num);
 }
@@ -269,82 +236,39 @@
 	jsonw_bool(self, val);
 }
 
+#ifdef notused
 void jsonw_float_field(json_writer_t *self, const char *prop, double val)
 {
 	jsonw_name(self, prop);
 	jsonw_float(self, val);
 }
+#endif
 
-void jsonw_uint_field(json_writer_t *self, const char *prop, unsigned int num)
+void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num)
 {
 	jsonw_name(self, prop);
 	jsonw_uint(self, num);
 }
 
-void jsonw_u64_field(json_writer_t *self, const char *prop, uint64_t num)
-{
-	jsonw_name(self, prop);
-	jsonw_u64(self, num);
-}
-
-void jsonw_xint_field(json_writer_t *self, const char *prop, uint64_t num)
-{
-	jsonw_name(self, prop);
-	jsonw_xint(self, num);
-}
-
-void jsonw_hhu_field(json_writer_t *self, const char *prop, unsigned char num)
-{
-	jsonw_name(self, prop);
-	jsonw_hhu(self, num);
-}
-
-void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num)
-{
-	jsonw_name(self, prop);
-	jsonw_hu(self, num);
-}
-
-void jsonw_luint_field(json_writer_t *self,
-			const char *prop,
-			unsigned long num)
-{
-	jsonw_name(self, prop);
-	jsonw_luint(self, num);
-}
-
-void jsonw_lluint_field(json_writer_t *self,
-			const char *prop,
-			unsigned long long num)
-{
-	jsonw_name(self, prop);
-	jsonw_lluint(self, num);
-}
-
-void jsonw_int_field(json_writer_t *self, const char *prop, int num)
+void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num)
 {
 	jsonw_name(self, prop);
 	jsonw_int(self, num);
 }
 
-void jsonw_s64_field(json_writer_t *self, const char *prop, int64_t num)
-{
-	jsonw_name(self, prop);
-	jsonw_s64(self, num);
-}
-
+#ifdef notused
 void jsonw_null_field(json_writer_t *self, const char *prop)
 {
 	jsonw_name(self, prop);
 	jsonw_null(self);
 }
+#endif
 
 #ifdef TEST
 int main(int argc, char **argv)
 {
 	json_writer_t *wr = jsonw_new(stdout);
 
-	jsonw_start_object(wr);
 	jsonw_pretty(wr, true);
 	jsonw_name(wr, "Vyatta");
 	jsonw_start_object(wr);
@@ -381,7 +305,6 @@
 
 	jsonw_end_object(wr);
 
-	jsonw_end_object(wr);
 	jsonw_destroy(&wr);
 	return 0;
 }
diff --git a/lib/libgenl.c b/lib/libgenl.c
index f2ce698..acb1478 100644
--- a/lib/libgenl.c
+++ b/lib/libgenl.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * libgenl.c	GENL library
  */
@@ -50,37 +49,15 @@
 {
 	GENL_REQUEST(req, 1024, GENL_ID_CTRL, 0, 0, CTRL_CMD_GETFAMILY,
 		     NLM_F_REQUEST);
-	struct nlmsghdr *answer;
-	int fnum;
 
 	addattr_l(&req.n, sizeof(req), CTRL_ATTR_FAMILY_NAME,
 		  family, strlen(family) + 1);
 
-	if (rtnl_talk(grth, &req.n, &answer) < 0) {
+	if (rtnl_talk(grth, &req.n, &req.n, sizeof(req)) < 0) {
 		fprintf(stderr, "Error talking to the kernel\n");
 		return -2;
 	}
 
-	fnum = genl_parse_getfamily(answer);
-	free(answer);
-
-	return fnum;
+	return genl_parse_getfamily(&req.n);
 }
 
-int genl_init_handle(struct rtnl_handle *grth, const char *family,
-		     int *genl_family)
-{
-	if (*genl_family >= 0)
-		return 0;
-
-	if (rtnl_open_byproto(grth, 0, NETLINK_GENERIC) < 0) {
-		fprintf(stderr, "Cannot open generic netlink socket\n");
-		return -1;
-	}
-
-	*genl_family = genl_resolve_family(grth, family);
-	if (*genl_family < 0)
-		return -1;
-
-	return 0;
-}
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index e02d629..d6b5fd3 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -12,8 +12,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <net/if_arp.h>
 #include <sys/socket.h>
@@ -22,15 +22,9 @@
 #include <errno.h>
 #include <time.h>
 #include <sys/uio.h>
-#include <linux/fib_rules.h>
-#include <linux/if_addrlabel.h>
-#include <linux/if_bridge.h>
-#include <linux/nexthop.h>
 
 #include "libnetlink.h"
 
-#define __aligned(x)		__attribute__((aligned(x)))
-
 #ifndef SOL_NETLINK
 #define SOL_NETLINK 270
 #endif
@@ -41,145 +35,6 @@
 
 int rcvbuf = 1024 * 1024;
 
-#ifdef HAVE_LIBMNL
-#include <libmnl/libmnl.h>
-
-static const enum mnl_attr_data_type extack_policy[NLMSGERR_ATTR_MAX + 1] = {
-	[NLMSGERR_ATTR_MSG]	= MNL_TYPE_NUL_STRING,
-	[NLMSGERR_ATTR_OFFS]	= MNL_TYPE_U32,
-};
-
-static int err_attr_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	uint16_t type;
-
-	if (mnl_attr_type_valid(attr, NLMSGERR_ATTR_MAX) < 0) {
-		fprintf(stderr, "Invalid extack attribute\n");
-		return MNL_CB_ERROR;
-	}
-
-	type = mnl_attr_get_type(attr);
-	if (mnl_attr_validate(attr, extack_policy[type]) < 0) {
-		fprintf(stderr, "extack attribute %d failed validation\n",
-			type);
-		return MNL_CB_ERROR;
-	}
-
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-static void print_ext_ack_msg(bool is_err, const char *msg)
-{
-	fprintf(stderr, "%s: %s", is_err ? "Error" : "Warning", msg);
-	if (msg[strlen(msg) - 1] != '.')
-		fprintf(stderr, ".");
-	fprintf(stderr, "\n");
-}
-
-/* dump netlink extended ack error message */
-int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
-{
-	struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
-	const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
-	const struct nlmsghdr *err_nlh = NULL;
-	unsigned int hlen = sizeof(*err);
-	const char *msg = NULL;
-	uint32_t off = 0;
-
-	/* no TLVs, nothing to do here */
-	if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
-		return 0;
-
-	/* if NLM_F_CAPPED is set then the inner err msg was capped */
-	if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
-		hlen += mnl_nlmsg_get_payload_len(&err->msg);
-
-	if (mnl_attr_parse(nlh, hlen, err_attr_cb, tb) != MNL_CB_OK)
-		return 0;
-
-	if (tb[NLMSGERR_ATTR_MSG])
-		msg = mnl_attr_get_str(tb[NLMSGERR_ATTR_MSG]);
-
-	if (tb[NLMSGERR_ATTR_OFFS]) {
-		off = mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]);
-
-		if (off > nlh->nlmsg_len) {
-			fprintf(stderr,
-				"Invalid offset for NLMSGERR_ATTR_OFFS\n");
-			off = 0;
-		} else if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
-			err_nlh = &err->msg;
-	}
-
-	if (errfn)
-		return errfn(msg, off, err_nlh);
-
-	if (msg && *msg != '\0') {
-		bool is_err = !!err->error;
-
-		print_ext_ack_msg(is_err, msg);
-		return is_err ? 1 : 0;
-	}
-
-	return 0;
-}
-
-int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
-{
-	struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
-	unsigned int hlen = sizeof(int);
-	const char *msg = NULL;
-
-	if (mnl_attr_parse(nlh, hlen, err_attr_cb, tb) != MNL_CB_OK)
-		return 0;
-
-	if (tb[NLMSGERR_ATTR_MSG])
-		msg = mnl_attr_get_str(tb[NLMSGERR_ATTR_MSG]);
-
-	if (msg && *msg != '\0') {
-		bool is_err = !!error;
-
-		print_ext_ack_msg(is_err, msg);
-		return is_err ? 1 : 0;
-	}
-
-	return 0;
-}
-#else
-#warning "libmnl required for error support"
-
-/* No extended error ack without libmnl */
-int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
-{
-	return 0;
-}
-
-int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
-{
-	return 0;
-}
-#endif
-
-/* Older kernels may not support strict dump and filtering */
-void rtnl_set_strict_dump(struct rtnl_handle *rth)
-{
-	int one = 1;
-
-	if (setsockopt(rth->fd, SOL_NETLINK, NETLINK_GET_STRICT_CHK,
-		       &one, sizeof(one)) < 0)
-		return;
-
-	rth->flags |= RTNL_HANDLE_F_STRICT_CHK;
-}
-
-int rtnl_add_nl_group(struct rtnl_handle *rth, unsigned int group)
-{
-	return setsockopt(rth->fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
-			  &group, sizeof(group));
-}
-
 void rtnl_close(struct rtnl_handle *rth)
 {
 	if (rth->fd >= 0) {
@@ -188,12 +43,11 @@
 	}
 }
 
-int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
+int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
 		      int protocol)
 {
 	socklen_t addr_len;
 	int sndbuf = 32768;
-	int one = 1;
 
 	memset(rth, 0, sizeof(*rth));
 
@@ -204,34 +58,26 @@
 		return -1;
 	}
 
-	if (setsockopt(rth->fd, SOL_SOCKET, SO_SNDBUF,
-		       &sndbuf, sizeof(sndbuf)) < 0) {
+	if (setsockopt(rth->fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
 		perror("SO_SNDBUF");
 		return -1;
 	}
 
-	if (setsockopt(rth->fd, SOL_SOCKET, SO_RCVBUF,
-		       &rcvbuf, sizeof(rcvbuf)) < 0) {
+	if (setsockopt(rth->fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf)) < 0) {
 		perror("SO_RCVBUF");
 		return -1;
 	}
 
-	/* Older kernels may no support extended ACK reporting */
-	setsockopt(rth->fd, SOL_NETLINK, NETLINK_EXT_ACK,
-		   &one, sizeof(one));
-
 	memset(&rth->local, 0, sizeof(rth->local));
 	rth->local.nl_family = AF_NETLINK;
 	rth->local.nl_groups = subscriptions;
 
-	if (bind(rth->fd, (struct sockaddr *)&rth->local,
-		 sizeof(rth->local)) < 0) {
+	if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
 		perror("Cannot bind netlink socket");
 		return -1;
 	}
 	addr_len = sizeof(rth->local);
-	if (getsockname(rth->fd, (struct sockaddr *)&rth->local,
-			&addr_len) < 0) {
+	if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
 		perror("Cannot getsockname");
 		return -1;
 	}
@@ -240,351 +86,47 @@
 		return -1;
 	}
 	if (rth->local.nl_family != AF_NETLINK) {
-		fprintf(stderr, "Wrong address family %d\n",
-			rth->local.nl_family);
+		fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
 		return -1;
 	}
 	rth->seq = time(NULL);
 	return 0;
 }
 
-int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)
+int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
 {
 	return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE);
 }
 
-int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family,
-			 req_filter_fn_t filter_fn)
+int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
 {
-	struct {
-		struct nlmsghdr nlh;
-		struct nhmsg nhm;
-		char buf[128];
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)),
-		.nlh.nlmsg_type = RTM_GETNEXTHOP,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.nhm.nh_family = family,
-	};
-
-	if (filter_fn) {
-		int err;
-
-		err = filter_fn(&req.nlh, sizeof(req));
-		if (err)
-			return err;
-	}
-
-	return send(rth->fd, &req, sizeof(req), 0);
+	return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF);
 }
 
-int rtnl_addrdump_req(struct rtnl_handle *rth, int family,
-		      req_filter_fn_t filter_fn)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct ifaddrmsg ifm;
-		char buf[128];
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
-		.nlh.nlmsg_type = RTM_GETADDR,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ifm.ifa_family = family,
-	};
-
-	if (filter_fn) {
-		int err;
-
-		err = filter_fn(&req.nlh, sizeof(req));
-		if (err)
-			return err;
-	}
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct ifaddrlblmsg ifal;
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrlblmsg)),
-		.nlh.nlmsg_type = RTM_GETADDRLABEL,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ifal.ifal_family = family,
-	};
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_routedump_req(struct rtnl_handle *rth, int family,
-		       req_filter_fn_t filter_fn)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct rtmsg rtm;
-		char buf[128];
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
-		.nlh.nlmsg_type = RTM_GETROUTE,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.rtm.rtm_family = family,
-	};
-
-	if (filter_fn) {
-		int err;
-
-		err = filter_fn(&req.nlh, sizeof(req));
-		if (err)
-			return err;
-	}
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct fib_rule_hdr frh;
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)),
-		.nlh.nlmsg_type = RTM_GETRULE,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.frh.family = family
-	};
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_neighdump_req(struct rtnl_handle *rth, int family,
-		       req_filter_fn_t filter_fn)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct ndmsg ndm;
-		char buf[256];
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
-		.nlh.nlmsg_type = RTM_GETNEIGH,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ndm.ndm_family = family,
-	};
-
-	if (filter_fn) {
-		int err;
-
-		err = filter_fn(&req.nlh, sizeof(req));
-		if (err)
-			return err;
-	}
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_neightbldump_req(struct rtnl_handle *rth, int family)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct ndtmsg ndtmsg;
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg)),
-		.nlh.nlmsg_type = RTM_GETNEIGHTBL,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ndtmsg.ndtm_family = family,
-	};
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_mdbdump_req(struct rtnl_handle *rth, int family)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct br_port_msg bpm;
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_port_msg)),
-		.nlh.nlmsg_type = RTM_GETMDB,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.bpm.family = family,
-	};
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_netconfdump_req(struct rtnl_handle *rth, int family)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct netconfmsg ncm;
-		char buf[0] __aligned(NLMSG_ALIGNTO);
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct netconfmsg))),
-		.nlh.nlmsg_type = RTM_GETNETCONF,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ncm.ncm_family = family,
-	};
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_nsiddump_req_filter_fn(struct rtnl_handle *rth, int family,
-				req_filter_fn_t filter_fn)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct rtgenmsg rtm;
-		char buf[1024];
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct rtgenmsg))),
-		.nlh.nlmsg_type = RTM_GETNSID,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.rtm.rtgen_family = family,
-	};
-	int err;
-
-	if (!filter_fn)
-		return -EINVAL;
-
-	err = filter_fn(&req.nlh, sizeof(req));
-	if (err)
-		return err;
-
-	return send(rth->fd, &req, req.nlh.nlmsg_len, 0);
-}
-
-static int __rtnl_linkdump_req(struct rtnl_handle *rth, int family)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct ifinfomsg ifm;
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.nlh.nlmsg_type = RTM_GETLINK,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ifm.ifi_family = family,
-	};
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_linkdump_req(struct rtnl_handle *rth, int family)
-{
-	if (family == AF_UNSPEC)
-		return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF);
-
-	return __rtnl_linkdump_req(rth, family);
-}
-
-int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int family,
+int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type,
 			    __u32 filt_mask)
 {
-	if (family == AF_UNSPEC || family == AF_BRIDGE) {
-		struct {
-			struct nlmsghdr nlh;
-			struct ifinfomsg ifm;
-			/* attribute has to be NLMSG aligned */
-			struct rtattr ext_req __aligned(NLMSG_ALIGNTO);
-			__u32 ext_filter_mask;
-		} req = {
-			.nlh.nlmsg_len = sizeof(req),
-			.nlh.nlmsg_type = RTM_GETLINK,
-			.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-			.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-			.ifm.ifi_family = family,
-			.ext_req.rta_type = IFLA_EXT_MASK,
-			.ext_req.rta_len = RTA_LENGTH(sizeof(__u32)),
-			.ext_filter_mask = filt_mask,
-		};
-
-		return send(rth->fd, &req, sizeof(req), 0);
-	}
-
-	return __rtnl_linkdump_req(rth, family);
-}
-
-int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int family,
-				req_filter_fn_t filter_fn)
-{
-	if (family == AF_UNSPEC || family == AF_PACKET) {
-		struct {
-			struct nlmsghdr nlh;
-			struct ifinfomsg ifm;
-			char buf[1024];
-		} req = {
-			.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-			.nlh.nlmsg_type = RTM_GETLINK,
-			.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-			.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-			.ifm.ifi_family = family,
-		};
-		int err;
-
-		if (!filter_fn)
-			return -EINVAL;
-
-		err = filter_fn(&req.nlh, sizeof(req));
-		if (err)
-			return err;
-
-		return send(rth->fd, &req, req.nlh.nlmsg_len, 0);
-	}
-
-	return __rtnl_linkdump_req(rth, family);
-}
-
-int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth,
-				    req_filter_fn_t filter_fn)
-{
 	struct {
 		struct nlmsghdr nlh;
 		struct ifinfomsg ifm;
-		char buf[128];
-	} req = {
-		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.nlh.nlmsg_type = RTM_GETNEIGH,
-		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
-		.ifm.ifi_family = PF_BRIDGE,
-	};
-	int err;
-
-	err = filter_fn(&req.nlh, sizeof(req));
-	if (err)
-		return err;
-
-	return send(rth->fd, &req, sizeof(req), 0);
-}
-
-int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
-{
-	struct {
-		struct nlmsghdr nlh;
-		struct if_stats_msg ifsm;
+		/* attribute has to be NLMSG aligned */
+		struct rtattr ext_req __attribute__ ((aligned(NLMSG_ALIGNTO)));
+		__u32 ext_filter_mask;
 	} req;
 
 	memset(&req, 0, sizeof(req));
-	req.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct if_stats_msg));
-	req.nlh.nlmsg_type = RTM_GETSTATS;
+	req.nlh.nlmsg_len = sizeof(req);
+	req.nlh.nlmsg_type = type;
 	req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST;
 	req.nlh.nlmsg_pid = 0;
 	req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
-	req.ifsm.family = fam;
-	req.ifsm.filter_mask = filt_mask;
+	req.ifm.ifi_family = family;
 
-	return send(rth->fd, &req, sizeof(req), 0);
+	req.ext_req.rta_type = IFLA_EXT_MASK;
+	req.ext_req.rta_len = RTA_LENGTH(sizeof(__u32));
+	req.ext_filter_mask = filt_mask;
+
+	return send(rth->fd, (void*)&req, sizeof(req), 0);
 }
 
 int rtnl_send(struct rtnl_handle *rth, const void *buf, int len)
@@ -613,11 +155,10 @@
 	for (h = (struct nlmsghdr *)resp; NLMSG_OK(h, status);
 	     h = NLMSG_NEXT(h, status)) {
 		if (h->nlmsg_type == NLMSG_ERROR) {
-			struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
-
+			struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
 			if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
 				fprintf(stderr, "ERROR truncated\n");
-			else
+			else 
 				errno = -err->error;
 			return -1;
 		}
@@ -628,12 +169,7 @@
 
 int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
 {
-	struct nlmsghdr nlh = {
-		.nlmsg_len = NLMSG_LENGTH(len),
-		.nlmsg_type = type,
-		.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
-		.nlmsg_seq = rth->dump = ++rth->seq,
-	};
+	struct nlmsghdr nlh;
 	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
 	struct iovec iov[2] = {
 		{ .iov_base = &nlh, .iov_len = sizeof(nlh) },
@@ -641,11 +177,17 @@
 	};
 	struct msghdr msg = {
 		.msg_name = &nladdr,
-		.msg_namelen = sizeof(nladdr),
+		.msg_namelen = 	sizeof(nladdr),
 		.msg_iov = iov,
 		.msg_iovlen = 2,
 	};
 
+	nlh.nlmsg_len = NLMSG_LENGTH(len);
+	nlh.nlmsg_type = type;
+	nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST;
+	nlh.nlmsg_pid = 0;
+	nlh.nlmsg_seq = rth->dump = ++rth->seq;
+
 	return sendmsg(rth->fd, &msg, 0);
 }
 
@@ -653,7 +195,7 @@
 {
 	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
 	struct iovec iov = {
-		.iov_base = n,
+		.iov_base = (void*) n,
 		.iov_len = n->nlmsg_len
 	};
 	struct msghdr msg = {
@@ -670,123 +212,8 @@
 	return sendmsg(rth->fd, &msg, 0);
 }
 
-static int rtnl_dump_done(struct nlmsghdr *h)
-{
-	int len = *(int *)NLMSG_DATA(h);
-
-	if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
-		fprintf(stderr, "DONE truncated\n");
-		return -1;
-	}
-
-	if (len < 0) {
-		/* check for any messages returned from kernel */
-		if (nl_dump_ext_ack_done(h, len))
-			return len;
-
-		errno = -len;
-		switch (errno) {
-		case ENOENT:
-		case EOPNOTSUPP:
-			return -1;
-		case EMSGSIZE:
-			fprintf(stderr,
-				"Error: Buffer too small for object.\n");
-			break;
-		default:
-			perror("RTNETLINK answers");
-		}
-		return len;
-	}
-
-	/* check for any messages returned from kernel */
-	nl_dump_ext_ack(h, NULL);
-
-	return 0;
-}
-
-static void rtnl_dump_error(const struct rtnl_handle *rth,
-			    struct nlmsghdr *h)
-{
-
-	if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
-		fprintf(stderr, "ERROR truncated\n");
-	} else {
-		const struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
-
-		errno = -err->error;
-		if (rth->proto == NETLINK_SOCK_DIAG &&
-		    (errno == ENOENT ||
-		     errno == EOPNOTSUPP))
-			return;
-
-		if (!(rth->flags & RTNL_HANDLE_F_SUPPRESS_NLERR))
-			perror("RTNETLINK answers");
-	}
-}
-
-static int __rtnl_recvmsg(int fd, struct msghdr *msg, int flags)
-{
-	int len;
-
-	do {
-		len = recvmsg(fd, msg, flags);
-	} while (len < 0 && (errno == EINTR || errno == EAGAIN));
-
-	if (len < 0) {
-		fprintf(stderr, "netlink receive error %s (%d)\n",
-			strerror(errno), errno);
-		return -errno;
-	}
-
-	if (len == 0) {
-		fprintf(stderr, "EOF on netlink\n");
-		return -ENODATA;
-	}
-
-	return len;
-}
-
-static int rtnl_recvmsg(int fd, struct msghdr *msg, char **answer)
-{
-	struct iovec *iov = msg->msg_iov;
-	char *buf;
-	int len;
-
-	iov->iov_base = NULL;
-	iov->iov_len = 0;
-
-	len = __rtnl_recvmsg(fd, msg, MSG_PEEK | MSG_TRUNC);
-	if (len < 0)
-		return len;
-
-	if (len < 32768)
-		len = 32768;
-	buf = malloc(len);
-	if (!buf) {
-		fprintf(stderr, "malloc error: not enough buffer\n");
-		return -ENOMEM;
-	}
-
-	iov->iov_base = buf;
-	iov->iov_len = len;
-
-	len = __rtnl_recvmsg(fd, msg, 0);
-	if (len < 0) {
-		free(buf);
-		return len;
-	}
-
-	if (answer)
-		*answer = buf;
-	else
-		free(buf);
-
-	return len;
-}
-
-static int rtnl_dump_filter_l(struct rtnl_handle *rth,
-			      const struct rtnl_dump_filter_arg *arg)
+int rtnl_dump_filter_l(struct rtnl_handle *rth,
+		       const struct rtnl_dump_filter_arg *arg)
 {
 	struct sockaddr_nl nladdr;
 	struct iovec iov;
@@ -796,25 +223,37 @@
 		.msg_iov = &iov,
 		.msg_iovlen = 1,
 	};
-	char *buf;
+	char buf[16384];
 	int dump_intr = 0;
 
+	iov.iov_base = buf;
 	while (1) {
 		int status;
 		const struct rtnl_dump_filter_arg *a;
 		int found_done = 0;
 		int msglen = 0;
 
-		status = rtnl_recvmsg(rth->fd, &msg, &buf);
-		if (status < 0)
-			return status;
+		iov.iov_len = sizeof(buf);
+		status = recvmsg(rth->fd, &msg, 0);
+
+		if (status < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			fprintf(stderr, "netlink receive error %s (%d)\n",
+				strerror(errno), errno);
+			return -1;
+		}
+
+		if (status == 0) {
+			fprintf(stderr, "EOF on netlink\n");
+			return -1;
+		}
 
 		if (rth->dump_fp)
 			fwrite(buf, 1, NLMSG_ALIGN(status), rth->dump_fp);
 
 		for (a = arg; a->filter; a++) {
-			struct nlmsghdr *h = (struct nlmsghdr *)buf;
-
+			struct nlmsghdr *h = (struct nlmsghdr*)buf;
 			msglen = status;
 
 			while (NLMSG_OK(h, msglen)) {
@@ -831,35 +270,36 @@
 					dump_intr = 1;
 
 				if (h->nlmsg_type == NLMSG_DONE) {
-					err = rtnl_dump_done(h);
-					if (err < 0) {
-						free(buf);
-						return -1;
-					}
-
 					found_done = 1;
 					break; /* process next filter */
 				}
-
 				if (h->nlmsg_type == NLMSG_ERROR) {
-					rtnl_dump_error(rth, h);
-					free(buf);
+					struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
+					if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
+						fprintf(stderr,
+							"ERROR truncated\n");
+					} else {
+						errno = -err->error;
+						if (rth->proto == NETLINK_SOCK_DIAG &&
+						    (errno == ENOENT ||
+						     errno == EOPNOTSUPP))
+							return -1;
+
+						perror("RTNETLINK answers");
+					}
 					return -1;
 				}
 
 				if (!rth->dump_fp) {
-					err = a->filter(h, a->arg1);
-					if (err < 0) {
-						free(buf);
+					err = a->filter(&nladdr, h, a->arg1);
+					if (err < 0)
 						return err;
-					}
 				}
 
 skip_it:
 				h = NLMSG_NEXT(h, msglen);
 			}
 		}
-		free(buf);
 
 		if (found_done) {
 			if (dump_intr)
@@ -891,40 +331,32 @@
 	return rtnl_dump_filter_l(rth, a);
 }
 
-static void rtnl_talk_error(struct nlmsghdr *h, struct nlmsgerr *err,
-			    nl_ext_ack_fn_t errfn)
+int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
+	      struct nlmsghdr *answer, size_t maxlen)
 {
-	if (nl_dump_ext_ack(h, errfn))
-		return;
-
-	fprintf(stderr, "RTNETLINK answers: %s\n",
-		strerror(-err->error));
-}
-
-
-static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov,
-			   size_t iovlen, struct nlmsghdr **answer,
-			   bool show_rtnl_err, nl_ext_ack_fn_t errfn)
-{
-	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
-	struct iovec riov;
+	int status;
+	unsigned seq;
+	struct nlmsghdr *h;
+	struct sockaddr_nl nladdr;
+	struct iovec iov = {
+		.iov_base = (void*) n,
+		.iov_len = n->nlmsg_len
+	};
 	struct msghdr msg = {
 		.msg_name = &nladdr,
 		.msg_namelen = sizeof(nladdr),
-		.msg_iov = iov,
-		.msg_iovlen = iovlen,
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
 	};
-	unsigned int seq = 0;
-	struct nlmsghdr *h;
-	int i, status;
-	char *buf;
+	char   buf[32768];
 
-	for (i = 0; i < iovlen; i++) {
-		h = iov[i].iov_base;
-		h->nlmsg_seq = seq = ++rtnl->seq;
-		if (answer == NULL)
-			h->nlmsg_flags |= NLM_F_ACK;
-	}
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+
+	n->nlmsg_seq = seq = ++rtnl->seq;
+
+	if (answer == NULL)
+		n->nlmsg_flags |= NLM_F_ACK;
 
 	status = sendmsg(rtnl->fd, &msg, 0);
 	if (status < 0) {
@@ -932,91 +364,80 @@
 		return -1;
 	}
 
-	/* change msg to use the response iov */
-	msg.msg_iov = &riov;
-	msg.msg_iovlen = 1;
-	i = 0;
+	memset(buf,0,sizeof(buf));
+
+	iov.iov_base = buf;
 	while (1) {
-next:
-		status = rtnl_recvmsg(rtnl->fd, &msg, &buf);
-		++i;
+		iov.iov_len = sizeof(buf);
+		status = recvmsg(rtnl->fd, &msg, 0);
 
-		if (status < 0)
-			return status;
-
+		if (status < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			fprintf(stderr, "netlink receive error %s (%d)\n",
+				strerror(errno), errno);
+			return -1;
+		}
+		if (status == 0) {
+			fprintf(stderr, "EOF on netlink\n");
+			return -1;
+		}
 		if (msg.msg_namelen != sizeof(nladdr)) {
-			fprintf(stderr,
-				"sender address length == %d\n",
-				msg.msg_namelen);
+			fprintf(stderr, "sender address length == %d\n", msg.msg_namelen);
 			exit(1);
 		}
-		for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) {
+		for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
 			int len = h->nlmsg_len;
 			int l = len - sizeof(*h);
 
-			if (l < 0 || len > status) {
+			if (l < 0 || len>status) {
 				if (msg.msg_flags & MSG_TRUNC) {
 					fprintf(stderr, "Truncated message\n");
-					free(buf);
 					return -1;
 				}
-				fprintf(stderr,
-					"!!!malformed message: len=%d\n",
-					len);
+				fprintf(stderr, "!!!malformed message: len=%d\n", len);
 				exit(1);
 			}
 
 			if (nladdr.nl_pid != 0 ||
 			    h->nlmsg_pid != rtnl->local.nl_pid ||
-			    h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) {
+			    h->nlmsg_seq != seq) {
 				/* Don't forget to skip that message. */
 				status -= NLMSG_ALIGN(len);
-				h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
+				h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
 				continue;
 			}
 
 			if (h->nlmsg_type == NLMSG_ERROR) {
-				struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
-				int error = err->error;
-
+				struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
 				if (l < sizeof(struct nlmsgerr)) {
 					fprintf(stderr, "ERROR truncated\n");
-					free(buf);
-					return -1;
+				} else if (!err->error) {
+					if (answer)
+						memcpy(answer, h,
+						       MIN(maxlen, h->nlmsg_len));
+					return 0;
 				}
 
-				if (!error) {
-					/* check messages from kernel */
-					nl_dump_ext_ack(h, errfn);
-				} else {
-					errno = -error;
-
-					if (rtnl->proto != NETLINK_SOCK_DIAG &&
-					    show_rtnl_err)
-						rtnl_talk_error(h, err, errfn);
-				}
-
-				if (answer)
-					*answer = (struct nlmsghdr *)buf;
-				else
-					free(buf);
-
-				if (i < iovlen)
-					goto next;
-				return error ? -i : 0;
+				if (rtnl->proto != NETLINK_SOCK_DIAG)
+					fprintf(stderr,
+						"RTNETLINK answers: %s\n",
+						strerror(-err->error));
+				errno = -err->error;
+				return -1;
 			}
 
 			if (answer) {
-				*answer = (struct nlmsghdr *)buf;
+				memcpy(answer, h,
+				       MIN(maxlen, h->nlmsg_len));
 				return 0;
 			}
 
 			fprintf(stderr, "Unexpected reply!!!\n");
 
 			status -= NLMSG_ALIGN(len);
-			h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
+			h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
 		}
-		free(buf);
 
 		if (msg.msg_flags & MSG_TRUNC) {
 			fprintf(stderr, "Message truncated\n");
@@ -1030,36 +451,6 @@
 	}
 }
 
-static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
-		       struct nlmsghdr **answer,
-		       bool show_rtnl_err, nl_ext_ack_fn_t errfn)
-{
-	struct iovec iov = {
-		.iov_base = n,
-		.iov_len = n->nlmsg_len
-	};
-
-	return __rtnl_talk_iov(rtnl, &iov, 1, answer, show_rtnl_err, errfn);
-}
-
-int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
-	      struct nlmsghdr **answer)
-{
-	return __rtnl_talk(rtnl, n, answer, true, NULL);
-}
-
-int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,
-		  struct nlmsghdr **answer)
-{
-	return __rtnl_talk_iov(rtnl, iovec, iovlen, answer, true, NULL);
-}
-
-int rtnl_talk_suppress_rtnl_errmsg(struct rtnl_handle *rtnl, struct nlmsghdr *n,
-				   struct nlmsghdr **answer)
-{
-	return __rtnl_talk(rtnl, n, answer, false, NULL);
-}
-
 int rtnl_listen_all_nsid(struct rtnl_handle *rth)
 {
 	unsigned int on = 1;
@@ -1079,7 +470,7 @@
 {
 	int status;
 	struct nlmsghdr *h;
-	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
+	struct sockaddr_nl nladdr;
 	struct iovec iov;
 	struct msghdr msg = {
 		.msg_name = &nladdr,
@@ -1095,6 +486,11 @@
 		msg.msg_controllen = sizeof(cmsgbuf);
 	}
 
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+	nladdr.nl_pid = 0;
+	nladdr.nl_groups = 0;
+
 	iov.iov_base = buf;
 	while (1) {
 		struct rtnl_ctrl_data ctrl;
@@ -1117,9 +513,7 @@
 			return -1;
 		}
 		if (msg.msg_namelen != sizeof(nladdr)) {
-			fprintf(stderr,
-				"Sender address length == %d\n",
-				msg.msg_namelen);
+			fprintf(stderr, "Sender address length == %d\n", msg.msg_namelen);
 			exit(1);
 		}
 
@@ -1137,28 +531,26 @@
 				}
 		}
 
-		for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) {
+		for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
 			int err;
 			int len = h->nlmsg_len;
 			int l = len - sizeof(*h);
 
-			if (l < 0 || len > status) {
+			if (l<0 || len>status) {
 				if (msg.msg_flags & MSG_TRUNC) {
 					fprintf(stderr, "Truncated message\n");
 					return -1;
 				}
-				fprintf(stderr,
-					"!!!malformed message: len=%d\n",
-					len);
+				fprintf(stderr, "!!!malformed message: len=%d\n", len);
 				exit(1);
 			}
 
-			err = handler(&ctrl, h, jarg);
+			err = handler(&nladdr, &ctrl, h, jarg);
 			if (err < 0)
 				return err;
 
 			status -= NLMSG_ALIGN(len);
-			h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
+			h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
 		}
 		if (msg.msg_flags & MSG_TRUNC) {
 			fprintf(stderr, "Message truncated\n");
@@ -1174,9 +566,15 @@
 int rtnl_from_file(FILE *rtnl, rtnl_listen_filter_t handler,
 		   void *jarg)
 {
-	size_t status;
-	char buf[16384];
-	struct nlmsghdr *h = (struct nlmsghdr *)buf;
+	int status;
+	struct sockaddr_nl nladdr;
+	char   buf[16384];
+	struct nlmsghdr *h = (void*)buf;
+
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+	nladdr.nl_pid = 0;
+	nladdr.nl_groups = 0;
 
 	while (1) {
 		int err, len;
@@ -1184,20 +582,19 @@
 
 		status = fread(&buf, 1, sizeof(*h), rtnl);
 
-		if (status == 0 && feof(rtnl))
-			return 0;
-		if (status != sizeof(*h)) {
-			if (ferror(rtnl))
-				perror("rtnl_from_file: fread");
-			if (feof(rtnl))
-				fprintf(stderr, "rtnl-from_file: truncated message\n");
+		if (status < 0) {
+			if (errno == EINTR)
+				continue;
+			perror("rtnl_from_file: fread");
 			return -1;
 		}
+		if (status == 0)
+			return 0;
 
 		len = h->nlmsg_len;
 		l = len - sizeof(*h);
 
-		if (l < 0 || len > sizeof(buf)) {
+		if (l<0 || len>sizeof(buf)) {
 			fprintf(stderr, "!!!malformed message: len=%d @%lu\n",
 				len, ftell(rtnl));
 			return -1;
@@ -1205,15 +602,16 @@
 
 		status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl);
 
-		if (status != NLMSG_ALIGN(l)) {
-			if (ferror(rtnl))
-				perror("rtnl_from_file: fread");
-			if (feof(rtnl))
-				fprintf(stderr, "rtnl-from_file: truncated message\n");
+		if (status < 0) {
+			perror("rtnl_from_file: fread");
+			return -1;
+		}
+		if (status < l) {
+			fprintf(stderr, "rtnl-from_file: truncated message\n");
 			return -1;
 		}
 
-		err = handler(NULL, h, jarg);
+		err = handler(&nladdr, NULL, h, jarg);
 		if (err < 0)
 			return err;
 	}
@@ -1256,16 +654,13 @@
 	struct rtattr *rta;
 
 	if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
-		fprintf(stderr,
-			"addattr_l ERROR: message exceeded bound of %d\n",
-			maxlen);
+		fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen);
 		return -1;
 	}
 	rta = NLMSG_TAIL(n);
 	rta->rta_type = type;
 	rta->rta_len = len;
-	if (alen)
-		memcpy(RTA_DATA(rta), data, alen);
+	memcpy(RTA_DATA(rta), data, alen);
 	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len);
 	return 0;
 }
@@ -1273,9 +668,7 @@
 int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
 {
 	if (NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) {
-		fprintf(stderr,
-			"addraw_l ERROR: message exceeded bound of %d\n",
-			maxlen);
+		fprintf(stderr, "addraw_l ERROR: message exceeded bound of %d\n",maxlen);
 		return -1;
 	}
 
@@ -1324,12 +717,10 @@
 	struct rtattr *subrta;
 
 	if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
-		fprintf(stderr,
-			"rta_addattr32: Error! max allowed bound %d exceeded\n",
-			maxlen);
+		fprintf(stderr,"rta_addattr32: Error! max allowed bound %d exceeded\n",maxlen);
 		return -1;
 	}
-	subrta = (struct rtattr *)(((char *)rta) + RTA_ALIGN(rta->rta_len));
+	subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
 	subrta->rta_type = type;
 	subrta->rta_len = len;
 	memcpy(RTA_DATA(subrta), &data, 4);
@@ -1344,16 +735,13 @@
 	int len = RTA_LENGTH(alen);
 
 	if (RTA_ALIGN(rta->rta_len) + RTA_ALIGN(len) > maxlen) {
-		fprintf(stderr,
-			"rta_addattr_l: Error! max allowed bound %d exceeded\n",
-			maxlen);
+		fprintf(stderr,"rta_addattr_l: Error! max allowed bound %d exceeded\n",maxlen);
 		return -1;
 	}
-	subrta = (struct rtattr *)(((char *)rta) + RTA_ALIGN(rta->rta_len));
+	subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
 	subrta->rta_type = type;
 	subrta->rta_len = len;
-	if (alen)
-		memcpy(RTA_DATA(subrta), data, alen);
+	memcpy(RTA_DATA(subrta), data, alen);
 	rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len);
 	return 0;
 }
@@ -1378,7 +766,6 @@
 	struct rtattr *nest = RTA_TAIL(rta);
 
 	rta_addattr_l(rta, maxlen, type, NULL, 0);
-	nest->rta_type |= NLA_F_NESTED;
 
 	return nest;
 }
@@ -1405,14 +792,28 @@
 		type = rta->rta_type & ~flags;
 		if ((type <= max) && (!tb[type]))
 			tb[type] = rta;
-		rta = RTA_NEXT(rta, len);
+		rta = RTA_NEXT(rta,len);
 	}
 	if (len)
-		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n",
-			len, rta->rta_len);
+		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
 	return 0;
 }
 
+int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len)
+{
+	int i = 0;
+
+	memset(tb, 0, sizeof(struct rtattr *) * max);
+	while (RTA_OK(rta, len)) {
+		if (rta->rta_type <= max && i < max)
+			tb[i++] = rta;
+		rta = RTA_NEXT(rta,len);
+	}
+	if (len)
+		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
+	return i;
+}
+
 struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len)
 {
 	while (RTA_OK(rta, len)) {
@@ -1420,16 +821,13 @@
 			return rta;
 		rta = RTA_NEXT(rta, len);
 	}
-
 	if (len)
-		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n",
-			len, rta->rta_len);
+		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
 	return NULL;
 }
 
-int __parse_rtattr_nested_compat(struct rtattr *tb[], int max,
-				 struct rtattr *rta,
-				 int len)
+int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta,
+			         int len)
 {
 	if (RTA_PAYLOAD(rta) < len)
 		return -1;
diff --git a/lib/ll_addr.c b/lib/ll_addr.c
index 00b562a..2ce9abf 100644
--- a/lib/ll_addr.c
+++ b/lib/ll_addr.c
@@ -12,9 +12,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
@@ -26,23 +28,31 @@
 #include "rt_names.h"
 #include "utils.h"
 
-const char *ll_addr_n2a(const unsigned char *addr, int alen, int type,
-			char *buf, int blen)
+
+const char *ll_addr_n2a(const unsigned char *addr, int alen, int type, char *buf, int blen)
 {
 	int i;
 	int l;
 
 	if (alen == 4 &&
-	    (type == ARPHRD_TUNNEL || type == ARPHRD_SIT
-	     || type == ARPHRD_IPGRE))
+	    (type == ARPHRD_TUNNEL || type == ARPHRD_SIT || type == ARPHRD_IPGRE)) {
 		return inet_ntop(AF_INET, addr, buf, blen);
-
-	if (alen == 16 && (type == ARPHRD_TUNNEL6 || type == ARPHRD_IP6GRE))
+	}
+	if (alen == 16 && type == ARPHRD_TUNNEL6) {
 		return inet_ntop(AF_INET6, addr, buf, blen);
-
-	snprintf(buf, blen, "%02x", addr[0]);
-	for (i = 1, l = 2; i < alen && l < blen; i++, l += 3)
-		snprintf(buf + l, blen - l, ":%02x", addr[i]);
+	}
+	l = 0;
+	for (i=0; i<alen; i++) {
+		if (i==0) {
+			snprintf(buf+l, blen, "%02x", addr[i]);
+			blen -= 2;
+			l += 2;
+		} else {
+			snprintf(buf+l, blen, ":%02x", addr[i]);
+			blen -= 3;
+			l += 3;
+		}
+	}
 	return buf;
 }
 
@@ -62,7 +72,7 @@
 	} else {
 		int i;
 
-		for (i = 0; i < len; i++) {
+		for (i=0; i<len; i++) {
 			int temp;
 			char *cp = strchr(arg, ':');
 			if (cp) {
@@ -70,13 +80,11 @@
 				cp++;
 			}
 			if (sscanf(arg, "%x", &temp) != 1) {
-				fprintf(stderr, "\"%s\" is invalid lladdr.\n",
-					arg);
+				fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
 				return -1;
 			}
 			if (temp < 0 || temp > 255) {
-				fprintf(stderr, "\"%s\" is invalid lladdr.\n",
-					arg);
+				fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
 				return -1;
 			}
 			lladdr[i] = temp;
@@ -84,6 +92,6 @@
 				break;
 			arg = cp;
 		}
-		return i + 1;
+		return i+1;
 	}
 }
diff --git a/lib/ll_map.c b/lib/ll_map.c
index e0ed54b..c6f7027 100644
--- a/lib/ll_map.c
+++ b/lib/ll_map.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -21,7 +22,7 @@
 
 #include "libnetlink.h"
 #include "ll_map.h"
-#include "list.h"
+#include "hlist.h"
 
 struct ll_cache {
 	struct hlist_node idx_hash;
@@ -29,7 +30,7 @@
 	unsigned	flags;
 	unsigned 	index;
 	unsigned short	type;
-	char		name[];
+	char		name[IFNAMSIZ];
 };
 
 #define IDXMAP_SIZE	1024
@@ -77,7 +78,8 @@
 	return NULL;
 }
 
-int ll_remember_index(struct nlmsghdr *n, void *arg)
+int ll_remember_index(const struct sockaddr_nl *who,
+		      struct nlmsghdr *n, void *arg)
 {
 	unsigned int h;
 	const char *ifname;
@@ -88,7 +90,7 @@
 	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
 		return 0;
 
-	if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifi)))
+	if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi)))
 		return -1;
 
 	im = ll_get_by_index(ifi->ifi_index);
@@ -101,6 +103,7 @@
 		return 0;
 	}
 
+	memset(tb, 0, sizeof(tb));
 	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
 	ifname = rta_getattr_str(tb[IFLA_IFNAME]);
 	if (ifname == NULL)
@@ -118,7 +121,7 @@
 		return 0;
 	}
 
-	im = malloc(sizeof(*im) + strlen(ifname) + 1);
+	im = malloc(sizeof(*im));
 	if (im == NULL)
 		return 0;
 	im->index = ifi->ifi_index;
@@ -135,68 +138,8 @@
 	return 0;
 }
 
-const char *ll_idx_n2a(unsigned int idx)
+const char *ll_idx_n2a(unsigned idx, char *buf)
 {
-	static char buf[IFNAMSIZ];
-
-	snprintf(buf, sizeof(buf), "if%u", idx);
-	return buf;
-}
-
-static unsigned int ll_idx_a2n(const char *name)
-{
-	unsigned int idx;
-
-	if (sscanf(name, "if%u", &idx) != 1)
-		return 0;
-	return idx;
-}
-
-static int ll_link_get(const char *name, int index)
-{
-	struct {
-		struct nlmsghdr		n;
-		struct ifinfomsg	ifm;
-		char			buf[1024];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_GETLINK,
-		.ifm.ifi_index = index,
-	};
-	__u32 filt_mask = RTEXT_FILTER_VF | RTEXT_FILTER_SKIP_STATS;
-	struct rtnl_handle rth = {};
-	struct nlmsghdr *answer;
-	int rc = 0;
-
-	if (rtnl_open(&rth, 0) < 0)
-		return 0;
-
-	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
-	if (name)
-		addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name,
-			  strlen(name) + 1);
-
-	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
-		goto out;
-
-	/* add entry to cache */
-	rc  = ll_remember_index(answer, NULL);
-	if (!rc) {
-		struct ifinfomsg *ifm = NLMSG_DATA(answer);
-
-		rc = ifm->ifi_index;
-	}
-
-	free(answer);
-out:
-	rtnl_close(&rth);
-	return rc;
-}
-
-const char *ll_index_to_name(unsigned int idx)
-{
-	static char buf[IFNAMSIZ];
 	const struct ll_cache *im;
 
 	if (idx == 0)
@@ -206,18 +149,19 @@
 	if (im)
 		return im->name;
 
-	if (ll_link_get(NULL, idx) == idx) {
-		im = ll_get_by_index(idx);
-		if (im)
-			return im->name;
-	}
-
 	if (if_indextoname(idx, buf) == NULL)
-		snprintf(buf, IFNAMSIZ, "if%u", idx);
+		snprintf(buf, IFNAMSIZ, "if%d", idx);
 
 	return buf;
 }
 
+const char *ll_index_to_name(unsigned idx)
+{
+	static char nbuf[IFNAMSIZ];
+
+	return ll_idx_n2a(idx, nbuf);
+}
+
 int ll_index_to_type(unsigned idx)
 {
 	const struct ll_cache *im;
@@ -252,28 +196,12 @@
 	if (im)
 		return im->index;
 
-	idx = ll_link_get(name, 0);
+	idx = if_nametoindex(name);
 	if (idx == 0)
-		idx = if_nametoindex(name);
-	if (idx == 0)
-		idx = ll_idx_a2n(name);
+		sscanf(name, "if%u", &idx);
 	return idx;
 }
 
-void ll_drop_by_index(unsigned index)
-{
-	struct ll_cache *im;
-
-	im = ll_get_by_index(index);
-	if (!im)
-		return;
-
-	hlist_del(&im->idx_hash);
-	hlist_del(&im->name_hash);
-
-	free(im);
-}
-
 void ll_init_map(struct rtnl_handle *rth)
 {
 	static int initialized;
@@ -281,7 +209,7 @@
 	if (initialized)
 		return;
 
-	if (rtnl_linkdump_req(rth, AF_UNSPEC) < 0) {
+	if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
diff --git a/lib/ll_proto.c b/lib/ll_proto.c
index 2a0c1cb..d8df68c 100644
--- a/lib/ll_proto.c
+++ b/lib/ll_proto.c
@@ -12,9 +12,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
@@ -78,8 +80,6 @@
 __PF(AOE,aoe)
 __PF(8021Q,802.1Q)
 __PF(8021AD,802.1ad)
-__PF(MPLS_UC,mpls_uc)
-__PF(MPLS_MC,mpls_mc)
 
 { 0x8100, "802.1Q" },
 { 0x88cc, "LLDP" },
@@ -94,7 +94,7 @@
 
 	id = ntohs(id);
 
-        for (i=0; !numeric && i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
+        for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
                  if (llproto_names[i].id == id)
 			return llproto_names[i].name;
 	}
@@ -111,7 +111,8 @@
 			 return 0;
 		 }
 	}
-	if (get_be16(id, buf, 0))
+	if (get_u16(id, buf, 0))
 		return -1;
+	*id = htons(*id);
 	return 0;
 }
diff --git a/lib/ll_types.c b/lib/ll_types.c
index 49da15d..2c5bf8b 100644
--- a/lib/ll_types.c
+++ b/lib/ll_types.c
@@ -12,9 +12,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
@@ -24,7 +26,6 @@
 #include <linux/sockios.h>
 
 #include "rt_names.h"
-#include "utils.h"
 
 const char * ll_type_n2a(int type, char *buf, int len)
 {
@@ -33,7 +34,7 @@
 	int type;
 	const char *name;
 } arphrd_names[] = {
-__PF(NETROM,netrom)
+{ 0, "generic" },
 __PF(ETHER,ether)
 __PF(EETHER,eether)
 __PF(AX25,ax25)
@@ -99,13 +100,11 @@
 __PF(IEEE80211_PRISM,ieee802.11/prism)
 __PF(IEEE80211_RADIOTAP,ieee802.11/radiotap)
 __PF(IEEE802154, ieee802.15.4)
-__PF(IEEE802154_MONITOR, ieee802.15.4/monitor)
 __PF(PHONET, phonet)
 __PF(PHONET_PIPE, phonet_pipe)
 __PF(CAIF, caif)
 __PF(IP6GRE, gre6)
 __PF(NETLINK, netlink)
-__PF(6LOWPAN, 6lowpan)
 
 __PF(NONE, none)
 __PF(VOID,void)
@@ -113,7 +112,7 @@
 #undef __PF
 
         int i;
-        for (i=0; !numeric && i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
+        for (i=0; i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
                  if (arphrd_names[i].type == type)
 			return arphrd_names[i].name;
 	}
diff --git a/lib/mpls_ntop.c b/lib/mpls_ntop.c
index f8d89f4..945d6d5 100644
--- a/lib/mpls_ntop.c
+++ b/lib/mpls_ntop.c
@@ -1,5 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-
 #include <errno.h>
 #include <string.h>
 #include <sys/types.h>
@@ -12,20 +10,18 @@
 {
 	size_t destlen = buflen;
 	char *dest = buf;
-	int count = 0;
+	int count;
 
-	while (1) {
-		uint32_t entry = ntohl(addr[count++].entry);
+	for (count = 0; count < MPLS_MAX_LABELS; count++) {
+		uint32_t entry = ntohl(addr[count].entry);
 		uint32_t label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
 		int len = snprintf(dest, destlen, "%u", label);
 
-		if (len >= destlen)
-			break;
-
 		/* Is this the end? */
 		if (entry & MPLS_LS_S_MASK)
 			return buf;
 
+
 		dest += len;
 		destlen -= len;
 		if (destlen) {
diff --git a/lib/mpls_pton.c b/lib/mpls_pton.c
index 065374e..bd448cf 100644
--- a/lib/mpls_pton.c
+++ b/lib/mpls_pton.c
@@ -1,5 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-
 #include <errno.h>
 #include <string.h>
 #include <sys/types.h>
@@ -9,13 +7,12 @@
 #include "utils.h"
 
 
-static int mpls_pton1(const char *name, struct mpls_label *addr,
-		      unsigned int maxlabels)
+static int mpls_pton1(const char *name, struct mpls_label *addr)
 {
 	char *endp;
 	unsigned count;
 
-	for (count = 0; count < maxlabels; count++) {
+	for (count = 0; count < MPLS_MAX_LABELS; count++) {
 		unsigned long label;
 
 		label = strtoul(name, &endp, 0);
@@ -40,19 +37,17 @@
 		addr += 1;
 	}
 	/* The address was too long */
-	fprintf(stderr, "Error: too many labels.\n");
 	return 0;
 }
 
-int mpls_pton(int af, const char *src, void *addr, size_t alen)
+int mpls_pton(int af, const char *src, void *addr)
 {
-	unsigned int maxlabels = alen / sizeof(struct mpls_label);
 	int err;
 
 	switch(af) {
 	case AF_MPLS:
 		errno = 0;
-		err = mpls_pton1(src, (struct mpls_label *)addr, maxlabels);
+		err = mpls_pton1(src, (struct mpls_label *)addr);
 		break;
 	default:
 		errno = EAFNOSUPPORT;
diff --git a/lib/names.c b/lib/names.c
index b46ea79..3b5b0b1 100644
--- a/lib/names.c
+++ b/lib/names.c
@@ -54,12 +54,15 @@
 {
 	struct db_names *db;
 
-	db = calloc(1, sizeof(*db));
+	db = malloc(sizeof(*db));
 	if (!db)
 		return NULL;
 
+	memset(db, 0, sizeof(*db));
+
 	db->size = MAX_ENTRIES;
-	db->hash = calloc(db->size, sizeof(struct db_entry *));
+	db->hash = malloc(sizeof(struct db_entry *) * db->size);
+	memset(db->hash, 0, sizeof(struct db_entry *) * db->size);
 
 	return db;
 }
@@ -150,3 +153,31 @@
 	snprintf(name, IDNAME_MAX, "%d", id);
 	return NULL;
 }
+
+int name_to_id(struct db_names *db, int *id, const char *name)
+{
+	struct db_entry *entry;
+	int i;
+
+	if (!db)
+		return -1;
+
+	if (db->cached && strcmp(db->cached->name, name) == 0) {
+		*id = db->cached->id;
+		return 0;
+	}
+
+	for (i = 0; i < db->size; i++) {
+		entry = db->hash[i];
+		while (entry && strcmp(entry->name, name))
+			entry = entry->next;
+
+		if (entry) {
+			db->cached = entry;
+			*id = entry->id;
+			return 0;
+		}
+	}
+
+	return -1;
+}
diff --git a/lib/namespace.c b/lib/namespace.c
index 06ae0a4..30b5138 100644
--- a/lib/namespace.c
+++ b/lib/namespace.c
@@ -7,7 +7,6 @@
  *		2 of the License, or (at your option) any later version.
  */
 
-#include <sys/statvfs.h>
 #include <fcntl.h>
 #include <dirent.h>
 #include <limits.h>
@@ -17,15 +16,12 @@
 
 static void bind_etc(const char *name)
 {
-	char etc_netns_path[sizeof(NETNS_ETC_DIR) + NAME_MAX];
+	char etc_netns_path[PATH_MAX];
 	char netns_name[PATH_MAX];
 	char etc_name[PATH_MAX];
 	struct dirent *entry;
 	DIR *dir;
 
-	if (strlen(name) >= NAME_MAX)
-		return;
-
 	snprintf(etc_netns_path, sizeof(etc_netns_path), "%s/%s", NETNS_ETC_DIR, name);
 	dir = opendir(etc_netns_path);
 	if (!dir)
@@ -50,8 +46,6 @@
 {
 	char net_path[PATH_MAX];
 	int netns;
-	unsigned long mountflags = 0;
-	struct statvfs fsstat;
 
 	snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
 	netns = open(net_path, O_RDONLY | O_CLOEXEC);
@@ -79,19 +73,12 @@
 			strerror(errno));
 		return -1;
 	}
-
 	/* Mount a version of /sys that describes the network namespace */
-
 	if (umount2("/sys", MNT_DETACH) < 0) {
-		/* If this fails, perhaps there wasn't a sysfs instance mounted. Good. */
-		if (statvfs("/sys", &fsstat) == 0) {
-			/* We couldn't umount the sysfs, we'll attempt to overlay it.
-			 * A read-only instance can't be shadowed with a read-write one. */
-			if (fsstat.f_flag & ST_RDONLY)
-				mountflags = MS_RDONLY;
-		}
+		fprintf(stderr, "umount of /sys failed: %s\n", strerror(errno));
+		return -1;
 	}
-	if (mount(name, "/sys", "sysfs", mountflags, NULL) < 0) {
+	if (mount(name, "/sys", "sysfs", 0, NULL) < 0) {
 		fprintf(stderr, "mount of /sys failed: %s\n",strerror(errno));
 		return -1;
 	}
diff --git a/lib/rt_names.c b/lib/rt_names.c
index 41cccfb..f6d17c0 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -12,12 +12,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <dirent.h>
-#include <limits.h>
 
 #include <asm/types.h>
 #include <linux/rtnetlink.h>
@@ -27,8 +27,6 @@
 
 #define NAME_MAX_LEN 512
 
-int numeric;
-
 struct rtnl_hash_entry {
 	struct rtnl_hash_entry	*next;
 	const char		*name;
@@ -120,7 +118,7 @@
 }
 
 static char *rtnl_rtprot_tab[256] = {
-	[RTPROT_UNSPEC]   = "unspec",
+	[RTPROT_UNSPEC]   = "none",
 	[RTPROT_REDIRECT] = "redirect",
 	[RTPROT_KERNEL]	  = "kernel",
 	[RTPROT_BOOT]	  = "boot",
@@ -136,11 +134,6 @@
 	[RTPROT_XORP]	  = "xorp",
 	[RTPROT_NTK]	  = "ntk",
 	[RTPROT_DHCP]	  = "dhcp",
-	[RTPROT_BGP]	  = "bgp",
-	[RTPROT_ISIS]	  = "isis",
-	[RTPROT_OSPF]	  = "ospf",
-	[RTPROT_RIP]	  = "rip",
-	[RTPROT_EIGRP]	  = "eigrp",
 };
 
 
@@ -148,41 +141,14 @@
 
 static void rtnl_rtprot_initialize(void)
 {
-	struct dirent *de;
-	DIR *d;
-
 	rtnl_rtprot_init = 1;
 	rtnl_tab_initialize(CONFDIR "/rt_protos",
 			    rtnl_rtprot_tab, 256);
-
-	d = opendir(CONFDIR "/rt_protos.d");
-	if (!d)
-		return;
-
-	while ((de = readdir(d)) != NULL) {
-		char path[PATH_MAX];
-		size_t len;
-
-		if (*de->d_name == '.')
-			continue;
-
-		/* only consider filenames ending in '.conf' */
-		len = strlen(de->d_name);
-		if (len <= 5)
-			continue;
-		if (strcmp(de->d_name + len - 5, ".conf"))
-			continue;
-
-		snprintf(path, sizeof(path), CONFDIR "/rt_protos.d/%s",
-			 de->d_name);
-		rtnl_tab_initialize(path, rtnl_rtprot_tab, 256);
-	}
-	closedir(d);
 }
 
 const char *rtnl_rtprot_n2a(int id, char *buf, int len)
 {
-	if (id < 0 || id >= 256 || numeric) {
+	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%u", id);
 		return buf;
 	}
@@ -248,7 +214,7 @@
 
 const char *rtnl_rtscope_n2a(int id, char *buf, int len)
 {
-	if (id < 0 || id >= 256 || numeric) {
+	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}
@@ -313,7 +279,7 @@
 
 const char *rtnl_rtrealm_n2a(int id, char *buf, int len)
 {
-	if (id < 0 || id >= 256 || numeric) {
+	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}
@@ -416,12 +382,16 @@
 {
 	struct rtnl_hash_entry *entry;
 
+	if (id > RT_TABLE_MAX) {
+		snprintf(buf, len, "%u", id);
+		return buf;
+	}
 	if (!rtnl_rttable_init)
 		rtnl_rttable_initialize();
 	entry = rtnl_rttable_hash[id & 255];
 	while (entry && entry->id != id)
 		entry = entry->next;
-	if (!numeric && entry)
+	if (entry)
 		return entry->name;
 	snprintf(buf, len, "%u", id);
 	return buf;
@@ -433,7 +403,7 @@
 	static unsigned long res;
 	struct rtnl_hash_entry *entry;
 	char *end;
-	unsigned long i;
+	__u32 i;
 
 	if (cache && strcmp(cache, arg) == 0) {
 		*id = res;
@@ -486,7 +456,7 @@
 		if (!rtnl_rtdsfield_init)
 			rtnl_rtdsfield_initialize();
 	}
-	if (!numeric && rtnl_rtdsfield_tab[id])
+	if (rtnl_rtdsfield_tab[id])
 		return rtnl_rtdsfield_tab[id];
 	snprintf(buf, len, "0x%02x", id);
 	return buf;
@@ -586,14 +556,10 @@
 	if (!rtnl_group_init)
 		rtnl_group_initialize();
 
-	for (i = 0; !numeric && i < 256; i++) {
+	for (i = 0; i < 256; i++) {
 		entry = rtnl_group_hash[i];
-
-		while (entry) {
-			if (entry->id == id)
-				return entry->name;
-			entry = entry->next;
-		}
+		if (entry && entry->id == id)
+			return entry->name;
 	}
 
 	snprintf(buf, len, "%d", id);
@@ -635,8 +601,8 @@
 
 const char *nl_proto_n2a(int id, char *buf, int len)
 {
-	if (id < 0 || id >= 256 || numeric) {
-		snprintf(buf, len, "%d", id);
+	if (id < 0 || id >= 256) {
+		snprintf(buf, len, "%u", id);
 		return buf;
 	}
 
diff --git a/lib/utils.c b/lib/utils.c
index 95d46ff..46a20de 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -14,12 +14,12 @@
 #include <stdlib.h>
 #include <math.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <string.h>
-#include <ctype.h>
 #include <netdb.h>
 #include <arpa/inet.h>
 #include <asm/types.h>
@@ -27,91 +27,15 @@
 #include <linux/param.h>
 #include <linux/if_arp.h>
 #include <linux/mpls.h>
-#include <linux/snmp.h>
 #include <time.h>
 #include <sys/time.h>
 #include <errno.h>
-#ifdef HAVE_LIBCAP
-#include <sys/capability.h>
-#endif
 
 #include "rt_names.h"
 #include "utils.h"
-#include "ll_map.h"
 #include "namespace.h"
 
-int resolve_hosts;
-int timestamp_short;
-int pretty;
-const char *_SL_ = "\n";
-
-static int af_byte_len(int af);
-static void print_time(char *buf, int len, __u32 time);
-static void print_time64(char *buf, int len, __s64 time);
-
-int read_prop(const char *dev, char *prop, long *value)
-{
-	char fname[128], buf[80], *endp, *nl;
-	FILE *fp;
-	long result;
-	int ret;
-
-	ret = snprintf(fname, sizeof(fname), "/sys/class/net/%s/%s",
-			dev, prop);
-
-	if (ret <= 0 || ret >= sizeof(fname)) {
-		fprintf(stderr, "could not build pathname for property\n");
-		return -1;
-	}
-
-	fp = fopen(fname, "r");
-	if (fp == NULL) {
-		fprintf(stderr, "fopen %s: %s\n", fname, strerror(errno));
-		return -1;
-	}
-
-	if (!fgets(buf, sizeof(buf), fp)) {
-		fprintf(stderr, "property \"%s\" in file %s is currently unknown\n", prop, fname);
-		fclose(fp);
-		goto out;
-	}
-
-	nl = strchr(buf, '\n');
-	if (nl)
-		*nl = '\0';
-
-	fclose(fp);
-	result = strtol(buf, &endp, 0);
-
-	if (*endp || buf == endp) {
-		fprintf(stderr, "value \"%s\" in file %s is not a number\n",
-			buf, fname);
-		goto out;
-	}
-
-	if ((result == LONG_MAX || result == LONG_MIN) && errno == ERANGE) {
-		fprintf(stderr, "strtol %s: %s", fname, strerror(errno));
-		goto out;
-	}
-
-	*value = result;
-	return 0;
-out:
-	fprintf(stderr, "Failed to parse %s\n", fname);
-	return -1;
-}
-
-int get_hex(char c)
-{
-	if (c >= 'A' && c <= 'F')
-		return c - 'A' + 10;
-	if (c >= 'a' && c <= 'f')
-		return c - 'a' + 10;
-	if (c >= '0' && c <= '9')
-		return c - '0';
-
-	return -1;
-}
+int timestamp_short = 0;
 
 int get_integer(int *val, const char *arg, int base)
 {
@@ -124,7 +48,7 @@
 	res = strtol(arg, &ptr, base);
 
 	/* If there were no digits at all, strtol()  stores
-	 * the original value of nptr in *endptr (and returns 0).
+         * the original value of nptr in *endptr (and returns 0).
 	 * In particular, if *nptr is not '\0' but **endptr is '\0' on return,
 	 * the entire string is valid.
 	 */
@@ -148,7 +72,7 @@
 
 int mask2bits(__u32 netmask)
 {
-	unsigned int bits = 0;
+	unsigned bits = 0;
 	__u32 mask = ntohl(netmask);
 	__u32 host = ~mask;
 
@@ -161,17 +85,17 @@
 	return bits;
 }
 
-static int get_netmask(unsigned int *val, const char *arg, int base)
+static int get_netmask(unsigned *val, const char *arg, int base)
 {
 	inet_prefix addr;
 
 	if (!get_unsigned(val, arg, base))
 		return 0;
 
-	/* try converting dotted quad to CIDR */
+	/* try coverting dotted quad to CIDR */
 	if (!get_addr_1(&addr, arg, AF_INET) && addr.family == AF_INET) {
 		int b = mask2bits(addr.data[0]);
-
+		
 		if (b >= 0) {
 			*val = b;
 			return 0;
@@ -181,7 +105,7 @@
 	return -1;
 }
 
-int get_unsigned(unsigned int *val, const char *arg, int base)
+int get_unsigned(unsigned *val, const char *arg, int base)
 {
 	unsigned long res;
 	char *ptr;
@@ -214,7 +138,7 @@
  * pass milliseconds (standard unit for rtt values since 2.6.27), and
  * have a different assumption for the units of a "raw" number.
  */
-int get_time_rtt(unsigned int *val, const char *arg, int *raw)
+int get_time_rtt(unsigned *val, const char *arg, int *raw)
 {
 	double t;
 	unsigned long res;
@@ -252,24 +176,23 @@
 
 	if (*p) {
 		*raw = 0;
-		if (strcasecmp(p, "s") == 0 ||
-		    strcasecmp(p, "sec") == 0 ||
-		    strcasecmp(p, "secs") == 0)
-			t *= 1000;
-		else if (strcasecmp(p, "ms") == 0 ||
-			 strcasecmp(p, "msec") == 0 ||
-			 strcasecmp(p, "msecs") == 0)
+                if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec")==0 ||
+                    strcasecmp(p, "secs")==0)
+                        t *= 1000;
+                else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec")==0 ||
+                         strcasecmp(p, "msecs") == 0)
 			t *= 1.0; /* allow suffix, do nothing */
-		else
-			return -1;
-	}
+                else
+                        return -1;
+        }
 
 	/* emulate ceil() without having to bring-in -lm and always be >= 1 */
+
 	*val = t;
 	if (*val < t)
 		*val += 1;
-
-	return 0;
+	
+        return 0;
 
 }
 
@@ -295,8 +218,8 @@
 	if (res > 0xFFFFFFFFFFFFFFFFULL)
 		return -1;
 
-	*val = res;
-	return 0;
+ 	*val = res;
+ 	return 0;
 }
 
 int get_u32(__u32 *val, const char *arg, int base)
@@ -372,27 +295,6 @@
 	return 0;
 }
 
-int get_s64(__s64 *val, const char *arg, int base)
-{
-	long long res;
-	char *ptr;
-
-	errno = 0;
-
-	if (!arg || !*arg)
-		return -1;
-	res = strtoll(arg, &ptr, base);
-	if (!ptr || ptr == arg || *ptr)
-		return -1;
-	if ((res == LLONG_MIN || res == LLONG_MAX) && errno == ERANGE)
-		return -1;
-	if (res > INT64_MAX || res < INT64_MIN)
-		return -1;
-
-	*val = res;
-	return 0;
-}
-
 int get_s32(__s32 *val, const char *arg, int base)
 {
 	long res;
@@ -414,37 +316,41 @@
 	return 0;
 }
 
-int get_be64(__be64 *val, const char *arg, int base)
+int get_s16(__s16 *val, const char *arg, int base)
 {
-	__u64 v;
-	int ret = get_u64(&v, arg, base);
+	long res;
+	char *ptr;
 
-	if (!ret)
-		*val = htonll(v);
+	if (!arg || !*arg)
+		return -1;
+	res = strtol(arg, &ptr, base);
+	if (!ptr || ptr == arg || *ptr)
+		return -1;
+	if ((res == LONG_MIN || res == LONG_MAX) && errno == ERANGE)
+		return -1;
+	if (res > 0x7FFF || res < -0x8000)
+		return -1;
 
-	return ret;
+	*val = res;
+	return 0;
 }
 
-int get_be32(__be32 *val, const char *arg, int base)
+int get_s8(__s8 *val, const char *arg, int base)
 {
-	__u32 v;
-	int ret = get_u32(&v, arg, base);
+	long res;
+	char *ptr;
 
-	if (!ret)
-		*val = htonl(v);
-
-	return ret;
-}
-
-int get_be16(__be16 *val, const char *arg, int base)
-{
-	__u16 v;
-	int ret = get_u16(&v, arg, base);
-
-	if (!ret)
-		*val = htons(v);
-
-	return ret;
+	if (!arg || !*arg)
+		return -1;
+	res = strtol(arg, &ptr, base);
+	if (!ptr || ptr == arg || *ptr)
+		return -1;
+	if ((res == LONG_MIN || res == LONG_MAX) && errno == ERANGE)
+		return -1;
+	if (res > 0x7F || res < -0x80)
+		return -1;
+	*val = res;
+	return 0;
 }
 
 /* This uses a non-standard parsing (ie not inet_aton, or inet_pton)
@@ -457,7 +363,7 @@
 	for (i = 0; i < 4; i++) {
 		unsigned long n;
 		char *endp;
-
+		
 		n = strtoul(cp, &endp, 0);
 		if (n > 255)
 			return -1;	/* bogus network value */
@@ -471,7 +377,7 @@
 			break;
 
 		if (i == 3 || *endp != '.')
-			return -1;	/* extra characters */
+			return -1; 	/* extra characters */
 		cp = endp + 1;
 	}
 
@@ -513,57 +419,24 @@
 	return 1;
 }
 
-static void set_address_type(inet_prefix *addr)
-{
-	switch (addr->family) {
-	case AF_INET:
-		if (!addr->data[0])
-			addr->flags |= ADDRTYPE_INET_UNSPEC;
-		else if (IN_MULTICAST(ntohl(addr->data[0])))
-			addr->flags |= ADDRTYPE_INET_MULTI;
-		else
-			addr->flags |= ADDRTYPE_INET;
-		break;
-	case AF_INET6:
-		if (IN6_IS_ADDR_UNSPECIFIED(addr->data))
-			addr->flags |= ADDRTYPE_INET_UNSPEC;
-		else if (IN6_IS_ADDR_MULTICAST(addr->data))
-			addr->flags |= ADDRTYPE_INET_MULTI;
-		else
-			addr->flags |= ADDRTYPE_INET;
-		break;
-	}
-}
-
-static int __get_addr_1(inet_prefix *addr, const char *name, int family)
+int get_addr_1(inet_prefix *addr, const char *name, int family)
 {
 	memset(addr, 0, sizeof(*addr));
 
-	if (strcmp(name, "default") == 0) {
-		if ((family == AF_DECnet) || (family == AF_MPLS))
-			return -1;
-		addr->family = family;
-		addr->bytelen = af_byte_len(addr->family);
-		addr->bitlen = -2;
-		addr->flags |= PREFIXLEN_SPECIFIED;
-		return 0;
-	}
-
-	if (strcmp(name, "all") == 0 ||
+	if (strcmp(name, "default") == 0 ||
+	    strcmp(name, "all") == 0 ||
 	    strcmp(name, "any") == 0) {
 		if ((family == AF_DECnet) || (family == AF_MPLS))
 			return -1;
 		addr->family = family;
-		addr->bytelen = 0;
-		addr->bitlen = -2;
+		addr->bytelen = (family == AF_INET6 ? 16 : 4);
+		addr->bitlen = -1;
 		return 0;
 	}
 
 	if (family == AF_PACKET) {
 		int len;
-
-		len = ll_addr_a2n((char *) &addr->data, sizeof(addr->data),
-				  name);
+		len = ll_addr_a2n((char *)&addr->data, sizeof(addr->data), name);
 		if (len < 0)
 			return -1;
 
@@ -584,19 +457,28 @@
 		return 0;
 	}
 
-	if (family == AF_MPLS) {
-		unsigned int maxlabels;
-		int i;
+#ifndef ANDROID
+	if (family == AF_DECnet) {
+		struct dn_naddr dna;
+		addr->family = AF_DECnet;
+		if (dnet_pton(AF_DECnet, name, &dna) <= 0)
+			return -1;
+		memcpy(addr->data, dna.a_addr, 2);
+		addr->bytelen = 2;
+		addr->bitlen = -1;
+		return 0;
+	}
+#endif
 
+	if (family == AF_MPLS) {
+		int i;
 		addr->family = AF_MPLS;
-		if (mpls_pton(AF_MPLS, name, addr->data,
-			      sizeof(addr->data)) <= 0)
+		if (mpls_pton(AF_MPLS, name, addr->data) <= 0)
 			return -1;
 		addr->bytelen = 4;
 		addr->bitlen = 20;
 		/* How many bytes do I need? */
-		maxlabels = sizeof(addr->data) / sizeof(struct mpls_label);
-		for (i = 0; i < maxlabels; i++) {
+		for (i = 0; i < 8; i++) {
 			if (ntohl(addr->data[i]) & MPLS_LS_S_MASK) {
 				addr->bytelen = (i + 1)*4;
 				break;
@@ -617,18 +499,6 @@
 	return 0;
 }
 
-int get_addr_1(inet_prefix *addr, const char *name, int family)
-{
-	int ret;
-
-	ret = __get_addr_1(addr, name, family);
-	if (ret)
-		return ret;
-
-	set_address_type(addr);
-	return 0;
-}
-
 int af_bit_len(int af)
 {
 	switch (af) {
@@ -647,125 +517,73 @@
 	return 0;
 }
 
-static int af_byte_len(int af)
+int af_byte_len(int af)
 {
 	return af_bit_len(af) / 8;
 }
 
 int get_prefix_1(inet_prefix *dst, char *arg, int family)
 {
+	int err;
+	unsigned plen;
 	char *slash;
-	int err, bitlen, flags;
+
+	memset(dst, 0, sizeof(*dst));
+
+	if (strcmp(arg, "default") == 0 ||
+	    strcmp(arg, "any") == 0 ||
+	    strcmp(arg, "all") == 0) {
+		if ((family == AF_DECnet) || (family == AF_MPLS))
+			return -1;
+		dst->family = family;
+		dst->bytelen = 0;
+		dst->bitlen = 0;
+		return 0;
+	}
 
 	slash = strchr(arg, '/');
 	if (slash)
 		*slash = 0;
 
 	err = get_addr_1(dst, arg, family);
+	if (err == 0) {
+		dst->bitlen = af_bit_len(dst->family);
 
+		if (slash) {
+			if (get_netmask(&plen, slash+1, 0)
+			    || plen > dst->bitlen) {
+				err = -1;
+				goto done;
+			}
+			dst->flags |= PREFIXLEN_SPECIFIED;
+			dst->bitlen = plen;
+		}
+	}
+done:
 	if (slash)
 		*slash = '/';
-
-	if (err)
-		return err;
-
-	bitlen = af_bit_len(dst->family);
-
-	flags = 0;
-	if (slash) {
-		unsigned int plen;
-
-		if (dst->bitlen == -2)
-			return -1;
-		if (get_netmask(&plen, slash + 1, 0))
-			return -1;
-		if (plen > bitlen)
-			return -1;
-
-		flags |= PREFIXLEN_SPECIFIED;
-		bitlen = plen;
-	} else {
-		if (dst->bitlen == -2)
-			bitlen = 0;
-	}
-
-	dst->flags |= flags;
-	dst->bitlen = bitlen;
-
-	return 0;
-}
-
-static const char *family_name_verbose(int family)
-{
-	if (family == AF_UNSPEC)
-		return "any valid";
-	return family_name(family);
+	return err;
 }
 
 int get_addr(inet_prefix *dst, const char *arg, int family)
 {
 	if (get_addr_1(dst, arg, family)) {
-		fprintf(stderr,
-			"Error: %s address is expected rather than \"%s\".\n",
-			family_name_verbose(family), arg);
+		fprintf(stderr, "Error: %s address is expected rather than \"%s\".\n",
+				family_name(family) ,arg);
 		exit(1);
 	}
 	return 0;
 }
 
-int get_addr_rta(inet_prefix *dst, const struct rtattr *rta, int family)
-{
-	const int len = RTA_PAYLOAD(rta);
-	const void *data = RTA_DATA(rta);
-
-	switch (len) {
-	case 4:
-		dst->family = AF_INET;
-		dst->bytelen = 4;
-		memcpy(dst->data, data, 4);
-		break;
-	case 16:
-		dst->family = AF_INET6;
-		dst->bytelen = 16;
-		memcpy(dst->data, data, 16);
-		break;
-	case 2:
-		dst->family = AF_DECnet;
-		dst->bytelen = 2;
-		memcpy(dst->data, data, 2);
-		break;
-	case 10:
-		dst->family = AF_IPX;
-		dst->bytelen = 10;
-		memcpy(dst->data, data, 10);
-		break;
-	default:
-		return -1;
-	}
-
-	if (family != AF_UNSPEC && family != dst->family)
-		return -2;
-
-	dst->bitlen = -1;
-	dst->flags = 0;
-
-	set_address_type(dst);
-	return 0;
-}
-
 int get_prefix(inet_prefix *dst, char *arg, int family)
 {
 	if (family == AF_PACKET) {
-		fprintf(stderr,
-			"Error: \"%s\" may be inet prefix, but it is not allowed in this context.\n",
-			arg);
+		fprintf(stderr, "Error: \"%s\" may be inet prefix, but it is not allowed in this context.\n", arg);
 		exit(1);
 	}
-
 	if (get_prefix_1(dst, arg, family)) {
-		fprintf(stderr,
-			"Error: %s prefix is expected rather than \"%s\".\n",
-			family_name_verbose(family), arg);
+		fprintf(stderr, "Error: %s prefix is expected rather than \"%s\".\n",
+				family_name(family) ,arg);
 		exit(1);
 	}
 	return 0;
@@ -774,11 +592,8 @@
 __u32 get_addr32(const char *name)
 {
 	inet_prefix addr;
-
 	if (get_addr_1(&addr, name, AF_INET)) {
-		fprintf(stderr,
-			"Error: an IP address is expected rather than \"%s\"\n",
-			name);
+		fprintf(stderr, "Error: an IP address is expected rather than \"%s\"\n", name);
 		exit(1);
 	}
 	return addr.data[0];
@@ -804,85 +619,22 @@
 
 void duparg(const char *key, const char *arg)
 {
-	fprintf(stderr,
-		"Error: duplicate \"%s\": \"%s\" is the second value.\n",
-		key, arg);
+	fprintf(stderr, "Error: duplicate \"%s\": \"%s\" is the second value.\n", key, arg);
 	exit(-1);
 }
 
 void duparg2(const char *key, const char *arg)
 {
-	fprintf(stderr,
-		"Error: either \"%s\" is duplicate, or \"%s\" is a garbage.\n",
-		key, arg);
+	fprintf(stderr, "Error: either \"%s\" is duplicate, or \"%s\" is a garbage.\n", key, arg);
 	exit(-1);
 }
 
-int nodev(const char *dev)
+int matches(const char *cmd, const char *pattern)
 {
-	fprintf(stderr, "Cannot find device \"%s\"\n", dev);
-	return -1;
-}
-
-int check_ifname(const char *name)
-{
-	/* These checks mimic kernel checks in dev_valid_name */
-	if (*name == '\0')
+	int len = strlen(cmd);
+	if (len > strlen(pattern))
 		return -1;
-	if (strlen(name) >= IFNAMSIZ)
-		return -1;
-
-	while (*name) {
-		if (*name == '/' || isspace(*name))
-			return -1;
-		++name;
-	}
-	return 0;
-}
-
-/* buf is assumed to be IFNAMSIZ */
-int get_ifname(char *buf, const char *name)
-{
-	int ret;
-
-	ret = check_ifname(name);
-	if (ret == 0)
-		strncpy(buf, name, IFNAMSIZ);
-
-	return ret;
-}
-
-const char *get_ifname_rta(int ifindex, const struct rtattr *rta)
-{
-	const char *name;
-
-	if (rta) {
-		name = rta_getattr_str(rta);
-	} else {
-		fprintf(stderr,
-			"BUG: device with ifindex %d has nil ifname\n",
-			ifindex);
-		name = ll_idx_n2a(ifindex);
-	}
-
-	if (check_ifname(name))
-		return NULL;
-
-	return name;
-}
-
-/* Returns false if 'prefix' is a not empty prefix of 'string'.
- */
-bool matches(const char *prefix, const char *string)
-{
-	if (!*prefix)
-		return true;
-	while (*string && *prefix == *string) {
-		prefix++;
-		string++;
-	}
-
-	return !!*prefix;
+	return memcmp(pattern, cmd, len);
 }
 
 int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits)
@@ -913,19 +665,6 @@
 	return 0;
 }
 
-int inet_addr_match_rta(const inet_prefix *m, const struct rtattr *rta)
-{
-	inet_prefix dst;
-
-	if (!rta || m->family == AF_UNSPEC || m->bitlen <= 0)
-		return 0;
-
-	if (get_addr_rta(&dst, rta, m->family))
-		return -1;
-
-	return inet_addr_match(&dst, m, m->bitlen);
-}
-
 int __iproute2_hz_internal;
 
 int __get_hz(void)
@@ -937,20 +676,17 @@
 	if (getenv("HZ"))
 		return atoi(getenv("HZ")) ? : HZ;
 
-	if (getenv("PROC_NET_PSCHED"))
-		snprintf(name, sizeof(name)-1,
-			 "%s", getenv("PROC_NET_PSCHED"));
-	else if (getenv("PROC_ROOT"))
-		snprintf(name, sizeof(name)-1,
-			 "%s/net/psched", getenv("PROC_ROOT"));
-	else
+	if (getenv("PROC_NET_PSCHED")) {
+		snprintf(name, sizeof(name)-1, "%s", getenv("PROC_NET_PSCHED"));
+	} else if (getenv("PROC_ROOT")) {
+		snprintf(name, sizeof(name)-1, "%s/net/psched", getenv("PROC_ROOT"));
+	} else {
 		strcpy(name, "/proc/net/psched");
-
+	}
 	fp = fopen(name, "r");
 
 	if (fp) {
-		unsigned int nom, denom;
-
+		unsigned nom, denom;
 		if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)
 			if (nom == 1000000)
 				hz = denom;
@@ -968,56 +704,40 @@
 	return sysconf(_SC_CLK_TCK);
 }
 
-const char *rt_addr_n2a_r(int af, int len,
-			  const void *addr, char *buf, int buflen)
+const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen)
 {
 	switch (af) {
 	case AF_INET:
 	case AF_INET6:
 		return inet_ntop(af, addr, buf, buflen);
+#ifndef ANDROID
 	case AF_MPLS:
 		return mpls_ntop(af, addr, buf, buflen);
+	case AF_IPX:
+		return ipx_ntop(af, addr, buf, buflen);
+	case AF_DECnet:
+	{
+		struct dn_naddr dna = { 2, { 0, 0, }};
+		memcpy(dna.a_addr, addr, 2);
+		return dnet_ntop(af, &dna, buf, buflen);
+	}
+#endif
 	case AF_PACKET:
 		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
-	case AF_BRIDGE:
-	{
-		const union {
-			struct sockaddr sa;
-			struct sockaddr_in sin;
-			struct sockaddr_in6 sin6;
-		} *sa = addr;
-
-		switch (sa->sa.sa_family) {
-		case AF_INET:
-			return inet_ntop(AF_INET, &sa->sin.sin_addr,
-					 buf, buflen);
-		case AF_INET6:
-			return inet_ntop(AF_INET6, &sa->sin6.sin6_addr,
-					 buf, buflen);
-		}
-
-		/* fallthrough */
-	}
 	default:
 		return "???";
 	}
 }
 
-const char *rt_addr_n2a(int af, int len, const void *addr)
-{
-	static char buf[256];
-
-	return rt_addr_n2a_r(af, len, addr, buf, 256);
-}
-
 int read_family(const char *name)
 {
 	int family = AF_UNSPEC;
-
 	if (strcmp(name, "inet") == 0)
 		family = AF_INET;
 	else if (strcmp(name, "inet6") == 0)
 		family = AF_INET6;
+	else if (strcmp(name, "dnet") == 0)
+		family = AF_DECnet;
 	else if (strcmp(name, "link") == 0)
 		family = AF_PACKET;
 	else if (strcmp(name, "ipx") == 0)
@@ -1035,6 +755,8 @@
 		return "inet";
 	if (family == AF_INET6)
 		return "inet6";
+	if (family == AF_DECnet)
+		return "dnet";
 	if (family == AF_PACKET)
 		return "link";
 	if (family == AF_IPX)
@@ -1047,7 +769,8 @@
 }
 
 #ifdef RESOLVE_HOSTNAMES
-struct namerec {
+struct namerec
+{
 	struct namerec *next;
 	const char *name;
 	inet_prefix addr;
@@ -1060,12 +783,12 @@
 {
 	struct namerec *n;
 	struct hostent *h_ent;
-	unsigned int hash;
+	unsigned hash;
 	static int notfirst;
 
 
-	if (af == AF_INET6 && ((__u32 *)addr)[0] == 0 &&
-	    ((__u32 *)addr)[1] == 0 && ((__u32 *)addr)[2] == htonl(0xffff)) {
+	if (af == AF_INET6 && ((__u32*)addr)[0] == 0 &&
+	    ((__u32*)addr)[1] == 0 && ((__u32*)addr)[2] == htonl(0xffff)) {
 		af = AF_INET;
 		addr += 12;
 		len = 4;
@@ -1079,8 +802,7 @@
 		    memcmp(n->addr.data, addr, len) == 0)
 			return n->name;
 	}
-	n = malloc(sizeof(*n));
-	if (n == NULL)
+	if ((n = malloc(sizeof(*n))) == NULL)
 		return NULL;
 	n->addr.family = af;
 	n->addr.bytelen = len;
@@ -1092,8 +814,7 @@
 		sethostent(1);
 	fflush(stdout);
 
-	h_ent = gethostbyaddr(addr, len, af);
-	if (h_ent != NULL)
+	if ((h_ent = gethostbyaddr(addr, len, af)) != NULL)
 		n->name = strdup(h_ent->h_name);
 
 	/* Even if we fail, "negative" entry is remembered. */
@@ -1101,7 +822,7 @@
 }
 #endif
 
-const char *format_host_r(int af, int len, const void *addr,
+const char *format_host(int af, int len, const void *addr,
 			char *buf, int buflen)
 {
 #ifdef RESOLVE_HOSTNAMES
@@ -1115,14 +836,7 @@
 			return n;
 	}
 #endif
-	return rt_addr_n2a_r(af, len, addr, buf, buflen);
-}
-
-const char *format_host(int af, int len, const void *addr)
-{
-	static char buf[256];
-
-	return format_host_r(af, len, addr, buf, 256);
+	return rt_addr_n2a(af, len, addr, buf, buflen);
 }
 
 
@@ -1131,7 +845,7 @@
 	char *ptr = buf;
 	int i;
 
-	for (i = 0; i < len; i++) {
+	for (i=0; i<len; i++) {
 		if (blen < 3)
 			break;
 		sprintf(ptr, "%02x", str[i]);
@@ -1141,9 +855,9 @@
 	return buf;
 }
 
-__u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len)
+__u8* hexstring_a2n(const char *str, __u8 *buf, int blen)
 {
-	unsigned int cnt = 0;
+	int cnt = 0;
 	char *endptr;
 
 	if (strlen(str) % 2)
@@ -1154,42 +868,15 @@
 
 		strncpy(tmpstr, str, 2);
 		tmpstr[2] = '\0';
-		errno = 0;
 		tmp = strtoul(tmpstr, &endptr, 16);
 		if (errno != 0 || tmp > 0xFF || *endptr != '\0')
 			return NULL;
 		buf[cnt++] = tmp;
 		str += 2;
 	}
-
-	if (len)
-		*len = cnt;
-
 	return buf;
 }
 
-int hex2mem(const char *buf, uint8_t *mem, int count)
-{
-	int i, j;
-	int c;
-
-	for (i = 0, j = 0; i < count; i++, j += 2) {
-		c = get_hex(buf[j]);
-		if (c < 0)
-			return -1;
-
-		mem[i] = c << 4;
-
-		c = get_hex(buf[j + 1]);
-		if (c < 0)
-			return -1;
-
-		mem[i] |= c;
-	}
-
-	return 0;
-}
-
 int addr64_n2a(__u64 addr, char *buff, size_t len)
 {
 	__u16 *words = (__u16 *)&addr;
@@ -1214,20 +901,6 @@
 	return written;
 }
 
-/* Print buffer and escape bytes that are !isprint or among 'escape' */
-void print_escape_buf(const __u8 *buf, size_t len, const char *escape)
-{
-	size_t i;
-
-	for (i = 0; i < len; ++i) {
-		if (isprint(buf[i]) && buf[i] != '\\' &&
-		    !strchr(escape, buf[i]))
-			printf("%c", buf[i]);
-		else
-			printf("\\%03o", buf[i]);
-	}
-}
-
 int print_timestamp(FILE *fp)
 {
 	struct timeval tv;
@@ -1252,54 +925,6 @@
 	return 0;
 }
 
-unsigned int print_name_and_link(const char *fmt,
-				 const char *name, struct rtattr *tb[])
-{
-	const char *link = NULL;
-	unsigned int m_flag = 0;
-	SPRINT_BUF(b1);
-
-	if (tb[IFLA_LINK]) {
-		int iflink = rta_getattr_u32(tb[IFLA_LINK]);
-
-		if (iflink) {
-			if (tb[IFLA_LINK_NETNSID]) {
-				if (is_json_context()) {
-					print_int(PRINT_JSON,
-						  "link_index", NULL, iflink);
-				} else {
-					link = ll_idx_n2a(iflink);
-				}
-			} else {
-				link = ll_index_to_name(iflink);
-
-				if (is_json_context()) {
-					print_string(PRINT_JSON,
-						     "link", NULL, link);
-					link = NULL;
-				}
-
-				m_flag = ll_index_to_flags(iflink);
-				m_flag = !(m_flag & IFF_UP);
-			}
-		} else {
-			if (is_json_context())
-				print_null(PRINT_JSON, "link", NULL, NULL);
-			else
-				link = "NONE";
-		}
-
-		if (link) {
-			snprintf(b1, sizeof(b1), "%s@%s", name, link);
-			name = b1;
-		}
-	}
-
-	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt, name);
-
-	return m_flag;
-}
-
 int cmdlineno;
 
 /* Like glibc getline but handle continuation lines and comments */
@@ -1308,8 +933,7 @@
 	ssize_t cc;
 	char *cp;
 
-	cc = getline(linep, lenp, in);
-	if (cc < 0)
+	if ((cc = getline(linep, lenp, in)) < 0)
 		return cc;	/* eof or error */
 	++cmdlineno;
 
@@ -1322,8 +946,7 @@
 		size_t len1 = 0;
 		ssize_t cc1;
 
-		cc1 = getline(&line1, &len1, in);
-		if (cc1 < 0) {
+		if ((cc1 = getline(&line1, &len1, in)) < 0) {
 			fprintf(stderr, "Missing continuation line\n");
 			return cc1;
 		}
@@ -1353,16 +976,10 @@
 int makeargs(char *line, char *argv[], int maxargs)
 {
 	static const char ws[] = " \t\r\n";
-	char *cp = line;
+	char *cp;
 	int argc = 0;
 
-	while (*cp) {
-		/* skip leading whitespace */
-		cp += strspn(cp, ws);
-
-		if (*cp == '\0')
-			break;
-
+	for (cp = line + strspn(line, ws); *cp; cp += strspn(cp, ws)) {
 		if (argc >= (maxargs - 1)) {
 			fprintf(stderr, "Too many arguments to command\n");
 			exit(1);
@@ -1379,16 +996,13 @@
 				fprintf(stderr, "Unterminated quoted string\n");
 				exit(1);
 			}
-		} else {
-			argv[argc++] = cp;
-
-			/* find end of word */
-			cp += strcspn(cp, ws);
-			if (*cp == '\0')
-				break;
+			*cp++ = 0;
+			continue;
 		}
 
-		/* separate words */
+		argv[argc++] = cp;
+		/* find end of word */
+		cp += strcspn(cp, ws);
 		*cp++ = 0;
 	}
 	argv[argc] = NULL;
@@ -1396,293 +1010,53 @@
 	return argc;
 }
 
+int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
+{
+	if (strchr(src, ':'))
+		return inet_pton(AF_INET6, src, dst6);
+	else
+		return inet_pton(AF_INET, src, dst);
+}
+
 void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n)
 {
 	char *tstr;
-	time_t secs = ((__u32 *)NLMSG_DATA(n))[0];
-	long usecs = ((__u32 *)NLMSG_DATA(n))[1];
-
+	time_t secs = ((__u32*)NLMSG_DATA(n))[0];
+	long usecs = ((__u32*)NLMSG_DATA(n))[1];
 	tstr = asctime(localtime(&secs));
 	tstr[strlen(tstr)-1] = 0;
 	fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
 }
 
+static int on_netns(char *nsname, void *arg)
+{
+	struct netns_func *f = arg;
+
+	if (netns_switch(nsname))
+		return -1;
+
+	return f->func(nsname, f->arg);
+}
+
+static int on_netns_label(char *nsname, void *arg)
+{
+	printf("\nnetns: %s\n", nsname);
+	return on_netns(nsname, arg);
+}
+
+int do_each_netns(int (*func)(char *nsname, void *arg), void *arg,
+		bool show_label)
+{
+	struct netns_func nsf = { .func = func, .arg = arg };
+
+	if (show_label)
+		return netns_foreach(on_netns_label, &nsf);
+
+	return netns_foreach(on_netns, &nsf);
+}
+
 char *int_to_str(int val, char *buf)
 {
 	sprintf(buf, "%d", val);
 	return buf;
 }
-
-int get_guid(__u64 *guid, const char *arg)
-{
-	unsigned long tmp;
-	char *endptr;
-	int i;
-
-#define GUID_STR_LEN 23
-	/* Verify strict format: format string must be
-	 * xx:xx:xx:xx:xx:xx:xx:xx where xx can be an arbitrary
-	 * hex digit
-	 */
-
-	if (strlen(arg) != GUID_STR_LEN)
-		return -1;
-
-	/* make sure columns are in place */
-	for (i = 0; i < 7; i++)
-		if (arg[2 + i * 3] != ':')
-			return -1;
-
-	*guid = 0;
-	for (i = 0; i < 8; i++) {
-		tmp = strtoul(arg + i * 3, &endptr, 16);
-		if (endptr != arg + i * 3 + 2)
-			return -1;
-
-		if (tmp > 255)
-			return -1;
-
-		 *guid |= tmp << (56 - 8 * i);
-	}
-
-	return 0;
-}
-
-/* This is a necessary workaround for multicast route dumps */
-int get_real_family(int rtm_type, int rtm_family)
-{
-	if (rtm_type != RTN_MULTICAST)
-		return rtm_family;
-
-	if (rtm_family == RTNL_FAMILY_IPMR)
-		return AF_INET;
-
-	if (rtm_family == RTNL_FAMILY_IP6MR)
-		return AF_INET6;
-
-	return rtm_family;
-}
-
-/* Based on copy_rtnl_link_stats() from kernel at net/core/rtnetlink.c */
-static void copy_rtnl_link_stats64(struct rtnl_link_stats64 *stats64,
-				   const struct rtnl_link_stats *stats)
-{
-	__u64 *a = (__u64 *)stats64;
-	const __u32 *b = (const __u32 *)stats;
-	const __u32 *e = b + sizeof(*stats) / sizeof(*b);
-
-	while (b < e)
-		*a++ = *b++;
-}
-
-#define IPSTATS_MIB_MAX_LEN	(__IPSTATS_MIB_MAX * sizeof(__u64))
-static void get_snmp_counters(struct rtnl_link_stats64 *stats64,
-			      struct rtattr *s)
-{
-	__u64 *mib = (__u64 *)RTA_DATA(s);
-
-	memset(stats64, 0, sizeof(*stats64));
-
-	stats64->rx_packets = mib[IPSTATS_MIB_INPKTS];
-	stats64->rx_bytes = mib[IPSTATS_MIB_INOCTETS];
-	stats64->tx_packets = mib[IPSTATS_MIB_OUTPKTS];
-	stats64->tx_bytes = mib[IPSTATS_MIB_OUTOCTETS];
-	stats64->rx_errors = mib[IPSTATS_MIB_INDISCARDS];
-	stats64->tx_errors = mib[IPSTATS_MIB_OUTDISCARDS];
-	stats64->multicast = mib[IPSTATS_MIB_INMCASTPKTS];
-	stats64->rx_frame_errors = mib[IPSTATS_MIB_CSUMERRORS];
-}
-
-int get_rtnl_link_stats_rta(struct rtnl_link_stats64 *stats64,
-			    struct rtattr *tb[])
-{
-	struct rtnl_link_stats stats;
-	void *s;
-	struct rtattr *rta;
-	int size, len;
-
-	if (tb[IFLA_STATS64]) {
-		rta = tb[IFLA_STATS64];
-		size = sizeof(struct rtnl_link_stats64);
-		s = stats64;
-	} else if (tb[IFLA_STATS]) {
-		rta = tb[IFLA_STATS];
-		size = sizeof(struct rtnl_link_stats);
-		s = &stats;
-	} else if (tb[IFLA_PROTINFO]) {
-		struct rtattr *ptb[IPSTATS_MIB_MAX_LEN + 1];
-
-		parse_rtattr_nested(ptb, IPSTATS_MIB_MAX_LEN,
-				    tb[IFLA_PROTINFO]);
-		if (ptb[IFLA_INET6_STATS])
-			get_snmp_counters(stats64, ptb[IFLA_INET6_STATS]);
-		return sizeof(*stats64);
-	} else {
-		return -1;
-	}
-
-	len = RTA_PAYLOAD(rta);
-	if (len < size)
-		memset(s + len, 0, size - len);
-	else
-		len = size;
-
-	memcpy(s, RTA_DATA(rta), len);
-
-	if (s != stats64)
-		copy_rtnl_link_stats64(stats64, s);
-	return size;
-}
-
-#ifdef NEED_STRLCPY
-size_t strlcpy(char *dst, const char *src, size_t size)
-{
-	size_t srclen = strlen(src);
-
-	if (size) {
-		size_t minlen = min(srclen, size - 1);
-
-		memcpy(dst, src, minlen);
-		dst[minlen] = '\0';
-	}
-	return srclen;
-}
-
-size_t strlcat(char *dst, const char *src, size_t size)
-{
-	size_t dlen = strlen(dst);
-
-	if (dlen >= size)
-		return dlen + strlen(src);
-
-	return dlen + strlcpy(dst + dlen, src, size - dlen);
-}
-#endif
-
-void drop_cap(void)
-{
-#ifdef HAVE_LIBCAP
-	/* don't harmstring root/sudo */
-	if (getuid() != 0 && geteuid() != 0) {
-		cap_t capabilities;
-		cap_value_t net_admin = CAP_NET_ADMIN;
-		cap_flag_t inheritable = CAP_INHERITABLE;
-		cap_flag_value_t is_set;
-
-		capabilities = cap_get_proc();
-		if (!capabilities)
-			exit(EXIT_FAILURE);
-		if (cap_get_flag(capabilities, net_admin, inheritable,
-		    &is_set) != 0)
-			exit(EXIT_FAILURE);
-		/* apps with ambient caps can fork and call ip */
-		if (is_set == CAP_CLEAR) {
-			if (cap_clear(capabilities) != 0)
-				exit(EXIT_FAILURE);
-			if (cap_set_proc(capabilities) != 0)
-				exit(EXIT_FAILURE);
-		}
-		cap_free(capabilities);
-	}
-#endif
-}
-
-int get_time(unsigned int *time, const char *str)
-{
-	double t;
-	char *p;
-
-	t = strtod(str, &p);
-	if (p == str)
-		return -1;
-
-	if (*p) {
-		if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec") == 0 ||
-		    strcasecmp(p, "secs") == 0)
-			t *= TIME_UNITS_PER_SEC;
-		else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec") == 0 ||
-			 strcasecmp(p, "msecs") == 0)
-			t *= TIME_UNITS_PER_SEC/1000;
-		else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec") == 0 ||
-			 strcasecmp(p, "usecs") == 0)
-			t *= TIME_UNITS_PER_SEC/1000000;
-		else
-			return -1;
-	}
-
-	*time = t;
-	return 0;
-}
-
-static void print_time(char *buf, int len, __u32 time)
-{
-	double tmp = time;
-
-	if (tmp >= TIME_UNITS_PER_SEC)
-		snprintf(buf, len, "%.1fs", tmp/TIME_UNITS_PER_SEC);
-	else if (tmp >= TIME_UNITS_PER_SEC/1000)
-		snprintf(buf, len, "%.1fms", tmp/(TIME_UNITS_PER_SEC/1000));
-	else
-		snprintf(buf, len, "%uus", time);
-}
-
-char *sprint_time(__u32 time, char *buf)
-{
-	print_time(buf, SPRINT_BSIZE-1, time);
-	return buf;
-}
-
-/* 64 bit times are represented internally in nanoseconds */
-int get_time64(__s64 *time, const char *str)
-{
-	double nsec;
-	char *p;
-
-	nsec = strtod(str, &p);
-	if (p == str)
-		return -1;
-
-	if (*p) {
-		if (strcasecmp(p, "s") == 0 ||
-		    strcasecmp(p, "sec") == 0 ||
-		    strcasecmp(p, "secs") == 0)
-			nsec *= NSEC_PER_SEC;
-		else if (strcasecmp(p, "ms") == 0 ||
-			 strcasecmp(p, "msec") == 0 ||
-			 strcasecmp(p, "msecs") == 0)
-			nsec *= NSEC_PER_MSEC;
-		else if (strcasecmp(p, "us") == 0 ||
-			 strcasecmp(p, "usec") == 0 ||
-			 strcasecmp(p, "usecs") == 0)
-			nsec *= NSEC_PER_USEC;
-		else if (strcasecmp(p, "ns") == 0 ||
-			 strcasecmp(p, "nsec") == 0 ||
-			 strcasecmp(p, "nsecs") == 0)
-			nsec *= 1;
-		else
-			return -1;
-	}
-
-	*time = nsec;
-	return 0;
-}
-
-static void print_time64(char *buf, int len, __s64 time)
-{
-	double nsec = time;
-
-	if (time >= NSEC_PER_SEC)
-		snprintf(buf, len, "%.3fs", nsec/NSEC_PER_SEC);
-	else if (time >= NSEC_PER_MSEC)
-		snprintf(buf, len, "%.3fms", nsec/NSEC_PER_MSEC);
-	else if (time >= NSEC_PER_USEC)
-		snprintf(buf, len, "%.3fus", nsec/NSEC_PER_USEC);
-	else
-		snprintf(buf, len, "%lldns", time);
-}
-
-char *sprint_time64(__s64 time, char *buf)
-{
-	print_time64(buf, SPRINT_BSIZE-1, time);
-	return buf;
-}
diff --git a/man/Makefile b/man/Makefile
index 0c759dd..749faa1 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -1,20 +1,14 @@
-# SPDX-License-Identifier: GPL-2.0
 INSTALL=install
 INSTALLDIR=install -m 0755 -d
 INSTALLMAN=install -m 0644
-# Pass the same parameters as Lintian uses on Debian.
-MAN_CHECK=LC_ALL=en_US.UTF-8 MANROFFSEQ='' MANWIDTH=80 man --warnings \
-	--encoding=UTF-8 --local-file --troff-device=utf8 --ditroff
-# Hide man output, count and print errors.
-MAN_REDIRECT=2>&1 >/dev/null | tee /dev/fd/2 | wc -l
 
 SUBDIRS = man3 man7 man8
 
-all clean install check:
+all clean install:
 	@for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir $@ || exit $$?; done
 
 distclean: clean
 
-.PHONY: install clean distclean check
+.PHONY: install clean distclean
 
 .EXPORT_ALL_VARIABLES:
diff --git a/man/man3/Makefile b/man/man3/Makefile
index 1732be2..bf55658 100644
--- a/man/man3/Makefile
+++ b/man/man3/Makefile
@@ -1,5 +1,4 @@
-# SPDX-License-Identifier: GPL-2.0
-MAN3PAGES = $(wildcard *.3)
+MAN3PAGES=libnetlink.3
 
 all:
 
@@ -11,8 +10,4 @@
 	$(INSTALLDIR) $(DESTDIR)$(MANDIR)/man3
 	$(INSTALLMAN) $(MAN3PAGES) $(DESTDIR)$(MANDIR)/man3
 
-check:
-	@for page in $(MAN3PAGES); do test 0 -eq $$($(MAN_CHECK) $$page \
-		$(MAN_REDIRECT)) || { echo "Error in $$page"; exit 1; }; done
-
-.PHONY: install clean distclean check
+.PHONY: install clean distclean
diff --git a/man/man3/libnetlink.3 b/man/man3/libnetlink.3
index 8e3dc62..99be9cc 100644
--- a/man/man3/libnetlink.3
+++ b/man/man3/libnetlink.3
@@ -32,12 +32,12 @@
 .br
 	      void *jarg)
 .sp
-int rtnl_listen(struct rtnl_handle *rtnl,
+int rtnl_listen(struct rtnl_handle *rtnl, 
 	      int (*handler)(struct sockaddr_nl *, struct rtnl_ctrl_data *,
 			     struct nlmsghdr *n, void *),
 	      void *jarg)
 .sp
-int rtnl_from_file(FILE *rtnl,
+int rtnl_from_file(FILE *rtnl, 
 	      int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
 	      void *jarg)
 .sp
@@ -49,35 +49,35 @@
 .sp
 int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
 .SH DESCRIPTION
-libnetlink provides a higher level interface to
-.BR rtnetlink(7).
+libnetlink provides a higher level interface to 
+.BR rtnetlink(7). 
 The read functions return 0 on success and a negative errno on failure.
 The send functions return the amount of data sent, or -1 on error.
-.TP
+.TP 
 rtnl_open
 Open a rtnetlink socket and save the state into the
 .B rth
-handle. This handle is passed to all subsequent calls.
+handle. This handle is passed to all subsequent calls. 
 .B subscriptions
 is a bitmap of the rtnetlink multicast groups the socket will be
 a member of.
 
 .TP
 rtnl_wilddump_request
-Request a full dump of the
+Request a full dump of the 
 .B type
 database for
 .B family
 addresses.
 .B type
-is a rtnetlink message type.
+is a rtnetlink message type. 
 .\" XXX
 
 .TP
 rtnl_dump_request
-Request a full dump of the
-.B type
-data buffer into
+Request a full dump of the 
+.B type 
+data buffer into 
 .B buf
 with maximum length of
 .B len.
@@ -91,12 +91,12 @@
 .B filter
 callback checks if the received message is wanted. It gets the source
 address of the message, the message itself and
-.B arg1
+.B arg1 
 as arguments. 0 as return means that the filter passed, a negative
 value is returned
 by
-.I rtnl_dump_filter
-in case of error. NULL for
+.I rtnl_dump_filter 
+in case of error. NULL for 
 .I filter
 means to not use a filter.
 .B junk
@@ -106,7 +106,7 @@
 
 .TP
 rtnl_listen
-Receive netlink data after a request and pass it to
+Receive netlink data after a request and pass it to 
 .I handler.
 .B handler
 is a callback that gets the message source address, anscillary data, the message
@@ -118,8 +118,8 @@
 
 .TP
 rtnl_from_file
-Works like
-.I rtnl_listen,
+Works like 
+.I rtnl_listen, 
 but reads a netlink message bundle from the file
 .B file
 and passes the messages to
@@ -134,7 +134,7 @@
 .BR netlink(3)
 on how to generate a rtnetlink message. The following utility functions
 require a continuous buffer that already contains a netlink message header
-and a rtnetlink request.
+and a rtnetlink request. 
 
 .TP
 rtnl_send
@@ -168,7 +168,7 @@
 .B n,
 which is part of a buffer of length
 .B maxlen.
-.B data
+.B data 
 is copied.
 
 .TP
diff --git a/man/man7/Makefile b/man/man7/Makefile
index c0e545a..ccfd839 100644
--- a/man/man7/Makefile
+++ b/man/man7/Makefile
@@ -1,5 +1,4 @@
-# SPDX-License-Identifier: GPL-2.0
-MAN7PAGES = $(wildcard *.7)
+MAN7PAGES = tc-hfsc.7
 
 all:
 
@@ -11,8 +10,4 @@
 	$(INSTALLDIR) $(DESTDIR)$(MANDIR)/man7
 	$(INSTALLMAN) $(MAN7PAGES) $(DESTDIR)$(MANDIR)/man7
 
-check:
-	@for page in $(MAN7PAGES); do test 0 -eq $$($(MAN_CHECK) $$page \
-		$(MAN_REDIRECT)) || { echo "Error in $$page"; exit 1; }; done
-
-.PHONY: install clean distclean check
+.PHONY: install clean distclean
diff --git a/man/man7/tc-hfsc.7 b/man/man7/tc-hfsc.7
index 5ae5e6b..ca04961 100644
--- a/man/man7/tc-hfsc.7
+++ b/man/man7/tc-hfsc.7
@@ -555,8 +555,8 @@
 .
 \fBtc\fR(8), \fBtc\-hfsc\fR(8), \fBtc\-stab\fR(8)
 
-Please direct bugreports and patches to: <netdev@vger.kernel.org>
+Please direct bugreports and patches to: <net...@vger.kernel.org>
 .
 .SH "AUTHOR"
 .
-Manpage created by Michal Soltys (soltys@ziu.info)
+Manpage created by Michal Soltys (sol...@ziu.info)
diff --git a/man/man8/.gitignore b/man/man8/.gitignore
index 0c3d150..4f1a476 100644
--- a/man/man8/.gitignore
+++ b/man/man8/.gitignore
@@ -2,3 +2,4 @@
 ip-address.8
 ip-link.8
 ip-route.8
+
diff --git a/man/man8/Makefile b/man/man8/Makefile
index 0269e17..2f77640 100644
--- a/man/man8/Makefile
+++ b/man/man8/Makefile
@@ -1,7 +1,20 @@
-# SPDX-License-Identifier: GPL-2.0
 TARGETS = ip-address.8 ip-link.8 ip-route.8
 
-MAN8PAGES = $(TARGETS) $(filter-out $(TARGETS),$(wildcard *.8))
+MAN8PAGES = $(TARGETS) ip.8 arpd.8 lnstat.8 routel.8 rtacct.8 rtmon.8 rtpr.8 ss.8 \
+	tc.8 tc-bfifo.8 tc-bpf.8 tc-cbq.8 tc-cbq-details.8 tc-choke.8 tc-codel.8 \
+	tc-fq.8 \
+	tc-drr.8 tc-ematch.8 tc-fq_codel.8 tc-hfsc.8 tc-htb.8 tc-pie.8 \
+	tc-mqprio.8 tc-netem.8 tc-pfifo.8 tc-pfifo_fast.8 tc-prio.8 tc-red.8 \
+	tc-sfb.8 tc-sfq.8 tc-stab.8 tc-tbf.8 \
+	bridge.8 rtstat.8 ctstat.8 nstat.8 routef.8 \
+	ip-addrlabel.8 ip-fou.8 ip-gue.8 ip-l2tp.8 \
+	ip-maddress.8 ip-monitor.8 ip-mroute.8 ip-neighbour.8 \
+	ip-netns.8 ip-ntable.8 ip-rule.8 ip-tunnel.8 ip-xfrm.8 \
+	ip-tcp_metrics.8 ip-netconf.8 ip-token.8 \
+	tipc.8 tipc-bearer.8 tipc-link.8 tipc-media.8 tipc-nametable.8 \
+	tipc-node.8 tipc-socket.8 \
+	tc-basic.8 tc-cgroup.8 tc-flow.8 tc-flower.8 tc-fw.8 tc-route.8 \
+	tc-tcindex.8 tc-u32.8
 
 all: $(TARGETS)
 
@@ -23,8 +36,4 @@
 	$(INSTALLDIR) $(DESTDIR)$(MANDIR)/man8
 	$(INSTALLMAN) $(MAN8PAGES) $(DESTDIR)$(MANDIR)/man8
 
-check: all
-	@for page in $(MAN8PAGES); do test 0 -eq $$($(MAN_CHECK) $$page \
-		$(MAN_REDIRECT)) || { echo "Error in $$page"; exit 1; }; done
-
-.PHONY: install clean distclean check
+.PHONY: install clean distclean
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index bb4fb52..0ec6f17 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -20,12 +20,8 @@
 .IR OPTIONS " := { "
 \fB\-V\fR[\fIersion\fR] |
 \fB\-s\fR[\fItatistics\fR] |
-\fB\-n\fR[\fIetns\fR] name |
-\fB\-b\fR[\fIatch\fR] filename |
-\fB\-c\fR[\folor\fR] |
-\fB\-p\fR[\fIretty\fR] |
-\fB\-j\fR[\fIson\fR] |
-\fB\-o\fR[\fIneline\fr] }
+\fB\-n\fR[\fIetns\fR] name }
+\fB\-b\fR[\fIatch\fR] filename }
 
 .ti -8
 .BR "bridge link set"
@@ -37,7 +33,7 @@
 .B priority
 .IR PRIO " ] [ "
 .B state
-.IR STATE " ] [ "
+.IR STATE "] ["
 .BR guard " { " on " | " off " } ] [ "
 .BR hairpin " { " on " | " off " } ] [ "
 .BR fastleave " { " on " | " off " } ] [ "
@@ -46,15 +42,7 @@
 .BR learning_sync " { " on " | " off " } ] [ "
 .BR flood " { " on " | " off " } ] [ "
 .BR hwmode " { " vepa " | " veb " } ] [ "
-.BR mcast_flood " { " on " | " off " } ] [ "
-.BR mcast_to_unicast " { " on " | " off " } ] [ "
-.BR neigh_suppress " { " on " | " off " } ] [ "
-.BR vlan_tunnel " { " on " | " off " } ] [ "
-.BR isolated " { " on " | " off " } ] [ "
-.B backup_port
-.IR  DEVICE " ] ["
-.BR nobackup_port " ] [ "
-.BR self " ] [ " master " ]"
+.BR self " ] [ " master " ] "
 
 .ti -8
 .BR "bridge link" " [ " show " ] [ "
@@ -66,12 +54,10 @@
 .I LLADDR
 .B dev
 .IR DEV " { "
-.BR local " | " static " | " dynamic " } [ "
-.BR self " ] [ " master " ] [ " router " ] [ " use " ] [ " extern_learn " ] [ " sticky " ] [ "
+.BR local " | " temp " } [ "
+.BR self " ] [ " master " ] [ " router " ] [ " use " ] [ "
 .B dst
 .IR IPADDR " ] [ "
-.B src_vni
-.IR SRC_VNI " ] ["
 .B vni
 .IR VNI " ] ["
 .B port
@@ -82,15 +68,7 @@
 .ti -8
 .BR "bridge fdb" " [ " show " ] [ "
 .B dev
-.IR DEV " ] [ "
-.B br
-.IR BRDEV " ] [ "
-.B brport
-.IR DEV " ] [ "
-.B vlan
-.IR VID " ] [ "
-.B state
-.IR STATE " ]"
+.IR DEV " ]"
 
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
@@ -115,13 +93,11 @@
 .IR DEV
 .B vid
 .IR VID " [ "
-.BR tunnel_info
-.IR TUNNEL_ID " ] [ "
 .BR pvid " ] [ " untagged " ] [ "
 .BR self " ] [ " master " ] "
 
 .ti -8
-.BR "bridge vlan" " [ " show " | " tunnelshow " ] [ "
+.BR "bridge vlan" " [ " show " ] [ "
 .B dev
 .IR DEV " ]"
 
@@ -143,10 +119,6 @@
 As a rule, the information is statistics or some time values.
 
 .TP
-.BR "\-d" , " \-details"
-print detailed information about MDB router ports.
-
-.TP
 .BR "\-n" , " \-net" , " \-netns " <NETNS>
 switches
 .B bridge
@@ -177,40 +149,6 @@
 If there were any errors during execution of the commands, the application
 return code will be non zero.
 
-.TP
-.BR \-c [ color ][ = { always | auto | never }
-Configure color output. If parameter is omitted or
-.BR always ,
-color output is enabled regardless of stdout state. If parameter is
-.BR auto ,
-stdout is checked to be a terminal before enabling color output. If parameter is
-.BR never ,
-color output is disabled. If specified multiple times, the last one takes
-precedence. This flag is ignored if
-.B \-json
-is also given.
-
-.TP
-.BR "\-j", " \-json"
-Output results in JavaScript Object Notation (JSON).
-
-.TP
-.BR "\-p", " \-pretty"
-When combined with -j generate a pretty JSON output.
-
-.TP
-.BR "\-o", " \-oneline"
-output each record on a single line, replacing line feeds
-with the
-.B '\e'
-character. This is convenient when you want to count records
-with
-.BR wc (1)
-or to
-.BR grep (1)
-the output.
-
-
 .SH BRIDGE - COMMAND SYNTAX
 
 .SS
@@ -292,8 +230,8 @@
 .sp
 
 .B 1
-- STP LISTENING state. Only valid if STP is enabled on the bridge. In this
-state the port listens for STP BPDUs and drops all other traffic frames.
+- STP LISTENING state. Only valid if STP is enabled on the brige. In this
+state the port for list for STP BPDUs and drop all other traffic.
 .sp
 
 .B 2
@@ -314,7 +252,7 @@
 
 .TP
 .BR "guard on " or " guard off "
-Controls whether STP BPDUs will be processed by the bridge port. By default,
+Controls whether STP BPUDs will be processed by the bridge port. By default,
 the flag is turned off allowed BPDU processing. Turning this flag on will
 cause the port to stop processing STP BPDUs.
 
@@ -347,7 +285,7 @@
 bridge FDB.
 
 .TP
-.BR "flood on " or " flood off "
+.BR "flooding on " or " flooding off "
 Controls whether a given port will flood unicast traffic for which there is no FDB entry. By default this flag is on.
 
 .TP
@@ -363,41 +301,6 @@
 - bridging happens in hardware.
 
 .TP
-.BR "mcast_flood on " or " mcast_flood off "
-Controls whether a given port will flood multicast traffic for which
-there is no MDB entry. By default this flag is on.
-
-.TP
-.BR "mcast_to_unicast on " or " mcast_to_unicast off "
-Controls whether a given port will replicate packets using unicast
-instead of multicast. By default this flag is off.
-
-.TP
-.BR "neigh_suppress on " or " neigh_suppress off "
-Controls whether neigh discovery (arp and nd) proxy and suppression is
-enabled on the port. By default this flag is off.
-
-.TP
-.BR "vlan_tunnel on " or " vlan_tunnel off "
-Controls whether vlan to tunnel mapping is enabled on the port. By
-default this flag is off.
-
-.TP
-.BR "isolated on " or " isolated off "
-Controls whether a given port will be isolated, which means it will be
-able to communicate with non-isolated ports only.  By default this
-flag is off.
-
-.TP
-.BI backup_port " DEVICE"
-If the port loses carrier all traffic will be redirected to the
-configured backup port
-
-.TP
-.BR nobackup_port
-Removes the currently configured backup port
-
-.TP
 .BI self
 link setting is configured on specified physical device
 
@@ -435,18 +338,6 @@
 .BI dev " DEV"
 the interface to which this address is associated.
 
-.B local
-- is a local permanent fdb entry
-.sp
-
-.B static
-- is a static (no arp) fdb entry
-.sp
-
-.B dynamic
-- is a dynamic reachable age-able fdb entry
-.sp
-
 .B self
 - the address is associated with the port drivers fdb. Usually hardware.
 .sp
@@ -466,16 +357,6 @@
 indicate to the kernel that the fdb entry is in use.
 .sp
 
-.B extern_learn
-- this entry was learned externally. This option can be used to
-indicate to the kernel that an entry was hardware or user-space
-controller learnt dynamic entry. Kernel will not age such an entry.
-.sp
-
-.B sticky
-- this entry will not change its port due to learning.
-.sp
-
 .in -8
 The next command line parameters apply only
 when the specified device
@@ -487,13 +368,6 @@
 VXLAN tunnel endpoint where the Ethernet MAC ADDRESS resides.
 
 .TP
-.BI src_vni " SRC VNI"
-the src VNI Network Identifier (or VXLAN Segment ID)
-this entry belongs to. Used only when the vxlan device is in
-external or collect metadata mode. If omitted the value specified at
-vxlan device creation will be used.
-
-.TP
 .BI vni " VNI"
 the VXLAN VNI Network Identifier (or VXLAN Segment ID)
 to use to connect to the remote VXLAN tunnel endpoint.
@@ -617,11 +491,6 @@
 option, the command becomes verbose. It prints out the ports known to have
 a connected router.
 
-.PP
-With the
-.B -statistics
-option, the command displays timer values for mdb and router port entries.
-
 .SH bridge vlan - VLAN filter list
 
 .B vlan
@@ -644,12 +513,6 @@
 the VLAN ID that identifies the vlan.
 
 .TP
-.BI tunnel_info " TUNNEL_ID"
-the TUNNEL ID that maps to this vlan. The tunnel id is set in
-dst_metadata for every packet that belongs to this vlan (applicable to
-bridge ports with vlan_tunnel flag set).
-
-.TP
 .BI pvid
 the vlan specified is to be considered a PVID at ingress.
 Any untagged frames will be assigned to this VLAN.
@@ -667,8 +530,8 @@
 .BI master
 the vlan is configured on the software bridge (default).
 
-.SS bridge vlan delete - delete a vlan filter entry
-This command removes an existing vlan filter entry.
+.SS bridge vlan delete - delete a forwarding database entry
+This command removes an existing fdb entry.
 
 .PP
 The arguments are the same as with
@@ -681,15 +544,6 @@
 
 This command displays the current VLAN filter table.
 
-.PP
-With the
-.B -statistics
-option, the command displays per-vlan traffic statistics.
-
-.SS bridge vlan tunnelshow - list vlan tunnel mapping.
-
-This command displays the current vlan tunnel info mapping.
-
 .SH bridge monitor - state monitoring
 
 The
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
deleted file mode 100644
index 1021ee8..0000000
--- a/man/man8/devlink-dev.8
+++ /dev/null
@@ -1,267 +0,0 @@
-.TH DEVLINK\-DEV 8 "14 Mar 2016" "iproute2" "Linux"
-.SH NAME
-devlink-dev \- devlink device configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B dev
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-n\fR[\fIno-nice-names\fR] }
-
-.ti -8
-.B devlink dev show
-.RI "[ " DEV " ]"
-
-.ti -8
-.B devlink dev help
-
-.ti -8
-.BR "devlink dev eswitch set"
-.IR DEV
-.RI "[ "
-.BR mode " { " legacy " | " switchdev " } "
-.RI "]"
-.RI "[ "
-.BR inline-mode " { " none " | " link " | " network " | " transport " } "
-.RI "]"
-.RI "[ "
-.BR encap " { " disable " | " enable " } "
-.RI "]"
-
-.ti -8
-.BR "devlink dev eswitch show"
-.IR DEV
-
-.ti -8
-.BR "devlink dev param set"
-.IR DEV
-.BR name
-.IR PARAMETER
-.BR value
-.IR VALUE
-.BR cmode " { " runtime " | " driverinit " | " permanent " } "
-
-.ti -8
-.BR "devlink dev param show"
-.RI "[ "
-.IR DEV
-.BR name
-.IR PARAMETER
-.RI "]"
-
-.ti -8
-.BR "devlink dev reload"
-.IR DEV
-
-.ti -8
-.BR "devlink dev info"
-.RI "[ "
-.IR DEV
-.RI "]"
-
-.ti -8
-.BR "devlink dev flash"
-.IR DEV
-.BR file
-.IR PATH
-.RI "["
-.BR target
-.IR ID
-.RI "]"
-
-.SH "DESCRIPTION"
-.SS devlink dev show - display devlink device attributes
-
-.PP
-.I "DEV"
-- specifies the devlink device to show.
-If this argument is omitted all devices are listed.
-
-.in +4
-Format is:
-.in +2
-BUS_NAME/BUS_ADDRESS
-
-.SS devlink dev eswitch show - display devlink device eswitch attributes
-.SS devlink dev eswitch set  - sets devlink device eswitch attributes
-
-.TP
-.BR mode " { " legacy " | " switchdev " } "
-Set eswitch mode
-
-.I legacy
-- Legacy SRIOV
-
-.I switchdev
-- SRIOV switchdev offloads
-
-.TP
-.BR inline-mode " { " none " | " link " | " network " | " transport " } "
-Some HWs need the VF driver to put part of the packet headers on the TX descriptor so the e-switch can do proper matching and steering.
-
-.I none
-- None
-
-.I link
-- L2 mode
-
-.I network
-- L3 mode
-
-.I transport
-- L4 mode
-
-.TP
-.BR encap " { " disable " | " enable " } "
-Set eswitch encapsulation support
-
-.I disable
-- Disable encapsulation support
-
-.I enable
-- Enable encapsulation support
-
-.SS devlink dev param set  - set new value to devlink device configuration parameter
-
-.TP
-.BI name " PARAMETER"
-Specify parameter name to set.
-
-.TP
-.BI value " VALUE"
-New value to set.
-
-.TP
-.BR cmode " { " runtime " | " driverinit " | " permanent " } "
-Configuration mode in which the new value is set.
-
-.I runtime
-- Set new value while driver is running. This configuration mode doesn't require any reset to apply the new value.
-
-.I driverinit
-- Set new value which will be applied during driver initialization. This configuration mode requires restart driver by devlink reload command to apply the new value.
-
-.I permanent
-- New value is written to device's non-volatile memory. This configuration mode requires hard reset to apply the new value.
-
-.SS devlink dev param show - display devlink device supported configuration parameters attributes
-
-.BR name
-.IR PARAMETER
-Specify parameter name to show.
-If this argument is omitted all parameters supported by devlink devices are listed.
-
-.SS devlink dev reload - perform hot reload of the driver.
-
-.PP
-.I "DEV"
-- Specifies the devlink device to reload.
-
-.SS devlink dev info - display device information.
-Display device information provided by the driver. This command can be used
-to query versions of the hardware components or device components which
-can't be updated (
-.I fixed
-) as well as device firmware which can be updated. For firmware components
-.I running
-displays the versions of firmware currently loaded into the device, while
-.I stored
-reports the versions in device's flash.
-.I Running
-and
-.I stored
-versions may differ after flash has been updated, but before reboot.
-
-.PP
-.I "DEV"
-- specifies the devlink device to show.
-If this argument is omitted all devices are listed.
-
-.SS devlink dev flash - write device's non-volatile memory.
-
-.PP
-.I "DEV"
-- specifies the devlink device to write to.
-
-.BR file
-.I PATH
-- Path to the file which will be written into device's flash. The path needs
-to be relative to one of the directories searched by the kernel firmware loaded,
-such as /lib/firmware.
-
-.BR component
-.I NAME
-- If device stores multiple firmware images in non-volatile memory, this
-parameter may be used to indicate which firmware image should be written.
-The value of
-.I NAME
-should match the component names from
-.B "devlink dev info"
-and may be driver-dependent.
-
-.SH "EXAMPLES"
-.PP
-devlink dev show
-.RS 4
-Shows the state of all devlink devices on the system.
-.RE
-.PP
-devlink dev show pci/0000:01:00.0
-.RS 4
-Shows the state of specified devlink device.
-.RE
-.PP
-devlink dev eswitch show pci/0000:01:00.0
-.RS 4
-Shows the eswitch mode of specified devlink device.
-.RE
-.PP
-devlink dev eswitch set pci/0000:01:00.0 mode switchdev
-.RS 4
-Sets the eswitch mode of specified devlink device to switchdev.
-.RE
-.PP
-devlink dev param show pci/0000:01:00.0 name max_macs
-.RS 4
-Shows the parameter max_macs attributes.
-.RE
-.PP
-devlink dev param set pci/0000:01:00.0 name internal_error_reset value true cmode runtime
-.RS 4
-Sets the parameter internal_error_reset of specified devlink device to true.
-.RE
-.PP
-devlink dev reload pci/0000:01:00.0
-.RS 4
-Performs hot reload of specified devlink device.
-.RE
-.PP
-devlink dev flash pci/0000:01:00.0 file firmware.bin
-.RS 4
-Flashes the specified devlink device with provided firmware file name. If the driver supports it, user gets updates about the flash status. For example:
-.br
-Preparing to flash
-.br
-Flashing 100%
-.br
-Flashing done
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-port (8),
-.BR devlink-sb (8),
-.BR devlink-monitor (8),
-.br
-
-.SH AUTHOR
-Jiri Pirko <jiri@mellanox.com>
diff --git a/man/man8/devlink-health.8 b/man/man8/devlink-health.8
deleted file mode 100644
index 7ed0ae4..0000000
--- a/man/man8/devlink-health.8
+++ /dev/null
@@ -1,197 +0,0 @@
-.TH DEVLINK\-HEALTH 8 "20 Feb 2019" "iproute2" "Linux"
-.SH NAME
-devlink-health \- devlink health reporting and recovery
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B health
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] }
-
-.ti -8
-.BR "devlink health show"
-.RI "[ " DEV ""
-.B reporter
-.RI ""REPORTER " ] "
-
-.ti -8
-.BR "devlink health recover"
-.RI "" DEV ""
-.B reporter
-.RI "" REPORTER ""
-
-.ti -8
-.BR "devlink health diagnose"
-.RI "" DEV ""
-.B reporter
-.RI "" REPORTER ""
-
-.ti -8
-.BR "devlink health dump show"
-.RI "" DEV ""
-.B  reporter
-.RI "" REPORTER ""
-
-.ti -8
-.BR "devlink health dump clear"
-.RI "" DEV ""
-.B reporter
-.RI "" REPORTER ""
-
-.ti -8
-.BR "devlink health set"
-.RI "" DEV ""
-.B reporter
-.RI "" REPORTER ""
-.RI " { "
-.B grace_period | auto_recover
-.RI " } { "
-.RI "" msec ""
-.RI "|"
-.RI "" boolean ""
-.RI " } "
-.ti -8
-.B devlink health help
-
-.SH "DESCRIPTION"
-.SS devlink health show - Show status and configuration on all supported reporters on all devlink devices.
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.PP
-.I "REPORTER"
-- specifies the reporter's name registered on the devlink device.
-
-.SS devlink health recover - Initiate a recovery operation on a reporter.
-This action performs a recovery and increases the recoveries counter on success.
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.PP
-.I "REPORTER"
-- specifies the reporter's name registered on the devlink device.
-
-.SS devlink health diagnose - Retrieve diagnostics data on a reporter.
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.PP
-.I "REPORTER"
-- specifies the reporter's name registered on the devlink device.
-
-.SS devlink health dump show - Display the last saved dump.
-
-.PD 0
-.P
-devlink health saves a single dump per reporter. If an dump is
-.P
-not already stored by the Devlink, this command will generate a new
-.P
-dump. The dump can be generated either automatically when a
-.P
-reporter reports on an error or manually at the user's request.
-.PD
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.PP
-.I "REPORTER"
-- specifies the reporter's name registered on the devlink device.
-
-.SS devlink health dump clear - Delete the saved dump.
-Deleting the saved dump enables a generation of a new dump on
-.PD 0
-.P
-the next "devlink health dump show" command.
-.PD
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.PP
-.I "REPORTER"
-- specifies the reporter's name registered on the devlink device.
-
-.SS devlink health set - Enable the user to configure:
-.PD 0
-1) grace_period [msec] - Time interval between consecutive auto recoveries.
-.P
-2) auto_recover [true/false] - Indicates whether the devlink should execute automatic recover on error.
-.P
-Please note that this command is not supported on a reporter which
-doesn't support a recovery method.
-.PD
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.PP
-.I "REPORTER"
-- specifies the reporter's name registered on the devlink device.
-
-.SH "EXAMPLES"
-.PP
-devlink health show
-.RS 4
-List status and configuration of available reporters on devices.
-.RE
-.PP
-devlink health recover pci/0000:00:09.0 reporter tx
-.RS 4
-Initiate recovery on tx reporter registered on pci/0000:00:09.0.
-.RE
-.PP
-devlink health diagnose pci/0000:00:09.0 reporter tx
-.RS 4
-List diagnostics data on the specified device and reporter.
-.RE
-.PP
-devlink health dump show pci/0000:00:09.0 reporter tx
-.RS 4
-Display the last saved dump on the specified device and reporter.
-.RE
-.PP
-devlink health dump clear pci/0000:00:09.0 reporter tx
-.RS 4
-Delete saved dump on the specified device and reporter.
-.RE
-.PP
-devlink health set pci/0000:00:09.0 reporter tx grace_period 3500
-.RS 4
-Set time interval between auto recoveries to minimum of 3500 msec on
-the specified device and reporter.
-.RE
-.PP
-devlink health set pci/0000:00:09.0 reporter tx auto_recover false
-.RS 4
-Turn off auto recovery on the specified device and reporter.
-.RE
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-dev (8),
-.BR devlink-port (8),
-.BR devlink-param (8),
-.BR devlink-region (8),
-.br
-
-.SH AUTHOR
-Aya Levin <ayal@mellanox.com>
diff --git a/man/man8/devlink-monitor.8 b/man/man8/devlink-monitor.8
deleted file mode 100644
index fffab3a..0000000
--- a/man/man8/devlink-monitor.8
+++ /dev/null
@@ -1,38 +0,0 @@
-.TH DEVLINK\-MONITOR 8 "14 Mar 2016" "iproute2" "Linux"
-.SH "NAME"
-devlink-monitor \- state monitoring
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.BR "devlink monitor" " [ " all " |"
-.IR OBJECT-LIST " ]"
-.sp
-
-.SH DESCRIPTION
-The
-.B devlink
-utility can monitor the state of devlink devices and ports
-continuously. This option has a slightly different format. Namely, the
-.B monitor
-command is the first in the command line and then the object list.
-
-.I OBJECT-LIST
-is the list of object types that we want to monitor.
-It may contain
-.BR dev ", " port ", " trap ", " trap-group .
-
-.B devlink
-opens Devlink Netlink socket, listens on it and dumps state changes.
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-dev (8),
-.BR devlink-sb (8),
-.BR devlink-port (8),
-.BR devlink-trap (8),
-.br
-
-.SH AUTHOR
-Jiri Pirko <jiri@mellanox.com>
diff --git a/man/man8/devlink-port.8 b/man/man8/devlink-port.8
deleted file mode 100644
index a639d01..0000000
--- a/man/man8/devlink-port.8
+++ /dev/null
@@ -1,128 +0,0 @@
-.TH DEVLINK\-PORT 8 "14 Mar 2016" "iproute2" "Linux"
-.SH NAME
-devlink-port \- devlink port configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B port
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-n\fR[\fIno-nice-names\fR] }
-
-.ti -8
-.BR "devlink port set "
-.IR DEV/PORT_INDEX
-.RI "[ "
-.BR type " { " eth " | " ib " | " auto " }"
-.RI "]"
-
-.ti -8
-.BR "devlink port split "
-.IR DEV/PORT_INDEX
-.BR count
-.IR COUNT
-
-.ti -8
-.BR "devlink port unsplit "
-.IR DEV/PORT_INDEX
-
-.ti -8
-.B devlink port show
-.RI "[ " DEV/PORT_INDEX " ]"
-
-.ti -8
-.B devlink port help
-
-.SH "DESCRIPTION"
-.SS devlink port set - change devlink port attributes
-
-.PP
-.B "DEV/PORT_INDEX"
-- specifies the devlink port to operate on.
-
-.in +4
-Format is:
-.in +2
-BUS_NAME/BUS_ADDRESS/PORT_INDEX
-
-.TP
-.BR type " { " eth " | " ib " | " auto " } "
-set port type
-
-.I eth
-- Ethernet
-
-.I ib
-- Infiniband
-
-.I auto
-- autoselect
-
-.SS devlink port split - split devlink port into more
-
-.PP
-.B "DEV/PORT_INDEX"
-- specifies the devlink port to operate on.
-
-.TP
-.BI count " COUNT"
-number of ports to split to.
-
-.SS devlink port unsplit - unsplit previously split devlink port
-Could be performed on any split port of the same split group.
-
-.PP
-.B "DEV/PORT_INDEX"
-- specifies the devlink port to operate on.
-
-.SS devlink port show - display devlink port attributes
-
-.PP
-.I "DEV/PORT_INDEX"
-- specifies the devlink port to show.
-If this argument is omitted all ports are listed.
-
-.SH "EXAMPLES"
-.PP
-devlink port show
-.RS 4
-Shows the state of all devlink ports on the system.
-.RE
-.PP
-devlink port show pci/0000:01:00.0/1
-.RS 4
-Shows the state of specified devlink port.
-.RE
-.PP
-devlink port set pci/0000:01:00.0/1 type eth
-.RS 4
-Set type of specified devlink port to Ethernet.
-.RE
-.PP
-devlink port split pci/0000:01:00.0/1 count 4
-.RS 4
-Split the specified devlink port into four ports.
-.RE
-.PP
-devlink port unsplit pci/0000:01:00.0/1
-.RS 4
-Unplit the specified previously split devlink port.
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-dev (8),
-.BR devlink-sb (8),
-.BR devlink-monitor (8),
-.br
-
-.SH AUTHOR
-Jiri Pirko <jiri@mellanox.com>
diff --git a/man/man8/devlink-region.8 b/man/man8/devlink-region.8
deleted file mode 100644
index ff10cdb..0000000
--- a/man/man8/devlink-region.8
+++ /dev/null
@@ -1,131 +0,0 @@
-.TH DEVLINK\-REGION 8 "10 Jan 2018" "iproute2" "Linux"
-.SH NAME
-devlink-region \- devlink address region access
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B region
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-n\fR[\fIno-nice-names\fR] }
-
-.ti -8
-.BR "devlink region show"
-.RI "[ " DEV/REGION " ]"
-
-.ti -8
-.BR "devlink region del"
-.RI "" DEV/REGION ""
-.BR "snapshot"
-.RI "" SNAPSHOT_ID ""
-
-.ti -8
-.BR "devlink region dump"
-.RI "" DEV/REGION ""
-.BR "snapshot"
-.RI "" SNAPSHOT_ID ""
-
-.ti -8
-.BR "devlink region read"
-.RI "" DEV/REGION ""
-.BR "[ "
-.BR "snapshot"
-.RI "" SNAPSHOT_ID ""
-.BR "]"
-.BR "address"
-.RI "" ADDRESS "
-.BR "length"
-.RI "" LENGTH ""
-
-.ti -8
-.B devlink region help
-
-.SH "DESCRIPTION"
-.SS devlink region show - Show all supported address regions names, snapshots and sizes
-
-.PP
-.I "DEV/REGION"
-- specifies the devlink device and address-region to query.
-
-.SS devlink region del - Delete a snapshot specified by address-region name and snapshot ID
-
-.PP
-.I "DEV/REGION"
-- specifies the devlink device and address-region to delete the snapshot from
-
-.PP
-snapshot
-.I "SNAPSHOT_ID"
-- specifies the snapshot ID to delete
-
-.SS devlink region dump - Dump all the available data from a region or from snapshot of a region
-
-.PP
-.I "DEV/REGION"
-- specifies the device and address-region to dump from.
-
-.PP
-snapshot
-.I "SNAPSHOT_ID"
-- specifies the snapshot-id of the region to dump.
-
-.SS devlink region read - Read from a specific region address for a given length
-
-.PP
-.I "DEV/REGION"
-- specifies the device and address-region to read from.
-
-.PP
-snapshot
-.I "SNAPSHOT_ID"
-- specifies the snapshot-id of the region to read.
-
-.PP
-address
-.I "ADDRESS"
-- specifies the address to read from.
-
-.PP
-length
-.I "LENGTH"
-- specifies the length of data to read.
-
-.SH "EXAMPLES"
-.PP
-devlink region show
-.RS 4
-List available address regions and snapshot.
-.RE
-.PP
-devlink region del pci/0000:00:05.0/cr-space snapshot 1
-.RS 4
-Delete snapshot id 1 from cr-space address region from device pci/0000:00:05.0.
-.RE
-.PP
-devlink region dump pci/0000:00:05.0/cr-space snapshot 1
-.RS 4
-Dump the snapshot taken from cr-space address region with ID 1
-.RE
-.PP
-devlink region read pci/0000:00:05.0/cr-space snapshot 1 address 0x10 legth 16
-.RS 4
-Read from address 0x10, 16 Bytes of snapshot ID 1 taken from cr-space address region
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-dev (8),
-.BR devlink-port (8),
-.BR devlink-monitor (8),
-.br
-
-.SH AUTHOR
-Alex Vesker <valex@mellanox.com>
diff --git a/man/man8/devlink-resource.8 b/man/man8/devlink-resource.8
deleted file mode 100644
index b8f7880..0000000
--- a/man/man8/devlink-resource.8
+++ /dev/null
@@ -1,78 +0,0 @@
-.TH DEVLINK\-RESOURCE 8 "11 Feb 2018" "iproute2" "Linux"
-.SH NAME
-devlink-resource \- devlink device resource configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B resource
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-v\fR[\fIerbose\fR] }
-
-.ti -8
-.B devlink resource show
-.IR DEV
-
-.ti -8
-.B devlink resource help
-
-.ti -8
-.BR "devlink resource set"
-.IR DEV
-.BI path " RESOURCE_PATH"
-.BI size " RESOURCE_SIZE"
-
-.SH "DESCRIPTION"
-.SS devlink resource show - display devlink device's resosources
-
-.PP
-.I "DEV"
-- specifies the devlink device to show.
-
-.in +4
-Format is:
-.in +2
-BUS_NAME/BUS_ADDRESS
-
-.SS devlink resource set - sets resource size of specific resource
-
-.PP
-.I "DEV"
-- specifies the devlink device.
-
-.TP
-.BI path " RESOURCE_PATH"
-Resource's path.
-
-.TP
-.BI size " RESOURCE_SIZE"
-The new resource's size.
-
-.SH "EXAMPLES"
-.PP
-devlink resource show pci/0000:01:00.0
-.RS 4
-Shows the resources of the specified devlink device.
-.RE
-.PP
-devlink resource set pci/0000:01:00.0 /kvd/linear 98304
-.RS 4
-Sets the size of the specified resource for the specified devlink device.
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-port (8),
-.BR devlink-sb (8),
-.BR devlink-monitor (8),
-.br
-
-.SH AUTHOR
-Arkadi Sharshevsky <arkadis@mellanox.com>
diff --git a/man/man8/devlink-sb.8 b/man/man8/devlink-sb.8
deleted file mode 100644
index 91b6818..0000000
--- a/man/man8/devlink-sb.8
+++ /dev/null
@@ -1,323 +0,0 @@
-.TH DEVLINK\-SB 8 "14 Apr 2016" "iproute2" "Linux"
-.SH NAME
-devlink-sb \- devlink shared buffer configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B sb
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-n\fR[\fIno-nice-names\fR] }
-
-.ti -8
-.BR "devlink sb show "
-.RI "[ " DEV " [ "
-.B sb
-.IR SB_INDEX " ] ]"
-
-.ti -8
-.BR "devlink sb pool show "
-.RI "[ " DEV " [ "
-.B sb
-.IR SB_INDEX " ] "
-.br
-.B pool
-.IR POOL_INDEX " ]"
-
-.ti -8
-.BI "devlink sb pool set " DEV "
-.RB "[ " sb
-.IR SB_INDEX " ] "
-.br
-.BI pool " POOL_INDEX "
-.br
-.BI size " POOL_SIZE "
-.br
-.BR thtype " { " static " | " dynamic " }"
-
-.ti -8
-.BR "devlink sb port pool show "
-.RI "[ " DEV/PORT_INDEX " [ "
-.B sb
-.IR SB_INDEX " ] "
-.br
-.B pool
-.IR POOL_INDEX " ]"
-
-.ti -8
-.BI "devlink sb port pool set " DEV/PORT_INDEX "
-.RB "[ " sb
-.IR SB_INDEX " ] "
-.br
-.BI pool " POOL_INDEX "
-.br
-.BI th " THRESHOLD "
-
-.ti -8
-.BR "devlink sb tc bind show "
-.RI "[ " DEV/PORT_INDEX " [ "
-.B sb
-.IR SB_INDEX " ] "
-.br
-.BI tc " TC_INDEX "
-.br
-.B type
-.RB "{ " ingress " | " egress " } ]"
-
-.ti -8
-.BI "devlink sb tc bind set " DEV/PORT_INDEX "
-.RB "[ " sb
-.IR SB_INDEX " ] "
-.br
-.BI tc " TC_INDEX "
-.br
-.BR type " { " ingress " | " egress " }"
-.br
-.BI pool " POOL_INDEX "
-.br
-.BI th " THRESHOLD "
-
-.ti -8
-.BR "devlink sb occupancy show "
-.RI "{ " DEV " | " DEV/PORT_INDEX " } [ "
-.B sb
-.IR SB_INDEX " ] "
-
-.ti -8
-.BR "devlink sb occupancy snapshot "
-.IR DEV " [ "
-.B sb
-.IR SB_INDEX " ]"
-
-.ti -8
-.BR "devlink sb occupancy clearmax "
-.IR DEV " [ "
-.B sb
-.IR SB_INDEX " ]"
-
-.ti -8
-.B devlink sb help
-
-.SH "DESCRIPTION"
-.SS devlink sb show - display available shared buffers and their attributes
-
-.PP
-.I "DEV"
-- specifies the devlink device to show shared buffers.
-If this argument is omitted all shared buffers of all devices are listed.
-
-.PP
-.I "SB_INDEX"
-- specifies the shared buffer.
-If this argument is omitted shared buffer with index 0 is selected.
-Behaviour of this argument it the same for every command.
-
-.SS devlink sb pool show - display available pools and their attributes
-
-.PP
-.I "DEV"
-- specifies the devlink device to show pools.
-If this argument is omitted all pools of all devices are listed.
-
-Display available pools listing their
-.B type, size, thtype
-and
-.B cell_size. cell_size
-is the allocation granularity of memory within the shared buffer. Drivers
-may round up, round down or reject
-.B size
-passed to the set command if it is not multiple of
-.B cell_size.
-
-.SS devlink sb pool set - set attributes of pool
-
-.PP
-.I "DEV"
-- specifies the devlink device to set pool.
-
-.TP
-.BI size " POOL_SIZE"
-size of the pool in Bytes.
-
-.TP
-.BR thtype " { " static " | " dynamic " } "
-pool threshold type.
-
-.I static
-- Threshold values for the pool will be passed in Bytes.
-
-.I dynamic
-- Threshold values ("to_alpha") for the pool will be used to compute alpha parameter according to formula:
-.br
-.in +16
-alpha = 2 ^ (to_alpha - 10)
-.in -16
-
-.in +10
-The range of the passed value is between 0 to 20. The computed alpha is used to determine the maximum usage of the flow:
-.in -10
-.br
-.in +16
-max_usage = alpha / (1 + alpha) * Free_Buffer
-.in -16
-
-.SS devlink sb port pool show - display port-pool combinations and threshold for each
-.I "DEV/PORT_INDEX"
-- specifies the devlink port.
-
-.TP
-.BI pool " POOL_INDEX"
-pool index.
-
-.SS devlink sb port pool set - set port-pool threshold
-.I "DEV/PORT_INDEX"
-- specifies the devlink port.
-
-.TP
-.BI pool " POOL_INDEX"
-pool index.
-
-.TP
-.BI th " THRESHOLD"
-threshold value. Type of the value is either Bytes or "to_alpha", depends on
-.B thtype
-set for the pool.
-
-.SS devlink sb tc bind show - display port-TC to pool bindings and threshold for each
-
-.I "DEV/PORT_INDEX"
-- specifies the devlink port.
-
-.TP
-.BI tc " TC_INDEX"
-index of either ingress or egress TC, usually in range 0 to 8 (depends on device).
-
-.TP
-.BR type " { " ingress " | " egress " } "
-TC type.
-
-.SS devlink sb tc bind set - set port-TC to pool binding with specified threshold
-
-.I "DEV/PORT_INDEX"
-- specifies the devlink port.
-
-.TP
-.BI tc " TC_INDEX"
-index of either ingress or egress TC, usually in range 0 to 8 (depends on device).
-
-.TP
-.BR type " { " ingress " | " egress " } "
-TC type.
-
-.TP
-.BI pool " POOL_INDEX"
-index of pool to bind this to.
-
-.TP
-.BI th " THRESHOLD"
-threshold value. Type of the value is either Bytes or "to_alpha", depends on
-.B thtype
-set for the pool.
-
-.SS devlink sb occupancy show - display shared buffer occupancy values for device or port
-
-.PP
-This command is used to browse shared buffer occupancy values. Values are showed for every port-pool combination as well as for all port-TC combinations (with pool this port-TC is bound to). Format of value is:
-.br
-.in +16
-current_value/max_value
-.in -16
-Note that before showing values, one has to issue
-.B occupancy snapshot
-command first.
-
-.PP
-.I "DEV"
-- specifies the devlink device to show occupancy values for.
-
-.I "DEV/PORT_INDEX"
-- specifies the devlink port to show occupancy values for.
-
-.SS devlink sb occupancy snapshot - take occupancy snapshot of shared buffer for device
-This command is used to take a snapshot of shared buffer occupancy values. After that, the values can be showed using
-.B occupancy show
-command.
-
-.PP
-.I "DEV"
-- specifies the devlink device to take occupancy snapshot on.
-
-.SS devlink sb occupancy clearmax - clear occupancy watermarks of shared buffer for device
-This command is used to reset maximal occupancy values reached for whole device. Note that before browsing reset values, one has to issue
-.B occupancy snapshot
-command.
-
-.PP
-.I "DEV"
-- specifies the devlink device to clear occupancy watermarks on.
-
-.SH "EXAMPLES"
-.PP
-devlink sb show
-.RS 4
-List available share buffers.
-.RE
-.PP
-devlink sb pool show
-.RS 4
-List available pools and their config.
-.RE
-.PP
-devlink sb port pool show pci/0000:03:00.0/1 pool 0
-.RS 4
-Show port-pool setup for specified port and pool.
-.RE
-.PP
-sudo devlink sb port pool set pci/0000:03:00.0/1 pool 0 th 15
-.RS 4
-Change threshold for port specified port and pool.
-.RE
-.PP
-devlink sb tc bind show pci/0000:03:00.0/1 tc 0 type ingress
-.RS 4
-Show pool binding and threshold for specified port and TC.
-.RE
-.PP
-sudo devlink sb tc bind set pci/0000:03:00.0/1 tc 0 type ingress pool 0 th 9
-.RS 4
-Set pool binding and threshold for specified port and TC.
-.RE
-.PP
-sudo devlink sb occupancy snapshot pci/0000:03:00.0
-.RS 4
-Make a snapshot of occupancy of shared buffer for specified devlink device.
-.RE
-.PP
-devlink sb occupancy show pci/0000:03:00.0/1
-.RS 4
-Show occupancy for specified port from the snapshot.
-.RE
-.PP
-sudo devlink sb occupancy clearmax pci/0000:03:00.0
-.RS 4
-Clear watermarks for shared buffer of specified devlink device.
-
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-dev (8),
-.BR devlink-port (8),
-.BR devlink-monitor (8),
-.br
-
-.SH AUTHOR
-Jiri Pirko <jiri@mellanox.com>
diff --git a/man/man8/devlink-trap.8 b/man/man8/devlink-trap.8
deleted file mode 100644
index 4f079eb..0000000
--- a/man/man8/devlink-trap.8
+++ /dev/null
@@ -1,138 +0,0 @@
-.TH DEVLINK\-TRAP 8 "2 August 2019" "iproute2" "Linux"
-.SH NAME
-devlink-trap \- devlink trap configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B trap
-.RI "{ " COMMAND " |"
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-v\fR[\fIerbose\fR] |
-\fB\-s\fR[\fItatistics\fR] }
-
-.ti -8
-.B "devlink trap show"
-.RI "[ " DEV
-.B trap
-.IR TRAP " ]"
-
-.ti -8
-.BI "devlink trap set " DEV " trap " TRAP
-.RB "[ " action " { " trap " | " drop " } ]"
-
-.ti -8
-.B "devlink trap group show"
-.RI "[ " DEV
-.B group
-.IR GROUP " ]"
-
-.ti -8
-.BI "devlink trap group set " DEV " group " GROUP
-.RB "[ " action " { " trap " | " drop " } ]"
-
-.ti -8
-.B devlink trap help
-
-.SH "DESCRIPTION"
-.SS devlink trap show - display available packet traps and their attributes
-
-.PP
-.I "DEV"
-- specifies the devlink device from which to show packet traps.
-If this argument is omitted all packet traps of all devices are listed.
-
-.PP
-.BI "trap " TRAP
-- specifies the packet trap.
-Only applicable if a devlink device is also specified.
-
-.SS devlink trap set - set attributes of a packet trap
-
-.PP
-.I "DEV"
-- specifies the devlink device the packet trap belongs to.
-
-.PP
-.BI "trap " TRAP
-- specifies the packet trap.
-
-.TP
-.BR action " { " trap " | " drop " } "
-packet trap action.
-
-.I trap
-- the sole copy of the packet is sent to the CPU.
-
-.I drop
-- the packet is dropped by the underlying device and a copy is not sent to the CPU.
-
-.SS devlink trap group show - display available packet trap groups and their attributes
-
-.PP
-.I "DEV"
-- specifies the devlink device from which to show packet trap groups.
-If this argument is omitted all packet trap groups of all devices are listed.
-
-.PP
-.BI "group " GROUP
-- specifies the packet trap group.
-Only applicable if a devlink device is also specified.
-
-.SS devlink trap group set - set attributes of a packet trap group
-
-.PP
-.I "DEV"
-- specifies the devlink device the packet trap group belongs to.
-
-.PP
-.BI "group " GROUP
-- specifies the packet trap group.
-
-.TP
-.BR action " { " trap " | " drop " } "
-packet trap action. The action is set for all the packet traps member in the
-trap group. The actions of non-drop traps cannot be changed and are thus
-skipped.
-
-.SH "EXAMPLES"
-.PP
-devlink trap show
-.RS 4
-List available packet traps.
-.RE
-.PP
-devlink trap group show
-.RS 4
-List available packet trap groups.
-.RE
-.PP
-devlink -vs trap show pci/0000:01:00.0 trap source_mac_is_multicast
-.RS 4
-Show attributes and statistics of a specific packet trap.
-.RE
-.PP
-devlink -s trap group show pci/0000:01:00.0 group l2_drops
-.RS 4
-Show attributes and statistics of a specific packet trap group.
-.RE
-.PP
-devlink trap set pci/0000:01:00.0 trap source_mac_is_multicast action trap
-.RS 4
-Set the action of a specific packet trap to 'trap'.
-
-.SH SEE ALSO
-.BR devlink (8),
-.BR devlink-dev (8),
-.BR devlink-monitor (8),
-.br
-
-.SH AUTHOR
-Ido Schimmel <idosch@mellanox.com>
diff --git a/man/man8/devlink.8 b/man/man8/devlink.8
deleted file mode 100644
index 12d4894..0000000
--- a/man/man8/devlink.8
+++ /dev/null
@@ -1,135 +0,0 @@
-.TH DEVLINK 8 "14 Mar 2016" "iproute2" "Linux"
-.SH NAME
-devlink \- Devlink tool
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ] { " dev | port | monitor | sb | resource | region | health | trap " } { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.B devlink
-.RB "[ " -force " ] "
-.BI "-batch " filename
-.sp
-
-.SH OPTIONS
-
-.TP
-.BR "\-V" , " --Version"
-Print the version of the
-.B devlink
-utility and exit.
-
-.TP
-.BR "\-b", " \-batch " <FILENAME>
-Read commands from provided file or standard input and invoke them.
-First failure will cause termination of devlink.
-
-.TP
-.BR "\-force"
-Don't terminate devlink on errors in batch mode.
-If there were any errors during execution of the commands, the application return code will be non zero.
-
-.TP
-.BR "\-n" , " --no-nice-names"
-Turn off printing out nice names, for example netdevice ifnames instead of devlink port identification.
-
-.TP
-.BR "\-j" , " --json"
-Generate JSON output.
-
-.TP
-.BR "\-p" , " --pretty"
-When combined with -j generate a pretty JSON output.
-
-.TP
-.BR "\-v" , " --verbose"
-Turn on verbose output.
-
-.TP
-.BR "\-s" , " --statistics"
-Output statistics.
-
-.SS
-.I OBJECT
-
-.TP
-.B dev
-- devlink device.
-
-.TP
-.B port
-- devlink port.
-
-.TP
-.B monitor
-- watch for netlink messages.
-
-.TP
-.B sb
-- devlink shared buffer configuration.
-
-.TP
-.B resource
-- devlink device resource configuration.
-
-.TP
-.B region
-- devlink address region access
-
-.TP
-.B health
-- devlink reporting and recovery
-
-.TP
-.B trap
-- devlink trap configuration
-
-.SS
-.I COMMAND
-
-Specifies the action to perform on the object.
-The set of possible actions depends on the object type.
-As a rule, it is possible to
-.B show
-(or
-.B list
-) objects, but some objects do not allow all of these operations
-or have some additional commands. The
-.B help
-command is available for all objects. It prints
-out a list of available commands and argument syntax conventions.
-.sp
-If no command is given, some default command is assumed.
-Usually it is
-.B list
-or, if the objects of this class cannot be listed,
-.BR "help" .
-
-.SH EXIT STATUS
-Exit status is 0 if command was successful or a positive integer upon failure.
-
-.SH SEE ALSO
-.BR devlink-dev (8),
-.BR devlink-port (8),
-.BR devlink-monitor (8),
-.BR devlink-sb (8),
-.BR devlink-resource (8),
-.BR devlink-region (8),
-.BR devlink-health (8),
-.BR devlink-trap (8),
-.br
-
-.SH REPORTING BUGS
-Report any bugs to the Network Developers mailing list
-.B <netdev@vger.kernel.org>
-where the development and maintenance is primarily done.
-You do not have to be subscribed to the list to send a message there.
-
-.SH AUTHOR
-Jiri Pirko <jiri@mellanox.com>
diff --git a/man/man8/ifstat.8 b/man/man8/ifstat.8
index 8cd164d..e49d868 100644
--- a/man/man8/ifstat.8
+++ b/man/man8/ifstat.8
@@ -14,8 +14,7 @@
 The utility keeps records of the previous data displayed in history files and
 by default only shows difference between the last and the current call.
 Location of the history files defaults to /tmp/.ifstat.u$UID but may be
-overridden with the IFSTAT_HISTORY environment variable. Similarly, the default
-location for xstat (extended stats) is /tmp/.<xstat name>_ifstat.u$UID.
+overridden with the IFSTAT_HISTORY environment variable.
 .SH OPTIONS
 .TP
 .B \-h, \-\-help
@@ -47,23 +46,6 @@
 .TP
 .B \-z, \-\-zeros
 Show entries with zero activity.
-.TP
-.B \-j, \-\-json
-Display results in JSON format
-.TP
-.B \-p, \-\-pretty
-If combined with
-.BR \-\-json ,
-pretty print the output.
-.TP
-.B \-x, \-\-extended=TYPE
-Show extended stats of TYPE. Supported types are:
-
-.in +8
-.B cpu_hits
-- Counts only packets that went via the CPU.
-.in -8
-
 .SH ENVIRONMENT
 .TP
 .B IFSTAT_HISTORY
diff --git a/man/man8/ip-address.8.in b/man/man8/ip-address.8.in
index fe773c9..159d906 100644
--- a/man/man8/ip-address.8.in
+++ b/man/man8/ip-address.8.in
@@ -23,35 +23,16 @@
 .IB IFADDR " dev " IFNAME " [ " mngtmpaddr " ]"
 
 .ti -8
-.BR "ip address" " { " save " | " flush " } [ " dev
+.BR "ip address" " { " show " | " save " | " flush " } [ " dev
 .IR IFNAME " ] [ "
 .B  scope
 .IR SCOPE-ID " ] [ "
-.B  metric
-.IR METRIC " ] [ "
 .B  to
 .IR PREFIX " ] [ " FLAG-LIST " ] [ "
 .B  label
 .IR PATTERN " ] [ " up " ]"
 
 .ti -8
-.BR "ip address" " [ " show  " [ " dev
-.IR IFNAME " ] [ "
-.B  scope
-.IR SCOPE-ID " ] [ "
-.B  to
-.IR PREFIX " ] [ " FLAG-LIST " ] [ "
-.B  label
-.IR PATTERN " ] [ "
-.B  master
-.IR DEVICE " ] [ "
-.B  type
-.IR TYPE " ] [ "
-.B vrf
-.IR NAME " ] [ "
-.BR up " ] ]"
-
-.ti -8
 .BR "ip address" " { " showdump " | " restore " }"
 
 .ti -8
@@ -76,28 +57,22 @@
 .IR FLAG-LIST " := [ "  FLAG-LIST " ] " FLAG
 
 .ti -8
-.IR FLAG " := ["
-.RB [ - ] permanent " |"
-.RB [ - ] dynamic " |"
-.RB [ - ] secondary " |"
-.RB [ - ] primary " |"
-.RB [ - ] tentative " |"
-.RB [ - ] deprecated " |"
-.RB [ - ] dadfailed " |"
-.RB [ - ] temporary " |"
-.IR CONFFLAG-LIST " ]"
+.IR FLAG " := "
+.RB "[ " permanent " | " dynamic " | " secondary " | " primary " | \
+[ - ] " tentative " | [ - ] " deprecated " | [ - ] " dadfailed " | "\
+temporary " | " CONFFLAG-LIST " ]"
 
 .ti -8
 .IR CONFFLAG-LIST " := [ "  CONFFLAG-LIST " ] " CONFFLAG
 
 .ti -8
 .IR CONFFLAG " := "
-.RB "[ " home " | " mngtmpaddr " | " nodad " | " optimstic " | " noprefixroute " | " autojoin " ]"
+.RB "[ " home " | " mngtmpaddr " | " nodad " | " noprefixroute " ]"
 
 .ti -8
 .IR LIFETIME " := [ "
 .BI valid_lft " LFT"
-.RB "] [ " preferred_lft
+.RB "| " preferred_lft
 .IR  LFT " ]"
 
 .ti -8
@@ -105,40 +80,6 @@
 .BR forever " |"
 .IR SECONDS " ]"
 
-.ti -8
-.IR TYPE " := [ "
-.BR bridge " | "
-.BR bridge_slave " |"
-.BR bond " | "
-.BR bond_slave " |"
-.BR can " | "
-.BR dummy " | "
-.BR hsr " | "
-.BR ifb " | "
-.BR ipoib " |"
-.BR macvlan  " | "
-.BR macvtap  " | "
-.BR vcan " | "
-.BR veth " | "
-.BR vlan " | "
-.BR vxlan " |"
-.BR ip6tnl " |"
-.BR ipip " |"
-.BR sit " |"
-.BR gre " |"
-.BR gretap " |"
-.BR erspan " |"
-.BR ip6gre " |"
-.BR ip6gretap " |"
-.BR ip6erspan " |"
-.BR vti " |"
-.BR vrf " |"
-.BR nlmon " |"
-.BR ipvlan " |"
-.BR lowpan " |"
-.BR geneve " |"
-.BR macsec " ]"
-
 .SH "DESCRIPTION"
 The
 .B address
@@ -197,7 +138,6 @@
 In order to preserve compatibility with Linux-2.0 net aliases,
 this string must coincide with the name of the device or must be prefixed
 with the device name followed by colon.
-The maximum allowed total length of label is 15 characters.
 
 .TP
 .BI scope " SCOPE_VALUE"
@@ -222,10 +162,6 @@
 .in -8
 
 .TP
-.BI metric " NUMBER"
-priority of prefix route associated with address.
-
-.TP
 .BI valid_lft " LFT"
 the valid lifetime of this address; see section 5.5.4 of
 RFC 4862. When it expires, the address is removed by the kernel.
@@ -259,37 +195,12 @@
 adding this address.
 
 .TP
-.B optimistic
-(IPv6 only) When performing Duplicate Address Detection, use the RFC 4429
-optimistic variant.
-
-.TP
 .B noprefixroute
 Do not automatically create a route for the network prefix of the added
 address, and don't search for one to delete when removing the address. Changing
 an address to add this flag will remove the automatically added prefix route,
 changing it to remove this flag will create the prefix route automatically.
 
-.TP
-.B autojoin
-Joining multicast groups on Ethernet level via
-.B "ip maddr"
-command does not work if connected to an Ethernet switch that does IGMP
-snooping since the switch would not replicate multicast packets on ports that
-did not have IGMP reports for the multicast addresses.
-
-Linux VXLAN interfaces created via
-.B "ip link add vxlan"
-have the
-.B group
-option that enables them to do the required join.
-
-Using the
-.B autojoin
-flag when adding a multicast address enables similar functionality for
-Openvswitch VXLAN interfaces as well as other tunneling mechanisms that need to
-receive multicast traffic.
-
 .SS ip address delete - delete protocol address
 .B Arguments:
 coincide with the arguments of
@@ -319,24 +230,6 @@
 is a usual shell style pattern.
 
 .TP
-.BI master " DEVICE"
-only list interfaces enslaved to this master device.
-
-.TP
-.BI vrf " NAME "
-only list interfaces enslaved to this vrf.
-
-.TP
-.BI type " TYPE"
-only list interfaces of the given type.
-
-Note that the type name is not checked against the list of supported types -
-instead it is sent as-is to the kernel. Later it is used to filter the returned
-interface list by comparing it with the relevant attribute in case the kernel
-didn't filter already. Therefore any string is accepted, but may lead to empty
-output.
-
-.TP
 .B up
 only list running interfaces.
 
@@ -344,9 +237,7 @@
 .BR dynamic " and " permanent
 (IPv6 only) only list addresses installed due to stateless
 address configuration or only list permanent (not dynamic)
-addresses. These two flags are inverses of each other, so
-.BR -dynamic " is equal to " permanent " and "
-.BR -permanent " is equal to " dynamic .
+addresses.
 
 .TP
 .B tentative
@@ -377,34 +268,20 @@
 address detection.
 
 .TP
-.BR temporary " or " secondary
-List temporary IPv6 or secondary IPv4 addresses only. The Linux kernel shares a
-single bit for those, so they are actually aliases for each other although the
-meaning differs depending on address family.
+.B temporary
+(IPv6 only) only list temporary addresses.
 
 .TP
-.BR -temporary " or " -secondary
-These flags are aliases for
-.BR primary .
-
-.TP
-.B primary
-List only primary addresses, in IPv6 exclude temporary ones. This flag is the
-inverse of
-.BR temporary " and " secondary .
-
-.TP
-.B -primary
-This is an alias for
-.BR temporary " or " secondary .
+.BR primary " and " secondary
+only list primary (or secondary) addresses.
 
 .SS ip address flush - flush protocol addresses
 This command flushes the protocol addresses selected by some criteria.
 
 .PP
 This command has the same arguments as
-.BR show " except that " type " and " master " selectors are not supported."
-Another difference is that it does not run when no arguments are given.
+.B show.
+The difference is that it does not run when no arguments are given.
 
 .PP
 .B Warning:
diff --git a/man/man8/ip-addrlabel.8 b/man/man8/ip-addrlabel.8
index 233d606..51ef572 100644
--- a/man/man8/ip-addrlabel.8
+++ b/man/man8/ip-addrlabel.8
@@ -6,9 +6,21 @@
 .ad l
 .in +8
 .ti -8
-.B ip addrlabel
+.B ip
+.RI "[ " OPTIONS " ]"
+.B addrlabel
 .RI " { " COMMAND " | "
 .BR help " }"
+.sp
+
+.ti -8
+.IR OPTIONS " := { "
+\fB\-V\fR[\fIersion\fR] |
+\fB\-s\fR[\fItatistics\fR] |
+\fB\-r\fR[\fIesolve\fR] |
+\fB\-f\fR[\fIamily\fR] {
+.BR inet " | " inet6 " | " ipx " | " dnet " | " link " } | "
+\fB\-o\fR[\fIneline\fR] }
 
 .ti -8
 .BR "ip addrlabel" " { " add " | " del " } " prefix
diff --git a/man/man8/ip-fou.8 b/man/man8/ip-fou.8
index f4e08f1..0fa22ee 100644
--- a/man/man8/ip-fou.8
+++ b/man/man8/ip-fou.8
@@ -24,46 +24,11 @@
 .B ipproto
 .IR PROTO
 .RB " }"
-.RB "[ "
-.B local
-.IR IFADDR
-.RB " ]"
-.RB "[ "
-.B peer
-.IR IFADDR
-.RB " ]"
-.RB "[ "
-.B peer_port
-.IR PORT
-.RB " ]"
-.RB "[ "
-.B dev
-.IR IFNAME
-.RB " ]"
 .br
 .ti -8
 .BR "ip fou del"
 .B port
 .IR PORT
-.RB "[ "
-.B local
-.IR IFADDR
-.RB " ]"
-.RB "[ "
-.B peer
-.IR IFADDR
-.RB " ]"
-.RB "[ "
-.B peer_port
-.IR PORT
-.RB " ]"
-.RB "[ "
-.B dev
-.IR IFNAME
-.RB " ]"
-.br
-.ti -8
-.B ip fou show
 .SH DESCRIPTION
 The
 .B ip fou
@@ -82,27 +47,16 @@
 .I PORT
 argument. If FOU is used, the IP protocol number associated with the port is specified in
 .I PROTO
-argument. You can bind a port to a local address/interface, by specifying the
-address in the local
-.I IFADDR
-argument or the device in the
-.I IFNAME
-argument. If you would like to connect the port, you can specify the peer
-address in the peer
-.I IFADDR
-argument and peer port in the peer_port
-.I PORT
 argument.
 .PP
 A FOU or GUE receive port is deleted by specifying
 .I PORT
-in the delete command, as well as local address/interface or peer address/port
-(if set).
+in the delete command.
 .SH EXAMPLES
 .PP
 .SS Configure a FOU receive port for GRE bound to 7777
 .nf
-# ip fou add port 7777 ipproto 47
+# ip fou add port 8888 ipproto 47
 .PP
 .SS Configure a FOU receive port for IPIP bound to 8888
 .nf
@@ -115,10 +69,6 @@
 .SS Delete the GUE receive port bound to 9999
 .nf
 # ip fou del port 9999
-.SS Configure a FOU receive port for GRE bound to 1.2.3.4:7777
-.nf
-# ip fou add port 7777 ipproto 47 local 1.2.3.4
-.PP
 .SH SEE ALSO
 .br
 .BR ip (8)
diff --git a/man/man8/ip-l2tp.8 b/man/man8/ip-l2tp.8
index 9aba6be..1738035 100644
--- a/man/man8/ip-l2tp.8
+++ b/man/man8/ip-l2tp.8
@@ -15,7 +15,10 @@
 .ti -8
 .BR "ip l2tp add tunnel"
 .br
-.BI remote " ADDR " local " ADDR "
+.B remote
+.RI "[ " ADDR " ]"
+.B local
+.RI "[ " ADDR " ]"
 .br
 .B tunnel_id
 .IR ID
@@ -30,12 +33,6 @@
 .IR PORT
 .RB " ]"
 .br
-.RB "[ " udp_csum " { " on " | " off " } ]"
-.br
-.RB "[ " udp6_csum_tx " { " on " | " off " } ]"
-.br
-.RB "[ " udp6_csum_rx " { " on " | " off " } ]"
-.br
 .ti -8
 .BR "ip l2tp add session"
 .RB "[ " name
@@ -57,7 +54,11 @@
 .br
 .RB "[ " l2spec_type " { " none " | " default " } ]"
 .br
-.RB "[ " seq " { " none " | " send " | " recv " | " both " } ]"
+.RB "[ " offset
+.IR OFFSET
+.RB " ] [ " peer_offset
+.IR OFFSET
+.RB " ]"
 .br
 .ti -8
 .BR "ip l2tp del tunnel"
@@ -72,21 +73,24 @@
 .IR ID
 .br
 .ti -8
-.BR "ip l2tp show tunnel" " [ " tunnel_id
-.IR ID " ]"
+.BR "ip l2tp show tunnel"
+.B "[" tunnel_id
+.IR ID
+.B "]"
 .br
 .ti -8
-.BR "ip l2tp show session" " [ " tunnel_id
-.IR ID .B " ] ["
-.B session_id
-.IR ID " ]"
+.BR "ip l2tp show session"
+.B "[" tunnel_id
+.IR ID
+.B "] [" session_id
+.IR ID
+.B "]"
 .br
 .ti -8
 .IR NAME " := "
 .IR STRING
 .ti -8
-.IR ADDR " := { " IP_ADDRESS " |"
-.BR any " }"
+.IR ADDR " := { " IP_ADDRESS " }"
 .ti -8
 .IR PORT " := { " NUMBER " }"
 .ti -8
@@ -156,6 +160,9 @@
 acting upon network failures.
 .SS ip l2tp add tunnel - add a new tunnel
 .TP
+.BI name " NAME "
+sets the session network interface name. Default is l2tpethN.
+.TP
 .BI tunnel_id " ID"
 set the tunnel id, which is a 32-bit integer value. Uniquely
 identifies the tunnel. The value used must match the peer_tunnel_id
@@ -190,33 +197,6 @@
 set the UDP destination port to be used for the tunnel. Must be
 present when udp encapsulation is selected. Ignored when ip
 encapsulation is selected.
-.TP
-.BI udp_csum " STATE"
-(IPv4 only) control if IPv4 UDP checksums should be calculated and checked for the
-encapsulating UDP packets, when UDP encapsulating is selected.
-Default is
-.BR off "."
-.br
-Valid values are:
-.BR on ", " off "."
-.TP
-.BI udp6_csum_tx " STATE"
-(IPv6 only) control if IPv6 UDP checksums should be calculated for encapsulating
-UDP packets, when UDP encapsulating is selected.
-Default is
-.BR on "."
-.br
-Valid values are:
-.BR on ", " off "."
-.TP
-.BI udp6_csum_rx " STATE"
-(IPv6 only) control if IPv6 UDP checksums should be checked for the encapsulating
-UDP packets, when UDP encapsulating is selected.
-Default is
-.BR on "."
-.br
-Valid values are:
-.BR on ", " off "."
 .SS ip l2tp del tunnel - destroy a tunnel
 .TP
 .BI tunnel_id " ID"
@@ -265,20 +245,17 @@
 set the layer2specific header type of the session.
 .br
 Valid values are:
-.BR none ", " default "."
+.BR none ", " udp "."
 .TP
-.BI seq " SEQ"
-controls sequence numbering to prevent or detect out of order packets.
-.B send
-puts a sequence number in the default layer2specific header of each
-outgoing packet.
-.B recv
-reorder packets if they are received out of order.
-Default is
-.BR none "."
-.br
-Valid values are:
-.BR none ", " send ", " recv ", " both "."
+.BI offset " OFFSET"
+sets the byte offset from the L2TP header where user data starts in
+transmitted L2TP data packets. This is hardly ever used. If set, the
+value must match the peer_offset value used at the peer. Default is 0.
+.TP
+.BI peer_offset " OFFSET"
+sets the byte offset from the L2TP header where user data starts in
+received L2TP data packets. This is hardly ever used. If set, the
+value must match the offset value used at the peer. Default is 0.
 .SS ip l2tp del session - destroy a session
 .TP
 .BI tunnel_id " ID"
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index d1db0e9..4d32343 100644
--- a/man/man8/ip-link.8.in
+++ b/man/man8/ip-link.8.in
@@ -6,12 +6,25 @@
 .ad l
 .in +8
 .ti -8
-.B ip link
+.B ip
+.RI "[ " OPTIONS " ]"
+.B link
 .RI  " { " COMMAND " | "
 .BR help " }"
 .sp
 
 .ti -8
+.IR OPTIONS " := { "
+\fB\-V\fR[\fIersion\fR] |
+\fB\-h\fR[\fIuman-readable\fR] |
+\fB\-s\fR[\fItatistics\fR] |
+\fB\-r\fR[\fIesolve\fR] |
+\fB\-f\fR[\fIamily\fR] {
+.BR inet " | " inet6 " | " ipx " | " dnet " | " link " } | "
+\fB\-o\fR[\fIneline\fR] |
+\fB\-br\fR[\fIief\fR] }
+
+.ti -8
 .BI "ip link add"
 .RB "[ " link
 .IR DEVICE " ]"
@@ -36,163 +49,10 @@
 .RB "[ " numrxqueues
 .IR QUEUE_COUNT " ]"
 .br
-.BR "[ " gso_max_size
-.IR BYTES " ]"
-.RB "[ " gso_max_segs
-.IR SEGMENTS " ]"
-.br
-.BI type " TYPE"
+.BR type " TYPE"
 .RI "[ " ARGS " ]"
 
 .ti -8
-.BR "ip link delete " {
-.IR DEVICE " | "
-.BI "group " GROUP
-}
-.BI type " TYPE"
-.RI "[ " ARGS " ]"
-
-.ti -8
-.BR "ip link set " {
-.IR DEVICE " | "
-.BI "group " GROUP
-}
-.br
-.RB "[ { " up " | " down " } ]"
-.br
-.RB "[ " type
-.IR "ETYPE TYPE_ARGS" " ]"
-.br
-.RB "[ " arp " { " on " | " off " } ]"
-.br
-.RB "[ " dynamic " { " on " | " off " } ]"
-.br
-.RB "[ " multicast " { " on " | " off " } ]"
-.br
-.RB "[ " allmulticast " { " on " | " off " } ]"
-.br
-.RB "[ " promisc " { " on " | " off " } ]"
-.br
-.RB "[ " protodown " { " on " | " off " } ]"
-.br
-.RB "[ " trailers " { " on " | " off " } ]"
-.br
-.RB "[ " txqueuelen
-.IR PACKETS " ]"
-.br
-.RB "[ " name
-.IR NEWNAME " ]"
-.br
-.RB "[ " address
-.IR LLADDR " ]"
-.br
-.RB "[ " broadcast
-.IR LLADDR " ]"
-.br
-.RB "[ " mtu
-.IR MTU " ]"
-.br
-.RB "[ " netns " {"
-.IR PID " | " NETNSNAME " } ]"
-.br
-.RB "[ " link-netnsid
-.IR ID " ]"
-.br
-.RB "[ " alias
-.IR NAME  " ]"
-.br
-.RB "[ " vf
-.IR NUM " ["
-.B  mac
-.IR LLADDR " ]"
-.br
-.in +9
-.RI "[ " VFVLAN-LIST " ]"
-.br
-.RB "[ " rate
-.IR TXRATE " ]"
-.br
-.RB "[ " max_tx_rate
-.IR TXRATE " ]"
-.br
-.RB "[ " min_tx_rate
-.IR TXRATE " ]"
-.br
-.RB "[ " spoofchk " { " on " | " off " } ]"
-.br
-.RB "[ " query_rss " { " on " | " off " } ]"
-.br
-.RB "[ " state " { " auto " | " enable " | " disable " } ]"
-.br
-.RB "[ " trust " { " on " | " off " } ]"
-.br
-.RB "[ " node_guid " eui64 ]"
-.br
-.RB "[ " port_guid " eui64 ] ]"
-.br
-.in -9
-.RB "[ { " xdp " | " xdpgeneric  " | " xdpdrv " | " xdpoffload " } { " off " | "
-.br
-.in +8
-.BR object
-.IR FILE
-.RB "[ " section
-.IR NAME " ]"
-.RB "[ " verbose " ] |"
-.br
-.BR pinned
-.IR FILE " } ]"
-.br
-.in -8
-.RB "[ " master
-.IR DEVICE " ]"
-.br
-.RB "[ " nomaster " ]"
-.br
-.RB "[ " vrf
-.IR NAME " ]"
-.br
-.RB "[ " addrgenmode " { " eui64 " | " none " | " stable_secret " | " random " } ]"
-.br
-.RB "[ " macaddr
-.RI "[ " MACADDR " ]"
-.br
-.in +10
-.RB "[ { " flush " | " add " | " del " } "
-.IR MACADDR " ]"
-.br
-.RB "[ " set
-.IR MACADDR " ] ]"
-.br
-
-.ti -8
-.B ip link show
-.RI "[ " DEVICE " | "
-.B group
-.IR GROUP " ] ["
-.BR up " ] ["
-.B master
-.IR DEVICE " ] ["
-.B type
-.IR ETYPE " ] ["
-.B vrf
-.IR NAME " ]"
-
-.ti -8
-.B ip link xstats
-.BI type " TYPE"
-.RI "[ " ARGS " ]"
-
-.ti -8
-.B ip link afstats
-.RB "[ " dev
-.IR DEVICE " ]"
-
-.ti -8
-.B ip link help
-.RI "[ " TYPE " ]"
-
-.ti -8
 .IR TYPE " := [ "
 .BR bridge " | "
 .BR bond " | "
@@ -204,7 +64,6 @@
 .BR macvlan  " | "
 .BR macvtap  " | "
 .BR vcan " | "
-.BR vxcan " | "
 .BR veth " | "
 .BR vlan " | "
 .BR vxlan " |"
@@ -213,37 +72,104 @@
 .BR sit " |"
 .BR gre " |"
 .BR gretap " |"
-.BR erspan " |"
 .BR ip6gre " |"
 .BR ip6gretap " |"
-.BR ip6erspan " |"
 .BR vti " |"
 .BR nlmon " |"
 .BR ipvlan " |"
-.BR ipvtap " |"
 .BR lowpan " |"
-.BR geneve " |"
-.BR vrf " |"
-.BR macsec " |"
-.BR netdevsim " |"
-.BR rmnet " |"
-.BR xfrm " ]"
+.BR geneve " ]"
 
 .ti -8
-.IR ETYPE " := [ " TYPE " |"
-.BR bridge_slave " | " bond_slave " ]"
+.BR "ip link delete " {
+.IR DEVICE " | "
+.BI "group " GROUP
+}
+.BI type " TYPE"
+.RI "[ " ARGS " ]"
 
 .ti -8
-.IR VFVLAN-LIST " := [ "  VFVLAN-LIST " ] " VFVLAN
-
-.ti -8
-.IR VFVLAN " := "
-.RB "[ " vlan
+.BR "ip link set " {
+.IR DEVICE " | "
+.BI "group " GROUP
+.RB "} { " up " | " down " | " arp " { " on " | " off " } |"
+.br
+.BR promisc " { " on " | " off " } |"
+.br
+.BR allmulticast " { " on " | " off " } |"
+.br
+.BR dynamic " { " on " | " off " } |"
+.br
+.BR multicast " { " on " | " off " } |"
+.br
+.BR protodown " { " on " | " off " } |"
+.br
+.B  txqueuelen
+.IR PACKETS " |"
+.br
+.B  name
+.IR NEWNAME " |"
+.br
+.B  address
+.IR LLADDR " |"
+.B  broadcast
+.IR LLADDR " |"
+.br
+.B  mtu
+.IR MTU " |"
+.br
+.B  netns
+.IR PID " |"
+.br
+.B  netns
+.IR NETNSNAME " |"
+.br
+.B alias
+.IR NAME  " |"
+.br
+.B vf
+.IR NUM " ["
+.B  mac
+.IR LLADDR " ] ["
+.B vlan
 .IR VLANID " [ "
 .B qos
-.IR VLAN-QOS " ] ["
-.B proto
-.IR VLAN-PROTO " ] ]"
+.IR VLAN-QOS " ] ] ["
+.B rate
+.IR TXRATE " ] ["
+.B max_tx_rate
+.IR TXRATE " ] ["
+.B min_tx_rate
+.IR TXRATE " ] ["
+.B spoofchk { on | off } ] [
+.B state { auto | enable | disable}
+] |
+.br
+.B master
+.IR DEVICE " |"
+.br
+.B nomaster " |"
+.br
+.B addrgenmode { eui64 | none | stable_secret | random }
+.br
+.B link-netnsid ID
+.BR " }"
+
+
+.ti -8
+.B ip link show
+.RI "[ " DEVICE " | "
+.B group
+.IR GROUP " | "
+.BR up " | "
+.B master
+.IR DEVICE " | "
+.B type
+.IR TYPE " ]"
+
+.ti -8
+.B ip link help
+.RI "[ " TYPE " ]"
 
 .SH "DESCRIPTION"
 .SS ip link add - add virtual link
@@ -266,6 +192,8 @@
 .sp
 .B bond
 - Bonding device
+.B can
+- Controller Area Network interface
 .sp
 .B dummy
 - Dummy network interface
@@ -288,9 +216,6 @@
 .B vcan
 - Virtual Controller Area Network interface
 .sp
-.B vxcan
-- Virtual Controller Area Network tunnel interface
-.sp
 .B veth
 - Virtual ethernet interface
 .sp
@@ -315,18 +240,12 @@
 .BR gretap
 - Virtual L2 tunnel interface GRE over IPv4
 .sp
-.BR erspan
-- Encapsulated Remote SPAN over GRE and IPv4
-.sp
 .BR ip6gre
 - Virtual tunnel interface GRE over IPv6
 .sp
 .BR ip6gretap
 - Virtual L2 tunnel interface GRE over IPv6
 .sp
-.BR ip6erspan
-- Encapsulated Remote SPAN over GRE and IPv6
-.sp
 .BR vti
 - Virtual tunnel interface
 .sp
@@ -336,29 +255,11 @@
 .BR ipvlan
 - Interface for L3 (IPv6/IPv4) based VLANs
 .sp
-.BR ipvtap
-- Interface for L3 (IPv6/IPv4) based VLANs and TAP
-.sp
 .BR lowpan
 - Interface for 6LoWPAN (IPv6) over IEEE 802.15.4 / Bluetooth
 .sp
 .BR geneve
 - GEneric NEtwork Virtualization Encapsulation
-.sp
-.BR macsec
-- Interface for IEEE 802.1AE MAC Security (MACsec)
-.sp
-.BR vrf
-- Interface for L3 VRF domains
-.sp
-.BR netdevsim
-- Interface for netdev API tests
-.sp
-.BR rmnet
-- Qualcomm rmnet device
-.sp
-.BR xfrm
-- Virtual xfrm interface
 .in -8
 
 .TP
@@ -370,19 +271,8 @@
 specifies the number of receive queues for new device.
 
 .TP
-.BI gso_max_size " BYTES "
-specifies the recommended maximum size of a Generic Segment Offload
-packet the new device should accept.
-
-.TP
-.BI gso_max_segs " SEGMENTS "
-specifies the recommended maximum number of a Generic Segment Offload
-segments the new device should accept.
-
-.TP
 .BI index " IDX "
-specifies the desired index of the new virtual device. The link
-creation fails, if the index is busy.
+specifies the desired index of the new virtual device. The link creation fails, if the index is busy.
 
 .TP
 VLAN Type Support
@@ -393,7 +283,7 @@
 .BI "ip link add
 .BI link " DEVICE "
 .BI name " NAME "
-.B "type vlan"
+.BI type " vlan "
 [
 .BI protocol " VLAN_PROTO "
 ]
@@ -411,9 +301,6 @@
 .BR loose_binding " { " on " | " off " } "
 ]
 [
-.BR bridge_binding " { " on " | " off " } "
-]
-[
 .BI ingress-qos-map " QOS-MAP "
 ]
 [
@@ -435,14 +322,13 @@
 .in +4
 If
 .BR reorder_hdr " is " on
-then VLAN header will be not inserted immediately but only before
-passing to the physical device (if this device does not support VLAN
-offloading), the similar on the RX direction - by default the packet
-will be untagged before being received by VLAN device. Reordering
-allows to accelerate tagging on egress and to hide VLAN header on
-ingress so the packet looks like regular Ethernet packet, at the same
-time it might be confusing for packet capture as the VLAN header does
-not exist within the packet.
+then VLAN header will be not inserted immediately but only before passing to the
+physical device (if this device does not support VLAN offloading), the similar
+on the RX direction - by default the packet will be untagged before being
+received by VLAN device. Reordering allows to accelerate tagging on egress and
+to hide VLAN header on ingress so the packet looks like regular Ethernet packet,
+at the same time it might be confusing for packet capture as the VLAN header
+does not exist within the packet.
 
 VLAN offloading can be checked by
 .BR ethtool "(8):"
@@ -457,20 +343,14 @@
 .in -4
 
 .BR gvrp " { " on " | " off " } "
-- specifies whether this VLAN should be registered using GARP VLAN
-  Registration Protocol.
+- specifies whether this VLAN should be registered using GARP VLAN Registration Protocol.
 
 .BR mvrp " { " on " | " off " } "
-- specifies whether this VLAN should be registered using Multiple VLAN
-  Registration Protocol.
+- specifies whether this VLAN should be registered using Multiple VLAN Registration Protocol.
 
 .BR loose_binding " { " on " | " off " } "
 - specifies whether the VLAN device state is bound to the physical device state.
 
-.BR bridge_binding " { " on " | " off " } "
-- specifies whether the VLAN device link state tracks the state of bridge ports
-that are members of the VLAN.
-
 .BI ingress-qos-map " QOS-MAP "
 - defines a mapping of VLAN header prio field to the Linux internal packet
 priority on incoming frames. The format is FROM:TO with multiple mappings
@@ -489,8 +369,7 @@
 -t mangle -A POSTROUTING [...] -j CLASSIFY --set-class 0:4
 .sp
 .in -4
-and this "4" priority can be used in the egress qos mapping to set
-VLAN prio "5":
+and this "4" priority can be used in the egress qos mapping to set VLAN prio "5":
 .sp
 .in +4
 .B ip
@@ -506,7 +385,7 @@
 the following additional arguments are supported:
 
 .BI "ip link add " DEVICE
-.BI type " vxlan " id " VNI"
+.BI type " vxlan " id " ID"
 [
 .BI dev " PHYS_DEV "
 .RB " ] [ { " group " | " remote " } "
@@ -519,39 +398,31 @@
 ] [
 .BI tos " TOS "
 ] [
-.BI df " DF "
-] [
-.BI flowlabel " FLOWLABEL "
-] [
 .BI dstport " PORT "
 ] [
 .BI srcport " MIN MAX "
 ] [
-.RB [ no ] learning
+.I "[no]learning "
 ] [
-.RB [ no ] proxy
+.I "[no]proxy "
 ] [
-.RB [ no ] rsc
+.I "[no]rsc "
 ] [
-.RB [ no ] l2miss
+.I "[no]l2miss "
 ] [
-.RB [ no ] l3miss
+.I "[no]l3miss "
 ] [
-.RB [ no ] udpcsum
+.I "[no]udpcsum "
 ] [
-.RB [ no ] udp6zerocsumtx
+.I "[no]udp6zerocsumtx "
 ] [
-.RB [ no ] udp6zerocsumrx
+.I "[no]udp6zerocsumrx "
 ] [
 .BI ageing " SECONDS "
 ] [
 .BI maxaddress " NUMBER "
 ] [
-.RB [ no ] external
-] [
 .B gbp
-] [
-.B gpe
 ]
 
 .in +8
@@ -591,25 +462,8 @@
 - specifies the TOS value to use in outgoing packets.
 
 .sp
-.BI df " DF"
-- specifies the usage of the Don't Fragment flag (DF) bit in outgoing packets
-with IPv4 headers. The value
-.B inherit
-causes the bit to be copied from the original IP header. The values
-.B unset
-and
-.B set
-cause the bit to be always unset or always set, respectively. By default, the
-bit is not set.
-
-.sp
-.BI flowlabel " FLOWLABEL"
-- specifies the flow label to use in outgoing packets.
-
-.sp
 .BI dstport " PORT"
-- specifies the UDP destination port to communicate to the remote
-  VXLAN tunnel endpoint.
+- specifies the UDP destination port to communicate to the remote VXLAN tunnel endpoint.
 
 .sp
 .BI srcport " MIN MAX"
@@ -617,37 +471,37 @@
 source ports to communicate to the remote VXLAN tunnel endpoint.
 
 .sp
-.RB [ no ] learning
+.I [no]learning
 - specifies if unknown source link layer addresses and IP addresses
 are entered into the VXLAN device forwarding database.
 
 .sp
-.RB [ no ] rsc
+.I [no]rsc
 - specifies if route short circuit is turned on.
 
 .sp
-.RB [ no ] proxy
+.I [no]proxy
 - specifies ARP proxy is turned on.
 
 .sp
-.RB [ no ] l2miss
+.I [no]l2miss
 - specifies if netlink LLADDR miss notifications are generated.
 
 .sp
-.RB [ no ] l3miss
+.I [no]l3miss
 - specifies if netlink IP ADDR miss notifications are generated.
 
 .sp
-.RB [ no ] udpcsum
-- specifies if UDP checksum is calculated for transmitted packets over IPv4.
+.I [no]udpcsum
+- specifies if UDP checksum is filled in
 
 .sp
-.RB [ no ] udp6zerocsumtx
-- skip UDP checksum calculation for transmitted packets over IPv6.
+.I [no]udp6zerocsumtx
+- specifies if UDP checksum is filled in
 
 .sp
-.RB [ no ] udp6zerocsumrx
-- allow incoming UDP packets over IPv6 with zero checksum field.
+.I [no]udp6zerocsumrx
+- specifies if UDP checksum is received
 
 .sp
 .BI ageing " SECONDS"
@@ -658,12 +512,6 @@
 - specifies the maximum number of FDB entries.
 
 .sp
-.RB [ no ] external
-- specifies whether an external control plane
-.RB "(e.g. " "ip route encap" )
-or the internal FDB should be used.
-
-.sp
 .B gbp
 - enables the Group Policy extension (VXLAN-GBP).
 
@@ -671,7 +519,7 @@
 Allows to transport group policy context across VXLAN network peers.
 If enabled, includes the mark of a packet in the VXLAN header for outgoing
 packets and fills the packet mark based on the information found in the
-VXLAN header for incoming packets.
+VXLAN header for incomming packets.
 
 Format of upper 16 bits of packet mark (flags);
 
@@ -706,61 +554,27 @@
 
 .in -4
 
-.sp
-.B gpe
-- enables the Generic Protocol extension (VXLAN-GPE). Currently, this is
-only supported together with the
-.B external
-keyword.
-
 .in -8
 
 .TP
-VETH, VXCAN Type Support
+GRE, IPIP, SIT Type Support
 For a link of types
-.I VETH/VXCAN
+.I GRE/IPIP/SIT
 the following additional arguments are supported:
 
 .BI "ip link add " DEVICE
-.BR type " { " veth " | " vxcan " }"
-[
-.BR peer
-.BI "name " NAME
-]
-
-.in +8
-.sp
-.BR peer
-.BI "name " NAME
-- specifies the virtual pair device name of the
-.I VETH/VXCAN
-tunnel.
-
-.in -8
-
-.TP
-IPIP, SIT Type Support
-For a link of type
-.IR IPIP or SIT
-the following additional arguments are supported:
-
-.BI "ip link add " DEVICE
-.BR type " { " ipip " | " sit " }"
+.BR type " { gre | ipip | sit } "
 .BI " remote " ADDR " local " ADDR
 [
-.BR encap " { " fou " | " gue " | " none " }"
+.BR encap " { fou | gue | none } "
 ] [
-.BR encap-sport " { " \fIPORT " | " auto " }"
+.BI "encap-sport { " PORT " | auto } "
 ] [
 .BI "encap-dport " PORT
 ] [
-.RB [ no ] encap-csum
+.I " [no]encap-csum "
 ] [
 .I " [no]encap-remcsum "
-] [
-.I " mode " { ip6ip | ipip | mplsip | any } "
-] [
-.BR external
 ]
 
 .in +8
@@ -774,12 +588,12 @@
 It must be an address on another interface on this host.
 
 .sp
-.BR encap " { " fou " | " gue " | " none " }"
+.BR encap " { fou | gue | none } "
 - specifies type of secondary UDP encapsulation. "fou" indicates
 Foo-Over-UDP, "gue" indicates Generic UDP Encapsulation.
 
 .sp
-.BR encap-sport " { " \fIPORT " | " auto " }"
+.BI "encap-sport { " PORT " | auto } "
 - specifies the source port in UDP encapsulation.
 .IR PORT
 indicates the port by number, "auto"
@@ -788,176 +602,15 @@
 encapsulated packet).
 
 .sp
-.RB [ no ] encap-csum
+.I [no]encap-csum
 - specifies if UDP checksums are enabled in the secondary
 encapsulation.
 
 .sp
-.RB [ no ] encap-remcsum
+.I [no]encap-remcsum
 - specifies if Remote Checksum Offload is enabled. This is only
 applicable for Generic UDP Encapsulation.
 
-.sp
-.BI mode " { ip6ip | ipip | mplsip | any } "
-- specifies mode in which device should run. "ip6ip" indicates
-IPv6-Over-IPv4, "ipip" indicates "IPv4-Over-IPv4", "mplsip" indicates
-MPLS-Over-IPv4, "any" indicates IPv6, IPv4 or MPLS Over IPv4. Supported for
-SIT where the default is "ip6ip" and IPIP where the default is "ipip".
-IPv6-Over-IPv4 is not supported for IPIP.
-
-.sp
-.BR external
-- make this tunnel externally controlled
-.RB "(e.g. " "ip route encap" ).
-
-.in -8
-.TP
-GRE Type Support
-For a link of type
-.IR GRE " or " GRETAP
-the following additional arguments are supported:
-
-.BI "ip link add " DEVICE
-.BR type " { " gre " | " gretap " }"
-.BI " remote " ADDR " local " ADDR
-[
-.RB [ no ] "" [ i | o ] seq
-] [
-.RB [ i | o ] key
-.I KEY
-|
-.BR no [ i | o ] key
-] [
-.RB [ no ] "" [ i | o ] csum
-] [
-.BI ttl " TTL "
-] [
-.BI tos " TOS "
-] [
-.RB [ no ] pmtudisc
-] [
-.RB [ no ] ignore-df
-] [
-.BI dev " PHYS_DEV "
-] [
-.BR encap " { " fou " | " gue " | " none " }"
-] [
-.BR encap-sport " { " \fIPORT " | " auto " }"
-] [
-.BI "encap-dport " PORT
-] [
-.RB [ no ] encap-csum
-] [
-.RB [ no ] encap-remcsum
-] [
-.BR external
-]
-
-.in +8
-.sp
-.BI  remote " ADDR "
-- specifies the remote address of the tunnel.
-
-.sp
-.BI  local " ADDR "
-- specifies the fixed local address for tunneled packets.
-It must be an address on another interface on this host.
-
-.sp
-.RB  [ no ] "" [ i | o ] seq
-- serialize packets.
-The
-.B oseq
-flag enables sequencing of outgoing packets.
-The
-.B iseq
-flag requires that all input packets are serialized.
-
-.sp
-.RB [ i | o ] key
-.I KEY
-|
-.BR no [ i | o ] key
-- use keyed GRE with key
-.IR KEY ". "KEY
-is either a number or an IPv4 address-like dotted quad.
-The
-.B key
-parameter specifies the same key to use in both directions.
-The
-.BR ikey " and " okey
-parameters specify different keys for input and output.
-
-.sp
-.RB  [ no ] "" [ i | o ] csum
-- generate/require checksums for tunneled packets.
-The
-.B ocsum
-flag calculates checksums for outgoing packets.
-The
-.B icsum
-flag requires that all input packets have the correct
-checksum. The
-.B csum
-flag is equivalent to the combination
-.B "icsum ocsum" .
-
-.sp
-.BI ttl " TTL"
-- specifies the TTL value to use in outgoing packets.
-
-.sp
-.BI tos " TOS"
-- specifies the TOS value to use in outgoing packets.
-
-.sp
-.RB [ no ] pmtudisc
-- enables/disables Path MTU Discovery on this tunnel.
-It is enabled by default. Note that a fixed ttl is incompatible
-with this option: tunneling with a fixed ttl always makes pmtu
-discovery.
-
-.sp
-.RB [ no ] ignore-df
-- enables/disables IPv4 DF suppression on this tunnel.
-Normally datagrams that exceed the MTU will be fragmented; the presence
-of the DF flag inhibits this, resulting instead in an ICMP Unreachable
-(Fragmentation Required) message.  Enabling this attribute causes the
-DF flag to be ignored.
-
-.sp
-.BI dev " PHYS_DEV"
-- specifies the physical device to use for tunnel endpoint communication.
-
-.sp
-.BR encap " { " fou " | " gue " | " none " }"
-- specifies type of secondary UDP encapsulation. "fou" indicates
-Foo-Over-UDP, "gue" indicates Generic UDP Encapsulation.
-
-.sp
-.BR encap-sport " { " \fIPORT " | " auto " }"
-- specifies the source port in UDP encapsulation.
-.IR PORT
-indicates the port by number, "auto"
-indicates that the port number should be chosen automatically
-(the kernel picks a flow based on the flow hash of the
-encapsulated packet).
-
-.sp
-.RB [ no ] encap-csum
-- specifies if UDP checksums are enabled in the secondary
-encapsulation.
-
-.sp
-.RB [ no ] encap-remcsum
-- specifies if Remote Checksum Offload is enabled. This is only
-applicable for Generic UDP Encapsulation.
-
-.sp
-.BR external
-- make this tunnel externally controlled
-.RB "(e.g. " "ip route encap" ).
-
 .in -8
 
 .TP
@@ -967,17 +620,13 @@
 the following additional arguments are supported:
 
 .BI "ip link add " DEVICE
-.BR type " { " ip6gre " | " ip6gretap " }"
-.BI remote " ADDR " local " ADDR"
+.BI type " { ip6gre | ip6gretap }  " remote " ADDR " local " ADDR
 [
-.RB [ no ] "" [ i | o ] seq
+.I "[i|o]seq]"
 ] [
-.RB [ i | o ] key
-.I KEY
-|
-.BR no [ i | o ] key
+.I "[i|o]key" KEY
 ] [
-.RB [ no ] "" [ i | o ] csum
+.I " [i|o]csum "
 ] [
 .BI hoplimit " TTL "
 ] [
@@ -989,11 +638,7 @@
 ] [
 .BI "dscp inherit"
 ] [
-.BI "[no]allow-localremote"
-] [
 .BI dev " PHYS_DEV "
-] [
-.RB external
 ]
 
 .in +8
@@ -1007,7 +652,7 @@
 It must be an address on another interface on this host.
 
 .sp
-.RB  [ no ] "" [ i | o ] seq
+.BI  [i|o]seq
 - serialize packets.
 The
 .B oseq
@@ -1017,10 +662,7 @@
 flag requires that all input packets are serialized.
 
 .sp
-.RB [ i | o ] key
-.I KEY
-|
-.BR no [ i | o ] key
+.BI  [i|o]key " KEY"
 - use keyed GRE with key
 .IR KEY ". "KEY
 is either a number or an IPv4 address-like dotted quad.
@@ -1032,7 +674,7 @@
 parameters specify different keys for input and output.
 
 .sp
-.RB  [ no ] "" [ i | o ] csum
+.BI  [i|o]csum
 - generate/require checksums for tunneled packets.
 The
 .B ocsum
@@ -1058,11 +700,6 @@
 - specifies a fixed flowlabel.
 
 .sp
-.BI  [no]allow-localremote
-- specifies whether to allow remote endpoint to have an address configured on
-local host.
-
-.sp
 .BI  tclass " TCLASS"
 - specifies the traffic class field on
 tunneled packets, which can be specified as either a two-digit
@@ -1080,21 +717,6 @@
 .IR 00 ".." ff
 when tunneling non-IP packets. The default value is 00.
 
-.sp
-.RB external
-- make this tunnel externally controlled (or not, which is the default).
-In the kernel, this is referred to as collect metadata mode.  This flag is
-mutually exclusive with the
-.BR remote ,
-.BR local ,
-.BR seq ,
-.BR key,
-.BR csum,
-.BR hoplimit,
-.BR encaplimit,
-.BR flowlabel " and " tclass
-options.
-
 .in -8
 
 .TP
@@ -1104,7 +726,7 @@
 the following additional arguments are supported:
 
 .BI "ip link add " DEVICE " name " NAME
-.BR "type ipoib " [ " pkey \fIPKEY" " ] [ " mode " \fIMODE \fR]"
+.BI type " ipoib [ " pkey " PKEY ] [" mode " MODE " ]
 
 .in +8
 .sp
@@ -1115,108 +737,17 @@
 - specifies the mode (datagram or connected) to use.
 
 .TP
-ERSPAN Type Support
-For a link of type
-.I ERSPAN/IP6ERSPAN
-the following additional arguments are supported:
-
-.BI "ip link add " DEVICE
-.BR type " { " erspan " | " ip6erspan " }"
-.BI remote " ADDR " local " ADDR " seq
-.RB key
-.I KEY
-.BR erspan_ver " \fIversion "
-[
-.BR erspan " \fIIDX "
-] [
-.BR erspan_dir " { " \fIingress " | " \fIegress " }"
-] [
-.BR erspan_hwid " \fIhwid "
-] [
-.BI "[no]allow-localremote"
-] [
-.RB external
-]
-
-.in +8
-.sp
-.BI  remote " ADDR "
-- specifies the remote address of the tunnel.
-
-.sp
-.BI  local " ADDR "
-- specifies the fixed local address for tunneled packets.
-It must be an address on another interface on this host.
-
-.sp
-.BR erspan_ver " \fIversion "
-- specifies the ERSPAN version number.
-.IR version
-indicates the ERSPAN version to be created: 1 for version 1 (type II)
-or 2 for version 2 (type III).
-
-.sp
-.BR erspan " \fIIDX "
-- specifies the ERSPAN v1 index field.
-.IR IDX
-indicates a 20 bit index/port number associated with the ERSPAN
-traffic's source port and direction.
-
-.sp
-.BR erspan_dir " { " \fIingress " | " \fIegress " }"
-- specifies the ERSPAN v2 mirrored traffic's direction.
-
-.sp
-.BR erspan_hwid " \fIhwid "
-- an unique identifier of an ERSPAN v2 engine within a system.
-.IR hwid
-is a 6-bit value for users to configure.
-
-.sp
-.BI  [no]allow-localremote
-- specifies whether to allow remote endpoint to have an address configured on
-local host.
-
-.sp
-.BR external
-- make this tunnel externally controlled (or not, which is the default).
-In the kernel, this is referred to as collect metadata mode.  This flag is
-mutually exclusive with the
-.BR remote ,
-.BR local ,
-.BR erspan_ver ,
-.BR erspan ,
-.BR erspan_dir " and " erspan_hwid
-options.
-
-.in -8
-
-.TP
 GENEVE Type Support
 For a link of type
 .I GENEVE
 the following additional arguments are supported:
 
 .BI "ip link add " DEVICE
-.BI type " geneve " id " VNI " remote " IPADDR"
+.BI type " geneve " id " ID " remote " IPADDR"
 [
 .BI ttl " TTL "
 ] [
 .BI tos " TOS "
-] [
-.BI df " DF "
-] [
-.BI flowlabel " FLOWLABEL "
-] [
-.BI dstport " PORT"
-] [
-.RB [ no ] external
-] [
-.RB [ no ] udpcsum
-] [
-.RB [ no ] udp6zerocsumtx
-] [
-.RB [ no ] udp6zerocsumrx
 ]
 
 .in +8
@@ -1230,56 +761,12 @@
 
 .sp
 .BI ttl " TTL"
-- specifies the TTL value to use in outgoing packets. "0" or "auto" means
-use whatever default value, "inherit" means inherit the inner protocol's
-ttl. Default option is "0".
+- specifies the TTL value to use in outgoing packets.
 
 .sp
 .BI tos " TOS"
 - specifies the TOS value to use in outgoing packets.
 
-.sp
-.BI df " DF"
-- specifies the usage of the Don't Fragment flag (DF) bit in outgoing packets
-with IPv4 headers. The value
-.B inherit
-causes the bit to be copied from the original IP header. The values
-.B unset
-and
-.B set
-cause the bit to be always unset or always set, respectively. By default, the
-bit is not set.
-
-.sp
-.BI flowlabel " FLOWLABEL"
-- specifies the flow label to use in outgoing packets.
-
-.sp
-.BI dstport " PORT"
-- select a destination port other than the default of 6081.
-
-.sp
-.RB [ no ] external
-- make this tunnel externally controlled (or not, which is the default). This
-flag is mutually exclusive with the
-.BR id ,
-.BR remote ,
-.BR ttl ,
-.BR tos " and " flowlabel
-options.
-
-.sp
-.RB [ no ] udpcsum
-- specifies if UDP checksum is calculated for transmitted packets over IPv4.
-
-.sp
-.RB [ no ] udp6zerocsumtx
-- skip UDP checksum calculation for transmitted packets over IPv6.
-
-.sp
-.RB [ no ] udp6zerocsumrx
-- allow incoming UDP packets over IPv6 with zero checksum field.
-
 .in -8
 
 .TP
@@ -1293,7 +780,7 @@
 .BI "ip link add link " DEVICE " name " NAME
 .BR type " { " macvlan " | " macvtap " } "
 .BR mode " { " private " | " vepa " | " bridge " | " passthru
-.RB " [ " nopromisc " ] | " source " } "
+.BR " [ " nopromisc " ] } "
 
 .in +8
 .sp
@@ -1330,461 +817,6 @@
 forces the underlying interface into promiscuous mode. Passing the
 .BR nopromisc " flag prevents this, so the promisc flag may be controlled "
 using standard tools.
-
-.B mode source
-- allows one to set a list of allowed mac address, which is used to match
-against source mac address from received frames on underlying interface. This
-allows creating mac based VLAN associations, instead of standard port or tag
-based. The feature is useful to deploy 802.1x mac based behavior,
-where drivers of underlying interfaces doesn't allows that.
-.in -8
-
-.TP
-High-availability Seamless Redundancy (HSR) Support
-For a link of type
-.I HSR
-the following additional arguments are supported:
-
-.BI "ip link add link " DEVICE " name " NAME " type hsr"
-.BI slave1 " SLAVE1-IF " slave2 " SLAVE2-IF "
-.RB [ " supervision"
-.IR ADDR-BYTE " ] ["
-.BR version " { " 0 " | " 1 " } ]"
-
-.in +8
-.sp
-.BR type " hsr "
-- specifies the link type to use, here HSR.
-
-.BI slave1 " SLAVE1-IF "
-- Specifies the physical device used for the first of the two ring ports.
-
-.BI slave2 " SLAVE2-IF "
-- Specifies the physical device used for the second of the two ring ports.
-
-.BI supervision " ADDR-BYTE"
-- The last byte of the multicast address used for HSR supervision frames.
-Default option is "0", possible values 0-255.
-
-.BR version " { " 0 " | " 1 " }"
-- Selects the protocol version of the interface. Default option is "0", which
-corresponds to the 2010 version of the HSR standard. Option "1" activates the
-2012 version.
-.in -8
-
-.TP
-BRIDGE Type Support
-For a link of type
-.I BRIDGE
-the following additional arguments are supported:
-
-.BI "ip link add " DEVICE " type bridge "
-[
-.BI ageing_time " AGEING_TIME "
-] [
-.BI group_fwd_mask " MASK "
-] [
-.BI group_address " ADDRESS "
-] [
-.BI forward_delay " FORWARD_DELAY "
-] [
-.BI hello_time " HELLO_TIME "
-] [
-.BI max_age " MAX_AGE "
-] [
-.BI stp_state " STP_STATE "
-] [
-.BI priority " PRIORITY "
-] [
-.BI vlan_filtering " VLAN_FILTERING "
-] [
-.BI vlan_protocol " VLAN_PROTOCOL "
-] [
-.BI vlan_default_pvid " VLAN_DEFAULT_PVID "
-] [
-.BI vlan_stats_enabled " VLAN_STATS_ENABLED "
-] [
-.BI vlan_stats_per_port " VLAN_STATS_PER_PORT "
-] [
-.BI mcast_snooping " MULTICAST_SNOOPING "
-] [
-.BI mcast_router " MULTICAST_ROUTER "
-] [
-.BI mcast_query_use_ifaddr " MCAST_QUERY_USE_IFADDR "
-] [
-.BI mcast_querier " MULTICAST_QUERIER "
-] [
-.BI mcast_hash_elasticity " HASH_ELASTICITY "
-] [
-.BI mcast_hash_max " HASH_MAX "
-] [
-.BI mcast_last_member_count " LAST_MEMBER_COUNT "
-] [
-.BI mcast_startup_query_count " STARTUP_QUERY_COUNT "
-] [
-.BI mcast_last_member_interval " LAST_MEMBER_INTERVAL "
-] [
-.BI mcast_membership_interval " MEMBERSHIP_INTERVAL "
-] [
-.BI mcast_querier_interval " QUERIER_INTERVAL "
-] [
-.BI mcast_query_interval " QUERY_INTERVAL "
-] [
-.BI mcast_query_response_interval " QUERY_RESPONSE_INTERVAL "
-] [
-.BI mcast_startup_query_interval " STARTUP_QUERY_INTERVAL "
-] [
-.BI mcast_stats_enabled " MCAST_STATS_ENABLED "
-] [
-.BI mcast_igmp_version " IGMP_VERSION "
-] [
-.BI mcast_mld_version " MLD_VERSION "
-] [
-.BI nf_call_iptables " NF_CALL_IPTABLES "
-] [
-.BI nf_call_ip6tables " NF_CALL_IP6TABLES "
-] [
-.BI nf_call_arptables " NF_CALL_ARPTABLES "
-]
-
-.in +8
-.sp
-.BI ageing_time " AGEING_TIME "
-- configure the bridge's FDB entries ageing time, ie the number of
-seconds a MAC address will be kept in the FDB after a packet has been
-received from that address. after this time has passed, entries are
-cleaned up.
-
-.BI group_fwd_mask " MASK "
-- set the group forward mask. This is the bitmask that is applied to
-decide whether to forward incoming frames destined to link-local
-addresses, ie addresses of the form 01:80:C2:00:00:0X (defaults to 0,
-ie the bridge does not forward any link-local frames).
-
-.BI group_address " ADDRESS "
-- set the MAC address of the multicast group this bridge uses for STP.
-The address must be a link-local address in standard Ethernet MAC
-address format, ie an address of the form 01:80:C2:00:00:0X, with X
- in [0, 4..f].
-
-.BI forward_delay " FORWARD_DELAY "
-- set the forwarding delay in seconds, ie the time spent in LISTENING
-state (before moving to LEARNING) and in LEARNING state (before
-moving to FORWARDING). Only relevant if STP is enabled. Valid values
-are between 2 and 30.
-
-.BI hello_time " HELLO_TIME "
-- set the time in seconds between hello packets sent by the bridge,
-when it is a root bridge or a designated bridges.
-Only relevant if STP is enabled. Valid values are between 1 and 10.
-
-.BI max_age " MAX_AGE "
-- set the hello packet timeout, ie the time in seconds until another
-bridge in the spanning tree is assumed to be dead, after reception of
-its last hello message. Only relevant if STP is enabled. Valid values
-are between 6 and 40.
-
-.BI stp_state " STP_STATE "
-- turn spanning tree protocol on
-.RI ( STP_STATE " > 0) "
-or off
-.RI ( STP_STATE " == 0). "
-for this bridge.
-
-.BI priority " PRIORITY "
-- set this bridge's spanning tree priority, used during STP root
-bridge election.
-.I PRIORITY
-is a 16bit unsigned integer.
-
-.BI vlan_filtering " VLAN_FILTERING "
-- turn VLAN filtering on
-.RI ( VLAN_FILTERING " > 0) "
-or off
-.RI ( VLAN_FILTERING " == 0). "
-When disabled, the bridge will not consider the VLAN tag when handling packets.
-
-.BR vlan_protocol " { " 802.1Q " | " 802.1ad " } "
-- set the protocol used for VLAN filtering.
-
-.BI vlan_default_pvid " VLAN_DEFAULT_PVID "
-- set the default PVID (native/untagged VLAN ID) for this bridge.
-
-.BI vlan_stats_enabled " VLAN_STATS_ENABLED "
-- enable
-.RI ( VLAN_STATS_ENABLED " == 1) "
-or disable
-.RI ( VLAN_STATS_ENABLED " == 0) "
-per-VLAN stats accounting.
-
-.BI vlan_stats_per_port " VLAN_STATS_PER_PORT "
-- enable
-.RI ( VLAN_STATS_PER_PORT " == 1) "
-or disable
-.RI ( VLAN_STATS_PER_PORT " == 0) "
-per-VLAN per-port stats accounting. Can be changed only when there are no port VLANs configured.
-
-.BI mcast_snooping " MULTICAST_SNOOPING "
-- turn multicast snooping on
-.RI ( MULTICAST_SNOOPING " > 0) "
-or off
-.RI ( MULTICAST_SNOOPING " == 0). "
-
-.BI mcast_router " MULTICAST_ROUTER "
-- set bridge's multicast router if IGMP snooping is enabled.
-.I MULTICAST_ROUTER
-is an integer value having the following meaning:
-.in +8
-.sp
-.B 0
-- disabled.
-
-.B 1
-- automatic (queried).
-
-.B 2
-- permanently enabled.
-.in -8
-
-.BI mcast_query_use_ifaddr " MCAST_QUERY_USE_IFADDR "
-- whether to use the bridge's own IP address as source address for IGMP queries
-.RI ( MCAST_QUERY_USE_IFADDR " > 0) "
-or the default of 0.0.0.0
-.RI ( MCAST_QUERY_USE_IFADDR " == 0). "
-
-.BI mcast_querier " MULTICAST_QUERIER "
-- enable
-.RI ( MULTICAST_QUERIER " > 0) "
-or disable
-.RI ( MULTICAST_QUERIER " == 0) "
-IGMP querier, ie sending of multicast queries by the bridge (default: disabled).
-
-.BI mcast_querier_interval " QUERIER_INTERVAL "
-- interval between queries sent by other routers. if no queries are seen
-after this delay has passed, the bridge will start to send its own queries
-(as if
-.BI mcast_querier
-was enabled).
-
-.BI mcast_hash_elasticity " HASH_ELASTICITY "
-- set multicast database hash elasticity, ie the maximum chain length
-in the multicast hash table (defaults to 4).
-
-.BI mcast_hash_max " HASH_MAX "
-- set maximum size of multicast hash table (defaults to 512,
-value must be a power of 2).
-
-.BI mcast_last_member_count " LAST_MEMBER_COUNT "
-- set multicast last member count, ie the number of queries the bridge
-will send before stopping forwarding a multicast group after a "leave"
-message has been received (defaults to 2).
-
-.BI mcast_last_member_interval " LAST_MEMBER_INTERVAL "
-- interval between queries to find remaining members of a group,
-after a "leave" message is received.
-
-.BI mcast_startup_query_count " STARTUP_QUERY_COUNT "
-- set the number of IGMP queries to send during startup phase (defaults to 2).
-
-.BI mcast_startup_query_interval " STARTUP_QUERY_INTERVAL "
-- interval between queries in the startup phase.
-
-.BI mcast_query_interval " QUERY_INTERVAL "
-- interval between queries sent by the bridge after the end of the
-startup phase.
-
-.BI mcast_query_response_interval " QUERY_RESPONSE_INTERVAL "
-- set the Max Response Time/Maximum Response Delay for IGMP/MLD
-queries sent by the bridge.
-
-.BI mcast_membership_interval " MEMBERSHIP_INTERVAL "
-- delay after which the bridge will leave a group,
-if no membership reports for this group are received.
-
-.BI mcast_stats_enabled " MCAST_STATS_ENABLED "
-- enable
-.RI ( MCAST_STATS_ENABLED " > 0) "
-or disable
-.RI ( MCAST_STATS_ENABLED " == 0) "
-multicast (IGMP/MLD) stats accounting.
-
-.BI mcast_igmp_version " IGMP_VERSION "
-- set the IGMP version.
-
-.BI mcast_mld_version " MLD_VERSION "
-- set the MLD version.
-
-.BI nf_call_iptables " NF_CALL_IPTABLES "
-- enable
-.RI ( NF_CALL_IPTABLES " > 0) "
-or disable
-.RI ( NF_CALL_IPTABLES " == 0) "
-iptables hooks on the bridge.
-
-.BI nf_call_ip6tables " NF_CALL_IP6TABLES "
-- enable
-.RI ( NF_CALL_IP6TABLES " > 0) "
-or disable
-.RI ( NF_CALL_IP6TABLES " == 0) "
-ip6tables hooks on the bridge.
-
-.BI nf_call_arptables " NF_CALL_ARPTABLES "
-- enable
-.RI ( NF_CALL_ARPTABLES " > 0) "
-or disable
-.RI ( NF_CALL_ARPTABLES " == 0) "
-arptables hooks on the bridge.
-
-
-.in -8
-
-.TP
-MACsec Type Support
-For a link of type
-.I MACsec
-the following additional arguments are supported:
-
-.BI "ip link add link " DEVICE " name " NAME " type macsec"
-[ [
-.BI address " <lladdr>"
-]
-.BI port " PORT"
-|
-.BI sci " SCI"
-] [
-.BI cipher " CIPHER_SUITE"
-] [
-.BR icvlen " { "
-.IR 8..16 " } ] ["
-.BR encrypt " {"
-.BR on " | " off " } ] [ "
-.BR send_sci " { " on " | " off " } ] ["
-.BR end_station " { " on " | " off " } ] ["
-.BR scb " { " on " | " off " } ] ["
-.BR protect " { " on " | " off " } ] ["
-.BR replay " { " on " | " off " }"
-.BR window " { "
-.IR 0..2^32-1 " } ] ["
-.BR validate " { " strict " | " check " | " disabled " } ] ["
-.BR encodingsa " { "
-.IR 0..3 " } ]"
-
-.in +8
-.sp
-.BI address " <lladdr> "
-- sets the system identifier component of secure channel for this MACsec device.
-
-.sp
-.BI port " PORT "
-- sets the port number component of secure channel for this MACsec
-device, in a range from 1 to 65535 inclusive. Numbers with a leading "
-0 " or " 0x " are interpreted as octal and hexadecimal, respectively.
-
-.sp
-.BI sci " SCI "
-- sets the secure channel identifier for this MACsec device.
-.I SCI
-is a 64bit wide number in hexadecimal format.
-
-.sp
-.BI cipher " CIPHER_SUITE "
-- defines the cipher suite to use.
-
-.sp
-.BI icvlen " LENGTH "
-- sets the length of the Integrity Check Value (ICV).
-
-.sp
-.BR "encrypt on " or " encrypt off"
-- switches between authenticated encryption, or authenticity mode only.
-
-.sp
-.BR "send_sci on " or " send_sci off"
-- specifies whether the SCI is included in every packet,
-or only when it is necessary.
-
-.sp
-.BR "end_station on " or " end_station off"
-- sets the End Station bit.
-
-.sp
-.BR "scb on " or " scb off"
-- sets the Single Copy Broadcast bit.
-
-.sp
-.BR "protect on " or " protect off"
-- enables MACsec protection on the device.
-
-.sp
-.BR "replay on " or " replay off"
-- enables replay protection on the device.
-
-.in +8
-
-.sp
-.BI window " SIZE "
-- sets the size of the replay window.
-
-.in -8
-
-.sp
-.BR "validate strict " or " validate check " or " validate disabled"
-- sets the validation mode on the device.
-
-.sp
-.BI encodingsa " AN "
-- sets the active secure association for transmission.
-
-.in -8
-
-.TP
-VRF Type Support
-For a link of type
-.I VRF
-the following additional arguments are supported:
-
-.BI "ip link add " DEVICE " type vrf table " TABLE
-
-.in +8
-.sp
-.BR table " table id associated with VRF device"
-
-.in -8
-
-.TP
-RMNET Type Support
-For a link of type
-.I RMNET
-the following additional arguments are supported:
-
-.BI "ip link add link " DEVICE " name " NAME " type rmnet mux_id " MUXID
-
-.in +8
-.sp
-.BI mux_id " MUXID "
-- specifies the mux identifier for the rmnet device, possible values 1-254.
-
-.in -8
-
-.TP
-XFRM Type Support
-For a link of type
-.I XFRM
-the following additional arguments are supported:
-
-.BI "ip link add " DEVICE " type xfrm dev " PHYS_DEV " [ if_id " IF_ID " ]"
-
-.in +8
-.sp
-.BI dev " PHYS_DEV "
-- specifies the underlying physical interface from which transform traffic is sent and received.
-
-.sp
-.BI if_id " IF-ID "
-- specifies the hexadecimal lookup key used to send traffic to and from specific xfrm
-policies. Policies must be configured with the same key. If not set, the key defaults to
-0 and will match any policies which similarly do not have a lookup key configuration.
-
 .in -8
 
 .SS ip link delete - delete virtual link
@@ -1804,29 +836,12 @@
 
 .SS ip link set - change device attributes
 
-.PP
-.B Warning:
-If multiple parameter changes are requested,
-.B ip
-aborts immediately after any of the changes have failed.
-This is the only case when
-.B ip
-can move the system to an unpredictable state. The solution
-is to avoid changing several parameters with one
-.B ip link set
-call.
-The modifier
-.B change
-is equivalent to
-.BR "set" .
-
-
 .TP
 .BI dev " DEVICE "
 .I DEVICE
-specifies network device to operate on. When configuring SR-IOV
-Virtual Function (VF) devices, this keyword should specify the
-associated Physical Function (PF) device.
+specifies network device to operate on. When configuring SR-IOV Virtual Function
+(VF) devices, this keyword should specify the associated Physical Function (PF)
+device.
 
 .TP
 .BI group " GROUP "
@@ -1858,16 +873,13 @@
 .BR "protodown on " or " protodown off"
 change the
 .B PROTODOWN
-state on the device. Indicates that a protocol error has been detected
-on the port. Switch drivers can react to this error by doing a phys
-down on the switch port.
+state on the device. Indicates that a protocol error has been detected on the port. Switch drivers can react to this error by doing a phys down on the switch port.
 
 .TP
 .BR "dynamic on " or " dynamic off"
 change the
 .B DYNAMIC
-flag on the device. Indicates that address can change when interface
-goes down (currently
+flag on the device. Indicates that address can change when interface goes down (currently
 .B NOT
 used by the Linux).
 
@@ -1910,10 +922,10 @@
 .RI process " PID".
 
 Some devices are not allowed to change network namespace: loopback, bridge,
-wireless. These are network namespace local devices. In such case
+ppp, wireless. These are network namespace local devices. In such case
 .B ip
-tool will return "Invalid argument" error. It is possible to find out
-if device is local to a single network namespace by checking
+tool will return "Invalid argument" error. It is possible to find out if device is local
+to a single network namespace by checking
 .B netns-local
 flag in the output of the
 .BR ethtool ":"
@@ -1925,8 +937,7 @@
 
 To change network namespace for wireless devices the
 .B iw
-tool can be used. But it allows to change network namespace only for
-physical devices and by process
+tool can be used. But it allows to change network namespace only for physical devices and by process
 .IR PID .
 
 .TP
@@ -1977,20 +988,6 @@
 as 0 disables VLAN tagging and filtering for the VF.
 
 .sp
-.BI proto " VLAN-PROTO"
-- assign VLAN PROTOCOL for the VLAN tag, either 802.1Q or 802.1ad.
-Setting to 802.1ad, all traffic sent from the VF will be tagged with
-VLAN S-Tag.  Incoming traffic will have VLAN S-Tags stripped before
-being passed to the VF.  Setting to 802.1ad also enables an option to
-concatenate another VLAN tag, so both S-TAG and C-TAG will be
-inserted/stripped for outgoing/incoming traffic, respectively.  If not
-specified, the value is assumed to be 802.1Q. Both the
-.B vf
-and
-.B vlan
-parameters must be specified.
-
-.sp
 .BI rate " TXRATE"
 -- change the allowed transmit bandwidth, in Mbps, for the specified VF.
 Setting this parameter to 0 disables rate limiting.
@@ -2002,8 +999,7 @@
 
 .sp
 .BI max_tx_rate " TXRATE"
-- change the allowed maximum transmit bandwidth, in Mbps, for the
-specified VF.  Setting this parameter to 0 disables rate limiting.
+- change the allowed maximum transmit bandwidth, in Mbps, for the specified VF.
 .B vf
 parameter must be specified.
 
@@ -2011,7 +1007,6 @@
 .BI min_tx_rate " TXRATE"
 - change the allowed minimum transmit bandwidth, in Mbps, for the specified VF.
 Minimum TXRATE should be always <= Maximum TXRATE.
-Setting this parameter to 0 disables rate limiting.
 .B vf
 parameter must be specified.
 
@@ -2019,111 +1014,14 @@
 .BI spoofchk " on|off"
 - turn packet spoof checking on or off for the specified VF.
 .sp
-.BI query_rss " on|off"
-- toggle the ability of querying the RSS configuration of a specific
-  VF. VF RSS information like RSS hash key may be considered sensitive
-  on some devices where this information is shared between VF and PF
-  and thus its querying may be prohibited by default.
-.sp
 .BI state " auto|enable|disable"
-- set the virtual link state as seen by the specified VF. Setting to
-auto means a reflection of the PF link state, enable lets the VF to
-communicate with other VFs on this host even if the PF link state is
-down, disable causes the HW to drop any packets sent by the VF.
-.sp
-.BI trust " on|off"
-- trust the specified VF user. This enables that VF user can set a
-specific feature which may impact security and/or
-performance. (e.g. VF multicast promiscuous mode)
-.sp
-.BI node_guid " eui64"
-- configure node GUID for Infiniband VFs.
-.sp
-.BI port_guid " eui64"
-- configure port GUID for Infiniband VFs.
+- set the virtual link state as seen by the specified VF. Setting to auto means a
+reflection of the PF link state, enable lets the VF to communicate with other VFs on
+this host even if the PF link state is down, disable causes the HW to drop any packets
+sent by the VF.
 .in -8
 
 .TP
-.B xdp object "|" pinned "|" off
-set (or unset) a XDP ("eXpress Data Path") BPF program to run on every
-packet at driver level.
-.B ip link
-output will indicate a
-.B xdp
-flag for the networking device. If the driver does not have native XDP
-support, the kernel will fall back to a slower, driver-independent "generic"
-XDP variant. The
-.B ip link
-output will in that case indicate
-.B xdpgeneric
-instead of
-.B xdp
-only. If the driver does have native XDP support, but the program is
-loaded under
-.B xdpgeneric object "|" pinned
-then the kernel will use the generic XDP variant instead of the native one.
-.B xdpdrv
-has the opposite effect of requestsing that the automatic fallback to the
-generic XDP variant be disabled and in case driver is not XDP-capable error
-should be returned.
-.B xdpdrv
-also disables hardware offloads.
-.B xdpoffload
-in ip link output indicates that the program has been offloaded to hardware
-and can also be used to request the "offload" mode, much like
-.B xdpgeneric
-it forces program to be installed specifically in HW/FW of the apater.
-
-.B off
-(or
-.B none
-)
-- Detaches any currently attached XDP/BPF program from the given device.
-
-.BI object " FILE "
-- Attaches a XDP/BPF program to the given device. The
-.I FILE
-points to a BPF ELF file (f.e. generated by LLVM) that contains the BPF
-program code, map specifications, etc. If a XDP/BPF program is already
-attached to the given device, an error will be thrown. If no XDP/BPF
-program is currently attached, the device supports XDP and the program
-from the BPF ELF file passes the kernel verifier, then it will be attached
-to the device. If the option
-.I -force
-is passed to
-.B ip
-then any prior attached XDP/BPF program will be atomically overridden and
-no error will be thrown in this case. If no
-.B section
-option is passed, then the default section name ("prog") will be assumed,
-otherwise the provided section name will be used. If no
-.B verbose
-option is passed, then a verifier log will only be dumped on load error.
-See also
-.B EXAMPLES
-section for usage examples.
-
-.BI section " NAME "
-- Specifies a section name that contains the BPF program code. If no section
-name is specified, the default one ("prog") will be used. This option is
-to be passed with the
-.B object
-option.
-
-.BI verbose
-- Act in verbose mode. For example, even in case of success, this will
-print the verifier log in case a program was loaded from a BPF ELF file.
-
-.BI pinned " FILE "
-- Attaches a XDP/BPF program to the given device. The
-.I FILE
-points to an already pinned BPF program in the BPF file system. The option
-.B section
-doesn't apply here, but otherwise semantics are the same as with the option
-.B object
-described already.
-
-.TP
 .BI master " DEVICE"
 set master device of the device (enslave device).
 
@@ -2142,8 +1040,7 @@
 - disable automatic address generation
 
 .I stable_secret
-- generate the interface identifier based on a preset
-  /proc/sys/net/ipv6/conf/{default,DEVICE}/stable_secret
+- generate the interface identifier based on a preset /proc/sys/net/ipv6/conf/{default,DEVICE}/stable_secret
 
 .I random
 - like stable_secret, but auto-generate a new random secret if none is set
@@ -2152,211 +1049,17 @@
 .BR "link-netnsid "
 set peer netnsid for a cross-netns interface
 
-.TP
-.BI type " ETYPE TYPE_ARGS"
-Change type-specific settings. For a list of supported types and arguments refer
-to the description of
-.B "ip link add"
-above. In addition to that, it is possible to manipulate settings to slave
-devices:
-
-.TP
-Bridge Slave Support
-For a link with master
-.B bridge
-the following additional arguments are supported:
-
-.B "ip link set type bridge_slave"
-[
-.B fdb_flush
-] [
-.BI state " STATE"
-] [
-.BI priority " PRIO"
-] [
-.BI cost " COST"
-] [
-.BR guard " { " on " | " off " }"
-] [
-.BR hairpin " { " on " | " off " }"
-] [
-.BR fastleave " { " on " | " off " }"
-] [
-.BR root_block " { " on " | " off " }"
-] [
-.BR learning " { " on " | " off " }"
-] [
-.BR flood " { " on " | " off " }"
-] [
-.BR proxy_arp " { " on " | " off " }"
-] [
-.BR proxy_arp_wifi " { " on " | " off " }"
-] [
-.BI mcast_router " MULTICAST_ROUTER"
-] [
-.BR mcast_fast_leave " { " on " | " off "}"
-] [
-.BR mcast_flood " { " on " | " off " }"
-] [
-.BR mcast_to_unicast " { " on " | " off " }"
-] [
-.BR group_fwd_mask " MASK"
-] [
-.BR neigh_suppress " { " on " | " off " }"
-] [
-.BR vlan_tunnel " { " on " | " off " }"
-] [
-.BR isolated " { " on " | " off " }"
-] [
-.BR backup_port " DEVICE"
-] [
-.BR nobackup_port " ]"
-
-.in +8
-.sp
-.B fdb_flush
-- flush bridge slave's fdb dynamic entries.
-
-.BI state " STATE"
-- Set port state.
-.I STATE
-is a number representing the following states:
-.BR 0 " (disabled),"
-.BR 1 " (listening),"
-.BR 2 " (learning),"
-.BR 3 " (forwarding),"
-.BR 4 " (blocking)."
-
-.BI priority " PRIO"
-- set port priority (allowed values are between 0 and 63, inclusively).
-
-.BI cost " COST"
-- set port cost (allowed values are between 1 and 65535, inclusively).
-
-.BR guard " { " on " | " off " }"
-- block incoming BPDU packets on this port.
-
-.BR hairpin " { " on " | " off " }"
-- enable hairpin mode on this port. This will allow incoming packets on this
-port to be reflected back.
-
-.BR fastleave " { " on " | " off " }"
-- enable multicast fast leave on this port.
-
-.BR root_block " { " on " | " off " }"
-- block this port from becoming the bridge's root port.
-
-.BR learning " { " on " | " off " }"
-- allow MAC address learning on this port.
-
-.BR flood " { " on " | " off " }"
-- open the flood gates on this port, i.e. forward all unicast frames to this
-port also. Requires
-.BR proxy_arp " and " proxy_arp_wifi
-to be turned off.
-
-.BR proxy_arp " { " on " | " off " }"
-- enable proxy ARP on this port.
-
-.BR proxy_arp_wifi " { " on " | " off " }"
-- enable proxy ARP on this port which meets extended requirements by IEEE
-802.11 and Hotspot 2.0 specifications.
-
-.BI mcast_router " MULTICAST_ROUTER"
-- configure this port for having multicast routers attached. A port with a
-multicast router will receive all multicast traffic.
-.I MULTICAST_ROUTER
-may be either
-.B 0
-to disable multicast routers on this port,
-.B 1
-to let the system detect the presence of of routers (this is the default),
-.B 2
-to permanently enable multicast traffic forwarding on this port or
-.B 3
-to enable multicast routers temporarily on this port, not depending on incoming
-queries.
-
-.BR mcast_fast_leave " { " on " | " off " }"
-- this is a synonym to the
-.B fastleave
-option above.
-
-.BR mcast_flood " { " on " | " off " }"
-- controls whether a given port will flood multicast traffic for which
-  there is no MDB entry.
-
-.BR mcast_to_unicast " { " on " | " off " }"
-- controls whether a given port will replicate packets using unicast
-  instead of multicast. By default this flag is off.
-
-.BI group_fwd_mask " MASK "
-- set the group forward mask. This is the bitmask that is applied to
-decide whether to forward incoming frames destined to link-local
-addresses, ie addresses of the form 01:80:C2:00:00:0X (defaults to
-0, ie the bridge does not forward any link-local frames coming on
-this port).
-
-.BR neigh_suppress " { " on " | " off " }"
-- controls whether neigh discovery (arp and nd) proxy and suppression
-is enabled on the port. By default this flag is off.
-
-.BR vlan_tunnel " { " on " | " off " }"
-- controls whether vlan to tunnel mapping is enabled on the port. By
-default this flag is off.
-
-.BI backup_port " DEVICE"
-- if the port loses carrier all traffic will be redirected to the
-configured backup port
-
-.BR nobackup_port
-- removes the currently configured backup port
-
-.in -8
-
-.TP
-Bonding Slave Support
-For a link with master
-.B bond
-the following additional arguments are supported:
-
-.B "ip link set type bond_slave"
-[
-.BI queue_id " ID"
-]
-
-.in +8
-.sp
-.BI queue_id " ID"
-- set the slave's queue ID (a 16bit unsigned value).
-
-.in -8
-
-.TP
-MACVLAN and MACVTAP Support
-Modify list of allowed macaddr for link in source mode.
-
-.B "ip link set type { macvlan | macvap } "
-[
-.BI macaddr " " "" COMMAND " " MACADDR " ..."
-]
-
-Commands:
-.in +8
-.B add
-- add MACADDR to allowed list
-.sp
-.B set
-- replace allowed list
-.sp
-.B del
-- remove MACADDR from allowed list
-.sp
-.B flush
-- flush whole allowed list
-.sp
-.in -8
-
+.PP
+.B Warning:
+If multiple parameter changes are requested,
+.B ip
+aborts immediately after any of the changes have failed.
+This is the only case when
+.B ip
+can move the system to an unpredictable state. The solution
+is to avoid changing several parameters with one
+.B ip link set
+call.
 
 .SS  ip link show - display device attributes
 
@@ -2364,6 +1067,7 @@
 .BI dev " NAME " (default)
 .I NAME
 specifies the network device to show.
+If this argument is omitted all devices in the default group are listed.
 
 .TP
 .BI group " GROUP "
@@ -2380,34 +1084,30 @@
 specifies the master device which enslaves devices to show.
 
 .TP
-.BI vrf " NAME "
-.I NAME
-speficies the VRF which enslaves devices to show.
-
-.TP
 .BI type " TYPE "
 .I TYPE
 specifies the type of devices to show.
 
-Note that the type name is not checked against the list of supported types -
-instead it is sent as-is to the kernel. Later it is used to filter the returned
-interface list by comparing it with the relevant attribute in case the kernel
-didn't filter already. Therefore any string is accepted, but may lead to empty
-output.
+.TP
+The show command has additional formatting options:
 
-.SS  ip link xstats - display extended statistics
+.RS
+.TP
+.BR "\-s" , " \-stats", " \-statistics"
+output more statistics about packet usage.
 
 .TP
-.BI type " TYPE "
-.I TYPE
-specifies the type of devices to display extended statistics for.
-
-.SS  ip link afstats - display address-family specific statistics
+.BR "\-d", " \-details"
+output more detailed information.
 
 .TP
-.BI dev " DEVICE "
-.I DEVICE
-specifies the device to display address-family statistics for.
+.BR "\-h", " \-human", " \-human-readable"
+output statistics with human readable values number followed by suffix
+
+.TP
+.BR "\-iec"
+print human readable rates in IEC units (ie. 1K = 1024).
+.RE
 
 .SS  ip link help - display help
 
@@ -2469,33 +1169,7 @@
 .RS 4
 Creates an IPIP that is encapsulated with Generic UDP Encapsulation,
 and the outer UDP checksum and remote checksum offload are enabled.
-.RE
-.PP
-ip link set dev eth0 xdp obj prog.o
-.RS 4
-Attaches a XDP/BPF program to device eth0, where the program is
-located in prog.o, section "prog" (default section). In case a
-XDP/BPF program is already attached, throw an error.
-.RE
-.PP
-ip -force link set dev eth0 xdp obj prog.o sec foo
-.RS 4
-Attaches a XDP/BPF program to device eth0, where the program is
-located in prog.o, section "foo". In case a XDP/BPF program is
-already attached, it will be overridden by the new one.
-.RE
-.PP
-ip -force link set dev eth0 xdp pinned /sys/fs/bpf/foo
-.RS 4
-Attaches a XDP/BPF program to device eth0, where the program was
-previously pinned as an object node into BPF file system under
-name foo.
-.RE
-.PP
-ip link set dev eth0 xdp off
-.RS 4
-If a XDP/BPF program is attached on device eth0, detach it and
-effectively turn off XDP for device eth0.
+
 .RE
 .PP
 ip link add link wpan0 lowpan0 type lowpan
@@ -2503,13 +1177,6 @@
 Creates a 6LoWPAN interface named lowpan0 on the underlying
 IEEE 802.15.4 device wpan0.
 .RE
-.PP
-ip link add dev ip6erspan11 type ip6erspan seq key 102
-local fc00:100::2 remote fc00:100::1
-erspan_ver 2 erspan_dir ingress erspan_hwid 17
-.RS 4
-Creates a IP6ERSPAN version 2 interface named ip6erspan00.
-.RE
 
 .SH SEE ALSO
 .br
diff --git a/man/man8/ip-macsec.8 b/man/man8/ip-macsec.8
deleted file mode 100644
index 2179b33..0000000
--- a/man/man8/ip-macsec.8
+++ /dev/null
@@ -1,120 +0,0 @@
-.TH IP\-MACSEC 8 "07 Mar 2016" "iproute" "Linux"
-.SH NAME
-ip-macsec \- MACsec device configuration
-.SH "SYNOPSIS"
-.BI "ip link add link " DEVICE " name " NAME " type macsec "
-[ [
-.BI address " <lladdr>"
-]
-.BI port " PORT"
-|
-.BI sci " <u64>"
-] [
-.BR cipher " { " default " | " gcm-aes-128 " | "gcm-aes-256" } ] ["
-.BI icvlen " ICVLEN"
-] [
-.BR encrypt " { " on " | " off " } ] ["
-.BR send_sci " { " on " | " off " } ] ["
-.BR end_station " { " on " | " off " } ] ["
-.BR scb " { " on " | " off " } ] ["
-.BR protect " { " on " | " off " } ] ["
-.BR replay " { " on " | " off " } ] ["
-.BI window " WINDOW"
-] [
-.BR validate " { " strict " | " check " | " disabled " } ] ["
-.BI encodingsa " SA"
-]
-
-.BI "ip macsec add " DEV " tx sa"
-.RI "{ " 0..3 " } [ " OPTS " ]"
-.BI key " ID KEY"
-.br
-.BI "ip macsec set " DEV " tx sa"
-.RI "{ " 0..3 " } [ " OPTS " ]"
-.br
-.BI "ip macsec del " DEV " tx sa"
-.RI "{ " 0..3 " }"
-
-.BI "ip macsec add " DEV " rx " SCI
-.RB [ " on " | " off " ]
-.br
-.BI "ip macsec set " DEV " rx " SCI
-.RB [ " on " | " off " ]
-.br
-.BI "ip macsec del " DEV " rx " SCI
-
-.BI "ip macsec add " DEV " rx " SCI " sa"
-.RI "{ " 0..3 " } [ " OPTS " ]"
-.BI key " ID KEY"
-.br
-.BI "ip macsec set " DEV " rx " SCI " sa"
-.RI "{ " 0..3 " } [ " OPTS " ]"
-.br
-.BI "ip macsec del " DEV " rx " SCI " sa"
-.RI "{ " 0..3 " }"
-
-.B ip macsec show
-.RI [ " DEV " ]
-
-.IR OPTS " := [ "
-.BR pn " { "
-.IR 1..2^32-1 " } ] ["
-.BR on " | " off " ]"
-.br
-.IR SCI " := { "
-.B sci
-.IR <u64> " | "
-.BI port
-.IR PORT
-.BI address " <lladdr> "
-}
-.br
-.IR PORT " := { " 1..2^16-1 " } "
-
-
-.SH DESCRIPTION
-The
-.B ip macsec
-commands are used to configure transmit secure associations and receive secure channels and their secure associations on a MACsec device created with the
-.B ip link add
-command using the
-.I macsec
-type.
-
-.SH EXAMPLES
-.PP
-.SS Create a MACsec device on link eth0
-.nf
-# ip link add link eth0 macsec0 type macsec port 11 encrypt on
-.PP
-.SS Configure a secure association on that device
-.nf
-# ip macsec add macsec0 tx sa 0 pn 1024 on key 01 81818181818181818181818181818181
-.PP
-.SS Configure a receive channel
-.nf
-# ip macsec add macsec0 rx port 1234 address c6:19:52:8f:e6:a0
-.PP
-.SS Configure a receive association
-.nf
-# ip macsec add macsec0 rx port 1234 address c6:19:52:8f:e6:a0 sa 0 pn 1 on key 00 82828282828282828282828282828282
-.PP
-.SS Display MACsec configuration
-.nf
-# ip macsec show
-
-.SH NOTES
-This tool can be used to configure the 802.1AE keys of the interface. Note that 802.1AE uses GCM-AES
-with a initialization vector (IV) derived from the packet number. The same key must not be used
-with the same IV more than once. Instead, keys must be frequently regenerated and distibuted.
-This tool is thus mostly for debugging and testing, or in combination with a user-space application
-that reconfigures the keys. It is wrong to just configure the keys statically and assume them to work
-indefinitely. The suggested and standardized way for key management is 802.1X-2010, which is implemented
-by wpa_supplicant.
-
-.SH SEE ALSO
-.br
-.BR ip-link (8)
-.BR wpa_supplicant (8)
-.SH AUTHOR
-Sabrina Dubroca <sd@queasysnail.net>
diff --git a/man/man8/ip-monitor.8 b/man/man8/ip-monitor.8
index 86f8f98..d2bd381 100644
--- a/man/man8/ip-monitor.8
+++ b/man/man8/ip-monitor.8
@@ -6,7 +6,9 @@
 .ad l
 .in +8
 .ti -8
-.BR "ip monitor" " [ " all " |"
+.BR "ip " " [ "
+.IR ip-OPTIONS " ]"
+.BR  "monitor" " [ " all " |"
 .IR OBJECT-LIST " ] ["
 .BI file " FILENAME "
 ] [
diff --git a/man/man8/ip-mroute.8 b/man/man8/ip-mroute.8
index b64e30d..e89b6b2 100644
--- a/man/man8/ip-mroute.8
+++ b/man/man8/ip-mroute.8
@@ -6,7 +6,7 @@
 .ad l
 .in +8
 .ti -8
-.BR "ip mroute show" " [ [ "
+.BR "ip " " [ ip-OPTIONS ] " "mroute show" " [ [ "
 .BR " to " " ] "
 .IR PREFIX " ] [ "
 .B  from
diff --git a/man/man8/ip-neighbour.8 b/man/man8/ip-neighbour.8
index 4a672bb..c9b0256 100644
--- a/man/man8/ip-neighbour.8
+++ b/man/man8/ip-neighbour.8
@@ -18,14 +18,10 @@
 .IR ADDR " [ "
 .B  lladdr
 .IR LLADDR " ] [ "
-.B nud
-.IR STATE " ] |"
-.B proxy
+.BR nud " { " permanent " | " noarp " | " stale " | " reachable " } ] | " proxy
 .IR ADDR " } [ "
 .B  dev
-.IR DEV " ] [ "
-.BR router " ] [ "
-.BR extern_learn " ]"
+.IR DEV " ]"
 
 .ti -8
 .BR "ip neigh" " { " show " | " flush " } [ " proxy " ] [ " to
@@ -33,14 +29,8 @@
 .B  dev
 .IR DEV " ] [ "
 .B  nud
-.IR STATE " ] [ "
-.B  vrf
-.IR NAME " ] "
+.IR STATE " ]"
 
-.ti -8
-.IR STATE " := {"
-.BR permanent " | " noarp " | " stale " | " reachable " | " none " |"
-.BR incomplete " | " delay " | " probe " | " failed " }"
 
 .SH DESCRIPTION
 The
@@ -78,20 +68,6 @@
 the interface to which this neighbour is attached.
 
 .TP
-.BI proxy
-indicates whether we are proxying for this neigbour entry
-
-.TP
-.BI router
-indicates whether neigbour is a router
-
-.TP
-.BI extern_learn
-this neigh entry was learned externally. This option can be used to
-indicate to the kernel that this is a controller learnt dynamic entry.
-Kernel will not gc such an entry.
-
-.TP
 .BI lladdr " LLADDRESS"
 the link layer address of the neighbour.
 .I LLADDRESS
@@ -99,13 +75,12 @@
 .BR "null" .
 
 .TP
-.BI nud " STATE"
+.BI nud " NUD_STATE"
 the state of the neighbour entry.
 .B nud
 is an abbreviation for 'Neighbour Unreachability Detection'.
 The state can take one of the following values:
 
-.RS
 .TP
 .B permanent
 the neighbour entry is valid forever and can be only
@@ -125,24 +100,6 @@
 .B ip neigh
 does not change the neighbour state if it was valid and the address
 is not changed by this command.
-.TP
-.B none
-this is a pseudo state used when initially creating a neighbour entry or after
-trying to remove it before it becomes free to do so.
-.TP
-.B incomplete
-the neighbour entry has not (yet) been validated/resolved.
-.TP
-.B delay
-neighbor entry validation is currently delayed.
-.TP
-.B probe
-neighbor is being probed.
-.TP
-.B failed
-max number of probes exceeded without success, neighbor validation has
-ultimately failed.
-.RE
 .RE
 
 .TP
@@ -182,10 +139,6 @@
 only list the neighbours attached to this device.
 
 .TP
-.BI vrf " NAME"
-only list the neighbours for given VRF.
-
-.TP
 .BI proxy
 list neighbour proxies.
 
@@ -194,7 +147,7 @@
 only list neighbours which are not currently in use.
 
 .TP
-.BI nud " STATE"
+.BI nud " NUD_STATE"
 only list neighbour entries in this state.
 .I NUD_STATE
 takes values listed below or the special value
diff --git a/man/man8/ip-netconf.8 b/man/man8/ip-netconf.8
index 7fe3e5f..2718258 100644
--- a/man/man8/ip-netconf.8
+++ b/man/man8/ip-netconf.8
@@ -15,7 +15,7 @@
 .B ip netconf
 utility can monitor IPv4 and IPv6 parameters (see
 .BR "/proc/sys/net/ipv[4|6]/conf/[all|DEV]/" ")"
-like forwarding, rp_filter, proxy_neigh, ignore_routes_with_linkdown
+like forwarding, rp_filter
 or mc_forwarding status.
 
 If no interface is specified, the entry
diff --git a/man/man8/ip-netns.8 b/man/man8/ip-netns.8
index c75917d..c9b0fbc 100644
--- a/man/man8/ip-netns.8
+++ b/man/man8/ip-netns.8
@@ -13,28 +13,21 @@
 .BR help " }"
 .sp
 .ti -8
-.BR "ip netns" " [ " list " ]"
+.BR "ip netns" " { " list " } "
 
 .ti -8
 .B ip netns add
 .I NETNSNAME
 
 .ti -8
-.B ip netns attach
-.I NETNSNAME PID
-
-.ti -8
 .B ip [-all] netns del
 .RI "[ " NETNSNAME " ]"
 
 .ti -8
-.B ip netns set
+.BR "ip netns" " { " set " } "
 .I NETNSNAME NETNSID
 
 .ti -8
-.IR NETNSID " := " auto " | " POSITIVE-INT
-
-.ti -8
 .BR "ip netns identify"
 .RI "[ " PID " ]"
 
@@ -51,7 +44,6 @@
 
 .ti -8
 .BR "ip netns list-id"
-.RI "[ target-nsid " POSITIVE-INT " ] [ nsid " POSITIVE-INT " ]"
 
 .SH DESCRIPTION
 A network namespace is logically another copy of the network stack,
@@ -98,12 +90,6 @@
 network namespace and assigns NAME.
 
 .TP
-.B ip netns attach NAME PID - create a new named network namespace
-.sp
-If NAME is available in /var/run/netns/ this command attaches the network
-namespace of the process PID to NAME as if it were created with ip netns.
-
-.TP
 .B ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)
 .sp
 If NAME is present in /var/run/netns it is umounted and the mount
@@ -151,7 +137,6 @@
 .sp
 This command assigns a id to a peer network namespace. This id is valid
 only in the current network namespace.
-If the keyword "auto" is specified an available nsid will be chosen.
 This id will be used by the kernel in some netlink messages. If no id is
 assigned when the kernel needs it, it will be automatically assigned by
 the kernel.
@@ -197,28 +182,12 @@
 and prints a line for each event it sees.
 
 .TP
-.B ip netns list-id [target-nsid POSITIVE-INT] [nsid POSITIVE-INT] - list network namespace ids (nsid)
+.B ip netns list-id - list network namespace ids (nsid)
 .sp
 Network namespace ids are used to identify a peer network namespace. This
-command displays nsids of the current network namespace and provides the
+command displays nsid of the current network namespace and provides the
 corresponding iproute2 netns name (from /var/run/netns) if any.
 
-The
-.B target-nsid
-option enables to display nsids of the specified network namespace instead of the current network
-namespace. This
-.B target-nsid
-is a nsid from the current network namespace.
-
-The
-.B nsid
-option enables to display only this nsid. It is a nsid from the current network namespace. In
-combination with the
-.B target-nsid
-option, it enables to convert a specific nsid from the current network namespace to a nsid of the
-.B target-nsid
-network namespace.
-
 .SH EXAMPLES
 .PP
 ip netns list
@@ -235,31 +204,6 @@
 .RS
 Bring up the loopback interface in the vpn network namespace.
 .RE
-.PP
-ip netns add foo
-.br
-ip netns add bar
-.br
-ip netns set foo 12
-.br
-ip netns set bar 13
-.br
-ip -n foo netns set foo 22
-.br
-ip -n foo netns set bar 23
-.br
-ip -n bar netns set foo 32
-.br
-ip -n bar netns set bar 33
-.br
-ip netns list-id target-nsid 12
-.RS
-Shows the list of nsids from the network namespace foo.
-.RE
-ip netns list-id target-nsid 12 nsid 13
-.RS
-Get nsid of bar from the network namespace foo (result is 23).
-.RE
 
 .SH SEE ALSO
 .br
@@ -267,5 +211,3 @@
 
 .SH AUTHOR
 Original Manpage by Eric W. Biederman
-.br
-Manpage revised by Nicolas Dichtel <nicolas.dichtel@6wind.com>
diff --git a/man/man8/ip-nexthop.8 b/man/man8/ip-nexthop.8
deleted file mode 100644
index da87ca3..0000000
--- a/man/man8/ip-nexthop.8
+++ /dev/null
@@ -1,196 +0,0 @@
-.TH IP\-NEXTHOP 8 "30 May 2019" "iproute2" "Linux"
-.SH "NAME"
-ip-nexthop \- nexthop object management
-.SH "SYNOPSIS"
-.sp
-.ad l
-.in +8
-.ti -8
-.B ip
-.RI "[ " ip-OPTIONS " ]"
-.B nexthop
-.RI " { " COMMAND " | "
-.BR help " }"
-.sp
-.ti -8
-
-.ti -8
-.BR "ip nexthop" " { "
-.BR show " | " flush " } "
-.I  SELECTOR
-
-.ti -8
-.BR "ip nexthop" " { " add " | " replace " } id "
-.I ID
-.IR  NH
-
-.ti -8
-.BR "ip nexthop" " { " get " | " del " } id "
-.I  ID
-
-.ti -8
-.IR SELECTOR " := "
-.RB "[ " id
-.IR ID " ] [ "
-.B  dev
-.IR DEV " ] [ "
-.B  vrf
-.IR NAME " ] [ "
-.B  master
-.IR DEV " ] [ "
-.BR  groups " ] "
-
-.ti -8
-.IR NH " := { "
-.BR blackhole " | [ "
-.B  via
-.IR ADDRESS " ] [ "
-.B  dev
-.IR DEV " ] [ "
-.BR onlink " ] [ "
-.B encap
-.IR ENCAP " ] | "
-.B  group
-.IR GROUP " } "
-
-.ti -8
-.IR ENCAP " := [ "
-.IR ENCAP_MPLS " ] "
-
-.ti -8
-.IR ENCAP_MPLS " := "
-.BR mpls " [ "
-.IR LABEL " ] ["
-.B  ttl
-.IR TTL " ]"
-
-.ti -8
-.IR GROUP " := "
-.BR id "[," weight "[/...]"
-
-.SH DESCRIPTION
-.B ip nexthop
-is used to manipulate entries in the kernel's nexthop tables.
-.TP
-ip nexthop add id ID
-add new nexthop entry
-.TP
-ip nexthop replace id ID
-change the configuration of a nexthop or add new one
-.RS
-.TP
-.BI via " [ FAMILY ] ADDRESS"
-the address of the nexthop router, in the address family FAMILY.
-Address family must match address family of nexthop instance.
-.TP
-.BI dev " NAME"
-is the output device.
-.TP
-.B onlink
-pretend that the nexthop is directly attached to this link,
-even if it does not match any interface prefix.
-.TP
-.BI encap " ENCAPTYPE ENCAPHDR"
-attach tunnel encapsulation attributes to this route.
-.sp
-.I ENCAPTYPE
-is a string specifying the supported encapsulation type. Namely:
-
-.in +8
-.BI mpls
-- encapsulation type MPLS
-.sp
-.in -8
-.I ENCAPHDR
-is a set of encapsulation attributes specific to the
-.I ENCAPTYPE.
-
-.in +8
-.B mpls
-.in +2
-.I MPLSLABEL
-- mpls label stack with labels separated by
-.I "/"
-.sp
-
-.B ttl
-.I TTL
-- TTL to use for MPLS header or 0 to inherit from IP header
-.in -2
-
-.TP
-.BI group " GROUP"
-create a nexthop group. Group specification is id with an optional
-weight (id,weight) and a '/' as a separator between entries.
-.TP
-.B blackhole
-create a blackhole nexthop
-.RE
-
-.TP
-ip nexthop delete id ID
-delete nexthop with given id.
-.RE
-
-.TP
-ip nexthop show
-show the contents of the nexthop table or the nexthops
-selected by some criteria.
-.RS
-.TP
-.BI dev " DEV "
-show the nexthops using the given device.
-.TP
-.BI vrf " NAME "
-show the nexthops using devices associated with the vrf name
-.TP
-.BI master " DEV "
-show the nexthops using devices enslaved to given master device
-.TP
-.BI groups
-show only nexthop groups
-.RE
-.TP
-ip nexthop flush
-flushes nexthops selected by some criteria. Criteria options are the same
-as show.
-.RE
-
-.TP
-ip nexthop get id ID
-get a single nexthop by id
-
-.SH EXAMPLES
-.PP
-ip nexthop ls
-.RS 4
-Show all nexthop entries in the kernel.
-.RE
-.PP
-ip nexthop add id 1 via 192.168.1.1 dev eth0
-.RS 4
-Adds an IPv4 nexthop with id 1 using the gateway 192.168.1.1 out device eth0.
-.RE
-.PP
-ip nexthop add id 2 encap mpls 200/300 via 10.1.1.1 dev eth0
-.RS 4
-Adds an IPv4 nexthop with mpls encapsulation attributes attached to it.
-.RE
-.PP
-ip nexthop add id 3 group 1/2
-.RS 4
-Adds a nexthop with id 3. The nexthop is a group using nexthops with ids
-1 and 2 at equal weight.
-.RE
-.PP
-ip nexthop add id 4 group 1,5/2,11
-.RS 4
-Adds a nexthop with id 4. The nexthop is a group using nexthops with ids
-1 and 2 with nexthop 1 at weight 5 and nexthop 2 at weight 11.
-.RE
-.SH SEE ALSO
-.br
-.BR ip (8)
-
-.SH AUTHOR
-Original Manpage by David Ahern <dsahern@kernel.org>
diff --git a/man/man8/ip-ntable.8 b/man/man8/ip-ntable.8
index 4f0f2e5..462e589 100644
--- a/man/man8/ip-ntable.8
+++ b/man/man8/ip-ntable.8
@@ -8,7 +8,7 @@
 .ti -8
 .B ip
 .RI "[ " OPTIONS " ]"
-.B ntable
+.B address
 .RI " { " COMMAND " | "
 .BR help " }"
 .sp
@@ -17,39 +17,34 @@
 .BR "ip ntable change name"
 .IR NAME " [ "
 .B dev
-.IR DEV " ] ["
+.IR DEV " ] " PARMS
+
+.ti -8
+.IR PARMS " := { "
 .B thresh1
-.IR VAL " ] ["
+.IR VAL " | "
 .B thresh2
-.IR VAL " ] ["
+.IR VAL " | "
 .B thresh3
-.IR VAL " ] ["
+.IR VAL " | "
 .B gc_int
-.IR MSEC " ] ["
+.IR MSEC " | "
 .B base_reachable
-.IR MSEC " ] ["
+.IR MSEC " | "
 .B retrans
-.IR MSEC " ] ["
-.B gc_stale
-.IR MSEC " ] ["
+.IR MSEC " | " "gc_stale MSEC " " | "
 .B delay_probe
-.IR MSEC " ] ["
-.B queue
-.IR LEN " ] ["
+.IR MSEC " | " "queue LEN " " | "
 .B app_probs
-.IR VAL " ] ["
+.IR VAL " | "
 .B ucast_probes
-.IR VAL " ] ["
-.B mcast_probes
-.IR VAL " ] ["
+.IR VAL " | " "mcast_probes VAL " " | "
 .B anycast_delay
-.IR MSEC " ] ["
+.IR MSEC " | "
 .B proxy_delay
-.IR MSEC " ] ["
-.B proxy_queue
-.IR LEN " ] ["
+.IR MSEC " | " "proxy_queue LEN " " | "
 .B locktime
-.IR MSEC " ]"
+.IR MSEC " }"
 
 .ti -8
 .BR "ip ntable show" " [ "
diff --git a/man/man8/ip-route.8.in b/man/man8/ip-route.8.in
index 34763cc..c764bfc 100644
--- a/man/man8/ip-route.8.in
+++ b/man/man8/ip-route.8.in
@@ -16,7 +16,7 @@
 
 .ti -8
 .BR "ip route" " { "
-.BR show " | " flush " } "
+.BR list " | " flush " } "
 .I  SELECTOR
 
 .ti -8
@@ -28,23 +28,12 @@
 
 .ti -8
 .B  ip route get
-.I ROUTE_GET_FLAGS
 .IR ADDRESS " [ "
 .BI from " ADDRESS " iif " STRING"
 .RB " ] [ " oif
 .IR STRING " ] [ "
-.B  mark
-.IR MARK " ] [ "
 .B  tos
-.IR TOS " ] [ "
-.B  vrf
-.IR NAME " ] [ "
-.B  ipproto
-.IR PROTOCOL " ] [ "
-.B  sport
-.IR NUMBER " ] [ "
-.B  dport
-.IR NUMBER " ] "
+.IR TOS " ]"
 
 .ti -8
 .BR "ip route" " { " add " | " del " | " change " | " append " | "\
@@ -61,8 +50,6 @@
 .IR PREFIX " ] [ "
 .B  table
 .IR TABLE_ID " ] [ "
-.B  vrf
-.IR NAME " ] [ "
 .B  proto
 .IR RTPROTO " ] [ "
 .B  type
@@ -84,14 +71,10 @@
 .B  scope
 .IR SCOPE " ] [ "
 .B  metric
-.IR METRIC " ] [ "
-.B  ttl-propagate
-.RB "{ " enabled " | " disabled " } ]"
+.IR METRIC " ]"
 
 .ti -8
-.IR INFO_SPEC " := { " NH " | "
-.B nhid
-.IR ID " } " "OPTIONS FLAGS" " ["
+.IR INFO_SPEC " := " "NH OPTIONS FLAGS" " ["
 .B  nexthop
 .IR NH " ] ..."
 
@@ -109,7 +92,7 @@
 
 .ti -8
 .IR FAMILY " := [ "
-.BR inet " | " inet6 " | " mpls " | " bridge " | " link " ]"
+.BR inet " | " inet6 " | " ipx " | " dnet " | " mpls " | " bridge " | " link " ]"
 
 .ti -8
 .IR OPTIONS " := " FLAGS " [ "
@@ -133,7 +116,7 @@
 .B  cwnd
 .IR NUMBER " ] [ "
 .B  ssthresh
-.IR NUMBER " ] [ "
+.IR REALM " ] [ "
 .B  realms
 .IR REALM " ] [ "
 .B  rto_min
@@ -151,9 +134,7 @@
 .B  pref
 .IR PREF " ] [ "
 .B  expires
-.IR TIME " ] ["
-.B  fastopen_no_cookie
-.IR BOOL " ]"
+.IR TIME " ]"
 
 .ti -8
 .IR TYPE " := [ "
@@ -189,15 +170,12 @@
 
 .ti -8
 .IR ENCAP " := [ "
-.IR ENCAP_MPLS " | " ENCAP_IP " | " ENCAP_BPF " | "
-.IR ENCAP_SEG6 " | " ENCAP_SEG6LOCAL " ] "
+.IR MPLS " | " IP " ]"
 
 .ti -8
 .IR ENCAP_MPLS " := "
 .BR mpls " [ "
-.IR LABEL " ] ["
-.B  ttl
-.IR TTL " ]"
+.IR LABEL " ]"
 
 .ti -8
 .IR ENCAP_IP " := "
@@ -206,48 +184,11 @@
 .IR TUNNEL_ID
 .B  dst
 .IR REMOTE_IP " [ "
-.B src
-.IR SRC " ] ["
 .B tos
 .IR TOS " ] ["
 .B  ttl
 .IR TTL " ]"
 
-.ti -8
-.IR ENCAP_BPF " := "
-.BR bpf " [ "
-.B in
-.IR PROG " ] ["
-.B out
-.IR PROG " ] ["
-.B xmit
-.IR PROG " ] ["
-.B headroom
-.IR SIZE " ]"
-
-.ti -8
-.IR ENCAP_SEG6 " := "
-.B seg6
-.BR mode " [ "
-.BR encap " | " inline " | " l2encap " ] "
-.B segs
-.IR SEGMENTS " [ "
-.B hmac
-.IR KEYID " ]"
-
-.ti -8
-.IR ENCAP_SEG6LOCAL " := "
-.B seg6local
-.BR action
-.IR SEG6_ACTION " [ "
-.IR SEG6_ACTION_PARAM " ] "
-
-.ti -8
-.IR ROUTE_GET_FLAGS " := "
-.BR " [ "
-.BR fibmatch
-.BR " ] "
-
 .SH DESCRIPTION
 .B ip route
 is used to manipulate entries in the kernel routing tables.
@@ -337,7 +278,7 @@
 .P
 .B Route tables:
 Linux-2.x can pack routes into several routing tables identified
-by a number in the range from 1 to 2^32-1 or by name from the file
+by a number in the range from 1 to 2^31 or by name from the file
 .B @SYSCONFDIR@/rt_tables
 By default all normal routes are inserted into the
 .B main
@@ -409,7 +350,7 @@
 .BI preference " NUMBER"
 the preference value of the route.
 .I NUMBER
-is an arbitrary 32bit number, where routes with lower values are preferred.
+is an arbitrary 32bit number.
 
 .TP
 .BI table " TABLEID"
@@ -428,11 +369,6 @@
 table by default.
 
 .TP
-.BI vrf " NAME"
-the vrf name to add this route to. Implicitly means the table
-associated with the VRF.
-
-.TP
 .BI dev " NAME"
 the output device name.
 
@@ -488,43 +424,43 @@
 
 
 .TP
-.BI rttvar " TIME " "(Linux 2.3.15+ only)"
+.BI rttvar " TIME " "(2.3.15+ only)"
 the initial RTT variance estimate. Values are specified as with
 .BI rtt
 above.
 
 .TP
-.BI rto_min " TIME " "(Linux 2.6.23+ only)"
+.BI rto_min " TIME " "(2.6.23+ only)"
 the minimum TCP Retransmission TimeOut to use when communicating with this
 destination. Values are specified as with
 .BI rtt
 above.
 
 .TP
-.BI ssthresh " NUMBER " "(Linux 2.3.15+ only)"
+.BI ssthresh " NUMBER " "(2.3.15+ only)"
 an estimate for the initial slow start threshold.
 
 .TP
-.BI cwnd " NUMBER " "(Linux 2.3.15+ only)"
+.BI cwnd " NUMBER " "(2.3.15+ only)"
 the clamp for congestion window. It is ignored if the
 .B lock
 flag is not used.
 
 .TP
-.BI initcwnd " NUMBER " "(Linux 2.5.70+ only)"
+.BI initcwnd " NUMBER " "(2.5.70+ only)"
 the initial congestion window size for connections to this destination.
 Actual window size is this value multiplied by the MSS
 (``Maximal Segment Size'') for same connection. The default is
 zero, meaning to use the values specified in RFC2414.
 
 .TP
-.BI initrwnd " NUMBER " "(Linux 2.6.33+ only)"
+.BI initrwnd " NUMBER " "(2.6.33+ only)"
 the initial receive window size for connections to this destination.
 Actual window size is this value multiplied by the MSS of the connection.
 The default value is zero, meaning to use Slow Start value.
 
 .TP
-.BI features " FEATURES " (Linux 3.18+ only)
+.BI features " FEATURES " (3.18+ only)
 Enable or disable per-route features. Only available feature at this
 time is
 .B ecn
@@ -536,17 +472,13 @@
 sysctl is set to 0.
 
 .TP
-.BI quickack " BOOL " "(Linux 3.11+ only)"
+.BI quickack " BOOL " "(3.11+ only)"
 Enable or disable quick ack for connections to this destination.
 
 .TP
-.BI fastopen_no_cookie " BOOL " "(Linux 4.15+ only)"
-Enable TCP Fastopen without a cookie for connections to this destination.
-
+.BI congctl " NAME " "(3.20+ only)"
 .TP
-.BI congctl " NAME " "(Linux 3.20+ only)"
-.TP
-.BI "congctl lock" " NAME " "(Linux 3.20+ only)"
+.BI "congctl lock" " NAME " "(3.20+ only)"
 Sets a specific TCP congestion control algorithm only for a given destination.
 If not specified, Linux keeps the current global default TCP congestion control
 algorithm, or the one set from the application. If the modifier
@@ -559,14 +491,14 @@
 use the proposed algorithm.
 
 .TP
-.BI advmss " NUMBER " "(Linux 2.3.15+ only)"
+.BI advmss " NUMBER " "(2.3.15+ only)"
 the MSS ('Maximal Segment Size') to advertise to these
 destinations when establishing TCP connections. If it is not given,
 Linux uses a default value calculated from the first hop device MTU.
 (If the path to these destination is asymmetric, this guess may be wrong.)
 
 .TP
-.BI reordering " NUMBER " "(Linux 2.3.15+ only)"
+.BI reordering " NUMBER " "(2.3.15+ only)"
 Maximal reordering on the path to this destination.
 If it is not given, Linux uses the value selected with
 .B sysctl
@@ -594,15 +526,6 @@
 route reflecting its relative bandwidth or quality.
 .in -8
 
-The internal buffer used in iproute2 limits the maximum number of nexthops that
-may be specified in one go. If only
-.I ADDRESS
-is given, the current buffer size allows for 144 IPv6 nexthops and 253 IPv4
-ones. For IPv4, this effectively limits the number of nexthops possible per
-route. With IPv6, further nexthops may be appended to the same route via
-.B "ip route append"
-command.
-
 .TP
 .BI scope " SCOPE_VAL"
 the scope of the destinations covered by the route prefix.
@@ -691,10 +614,6 @@
 .sp
 
 .TP
-.BI nhid " ID"
-use nexthop object with given id as nexthop specification.
-.sp
-.TP
 .BI encap " ENCAPTYPE ENCAPHDR"
 attach tunnel encapsulation attributes to this route.
 .sp
@@ -708,14 +627,6 @@
 .BI ip
 - IP encapsulation (Geneve, GRE, VXLAN, ...)
 .sp
-.BI bpf
-- Execution of BPF program
-.sp
-.BI seg6
-- encapsulation type IPv6 Segment Routing
-.sp
-.BI seg6local
-- local SRv6 segment processing
 
 .in -8
 .I ENCAPHDR
@@ -728,11 +639,6 @@
 .I MPLSLABEL
 - mpls label stack with labels separated by
 .I "/"
-.sp
-
-.B ttl
-.I TTL
-- TTL to use for MPLS header or 0 to inherit from IP header
 .in -2
 .sp
 
@@ -742,128 +648,23 @@
 .I TUNNEL_ID
 .B  dst
 .IR REMOTE_IP " [ "
-.B src
-.IR SRC " ] ["
 .B tos
 .IR TOS " ] ["
 .B  ttl
-.IR TTL " ] [ "
-.BR key " ] [ " csum " ] [ " seq " ] "
+.IR TTL " ]"
 .in -2
 .sp
 
-.B bpf
-.in +2
-.B in
-.I PROG
-- BPF program to execute for incoming packets
-.sp
-
-.B out
-.I PROG
-- BPF program to execute for outgoing packets
-.sp
-
-.B xmit
-.I PROG
-- BPF program to execute for transmitted packets
-.sp
-
-.B headroom
-.I SIZE
-- Size of header BPF program will attach (xmit)
-.in -2
-.sp
-
-.B seg6
-.in +2
-.B mode inline
-- Directly insert Segment Routing Header after IPv6 header
-.sp
-
-.B mode encap
-- Encapsulate packet in an outer IPv6 header with SRH
-.sp
-
-.B mode l2encap
-- Encapsulate ingress L2 frame within an outer IPv6 header and SRH
-.sp
-
-.I SEGMENTS
-- List of comma-separated IPv6 addresses
-.sp
-
-.I KEYID
-- Numerical value in decimal representation. See \fBip-sr\fR(8).
-.in -2
-.sp
-
-.B seg6local
-.in +2
-.IR SEG6_ACTION " [ "
-.IR SEG6_ACTION_PARAM " ] "
-- Operation to perform on matching packets.
-The following actions are currently supported (\fBLinux 4.14+ only\fR).
-.in +2
-
-.B End
-- Regular SRv6 processing as intermediate segment endpoint.
-This action only accepts packets with a non-zero Segments Left
-value. Other matching packets are dropped.
-
-.B End.X nh6
-.I NEXTHOP
-- Regular SRv6 processing as intermediate segment endpoint.
-Additionally, forward processed packets to given next-hop.
-This action only accepts packets with a non-zero Segments Left
-value. Other matching packets are dropped.
-
-.B End.DX6 nh6
-.I NEXTHOP
-- Decapsulate inner IPv6 packet and forward it to the
-specified next-hop. If the argument is set to ::, then
-the next-hop is selected according to the local selection
-rules. This action only accepts packets with either a zero Segments
-Left value or no SRH at all, and an inner IPv6 packet. Other
-matching packets are dropped.
-
-.B End.B6 srh segs
-.IR SEGMENTS " [ "
-.B hmac
-.IR KEYID " ] "
-- Insert the specified SRH immediately after the IPv6 header,
-update the DA with the first segment of the newly inserted SRH,
-then forward the resulting packet. The original SRH is not
-modified. This action only accepts packets with a non-zero
-Segments Left value. Other matching packets are dropped.
-
-.B End.B6.Encaps srh segs
-.IR SEGMENTS " [ "
-.B hmac
-.IR KEYID " ] "
-- Regular SRv6 processing as intermediate segment endpoint.
-Additionally, encapsulate the matching packet within an outer IPv6 header
-followed by the specified SRH. The destination address of the outer IPv6
-header is set to the first segment of the new SRH. The source
-address is set as described in \fBip-sr\fR(8).
-.in -4
-
 .in -8
+.RE
 
 .TP
-.BI expires " TIME " "(Linux 4.4+ only)"
+.BI expires " TIME " "(4.4+ only)"
 the route will be deleted after the expires time.
 .B Only
 support IPv6 at present.
 
 .TP
-.BR ttl-propagate " { " enabled " | " disabled " } "
-Control whether TTL should be propagated from any encap into the
-un-encapsulated packet, overriding any global configuration. Only
-supported for MPLS at present.
-.RE
-
-.TP
 ip route delete
 delete route
 .RS
@@ -945,10 +746,6 @@
 .in -8
 
 .TP
-.BI vrf " NAME"
-show the routes for the table associated with the vrf name
-
-.TP
 .B cloned
 .TP
 .B cached
@@ -1036,11 +833,6 @@
 contents exactly as the kernel sees it.
 
 .TP
-.BI fibmatch
-Return full fib lookup matched route. Default is to return the resolved
-dst entry
-
-.TP
 .BI to " ADDRESS " (default)
 the destination address.
 
@@ -1063,27 +855,6 @@
 force the output device on which this packet will be routed.
 
 .TP
-.BI mark " MARK"
-the firewall mark
-.RB ( "fwmark" )
-
-.TP
-.BI vrf " NAME"
-force the vrf device on which this packet will be routed.
-
-.TP
-.BI ipproto " PROTOCOL"
-ip protocol as seen by the route lookup
-
-.TP
-.BI sport " NUMBER"
-source port as seen by the route lookup
-
-.TP
-.BI dport " NUMBER"
-destination port as seen by the route lookup
-
-.TP
 .B connected
 if no source address
 .RB "(option " from ")"
@@ -1136,12 +907,6 @@
 already exist in the table will be ignored.
 .RE
 
-.SH NOTES
-Starting with Linux kernel version 3.6, there is no routing cache for IPv4
-anymore. Hence
-.B "ip route show cached"
-will never print any entries on systems with this or newer kernel versions.
-
 .SH EXAMPLES
 .PP
 ip ro
@@ -1159,16 +924,6 @@
 .RS 4
 Adds an ipv4 route with mpls encapsulation attributes attached to it.
 .RE
-.PP
-ip -6 route add 2001:db8:1::/64 encap seg6 mode encap segs 2001:db8:42::1,2001:db8:ffff::2 dev eth0
-.RS 4
-Adds an IPv6 route with SRv6 encapsulation and two segments attached.
-.RE
-.PP
-ip route add 10.1.1.0/30 nhid 10
-.RS 4
-Adds an ipv4 route using nexthop object with id 10.
-.RE
 .SH SEE ALSO
 .br
 .BR ip (8)
diff --git a/man/man8/ip-rule.8 b/man/man8/ip-rule.8
index 2c12bf6..b7008c6 100644
--- a/man/man8/ip-rule.8
+++ b/man/man8/ip-rule.8
@@ -9,27 +9,20 @@
 .B ip
 .RI "[ " OPTIONS " ]"
 .B rule
-.RI "{ " COMMAND " | "
+.RI " { " COMMAND " | "
 .BR help " }"
 .sp
 
 .ti -8
 .B  ip rule
-.RB "[ " list
-.RI "[ " SELECTOR " ]]"
-
-.ti -8
-.B  ip rule
-.RB "{ " add " | " del " }"
+.RB " [ " list " | " add " | " del " | " flush " | " save " ]"
 .I  SELECTOR ACTION
 
 .ti -8
-.B ip rule
-.RB "{ " flush " | " save " | " restore " }"
+.B  ip rule  " restore "
 
 .ti -8
 .IR SELECTOR " := [ "
-.BR not " ] ["
 .B  from
 .IR PREFIX " ] [ "
 .B  to
@@ -37,41 +30,23 @@
 .B  tos
 .IR TOS " ] [ "
 .B  fwmark
-.IR FWMARK\fR[\fB/\fIMASK "] ] [ "
+.IR FWMARK[/MASK] " ] [ "
 .B  iif
 .IR STRING " ] [ "
 .B  oif
 .IR STRING " ] [ "
 .B  pref
-.IR NUMBER " ] [ "
-.IR l3mdev " ] [ "
-.B uidrange
-.IR NUMBER "-" NUMBER " ] [ "
-.B ipproto
-.IR PROTOCOL " ] [ "
-.BR sport " [ "
-.IR NUMBER " | "
-.IR NUMBER "-" NUMBER " ] ] [ "
-.BR dport " [ "
-.IR NUMBER " | "
-.IR NUMBER "-" NUMBER " ] ] [ "
-.B  tun_id
-.IR TUN_ID " ]"
-.BR
-
+.IR NUMBER " ]"
 
 .ti -8
 .IR ACTION " := [ "
 .B  table
 .IR TABLE_ID " ] [ "
-.B  protocol
-.IR PROTO " ] [ "
 .B  nat
 .IR ADDRESS " ] [ "
 .B realms
-.RI "[" SRCREALM "\fB/\fR]" DSTREALM " ] ["
-.B goto
-.IR NUMBER " ] " SUPPRESSOR
+.RI "[" SRCREALM "/]" DSTREALM " ]"
+.I  SUPPRESSOR
 
 .ti -8
 .IR SUPPRESSOR " := [ "
@@ -111,10 +86,7 @@
 .B selector
 and an
 .B action predicate.
-The RPDB is scanned in order of decreasing priority (note that lower number
-means higher priority, see the description of
-.I PREFERENCE
-below). The selector
+The RPDB is scanned in order of decreasing priority. The selector
 of each rule is applied to {source address, destination address, incoming
 interface, tos, fwmark} and, if the selector matches the packet,
 the action is performed. The action predicate may return with success.
@@ -139,6 +111,8 @@
 .B local
 table is a special routing table containing
 high priority control routes for local and broadcast addresses.
+.sp
+Rule 0 is special. It cannot be deleted or overridden.
 
 .TP
 2.
@@ -241,30 +215,9 @@
 value to match.
 
 .TP
-.BI uidrange " NUMBER-NUMBER"
-select the
-.B uid
-value to match.
-
-.TP
-.BI ipproto " PROTOCOL"
-select the ip protocol value to match.
-
-.TP
-.BI sport " NUMBER | NUMBER-NUMBER"
-select the source port value to match. supports port range.
-
-.TP
-.BI dport " NUMBER | NUMBER-NUMBER"
-select the destination port value to match. supports port range.
-
-.TP
 .BI priority " PREFERENCE"
-the priority of this rule.
-.I PREFERENCE
-is an unsigned integer value, higher number means lower priority, and rules get
-processed in order of increasing number. Each rule
-should have an explicitly set
+the priority of this rule. Each rule should have an explicitly
+set
 .I unique
 priority value.
 The options preference and order are synonyms with priority.
@@ -275,10 +228,6 @@
 It is also possible to use lookup instead of table.
 
 .TP
-.BI protocol " PROTO"
-the routing protocol who installed the rule in question.  As an example when zebra installs a rule it would get RTPROT_ZEBRA as the installing protocol.
-
-.TP
 .BI suppress_prefixlength " NUMBER"
 reject routing decisions that have a prefix length of NUMBER or less.
 
@@ -313,11 +262,7 @@
 .RE
 .TP
 .B ip rule flush - also dumps all the deleted rules.
-.RS
-.TP
-.BI protocol " PROTO"
-Select the originating protocol.
-.RE
+This command has no arguments.
 .TP
 .B ip rule show - list rules
 This command has no arguments.
@@ -325,12 +270,6 @@
 
 .TP
 .B ip rule save
-.RS
-.TP
-.BI protocol " PROTO"
-Select the originating protocol.
-.RE
-.TP
 save rules table information to stdout
 .RS
 This command behaves like
diff --git a/man/man8/ip-sr.8 b/man/man8/ip-sr.8
deleted file mode 100644
index 6be1cc5..0000000
--- a/man/man8/ip-sr.8
+++ /dev/null
@@ -1,58 +0,0 @@
-.TH IP\-SR 8 "14 Apr 2017" "iproute2" "Linux"
-.SH "NAME"
-ip-sr \- IPv6 Segment Routing management
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B ip sr
-.RI " { " COMMAND " | "
-.BR help " }"
-.sp
-.ti -8
-
-.ti -8
-.B ip sr hmac show
-
-.ti -8
-.B ip sr hmac set
-.I KEYID ALGO
-
-.ti -8
-.B ip sr tunsrc show
-
-.ti -8
-.B ip sr tunsrc set
-.I ADDRESS
-
-.SH DESCRIPTION
-The \fBip sr\fR command is used to configure IPv6 Segment Routing (SRv6)
-internal parameters.
-.PP
-Those parameters include the mapping between an HMAC key ID and its associated
-hashing algorithm and secret, and the IPv6 address to use as source for encapsulated
-packets.
-.PP
-The \fBip sr hmac set\fR command prompts for a passphrase that will be used as the
-HMAC secret for the corresponding key ID. A blank passphrase removes the mapping.
-The currently supported algorithms for \fIALGO\fR are \fBsha1\fR and \fBsha256\fR.
-.PP
-If the tunnel source is set to the address :: (which is the default), then an address
-of the egress interface will be selected. As this operation may hinder performances,
-it is recommended to set a non-default address.
-
-.SH EXAMPLES
-.PP
-.SS Configure an HMAC mapping for key ID 42 and hashing algorithm SHA-256
-.nf
-# ip sr hmac set 42 sha256
-.PP
-.SS Set the tunnel source address to 2001:db8::1
-.nf
-# ip sr tunsrc set 2001:db8::1
-.SH SEE ALSO
-.br
-.BR ip-route (8)
-.SH AUTHOR
-David Lebrun <david.lebrun@uclouvain.be>
diff --git a/man/man8/ip-token.8 b/man/man8/ip-token.8
index 6505b8c..35a3d1e 100644
--- a/man/man8/ip-token.8
+++ b/man/man8/ip-token.8
@@ -7,27 +7,23 @@
 .in +8
 .ti -8
 .B ip token
-.RI "{ " COMMAND " | "
+.RI " { " COMMAND " | "
 .BR help " }"
 .sp
 
 .ti -8
-.B ip token set
+.BR "ip token" " { " set " } "
 .IR TOKEN
 .B dev
 .IR DEV
 
 .ti -8
-.B ip token del dev
+.BR "ip token" " { " get " } "
+.B dev
 .IR DEV
 
 .ti -8
-.B ip token get
-.RB "[ " dev
-.IR DEV " ]"
-
-.ti -8
-.BR "ip token" " [ " list " ]"
+.BR "ip token" " { " list " }"
 
 .SH "DESCRIPTION"
 IPv6 tokenized interface identifier support is used for assigning well-known
@@ -41,7 +37,8 @@
 [1]: <draft-chown-6man-tokenised-ipv6-identifiers-02>.
 
 .SS ip token set - set an interface token
-set the interface token to the kernel.
+set the interface token to the kernel. Once a token is set, it cannot be
+removed from the interface, only overwritten.
 .TP
 .I TOKEN
 the interface identifier token address.
@@ -49,12 +46,6 @@
 .BI dev " DEV"
 the networking interface.
 
-.SS ip token del - delete an interface token
-delete the interface token from the kernel.
-.TP
-.BI dev " DEV"
-the networking interface.
-
 .SS ip token get - get the interface token from the kernel
 show a tokenized interface identifier of a particular networking device.
 .B Arguments:
diff --git a/man/man8/ip-tunnel.8 b/man/man8/ip-tunnel.8
index 9a510af..8b746cb 100644
--- a/man/man8/ip-tunnel.8
+++ b/man/man8/ip-tunnel.8
@@ -11,7 +11,7 @@
 .ti -8
 .BR "ip "
 .RI "[ " OPTIONS " ]"
-.BR "tunnel" " { " add " | " change " | " del " | " show " | " prl " | " 6rd " }"
+.BR "tunnel" " { " add " | " change " | " del " | " show " | " prl " }"
 .RI "[ " NAME " ]"
 .br
 .RB "[ " mode
@@ -42,16 +42,7 @@
 .B prl-delete
 .IR ADDR " ]"
 .br
-.RB "[ " 6rd-prefix
-.IR ADDR " ] ["
-.B 6rd-relay_prefix
-.IR ADDR " ] [
-.BR 6rd-reset " ]"
-.br
 .RB "[ [" no "]" pmtudisc " ]"
-.RB "[ [" no "]" ignore-df " ]"
-.RB "[ [" no "]" allow-localremote " ]"
-.br
 .RB "[ " dev
 .IR PHYS_DEV " ]"
 
@@ -84,6 +75,9 @@
 .ti -8
 .IR KEY " := { " DOTTED_QUAD " | " NUMBER " }"
 
+.ti -8
+.IR TIME " := " NUMBER "[s|ms]"
+
 .SH DESCRIPTION
 .B tunnel
 objects are tunnels, encapsulating packets in IP packets and then
@@ -179,14 +173,6 @@
 discovery.
 
 .TP
-.B ignore-df
-enable IPv4 DF suppression on this tunnel.
-Normally datagrams that exceed the MTU will be fragmented; the presence
-of the DF flag inhibits this, resulting instead in an ICMP Unreachable
-(Fragmentation Required) message.  Enabling this attribute causes the
-DF flag to be ignored.
-
-.TP
 .BI key " K"
 .TP
 .BI ikey " K"
@@ -243,11 +229,6 @@
 .BI flowlabel " FLOWLABEL"
 .RB ( " only IPv6 tunnels " )
 set a fixed flowlabel.
-
-.TP
-.BI allow-localremote
-.RB ( " only IPv6 tunnels " )
-allow remote endpoint on the local host.
 .RE
 
 .TP
diff --git a/man/man8/ip-vrf.8 b/man/man8/ip-vrf.8
deleted file mode 100644
index c1c9b95..0000000
--- a/man/man8/ip-vrf.8
+++ /dev/null
@@ -1,111 +0,0 @@
-.TH IP\-VRF 8 "7 Dec 2016" "iproute2" "Linux"
-.SH NAME
-ip-vrf \- run a command against a vrf
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B ip
-.B vrf
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.BR "ip vrf show"
-.RI "[ " NAME " ]"
-
-.ti -8
-.BR "ip vrf identify"
-.RI "[ " PID " ]"
-
-.ti -8
-.BR "ip vrf pids"
-.I NAME
-
-.ti -8
-.BR "ip vrf exec "
-.RI "[ " NAME " ] " command ...
-
-.SH DESCRIPTION
-A VRF provides traffic isolation at layer 3 for routing, similar to how a
-VLAN is used to isolate traffic at layer 2. Fundamentally, a VRF is a separate
-routing table. Network devices are associated with a VRF by enslaving the
-device to the VRF. At that point network addresses assigned to the device are
-local to the VRF with host and connected routes moved to the table associated
-with the VRF.
-
-A process can specify a VRF using several APIs -- binding the socket to the
-VRF device using SO_BINDTODEVICE, setting the VRF association using
-IP_UNICAST_IF or IPV6_UNICAST_IF, or specifying the VRF for a specific message
-using IP_PKTINFO or IPV6_PKTINFO.
-
-By default a process is not bound to any VRF. An association can be set
-explicitly by making the program use one of the APIs mentioned above or
-implicitly using a helper to set SO_BINDTODEVICE for all IPv4 and IPv6
-sockets (AF_INET and AF_INET6) when the socket is created. This ip-vrf command
-is a helper to run a command against a specific VRF with the VRF association
-inherited parent to child.
-
-.TP
-.B ip vrf show [ NAME ] - Show all configured VRF
-.sp
-This command lists all VRF and their corresponding table ids. If NAME is
-given, then only that VRF and table id is shown. The latter command is
-useful for scripting where the table id for a VRF is needed.
-
-.TP
-.B ip vrf exec [ NAME ] cmd ... - Run cmd against the named VRF
-.sp
-This command allows applications that are VRF unaware to be run against
-a VRF other than the default VRF (main table). A command can be run against
-the default VRF by passing the "default" as the VRF name. This is useful if
-the current shell is associated with another VRF (e.g, Management VRF).
-
-This command requires the system to be booted with cgroup v2 (e.g. with systemd,
-add systemd.unified_cgroup_hierarchy=1 to the kernel command line).
-
-This command also requires to be ran as root or with the CAP_SYS_ADMIN,
-CAP_NET_ADMIN and CAP_DAC_OVERRIDE capabilities. If built with libcap and if
-capabilities are added to the ip binary program via setcap, the program will
-drop them as the first thing when invoked, unless the command is vrf exec.
-.br
-NOTE: capabilities will NOT be dropped if CAP_NET_ADMIN is set to INHERITABLE
-to avoid breaking programs with ambient capabilities that call ip.
-Do not set the INHERITABLE flag on the ip binary itself.
-
-.TP
-.B ip vrf identify [PID] - Report VRF association for process
-.sp
-This command shows the VRF association of the specified process. If PID is
-not specified then the id of the current process is used.
-
-.TP
-.B ip vrf pids NAME - Report processes associated with the named VRF
-.sp
-This command shows all process ids that are associated with the given
-VRF.
-
-.SH CAVEATS
-This command requires a kernel compiled with CGROUPS and CGROUP_BPF enabled.
-
-The VRF helper *only* affects network layer sockets.
-
-.SH EXAMPLES
-.PP
-ip vrf exec red ssh 10.100.1.254
-.RS
-Executes ssh to 10.100.1.254 against the VRF red table.
-.RE
-
-.SH SEE ALSO
-.br
-.BR ip (8),
-.BR ip-link (8),
-.BR ip-address (8),
-.BR ip-route (8),
-.BR ip-neighbor (8)
-
-.SH AUTHOR
-Original Manpage by David Ahern
diff --git a/man/man8/ip-xfrm.8 b/man/man8/ip-xfrm.8
index cfce1e4..dae0728 100644
--- a/man/man8/ip-xfrm.8
+++ b/man/man8/ip-xfrm.8
@@ -57,10 +57,6 @@
 .IR ADDR "[/" PLEN "] ]"
 .RB "[ " ctx
 .IR CTX " ]"
-.RB "[ " extra-flag
-.IR EXTRA-FLAG-LIST " ]"
-.RB "[ " output-mark
-.IR OUTPUT-MARK " ]"
 
 .ti -8
 .B "ip xfrm state allocspi"
@@ -89,7 +85,7 @@
 .IR MASK " ] ]"
 
 .ti -8
-.BR ip " [ " -4 " | " -6 " ] " "xfrm state deleteall" " ["
+.BR "ip xfrm state" " { " deleteall " | " list " } ["
 .IR ID " ]"
 .RB "[ " mode
 .IR MODE " ]"
@@ -99,17 +95,6 @@
 .IR FLAG-LIST " ]"
 
 .ti -8
-.BR ip " [ " -4 " | " -6 " ] " "xfrm state list" " ["
-.IR ID " ]"
-.RB "[ " nokeys " ]"
-.RB "[ " mode
-.IR MODE " ]"
-.RB "[ " reqid
-.IR REQID " ]"
-.RB "[ " flag
-.IR FLAG-LIST " ]"
-
-.ti -8
 .BR "ip xfrm state flush" " [ " proto
 .IR XFRM-PROTO " ]"
 
@@ -211,13 +196,6 @@
 .IR SPORT " " DPORT " " OADDR
 
 .ti -8
-.IR EXTRA-FLAG-LIST " := [ " EXTRA-FLAG-LIST " ] " EXTRA-FLAG
-
-.ti -8
-.IR EXTRA-FLAG " := "
-.B dont-encap-dscp
-
-.ti -8
 .BR "ip xfrm policy" " { " add " | " update " }"
 .I SELECTOR
 .B dir
@@ -257,8 +235,7 @@
 .IR PTYPE " ]"
 
 .ti -8
-.BR ip " [ " -4 " | " -6 " ] " "xfrm policy" " { " deleteall " | " list " }"
-.RB "[ " nosock " ]"
+.BR "ip xfrm policy" " { " deleteall " | " list " }"
 .RI "[ " SELECTOR " ]"
 .RB "[ " dir
 .IR DIR " ]"
@@ -270,8 +247,6 @@
 .IR ACTION " ]"
 .RB "[ " priority
 .IR PRIORITY " ]"
-.RB "[ " flag
-.IR FLAG-LIST "]"
 
 .ti -8
 .B "ip xfrm policy flush"
@@ -392,8 +367,6 @@
 .BR "ip xfrm monitor" " ["
 .BI all-nsid
 ] [
-.BI nokeys
-] [
 .BI all
  |
 .IR LISTofXFRM-OBJECTS " ]"
@@ -493,7 +466,7 @@
 
 Authentication algorithms include
 .BR digest_null ", " hmac(md5) ", " hmac(sha1) ", " hmac(sha256) ","
-.BR hmac(sha384) ", " hmac(sha512) ", " hmac(rmd160) ", and " xcbc(aes) "."
+.BR hmac(sha384) ", " hmac(sha512) ", " hmac(rmd610) ", and " xcbc(aes) "."
 
 Authenticated encryption with associated data (AEAD) algorithms include
 .BR rfc4106(gcm(aes)) ", " rfc4309(ccm(aes)) ", and " rfc4543(gcm(aes)) "."
@@ -552,15 +525,6 @@
 .RI "using source port " SPORT ", destination port "  DPORT
 .RI ", and original address " OADDR "."
 
-.TP
-.I MARK
-used to match xfrm policies and states
-
-.TP
-.I OUTPUT-MARK
-used to set the output mark to influence the routing
-of the packets emitted by the state
-
 .sp
 .PP
 .TS
@@ -575,10 +539,6 @@
 .TE
 
 .TP
-.BR nosock
-filter (remove) all socket policies from the output.
-
-.TP
 .IR SELECTOR
 selects the traffic that will be controlled by the policy, based on the source
 address, the destination address, the network device, and/or
diff --git a/man/man8/ip.8 b/man/man8/ip.8
index e2bda2a..b1f6907 100644
--- a/man/man8/ip.8
+++ b/man/man8/ip.8
@@ -1,6 +1,6 @@
 .TH IP 8 "20 Dec 2011" "iproute2" "Linux"
 .SH NAME
-ip \- show / manipulate routing, network devices, interfaces and tunnels
+ip \- show / manipulate routing, devices, policy routing and tunnels
 .SH SYNOPSIS
 
 .ad l
@@ -21,8 +21,7 @@
 .IR OBJECT " := { "
 .BR link " | " address " | " addrlabel " | " route " | " rule " | " neigh " | "\
  ntable " | " tunnel " | " tuntap " | " maddress " | "  mroute " | " mrule " | "\
- monitor " | " xfrm " | " netns " | "  l2tp " | "  tcp_metrics " | " token " | "\
- macsec " }"
+ monitor " | " xfrm " | " netns " | "  l2tp " | "  tcp_metrics " }"
 .sp
 
 .ti -8
@@ -30,29 +29,14 @@
 \fB\-V\fR[\fIersion\fR] |
 \fB\-h\fR[\fIuman-readable\fR] |
 \fB\-s\fR[\fItatistics\fR] |
-\fB\-d\fR[\fIetails\fR] |
 \fB\-r\fR[\fIesolve\fR] |
-\fB\-iec\fR |
 \fB\-f\fR[\fIamily\fR] {
-.BR inet " | " inet6 " | " link " } | "
-\fB-4\fR |
-\fB-6\fR |
-\fB-I\fR |
-\fB-D\fR |
-\fB-B\fR |
-\fB-0\fR |
-\fB-l\fR[\fIoops\fR] { \fBmaximum-addr-flush-attempts\fR } |
+.BR inet " | " inet6 " | " ipx " | " dnet " | " link " } | "
 \fB\-o\fR[\fIneline\fR] |
-\fB\-rc\fR[\fIvbuf\fR] [\fBsize\fR] |
-\fB\-t\fR[\fIimestamp\fR] |
-\fB\-ts\fR[\fIhort\fR] |
 \fB\-n\fR[\fIetns\fR] name |
-\fB\-N\fR[\fIumeric\fR] |
 \fB\-a\fR[\fIll\fR] |
-\fB\-c\fR[\fIolor\fR] |
-\fB\-br\fR[\fIief\fR] |
-\fB\-j\fR[son\fR] |
-\fB\-p\fR[retty\fR] }
+\fB\-c\fR[\fIolor\fR] }
+
 
 .SH OPTIONS
 
@@ -73,9 +57,8 @@
 
 .TP
 .BR "\-force"
-Don't terminate ip on errors in batch mode.  If there were any errors
-during execution of the commands, the application return code will be
-non zero.
+Don't terminate ip on errors in batch mode.
+If there were any errors during execution of the commands, the application return code will be non zero.
 
 .TP
 .BR "\-s" , " \-stats" , " \-statistics"
@@ -95,9 +78,8 @@
 
 .TP
 .BR "\-f" , " \-family " <FAMILY>
-Specifies the protocol family to use. The protocol family identifier
-can be one of
-.BR "inet" , " inet6" , " bridge" ,  " mpls"
+Specifies the protocol family to use. The protocol family identifier can be one of
+.BR "inet" , " inet6" , " bridge" , " ipx" , " dnet" , " mpls"
 or
 .BR link .
 If this option is not present,
@@ -129,6 +111,16 @@
 .BR "\-family bridge" .
 
 .TP
+.B \-D
+shortcut for
+.BR "\-family decnet" .
+
+.TP
+.B \-I
+shortcut for
+.BR "\-family ipx" .
+
+.TP
 .B \-M
 shortcut for
 .BR "\-family mpls" .
@@ -176,69 +168,17 @@
 .BR help " }"
 
 .TP
-.BR "\-N" , " \-Numeric"
-Print the number of protocol, scope, dsfield, etc directly instead of
-converting it to human readable name.
-
-.TP
 .BR "\-a" , " \-all"
-executes specified command over all objects, it depends if command
-supports this option.
+executes specified command over all objects, it depends if command supports this option.
 
 .TP
-.BR \-c [ color ][ = { always | auto | never }
-Configure color output. If parameter is omitted or
-.BR always ,
-color output is enabled regardless of stdout state. If parameter is
-.BR auto ,
-stdout is checked to be a terminal before enabling color output. If
-parameter is
-.BR never ,
-color output is disabled. If specified multiple times, the last one takes
-precedence. This flag is ignored if
-.B \-json
-is also given.
-
-Used color palette can be influenced by
-.BR COLORFGBG
-environment variable
-(see
-.BR ENVIRONMENT ).
+.BR "\-c" , " -color"
+Use color output.
 
 .TP
 .BR "\-t" , " \-timestamp"
 display current time when using monitor option.
 
-.TP
-.BR "\-ts" , " \-tshort"
-Like
-.BR \-timestamp ,
-but use shorter format.
-
-.TP
-.BR "\-rc" , " \-rcvbuf" <SIZE>
-Set the netlink socket receive buffer size, defaults to 1MB.
-
-.TP
-.BR "\-iec"
-print human readable rates in IEC units (e.g. 1Ki = 1024).
-
-.TP
-.BR "\-br" , " \-brief"
-Print only basic information in a tabular format for better
-readability. This option is currently only supported by
-.BR "ip addr show " and " ip link show " commands.
-
-.TP
-.BR "\-j", " \-json"
-Output results in JavaScript Object Notation (JSON).
-
-.TP
-.BR "\-p", " \-pretty"
-The default JSON format is compact and more efficient to parse but
-hard for most users to read.  This flag adds indentation for
-readability.
-
 .SH IP - COMMAND SYNTAX
 
 .SS
@@ -301,10 +241,6 @@
 - manage TCP Metrics
 
 .TP
-.B token
-- manage tokenized interface identifiers.
-
-.TP
 .B tunnel
 - tunnel over IP.
 
@@ -348,50 +284,10 @@
 or, if the objects of this class cannot be listed,
 .BR "help" .
 
-.SH ENVIRONMENT
-.TP
-.B COLORFGBG
-If set, it's value is used for detection whether background is dark or
-light and use contrast colors for it.
-
-COLORFGBG environment variable usually contains either two or three
-values separated by semicolons; we want the last value in either case.
-If this value is 0-6 or 8, chose colors suitable for dark background:
-
-COLORFGBG=";0" ip -c a
-
 .SH EXIT STATUS
 Exit status is 0 if command was successful, and 1 if there is a syntax error.
 If an error was reported by the kernel exit status is 2.
 
-.SH "EXAMPLES"
-.PP
-ip addr
-.RS 4
-Shows addresses assigned to all network interfaces.
-.RE
-.PP
-ip neigh
-.RS 4
-Shows the current neighbour table in kernel.
-.RE
-.PP
-ip link set x up
-.RS 4
-Bring up interface x.
-.RE
-.PP
-ip link set x down
-.RE
-.RS 4
-Bring down interface x.
-.RE
-.PP
-ip route
-.RS 4
-Show table routes.
-.RE
-
 .SH HISTORY
 .B ip
 was written by Alexey N. Kuznetsov and added in Linux 2.2.
@@ -409,7 +305,6 @@
 .BR ip-route (8),
 .BR ip-rule (8),
 .BR ip-tcp_metrics (8),
-.BR ip-token (8),
 .BR ip-tunnel (8),
 .BR ip-xfrm (8)
 .br
diff --git a/man/man8/lnstat.8 b/man/man8/lnstat.8
index b98241b..acd5f4a 100644
--- a/man/man8/lnstat.8
+++ b/man/man8/lnstat.8
@@ -254,7 +254,8 @@
 route cache removal, therefore always zero.
 
 .SH SEE ALSO
-.BR ip (8)
+.BR ip (8),
+and /usr/share/doc/iproute-doc/README.lnstat (package iproute-doc on Debian)
 .br
 .SH AUTHOR
 lnstat was written by Harald Welte <laforge@gnumonks.org>.
diff --git a/man/man8/rdma-dev.8 b/man/man8/rdma-dev.8
deleted file mode 100644
index 368cdc7..0000000
--- a/man/man8/rdma-dev.8
+++ /dev/null
@@ -1,98 +0,0 @@
-.TH RDMA\-DEV 8 "06 Jul 2017" "iproute2" "Linux"
-.SH NAME
-rdma-dev \- RDMA device configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B rdma
-.RI "[ " OPTIONS " ]"
-.B dev
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-d\fR[\fIetails\fR] }
-
-.ti -8
-.B rdma dev show
-.RI "[ " DEV " ]"
-
-.ti -8
-.B rdma dev set
-.RI "[ " DEV " ]"
-.BR name
-.BR NEWNAME
-
-.ti -8
-.B rdma dev set
-.RI "[ " DEV " ]"
-.BR netns
-.BR NSNAME
-
-.ti -8
-.B rdma dev set
-.RI "[ " DEV " ]"
-.BR adaptive-moderation
-.BR [on/off]
-
-.ti -8
-.B rdma dev help
-
-.SH "DESCRIPTION"
-.SS rdma dev set - rename RDMA device or set network namespace or set RDMA device adaptive-moderation
-
-.SS rdma dev show - display RDMA device attributes
-
-.PP
-.I "DEV"
-- specifies the RDMA device to show.
-If this argument is omitted all devices are listed.
-
-.SH "EXAMPLES"
-.PP
-rdma dev
-.RS 4
-Shows the state of all RDMA devices on the system.
-.RE
-.PP
-rdma dev show mlx5_3
-.RS 4
-Shows the state of specified RDMA device.
-.RE
-.PP
-rdma dev set mlx5_3 name rdma_0
-.RS 4
-Renames the mlx5_3 device to rdma_0.
-.RE
-.PP
-rdma dev set mlx5_3 netns foo
-.RS 4
-Changes the network namespace of RDMA device to foo where foo is
-previously created using iproute2 ip command.
-.RE
-.PP
-rdma dev set mlx5_3 adaptive-moderation [on/off]
-.RS 4
-Sets the state of adaptive interrupt moderation for the RDMA device.
-.RE
-.RS 4
-This is a global setting for the RDMA device but the value is printed for each CQ individually because the state is constant from CQ allocation.
-.RE
-.PP
-
-.SH SEE ALSO
-.BR ip (8),
-.BR rdma (8),
-.BR rdma-link (8),
-.BR rdma-resource (8),
-.BR rdma-system (8),
-.BR rdma-statistic (8),
-.br
-
-.SH AUTHOR
-Leon Romanovsky <leonro@mellanox.com>
diff --git a/man/man8/rdma-link.8 b/man/man8/rdma-link.8
deleted file mode 100644
index 32f8022..0000000
--- a/man/man8/rdma-link.8
+++ /dev/null
@@ -1,104 +0,0 @@
-.TH RDMA\-LINK 8 "06 Jul 2017" "iproute2" "Linux"
-.SH NAME
-rdma-link \- rdma link configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B devlink
-.RI "[ " OPTIONS " ]"
-.B link
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-d\fR[\fIetails\fR] }
-
-.ti -8
-.B rdma link show
-.RI "[ " DEV/PORT_INDEX " ]"
-
-.ti -8
-.B rdma link add
-.BR NAME
-.BR type
-.BR TYPE
-.BR netdev
-.BR NETDEV
-
-.ti -8
-.B rdma link delete
-.RI NAME
-
-.ti -8
-.B rdma link help
-
-.SH "DESCRIPTION"
-.SS rdma link show - display rdma link attributes
-
-.PP
-.I "DEV/PORT_INDEX"
-- specifies the RDMA link to show.
-If this argument is omitted all links are listed.
-
-.SS rdma link add NAME type TYPE netdev NETDEV - add an rdma link for the specified type to the network device
-.sp
-.BR NAME
-- specifies the new name of the rdma link to add
-
-.BR TYPE
-- specifies which rdma type to use.  Link types:
-.sp
-.in +8
-.B rxe
-- Soft RoCE driver
-.sp
-.B siw
-- Soft iWARP driver
-.in -8
-
-.BR NETDEV
-- specifies the network device to which the link is bound
-
-.SS rdma link delete NAME - delete an rdma link
-.PP
-.BR NAME
-- specifies the name of the rdma link to delete
-.PP
-
-.SH "EXAMPLES"
-.PP
-rdma link show
-.RS 4
-Shows the state of all rdma links on the system.
-.RE
-.PP
-rdma link show mlx5_2/1
-.RS 4
-Shows the state of specified rdma link.
-.RE
-.PP
-rdma link add rxe_eth0 type rxe netdev eth0
-.RS 4
-Adds a RXE link named rxe_eth0 to network device eth0
-.RE
-.PP
-rdma link del rxe_eth0
-.RS 4
-Removes RXE link rxe_eth0
-.RE
-.PP
-
-.SH SEE ALSO
-.BR rdma (8),
-.BR rdma-dev (8),
-.BR rdma-resource (8),
-.BR rdma-statistic (8),
-.br
-
-.SH AUTHOR
-Leon Romanovsky <leonro@mellanox.com>
diff --git a/man/man8/rdma-resource.8 b/man/man8/rdma-resource.8
deleted file mode 100644
index 05030d0..0000000
--- a/man/man8/rdma-resource.8
+++ /dev/null
@@ -1,110 +0,0 @@
-.TH RDMA\-RESOURCE 8 "26 Dec 2017" "iproute2" "Linux"
-.SH NAME
-rdma-resource \- rdma resource configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B rdma
-.RI "[ " OPTIONS " ] " RESOURCE " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR RESOURCE " := { "
-.BR cm_id " | " cq " | " mr " | " pd " | " qp " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-j\fR[\fIson\fR] |
-\fB\-d\fR[\fIetails\fR] }
-
-.ti -8
-.B rdma resource show
-.RI "[ " DEV/PORT_INDEX " ]"
-
-.ti -8
-.B rdma resource help
-
-.SH "DESCRIPTION"
-.SS rdma resource show - display rdma resource tracking information
-
-.PP
-.I "DEV/PORT_INDEX"
-- specifies the RDMA link to show.
-If this argument is omitted all links are listed.
-
-.SH "EXAMPLES"
-.PP
-rdma resource show
-.RS 4
-Shows summary for all devices on the system.
-.RE
-.PP
-rdma resource show mlx5_2
-.RS 4
-Shows the state of specified rdma device.
-.RE
-.PP
-rdma res show qp link mlx5_4
-.RS 4
-Get all QPs for the specific device.
-.RE
-.PP
-rdma res show qp link mlx5_4/1
-.RS 4
-Get QPs of specific port.
-.RE
-.PP
-rdma res show qp link mlx5_4/0
-.RS 4
-Provide illegal port number (0 is illegal).
-.RE
-.PP
-rdma res show qp link mlx5_4/-
-.RS 4
-Get QPs which have not assigned port yet.
-.RE
-.PP
-rdma res show qp link mlx5_4/- -d
-.RS 4
-Detailed view.
-.RE
-.PP
-rdma res show qp link mlx5_4/- -dd
-.RS 4
-Detailed view including driver-specific details.
-.RE
-.PP
-rdma res show qp link mlx5_4/1 lqpn 0-6
-.RS 4
-Limit to specific Local QPNs.
-.RE
-.PP
-rdma resource show cm_id dst-port 7174
-.RS 4
-Show CM_IDs with destination ip port of 7174.
-.RE
-.PP
-rdma resource show cm_id src-addr 172.16.0.100
-.RS 4
-Show CM_IDs bound to local ip address 172.16.0.100
-.RE
-.PP
-rdma resource show cq pid 30489
-.RS 4
-Show CQs belonging to pid 30489
-.RE
-.PP
-
-.SH SEE ALSO
-.BR rdma (8),
-.BR rdma-dev (8),
-.BR rdma-link (8),
-.BR rdma-statistic (8),
-.br
-
-.SH AUTHOR
-Leon Romanovsky <leonro@mellanox.com>
diff --git a/man/man8/rdma-statistic.8 b/man/man8/rdma-statistic.8
deleted file mode 100644
index dea6ff2..0000000
--- a/man/man8/rdma-statistic.8
+++ /dev/null
@@ -1,167 +0,0 @@
-.TH RDMA\-STATISTIC 8 "17 Mar 2019" "iproute2" "Linux"
-.SH NAME
-rdma-statistic \- RDMA statistic counter configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B rdma
-.RI "[ " OPTIONS " ]"
-.B statistic
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.B rdma statistic
-.RI "[ " OBJECT " ]"
-.B show
-
-.ti -8
-.B rdma statistic
-.RI "[ " OBJECT " ]"
-.B show link
-.RI "[ " DEV/PORT_INDX " ]"
-
-.ti -8
-.B rdma statistic
-.IR OBJECT
-.B mode
-
-.ti -8
-.B rdma statistic
-.IR OBJECT
-.B set
-.IR COUNTER_SCOPE
-.RI "[ " DEV/PORT_INDEX "]"
-.B auto
-.RI "{ " CRITERIA " | "
-.BR off " }"
-
-.ti -8
-.B rdma statistic
-.IR OBJECT
-.B bind
-.IR COUNTER_SCOPE
-.RI "[ " DEV/PORT_INDEX "]"
-.RI "[ " OBJECT-ID " ]"
-.RI "[ " COUNTER-ID " ]"
-
-.ti -8
-.B rdma statistic
-.IR OBJECT
-.B unbind
-.IR COUNTER_SCOPE
-.RI "[ " DEV/PORT_INDEX "]"
-.RI "[ " COUNTER-ID " ]"
-.RI "[ " OBJECT-ID " ]"
-
-.ti -8
-.IR COUNTER_SCOPE " := "
-.RB "{ " link " | " dev " }"
-
-.ti -8
-.IR OBJECT " := "
-.RB "{ " qp " }"
-
-.ti -8
-.IR CRITERIA " := "
-.RB "{ " type " }"
-
-.SH "DESCRIPTION"
-.SS rdma statistic [object] show - Queries the specified RDMA device for RDMA and driver-specific statistics. Show the default hw counters if object is not specified
-
-.PP
-.I "DEV"
-- specifies counters on this RDMA device to show.
-
-.I "PORT_INDEX"
-- specifies counters on this RDMA port to show.
-
-.SS rdma statistic <object> set - configure counter statistic auto-mode for a specific device/port
-In auto mode all objects belong to one category are bind automatically to a single counter set.
-
-.SS rdma statistic <object> bind - manually bind an object (e.g., a qp) with a counter
-When bound the statistics of this object are available in this counter.
-
-.SS rdma statistic <object> unbind - manually unbind an object (e.g., a qp) from the counter previously bound
-When unbound the statistics of this object are no longer available in this counter; And if object id is not specified then all objects on this counter will be unbound.
-
-.I "COUNTER-ID"
-- specifies the id of the counter to be bound.
-If this argument is omitted then a new counter will be allocated.
-
-.SH "EXAMPLES"
-.PP
-rdma statistic show
-.RS 4
-Shows the state of the default counter of all RDMA devices on the system.
-.RE
-.PP
-rdma statistic show link mlx5_2/1
-.RS 4
-Shows the state of the default counter of specified RDMA port
-.RE
-.PP
-rdma statistic qp show
-.RS 4
-Shows the state of all qp counters of all RDMA devices on the system.
-.RE
-.PP
-rdma statistic qp show link mlx5_2/1
-.RS 4
-Shows the state of all qp counters of specified RDMA port.
-.RE
-.PP
-rdma statistic qp show link mlx5_2 pid 30489
-.RS 4
-Shows the state of all qp counters of specified RDMA port and belonging to pid 30489
-.RE
-.PP
-rdma statistic qp mode
-.RS 4
-List current counter mode on all devices
-.RE
-.PP
-rdma statistic qp mode link mlx5_2/1
-.RS 4
-List current counter mode of device mlx5_2 port 1
-.RE
-.PP
-rdma statistic qp set link mlx5_2/1 auto type on
-.RS 4
-On device mlx5_2 port 1, for each new QP bind it with a counter automatically. Per counter for QPs with same qp type in each process. Currently only "type" is supported.
-.RE
-.PP
-rdma statistic qp set link mlx5_2/1 auto off
-.RS 4
-Turn-off auto mode on device mlx5_2 port 1. The allocated counters can be manually accessed.
-.RE
-.PP
-rdma statistic qp bind link mlx5_2/1 lqpn 178
-.RS 4
-On device mlx5_2 port 1, allocate a counter and bind the specified qp on it
-.RE
-.PP
-rdma statistic qp unbind link mlx5_2/1 cntn 4 lqpn 178
-.RS 4
-On device mlx5_2 port 1, bind the specified qp on the specified counter
-.RE
-.PP
-rdma statistic qp unbind link mlx5_2/1 cntn 4
-.RS 4
-On device mlx5_2 port 1, unbind all QPs on the specified counter. After that this counter will be released automatically by the kernel.
-
-.RE
-.PP
-
-.SH SEE ALSO
-.BR rdma (8),
-.BR rdma-dev (8),
-.BR rdma-link (8),
-.BR rdma-resource (8),
-.br
-
-.SH AUTHOR
-Mark Zhang <markz@mellanox.com>
diff --git a/man/man8/rdma-system.8 b/man/man8/rdma-system.8
deleted file mode 100644
index ab1d89f..0000000
--- a/man/man8/rdma-system.8
+++ /dev/null
@@ -1,82 +0,0 @@
-.TH RDMA\-SYSTEM 8 "06 Jul 2017" "iproute2" "Linux"
-.SH NAME
-rdma-system \- RDMA subsystem configuration
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B rdma
-.RI "[ " OPTIONS " ]"
-.B sys
-.RI  " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-d\fR[\fIetails\fR] }
-
-.ti -8
-.B rdma system show
-
-.ti -8
-.B rdma system set
-.BR netns
-.BR NEWMODE
-
-.ti -8
-.B rdma system help
-
-.SH "DESCRIPTION"
-.SS rdma system set - set RDMA subsystem network namespace mode
-
-.SS rdma system show - display RDMA subsystem network namespace mode
-
-.PP
-.I "NEWMODE"
-- specifies the RDMA subsystem mode. Either exclusive or shared.
-When user wants to assign dedicated RDMA device to a particular
-network namespace, exclusive mode should be set before creating
-any network namespace. If there are active network namespaces and if
-one or more RDMA devices exist, changing mode from shared to
-exclusive returns error code EBUSY.
-
-When RDMA subsystem is in shared mode, RDMA device is accessible in
-all network namespace. When RDMA device isolation among multiple
-network namespaces is not needed, shared mode can be used.
-
-It is preferred to not change the subsystem mode when there is active
-RDMA traffic running, even though it is supported.
-
-.SH "EXAMPLES"
-.PP
-rdma system show
-.RS 4
-Shows the state of RDMA subsystem network namespace mode on the system.
-.RE
-.PP
-rdma system set netns exclusive
-.RS 4
-Sets the RDMA subsystem in network namespace exclusive mode. In this mode RDMA devices
-are visible only in single network namespace.
-.RE
-.PP
-rdma system set netns shared
-.RS 4
-Sets the RDMA subsystem in network namespace shared mode. In this mode RDMA devices
-are shared among network namespaces.
-.RE
-.PP
-
-.SH SEE ALSO
-.BR rdma (8),
-.BR rdma-link (8),
-.BR rdma-resource (8),
-.BR network_namespaces (7),
-.BR namespaces (7),
-.br
-
-.SH AUTHOR
-Parav Pandit <parav@mellanox.com>
diff --git a/man/man8/rdma.8 b/man/man8/rdma.8
deleted file mode 100644
index ef29b1c..0000000
--- a/man/man8/rdma.8
+++ /dev/null
@@ -1,129 +0,0 @@
-.TH RDMA 8 "28 Mar 2017" "iproute2" "Linux"
-.SH NAME
-rdma \- RDMA tool
-.SH SYNOPSIS
-.sp
-.ad l
-.in +8
-.ti -8
-.B rdma
-.RI "[ " OPTIONS " ] " OBJECT " { " COMMAND " | "
-.BR help " }"
-.sp
-
-.ti -8
-.B rdma
-.RB "[ " -force " ] "
-.BI "-batch " filename
-.sp
-
-.ti -8
-.IR OBJECT " := { "
-.BR dev " | " link " | " system " | " statistic " }"
-.sp
-
-.ti -8
-.IR OPTIONS " := { "
-\fB\-V\fR[\fIersion\fR] |
-\fB\-d\fR[\fIetails\fR] }
-\fB\-j\fR[\fIson\fR] }
-\fB\-p\fR[\fIretty\fR] }
-
-.SH OPTIONS
-
-.TP
-.BR "\-V" , " -Version"
-Print the version of the
-.B rdma
-tool and exit.
-
-.TP
-.BR "\-b", " \-batch " <FILENAME>
-Read commands from provided file or standard input and invoke them.
-First failure will cause termination of rdma.
-
-.TP
-.BR "\-force"
-Don't terminate rdma on errors in batch mode.
-If there were any errors during execution of the commands, the application return code will be non zero.
-
-.TP
-.BR "\-d" , " --details"
-Output detailed information.  Adding a second \-d includes driver-specific details.
-
-.TP
-.BR "\-p" , " --pretty"
-When combined with -j generate a pretty JSON output.
-
-.TP
-.BR "\-j" , " --json"
-Generate JSON output.
-
-.SS
-.I OBJECT
-
-.TP
-.B dev
-- RDMA device.
-
-.TP
-.B link
-- RDMA port related.
-
-.TP
-.B sys
-- RDMA subsystem related.
-
-.TP
-.B statistic
-- RDMA counter statistic related.
-
-.PP
-The names of all objects may be written in full or
-abbreviated form, for example
-.B stats
-can be abbreviated as
-.B stat
-or just
-.B s.
-
-.SS
-.I COMMAND
-
-Specifies the action to perform on the object.
-The set of possible actions depends on the object type.
-As a rule, it is possible to
-.B show
-(or
-.B list
-) objects, but some objects do not allow all of these operations
-or have some additional commands. The
-.B help
-command is available for all objects. It prints
-out a list of available commands and argument syntax conventions.
-.sp
-If no command is given, some default command is assumed.
-Usually it is
-.B list
-or, if the objects of this class cannot be listed,
-.BR "help" .
-
-.SH EXIT STATUS
-Exit status is 0 if command was successful or a positive integer upon failure.
-
-.SH SEE ALSO
-.BR rdma-dev (8),
-.BR rdma-link (8),
-.BR rdma-resource (8),
-.BR rdma-system (8),
-.BR rdma-statistic (8),
-.br
-
-.SH REPORTING BUGS
-Report any bugs to the Linux RDMA mailing list
-.B <linux-rdma@vger.kernel.org>
-where the development and maintenance is primarily done.
-You do not have to be subscribed to the list to send a message there.
-
-.SH AUTHOR
-Leon Romanovsky <leonro@mellanox.com>
diff --git a/man/man8/routel.8 b/man/man8/routel.8
index 2270eac..82d580f 100644
--- a/man/man8/routel.8
+++ b/man/man8/routel.8
@@ -17,6 +17,11 @@
 .br
 The routef script does not take any arguments and will simply flush the routing table down the drain. Beware! This means deleting all routes which will make your network unusable!
 
+.SH "FILES"
+.LP
+\fI/usr/bin/routef\fP
+.br
+\fI/usr/bin/routel\fP
 .SH "AUTHORS"
 .LP
 The routel script was written by Stephen R. van den Berg <srb@cuci.nl>, 1999/04/18 and donated to the public domain.
diff --git a/man/man8/rtacct.8 b/man/man8/rtacct.8
index ccdbf6c..7cf97aa 100644
--- a/man/man8/rtacct.8
+++ b/man/man8/rtacct.8
@@ -4,7 +4,7 @@
 nstat, rtacct - network statistics tools.
 
 .SH SYNOPSIS
-Usage: nstat [ -h?vVzrnasd:t:jp ] [ PATTERN [ PATTERN ] ]
+Usage: nstat [ -h?vVzrnasd:t: ] [ PATTERN [ PATTERN ] ]
 .br
 Usage: rtacct [ -h?vVzrnasd:t: ] [ ListOfRealms ]
 
@@ -21,7 +21,7 @@
 .B \-V, \-\-version
 Print version
 .TP
-.B \-z, \-\-zeros
+.B \-z, \-\-zero
 Dump zero counters too. By default they are not shown.
 .TP
 .B \-r, \-\-reset
@@ -35,20 +35,15 @@
 .TP
 .B \-s, \-\-noupdate
 Do not update history, so that the next time you will see counters including values accumulated to the moment of this measurement too.
-.TP
 .B \-j, \-\-json
 Display results in JSON format.
 .TP
-.B \-p, \-\-pretty
-When combined with
-.BR \-\-json ,
-pretty print the output.
-.TP
-.B \-d, \-\-scan <INTERVAL>
+.B \-d, \-\-interval <INTERVAL>
 Run in daemon mode collecting statistics. <INTERVAL> is interval between measurements in seconds.
 .TP
-.B \-t, \-\-interval <INTERVAL>
+
 Time interval to average rates. Default value is 60 seconds.
+.TP
 
 .SH SEE ALSO
 lnstat(8)
diff --git a/man/man8/rtpr.8 b/man/man8/rtpr.8
index 87f291a..5e32b2e 100644
--- a/man/man8/rtpr.8
+++ b/man/man8/rtpr.8
@@ -5,7 +5,7 @@
 
 .SH DESCRIPTION
 .B rtpr
-is a trivial shell script which converts backslashes in standard input to newlines. It's sole purpose is to be fed with input from
+is a trivial bash script which converts backslashes in standard input to newlines. It's sole purpose is to be fed with input from
 .B ip
 when executed with it's
 .B --oneline
@@ -13,7 +13,7 @@
 
 .SH EXAMPLES
 .TP
-ip --oneline address show | rtpr
+ip --onenline address show | rtpr
 Undo oneline converted
 .B ip-address
 output.
diff --git a/man/man8/ss.8 b/man/man8/ss.8
index 023d771..758460c 100644
--- a/man/man8/ss.8
+++ b/man/man8/ss.8
@@ -9,11 +9,11 @@
 is used to dump socket statistics. It allows showing information similar
 to
 .IR netstat .
-It can display more TCP and state information than other tools.
+It can display more TCP and state informations than other tools.
 
 .SH OPTIONS
-When no option is used ss displays a list of open non-listening
-sockets (e.g. TCP/UNIX/UDP) that have established connection.
+When no option is used ss displays a list of
+open non-listening sockets (e.g. TCP/UNIX/UDP) that have established connection.
 .TP
 .B \-h, \-\-help
 Show summary of options.
@@ -21,265 +21,32 @@
 .B \-V, \-\-version
 Output version information.
 .TP
-.B \-H, \-\-no-header
-Suppress header line.
-.TP
-.B \-O, \-\-oneline
-Print each socket's data on a single line.
-.TP
 .B \-n, \-\-numeric
-Do not try to resolve service names. Show exact bandwidth values, instead of human-readable.
+Do not try to resolve service names.
 .TP
 .B \-r, \-\-resolve
 Try to resolve numeric address/ports.
 .TP
 .B \-a, \-\-all
-Display both listening and non-listening (for TCP this means
-established connections) sockets.
+Display both listening and non-listening (for TCP this means established connections) sockets.
 .TP
 .B \-l, \-\-listening
 Display only listening sockets (these are omitted by default).
 .TP
 .B \-o, \-\-options
-Show timer information. For TCP protocol, the output format is:
-.RS
-.P
-timer:(<timer_name>,<expire_time>,<retrans>)
-.P
-.TP
-.B <timer_name>
-the name of the timer, there are five kind of timer names:
-.RS
-.P
-.B on
-: means one of these timers: TCP retrans timer, TCP early retrans
-timer and tail loss probe timer
-.P
-.BR keepalive ": tcp keep alive timer"
-.P
-.BR timewait ": timewait stage timer"
-.P
-.BR persist ": zero window probe timer"
-.P
-.BR unknown ": none of the above timers"
-.RE
-.TP
-.B <expire_time>
-how long time the timer will expire
-.P
-.TP
-.B <retrans>
-how many times the retransmission occured
-.RE
+Show timer information.
 .TP
 .B \-e, \-\-extended
-Show detailed socket information. The output format is:
-.RS
-.P
-uid:<uid_number> ino:<inode_number> sk:<cookie>
-.P
-.TP
-.B <uid_number>
-the user id the socket belongs to
-.P
-.TP
-.B <inode_number>
-the socket's inode number in VFS
-.P
-.TP
-.B <cookie>
-an uuid of the socket
-.RE
+Show detailed socket information
 .TP
 .B \-m, \-\-memory
-Show socket memory usage. The output format is:
-.RS
-.P
-skmem:(r<rmem_alloc>,rb<rcv_buf>,t<wmem_alloc>,tb<snd_buf>,
-.br
-.RS
-.RS
-f<fwd_alloc>,w<wmem_queued>,o<opt_mem>,
-.RE
-.RE
-.br
-.RS
-.RS
-bl<back_log>,d<sock_drop>)
-.RE
-.RE
-.P
-.TP
-.B <rmem_alloc>
-the memory allocated for receiving packet
-.P
-.TP
-.B <rcv_buf>
-the total memory can be allocated for receiving packet
-.P
-.TP
-.B <wmem_alloc>
-the memory used for sending packet (which has been sent to layer 3)
-.P
-.TP
-.B <snd_buf>
-the total memory can be allocated for sending packet
-.P
-.TP
-.B <fwd_alloc>
-the memory allocated by the socket as cache, but not used for
-receiving/sending packet yet. If need memory to send/receive packet,
-the memory in this cache will be used before allocate additional
-memory.
-.P
-.TP
-.B <wmem_queued>
-The memory allocated for sending packet (which has not been sent to layer 3)
-.P
-.TP
-.B <ropt_mem>
-The memory used for storing socket option, e.g., the key for TCP MD5 signature
-.P
-.TP
-.B <back_log>
-The memory used for the sk backlog queue. On a process context, if the
-process is receiving packet, and a new packet is received, it will be
-put into the sk backlog queue, so it can be received by the process
-immediately
-.P
-.TP
-.B <sock_drop>
-the number of packets dropped before they are de-multiplexed into the socket
-.RE
+Show socket memory usage.
 .TP
 .B \-p, \-\-processes
 Show process using socket.
 .TP
 .B \-i, \-\-info
-Show internal TCP information. Below fields may appear:
-.RS
-.P
-.TP
-.B ts
-show string "ts" if the timestamp option is set
-.P
-.TP
-.B sack
-show string "sack" if the sack option is set
-.P
-.TP
-.B ecn
-show string "ecn" if the explicit congestion notification option is set
-.P
-.TP
-.B ecnseen
-show string "ecnseen" if the saw ecn flag is found in received packets
-.P
-.TP
-.B fastopen
-show string "fastopen" if the fastopen option is set
-.P
-.TP
-.B cong_alg
-the congestion algorithm name, the default congestion algorithm is "cubic"
-.P
-.TP
-.B wscale:<snd_wscale>:<rcv_wscale>
-if window scale option is used, this field shows the send scale factor
-and receive scale factor
-.P
-.TP
-.B rto:<icsk_rto>
-tcp re-transmission timeout value, the unit is millisecond
-.P
-.TP
-.B backoff:<icsk_backoff>
-used for exponential backoff re-transmission, the actual
-re-transmission timeout value is icsk_rto << icsk_backoff
-.P
-.TP
-.B rtt:<rtt>/<rttvar>
-rtt is the average round trip time, rttvar is the mean deviation of
-rtt, their units are millisecond
-.P
-.TP
-.B ato:<ato>
-ack timeout, unit is millisecond, used for delay ack mode
-.P
-.TP
-.B mss:<mss>
-max segment size
-.P
-.TP
-.B cwnd:<cwnd>
-congestion window size
-.P
-.TP
-.B pmtu:<pmtu>
-path MTU value
-.P
-.TP
-.B ssthresh:<ssthresh>
-tcp congestion window slow start threshold
-.P
-.TP
-.B bytes_acked:<bytes_acked>
-bytes acked
-.P
-.TP
-.B bytes_received:<bytes_received>
-bytes received
-.P
-.TP
-.B segs_out:<segs_out>
-segments sent out
-.P
-.TP
-.B segs_in:<segs_in>
-segments received
-.P
-.TP
-.B send <send_bps>bps
-egress bps
-.P
-.TP
-.B lastsnd:<lastsnd>
-how long time since the last packet sent, the unit is millisecond
-.P
-.TP
-.B lastrcv:<lastrcv>
-how long time since the last packet received, the unit is millisecond
-.P
-.TP
-.B lastack:<lastack>
-how long time since the last ack received, the unit is millisecond
-.P
-.TP
-.B pacing_rate <pacing_rate>bps/<max_pacing_rate>bps
-the pacing rate and max pacing rate
-.P
-.TP
-.B rcv_space:<rcv_space>
-a helper variable for TCP internal auto tuning socket receive buffer
-.RE
-.TP
-.B \-\-tos
-Show ToS and priority information. Below fields may appear:
-.RS
-.P
-.TP
-.B tos
-IPv4 Type-of-Service byte
-.P
-.TP
-.B tclass
-IPv6 Traffic Class byte
-.P
-.TP
-.B class_id
-Class id set by net_cls cgroup. If class is zero this shows priority
-set by SO_PRIORITY.
-.RE
+Show internal TCP information.
 .TP
 .B \-K, \-\-kill
 Attempts to forcibly close sockets. This option displays sockets that are
@@ -291,9 +58,6 @@
 summary from various sources. It is useful when amount of sockets is so huge
 that parsing /proc/net/tcp is painful.
 .TP
-.B \-E, \-\-events
-Continually display sockets as they are destroyed
-.TP
 .B \-Z, \-\-context
 As the
 .B \-p
@@ -329,8 +93,7 @@
 Switch to the specified network namespace name.
 .TP
 .B \-b, \-\-bpf
-Show socket BPF filters (only administrators are allowed to get these
-information).
+Show socket BPF filters (only administrators are allowed to get these information).
 .TP
 .B \-4, \-\-ipv4
 Display only IP version 4 sockets (alias for -f inet).
@@ -356,58 +119,42 @@
 .B \-x, \-\-unix
 Display Unix domain sockets (alias for -f unix).
 .TP
-.B \-S, \-\-sctp
-Display SCTP sockets.
-.TP
-.B \-\-vsock
-Display vsock sockets (alias for -f vsock).
-.TP
-.B \-\-xdp
-Display XDP sockets (alias for -f xdp).
-.TP
 .B \-f FAMILY, \-\-family=FAMILY
-Display sockets of type FAMILY.  Currently the following families are
-supported: unix, inet, inet6, link, netlink, vsock, xdp.
+Display sockets of type FAMILY.
+Currently the following families are supported: unix, inet, inet6, link, netlink.
 .TP
 .B \-A QUERY, \-\-query=QUERY, \-\-socket=QUERY
 List of socket tables to dump, separated by commas. The following identifiers
 are understood: all, inet, tcp, udp, raw, unix, packet, netlink, unix_dgram,
-unix_stream, unix_seqpacket, packet_raw, packet_dgram, dccp, sctp,
-vsock_stream, vsock_dgram, xdp Any item in the list may optionally be
-prefixed by an exclamation mark
-.RB ( ! )
-to exclude that socket table from being dumped.
+unix_stream, unix_seqpacket, packet_raw, packet_dgram.
 .TP
 .B \-D FILE, \-\-diag=FILE
-Do not display anything, just dump raw information about TCP sockets
-to FILE after applying filters. If FILE is - stdout is used.
+Do not display anything, just dump raw information about TCP sockets to FILE after applying filters. If FILE is - stdout is used.
 .TP
 .B \-F FILE, \-\-filter=FILE
-Read filter information from FILE.  Each line of FILE is interpreted
-like single command line option. If FILE is - stdin is used.
+Read filter information from FILE.
+Each line of FILE is interpreted like single command line option. If FILE is - stdin is used.
 .TP
 .B FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
-Please take a look at the official documentation for details regarding filters.
+Please take a look at the official documentation (Debian package iproute-doc) for details regarding filters.
 
 .SH STATE-FILTER
 
 .B STATE-FILTER
-allows to construct arbitrary set of states to match. Its syntax is
-sequence of keywords state and exclude followed by identifier of
-state.
+allows to construct arbitrary set of states to match. Its syntax is sequence of keywords state and exclude followed by identifier of state.
 .TP
 Available identifiers are:
 
 All standard TCP states:
 .BR established ", " syn-sent ", " syn-recv ", " fin-wait-1 ", " fin-wait-2 ", " time-wait ", " closed ", " close-wait ", " last-ack ", "
-.BR  listening " and " closing.
+.BR  listen " and " closing.
 
 .B all
 - for all the states
 
 .B connected
 - all the states except for
-.BR listening " and " closed
+.BR listen " and " closed
 
 .B synchronized
 - all the
@@ -441,13 +188,10 @@
 Find all local processes connected to X server.
 .TP
 .B ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 193.233.7/24
-List all the tcp sockets in state FIN-WAIT-1 for our apache to network
-193.233.7/24 and look at their timers.
-.TP
-.B ss -a -A 'all,!tcp'
-List sockets in all states from all socket tables but TCP.
+List all the tcp sockets in state FIN-WAIT-1 for our apache to network 193.233.7/24 and look at their timers.
 .SH SEE ALSO
 .BR ip (8),
+.BR /usr/share/doc/iproute-doc/ss.html " (package iproute­doc)",
 .br
 .BR RFC " 793 "
 - https://tools.ietf.org/rfc/rfc793.txt (TCP states)
diff --git a/man/man8/tc-actions.8 b/man/man8/tc-actions.8
deleted file mode 100644
index f46166e..0000000
--- a/man/man8/tc-actions.8
+++ /dev/null
@@ -1,244 +0,0 @@
-.TH "actions in tc" 8 "1 Aug 2017" "iproute2" "Linux"
-
-.SH NAME
-actions \- independently defined actions in tc
-.SH SYNOPSIS
-.B tc
-[
-.I TC_OPTIONS
-]
-.B actions
-.BR add " | " change " | " replace
-.I ACTSPEC
-
-.B tc
-[
-.I TC_OPTIONS
-]
-.B actions
-.BR get " | " delete
-.I ACTISPEC
-
-.B tc
-[
-.I TC_OPTIONS
-]
-.B actions flush
-.I ACTNAMESPEC
-
-.B tc
-[
-.I TC_OPTIONS
-]
-.B actions
-.BR ls " | " list
-.I ACTNAMESPEC
-[
-.I ACTFILTER
-]
-
-.in +8
-.I ACTSPEC
-:=
-.B action
-.I ACTDETAIL
-[
-.I INDEXSPEC
-] [
-.I COOKIESPEC
-] [
-.I CONTROL
-]
-
-.I ACTISPEC
-:=
-.I ACTNAMESPEC INDEXSPEC
-
-.I ACTNAMESPEC
-:=
-.B action
-ACTNAME
-
-.I INDEXSPEC
-:=
-.BI index " INDEX"
-
-.I ACTFILTER
-:=
-.BI since " MSTIME"
-
-.I COOKIESPEC
-:=
-.BI cookie " COOKIE"
-
-.I ACTDETAIL
-:=
-.I ACTNAME ACTPARAMS
-
-.I ACTNAME
-may be any valid action type: gact, mirred, bpf, connmark, csum, police, etc.
-
-.I MSTIME
-Time since last update.
-
-.I CONTROL
-:= {
-.IR reclassify " | " pipe " | " drop " | " continue " | " ok
-}
-
-.I TC_OPTIONS
-These are the options that are specific to
-.B tc
-and not only the options. Refer to
-.BR tc(8)
-for more information.
-.in
-
-.SH DESCRIPTION
-
-The
-.B actions
-object in
-.B tc
-allows a user to define actions independently of a classifier (filter). These
-actions can then be assigned to one or more filters, with any
-packets matching the classifier's criteria having that action performed
-on them.
-
-Each action type (mirred, police, etc.) will have its own table to store
-all created actions.
-
-.SH OPERATIONS
-.TP
-.B add
-Create a new action in that action's table.
-
-.TP
-.B change
-.TQ
-.B replace
-Make modifications to an existing action.
-.TP
-.B get
-Display the action with the specified index value. When combined with the
-.B -s
-option for
-.BR tc ","
-display the statistics for that action.
-.TP
-.B delete
-Delete the action with the specified index value. If the action is already
-associated with a classifier, it does not delete the classifier.
-.TP
-.B ls
-.TQ
-.B list
-List all the actions in the specified table. When combined with the
-.B -s
-option for
-.BR tc ","
-display the statistics for all actions in the specified table.
-When combined with the option
-.B since
-allows doing a millisecond time-filter since the last time an
-action was used in the datapath.
-.TP
-.B flush
-Delete all actions stored in the specified table.
-
-.SH ACTION OPTIONS
-Note that these options are available to all action types.
-.TP
-.BI index " INDEX"
-Specify the table index value of an action.
-.I INDEX
-is a 32-bit value that is unique to the specific type of action referenced.
-
-.RS
-For
-.BR add ", " change ", and"
-.B replace
-operations, the index is
-.BR optional.
-When adding a new action,
-specifying an index value will assign the action to that index unless that
-index value has already been assigned. Omitting the index value for an add
-operation will cause the kernel to assign a value to the new action.
-.RE
-
-.RS
-For
-.BR get " and " delete
-operations, the index is
-.B required
-to identify the specific action to be displayed or deleted.
-.RE
-
-.TP
-.BI cookie " COOKIE"
-In addition to the specific action, mark the matching packet with the value
-specified by
-.IR COOKIE "."
-The
-.I COOKIE
-is a 128-bit value that will not be interpreted by the kernel whatsoever.
-As such, it can be used as a correlating value for maintaining user state.
-The value to be stored is completely arbitrary and does not require a specific
-format. It is stored inside the action structure itself.
-
-.TP
-.BI since " MSTIME"
-When dumping large number of actions, a millisecond time-filter can be
-specified
-.IR MSTIME "."
-The
-.I MSTIME
-is a millisecond count since last time a packet hit the action.
-As an example specifying "since 20000" implies to dump all actions
-that have seen packets in the last 20 seconds. This option is useful
-when the kernel has a large number of actions and you are only interested
-in recently used actions.
-
-.TP
-.I CONTROL
-The
-.I CONTROL
-indicates how
-.B tc
-should proceed after executing the action. Any of the following are valid:
-.RS
-.TP
-.B reclassify
-Restart the classifiction by jumping back to the first filter attached to
-the action's parent.
-.TP
-.B pipe
-Continue with the next action. This is the default control.
-.TP
-.B drop
-Drop the packed without running any further actions.
-.TP
-.B continue
-Continue the classification with the next filter.
-.TP
-.B pass
-Return to the calling qdisc for packet processing, and end classification of
-this packet.
-.RE
-
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-bpf (8),
-.BR tc-connmark (8),
-.BR tc-csum (8),
-.BR tc-ife (8),
-.BR tc-mirred (8),
-.BR tc-nat (8),
-.BR tc-pedit (8),
-.BR tc-police (8),
-.BR tc-simple (8),
-.BR tc-skbedit (8),
-.BR tc-skbmod (8),
-.BR tc-tunnel_key (8),
-.BR tc-vlan (8),
-.BR tc-xt (8)
diff --git a/man/man8/tc-bpf.8 b/man/man8/tc-bpf.8
index e4f68aa..c8d5c5f 100644
--- a/man/man8/tc-bpf.8
+++ b/man/man8/tc-bpf.8
@@ -14,14 +14,6 @@
 UDS_FILE ] [
 .B verbose
 ] [
-.B direct-action
-|
-.B da
-] [
-.B skip_hw
-|
-.B skip_sw
-] [
 .B police
 POLICE_SPEC ] [
 .B action
@@ -79,39 +71,10 @@
 The kernel internally transforms cBPF expressions into eBPF expressions and
 executes the latter. Execution of them can be performed in an interpreter
 or at setup time, they can be just-in-time compiled (JIT'ed) to run as
-native machine code.
-.PP
-Currently, the eBPF JIT compiler is available for the following architectures:
-.IP * 4
-x86_64 (since Linux 3.18)
-.PD 0
-.IP *
-arm64 (since Linux 3.18)
-.IP *
-s390 (since Linux 4.1)
-.IP *
-ppc64 (since Linux 4.8)
-.IP *
-sparc64 (since Linux 4.12)
-.IP *
-mips64 (since Linux 4.13)
-.IP *
-arm32 (since Linux 4.14)
-.IP *
-x86_32 (since Linux 4.18)
-.PD
-.PP
-Whereas the following architectures have cBPF, but did not (yet) switch to eBPF
-JIT support:
-.IP * 4
-ppc32
-.PD 0
-.IP *
-sparc32
-.IP *
-mips32
-.PD
-.PP
+native machine code. Currently, x86_64, ARM64 and s390 architectures have
+eBPF JIT support, whereas PPC, SPARC, ARM and MIPS have cBPF, but did not
+(yet) switch to eBPF JIT support.
+
 eBPF's instruction set has similar underlying principles as the cBPF
 instruction set, it however is modelled closer to the underlying
 architecture to better mimic native instruction sets with the aim to
@@ -174,21 +137,6 @@
 program was successful. By default, only on error, the verifier log is
 being emitted to the user.
 
-.SS direct-action | da
-instructs eBPF classifier to not invoke external TC actions, instead use the
-TC actions return codes (\fBTC_ACT_OK\fR, \fBTC_ACT_SHOT\fR etc.) for
-classifiers.
-
-.SS skip_hw | skip_sw
-hardware offload control flags. By default TC will try to offload
-filters to hardware if possible.
-.B skip_hw
-explicitly disables the attempt to offload.
-.B skip_sw
-forces the offload and disables running the eBPF program in the kernel.
-If hardware offload is not possible and this flag was set kernel will
-report an error and filter will not be installed at all.
-
 .SS police
 is an optional parameter for an eBPF/cBPF classifier that specifies a
 police in
@@ -597,7 +545,6 @@
         .size_key       =       sizeof(uint32_t),
         .size_value     =       sizeof(struct tuple),
         .max_elem       =       BPF_MAX_MARK,
-        .pinning        =       PIN_GLOBAL_NS,
 };
 
 static inline void cls_update_stats(const struct __sk_buff *skb,
@@ -710,22 +657,13 @@
 #define likely(x) __builtin_expect(!!(x), 1)
 #define unlikely(x) __builtin_expect(!!(x), 0)
 
-/* Object pinning settings */
-#define PIN_NONE       0
-#define PIN_OBJECT_NS  1
-#define PIN_GLOBAL_NS  2
-
-/* ELF map definition */
+/* Used map structure */
 struct bpf_elf_map {
     __u32 type;
     __u32 size_key;
     __u32 size_value;
     __u32 max_elem;
-    __u32 flags;
     __u32 id;
-    __u32 pinning;
-    __u32 inner_id;
-    __u32 inner_idx;
 };
 
 /* Some used BPF function calls. */
diff --git a/man/man8/tc-cake.8 b/man/man8/tc-cake.8
deleted file mode 100644
index 4112b75..0000000
--- a/man/man8/tc-cake.8
+++ /dev/null
@@ -1,726 +0,0 @@
-.TH CAKE 8 "19 July 2018" "iproute2" "Linux"
-.SH NAME
-CAKE \- Common Applications Kept Enhanced (CAKE)
-.SH SYNOPSIS
-.B tc qdisc ... cake
-.br
-[
-.BR bandwidth
-RATE |
-.BR unlimited*
-|
-.BR autorate-ingress
-]
-.br
-[
-.BR rtt
-TIME |
-.BR datacentre
-|
-.BR lan
-|
-.BR metro
-|
-.BR regional
-|
-.BR internet*
-|
-.BR oceanic
-|
-.BR satellite
-|
-.BR interplanetary
-]
-.br
-[
-.BR besteffort
-|
-.BR diffserv8
-|
-.BR diffserv4
-|
-.BR diffserv3*
-]
-.br
-[
-.BR flowblind
-|
-.BR srchost
-|
-.BR dsthost
-|
-.BR hosts
-|
-.BR flows
-|
-.BR dual-srchost
-|
-.BR dual-dsthost
-|
-.BR triple-isolate*
-]
-.br
-[
-.BR nat
-|
-.BR nonat*
-]
-.br
-[
-.BR wash
-|
-.BR nowash*
-]
-.br
-[
-.BR split-gso*
-|
-.BR no-split-gso
-]
-.br
-[
-.BR ack-filter
-|
-.BR ack-filter-aggressive
-|
-.BR no-ack-filter*
-]
-.br
-[
-.BR memlimit
-LIMIT ]
-.br
-[
-.BR fwmark
-MASK ]
-.br
-[
-.BR ptm
-|
-.BR atm
-|
-.BR noatm*
-]
-.br
-[
-.BR overhead
-N |
-.BR conservative
-|
-.BR raw*
-]
-.br
-[
-.BR mpu
-N ]
-.br
-[
-.BR ingress
-|
-.BR egress*
-]
-.br
-(* marks defaults)
-
-
-.SH DESCRIPTION
-CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
-which uses both AQM and FQ.  It combines COBALT, which is an AQM algorithm
-combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
-of DRR++ for flow isolation.  8-way set-associative hashing is used to virtually
-eliminate hash collisions.  Priority queuing is available through a simplified
-diffserv implementation.  Overhead compensation for various encapsulation
-schemes is tightly integrated.
-
-All settings are optional; the default settings are chosen to be sensible in
-most common deployments.  Most people will only need to set the
-.B bandwidth
-parameter to get useful results, but reading the
-.B Overhead Compensation
-and
-.B Round Trip Time
-sections is strongly encouraged.
-
-.SH SHAPER PARAMETERS
-CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
-typical of token-bucket shapers.  It will automatically burst precisely as much
-as required to maintain the configured throughput.  As such, it is very
-straightforward to configure.
-.PP
-.B unlimited
-(default)
-.br
-	No limit on the bandwidth.
-.PP
-.B bandwidth
-RATE
-.br
-	Set the shaper bandwidth.  See
-.BR tc(8)
-or examples below for details of the RATE value.
-.PP
-.B autorate-ingress
-.br
-	Automatic capacity estimation based on traffic arriving at this qdisc.
-This is most likely to be useful with cellular links, which tend to change
-quality randomly.  A
-.B bandwidth
-parameter can be used in conjunction to specify an initial estimate.  The shaper
-will periodically be set to a bandwidth slightly below the estimated rate.  This
-estimator cannot estimate the bandwidth of links downstream of itself.
-
-.SH OVERHEAD COMPENSATION PARAMETERS
-The size of each packet on the wire may differ from that seen by Linux.  The
-following parameters allow CAKE to compensate for this difference by internally
-considering each packet to be bigger than Linux informs it.  To assist users who
-are not expert network engineers, keywords have been provided to represent a
-number of common link technologies.
-
-.SS	Manual Overhead Specification
-.B overhead
-BYTES
-.br
-	Adds BYTES to the size of each packet.  BYTES may be negative; values
-between -64 and 256 (inclusive) are accepted.
-.PP
-.B mpu
-BYTES
-.br
-	Rounds each packet (including overhead) up to a minimum length
-BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
-are accepted.
-.PP
-.B atm
-.br
-	Compensates for ATM cell framing, which is normally found on ADSL links.
-This is performed after the
-.B overhead
-parameter above.  ATM uses fixed 53-byte cells, each of which can carry 48 bytes
-payload.
-.PP
-.B ptm
-.br
-	Compensates for PTM encoding, which is normally found on VDSL2 links and
-uses a 64b/65b encoding scheme. It is even more efficient to simply
-derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
-ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
-.PP
-.B noatm
-.br
-	Disables ATM and PTM compensation.
-
-.SS	Failsafe Overhead Keywords
-These two keywords are provided for quick-and-dirty setup.  Use them if you
-can't be bothered to read the rest of this section.
-.PP
-.B raw
-(default)
-.br
-	Turns off all overhead compensation in CAKE.  The packet size reported
-by Linux will be used directly.
-.PP
-	Other overhead keywords may be added after "raw".  The effect of this is
-to make the overhead compensation operate relative to the reported packet size,
-not the underlying IP packet size.
-.PP
-.B conservative
-.br
-	Compensates for more overhead than is likely to occur on any
-widely-deployed link technology.
-.br
-	Equivalent to
-.B overhead 48 atm.
-
-.SS ADSL Overhead Keywords
-Most ADSL modems have a way to check which framing scheme is in use.  Often this
-is also specified in the settings document provided by the ISP.  The keywords in
-this section are intended to correspond with these sources of information.  All
-of them implicitly set the
-.B atm
-flag.
-.PP
-.B pppoa-vcmux
-.br
-	Equivalent to
-.B overhead 10 atm
-.PP
-.B pppoa-llc
-.br
-	Equivalent to
-.B overhead 14 atm
-.PP
-.B pppoe-vcmux
-.br
-	Equivalent to
-.B overhead 32 atm
-.PP
-.B pppoe-llcsnap
-.br
-	Equivalent to
-.B overhead 40 atm
-.PP
-.B bridged-vcmux
-.br
-	Equivalent to
-.B overhead 24 atm
-.PP
-.B bridged-llcsnap
-.br
-	Equivalent to
-.B overhead 32 atm
-.PP
-.B ipoa-vcmux
-.br
-	Equivalent to
-.B overhead 8 atm
-.PP
-.B ipoa-llcsnap
-.br
-	Equivalent to
-.B overhead 16 atm
-.PP
-See also the Ethernet Correction Factors section below.
-
-.SS VDSL2 Overhead Keywords
-ATM was dropped from VDSL2 in favour of PTM, which is a much more
-straightforward framing scheme.  Some ISPs retained PPPoE for compatibility with
-their existing back-end systems.
-.PP
-.B pppoe-ptm
-.br
-	Equivalent to
-.B overhead 30 ptm
-
-.br
-	PPPoE: 2B PPP + 6B PPPoE +
-.br
-	ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
-.br
-	PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
-.br
-.PP
-.B bridged-ptm
-.br
-	Equivalent to
-.B overhead 22 ptm
-.br
-	ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
-.br
-	PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
-.br
-.PP
-See also the Ethernet Correction Factors section below.
-
-.SS DOCSIS Cable Overhead Keyword
-DOCSIS is the universal standard for providing Internet service over cable-TV
-infrastructure.
-
-In this case, the actual on-wire overhead is less important than the packet size
-the head-end equipment uses for shaping and metering.  This is specified to be
-an Ethernet frame including the CRC (aka FCS).
-.PP
-.B docsis
-.br
-	Equivalent to
-.B overhead 18 mpu 64 noatm
-
-.SS Ethernet Overhead Keywords
-.PP
-.B ethernet
-.br
-	Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
-Sequence.  Use this keyword when the bottleneck being shaped for is an
-actual Ethernet cable.
-.br
-	Equivalent to
-.B overhead 38 mpu 84 noatm
-.PP
-.B ether-vlan
-.br
-	Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
-VLAN header appended to the Ethernet frame header.  NB: Some ISPs use one or
-even two of these within PPPoE; this keyword may be repeated as necessary to
-express this.
-
-.SH ROUND TRIP TIME PARAMETERS
-Active Queue Management (AQM) consists of embedding congestion signals in the
-packet flow, which receivers use to instruct senders to slow down when the queue
-is persistently occupied.  CAKE uses ECN signalling when available, and packet
-drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
-called COBALT.
-
-Very short latencies require a very rapid AQM response to adequately control
-latency.  However, such a rapid response tends to impair throughput when the
-actual RTT is relatively long.  CAKE allows specifying the RTT it assumes for
-tuning various parameters.  Actual RTTs within an order of magnitude of this
-will generally work well for both throughput and latency management.
-
-At the 'lan' setting and below, the time constants are similar in magnitude to
-the jitter in the Linux kernel itself, so congestion might be signalled
-prematurely. The flows will then become sparse and total throughput reduced,
-leaving little or no back-pressure for the fairness logic to work against. Use
-the "metro" setting for local lans unless you have a custom kernel.
-.PP
-.B rtt
-TIME
-.br
-	Manually specify an RTT.
-.PP
-.B datacentre
-.br
-	For extremely high-performance 10GigE+ networks only.  Equivalent to
-.B rtt 100us.
-.PP
-.B lan
-.br
-	For pure Ethernet (not Wi-Fi) networks, at home or in the office.  Don't
-use this when shaping for an Internet access link.  Equivalent to
-.B rtt 1ms.
-.PP
-.B metro
-.br
-	For traffic mostly within a single city.  Equivalent to
-.B rtt 10ms.
-.PP
-.B regional
-.br
-	For traffic mostly within a European-sized country.  Equivalent to
-.B rtt 30ms.
-.PP
-.B internet
-(default)
-.br
-	This is suitable for most Internet traffic.  Equivalent to
-.B rtt 100ms.
-.PP
-.B oceanic
-.br
-	For Internet traffic with generally above-average latency, such as that
-suffered by Australasian residents.  Equivalent to
-.B rtt 300ms.
-.PP
-.B satellite
-.br
-	For traffic via geostationary satellites.  Equivalent to
-.B rtt 1000ms.
-.PP
-.B interplanetary
-.br
-	So named because Jupiter is about 1 light-hour from Earth.  Use this to
-(almost) completely disable AQM actions.  Equivalent to
-.B rtt 3600s.
-
-.SH FLOW ISOLATION PARAMETERS
-With flow isolation enabled, CAKE places packets from different flows into
-different queues, each of which carries its own AQM state.  Packets from each
-queue are then delivered fairly, according to a DRR++ algorithm which minimises
-latency for "sparse" flows.  CAKE uses a set-associative hashing algorithm to
-minimise flow collisions.
-
-These keywords specify whether fairness based on source address, destination
-address, individual flows, or any combination of those is desired.
-.PP
-.B flowblind
-.br
-	Disables flow isolation; all traffic passes through a single queue for
-each tin.
-.PP
-.B srchost
-.br
-	Flows are defined only by source address.  Could be useful on the egress
-path of an ISP backhaul.
-.PP
-.B dsthost
-.br
-	Flows are defined only by destination address.  Could be useful on the
-ingress path of an ISP backhaul.
-.PP
-.B hosts
-.br
-	Flows are defined by source-destination host pairs.  This is host
-isolation, rather than flow isolation.
-.PP
-.B flows
-.br
-	Flows are defined by the entire 5-tuple of source address, destination
-address, transport protocol, source port and destination port.  This is the type
-of flow isolation performed by SFQ and fq_codel.
-.PP
-.B dual-srchost
-.br
-	Flows are defined by the 5-tuple, and fairness is applied first over
-source addresses, then over individual flows.  Good for use on egress traffic
-from a LAN to the internet, where it'll prevent any one LAN host from
-monopolising the uplink, regardless of the number of flows they use.
-.PP
-.B dual-dsthost
-.br
-	Flows are defined by the 5-tuple, and fairness is applied first over
-destination addresses, then over individual flows.  Good for use on ingress
-traffic to a LAN from the internet, where it'll prevent any one LAN host from
-monopolising the downlink, regardless of the number of flows they use.
-.PP
-.B triple-isolate
-(default)
-.br
-	Flows are defined by the 5-tuple, and fairness is applied over source
-*and* destination addresses intelligently (ie. not merely by host-pairs), and
-also over individual flows.  Use this if you're not certain whether to use
-dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
-host on *either* side of the link from monopolising it with a large number of
-flows.
-.PP
-.B nat
-.br
-	Instructs Cake to perform a NAT lookup before applying flow-isolation
-rules, to determine the true addresses and port numbers of the packet, to
-improve fairness between hosts "inside" the NAT.  This has no practical effect
-in "flowblind" or "flows" modes, or if NAT is performed on a different host.
-.PP
-.B nonat
-(default)
-.br
-	Cake will not perform a NAT lookup.  Flow isolation will be performed
-using the addresses and port numbers directly visible to the interface Cake is
-attached to.
-
-.SH PRIORITY QUEUE PARAMETERS
-CAKE can divide traffic into "tins" based on the Diffserv field.  Each tin has
-its own independent set of flow-isolation queues, and is serviced based on a WRR
-algorithm.  To avoid perverse Diffserv marking incentives, tin weights have a
-"priority sharing" value when bandwidth used by that tin is below a threshold,
-and a lower "bandwidth sharing" value when above.  Bandwidth is compared against
-the threshold using the same algorithm as the deficit-mode shaper.
-
-Detailed customisation of tin parameters is not provided.  The following presets
-perform all necessary tuning, relative to the current shaper bandwidth and RTT
-settings.
-.PP
-.B besteffort
-.br
-	Disables priority queuing by placing all traffic in one tin.
-.PP
-.B precedence
-.br
-	Enables legacy interpretation of TOS "Precedence" field.  Use of this
-preset on the modern Internet is firmly discouraged.
-.PP
-.B diffserv4
-.br
-	Provides a general-purpose Diffserv implementation with four tins:
-.br
-		Bulk (CS1), 6.25% threshold, generally low priority.
-.br
-		Best Effort (general), 100% threshold.
-.br
-		Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
-.br
-		Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
-.PP
-.B diffserv3
-(default)
-.br
-	Provides a simple, general-purpose Diffserv implementation with three tins:
-.br
-		Bulk (CS1), 6.25% threshold, generally low priority.
-.br
-		Best Effort (general), 100% threshold.
-.br
-		Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
-
-.PP
-.B fwmark
-MASK
-.br
-	This options turns on fwmark-based overriding of CAKE's tin selection.
-If set, the option specifies a bitmask that will be applied to the fwmark
-associated with each packet. If the result of this masking is non-zero, the
-result will be right-shifted by the number of least-significant unset bits in
-the mask value, and the result will be used as a the tin number for that packet.
-This can be used to set policies in a firewall script that will override CAKE's
-built-in tin selection.
-
-.SH OTHER PARAMETERS
-.B memlimit
-LIMIT
-.br
-	Limit the memory consumed by Cake to LIMIT bytes. Note that this does
-not translate directly to queue size (so do not size this based on bandwidth
-delay product considerations, but rather on worst case acceptable memory
-consumption), as there is some overhead in the data structures containing the
-packets, especially for small packets.
-
-	By default, the limit is calculated based on the bandwidth and RTT
-settings.
-
-.PP
-.B wash
-
-.br
-	Traffic entering your diffserv domain is frequently mis-marked in
-transit from the perspective of your network, and traffic exiting yours may be
-mis-marked from the perspective of the transiting provider.
-
-Apply the wash option to clear all extra diffserv (but not ECN bits), after
-priority queuing has taken place.
-
-If you are shaping inbound, and cannot trust the diffserv markings (as is the
-case for Comcast Cable, among others), it is best to use a single queue
-"besteffort" mode with wash.
-
-.PP
-.B split-gso
-
-.br
-	This option controls whether CAKE will split General Segmentation
-Offload (GSO) super-packets into their on-the-wire components and
-dequeue them individually.
-
-.br
-Super-packets are created by the networking stack to improve efficiency.
-However, because they are larger they take longer to dequeue, which
-translates to higher latency for competing flows, especially at lower
-bandwidths. CAKE defaults to splitting GSO packets to achieve the lowest
-possible latency. At link speeds higher than 10 Gbps, setting the
-no-split-gso parameter can increase the maximum achievable throughput by
-retaining the full GSO packets.
-
-.SH OVERRIDING CLASSIFICATION WITH TC FILTERS
-
-CAKE supports overriding of its internal classification of packets through the
-tc filter mechanism. Packets can be assigned to different priority tins by
-setting the
-.B priority
-field on the skb, and the flow hashing can be overridden by setting the
-.B classid
-parameter.
-
-.PP
-.B Tin override
-
-.br
-        To assign a priority tin, the major number of the priority field needs
-to match the qdisc handle of the cake instance; if it does, the minor number
-will be interpreted as the tin index. For example, to classify all ICMP packets
-as 'bulk', the following filter can be used:
-
-.br
-        # tc qdisc replace dev eth0 handle 1: root cake diffserv3
-        # tc filter add dev eth0 parent 1: protocol ip prio 1 \\
-          u32 match icmp type 0 0 action skbedit priority 1:1
-
-.PP
-.B Flow hash override
-
-.br
-        To override flow hashing, the classid can be set. CAKE will interpret
-the major number of the classid as the host hash used in host isolation mode,
-and the minor number as the flow hash used for flow-based queueing. One or both
-of those can be set, and will be used if the relevant flow isolation parameter
-is set (i.e., the major number will be ignored if CAKE is not configured in
-hosts mode, and the minor number will be ignored if CAKE is not configured in
-flows mode).
-
-.br
-This example will assign all ICMP packets to the first queue:
-
-.br
-        # tc qdisc replace dev eth0 handle 1: root cake
-        # tc filter add dev eth0 parent 1: protocol ip prio 1 \\
-          u32 match icmp type 0 0 classid 0:1
-
-.br
-If only one of the host and flow overrides is set, CAKE will compute the other
-hash from the packet as normal. Note, however, that the host isolation mode
-works by assigning a host ID to the flow queue; so if overriding both host and
-flow, the same flow cannot have more than one host assigned. In addition, it is
-not possible to assign different source and destination host IDs through the
-override mechanism; if a host ID is assigned, it will be used as both source and
-destination host.
-
-
-
-.SH EXAMPLES
-# tc qdisc delete root dev eth0
-.br
-# tc qdisc add root dev eth0 cake bandwidth 100Mbit ethernet
-.br
-# tc -s qdisc show dev eth0
-.br
-qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
- Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
- backlog 0b 0p requeues 0
- memory used: 0b of 5000000b
- capacity estimate: 100Mbit
- min/max network layer size:        65535 /       0
- min/max overhead-adjusted size:    65535 /       0
- average network hdr offset:            0
-
-                   Bulk  Best Effort        Voice
-  thresh       6250Kbit      100Mbit       25Mbit
-  target          5.0ms        5.0ms        5.0ms
-  interval      100.0ms      100.0ms      100.0ms
-  pk_delay          0us          0us          0us
-  av_delay          0us          0us          0us
-  sp_delay          0us          0us          0us
-  pkts                0            0            0
-  bytes               0            0            0
-  way_inds            0            0            0
-  way_miss            0            0            0
-  way_cols            0            0            0
-  drops               0            0            0
-  marks               0            0            0
-  ack_drop            0            0            0
-  sp_flows            0            0            0
-  bk_flows            0            0            0
-  un_flows            0            0            0
-  max_len             0            0            0
-  quantum           300         1514          762
-
-After some use:
-.br
-# tc -s qdisc show dev eth0
-
-qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
- Sent 44709231 bytes 31931 pkt (dropped 45, overlimits 93782 requeues 0)
- backlog 33308b 22p requeues 0
- memory used: 292352b of 5000000b
- capacity estimate: 100Mbit
- min/max network layer size:           28 /    1500
- min/max overhead-adjusted size:       84 /    1538
- average network hdr offset:           14
-
-                   Bulk  Best Effort        Voice
-  thresh       6250Kbit      100Mbit       25Mbit
-  target          5.0ms        5.0ms        5.0ms
-  interval      100.0ms      100.0ms      100.0ms
-  pk_delay        8.7ms        6.9ms        5.0ms
-  av_delay        4.9ms        5.3ms        3.8ms
-  sp_delay        727us        1.4ms        511us
-  pkts             2590        21271         8137
-  bytes         3081804     30302659     11426206
-  way_inds            0           46            0
-  way_miss            3           17            4
-  way_cols            0            0            0
-  drops              20           15           10
-  marks               0            0            0
-  ack_drop            0            0            0
-  sp_flows            2            4            1
-  bk_flows            1            2            1
-  un_flows            0            0            0
-  max_len          1514         1514         1514
-  quantum           300         1514          762
-
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-codel (8),
-.BR tc-fq_codel (8),
-.BR tc-htb (8)
-
-.SH AUTHORS
-Cake's principal author is Jonathan Morton, with contributions from
-Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
-Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
-
-This manual page was written by Loganaden Velvindron. Please report corrections
-to the Linux Networking mailing list <netdev@vger.kernel.org>.
diff --git a/man/man8/tc-cbs.8 b/man/man8/tc-cbs.8
deleted file mode 100644
index ad1d882..0000000
--- a/man/man8/tc-cbs.8
+++ /dev/null
@@ -1,124 +0,0 @@
-.TH CBS 8 "18 Sept 2017" "iproute2" "Linux"
-.SH NAME
-CBS \- Credit Based Shaper (CBS) Qdisc
-.SH SYNOPSIS
-.B tc qdisc ... dev
-dev
-.B parent
-classid
-.B [ handle
-major:
-.B ] cbs idleslope
-idleslope
-.B sendslope
-sendslope
-.B hicredit
-hicredit
-.B locredit
-locredit
-.B [ offload
-0|1
-.B ]
-
-.SH DESCRIPTION
-The CBS (Credit Based Shaper) qdisc implements the shaping algorithm
-defined by the IEEE 802.1Q-2014 Section 8.6.8.2, which applies a well
-defined rate limiting method to the traffic.
-
-This queueing discipline is intended to be used by TSN (Time Sensitive
-Networking) applications, the CBS parameters are derived directly by
-what is described by the Annex L of the IEEE 802.1Q-2014
-Specification. The algorithm and how it affects the latency are
-detailed there.
-
-CBS is meant to be installed under another qdisc that maps packet
-flows to traffic classes, one example is
-.BR mqprio(8).
-
-.SH PARAMETERS
-.TP
-idleslope
-Idleslope is the rate of credits that is accumulated (in kilobits per
-second) when there is at least one packet waiting for transmission.
-Packets are transmitted when the current value of credits is equal or
-greater than zero. When there is no packet to be transmitted the
-amount of credits is set to zero. This is the main tunable of the CBS
-algorithm and represents the bandwidth that will be consumed.
-Note that when calculating idleslope, the entire packet size must be
-considered, including headers from all layers (i.e. MAC framing and any
-overhead from the physical layer), as described by IEEE 802.1Q-2014
-section 34.4.
-
-As an example, for an ethernet frame carrying 284 bytes of payload,
-and with no VLAN tags, you must add 14 bytes for the Ethernet headers,
-4 bytes for the Frame check sequence (CRC), and 20 bytes for the L1
-overhead: 12 bytes of interpacket gap, 7 bytes of preamble and 1 byte
-of start of frame delimiter. That results in 322 bytes for the total
-packet size, which is then used for calculating the idleslope.
-
-.TP
-sendslope
-Sendslope is the rate of credits that is depleted (it should be a
-negative number of kilobits per second) when a transmission is
-occurring. It can be calculated as follows, (IEEE 802.1Q-2014 Section
-8.6.8.2 item g):
-
-sendslope = idleslope - port_transmit_rate
-
-.TP
-hicredit
-Hicredit defines the maximum amount of credits (in bytes) that can be
-accumulated. Hicredit depends on the characteristics of interfering
-traffic, 'max_interference_size' is the maximum size of any burst of
-traffic that can delay the transmission of a frame that is available
-for transmission for this traffic class, (IEEE 802.1Q-2014 Annex L,
-Equation L-3):
-
-hicredit = max_interference_size * (idleslope / port_transmit_rate)
-
-.TP
-locredit
-Locredit is the minimum amount of credits that can be reached. It is a
-function of the traffic flowing through this qdisc (IEEE 802.1Q-2014
-Annex L, Equation L-2):
-
-locredit = max_frame_size * (sendslope / port_transmit_rate)
-
-.TP
-offload
-When
-.B offload
-is 1,
-.BR cbs(8)
-will try to configure the network interface so the CBS algorithm runs
-in the controller. The default is 0.
-
-.SH EXAMPLES
-
-CBS is used to enforce a Quality of Service by limiting the data rate
-of a traffic class, to separate packets into traffic classes the user
-may choose
-.BR mqprio(8),
-and configure it like this:
-
-.EX
-# tc qdisc add dev eth0 handle 100: parent root mqprio num_tc 3 \\
-	map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \\
-	queues 1@0 1@1 2@2 \\
-	hw 0
-.EE
-.P
-To replace the current queuing disciple by CBS in the current queueing
-discipline connected to traffic class number 0, issue:
-.P
-.EX
-# tc qdisc replace dev eth0 parent 100:4 cbs \\
-	locredit -1470 hicredit 30 sendslope -980000 idleslope 20000
-.EE
-
-These values are obtained from the following parameters, idleslope is
-20mbit/s, the transmission rate is 1Gbit/s and the maximum interfering
-frame size is 1500 bytes.
-
-.SH AUTHORS
-Vinicius Costa Gomes <vinicius.gomes@intel.com>
diff --git a/man/man8/tc-codel.8 b/man/man8/tc-codel.8
index e538e94..a0e50a4 100644
--- a/man/man8/tc-codel.8
+++ b/man/man8/tc-codel.8
@@ -13,9 +13,7 @@
 .B ecn
 |
 .B noecn
-] [
-.B ce_threshold
-TIME ]
+]
 
 .SH DESCRIPTION
 CoDel (pronounced "coddle") is an adaptive "no-knobs" active queue management
@@ -82,12 +80,6 @@
 .B ecn
 is turned off.
 
-.SS ce_threshold
-sets a threshold above which all packets are marked with ECN Congestion
-Experienced. This is useful for DCTCP-style congestion control algorithms that
-require marking at very shallow queueing thresholds.
-
-
 .SH EXAMPLES
  # tc qdisc add dev eth0 root codel
  # tc -s qdisc show
diff --git a/man/man8/tc-connmark.8 b/man/man8/tc-connmark.8
deleted file mode 100644
index 44f29f5..0000000
--- a/man/man8/tc-connmark.8
+++ /dev/null
@@ -1,55 +0,0 @@
-.TH "Connmark retriever action in tc" 8 "11 Jan 2016" "iproute2" "Linux"
-
-.SH NAME
-connmark - netfilter connmark retriever action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action connmark " [ " zone"
-.IR u16_zone_index " ] [ " CONTROL " ] ["
-.BI index " u32_index "
-]
-
-.ti -8
-.IR CONTROL " := { " reclassify " | " pipe " | " drop " | " continue " | " ok " }"
-.SH DESCRIPTION
-The connmark action is used to restore the connection's mark value into the
-packet's fwmark.
-.SH OPTIONS
-.TP
-.BI zone " u16_zone_index"
-Specify the conntrack zone when doing conntrack lookups for packets.
-.I u16_zone_index
-is a 16bit unsigned decimal value.
-.TP
-.I CONTROL
-How to continue after executing this action.
-.RS
-.TP
-.B reclassify
-Restarts classification by jumping back to the first filter attached to this
-action's parent.
-.TP
-.B pipe
-Continue with the next action, this is the default.
-.TP
-.B drop
-.TQ
-.B shot
-Packet will be dropped without running further actions.
-.TP
-.B continue
-Continue classification with next filter in line.
-.TP
-.B pass
-Return to calling qdisc for packet processing. This ends the classification
-process.
-.RE
-.TP
-.BI index " u32_index "
-Specify an index for this action in order to being able to identify it in later
-commands.
-.I u32_index
-is a 32bit unsigned decimal value.
-.SH SEE ALSO
-.BR tc (8)
diff --git a/man/man8/tc-csum.8 b/man/man8/tc-csum.8
deleted file mode 100644
index 65724b8..0000000
--- a/man/man8/tc-csum.8
+++ /dev/null
@@ -1,72 +0,0 @@
-.TH "Checksum action in tc" 8 "11 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-csum - checksum update action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action csum"
-.I UPDATE
-
-.ti -8
-.IR UPDATE " := " TARGET " [ " UPDATE " ]"
-
-.ti -8
-.IR TARGET " := { "
-.BR ip4h " |"
-.BR icmp " |"
-.BR igmp " |"
-.BR tcp " |"
-.BR udp " |"
-.BR udplite " |"
-.BR sctp " |"
-.IR SWEETS " }"
-
-.ti -8
-.IR SWEETS " := { "
-.BR and " | " or " | " + " }"
-.SH DESCRIPTION
-The
-.B csum
-action triggers checksum recalculation of specified packet headers. It is
-commonly used to fix incorrect checksums after the
-.B pedit
-action has modified the packet content.
-.SH OPTIONS
-.TP
-.I TARGET
-Specify which headers to update: IPv4 header
-.RB ( ip4h ),
-ICMP header
-.RB ( icmp ),
-IGMP header
-.RB ( igmp ),
-TCP header
-.RB ( tcp ),
-UDP header
-.RB ( udp ),
-UDPLite header
-.RB ( udplite ") or"
-SCTP header
-.RB ( sctp ).
-.TP
-.B SWEETS
-These are merely syntactic sugar and ignored internally.
-.SH EXAMPLES
-The following performs stateless NAT for incoming packets from 192.0.2.100 to
-new destination 198.51.100.1. Assuming these are UDP
-packets, both IP and UDP checksums have to be recalculated:
-
-.RS
-.EX
-# tc qdisc add dev eth0 ingress handle ffff:
-# tc filter add dev eth0 prio 1 protocol ip parent ffff: \\
-	u32 match ip src 192.0.2.100/32 flowid :1 \\
-	action pedit munge ip dst set 198.51.100.1 pipe \\
-	csum ip and udp
-.EE
-.RE
-
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-pedit (8)
diff --git a/man/man8/tc-ctinfo.8 b/man/man8/tc-ctinfo.8
deleted file mode 100644
index 9015b84..0000000
--- a/man/man8/tc-ctinfo.8
+++ /dev/null
@@ -1,170 +0,0 @@
-.TH "ctinfo action in tc" 8 "4 Jun 2019" "iproute2" "Linux"
-.SH NAME
-ctinfo \- tc connmark processing action
-.SH SYNOPSIS
-.B tc ... action ctinfo
-[
-.B dscp
-MASK [STATEMASK] ] [
-.B cpmark
-[MASK] ] [
-.B zone
-ZONE ] [
-.B CONTROL
-] [
-.B index
-<INDEX>
-]
-
-.SH DESCRIPTION
-CTINFO (Conntrack Information) is a tc action for retrieving data from
-conntrack marks into various fields.  At present it has two independent
-processing modes which may be viewed as sub-functions.
-
-DSCP mode copies a DSCP stored in conntrack's connmark into the IPv4/v6 diffserv
-field.  The copying may conditionally occur based on a flag also stored in the
-connmark.  DSCP mode was designed to assist in restoring packet classifications on
-ingress, classifications which may then be used by qdiscs such as CAKE.  It may be
-used in any circumstance where ingress classification needs to be maintained across
-links that otherwise bleach or remap according to their own policies.
-
-CPMARK (copymark) mode copies the conntrack connmark into the packet's mark field.  Without
-additional parameters it is functionally completely equivalent to the existing
-connmark action.  An optional mask may be specified to mask which bits of the
-connmark are restored.  This may be useful when DSCP and CPMARK modes are combined.
-
-Simple statistics (tc -s) on DSCP restores and CPMARK copies are maintained where values for
-set indicate a count of packets altered for that mode.  DSCP includes an error count
-where the destination packet's diffserv field was unwriteable.
-.SH PARAMETERS
-.SS DSCP mode parameters:
-.IP mask
-A mask of 6 contiguous bits indicating where the DSCP value is located in the 32 bit
-conntrack mark field.  A mask must be provided for this mode.  mask is a 32 bit
-unsigned value.
-.IP statemask
-A mask of at least 1 bit indicating where a conditional restore flag is located in the
-32 bit conntrack mark field.  The statemask bit/s must NOT overlap the mask bits.  The
-DSCP will be restored if the conntrack mark logically ANDed with the statemask yields
-a non-zero result.  statemask is an optional unsigned 32 bit value.
-.SS CPMARK mode parameters:
-.IP mask
-Store the logically ANDed result of conntrack mark and mask into the packet's mark
-field.  Default is 0xffffffff i.e. the whole mark field.  mask is an optional unsigned 32 bit
-value
-.SS Overall action parameters:
-.IP zone
-Specify the conntrack zone when doing conntrack lookups for packets.
-zone is a 16bit unsigned decimal value.
-Default is 0.
-.IP CONTROL
-The following keywords allow to control how the tree of qdisc, classes,
-filters and actions is further traversed after this action.
-.RS
-.TP
-.B reclassify
-Restart with the first filter in the current list.
-.TP
-.B pipe
-Continue with the next action attached to the same filter.
-.TP
-.B drop
-Drop the packet.
-.TP
-.B shot
-synonym for
-.B drop
-.TP
-.B continue
-Continue classification with the next filter in line.
-.TP
-.B pass
-Finish classification process and return to calling qdisc for further packet
-processing. This is the default.
-.RE
-.IP index
-Specify an index for this action in order to being able to identify it in later
-commands. index is a 32bit unsigned decimal value.
-.SH EXAMPLES
-Example showing conditional restoration of DSCP on ingress via an IFB
-.RS
-.EX
-
-#Set up the IFB interface
-.br
-tc qdisc add dev ifb4eth0 handle ffff: ingress
-
-#Put CAKE qdisc on it
-.br
-tc qdisc add dev ifb4eth0 root cake bandwidth 40mbit
-
-#Set interface UP
-.br
-ip link set dev ifb4eth0 up
-
-#Add 2 actions, ctinfo to restore dscp & mirred to redirect the packets to IFB
-.br
-tc filter add dev eth0 parent ffff: protocol all prio 10 u32 \\
-    match u32 0 0 flowid 1:1 action    \\
-    ctinfo dscp 0xfc000000 0x01000000  \\
-    mirred egress redirect dev ifb4eth0
-
-tc -s qdisc show dev eth0 ingress
-
- filter parent ffff: protocol all pref 10 u32 chain 0
- filter parent ffff: protocol all pref 10 u32 chain 0 fh 800: ht divisor 1
- filter parent ffff: protocol all pref 10 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 not_in_hw
-  match 00000000/00000000 at 0
-    action order 1: ctinfo zone 0 pipe
-    index 2 ref 1 bind 1 dscp 0xfc000000 0x01000000 installed 72 sec used 0 sec DSCP set 1333 error 0 CPMARK set 0
-    Action statistics:
-    Sent 658484 bytes 1833 pkt (dropped 0, overlimits 0 requeues 0)
-    backlog 0b 0p requeues 0
-
-    action order 2: mirred (Egress Redirect to device ifb4eth0) stolen
-    index 1 ref 1 bind 1 installed 72 sec used 0 sec
-    Action statistics:
-    Sent 658484 bytes 1833 pkt (dropped 0, overlimits 0 requeues 0)
-    backlog 0b 0p requeues 0
-.EE
-.RE
-
-Example showing conditional restoration of DSCP on egress
-
-This may appear nonsensical since iptables marking of egress packets is easy
-to achieve, however the iptables flow classification rules may be extensive
-and so some sort of set once and forget may be useful especially on cpu
-constrained devices.
-.RS
-.EX
-
-# Send unmarked connections to a marking chain which needs to store a DSCP
-and set statemask bit in the connmark
-.br
-iptables -t mangle -A POSTROUTING -o eth0 -m connmark \\
-    --mark 0x00000000/0x01000000 -g CLASS_MARKING_CHAIN
-
-# Apply marked DSCP to the packets
-.br
-tc filter add dev eth0 protocol all prio 10 u32 \\
-    match u32 0 0 flowid 1:1 action \\
-    ctinfo dscp 0xfc000000 0x01000000
-
-tc -s filter show dev eth0
- filter parent 800e: protocol all pref 10 u32 chain 0
- filter parent 800e: protocol all pref 10 u32 chain 0 fh 800: ht divisor 1
- filter parent 800e: protocol all pref 10 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 not_in_hw
-  match 00000000/00000000 at 0
-    action order 1: ctinfo zone 0 pipe
-    index 1 ref 1 bind 1 dscp 0xfc000000 0x01000000 installed 7414 sec used 0 sec DSCP set 53404 error 0 CPMARK set 0
-    Action statistics:
-    Sent 32890260 bytes 120441 pkt (dropped 0, overlimits 0 requeues 0)
-    backlog 0b 0p requeues 0
-.br
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-cake (8)
-.BR tc-connmark (8)
-.BR tc-mirred (8)
-.SH AUTHORS
-ctinfo was written by Kevin Darbyshire-Bryant.
diff --git a/man/man8/tc-ematch.8 b/man/man8/tc-ematch.8
index 3df870f..b9bf70c 100644
--- a/man/man8/tc-ematch.8
+++ b/man/man8/tc-ematch.8
@@ -1,7 +1,7 @@
 .TH ematch 8 "6 August 2012" iproute2 Linux
 .
 .SH NAME
-ematch \- extended matches for use with "basic", "cgroup"  or "flow" filters
+ematch \- extended matches for use with "basic" or "flow" filters
 .
 .SH SYNOPSIS
 .sp
@@ -98,30 +98,6 @@
 the interface can be queried using "src,dst (source ip address, outgoing interface) or
 "src,src" (source ip address, incoming interface) syntax.
 
-.SS ipt
-test packet against xtables matches
-
-.IR ipt "( " [-6] " "-m " " MATCH_NAME " " FLAGS " )
-
-.IR MATCH_NAME " := " string
-
-.IR FLAGS " := { " FLAG " [, " FLAGS "] }
-
-The flag options are the same as those used by the xtable match used.
-
-.SS canid
-ematch rule to match CAN frames
-
-.IR canid "( " IDLIST " )
-
-.IR IDLIST " :=  " IDSPEC [ IDLIST ]
-
-.IR IDSPEC " := { ’sff’ " CANID " | ’eff’ " CANID " }
-
-.IR CANID " := " ID [ ":MASK" ]
-
-.IR ID ", " MASK " := hexadecimal number (i.e. 0x123)
-
 .SH CAVEATS
 
 The ematch syntax uses '(' and ')' to group expressions. All braces need to be
@@ -151,10 +127,6 @@
 
 # 'ipset(interactive src,src)'
 
-Check if packet matches an IPSec state with reqid 1:
-
-# 'ipt(-m policy --dir in --pol ipsec --reqid 1)'
-
 .SH "AUTHOR"
 
 The extended match infrastructure was added by Thomas Graf.
diff --git a/man/man8/tc-etf.8 b/man/man8/tc-etf.8
deleted file mode 100644
index 4cb3b9e..0000000
--- a/man/man8/tc-etf.8
+++ /dev/null
@@ -1,151 +0,0 @@
-.TH ETF 8 "05 Jul 2018" "iproute2" "Linux"
-.SH NAME
-ETF \- Earliest TxTime First (ETF) Qdisc
-.SH SYNOPSIS
-.B tc qdisc ... dev
-dev
-.B parent
-classid
-.B [ handle
-major:
-.B ] etf clockid
-clockid
-.B [ delta
-delta_nsecs
-.B ] [ deadline_mode ]
-.B [ offload ]
-
-.SH DESCRIPTION
-The ETF (Earliest TxTime First) qdisc allows applications to control
-the instant when a packet should be dequeued from the traffic control
-layer into the netdevice. If
-.B offload
-is configured and supported by the network interface card, the it will
-also control when packets leave the network controller.
-
-ETF achieves that by buffering packets until a configurable time
-before their transmission time (i.e. txtime, or deadline), which can
-be configured through the
-.B delta
-option.
-
-The qdisc uses a rb-tree internally so packets are always 'ordered' by
-their txtime and will be dequeued following the (next) earliest txtime
-first.
-
-It relies on the SO_TXTIME socket option and the SCM_TXTIME CMSG in
-each packet field to configure the behavior of time dependent sockets:
-the clockid to be used as a reference, if the expected mode of txtime
-for that socket is deadline or strict mode, and if packet drops should
-be reported on the socket's error queue. See
-.BR socket(7)
-for more information.
-
-The etf qdisc will drop any packets with a txtime in the past, or if a
-packet expires while waiting for being dequeued.
-
-This queueing discipline is intended to be used by TSN (Time Sensitive
-Networking) applications, and it exposes a traffic shaping functionality
-that is commonly documented as "Launch Time" or "Time-Based Scheduling"
-by vendors and the documentation of network interface controllers.
-
-ETF is meant to be installed under another qdisc that maps packet flows
-to traffic classes, one example is
-.BR mqprio(8).
-
-.SH PARAMETERS
-.TP
-clockid
-.br
-Specifies the clock to be used by qdisc's internal timer for measuring
-time and scheduling events. The qdisc expects that packets passing
-through it to be using this same
-.B clockid
-as the reference of their txtime timestamps. It will drop packets
-coming from sockets that do not comply with that.
-
-For more information about time and clocks on Linux, please refer
-to
-.BR time(7)
-and
-.BR clock_gettime(3).
-
-.TP
-delta
-.br
-After enqueueing or dequeueing a packet, the qdisc will schedule its
-next wake-up time for the next txtime minus this delta value.
-This means
-.B delta
-can be used as a fudge factor for the scheduler latency of a system.
-This value must be specified in nanoseconds.
-The default value is 0 nanoseconds.
-
-.TP
-deadline_mode
-.br
-When
-.B deadline_mode
-is set, the qdisc will handle txtime with a different semantics,
-changed from a 'strict' transmission time to a deadline.
-In practice, this means during the dequeue flow
-.BR etf(8)
-will set the txtime of the packet being dequeued to 'now'.
-The default is for this option to be disabled.
-
-.TP
-offload
-.br
-When
-.B offload
-is set,
-.BR etf(8)
-will try to configure the network interface so time-based transmission
-arbitration is enabled in the controller. This feature is commonly
-referred to as "Launch Time" or "Time-Based Scheduling" by the
-documentation of network interface controllers.
-The default is for this option to be disabled.
-
-.TP
-skip_sock_check
-.br
-.BR etf(8)
-currently drops any packet which does not have a socket associated with it or
-if the socket does not have SO_TXTIME socket option set. But, this will not
-work if the launchtime is set by another entity inside the kernel (e.g. some
-other Qdisc). Setting the skip_sock_check will skip checking for a socket
-associated with the packet.
-
-.SH EXAMPLES
-
-ETF is used to enforce a Quality of Service. It controls when each
-packets should be dequeued and transmitted, and can be used for
-limiting the data rate of a traffic class. To separate packets into
-traffic classes the user may choose
-.BR mqprio(8),
-and configure it like this:
-
-.EX
-# tc qdisc add dev eth0 handle 100: parent root mqprio num_tc 3 \\
-	map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \\
-	queues 1@0 1@1 2@2 \\
-	hw 0
-.EE
-.P
-To replace the current queueing discipline by ETF in traffic class
-number 0, issue:
-.P
-.EX
-# tc qdisc replace dev eth0 parent 100:1 etf \\
-	clockid CLOCK_TAI delta 300000 offload
-.EE
-
-With the options above, etf will be configured to use CLOCK_TAI as
-its clockid_t, will schedule packets for 300 us before their txtime,
-and will enable the functionality on that in the network interface
-card. Deadline mode will not be configured for this mode.
-
-.SH AUTHORS
-Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
-.br
-Vinicius Costa Gomes <vinicius.gomes@intel.com>
diff --git a/man/man8/tc-flow.8 b/man/man8/tc-flow.8
index 54f6bf7..f1b7e2a 100644
--- a/man/man8/tc-flow.8
+++ b/man/man8/tc-flow.8
@@ -73,10 +73,8 @@
 .I ID
 may be
 .BR root ", " none
-or a hexadecimal class ID in the form [\fIX\fB:\fR]\fIY\fR. \fIX\fR must
-match qdisc's/class's major handle (if omitted, the correct value is chosen
-automatically). If the whole \fBbaseclass\fR is omitted, \fIY\fR defaults
-to 1.
+or a hexadecimal class ID in the form [\fIX\fB:\fR]\fIY\fR. If \fIX\fR is
+omitted, it is assumed to be zero.
 .TP
 .BI divisor " NUM"
 Number of buckets to use for sorting into. Keys are calculated modulo
@@ -241,7 +239,7 @@
 	divisor 1024
 .EE
 .TP
-Map destination IPs of 192.168.0.0/24 to classids 1-256:
+Map destination IPs of 192.168.0.0/24 to classids 1-257:
 
 .EX
 tc filter add ... flow map \\
diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
index 04ee194..df4d8e1 100644
--- a/man/man8/tc-flower.8
+++ b/man/man8/tc-flower.8
@@ -10,10 +10,7 @@
 .B action
 .IR ACTION_SPEC " ] [ "
 .B classid
-.IR CLASSID " ] [ "
-.B hw_tc
-.IR TCID " ]"
-
+.IR CLASSID " ]"
 
 .ti -8
 .IR MATCH_LIST " := [ " MATCH_LIST " ] " MATCH
@@ -21,70 +18,17 @@
 .ti -8
 .IR MATCH " := { "
 .B indev
-.IR ifname " | "
-.BR verbose
-.RI " | "
-.BR skip_sw " | " skip_hw
-.RI " | { "
+.IR ifname " | { "
 .BR dst_mac " | " src_mac " } "
-.IR MASKED_LLADDR " | "
-.B vlan_id
-.IR VID " | "
-.B vlan_prio
-.IR PRIORITY " | "
-.BR vlan_ethtype " { " ipv4 " | " ipv6 " | "
+.IR mac_address " | "
+.BR eth_type " { " ipv4 " | " ipv6 " | "
 .IR ETH_TYPE " } | "
-.B cvlan_id
-.IR VID " | "
-.B cvlan_prio
-.IR PRIORITY " | "
-.BR cvlan_ethtype " { " ipv4 " | " ipv6 " | "
-.IR ETH_TYPE " } | "
-.B mpls_label
-.IR LABEL " | "
-.B mpls_tc
-.IR TC " | "
-.B mpls_bos
-.IR BOS " | "
-.B mpls_ttl
-.IR TTL " | "
-.BR ip_proto " { " tcp " | " udp " | " sctp " | " icmp " | " icmpv6 " | "
-.IR IP_PROTO " } | "
-.B ip_tos
-.IR MASKED_IP_TOS " | "
-.B ip_ttl
-.IR MASKED_IP_TTL " | { "
-.BR dst_ip " | " src_ip " } "
-.IR PREFIX " | { "
-.BR dst_port " | " src_port " } { "
-.IR port_number " | "
-.IR min_port_number-max_port_number " } | "
-.B tcp_flags
-.IR MASKED_TCP_FLAGS " | "
-.B type
-.IR MASKED_TYPE " | "
-.B code
-.IR MASKED_CODE " | { "
-.BR arp_tip " | " arp_sip " } "
-.IR IPV4_PREFIX " | "
-.BR arp_op " { " request " | " reply " | "
-.IR OP " } | { "
-.BR arp_tha " | " arp_sha " } "
-.IR MASKED_LLADDR " | "
-.B enc_key_id
-.IR KEY-ID " | {"
-.BR enc_dst_ip " | " enc_src_ip " } { "
-.IR ipv4_address " | " ipv6_address " } | "
-.B enc_dst_port
-.IR port_number " | "
-.B enc_tos
-.IR TOS " | "
-.B enc_ttl
-.IR TTL " | "
-.B geneve_opts
-.IR OPTIONS " | "
-.BR ip_flags
-.IR IP_FLAGS
+.BR ip_proto " { " tcp " | " udp " | "
+.IR IP_PROTO " } | { "
+.BR dst_ip " | " src_ip " } { "
+.IR ipv4_address " | " ipv6_address " } | { "
+.BR dst_port " | " src_port " } "
+.IR port_number " }"
 .SH DESCRIPTION
 The
 .B flower
@@ -103,10 +47,6 @@
 .BR X : Y ", while " X " and " Y
 are interpreted as numbers in hexadecimal format.
 .TP
-.BI hw_tc " TCID"
-Specify a hardware traffic class to pass matching packets on to. TCID is in the
-range 0 through 15.
-.TP
 .BI indev " ifname"
 Match on incoming interface name. Obviously this makes sense only for forwarded
 flows.
@@ -115,267 +55,56 @@
 .B tc
 invocation.
 .TP
-.BI verbose
-Enable verbose logging, including offloading errors when not using
-.B skip_sw
-flag.
-.TP
-.BI skip_sw
-Do not process filter by software. If hardware has no offload support for this
-filter, or TC offload is not enabled for the interface, operation will fail.
-.TP
-.BI skip_hw
-Do not process filter by hardware.
-.TP
-.BI dst_mac " MASKED_LLADDR"
+.BI dst_mac " mac_address"
 .TQ
-.BI src_mac " MASKED_LLADDR"
-Match on source or destination MAC address.  A mask may be optionally
-provided to limit the bits of the address which are matched. A mask is
-provided by following the address with a slash and then the mask. It may be
-provided in LLADDR format, in which case it is a bitwise mask, or as a
-number of high bits to match. If the mask is missing then a match on all
-bits is assumed.
+.BI src_mac " mac_address"
+Match on source or destination MAC address.
 .TP
-.BI vlan_id " VID"
-Match on vlan tag id.
-.I VID
-is an unsigned 12bit value in decimal format.
-.TP
-.BI vlan_prio " PRIORITY"
-Match on vlan tag priority.
-.I PRIORITY
-is an unsigned 3bit value in decimal format.
-.TP
-.BI vlan_ethtype " VLAN_ETH_TYPE"
+.BI eth_type " ETH_TYPE"
 Match on layer three protocol.
-.I VLAN_ETH_TYPE
+.I ETH_TYPE
 may be either
-.BR ipv4 ", " ipv6
-or an unsigned 16bit value in hexadecimal format. To match on QinQ packet, it must be 802.1Q or 802.1AD.
-.TP
-.BI cvlan_id " VID"
-Match on QinQ inner vlan tag id.
-.I VID
-is an unsigned 12bit value in decimal format.
-.TP
-.BI cvlan_prio " PRIORITY"
-Match on QinQ inner vlan tag priority.
-.I PRIORITY
-is an unsigned 3bit value in decimal format.
-.TP
-.BI cvlan_ethtype " VLAN_ETH_TYPE"
-Match on QinQ layer three protocol.
-.I VLAN_ETH_TYPE
-may be either
-.BR ipv4 ", " ipv6
+.BR ipv4 , ipv6
 or an unsigned 16bit value in hexadecimal format.
 .TP
-.BI mpls_label " LABEL"
-Match the label id in the outermost MPLS label stack entry.
-.I LABEL
-is an unsigned 20 bit value in decimal format.
-.TP
-.BI mpls_tc " TC"
-Match on the MPLS TC field, which is typically used for packet priority,
-in the outermost MPLS label stack entry.
-.I TC
-is an unsigned 3 bit value in decimal format.
-.TP
-.BI mpls_bos " BOS"
-Match on the MPLS Bottom Of Stack field in the outermost MPLS label stack
-entry.
-.I BOS
-is a 1 bit value in decimal format.
-.TP
-.BI mpls_ttl " TTL"
-Match on the MPLS Time To Live field in the outermost MPLS label stack
-entry.
-.I TTL
-is an unsigned 8 bit value in decimal format.
-.TP
 .BI ip_proto " IP_PROTO"
 Match on layer four protocol.
 .I IP_PROTO
-may be
-.BR tcp ", " udp ", " sctp ", " icmp ", " icmpv6
+may be either
+.BR tcp , udp
 or an unsigned 8bit value in hexadecimal format.
 .TP
-.BI ip_tos " MASKED_IP_TOS"
-Match on ipv4 TOS or ipv6 traffic-class - eight bits in hexadecimal format.
-A mask may be optionally provided to limit the bits which are matched. A mask
-is provided by following the value with a slash and then the mask. If the mask
-is missing then a match on all bits is assumed.
-.TP
-.BI ip_ttl " MASKED_IP_TTL"
-Match on ipv4 TTL or ipv6 hop-limit  - eight bits value in decimal or hexadecimal format.
-A mask may be optionally provided to limit the bits which are matched. Same
-logic is used for the mask as with matching on ip_tos.
-.TP
-.BI dst_ip " PREFIX"
+.BI dst_ip " ADDRESS"
 .TQ
-.BI src_ip " PREFIX"
+.BI src_ip " ADDRESS"
 Match on source or destination IP address.
-.I PREFIX
-must be a valid IPv4 or IPv6 address, depending on the \fBprotocol\fR
-option to tc filter, optionally followed by a slash and the prefix length.
-If the prefix is missing, \fBtc\fR assumes a full-length host match.
+.I ADDRESS
+must be a valid IPv4 or IPv6 address, depending on
+.BR ether_type ,
+which has to be specified in beforehand.
 .TP
-.IR \fBdst_port " { "  NUMBER " | " " MIN_VALUE-MAX_VALUE "  }
+.BI dst_port " NUMBER"
 .TQ
-.IR \fBsrc_port " { "  NUMBER " | " " MIN_VALUE-MAX_VALUE "  }
-Match on layer 4 protocol source or destination port number. Alternatively, the
-mininum and maximum values can be specified to match on a range of layer 4
-protocol source or destination port numbers. Only available for
-.BR ip_proto " values " udp ", " tcp  " and " sctp
-which have to be specified in beforehand.
-.TP
-.BI tcp_flags " MASKED_TCP_FLAGS"
-Match on TCP flags represented as 12bit bitfield in in hexadecimal format.
-A mask may be optionally provided to limit the bits which are matched. A mask
-is provided by following the value with a slash and then the mask. If the mask
-is missing then a match on all bits is assumed.
-.TP
-.BI type " MASKED_TYPE"
-.TQ
-.BI code " MASKED_CODE"
-Match on ICMP type or code. A mask may be optionally provided to limit the
-bits of the address which are matched. A mask is provided by following the
-address with a slash and then the mask. The mask must be as a number which
-represents a bitwise mask If the mask is missing then a match on all bits
-is assumed.  Only available for
-.BR ip_proto " values " icmp  " and " icmpv6
-which have to be specified in beforehand.
-.TP
-.BI arp_tip " IPV4_PREFIX"
-.TQ
-.BI arp_sip " IPV4_PREFIX"
-Match on ARP or RARP sender or target IP address.
-.I IPV4_PREFIX
-must be a valid IPv4 address optionally followed by a slash and the prefix
-length. If the prefix is missing, \fBtc\fR assumes a full-length host
-match.
-.TP
-.BI arp_op " ARP_OP"
-Match on ARP or RARP operation.
-.I ARP_OP
-may be
-.BR request ", " reply
-or an integer value 0, 1 or 2.  A mask may be optionally provided to limit
-the bits of the operation which are matched. A mask is provided by
-following the address with a slash and then the mask. It may be provided as
-an unsigned 8 bit value representing a bitwise mask. If the mask is missing
-then a match on all bits is assumed.
-.TP
-.BI arp_sha " MASKED_LLADDR"
-.TQ
-.BI arp_tha " MASKED_LLADDR"
-Match on ARP or RARP sender or target MAC address.  A mask may be optionally
-provided to limit the bits of the address which are matched. A mask is
-provided by following the address with a slash and then the mask. It may be
-provided in LLADDR format, in which case it is a bitwise mask, or as a
-number of high bits to match. If the mask is missing then a match on all
-bits is assumed.
-.TP
-.BI enc_key_id " NUMBER"
-.TQ
-.BI enc_dst_ip " PREFIX"
-.TQ
-.BI enc_src_ip " PREFIX"
-.TQ
-.BI enc_dst_port " NUMBER"
-.TQ
-.BI enc_tos " NUMBER"
-.TQ
-.BI enc_ttl " NUMBER"
-.TQ
-.BR
-.TP
-.BI ct_state " CT_STATE"
-.TQ
-.BI ct_zone " CT_MASKED_ZONE"
-.TQ
-.BI ct_mark " CT_MASKED_MARK"
-.TQ
-.BI ct_label " CT_MASKED_LABEL"
-Matches on connection tracking info
-.RS
-.TP
-.I CT_STATE
-Match the connection state, and can ne combination of [{+|-}flag] flags, where flag can be one of
-.RS
-.TP
-trk - Tracked connection.
-.TP
-new - New connection.
-.TP
-est - Established connection.
-.TP
-Example: +trk+est
-.RE
-.TP
-.I CT_MASKED_ZONE
-Match the connection zone, and can be masked.
-.TP
-.I CT_MASKED_MARK
-32bit match on the connection mark, and can be masked.
-.TP
-.I CT_MASKED_LABEL
-128bit match on the connection label, and can be masked.
-.RE
-.TP
-.BI geneve_opts " OPTIONS"
-Match on IP tunnel metadata. Key id
-.I NUMBER
-is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel).
-.I PREFIX
-must be a valid IPv4 or IPv6 address optionally followed by a slash and the
-prefix length. If the prefix is missing, \fBtc\fR assumes a full-length
-host match.  Dst port
-.I NUMBER
-is a 16 bit UDP dst port. Tos
-.I NUMBER
-is an 8 bit tos (dscp+ecn) value, ttl
-.I NUMBER
-is an 8 bit time-to-live value. geneve_opts
-.I OPTIONS
-must be a valid list of comma-separated geneve options where each option
-consists of a key optionally followed by a slash and corresponding mask. If
-the masks is missing, \fBtc\fR assumes a full-length match. The options can
-be described in the form CLASS:TYPE:DATA/CLASS_MASK:TYPE_MASK:DATA_MASK,
-where CLASS is represented as a 16bit hexadecimal value, TYPE as an 8bit
-hexadecimal value and DATA as a variable length hexadecimal value.
-.TP
-.BI ip_flags " IP_FLAGS"
-.I IP_FLAGS
-may be either
-.BR frag ", " nofrag ", " firstfrag " or " nofirstfrag
-where frag and nofrag could be used to match on fragmented packets or not,
-respectively. firstfrag and nofirstfrag can be used to further distinguish
-fragmented packet. firstfrag can be used to indicate the first fragmented
-packet. nofirstfrag can be used to indicates subsequent fragmented packets
-or non-fragmented packets.
+.BI src_port " NUMBER"
+Match on layer 4 protocol source or destination port number. Only available for
+.BR ip_proto " values " udp " and " tcp ,
+which has to be specified in beforehand.
 .SH NOTES
 As stated above where applicable, matches of a certain layer implicitly depend
-on the matches of the next lower layer. Precisely, layer one and two matches
-(\fBindev\fR,  \fBdst_mac\fR and \fBsrc_mac\fR)
-have no dependency,
-MPLS and layer three matches
-(\fBmpls_label\fR, \fBmpls_tc\fR, \fBmpls_bos\fR, \fBmpls_ttl\fR,
-\fBip_proto\fR, \fBdst_ip\fR, \fBsrc_ip\fR, \fBarp_tip\fR, \fBarp_sip\fR,
-\fBarp_op\fR, \fBarp_tha\fR, \fBarp_sha\fR and \fBip_flags\fR)
-depend on the
-.B protocol
-option of tc filter, layer four port matches
-(\fBdst_port\fR and \fBsrc_port\fR)
+on the matches of the next lower layer. Precisely, layer one and two matches (
+.BR indev , dst_mac , src_mac " and " eth_type )
+have no dependency, layer three matches (
+.BR ip_proto , dst_ip " and " src_ip )
+require
+.B eth_type
+being set to either
+.BR ipv4 " or " ipv6 ,
+and finally layer four matches (
+.BR dst_port " and " src_port )
 depend on
 .B ip_proto
-being set to
-.BR tcp ", " udp " or " sctp,
-and finally ICMP matches (\fBcode\fR and \fBtype\fR) depend on
-.B ip_proto
-being set to
-.BR icmp " or " icmpv6.
+being set to either
+.BR tcp " or " udp .
 .P
 There can be only used one mask per one prio. If user needs to specify different
 mask, he has to use different prio.
diff --git a/man/man8/tc-fq.8 b/man/man8/tc-fq.8
index 1febe62..f058a05 100644
--- a/man/man8/tc-fq.8
+++ b/man/man8/tc-fq.8
@@ -15,28 +15,23 @@
 .B maxrate
 RATE ] [
 .B buckets
-NUMBER ] [
-.B orphan_mask
-NUMBER ] [
+NUMBER ]  [
 .B pacing
 |
 .B nopacing
-] [
-.B ce_threshold
-TIME ]
+]
 
 .SH DESCRIPTION
 FQ (Fair Queue) is a classless packet scheduler meant to be mostly
 used for locally generated traffic.  It is designed to achieve per flow pacing.
 FQ does flow separation, and is able to respect pacing requirements set by TCP stack.
 All packets belonging to a socket are considered as a 'flow'.
-For non local packets (router workload), packet hash is used as fallback.
+For non local packets (router workload), packet rxhash is used as fallback.
 
 An application can specify a maximum pacing rate using the
 .B SO_MAX_PACING_RATE
 setsockopt call.  This packet scheduler adds delay between packets to
-respect rate limitation set on each socket. Note that after linux-4.20, linux adopted EDT (Earliest Departure Time)
-and TCP directly sets the appropriate Departure Time for each skb.
+respect rate limitation set by TCP stack.
 
 Dequeueing happens in a round-robin fashion.
 A special FIFO queue is reserved for high priority packets (
@@ -77,28 +72,18 @@
 The size of the hash table used for flow lookups. Each bucket is assigned a
 red-black tree for efficient collision sorting.
 Default: 1024.
-.SS orphan_mask
-For packets not owned by a socket, fq is able to mask a part of skb->hash
-and reduce number of buckets associated with the traffic. This is a DDOS
-prevention mechanism, and the default is 1023 (meaning no more than 1024 flows
-are allocated for these packets)
 .SS [no]pacing
 Enable or disable flow pacing. Default is enabled.
-.SS ce_threshold
-sets a threshold above which all packets are marked with ECN Congestion
-Experienced. This is useful for DCTCP-style congestion control algorithms that
-require marking at very shallow queueing thresholds.
-
 .SH EXAMPLES
-#tc qdisc add dev eth0 root est 1sec 4sec fq ce_threshold 4ms
+#tc qdisc add dev eth0 root fq
 .br
-#tc -s -d qdisc sh dev eth0
+#tc -s -d qdisc
 .br
-qdisc fq 800e: root refcnt 9 limit 10000p flow_limit 1000p buckets 1024 orphan_mask 1023 quantum 3028 initial_quantum 15140 low_rate_threshold 550Kbit refill_delay 40.0ms ce_threshold 4.0ms
- Sent 533368436185 bytes 352296695 pkt (dropped 0, overlimits 0 requeues 1339864)
- rate 39220Mbit 3238202pps backlog 12417828b 358p requeues 1339864
-  1052 flows (852 inactive, 0 throttled)
-  112 gc, 0 highprio, 212 throttled, 21501 ns latency, 470241 ce_mark
+qdisc fq 8003: dev eth0 root refcnt 2 limit 10000p flow_limit 100p buckets 1024 quantum 3028 initial_quantum 15140
+ Sent 503727981 bytes 1146972 pkt (dropped 0, overlimits 0 requeues 54452)
+ backlog 0b 0p requeues 54452
+  1289 flows (1289 inactive, 0 throttled)
+  0 gc, 31 highprio, 27411 throttled
 .br
 .SH SEE ALSO
 .BR tc (8),
diff --git a/man/man8/tc-fq_codel.8 b/man/man8/tc-fq_codel.8
index 7ee6c26..a80389a 100644
--- a/man/man8/tc-fq_codel.8
+++ b/man/man8/tc-fq_codel.8
@@ -17,11 +17,7 @@
 .B ecn
 |
 .B noecn
-] [
-.B ce_threshold
-TIME ] [
-.B memory_limit
-BYTES ]
+]
 
 .SH DESCRIPTION
 FQ_Codel (Fair Queuing Controlled Delay) is queuing discipline that combines Fair
@@ -39,13 +35,6 @@
 When this limit is reached, incoming packets are dropped. Default is 10240
 packets.
 
-.SS memory_limit
-sets a limit on the total number of bytes that can be queued in this FQ-CoDel
-instance. The lower of the packet limit of the
-.B limit
-parameter and the memory limit will be enforced. Default is 32 MB.
-
-
 .SS flows
 is the number of flows into which the incoming packets are classified. Due to
 the stochastic nature of hashing, multiple flows may end up being hashed into
@@ -84,11 +73,6 @@
 .B codel, ecn
 is turned on by default.
 
-.SS ce_threshold
-sets a threshold above which all packets are marked with ECN Congestion
-Experienced. This is useful for DCTCP-style congestion control algorithms that
-require marking at very shallow queueing thresholds.
-
 .SH EXAMPLES
 #tc qdisc add   dev eth0 root fq_codel
 .br
diff --git a/man/man8/tc-hfsc.8 b/man/man8/tc-hfsc.8
index fd0df8f..5444118 100644
--- a/man/man8/tc-hfsc.8
+++ b/man/man8/tc-hfsc.8
@@ -54,8 +54,8 @@
 .
 \fBtc\fR(8), \fBtc\-hfsc\fR(7), \fBtc\-stab\fR(8)
 
-Please direct bugreports and patches to: <netdev@vger.kernel.org>
+Please direct bugreports and patches to: <net...@vger.kernel.org>
 .
 .SH "AUTHOR"
 .
-Manpage created by Michal Soltys (soltys@ziu.info)
+Manpage created by Michal Soltys (sol...@ziu.info)
diff --git a/man/man8/tc-ife.8 b/man/man8/tc-ife.8
deleted file mode 100644
index fd2df6c..0000000
--- a/man/man8/tc-ife.8
+++ /dev/null
@@ -1,143 +0,0 @@
-.TH "IFE action in tc" 8 "22 Apr 2016" "iproute2" "Linux"
-
-.SH NAME
-IFE - encapsulate/decapsulate metadata
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " " action ife"
-.IR DIRECTION " [ " ACTION " ] "
-.RB "[ " dst
-.IR DMAC " ] "
-.RB "[ " src
-.IR SMAC " ] "
-.RB "[ " type
-.IR TYPE " ] "
-.RI "[ "
-.IR CONTROL " ] "
-.RB "[ " index
-.IR INDEX " ] "
-
-.ti -8
-.IR DIRECTION " := { "
-.BR decode " | " encode " }"
-
-.ti -8
-.IR ACTION " := { "
-.BI allow " ATTR"
-.RB "| " use
-.IR "ATTR value" " }"
-
-.ti -8
-.IR ATTR " := { "
-.BR mark " | " prio " | " tcindex " }"
-
-.ti -8
-.IR CONTROL " := { "
-.BR reclassify " | " use " | " pipe " | " drop " | " continue " | " ok " | " goto " " chain " " CHAIN_INDEX " }"
-.SH DESCRIPTION
-The
-.B ife
-action allows for a sending side to encapsulate arbitrary metadata, which is
-then decapsulated by the receiving end. The sender runs in encoding mode and
-the receiver in decode mode. Both sender and receiver must specify the same
-ethertype. In the future, a registered ethertype may be available as a default.
-.SH OPTIONS
-.TP
-.B decode
-For the receiving side; decode the metadata if the packet matches.
-.TP
-.B encode
-For the sending side. Encode the specified metadata if the packet matches.
-.TP
-.B allow
-Encode direction only. Allows encoding specified metadata.
-.TP
-.B use
-Encode direction only. Enforce static encoding of specified metadata.
-.TP
-.BR mark " [ "
-.IR u32_value " ]"
-The value to set for the skb mark. The u32 value is required only when
-.BR use " is specified. If
-.BR mark " value is zero, it will not be encoded, instead
-"overlimits" statistics increment and
-.BR CONTROL " action is taken.
-.TP
-.BR prio " [ "
-.IR u32_value " ]"
-The value to set for priority in the skb structure. The u32 value is required
-only when
-.BR use " is specified."
-.TP
-.BR tcindex " ["
-.IR u16_value " ]"
-Value to set for the traffic control index in the skb structure. The u16 value
-is required only when
-.BR use " is specified."
-.TP
-.BI dmac " DMAC"
-.TQ
-.BI smac " SMAC"
-Optional six byte destination or source MAC address to encode.
-.TP
-.BI type " TYPE"
-Optional 16-bit ethertype to encode. If not specified value of 0xED3E will be used.
-.TP
-.BI CONTROL
-Action to take following an encode/decode.
-.TP
-.BI index " INDEX"
-Assign a unique ID to this action instead of letting the kernel choose one
-automatically.
-.I INDEX
-is a 32bit unsigned integer greater than zero.
-.SH EXAMPLES
-
-On the receiving side, match packets with ethertype 0xdead and restart
-classification so that it will match ICMP on the next rule, at prio 3:
-.RS
-.EX
-# tc qdisc add dev eth0 handle ffff: ingress
-# tc filter add dev eth0 parent ffff: prio 2 protocol 0xdead \\
-	u32 match u32 0 0 flowid 1:1 \\
-	action ife decode reclassify
-# tc filter add dev eth0 parent ffff: prio 3 protocol ip \\
-	u32 match ip protocol 0xff flowid 1:1 \\
-	action continue
-.EE
-.RE
-
-Match with skb mark of 17:
-
-.RS
-.EX
-# tc filter add dev eth0 parent ffff: prio 4 protocol ip \\
-	handle 0x11 fw flowid 1:1 \\
-	action ok
-.EE
-.RE
-
-Configure the sending side to encode for the filters above. Use a destination
-IP address of 192.168.122.237/24, then tag with skb mark of decimal 17. Encode
-the packaet with ethertype 0xdead, add skb->mark to whitelist of metadatum to
-send, and rewrite the destination MAC address to 02:15:15:15:15:15.
-
-.RS
-.EX
-# tc qdisc add dev eth0 root handle 1: prio
-# tc filter add dev eth0 parent 1: protocol ip prio 10 u32 \\
-	match ip dst 192.168.122.237/24 \\
-	match ip protocol 1 0xff \\
-	flowid 1:2 \\
-	action skbedit mark 17 \\
-	action ife encode \\
-	type 0xDEAD \\
-	allow mark \\
-	dst 02:15:15:15:15:15
-.EE
-.RE
-
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-u32 (8)
diff --git a/man/man8/tc-matchall.8 b/man/man8/tc-matchall.8
deleted file mode 100644
index e3cddb1..0000000
--- a/man/man8/tc-matchall.8
+++ /dev/null
@@ -1,87 +0,0 @@
-.TH "Match-all classifier in tc" 8 "21 Oct 2015" "iproute2" "Linux"
-
-.SH NAME
-matchall \- traffic control filter that matches every packet
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " " filter " ... " matchall " [ "
-.BR skip_sw " | " skip_hw
-.RI " ] [ "
-.B action
-.IR ACTION_SPEC " ] [ "
-.B classid
-.IR CLASSID " ]"
-.SH DESCRIPTION
-The
-.B matchall
-filter allows to classify every packet that flows on the port and run a
-action on it.
-.SH OPTIONS
-.TP
-.BI action " ACTION_SPEC"
-Apply an action from the generic actions framework on matching packets.
-.TP
-.BI classid " CLASSID"
-Push matching packets into the class identified by
-.IR CLASSID .
-.TP
-.BI skip_sw
-Do not process filter by software. If hardware has no offload support for this
-filter, or TC offload is not enabled for the interface, operation will fail.
-.TP
-.BI skip_hw
-Do not process filter by hardware.
-.SH EXAMPLES
-To create ingress mirroring from port eth1 to port eth2:
-.RS
-.EX
-
-tc qdisc  add dev eth1 handle ffff: ingress
-tc filter add dev eth1 parent ffff:           \\
-        matchall skip_sw                      \\
-        action mirred egress mirror           \\
-        dev eth2
-.EE
-.RE
-
-The first command creats an ingress qdisc with handle
-.BR ffff:
-on device
-.BR eth1
-where the second command attaches a matchall filters on it that mirrors the
-packets to device eth2.
-
-To create egress mirroring from port eth1 to port eth2:
-.RS
-.EX
-
-tc qdisc add dev eth1 handle 1: root prio
-tc filter add dev eth1 parent 1:               \\
-        matchall skip_sw                       \\
-        action mirred egress mirror            \\
-        dev eth2
-.EE
-.RE
-
-The first command creats an egress qdisc with handle
-.BR 1:
-that replaces the root qdisc on device
-.BR eth1
-where the second command attaches a matchall filters on it that mirrors the
-packets to device eth2.
-
-To sample one of every 100 packets flowing into interface eth0 to psample group
-12:
-.RS
-.EX
-
-tc qdisc add dev eth0 handle ffff: ingress
-tc filter add dev eth0 parent ffff: matchall \\
-     action sample rate 100 group 12
-.EE
-.RE
-
-.EE
-.SH SEE ALSO
-.BR tc (8),
diff --git a/man/man8/tc-mirred.8 b/man/man8/tc-mirred.8
deleted file mode 100644
index 38833b4..0000000
--- a/man/man8/tc-mirred.8
+++ /dev/null
@@ -1,99 +0,0 @@
-.TH "Mirror/redirect action in tc" 8 "11 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-mirred - mirror/redirect action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action mirred"
-.I DIRECTION ACTION
-.RB "[ " index
-.IR INDEX " ] "
-.BI dev " DEVICENAME"
-
-.ti -8
-.IR DIRECTION " := { "
-.BR ingress " | " egress " }"
-
-.ti -8
-.IR ACTION " := { "
-.BR mirror " | " redirect " }"
-.SH DESCRIPTION
-The
-.B mirred
-action allows packet mirroring (copying) or redirecting (stealing) the packet it
-receives. Mirroring is what is sometimes referred to as Switch Port Analyzer
-(SPAN) and is commonly used to analyze and/or debug flows.
-.SH OPTIONS
-.TP
-.B ingress
-.TQ
-.B egress
-Specify the direction in which the packet shall appear on the destination
-interface.
-.TP
-.B mirror
-.TQ
-.B redirect
-Define whether the packet should be copied
-.RB ( mirror )
-or moved
-.RB ( redirect )
-to the destination interface.
-.TP
-.BI index " INDEX"
-Assign a unique ID to this action instead of letting the kernel choose one
-automatically.
-.I INDEX
-is a 32bit unsigned integer greater than zero.
-.TP
-.BI dev " DEVICENAME"
-Specify the network interface to redirect or mirror to.
-.SH EXAMPLES
-Limit ingress bandwidth on eth0 to 1mbit/s, redirect exceeding traffic to lo for
-debugging purposes:
-
-.RS
-.EX
-# tc qdisc add dev eth0 handle ffff: ingress
-# tc filter add dev eth0 parent ffff: u32 \\
-	match u32 0 0 \\
-	action police rate 1mbit burst 100k conform-exceed pipe \\
-	action mirred egress redirect dev lo
-.EE
-.RE
-
-Mirror all incoming ICMP packets on eth0 to a dummy interface for examination
-with e.g. tcpdump:
-
-.RS
-.EX
-# ip link add dummy0 type dummy
-# ip link set dummy0 up
-# tc qdisc add dev eth0 handle ffff: ingress
-# tc filter add dev eth0 parent ffff: protocol ip \\
-	u32 match ip protocol 1 0xff \\
-	action mirred egress mirror dev dummy0
-.EE
-.RE
-
-Using an
-.B ifb
-interface, it is possible to send ingress traffic through an instance of
-.BR sfq :
-
-.RS
-.EX
-# modprobe ifb
-# ip link set ifb0 up
-# tc qdisc add dev ifb0 root sfq
-# tc qdisc add dev eth0 handle ffff: ingress
-# tc filter add dev eth0 parent ffff: u32 \\
-	match u32 0 0 \\
-	action mirred egress redirect dev ifb0
-.EE
-.RE
-
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-u32 (8)
diff --git a/man/man8/tc-mpls.8 b/man/man8/tc-mpls.8
deleted file mode 100644
index 84ef2ef..0000000
--- a/man/man8/tc-mpls.8
+++ /dev/null
@@ -1,156 +0,0 @@
-.TH "MPLS manipulation action in tc" 8 "22 May 2019" "iproute2" "Linux"
-
-.SH NAME
-mpls - mpls manipulation module
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action mpls" " { "
-.IR POP " | " PUSH " | " MODIFY " | "
-.BR dec_ttl " } [ "
-.IR CONTROL " ]"
-
-.ti -8
-.IR POP " := "
-.BR pop " " protocol
-.IR MPLS_PROTO
-
-.ti -8
-.IR PUSH " := "
-.BR push " [ " protocol
-.IR MPLS_PROTO " ]"
-.RB " [ " tc
-.IR MPLS_TC " ] "
-.RB " [ " ttl
-.IR MPLS_TTL " ] "
-.RB " [ " bos
-.IR MPLS_BOS " ] "
-.BI label " MPLS_LABEL"
-
-.ti -8
-.IR MODIFY " := "
-.BR modify " [ " label
-.IR MPLS_LABEL " ]"
-.RB " [ " tc
-.IR MPLS_TC " ] "
-.RB " [ " ttl
-.IR MPLS_TTL " ] "
-
-.ti -8
-.IR CONTROL " := { "
-.BR reclassify " | " pipe " | " drop " | " continue " | " pass " | " goto " " chain " " CHAIN_INDEX " }"
-.SH DESCRIPTION
-The
-.B mpls
-action performs mpls encapsulation or decapsulation on a packet, reflected by the
-operation modes
-.IR POP ", " PUSH ", " MODIFY " and " DEC_TTL .
-The
-.I POP
-mode requires the ethertype of the header that follows the MPLS header (e.g.
-IPv4 or another MPLS). It will remove the outer MPLS header and replace the
-ethertype in the MAC header with that passed. The
-.IR PUSH " and " MODIFY
-modes update the current MPLS header information or add a new header.
-.IR PUSH
-requires at least an
-.IR MPLS_LABEL ". "
-.I DEC_TTL
-requires no arguments and simply subtracts 1 from the MPLS header TTL field.
-
-.SH OPTIONS
-.TP
-.B pop
-Decapsulation mode. Requires the protocol of the next header.
-.TP
-.B push
-Encapsulation mode. Requires at least the
-.B label
-option.
-.TP
-.B modify
-Replace mode. Existing MPLS tag is replaced.
-.BR label ", "
-.BR tc ", "
-and
-.B ttl
-are all optional.
-.TP
-.B dec_ttl
-Decrement the TTL field on the outer most MPLS header.
-.TP
-.BI label " MPLS_LABEL"
-Specify the MPLS LABEL for the outer MPLS header.
-.I MPLS_LABEL
-is an unsigned 20bit integer, the format is detected automatically (e.g. prefix
-with
-.RB ' 0x '
-for hexadecimal interpretation, etc.).
-.TP
-.BI protocol " MPLS_PROTO"
-Choose the protocol to use. For push actions this must be
-.BR mpls_uc " or " mpls_mc " (" mpls_uc
-is the default). For pop actions it should be the protocol of the next header.
-This option cannot be used with modify.
-.TP
-.BI tc " MPLS_TC"
-Choose the TC value for the outer MPLS header. Decimal number in range of 0-7.
-Defaults to 0.
-.TP
-.BI ttl " MPLS_TTL"
-Choose the TTL value for the outer MPLS header. Number in range of 0-255. A
-non-zero default value will be selected if this is not explicitly set.
-.TP
-.BI bos " MPLS_BOS"
-Manually configure the bottom of stack bit for an MPLS header push. The default
-is for TC to automatically set (or unset) the bit based on the next header of
-the packet.
-.TP
-.I CONTROL
-How to continue after executing this action.
-.RS
-.TP
-.B reclassify
-Restarts classification by jumping back to the first filter attached to this
-action's parent.
-.TP
-.B pipe
-Continue with the next action, this is the default.
-.TP
-.B drop
-Packet will be dropped without running further actions.
-.TP
-.B continue
-Continue classification with next filter in line.
-.TP
-.B pass
-Return to calling qdisc for packet processing. This ends the classification
-process.
-.RE
-.SH EXAMPLES
-The following example encapsulates incoming IP packets on eth0 into MPLS with
-a label 123 and sends them out eth1:
-
-.RS
-.EX
-#tc qdisc add dev eth0 handle ffff: ingress
-#tc filter add dev eth0 protocol ip parent ffff: flower \\
-	action mpls push protocol mpls_uc label 123  \\
-	action mirred egress redirect dev eth1
-.EE
-.RE
-
-In this example, incoming MPLS unicast packets on eth0 are decapsulated and to
-ip packets and output to eth1:
-
-.RS
-.EX
-#tc qdisc add dev eth0 handle ffff: ingress
-#tc filter add dev eth0 protocol mpls_uc parent ffff: flower \\
-	action mpls pop protocol ipv4  \\
-	action mirred egress redirect dev eth0
-.EE
-.RE
-
-.SH SEE ALSO
-.BR tc (8)
diff --git a/man/man8/tc-mqprio.8 b/man/man8/tc-mqprio.8
index 4b9e942..0e1d305 100644
--- a/man/man8/tc-mqprio.8
+++ b/man/man8/tc-mqprio.8
@@ -8,7 +8,7 @@
 classid
 .B | root) [ handle
 major:
-.B ] mqprio [ num_tc
+.B ] mqprio [ numtc
 tcs
 .B ] [ map
 P0 P1 P2...
@@ -16,17 +16,7 @@
 count1@offset1 count2@offset2 ...
 .B ] [ hw
 1|0
-.B ] [ mode
-dcb|channel]
-.B ] [ shaper
-dcb|
-.B [ bw_rlimit
-.B min_rate
-min_rate1 min_rate2 ...
-.B max_rate
-max_rate1 max_rate2 ...
-.B ]]
-
+.B ]
 
 .SH DESCRIPTION
 The MQPRIO qdisc is a simple queuing discipline that allows mapping
@@ -46,16 +36,14 @@
 By default these parameters are configured by the hardware
 driver to match the hardware QOS structures.
 
-.B Channel
-mode supports full offload of the mqprio options, the traffic classes, the queue
-configurations and QOS attributes to the hardware. Enabled hardware can provide
-hardware QOS with the ability to steer traffic flows to designated traffic
-classes provided by this qdisc. Hardware based QOS is configured using the
-.B shaper
-parameter.
-.B bw_rlimit
-with minimum and maximum bandwidth rates can be used for setting
-transmission rates on each traffic class. Also further qdiscs may be added
+Enabled hardware can provide hardware QOS with the ability to steer
+traffic flows to designated traffic classes provided by this qdisc.
+Configuring the hardware based QOS mechanism is outside the scope of
+this qdisc. Tools such as
+.B lldpad
+and
+.B ethtool
+exist to provide this functionality. Also further qdiscs may be added
 to the classes of MQPRIO to create more complex configurations.
 
 .SH ALGORITHM
@@ -116,35 +104,9 @@
 hw
 Set to
 .B 1
-to support hardware offload. Set to
+to use hardware QOS defaults. Set to
 .B 0
-to configure user specified values in software only.
-
-.TP
-mode
-Set to
-.B channel
-for full use of the mqprio options. Use
-.B dcb
-to offload only TC values and use hardware QOS defaults. Supported with 'hw'
-set to 1 only.
-
-.TP
-shaper
-Use
-.B bw_rlimit
-to set bandwidth rate limits for a traffic class. Use
-.B dcb
-for hardware QOS defaults. Supported with 'hw' set to 1 only.
-
-.TP
-min_rate
-Minimum value of bandwidth rate limit for a traffic class.
-
-.TP
-max_rate
-Maximum value of bandwidth rate limit for a traffic class.
-
+to override hardware defaults with user specified values.
 
 .SH AUTHORS
 John Fastabend, <john.r.fastabend@intel.com>
diff --git a/man/man8/tc-nat.8 b/man/man8/tc-nat.8
deleted file mode 100644
index fdcc052..0000000
--- a/man/man8/tc-nat.8
+++ /dev/null
@@ -1,78 +0,0 @@
-.TH "NAT action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-nat - stateless native address translation action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action nat"
-.I DIRECTION OLD NEW
-
-.ti -8
-.IR DIRECTION " := { "
-.BR ingress " | " egress " }"
-
-.ti -8
-.IR OLD " := " IPV4_ADDR_SPEC
-
-.ti -8
-.IR NEW " := " IPV4_ADDR_SPEC
-
-.ti -8
-.IR IPV4_ADDR_SPEC " := { "
-.BR default " | " any " | " all " | "
-\fIin_addr\fR[\fB/\fR{\fIprefix\fR|\fInetmask\fR}]
-.SH DESCRIPTION
-The
-.B nat
-action allows to perform NAT without the overhead of conntrack, which is
-desirable if the number of flows or addresses to perform NAT on is large. This
-action is best used in combination with the
-.B u32
-filter to allow for efficient lookups of a large number of stateless NAT rules
-in constant time.
-.SH OPTIONS
-.TP
-.B ingress
-Translate destination addresses, i.e. perform DNAT.
-.TP
-.B egress
-Translate source addresses, i.e. perform SNAT.
-.TP
-.I OLD
-Specifies addresses which should be translated.
-.TP
-.I NEW
-Specifies addresses which
-.I OLD
-should be translated into.
-.SH NOTES
-The accepted address format in
-.IR OLD " and " NEW
-is quite flexible. It may either consist of one of the keywords
-.BR default ", " any " or " all ,
-representing the all-zero IP address or a combination of IP address and netmask
-or prefix length separated by a slash
-.RB ( / )
-sign. In any case, the mask (or prefix length) value of
-.I OLD
-is used for
-.I NEW
-as well so that a one-to-one mapping of addresses is assured.
-
-Address translation is done using a combination of binary operations. First, the
-original (source or destination) address is matched against the value of
-.IR OLD .
-If the original address fits, the new address is created by taking the leading
-bits from
-.I NEW
-(defined by the netmask of
-.IR OLD )
-and taking the remaining bits from the original address.
-
-There is rudimental support for upper layer protocols, namely TCP, UDP and ICMP.
-While for the first two only checksum recalculation is performed, the action
-also takes care of embedded IP headers in ICMP packets by translating the
-respective address therein, too.
-.SH SEE ALSO
-.BR tc (8)
diff --git a/man/man8/tc-netem.8 b/man/man8/tc-netem.8
index 5a08a40..b31384f 100644
--- a/man/man8/tc-netem.8
+++ b/man/man8/tc-netem.8
@@ -8,8 +8,7 @@
 .I OPTIONS
 
 .IR OPTIONS " := [ " LIMIT " ] [ " DELAY " ] [ " LOSS \
-" ] [ " CORRUPT " ] [ " DUPLICATION " ] [ " REORDERING " ] [ " RATE \
-" ] [ " SLOT " ]"
+" ] [ " CORRUPT " ] [ " DUPLICATION " ] [ " REORDERING " ][ " RATE " ]"
 
 .IR LIMIT " := "
 .B limit
@@ -52,18 +51,6 @@
 .B rate
 .IR RATE " [ " PACKETOVERHEAD " [ " CELLSIZE " [ " CELLOVERHEAD " ]]]]"
 
-.IR SLOT " := "
-.BR slot " { "
-.IR MIN_DELAY " [ " MAX_DELAY " ] |"
-.br
-.RB "               " distribution " { "uniform " | " normal " | " pareto " | " paretonormal " | "
-.IR FILE " } " DELAY " " JITTER " } "
-.br
-.RB "             [ " packets
-.IR PACKETS " ] [ "
-.BR bytes
-.IR BYTES " ]"
-
 
 .SH DESCRIPTION
 NetEm is an enhancement of the Linux traffic control facilities
@@ -78,7 +65,7 @@
 
 .SS limit packets
 
-maximum number of packets the qdisc may hold queued at a time.
+limits the effect of selected options to the indicated number of next packets.
 
 .SS delay
 adds the chosen delay to the packets outgoing to chosen network interface. The
@@ -175,31 +162,6 @@
 an artificial packet compression (bursts). Another influence factor are network
 adapter buffers which can also add artificial delay.
 
-.SS slot
-defer delivering accumulated packets to within a slot. Each available slot can be
-configured with a minimum delay to acquire, and an optional maximum delay.
-Alternatively it can be configured with the distribution similar to
-.BR distribution
-for
-.BR delay
-option. Slot delays can be specified in nanoseconds, microseconds, milliseconds or seconds
-(e.g. 800us). Values for the optional parameters
-.I BYTES
-will limit the number of bytes delivered per slot, and/or
-.I PACKETS
-will limit the number of packets delivered per slot.
-
-These slot options can provide a crude approximation of bursty MACs such as
-DOCSIS, WiFi, and LTE.
-
-Note that slotting is limited by several factors: the kernel clock granularity,
-as with a rate, and attempts to deliver many packets within a slot will be
-smeared by the timer resolution, and by the underlying native bandwidth also.
-
-It is possible to combine slotting with a rate, in which case complex behaviors
-where either the rate, or the slot limits on bytes or packets per slot, govern
-the actual delivered rate.
-
 .SH LIMITATIONS
 The main known limitation of Netem are related to timer granularity, since
 Linux is not a real-time operating system.
@@ -219,7 +181,7 @@
 (http://devresources.linux-foundation.org/shemminger/netem/LCA2005_paper.pdf)
 
 .IP " 2. " 4
-Netem page from Linux foundation, (https://wiki.linuxfoundation.org/networking/netem)
+Netem page from Linux foundation, (http://www.linuxfoundation.org/en/Net:Netem)
 
 .IP " 3. " 4
 Salsano S., Ludovici F., Ordine A., "Definition of a general and intuitive loss
diff --git a/man/man8/tc-pedit.8 b/man/man8/tc-pedit.8
deleted file mode 100644
index bbd725c..0000000
--- a/man/man8/tc-pedit.8
+++ /dev/null
@@ -1,373 +0,0 @@
-.TH "Generic packet editor action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-pedit - generic packet editor action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action pedit [ex] munge " {
-.IR RAW_OP " | " LAYERED_OP " | " EXTENDED_LAYERED_OP " } [ " CONTROL " ]"
-
-.ti -8
-.IR RAW_OP " := "
-.BI offset " OFFSET"
-.RB "{ " u8 " | " u16 " | " u32 " } ["
-.IR AT_SPEC " ] " CMD_SPEC
-
-.ti -8
-.IR AT_SPEC " := "
-.BI at " AT " offmask " MASK " shift " SHIFT"
-
-.ti -8
-.IR LAYERED_OP " := { "
-.BI ip " IPHDR_FIELD"
-|
-.BI ip " BEYOND_IPHDR_FIELD"
-.RI } " CMD_SPEC"
-
-.ti -8
-.IR EXTENDED_LAYERED_OP " := { "
-.BI eth " ETHHDR_FIELD"
-|
-.BI ip " IPHDR_FIELD"
-|
-.BI ip " EX_IPHDR_FIELD"
-|
-.BI ip6 " IP6HDR_FIELD"
-|
-.BI tcp " TCPHDR_FIELD"
-|
-.BI udp " UDPHDR_FIELD"
-.RI } " CMD_SPEC"
-
-.ti -8
-.IR ETHHDR_FIELD " := { "
-.BR src " | " dst " | " type " }"
-
-.ti -8
-.IR IPHDR_FIELD " := { "
-.BR src " | " dst " | " tos " | " dsfield " | " ihl " | " protocol " |"
-.BR precedence " | " nofrag " | " firstfrag " | " ce " | " df " }"
-
-.ti -8
-.IR BEYOND_IPHDR_FIELD " := { "
-.BR dport " | " sport " | " icmp_type " | " icmp_code " }"
-
-.ti -8
-.IR EX_IPHDR_FIELD " := { "
-.BR ttl " }"
-
-
-.ti -8
-.IR IP6HDR_FIELD " := { "
-.BR src " | " dst " | " flow_lbl " | " payload_len " | " nexthdr " |"
-.BR hoplimit " }"
-
-.ti -8
-.IR TCPHDR_FIELD " := { "
-.BR sport " | " dport " | " flags " }"
-
-.ti -8
-.IR UDPHDR_FIELD " := { "
-.BR sport " | " dport " }"
-
-.ti -8
-.IR CMD_SPEC " := {"
-.BR clear " | " invert " | " set
-.IR VAL " | "
-.BR add
-.IR VAL " | "
-.BR preserve " } [ " retain
-.IR RVAL " ]"
-
-.ti -8
-.IR CONTROL " := {"
-.BR reclassify " | " pipe " | " drop " | " shot " | " continue " | " pass " | " goto " " chain " " CHAIN_INDEX " }"
-.SH DESCRIPTION
-The
-.B pedit
-action can be used to change arbitrary packet data. The location of data to
-change can either be specified by giving an offset and size as in
-.IR RAW_OP ,
-or for header values by naming the header and field to edit the size is then
-chosen automatically based on the header field size. Currently this is supported
-only for IPv4 headers.
-.SH OPTIONS
-.TP
-.B ex
-Use extended pedit.
-.I EXTENDED_LAYERED_OP
-and the add
-.I CMD_SPEC
-are allowed only in this mode.
-.TP
-.BI offset " OFFSET " "\fR{ \fBu32 \fR| \fBu16 \fR| \fBu8 \fR}"
-Specify the offset at which to change data.
-.I OFFSET
-is a signed integer, it's base is automatically chosen (e.g. hex if prefixed by
-.B 0x
-or octal if prefixed by
-.BR 0 ).
-The second argument specifies the length of data to change, that is four bytes
-.RB ( u32 ),
-two bytes
-.RB ( u16 )
-or a single byte
-.RB ( u8 ).
-.TP
-.BI at " AT " offmask " MASK " shift " SHIFT"
-This is an optional part of
-.IR RAW_OP
-which allows to have a variable
-.I OFFSET
-depending on packet data at offset
-.IR AT ,
-which is binary ANDed with
-.I MASK
-and right-shifted by
-.I SHIFT
-before adding it to
-.IR OFFSET .
-.TP
-.BI eth " ETHHDR_FIELD"
-Change an ETH header field. The supported keywords for
-.I ETHHDR_FIELD
-are:
-.RS
-.TP
-.B src
-.TQ
-.B dst
-Source or destination MAC address in the standard format: XX:XX:XX:XX:XX:XX
-.TP
-.B type
-Ether-type in numeric value
-.RE
-.TP
-.BI ip " IPHDR_FIELD"
-Change an IPv4 header field. The supported keywords for
-.I IPHDR_FIELD
-are:
-.RS
-.TP
-.B src
-.TQ
-.B dst
-Source or destination IP address, a four-byte value.
-.TP
-.B tos
-.TQ
-.B dsfield
-.TQ
-.B precedence
-Type Of Service field, an eight-bit value.
-.TP
-.B ihl
-Change the IP Header Length field, a four-bit value.
-.TP
-.B protocol
-Next-layer Protocol field, an eight-bit value.
-.TP
-.B nofrag
-.TQ
-.B firstfrag
-.TQ
-.B ce
-.TQ
-.B df
-.TQ
-.B mf
-Change IP header flags. Note that the value to pass to the
-.B set
-command is not just a bit value, but the full byte including the flags field.
-Though only the relevant bits of that value are respected, the rest ignored.
-.RE
-.TP
-.BI ip " BEYOND_IPHDR_FIELD"
-Supported only for non-extended layered op. It is passed to the kernel as
-offsets relative to the beginning of the IP header and assumes the IP header is
-of minimum size (20 bytes). The supported keywords for
-.I BEYOND_IPHDR_FIELD
-are:
-.RS
-.TP
-.B dport
-.TQ
-.B sport
-Destination or source port numbers, a 16-bit value. Indeed, IPv4 headers don't
-contain this information. Instead, this will set an offset which suits at least
-TCP and UDP if the IP header is of minimum size (20 bytes). If not, this will do
-unexpected things.
-.TP
-.B icmp_type
-.TQ
-.B icmp_code
-Again, this allows to change data past the actual IP header itself. It assumes
-an ICMP header is present immediately following the (minimal sized) IP header.
-If it is not or the latter is bigger than the minimum of 20 bytes, this will do
-unexpected things. These fields are eight-bit values.
-.RE
-.TP
-.BI ip " EX_IPHDR_FIELD"
-Supported only when
-.I ex
-is used. The supported keywords for
-.I EX_IPHDR_FIELD
-are:
-.RS
-.TP
-.B ttl
-.RE
-.TP
-.BI ip6 " IP6HDR_FIELD"
-The supported keywords for
-.I IP6HDR_FIELD
-are:
-.RS
-.TP
-.B src
-.TQ
-.B dst
-.TQ
-.B flow_lbl
-.TQ
-.B payload_len
-.TQ
-.B nexthdr
-.TQ
-.B hoplimit
-.RE
-.TP
-.BI tcp " TCPHDR_FIELD"
-The supported keywords for
-.I TCPHDR_FIELD
-are:
-.RS
-.TP
-.B sport
-.TQ
-.B dport
-Source or destination TCP port number, a 16-bit value.
-.TP
-.B flags
-.RE
-.TP
-.BI udp " UDPHDR_FIELD"
-The supported keywords for
-.I UDPHDR_FIELD
-are:
-.RS
-.TP
-.B sport
-.TQ
-.B dport
-Source or destination TCP port number, a 16-bit value.
-.RE
-.TP
-.B clear
-Clear the addressed data (i.e., set it to zero).
-.TP
-.B invert
-Swap every bit in the addressed data.
-.TP
-.BI set " VAL"
-Set the addressed data to a specific value. The size of
-.I VAL
-is defined by either one of the
-.BR u32 ", " u16 " or " u8
-keywords in
-.IR RAW_OP ,
-or the size of the addressed header field in
-.IR LAYERED_OP .
-.TP
-.BI add " VAL"
-Add the addressed data by a specific value. The size of
-.I VAL
-is defined by the size of the addressed header field in
-.IR EXTENDED_LAYERED_OP .
-This operation is supported only for extended layered op.
-.TP
-.B preserve
-Keep the addressed data as is.
-.TP
-.BI retain " RVAL"
-This optional extra part of
-.I CMD_SPEC
-allows to exclude bits from being changed. Supported only for 32 bits fields
-or smaller.
-.TP
-.I CONTROL
-The following keywords allow to control how the tree of qdisc, classes,
-filters and actions is further traversed after this action.
-.RS
-.TP
-.B reclassify
-Restart with the first filter in the current list.
-.TP
-.B pipe
-Continue with the next action attached to the same filter.
-.TP
-.B drop
-.TQ
-.B shot
-Drop the packet.
-.TP
-.B continue
-Continue classification with the next filter in line.
-.TP
-.B pass
-Finish classification process and return to calling qdisc for further packet
-processing. This is the default.
-.RE
-.SH EXAMPLES
-Being able to edit packet data, one could do all kinds of things, such as e.g.
-implementing port redirection. Certainly not the most useful application, but
-as an example it should do:
-
-First, qdiscs need to be set up to attach filters to. For the receive path, a simple
-.B ingress
-qdisc will do, for transmit path a classful qdisc
-.RB ( HTB
-in this case) is necessary:
-
-.RS
-.EX
-tc qdisc replace dev eth0 root handle 1: htb
-tc qdisc add dev eth0 ingress handle ffff:
-.EE
-.RE
-
-Finally, a filter with
-.B pedit
-action can be added for each direction. In this case,
-.B u32
-is used matching on the port number to redirect from, while
-.B pedit
-then does the actual rewriting:
-
-.RS
-.EX
-tc filter add dev eth0 parent 1: u32 \\
-	match ip dport 23 0xffff \\
-	action pedit pedit munge ip dport set 22
-tc filter add dev eth0 parent ffff: u32 \\
-	match ip sport 22 0xffff \\
-	action pedit pedit munge ip sport set 23
-tc filter add dev eth0 parent ffff: u32 \\
-	match ip sport 22 0xffff \\
-	action pedit ex munge ip dst set 192.168.1.199
-tc filter add dev eth0 parent ffff: u32 \\
-	match ip sport 22 0xffff \\
-	action pedit ex munge ip6 dst set fe80::dacb:8aff:fec7:320e
-tc filter add dev eth0 parent ffff: u32 \\
-	match ip sport 22 0xffff \\
-	action pedit ex munge eth dst set 11:22:33:44:55:66
-tc filter add dev eth0 parent ffff: u32 \\
-	match ip dport 23 0xffff \\
-	action pedit ex munge tcp dport set 22
-.EE
-.RE
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-htb (8),
-.BR tc-u32 (8)
diff --git a/man/man8/tc-pie.8 b/man/man8/tc-pie.8
index a302132..278293b 100644
--- a/man/man8/tc-pie.8
+++ b/man/man8/tc-pie.8
@@ -60,10 +60,10 @@
 is reached. Default is 1000 packets.
 
 .SS target
-is the expected queue delay. The default target delay is 15ms.
+is the expected queue delay. The default target delay is 20ms.
 
 .SS tupdate
-is the frequency at which the system drop probability is calculated. The default is 15ms.
+is the frequency at which the system drop probability is calculated. The default is 30ms.
 
 .SS alpha
 .SS beta
@@ -91,27 +91,29 @@
 .SH EXAMPLES
  # tc qdisc add dev eth0 root pie
  # tc -s qdisc show
-   qdisc pie 8036: dev eth0 root refcnt 2 limit 1000p target 15.0ms tupdate 16.0ms alpha 2 beta 20
-    Sent 31216108 bytes 20800 pkt (dropped 80, overlimits 0 requeues 0)
-    backlog 16654b 11p requeues 0
-   prob 0.006161 delay 15666us avg_dq_rate 1159667
-   pkts_in 20811 overlimit 0 dropped 80 maxq 50 ecn_mark 0
+   qdisc pie 8034: dev eth0 root refcnt 2 limit 200p target 19000us tupdate 29000us alpha 2 beta 20
+   Sent 7443524 bytes 7204 pkt (dropped 900, overlimits 0 requeues 0)
+   backlog 38998b 37p requeues 0
+   prob 0.123384 delay 25000us avg_dq_rate 1464840
+   pkts_in 7241 overlimit 900 dropped 0 maxq 186 ecn_mark 0
 
  # tc qdisc add dev eth0 root pie limit 100 target 20ms tupdate 30ms ecn
  # tc -s qdisc show
-   qdisc pie 8036: dev eth0 root refcnt 2 limit 100p target 20.0ms tupdate 32.0ms alpha 2 beta 20 ecn
-    Sent 6591724 bytes 4442 pkt (dropped 27, overlimits 0 requeues 0)
-    backlog 18168b 12p requeues 0
-   prob 0.008845 delay 11348us avg_dq_rate 1342773
-   pkts_in 4454 overlimit 0 dropped 27 maxq 65 ecn_mark 0
+   qdisc pie 8036: dev eth0 root refcnt 2 limit 200p target 19000 tupdate 29000 alpha 2 beta 20 ecn
+   Sent 2491922 bytes 2507 pkt (dropped 214, overlimits 0 requeues 0)
+   backlog 33728b 32p requeues 0
+   prob 0.102262 delay 24000us avg_dq_rate 1464840
+   pkts_in 2468 overlimit 214 dropped 0 maxq 192 ecn_mark 71
+
 
  # tc qdisc add dev eth0 root pie limit 100 target 50ms tupdate 30ms bytemode
  # tc -s qdisc show
-   qdisc pie 8036: dev eth0 root refcnt 2 limit 100p target 50.0ms tupdate 32.0ms alpha 2 beta 20 bytemode
-    Sent 1616274 bytes 1137 pkt (dropped 0, overlimits 0 requeues 0)
-    backlog 13626b 9p requeues 0
-   prob 0.000000 delay 0us avg_dq_rate 0
-   pkts_in 1146 overlimit 0 dropped 0 maxq 23 ecn_mark 0
+   qdisc pie 8036: dev eth0 root refcnt 2 limit 200p target 19000 tupdate 29000 alpha 2 beta 20 ecn
+   Sent 2491922 bytes 2507 pkt (dropped 214, overlimits 0 requeues 0)
+   backlog 33728b 32p requeues 0
+   prob 0.102262 delay 24000us avg_dq_rate 1464840
+   pkts_in 2468 overlimit 214 dropped 0 maxq 192 ecn_mark 71
+
 
 .SH SEE ALSO
 .BR tc (8),
@@ -119,7 +121,9 @@
 .BR tc-red (8)
 
 .SH SOURCES
- o RFC 8033: https://tools.ietf.org/html/rfc8033
+ o IETF draft submission is at http://tools.ietf.org/html/draft-pan-tsvwg-pie-00
+ o IEEE  Conference on High Performance Switching and Routing 2013 : "PIE: A
+Lightweight Control Scheme to Address the Bufferbloat Problem"
 
 .SH AUTHORS
 PIE was implemented by Vijay Subramanian and Mythili Prabhu, also the authors of
diff --git a/man/man8/tc-police.8 b/man/man8/tc-police.8
deleted file mode 100644
index bcc5f43..0000000
--- a/man/man8/tc-police.8
+++ /dev/null
@@ -1,146 +0,0 @@
-.TH "Policing action in tc" 8 "20 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-police - policing action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action police"
-.BI rate " RATE " burst
-.IR BYTES [\fB/ BYTES "] ["
-.B mtu
-.IR BYTES [\fB/ BYTES "] ] ["
-.BI peakrate " RATE"
-] [
-.BI overhead " BYTES"
-] [
-.BI linklayer " TYPE"
-] [
-.IR CONTROL " ]"
-
-.ti -8
-.BR tc " ... " filter " ... [ " estimator
-.IR "SAMPLE AVERAGE " ]
-.BR "action police avrate"
-.IR RATE " [ " CONTROL " ]"
-
-.ti -8
-.IR CONTROL " :="
-.BI conform-exceed " EXCEEDACT\fR[\fB/\fINOTEXCEEDACT"
-
-.ti -8
-.IR EXCEEDACT/NOTEXCEEDACT " := { "
-.BR pipe " | " ok " | " reclassify " | " drop " | " continue " | " goto " " chain " " CHAIN_INDEX " }"
-.SH DESCRIPTION
-The
-.B police
-action allows to limit bandwidth of traffic matched by the filter it is
-attached to. Basically there are two different algorithms available to measure
-the packet rate: The first one uses an internal dual token bucket and is
-configured using the
-.BR rate ", " burst ", " mtu ", " peakrate ", " overhead " and " linklayer
-parameters. The second one uses an in-kernel sampling mechanism. It can be
-fine-tuned using the
-.B estimator
-filter parameter.
-.SH OPTIONS
-.TP
-.BI rate " RATE"
-The maximum traffic rate of packets passing this action. Those exceeding it will
-be treated as defined by the
-.B conform-exceed
-option.
-.TP
-.BI burst " BYTES\fR[\fB/\fIBYTES\fR]"
-Set the maximum allowed burst in bytes, optionally followed by a slash ('/')
-sign and cell size which must be a power of 2.
-.TP
-.BI mtu " BYTES\fR[\fB/\fIBYTES\fR]"
-This is the maximum packet size handled by the policer (larger ones will be
-handled like they exceeded the configured rate). Setting this value correctly
-will improve the scheduler's precision.
-Value formatting is identical to
-.B burst
-above. Defaults to unlimited.
-.TP
-.BI peakrate " RATE"
-Set the maximum bucket depletion rate, exceeding
-.BR rate .
-.TP
-.BI avrate " RATE"
-Make use of an in-kernel bandwidth rate estimator and match the given
-.I RATE
-against it.
-.TP
-.BI overhead " BYTES"
-Account for protocol overhead of encapsulating output devices when computing
-.BR rate " and " peakrate .
-.TP
-.BI linklayer " TYPE"
-Specify the link layer type.
-.I TYPE
-may be one of
-.B ethernet
-(the default),
-.BR atm " or " adsl
-(which are synonyms). It is used to align the precomputed rate tables to ATM
-cell sizes, for
-.B ethernet
-no action is taken.
-.TP
-.BI estimator " SAMPLE AVERAGE"
-Fine-tune the in-kernel packet rate estimator.
-.IR SAMPLE " and " AVERAGE
-are time values and control the frequency in which samples are taken and over
-what timespan an average is built.
-.TP
-.BI conform-exceed " EXCEEDACT\fR[\fB/\fINOTEXCEEDACT\fR]"
-Define how to handle packets which exceed or conform the
-configured bandwidth limit. Possible values are:
-.RS
-.IP continue
-Don't do anything, just continue with the next action in line.
-.IP drop
-Drop the packet immediately.
-.IP shot
-This is a synonym to
-.BR drop .
-.IP ok
-Accept the packet. This is the default for conforming packets.
-.IP pass
-This is a synonym to
-.BR ok .
-.IP reclassify
-Treat the packet as non-matching to the filter this action is attached to and
-continue with the next filter in line (if any). This is the default for
-exceeding packets.
-.IP pipe
-Pass the packet to the next action in line.
-.SH EXAMPLES
-A typical application of the police action is to enforce ingress traffic rate
-by dropping exceeding packets. Although better done on the sender's side,
-especially in scenarios with lack of peer control (e.g. with dial-up providers)
-this is often the best one can do in order to keep latencies low under high
-load. The following establishes input bandwidth policing to 1mbit/s using the
-.B ingress
-qdisc and
-.B u32
-filter:
-
-.RS
-.EX
-# tc qdisc add dev eth0 handle ffff: ingress
-# tc filter add dev eth0 parent ffff: u32 \\
-	match u32 0 0 \\
-	police rate 1mbit burst 100k
-.EE
-.RE
-
-As an action can not live on it's own, there always has to be a filter involved as link between qdisc and action. The example above uses
-.B u32
-for that, which is configured to effectively match any packet (passing it to the
-.B police
-action thereby).
-
-.SH SEE ALSO
-.BR tc (8)
diff --git a/man/man8/tc-sample.8 b/man/man8/tc-sample.8
deleted file mode 100644
index 3e03eba..0000000
--- a/man/man8/tc-sample.8
+++ /dev/null
@@ -1,125 +0,0 @@
-.TH "Packet sample action in tc" 8 "31 Jan 2017" "iproute2" "Linux"
-
-.SH NAME
-sample - packet sampling tc action
-.SH SYNOPSIS
-.in +8
-.ti -8
-
-.BR tc " ... " "action sample rate"
-.I RATE
-.BR "group"
-.I GROUP
-.RB "[ " trunc
-.IR SIZE " ] "
-.RB "[ " index
-.IR INDEX " ] "
-.ti -8
-
-.BR tc " ... " "action sample index "
-.I INDEX
-.ti -8
-
-.SH DESCRIPTION
-The
-.B sample
-action allows sampling packets matching classifier.
-
-The packets are chosen randomly according to the
-.B rate
-parameter, and are sampled using the
-.B psample
-generic netlink channel. The user can also specify packet truncation to save
-user-kernel traffic. Each sample includes some informative metadata about the
-original packet, which is sent using netlink attributes, alongside the original
-packet data.
-
-The user can either specify the sample action parameters as presented in the
-first form above, or use an existing sample action using its index, as presented
-in the second form.
-
-.SH SAMPLED PACKETS METADATA FIELDS
-The metadata are delivered to userspace applications using the
-.B psample
-generic netlink channel, where each sample includes the following netlink
-attributes:
-.TP
-.BI PSAMPLE_ATTR_IIFINDEX
-The input interface index of the packet, if there is one.
-.TP
-.BI PSAMPLE_ATTR_OIFINDEX
-The output interface index of the packet. This field is not relevant on ingress
-sampling
-.TP
-.BI PSAMPLE_ATTR_ORIGSIZE
-The size of the original packet (before truncation)
-.TP
-.BI PSAMPLE_ATTR_SAMPLE_GROUP
-The
-.B psample
-group the packet was sent to
-.TP
-.BI PSAMPLE_ATTR_GROUP_SEQ
-A sequence number of the sampled packet. This number is incremented with each
-sampled packet of the current
-.B psample
-group
-.TP
-.BI PSAMPLE_ATTR_SAMPLE_RATE
-The rate the packet was sampled with
-.RE
-
-.SH OPTIONS
-.TP
-.BI rate " RATE"
-The packet sample rate.
-.I "RATE"
-is the expected ratio between observed packets and sampled packets. For example,
-.I "RATE"
-of 100 will lead to an average of one sampled packet out of every 100 observed.
-.TP
-.BI trunc " SIZE"
-Upon set, defines the maximum size of the sampled packets, and causes truncation
-if needed
-.TP
-.BI group " GROUP"
-The
-.B psample
-group the packet will be sent to. The
-.B psample
-module defines the concept of groups, which allows the user to match specific
-sampled packets in the case of multiple sampling rules, thus identify only the
-packets that came from a specific rule.
-.TP
-.BI index " INDEX"
-Is a unique ID for an action. When creating new action instance, this parameter
-allows to set the new action index. When using existing action, this parameter
-allows to specify the existing action index.  The index must 32bit unsigned
-integer greater than zero.
-.SH EXAMPLES
-Sample one of every 100 packets flowing into interface eth0 to psample group 12:
-
-.RS
-.EX
-tc qdisc add dev eth0 handle ffff: ingress
-tc filter add dev eth0 parent ffff: matchall \\
-     action sample rate 100 group 12 index 19
-.EE
-.RE
-
-Use the same action instance to sample eth1 too:
-
-.RS
-.EX
-tc qdisc add dev eth1 handle ffff: ingress
-tc filter add dev eth1 parent ffff: matchall \\
-     action sample index 19
-.EE
-.RE
-
-.EE
-.RE
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-matchall (8)
-.BR psample (1)
diff --git a/man/man8/tc-simple.8 b/man/man8/tc-simple.8
deleted file mode 100644
index 7363ab5..0000000
--- a/man/man8/tc-simple.8
+++ /dev/null
@@ -1,99 +0,0 @@
-.TH "Simple action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-simple - basic example action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action simple"
-[
-.BI sdata " STRING"
-] [
-.BI index " INDEX"
-] [
-.I CONTROL
-]
-
-.ti -8
-.IR CONTROL " := {"
-.BR reclassify " | " pipe " | " drop " | " continue " | " ok " }"
-
-.SH DESCRIPTION
-This is a pedagogical example rather than an actually useful action. Upon every access, it prints the given
-.I STRING
-which may be of arbitrary length.
-.SH OPTIONS
-.TP
-.BI sdata " STRING"
-The actual string to print.
-.TP
-.BI index " INDEX"
-Optional action index value.
-.TP
-.I CONTROL
-Indicate how
-.B tc
-should proceed after executing the action. For a description of the possible
-.I CONTROL
-values, see
-.BR tc-actions (8).
-.SH EXAMPLES
-The following example makes the kernel yell "Incoming ICMP!" every time it sees
-an incoming ICMP on eth0. Steps are:
-.IP 1) 4
-Add an ingress qdisc point to eth0
-.IP 2) 4
-Start a chain on ingress of eth0 that first matches ICMP then invokes the
-simple action to shout.
-.IP 3) 4
-display stats and show that no packet has been seen by the action
-.IP 4) 4
-Send one ping packet to google (expect to receive a response back)
-.IP 5) 4
-grep the logs to see the logged message
-.IP 6) 4
-display stats again and observe increment by 1
-
-.RE
-.EX
-  hadi@noma1:$ tc qdisc add dev eth0 ingress
-  hadi@noma1:$tc filter add dev eth0 parent ffff: protocol ip prio 5 \\
-	 u32 match ip protocol 1 0xff flowid 1:1 action simple sdata "Incoming ICMP"
-
-  hadi@noma1:$ sudo tc -s filter ls  dev eth0 parent ffff:
-   filter protocol ip pref 5 u32
-   filter protocol ip pref 5 u32 fh 800: ht divisor 1
-   filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
-     match 00010000/00ff0000 at 8
-	action order 1: Simple <Incoming ICMP>
-	 index 4 ref 1 bind 1 installed 29 sec used 29 sec
-	 Action statistics:
-		Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
-		backlog 0b 0p requeues 0
-
-
-  hadi@noma1$ ping -c 1 www.google.ca
-  PING www.google.ca (74.125.225.120) 56(84) bytes of data.
-  64 bytes from ord08s08-in-f24.1e100.net (74.125.225.120): icmp_req=1 ttl=53 time=31.3 ms
-
-  --- www.google.ca ping statistics ---
-  1 packets transmitted, 1 received, 0% packet loss, time 0ms
-  rtt min/avg/max/mdev = 31.316/31.316/31.316/0.000 ms
-
-  hadi@noma1$ dmesg | grep simple
-  [135354.473951] simple: Incoming ICMP_1
-
-  hadi@noma1$ sudo tc/tc -s filter ls  dev eth0 parent ffff:
-  filter protocol ip pref 5 u32
-  filter protocol ip pref 5 u32 fh 800: ht divisor 1
-  filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
-    match 00010000/00ff0000 at 8
-	action order 1: Simple <Incoming ICMP>
-	 index 4 ref 1 bind 1 installed 206 sec used 67 sec
-	Action statistics:
-	Sent 84 bytes 1 pkt (dropped 0, overlimits 0 requeues 0)
-	backlog 0b 0p requeues 0
-.EE
-.SH SEE ALSO
-.BR tc (8)
-.BR tc-actions (8)
diff --git a/man/man8/tc-skbedit.8 b/man/man8/tc-skbedit.8
deleted file mode 100644
index 704f63b..0000000
--- a/man/man8/tc-skbedit.8
+++ /dev/null
@@ -1,74 +0,0 @@
-.TH "SKB editing action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-skbedit - SKB editing action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action skbedit " [ " queue_mapping
-.IR QUEUE_MAPPING " ] ["
-.B priority
-.IR PRIORITY " ] ["
-.BI mark " MARK\fR[\fB/\fIMASK] ] ["
-.B ptype
-.IR PTYPE " ] ["
-.BR inheritdsfield " ]"
-.SH DESCRIPTION
-The
-.B skbedit
-action allows to change a packet's associated meta data. It complements the
-.B pedit
-action, which in turn allows to change parts of the packet data itself.
-
-The most unique feature of
-.B skbedit
-is its ability to decide over which queue of an interface with multiple
-transmit queues the packet is to be sent out. The number of available transmit
-queues is reflected by sysfs entries within
-.I /sys/class/net/<interface>/queues
-with name
-.I tx-N
-(where
-.I N
-is the actual queue number).
-.SH OPTIONS
-.TP
-.BI queue_mapping " QUEUE_MAPPING"
-Override the packet's transmit queue. Useful when applied to packets transmitted
-over MQ-capable network interfaces.
-.I QUEUE_MAPPING
-is an unsigned 16bit value in decimal format.
-.TP
-.BI priority " PRIORITY"
-Override the packet classification decision.
-.I PRIORITY
-is either
-.BR root ", " none
-or a hexadecimal major class ID optionally followed by a colon
-.RB ( : )
-and a hexadecimal minor class ID.
-.TP
-.BI mark " MARK\fR[\fB/\fIMASK]"
-Change the packet's firewall mark value.
-.I MARK
-is an unsigned 32bit value in automatically detected format (i.e., prefix with
-.RB ' 0x '
-for hexadecimal interpretation, etc.).
-.I MASK
-defines the 32-bit mask selecting bits of mark value. Default is 0xffffffff.
-.TP
-.BI ptype " PTYPE"
-Override the packet's type. Useful for setting packet type to host when
-needing to allow ingressing packets with the wrong MAC address but
-correct IP address.
-.I PTYPE
-is one of: host, otherhost, broadcast, multicast
-.TP
-.BI inheritdsfield
-Override the packet classification decision, and any value specified with
-.BR priority ", "
-using the information stored in the Differentiated Services Field of the
-IPv6/IPv4 header (RFC2474).
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-pedit (8)
diff --git a/man/man8/tc-skbmod.8 b/man/man8/tc-skbmod.8
deleted file mode 100644
index 46418b6..0000000
--- a/man/man8/tc-skbmod.8
+++ /dev/null
@@ -1,137 +0,0 @@
-.TH "skbmod action in tc" 8 "21 Sep 2016" "iproute2" "Linux"
-
-.SH NAME
-skbmod - user-friendly packet editor action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action skbmod " "{ [ " "set "
-.IR SETTABLE " ] [ "
-.BI swap " SWAPPABLE"
-.RI " ] [ " CONTROL " ] [ "
-.BI index " INDEX "
-] }
-
-.ti -8
-.IR SETTABLE " := "
-.RB " [ " dmac
-.IR DMAC " ] "
-.RB " [ " smac
-.IR SMAC " ] "
-.RB " [ " etype
-.IR ETYPE " ] "
-
-.ti -8
-.IR SWAPPABLE " := "
-.B mac
-.ti -8
-.IR CONTROL " := {"
-.BR reclassify " | " pipe " | " drop " | " shot " | " continue " | " pass " }"
-.SH DESCRIPTION
-The
-.B skbmod
-action is intended as a usability upgrade to the existing
-.B pedit
-action. Instead of having to manually edit 8-, 16-, or 32-bit chunks of an
-ethernet header,
-.B skbmod
-allows complete substitution of supported elements.
-.SH OPTIONS
-.TP
-.BI dmac " DMAC"
-Change the destination mac to the specified address.
-.TP
-.BI smac " SMAC"
-Change the source mac to the specified address.
-.TP
-.BI etype " ETYPE"
-Change the ethertype to the specified value.
-.TP
-.BI mac
-Used to swap mac addresses. The
-.B swap mac
-directive is performed
-after any outstanding D/SMAC changes.
-.TP
-.I CONTROL
-The following keywords allow to control how the tree of qdisc, classes,
-filters and actions is further traversed after this action.
-.RS
-.TP
-.B reclassify
-Restart with the first filter in the current list.
-.TP
-.B pipe
-Continue with the next action attached to the same filter.
-.TP
-.B drop
-.TQ
-.B shot
-Drop the packet.
-.TP
-.B continue
-Continue classification with the next filter in line.
-.TP
-.B pass
-Finish classification process and return to calling qdisc for further packet
-processing. This is the default.
-.SH EXAMPLES
-To start, observe the following filter with a pedit action:
-
-.RS
-.EX
-tc filter add dev eth1 parent 1: protocol ip prio 10 \\
-	u32 match ip protocol 1 0xff flowid 1:2 \\
-	action pedit munge offset -14 u8 set 0x02 \\
-	munge offset -13 u8 set 0x15 \\
-	munge offset -12 u8 set 0x15 \\
-	munge offset -11 u8 set 0x15 \\
-	munge offset -10 u16 set 0x1515 \\
-	pipe
-.EE
-.RE
-
-Using the skbmod action, this command can be simplified to:
-
-.RS
-.EX
-tc filter add dev eth1 parent 1: protocol ip prio 10 \\
-	u32 match ip protocol 1 0xff flowid 1:2 \\
-	action skbmod set dmac 02:15:15:15:15:15 \\
-	pipe
-.EE
-.RE
-
-Complexity will increase if source mac and ethertype are also being edited
-as part of the action. If all three fields are to be changed with skbmod:
-
-.RS
-.EX
-tc filter add dev eth5 parent 1: protocol ip prio 10 \\
-	u32 match ip protocol 1 0xff flowid 1:2 \\
-	action skbmod \\
-	set etype 0xBEEF \\
-	set dmac 02:12:13:14:15:16 \\
-	set smac 02:22:23:24:25:26
-.EE
-.RE
-
-Finally, swap the destination and source mac addresses in the header:
-
-.RS
-.EX
-tc filter add dev eth3 parent 1: protocol ip prio 10 \\
-	u32 match ip protocol 1 0xff flowid 1:2 \\
-	action skbmod \\
-	swap mac
-.EE
-.RE
-
-As mentioned above, the swap action will occur after any
-.B " smac/dmac "
-substitutions are executed, if they are present.
-
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-u32 (8),
-.BR tc-pedit (8)
diff --git a/man/man8/tc-skbprio.8 b/man/man8/tc-skbprio.8
deleted file mode 100644
index a0a316b..0000000
--- a/man/man8/tc-skbprio.8
+++ /dev/null
@@ -1,70 +0,0 @@
-.TH SKBPRIO 8 "13 August 2018" "iproute2" "Linux"
-.SH NAME
-skbprio \- SKB Priority Queue
-
-.SH SYNOPSIS
-.B tc qdisc ... add skbprio
-.B [ limit
-packets
-.B ]
-
-.SH DESCRIPTION
-SKB Priority Queue is a queueing discipline intended to prioritize
-the most important packets during a denial-of-service (
-.B DoS
-) attack. The priority of a packet is given by
-.B skb->priority
-, where a higher value places the packet closer to the exit of the queue. When
-the queue is full, the lowest priority packet in the queue is dropped to make
-room for the packet to be added if it has higher priority. If the packet to be
-added has lower priority than all packets in the queue, it is dropped.
-
-Without SKB priority queue, queue length limits must be imposed
-on individual sub-queues, and there is no straightforward way to enforce
-a global queue length limit across all priorities. SKBprio queue enforces
-a global queue length limit while not restricting the lengths of
-individual sub-queues.
-
-While SKB Priority Queue is agnostic to how
-.B skb->priority
-is assigned. A typical use case is to copy
-the 6-bit DS field of IPv4 and IPv6 packets using
-.BR tc-skbedit (8).
-If
-.B skb->priority
-is greater or equal to 64, the priority is assumed to be 63.
-Priorities less than 64 are taken at face value.
-
-SKB Priority Queue enables routers to locally decide which
-packets to drop under a DoS attack.
-Priorities should be assigned to packets such that the higher the priority,
-the more expected behavior a source shows.
-So sources have an incentive to play by the rules.
-
-.SH ALGORITHM
-
-Skbprio maintains 64 lists (priorities go from 0 to 63).
-When a packet is enqueued, it gets inserted at the
-.B tail
-of its priority list. When a packet needs to be sent out to the network, it is
-taken from the head of the highest priority list. When the queue is full,
-the packet at the tail of the lowest priority list is dropped to serve the
-ingress packet - if it is of higher priority, otherwise the ingress packet is
-dropped. This algorithm allocates as much bandwidth as possible to high
-priority packets, while only servicing low priority packets when
-there is enough bandwidth.
-
-.SH PARAMETERS
-.TP
-limit
-Maximum queue size specified in packets. It defaults to 64.
-The range for this parameter is [0, UINT32_MAX].
-
-.SH SEE ALSO
-.BR tc-prio (8),
-.BR tc-skbedit (8)
-
-.SH AUTHORS
-Nishanth Devarajan <devarajn@uci.edu>, Michel Machado <michel@digirati.com.br>
-
-This manpage maintained by Bert Hubert <ahu@ds9a.nl>
diff --git a/man/man8/tc-stab.8 b/man/man8/tc-stab.8
index 03a0659..02caa7d 100644
--- a/man/man8/tc-stab.8
+++ b/man/man8/tc-stab.8
@@ -156,8 +156,8 @@
 .br
 \fB[2]\fR http://www.faqs.org/rfcs/rfc2684.html
 
-Please direct bugreports and patches to: <netdev@vger.kernel.org>
+Please direct bugreports and patches to: <net...@vger.kernel.org>
 .
 .SH "AUTHOR"
 .
-Manpage created by Michal Soltys (soltys@ziu.info)
+Manpage created by Michal Soltys (sol...@ziu.info)
diff --git a/man/man8/tc-taprio.8 b/man/man8/tc-taprio.8
deleted file mode 100644
index e1d19ba..0000000
--- a/man/man8/tc-taprio.8
+++ /dev/null
@@ -1,182 +0,0 @@
-.TH TAPRIO 8 "25 Sept 2018" "iproute2" "Linux"
-.SH NAME
-TAPRIO \- Time Aware Priority Shaper
-.SH SYNOPSIS
-.B tc qdisc ... dev
-dev
-.B parent
-classid
-.B [ handle
-major:
-.B ] taprio num_tc
-tcs
-.ti +8
-.B map
-P0 P1 P2 ...
-.B queues
-count1@offset1 count2@offset2 ...
-.ti +8
-.B base-time
-base-time
-.B clockid
-clockid
-.ti +8
-.B sched-entry
-<command 1> <gate mask 1> <interval 1>
-.ti +8
-.B sched-entry
-<command 2> <gate mask 2> <interval 2>
-.ti +8
-.B sched-entry
-<command 3> <gate mask 3> <interval 3>
-.ti +8
-.B sched-entry
-<command N> <gate mask N> <interval N>
-
-.SH DESCRIPTION
-The TAPRIO qdisc implements a simplified version of the scheduling
-state machine defined by IEEE 802.1Q-2018 Section 8.6.9, which allows
-configuration of a sequence of gate states, where each gate state
-allows outgoing traffic for a subset (potentially empty) of traffic
-classes.
-
-How traffic is mapped to different hardware queues is similar to
-.BR mqprio(8)
-and so the
-.B map
-and
-.B queues
-parameters have the same meaning.
-
-The other parameters specify the schedule, and at what point in time
-it should start (it can behave as the schedule started in the past).
-
-.SH PARAMETERS
-.TP
-num_tc
-.BR
-Number of traffic classes to use. Up to 16 classes supported.
-
-.TP
-map
-.br
-The priority to traffic class map. Maps priorities 0..15 to a specified
-traffic class. See
-.BR mqprio(8)
-for more details.
-
-.TP
-queues
-.br
-Provide count and offset of queue range for each traffic class. In the
-format,
-.B count@offset.
-Queue ranges for each traffic classes cannot overlap and must be a
-contiguous range of queues.
-
-.TP
-base-time
-.br
-Specifies the instant in nanoseconds, using the reference of
-.B clockid,
-defining the time when the schedule starts. If 'base-time' is a time
-in the past, the schedule will start at
-
-base-time + (N * cycle-time)
-
-where N is the smallest integer so the resulting time is greater than
-"now", and "cycle-time" is the sum of all the intervals of the entries
-in the schedule;
-
-.TP
-clockid
-.br
-Specifies the clock to be used by qdisc's internal timer for measuring
-time and scheduling events.
-
-.TP
-sched-entry
-.br
-There may multiple
-.B sched-entry
-parameters in a single schedule. Each one has the
-
-sched-entry <command> <gatemask> <interval>
-
-format. The only supported <command> is "S", which
-means "SetGateStates", following the IEEE 802.1Q-2018 definition
-(Table 8-7). <gate mask> is a bitmask where each bit is a associated
-with a traffic class, so bit 0 (the least significant bit) being "on"
-means that traffic class 0 is "active" for that schedule entry.
-<interval> is a time duration, in nanoseconds, that specifies for how
-long that state defined by <command> and <gate mask> should be held
-before moving to the next entry.
-
-.TP
-flags
-.br
-Specifies different modes for taprio. Currently, only txtime-assist is
-supported which can be enabled by setting it to 0x1. In this mode, taprio will
-set the transmit timestamp depending on the interval in which the packet needs
-to be transmitted. It will then utililize the
-.BR etf(8)
-qdisc to sort and transmit the packets at the right time. The second example
-can be used as a reference to configure this mode.
-
-.TP
-txtime-delay
-.br
-This parameter is specific to the txtime offload mode. It specifies the maximum
-time a packet might take to reach the network card from the taprio qdisc. The
-value should always be greater than the delta specified in the
-.BR etf(8)
-qdisc.
-
-.SH EXAMPLES
-
-The following example shows how an traffic schedule with three traffic
-classes ("num_tc 3"), which are separated different traffic classes,
-we are going to call these TC 0, TC 1 and TC 2. We could read the
-"map" parameter below as: traffic with priority 3 is classified as TC
-0, priority 2 is classified as TC 1 and the rest is classified as TC
-2.
-
-The schedule will start at instant 1528743495910289987 using the
-reference CLOCK_TAI. The schedule is composed of three entries each of
-300us duration.
-
-.EX
-# tc qdisc replace dev eth0 parent root handle 100 taprio \\
-              num_tc 3 \\
-              map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \\
-              queues 1@0 1@1 2@2 \\
-              base-time 1528743495910289987 \\
-              sched-entry S 01 300000 \\
-              sched-entry S 02 300000 \\
-              sched-entry S 04 300000 \\
-              clockid CLOCK_TAI
-.EE
-
-Following is an example to enable the txtime offload mode in taprio. See
-.BR etf(8)
-for more information about configuring the ETF qdisc.
-
-.EX
-# tc qdisc replace dev eth0 parent root handle 100 taprio \\
-              num_tc 3 \\
-              map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \\
-              queues 1@0 1@0 1@0 \\
-              base-time 1528743495910289987 \\
-              sched-entry S 01 300000 \\
-              sched-entry S 02 300000 \\
-              sched-entry S 04 400000 \\
-              flags 0x1 \\
-              txtime-delay 200000 \\
-              clockid CLOCK_TAI
-
-# tc qdisc replace dev $IFACE parent 100:1 etf skip_skb_check \\
-              offload delta 200000 clockid CLOCK_TAI
-.EE
-
-.SH AUTHORS
-Vinicius Costa Gomes <vinicius.gomes@intel.com>
diff --git a/man/man8/tc-tcindex.8 b/man/man8/tc-tcindex.8
index 9a4e5ff..7fcf825 100644
--- a/man/man8/tc-tcindex.8
+++ b/man/man8/tc-tcindex.8
@@ -11,7 +11,7 @@
 .IR MASK " ] [ "
 .B shift
 .IR SHIFT " ] [ "
-.BR pass_on " | " fall_through " ] [ " classid
+.BR pas_on " | " fall_through " ] [ " classid
 .IR CLASSID " ] [ "
 .B action
 .BR ACTION_SPEC " ]"
diff --git a/man/man8/tc-tunnel_key.8 b/man/man8/tc-tunnel_key.8
deleted file mode 100644
index 2145eb6..0000000
--- a/man/man8/tc-tunnel_key.8
+++ /dev/null
@@ -1,154 +0,0 @@
-.TH "Tunnel metadata manipulation action in tc" 8 "10 Nov 2016" "iproute2" "Linux"
-
-.SH NAME
-tunnel_key - Tunnel metadata manipulation
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action tunnel_key" " { " unset " | "
-.IR SET " }"
-
-.ti -8
-.IR SET " := "
-.BR set " " src_ip
-.IR ADDRESS
-.BR dst_ip
-.IR ADDRESS
-.BI id " KEY_ID"
-.BI dst_port " UDP_PORT"
-.BI tos " TOS"
-.BI ttl " TTL"
-.RB "[ " csum " | " nocsum " ]"
-
-.SH DESCRIPTION
-The
-.B tunnel_key
-action combined with a shared IP tunnel device, allows to perform IP tunnel en-
-or decapsulation on a packet, reflected by
-the operation modes
-.IR UNSET " and " SET .
-The
-.I UNSET
-mode is optional - even without using it, the metadata information will be
-released automatically when packet processing will be finished.
-.IR UNSET
-function could be used in cases when traffic is forwarded between two tunnels,
-where the metadata from the first tunnel will be used for encapsulation done by
-the second tunnel.
-.IR SET
-mode requires the source and destination ip
-.I ADDRESS
-and the tunnel key id
-.I KEY_ID
-which will be used by the ip tunnel shared device to create the tunnel header. The
-.B tunnel_key
-action is useful only in combination with a
-.B mirred redirect
-action to a shared IP tunnel device which will use the metadata (for
-.I SET
-) and unset the metadata created by it (for
-.I UNSET
-).
-
-.SH OPTIONS
-.TP
-.B unset
-Unset the tunnel metadata created by the IP tunnel device.  This function is
-not mandatory and might be used only in some specific use cases (as explained
-above).
-.TP
-.B set
-Set tunnel metadata to be used by the IP tunnel device. Requires
-.B src_ip
-and
-.B dst_ip
-options.
-.B id
-,
-.B dst_port
-and
-.B geneve_opts
-are optional.
-.RS
-.TP
-.B id
-Tunnel ID (for example VNI in VXLAN tunnel)
-.TP
-.B src_ip
-Outer header source IP address (IPv4 or IPv6)
-.TP
-.B dst_ip
-Outer header destination IP address (IPv4 or IPv6)
-.TP
-.B dst_port
-Outer header destination UDP port
-.TP
-.B geneve_opts
-Geneve variable length options.
-.B geneve_opts
-is specified in the form CLASS:TYPE:DATA, where CLASS is represented as a
-16bit hexadecimal value, TYPE as an 8bit hexadecimal value and DATA as a
-variable length hexadecimal value. Additionally multiple options may be
-listed using a comma delimiter.
-.TP
-.B tos
-Outer header TOS
-.TP
-.B ttl
-Outer header TTL
-.TP
-.RB [ no ] csum
-Controls outer UDP checksum. When set to
-.B csum
-(which is default), the outer UDP checksum is calculated and included in the
-packets. When set to
-.BR nocsum ,
-outer UDP checksum is zero. Note that when using zero UDP checksums with
-IPv6, the other tunnel endpoint must be configured to accept such packets.
-In Linux, this would be the
-.B udp6zerocsumrx
-option for the VXLAN tunnel interface.
-.IP
-If using
-.B nocsum
-with IPv6, be sure you know what you are doing. Zero UDP checksums provide
-weaker protection against corrupted packets. See RFC6935 for details.
-.RE
-.SH EXAMPLES
-The following example encapsulates incoming ICMP packets on eth0 into a vxlan
-tunnel, by setting metadata to VNI 11, source IP 11.11.0.1 and destination IP
-11.11.0.2, and by redirecting the packet with the metadata to device vxlan0,
-which will do the actual encapsulation using the metadata:
-
-.RS
-.EX
-#tc qdisc add dev eth0 handle ffff: ingress
-#tc filter add dev eth0 protocol ip parent ffff: \\
-  flower \\
-    ip_proto icmp \\
-  action tunnel_key set \\
-    src_ip 11.11.0.1 \\
-    dst_ip 11.11.0.2 \\
-    id 11 \\
-  action mirred egress redirect dev vxlan0
-.EE
-.RE
-
-Here is an example of the
-.B unset
-function: Incoming VXLAN traffic with outer IP's and VNI 11 is decapsulated by
-vxlan0 and metadata is unset before redirecting to tunl1 device:
-
-.RS
-.EX
-#tc qdisc add dev eth0 handle ffff: ingress
-#tc filter add dev vxlan0 protocol ip parent ffff: \
-  flower \\
-	  enc_src_ip 11.11.0.2 enc_dst_ip 11.11.0.1 enc_key_id 11 \
-	action tunnel_key unset \
-	action mirred egress redirect dev tunl1
-.EE
-.RE
-
-.SH SEE ALSO
-.BR tc (8)
diff --git a/man/man8/tc-u32.8 b/man/man8/tc-u32.8
index 2bf2e3e..47c8f2d 100644
--- a/man/man8/tc-u32.8
+++ b/man/man8/tc-u32.8
@@ -29,8 +29,6 @@
 .IR HANDLE " ] [ "
 .B indev
 .IR ifname " ] [ "
-.BR skip_hw " | "
-.BR skip_sw " ] [ "
 .BR help " ]"
 
 .ti -8
@@ -333,13 +331,6 @@
 Filter on the incoming interface of the packet. Obviously works only for
 forwarded traffic.
 .TP
-.BI skip_sw
-Do not process filter by software. If hardware has no offload support for this
-filter, or TC offload is not enabled for the interface, operation will fail.
-.TP
-.BI skip_hw
-Do not process filter by hardware.
-.TP
 .BI help
 Print a brief help text about possible options.
 .SH SELECTORS
@@ -379,7 +370,6 @@
 .RS
 .TP
 .BI src " ADDR"
-.TQ
 .BI dst " ADDR"
 Compare Source or Destination Address fields against the value of
 .IR ADDR .
diff --git a/man/man8/tc-vlan.8 b/man/man8/tc-vlan.8
deleted file mode 100644
index f5ffc25..0000000
--- a/man/man8/tc-vlan.8
+++ /dev/null
@@ -1,126 +0,0 @@
-.TH "VLAN manipulation action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
-
-.SH NAME
-vlan - vlan manipulation module
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action vlan" " { " pop " |"
-.IR PUSH " | " MODIFY " } [ " CONTROL " ]"
-
-.ti -8
-.IR PUSH " := "
-.BR push " [ " protocol
-.IR VLANPROTO " ]"
-.BR " [ " priority
-.IR VLANPRIO " ] "
-.BI id " VLANID"
-
-.ti -8
-.IR MODIFY " := "
-.BR modify " [ " protocol
-.IR VLANPROTO " ]"
-.BR " [ " priority
-.IR VLANPRIO " ] "
-.BI id " VLANID"
-
-.ti -8
-.IR CONTROL " := { "
-.BR reclassify " | " pipe " | " drop " | " continue " | " pass " | " goto " " chain " " CHAIN_INDEX " }"
-.SH DESCRIPTION
-The
-.B vlan
-action allows to perform 802.1Q en- or decapsulation on a packet, reflected by
-the operation modes
-.IR POP ", " PUSH " and " MODIFY .
-The
-.I POP
-mode is simple, as no further information is required to just drop the
-outer-most VLAN encapsulation. The
-.IR PUSH " and " MODIFY
-modes require at least a
-.I VLANID
-and allow to optionally choose the
-.I VLANPROTO
-to use.
-.SH OPTIONS
-.TP
-.B pop
-Decapsulation mode, no further arguments allowed.
-.TP
-.B push
-Encapsulation mode. Requires at least
-.B id
-option.
-.TP
-.B modify
-Replace mode. Existing 802.1Q tag is replaced. Requires at least
-.B id
-option.
-.TP
-.BI id " VLANID"
-Specify the VLAN ID to encapsulate into.
-.I VLANID
-is an unsigned 16bit integer, the format is detected automatically (e.g. prefix
-with
-.RB ' 0x '
-for hexadecimal interpretation, etc.).
-.TP
-.BI protocol " VLANPROTO"
-Choose the VLAN protocol to use. At the time of writing, the kernel accepts only
-.BR 802.1Q " or " 802.1ad .
-.TP
-.BI priority " VLANPRIO"
-Choose the VLAN priority to use. Decimal number in range of 0-7.
-.TP
-.I CONTROL
-How to continue after executing this action.
-.RS
-.TP
-.B reclassify
-Restarts classification by jumping back to the first filter attached to this
-action's parent.
-.TP
-.B pipe
-Continue with the next action, this is the default.
-.TP
-.B drop
-Packet will be dropped without running further actions.
-.TP
-.B continue
-Continue classification with next filter in line.
-.TP
-.B pass
-Return to calling qdisc for packet processing. This ends the classification
-process.
-.RE
-.SH EXAMPLES
-The following example encapsulates incoming ICMP packets on eth0 from 10.0.0.2
-into VLAN ID 123:
-
-.RS
-.EX
-#tc qdisc add dev eth0 handle ffff: ingress
-#tc filter add dev eth0 parent ffff: pref 11 protocol ip \\
-	u32 match ip protocol 1 0xff flowid 1:1 \\
-	    match ip src 10.0.0.2 flowid 1:1 \\
-	action vlan push id 123
-.EE
-.RE
-
-Here is an example of the
-.B pop
-function: Incoming VLAN packets on eth0 are decapsulated and the classification
-process then restarted for the plain packet:
-
-.RS
-.EX
-#tc qdisc add dev eth0 handle ffff: ingress
-#tc filter add dev $ETH parent ffff: pref 1 protocol 802.1Q \\
-	u32 match u32 0 0 flowid 1:1 \\
-	action vlan pop reclassify
-.EE
-.RE
-
-.SH SEE ALSO
-.BR tc (8)
diff --git a/man/man8/tc-xt.8 b/man/man8/tc-xt.8
deleted file mode 100644
index 4fd800c..0000000
--- a/man/man8/tc-xt.8
+++ /dev/null
@@ -1,42 +0,0 @@
-.TH "iptables action in tc" 8 "3 Mar 2016" "iproute2" "Linux"
-
-.SH NAME
-xt - tc iptables action
-.SH SYNOPSIS
-.in +8
-.ti -8
-.BR tc " ... " "action xt \-j"
-.IR TARGET " [ " TARGET_OPTS " ]"
-.SH DESCRIPTION
-The
-.B xt
-action allows to call arbitrary iptables targets for packets matching the filter
-this action is attached to.
-.SH OPTIONS
-.TP
-.BI -j " TARGET \fR[\fI TARGET_OPTS \fR]"
-Perform a jump to the given iptables target, optionally passing any target
-specific options in
-.IR TARGET_OPTS .
-.SH EXAMPLES
-The following will attach a
-.B u32
-filter to the
-.B ingress
-qdisc matching ICMP replies and using the
-.B xt
-action to make the kernel yell 'PONG' each time:
-
-.RS
-.EX
-tc qdisc add dev eth0 ingress
-tc filter add dev eth0 parent ffff: proto ip u32 \\
-	match ip protocol 1 0xff \\
-	match ip icmp_type 0 0xff \\
-	action xt -j LOG --log-prefix PONG
-.EE
-.RE
-.SH SEE ALSO
-.BR tc (8),
-.BR tc-u32 (8),
-.BR iptables-extensions (8)
diff --git a/man/man8/tc.8 b/man/man8/tc.8
index b81a396..4e99dca 100644
--- a/man/man8/tc.8
+++ b/man/man8/tc.8
@@ -5,136 +5,75 @@
 .B tc
 .RI "[ " OPTIONS " ]"
 .B qdisc [ add | change | replace | link | delete ] dev
-\fIDEV\fR
+DEV
 .B
 [ parent
-\fIqdisc-id\fR
+qdisc-id
 .B | root ]
 .B [ handle
-\fIqdisc-id\fR ]
-.B [ ingress_block
-\fIBLOCK_INDEX\fR ]
-.B [ egress_block
-\fIBLOCK_INDEX\fR ] qdisc
+qdisc-id ] qdisc
 [ qdisc specific parameters ]
 .P
 
 .B tc
 .RI "[ " OPTIONS " ]"
 .B class [ add | change | replace | delete ] dev
-\fIDEV\fR
+DEV
 .B parent
-\fIqdisc-id\fR
+qdisc-id
 .B [ classid
-\fIclass-id\fR ] qdisc
+class-id ] qdisc
 [ qdisc specific parameters ]
 .P
 
 .B tc
 .RI "[ " OPTIONS " ]"
-.B filter [ add | change | replace | delete | get ] dev
-\fIDEV\fR
+.B filter [ add | change | replace | delete ] dev
+DEV
 .B [ parent
-\fIqdisc-id\fR
-.B | root ] [ handle \fIfilter-id\fR ]
-.B protocol
-\fIprotocol\fR
+qdisc-id
+.B | root ] protocol
+protocol
 .B prio
-\fIpriority\fR filtertype
+priority filtertype
 [ filtertype specific parameters ]
 .B flowid
-\fIflow-id\fR
-
-.B tc
-.RI "[ " OPTIONS " ]"
-.B filter [ add | change | replace | delete | get ] block
-\fIBLOCK_INDEX\fR
-.B [ handle \fIfilter-id\fR ]
-.B protocol
-\fIprotocol\fR
-.B prio
-\fIpriority\fR filtertype
-[ filtertype specific parameters ]
-.B flowid
-\fIflow-id\fR
-
-.B tc
-.RI "[ " OPTIONS " ]"
-.B chain [ add | delete | get ] dev
-\fIDEV\fR
-.B [ parent
-\fIqdisc-id\fR
-.B | root ]\fR filtertype
-[ filtertype specific parameters ]
-
-.B tc
-.RI "[ " OPTIONS " ]"
-.B chain [ add | delete | get ] block
-\fIBLOCK_INDEX\fR filtertype
-[ filtertype specific parameters ]
-
+flow-id
 
 .B tc
 .RI "[ " OPTIONS " ]"
 .RI "[ " FORMAT " ]"
 .B qdisc show [ dev
-\fIDEV\fR
+DEV
 .B ]
 .P
 .B tc
 .RI "[ " OPTIONS " ]"
 .RI "[ " FORMAT " ]"
 .B class show dev
-\fIDEV\fR
+DEV
 .P
 .B tc
 .RI "[ " OPTIONS " ]"
 .B filter show dev
-\fIDEV\fR
-.P
-.B tc
-.RI "[ " OPTIONS " ]"
-.B filter show block
-\fIBLOCK_INDEX\fR
-.P
-.B tc
-.RI "[ " OPTIONS " ]"
-.B chain show dev
-\fIDEV\fR
-.P
-.B tc
-.RI "[ " OPTIONS " ]"
-.B chain show block
-\fIBLOCK_INDEX\fR
-
-.P
-.B tc
-.RI "[ " OPTIONS " ]"
-.B monitor [ file
-\fIFILENAME\fR
-.B ]
+DEV
 
 .P
 .ti 8
 .IR OPTIONS " := {"
 \fB[ -force ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
 \fB[ \fB-n\fR[\fIetns\fR] name \fB] \fR|
-\fB[ \fB-N\fR[\fIumeric\fR] \fB] \fR|
 \fB[ \fB-nm \fR| \fB-nam\fR[\fIes\fR] \fB] \fR|
-\fB[ \fR{ \fB-cf \fR| \fB-c\fR[\fIonf\fR] \fR} \fB[ filename ] \fB] \fR
-\fB[ -t\fR[imestamp\fR] \fB\] \fR| \fB[ -t\fR[short\fR] \fR| \fB[
--o\fR[neline\fR] \fB]\fR }
+\fB[ \fR{ \fB-cf \fR| \fB-c\fR[\fIonf\fR] \fR} \fB[ filename ] \fB] \fR}
 
 .ti 8
 .IR FORMAT " := {"
 \fB\-s\fR[\fItatistics\fR] |
 \fB\-d\fR[\fIetails\fR] |
 \fB\-r\fR[\fIaw\fR] |
-\fB\-i\fR[\fIec\fR] |
-\fB\-g\fR[\fIraph\fR] |
-\fB\-j\fR[\fIjson\fR] |
 \fB\-p\fR[\fIretty\fR] |
-\fB\-col\fR[\fIor\fR] }
+\fB\-i\fR[\fIec\fR] |
+\fB\-g\fR[\fIraph\fR] }
 
 .SH DESCRIPTION
 .B Tc
@@ -248,11 +187,6 @@
 Generic filtering on arbitrary packet data, assisted by syntax to abstract common operations. See
 .BR tc-u32 (8)
 for details.
-.TP
-matchall
-Traffic control filter that matches every packet. See
-.BR tc-matchall (8)
-for details.
 
 .SH CLASSLESS QDISCS
 The classless qdiscs are:
@@ -355,14 +289,14 @@
 the root of a device. Full syntax:
 .P
 .B tc qdisc add dev
-\fIDEV\fR
+DEV
 .B root
 QDISC QDISC-PARAMETERS
 
 To remove, issue
 .P
 .B tc qdisc del dev
-\fIDEV\fR
+DEV
 .B root
 
 The
@@ -447,7 +381,7 @@
 Some qdiscs have built in rules for classifying packets based on the TOS field.
 .TP
 skb->priority
-Userspace programs can encode a \fIclass-id\fR in the 'skb->priority' field using
+Userspace programs can encode a class-id in the 'skb->priority' field using
 the SO_PRIORITY option.
 .P
 Each node within the tree can have its own filters but higher level filters
@@ -503,10 +437,7 @@
 RATES
 Bandwidths or rates.
 These parameters accept a floating point number, possibly followed by
-either a unit (both SI and IEC units supported), or a float followed by a '%'
-character to specify the rate as a percentage of the device's speed
-(e.g. 5%, 99.5%). Warning: specifying the rate as a percentage means a fraction
-of the current speed; if the speed changes, the value will not be recalculated.
+a unit (both SI and IEC units supported).
 .RS
 .TP
 bit or a bare number
@@ -618,7 +549,7 @@
 When creating a qdisc or a filter, it can be named with the
 .B handle
 parameter. A class is named with the
-.B \fBclassid\fR
+.B classid
 parameter.
 
 .TP
@@ -640,30 +571,10 @@
 it is created.
 
 .TP
-get
-Displays a single filter given the interface \fIDEV\fR, \fIqdisc-id\fR,
-\fIpriority\fR, \fIprotocol\fR and \fIfilter-id\fR.
-
-.TP
-show
-Displays all filters attached to the given interface. A valid parent ID must be passed.
-
-.TP
 link
 Only available for qdiscs and performs a replace where the node
 must exist already.
 
-.SH MONITOR
-The\fB\ tc\fR\ utility can monitor events generated by the kernel such as
-adding/deleting qdiscs, filters or actions, or modifying existing ones.
-
-The following command is available for\fB\ monitor\fR\ :
-.TP
-\fBfile\fR
-If the file option is given, the \fBtc\fR does not listen to kernel events, but opens
-the given file and dumps its contents. The file has to be in binary
-format and contain netlink messages.
-
 .SH OPTIONS
 
 .TP
@@ -677,18 +588,6 @@
 If there were any errors during execution of the commands, the application return code will be non zero.
 
 .TP
-.BR "\-o" , " \-oneline"
-output each record on a single line, replacing line feeds
-with the
-.B '\e'
-character. This is convenient when you want to count records
-with
-.BR wc (1)
-or to
-.BR grep (1)
-the output.
-
-.TP
 .BR "\-n" , " \-net" , " \-netns " <NETNS>
 switches
 .B tc
@@ -709,25 +608,10 @@
 .BR help " }"
 
 .TP
-.BR "\-N" , " \-Numeric"
-Print the number of protocol, scope, dsfield, etc directly instead of
-converting it to human readable name.
-
-.TP
 .BR "\-cf" , " \-conf " <FILENAME>
 specifies path to the config file. This option is used in conjunction with other options (e.g.
 .BR -nm ")."
 
-.TP
-.BR "\-t", " \-timestamp"
-When\fB\ tc monitor\fR\ runs, print timestamp before the event message in format:
-   Timestamp: <Day> <Month> <DD> <hh:mm:ss> <YYYY> <usecs> usec
-
-.TP
-.BR "\-ts", " \-tshort"
-When\fB\ tc monitor\fR\ runs, prints short timestamp before the event message in format:
-   [<YYYY>-<MM>-<DD>T<hh:mm:ss>.<ms>]
-
 .SH FORMAT
 The show command has additional formatting options:
 
@@ -745,8 +629,7 @@
 
 .TP
 .BR "\-p", " \-pretty"
-for u32 filter, decode offset and mask values to equivalent filter commands based on TCP/IP.
-In JSON output, add whitespace to improve readability.
+decode filter offset and mask values to equivalent filter commands based on TCP/IP.
 
 .TP
 .BR "\-iec"
@@ -761,23 +644,6 @@
 option.
 
 .TP
-.BR \-c [ color ][ = { always | auto | never }
-Configure color output. If parameter is omitted or
-.BR always ,
-color output is enabled regardless of stdout state. If parameter is
-.BR auto ,
-stdout is checked to be a terminal before enabling color output. If parameter is
-.BR never ,
-color output is disabled. If specified multiple times, the last one takes
-precedence. This flag is ignored if
-.B \-json
-is also given.
-
-.TP
-.BR "\-j", " \-json"
-Display results in JSON format.
-
-.TP
 .BR "\-nm" , " \-name"
 resolve class name from
 .B /etc/iproute2/tc_cls
@@ -836,7 +702,6 @@
 .BR tc-basic (8),
 .BR tc-bfifo (8),
 .BR tc-bpf (8),
-.BR tc-cake (8),
 .BR tc-cbq (8),
 .BR tc-cgroup (8),
 .BR tc-choke (8),
@@ -854,7 +719,6 @@
 .BR tc-mqprio (8),
 .BR tc-pfifo (8),
 .BR tc-pfifo_fast (8),
-.BR tc-pie (8),
 .BR tc-red (8),
 .BR tc-route (8),
 .BR tc-sfb (8),
diff --git a/man/man8/tipc-bearer.8 b/man/man8/tipc-bearer.8
index d95b1e1..565ee01 100644
--- a/man/man8/tipc-bearer.8
+++ b/man/man8/tipc-bearer.8
@@ -11,11 +11,6 @@
 .in +8
 
 .ti -8
-.B tipc bearer add media udp name
-.IB "NAME " "remoteip " REMOTEIP
-.br
-
-.ti -8
 .B tipc bearer enable
 .RB "[ " domain
 .IR DOMAIN " ]"
@@ -44,12 +39,14 @@
 .B tipc bearer disable media
 .br
 .RB "{ { " eth " | " ib " } " device
-.IR "DEVICE " }
+.IR DEVICE
 .RB "|"
 .br
 .RB "{ " udp
 .B name
-.IR NAME " }"
+.IR NAME
+.B localip
+.IR LOCALIP " } }"
 .br
 
 .ti -8
@@ -68,12 +65,14 @@
 .br
 .RB "{ " udp
 .B name
-.IR NAME " }"
+.IR NAME
+.B localip
+.IR LOCALIP " } }"
 .br
 
 .ti -8
 .B tipc bearer get
-.RB "[ " "priority" " | " tolerance " | " window " ] " media
+.RB "{ " "priority" " | " tolerance " | " window " } " media
 .br
 .RB "{ { " eth " | " ib " } " device
 .IR "DEVICE" " }"
@@ -82,7 +81,8 @@
 .RB "{ " udp
 .B name
 .IR NAME
-.RB "[ " "localip " "| " "localport " "| " "remoteip " "| " "remoteport " "] }"
+.B localip
+.IR LOCALIP " } }"
 .br
 
 .ti -8
@@ -202,25 +202,6 @@
 .B udp
 bearer runs in point-to-point mode.
 
-Multiple
-.B remoteip
-addresses can be added via the
-.B bearer add
-command. Adding one or more unicast
-.B remoteip
-addresses to an existing
-.B udp
-bearer puts the bearer in replicast mode where IP
-multicast is emulated by sending multiple unicast messages to each configured
-.B remoteip.
-When a peer sees a TIPC discovery message from an unknown peer the peer address
-is automatically added to the
-.B remoteip
-(replicast) list, thus only one side of
-a link needs to be manually configured. A
-.B remoteip
-address cannot be added to a multicast bearer.
-
 .TP
 .BI "remoteport " REMOTEPORT
 .br
diff --git a/man/man8/tipc-link.8 b/man/man8/tipc-link.8
index 47dae25..2ee03a0 100644
--- a/man/man8/tipc-link.8
+++ b/man/man8/tipc-link.8
@@ -1,4 +1,4 @@
-.TH TIPC-LINK 8 "22 Mar 2019" "iproute2" "Linux"
+.TH TIPC-LINK 8 "02 Jun 2015" "iproute2" "Linux"
 
 .\" For consistency, please keep padding right aligned.
 .\" For example '.B "foo " bar' and not '.B foo " bar"'
@@ -14,36 +14,18 @@
 
 .ti -8
 .B tipc link set
-.br
-.RB "[ " "{ " "priority "
+.RB "{ " "priority "
 .IR PRIORITY
 .RB "| " tolerance
 .IR TOLERANCE
 .RB "| " window
 .IR "WINDOW " }
-.BI "link " LINK " ]"
-.RB "|"
-.br
-.RB "[ "
-.RB "{ " broadcast " [ "
-.IR BROADCAST
-.RB " | "
-.IR REPLICAST
-.RB " | "
-.IR AUTOSELECT
-.RB "[ " ratio
-.IR SIZE
-.RB "] " ] " } " "]"
+.BI "link " LINK
 
 .ti -8
 .B tipc link get
-.br
-.RB "[ " "{ " "priority" " | " tolerance " | " window " } " link
-.IR LINK " ] "
-.RB "|"
-.br
-.RB "[ " { " broadcast " } " ]"
-.br
+.RB "{ " "priority" " | " tolerance " | " window " } " link
+.I LINK
 
 .ti -8
 .B tipc link statistics
@@ -57,29 +39,6 @@
 .B tipc link list
 .br
 
-.ti -8
-.B tipc link monitor set
-.RB "{ " "threshold" " } "
-
-.ti -8
-.B tipc link monitor get
-.RB "{ " "threshold" " } "
-
-.ti -8
-.B tipc link monitor summary
-.br
-
-.ti -8
-.B tipc link monitor list
-.br
-.RB "[ " "media " " { " eth " | " ib " } " device
-.IR "DEVICE" " ]"
-.RB "|"
-.br
-.RB "[ " "media udp name"
-.IR NAME " ]"
-.br
-
 .SH OPTIONS
 Options (flags) that can be passed anywhere in the command chain.
 .TP
@@ -89,16 +48,6 @@
 will show link help and
 .B tipc --help
 will show general help. The position of the option in the string is irrelevant.
-
-.TP
-.BR "\-j", " \-json"
-Output results in JavaScript Object Notation (JSON).
-
-.TP
-.BR "\-p", " \-pretty"
-The default JSON format is compact and more efficient to parse but hard for most users to read.
-This flag adds indentation for readability.
-
 .SH DESCRIPTION
 
 .SS Link statistics
@@ -255,112 +204,6 @@
 have in its transmit queue before TIPC's congestion control mechanism is
 activated.
 
-.SS Monitor properties
-
-.TP
-.B threshold
-.br
-The threshold specifies the cluster size exceeding which the link monitoring
-algorithm will switch from "full-mesh" to "overlapping-ring".
-If set of 0 the overlapping-ring monitoring is always on and if set to a
-value larger than anticipated cluster size the overlapping-ring is disabled.
-The default value is 32.
-
-.SS Monitor information
-
-.TP
-.B table_generation
-.br
-Represents the event count in a node's local monitoring list. It steps every
-time something changes in the local monitor list, including changes in the
-local domain.
-
-.TP
-.B cluster_size
-.br
-Represents the current count of cluster members.
-
-.TP
-.B algorithm
-.br
-The current supervision algorithm used for neighbour monitoring for the bearer.
-Possible values are full-mesh or overlapping-ring.
-
-.TP
-.B status
-.br
-The node status derived by the local node.
-Possible status are up or down.
-
-.TP
-.B monitored
-.br
-Represent the type of monitoring chosen by the local node.
-Possible values are direct or indirect.
-
-.TP
-.B generation
-.br
-Represents the domain generation which is the event count in a node's local
-domain. Every time something changes (peer add/remove/up/down) the domain
-generation is stepped and a new version of node record is sent to inform
-the neighbors about this change. The domain generation helps the receiver
-of a domain record to know if it should ignore or process the record.
-
-.TP
-.B applied_node_status
-.br
-The node status reported by the peer node for the succeeding peers in
-the node list. The Node list is a circular list of ascending addresses
-starting with the local node.
-Possible status are: U or D. The status U implies up and D down.
-
-.TP
-.B [non_applied_node:status]
-.br
-Represents the nodes and their status as reported by the peer node.
-These nodes were not applied to the monitoring list for this peer node.
-They are usually transient and occur during the cluster startup phase
-or network reconfiguration.
-Possible status are: U or D. The status U implies up and D down.
-
-.SS Broadcast properties
-.TP
-.B  BROADCAST
-.br
-Forces all multicast traffic to be transmitted via broadcast only,
-irrespective of cluster size and number of destinations.
-
-.TP
-.B REPLICAST
-.br
-Forces all multicast traffic to be transmitted via replicast only,
-irrespective of cluster size and number of destinations.
-
-.TP
-.B AUTOSELECT
-.br
-Auto switching to broadcast or replicast depending on cluster size and
-destination node number.
-
-.TP
-.B ratio SIZE
-.br
-Set the AUTOSELECT criteria, percentage of destination nodes vs cluster
-size.
-
-.SH EXAMPLES
-.PP
-tipc link monitor list
-.RS 4
-Shows the link monitoring information for cluster members on device data0.
-.RE
-.PP
-tipc link monitor summary
-.RS 4
-The monitor summary command prints the basic attributes.
-.RE
-
 .SH EXIT STATUS
 Exit status is 0 if command was successful or a positive integer upon failure.
 
diff --git a/man/man8/tipc-nametable.8 b/man/man8/tipc-nametable.8
index b187d25..4bcefe4 100644
--- a/man/man8/tipc-nametable.8
+++ b/man/man8/tipc-nametable.8
@@ -18,16 +18,6 @@
 Options (flags) that can be passed anywhere in the command chain.
 .TP
 .BR "\-h" , " --help"
-
-.TP
-.BR "\-j", " \-json"
-Output results in JavaScript Object Notation (JSON).
-
-.TP
-.BR "\-p", " \-pretty"
-The default JSON format is compact and more efficient to parse but hard for most users to read.
-This flag adds indentation for readability.
-
 Show help about last valid command. For example
 .B tipc nametable --help
 will show nametable help and
diff --git a/man/man8/tipc.8 b/man/man8/tipc.8
index 6706cca..32943fa 100644
--- a/man/man8/tipc.8
+++ b/man/man8/tipc.8
@@ -40,15 +40,6 @@
 .B tipc --help
 will show general help. The position of the option in the string is irrelevant.
 
-.TP
-.BR "\-j", " \-json"
-Output results in JavaScript Object Notation (JSON).
-
-.TP
-.BR "\-p", " \-pretty"
-The default JSON format is compact and more efficient to parse but hard for most users to read.
-This flag adds indentation for readability.
-
 .SH COMMANDS
 
 .TP
diff --git a/misc/Android.mk b/misc/Android.mk
index 6b07f70..6867895 100644
--- a/misc/Android.mk
+++ b/misc/Android.mk
@@ -1,55 +1,37 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
+
+LOCAL_SRC_FILES := ss.c ssfilter.y
+
 LOCAL_MODULE := ss
-LOCAL_MODULE_TAGS := optional
 
-LOCAL_SRC_FILES :=  ss.c ssfilter.c
+LOCAL_MODULE_TAGS := debug
 
-LOCAL_STATIC_LIBRARIES += libiprouteutil libnetlink
+LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
 
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
 
-ss_local_path := $(LOCAL_PATH)
+##
+# "-x c" forces the lex/yacc files to be compiled as c the build system
+# otherwise forces them to be c++.
+yacc_flags := -x c
 
-LOCAL_CFLAGS := -O2 -g -W -Wall -Wno-pointer-arith -Wno-sign-compare -Werror \
-                -Wno-missing-field-initializers -Wno-unused-parameter \
-                -Wno-unused-result -Wno-tautological-pointer-compare \
-                -DHAVE_SETNS -DNEED_STRLCPY
+LOCAL_CFLAGS := \
+    -O2 -g \
+    -W -Wall \
+    -Wno-missing-field-initializers \
+    -Wno-sign-compare \
+    -Wno-tautological-pointer-compare \
+    -Wno-unused-parameter \
+    -Werror \
+    '-Dsethostent(x)=' \
+    $(yacc_flags) \
+    -DHAVE_SETNS
 
-$(ss_local_path)/ssfilter.c: $(ss_local_path)/ssfilter.y
-	bison $(ss_local_path)/ssfilter.y -o $(ss_local_path)/ssfilter.c
+LOCAL_CPPFLAGS := $(yacc_flags)
 
+LOCAL_LDFLAGS := -Wl,-export-dynamic
 include $(BUILD_EXECUTABLE)
 
-include $(CLEAR_VARS)
-LOCAL_MODULE := nstat
-LOCAL_MODULE_TAGS := eng
-
-LOCAL_SRC_FILES := nstat.c
-LOCAL_STATIC_LIBRARIES += libiprouteutil libnetlink
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
-LOCAL_CFLAGS := -O2 -g -W -Wall -Wno-pointer-arith -Wno-sign-compare -Werror \
-                -Wno-missing-field-initializers -Wno-unused-parameter \
-                -Wno-unused-result -Wno-tautological-pointer-compare \
-                -DHAVE_SETNS
-LOCAL_LDLIBS += -lm
-
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := ifstat
-LOCAL_MODULE_TAGS := eng
-
-LOCAL_SRC_FILES := ifstat.c
-LOCAL_STATIC_LIBRARIES += libiprouteutil libnetlink
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
-LOCAL_CFLAGS := -O2 -g -W -Wall -Wno-pointer-arith -Wno-sign-compare -Werror \
-                -Wno-missing-field-initializers -Wno-unused-parameter \
-                -Wno-unused-result -Wno-tautological-pointer-compare \
-                -DHAVE_SETNS
-LOCAL_LDLIBS += -lm
-
-include $(BUILD_EXECUTABLE)
-
-
diff --git a/misc/Makefile b/misc/Makefile
index 6a849af..f50e740 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -1,37 +1,43 @@
-# SPDX-License-Identifier: GPL-2.0
 SSOBJ=ss.o ssfilter.o
 LNSTATOBJ=lnstat.o lnstat_util.o
 
 TARGETS=ss nstat ifstat rtacct lnstat
 
-include ../config.mk
+include ../Config
 
 ifeq ($(HAVE_BERKELEY_DB),y)
 	TARGETS += arpd
 endif
 
+ifeq ($(HAVE_SELINUX),y)
+	LDLIBS += $(shell $(PKG_CONFIG) --libs libselinux)
+	CFLAGS += $(shell $(PKG_CONFIG) --cflags libselinux) -DHAVE_SELINUX
+endif
+
+ifeq ($(IP_CONFIG_SETNS),y)
+	CFLAGS += -DHAVE_SETNS
+endif
+
 all: $(TARGETS)
 
 ss: $(SSOBJ)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
 
 nstat: nstat.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o nstat nstat.c $(LDLIBS) -lm
+	$(CC) $(CFLAGS) $(LDFLAGS) -o nstat nstat.c $(LIBNETLINK) -lm
 
 ifstat: ifstat.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o ifstat ifstat.c $(LDLIBS) -lm
+	$(CC) $(CFLAGS) $(LDFLAGS) -o ifstat ifstat.c $(LIBNETLINK) -lm
 
 rtacct: rtacct.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o rtacct rtacct.c $(LDLIBS) -lm
+	$(CC) $(CFLAGS) $(LDFLAGS) -o rtacct rtacct.c $(LIBNETLINK) -lm
 
 arpd: arpd.c
-	$(QUIET_CC)$(CC) $(CFLAGS) -I$(DBM_INCLUDE) $(CPPFLAGS) $(LDFLAGS) -o arpd arpd.c $(LDLIBS) -ldb
+	$(CC) $(CFLAGS) -I$(DBM_INCLUDE) $(LDFLAGS) -o arpd arpd.c $(LIBNETLINK) -ldb -lpthread
 
 ssfilter.c: ssfilter.y
-	$(QUIET_YACC)bison ssfilter.y -o ssfilter.c
+	bison ssfilter.y -o ssfilter.c
 
 lnstat: $(LNSTATOBJ)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
 
 install: all
 	install -m 0755 $(TARGETS) $(DESTDIR)$(SBINDIR)
diff --git a/misc/arpd.c b/misc/arpd.c
index 504961c..6bb9bd1 100644
--- a/misc/arpd.c
+++ b/misc/arpd.c
@@ -38,6 +38,8 @@
 #include "utils.h"
 #include "rt_names.h"
 
+int resolve_hosts;
+
 DB	*dbase;
 char	*dbname = "/var/lib/arpd/arpd.db";
 
@@ -45,16 +47,17 @@
 int	*ifvec;
 char	**ifnames;
 
-struct dbkey {
+struct dbkey
+{
 	__u32	iface;
 	__u32	addr;
 };
 
-#define IS_NEG(x)	(((__u8 *)(x))[0] == 0xFF)
+#define IS_NEG(x)	(((__u8*)(x))[0] == 0xFF)
 #define NEG_TIME(x)	(((x)[2]<<24)|((x)[3]<<16)|((x)[4]<<8)|(x)[5])
-#define NEG_AGE(x)	((__u32)time(NULL) - NEG_TIME((__u8 *)x))
+#define NEG_AGE(x)	((__u32)time(NULL) - NEG_TIME((__u8*)x))
 #define NEG_VALID(x)	(NEG_AGE(x) < negative_timeout)
-#define NEG_CNT(x)	(((__u8 *)(x))[1])
+#define NEG_CNT(x)	(((__u8*)(x))[1])
 
 struct rtnl_handle rth;
 
@@ -93,7 +96,8 @@
 static void usage(void)
 {
 	fprintf(stderr,
-		"Usage: arpd [ -lkh? ] [ -a N ] [ -b dbase ] [ -B number ] [ -f file ] [ -n time ] [-p interval ] [ -R rate ] [ interfaces ]\n");
+		"Usage: arpd [ -lkh? ] [ -a N ] [ -b dbase ] [ -B number ]"
+		" [ -f file ] [ -n time ] [-p interval ] [ -R rate ] [ interfaces ]\n");
 	exit(1);
 }
 
@@ -104,7 +108,7 @@
 	if (ifnum == 0)
 		return 1;
 
-	for (i = 0; i < ifnum; i++)
+	for (i=0; i<ifnum; i++)
 		if (ifvec[i] == ifindex)
 			return 1;
 	return 0;
@@ -119,7 +123,7 @@
 	if (!ifnum)
 		return;
 
-	for (i = 0; i < ifnum; i++) {
+	for (i=0; i<ifnum; i++) {
 		char buf[128];
 		FILE *fp;
 
@@ -129,7 +133,7 @@
 				if (no_kernel_broadcasts)
 					strcpy(buf, "0\n");
 				else
-					sprintf(buf, "%d\n", active_probing >= 2 ? 1 : 3-active_probing);
+					sprintf(buf, "%d\n", active_probing>=2 ? 1 : 3-active_probing);
 				fputs(buf, fp);
 				fclose(fp);
 			}
@@ -137,7 +141,7 @@
 
 		sprintf(buf, "/proc/sys/net/ipv4/neigh/%s/app_solicit", ifnames[i]);
 		if ((fp = fopen(buf, "w")) != NULL) {
-			sprintf(buf, "%d\n", active_probing <= 1 ? 1 : active_probing);
+			sprintf(buf, "%d\n", active_probing<=1 ? 1 : active_probing);
 			fputs(buf, fp);
 			fclose(fp);
 		}
@@ -152,7 +156,7 @@
 	if (!sysctl_adjusted)
 		return;
 
-	for (i = 0; i < ifnum; i++) {
+	for (i=0; i<ifnum; i++) {
 		char buf[128];
 		FILE *fp;
 
@@ -177,22 +181,16 @@
 
 static int send_probe(int ifindex, __u32 addr)
 {
-	struct ifreq ifr = { .ifr_ifindex = ifindex };
-	struct sockaddr_in dst = {
-		.sin_family = AF_INET,
-		.sin_port = htons(1025),
-		.sin_addr.s_addr = addr,
-	};
+	struct ifreq ifr;
+	struct sockaddr_in dst;
 	socklen_t len;
 	unsigned char buf[256];
-	struct arphdr *ah = (struct arphdr *)buf;
+	struct arphdr *ah = (struct arphdr*)buf;
 	unsigned char *p = (unsigned char *)(ah+1);
-	struct sockaddr_ll sll = {
-		.sll_family = AF_PACKET,
-		.sll_ifindex = ifindex,
-		.sll_protocol = htons(ETH_P_ARP),
-	};
+	struct sockaddr_ll sll;
 
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = ifindex;
 	if (ioctl(udp_sock, SIOCGIFNAME, &ifr))
 		return -1;
 	if (ioctl(udp_sock, SIOCGIFHWADDR, &ifr))
@@ -202,10 +200,13 @@
 	if (setsockopt(udp_sock, SOL_SOCKET, SO_BINDTODEVICE, ifr.ifr_name, strlen(ifr.ifr_name)+1) < 0)
 		return -1;
 
-	if (connect(udp_sock, (struct sockaddr *)&dst, sizeof(dst)) < 0)
+	dst.sin_family = AF_INET;
+	dst.sin_port = htons(1025);
+	dst.sin_addr.s_addr = addr;
+	if (connect(udp_sock, (struct sockaddr*)&dst, sizeof(dst)) < 0)
 		return -1;
 	len = sizeof(dst);
-	if (getsockname(udp_sock, (struct sockaddr *)&dst, &len) < 0)
+	if (getsockname(udp_sock, (struct sockaddr*)&dst, &len) < 0)
 		return -1;
 
 	ah->ar_hrd = htons(ifr.ifr_hwaddr.sa_family);
@@ -218,16 +219,19 @@
 	p += ah->ar_hln;
 
 	memcpy(p, &dst.sin_addr, 4);
-	p += 4;
+	p+=4;
 
+	sll.sll_family = AF_PACKET;
 	memset(sll.sll_addr, 0xFF, sizeof(sll.sll_addr));
+	sll.sll_ifindex = ifindex;
+	sll.sll_protocol = htons(ETH_P_ARP);
 	memcpy(p, &sll.sll_addr, ah->ar_hln);
-	p += ah->ar_hln;
+	p+=ah->ar_hln;
 
 	memcpy(p, &addr, 4);
-	p += 4;
+	p+=4;
 
-	if (sendto(pset[0].fd, buf, p-buf, 0, (struct sockaddr *)&sll, sizeof(sll)) < 0)
+	if (sendto(pset[0].fd, buf, p-buf, 0, (struct sockaddr*)&sll, sizeof(sll)) < 0)
 		return -1;
 	stats.probes_sent++;
 	return 0;
@@ -244,7 +248,6 @@
 	gettimeofday(&now, NULL);
 	if (prev.tv_sec) {
 		int diff = (now.tv_sec-prev.tv_sec)*1000+(now.tv_usec-prev.tv_usec)/1000;
-
 		buckets += diff;
 	} else {
 		buckets = broadcast_burst;
@@ -263,18 +266,21 @@
 static int respond_to_kernel(int ifindex, __u32 addr, char *lla, int llalen)
 {
 	struct {
-		struct nlmsghdr	n;
-		struct ndmsg		ndm;
-		char			buf[256];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST,
-		.n.nlmsg_type = RTM_NEWNEIGH,
-		.ndm.ndm_family = AF_INET,
-		.ndm.ndm_state = NUD_STALE,
-		.ndm.ndm_ifindex = ifindex,
-		.ndm.ndm_type = RTN_UNICAST,
-	};
+		struct nlmsghdr 	n;
+		struct ndmsg 		ndm;
+		char   			buf[256];
+	} req;
+
+	memset(&req.n, 0, sizeof(req.n));
+	memset(&req.ndm, 0, sizeof(req.ndm));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST;
+	req.n.nlmsg_type = RTM_NEWNEIGH;
+	req.ndm.ndm_family = AF_INET;
+	req.ndm.ndm_state = NUD_STALE;
+	req.ndm.ndm_ifindex = ifindex;
+	req.ndm.ndm_type = RTN_UNICAST;
 
 	addattr_l(&req.n, sizeof(req), NDA_DST, &addr, 4);
 	addattr_l(&req.n, sizeof(req), NDA_LLADDR, lla, llalen);
@@ -296,7 +302,7 @@
 {
 	struct ndmsg *ndm = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[NDA_MAX+1];
+	struct rtattr * tb[NDA_MAX+1];
 	struct dbkey key;
 	DBT dbkey, dbdat;
 	int do_acct = 0;
@@ -399,7 +405,6 @@
 			    !IS_NEG(dbdat.data) ||
 			    !NEG_VALID(dbdat.data)) {
 				__u8 ndata[6];
-
 				stats.kern_neg++;
 				prepare_neg_entry(ndata, time(NULL));
 				dbdat.data = ndata;
@@ -424,7 +429,7 @@
 
 static void load_initial_table(void)
 {
-	if (rtnl_neighdump_req(&rth, AF_INET, NULL) < 0) {
+	if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETNEIGH) < 0) {
 		perror("dump request failed");
 		exit(1);
 	}
@@ -435,16 +440,18 @@
 {
 	int status;
 	struct nlmsghdr *h;
-	struct sockaddr_nl nladdr = {};
+	struct sockaddr_nl nladdr;
 	struct iovec iov;
 	char   buf[8192];
 	struct msghdr msg = {
-		(void *)&nladdr, sizeof(nladdr),
+		(void*)&nladdr, sizeof(nladdr),
 		&iov,	1,
 		NULL,	0,
 		0
 	};
 
+	memset(&nladdr, 0, sizeof(nladdr));
+
 	iov.iov_base = buf;
 	iov.iov_len = sizeof(buf);
 
@@ -459,7 +466,7 @@
 	if (nladdr.nl_pid)
 		return;
 
-	for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) {
+	for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
 		int len = h->nlmsg_len;
 		int l = len - sizeof(*h);
 
@@ -470,7 +477,7 @@
 			return;
 
 		status -= NLMSG_ALIGN(len);
-		h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
+		h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
 	}
 }
 
@@ -480,13 +487,13 @@
 	unsigned char buf[1024];
 	struct sockaddr_ll sll;
 	socklen_t sll_len = sizeof(sll);
-	struct arphdr *a = (struct arphdr *)buf;
+	struct arphdr *a = (struct arphdr*)buf;
 	struct dbkey key;
 	DBT dbkey, dbdat;
 	int n;
 
 	n = recvfrom(pset[0].fd, buf, sizeof(buf), MSG_DONTWAIT,
-		     (struct sockaddr *)&sll, &sll_len);
+		     (struct sockaddr*)&sll, &sll_len);
 	if (n < 0) {
 		if (errno != EINTR && errno != EAGAIN)
 			syslog(LOG_ERR, "recvfrom: %m");
@@ -508,7 +515,7 @@
 		return;
 
 	key.iface = sll.sll_ifindex;
-	memcpy(&key.addr, (char *)(a+1) + a->ar_hln, 4);
+	memcpy(&key.addr, (char*)(a+1) + a->ar_hln, 4);
 
 	/* DAD message, ignore. */
 	if (key.addr == 0)
@@ -532,8 +539,10 @@
 
 static void catch_signal(int sig, void (*handler)(int))
 {
-	struct sigaction sa = { .sa_handler = handler };
+	struct sigaction sa;
 
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = handler;
 #ifdef SA_INTERRUPT
 	sa.sa_flags = SA_INTERRUPT;
 #endif
@@ -591,7 +600,7 @@
 
 	while ((opt = getopt(argc, argv, "h?b:lf:a:n:p:kR:B:")) != EOF) {
 		switch (opt) {
-		case 'b':
+	        case 'b':
 			dbname = optarg;
 			break;
 		case 'f':
@@ -615,7 +624,7 @@
 			break;
 		case 'p':
 			if ((poll_timeout = 1000 * strtod(optarg, NULL)) < 100) {
-				fprintf(stderr, "Invalid poll timeout\n");
+				fprintf(stderr,"Invalid poll timeout\n");
 				exit(-1);
 			}
 			break;
@@ -657,16 +666,15 @@
 		exit(-1);
 	}
 
-	if (ifnum) {
+        if (ifnum) {
 		int i;
-		struct ifreq ifr = {};
-
-		for (i = 0; i < ifnum; i++) {
-			if (get_ifname(ifr.ifr_name, ifnames[i]))
-				invarg("not a valid ifname", ifnames[i]);
+		struct ifreq ifr;
+		memset(&ifr, 0, sizeof(ifr));
+		for (i=0; i<ifnum; i++) {
+			strncpy(ifr.ifr_name, ifnames[i], IFNAMSIZ);
 			if (ioctl(udp_sock, SIOCGIFINDEX, &ifr)) {
 				perror("ioctl(SIOCGIFINDEX)");
-				exit(-1);
+				exit(-1);;
 			}
 			ifvec[i] = ifr.ifr_ifindex;
 		}
@@ -709,7 +717,7 @@
 			}
 			if (strncmp(macbuf, "FAILED:", 7) == 0)
 				continue;
-			if (!inet_aton(ipbuf, (struct in_addr *)&k.addr)) {
+			if (!inet_aton(ipbuf, (struct in_addr*)&k.addr)) {
 				fprintf(stderr, "Invalid IP address: \"%s\"\n", ipbuf);
 				goto do_abort;
 			}
@@ -730,23 +738,20 @@
 
 	if (do_list) {
 		DBT dbkey, dbdat;
-
 		printf("%-8s %-15s %s\n", "#Ifindex", "IP", "MAC");
 		while (dbase->seq(dbase, &dbkey, &dbdat, R_NEXT) == 0) {
 			struct dbkey *key = dbkey.data;
-
 			if (handle_if(key->iface)) {
 				if (!IS_NEG(dbdat.data)) {
 					char b1[18];
-
 					printf("%-8d %-15s %s\n",
 					       key->iface,
-					       inet_ntoa(*(struct in_addr *)&key->addr),
+					       inet_ntoa(*(struct in_addr*)&key->addr),
 					       ll_addr_n2a(dbdat.data, 6, ARPHRD_ETHER, b1, 18));
 				} else {
 					printf("%-8d %-15s FAILED: %dsec ago\n",
 					       key->iface,
-					       inet_ntoa(*(struct in_addr *)&key->addr),
+					       inet_ntoa(*(struct in_addr*)&key->addr),
 					       NEG_AGE(dbdat.data));
 				}
 			}
@@ -763,13 +768,12 @@
 	}
 
 	if (1) {
-		struct sockaddr_ll sll = {
-			.sll_family = AF_PACKET,
-			.sll_protocol = htons(ETH_P_ARP),
-			.sll_ifindex = (ifnum == 1 ? ifvec[0] : 0),
-		};
-
-		if (bind(pset[0].fd, (struct sockaddr *)&sll, sizeof(sll)) < 0) {
+		struct sockaddr_ll sll;
+		memset(&sll, 0, sizeof(sll));
+		sll.sll_family = AF_PACKET;
+		sll.sll_protocol = htons(ETH_P_ARP);
+		sll.sll_ifindex = (ifnum == 1 ? ifvec[0] : 0);
+		if (bind(pset[0].fd, (struct sockaddr*)&sll, sizeof(sll)) < 0) {
 			perror("bind");
 			goto do_abort;
 		}
diff --git a/misc/ifstat.c b/misc/ifstat.c
index 60efe6c..ac5c29c 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -28,41 +28,38 @@
 #include <math.h>
 #include <getopt.h>
 
+#include <libnetlink.h>
+#include <json_writer.h>
 #include <linux/if.h>
 #include <linux/if_link.h>
 
-#include "libnetlink.h"
-#include "json_writer.h"
-#include "SNAPSHOT.h"
-#include "utils.h"
+#include <SNAPSHOT.h>
 
-int dump_zeros;
-int reset_history;
-int ignore_history;
-int no_output;
-int json_output;
-int no_update;
-int scan_interval;
-int time_constant;
-int show_errors;
+int dump_zeros = 0;
+int reset_history = 0;
+int ignore_history = 0;
+int no_output = 0;
+int json_output = 0;
+int no_update = 0;
+int scan_interval = 0;
+int time_constant = 0;
+int show_errors = 0;
+int pretty;
 double W;
 char **patterns;
 int npatterns;
-bool is_extended;
-int filter_type;
-int sub_type;
 
 char info_source[128];
 int source_mismatch;
 
 #define MAXS (sizeof(struct rtnl_link_stats)/sizeof(__u32))
-#define NO_SUB_TYPE 0xffff
 
-struct ifstat_ent {
+struct ifstat_ent
+{
 	struct ifstat_ent	*next;
 	char			*name;
 	int			ifindex;
-	__u64			val[MAXS];
+	unsigned long long	val[MAXS];
 	double			rate[MAXS];
 	__u32			ival[MAXS];
 };
@@ -103,60 +100,18 @@
 	if (npatterns == 0)
 		return 1;
 
-	for (i = 0; i < npatterns; i++) {
+	for (i=0; i<npatterns; i++) {
 		if (!fnmatch(patterns[i], id, 0))
 			return 1;
 	}
 	return 0;
 }
 
-static int get_nlmsg_extended(struct nlmsghdr *m, void *arg)
-{
-	struct if_stats_msg *ifsm = NLMSG_DATA(m);
-	struct rtattr *tb[IFLA_STATS_MAX+1];
-	int len = m->nlmsg_len;
-	struct ifstat_ent *n;
-
-	if (m->nlmsg_type != RTM_NEWSTATS)
-		return 0;
-
-	len -= NLMSG_LENGTH(sizeof(*ifsm));
-	if (len < 0)
-		return -1;
-
-	parse_rtattr(tb, IFLA_STATS_MAX, IFLA_STATS_RTA(ifsm), len);
-	if (tb[filter_type] == NULL)
-		return 0;
-
-	n = malloc(sizeof(*n));
-	if (!n)
-		abort();
-
-	n->ifindex = ifsm->ifindex;
-	n->name = strdup(ll_index_to_name(ifsm->ifindex));
-
-	if (sub_type == NO_SUB_TYPE) {
-		memcpy(&n->val, RTA_DATA(tb[filter_type]), sizeof(n->val));
-	} else {
-		struct rtattr *attr;
-
-		attr = parse_rtattr_one_nested(sub_type, tb[filter_type]);
-		if (attr == NULL) {
-			free(n);
-			return 0;
-		}
-		memcpy(&n->val, RTA_DATA(attr), sizeof(n->val));
-	}
-	memset(&n->rate, 0, sizeof(n->rate));
-	n->next = kern_db;
-	kern_db = n;
-	return 0;
-}
-
-static int get_nlmsg(struct nlmsghdr *m, void *arg)
+static int get_nlmsg(const struct sockaddr_nl *who,
+		     struct nlmsghdr *m, void *arg)
 {
 	struct ifinfomsg *ifi = NLMSG_DATA(m);
-	struct rtattr *tb[IFLA_MAX+1];
+	struct rtattr * tb[IFLA_MAX+1];
 	int len = m->nlmsg_len;
 	struct ifstat_ent *n;
 	int i;
@@ -182,7 +137,7 @@
 	n->name = strdup(RTA_DATA(tb[IFLA_IFNAME]));
 	memcpy(&n->ival, RTA_DATA(tb[IFLA_STATS]), sizeof(n->ival));
 	memset(&n->rate, 0, sizeof(n->rate));
-	for (i = 0; i < MAXS; i++)
+	for (i=0; i<MAXS; i++)
 		n->val[i] = n->ival[i];
 	n->next = kern_db;
 	kern_db = n;
@@ -193,34 +148,18 @@
 {
 	struct ifstat_ent *db, *n;
 	struct rtnl_handle rth;
-	__u32 filter_mask;
 
 	if (rtnl_open(&rth, 0) < 0)
 		exit(1);
 
-	if (is_extended) {
-		ll_init_map(&rth);
-		filter_mask = IFLA_STATS_FILTER_BIT(filter_type);
-		if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC,
-					      filter_mask) < 0) {
-			perror("Cannot send dump request");
-			exit(1);
-		}
+	if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETLINK) < 0) {
+		perror("Cannot send dump request");
+		exit(1);
+	}
 
-		if (rtnl_dump_filter(&rth, get_nlmsg_extended, NULL) < 0) {
-			fprintf(stderr, "Dump terminated\n");
-			exit(1);
-		}
-	} else {
-		if (rtnl_linkdump_req(&rth, AF_INET) < 0) {
-			perror("Cannot send dump request");
-			exit(1);
-		}
-
-		if (rtnl_dump_filter(&rth, get_nlmsg, NULL) < 0) {
-			fprintf(stderr, "Dump terminated\n");
-			exit(1);
-		}
+	if (rtnl_dump_filter(&rth, get_nlmsg, NULL) < 0) {
+		fprintf(stderr, "Dump terminated\n");
+		exit(1);
 	}
 
 	rtnl_close(&rth);
@@ -270,9 +209,8 @@
 		n->name = strdup(p);
 		p = next;
 
-		for (i = 0; i < MAXS; i++) {
-			unsigned int rate;
-
+		for (i=0; i<MAXS; i++) {
+			unsigned rate;
 			if (!(next = strchr(p, ' ')))
 				abort();
 			*next++ = 0;
@@ -307,21 +245,18 @@
 
 	h = hist_db;
 	if (jw) {
-		jsonw_start_object(jw);
 		jsonw_pretty(jw, pretty);
 		jsonw_name(jw, info_source);
 		jsonw_start_object(jw);
 	} else
 		fprintf(fp, "#%s\n", info_source);
 
-	for (n = kern_db; n; n = n->next) {
+	for (n=kern_db; n; n=n->next) {
 		int i;
 		unsigned long long *vals = n->val;
 		double *rates = n->rate;
-
 		if (!match(n->name)) {
 			struct ifstat_ent *h1;
-
 			if (!to_hist)
 				continue;
 			for (h1 = h; h1; h1 = h1->next) {
@@ -338,21 +273,19 @@
 			jsonw_name(jw, n->name);
 			jsonw_start_object(jw);
 
-			for (i = 0; i < MAXS && stats[i]; i++)
+			for (i=0; i<MAXS && stats[i]; i++)
 				jsonw_uint_field(jw, stats[i], vals[i]);
 			jsonw_end_object(jw);
 		} else {
 			fprintf(fp, "%d %s ", n->ifindex, n->name);
-			for (i = 0; i < MAXS; i++)
+			for (i=0; i<MAXS; i++)
 				fprintf(fp, "%llu %u ", vals[i],
-					(unsigned int)rates[i]);
+					(unsigned)rates[i]);
 			fprintf(fp, "\n");
 		}
 	}
 	if (jw) {
 		jsonw_end_object(jw);
-
-		jsonw_end_object(jw);
 		jsonw_destroy(&jw);
 	}
 }
@@ -375,19 +308,18 @@
 		fprintf(fp, "%8llu ", vals[i]);
 
 	if (rates[i] > mega) {
-		sprintf(temp, "%uM", (unsigned int)(rates[i]/mega));
+		sprintf(temp, "%uM", (unsigned)(rates[i]/mega));
 		fprintf(fp, "%-6s ", temp);
 	} else if (rates[i] > kilo) {
-		sprintf(temp, "%uK", (unsigned int)(rates[i]/kilo));
+		sprintf(temp, "%uK", (unsigned)(rates[i]/kilo));
 		fprintf(fp, "%-6s ", temp);
 	} else
-		fprintf(fp, "%-6u ", (unsigned int)rates[i]);
+		fprintf(fp, "%-6u ", (unsigned)rates[i]);
 }
 
 static void format_pair(FILE *fp, const unsigned long long *vals, int i, int k)
 {
 	char temp[64];
-
 	if (vals[i] > giga)
 		fprintf(fp, "%7lluM ", vals[i]/mega);
 	else if (vals[i] > mega)
@@ -396,13 +328,13 @@
 		fprintf(fp, "%8llu ", vals[i]);
 
 	if (vals[k] > giga) {
-		sprintf(temp, "%uM", (unsigned int)(vals[k]/mega));
+		sprintf(temp, "%uM", (unsigned)(vals[k]/mega));
 		fprintf(fp, "%-6s ", temp);
 	} else if (vals[k] > mega) {
-		sprintf(temp, "%uK", (unsigned int)(vals[k]/kilo));
+		sprintf(temp, "%uK", (unsigned)(vals[k]/kilo));
 		fprintf(fp, "%-6s ", temp);
 	} else
-		fprintf(fp, "%-6u ", (unsigned int)vals[k]);
+		fprintf(fp, "%-6u ", (unsigned)vals[k]);
 }
 
 static void print_head(FILE *fp)
@@ -413,38 +345,38 @@
 	fprintf(fp, "%8s/%-6s ", "RX Pkts", "Rate");
 	fprintf(fp, "%8s/%-6s ", "TX Pkts", "Rate");
 	fprintf(fp, "%8s/%-6s ", "RX Data", "Rate");
-	fprintf(fp, "%8s/%-6s\n", "TX Data", "Rate");
+	fprintf(fp, "%8s/%-6s\n","TX Data", "Rate");
 
 	if (!show_errors) {
 		fprintf(fp, "%-15s ", "");
 		fprintf(fp, "%8s/%-6s ", "RX Errs", "Drop");
 		fprintf(fp, "%8s/%-6s ", "TX Errs", "Drop");
 		fprintf(fp, "%8s/%-6s ", "RX Over", "Rate");
-		fprintf(fp, "%8s/%-6s\n", "TX Coll", "Rate");
+		fprintf(fp, "%8s/%-6s\n","TX Coll", "Rate");
 	} else {
 		fprintf(fp, "%-15s ", "");
 		fprintf(fp, "%8s/%-6s ", "RX Errs", "Rate");
 		fprintf(fp, "%8s/%-6s ", "RX Drop", "Rate");
 		fprintf(fp, "%8s/%-6s ", "RX Over", "Rate");
-		fprintf(fp, "%8s/%-6s\n", "RX Leng", "Rate");
+		fprintf(fp, "%8s/%-6s\n","RX Leng", "Rate");
 
 		fprintf(fp, "%-15s ", "");
 		fprintf(fp, "%8s/%-6s ", "RX Crc", "Rate");
 		fprintf(fp, "%8s/%-6s ", "RX Frm", "Rate");
 		fprintf(fp, "%8s/%-6s ", "RX Fifo", "Rate");
-		fprintf(fp, "%8s/%-6s\n", "RX Miss", "Rate");
+		fprintf(fp, "%8s/%-6s\n","RX Miss", "Rate");
 
 		fprintf(fp, "%-15s ", "");
 		fprintf(fp, "%8s/%-6s ", "TX Errs", "Rate");
 		fprintf(fp, "%8s/%-6s ", "TX Drop", "Rate");
 		fprintf(fp, "%8s/%-6s ", "TX Coll", "Rate");
-		fprintf(fp, "%8s/%-6s\n", "TX Carr", "Rate");
+		fprintf(fp, "%8s/%-6s\n","TX Carr", "Rate");
 
 		fprintf(fp, "%-15s ", "");
 		fprintf(fp, "%8s/%-6s ", "TX Abrt", "Rate");
 		fprintf(fp, "%8s/%-6s ", "TX Fifo", "Rate");
 		fprintf(fp, "%8s/%-6s ", "TX Hear", "Rate");
-		fprintf(fp, "%8s/%-6s\n", "TX Wind", "Rate");
+		fprintf(fp, "%8s/%-6s\n","TX Wind", "Rate");
 	}
 }
 
@@ -456,7 +388,7 @@
 	jsonw_name(jw, n->name);
 	jsonw_start_object(jw);
 
-	for (i = 0; i < m && stats[i]; i++)
+	for (i=0; i < m && stats[i]; i++)
 		jsonw_uint_field(jw, stats[i], vals[i]);
 
 	jsonw_end_object(jw);
@@ -468,7 +400,7 @@
 	int i;
 
 	fprintf(fp, "%-15s ", n->name);
-	for (i = 0; i < 4; i++)
+	for (i=0; i<4; i++)
 		format_rate(fp, vals, n->rate, i);
 	fprintf(fp, "\n");
 
@@ -516,14 +448,13 @@
 	struct ifstat_ent *n;
 
 	if (jw) {
-		jsonw_start_object(jw);
 		jsonw_pretty(jw, pretty);
 		jsonw_name(jw, info_source);
 		jsonw_start_object(jw);
 	} else
 		print_head(fp);
 
-	for (n = kern_db; n; n = n->next) {
+	for (n=kern_db; n; n=n->next) {
 		if (!match(n->name))
 			continue;
 
@@ -532,12 +463,8 @@
 		else
 			print_one_if(fp, n, n->val);
 	}
-	if (jw) {
-		jsonw_end_object(jw);
-
-		jsonw_end_object(jw);
-		jsonw_destroy(&jw);
-	}
+	if (json_output)
+		fprintf(fp, "\n} }\n");
 }
 
 static void dump_incr_db(FILE *fp)
@@ -547,14 +474,13 @@
 
 	h = hist_db;
 	if (jw) {
-		jsonw_start_object(jw);
 		jsonw_pretty(jw, pretty);
 		jsonw_name(jw, info_source);
 		jsonw_start_object(jw);
 	} else
 		print_head(fp);
 
-	for (n = kern_db; n; n = n->next) {
+	for (n=kern_db; n; n=n->next) {
 		int i;
 		unsigned long long vals[MAXS];
 		struct ifstat_ent *h1;
@@ -580,8 +506,6 @@
 
 	if (jw) {
 		jsonw_end_object(jw);
-
-		jsonw_end_object(jw);
 		jsonw_destroy(&jw);
 	}
 }
@@ -606,11 +530,9 @@
 
 	for (n = kern_db; n; n = n->next) {
 		struct ifstat_ent *h1;
-
 		for (h1 = h; h1; h1 = h1->next) {
 			if (h1->ifindex == n->ifindex) {
 				int i;
-
 				for (i = 0; i < MAXS; i++) {
 					if ((long)(h1->ival[i] - n->ival[i]) < 0) {
 						memset(n->ival, 0, sizeof(n->ival));
@@ -619,17 +541,9 @@
 				}
 				for (i = 0; i < MAXS; i++) {
 					double sample;
-					__u64 incr;
-
-					if (is_extended) {
-						incr = h1->val[i] - n->val[i];
-						n->val[i] = h1->val[i];
-					} else {
-						incr = (__u32) (h1->ival[i] - n->ival[i]);
-						n->val[i] += incr;
-						n->ival[i] = h1->ival[i];
-					}
-
+					unsigned long incr = h1->ival[i] - n->ival[i];
+					n->val[i] += incr;
+					n->ival[i] = h1->ival[i];
 					sample = (double)(incr*1000)/interval;
 					if (interval >= scan_interval) {
 						n->rate[i] += W*(sample-n->rate[i]);
@@ -638,7 +552,6 @@
 							n->rate[i] = sample;
 						} else {
 							double w = W*(double)interval/scan_interval;
-
 							n->rate[i] += w*(sample-n->rate[i]);
 						}
 					}
@@ -646,7 +559,6 @@
 
 				while (h != h1) {
 					struct ifstat_ent *tmp = h;
-
 					h = h->next;
 					free(tmp->name);
 					free(tmp);
@@ -660,14 +572,13 @@
 	}
 }
 
-#define T_DIFF(a, b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
+#define T_DIFF(a,b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
 
 
 static void server_loop(int fd)
 {
 	struct timeval snaptime = { 0 };
 	struct pollfd p;
-
 	p.fd = fd;
 	p.events = p.revents = POLLIN;
 
@@ -678,7 +589,7 @@
 
 	for (;;) {
 		int status;
-		time_t tdiff;
+		int tdiff;
 		struct timeval now;
 
 		gettimeofday(&now, NULL);
@@ -689,24 +600,24 @@
 			tdiff = 0;
 		}
 
-		if (poll(&p, 1, scan_interval - tdiff) > 0
+		if (poll(&p, 1, tdiff + scan_interval) > 0
 		    && (p.revents&POLLIN)) {
 			int clnt = accept(fd, NULL, NULL);
-
 			if (clnt >= 0) {
 				pid_t pid;
-
 				if (children >= 5) {
 					close(clnt);
 				} else if ((pid = fork()) != 0) {
-					if (pid > 0)
+					if (pid>0)
 						children++;
 					close(clnt);
 				} else {
 					FILE *fp = fdopen(clnt, "w");
-
-					if (fp)
+					if (fp) {
+						if (tdiff > 0)
+							update_db(tdiff);
 						dump_raw_db(fp, 0);
+					}
 					exit(0);
 				}
 			}
@@ -721,7 +632,7 @@
 	struct ucred cred;
 	socklen_t olen = sizeof(cred);
 
-	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &olen) ||
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void*)&cred, &olen) ||
 	    olen < sizeof(cred))
 		return -1;
 	if (cred.uid == getuid() || cred.uid == 0)
@@ -729,68 +640,24 @@
 	return -1;
 }
 
-static void xstat_usage(void)
-{
-	fprintf(stderr,
-"Usage: ifstat supported xstats:\n"
-"       cpu_hits       Counts only packets that went via the CPU.\n");
-}
-
-struct extended_stats_options_t {
-	char *name;
-	int id;
-	int sub_type;
-};
-
-/* Note: if one xstat name is subset of another, it should be before it in this
- * list.
- * Name length must be under 64 chars.
- */
-static const struct extended_stats_options_t extended_stats_options[] = {
-	{"cpu_hits",  IFLA_STATS_LINK_OFFLOAD_XSTATS, IFLA_OFFLOAD_XSTATS_CPU_HIT},
-};
-
-static const char *get_filter_type(const char *name)
-{
-	int name_len;
-	int i;
-
-	name_len = strlen(name);
-	for (i = 0; i < ARRAY_SIZE(extended_stats_options); i++) {
-		const struct extended_stats_options_t *xstat;
-
-		xstat = &extended_stats_options[i];
-		if (strncmp(name, xstat->name, name_len) == 0) {
-			filter_type = xstat->id;
-			sub_type = xstat->sub_type;
-			return xstat->name;
-		}
-	}
-
-	fprintf(stderr, "invalid ifstat extension %s\n", name);
-	xstat_usage();
-	return NULL;
-}
-
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
 	fprintf(stderr,
 "Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
-"   -h, --help           this message\n"
-"   -a, --ignore         ignore history\n"
-"   -d, --scan=SECS      sample every statistics every SECS\n"
-"   -e, --errors         show errors\n"
-"   -j, --json           format output in JSON\n"
-"   -n, --nooutput       do history only\n"
-"   -p, --pretty         pretty print\n"
-"   -r, --reset          reset history\n"
-"   -s, --noupdate       don't update history\n"
-"   -t, --interval=SECS  report average over the last SECS\n"
-"   -V, --version        output version information\n"
-"   -z, --zeros          show entries with zero activity\n"
-"   -x, --extended=TYPE  show extended stats of TYPE\n");
+"   -h, --help		this message\n"
+"   -a, --ignore	ignore history\n"
+"   -d, --scan=SECS	sample every statistics every SECS\n"
+"   -e, --errors	show errors\n"
+"   -j, --json          format output in JSON\n"
+"   -n, --nooutput	do history only\n"
+"   -p, --pretty        pretty print\n"
+"   -r, --reset		reset history\n"
+"   -s, --noupdate	don\'t update history\n"
+"   -t, --interval=SECS	report average over the last SECS\n"
+"   -V, --version	output version information\n"
+"   -z, --zeros		show entries with zero activity\n");
 
 	exit(-1);
 }
@@ -808,7 +675,6 @@
 	{ "interval", 1, 0, 't' },
 	{ "version", 0, 0, 'V' },
 	{ "zeros", 0, 0, 'z' },
-	{ "extended", 1, 0, 'x'},
 	{ 0 }
 };
 
@@ -817,14 +683,12 @@
 	char hist_name[128];
 	struct sockaddr_un sun;
 	FILE *hist_fp = NULL;
-	const char *stats_type = NULL;
 	int ch;
 	int fd;
 
-	is_extended = false;
-	while ((ch = getopt_long(argc, argv, "hjpvVzrnasd:t:ex:",
+	while ((ch = getopt_long(argc, argv, "hjpvVzrnasd:t:e",
 			longopts, NULL)) != EOF) {
-		switch (ch) {
+		switch(ch) {
 		case 'z':
 			dump_zeros = 1;
 			break;
@@ -863,10 +727,6 @@
 				exit(-1);
 			}
 			break;
-		case 'x':
-			stats_type = optarg;
-			is_extended = true;
-			break;
 		case 'v':
 		case 'V':
 			printf("ifstat utility, iproute2-ss%s\n", SNAPSHOT);
@@ -881,12 +741,6 @@
 	argc -= optind;
 	argv += optind;
 
-	if (stats_type) {
-		stats_type = get_filter_type(stats_type);
-		if (!stats_type)
-			exit(-1);
-	}
-
 	sun.sun_family = AF_UNIX;
 	sun.sun_path[0] = 0;
 	sprintf(sun.sun_path+1, "ifstat%d", getuid());
@@ -900,7 +754,7 @@
 			perror("ifstat: socket");
 			exit(-1);
 		}
-		if (bind(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
+		if (bind(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
 			perror("ifstat: bind");
 			exit(-1);
 		}
@@ -925,13 +779,8 @@
 		snprintf(hist_name, sizeof(hist_name),
 			 "%s", getenv("IFSTAT_HISTORY"));
 	else
-		if (!stats_type)
-			snprintf(hist_name, sizeof(hist_name),
-				 "%s/.ifstat.u%d", P_tmpdir, getuid());
-		else
-			snprintf(hist_name, sizeof(hist_name),
-				 "%s/.%s_ifstat.u%d", P_tmpdir, stats_type,
-				 getuid());
+		snprintf(hist_name, sizeof(hist_name),
+			 "%s/.ifstat.u%d", P_tmpdir, getuid());
 
 	if (reset_history)
 		unlink(hist_name);
@@ -963,7 +812,6 @@
 		if (!ignore_history) {
 			FILE *tfp;
 			long uptime = -1;
-
 			if ((tfp = fopen("/proc/uptime", "r")) != NULL) {
 				if (fscanf(tfp, "%ld", &uptime) != 1)
 					uptime = -1;
@@ -983,24 +831,17 @@
 	}
 
 	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 &&
-	    (connect(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) == 0
+	    (connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0
 	     || (strcpy(sun.sun_path+1, "ifstat0"),
-		 connect(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
+		 connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
 	    && verify_forging(fd) == 0) {
 		FILE *sfp = fdopen(fd, "r");
-
-		if (!sfp) {
-			fprintf(stderr, "ifstat: fdopen failed: %s\n",
-				strerror(errno));
-			close(fd);
-		} else  {
-			load_raw_table(sfp);
-			if (hist_db && source_mismatch) {
-				fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
-				hist_db = NULL;
-			}
-			fclose(sfp);
+		load_raw_table(sfp);
+		if (hist_db && source_mismatch) {
+			fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
+			hist_db = NULL;
 		}
+		fclose(sfp);
 	} else {
 		if (fd >= 0)
 			close(fd);
diff --git a/misc/lnstat.c b/misc/lnstat.c
index e3c8421..264c953 100644
--- a/misc/lnstat.c
+++ b/misc/lnstat.c
@@ -55,31 +55,30 @@
 
 static int usage(char *name, int exit_code)
 {
-	fprintf(stderr,
-		"%s Version %s\n"
-		"Copyright (C) 2004 by Harald Welte <laforge@gnumonks.org>\n"
-		"This program is free software licensed under GNU GPLv2\nwith ABSOLUTELY NO WARRANTY.\n"
-		"\n"
-		"Parameters:\n"
-		"	-V --version		Print Version of Program\n"
-		"	-c --count <count>	"
-		"Print <count> number of intervals\n"
-		"	-d --dump		"
-		"Dump list of available files/keys\n"
-		"	-j --json		"
-		"Display in JSON format\n"
-		"	-f --file <file>	Statistics file to use\n"
-		"	-h --help		This help message\n"
-		"	-i --interval <intv>	"
-		"Set interval to 'intv' seconds\n"
-		"	-k --keys k,k,k,...	Display only keys specified\n"
-		"	-s --subject [0-2]	Control header printing:\n"
-		"				0 = never\n"
-		"				1 = once\n"
-		"				2 = every 20 lines (default))\n"
-		"	-w --width n,n,n,...	Width for each field\n"
-		"\n",
-		name, LNSTAT_VERSION);
+	fprintf(stderr, "%s Version %s\n", name, LNSTAT_VERSION);
+	fprintf(stderr, "Copyright (C) 2004 by Harald Welte "
+			"<laforge@gnumonks.org>\n");
+	fprintf(stderr, "This program is free software licensed under GNU GPLv2"
+			"\nwith ABSOLUTELY NO WARRANTY.\n\n");
+	fprintf(stderr, "Parameters:\n");
+	fprintf(stderr, "\t-V --version\t\tPrint Version of Program\n");
+	fprintf(stderr, "\t-c --count <count>\t"
+			"Print <count> number of intervals\n");
+	fprintf(stderr, "\t-d --dump\t\t"
+			"Dump list of available files/keys\n");
+	fprintf(stderr, "\t-j --json\t\t"
+			"Display in JSON format\n");
+	fprintf(stderr, "\t-f --file <file>\tStatistics file to use\n");
+	fprintf(stderr, "\t-h --help\t\tThis help message\n");
+	fprintf(stderr, "\t-i --interval <intv>\t"
+			"Set interval to 'intv' seconds\n");
+	fprintf(stderr, "\t-k --keys k,k,k,...\tDisplay only keys specified\n");
+	fprintf(stderr, "\t-s --subject [0-2]\tControl header printing:\n");
+	fprintf(stderr, "\t\t\t\t0 = never\n");
+	fprintf(stderr, "\t\t\t\t1 = once\n");
+	fprintf(stderr, "\t\t\t\t2 = every 20 lines (default))\n");
+	fprintf(stderr, "\t-w --width n,n,n,...\tWidth for each field\n");
+	fprintf(stderr, "\n");
 
 	exit(exit_code);
 }
@@ -146,13 +145,14 @@
 
 				if (++j >= MAX_FIELDS - 1) {
 					fprintf(stderr,
-						"WARN: MAX_FIELDS (%d) reached, truncating number of keys\n",
+						"WARN: MAX_FIELDS (%d) reached,"
+						" truncating number of keys\n",
 						MAX_FIELDS);
 					goto full;
 				}
 			}
 		}
-full:
+	full:
 		fps->num = j;
 		return 1;
 	}
@@ -181,12 +181,14 @@
 					  struct field_params *fps,
 					  int linewidth)
 {
-	int h, i;
+	int h,i;
 	static struct table_hdr th;
 	int ofs = 0;
 
-	for (i = 0; i < HDR_LINES; i++)
-		th.hdr[i] = calloc(1, HDR_LINE_LENGTH);
+	for (i = 0; i < HDR_LINES; i++) {
+		th.hdr[i] = malloc(HDR_LINE_LENGTH);
+		memset(th.hdr[i], 0, HDR_LINE_LENGTH);
+	}
 
 	for (i = 0; i < fps->num; i++) {
 		char *cname, *fname = fps->params[i].lf->name;
@@ -267,7 +269,7 @@
 		num_req_files = 1;
 	}
 
-	while ((c = getopt_long(argc, argv, "Vc:djpf:h?i:k:s:w:",
+	while ((c = getopt_long(argc, argv,"Vc:djpf:h?i:k:s:w:",
 				opts, NULL)) != -1) {
 		int len = 0;
 		char *tmp, *tok;
@@ -301,7 +303,8 @@
 			     tok = strtok(NULL, ",")) {
 				if (fp.num >= MAX_FIELDS) {
 					fprintf(stderr,
-						"WARN: too many keys requested: (%d max)\n",
+						"WARN: too many keys"
+						" requested: (%d max)\n",
 						MAX_FIELDS);
 					break;
 				}
@@ -353,7 +356,7 @@
 		if (!header)
 			exit(1);
 
-		if (interval < 1)
+		if (interval < 1 )
 			interval = 1;
 
 		for (i = 0; i < count || !count; i++) {
diff --git a/misc/lnstat.h b/misc/lnstat.h
index 199eb54..83dad97 100644
--- a/misc/lnstat.h
+++ b/misc/lnstat.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _LNSTAT_H
 #define _LNSTAT_H
 
diff --git a/misc/lnstat_util.c b/misc/lnstat_util.c
index c2dc42e..a258366 100644
--- a/misc/lnstat_util.c
+++ b/misc/lnstat_util.c
@@ -49,7 +49,7 @@
 	if (!lf->compat && !fgets(buf, sizeof(buf)-1, lf->fp))
 		return -1;
 
-	while (!feof(lf->fp) && fgets(buf, sizeof(buf)-1, lf->fp)) {
+	while(!feof(lf->fp) && fgets(buf, sizeof(buf)-1, lf->fp)) {
 		char *ptr = buf;
 
 		num_lines++;
@@ -58,7 +58,6 @@
 
 		for (j = 0; j < lf->num_fields; j++) {
 			unsigned long f = strtoul(ptr, &ptr, 16);
-
 			if (j == 0)
 				lf->fields[j].values[i] = f;
 			else
@@ -103,7 +102,7 @@
 					lfi->result = lfi->values[1];
 				else
 					lfi->result = (lfi->values[1]-lfi->values[0])
-							/ lf->interval.tv_sec;
+				    			/ lf->interval.tv_sec;
 			}
 
 			scan_lines(lf, 0);
@@ -150,8 +149,7 @@
 {
 	char buf[FGETS_BUF_SIZE];
 
-	strncpy(buf, RTSTAT_COMPAT_LINE, sizeof(buf) - 1);
-	buf[sizeof(buf) - 1] = '\0';
+	strncpy(buf, RTSTAT_COMPAT_LINE, sizeof(buf)-1);
 
 	return __lnstat_scan_fields(lf, buf);
 }
@@ -160,7 +158,6 @@
 static int name_in_array(const int num, const char **arr, const char *name)
 {
 	int i;
-
 	for (i = 0; i < num; i++) {
 		if (!strcmp(arr[i], name))
 			return 1;
@@ -174,15 +171,20 @@
 	struct lnstat_file *lf;
 
 	/* allocate */
-	lf = calloc(1, sizeof(*lf));
+	lf = malloc(sizeof(*lf));
 	if (!lf) {
 		fprintf(stderr, "out of memory\n");
 		return NULL;
 	}
 
 	/* initialize */
-	snprintf(lf->basename, sizeof(lf->basename), "%s", file);
-	snprintf(lf->path, sizeof(lf->path), "%s/%s", path, file);
+	memset(lf, 0, sizeof(*lf));
+
+	/* de->d_name is guaranteed to be <= NAME_MAX */
+	strcpy(lf->basename, file);
+	strcpy(lf->path, path);
+	strcat(lf->path, "/");
+	strcat(lf->path, lf->basename);
 
 	/* initialize to default */
 	lf->interval.tv_sec = 1;
diff --git a/misc/nstat.c b/misc/nstat.c
index 23113b2..9970528 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -30,16 +30,16 @@
 
 #include <json_writer.h>
 #include <SNAPSHOT.h>
-#include "utils.h"
 
-int dump_zeros;
-int reset_history;
-int ignore_history;
-int no_output;
-int json_output;
-int no_update;
-int scan_interval;
-int time_constant;
+int dump_zeros = 0;
+int reset_history = 0;
+int ignore_history = 0;
+int no_output = 0;
+int json_output = 0;
+int pretty = 0;
+int no_update = 0;
+int scan_interval = 0;
+int time_constant = 0;
 double W;
 char **patterns;
 int npatterns;
@@ -51,7 +51,6 @@
 {
 	char store[128];
 	char *p = getenv(env);
-
 	if (!p) {
 		p = getenv("PROC_ROOT") ? : "/proc";
 		snprintf(store, sizeof(store)-1, "%s/%s", p, name);
@@ -75,12 +74,8 @@
 	return generic_proc_open("PROC_NET_SNMP6", "net/snmp6");
 }
 
-static int net_sctp_snmp_open(void)
+struct nstat_ent
 {
-	return generic_proc_open("PROC_NET_SCTP_SNMP", "net/sctp/snmp");
-}
-
-struct nstat_ent {
 	struct nstat_ent *next;
 	char		 *id;
 	unsigned long long val;
@@ -99,8 +94,7 @@
 static int useless_number(const char *id)
 {
 	int i;
-
-	for (i = 0; i < ARRAY_SIZE(useless_numbers); i++)
+	for (i=0; i<sizeof(useless_numbers)/sizeof(*useless_numbers); i++)
 		if (strcmp(id, useless_numbers[i]) == 0)
 			return 1;
 	return 0;
@@ -113,7 +107,7 @@
 	if (npatterns == 0)
 		return 1;
 
-	for (i = 0; i < npatterns; i++) {
+	for (i=0; i<npatterns; i++) {
 		if (!fnmatch(patterns[i], id, 0))
 			return 1;
 	}
@@ -131,7 +125,6 @@
 		unsigned long long val;
 		double rate;
 		char idbuf[sizeof(buf)];
-
 		if (buf[0] == '#') {
 			buf[strlen(buf)-1] = 0;
 			if (info_source[0] && strcmp(info_source, buf+1))
@@ -177,14 +170,12 @@
 
 static void load_ugly_table(FILE *fp)
 {
-	char *buf = NULL;
-	size_t buflen = 0;
-	ssize_t nread;
+	char buf[4096];
 	struct nstat_ent *db = NULL;
 	struct nstat_ent *n;
 
-	while ((nread = getline(&buf, &buflen, fp)) != -1) {
-		char idbuf[4096];
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
+		char idbuf[sizeof(buf)];
 		int  off;
 		char *p;
 		int count1, count2, skip = 0;
@@ -201,7 +192,6 @@
 
 		while (*p) {
 			char *next;
-
 			if ((next = strchr(p, ' ')) != NULL)
 				*next++ = 0;
 			else if ((next = strchr(p, '\n')) != NULL)
@@ -220,8 +210,7 @@
 			p = next;
 		}
 		n = db;
-		nread = getline(&buf, &buflen, fp);
-		if (nread == -1)
+		if (fgets(buf, sizeof(buf), fp) == NULL)
 			abort();
 		count2 = count_spaces(buf);
 		if (count2 > count1)
@@ -240,7 +229,6 @@
 				n = n->next;
 		} while (p > buf + off + 2);
 	}
-	free(buf);
 
 	while (db) {
 		n = db;
@@ -255,20 +243,9 @@
 	}
 }
 
-static void load_sctp_snmp(void)
-{
-	FILE *fp = fdopen(net_sctp_snmp_open(), "r");
-
-	if (fp) {
-		load_good_table(fp);
-		fclose(fp);
-	}
-}
-
 static void load_snmp(void)
 {
 	FILE *fp = fdopen(net_snmp_open(), "r");
-
 	if (fp) {
 		load_ugly_table(fp);
 		fclose(fp);
@@ -278,7 +255,6 @@
 static void load_snmp6(void)
 {
 	FILE *fp = fdopen(net_snmp6_open(), "r");
-
 	if (fp) {
 		load_good_table(fp);
 		fclose(fp);
@@ -288,7 +264,6 @@
 static void load_netstat(void)
 {
 	FILE *fp = fdopen(net_netstat_open(), "r");
-
 	if (fp) {
 		load_ugly_table(fp);
 		fclose(fp);
@@ -303,21 +278,18 @@
 
 	h = hist_db;
 	if (jw) {
-		jsonw_start_object(jw);
 		jsonw_pretty(jw, pretty);
 		jsonw_name(jw, info_source);
 		jsonw_start_object(jw);
 	} else
 		fprintf(fp, "#%s\n", info_source);
 
-	for (n = kern_db; n; n = n->next) {
+	for (n=kern_db; n; n=n->next) {
 		unsigned long long val = n->val;
-
 		if (!dump_zeros && !val && !n->rate)
 			continue;
 		if (!match(n->id)) {
 			struct nstat_ent *h1;
-
 			if (!to_hist)
 				continue;
 			for (h1 = h; h1; h1 = h1->next) {
@@ -337,8 +309,6 @@
 
 	if (jw) {
 		jsonw_end_object(jw);
-
-		jsonw_end_object(jw);
 		jsonw_destroy(&jw);
 	}
 }
@@ -350,18 +320,16 @@
 
 	h = hist_db;
 	if (jw) {
-		jsonw_start_object(jw);
 		jsonw_pretty(jw, pretty);
 		jsonw_name(jw, info_source);
 		jsonw_start_object(jw);
 	} else
 		fprintf(fp, "#%s\n", info_source);
 
-	for (n = kern_db; n; n = n->next) {
+	for (n=kern_db; n; n=n->next) {
 		int ovfl = 0;
 		unsigned long long val = n->val;
 		struct nstat_ent *h1;
-
 		for (h1 = h; h1; h1 = h1->next) {
 			if (strcmp(h1->id, n->id) == 0) {
 				if (val < h1->val) {
@@ -387,8 +355,6 @@
 
 	if (jw) {
 		jsonw_end_object(jw);
-
-		jsonw_end_object(jw);
 		jsonw_destroy(&jw);
 	}
 }
@@ -409,14 +375,12 @@
 	load_netstat();
 	load_snmp6();
 	load_snmp();
-	load_sctp_snmp();
 
 	h = kern_db;
 	kern_db = n;
 
 	for (n = kern_db; n; n = n->next) {
 		struct nstat_ent *h1;
-
 		for (h1 = h; h1; h1 = h1->next) {
 			if (strcmp(h1->id, n->id) == 0) {
 				double sample;
@@ -431,14 +395,12 @@
 						n->rate = sample;
 					} else {
 						double w = W*(double)interval/scan_interval;
-
 						n->rate += w*(sample-n->rate);
 					}
 				}
 
 				while (h != h1) {
 					struct nstat_ent *tmp = h;
-
 					h = h->next;
 					free(tmp->id);
 					free(tmp);
@@ -452,14 +414,13 @@
 	}
 }
 
-#define T_DIFF(a, b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
+#define T_DIFF(a,b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
 
 
 static void server_loop(int fd)
 {
 	struct timeval snaptime = { 0 };
 	struct pollfd p;
-
 	p.fd = fd;
 	p.events = p.revents = POLLIN;
 
@@ -469,13 +430,11 @@
 	load_netstat();
 	load_snmp6();
 	load_snmp();
-	load_sctp_snmp();
 
 	for (;;) {
 		int status;
-		time_t tdiff;
+		int tdiff;
 		struct timeval now;
-
 		gettimeofday(&now, NULL);
 		tdiff = T_DIFF(now, snaptime);
 		if (tdiff >= scan_interval) {
@@ -483,24 +442,24 @@
 			snaptime = now;
 			tdiff = 0;
 		}
-		if (poll(&p, 1, scan_interval - tdiff) > 0
+		if (poll(&p, 1, tdiff + scan_interval) > 0
 		    && (p.revents&POLLIN)) {
 			int clnt = accept(fd, NULL, NULL);
-
 			if (clnt >= 0) {
 				pid_t pid;
-
 				if (children >= 5) {
 					close(clnt);
 				} else if ((pid = fork()) != 0) {
-					if (pid > 0)
+					if (pid>0)
 						children++;
 					close(clnt);
 				} else {
 					FILE *fp = fdopen(clnt, "w");
-
-					if (fp)
+					if (fp) {
+						if (tdiff > 0)
+							update_db(tdiff);
 						dump_kern_db(fp, 0);
+					}
 					exit(0);
 				}
 			}
@@ -515,7 +474,7 @@
 	struct ucred cred;
 	socklen_t olen = sizeof(cred);
 
-	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &olen) ||
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void*)&cred, &olen) ||
 	    olen < sizeof(cred))
 		return -1;
 	if (cred.uid == getuid() || cred.uid == 0)
@@ -528,18 +487,18 @@
 static void usage(void)
 {
 	fprintf(stderr,
-		"Usage: nstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
-		"   -h, --help		this message\n"
-		"   -a, --ignore	ignore history\n"
-		"   -d, --scan=SECS	sample every statistics every SECS\n"
-		"   -j, --json		format output in JSON\n"
-		"   -n, --nooutput	do history only\n"
-		"   -p, --pretty	pretty print\n"
-		"   -r, --reset		reset history\n"
-		"   -s, --noupdate	don't update history\n"
-		"   -t, --interval=SECS	report average over the last SECS\n"
-		"   -V, --version	output version information\n"
-		"   -z, --zeros		show entries with zero activity\n");
+"Usage: nstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
+"   -h, --help		this message\n"
+"   -a, --ignore	ignore history\n"
+"   -d, --scan=SECS	sample every statistics every SECS\n"
+"   -j, --json          format output in JSON\n"
+"   -n, --nooutput	do history only\n"
+"   -p, --pretty        pretty print\n"
+"   -r, --reset		reset history\n"
+"   -s, --noupdate	don\'t update history\n"
+"   -t, --interval=SECS	report average over the last SECS\n"
+"   -V, --version	output version information\n"
+"   -z, --zeros		show entries with zero activity\n");
 	exit(-1);
 }
 
@@ -568,7 +527,7 @@
 
 	while ((ch = getopt_long(argc, argv, "h?vVzrnasd:t:jp",
 				 longopts, NULL)) != EOF) {
-		switch (ch) {
+		switch(ch) {
 		case 'z':
 			dump_zeros = 1;
 			break;
@@ -627,7 +586,7 @@
 			perror("nstat: socket");
 			exit(-1);
 		}
-		if (bind(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
+		if (bind(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
 			perror("nstat: bind");
 			exit(-1);
 		}
@@ -683,7 +642,6 @@
 		if (!ignore_history) {
 			FILE *tfp;
 			long uptime = -1;
-
 			if ((tfp = fopen("/proc/uptime", "r")) != NULL) {
 				if (fscanf(tfp, "%ld", &uptime) != 1)
 					uptime = -1;
@@ -703,24 +661,17 @@
 	}
 
 	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 &&
-	    (connect(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) == 0
+	    (connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0
 	     || (strcpy(sun.sun_path+1, "nstat0"),
-		 connect(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
+		 connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
 	    && verify_forging(fd) == 0) {
 		FILE *sfp = fdopen(fd, "r");
-
-		if (!sfp) {
-			fprintf(stderr, "nstat: fdopen failed: %s\n",
-				strerror(errno));
-			close(fd);
-		} else {
-			load_good_table(sfp);
-			if (hist_db && source_mismatch) {
-				fprintf(stderr, "nstat: history is stale, ignoring it.\n");
-				hist_db = NULL;
-			}
-			fclose(sfp);
+		load_good_table(sfp);
+		if (hist_db && source_mismatch) {
+			fprintf(stderr, "nstat: history is stale, ignoring it.\n");
+			hist_db = NULL;
 		}
+		fclose(sfp);
 	} else {
 		if (fd >= 0)
 			close(fd);
@@ -732,7 +683,6 @@
 		load_netstat();
 		load_snmp6();
 		load_snmp();
-		load_sctp_snmp();
 		if (info_source[0] == 0)
 			strcpy(info_source, "kernel");
 	}
diff --git a/misc/rtacct.c b/misc/rtacct.c
index b1cb378..bb8c90f 100644
--- a/misc/rtacct.c
+++ b/misc/rtacct.c
@@ -33,21 +33,20 @@
 
 #include <SNAPSHOT.h>
 
-int reset_history;
-int ignore_history;
-int no_output;
-int no_update;
-int scan_interval;
-int time_constant;
-int dump_zeros;
-unsigned long magic_number;
+int reset_history = 0;
+int ignore_history = 0;
+int no_output = 0;
+int no_update = 0;
+int scan_interval = 0;
+int time_constant = 0;
+int dump_zeros = 0;
+unsigned long magic_number = 0;
 double W;
 
 static int generic_proc_open(const char *env, const char *name)
 {
 	char store[1024];
 	char *p = getenv(env);
-
 	if (!p) {
 		p = getenv("PROC_ROOT") ? : "/proc";
 		snprintf(store, sizeof(store)-1, "%s/%s", p, name);
@@ -63,7 +62,8 @@
 
 static __u32 rmap[256/4];
 
-struct rtacct_data {
+struct rtacct_data
+{
 	__u32			ival[256*4];
 
 	unsigned long long	val[256*4];
@@ -82,7 +82,6 @@
 
 	while (count < tot) {
 		int n = read(fd, buf+count, tot-count);
-
 		if (n < 0) {
 			if (errno == EINTR)
 				continue;
@@ -122,7 +121,7 @@
 
 	fd = net_rtacct_open();
 	if (fd >= 0) {
-		nread(fd, (char *)tbl, 256*16);
+		nread(fd, (char*)tbl, 256*16);
 		close(fd);
 	} else {
 		memset(tbl, 0, 256*16);
@@ -135,13 +134,13 @@
 	char temp[64];
 
 	if (rate > 1024*1024) {
-		sprintf(temp, "%uM", (unsigned int)rint(rate/(1024*1024)));
+		sprintf(temp, "%uM", (unsigned)rint(rate/(1024*1024)));
 		fprintf(fp, " %-10s", temp);
 	} else if (rate > 1024) {
-		sprintf(temp, "%uK", (unsigned int)rint(rate/1024));
+		sprintf(temp, "%uK", (unsigned)rint(rate/1024));
 		fprintf(fp, " %-10s", temp);
 	} else
-		fprintf(fp, " %-10u", (unsigned int)rate);
+		fprintf(fp, " %-10u", (unsigned)rate);
 }
 
 static void format_count(FILE *fp, unsigned long long val)
@@ -162,19 +161,25 @@
 	if (!no_output) {
 		fprintf(fp, "#%s\n", kern_db->signature);
 		fprintf(fp,
-"%-10s %-10s "
-"%-10s %-10s "
-"%-10s \n"
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"\n"
 		       , "Realm", "BytesTo", "PktsTo", "BytesFrom", "PktsFrom");
 		fprintf(fp,
-"%-10s %-10s "
-"%-10s %-10s "
-"%-10s \n"
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"\n"
 		       , "", "BPSTo", "PPSTo", "BPSFrom", "PPSFrom");
 
 	}
 
-	for (realm = 0; realm < 256; realm++) {
+	for (realm=0; realm<256; realm++) {
 		int i;
 		unsigned long long *val;
 		double		   *rate;
@@ -218,18 +223,24 @@
 	if (!no_output) {
 		fprintf(fp, "#%s\n", kern_db->signature);
 		fprintf(fp,
-"%-10s %-10s "
-"%-10s %-10s "
-"%-10s \n"
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"\n"
 		       , "Realm", "BytesTo", "PktsTo", "BytesFrom", "PktsFrom");
 		fprintf(fp,
-"%-10s %-10s "
-"%-10s %-10s "
-"%-10s \n"
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"%-10s "
+"\n"
 		       , "", "BPSTo", "PPSTo", "BPSFrom", "PPSFrom");
 	}
 
-	for (realm = 0; realm < 256; realm++) {
+	for (realm=0; realm<256; realm++) {
 		int ovfl = 0;
 		int i;
 		unsigned long long *val;
@@ -242,7 +253,7 @@
 		val = &kern_db->val[realm*4];
 		rate = &kern_db->rate[realm*4];
 
-		for (k = 0; k < 4; k++) {
+		for (k=0; k<4; k++) {
 			rval[k] = val[k];
 			if (rval[k] < hist_db->val[realm*4+k])
 				ovfl = 1;
@@ -250,7 +261,7 @@
 				rval[k] -= hist_db->val[realm*4+k];
 		}
 		if (ovfl) {
-			for (k = 0; k < 4; k++)
+			for (k=0; k<4; k++)
 				rval[k] = val[k];
 		}
 		if (hist_db) {
@@ -295,7 +306,7 @@
 
 	ival = read_kern_table(_ival);
 
-	for (i = 0; i < 256*4; i++) {
+	for (i=0; i<256*4; i++) {
 		double sample;
 		__u32 incr = ival[i] - kern_db->ival[i];
 
@@ -313,7 +324,6 @@
 				kern_db->rate[i] = sample;
 			} else {
 				double w = W*(double)interval/scan_interval;
-
 				kern_db->rate[i] += w*(sample-kern_db->rate[i]);
 			}
 		}
@@ -325,8 +335,7 @@
 	int tot = 0;
 
 	while (tot < sizeof(*kern_db)) {
-		int n = write(fd, ((char *)kern_db) + tot, sizeof(*kern_db)-tot);
-
+		int n = write(fd, ((char*)kern_db) + tot, sizeof(*kern_db)-tot);
 		if (n < 0) {
 			if (errno == EINTR)
 				continue;
@@ -338,17 +347,16 @@
 
 
 
-#define T_DIFF(a, b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
+#define T_DIFF(a,b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
 
 
 static void pad_kern_table(struct rtacct_data *dat, __u32 *ival)
 {
 	int i;
-
 	memset(dat->rate, 0, sizeof(dat->rate));
 	if (dat->ival != ival)
 		memcpy(dat->ival, ival, sizeof(dat->ival));
-	for (i = 0; i < 256*4; i++)
+	for (i=0; i<256*4; i++)
 		dat->val[i] = ival[i];
 }
 
@@ -356,13 +364,12 @@
 {
 	struct timeval snaptime = { 0 };
 	struct pollfd p;
-
 	p.fd = fd;
 	p.events = p.revents = POLLIN;
 
 	sprintf(kern_db->signature,
 		"%u.%lu sampling_interval=%d time_const=%d",
-		(unsigned int) getpid(), (unsigned long)random(),
+		(unsigned) getpid(), (unsigned long)random(),
 		scan_interval/1000, time_constant/1000);
 
 	pad_kern_table(kern_db, read_kern_table(kern_db->ival));
@@ -371,7 +378,6 @@
 		int status;
 		int tdiff;
 		struct timeval now;
-
 		gettimeofday(&now, NULL);
 		tdiff = T_DIFF(now, snaptime);
 		if (tdiff >= scan_interval) {
@@ -382,14 +388,12 @@
 		if (poll(&p, 1, tdiff + scan_interval) > 0
 		    && (p.revents&POLLIN)) {
 			int clnt = accept(fd, NULL, NULL);
-
 			if (clnt >= 0) {
 				pid_t pid;
-
 				if (children >= 5) {
 					close(clnt);
 				} else if ((pid = fork()) != 0) {
-					if (pid > 0)
+					if (pid>0)
 						children++;
 					close(clnt);
 				} else {
@@ -410,7 +414,7 @@
 	struct ucred cred;
 	socklen_t olen = sizeof(cred);
 
-	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &olen) ||
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void*)&cred, &olen) ||
 	    olen < sizeof(cred))
 		return -1;
 	if (cred.uid == getuid() || cred.uid == 0)
@@ -436,7 +440,7 @@
 	int fd;
 
 	while ((ch = getopt(argc, argv, "h?vVzrM:nasd:t:")) != EOF) {
-		switch (ch) {
+		switch(ch) {
 		case 'z':
 			dump_zeros = 1;
 			break;
@@ -485,7 +489,6 @@
 	if (argc) {
 		while (argc > 0) {
 			__u32 realm;
-
 			if (rtnl_rtrealm_a2n(&realm, argv[0])) {
 				fprintf(stderr, "Warning: realm \"%s\" does not exist.\n", argv[0]);
 				exit(-1);
@@ -512,7 +515,7 @@
 			perror("rtacct: socket");
 			exit(-1);
 		}
-		if (bind(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
+		if (bind(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
 			perror("rtacct: bind");
 			exit(-1);
 		}
@@ -577,7 +580,6 @@
 		if (!ignore_history) {
 			FILE *tfp;
 			long uptime = -1;
-
 			if ((tfp = fopen("/proc/uptime", "r")) != NULL) {
 				if (fscanf(tfp, "%ld", &uptime) != 1)
 					uptime = -1;
@@ -594,11 +596,11 @@
 	}
 
 	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 &&
-	    (connect(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) == 0
+	    (connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0
 	     || (strcpy(sun.sun_path+1, "rtacct0"),
-		 connect(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
+		 connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
 	    && verify_forging(fd) == 0) {
-		nread(fd, (char *)kern_db, sizeof(*kern_db));
+		nread(fd, (char*)kern_db, sizeof(*kern_db));
 		if (hist_db && hist_db->signature[0] &&
 		    strcmp(kern_db->signature, hist_db->signature)) {
 			fprintf(stderr, "rtacct: history is stale, ignoring it.\n");
diff --git a/misc/ss.c b/misc/ss.c
index 794c189..12a343c 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -12,11 +12,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
-#include <sys/sysmacros.h>
 #include <netinet/in.h>
 #include <string.h>
 #include <errno.h>
@@ -26,8 +26,6 @@
 #include <fnmatch.h>
 #include <getopt.h>
 #include <stdbool.h>
-#include <limits.h>
-#include <stdarg.h>
 
 #include "utils.h"
 #include "rt_names.h"
@@ -42,28 +40,10 @@
 #include <linux/unix_diag.h>
 #include <linux/netdevice.h>	/* for MAX_ADDR_LEN */
 #include <linux/filter.h>
-#include <linux/xdp_diag.h>
 #include <linux/packet_diag.h>
 #include <linux/netlink_diag.h>
-#include <linux/sctp.h>
-#include <linux/vm_sockets_diag.h>
-#include <linux/net.h>
-#include <linux/tipc.h>
-#include <linux/tipc_netlink.h>
-#include <linux/tipc_sockets_diag.h>
-
-/* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
-#ifndef PF_VSOCK
-#define PF_VSOCK 40
-#endif
-#ifndef AF_VSOCK
-#define AF_VSOCK PF_VSOCK
-#endif
 
 #define MAGIC_SEQ 123456
-#define BUF_CHUNK (1024 * 1024)	/* Buffer chunk allocation size */
-#define BUF_CHUNKS_MAX 5	/* Maximum number of allocated buffer chunks */
-#define LEN_ALIGN(x) (((x) + 1) & ~1)
 
 #define DIAG_REQUEST(_req, _r)						    \
 	struct {							    \
@@ -106,99 +86,35 @@
 }
 #endif
 
+int resolve_hosts = 0;
+int resolve_services = 1;
 int preferred_family = AF_UNSPEC;
-static int show_options;
-int show_details;
-static int show_users;
-static int show_mem;
-static int show_tcpinfo;
-static int show_bpf;
-static int show_proc_ctx;
-static int show_sock_ctx;
-static int show_header = 1;
-static int follow_events;
-static int sctp_ino;
-static int show_tipcinfo;
-static int show_tos;
-int numeric;
-int oneline;
+int show_options = 0;
+int show_details = 0;
+int show_users = 0;
+int show_mem = 0;
+int show_tcpinfo = 0;
+int show_bpf = 0;
+int show_proc_ctx = 0;
+int show_sock_ctx = 0;
+/* If show_users & show_proc_ctx only do user_ent_hash_build() once */
+int user_ent_hash_build_init = 0;
+int follow_events = 0;
 
-enum col_id {
-	COL_NETID,
-	COL_STATE,
-	COL_RECVQ,
-	COL_SENDQ,
-	COL_ADDR,
-	COL_SERV,
-	COL_RADDR,
-	COL_RSERV,
-	COL_EXT,
-	COL_PROC,
-	COL_MAX
-};
-
-enum col_align {
-	ALIGN_LEFT,
-	ALIGN_CENTER,
-	ALIGN_RIGHT
-};
-
-struct column {
-	const enum col_align align;
-	const char *header;
-	const char *ldelim;
-	int disabled;
-	int width;	/* Calculated, including additional layout spacing */
-	int max_len;	/* Measured maximum field length in this column */
-};
-
-static struct column columns[] = {
-	{ ALIGN_LEFT,	"Netid",		"",	0, 0, 0 },
-	{ ALIGN_LEFT,	"State",		" ",	0, 0, 0 },
-	{ ALIGN_LEFT,	"Recv-Q",		" ",	0, 0, 0 },
-	{ ALIGN_LEFT,	"Send-Q",		" ",	0, 0, 0 },
-	{ ALIGN_RIGHT,	"Local Address:",	" ",	0, 0, 0 },
-	{ ALIGN_LEFT,	"Port",			"",	0, 0, 0 },
-	{ ALIGN_RIGHT,	"Peer Address:",	" ",	0, 0, 0 },
-	{ ALIGN_LEFT,	"Port",			"",	0, 0, 0 },
-	{ ALIGN_LEFT,	"Process",		"",	0, 0, 0 },
-	{ ALIGN_LEFT,	"",			"",	0, 0, 0 },
-};
-
-static struct column *current_field = columns;
-
-/* Output buffer: chained chunks of BUF_CHUNK bytes. Each field is written to
- * the buffer as a variable size token. A token consists of a 16 bits length
- * field, followed by a string which is not NULL-terminated.
- *
- * A new chunk is allocated and linked when the current chunk doesn't have
- * enough room to store the current token as a whole.
- */
-struct buf_chunk {
-	struct buf_chunk *next;	/* Next chained chunk */
-	char *end;		/* Current end of content */
-	char data[0];
-};
-
-struct buf_token {
-	uint16_t len;		/* Data length, excluding length descriptor */
-	char data[0];
-};
-
-static struct {
-	struct buf_token *cur;	/* Position of current token in chunk */
-	struct buf_chunk *head;	/* First chunk */
-	struct buf_chunk *tail;	/* Current chunk */
-	int chunks;		/* Number of allocated chunks */
-} buffer;
+int netid_width;
+int state_width;
+int addrp_width;
+int addr_width;
+int serv_width;
+int screen_width;
 
 static const char *TCP_PROTO = "tcp";
-static const char *SCTP_PROTO = "sctp";
 static const char *UDP_PROTO = "udp";
 static const char *RAW_PROTO = "raw";
-static const char *dg_proto;
+static const char *dg_proto = NULL;
 
-enum {
+enum
+{
 	TCP_DB,
 	DCCP_DB,
 	UDP_DB,
@@ -209,20 +125,13 @@
 	PACKET_DG_DB,
 	PACKET_R_DB,
 	NETLINK_DB,
-	SCTP_DB,
-	VSOCK_ST_DB,
-	VSOCK_DG_DB,
-	TIPC_DB,
-	XDP_DB,
 	MAX_DB
 };
 
 #define PACKET_DBM ((1<<PACKET_DG_DB)|(1<<PACKET_R_DB))
 #define UNIX_DBM ((1<<UNIX_DG_DB)|(1<<UNIX_ST_DB)|(1<<UNIX_SQ_DB))
 #define ALL_DB ((1<<MAX_DB)-1)
-#define INET_L4_DBM ((1<<TCP_DB)|(1<<UDP_DB)|(1<<DCCP_DB)|(1<<SCTP_DB))
-#define INET_DBM (INET_L4_DBM | (1<<RAW_DB))
-#define VSOCK_DBM ((1<<VSOCK_ST_DB)|(1<<VSOCK_DG_DB))
+#define INET_DBM ((1<<TCP_DB)|(1<<UDP_DB)|(1<<DCCP_DB)|(1<<RAW_DB))
 
 enum {
 	SS_UNKNOWN,
@@ -240,94 +149,60 @@
 	SS_MAX
 };
 
-enum {
-	SCTP_STATE_CLOSED		= 0,
-	SCTP_STATE_COOKIE_WAIT		= 1,
-	SCTP_STATE_COOKIE_ECHOED	= 2,
-	SCTP_STATE_ESTABLISHED		= 3,
-	SCTP_STATE_SHUTDOWN_PENDING	= 4,
-	SCTP_STATE_SHUTDOWN_SENT	= 5,
-	SCTP_STATE_SHUTDOWN_RECEIVED	= 6,
-	SCTP_STATE_SHUTDOWN_ACK_SENT	= 7,
-};
-
 #define SS_ALL ((1 << SS_MAX) - 1)
 #define SS_CONN (SS_ALL & ~((1<<SS_LISTEN)|(1<<SS_CLOSE)|(1<<SS_TIME_WAIT)|(1<<SS_SYN_RECV)))
-#define TIPC_SS_CONN ((1<<SS_ESTABLISHED)|(1<<SS_LISTEN)|(1<<SS_CLOSE))
 
 #include "ssfilter.h"
 
-struct filter {
+struct filter
+{
 	int dbs;
 	int states;
-	uint64_t families;
+	int families;
 	struct ssfilter *f;
 	bool kill;
-	struct rtnl_handle *rth_for_killing;
 };
 
-#define FAMILY_MASK(family) ((uint64_t)1 << (family))
-
 static const struct filter default_dbs[MAX_DB] = {
 	[TCP_DB] = {
 		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_INET) | FAMILY_MASK(AF_INET6),
+		.families = (1 << AF_INET) | (1 << AF_INET6),
 	},
 	[DCCP_DB] = {
 		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_INET) | FAMILY_MASK(AF_INET6),
+		.families = (1 << AF_INET) | (1 << AF_INET6),
 	},
 	[UDP_DB] = {
 		.states   = (1 << SS_ESTABLISHED),
-		.families = FAMILY_MASK(AF_INET) | FAMILY_MASK(AF_INET6),
+		.families = (1 << AF_INET) | (1 << AF_INET6),
 	},
 	[RAW_DB] = {
 		.states   = (1 << SS_ESTABLISHED),
-		.families = FAMILY_MASK(AF_INET) | FAMILY_MASK(AF_INET6),
+		.families = (1 << AF_INET) | (1 << AF_INET6),
 	},
 	[UNIX_DG_DB] = {
 		.states   = (1 << SS_CLOSE),
-		.families = FAMILY_MASK(AF_UNIX),
+		.families = (1 << AF_UNIX),
 	},
 	[UNIX_ST_DB] = {
 		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_UNIX),
+		.families = (1 << AF_UNIX),
 	},
 	[UNIX_SQ_DB] = {
 		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_UNIX),
+		.families = (1 << AF_UNIX),
 	},
 	[PACKET_DG_DB] = {
 		.states   = (1 << SS_CLOSE),
-		.families = FAMILY_MASK(AF_PACKET),
+		.families = (1 << AF_PACKET),
 	},
 	[PACKET_R_DB] = {
 		.states   = (1 << SS_CLOSE),
-		.families = FAMILY_MASK(AF_PACKET),
+		.families = (1 << AF_PACKET),
 	},
 	[NETLINK_DB] = {
 		.states   = (1 << SS_CLOSE),
-		.families = FAMILY_MASK(AF_NETLINK),
-	},
-	[SCTP_DB] = {
-		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_INET) | FAMILY_MASK(AF_INET6),
-	},
-	[VSOCK_ST_DB] = {
-		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_VSOCK),
-	},
-	[VSOCK_DG_DB] = {
-		.states   = SS_CONN,
-		.families = FAMILY_MASK(AF_VSOCK),
-	},
-	[TIPC_DB] = {
-		.states   = TIPC_SS_CONN,
-		.families = FAMILY_MASK(AF_TIPC),
-	},
-	[XDP_DB] = {
-		.states   = (1 << SS_CLOSE),
-		.families = FAMILY_MASK(AF_XDP),
+		.families = (1 << AF_NETLINK),
 	},
 };
 
@@ -352,107 +227,49 @@
 		.dbs    = (1 << NETLINK_DB),
 		.states = (1 << SS_CLOSE),
 	},
-	[AF_VSOCK] = {
-		.dbs    = VSOCK_DBM,
-		.states = SS_CONN,
-	},
-	[AF_TIPC] = {
-		.dbs    = (1 << TIPC_DB),
-		.states = TIPC_SS_CONN,
-	},
-	[AF_XDP] = {
-		.dbs    = (1 << XDP_DB),
-		.states = (1 << SS_CLOSE),
-	},
 };
 
 static int do_default = 1;
 static struct filter current_filter;
 
-static void filter_db_set(struct filter *f, int db, bool enable)
+static void filter_db_set(struct filter *f, int db)
 {
-	if (enable) {
-		f->states   |= default_dbs[db].states;
-		f->dbs	    |= 1 << db;
-	} else {
-		f->dbs &= ~(1 << db);
-	}
+	f->states   |= default_dbs[db].states;
+	f->dbs	    |= 1 << db;
 	do_default   = 0;
 }
 
-static int filter_db_parse(struct filter *f, const char *s)
-{
-	const struct {
-		const char *name;
-		int dbs[MAX_DB + 1];
-	} db_name_tbl[] = {
-#define ENTRY(name, ...) { #name, { __VA_ARGS__, MAX_DB } }
-		ENTRY(all, UDP_DB, DCCP_DB, TCP_DB, RAW_DB,
-			   UNIX_ST_DB, UNIX_DG_DB, UNIX_SQ_DB,
-			   PACKET_R_DB, PACKET_DG_DB, NETLINK_DB,
-			   SCTP_DB, VSOCK_ST_DB, VSOCK_DG_DB, XDP_DB),
-		ENTRY(inet, UDP_DB, DCCP_DB, TCP_DB, SCTP_DB, RAW_DB),
-		ENTRY(udp, UDP_DB),
-		ENTRY(dccp, DCCP_DB),
-		ENTRY(tcp, TCP_DB),
-		ENTRY(sctp, SCTP_DB),
-		ENTRY(raw, RAW_DB),
-		ENTRY(unix, UNIX_ST_DB, UNIX_DG_DB, UNIX_SQ_DB),
-		ENTRY(unix_stream, UNIX_ST_DB),
-		ENTRY(u_str, UNIX_ST_DB),	/* alias for unix_stream */
-		ENTRY(unix_dgram, UNIX_DG_DB),
-		ENTRY(u_dgr, UNIX_DG_DB),	/* alias for unix_dgram */
-		ENTRY(unix_seqpacket, UNIX_SQ_DB),
-		ENTRY(u_seq, UNIX_SQ_DB),	/* alias for unix_seqpacket */
-		ENTRY(packet, PACKET_R_DB, PACKET_DG_DB),
-		ENTRY(packet_raw, PACKET_R_DB),
-		ENTRY(p_raw, PACKET_R_DB),	/* alias for packet_raw */
-		ENTRY(packet_dgram, PACKET_DG_DB),
-		ENTRY(p_dgr, PACKET_DG_DB),	/* alias for packet_dgram */
-		ENTRY(netlink, NETLINK_DB),
-		ENTRY(vsock, VSOCK_ST_DB, VSOCK_DG_DB),
-		ENTRY(vsock_stream, VSOCK_ST_DB),
-		ENTRY(v_str, VSOCK_ST_DB),	/* alias for vsock_stream */
-		ENTRY(vsock_dgram, VSOCK_DG_DB),
-		ENTRY(v_dgr, VSOCK_DG_DB),	/* alias for vsock_dgram */
-		ENTRY(xdp, XDP_DB),
-#undef ENTRY
-	};
-	bool enable = true;
-	unsigned int i;
-	const int *dbp;
-
-	if (s[0] == '!') {
-		enable = false;
-		s++;
-	}
-	for (i = 0; i < ARRAY_SIZE(db_name_tbl); i++) {
-		if (strcmp(s, db_name_tbl[i].name))
-			continue;
-		for (dbp = db_name_tbl[i].dbs; *dbp != MAX_DB; dbp++)
-			filter_db_set(f, *dbp, enable);
-		return 0;
-	}
-	return -1;
-}
-
 static void filter_af_set(struct filter *f, int af)
 {
 	f->states	   |= default_afs[af].states;
-	f->families	   |= FAMILY_MASK(af);
+	f->families	   |= 1 << af;
 	do_default	    = 0;
 	preferred_family    = af;
 }
 
 static int filter_af_get(struct filter *f, int af)
 {
-	return !!(f->families & FAMILY_MASK(af));
+	return f->families & (1 << af);
+}
+
+static void filter_default_dbs(struct filter *f)
+{
+	filter_db_set(f, UDP_DB);
+	filter_db_set(f, DCCP_DB);
+	filter_db_set(f, TCP_DB);
+	filter_db_set(f, RAW_DB);
+	filter_db_set(f, UNIX_ST_DB);
+	filter_db_set(f, UNIX_DG_DB);
+	filter_db_set(f, UNIX_SQ_DB);
+	filter_db_set(f, PACKET_R_DB);
+	filter_db_set(f, PACKET_DG_DB);
+	filter_db_set(f, NETLINK_DB);
 }
 
 static void filter_states_set(struct filter *f, int states)
 {
 	if (states)
-		f->states = states;
+		f->states = (f->states | states) & states;
 }
 
 static void filter_merge_defaults(struct filter *f)
@@ -468,7 +285,7 @@
 			f->families |= default_dbs[db].families;
 	}
 	for (af = 0; af < AF_MAX; af++) {
-		if (!(f->families & FAMILY_MASK(af)))
+		if (!(f->families & (1 << af)))
 			continue;
 
 		if (!(default_afs[af].dbs & f->dbs))
@@ -489,24 +306,76 @@
 
 	return fopen(p, "r");
 }
-#define net_tcp_open()		generic_proc_open("PROC_NET_TCP", "net/tcp")
-#define net_tcp6_open()		generic_proc_open("PROC_NET_TCP6", "net/tcp6")
-#define net_udp_open()		generic_proc_open("PROC_NET_UDP", "net/udp")
-#define net_udp6_open()		generic_proc_open("PROC_NET_UDP6", "net/udp6")
-#define net_raw_open()		generic_proc_open("PROC_NET_RAW", "net/raw")
-#define net_raw6_open()		generic_proc_open("PROC_NET_RAW6", "net/raw6")
-#define net_unix_open()		generic_proc_open("PROC_NET_UNIX", "net/unix")
-#define net_packet_open()	generic_proc_open("PROC_NET_PACKET", \
-							"net/packet")
-#define net_netlink_open()	generic_proc_open("PROC_NET_NETLINK", \
-							"net/netlink")
-#define net_sockstat_open()	generic_proc_open("PROC_NET_SOCKSTAT", \
-							"net/sockstat")
-#define net_sockstat6_open()	generic_proc_open("PROC_NET_SOCKSTAT6", \
-							"net/sockstat6")
-#define net_snmp_open()		generic_proc_open("PROC_NET_SNMP", "net/snmp")
-#define ephemeral_ports_open()	generic_proc_open("PROC_IP_LOCAL_PORT_RANGE", \
-					"sys/net/ipv4/ip_local_port_range")
+
+static FILE *net_tcp_open(void)
+{
+	return generic_proc_open("PROC_NET_TCP", "net/tcp");
+}
+
+static FILE *net_tcp6_open(void)
+{
+	return generic_proc_open("PROC_NET_TCP6", "net/tcp6");
+}
+
+static FILE *net_udp_open(void)
+{
+	return generic_proc_open("PROC_NET_UDP", "net/udp");
+}
+
+static FILE *net_udp6_open(void)
+{
+	return generic_proc_open("PROC_NET_UDP6", "net/udp6");
+}
+
+static FILE *net_raw_open(void)
+{
+	return generic_proc_open("PROC_NET_RAW", "net/raw");
+}
+
+static FILE *net_raw6_open(void)
+{
+	return generic_proc_open("PROC_NET_RAW6", "net/raw6");
+}
+
+static FILE *net_unix_open(void)
+{
+	return generic_proc_open("PROC_NET_UNIX", "net/unix");
+}
+
+static FILE *net_packet_open(void)
+{
+	return generic_proc_open("PROC_NET_PACKET", "net/packet");
+}
+
+static FILE *net_netlink_open(void)
+{
+	return generic_proc_open("PROC_NET_NETLINK", "net/netlink");
+}
+
+static FILE *slabinfo_open(void)
+{
+	return generic_proc_open("PROC_SLABINFO", "slabinfo");
+}
+
+static FILE *net_sockstat_open(void)
+{
+	return generic_proc_open("PROC_NET_SOCKSTAT", "net/sockstat");
+}
+
+static FILE *net_sockstat6_open(void)
+{
+	return generic_proc_open("PROC_NET_SOCKSTAT6", "net/sockstat6");
+}
+
+static FILE *net_snmp_open(void)
+{
+	return generic_proc_open("PROC_NET_SNMP", "net/snmp");
+}
+
+static FILE *ephemeral_ports_open(void)
+{
+	return generic_proc_open("PROC_IP_LOCAL_PORT_RANGE", "sys/net/ipv4/ip_local_port_range");
+}
 
 struct user_ent {
 	struct user_ent	*next;
@@ -519,7 +388,7 @@
 };
 
 #define USER_ENT_HASH_SIZE	256
-static struct user_ent *user_ent_hash[USER_ENT_HASH_SIZE];
+struct user_ent *user_ent_hash[USER_ENT_HASH_SIZE];
 
 static int user_ent_hashfn(unsigned int ino)
 {
@@ -582,7 +451,6 @@
 	char *pid_context;
 	char *sock_context;
 	const char *no_ctx = "unavailable";
-	static int user_ent_hash_build_init;
 
 	/* If show_users & show_proc_ctx set only do this once */
 	if (user_ent_hash_build_init != 0)
@@ -590,7 +458,8 @@
 
 	user_ent_hash_build_init = 1;
 
-	strlcpy(name, root, sizeof(name));
+	strncpy(name, root, sizeof(name)-1);
+	name[sizeof(name)-1] = 0;
 
 	if (strlen(name) == 0 || name[strlen(name)-1] != '/')
 		strcat(name, "/");
@@ -682,7 +551,7 @@
 };
 
 #define ENTRY_BUF_SIZE 512
-static int find_entry(unsigned int ino, char **buf, int type)
+static int find_entry(unsigned ino, char **buf, int type)
 {
 	struct user_ent *p;
 	int cnt = 0;
@@ -753,43 +622,117 @@
 	return cnt;
 }
 
+/* Get stats from slab */
+
+struct slabstat
+{
+	int socks;
+	int tcp_ports;
+	int tcp_tws;
+	int tcp_syns;
+	int skbs;
+};
+
+static struct slabstat slabstat;
+
+static const char *slabstat_ids[] =
+{
+	"sock",
+	"tcp_bind_bucket",
+	"tcp_tw_bucket",
+	"tcp_open_request",
+	"skbuff_head_cache",
+};
+
+static int get_slabstat(struct slabstat *s)
+{
+	char buf[256];
+	FILE *fp;
+	int cnt;
+	static int slabstat_valid;
+
+	if (slabstat_valid)
+		return 0;
+
+	memset(s, 0, sizeof(*s));
+
+	fp = slabinfo_open();
+	if (!fp)
+		return -1;
+
+	cnt = sizeof(*s)/sizeof(int);
+
+	if (!fgets(buf, sizeof(buf), fp)) {
+		fclose(fp);
+		return -1;
+	}
+	while(fgets(buf, sizeof(buf), fp) != NULL) {
+		int i;
+		for (i=0; i<sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) {
+			if (memcmp(buf, slabstat_ids[i], strlen(slabstat_ids[i])) == 0) {
+				sscanf(buf, "%*s%d", ((int *)s) + i);
+				cnt--;
+				break;
+			}
+		}
+		if (cnt <= 0)
+			break;
+	}
+
+	slabstat_valid = 1;
+
+	fclose(fp);
+	return 0;
+}
+
 static unsigned long long cookie_sk_get(const uint32_t *cookie)
 {
 	return (((unsigned long long)cookie[1] << 31) << 1) | cookie[0];
 }
 
-static const char *sctp_sstate_name[] = {
-	[SCTP_STATE_CLOSED] = "CLOSED",
-	[SCTP_STATE_COOKIE_WAIT] = "COOKIE_WAIT",
-	[SCTP_STATE_COOKIE_ECHOED] = "COOKIE_ECHOED",
-	[SCTP_STATE_ESTABLISHED] = "ESTAB",
-	[SCTP_STATE_SHUTDOWN_PENDING] = "SHUTDOWN_PENDING",
-	[SCTP_STATE_SHUTDOWN_SENT] = "SHUTDOWN_SENT",
-	[SCTP_STATE_SHUTDOWN_RECEIVED] = "SHUTDOWN_RECEIVED",
-	[SCTP_STATE_SHUTDOWN_ACK_SENT] = "ACK_SENT",
-};
-
-static const char * const stype_nameg[] = {
+static const char *sstate_name[] = {
 	"UNKNOWN",
-	[SOCK_STREAM] = "STREAM",
-	[SOCK_DGRAM] = "DGRAM",
-	[SOCK_RDM] = "RDM",
-	[SOCK_SEQPACKET] = "SEQPACKET",
+	[SS_ESTABLISHED] = "ESTAB",
+	[SS_SYN_SENT] = "SYN-SENT",
+	[SS_SYN_RECV] = "SYN-RECV",
+	[SS_FIN_WAIT1] = "FIN-WAIT-1",
+	[SS_FIN_WAIT2] = "FIN-WAIT-2",
+	[SS_TIME_WAIT] = "TIME-WAIT",
+	[SS_CLOSE] = "UNCONN",
+	[SS_CLOSE_WAIT] = "CLOSE-WAIT",
+	[SS_LAST_ACK] = "LAST-ACK",
+	[SS_LISTEN] = 	"LISTEN",
+	[SS_CLOSING] = "CLOSING",
 };
 
-struct sockstat {
+static const char *sstate_namel[] = {
+	"UNKNOWN",
+	[SS_ESTABLISHED] = "established",
+	[SS_SYN_SENT] = "syn-sent",
+	[SS_SYN_RECV] = "syn-recv",
+	[SS_FIN_WAIT1] = "fin-wait-1",
+	[SS_FIN_WAIT2] = "fin-wait-2",
+	[SS_TIME_WAIT] = "time-wait",
+	[SS_CLOSE] = "unconnected",
+	[SS_CLOSE_WAIT] = "close-wait",
+	[SS_LAST_ACK] = "last-ack",
+	[SS_LISTEN] = 	"listening",
+	[SS_CLOSING] = "closing",
+};
+
+struct sockstat
+{
 	struct sockstat	   *next;
 	unsigned int	    type;
 	uint16_t	    prot;
-	uint16_t	    raw_prot;
 	inet_prefix	    local;
 	inet_prefix	    remote;
 	int		    lport;
 	int		    rport;
 	int		    state;
 	int		    rq, wq;
-	unsigned int ino;
-	unsigned int uid;
+	unsigned	    ino;
+	unsigned	    uid;
 	int		    refcnt;
 	unsigned int	    iface;
 	unsigned long long  sk;
@@ -798,7 +741,8 @@
 	__u32		    mark;
 };
 
-struct dctcpstat {
+struct dctcpstat
+{
 	unsigned int	ce_state;
 	unsigned int	alpha;
 	unsigned int	ab_ecn;
@@ -806,34 +750,28 @@
 	bool		enabled;
 };
 
-struct tcpstat {
+struct tcpstat
+{
 	struct sockstat	    ss;
-	unsigned int	    timer;
-	unsigned int	    timeout;
+	int		    timer;
+	int		    timeout;
 	int		    probes;
 	char		    cong_alg[16];
 	double		    rto, ato, rtt, rttvar;
-	int		    qack, ssthresh, backoff;
+	int		    qack, cwnd, ssthresh, backoff;
 	double		    send_bps;
 	int		    snd_wscale;
 	int		    rcv_wscale;
 	int		    mss;
-	int		    rcv_mss;
-	int		    advmss;
-	unsigned int	    pmtu;
-	unsigned int	    cwnd;
 	unsigned int	    lastsnd;
 	unsigned int	    lastrcv;
 	unsigned int	    lastack;
 	double		    pacing_rate;
 	double		    pacing_rate_max;
-	double		    delivery_rate;
 	unsigned long long  bytes_acked;
 	unsigned long long  bytes_received;
 	unsigned int	    segs_out;
 	unsigned int	    segs_in;
-	unsigned int	    data_segs_out;
-	unsigned int	    data_segs_in;
 	unsigned int	    unacked;
 	unsigned int	    retrans;
 	unsigned int	    retrans_total;
@@ -841,585 +779,72 @@
 	unsigned int	    sacked;
 	unsigned int	    fackets;
 	unsigned int	    reordering;
-	unsigned int	    not_sent;
-	unsigned int	    delivered;
-	unsigned int	    delivered_ce;
-	unsigned int	    dsack_dups;
-	unsigned int	    reord_seen;
 	double		    rcv_rtt;
-	double		    min_rtt;
 	int		    rcv_space;
-	unsigned int        rcv_ssthresh;
-	unsigned long long  busy_time;
-	unsigned long long  rwnd_limited;
-	unsigned long long  sndbuf_limited;
-	unsigned long long  bytes_sent;
-	unsigned long long  bytes_retrans;
 	bool		    has_ts_opt;
 	bool		    has_sack_opt;
 	bool		    has_ecn_opt;
 	bool		    has_ecnseen_opt;
 	bool		    has_fastopen_opt;
 	bool		    has_wscale_opt;
-	bool		    app_limited;
 	struct dctcpstat    *dctcp;
-	struct tcp_bbr_info *bbr_info;
 };
 
-/* SCTP assocs share the same inode number with their parent endpoint. So if we
- * have seen the inode number before, it must be an assoc instead of the next
- * endpoint. */
-static bool is_sctp_assoc(struct sockstat *s, const char *sock_name)
+static void sock_state_print(struct sockstat *s, const char *sock_name)
 {
-	if (strcmp(sock_name, "sctp"))
-		return false;
-	if (!sctp_ino || sctp_ino != s->ino)
-		return false;
-	return true;
-}
+	if (netid_width)
+		printf("%-*s ", netid_width, sock_name);
+	if (state_width)
+		printf("%-*s ", state_width, sstate_name[s->state]);
 
-static const char *unix_netid_name(int type)
-{
-	switch (type) {
-	case SOCK_STREAM:
-		return "u_str";
-	case SOCK_SEQPACKET:
-		return "u_seq";
-	case SOCK_DGRAM:
-	default:
-		return "u_dgr";
-	}
-}
-
-static const char *proto_name(int protocol)
-{
-	switch (protocol) {
-	case 0:
-		return "raw";
-	case IPPROTO_UDP:
-		return "udp";
-	case IPPROTO_TCP:
-		return "tcp";
-	case IPPROTO_SCTP:
-		return "sctp";
-	case IPPROTO_DCCP:
-		return "dccp";
-	case IPPROTO_ICMPV6:
-		return "icmp6";
-	}
-
-	return "???";
-}
-
-static const char *vsock_netid_name(int type)
-{
-	switch (type) {
-	case SOCK_STREAM:
-		return "v_str";
-	case SOCK_DGRAM:
-		return "v_dgr";
-	default:
-		return "???";
-	}
-}
-
-static const char *tipc_netid_name(int type)
-{
-	switch (type) {
-	case SOCK_STREAM:
-		return "ti_st";
-	case SOCK_DGRAM:
-		return "ti_dg";
-	case SOCK_RDM:
-		return "ti_rd";
-	case SOCK_SEQPACKET:
-		return "ti_sq";
-	default:
-		return "???";
-	}
-}
-
-/* Allocate and initialize a new buffer chunk */
-static struct buf_chunk *buf_chunk_new(void)
-{
-	struct buf_chunk *new = malloc(BUF_CHUNK);
-
-	if (!new)
-		abort();
-
-	new->next = NULL;
-
-	/* This is also the last block */
-	buffer.tail = new;
-
-	/* Next token will be stored at the beginning of chunk data area, and
-	 * its initial length is zero.
-	 */
-	buffer.cur = (struct buf_token *)new->data;
-	buffer.cur->len = 0;
-
-	new->end = buffer.cur->data;
-
-	buffer.chunks++;
-
-	return new;
-}
-
-/* Return available tail room in given chunk */
-static int buf_chunk_avail(struct buf_chunk *chunk)
-{
-	return BUF_CHUNK - offsetof(struct buf_chunk, data) -
-	       (chunk->end - chunk->data);
-}
-
-/* Update end pointer and token length, link new chunk if we hit the end of the
- * current one. Return -EAGAIN if we got a new chunk, caller has to print again.
- */
-static int buf_update(int len)
-{
-	struct buf_chunk *chunk = buffer.tail;
-	struct buf_token *t = buffer.cur;
-
-	/* Claim success if new content fits in the current chunk, and anyway
-	 * if this is the first token in the chunk: in the latter case,
-	 * allocating a new chunk won't help, so we'll just cut the output.
-	 */
-	if ((len < buf_chunk_avail(chunk) && len != -1 /* glibc < 2.0.6 */) ||
-	    t == (struct buf_token *)chunk->data) {
-		len = min(len, buf_chunk_avail(chunk));
-
-		/* Total field length can't exceed 2^16 bytes, cut as needed */
-		len = min(len, USHRT_MAX - t->len);
-
-		chunk->end += len;
-		t->len += len;
-		return 0;
-	}
-
-	/* Content truncated, time to allocate more */
-	chunk->next = buf_chunk_new();
-
-	/* Copy current token over to new chunk, including length descriptor */
-	memcpy(chunk->next->data, t, sizeof(t->len) + t->len);
-	chunk->next->end += t->len;
-
-	/* Discard partially written field in old chunk */
-	chunk->end -= t->len + sizeof(t->len);
-
-	return -EAGAIN;
-}
-
-/* Append content to buffer as part of the current field */
-__attribute__((format(printf, 1, 2)))
-static void out(const char *fmt, ...)
-{
-	struct column *f = current_field;
-	va_list args;
-	char *pos;
-	int len;
-
-	if (f->disabled)
-		return;
-
-	if (!buffer.head)
-		buffer.head = buf_chunk_new();
-
-again:	/* Append to buffer: if we have a new chunk, print again */
-
-	pos = buffer.cur->data + buffer.cur->len;
-	va_start(args, fmt);
-
-	/* Limit to tail room. If we hit the limit, buf_update() will tell us */
-	len = vsnprintf(pos, buf_chunk_avail(buffer.tail), fmt, args);
-	va_end(args);
-
-	if (buf_update(len))
-		goto again;
-}
-
-static int print_left_spacing(struct column *f, int stored, int printed)
-{
-	int s;
-
-	if (!f->width || f->align == ALIGN_LEFT)
-		return 0;
-
-	s = f->width - stored - printed;
-	if (f->align == ALIGN_CENTER)
-		/* If count of total spacing is odd, shift right by one */
-		s = (s + 1) / 2;
-
-	if (s > 0)
-		return printf("%*c", s, ' ');
-
-	return 0;
-}
-
-static void print_right_spacing(struct column *f, int printed)
-{
-	int s;
-
-	if (!f->width || f->align == ALIGN_RIGHT)
-		return;
-
-	s = f->width - printed;
-	if (f->align == ALIGN_CENTER)
-		s /= 2;
-
-	if (s > 0)
-		printf("%*c", s, ' ');
-}
-
-/* Done with field: update buffer pointer, start new token after current one */
-static void field_flush(struct column *f)
-{
-	struct buf_chunk *chunk;
-	unsigned int pad;
-
-	if (f->disabled)
-		return;
-
-	chunk = buffer.tail;
-	pad = buffer.cur->len % 2;
-
-	if (buffer.cur->len > f->max_len)
-		f->max_len = buffer.cur->len;
-
-	/* We need a new chunk if we can't store the next length descriptor.
-	 * Mind the gap between end of previous token and next aligned position
-	 * for length descriptor.
-	 */
-	if (buf_chunk_avail(chunk) - pad < sizeof(buffer.cur->len)) {
-		chunk->end += pad;
-		chunk->next = buf_chunk_new();
-		return;
-	}
-
-	buffer.cur = (struct buf_token *)(buffer.cur->data +
-					  LEN_ALIGN(buffer.cur->len));
-	buffer.cur->len = 0;
-	buffer.tail->end = buffer.cur->data;
-}
-
-static int field_is_last(struct column *f)
-{
-	return f - columns == COL_MAX - 1;
-}
-
-/* Get the next available token in the buffer starting from the current token */
-static struct buf_token *buf_token_next(struct buf_token *cur)
-{
-	struct buf_chunk *chunk = buffer.tail;
-
-	/* If we reached the end of chunk contents, get token from next chunk */
-	if (cur->data + LEN_ALIGN(cur->len) == chunk->end) {
-		buffer.tail = chunk = chunk->next;
-		return chunk ? (struct buf_token *)chunk->data : NULL;
-	}
-
-	return (struct buf_token *)(cur->data + LEN_ALIGN(cur->len));
-}
-
-/* Free up all allocated buffer chunks */
-static void buf_free_all(void)
-{
-	struct buf_chunk *tmp;
-
-	for (buffer.tail = buffer.head; buffer.tail; ) {
-		tmp = buffer.tail;
-		buffer.tail = buffer.tail->next;
-		free(tmp);
-	}
-	buffer.head = NULL;
-	buffer.chunks = 0;
-}
-
-/* Get current screen width, default to 80 columns if TIOCGWINSZ fails */
-static int render_screen_width(void)
-{
-	int width = 80;
-
-	if (isatty(STDOUT_FILENO)) {
-		struct winsize w;
-
-		if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) {
-			if (w.ws_col > 0)
-				width = w.ws_col;
-		}
-	}
-
-	return width;
-}
-
-/* Calculate column width from contents length. If columns don't fit on one
- * line, break them into the least possible amount of lines and keep them
- * aligned across lines. Available screen space is equally spread between fields
- * as additional spacing.
- */
-static void render_calc_width(void)
-{
-	int screen_width = render_screen_width();
-	struct column *c, *eol = columns - 1;
-	int first, len = 0, linecols = 0;
-
-	/* First pass: set width for each column to measured content length */
-	for (first = 1, c = columns; c - columns < COL_MAX; c++) {
-		if (c->disabled)
-			continue;
-
-		if (!first && c->max_len)
-			c->width = c->max_len + strlen(c->ldelim);
-		else
-			c->width = c->max_len;
-
-		/* But don't exceed screen size. If we exceed the screen size
-		 * for even a single field, it will just start on a line of its
-		 * own and then naturally wrap.
-		 */
-		c->width = min(c->width, screen_width);
-
-		if (c->width)
-			first = 0;
-	}
-
-	/* Second pass: find out newlines and distribute available spacing */
-	for (c = columns; c - columns < COL_MAX; c++) {
-		int pad, spacing, rem, last;
-		struct column *tmp;
-
-		if (!c->width)
-			continue;
-
-		linecols++;
-		len += c->width;
-
-		for (last = 1, tmp = c + 1; tmp - columns < COL_MAX; tmp++) {
-			if (tmp->width) {
-				last = 0;
-				break;
-			}
-		}
-
-		if (!last && len < screen_width) {
-			/* Columns fit on screen so far, nothing to do yet */
-			continue;
-		}
-
-		if (len == screen_width) {
-			/* Exact fit, just start with new line */
-			goto newline;
-		}
-
-		if (len > screen_width) {
-			/* Screen width exceeded: go back one column */
-			len -= c->width;
-			c--;
-			linecols--;
-		}
-
-		/* Distribute remaining space to columns on this line */
-		pad = screen_width - len;
-		spacing = pad / linecols;
-		rem = pad % linecols;
-		for (tmp = c; tmp > eol; tmp--) {
-			if (!tmp->width)
-				continue;
-
-			tmp->width += spacing;
-			if (rem) {
-				tmp->width++;
-				rem--;
-			}
-		}
-
-newline:
-		/* Line break: reset line counters, mark end-of-line */
-		eol = c;
-		len = 0;
-		linecols = 0;
-	}
-}
-
-/* Render buffered output with spacing and delimiters, then free up buffers */
-static void render(void)
-{
-	struct buf_token *token;
-	int printed, line_started = 0;
-	struct column *f;
-
-	if (!buffer.head)
-		return;
-
-	token = (struct buf_token *)buffer.head->data;
-
-	/* Ensure end alignment of last token, it wasn't necessarily flushed */
-	buffer.tail->end += buffer.cur->len % 2;
-
-	render_calc_width();
-
-	/* Rewind and replay */
-	buffer.tail = buffer.head;
-
-	f = columns;
-	while (!f->width)
-		f++;
-
-	while (token) {
-		/* Print left delimiter only if we already started a line */
-		if (line_started++)
-			printed = printf("%s", f->ldelim);
-		else
-			printed = 0;
-
-		/* Print field content from token data with spacing */
-		printed += print_left_spacing(f, token->len, printed);
-		printed += fwrite(token->data, 1, token->len, stdout);
-		print_right_spacing(f, printed);
-
-		/* Go to next non-empty field, deal with end-of-line */
-		do {
-			if (field_is_last(f)) {
-				printf("\n");
-				f = columns;
-				line_started = 0;
-			} else {
-				f++;
-			}
-		} while (f->disabled);
-
-		token = buf_token_next(token);
-	}
-
-	buf_free_all();
-	current_field = columns;
-}
-
-/* Move to next field, and render buffer if we reached the maximum number of
- * chunks, at the last field in a line.
- */
-static void field_next(void)
-{
-	if (field_is_last(current_field) && buffer.chunks >= BUF_CHUNKS_MAX) {
-		render();
-		return;
-	}
-
-	field_flush(current_field);
-	if (field_is_last(current_field))
-		current_field = columns;
-	else
-		current_field++;
-}
-
-/* Walk through fields and flush them until we reach the desired one */
-static void field_set(enum col_id id)
-{
-	while (id != current_field - columns)
-		field_next();
-}
-
-/* Print header for all non-empty columns */
-static void print_header(void)
-{
-	while (!field_is_last(current_field)) {
-		if (!current_field->disabled)
-			out("%s", current_field->header);
-		field_next();
-	}
-}
-
-static void sock_state_print(struct sockstat *s)
-{
-	const char *sock_name;
-	static const char * const sstate_name[] = {
-		"UNKNOWN",
-		[SS_ESTABLISHED] = "ESTAB",
-		[SS_SYN_SENT] = "SYN-SENT",
-		[SS_SYN_RECV] = "SYN-RECV",
-		[SS_FIN_WAIT1] = "FIN-WAIT-1",
-		[SS_FIN_WAIT2] = "FIN-WAIT-2",
-		[SS_TIME_WAIT] = "TIME-WAIT",
-		[SS_CLOSE] = "UNCONN",
-		[SS_CLOSE_WAIT] = "CLOSE-WAIT",
-		[SS_LAST_ACK] = "LAST-ACK",
-		[SS_LISTEN] =	"LISTEN",
-		[SS_CLOSING] = "CLOSING",
-	};
-
-	switch (s->local.family) {
-	case AF_UNIX:
-		sock_name = unix_netid_name(s->type);
-		break;
-	case AF_INET:
-	case AF_INET6:
-		sock_name = proto_name(s->type);
-		break;
-	case AF_PACKET:
-		sock_name = s->type == SOCK_RAW ? "p_raw" : "p_dgr";
-		break;
-	case AF_NETLINK:
-		sock_name = "nl";
-		break;
-	case AF_TIPC:
-		sock_name = tipc_netid_name(s->type);
-		break;
-	case AF_VSOCK:
-		sock_name = vsock_netid_name(s->type);
-		break;
-	case AF_XDP:
-		sock_name = "xdp";
-		break;
-	default:
-		sock_name = "unknown";
-	}
-
-	if (is_sctp_assoc(s, sock_name)) {
-		field_set(COL_STATE);		/* Empty Netid field */
-		out("`- %s", sctp_sstate_name[s->state]);
-	} else {
-		field_set(COL_NETID);
-		out("%s", sock_name);
-		field_set(COL_STATE);
-		out("%s", sstate_name[s->state]);
-	}
-
-	field_set(COL_RECVQ);
-	out("%-6d", s->rq);
-	field_set(COL_SENDQ);
-	out("%-6d", s->wq);
-	field_set(COL_ADDR);
+	printf("%-6d %-6d ", s->rq, s->wq);
 }
 
 static void sock_details_print(struct sockstat *s)
 {
 	if (s->uid)
-		out(" uid:%u", s->uid);
+		printf(" uid:%u", s->uid);
 
-	out(" ino:%u", s->ino);
-	out(" sk:%llx", s->sk);
+	printf(" ino:%u", s->ino);
+	printf(" sk:%llx", s->sk);
 
 	if (s->mark)
-		out(" fwmark:0x%x", s->mark);
+		printf(" fwmark:0x%x", s->mark);
+}
+
+static void sock_addr_print_width(int addr_len, const char *addr, char *delim,
+		int port_len, const char *port, const char *ifname)
+{
+	if (ifname) {
+		printf("%*s%%%s%s%-*s ", addr_len, addr, ifname, delim,
+				port_len, port);
+	}
+	else {
+		printf("%*s%s%-*s ", addr_len, addr, delim, port_len, port);
+	}
 }
 
 static void sock_addr_print(const char *addr, char *delim, const char *port,
 		const char *ifname)
 {
-	if (ifname)
-		out("%s" "%%" "%s%s", addr, ifname, delim);
-	else
-		out("%s%s", addr, delim);
-
-	field_next();
-	out("%s", port);
-	field_next();
+	sock_addr_print_width(addr_width, addr, delim, serv_width, port, ifname);
 }
 
-static const char *print_ms_timer(unsigned int timeout)
+static const char *tmr_name[] = {
+	"off",
+	"on",
+	"keepalive",
+	"timewait",
+	"persist",
+	"unknown"
+};
+
+static const char *print_ms_timer(int timeout)
 {
 	static char buf[64];
 	int secs, msecs, minutes;
-
+	if (timeout < 0)
+		timeout = 0;
 	secs = timeout/1000;
 	minutes = secs/60;
 	secs = secs%60;
@@ -1448,7 +873,7 @@
 	const char *proto;
 };
 
-static struct scache *rlist;
+struct scache *rlist;
 
 static void init_service_resolver(void)
 {
@@ -1468,7 +893,7 @@
 		struct scache *c;
 
 		if (sscanf(buf, "%u %*d %s %u %s",
-			   &progn, proto, &port, prog+4) != 4)
+		           &progn, proto, &port, prog+4) != 4)
 			continue;
 
 		if (!(c = malloc(sizeof(*c))))
@@ -1480,8 +905,6 @@
 			c->proto = TCP_PROTO;
 		else if (strcmp(proto, UDP_PROTO) == 0)
 			c->proto = UDP_PROTO;
-		else if (strcmp(proto, SCTP_PROTO) == 0)
-			c->proto = SCTP_PROTO;
 		else
 			c->proto = NULL;
 		c->next = rlist;
@@ -1498,11 +921,10 @@
  */
 static int is_ephemeral(int port)
 {
-	static int min = 0, max;
+	static int min = 0, max = 0;
 
 	if (!min) {
 		FILE *f = ephemeral_ports_open();
-
 		if (!f || fscanf(f, "%d %d", &min, &max) < 2) {
 			min = 1024;
 			max = 4999;
@@ -1526,7 +948,6 @@
 	if (!is_ephemeral(port)) {
 		static int notfirst;
 		struct servent *se;
-
 		if (!notfirst) {
 			setservent(1);
 			notfirst = 1;
@@ -1555,7 +976,7 @@
 		return buf;
 	}
 
-	if (numeric)
+	if (!resolve_services)
 		goto do_numeric;
 
 	if (dg_proto == RAW_PROTO)
@@ -1588,42 +1009,44 @@
 	return buf;
 }
 
-static void inet_addr_print(const inet_prefix *a, int port,
-			    unsigned int ifindex, bool v6only)
+static void inet_addr_print(const inet_prefix *a, int port, unsigned int ifindex)
 {
 	char buf[1024];
 	const char *ap = buf;
+	int est_len = addr_width;
 	const char *ifname = NULL;
 
 	if (a->family == AF_INET) {
-		ap = format_host(AF_INET, 4, a->data);
-	} else {
-		if (!v6only &&
-		    !memcmp(a->data, &in6addr_any, sizeof(in6addr_any))) {
+		if (a->data[0] == 0) {
 			buf[0] = '*';
 			buf[1] = 0;
 		} else {
-			ap = format_host(a->family, 16, a->data);
-
-			/* Numeric IPv6 addresses should be bracketed */
-			if (strchr(ap, ':')) {
-				snprintf(buf, sizeof(buf),
-					 "[%s]", ap);
-				ap = buf;
-			}
+			ap = format_host(AF_INET, 4, a->data, buf, sizeof(buf));
 		}
+	} else {
+		ap = format_host(a->family, 16, a->data, buf, sizeof(buf));
+		est_len = strlen(ap);
+		if (est_len <= addr_width)
+			est_len = addr_width;
+		else
+			est_len = addr_width + ((est_len-addr_width+3)/4)*4;
 	}
 
-	if (ifindex)
-		ifname = ll_index_to_name(ifindex);
+	if (ifindex) {
+		ifname   = ll_index_to_name(ifindex);
+		est_len -= strlen(ifname) + 1;  /* +1 for percent char */
+		if (est_len < 0)
+			est_len = 0;
+	}
 
-	sock_addr_print(ap, ":", resolve_service(port), ifname);
+	sock_addr_print_width(est_len, ap, ":", serv_width, resolve_service(port),
+			ifname);
 }
 
-struct aafilter {
+struct aafilter
+{
 	inet_prefix	addr;
 	int		port;
-	unsigned int	iface;
 	__u32		mark;
 	__u32		mask;
 	struct aafilter *next;
@@ -1642,7 +1065,6 @@
 		if (a->data[0] == 0 && a->data[1] == 0 &&
 		    a->data[2] == htonl(0xffff)) {
 			inet_prefix tmp = *a;
-
 			tmp.data[0] = a->data[3];
 			return inet_addr_match(&tmp, p, plen);
 		}
@@ -1653,7 +1075,6 @@
 static int unix_match(const inet_prefix *a, const inet_prefix *p)
 {
 	char *addr, *pattern;
-
 	memcpy(&addr, a->data, sizeof(addr));
 	memcpy(&pattern, p->data, sizeof(pattern));
 	if (pattern == NULL)
@@ -1670,7 +1091,6 @@
 	{
 		if (s->local.family == AF_UNIX) {
 			char *p;
-
 			memcpy(&p, s->local.data, sizeof(p));
 			return p == NULL || (p[0] == '@' && strlen(p) == 6 &&
 					     strspn(p+1, "0123456789abcdef") == 5);
@@ -1679,15 +1099,12 @@
 			return s->lport == 0 && s->local.data[0] == 0;
 		if (s->local.family == AF_NETLINK)
 			return s->lport < 0;
-		if (s->local.family == AF_VSOCK)
-			return s->lport > 1023;
 
 		return is_ephemeral(s->lport);
 	}
 		case SSF_DCOND:
 	{
-		struct aafilter *a = (void *)f->pred;
-
+		struct aafilter *a = (void*)f->pred;
 		if (a->addr.family == AF_UNIX)
 			return unix_match(&s->remote, &a->addr);
 		if (a->port != -1 && a->port != s->rport)
@@ -1703,8 +1120,7 @@
 	}
 		case SSF_SCOND:
 	{
-		struct aafilter *a = (void *)f->pred;
-
+		struct aafilter *a = (void*)f->pred;
 		if (a->addr.family == AF_UNIX)
 			return unix_match(&s->local, &a->addr);
 		if (a->port != -1 && a->port != s->lport)
@@ -1720,34 +1136,24 @@
 	}
 		case SSF_D_GE:
 	{
-		struct aafilter *a = (void *)f->pred;
-
+		struct aafilter *a = (void*)f->pred;
 		return s->rport >= a->port;
 	}
 		case SSF_D_LE:
 	{
-		struct aafilter *a = (void *)f->pred;
-
+		struct aafilter *a = (void*)f->pred;
 		return s->rport <= a->port;
 	}
 		case SSF_S_GE:
 	{
-		struct aafilter *a = (void *)f->pred;
-
+		struct aafilter *a = (void*)f->pred;
 		return s->lport >= a->port;
 	}
 		case SSF_S_LE:
 	{
-		struct aafilter *a = (void *)f->pred;
-
+		struct aafilter *a = (void*)f->pred;
 		return s->lport <= a->port;
 	}
-		case SSF_DEVCOND:
-	{
-		struct aafilter *a = (void *)f->pred;
-
-		return s->iface == a->iface;
-	}
 		case SSF_MARKMASK:
 	{
 		struct aafilter *a = (void *)f->pred;
@@ -1770,8 +1176,7 @@
 static void ssfilter_patch(char *a, int len, int reloc)
 {
 	while (len > 0) {
-		struct inet_diag_bc_op *op = (struct inet_diag_bc_op *)a;
-
+		struct inet_diag_bc_op *op = (struct inet_diag_bc_op*)a;
 		if (op->no == len+4)
 			op->no += reloc;
 		len -= op->yes;
@@ -1786,20 +1191,20 @@
 	switch (f->type) {
 		case SSF_S_AUTO:
 	{
-		if (!(*bytecode = malloc(4))) abort();
-		((struct inet_diag_bc_op *)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_AUTO, 4, 8 };
+		if (!(*bytecode=malloc(4))) abort();
+		((struct inet_diag_bc_op*)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_AUTO, 4, 8 };
 		return 4;
 	}
 		case SSF_DCOND:
 		case SSF_SCOND:
 	{
-		struct aafilter *a = (void *)f->pred;
+		struct aafilter *a = (void*)f->pred;
 		struct aafilter *b;
 		char *ptr;
 		int  code = (f->type == SSF_DCOND ? INET_DIAG_BC_D_COND : INET_DIAG_BC_S_COND);
 		int len = 0;
 
-		for (b = a; b; b = b->next) {
+		for (b=a; b; b=b->next) {
 			len += 4 + sizeof(struct inet_diag_hostcond);
 			if (a->addr.family == AF_INET6)
 				len += 16;
@@ -1810,11 +1215,11 @@
 		}
 		if (!(ptr = malloc(len))) abort();
 		*bytecode = ptr;
-		for (b = a; b; b = b->next) {
+		for (b=a; b; b=b->next) {
 			struct inet_diag_bc_op *op = (struct inet_diag_bc_op *)ptr;
 			int alen = (a->addr.family == AF_INET6 ? 16 : 4);
 			int oplen = alen + 4 + sizeof(struct inet_diag_hostcond);
-			struct inet_diag_hostcond *cond = (struct inet_diag_hostcond *)(ptr+4);
+			struct inet_diag_hostcond *cond = (struct inet_diag_hostcond*)(ptr+4);
 
 			*op = (struct inet_diag_bc_op){ code, oplen, oplen+4 };
 			cond->family = a->addr.family;
@@ -1832,53 +1237,43 @@
 	}
 		case SSF_D_GE:
 	{
-		struct aafilter *x = (void *)f->pred;
-
-		if (!(*bytecode = malloc(8))) abort();
-		((struct inet_diag_bc_op *)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_D_GE, 8, 12 };
-		((struct inet_diag_bc_op *)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
+		struct aafilter *x = (void*)f->pred;
+		if (!(*bytecode=malloc(8))) abort();
+		((struct inet_diag_bc_op*)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_D_GE, 8, 12 };
+		((struct inet_diag_bc_op*)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
 		return 8;
 	}
 		case SSF_D_LE:
 	{
-		struct aafilter *x = (void *)f->pred;
-
-		if (!(*bytecode = malloc(8))) abort();
-		((struct inet_diag_bc_op *)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_D_LE, 8, 12 };
-		((struct inet_diag_bc_op *)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
+		struct aafilter *x = (void*)f->pred;
+		if (!(*bytecode=malloc(8))) abort();
+		((struct inet_diag_bc_op*)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_D_LE, 8, 12 };
+		((struct inet_diag_bc_op*)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
 		return 8;
 	}
 		case SSF_S_GE:
 	{
-		struct aafilter *x = (void *)f->pred;
-
-		if (!(*bytecode = malloc(8))) abort();
-		((struct inet_diag_bc_op *)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_S_GE, 8, 12 };
-		((struct inet_diag_bc_op *)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
+		struct aafilter *x = (void*)f->pred;
+		if (!(*bytecode=malloc(8))) abort();
+		((struct inet_diag_bc_op*)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_S_GE, 8, 12 };
+		((struct inet_diag_bc_op*)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
 		return 8;
 	}
 		case SSF_S_LE:
 	{
-		struct aafilter *x = (void *)f->pred;
-
-		if (!(*bytecode = malloc(8))) abort();
-		((struct inet_diag_bc_op *)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_S_LE, 8, 12 };
-		((struct inet_diag_bc_op *)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
+		struct aafilter *x = (void*)f->pred;
+		if (!(*bytecode=malloc(8))) abort();
+		((struct inet_diag_bc_op*)*bytecode)[0] = (struct inet_diag_bc_op){ INET_DIAG_BC_S_LE, 8, 12 };
+		((struct inet_diag_bc_op*)*bytecode)[1] = (struct inet_diag_bc_op){ 0, 0, x->port };
 		return 8;
 	}
 
 		case SSF_AND:
 	{
-		char *a1 = NULL, *a2 = NULL, *a;
+		char *a1, *a2, *a;
 		int l1, l2;
-
 		l1 = ssfilter_bytecompile(f->pred, &a1);
 		l2 = ssfilter_bytecompile(f->post, &a2);
-		if (!l1 || !l2) {
-			free(a1);
-			free(a2);
-			return 0;
-		}
 		if (!(a = malloc(l1+l2))) abort();
 		memcpy(a, a1, l1);
 		memcpy(a+l1, a2, l2);
@@ -1889,46 +1284,30 @@
 	}
 		case SSF_OR:
 	{
-		char *a1 = NULL, *a2 = NULL, *a;
+		char *a1, *a2, *a;
 		int l1, l2;
-
 		l1 = ssfilter_bytecompile(f->pred, &a1);
 		l2 = ssfilter_bytecompile(f->post, &a2);
-		if (!l1 || !l2) {
-			free(a1);
-			free(a2);
-			return 0;
-		}
 		if (!(a = malloc(l1+l2+4))) abort();
 		memcpy(a, a1, l1);
 		memcpy(a+l1+4, a2, l2);
 		free(a1); free(a2);
-		*(struct inet_diag_bc_op *)(a+l1) = (struct inet_diag_bc_op){ INET_DIAG_BC_JMP, 4, l2+4 };
+		*(struct inet_diag_bc_op*)(a+l1) = (struct inet_diag_bc_op){ INET_DIAG_BC_JMP, 4, l2+4 };
 		*bytecode = a;
 		return l1+l2+4;
 	}
 		case SSF_NOT:
 	{
-		char *a1 = NULL, *a;
+		char *a1, *a;
 		int l1;
-
 		l1 = ssfilter_bytecompile(f->pred, &a1);
-		if (!l1) {
-			free(a1);
-			return 0;
-		}
 		if (!(a = malloc(l1+4))) abort();
 		memcpy(a, a1, l1);
 		free(a1);
-		*(struct inet_diag_bc_op *)(a+l1) = (struct inet_diag_bc_op){ INET_DIAG_BC_JMP, 4, 8 };
+		*(struct inet_diag_bc_op*)(a+l1) = (struct inet_diag_bc_op){ INET_DIAG_BC_JMP, 4, 8 };
 		*bytecode = a;
 		return l1+4;
 	}
-		case SSF_DEVCOND:
-	{
-		/* bytecompile for SSF_DEVCOND not supported yet */
-		return 0;
-	}
 		case SSF_MARKMASK:
 	{
 		struct aafilter *a = (void *)f->pred;
@@ -1939,7 +1318,7 @@
 		int inslen = sizeof(struct instr);
 
 		if (!(*bytecode = malloc(inslen))) abort();
-		((struct instr *)*bytecode)[0] = (struct instr) {
+                ((struct instr *)*bytecode)[0] = (struct instr) {
 			{ INET_DIAG_BC_MARK_COND, inslen, inslen + 4 },
 			{ a->mark, a->mask},
 		};
@@ -1966,11 +1345,11 @@
 
 	while (*ptr) {
 		struct aafilter *b = a;
-
 		if (a->addr.bitlen) {
 			if ((b = malloc(sizeof(*b))) == NULL)
 				return cnt;
 			*b = *a;
+			b->next = a->next;
 			a->next = b;
 		}
 		memcpy(b->addr.data, *ptr, len);
@@ -2005,12 +1384,11 @@
 	return !cnt;
 }
 
-static int xll_initted;
+static int xll_initted = 0;
 
 static void xll_init(void)
 {
 	struct rtnl_handle rth;
-
 	if (rtnl_open(&rth, 0) < 0)
 		exit(1);
 
@@ -2033,38 +1411,6 @@
 	return ll_name_to_index(dev);
 }
 
-void *parse_devcond(char *name)
-{
-	struct aafilter a = { .iface = 0 };
-	struct aafilter *res;
-
-	a.iface = xll_name_to_index(name);
-	if (a.iface == 0) {
-		char *end;
-		unsigned long n;
-
-		n = strtoul(name, &end, 0);
-		if (!end || end == name || *end || n > UINT_MAX)
-			return NULL;
-
-		a.iface = n;
-	}
-
-	res = malloc(sizeof(*res));
-	*res = a;
-
-	return res;
-}
-
-static void vsock_set_inet_prefix(inet_prefix *a, __u32 cid)
-{
-	*a = (inet_prefix){
-		.bytelen = sizeof(cid),
-		.family = AF_VSOCK,
-	};
-	memcpy(a->data, &cid, sizeof(cid));
-}
-
 void *parse_hostcond(char *addr, bool is_port)
 {
 	char *port = NULL;
@@ -2075,10 +1421,9 @@
 
 	if (fam == AF_UNIX || strncmp(addr, "unix:", 5) == 0) {
 		char *p;
-
 		a.addr.family = AF_UNIX;
 		if (strncmp(addr, "unix:", 5) == 0)
-			addr += 5;
+			addr+=5;
 		p = strdup(addr);
 		a.addr.bitlen = 8*strlen(p);
 		memcpy(a.addr.data, &p, sizeof(p));
@@ -2090,7 +1435,7 @@
 		a.addr.family = AF_PACKET;
 		a.addr.bitlen = 0;
 		if (strncmp(addr, "link:", 5) == 0)
-			addr += 5;
+			addr+=5;
 		port = strchr(addr, ':');
 		if (port) {
 			*port = 0;
@@ -2103,7 +1448,6 @@
 		}
 		if (addr[0] && strcmp(addr, "*")) {
 			unsigned short tmp;
-
 			a.addr.bitlen = 32;
 			if (ll_proto_a2n(&tmp, addr))
 				return NULL;
@@ -2117,7 +1461,7 @@
 		a.addr.family = AF_NETLINK;
 		a.addr.bitlen = 0;
 		if (strncmp(addr, "netlink:", 8) == 0)
-			addr += 8;
+			addr+=8;
 		port = strchr(addr, ':');
 		if (port) {
 			*port = 0;
@@ -2139,37 +1483,6 @@
 		goto out;
 	}
 
-	if (fam == AF_VSOCK || strncmp(addr, "vsock:", 6) == 0) {
-		__u32 cid = ~(__u32)0;
-
-		a.addr.family = AF_VSOCK;
-		if (strncmp(addr, "vsock:", 6) == 0)
-			addr += 6;
-
-		if (is_port)
-			port = addr;
-		else {
-			port = strchr(addr, ':');
-			if (port) {
-				*port = '\0';
-				port++;
-			}
-		}
-
-		if (port && strcmp(port, "*") &&
-		    get_u32((__u32 *)&a.port, port, 0))
-			return NULL;
-
-		if (addr[0] && strcmp(addr, "*")) {
-			a.addr.bitlen = 32;
-			if (get_u32(&cid, addr, 0))
-				return NULL;
-		}
-		vsock_set_inet_prefix(&a.addr, cid);
-		fam = AF_VSOCK;
-		goto out;
-	}
-
 	if (fam == AF_INET || !strncmp(addr, "inet:", 5)) {
 		fam = AF_INET;
 		if (!strncmp(addr, "inet:", 5))
@@ -2203,7 +1516,6 @@
 			if (get_integer(&a.port, port, 0)) {
 				struct servent *se1 = NULL;
 				struct servent *se2 = NULL;
-
 				if (current_filter.dbs&(1<<UDP_DB))
 					se1 = getservbyname(port, UDP_PROTO);
 				if (current_filter.dbs&(1<<TCP_DB))
@@ -2218,7 +1530,6 @@
 					a.port = ntohs(se1->s_port);
 				} else {
 					struct scache *s;
-
 					for (s = rlist; s; s = s->next) {
 						if ((s->proto == UDP_PROTO &&
 						     (current_filter.dbs&(1<<UDP_DB))) ||
@@ -2241,7 +1552,7 @@
 			}
 		}
 	}
-	if (!is_port && *addr && *addr != '*') {
+	if (!is_port && addr && *addr && *addr != '*') {
 		if (get_prefix_1(&a.addr, addr, fam)) {
 			if (get_dns_host(&a, addr, fam)) {
 				fprintf(stderr, "Error: an inet prefix is expected rather than \"%s\".\n", addr);
@@ -2252,10 +1563,9 @@
 
 out:
 	if (fam != AF_UNSPEC) {
-		int states = f->states;
 		f->families = 0;
 		filter_af_set(f, fam);
-		filter_states_set(f, states);
+		filter_states_set(f, 0);
 	}
 
 	res = malloc(sizeof(*res));
@@ -2283,42 +1593,53 @@
 	return res;
 }
 
-static void proc_ctx_print(struct sockstat *s)
+static char *proto_name(int protocol)
 {
-	char *buf;
+	switch (protocol) {
+	case 0:
+		return "raw";
+	case IPPROTO_UDP:
+		return "udp";
+	case IPPROTO_TCP:
+		return "tcp";
+	case IPPROTO_DCCP:
+		return "dccp";
+	}
+
+	return "???";
+}
+
+static void inet_stats_print(struct sockstat *s, int protocol)
+{
+	char *buf = NULL;
+
+	sock_state_print(s, proto_name(protocol));
+
+	inet_addr_print(&s->local, s->lport, s->iface);
+	inet_addr_print(&s->remote, s->rport, 0);
 
 	if (show_proc_ctx || show_sock_ctx) {
 		if (find_entry(s->ino, &buf,
 				(show_proc_ctx & show_sock_ctx) ?
 				PROC_SOCK_CTX : PROC_CTX) > 0) {
-			out(" users:(%s)", buf);
+			printf(" users:(%s)", buf);
 			free(buf);
 		}
 	} else if (show_users) {
 		if (find_entry(s->ino, &buf, USERS) > 0) {
-			out(" users:(%s)", buf);
+			printf(" users:(%s)", buf);
 			free(buf);
 		}
 	}
 }
 
-static void inet_stats_print(struct sockstat *s, bool v6only)
-{
-	sock_state_print(s);
-
-	inet_addr_print(&s->local, s->lport, s->iface, v6only);
-	inet_addr_print(&s->remote, s->rport, 0, v6only);
-
-	proc_ctx_print(s);
-}
-
 static int proc_parse_inet_addr(char *loc, char *rem, int family, struct
-		sockstat * s)
+		sockstat *s)
 {
 	s->local.family = s->remote.family = family;
 	if (family == AF_INET) {
-		sscanf(loc, "%x:%x", s->local.data, (unsigned *)&s->lport);
-		sscanf(rem, "%x:%x", s->remote.data, (unsigned *)&s->rport);
+		sscanf(loc, "%x:%x", s->local.data, (unsigned*)&s->lport);
+		sscanf(rem, "%x:%x", s->remote.data, (unsigned*)&s->rport);
 		s->local.bytelen = s->remote.bytelen = 4;
 		return 0;
 	} else {
@@ -2363,251 +1684,120 @@
 
 static char *sprint_bw(char *buf, double bw)
 {
-	if (numeric)
-		sprintf(buf, "%.0f", bw);
-	else if (bw > 1000000.)
-		sprintf(buf, "%.1fM", bw / 1000000.);
+	if (bw > 1000000.)
+		sprintf(buf,"%.1fM", bw / 1000000.);
 	else if (bw > 1000.)
-		sprintf(buf, "%.1fK", bw / 1000.);
+		sprintf(buf,"%.1fK", bw / 1000.);
 	else
 		sprintf(buf, "%g", bw);
 
 	return buf;
 }
 
-static void sctp_stats_print(struct sctp_info *s)
-{
-	if (s->sctpi_tag)
-		out(" tag:%x", s->sctpi_tag);
-	if (s->sctpi_state)
-		out(" state:%s", sctp_sstate_name[s->sctpi_state]);
-	if (s->sctpi_rwnd)
-		out(" rwnd:%d", s->sctpi_rwnd);
-	if (s->sctpi_unackdata)
-		out(" unackdata:%d", s->sctpi_unackdata);
-	if (s->sctpi_penddata)
-		out(" penddata:%d", s->sctpi_penddata);
-	if (s->sctpi_instrms)
-		out(" instrms:%d", s->sctpi_instrms);
-	if (s->sctpi_outstrms)
-		out(" outstrms:%d", s->sctpi_outstrms);
-	if (s->sctpi_inqueue)
-		out(" inqueue:%d", s->sctpi_inqueue);
-	if (s->sctpi_outqueue)
-		out(" outqueue:%d", s->sctpi_outqueue);
-	if (s->sctpi_overall_error)
-		out(" overerr:%d", s->sctpi_overall_error);
-	if (s->sctpi_max_burst)
-		out(" maxburst:%d", s->sctpi_max_burst);
-	if (s->sctpi_maxseg)
-		out(" maxseg:%d", s->sctpi_maxseg);
-	if (s->sctpi_peer_rwnd)
-		out(" prwnd:%d", s->sctpi_peer_rwnd);
-	if (s->sctpi_peer_tag)
-		out(" ptag:%x", s->sctpi_peer_tag);
-	if (s->sctpi_peer_capable)
-		out(" pcapable:%d", s->sctpi_peer_capable);
-	if (s->sctpi_peer_sack)
-		out(" psack:%d", s->sctpi_peer_sack);
-	if (s->sctpi_s_autoclose)
-		out(" autoclose:%d", s->sctpi_s_autoclose);
-	if (s->sctpi_s_adaptation_ind)
-		out(" adapind:%d", s->sctpi_s_adaptation_ind);
-	if (s->sctpi_s_pd_point)
-		out(" pdpoint:%d", s->sctpi_s_pd_point);
-	if (s->sctpi_s_nodelay)
-		out(" nodelay:%d", s->sctpi_s_nodelay);
-	if (s->sctpi_s_disable_fragments)
-		out(" nofrag:%d", s->sctpi_s_disable_fragments);
-	if (s->sctpi_s_v4mapped)
-		out(" v4mapped:%d", s->sctpi_s_v4mapped);
-	if (s->sctpi_s_frag_interleave)
-		out(" fraginl:%d", s->sctpi_s_frag_interleave);
-}
-
 static void tcp_stats_print(struct tcpstat *s)
 {
 	char b1[64];
 
 	if (s->has_ts_opt)
-		out(" ts");
+		printf(" ts");
 	if (s->has_sack_opt)
-		out(" sack");
+		printf(" sack");
 	if (s->has_ecn_opt)
-		out(" ecn");
+		printf(" ecn");
 	if (s->has_ecnseen_opt)
-		out(" ecnseen");
+		printf(" ecnseen");
 	if (s->has_fastopen_opt)
-		out(" fastopen");
+		printf(" fastopen");
 	if (s->cong_alg[0])
-		out(" %s", s->cong_alg);
+		printf(" %s", s->cong_alg);
 	if (s->has_wscale_opt)
-		out(" wscale:%d,%d", s->snd_wscale, s->rcv_wscale);
+		printf(" wscale:%d,%d", s->snd_wscale, s->rcv_wscale);
 	if (s->rto)
-		out(" rto:%g", s->rto);
+		printf(" rto:%g", s->rto);
 	if (s->backoff)
-		out(" backoff:%u", s->backoff);
+		printf(" backoff:%u", s->backoff);
 	if (s->rtt)
-		out(" rtt:%g/%g", s->rtt, s->rttvar);
+		printf(" rtt:%g/%g", s->rtt, s->rttvar);
 	if (s->ato)
-		out(" ato:%g", s->ato);
+		printf(" ato:%g", s->ato);
 
 	if (s->qack)
-		out(" qack:%d", s->qack);
+		printf(" qack:%d", s->qack);
 	if (s->qack & 1)
-		out(" bidir");
+		printf(" bidir");
 
 	if (s->mss)
-		out(" mss:%d", s->mss);
-	if (s->pmtu)
-		out(" pmtu:%u", s->pmtu);
-	if (s->rcv_mss)
-		out(" rcvmss:%d", s->rcv_mss);
-	if (s->advmss)
-		out(" advmss:%d", s->advmss);
+		printf(" mss:%d", s->mss);
 	if (s->cwnd)
-		out(" cwnd:%u", s->cwnd);
+		printf(" cwnd:%d", s->cwnd);
 	if (s->ssthresh)
-		out(" ssthresh:%d", s->ssthresh);
+		printf(" ssthresh:%d", s->ssthresh);
 
-	if (s->bytes_sent)
-		out(" bytes_sent:%llu", s->bytes_sent);
-	if (s->bytes_retrans)
-		out(" bytes_retrans:%llu", s->bytes_retrans);
 	if (s->bytes_acked)
-		out(" bytes_acked:%llu", s->bytes_acked);
+		printf(" bytes_acked:%llu", s->bytes_acked);
 	if (s->bytes_received)
-		out(" bytes_received:%llu", s->bytes_received);
+		printf(" bytes_received:%llu", s->bytes_received);
 	if (s->segs_out)
-		out(" segs_out:%u", s->segs_out);
+		printf(" segs_out:%u", s->segs_out);
 	if (s->segs_in)
-		out(" segs_in:%u", s->segs_in);
-	if (s->data_segs_out)
-		out(" data_segs_out:%u", s->data_segs_out);
-	if (s->data_segs_in)
-		out(" data_segs_in:%u", s->data_segs_in);
+		printf(" segs_in:%u", s->segs_in);
 
 	if (s->dctcp && s->dctcp->enabled) {
 		struct dctcpstat *dctcp = s->dctcp;
 
-		out(" dctcp:(ce_state:%u,alpha:%u,ab_ecn:%u,ab_tot:%u)",
-			     dctcp->ce_state, dctcp->alpha, dctcp->ab_ecn,
-			     dctcp->ab_tot);
+		printf(" dctcp:(ce_state:%u,alpha:%u,ab_ecn:%u,ab_tot:%u)",
+				dctcp->ce_state, dctcp->alpha, dctcp->ab_ecn,
+				dctcp->ab_tot);
 	} else if (s->dctcp) {
-		out(" dctcp:fallback_mode");
-	}
-
-	if (s->bbr_info) {
-		__u64 bw;
-
-		bw = s->bbr_info->bbr_bw_hi;
-		bw <<= 32;
-		bw |= s->bbr_info->bbr_bw_lo;
-
-		out(" bbr:(bw:%sbps,mrtt:%g",
-		    sprint_bw(b1, bw * 8.0),
-		    (double)s->bbr_info->bbr_min_rtt / 1000.0);
-		if (s->bbr_info->bbr_pacing_gain)
-			out(",pacing_gain:%g",
-			    (double)s->bbr_info->bbr_pacing_gain / 256.0);
-		if (s->bbr_info->bbr_cwnd_gain)
-			out(",cwnd_gain:%g",
-			    (double)s->bbr_info->bbr_cwnd_gain / 256.0);
-		out(")");
+		printf(" dctcp:fallback_mode");
 	}
 
 	if (s->send_bps)
-		out(" send %sbps", sprint_bw(b1, s->send_bps));
+		printf(" send %sbps", sprint_bw(b1, s->send_bps));
 	if (s->lastsnd)
-		out(" lastsnd:%u", s->lastsnd);
+		printf(" lastsnd:%u", s->lastsnd);
 	if (s->lastrcv)
-		out(" lastrcv:%u", s->lastrcv);
+		printf(" lastrcv:%u", s->lastrcv);
 	if (s->lastack)
-		out(" lastack:%u", s->lastack);
+		printf(" lastack:%u", s->lastack);
 
 	if (s->pacing_rate) {
-		out(" pacing_rate %sbps", sprint_bw(b1, s->pacing_rate));
+		printf(" pacing_rate %sbps", sprint_bw(b1, s->pacing_rate));
 		if (s->pacing_rate_max)
-			out("/%sbps", sprint_bw(b1, s->pacing_rate_max));
-	}
-
-	if (s->delivery_rate)
-		out(" delivery_rate %sbps", sprint_bw(b1, s->delivery_rate));
-	if (s->delivered)
-		out(" delivered:%u", s->delivered);
-	if (s->delivered_ce)
-		out(" delivered_ce:%u", s->delivered_ce);
-	if (s->app_limited)
-		out(" app_limited");
-
-	if (s->busy_time) {
-		out(" busy:%llums", s->busy_time / 1000);
-		if (s->rwnd_limited)
-			out(" rwnd_limited:%llums(%.1f%%)",
-			    s->rwnd_limited / 1000,
-			    100.0 * s->rwnd_limited / s->busy_time);
-		if (s->sndbuf_limited)
-			out(" sndbuf_limited:%llums(%.1f%%)",
-			    s->sndbuf_limited / 1000,
-			    100.0 * s->sndbuf_limited / s->busy_time);
+				printf("/%sbps", sprint_bw(b1,
+							s->pacing_rate_max));
 	}
 
 	if (s->unacked)
-		out(" unacked:%u", s->unacked);
+		printf(" unacked:%u", s->unacked);
 	if (s->retrans || s->retrans_total)
-		out(" retrans:%u/%u", s->retrans, s->retrans_total);
+		printf(" retrans:%u/%u", s->retrans, s->retrans_total);
 	if (s->lost)
-		out(" lost:%u", s->lost);
+		printf(" lost:%u", s->lost);
 	if (s->sacked && s->ss.state != SS_LISTEN)
-		out(" sacked:%u", s->sacked);
-	if (s->dsack_dups)
-		out(" dsack_dups:%u", s->dsack_dups);
+		printf(" sacked:%u", s->sacked);
 	if (s->fackets)
-		out(" fackets:%u", s->fackets);
+		printf(" fackets:%u", s->fackets);
 	if (s->reordering != 3)
-		out(" reordering:%d", s->reordering);
-	if (s->reord_seen)
-		out(" reord_seen:%d", s->reord_seen);
+		printf(" reordering:%d", s->reordering);
 	if (s->rcv_rtt)
-		out(" rcv_rtt:%g", s->rcv_rtt);
+		printf(" rcv_rtt:%g", s->rcv_rtt);
 	if (s->rcv_space)
-		out(" rcv_space:%d", s->rcv_space);
-	if (s->rcv_ssthresh)
-		out(" rcv_ssthresh:%u", s->rcv_ssthresh);
-	if (s->not_sent)
-		out(" notsent:%u", s->not_sent);
-	if (s->min_rtt)
-		out(" minrtt:%g", s->min_rtt);
+		printf(" rcv_space:%d", s->rcv_space);
 }
 
 static void tcp_timer_print(struct tcpstat *s)
 {
-	static const char * const tmr_name[] = {
-		"off",
-		"on",
-		"keepalive",
-		"timewait",
-		"persist",
-		"unknown"
-	};
-
 	if (s->timer) {
 		if (s->timer > 4)
 			s->timer = 5;
-		out(" timer:(%s,%s,%d)",
-			     tmr_name[s->timer],
-			     print_ms_timer(s->timeout),
-			     s->retrans);
+		printf(" timer:(%s,%s,%d)",
+				tmr_name[s->timer],
+				print_ms_timer(s->timeout),
+				s->retrans);
 	}
 }
 
-static void sctp_timer_print(struct tcpstat *s)
-{
-	if (s->timer)
-		out(" timer:(T3_RTX,%s,%d)",
-		    print_ms_timer(s->timeout), s->retrans);
-}
-
 static int tcp_show_line(char *line, const struct filter *f, int family)
 {
 	int rto = 0, ato = 0;
@@ -2621,7 +1811,6 @@
 		return -1;
 
 	int state = (data[1] >= 'A') ? (data[1] - 'A' + 10) : (data[1] - '0');
-
 	if (!(f->states & (1 << state)))
 		return 0;
 
@@ -2631,7 +1820,7 @@
 		return 0;
 
 	opt[0] = 0;
-	n = sscanf(data, "%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %u %d %[^\n]\n",
+	n = sscanf(data, "%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %d %d %[^\n]\n",
 		   &s.ss.state, &s.ss.wq, &s.ss.rq,
 		   &s.timer, &s.timeout, &s.retrans, &s.ss.uid, &s.probes,
 		   &s.ss.ino, &s.ss.refcnt, &s.ss.sk, &rto, &ato, &s.qack, &s.cwnd,
@@ -2654,9 +1843,8 @@
 	s.rto	    = (double)rto;
 	s.ssthresh  = s.ssthresh == -1 ? 0 : s.ssthresh;
 	s.rto	    = s.rto != 3 * hz  ? s.rto / hz : 0;
-	s.ss.type   = IPPROTO_TCP;
 
-	inet_stats_print(&s.ss, false);
+	inet_stats_print(&s.ss, IPPROTO_TCP);
 
 	if (show_options)
 		tcp_timer_print(&s);
@@ -2664,12 +1852,13 @@
 	if (show_details) {
 		sock_details_print(&s.ss);
 		if (opt[0])
-			out(" opt:\"%s\"", opt);
+			printf(" opt:\"%s\"", opt);
 	}
 
 	if (show_tcpinfo)
 		tcp_stats_print(&s);
 
+	printf("\n");
 	return 0;
 }
 
@@ -2685,7 +1874,6 @@
 
 	while (fgets(line, sizeof(line), fp) != NULL) {
 		int n = strlen(line);
-
 		if (n == 0 || line[n-1] != '\n') {
 			errno = -EINVAL;
 			return -1;
@@ -2712,45 +1900,31 @@
 			const struct inet_diag_meminfo *minfo =
 				RTA_DATA(tb[INET_DIAG_MEMINFO]);
 
-			out(" mem:(r%u,w%u,f%u,t%u)",
-				   minfo->idiag_rmem,
-				   minfo->idiag_wmem,
-				   minfo->idiag_fmem,
-				   minfo->idiag_tmem);
+			printf(" mem:(r%u,w%u,f%u,t%u)",
+					minfo->idiag_rmem,
+					minfo->idiag_wmem,
+					minfo->idiag_fmem,
+					minfo->idiag_tmem);
 		}
 		return;
 	}
 
 	skmeminfo = RTA_DATA(tb[attrtype]);
 
-	out(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u",
-		     skmeminfo[SK_MEMINFO_RMEM_ALLOC],
-		     skmeminfo[SK_MEMINFO_RCVBUF],
-		     skmeminfo[SK_MEMINFO_WMEM_ALLOC],
-		     skmeminfo[SK_MEMINFO_SNDBUF],
-		     skmeminfo[SK_MEMINFO_FWD_ALLOC],
-		     skmeminfo[SK_MEMINFO_WMEM_QUEUED],
-		     skmeminfo[SK_MEMINFO_OPTMEM]);
+	printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u",
+	       skmeminfo[SK_MEMINFO_RMEM_ALLOC],
+	       skmeminfo[SK_MEMINFO_RCVBUF],
+	       skmeminfo[SK_MEMINFO_WMEM_ALLOC],
+	       skmeminfo[SK_MEMINFO_SNDBUF],
+	       skmeminfo[SK_MEMINFO_FWD_ALLOC],
+	       skmeminfo[SK_MEMINFO_WMEM_QUEUED],
+	       skmeminfo[SK_MEMINFO_OPTMEM]);
 
 	if (RTA_PAYLOAD(tb[attrtype]) >=
 		(SK_MEMINFO_BACKLOG + 1) * sizeof(__u32))
-		out(",bl%u", skmeminfo[SK_MEMINFO_BACKLOG]);
+		printf(",bl%u", skmeminfo[SK_MEMINFO_BACKLOG]);
 
-	if (RTA_PAYLOAD(tb[attrtype]) >=
-		(SK_MEMINFO_DROPS + 1) * sizeof(__u32))
-		out(",d%u", skmeminfo[SK_MEMINFO_DROPS]);
-
-	out(")");
-}
-
-static void print_md5sig(struct tcp_diag_md5sig *sig)
-{
-	out("%s/%d=",
-	    format_host(sig->tcpm_family,
-			sig->tcpm_family == AF_INET6 ? 16 : 4,
-			&sig->tcpm_addr),
-	    sig->tcpm_prefixlen);
-	print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
+	printf(")");
 }
 
 #define TCPI_HAS_OPT(info, opt) !!(info->tcpi_options & (opt))
@@ -2804,8 +1978,6 @@
 		s.rttvar	 = (double)info->tcpi_rttvar / 1000;
 		s.ato		 = (double)info->tcpi_ato / 1000;
 		s.mss		 = info->tcpi_snd_mss;
-		s.rcv_mss	 = info->tcpi_rcv_mss;
-		s.advmss	 = info->tcpi_advmss;
 		s.rcv_space	 = info->tcpi_rcv_space;
 		s.rcv_rtt	 = (double)info->tcpi_rcv_rtt / 1000;
 		s.lastsnd	 = info->tcpi_last_data_sent;
@@ -2816,11 +1988,9 @@
 		s.retrans_total  = info->tcpi_total_retrans;
 		s.lost		 = info->tcpi_lost;
 		s.sacked	 = info->tcpi_sacked;
-		s.fackets	 = info->tcpi_fackets;
 		s.reordering	 = info->tcpi_reordering;
-		s.rcv_ssthresh   = info->tcpi_rcv_ssthresh;
+		s.rcv_space	 = info->tcpi_rcv_space;
 		s.cwnd		 = info->tcpi_snd_cwnd;
-		s.pmtu		 = info->tcpi_pmtu;
 
 		if (info->tcpi_snd_ssthresh < 0xFFFF)
 			s.ssthresh = info->tcpi_snd_ssthresh;
@@ -2850,16 +2020,6 @@
 			s.dctcp		= dctcp;
 		}
 
-		if (tb[INET_DIAG_BBRINFO]) {
-			const void *bbr_info = RTA_DATA(tb[INET_DIAG_BBRINFO]);
-			int len = min(RTA_PAYLOAD(tb[INET_DIAG_BBRINFO]),
-				      sizeof(*s.bbr_info));
-
-			s.bbr_info = calloc(1, sizeof(*s.bbr_info));
-			if (s.bbr_info && bbr_info)
-				memcpy(s.bbr_info, bbr_info, len);
-		}
-
 		if (rtt > 0 && info->tcpi_snd_mss && info->tcpi_snd_cwnd) {
 			s.send_bps = (double) info->tcpi_snd_cwnd *
 				(double)info->tcpi_snd_mss * 8000000. / rtt;
@@ -2877,150 +2037,51 @@
 		s.bytes_received = info->tcpi_bytes_received;
 		s.segs_out = info->tcpi_segs_out;
 		s.segs_in = info->tcpi_segs_in;
-		s.data_segs_out = info->tcpi_data_segs_out;
-		s.data_segs_in = info->tcpi_data_segs_in;
-		s.not_sent = info->tcpi_notsent_bytes;
-		if (info->tcpi_min_rtt && info->tcpi_min_rtt != ~0U)
-			s.min_rtt = (double) info->tcpi_min_rtt / 1000;
-		s.delivery_rate = info->tcpi_delivery_rate * 8.;
-		s.app_limited = info->tcpi_delivery_rate_app_limited;
-		s.busy_time = info->tcpi_busy_time;
-		s.rwnd_limited = info->tcpi_rwnd_limited;
-		s.sndbuf_limited = info->tcpi_sndbuf_limited;
-		s.delivered = info->tcpi_delivered;
-		s.delivered_ce = info->tcpi_delivered_ce;
-		s.dsack_dups = info->tcpi_dsack_dups;
-		s.reord_seen = info->tcpi_reord_seen;
-		s.bytes_sent = info->tcpi_bytes_sent;
-		s.bytes_retrans = info->tcpi_bytes_retrans;
 		tcp_stats_print(&s);
 		free(s.dctcp);
-		free(s.bbr_info);
-	}
-	if (tb[INET_DIAG_MD5SIG]) {
-		struct tcp_diag_md5sig *sig = RTA_DATA(tb[INET_DIAG_MD5SIG]);
-		int len = RTA_PAYLOAD(tb[INET_DIAG_MD5SIG]);
-
-		out(" md5keys:");
-		print_md5sig(sig++);
-		for (len -= sizeof(*sig); len > 0; len -= sizeof(*sig)) {
-			out(",");
-			print_md5sig(sig++);
-		}
 	}
 }
 
-static const char *format_host_sa(struct sockaddr_storage *sa)
+static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
 {
-	union {
-		struct sockaddr_in sin;
-		struct sockaddr_in6 sin6;
-	} *saddr = (void *)sa;
-
-	switch (sa->ss_family) {
-	case AF_INET:
-		return format_host(AF_INET, 4, &saddr->sin.sin_addr);
-	case AF_INET6:
-		return format_host(AF_INET6, 16, &saddr->sin6.sin6_addr);
-	default:
-		return "";
-	}
-}
-
-static void sctp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
-		struct rtattr *tb[])
-{
-	struct sockaddr_storage *sa;
-	int len;
-
-	print_skmeminfo(tb, INET_DIAG_SKMEMINFO);
-
-	if (tb[INET_DIAG_LOCALS]) {
-		len = RTA_PAYLOAD(tb[INET_DIAG_LOCALS]);
-		sa = RTA_DATA(tb[INET_DIAG_LOCALS]);
-
-		out(" locals:%s", format_host_sa(sa));
-		for (sa++, len -= sizeof(*sa); len > 0; sa++, len -= sizeof(*sa))
-			out(",%s", format_host_sa(sa));
-
-	}
-	if (tb[INET_DIAG_PEERS]) {
-		len = RTA_PAYLOAD(tb[INET_DIAG_PEERS]);
-		sa = RTA_DATA(tb[INET_DIAG_PEERS]);
-
-		out(" peers:%s", format_host_sa(sa));
-		for (sa++, len -= sizeof(*sa); len > 0; sa++, len -= sizeof(*sa))
-			out(",%s", format_host_sa(sa));
-	}
-	if (tb[INET_DIAG_INFO]) {
-		struct sctp_info *info;
-		len = RTA_PAYLOAD(tb[INET_DIAG_INFO]);
-
-		/* workaround for older kernels with less fields */
-		if (len < sizeof(*info)) {
-			info = alloca(sizeof(*info));
-			memcpy(info, RTA_DATA(tb[INET_DIAG_INFO]), len);
-			memset((char *)info + len, 0, sizeof(*info) - len);
-		} else
-			info = RTA_DATA(tb[INET_DIAG_INFO]);
-
-		sctp_stats_print(info);
-	}
-}
-
-static void parse_diag_msg(struct nlmsghdr *nlh, struct sockstat *s)
-{
-	struct rtattr *tb[INET_DIAG_MAX+1];
+	struct rtattr * tb[INET_DIAG_MAX+1];
 	struct inet_diag_msg *r = NLMSG_DATA(nlh);
+	struct sockstat s = {};
 
-	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr *)(r+1),
+	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
 		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
-	s->state	= r->idiag_state;
-	s->local.family	= s->remote.family = r->idiag_family;
-	s->lport	= ntohs(r->id.idiag_sport);
-	s->rport	= ntohs(r->id.idiag_dport);
-	s->wq		= r->idiag_wqueue;
-	s->rq		= r->idiag_rqueue;
-	s->ino		= r->idiag_inode;
-	s->uid		= r->idiag_uid;
-	s->iface	= r->id.idiag_if;
-	s->sk		= cookie_sk_get(&r->id.idiag_cookie[0]);
+	s.state		= r->idiag_state;
+	s.local.family  = s.remote.family = r->idiag_family;
+	s.lport		= ntohs(r->id.idiag_sport);
+	s.rport		= ntohs(r->id.idiag_dport);
+	s.wq		= r->idiag_wqueue;
+	s.rq		= r->idiag_rqueue;
+	s.ino		= r->idiag_inode;
+	s.uid		= r->idiag_uid;
+	s.iface		= r->id.idiag_if;
+	s.sk		= cookie_sk_get(&r->id.idiag_cookie[0]);
 
-	s->mark = 0;
+	s.mark = 0;
 	if (tb[INET_DIAG_MARK])
-		s->mark = rta_getattr_u32(tb[INET_DIAG_MARK]);
-	if (tb[INET_DIAG_PROTOCOL])
-		s->raw_prot = rta_getattr_u8(tb[INET_DIAG_PROTOCOL]);
-	else
-		s->raw_prot = 0;
+		s.mark = *(__u32 *) RTA_DATA(tb[INET_DIAG_MARK]);
 
-	if (s->local.family == AF_INET)
-		s->local.bytelen = s->remote.bytelen = 4;
-	else
-		s->local.bytelen = s->remote.bytelen = 16;
+	if (s.local.family == AF_INET) {
+		s.local.bytelen = s.remote.bytelen = 4;
+	} else {
+		s.local.bytelen = s.remote.bytelen = 16;
+	}
 
-	memcpy(s->local.data, r->id.idiag_src, s->local.bytelen);
-	memcpy(s->remote.data, r->id.idiag_dst, s->local.bytelen);
-}
+	memcpy(s.local.data, r->id.idiag_src, s.local.bytelen);
+	memcpy(s.remote.data, r->id.idiag_dst, s.local.bytelen);
 
-static int inet_show_sock(struct nlmsghdr *nlh,
-			  struct sockstat *s)
-{
-	struct rtattr *tb[INET_DIAG_MAX+1];
-	struct inet_diag_msg *r = NLMSG_DATA(nlh);
-	unsigned char v6only = 0;
-
-	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr *)(r+1),
-		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
+	if (f && f->f && run_ssfilter(f->f, &s) == 0)
+		return 0;
 
 	if (tb[INET_DIAG_PROTOCOL])
-		s->type = rta_getattr_u8(tb[INET_DIAG_PROTOCOL]);
+		protocol = *(__u8 *)RTA_DATA(tb[INET_DIAG_PROTOCOL]);
 
-	if (s->local.family == AF_INET6 && tb[INET_DIAG_SKV6ONLY])
-		v6only = rta_getattr_u8(tb[INET_DIAG_SKV6ONLY]);
-
-	inet_stats_print(s, v6only);
+	inet_stats_print(&s, protocol);
 
 	if (show_options) {
 		struct tcpstat t = {};
@@ -3028,75 +2089,62 @@
 		t.timer = r->idiag_timer;
 		t.timeout = r->idiag_expires;
 		t.retrans = r->idiag_retrans;
-		if (s->type == IPPROTO_SCTP)
-			sctp_timer_print(&t);
-		else
-			tcp_timer_print(&t);
+		tcp_timer_print(&t);
 	}
 
 	if (show_details) {
-		sock_details_print(s);
-		if (s->local.family == AF_INET6 && tb[INET_DIAG_SKV6ONLY])
-			out(" v6only:%u", v6only);
-
+		sock_details_print(&s);
+		if (s.local.family == AF_INET6 && tb[INET_DIAG_SKV6ONLY]) {
+			unsigned char v6only;
+			v6only = *(__u8 *)RTA_DATA(tb[INET_DIAG_SKV6ONLY]);
+			printf(" v6only:%u", v6only);
+		}
 		if (tb[INET_DIAG_SHUTDOWN]) {
 			unsigned char mask;
-
-			mask = rta_getattr_u8(tb[INET_DIAG_SHUTDOWN]);
-			out(" %c-%c",
-			    mask & 1 ? '-' : '<', mask & 2 ? '-' : '>');
+			mask = *(__u8 *)RTA_DATA(tb[INET_DIAG_SHUTDOWN]);
+			printf(" %c-%c", mask & 1 ? '-' : '<', mask & 2 ? '-' : '>');
 		}
 	}
 
-	if (show_tos) {
-		if (tb[INET_DIAG_TOS])
-			out(" tos:%#x", rta_getattr_u8(tb[INET_DIAG_TOS]));
-		if (tb[INET_DIAG_TCLASS])
-			out(" tclass:%#x", rta_getattr_u8(tb[INET_DIAG_TCLASS]));
-		if (tb[INET_DIAG_CLASS_ID])
-			out(" class_id:%#x", rta_getattr_u32(tb[INET_DIAG_CLASS_ID]));
+	if (show_mem || show_tcpinfo) {
+		printf("\n\t");
+		tcp_show_info(nlh, r, tb);
 	}
 
-	if (show_mem || (show_tcpinfo && s->type != IPPROTO_UDP)) {
-		if (!oneline)
-			out("\n\t");
-		if (s->type == IPPROTO_SCTP)
-			sctp_show_info(nlh, r, tb);
-		else
-			tcp_show_info(nlh, r, tb);
-	}
-	sctp_ino = s->ino;
-
+	printf("\n");
 	return 0;
 }
 
 static int tcpdiag_send(int fd, int protocol, struct filter *f)
 {
-	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
+	struct sockaddr_nl nladdr;
 	struct {
 		struct nlmsghdr nlh;
 		struct inet_diag_req r;
-	} req = {
-		.nlh.nlmsg_len = sizeof(req),
-		.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST,
-		.nlh.nlmsg_seq = MAGIC_SEQ,
-		.r.idiag_family = AF_INET,
-		.r.idiag_states = f->states,
-	};
+	} req;
 	char    *bc = NULL;
 	int	bclen;
 	struct msghdr msg;
 	struct rtattr rta;
 	struct iovec iov[3];
-	int iovlen = 1;
 
 	if (protocol == IPPROTO_UDP)
 		return -1;
 
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+
+	req.nlh.nlmsg_len = sizeof(req);
 	if (protocol == IPPROTO_TCP)
 		req.nlh.nlmsg_type = TCPDIAG_GETSOCK;
 	else
 		req.nlh.nlmsg_type = DCCPDIAG_GETSOCK;
+	req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
+	req.nlh.nlmsg_pid = 0;
+	req.nlh.nlmsg_seq = MAGIC_SEQ;
+	memset(&req.r, 0, sizeof(req.r));
+	req.r.idiag_family = AF_INET;
+	req.r.idiag_states = f->states;
 	if (show_mem) {
 		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
 		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
@@ -3108,32 +2156,24 @@
 		req.r.idiag_ext |= (1<<(INET_DIAG_CONG-1));
 	}
 
-	if (show_tos) {
-		req.r.idiag_ext |= (1<<(INET_DIAG_TOS-1));
-		req.r.idiag_ext |= (1<<(INET_DIAG_TCLASS-1));
-	}
-
 	iov[0] = (struct iovec){
 		.iov_base = &req,
 		.iov_len = sizeof(req)
 	};
 	if (f->f) {
 		bclen = ssfilter_bytecompile(f->f, &bc);
-		if (bclen) {
-			rta.rta_type = INET_DIAG_REQ_BYTECODE;
-			rta.rta_len = RTA_LENGTH(bclen);
-			iov[1] = (struct iovec){ &rta, sizeof(rta) };
-			iov[2] = (struct iovec){ bc, bclen };
-			req.nlh.nlmsg_len += RTA_LENGTH(bclen);
-			iovlen = 3;
-		}
+		rta.rta_type = INET_DIAG_REQ_BYTECODE;
+		rta.rta_len = RTA_LENGTH(bclen);
+		iov[1] = (struct iovec){ &rta, sizeof(rta) };
+		iov[2] = (struct iovec){ bc, bclen };
+		req.nlh.nlmsg_len += RTA_LENGTH(bclen);
 	}
 
 	msg = (struct msghdr) {
-		.msg_name = (void *)&nladdr,
+		.msg_name = (void*)&nladdr,
 		.msg_namelen = sizeof(nladdr),
 		.msg_iov = iov,
-		.msg_iovlen = iovlen,
+		.msg_iovlen = f->f ? 3 : 1,
 	};
 
 	if (sendmsg(fd, &msg, 0) < 0) {
@@ -3146,18 +2186,20 @@
 
 static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
 {
-	struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
+	struct sockaddr_nl nladdr;
 	DIAG_REQUEST(req, struct inet_diag_req_v2 r);
 	char    *bc = NULL;
 	int	bclen;
 	struct msghdr msg;
 	struct rtattr rta;
 	struct iovec iov[3];
-	int iovlen = 1;
 
 	if (family == PF_UNSPEC)
 		return tcpdiag_send(fd, protocol, f);
 
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+
 	memset(&req.r, 0, sizeof(req.r));
 	req.r.sdiag_family = family;
 	req.r.sdiag_protocol = protocol;
@@ -3173,32 +2215,24 @@
 		req.r.idiag_ext |= (1<<(INET_DIAG_CONG-1));
 	}
 
-	if (show_tos) {
-		req.r.idiag_ext |= (1<<(INET_DIAG_TOS-1));
-		req.r.idiag_ext |= (1<<(INET_DIAG_TCLASS-1));
-	}
-
 	iov[0] = (struct iovec){
 		.iov_base = &req,
 		.iov_len = sizeof(req)
 	};
 	if (f->f) {
 		bclen = ssfilter_bytecompile(f->f, &bc);
-		if (bclen) {
-			rta.rta_type = INET_DIAG_REQ_BYTECODE;
-			rta.rta_len = RTA_LENGTH(bclen);
-			iov[1] = (struct iovec){ &rta, sizeof(rta) };
-			iov[2] = (struct iovec){ bc, bclen };
-			req.nlh.nlmsg_len += RTA_LENGTH(bclen);
-			iovlen = 3;
-		}
+		rta.rta_type = INET_DIAG_REQ_BYTECODE;
+		rta.rta_len = RTA_LENGTH(bclen);
+		iov[1] = (struct iovec){ &rta, sizeof(rta) };
+		iov[2] = (struct iovec){ bc, bclen };
+		req.nlh.nlmsg_len += RTA_LENGTH(bclen);
 	}
 
 	msg = (struct msghdr) {
-		.msg_name = (void *)&nladdr,
+		.msg_name = (void*)&nladdr,
 		.msg_namelen = sizeof(nladdr),
 		.msg_iov = iov,
-		.msg_iovlen = iovlen,
+		.msg_iovlen = f->f ? 3 : 1,
 	};
 
 	if (sendmsg(fd, &msg, 0) < 0) {
@@ -3215,12 +2249,12 @@
 	struct rtnl_handle *rth;
 };
 
-static int kill_inet_sock(struct nlmsghdr *h, void *arg, struct sockstat *s)
+static int kill_inet_sock(const struct sockaddr_nl *addr,
+		struct nlmsghdr *h, void *arg)
 {
 	struct inet_diag_msg *d = NLMSG_DATA(h);
 	struct inet_diag_arg *diag_arg = arg;
 	struct rtnl_handle *rth = diag_arg->rth;
-
 	DIAG_REQUEST(req, struct inet_diag_req_v2 r);
 
 	req.nlh.nlmsg_type = SOCK_DESTROY;
@@ -3230,33 +2264,19 @@
 	req.r.sdiag_protocol = diag_arg->protocol;
 	req.r.id = d->id;
 
-	if (diag_arg->protocol == IPPROTO_RAW) {
-		struct inet_diag_req_raw *raw = (void *)&req.r;
-
-		BUILD_BUG_ON(sizeof(req.r) != sizeof(*raw));
-		raw->sdiag_raw_protocol = s->raw_prot;
-	}
-
-	return rtnl_talk(rth, &req.nlh, NULL);
+	return rtnl_talk(rth, &req.nlh, NULL, 0);
 }
 
-static int show_one_inet_sock(struct nlmsghdr *h, void *arg)
+static int show_one_inet_sock(const struct sockaddr_nl *addr,
+		struct nlmsghdr *h, void *arg)
 {
 	int err;
 	struct inet_diag_arg *diag_arg = arg;
 	struct inet_diag_msg *r = NLMSG_DATA(h);
-	struct sockstat s = {};
 
-	if (!(diag_arg->f->families & FAMILY_MASK(r->idiag_family)))
+	if (!(diag_arg->f->families & (1 << r->idiag_family)))
 		return 0;
-
-	parse_diag_msg(h, &s);
-	s.type = diag_arg->protocol;
-
-	if (diag_arg->f->f && run_ssfilter(diag_arg->f->f, &s) == 0)
-		return 0;
-
-	if (diag_arg->f->kill && kill_inet_sock(h, arg, &s) != 0) {
+	if (diag_arg->f->kill && kill_inet_sock(addr, h, arg) != 0) {
 		if (errno == EOPNOTSUPP || errno == ENOENT) {
 			/* Socket can't be closed, or is already closed. */
 			return 0;
@@ -3265,9 +2285,7 @@
 			return -1;
 		}
 	}
-
-	err = inet_show_sock(h, &s);
-	if (err < 0)
+	if ((err = inet_show_sock(h, diag_arg->f, diag_arg->protocol)) < 0)
 		return err;
 
 	return 0;
@@ -3323,79 +2341,63 @@
 {
 	FILE	*fp;
 	char	buf[16384];
-	int	err = -1;
 
 	if ((fp = fopen(getenv("TCPDIAG_FILE"), "r")) == NULL) {
 		perror("fopen($TCPDIAG_FILE)");
-		return err;
+		return -1;
 	}
 
 	while (1) {
-		int err2;
-		size_t status, nitems;
-		struct nlmsghdr *h = (struct nlmsghdr *)buf;
-		struct sockstat s = {};
+		int status, err;
+		struct nlmsghdr *h = (struct nlmsghdr*)buf;
 
 		status = fread(buf, 1, sizeof(*h), fp);
+		if (status < 0) {
+			perror("Reading header from $TCPDIAG_FILE");
+			return -1;
+		}
 		if (status != sizeof(*h)) {
-			if (ferror(fp))
-				perror("Reading header from $TCPDIAG_FILE");
-			if (feof(fp))
-				fprintf(stderr, "Unexpected EOF reading $TCPDIAG_FILE");
-			break;
+			perror("Unexpected EOF reading $TCPDIAG_FILE");
+			return -1;
 		}
 
-		nitems = NLMSG_ALIGN(h->nlmsg_len - sizeof(*h));
-		status = fread(h+1, 1, nitems, fp);
+		status = fread(h+1, 1, NLMSG_ALIGN(h->nlmsg_len-sizeof(*h)), fp);
 
-		if (status != nitems) {
-			if (ferror(fp))
-				perror("Reading $TCPDIAG_FILE");
-			if (feof(fp))
-				fprintf(stderr, "Unexpected EOF reading $TCPDIAG_FILE");
-			break;
+		if (status < 0) {
+			perror("Reading $TCPDIAG_FILE");
+			return -1;
+		}
+		if (status + sizeof(*h) < h->nlmsg_len) {
+			perror("Unexpected EOF reading $TCPDIAG_FILE");
+			return -1;
 		}
 
 		/* The only legal exit point */
-		if (h->nlmsg_type == NLMSG_DONE) {
-			err = 0;
-			break;
-		}
+		if (h->nlmsg_type == NLMSG_DONE)
+			return 0;
 
 		if (h->nlmsg_type == NLMSG_ERROR) {
-			struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
-
+			struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
 			if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
 				fprintf(stderr, "ERROR truncated\n");
 			} else {
 				errno = -err->error;
 				perror("TCPDIAG answered");
 			}
-			break;
+			return -1;
 		}
 
-		parse_diag_msg(h, &s);
-		s.type = IPPROTO_TCP;
-
-		if (f && f->f && run_ssfilter(f->f, &s) == 0)
-			continue;
-
-		err2 = inet_show_sock(h, &s);
-		if (err2 < 0) {
-			err = err2;
-			break;
-		}
+		err = inet_show_sock(h, f, IPPROTO_TCP);
+		if (err < 0)
+			return err;
 	}
-
-	fclose(fp);
-	return err;
 }
 
-static int tcp_show(struct filter *f)
+static int tcp_show(struct filter *f, int socktype)
 {
 	FILE *fp = NULL;
 	char *buf = NULL;
-	int bufsize = 1024*1024;
+	int bufsize = 64*1024;
 
 	if (!filter_af_get(f, AF_INET) && !filter_af_get(f, AF_INET6))
 		return 0;
@@ -3406,10 +2408,30 @@
 		return tcp_show_netlink_file(f);
 
 	if (!getenv("PROC_NET_TCP") && !getenv("PROC_ROOT")
-	    && inet_show_netlink(f, NULL, IPPROTO_TCP) == 0)
+	    && inet_show_netlink(f, NULL, socktype) == 0)
 		return 0;
 
 	/* Sigh... We have to parse /proc/net/tcp... */
+
+
+	/* Estimate amount of sockets and try to allocate
+	 * huge buffer to read all the table at one read.
+	 * Limit it by 16MB though. The assumption is: as soon as
+	 * kernel was able to hold information about N connections,
+	 * it is able to give us some memory for snapshot.
+	 */
+	if (1) {
+		get_slabstat(&slabstat);
+
+		int guess = slabstat.socks+slabstat.tcp_syns;
+		if (f->states&(1<<SS_TIME_WAIT))
+			guess += slabstat.tcp_tws;
+		if (guess > (16*1024*1024)/128)
+			guess = (16*1024*1024)/128;
+		guess *= 128;
+		if (guess > bufsize)
+			bufsize = guess;
+	}
 	while (bufsize >= 64*1024) {
 		if ((buf = malloc(bufsize)) != NULL)
 			break;
@@ -3420,7 +2442,7 @@
 		return -1;
 	}
 
-	if (f->families & FAMILY_MASK(AF_INET)) {
+	if (f->families & (1<<AF_INET)) {
 		if ((fp = net_tcp_open()) == NULL)
 			goto outerr;
 
@@ -3430,7 +2452,7 @@
 		fclose(fp);
 	}
 
-	if ((f->families & FAMILY_MASK(AF_INET6)) &&
+	if ((f->families & (1<<AF_INET6)) &&
 	    (fp = net_tcp6_open()) != NULL) {
 		setbuffer(fp, buf, bufsize);
 		if (generic_record_read(fp, tcp_show_line, f, AF_INET6))
@@ -3444,7 +2466,6 @@
 outerr:
 	do {
 		int saved_errno = errno;
-
 		free(buf);
 		if (fp)
 			fclose(fp);
@@ -3453,29 +2474,6 @@
 	} while (0);
 }
 
-static int dccp_show(struct filter *f)
-{
-	if (!filter_af_get(f, AF_INET) && !filter_af_get(f, AF_INET6))
-		return 0;
-
-	if (!getenv("PROC_NET_DCCP") && !getenv("PROC_ROOT")
-	    && inet_show_netlink(f, NULL, IPPROTO_DCCP) == 0)
-		return 0;
-
-	return 0;
-}
-
-static int sctp_show(struct filter *f)
-{
-	if (!filter_af_get(f, AF_INET) && !filter_af_get(f, AF_INET6))
-		return 0;
-
-	if (!getenv("PROC_NET_SCTP") && !getenv("PROC_ROOT")
-	    && inet_show_netlink(f, NULL, IPPROTO_SCTP) == 0)
-		return 0;
-
-	return 0;
-}
 
 static int dgram_show_line(char *line, const struct filter *f, int family)
 {
@@ -3488,7 +2486,6 @@
 		return -1;
 
 	int state = (data[1] >= 'A') ? (data[1] - 'A' + 10) : (data[1] - '0');
-
 	if (!(f->states & (1 << state)))
 		return 0;
 
@@ -3506,12 +2503,12 @@
 	if (n < 9)
 		opt[0] = 0;
 
-	s.type = dg_proto == UDP_PROTO ? IPPROTO_UDP : 0;
-	inet_stats_print(&s, false);
+	inet_stats_print(&s, dg_proto == UDP_PROTO ? IPPROTO_UDP : 0);
 
 	if (show_details && opt[0])
-		out(" opt:\"%s\"", opt);
+		printf(" opt:\"%s\"", opt);
 
+	printf("\n");
 	return 0;
 }
 
@@ -3528,7 +2525,7 @@
 	    && inet_show_netlink(f, NULL, IPPROTO_UDP) == 0)
 		return 0;
 
-	if (f->families&FAMILY_MASK(AF_INET)) {
+	if (f->families&(1<<AF_INET)) {
 		if ((fp = net_udp_open()) == NULL)
 			goto outerr;
 		if (generic_record_read(fp, dgram_show_line, f, AF_INET))
@@ -3536,7 +2533,7 @@
 		fclose(fp);
 	}
 
-	if ((f->families&FAMILY_MASK(AF_INET6)) &&
+	if ((f->families&(1<<AF_INET6)) &&
 	    (fp = net_udp6_open()) != NULL) {
 		if (generic_record_read(fp, dgram_show_line, f, AF_INET6))
 			goto outerr;
@@ -3547,7 +2544,6 @@
 outerr:
 	do {
 		int saved_errno = errno;
-
 		if (fp)
 			fclose(fp);
 		errno = saved_errno;
@@ -3564,11 +2560,7 @@
 
 	dg_proto = RAW_PROTO;
 
-	if (!getenv("PROC_NET_RAW") && !getenv("PROC_ROOT") &&
-	    inet_show_netlink(f, NULL, IPPROTO_RAW) == 0)
-		return 0;
-
-	if (f->families&FAMILY_MASK(AF_INET)) {
+	if (f->families&(1<<AF_INET)) {
 		if ((fp = net_raw_open()) == NULL)
 			goto outerr;
 		if (generic_record_read(fp, dgram_show_line, f, AF_INET))
@@ -3576,7 +2568,7 @@
 		fclose(fp);
 	}
 
-	if ((f->families&FAMILY_MASK(AF_INET6)) &&
+	if ((f->families&(1<<AF_INET6)) &&
 	    (fp = net_raw6_open()) != NULL) {
 		if (generic_record_read(fp, dgram_show_line, f, AF_INET6))
 			goto outerr;
@@ -3587,7 +2579,6 @@
 outerr:
 	do {
 		int saved_errno = errno;
-
 		if (fp)
 			fclose(fp);
 		errno = saved_errno;
@@ -3595,15 +2586,39 @@
 	} while (0);
 }
 
+int unix_state_map[] = { SS_CLOSE, SS_SYN_SENT,
+			 SS_ESTABLISHED, SS_CLOSING };
+
 #define MAX_UNIX_REMEMBER (1024*1024/sizeof(struct sockstat))
 
-static void unix_list_drop_first(struct sockstat **list)
+static void unix_list_free(struct sockstat *list)
 {
-	struct sockstat *s = *list;
+	while (list) {
+		struct sockstat *s = list;
 
-	(*list) = (*list)->next;
-	free(s->name);
-	free(s);
+		list = list->next;
+		free(s->name);
+		free(s);
+	}
+}
+
+static const char *unix_netid_name(int type)
+{
+	const char *netid;
+
+	switch (type) {
+	case SOCK_STREAM:
+		netid = "u_str";
+		break;
+	case SOCK_SEQPACKET:
+		netid = "u_seq";
+		break;
+	case SOCK_DGRAM:
+	default:
+		netid = "u_dgr";
+		break;
+	}
+	return netid;
 }
 
 static bool unix_type_skip(struct sockstat *s, struct filter *f)
@@ -3617,21 +2632,83 @@
 	return false;
 }
 
-static void unix_stats_print(struct sockstat *s, struct filter *f)
+static bool unix_use_proc(void)
 {
-	char port_name[30] = {};
-
-	sock_state_print(s);
-
-	sock_addr_print(s->name ?: "*", " ",
-			int_to_str(s->lport, port_name), NULL);
-	sock_addr_print(s->peer_name ?: "*", " ",
-			int_to_str(s->rport, port_name), NULL);
-
-	proc_ctx_print(s);
+	return getenv("PROC_NET_UNIX") || getenv("PROC_ROOT");
 }
 
-static int unix_show_sock(struct nlmsghdr *nlh, void *arg)
+static void unix_stats_print(struct sockstat *list, struct filter *f)
+{
+	struct sockstat *s;
+	char *peer;
+	char *ctx_buf = NULL;
+	bool use_proc = unix_use_proc();
+	char port_name[30] = {};
+
+	for (s = list; s; s = s->next) {
+		if (!(f->states & (1 << s->state)))
+			continue;
+		if (unix_type_skip(s, f))
+			continue;
+
+		peer = "*";
+		if (s->peer_name)
+			peer = s->peer_name;
+
+		if (s->rport && use_proc) {
+			struct sockstat *p;
+
+			for (p = list; p; p = p->next) {
+				if (s->rport == p->lport)
+					break;
+			}
+
+			if (!p) {
+				peer = "?";
+			} else {
+				peer = p->name ? : "*";
+			}
+		}
+
+		if (use_proc && f->f) {
+			struct sockstat st;
+			st.local.family = AF_UNIX;
+			st.remote.family = AF_UNIX;
+			memcpy(st.local.data, &s->name, sizeof(s->name));
+			if (strcmp(peer, "*") == 0)
+				memset(st.remote.data, 0, sizeof(peer));
+			else
+				memcpy(st.remote.data, &peer, sizeof(peer));
+			if (run_ssfilter(f->f, &st) == 0)
+				continue;
+		}
+
+		sock_state_print(s, unix_netid_name(s->type));
+
+		sock_addr_print(s->name ?: "*", " ",
+				int_to_str(s->lport, port_name), NULL);
+		sock_addr_print(peer, " ", int_to_str(s->rport, port_name),
+				NULL);
+
+		if (show_proc_ctx || show_sock_ctx) {
+			if (find_entry(s->ino, &ctx_buf,
+					(show_proc_ctx & show_sock_ctx) ?
+					PROC_SOCK_CTX : PROC_CTX) > 0) {
+				printf(" users:(%s)", ctx_buf);
+				free(ctx_buf);
+			}
+		} else if (show_users) {
+			if (find_entry(s->ino, &ctx_buf, USERS) > 0) {
+				printf(" users:(%s)", ctx_buf);
+				free(ctx_buf);
+			}
+		}
+		printf("\n");
+	}
+}
+
+static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
+		void *arg)
 {
 	struct filter *f = (struct filter *)arg;
 	struct unix_diag_msg *r = NLMSG_DATA(nlh);
@@ -3639,7 +2716,7 @@
 	char name[128];
 	struct sockstat stat = { .name = "*", .peer_name = "*" };
 
-	parse_rtattr(tb, UNIX_DIAG_MAX, (struct rtattr *)(r+1),
+	parse_rtattr(tb, UNIX_DIAG_MAX, (struct rtattr*)(r+1),
 		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
 	stat.type  = r->udiag_type;
@@ -3652,7 +2729,6 @@
 
 	if (tb[UNIX_DIAG_RQLEN]) {
 		struct unix_diag_rqlen *rql = RTA_DATA(tb[UNIX_DIAG_RQLEN]);
-
 		stat.rq = rql->udiag_rqueue;
 		stat.wq = rql->udiag_wqueue;
 	}
@@ -3661,12 +2737,8 @@
 
 		memcpy(name, RTA_DATA(tb[UNIX_DIAG_NAME]), len);
 		name[len] = '\0';
-		if (name[0] == '\0') {
-			int i;
-			for (i = 0; i < len; i++)
-				if (name[i] == '\0')
-					name[i] = '@';
-		}
+		if (name[0] == '\0')
+			name[0] = '@';
 		stat.name = &name[0];
 		memcpy(stat.local.data, &stat.name, sizeof(stat.name));
 	}
@@ -3678,32 +2750,19 @@
 
 	unix_stats_print(&stat, f);
 
-	if (show_mem)
+	if (show_mem) {
+		printf("\t");
 		print_skmeminfo(tb, UNIX_DIAG_MEMINFO);
+	}
 	if (show_details) {
 		if (tb[UNIX_DIAG_SHUTDOWN]) {
 			unsigned char mask;
-
-			mask = rta_getattr_u8(tb[UNIX_DIAG_SHUTDOWN]);
-			out(" %c-%c",
-			    mask & 1 ? '-' : '<', mask & 2 ? '-' : '>');
-		}
-		if (tb[UNIX_DIAG_VFS]) {
-			struct unix_diag_vfs *uv = RTA_DATA(tb[UNIX_DIAG_VFS]);
-
-			out(" ino:%u dev:%u/%u", uv->udiag_vfs_ino, major(uv->udiag_vfs_dev),
-						 minor(uv->udiag_vfs_dev));
-		}
-		if (tb[UNIX_DIAG_ICONS]) {
-			int len = RTA_PAYLOAD(tb[UNIX_DIAG_ICONS]);
-			__u32 *peers = RTA_DATA(tb[UNIX_DIAG_ICONS]);
-			int i;
-
-			out(" peers:");
-			for (i = 0; i < len / sizeof(__u32); i++)
-				out(" %u", peers[i]);
+			mask = *(__u8 *)RTA_DATA(tb[UNIX_DIAG_SHUTDOWN]);
+			printf(" %c-%c", mask & 1 ? '-' : '<', mask & 2 ? '-' : '>');
 		}
 	}
+	if (show_mem || show_details)
+		printf("\n");
 
 	return 0;
 }
@@ -3740,8 +2799,6 @@
 	req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER | UDIAG_SHOW_RQLEN;
 	if (show_mem)
 		req.r.udiag_show |= UDIAG_SHOW_MEMINFO;
-	if (show_details)
-		req.r.udiag_show |= UDIAG_SHOW_VFS | UDIAG_SHOW_ICONS;
 
 	return handle_netlink_request(f, &req.nlh, sizeof(req), unix_show_sock);
 }
@@ -3754,14 +2811,11 @@
 	int  newformat = 0;
 	int  cnt;
 	struct sockstat *list = NULL;
-	const int unix_state_map[] = { SS_CLOSE, SS_SYN_SENT,
-				       SS_ESTABLISHED, SS_CLOSING };
 
 	if (!filter_af_get(f, AF_UNIX))
 		return 0;
 
-	if (!getenv("PROC_NET_UNIX") && !getenv("PROC_ROOT")
-	    && unix_show_netlink(f) == 0)
+	if (!unix_use_proc() && unix_show_netlink(f) == 0)
 		return 0;
 
 	if ((fp = net_unix_open()) == NULL)
@@ -3781,6 +2835,8 @@
 
 		if (!(u = calloc(1, sizeof(*u))))
 			break;
+		u->name = NULL;
+		u->peer_name = NULL;
 
 		if (sscanf(buf, "%x: %x %x %x %x %x %d %s",
 			   &u->rport, &u->rq, &u->wq, &flags, &u->type,
@@ -3792,17 +2848,11 @@
 
 		if (flags & (1 << 16)) {
 			u->state = SS_LISTEN;
-		} else if (u->state > 0 &&
-			   u->state <= ARRAY_SIZE(unix_state_map)) {
+		} else {
 			u->state = unix_state_map[u->state-1];
 			if (u->type == SOCK_DGRAM && u->state == SS_CLOSE && u->rport)
 				u->state = SS_ESTABLISHED;
 		}
-		if (unix_type_skip(u, f) ||
-		    !(f->states & (1 << u->state))) {
-			free(u);
-			continue;
-		}
 
 		if (!newformat) {
 			u->rport = 0;
@@ -3810,47 +2860,6 @@
 			u->wq = 0;
 		}
 
-		if (name[0]) {
-			u->name = strdup(name);
-			if (!u->name) {
-				free(u);
-				break;
-			}
-		}
-
-		if (u->rport) {
-			struct sockstat *p;
-
-			for (p = list; p; p = p->next) {
-				if (u->rport == p->lport)
-					break;
-			}
-			if (!p)
-				u->peer_name = "?";
-			else
-				u->peer_name = p->name ? : "*";
-		}
-
-		if (f->f) {
-			struct sockstat st = {
-				.local.family = AF_UNIX,
-				.remote.family = AF_UNIX,
-			};
-
-			memcpy(st.local.data, &u->name, sizeof(u->name));
-			/* when parsing the old format rport is set to 0 and
-			 * therefore peer_name remains NULL
-			 */
-			if (u->peer_name && strcmp(u->peer_name, "*"))
-				memcpy(st.remote.data, &u->peer_name,
-				       sizeof(u->peer_name));
-			if (run_ssfilter(f->f, &st) == 0) {
-				free(u->name);
-				free(u);
-				continue;
-			}
-		}
-
 		insp = &list;
 		while (*insp) {
 			if (u->type < (*insp)->type ||
@@ -3862,18 +2871,24 @@
 		u->next = *insp;
 		*insp = u;
 
+		if (name[0]) {
+			if ((u->name = malloc(strlen(name)+1)) == NULL)
+				break;
+			strcpy(u->name, name);
+		}
 		if (++cnt > MAX_UNIX_REMEMBER) {
-			while (list) {
-				unix_stats_print(list, f);
-				unix_list_drop_first(&list);
-			}
+			unix_stats_print(list, f);
+			unix_list_free(list);
+			list = NULL;
 			cnt = 0;
 		}
 	}
 	fclose(fp);
-	while (list) {
+	if (list) {
 		unix_stats_print(list, f);
-		unix_list_drop_first(&list);
+		unix_list_free(list);
+		list = NULL;
+		cnt = 0;
 	}
 
 	return 0;
@@ -3881,18 +2896,19 @@
 
 static int packet_stats_print(struct sockstat *s, const struct filter *f)
 {
+	char *buf = NULL;
 	const char *addr, *port;
 	char ll_name[16];
 
-	s->local.family = s->remote.family = AF_PACKET;
-
 	if (f->f) {
+		s->local.family = AF_PACKET;
+		s->remote.family = AF_PACKET;
 		s->local.data[0] = s->prot;
 		if (run_ssfilter(f->f, s) == 0)
 			return 1;
 	}
 
-	sock_state_print(s);
+	sock_state_print(s, s->type == SOCK_RAW ? "p_raw" : "p_dgr");
 
 	if (s->prot == 3)
 		addr = "*";
@@ -3907,7 +2923,19 @@
 	sock_addr_print(addr, ":", port, NULL);
 	sock_addr_print("", "*", "", NULL);
 
-	proc_ctx_print(s);
+	if (show_proc_ctx || show_sock_ctx) {
+		if (find_entry(s->ino, &buf,
+					(show_proc_ctx & show_sock_ctx) ?
+					PROC_SOCK_CTX : PROC_CTX) > 0) {
+			printf(" users:(%s)", buf);
+			free(buf);
+		}
+	} else if (show_users) {
+		if (find_entry(s->ino, &buf, USERS) > 0) {
+			printf(" users:(%s)", buf);
+			free(buf);
+		}
+	}
 
 	if (show_details)
 		sock_details_print(s);
@@ -3917,15 +2945,16 @@
 
 static void packet_show_ring(struct packet_diag_ring *ring)
 {
-	out("blk_size:%d", ring->pdr_block_size);
-	out(",blk_nr:%d", ring->pdr_block_nr);
-	out(",frm_size:%d", ring->pdr_frame_size);
-	out(",frm_nr:%d", ring->pdr_frame_nr);
-	out(",tmo:%d", ring->pdr_retire_tmo);
-	out(",features:0x%x", ring->pdr_features);
+	printf("blk_size:%d", ring->pdr_block_size);
+	printf(",blk_nr:%d", ring->pdr_block_nr);
+	printf(",frm_size:%d", ring->pdr_frame_size);
+	printf(",frm_nr:%d", ring->pdr_frame_nr);
+	printf(",tmo:%d", ring->pdr_retire_tmo);
+	printf(",features:0x%x", ring->pdr_features);
 }
 
-static int packet_show_sock(struct nlmsghdr *nlh, void *arg)
+static int packet_show_sock(const struct sockaddr_nl *addr,
+		struct nlmsghdr *nlh, void *arg)
 {
 	const struct filter *f = arg;
 	struct packet_diag_msg *r = NLMSG_DATA(nlh);
@@ -3936,7 +2965,7 @@
 	uint32_t fanout = 0;
 	bool has_fanout = false;
 
-	parse_rtattr(tb, PACKET_DIAG_MAX, (struct rtattr *)(r+1),
+	parse_rtattr(tb, PACKET_DIAG_MAX, (struct rtattr*)(r+1),
 		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
 	/* use /proc/net/packet if all info are not available */
@@ -3951,7 +2980,6 @@
 
 	if (tb[PACKET_DIAG_MEMINFO]) {
 		__u32 *skmeminfo = RTA_DATA(tb[PACKET_DIAG_MEMINFO]);
-
 		stat.rq = skmeminfo[SK_MEMINFO_RMEM_ALLOC];
 	}
 
@@ -3961,7 +2989,7 @@
 	}
 
 	if (tb[PACKET_DIAG_UID])
-		stat.uid = rta_getattr_u32(tb[PACKET_DIAG_UID]);
+		stat.uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]);
 
 	if (tb[PACKET_DIAG_RX_RING])
 		ring_rx = RTA_DATA(tb[PACKET_DIAG_RX_RING]);
@@ -3971,7 +2999,7 @@
 
 	if (tb[PACKET_DIAG_FANOUT]) {
 		has_fanout = true;
-		fanout = rta_getattr_u32(tb[PACKET_DIAG_FANOUT]);
+		fanout = *(uint32_t *)RTA_DATA(tb[PACKET_DIAG_FANOUT]);
 	}
 
 	if (packet_stats_print(&stat, f))
@@ -3979,68 +3007,56 @@
 
 	if (show_details) {
 		if (pinfo) {
-			if (oneline)
-				out(" ver:%d", pinfo->pdi_version);
-			else
-				out("\n\tver:%d", pinfo->pdi_version);
-			out(" cpy_thresh:%d", pinfo->pdi_copy_thresh);
-			out(" flags( ");
+			printf("\n\tver:%d", pinfo->pdi_version);
+			printf(" cpy_thresh:%d", pinfo->pdi_copy_thresh);
+			printf(" flags( ");
 			if (pinfo->pdi_flags & PDI_RUNNING)
-				out("running");
+				printf("running");
 			if (pinfo->pdi_flags & PDI_AUXDATA)
-				out(" auxdata");
+				printf(" auxdata");
 			if (pinfo->pdi_flags & PDI_ORIGDEV)
-				out(" origdev");
+				printf(" origdev");
 			if (pinfo->pdi_flags & PDI_VNETHDR)
-				out(" vnethdr");
+				printf(" vnethdr");
 			if (pinfo->pdi_flags & PDI_LOSS)
-				out(" loss");
+				printf(" loss");
 			if (!pinfo->pdi_flags)
-				out("0");
-			out(" )");
+				printf("0");
+			printf(" )");
 		}
 		if (ring_rx) {
-			if (oneline)
-				out(" ring_rx(");
-			else
-				out("\n\tring_rx(");
+			printf("\n\tring_rx(");
 			packet_show_ring(ring_rx);
-			out(")");
+			printf(")");
 		}
 		if (ring_tx) {
-			if (oneline)
-				out(" ring_tx(");
-			else
-				out("\n\tring_tx(");
+			printf("\n\tring_tx(");
 			packet_show_ring(ring_tx);
-			out(")");
+			printf(")");
 		}
 		if (has_fanout) {
 			uint16_t type = (fanout >> 16) & 0xffff;
 
-			if (oneline)
-				out(" fanout(");
-			else
-				out("\n\tfanout(");
-			out("id:%d,", fanout & 0xffff);
-			out("type:");
+			printf("\n\tfanout(");
+			printf("id:%d,", fanout & 0xffff);
+			printf("type:");
 
 			if (type == 0)
-				out("hash");
+				printf("hash");
 			else if (type == 1)
-				out("lb");
+				printf("lb");
 			else if (type == 2)
-				out("cpu");
+				printf("cpu");
 			else if (type == 3)
-				out("roll");
+				printf("roll");
 			else if (type == 4)
-				out("random");
+				printf("random");
 			else if (type == 5)
-				out("qm");
+				printf("qm");
 			else
-				out("0x%x", type);
+				printf("0x%x", type);
 
-			out(")");
+			printf(")");
 		}
 	}
 
@@ -4050,20 +3066,15 @@
 		int num = RTA_PAYLOAD(tb[PACKET_DIAG_FILTER]) /
 			  sizeof(struct sock_filter);
 
-		if (oneline)
-			out(" bpf filter (%d): ", num);
-		else
-			out("\n\tbpf filter (%d): ", num);
+		printf("\n\tbpf filter (%d): ", num);
 		while (num) {
-			out(" 0x%02x %u %u %u,",
-			    fil->code, fil->jt, fil->jf, fil->k);
+			printf(" 0x%02x %u %u %u,",
+			      fil->code, fil->jt, fil->jf, fil->k);
 			num--;
 			fil++;
 		}
 	}
-
-	if (show_mem)
-		print_skmeminfo(tb, PACKET_DIAG_MEMINFO);
+	printf("\n");
 	return 0;
 }
 
@@ -4106,6 +3117,7 @@
 	if (packet_stats_print(&stat, f))
 		return 0;
 
+	printf("\n");
 	return 0;
 }
 
@@ -4130,167 +3142,24 @@
 	return rc;
 }
 
-static int xdp_stats_print(struct sockstat *s, const struct filter *f)
-{
-	const char *addr, *port;
-	char q_str[16];
-
-	s->local.family = s->remote.family = AF_XDP;
-
-	if (f->f) {
-		if (run_ssfilter(f->f, s) == 0)
-			return 1;
-	}
-
-	sock_state_print(s);
-
-	if (s->iface) {
-		addr = xll_index_to_name(s->iface);
-		snprintf(q_str, sizeof(q_str), "q%d", s->lport);
-		port = q_str;
-		sock_addr_print(addr, ":", port, NULL);
-	} else {
-		sock_addr_print("", "*", "", NULL);
-	}
-
-	sock_addr_print("", "*", "", NULL);
-
-	proc_ctx_print(s);
-
-	if (show_details)
-		sock_details_print(s);
-
-	return 0;
-}
-
-static void xdp_show_ring(const char *name, struct xdp_diag_ring *ring)
-{
-	if (oneline)
-		out(" %s(", name);
-	else
-		out("\n\t%s(", name);
-	out("entries:%u", ring->entries);
-	out(")");
-}
-
-static void xdp_show_umem(struct xdp_diag_umem *umem, struct xdp_diag_ring *fr,
-			  struct xdp_diag_ring *cr)
-{
-	if (oneline)
-		out(" tumem(");
-	else
-		out("\n\tumem(");
-	out("id:%u", umem->id);
-	out(",size:%llu", umem->size);
-	out(",num_pages:%u", umem->num_pages);
-	out(",chunk_size:%u", umem->chunk_size);
-	out(",headroom:%u", umem->headroom);
-	out(",ifindex:%u", umem->ifindex);
-	out(",qid:%u", umem->queue_id);
-	out(",zc:%u", umem->flags & XDP_DU_F_ZEROCOPY);
-	out(",refs:%u", umem->refs);
-	out(")");
-
-	if (fr)
-		xdp_show_ring("fr", fr);
-	if (cr)
-		xdp_show_ring("cr", cr);
-}
-
-static int xdp_show_sock(struct nlmsghdr *nlh, void *arg)
-{
-	struct xdp_diag_ring *rx = NULL, *tx = NULL, *fr = NULL, *cr = NULL;
-	struct xdp_diag_msg *msg = NLMSG_DATA(nlh);
-	struct rtattr *tb[XDP_DIAG_MAX + 1];
-	struct xdp_diag_info *info = NULL;
-	struct xdp_diag_umem *umem = NULL;
-	const struct filter *f = arg;
-	struct sockstat stat = {};
-
-	parse_rtattr(tb, XDP_DIAG_MAX, (struct rtattr *)(msg + 1),
-		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*msg)));
-
-	stat.type = msg->xdiag_type;
-	stat.ino = msg->xdiag_ino;
-	stat.state = SS_CLOSE;
-	stat.sk = cookie_sk_get(&msg->xdiag_cookie[0]);
-
-	if (tb[XDP_DIAG_INFO]) {
-		info = RTA_DATA(tb[XDP_DIAG_INFO]);
-		stat.iface = info->ifindex;
-		stat.lport = info->queue_id;
-	}
-
-	if (tb[XDP_DIAG_UID])
-		stat.uid = rta_getattr_u32(tb[XDP_DIAG_UID]);
-	if (tb[XDP_DIAG_RX_RING])
-		rx = RTA_DATA(tb[XDP_DIAG_RX_RING]);
-	if (tb[XDP_DIAG_TX_RING])
-		tx = RTA_DATA(tb[XDP_DIAG_TX_RING]);
-	if (tb[XDP_DIAG_UMEM])
-		umem = RTA_DATA(tb[XDP_DIAG_UMEM]);
-	if (tb[XDP_DIAG_UMEM_FILL_RING])
-		fr = RTA_DATA(tb[XDP_DIAG_UMEM_FILL_RING]);
-	if (tb[XDP_DIAG_UMEM_COMPLETION_RING])
-		cr = RTA_DATA(tb[XDP_DIAG_UMEM_COMPLETION_RING]);
-	if (tb[XDP_DIAG_MEMINFO]) {
-		__u32 *skmeminfo = RTA_DATA(tb[XDP_DIAG_MEMINFO]);
-
-		stat.rq = skmeminfo[SK_MEMINFO_RMEM_ALLOC];
-	}
-
-	if (xdp_stats_print(&stat, f))
-		return 0;
-
-	if (show_details) {
-		if (rx)
-			xdp_show_ring("rx", rx);
-		if (tx)
-			xdp_show_ring("tx", tx);
-		if (umem)
-			xdp_show_umem(umem, fr, cr);
-	}
-
-	if (show_mem)
-		print_skmeminfo(tb, XDP_DIAG_MEMINFO); // really?
-
-
-	return 0;
-}
-
-static int xdp_show(struct filter *f)
-{
-	DIAG_REQUEST(req, struct xdp_diag_req r);
-
-	if (!filter_af_get(f, AF_XDP) || !(f->states & (1 << SS_CLOSE)))
-		return 0;
-
-	req.r.sdiag_family = AF_XDP;
-	req.r.xdiag_show = XDP_SHOW_INFO | XDP_SHOW_RING_CFG | XDP_SHOW_UMEM |
-			   XDP_SHOW_MEMINFO;
-
-	return handle_netlink_request(f, &req.nlh, sizeof(req), xdp_show_sock);
-}
-
 static int netlink_show_one(struct filter *f,
-				int prot, int pid, unsigned int groups,
-				int state, int dst_pid, unsigned int dst_group,
+				int prot, int pid, unsigned groups,
+				int state, int dst_pid, unsigned dst_group,
 				int rq, int wq,
 				unsigned long long sk, unsigned long long cb)
 {
-	struct sockstat st = {
-		.state		= SS_CLOSE,
-		.rq		= rq,
-		.wq		= wq,
-		.local.family	= AF_NETLINK,
-		.remote.family	= AF_NETLINK,
-	};
-
+	struct sockstat st;
 	SPRINT_BUF(prot_buf) = {};
 	const char *prot_name;
 	char procname[64] = {};
 
+	st.state = SS_CLOSE;
+	st.rq	 = rq;
+	st.wq	 = wq;
+
 	if (f->f) {
+		st.local.family = AF_NETLINK;
+		st.remote.family = AF_NETLINK;
 		st.rport = -1;
 		st.lport = pid;
 		st.local.data[0] = prot;
@@ -4298,21 +3167,22 @@
 			return 1;
 	}
 
-	sock_state_print(&st);
+	sock_state_print(&st, "nl");
 
-	prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
+	if (resolve_services)
+		prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
+	else
+		prot_name = int_to_str(prot, prot_buf);
 
 	if (pid == -1) {
 		procname[0] = '*';
-	} else if (!numeric) {
+	} else if (resolve_services) {
 		int done = 0;
-
 		if (!pid) {
 			done = 1;
-			strncpy(procname, "kernel", 7);
+			strncpy(procname, "kernel", 6);
 		} else if (pid > 0) {
 			FILE *fp;
-
 			snprintf(procname, sizeof(procname), "%s/%d/stat",
 				getenv("PROC_ROOT") ? : "/proc", pid);
 			if ((fp = fopen(procname, "r")) != NULL) {
@@ -4336,7 +3206,6 @@
 	if (state == NETLINK_CONNECTED) {
 		char dst_group_buf[30];
 		char dst_pid_buf[30];
-
 		sock_addr_print(int_to_str(dst_group, dst_group_buf), ":",
 				int_to_str(dst_pid, dst_pid_buf), NULL);
 	} else {
@@ -4344,7 +3213,6 @@
 	}
 
 	char *pid_context = NULL;
-
 	if (show_proc_ctx) {
 		/* The pid value will either be:
 		 *   0 if destination kernel - show kernel initial context.
@@ -4357,18 +3225,24 @@
 		else if (pid > 0)
 			getpidcon(pid, &pid_context);
 
-		out(" proc_ctx=%s", pid_context ? : "unavailable");
-		free(pid_context);
+		if (pid_context != NULL) {
+			printf("proc_ctx=%-*s ", serv_width, pid_context);
+			free(pid_context);
+		} else {
+			printf("proc_ctx=%-*s ", serv_width, "unavailable");
+		}
 	}
 
 	if (show_details) {
-		out(" sk=%llx cb=%llx groups=0x%08x", sk, cb, groups);
+		printf(" sk=%llx cb=%llx groups=0x%08x", sk, cb, groups);
 	}
+	printf("\n");
 
 	return 0;
 }
 
-static int netlink_show_sock(struct nlmsghdr *nlh, void *arg)
+static int netlink_show_sock(const struct sockaddr_nl *addr,
+		struct nlmsghdr *nlh, void *arg)
 {
 	struct filter *f = (struct filter *)arg;
 	struct netlink_diag_msg *r = NLMSG_DATA(nlh);
@@ -4376,7 +3250,7 @@
 	int rq = 0, wq = 0;
 	unsigned long groups = 0;
 
-	parse_rtattr(tb, NETLINK_DIAG_MAX, (struct rtattr *)(r+1),
+	parse_rtattr(tb, NETLINK_DIAG_MAX, (struct rtattr*)(r+1),
 		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
 	if (tb[NETLINK_DIAG_GROUPS] && RTA_PAYLOAD(tb[NETLINK_DIAG_GROUPS]))
@@ -4384,7 +3258,6 @@
 
 	if (tb[NETLINK_DIAG_MEMINFO]) {
 		const __u32 *skmeminfo;
-
 		skmeminfo = RTA_DATA(tb[NETLINK_DIAG_MEMINFO]);
 
 		rq = skmeminfo[SK_MEMINFO_RMEM_ALLOC];
@@ -4398,8 +3271,9 @@
 	}
 
 	if (show_mem) {
-		out("\t");
+		printf("\t");
 		print_skmeminfo(tb, NETLINK_DIAG_MEMINFO);
+		printf("\n");
 	}
 
 	return 0;
@@ -4421,7 +3295,7 @@
 	FILE *fp;
 	char buf[256];
 	int prot, pid;
-	unsigned int groups;
+	unsigned groups;
 	int rq, wq, rc;
 	unsigned long long sk, cb;
 
@@ -4451,239 +3325,44 @@
 	return 0;
 }
 
-static bool vsock_type_skip(struct sockstat *s, struct filter *f)
-{
-	if (s->type == SOCK_STREAM && !(f->dbs & (1 << VSOCK_ST_DB)))
-		return true;
-	if (s->type == SOCK_DGRAM && !(f->dbs & (1 << VSOCK_DG_DB)))
-		return true;
-	return false;
-}
-
-static void vsock_addr_print(inet_prefix *a, __u32 port)
-{
-	char cid_str[sizeof("4294967295")];
-	char port_str[sizeof("4294967295")];
-	__u32 cid;
-
-	memcpy(&cid, a->data, sizeof(cid));
-
-	if (cid == ~(__u32)0)
-		snprintf(cid_str, sizeof(cid_str), "*");
-	else
-		snprintf(cid_str, sizeof(cid_str), "%u", cid);
-
-	if (port == ~(__u32)0)
-		snprintf(port_str, sizeof(port_str), "*");
-	else
-		snprintf(port_str, sizeof(port_str), "%u", port);
-
-	sock_addr_print(cid_str, ":", port_str, NULL);
-}
-
-static void vsock_stats_print(struct sockstat *s, struct filter *f)
-{
-	sock_state_print(s);
-
-	vsock_addr_print(&s->local, s->lport);
-	vsock_addr_print(&s->remote, s->rport);
-
-	proc_ctx_print(s);
-}
-
-static int vsock_show_sock(struct nlmsghdr *nlh, void *arg)
-{
-	struct filter *f = (struct filter *)arg;
-	struct vsock_diag_msg *r = NLMSG_DATA(nlh);
-	struct sockstat stat = {
-		.type = r->vdiag_type,
-		.lport = r->vdiag_src_port,
-		.rport = r->vdiag_dst_port,
-		.state = r->vdiag_state,
-		.ino = r->vdiag_ino,
-	};
-
-	vsock_set_inet_prefix(&stat.local, r->vdiag_src_cid);
-	vsock_set_inet_prefix(&stat.remote, r->vdiag_dst_cid);
-
-	if (vsock_type_skip(&stat, f))
-		return 0;
-
-	if (f->f && run_ssfilter(f->f, &stat) == 0)
-		return 0;
-
-	vsock_stats_print(&stat, f);
-
-	return 0;
-}
-
-static int vsock_show(struct filter *f)
-{
-	DIAG_REQUEST(req, struct vsock_diag_req r);
-
-	if (!filter_af_get(f, AF_VSOCK))
-		return 0;
-
-	req.r.sdiag_family = AF_VSOCK;
-	req.r.vdiag_states = f->states;
-
-	return handle_netlink_request(f, &req.nlh, sizeof(req), vsock_show_sock);
-}
-
-static void tipc_sock_addr_print(struct rtattr *net_addr, struct rtattr *id)
-{
-	uint32_t node = rta_getattr_u32(net_addr);
-	uint32_t identity = rta_getattr_u32(id);
-
-	SPRINT_BUF(addr) = {};
-	SPRINT_BUF(port) = {};
-
-	sprintf(addr, "%u", node);
-	sprintf(port, "%u", identity);
-	sock_addr_print(addr, ":", port, NULL);
-
-}
-
-static int tipc_show_sock(struct nlmsghdr *nlh, void *arg)
-{
-	struct rtattr *stat[TIPC_NLA_SOCK_STAT_MAX + 1] = {};
-	struct rtattr *attrs[TIPC_NLA_SOCK_MAX + 1] = {};
-	struct rtattr *con[TIPC_NLA_CON_MAX + 1] = {};
-	struct rtattr *info[TIPC_NLA_MAX + 1] = {};
-	struct rtattr *msg_ref;
-	struct sockstat ss = {};
-
-	parse_rtattr(info, TIPC_NLA_MAX, NLMSG_DATA(nlh),
-		     NLMSG_PAYLOAD(nlh, 0));
-
-	if (!info[TIPC_NLA_SOCK])
-		return 0;
-
-	msg_ref = info[TIPC_NLA_SOCK];
-	parse_rtattr(attrs, TIPC_NLA_SOCK_MAX, RTA_DATA(msg_ref),
-		     RTA_PAYLOAD(msg_ref));
-
-	msg_ref = attrs[TIPC_NLA_SOCK_STAT];
-	parse_rtattr(stat, TIPC_NLA_SOCK_STAT_MAX,
-		     RTA_DATA(msg_ref), RTA_PAYLOAD(msg_ref));
-
-
-	ss.local.family = AF_TIPC;
-	ss.type = rta_getattr_u32(attrs[TIPC_NLA_SOCK_TYPE]);
-	ss.state = rta_getattr_u32(attrs[TIPC_NLA_SOCK_TIPC_STATE]);
-	ss.uid = rta_getattr_u32(attrs[TIPC_NLA_SOCK_UID]);
-	ss.ino = rta_getattr_u32(attrs[TIPC_NLA_SOCK_INO]);
-	ss.rq = rta_getattr_u32(stat[TIPC_NLA_SOCK_STAT_RCVQ]);
-	ss.wq = rta_getattr_u32(stat[TIPC_NLA_SOCK_STAT_SENDQ]);
-	ss.sk = rta_getattr_u64(attrs[TIPC_NLA_SOCK_COOKIE]);
-
-	sock_state_print (&ss);
-
-	tipc_sock_addr_print(attrs[TIPC_NLA_SOCK_ADDR],
-			     attrs[TIPC_NLA_SOCK_REF]);
-
-	msg_ref = attrs[TIPC_NLA_SOCK_CON];
-	if (msg_ref) {
-		parse_rtattr(con, TIPC_NLA_CON_MAX,
-			     RTA_DATA(msg_ref), RTA_PAYLOAD(msg_ref));
-
-		tipc_sock_addr_print(con[TIPC_NLA_CON_NODE],
-				     con[TIPC_NLA_CON_SOCK]);
-	} else
-		sock_addr_print("", "-", "", NULL);
-
-	if (show_details)
-		sock_details_print(&ss);
-
-	proc_ctx_print(&ss);
-
-	if (show_tipcinfo) {
-		if (oneline)
-			out(" type:%s", stype_nameg[ss.type]);
-		else
-			out("\n type:%s", stype_nameg[ss.type]);
-		out(" cong:%s ",
-		       stat[TIPC_NLA_SOCK_STAT_LINK_CONG] ? "link" :
-		       stat[TIPC_NLA_SOCK_STAT_CONN_CONG] ? "conn" : "none");
-		out(" drop:%d ",
-		       rta_getattr_u32(stat[TIPC_NLA_SOCK_STAT_DROP]));
-
-		if (attrs[TIPC_NLA_SOCK_HAS_PUBL])
-			out(" publ");
-
-		if (con[TIPC_NLA_CON_FLAG])
-			out(" via {%u,%u} ",
-			       rta_getattr_u32(con[TIPC_NLA_CON_TYPE]),
-			       rta_getattr_u32(con[TIPC_NLA_CON_INST]));
-	}
-
-	return 0;
-}
-
-static int tipc_show(struct filter *f)
-{
-	DIAG_REQUEST(req, struct tipc_sock_diag_req r);
-
-	memset(&req.r, 0, sizeof(req.r));
-	req.r.sdiag_family = AF_TIPC;
-	req.r.tidiag_states = f->states;
-
-	return handle_netlink_request(f, &req.nlh, sizeof(req), tipc_show_sock);
-}
-
 struct sock_diag_msg {
 	__u8 sdiag_family;
 };
 
-static int generic_show_sock(struct nlmsghdr *nlh, void *arg)
+static int generic_show_sock(const struct sockaddr_nl *addr,
+		struct nlmsghdr *nlh, void *arg)
 {
 	struct sock_diag_msg *r = NLMSG_DATA(nlh);
 	struct inet_diag_arg inet_arg = { .f = arg, .protocol = IPPROTO_MAX };
-	int ret;
 
 	switch (r->sdiag_family) {
 	case AF_INET:
 	case AF_INET6:
-		inet_arg.rth = inet_arg.f->rth_for_killing;
-		ret = show_one_inet_sock(nlh, &inet_arg);
-		break;
+		return show_one_inet_sock(addr, nlh, &inet_arg);
 	case AF_UNIX:
-		ret = unix_show_sock(nlh, arg);
-		break;
+		return unix_show_sock(addr, nlh, arg);
 	case AF_PACKET:
-		ret = packet_show_sock(nlh, arg);
-		break;
+		return packet_show_sock(addr, nlh, arg);
 	case AF_NETLINK:
-		ret = netlink_show_sock(nlh, arg);
-		break;
-	case AF_VSOCK:
-		ret = vsock_show_sock(nlh, arg);
-		break;
-	case AF_XDP:
-		ret = xdp_show_sock(nlh, arg);
-		break;
+		return netlink_show_sock(addr, nlh, arg);
 	default:
-		ret = -1;
+		return -1;
 	}
-
-	render();
-
-	return ret;
 }
 
 static int handle_follow_request(struct filter *f)
 {
-	int ret = 0;
+	int ret = -1;
 	int groups = 0;
-	struct rtnl_handle rth, rth2;
+	struct rtnl_handle rth;
 
-	if (f->families & FAMILY_MASK(AF_INET) && f->dbs & (1 << TCP_DB))
+	if (f->families & (1 << AF_INET) && f->dbs & (1 << TCP_DB))
 		groups |= 1 << (SKNLGRP_INET_TCP_DESTROY - 1);
-	if (f->families & FAMILY_MASK(AF_INET) && f->dbs & (1 << UDP_DB))
+	if (f->families & (1 << AF_INET) && f->dbs & (1 << UDP_DB))
 		groups |= 1 << (SKNLGRP_INET_UDP_DESTROY - 1);
-	if (f->families & FAMILY_MASK(AF_INET6) && f->dbs & (1 << TCP_DB))
+	if (f->families & (1 << AF_INET6) && f->dbs & (1 << TCP_DB))
 		groups |= 1 << (SKNLGRP_INET6_TCP_DESTROY - 1);
-	if (f->families & FAMILY_MASK(AF_INET6) && f->dbs & (1 << UDP_DB))
+	if (f->families & (1 << AF_INET6) && f->dbs & (1 << UDP_DB))
 		groups |= 1 << (SKNLGRP_INET6_UDP_DESTROY - 1);
 
 	if (groups == 0)
@@ -4695,23 +3374,20 @@
 	rth.dump = 0;
 	rth.local.nl_pid = 0;
 
-	if (f->kill) {
-		if (rtnl_open_byproto(&rth2, groups, NETLINK_SOCK_DIAG)) {
-			rtnl_close(&rth);
-			return -1;
-		}
-		f->rth_for_killing = &rth2;
-	}
-
 	if (rtnl_dump_filter(&rth, generic_show_sock, f))
-		ret = -1;
+		goto Exit;
 
+	ret = 0;
+Exit:
 	rtnl_close(&rth);
-	if (f->rth_for_killing)
-		rtnl_close(f->rth_for_killing);
 	return ret;
 }
 
+struct snmpstat
+{
+	int tcp_estab;
+};
+
 static int get_snmp_int(char *proto, char *key, int *result)
 {
 	char buf[1024];
@@ -4727,7 +3403,6 @@
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		char *p = buf;
 		int  pos = 0;
-
 		if (memcmp(buf, proto, protolen))
 			continue;
 		while ((p = strchr(p, ' ')) != NULL) {
@@ -4760,7 +3435,8 @@
 
 /* Get stats from sockstat */
 
-struct ssummary {
+struct ssummary
+{
 	int socks;
 	int tcp_mem;
 	int tcp_total;
@@ -4816,13 +3492,13 @@
 
 	if ((fp = net_sockstat_open()) == NULL)
 		return -1;
-	while (fgets(buf, sizeof(buf), fp) != NULL)
+	while(fgets(buf, sizeof(buf), fp) != NULL)
 		get_sockstat_line(buf, s);
 	fclose(fp);
 
 	if ((fp = net_sockstat6_open()) == NULL)
 		return 0;
-	while (fgets(buf, sizeof(buf), fp) != NULL)
+	while(fgets(buf, sizeof(buf), fp) != NULL)
 		get_sockstat_line(buf, s);
 	fclose(fp);
 
@@ -4832,22 +3508,30 @@
 static int print_summary(void)
 {
 	struct ssummary s;
-	int tcp_estab;
+	struct snmpstat sn;
 
 	if (get_sockstat(&s) < 0)
 		perror("ss: get_sockstat");
-	if (get_snmp_int("Tcp:", "CurrEstab", &tcp_estab) < 0)
+	if (get_snmp_int("Tcp:", "CurrEstab", &sn.tcp_estab) < 0)
 		perror("ss: get_snmpstat");
 
-	printf("Total: %d\n", s.socks);
+	get_slabstat(&slabstat);
 
-	printf("TCP:   %d (estab %d, closed %d, orphaned %d, timewait %d)\n",
-	       s.tcp_total + s.tcp_tws, tcp_estab,
-	       s.tcp_total - (s.tcp4_hashed + s.tcp6_hashed - s.tcp_tws),
-	       s.tcp_orphans, s.tcp_tws);
+	printf("Total: %d (kernel %d)\n", s.socks, slabstat.socks);
+
+	printf("TCP:   %d (estab %d, closed %d, orphaned %d, synrecv %d, timewait %d/%d), ports %d\n",
+	       s.tcp_total + slabstat.tcp_syns + s.tcp_tws,
+	       sn.tcp_estab,
+	       s.tcp_total - (s.tcp4_hashed+s.tcp6_hashed-s.tcp_tws),
+	       s.tcp_orphans,
+	       slabstat.tcp_syns,
+	       s.tcp_tws, slabstat.tcp_tws,
+	       slabstat.tcp_ports
+	       );
 
 	printf("\n");
 	printf("Transport Total     IP        IPv6\n");
+	printf("*	  %-9d %-9s %-9s\n", slabstat.socks, "-", "-");
 	printf("RAW	  %-9d %-9d %-9d\n", s.raw4+s.raw6, s.raw4, s.raw6);
 	printf("UDP	  %-9d %-9d %-9d\n", s.udp4+s.udp6, s.udp4, s.udp6);
 	printf("TCP	  %-9d %-9d %-9d\n", s.tcp4_hashed+s.tcp6_hashed, s.tcp4_hashed, s.tcp6_hashed);
@@ -4879,9 +3563,7 @@
 "   -m, --memory        show socket memory usage\n"
 "   -p, --processes     show process using socket\n"
 "   -i, --info          show internal TCP information\n"
-"       --tipcinfo      show internal tipc socket information\n"
 "   -s, --summary       show socket usage summary\n"
-"       --tos           show tos and priority information\n"
 "   -b, --bpf           show bpf filter socket information\n"
 "   -E, --events        continually display sockets as they are destroyed\n"
 "   -Z, --context       display process SELinux security contexts\n"
@@ -4892,32 +3574,26 @@
 "   -6, --ipv6          display only IP version 6 sockets\n"
 "   -0, --packet        display PACKET sockets\n"
 "   -t, --tcp           display only TCP sockets\n"
-"   -S, --sctp          display only SCTP sockets\n"
 "   -u, --udp           display only UDP sockets\n"
 "   -d, --dccp          display only DCCP sockets\n"
 "   -w, --raw           display only RAW sockets\n"
 "   -x, --unix          display only Unix domain sockets\n"
-"       --tipc          display only TIPC sockets\n"
-"       --vsock         display only vsock sockets\n"
 "   -f, --family=FAMILY display sockets of type FAMILY\n"
-"       FAMILY := {inet|inet6|link|unix|netlink|vsock|tipc|xdp|help}\n"
 "\n"
 "   -K, --kill          forcibly close sockets, display what was closed\n"
-"   -H, --no-header     Suppress header line\n"
-"   -O, --oneline       socket's data printed on a single line\n"
 "\n"
 "   -A, --query=QUERY, --socket=QUERY\n"
-"       QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram|tipc}[,QUERY]\n"
+"       QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink}[,QUERY]\n"
 "\n"
 "   -D, --diag=FILE     Dump raw information about TCP sockets to FILE\n"
 "   -F, --filter=FILE   read filter information from FILE\n"
 "       FILTER := [ state STATE-FILTER ] [ EXPRESSION ]\n"
 "       STATE-FILTER := {all|connected|synchronized|bucket|big|TCP-STATES}\n"
-"         TCP-STATES := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|closed|close-wait|last-ack|listening|closing}\n"
+"         TCP-STATES := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|closed|close-wait|last-ack|listen|closing}\n"
 "          connected := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}\n"
 "       synchronized := {established|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}\n"
 "             bucket := {syn-recv|time-wait}\n"
-"                big := {established|syn-sent|fin-wait-{1,2}|closed|close-wait|last-ack|listening|closing}\n"
+"                big := {established|syn-sent|fin-wait-{1,2}|closed|close-wait|last-ack|listen|closing}\n"
 		);
 }
 
@@ -4938,22 +3614,7 @@
 
 static int scan_state(const char *state)
 {
-	static const char * const sstate_namel[] = {
-		"UNKNOWN",
-		[SS_ESTABLISHED] = "established",
-		[SS_SYN_SENT] = "syn-sent",
-		[SS_SYN_RECV] = "syn-recv",
-		[SS_FIN_WAIT1] = "fin-wait-1",
-		[SS_FIN_WAIT2] = "fin-wait-2",
-		[SS_TIME_WAIT] = "time-wait",
-		[SS_CLOSE] = "unconnected",
-		[SS_CLOSE_WAIT] = "close-wait",
-		[SS_LAST_ACK] = "last-ack",
-		[SS_LISTEN] =	"listening",
-		[SS_CLOSING] = "closing",
-	};
 	int i;
-
 	if (strcasecmp(state, "close") == 0 ||
 	    strcasecmp(state, "closed") == 0)
 		return (1<<SS_CLOSE);
@@ -4971,7 +3632,7 @@
 		return (1<<SS_SYN_RECV)|(1<<SS_TIME_WAIT);
 	if (strcasecmp(state, "big") == 0)
 		return SS_ALL & ~((1<<SS_SYN_RECV)|(1<<SS_TIME_WAIT));
-	for (i = 0; i < SS_MAX; i++) {
+	for (i=0; i<SS_MAX; i++) {
 		if (strcasecmp(state, sstate_namel[i]) == 0)
 			return (1<<i);
 	}
@@ -4980,18 +3641,6 @@
 	exit(-1);
 }
 
-/* Values 'v' and 'V' are already used so a non-character is used */
-#define OPT_VSOCK 256
-
-/* Values of 't' are already used so a non-character is used */
-#define OPT_TIPCSOCK 257
-#define OPT_TIPCINFO 258
-
-#define OPT_TOS 259
-
-/* Values of 'x' are already used so a non-character is used */
-#define OPT_XDPSOCK 260
-
 static const struct option long_opts[] = {
 	{ "numeric", 0, 0, 'n' },
 	{ "resolve", 0, 0, 'r' },
@@ -5004,12 +3653,9 @@
 	{ "events", 0, 0, 'E' },
 	{ "dccp", 0, 0, 'd' },
 	{ "tcp", 0, 0, 't' },
-	{ "sctp", 0, 0, 'S' },
 	{ "udp", 0, 0, 'u' },
 	{ "raw", 0, 0, 'w' },
 	{ "unix", 0, 0, 'x' },
-	{ "tipc", 0, 0, OPT_TIPCSOCK},
-	{ "vsock", 0, 0, OPT_VSOCK },
 	{ "all", 0, 0, 'a' },
 	{ "listening", 0, 0, 'l' },
 	{ "ipv4", 0, 0, '4' },
@@ -5026,12 +3672,7 @@
 	{ "context", 0, 0, 'Z' },
 	{ "contexts", 0, 0, 'z' },
 	{ "net", 1, 0, 'N' },
-	{ "tipcinfo", 0, 0, OPT_TIPCINFO},
-	{ "tos", 0, 0, OPT_TOS },
 	{ "kill", 0, 0, 'K' },
-	{ "no-header", 0, 0, 'H' },
-	{ "xdp", 0, 0, OPT_XDPSOCK},
-	{ "oneline", 0, 0, 'O' },
 	{ 0 }
 
 };
@@ -5046,12 +3687,11 @@
 	int ch;
 	int state_filter = 0;
 
-	while ((ch = getopt_long(argc, argv,
-				 "dhaletuwxnro460spbEf:miA:D:F:vVzZN:KHSO",
+	while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spbEf:miA:D:F:vVzZN:K",
 				 long_opts, NULL)) != EOF) {
-		switch (ch) {
+		switch(ch) {
 		case 'n':
-			numeric = 1;
+			resolve_services = 0;
 			break;
 		case 'r':
 			resolve_hosts = 1;
@@ -5081,29 +3721,20 @@
 			follow_events = 1;
 			break;
 		case 'd':
-			filter_db_set(&current_filter, DCCP_DB, true);
+			filter_db_set(&current_filter, DCCP_DB);
 			break;
 		case 't':
-			filter_db_set(&current_filter, TCP_DB, true);
-			break;
-		case 'S':
-			filter_db_set(&current_filter, SCTP_DB, true);
+			filter_db_set(&current_filter, TCP_DB);
 			break;
 		case 'u':
-			filter_db_set(&current_filter, UDP_DB, true);
+			filter_db_set(&current_filter, UDP_DB);
 			break;
 		case 'w':
-			filter_db_set(&current_filter, RAW_DB, true);
+			filter_db_set(&current_filter, RAW_DB);
 			break;
 		case 'x':
 			filter_af_set(&current_filter, AF_UNIX);
 			break;
-		case OPT_VSOCK:
-			filter_af_set(&current_filter, AF_VSOCK);
-			break;
-		case OPT_TIPCSOCK:
-			filter_af_set(&current_filter, AF_TIPC);
-			break;
 		case 'a':
 			state_filter = SS_ALL;
 			break;
@@ -5119,9 +3750,6 @@
 		case '0':
 			filter_af_set(&current_filter, AF_PACKET);
 			break;
-		case OPT_XDPSOCK:
-			filter_af_set(&current_filter, AF_XDP);
-			break;
 		case 'f':
 			if (strcmp(optarg, "inet") == 0)
 				filter_af_set(&current_filter, AF_INET);
@@ -5133,12 +3761,6 @@
 				filter_af_set(&current_filter, AF_UNIX);
 			else if (strcmp(optarg, "netlink") == 0)
 				filter_af_set(&current_filter, AF_NETLINK);
-			else if (strcmp(optarg, "tipc") == 0)
-				filter_af_set(&current_filter, AF_TIPC);
-			else if (strcmp(optarg, "vsock") == 0)
-				filter_af_set(&current_filter, AF_VSOCK);
-			else if (strcmp(optarg, "xdp") == 0)
-				filter_af_set(&current_filter, AF_XDP);
 			else if (strcmp(optarg, "help") == 0)
 				help();
 			else {
@@ -5150,11 +3772,10 @@
 		case 'A':
 		{
 			char *p, *p1;
-
 			if (!saw_query) {
 				current_filter.dbs = 0;
 				state_filter = state_filter ?
-					       state_filter : SS_CONN;
+				               state_filter : SS_CONN;
 				saw_query = 1;
 				do_default = 0;
 			}
@@ -5162,7 +3783,46 @@
 			do {
 				if ((p1 = strchr(p, ',')) != NULL)
 					*p1 = 0;
-				if (filter_db_parse(&current_filter, p)) {
+				if (strcmp(p, "all") == 0) {
+					filter_default_dbs(&current_filter);
+				} else if (strcmp(p, "inet") == 0) {
+					filter_db_set(&current_filter, UDP_DB);
+					filter_db_set(&current_filter, DCCP_DB);
+					filter_db_set(&current_filter, TCP_DB);
+					filter_db_set(&current_filter, RAW_DB);
+				} else if (strcmp(p, "udp") == 0) {
+					filter_db_set(&current_filter, UDP_DB);
+				} else if (strcmp(p, "dccp") == 0) {
+					filter_db_set(&current_filter, DCCP_DB);
+				} else if (strcmp(p, "tcp") == 0) {
+					filter_db_set(&current_filter, TCP_DB);
+				} else if (strcmp(p, "raw") == 0) {
+					filter_db_set(&current_filter, RAW_DB);
+				} else if (strcmp(p, "unix") == 0) {
+					filter_db_set(&current_filter, UNIX_ST_DB);
+					filter_db_set(&current_filter, UNIX_DG_DB);
+					filter_db_set(&current_filter, UNIX_SQ_DB);
+				} else if (strcasecmp(p, "unix_stream") == 0 ||
+					   strcmp(p, "u_str") == 0) {
+					filter_db_set(&current_filter, UNIX_ST_DB);
+				} else if (strcasecmp(p, "unix_dgram") == 0 ||
+					   strcmp(p, "u_dgr") == 0) {
+					filter_db_set(&current_filter, UNIX_DG_DB);
+				} else if (strcasecmp(p, "unix_seqpacket") == 0 ||
+					   strcmp(p, "u_seq") == 0) {
+					filter_db_set(&current_filter, UNIX_SQ_DB);
+				} else if (strcmp(p, "packet") == 0) {
+					filter_db_set(&current_filter, PACKET_R_DB);
+					filter_db_set(&current_filter, PACKET_DG_DB);
+				} else if (strcmp(p, "packet_raw") == 0 ||
+					   strcmp(p, "p_raw") == 0) {
+					filter_db_set(&current_filter, PACKET_R_DB);
+				} else if (strcmp(p, "packet_dgram") == 0 ||
+					   strcmp(p, "p_dgr") == 0) {
+					filter_db_set(&current_filter, PACKET_DG_DB);
+				} else if (strcmp(p, "netlink") == 0) {
+					filter_db_set(&current_filter, NETLINK_DB);
+				} else {
 					fprintf(stderr, "ss: \"%s\" is illegal socket table id\n", p);
 					usage();
 				}
@@ -5196,7 +3856,6 @@
 			exit(0);
 		case 'z':
 			show_sock_ctx++;
-			/* fall through */
 		case 'Z':
 			if (is_selinux_enabled() <= 0) {
 				fprintf(stderr, "ss: SELinux is not enabled.\n");
@@ -5209,21 +3868,9 @@
 			if (netns_switch(optarg))
 				exit(1);
 			break;
-		case OPT_TIPCINFO:
-			show_tipcinfo = 1;
-			break;
-		case OPT_TOS:
-			show_tos = 1;
-			break;
 		case 'K':
 			current_filter.kill = 1;
 			break;
-		case 'H':
-			show_header = 0;
-			break;
-		case 'O':
-			oneline = 1;
-			break;
 		case 'h':
 			help();
 		case '?':
@@ -5263,16 +3910,17 @@
 
 	if (do_default) {
 		state_filter = state_filter ? state_filter : SS_CONN;
-		filter_db_parse(&current_filter, "all");
+		filter_default_dbs(&current_filter);
 	}
 
 	filter_states_set(&current_filter, state_filter);
 	filter_merge_defaults(&current_filter);
 
-	if (!numeric && resolve_hosts &&
-	    (current_filter.dbs & (UNIX_DBM|INET_L4_DBM)))
+	if (resolve_services && resolve_hosts &&
+	    (current_filter.dbs&(UNIX_DBM|(1<<TCP_DB)|(1<<UDP_DB)|(1<<DCCP_DB))))
 		init_service_resolver();
 
+
 	if (current_filter.dbs == 0) {
 		fprintf(stderr, "ss: no socket tables to show with such filter.\n");
 		exit(0);
@@ -5288,7 +3936,6 @@
 
 	if (dump_tcpdiag) {
 		FILE *dump_fp = stdout;
-
 		if (!(current_filter.dbs & (1<<TCP_DB))) {
 			fprintf(stderr, "ss: tcpdiag dump requested and no tcp in filter.\n");
 			exit(0);
@@ -5308,14 +3955,59 @@
 	if (ssfilter_parse(&current_filter.f, argc, argv, filter_fp))
 		usage();
 
-	if (!(current_filter.dbs & (current_filter.dbs - 1)))
-		columns[COL_NETID].disabled = 1;
+	netid_width = 0;
+	if (current_filter.dbs&(current_filter.dbs-1))
+		netid_width = 5;
 
-	if (!(current_filter.states & (current_filter.states - 1)))
-		columns[COL_STATE].disabled = 1;
+	state_width = 0;
+	if (current_filter.states&(current_filter.states-1))
+		state_width = 10;
 
-	if (show_header)
-		print_header();
+	screen_width = 80;
+	if (isatty(STDOUT_FILENO)) {
+		struct winsize w;
+
+		if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) {
+			if (w.ws_col > 0)
+				screen_width = w.ws_col;
+		}
+	}
+
+	addrp_width = screen_width;
+	addrp_width -= netid_width+1;
+	addrp_width -= state_width+1;
+	addrp_width -= 14;
+
+	if (addrp_width&1) {
+		if (netid_width)
+			netid_width++;
+		else if (state_width)
+			state_width++;
+	}
+
+	addrp_width /= 2;
+	addrp_width--;
+
+	serv_width = resolve_services ? 7 : 5;
+
+	if (addrp_width < 15+serv_width+1)
+		addrp_width = 15+serv_width+1;
+
+	addr_width = addrp_width - serv_width - 1;
+
+	if (netid_width)
+		printf("%-*s ", netid_width, "Netid");
+	if (state_width)
+		printf("%-*s ", state_width, "State");
+	printf("%-6s %-6s ", "Recv-Q", "Send-Q");
+
+	/* Make enough space for the local/remote port field */
+	addr_width -= 13;
+	serv_width += 13;
+
+	printf("%*s:%-*s %*s:%-*s\n",
+	       addr_width, "Local Address", serv_width, "Port",
+	       addr_width, "Peer Address", serv_width, "Port");
 
 	fflush(stdout);
 
@@ -5333,22 +4025,12 @@
 	if (current_filter.dbs & (1<<UDP_DB))
 		udp_show(&current_filter);
 	if (current_filter.dbs & (1<<TCP_DB))
-		tcp_show(&current_filter);
+		tcp_show(&current_filter, IPPROTO_TCP);
 	if (current_filter.dbs & (1<<DCCP_DB))
-		dccp_show(&current_filter);
-	if (current_filter.dbs & (1<<SCTP_DB))
-		sctp_show(&current_filter);
-	if (current_filter.dbs & VSOCK_DBM)
-		vsock_show(&current_filter);
-	if (current_filter.dbs & (1<<TIPC_DB))
-		tipc_show(&current_filter);
-	if (current_filter.dbs & (1<<XDP_DB))
-		xdp_show(&current_filter);
+		tcp_show(&current_filter, IPPROTO_DCCP);
 
 	if (show_users || show_proc_ctx || show_sock_ctx)
 		user_ent_destroy();
 
-	render();
-
 	return 0;
 }
diff --git a/misc/ssfilter.h b/misc/ssfilter.h
index f5b0bc8..c7293cc 100644
--- a/misc/ssfilter.h
+++ b/misc/ssfilter.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #define SSF_DCOND 0
 #define SSF_SCOND 1
 #define SSF_OR	  2
@@ -9,7 +8,6 @@
 #define SSF_S_GE  7
 #define SSF_S_LE  8
 #define SSF_S_AUTO  9
-#define SSF_DEVCOND 10
 #define SSF_MARKMASK 11
 
 #include <stdbool.h>
@@ -23,5 +21,4 @@
 
 int ssfilter_parse(struct ssfilter **f, int argc, char **argv, FILE *fp);
 void *parse_hostcond(char *addr, bool is_port);
-void *parse_devcond(char *name);
 void *parse_markmask(const char *markmask);
diff --git a/misc/ssfilter.y b/misc/ssfilter.y
index a901ae7..ba6b06f 100644
--- a/misc/ssfilter.y
+++ b/misc/ssfilter.y
@@ -4,7 +4,10 @@
 #include <stdlib.h>
 #include <malloc.h>
 #include <string.h>
-#include "ssfilter.h"
+/* NOTE: Android yacc build rules transform ssfilter.y into ssfilter.h, and
+ * #include "ssfilter.h" gets this file instead of the ssfilter.h in the
+ * source tree. This does not work. #include <ssfilter.h> instead. */
+#include <ssfilter.h>
 
 typedef struct ssfilter * ssfilter_t;
 
@@ -36,60 +39,28 @@
 
 %}
 
-%token HOSTCOND DCOND SCOND DPORT SPORT LEQ GEQ NEQ AUTOBOUND DEVCOND DEVNAME MARKMASK FWMARK
+%token HOSTCOND DCOND SCOND DPORT SPORT LEQ GEQ NEQ AUTOBOUND MARKMASK FWMARK
 %left '|'
 %left '&'
 %nonassoc '!'
 
 %%
-applet: exprlist
+applet: null expr
         {
-                *yy_ret = $1;
-                $$ = $1;
+                *yy_ret = $2;
+                $$ = $2;
         }
         | null
         ;
-
 null:   /* NOTHING */ { $$ = NULL; }
         ;
-
-exprlist: expr
-        | exprlist '|' expr
+expr:	DCOND HOSTCOND
         {
-                $$ = alloc_node(SSF_OR, $1);
-                $$->post = $3;
+		$$ = alloc_node(SSF_DCOND, $2);
         }
-        | exprlist '&' expr
+        | SCOND HOSTCOND
         {
-                $$ = alloc_node(SSF_AND, $1);
-                $$->post = $3;
-        }
-        | exprlist expr
-        {
-                $$ = alloc_node(SSF_AND, $1);
-                $$->post = $2;
-        }
-        ;
-
-eq:	'='
-	| /* nothing */
-	;
-
-expr:	'(' exprlist ')'
-	{
-		$$ = $2;
-	}
-	| '!' expr
-	{
-		$$ = alloc_node(SSF_NOT, $2);
-	}
-	| DCOND eq HOSTCOND
-        {
-		$$ = alloc_node(SSF_DCOND, $3);
-        }
-        | SCOND eq HOSTCOND
-        {
-		$$ = alloc_node(SSF_SCOND, $3);
+		$$ = alloc_node(SSF_SCOND, $2);
         }
         | DPORT GEQ HOSTCOND
         {
@@ -107,7 +78,7 @@
         {
                 $$ = alloc_node(SSF_NOT, alloc_node(SSF_D_GE, $3));
         }
-        | DPORT eq HOSTCOND
+        | DPORT '=' HOSTCOND
         {
 		$$ = alloc_node(SSF_DCOND, $3);
         }
@@ -132,7 +103,7 @@
         {
                 $$ = alloc_node(SSF_NOT, alloc_node(SSF_S_GE, $3));
         }
-        | SPORT eq HOSTCOND
+        | SPORT '=' HOSTCOND
         {
 		$$ = alloc_node(SSF_SCOND, $3);
         }
@@ -140,15 +111,7 @@
         {
 		$$ = alloc_node(SSF_NOT, alloc_node(SSF_SCOND, $3));
         }
-        | DEVNAME eq DEVCOND
-        {
-		$$ = alloc_node(SSF_DEVCOND, $3);
-        }
-        | DEVNAME NEQ DEVCOND
-        {
-		$$ = alloc_node(SSF_NOT, alloc_node(SSF_DEVCOND, $3));
-        }
-        | FWMARK eq MARKMASK
+        | FWMARK '=' MARKMASK
         {
                 $$ = alloc_node(SSF_MARKMASK, $3);
         }
@@ -160,6 +123,30 @@
         {
                 $$ = alloc_node(SSF_S_AUTO, NULL);
         }
+        | expr '|' expr
+        {
+                $$ = alloc_node(SSF_OR, $1);
+	        $$->post = $3;
+        }
+        | expr expr
+        {
+                $$ = alloc_node(SSF_AND, $1);
+	        $$->post = $2;
+        }
+        | expr '&' expr
+
+        {
+                $$ = alloc_node(SSF_AND, $1);
+	        $$->post = $3;
+        }
+        | '!' expr
+        {
+                $$ = alloc_node(SSF_NOT, $2);
+        }
+        | '(' expr ')'
+        {
+                $$ = $2;
+        }
 ;
 %%
 
@@ -210,23 +197,15 @@
 				argc++;
 			} else if (yy_fp) {
 				while (tokptr == NULL) {
-					size_t len;
-
-					if (fgets(argbuf, sizeof(argbuf), yy_fp) == NULL)
+					if (fgets(argbuf, sizeof(argbuf)-1, yy_fp) == NULL)
 						return 0;
-
-					len = strnlen(argbuf, sizeof(argbuf));
-					if (len == 0) {
-						fprintf(stderr, "Invalid line\n");
+					argbuf[sizeof(argbuf)-1] = 0;
+					if (strlen(argbuf) == sizeof(argbuf) - 1) {
+						fprintf(stderr, "Too long line in filter");
 						exit(-1);
 					}
-
-					if (len >= sizeof(argbuf) - 1) {
-						fprintf(stderr, "Too long line in filter\n");
-						exit(-1);
-					}
-					if (argbuf[len - 1] == '\n')
-						argbuf[len-1] = 0;
+					if (argbuf[strlen(argbuf)-1] == '\n')
+						argbuf[strlen(argbuf)-1] = 0;
 					if (argbuf[0] == '#' || argbuf[0] == '0')
 						continue;
 					tokptr = argbuf;
@@ -268,10 +247,6 @@
 		tok_type = SPORT;
 		return SPORT;
 	}
-	if (strcmp(curtok, "dev") == 0) {
-		tok_type = DEVNAME;
-		return DEVNAME;
-	}
 	if (strcmp(curtok, "fwmark") == 0) {
 		tok_type = FWMARK;
 		return FWMARK;
@@ -302,14 +277,6 @@
 		tok_type = AUTOBOUND;
 		return AUTOBOUND;
 	}
-	if (tok_type == DEVNAME) {
-		yylval = (void*)parse_devcond(curtok);
-		if (yylval == NULL) {
-			fprintf(stderr, "Cannot parse device.\n");
-			exit(1);
-		}
-		return DEVCOND;
-	}
 	if (tok_type == FWMARK) {
 		yylval = (void*)parse_markmask(curtok);
 		if (yylval == NULL) {
diff --git a/netem/Makefile b/netem/Makefile
index ba4c5a7..e52e125 100644
--- a/netem/Makefile
+++ b/netem/Makefile
@@ -1,12 +1,9 @@
-# SPDX-License-Identifier: GPL-2.0
-include ../config.mk
-
 DISTGEN = maketable normal pareto paretonormal
 DISTDATA = normal.dist pareto.dist paretonormal.dist experimental.dist
 
 HOSTCC ?= $(CC)
 CCOPTS  = $(CBUILD_CFLAGS)
-LDLIBS += -lm
+LDLIBS += -lm 
 
 all: $(DISTGEN) $(DISTDATA)
 
diff --git a/netem/README.distribution b/netem/README.distribution
index 6d52785..23f7ecb 100644
--- a/netem/README.distribution
+++ b/netem/README.distribution
@@ -1,4 +1,4 @@
-Notes about distribution tables from Nistnet
+Notes about distribution tables from Nistnet 
 -------------------------------------------------------------------------------
 I. About the distribution tables
 
diff --git a/netem/maketable.c b/netem/maketable.c
index ccb8f0c..a5452b6 100644
--- a/netem/maketable.c
+++ b/netem/maketable.c
@@ -24,8 +24,8 @@
 	int limit;
 	int n=0, i;
 
-	if (!fstat(fileno(fp), &info) &&
-	    info.st_size > 0) {
+	fstat(fileno(fp), &info);
+	if (info.st_size > 0) {
 		limit = 2*info.st_size/sizeof(double);	/* @@ approximate */
 	} else {
 		limit = 10000;
@@ -38,8 +38,8 @@
 	}
 
 	for (i=0; i<limit; ++i){
-		if (fscanf(fp, "%lf", &x[i]) != 1 ||
-		    feof(fp))
+		fscanf(fp, "%lf", &x[i]);
+		if (feof(fp))
 			break;
 		++n;
 	}
@@ -149,8 +149,6 @@
 		inversevalue = (int)rint(findex*TABLEFACTOR);
 		if (inversevalue <= MINSHORT) inversevalue = MINSHORT+1;
 		if (inversevalue > MAXSHORT) inversevalue = MAXSHORT;
-		if (inverseindex >= inversesize) inverseindex = inversesize- 1;
-
 		inverse[inverseindex] = inversevalue;
 	}
 	return inverse;
@@ -212,7 +210,7 @@
 		}
 	} else {
 		fp = stdin;
-	}
+	}				
 	x = readdoubles(fp, &limit);
 	if (limit <= 0) {
 		fprintf(stderr, "Nothing much read!\n");
@@ -223,7 +221,7 @@
 	fprintf(stderr, "%d values, mu %10.4f, sigma %10.4f, rho %10.4f\n",
 		limit, mu, sigma, rho);
 #endif
-
+	
 	table = makedist(x, limit, mu, sigma);
 	free((void *) x);
 	cumulativedist(table, DISTTABLESIZE, &total);
diff --git a/netem/normal.c b/netem/normal.c
index 90963f4..dbdebb1 100644
--- a/netem/normal.c
+++ b/netem/normal.c
@@ -33,7 +33,7 @@
 		table[i] = x;
 	}
 
-
+	
 	printf("# This is the distribution table for the normal distribution.\n");
 	for (i = n = 0; i < TABLESIZE; i += 4) {
 		int value = (int) rint(table[i]*TABLEFACTOR);
diff --git a/netem/pareto.c b/netem/pareto.c
index 51d9437..8aa647b 100644
--- a/netem/pareto.c
+++ b/netem/pareto.c
@@ -36,6 +36,6 @@
 			n = 0;
 		}
 	}
-
+	
 	return 0;
-}
+}	
diff --git a/netem/paretonormal.c b/netem/paretonormal.c
index 9773e37..ed75f28 100644
--- a/netem/paretonormal.c
+++ b/netem/paretonormal.c
@@ -11,6 +11,7 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdlib.h>
 #include <string.h>
 #include <math.h>
 #include <limits.h>
@@ -43,7 +44,7 @@
 	if (dvalue > 32767)
 		dvalue = 32767;
 	return (int)rint(dvalue);
-}
+}	
 
 int
 main(int argc, char **argv)
diff --git a/rdma/.gitignore b/rdma/.gitignore
deleted file mode 100644
index 51fb172..0000000
--- a/rdma/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-rdma
diff --git a/rdma/Makefile b/rdma/Makefile
deleted file mode 100644
index e3f550b..0000000
--- a/rdma/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-include ../config.mk
-
-TARGETS :=
-
-ifeq ($(HAVE_MNL),y)
-CFLAGS += -I./include/uapi/
-
-RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o \
-	   res-cmid.o res-qp.o sys.o stat.o
-
-TARGETS += rdma
-endif
-
-all:	$(TARGETS) $(LIBS)
-
-rdma:	$(RDMA_OBJ) $(LIBS)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
-
-install: all
-	for i in $(TARGETS); \
-	do install -m 0755 $$i $(DESTDIR)$(SBINDIR); \
-	done
-
-clean:
-	rm -f $(RDMA_OBJ) $(TARGETS)
diff --git a/rdma/dev.c b/rdma/dev.c
deleted file mode 100644
index c597cba..0000000
--- a/rdma/dev.c
+++ /dev/null
@@ -1,398 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * dev.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include <fcntl.h>
-#include "rdma.h"
-
-static int dev_help(struct rd *rd)
-{
-	pr_out("Usage: %s dev show [DEV]\n", rd->filename);
-	pr_out("       %s dev set [DEV] name DEVNAME\n", rd->filename);
-	pr_out("       %s dev set [DEV] netns NSNAME\n", rd->filename);
-	pr_out("       %s dev set [DEV] adaptive-moderation [on|off]\n", rd->filename);
-	return 0;
-}
-
-static const char *dev_caps_to_str(uint32_t idx)
-{
-#define RDMA_DEV_FLAGS_LOW(x) \
-	x(RESIZE_MAX_WR, 0) \
-	x(BAD_PKEY_CNTR, 1) \
-	x(BAD_QKEY_CNTR, 2) \
-	x(RAW_MULTI, 3) \
-	x(AUTO_PATH_MIG, 4) \
-	x(CHANGE_PHY_PORT, 5) \
-	x(UD_AV_PORT_ENFORCE_PORT_ENFORCE, 6) \
-	x(CURR_QP_STATE_MOD, 7) \
-	x(SHUTDOWN_PORT, 8) \
-	x(INIT_TYPE, 9) \
-	x(PORT_ACTIVE_EVENT, 10) \
-	x(SYS_IMAGE_GUID, 11) \
-	x(RC_RNR_NAK_GEN, 12) \
-	x(SRQ_RESIZE, 13) \
-	x(N_NOTIFY_CQ, 14) \
-	x(LOCAL_DMA_LKEY, 15) \
-	x(MEM_WINDOW, 17) \
-	x(UD_IP_CSUM, 18) \
-	x(UD_TSO, 19) \
-	x(XRC, 20) \
-	x(MEM_MGT_EXTENSIONS, 21) \
-	x(BLOCK_MULTICAST_LOOPBACK, 22) \
-	x(MEM_WINDOW_TYPE_2A, 23) \
-	x(MEM_WINDOW_TYPE_2B, 24) \
-	x(RC_IP_CSUM, 25) \
-	x(RAW_IP_CSUM, 26) \
-	x(CROSS_CHANNEL, 27) \
-	x(MANAGED_FLOW_STEERING, 29) \
-	x(SIGNATURE_HANDOVER, 30) \
-	x(ON_DEMAND_PAGING, 31)
-
-#define RDMA_DEV_FLAGS_HIGH(x) \
-	x(SG_GAPS_REG, 0) \
-	x(VIRTUAL_FUNCTION, 1) \
-	x(RAW_SCATTER_FCS, 2) \
-	x(RDMA_NETDEV_OPA_VNIC, 3) \
-	x(PCI_WRITE_END_PADDING, 4)
-
-	/*
-	 * Separation below is needed to allow compilation of rdmatool
-	 * on 32bits systems. On such systems, C-enum is limited to be
-	 * int and can't hold more than 32 bits.
-	 */
-	enum { RDMA_DEV_FLAGS_LOW(RDMA_BITMAP_ENUM) };
-	enum { RDMA_DEV_FLAGS_HIGH(RDMA_BITMAP_ENUM) };
-
-	static const char * const
-		rdma_dev_names_low[] = { RDMA_DEV_FLAGS_LOW(RDMA_BITMAP_NAMES) };
-	static const char * const
-		rdma_dev_names_high[] = { RDMA_DEV_FLAGS_HIGH(RDMA_BITMAP_NAMES) };
-	uint32_t high_idx;
-	#undef RDMA_DEV_FLAGS_LOW
-	#undef RDMA_DEV_FLAGS_HIGH
-
-	if (idx < ARRAY_SIZE(rdma_dev_names_low) && rdma_dev_names_low[idx])
-		return rdma_dev_names_low[idx];
-
-	high_idx = idx - ARRAY_SIZE(rdma_dev_names_low);
-	if (high_idx <  ARRAY_SIZE(rdma_dev_names_high) &&
-	    rdma_dev_names_high[high_idx])
-		return rdma_dev_names_high[high_idx];
-
-	return "UNKNOWN";
-}
-
-static void dev_print_caps(struct rd *rd, struct nlattr **tb)
-{
-	uint64_t caps;
-	uint32_t idx;
-
-	if (!tb[RDMA_NLDEV_ATTR_CAP_FLAGS])
-		return;
-
-	caps = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_CAP_FLAGS]);
-
-	if (rd->json_output) {
-		jsonw_name(rd->jw, "caps");
-		jsonw_start_array(rd->jw);
-	} else {
-		pr_out("\n    caps: <");
-	}
-	for (idx = 0; caps; idx++) {
-		if (caps & 0x1) {
-			if (rd->json_output) {
-				jsonw_string(rd->jw, dev_caps_to_str(idx));
-			} else {
-				pr_out("%s", dev_caps_to_str(idx));
-				if (caps >> 0x1)
-					pr_out(", ");
-			}
-		}
-		caps >>= 0x1;
-	}
-
-	if (rd->json_output)
-		jsonw_end_array(rd->jw);
-	else
-		pr_out(">");
-}
-
-static void dev_print_fw(struct rd *rd, struct nlattr **tb)
-{
-	const char *str;
-	if (!tb[RDMA_NLDEV_ATTR_FW_VERSION])
-		return;
-
-	str = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_FW_VERSION]);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "fw", str);
-	else
-		pr_out("fw %s ", str);
-}
-
-static void dev_print_node_guid(struct rd *rd, struct nlattr **tb)
-{
-	uint64_t node_guid;
-	uint16_t vp[4];
-	char str[32];
-
-	if (!tb[RDMA_NLDEV_ATTR_NODE_GUID])
-		return;
-
-	node_guid = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_NODE_GUID]);
-	memcpy(vp, &node_guid, sizeof(uint64_t));
-	snprintf(str, 32, "%04x:%04x:%04x:%04x", vp[3], vp[2], vp[1], vp[0]);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "node_guid", str);
-	else
-		pr_out("node_guid %s ", str);
-}
-
-static void dev_print_sys_image_guid(struct rd *rd, struct nlattr **tb)
-{
-	uint64_t sys_image_guid;
-	uint16_t vp[4];
-	char str[32];
-
-	if (!tb[RDMA_NLDEV_ATTR_SYS_IMAGE_GUID])
-		return;
-
-	sys_image_guid = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_SYS_IMAGE_GUID]);
-	memcpy(vp, &sys_image_guid, sizeof(uint64_t));
-	snprintf(str, 32, "%04x:%04x:%04x:%04x", vp[3], vp[2], vp[1], vp[0]);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "sys_image_guid", str);
-	else
-		pr_out("sys_image_guid %s ", str);
-}
-
-static void dev_print_dim_setting(struct rd *rd, struct nlattr **tb)
-{
-	uint8_t dim_setting;
-
-	if (!tb[RDMA_NLDEV_ATTR_DEV_DIM])
-		return;
-
-	dim_setting = mnl_attr_get_u8(tb[RDMA_NLDEV_ATTR_DEV_DIM]);
-	if (dim_setting > 1)
-		return;
-
-	print_on_off(rd, "adaptive-moderation", dim_setting);
-
-}
-
-static const char *node_type_to_str(uint8_t node_type)
-{
-	static const char * const node_type_str[] = { "unknown", "ca",
-						      "switch", "router",
-						      "rnic", "usnic",
-						      "usnic_udp",
-						      "unspecified" };
-	if (node_type < ARRAY_SIZE(node_type_str))
-		return node_type_str[node_type];
-	return "unknown";
-}
-
-static void dev_print_node_type(struct rd *rd, struct nlattr **tb)
-{
-	const char *node_str;
-	uint8_t node_type;
-
-	if (!tb[RDMA_NLDEV_ATTR_DEV_NODE_TYPE])
-		return;
-
-	node_type = mnl_attr_get_u8(tb[RDMA_NLDEV_ATTR_DEV_NODE_TYPE]);
-	node_str = node_type_to_str(node_type);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "node_type", node_str);
-	else
-		pr_out("node_type %s ", node_str);
-}
-
-static int dev_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	if (rd->json_output) {
-		jsonw_uint_field(rd->jw, "ifindex", idx);
-		jsonw_string_field(rd->jw, "ifname", name);
-	} else {
-		pr_out("%u: %s: ", idx, name);
-	}
-
-	dev_print_node_type(rd, tb);
-	dev_print_fw(rd, tb);
-	dev_print_node_guid(rd, tb);
-	dev_print_sys_image_guid(rd, tb);
-	if (rd->show_details) {
-		dev_print_dim_setting(rd, tb);
-		dev_print_caps(rd, tb);
-	}
-
-	if (!rd->json_output)
-		pr_out("\n");
-	return MNL_CB_OK;
-}
-
-static int dev_no_args(struct rd *rd)
-{
-	uint32_t seq;
-	int ret;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_GET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	if (rd->json_output)
-		jsonw_start_object(rd->jw);
-	ret = rd_recv_msg(rd, dev_parse_cb, rd, seq);
-	if (rd->json_output)
-		jsonw_end_object(rd->jw);
-	return ret;
-}
-
-static int dev_one_show(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		dev_no_args},
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int dev_set_name(struct rd *rd)
-{
-	uint32_t seq;
-
-	if (rd_no_arg(rd)) {
-		pr_err("Please provide device new name.\n");
-		return -EINVAL;
-	}
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_SET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_DEV_NAME, rd_argv(rd));
-
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int dev_set_netns(struct rd *rd)
-{
-	char *netns_path;
-	uint32_t seq;
-	int netns;
-	int ret;
-
-	if (rd_no_arg(rd)) {
-		pr_err("Please provide device name.\n");
-		return -EINVAL;
-	}
-
-	if (asprintf(&netns_path, "%s/%s", NETNS_RUN_DIR, rd_argv(rd)) < 0)
-		return -ENOMEM;
-
-	netns = open(netns_path, O_RDONLY | O_CLOEXEC);
-	if (netns < 0) {
-		fprintf(stderr, "Cannot open network namespace \"%s\": %s\n",
-			rd_argv(rd), strerror(errno));
-		ret = -EINVAL;
-		goto done;
-	}
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_SET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_NET_NS_FD, netns);
-	ret = rd_sendrecv_msg(rd, seq);
-	close(netns);
-done:
-	free(netns_path);
-	return ret;
-}
-
-static int dev_set_dim_sendmsg(struct rd *rd, uint8_t dim_setting)
-{
-	uint32_t seq;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_SET, &seq,
-		       (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u8(rd->nlh, RDMA_NLDEV_ATTR_DEV_DIM, dim_setting);
-
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int dev_set_dim_off(struct rd *rd)
-{
-	return dev_set_dim_sendmsg(rd, 0);
-}
-
-static int dev_set_dim_on(struct rd *rd)
-{
-	return dev_set_dim_sendmsg(rd, 1);
-}
-
-static int dev_set_dim(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		dev_help},
-		{ "on",		dev_set_dim_on},
-		{ "off",	dev_set_dim_off},
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int dev_one_set(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		dev_help},
-		{ "name",	dev_set_name},
-		{ "netns",	dev_set_netns},
-		{ "adaptive-moderation",	dev_set_dim},
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int dev_show(struct rd *rd)
-{
-	return rd_exec_dev(rd, dev_one_show);
-}
-
-static int dev_set(struct rd *rd)
-{
-	return rd_exec_require_dev(rd, dev_one_set);
-}
-
-int cmd_dev(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		dev_show },
-		{ "show",	dev_show },
-		{ "list",	dev_show },
-		{ "set",	dev_set },
-		{ "help",	dev_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "dev command");
-}
diff --git a/rdma/link.c b/rdma/link.c
deleted file mode 100644
index 10b2e51..0000000
--- a/rdma/link.c
+++ /dev/null
@@ -1,428 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * link.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "rdma.h"
-
-static int link_help(struct rd *rd)
-{
-	pr_out("Usage: %s link show [DEV/PORT_INDEX]\n", rd->filename);
-	pr_out("Usage: %s link add NAME type TYPE netdev NETDEV\n",
-	       rd->filename);
-	pr_out("Usage: %s link delete NAME\n", rd->filename);
-	return 0;
-}
-
-static const char *caps_to_str(uint32_t idx)
-{
-#define RDMA_PORT_FLAGS_LOW(x) \
-	x(RESERVED, 0) \
-	x(SM, 1) \
-	x(NOTICE, 2) \
-	x(TRAP, 3) \
-	x(OPT_IPD, 4) \
-	x(AUTO_MIGR, 5) \
-	x(SL_MAP, 6) \
-	x(MKEY_NVRAM, 7) \
-	x(PKEY_NVRAM, 8) \
-	x(LED_INFO, 9) \
-	x(SM_DISABLED, 10) \
-	x(SYS_IMAGE_GUID, 11) \
-	x(PKEY_SW_EXT_PORT_TRAP, 12) \
-	x(CABLE_INFO, 13) \
-	x(EXTENDED_SPEEDS, 14) \
-	x(CAP_MASK2, 15) \
-	x(CM, 16) \
-	x(SNMP_TUNNEL, 17) \
-	x(REINIT, 18) \
-	x(DEVICE_MGMT, 19) \
-	x(VENDOR_CLASS, 20) \
-	x(DR_NOTICE, 21) \
-	x(CAP_MASK_NOTICE, 22) \
-	x(BOOT_MGMT, 23) \
-	x(LINK_LATENCY, 24) \
-	x(CLIENT_REG, 25) \
-	x(OTHER_LOCAL_CHANGES, 26) \
-	x(LINK_SPPED_WIDTH, 27) \
-	x(VENDOR_SPECIFIC_MADS, 28) \
-	x(MULT_PKER_TRAP, 29) \
-	x(MULT_FDB, 30) \
-	x(HIERARCHY_INFO, 31)
-
-#define RDMA_PORT_FLAGS_HIGH(x) \
-	x(SET_NODE_DESC, 0) \
-	x(EXT_INFO, 1) \
-	x(VIRT, 2) \
-	x(SWITCH_POR_STATE_TABLE, 3) \
-	x(LINK_WIDTH_2X, 4) \
-	x(LINK_SPEED_HDR, 5)
-
-	/*
-	 * Separation below is needed to allow compilation of rdmatool
-	 * on 32bits systems. On such systems, C-enum is limited to be
-	 * int and can't hold more than 32 bits.
-	 */
-	enum { RDMA_PORT_FLAGS_LOW(RDMA_BITMAP_ENUM) };
-	enum { RDMA_PORT_FLAGS_HIGH(RDMA_BITMAP_ENUM) };
-
-	static const char * const
-		rdma_port_names_low[] = { RDMA_PORT_FLAGS_LOW(RDMA_BITMAP_NAMES) };
-	static const char * const
-		rdma_port_names_high[] = { RDMA_PORT_FLAGS_HIGH(RDMA_BITMAP_NAMES) };
-	uint32_t high_idx;
-	#undef RDMA_PORT_FLAGS_LOW
-	#undef RDMA_PORT_FLAGS_HIGH
-
-	if (idx < ARRAY_SIZE(rdma_port_names_low) && rdma_port_names_low[idx])
-		return rdma_port_names_low[idx];
-
-	high_idx = idx - ARRAY_SIZE(rdma_port_names_low);
-	if (high_idx < ARRAY_SIZE(rdma_port_names_high) &&
-	    rdma_port_names_high[high_idx])
-		return rdma_port_names_high[high_idx];
-
-	return "UNKNOWN";
-}
-
-static void link_print_caps(struct rd *rd, struct nlattr **tb)
-{
-	uint64_t caps;
-	uint32_t idx;
-
-	if (!tb[RDMA_NLDEV_ATTR_CAP_FLAGS])
-		return;
-
-	caps = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_CAP_FLAGS]);
-
-	if (rd->json_output) {
-		jsonw_name(rd->jw, "caps");
-		jsonw_start_array(rd->jw);
-	} else {
-		pr_out("\n    caps: <");
-	}
-	for (idx = 0; caps; idx++) {
-		if (caps & 0x1) {
-			if (rd->json_output) {
-				jsonw_string(rd->jw, caps_to_str(idx));
-			} else {
-				pr_out("%s", caps_to_str(idx));
-				if (caps >> 0x1)
-					pr_out(", ");
-			}
-		}
-		caps >>= 0x1;
-	}
-
-	if (rd->json_output)
-		jsonw_end_array(rd->jw);
-	else
-		pr_out(">");
-}
-
-static void link_print_subnet_prefix(struct rd *rd, struct nlattr **tb)
-{
-	uint64_t subnet_prefix;
-	uint16_t vp[4];
-	char str[32];
-
-	if (!tb[RDMA_NLDEV_ATTR_SUBNET_PREFIX])
-		return;
-
-	subnet_prefix = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_SUBNET_PREFIX]);
-	memcpy(vp, &subnet_prefix, sizeof(uint64_t));
-	snprintf(str, 32, "%04x:%04x:%04x:%04x", vp[3], vp[2], vp[1], vp[0]);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "subnet_prefix", str);
-	else
-		pr_out("subnet_prefix %s ", str);
-}
-
-static void link_print_lid(struct rd *rd, struct nlattr **tb)
-{
-	uint32_t lid;
-
-	if (!tb[RDMA_NLDEV_ATTR_LID])
-		return;
-
-	lid = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_LID]);
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "lid", lid);
-	else
-		pr_out("lid %u ", lid);
-}
-
-static void link_print_sm_lid(struct rd *rd, struct nlattr **tb)
-{
-	uint32_t sm_lid;
-
-	if (!tb[RDMA_NLDEV_ATTR_SM_LID])
-		return;
-
-	sm_lid = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_SM_LID]);
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "sm_lid", sm_lid);
-	else
-		pr_out("sm_lid %u ", sm_lid);
-}
-
-static void link_print_lmc(struct rd *rd, struct nlattr **tb)
-{
-	uint8_t lmc;
-
-	if (!tb[RDMA_NLDEV_ATTR_LMC])
-		return;
-
-	lmc = mnl_attr_get_u8(tb[RDMA_NLDEV_ATTR_LMC]);
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "lmc", lmc);
-	else
-		pr_out("lmc %u ", lmc);
-}
-
-static const char *link_state_to_str(uint8_t link_state)
-{
-	static const char * const link_state_str[] = { "NOP", "DOWN",
-						       "INIT", "ARMED",
-						       "ACTIVE",
-						       "ACTIVE_DEFER" };
-	if (link_state < ARRAY_SIZE(link_state_str))
-		return link_state_str[link_state];
-	return "UNKNOWN";
-}
-
-static void link_print_state(struct rd *rd, struct nlattr **tb)
-{
-	uint8_t state;
-
-	if (!tb[RDMA_NLDEV_ATTR_PORT_STATE])
-		return;
-
-	state = mnl_attr_get_u8(tb[RDMA_NLDEV_ATTR_PORT_STATE]);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "state", link_state_to_str(state));
-	else
-		pr_out("state %s ", link_state_to_str(state));
-}
-
-static const char *phys_state_to_str(uint8_t phys_state)
-{
-	static const char * const phys_state_str[] = { "NOP", "SLEEP",
-						       "POLLING", "DISABLED",
-						       "ARMED", "LINK_UP",
-						       "LINK_ERROR_RECOVER",
-						       "PHY_TEST", "UNKNOWN",
-						       "OPA_OFFLINE",
-						       "UNKNOWN", "OPA_TEST" };
-	if (phys_state < ARRAY_SIZE(phys_state_str))
-		return phys_state_str[phys_state];
-	return "UNKNOWN";
-};
-
-static void link_print_phys_state(struct rd *rd, struct nlattr **tb)
-{
-	uint8_t phys_state;
-
-	if (!tb[RDMA_NLDEV_ATTR_PORT_PHYS_STATE])
-		return;
-
-	phys_state = mnl_attr_get_u8(tb[RDMA_NLDEV_ATTR_PORT_PHYS_STATE]);
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "physical_state",
-				   phys_state_to_str(phys_state));
-	else
-		pr_out("physical_state %s ", phys_state_to_str(phys_state));
-}
-
-static void link_print_netdev(struct rd *rd, struct nlattr **tb)
-{
-	const char *netdev_name;
-	uint32_t idx;
-
-	if (!tb[RDMA_NLDEV_ATTR_NDEV_NAME] || !tb[RDMA_NLDEV_ATTR_NDEV_INDEX])
-		return;
-
-	netdev_name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_NDEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_NDEV_INDEX]);
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "netdev", netdev_name);
-		jsonw_uint_field(rd->jw, "netdev_index", idx);
-	} else {
-		pr_out("netdev %s ", netdev_name);
-		if (rd->show_details)
-			pr_out("netdev_index %u ", idx);
-	}
-}
-
-static int link_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	uint32_t port, idx;
-	char name[32];
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	if (!tb[RDMA_NLDEV_ATTR_PORT_INDEX]) {
-		pr_err("This tool doesn't support switches yet\n");
-		return MNL_CB_ERROR;
-	}
-
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	port = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
-	snprintf(name, 32, "%s/%u",
-		 mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]), port);
-
-	if (rd->json_output) {
-		jsonw_uint_field(rd->jw, "ifindex", idx);
-		jsonw_uint_field(rd->jw, "port", port);
-		jsonw_string_field(rd->jw, "ifname", name);
-
-	} else {
-		pr_out("%u/%u: %s: ", idx, port, name);
-	}
-
-	link_print_subnet_prefix(rd, tb);
-	link_print_lid(rd, tb);
-	link_print_sm_lid(rd, tb);
-	link_print_lmc(rd, tb);
-	link_print_state(rd, tb);
-	link_print_phys_state(rd, tb);
-	link_print_netdev(rd, tb);
-	if (rd->show_details)
-		link_print_caps(rd, tb);
-
-	if (!rd->json_output)
-		pr_out("\n");
-	return MNL_CB_OK;
-}
-
-static int link_no_args(struct rd *rd)
-{
-	uint32_t seq;
-	int ret;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_PORT_GET, &seq,
-		       (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	if (rd->json_output)
-		jsonw_start_object(rd->jw);
-	ret = rd_recv_msg(rd, link_parse_cb, rd, seq);
-	if (rd->json_output)
-		jsonw_end_object(rd->jw);
-	return ret;
-}
-
-static int link_one_show(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		link_no_args},
-		{ 0 }
-	};
-
-	if (!rd->port_idx)
-		return 0;
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int link_show(struct rd *rd)
-{
-	return rd_exec_link(rd, link_one_show, true);
-}
-
-static int link_add_netdev(struct rd *rd)
-{
-	char *link_netdev;
-	uint32_t seq;
-
-	if (rd_no_arg(rd)) {
-		pr_err("Please provide a net device name.\n");
-		return -EINVAL;
-	}
-
-	link_netdev = rd_argv(rd);
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_NEWLINK, &seq,
-		       (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_DEV_NAME, rd->link_name);
-	mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_LINK_TYPE, rd->link_type);
-	mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_NDEV_NAME, link_netdev);
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int link_add_type(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		link_help},
-		{ "netdev",	link_add_netdev},
-		{ 0 }
-	};
-
-	if (rd_no_arg(rd)) {
-		pr_err("Please provide a link type name.\n");
-		return -EINVAL;
-	}
-	rd->link_type = rd_argv(rd);
-	rd_arg_inc(rd);
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int link_add(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		link_help},
-		{ "type",	link_add_type},
-		{ 0 }
-	};
-
-	if (rd_no_arg(rd)) {
-		pr_err("Please provide a link name to add.\n");
-		return -EINVAL;
-	}
-	rd->link_name = rd_argv(rd);
-	rd_arg_inc(rd);
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int _link_del(struct rd *rd)
-{
-	uint32_t seq;
-
-	if (!rd_no_arg(rd)) {
-		pr_err("Unknown parameter %s\n", rd_argv(rd));
-		return -EINVAL;
-	}
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_DELLINK, &seq,
-		       (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int link_del(struct rd *rd)
-{
-	return rd_exec_require_dev(rd, _link_del);
-}
-
-int cmd_link(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		link_show },
-		{ "add",	link_add },
-		{ "delete",	link_del },
-		{ "show",	link_show },
-		{ "list",	link_show },
-		{ "help",	link_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "link command");
-}
diff --git a/rdma/rdma.c b/rdma/rdma.c
deleted file mode 100644
index 4e34da9..0000000
--- a/rdma/rdma.c
+++ /dev/null
@@ -1,200 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * rdma.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "rdma.h"
-#include "SNAPSHOT.h"
-
-static void help(char *name)
-{
-	pr_out("Usage: %s [ OPTIONS ] OBJECT { COMMAND | help }\n"
-	       "       %s [ -f[orce] ] -b[atch] filename\n"
-	       "where  OBJECT := { dev | link | resource | system | statistic | help }\n"
-	       "       OPTIONS := { -V[ersion] | -d[etails] | -j[son] | -p[retty]}\n", name, name);
-}
-
-static int cmd_help(struct rd *rd)
-{
-	help(rd->filename);
-	return 0;
-}
-
-static int rd_cmd(struct rd *rd, int argc, char **argv)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		cmd_help },
-		{ "help",	cmd_help },
-		{ "dev",	cmd_dev },
-		{ "link",	cmd_link },
-		{ "resource",	cmd_res },
-		{ "system",	cmd_sys },
-		{ "statistic",	cmd_stat },
-		{ 0 }
-	};
-
-	rd->argc = argc;
-	rd->argv = argv;
-
-	return rd_exec_cmd(rd, cmds, "object");
-}
-
-static int rd_batch(struct rd *rd, const char *name, bool force)
-{
-	char *line = NULL;
-	size_t len = 0;
-	int ret = 0;
-
-	if (name && strcmp(name, "-") != 0) {
-		if (!freopen(name, "r", stdin)) {
-			pr_err("Cannot open file \"%s\" for reading: %s\n",
-			       name, strerror(errno));
-			return errno;
-		}
-	}
-
-	cmdlineno = 0;
-	while (getcmdline(&line, &len, stdin) != -1) {
-		char *largv[512];
-		int largc;
-
-		largc = makeargs(line, largv, ARRAY_SIZE(largv));
-		if (!largc)
-			continue;	/* blank line */
-
-		ret = rd_cmd(rd, largc, largv);
-		if (ret) {
-			pr_err("Command failed %s:%d\n", name, cmdlineno);
-			if (!force)
-				break;
-		}
-	}
-
-	free(line);
-
-	return ret;
-}
-
-static int rd_init(struct rd *rd, char *filename)
-{
-	uint32_t seq;
-	int ret;
-
-	rd->filename = filename;
-	INIT_LIST_HEAD(&rd->dev_map_list);
-	INIT_LIST_HEAD(&rd->filter_list);
-
-	if (rd->json_output) {
-		rd->jw = jsonw_new(stdout);
-		if (!rd->jw) {
-			pr_err("Failed to create JSON writer\n");
-			return -ENOMEM;
-		}
-		jsonw_pretty(rd->jw, rd->pretty_output);
-	}
-
-	rd->buff = malloc(MNL_SOCKET_BUFFER_SIZE);
-	if (!rd->buff)
-		return -ENOMEM;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_GET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP));
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	return rd_recv_msg(rd, rd_dev_init_cb, rd, seq);
-}
-
-static void rd_cleanup(struct rd *rd)
-{
-	if (rd->json_output)
-		jsonw_destroy(&rd->jw);
-	rd_free(rd);
-}
-
-int main(int argc, char **argv)
-{
-	static const struct option long_options[] = {
-		{ "version",		no_argument,		NULL, 'V' },
-		{ "help",		no_argument,		NULL, 'h' },
-		{ "json",		no_argument,		NULL, 'j' },
-		{ "pretty",		no_argument,		NULL, 'p' },
-		{ "details",		no_argument,		NULL, 'd' },
-		{ "force",		no_argument,		NULL, 'f' },
-		{ "batch",		required_argument,	NULL, 'b' },
-		{ NULL, 0, NULL, 0 }
-	};
-	bool show_driver_details = false;
-	const char *batch_file = NULL;
-	bool pretty_output = false;
-	bool show_details = false;
-	bool json_output = false;
-	bool force = false;
-	struct rd rd = {};
-	char *filename;
-	int opt;
-	int err;
-
-	filename = basename(argv[0]);
-
-	while ((opt = getopt_long(argc, argv, ":Vhdpjfb:",
-				  long_options, NULL)) >= 0) {
-		switch (opt) {
-		case 'V':
-			printf("%s utility, iproute2-ss%s\n",
-			       filename, SNAPSHOT);
-			return EXIT_SUCCESS;
-		case 'p':
-			pretty_output = true;
-			break;
-		case 'd':
-			if (show_details)
-				show_driver_details = true;
-			else
-				show_details = true;
-			break;
-		case 'j':
-			json_output = true;
-			break;
-		case 'f':
-			force = true;
-			break;
-		case 'b':
-			batch_file = optarg;
-			break;
-		case 'h':
-			help(filename);
-			return EXIT_SUCCESS;
-		case ':':
-			pr_err("-%c option requires an argument\n", optopt);
-			return EXIT_FAILURE;
-		default:
-			pr_err("Unknown option.\n");
-			help(filename);
-			return EXIT_FAILURE;
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	rd.show_details = show_details;
-	rd.show_driver_details = show_driver_details;
-	rd.json_output = json_output;
-	rd.pretty_output = pretty_output;
-
-	err = rd_init(&rd, filename);
-	if (err)
-		goto out;
-
-	if (batch_file)
-		err = rd_batch(&rd, batch_file, force);
-	else
-		err = rd_cmd(&rd, argc, argv);
-out:
-	/* Always cleanup */
-	rd_cleanup(&rd);
-	return err ? EXIT_FAILURE : EXIT_SUCCESS;
-}
diff --git a/rdma/rdma.h b/rdma/rdma.h
deleted file mode 100644
index dfd1b70..0000000
--- a/rdma/rdma.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
-/*
- * rdma.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-#ifndef _RDMA_TOOL_H_
-#define _RDMA_TOOL_H_
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <getopt.h>
-#include <netinet/in.h>
-#include <libmnl/libmnl.h>
-#include <rdma/rdma_netlink.h>
-#include <rdma/rdma_user_cm.h>
-#include <time.h>
-#include <net/if_arp.h>
-
-#include "list.h"
-#include "utils.h"
-#include "json_writer.h"
-
-#define pr_err(args...) fprintf(stderr, ##args)
-#define pr_out(args...) fprintf(stdout, ##args)
-
-#define RDMA_BITMAP_ENUM(name, bit_no) RDMA_BITMAP_##name = BIT(bit_no),
-#define RDMA_BITMAP_NAMES(name, bit_no) [bit_no] = #name,
-
-#define MAX_NUMBER_OF_FILTERS 64
-struct filters {
-	const char *name;
-	uint8_t is_number:1;
-	uint8_t is_doit:1;
-};
-
-struct filter_entry {
-	struct list_head list;
-	char *key;
-	char *value;
-	/*
-	 * This field menas that we can try to issue .doit calback
-	 * on value above. This value can be converted to integer
-	 * with simple atoi(). Otherwise "is_doit" will be false.
-	 */
-	uint8_t is_doit:1;
-};
-
-struct dev_map {
-	struct list_head list;
-	char *dev_name;
-	uint32_t num_ports;
-	uint32_t idx;
-};
-
-struct rd {
-	int argc;
-	char **argv;
-	char *filename;
-	bool show_details;
-	bool show_driver_details;
-	struct list_head dev_map_list;
-	uint32_t dev_idx;
-	uint32_t port_idx;
-	struct mnl_socket *nl;
-	struct nlmsghdr *nlh;
-	char *buff;
-	json_writer_t *jw;
-	bool json_output;
-	bool pretty_output;
-	bool suppress_errors;
-	struct list_head filter_list;
-	char *link_name;
-	char *link_type;
-};
-
-struct rd_cmd {
-	const char *cmd;
-	int (*func)(struct rd *rd);
-};
-
-/*
- * Parser interface
- */
-bool rd_no_arg(struct rd *rd);
-void rd_arg_inc(struct rd *rd);
-
-char *rd_argv(struct rd *rd);
-
-/*
- * Commands interface
- */
-int cmd_dev(struct rd *rd);
-int cmd_link(struct rd *rd);
-int cmd_res(struct rd *rd);
-int cmd_sys(struct rd *rd);
-int cmd_stat(struct rd *rd);
-int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
-int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
-int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd));
-int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port);
-void rd_free(struct rd *rd);
-int rd_set_arg_to_devname(struct rd *rd);
-int rd_argc(struct rd *rd);
-
-int strcmpx(const char *str1, const char *str2);
-
-/*
- * Device manipulation
- */
-struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);
-
-/*
- * Filter manipulation
- */
-bool rd_doit_index(struct rd *rd, uint32_t *idx);
-int rd_build_filter(struct rd *rd, const struct filters valid_filters[]);
-bool rd_is_filtered_attr(struct rd *rd, const char *key, uint32_t val,
-			 struct nlattr *attr);
-bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val,
-				struct nlattr *attr);
-/*
- * Netlink
- */
-int rd_send_msg(struct rd *rd);
-int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq);
-int rd_sendrecv_msg(struct rd *rd, unsigned int seq);
-void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags);
-int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data);
-int rd_attr_cb(const struct nlattr *attr, void *data);
-int rd_attr_check(const struct nlattr *attr, int *typep);
-
-/*
- * Print helpers
- */
-void print_driver_table(struct rd *rd, struct nlattr *tb);
-void newline(struct rd *rd);
-void newline_indent(struct rd *rd);
-void print_on_off(struct rd *rd, const char *key_str, bool on);
-#define MAX_LINE_LENGTH 80
-
-#endif /* _RDMA_TOOL_H_ */
diff --git a/rdma/res-cmid.c b/rdma/res-cmid.c
deleted file mode 100644
index 0b83008..0000000
--- a/rdma/res-cmid.c
+++ /dev/null
@@ -1,275 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * res-cmid.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "res.h"
-#include <inttypes.h>
-
-static void print_qp_type(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "qp-type", qp_types_to_str(val));
-	else
-		pr_out("qp-type %s ", qp_types_to_str(val));
-}
-
-static const char *cm_id_state_to_str(uint8_t idx)
-{
-	static const char *const cm_id_states_str[] = {
-		"IDLE",		  "ADDR_QUERY",     "ADDR_RESOLVED",
-		"ROUTE_QUERY",    "ROUTE_RESOLVED", "CONNECT",
-		"DISCONNECT",     "ADDR_BOUND",     "LISTEN",
-		"DEVICE_REMOVAL", "DESTROYING"
-	};
-
-	if (idx < ARRAY_SIZE(cm_id_states_str))
-		return cm_id_states_str[idx];
-	return "UNKNOWN";
-}
-
-static const char *cm_id_ps_to_str(uint32_t ps)
-{
-	switch (ps) {
-	case RDMA_PS_IPOIB:
-		return "IPoIB";
-	case RDMA_PS_IB:
-		return "IPoIB";
-	case RDMA_PS_TCP:
-		return "TCP";
-	case RDMA_PS_UDP:
-		return "UDP";
-	default:
-		return "---";
-	}
-}
-
-static void print_cm_id_state(struct rd *rd, uint8_t state)
-{
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "state", cm_id_state_to_str(state));
-		return;
-	}
-	pr_out("state %s ", cm_id_state_to_str(state));
-}
-
-static void print_ps(struct rd *rd, uint32_t ps)
-{
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "ps", cm_id_ps_to_str(ps));
-		return;
-	}
-	pr_out("ps %s ", cm_id_ps_to_str(ps));
-}
-
-static void print_ipaddr(struct rd *rd, const char *key, char *addrstr,
-			 uint16_t port)
-{
-	if (rd->json_output) {
-		int name_size = INET6_ADDRSTRLEN + strlen(":65535");
-		char json_name[name_size];
-
-		snprintf(json_name, name_size, "%s:%u", addrstr, port);
-		jsonw_string_field(rd->jw, key, json_name);
-		return;
-	}
-	pr_out("%s %s:%u ", key, addrstr, port);
-}
-
-static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)
-{
-	struct __kernel_sockaddr_storage *addr;
-
-	addr = (struct __kernel_sockaddr_storage *)mnl_attr_get_payload(
-		nla_line);
-	switch (addr->ss_family) {
-	case AF_INET: {
-		struct sockaddr_in *sin = (struct sockaddr_in *)addr;
-
-		if (!inet_ntop(AF_INET, (const void *)&sin->sin_addr, addr_str,
-			       INET6_ADDRSTRLEN))
-			return -EINVAL;
-		*port = ntohs(sin->sin_port);
-		break;
-	}
-	case AF_INET6: {
-		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
-
-		if (!inet_ntop(AF_INET6, (const void *)&sin6->sin6_addr,
-			       addr_str, INET6_ADDRSTRLEN))
-			return -EINVAL;
-		*port = ntohs(sin6->sin6_port);
-		break;
-	}
-	default:
-		return -EINVAL;
-	}
-	return 0;
-}
-static int res_cm_id_line(struct rd *rd, const char *name, int idx,
-		       struct nlattr **nla_line)
-{
-	char src_addr_str[INET6_ADDRSTRLEN];
-	char dst_addr_str[INET6_ADDRSTRLEN];
-	uint16_t src_port, dst_port;
-	uint32_t port = 0, pid = 0;
-	uint8_t type = 0, state;
-	uint32_t lqpn = 0, ps;
-	uint32_t cm_idn = 0;
-	char *comm = NULL;
-
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
-	    !nla_line[RDMA_NLDEV_ATTR_RES_PS] ||
-	    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-	     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-		return MNL_CB_ERROR;
-	}
-
-	if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-		port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
-
-	if (port && port != rd->port_idx)
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN])
-		lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-
-	if (rd_is_filtered_attr(rd, "lqpn", lqpn,
-				nla_line[RDMA_NLDEV_ATTR_RES_LQPN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE])
-		type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
-	if (rd_is_string_filtered_attr(rd, "qp-type", qp_types_to_str(type),
-				       nla_line[RDMA_NLDEV_ATTR_RES_TYPE]))
-		goto out;
-
-	ps = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PS]);
-	if (rd_is_string_filtered_attr(rd, "ps", cm_id_ps_to_str(ps),
-				       nla_line[RDMA_NLDEV_ATTR_RES_PS]))
-		goto out;
-
-	state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
-	if (rd_is_string_filtered_attr(rd, "state", cm_id_state_to_str(state),
-				       nla_line[RDMA_NLDEV_ATTR_RES_STATE]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR])
-		if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR],
-			    src_addr_str, &src_port))
-			goto out;
-	if (rd_is_string_filtered_attr(rd, "src-addr", src_addr_str,
-				       nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]))
-		goto out;
-	if (rd_is_filtered_attr(rd, "src-port", src_port,
-				nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR])
-		if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR],
-			    dst_addr_str, &dst_port))
-			goto out;
-	if (rd_is_string_filtered_attr(rd, "dst-addr", dst_addr_str,
-				       nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]))
-		goto out;
-	if (rd_is_filtered_attr(rd, "dst-port", dst_port,
-				nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-		comm = get_task_name(pid);
-	}
-
-	if (rd_is_filtered_attr(rd, "pid", pid,
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
-		cm_idn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]);
-	if (rd_is_filtered_attr(rd, "cm-idn", cm_idn,
-				nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
-		/* discard const from mnl_attr_get_str */
-		comm = (char *)mnl_attr_get_str(
-			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-	}
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-
-	print_link(rd, idx, name, port, nla_line);
-	res_print_uint(rd, "cm-idn", cm_idn,
-		       nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]);
-	res_print_uint(rd, "lqpn", lqpn, nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-	if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE])
-		print_qp_type(rd, type);
-	print_cm_id_state(rd, state);
-	print_ps(rd, ps);
-	res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-	print_comm(rd, comm, nla_line);
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR])
-		print_ipaddr(rd, "src-addr", src_addr_str, src_port);
-	if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR])
-		print_ipaddr(rd, "dst-addr", dst_addr_str, dst_port);
-
-	print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-	newline(rd);
-
-out:	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-		free(comm);
-	return MNL_CB_OK;
-}
-
-int res_cm_id_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	int idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-
-	return res_cm_id_line(rd, name, idx, tb);
-}
-
-int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	int ret = MNL_CB_OK;
-	const char *name;
-	int idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_CM_ID])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_CM_ID];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-
-		ret = res_cm_id_line(rd, name, idx, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-	}
-	return ret;
-}
diff --git a/rdma/res-cq.c b/rdma/res-cq.c
deleted file mode 100644
index d2591fb..0000000
--- a/rdma/res-cq.c
+++ /dev/null
@@ -1,175 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * res-cq.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "res.h"
-#include <inttypes.h>
-
-static const char *poll_ctx_to_str(uint8_t idx)
-{
-	static const char * const cm_id_states_str[] = {
-		"DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"};
-
-	if (idx < ARRAY_SIZE(cm_id_states_str))
-		return cm_id_states_str[idx];
-	return "UNKNOWN";
-}
-
-static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr)
-{
-	if (!attr)
-		return;
-
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "poll-ctx",
-				   poll_ctx_to_str(poll_ctx));
-		return;
-	}
-	pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx));
-}
-
-static void print_cq_dim_setting(struct rd *rd, struct nlattr *attr)
-{
-	uint8_t dim_setting;
-
-	if (!attr)
-		return;
-
-	dim_setting = mnl_attr_get_u8(attr);
-	if (dim_setting > 1)
-		return;
-
-	print_on_off(rd, "adaptive-moderation", dim_setting);
-}
-
-static int res_cq_line(struct rd *rd, const char *name, int idx,
-		       struct nlattr **nla_line)
-{
-	char *comm = NULL;
-	uint32_t pid = 0;
-	uint8_t poll_ctx = 0;
-	uint32_t ctxn = 0;
-	uint32_t cqn = 0;
-	uint64_t users;
-	uint32_t cqe;
-
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
-	    !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
-	    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-	     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-		return MNL_CB_ERROR;
-	}
-
-	cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
-
-	users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-	if (rd_is_filtered_attr(rd, "users", users,
-				nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
-		poll_ctx =
-			mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
-	if (rd_is_string_filtered_attr(rd, "poll-ctx",
-				       poll_ctx_to_str(poll_ctx),
-				       nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-		comm = get_task_name(pid);
-	}
-
-	if (rd_is_filtered_attr(rd, "pid", pid,
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
-		cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
-	if (rd_is_filtered_attr(rd, "cqn", cqn,
-				nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
-		goto out;
-	if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
-		ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-	if (rd_is_filtered_attr(rd, "ctxn", ctxn,
-				nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-		/* discard const from mnl_attr_get_str */
-		comm = (char *)mnl_attr_get_str(
-			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-
-	print_dev(rd, idx, name);
-	res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
-	res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
-	res_print_uint(rd, "users", users,
-		       nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-	print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
-	print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]);
-	res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-	res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-	print_comm(rd, comm, nla_line);
-
-	print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-	newline(rd);
-
-out:	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-		free(comm);
-	return MNL_CB_OK;
-}
-
-int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-
-	return res_cq_line(rd, name, idx, tb);
-}
-
-int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	int ret = MNL_CB_OK;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_CQ])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-
-		ret = res_cq_line(rd, name, idx, nla_line);
-
-		if (ret != MNL_CB_OK)
-			break;
-	}
-	return ret;
-}
diff --git a/rdma/res-mr.c b/rdma/res-mr.c
deleted file mode 100644
index f4a24dc..0000000
--- a/rdma/res-mr.c
+++ /dev/null
@@ -1,133 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * res-mr.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "res.h"
-#include <inttypes.h>
-
-static int res_mr_line(struct rd *rd, const char *name, int idx,
-		       struct nlattr **nla_line)
-{
-	uint32_t rkey = 0, lkey = 0;
-	uint64_t iova = 0, mrlen;
-	char *comm = NULL;
-	uint32_t pdn = 0;
-	uint32_t mrn = 0;
-	uint32_t pid = 0;
-
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN] ||
-	    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-	     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-		return MNL_CB_ERROR;
-	}
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
-		rkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
-	if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
-		lkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
-	if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
-		iova = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
-
-	mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
-	if (rd_is_filtered_attr(rd, "mrlen", mrlen,
-				nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-		comm = get_task_name(pid);
-	}
-
-	if (rd_is_filtered_attr(rd, "pid", pid,
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
-		mrn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
-	if (rd_is_filtered_attr(rd, "mrn", mrn,
-				nla_line[RDMA_NLDEV_ATTR_RES_MRN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-		pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-	if (rd_is_filtered_attr(rd, "pdn", pdn,
-				nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-		/* discard const from mnl_attr_get_str */
-		comm = (char *)mnl_attr_get_str(
-			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-
-	print_dev(rd, idx, name);
-	res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
-	print_key(rd, "rkey", rkey, nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
-	print_key(rd, "lkey", lkey, nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
-	print_key(rd, "iova", iova, nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
-	res_print_uint(rd, "mrlen", mrlen, nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
-	res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-	res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-	print_comm(rd, comm, nla_line);
-
-	print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-	newline(rd);
-
-out:
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-		free(comm);
-	return MNL_CB_OK;
-}
-
-int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-
-	return res_mr_line(rd, name, idx, tb);
-}
-
-int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	int ret = MNL_CB_OK;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_MR])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_MR];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-
-		ret = res_mr_line(rd, name, idx, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-	}
-	return ret;
-}
diff --git a/rdma/res-pd.c b/rdma/res-pd.c
deleted file mode 100644
index 07c836e..0000000
--- a/rdma/res-pd.c
+++ /dev/null
@@ -1,136 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * res-pd.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "res.h"
-#include <inttypes.h>
-
-static int res_pd_line(struct rd *rd, const char *name, int idx,
-		       struct nlattr **nla_line)
-{
-	uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0;
-	char *comm = NULL;
-	uint32_t ctxn = 0;
-	uint32_t pid = 0;
-	uint32_t pdn = 0;
-	uint64_t users;
-
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
-	    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-	     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-		return MNL_CB_ERROR;
-	}
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY])
-		local_dma_lkey = mnl_attr_get_u32(
-			nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]);
-
-	users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-	if (rd_is_filtered_attr(rd, "users", users,
-				nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
-		unsafe_global_rkey = mnl_attr_get_u32(
-			nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]);
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-		comm = get_task_name(pid);
-	}
-
-	if (rd_is_filtered_attr(rd, "pid", pid,
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
-		ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-
-	if (rd_is_filtered_attr(rd, "ctxn", ctxn,
-				nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-		pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-	if (rd_is_filtered_attr(rd, "pdn", pdn,
-				nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-		/* discard const from mnl_attr_get_str */
-		comm = (char *)mnl_attr_get_str(
-			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-
-	print_dev(rd, idx, name);
-	res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-	print_key(rd, "local_dma_lkey", local_dma_lkey,
-		  nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]);
-	res_print_uint(rd, "users", users,
-		       nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-	print_key(rd, "unsafe_global_rkey", unsafe_global_rkey,
-		  nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]);
-	res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-	res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-	print_comm(rd, comm, nla_line);
-
-	print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-	newline(rd);
-
-out:	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-		free(comm);
-	return MNL_CB_OK;
-}
-
-int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-
-	return res_pd_line(rd, name, idx, tb);
-}
-
-int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	int ret = MNL_CB_OK;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_PD])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_PD];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-
-		ret = res_pd_line(rd, name, idx, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-	}
-	return ret;
-}
diff --git a/rdma/res-qp.c b/rdma/res-qp.c
deleted file mode 100644
index 954e465..0000000
--- a/rdma/res-qp.c
+++ /dev/null
@@ -1,240 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * res-qp.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "res.h"
-#include <inttypes.h>
-
-static const char *path_mig_to_str(uint8_t idx)
-{
-	static const char *const path_mig_str[] = { "MIGRATED", "REARM",
-						    "ARMED" };
-
-	if (idx < ARRAY_SIZE(path_mig_str))
-		return path_mig_str[idx];
-	return "UNKNOWN";
-}
-
-static const char *qp_states_to_str(uint8_t idx)
-{
-	static const char *const qp_states_str[] = { "RESET", "INIT", "RTR",
-						     "RTS",   "SQD",  "SQE",
-						     "ERR" };
-
-	if (idx < ARRAY_SIZE(qp_states_str))
-		return qp_states_str[idx];
-	return "UNKNOWN";
-}
-
-static void print_rqpn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
-{
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQPN])
-		return;
-
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "rqpn", val);
-	else
-		pr_out("rqpn %u ", val);
-}
-
-static void print_type(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "type", qp_types_to_str(val));
-	else
-		pr_out("type %s ", qp_types_to_str(val));
-}
-
-static void print_state(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "state", qp_states_to_str(val));
-	else
-		pr_out("state %s ", qp_states_to_str(val));
-}
-
-static void print_rqpsn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
-{
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN])
-		return;
-
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "rq-psn", val);
-	else
-		pr_out("rq-psn %u ", val);
-}
-
-static void print_pathmig(struct rd *rd, uint32_t val, struct nlattr **nla_line)
-{
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
-		return;
-
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "path-mig-state",
-				   path_mig_to_str(val));
-	else
-		pr_out("path-mig-state %s ", path_mig_to_str(val));
-}
-
-static int res_qp_line(struct rd *rd, const char *name, int idx,
-		       struct nlattr **nla_line)
-{
-	uint32_t lqpn, rqpn = 0, rq_psn = 0, sq_psn;
-	uint8_t type, state, path_mig_state = 0;
-	uint32_t port = 0, pid = 0;
-	uint32_t pdn = 0;
-	char *comm = NULL;
-
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_LQPN] ||
-	    !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN] ||
-	    !nla_line[RDMA_NLDEV_ATTR_RES_TYPE] ||
-	    !nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
-	    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-	     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-		return MNL_CB_ERROR;
-	}
-
-	if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-		port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
-
-	if (port != rd->port_idx)
-		goto out;
-
-	lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-	if (rd_is_filtered_attr(rd, "lqpn", lqpn,
-				nla_line[RDMA_NLDEV_ATTR_RES_LQPN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-		pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-	if (rd_is_filtered_attr(rd, "pdn", pdn,
-				nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN])
-		rqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQPN]);
-	if (rd_is_filtered_attr(rd, "rqpn", rqpn,
-				nla_line[RDMA_NLDEV_ATTR_RES_RQPN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN])
-		rq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]);
-	if (rd_is_filtered_attr(rd, "rq-psn", rq_psn,
-				nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]))
-		goto out;
-
-	sq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]);
-	if (rd_is_filtered_attr(rd, "sq-psn", sq_psn,
-				nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
-		path_mig_state = mnl_attr_get_u8(
-			nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]);
-	if (rd_is_string_filtered_attr(
-		    rd, "path-mig-state", path_mig_to_str(path_mig_state),
-		    nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]))
-		goto out;
-
-	type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
-	if (rd_is_string_filtered_attr(rd, "type", qp_types_to_str(type),
-				       nla_line[RDMA_NLDEV_ATTR_RES_TYPE]))
-		goto out;
-
-	state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
-	if (rd_is_string_filtered_attr(rd, "state", qp_states_to_str(state),
-				       nla_line[RDMA_NLDEV_ATTR_RES_STATE]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-		comm = get_task_name(pid);
-	}
-
-	if (rd_is_filtered_attr(rd, "pid", pid,
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]))
-		goto out;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-		/* discard const from mnl_attr_get_str */
-		comm = (char *)mnl_attr_get_str(
-			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-
-	print_link(rd, idx, name, port, nla_line);
-
-	res_print_uint(rd, "lqpn", lqpn, nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-	print_rqpn(rd, rqpn, nla_line);
-
-	print_type(rd, type);
-	print_state(rd, state);
-
-	print_rqpsn(rd, rq_psn, nla_line);
-	res_print_uint(rd, "sq-psn", sq_psn,
-		       nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]);
-
-	print_pathmig(rd, path_mig_state, nla_line);
-	res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-	res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-	print_comm(rd, comm, nla_line);
-
-	print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-	newline(rd);
-out:
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-		free(comm);
-	return MNL_CB_OK;
-}
-
-int res_qp_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-
-	return res_qp_line(rd, name, idx, tb);
-}
-
-int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	int ret = MNL_CB_OK;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_QP])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_QP];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-
-		ret = res_qp_line(rd, name, idx, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-	}
-	return ret;
-}
diff --git a/rdma/res.c b/rdma/res.c
deleted file mode 100644
index 6003006..0000000
--- a/rdma/res.c
+++ /dev/null
@@ -1,288 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * res.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "res.h"
-#include <inttypes.h>
-
-static int res_help(struct rd *rd)
-{
-	pr_out("Usage: %s resource\n", rd->filename);
-	pr_out("          resource show [DEV]\n");
-	pr_out("          resource show [qp|cm_id|pd|mr|cq]\n");
-	pr_out("          resource show qp link [DEV/PORT]\n");
-	pr_out("          resource show qp link [DEV/PORT] [FILTER-NAME FILTER-VALUE]\n");
-	pr_out("          resource show cm_id link [DEV/PORT]\n");
-	pr_out("          resource show cm_id link [DEV/PORT] [FILTER-NAME FILTER-VALUE]\n");
-	pr_out("          resource show cq link [DEV/PORT]\n");
-	pr_out("          resource show cq link [DEV/PORT] [FILTER-NAME FILTER-VALUE]\n");
-	pr_out("          resource show pd dev [DEV]\n");
-	pr_out("          resource show pd dev [DEV] [FILTER-NAME FILTER-VALUE]\n");
-	pr_out("          resource show mr dev [DEV]\n");
-	pr_out("          resource show mr dev [DEV] [FILTER-NAME FILTER-VALUE]\n");
-	return 0;
-}
-
-static int res_print_summary(struct rd *rd, struct nlattr **tb)
-{
-	struct nlattr *nla_table = tb[RDMA_NLDEV_ATTR_RES_SUMMARY];
-	struct nlattr *nla_entry;
-	const char *name;
-	uint64_t curr;
-	int err;
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return -EINVAL;
-
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME] ||
-		    !nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]) {
-			return -EINVAL;
-		}
-
-		name = mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME]);
-		curr = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]);
-		res_print_uint(
-			rd, name, curr,
-			nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]);
-	}
-	return 0;
-}
-
-static int res_no_args_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	return MNL_CB_OK;
-}
-
-static int res_no_args_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
-	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_SUMMARY])
-		return MNL_CB_ERROR;
-
-	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	if (rd->json_output) {
-		jsonw_uint_field(rd->jw, "ifindex", idx);
-		jsonw_string_field(rd->jw, "ifname", name);
-	} else {
-		pr_out("%u: %s: ", idx, name);
-	}
-
-	res_print_summary(rd, tb);
-
-	if (!rd->json_output)
-		pr_out("\n");
-	return MNL_CB_OK;
-}
-
-int _res_send_idx_msg(struct rd *rd, uint32_t command, mnl_cb_t callback,
-		      uint32_t idx, uint32_t id)
-{
-	uint32_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	uint32_t seq;
-	int ret;
-
-	rd_prepare_msg(rd, command, &seq, flags);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	if (rd->port_idx)
-		mnl_attr_put_u32(rd->nlh,
-				 RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-
-	mnl_attr_put_u32(rd->nlh, id, idx);
-
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	if (rd->json_output)
-		jsonw_start_object(rd->jw);
-	ret = rd_recv_msg(rd, callback, rd, seq);
-	if (rd->json_output)
-		jsonw_end_object(rd->jw);
-	return ret;
-}
-
-int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback)
-{
-	uint32_t flags = NLM_F_REQUEST | NLM_F_ACK;
-	uint32_t seq;
-	int ret;
-
-	if (command != RDMA_NLDEV_CMD_RES_GET)
-		flags |= NLM_F_DUMP;
-
-	rd_prepare_msg(rd, command, &seq, flags);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	if (rd->port_idx)
-		mnl_attr_put_u32(rd->nlh,
-				 RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	if (rd->json_output)
-		jsonw_start_object(rd->jw);
-	ret = rd_recv_msg(rd, callback, rd, seq);
-	if (rd->json_output)
-		jsonw_end_object(rd->jw);
-	return ret;
-}
-
-const char *qp_types_to_str(uint8_t idx)
-{
-	static const char * const qp_types_str[] = { "SMI", "GSI", "RC",
-						     "UC", "UD", "RAW_IPV6",
-						     "RAW_ETHERTYPE",
-						     "UNKNOWN", "RAW_PACKET",
-						     "XRC_INI", "XRC_TGT",
-						     [0xFF] = "DRIVER",
-	};
-
-	if (idx < ARRAY_SIZE(qp_types_str) && qp_types_str[idx])
-		return qp_types_str[idx];
-	return "UNKNOWN";
-}
-
-void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line)
-{
-	char tmp[18];
-
-	if (!str)
-		return;
-
-	if (rd->json_output) {
-		/* Don't beatify output in JSON format */
-		jsonw_string_field(rd->jw, "comm", str);
-		return;
-	}
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-		snprintf(tmp, sizeof(tmp), "%s", str);
-	else
-		snprintf(tmp, sizeof(tmp), "[%s]", str);
-
-	pr_out("comm %s ", tmp);
-}
-
-void print_dev(struct rd *rd, uint32_t idx, const char *name)
-{
-	if (rd->json_output) {
-		jsonw_uint_field(rd->jw, "ifindex", idx);
-		jsonw_string_field(rd->jw, "ifname", name);
-	} else {
-		pr_out("dev %s ", name);
-	}
-}
-
-void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
-		struct nlattr **nla_line)
-{
-	if (rd->json_output) {
-		jsonw_uint_field(rd->jw, "ifindex", idx);
-
-		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-			jsonw_uint_field(rd->jw, "port", port);
-
-		jsonw_string_field(rd->jw, "ifname", name);
-	} else {
-		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-			pr_out("link %s/%u ", name, port);
-		else
-			pr_out("link %s/- ", name);
-	}
-}
-
-char *get_task_name(uint32_t pid)
-{
-	char *comm;
-	FILE *f;
-
-	if (asprintf(&comm, "/proc/%d/comm", pid) < 0)
-		return NULL;
-
-	f = fopen(comm, "r");
-	free(comm);
-	if (!f)
-		return NULL;
-
-	if (fscanf(f, "%ms\n", &comm) != 1)
-		comm = NULL;
-
-	fclose(f);
-
-	return comm;
-}
-
-void print_key(struct rd *rd, const char *name, uint64_t val,
-	       struct nlattr *nlattr)
-{
-	if (!nlattr)
-		return;
-
-	if (rd->json_output)
-		jsonw_xint_field(rd->jw, name, val);
-	else
-		pr_out("%s 0x%" PRIx64 " ", name, val);
-}
-
-void res_print_uint(struct rd *rd, const char *name, uint64_t val,
-		    struct nlattr *nlattr)
-{
-	if (!nlattr)
-		return;
-
-	if (rd->json_output)
-		jsonw_u64_field(rd->jw, name, val);
-	else
-		pr_out("%s %" PRIu64 " ", name, val);
-}
-
-RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true, 0);
-
-static int res_show(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		res_no_args	},
-		{ "qp",		res_qp		},
-		{ "cm_id",	res_cm_id	},
-		{ "cq",		res_cq		},
-		{ "mr",		res_mr		},
-		{ "pd",		res_pd		},
-		{ 0 }
-	};
-
-	/*
-	 * Special case to support "rdma res show DEV_NAME"
-	 */
-	if (rd_argc(rd) == 1 && dev_map_lookup(rd, false))
-		return rd_exec_dev(rd, _res_no_args);
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-int cmd_res(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		res_show },
-		{ "show",	res_show },
-		{ "list",	res_show },
-		{ "help",	res_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "resource command");
-}
diff --git a/rdma/res.h b/rdma/res.h
deleted file mode 100644
index 525171f..0000000
--- a/rdma/res.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
-/*
- * res.h	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-#ifndef _RDMA_TOOL_RES_H_
-#define _RDMA_TOOL_RES_H_
-
-#include "rdma.h"
-
-int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
-int _res_send_idx_msg(struct rd *rd, uint32_t command, mnl_cb_t callback,
-		      uint32_t idx, uint32_t id);
-
-int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_cm_id_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data);
-int res_qp_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
-
-#define RES_FUNC(name, command, valid_filters, strict_port, id)                        \
-	static inline int _##name(struct rd *rd)                                       \
-	{                                                                              \
-		uint32_t idx;                                                          \
-		int ret;                                                               \
-		if (id) {                                                              \
-			ret = rd_doit_index(rd, &idx);                                 \
-			if (ret) {                                                     \
-				rd->suppress_errors = true;                            \
-				ret = _res_send_idx_msg(rd, command,                   \
-							name##_idx_parse_cb,           \
-							idx, id);                      \
-				if (!ret)                                              \
-					return ret;                                    \
-				/* Fallback for old systems without .doit callbacks */ \
-			}                                                              \
-		}                                                                      \
-		return _res_send_msg(rd, command, name##_parse_cb);                    \
-	}                                                                              \
-	static inline int name(struct rd *rd)                                          \
-	{                                                                              \
-		int ret = rd_build_filter(rd, valid_filters);                          \
-		if (ret)                                                               \
-			return ret;                                                    \
-		if ((uintptr_t)valid_filters != (uintptr_t)NULL) {                     \
-			ret = rd_set_arg_to_devname(rd);                               \
-			if (ret)                                                       \
-				return ret;                                            \
-		}                                                                      \
-		if (strict_port)                                                       \
-			return rd_exec_dev(rd, _##name);                               \
-		else                                                                   \
-			return rd_exec_link(rd, _##name, strict_port);                 \
-	}
-
-static const
-struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "dev", .is_number = false },
-	{ .name = "users", .is_number = true },
-	{ .name = "pid", .is_number = true },
-	{ .name = "ctxn", .is_number = true },
-	{ .name = "pdn", .is_number = true, .is_doit = true },
-	{ .name = "ctxn", .is_number = true }
-};
-
-RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true,
-	 RDMA_NLDEV_ATTR_RES_PDN);
-
-static const
-struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "dev", .is_number = false },
-	{ .name = "rkey", .is_number = true },
-	{ .name = "lkey", .is_number = true },
-	{ .name = "mrlen", .is_number = true },
-	{ .name = "pid", .is_number = true },
-	{ .name = "mrn", .is_number = true, .is_doit = true },
-	{ .name = "pdn", .is_number = true }
-};
-
-RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true,
-	 RDMA_NLDEV_ATTR_RES_MRN);
-
-static const
-struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "dev", .is_number = false },
-	{ .name = "users", .is_number = true },
-	{ .name = "poll-ctx", .is_number = false },
-	{ .name = "pid", .is_number = true },
-	{ .name = "cqn", .is_number = true, .is_doit = true },
-	{ .name = "ctxn", .is_number = true }
-};
-
-RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true,
-	 RDMA_NLDEV_ATTR_RES_CQN);
-
-static const
-struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "link", .is_number = false },
-	{ .name = "lqpn", .is_number = true },
-	{ .name = "qp-type", .is_number = false },
-	{ .name = "state", .is_number = false },
-	{ .name = "ps", .is_number = false },
-	{ .name = "dev-type", .is_number = false },
-	{ .name = "transport-type", .is_number = false },
-	{ .name = "pid", .is_number = true },
-	{ .name = "src-addr", .is_number = false },
-	{ .name = "src-port", .is_number = true },
-	{ .name = "dst-addr", .is_number = false },
-	{ .name = "dst-port", .is_number = true },
-	{ .name = "cm-idn", .is_number = true, .is_doit = true }
-};
-
-RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false,
-	 RDMA_NLDEV_ATTR_RES_CM_IDN);
-
-static const struct
-filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "link", .is_number = false },
-	{ .name = "lqpn", .is_number = true, .is_doit = true },
-	{ .name = "rqpn", .is_number = true },
-	{ .name = "pid",  .is_number = true },
-	{ .name = "sq-psn", .is_number = true },
-	{ .name = "rq-psn", .is_number = true },
-	{ .name = "type", .is_number = false },
-	{ .name = "path-mig-state", .is_number = false },
-	{ .name = "state", .is_number = false },
-	{ .name = "pdn", .is_number = true },
-};
-
-RES_FUNC(res_qp, RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false,
-	 RDMA_NLDEV_ATTR_RES_LQPN);
-
-char *get_task_name(uint32_t pid);
-void print_dev(struct rd *rd, uint32_t idx, const char *name);
-void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
-		struct nlattr **nla_line);
-void print_key(struct rd *rd, const char *name, uint64_t val,
-	       struct nlattr *nlattr);
-void res_print_uint(struct rd *rd, const char *name, uint64_t val,
-		    struct nlattr *nlattr);
-void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line);
-const char *qp_types_to_str(uint8_t idx);
-
-#endif /* _RDMA_TOOL_RES_H_ */
diff --git a/rdma/stat.c b/rdma/stat.c
deleted file mode 100644
index ef0bbcf..0000000
--- a/rdma/stat.c
+++ /dev/null
@@ -1,759 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * rdma.c	RDMA tool
- * Authors:     Mark Zhang <markz@mellanox.com>
- */
-
-#include "rdma.h"
-#include "res.h"
-#include <inttypes.h>
-
-static int stat_help(struct rd *rd)
-{
-	pr_out("Usage: %s [ OPTIONS ] statistic { COMMAND | help }\n", rd->filename);
-	pr_out("       %s statistic OBJECT show\n", rd->filename);
-	pr_out("       %s statistic OBJECT show link [ DEV/PORT_INDEX ] [ FILTER-NAME FILTER-VALUE ]\n", rd->filename);
-	pr_out("       %s statistic OBJECT mode\n", rd->filename);
-	pr_out("       %s statistic OBJECT set COUNTER_SCOPE [DEV/PORT_INDEX] auto {CRITERIA | off}\n", rd->filename);
-	pr_out("       %s statistic OBJECT bind COUNTER_SCOPE [DEV/PORT_INDEX] [OBJECT-ID] [COUNTER-ID]\n", rd->filename);
-	pr_out("       %s statistic OBJECT unbind COUNTER_SCOPE [DEV/PORT_INDEX] [COUNTER-ID]\n", rd->filename);
-	pr_out("       %s statistic show\n", rd->filename);
-	pr_out("       %s statistic show link [ DEV/PORT_INDEX ]\n", rd->filename);
-	pr_out("where  OBJECT: = { qp }\n");
-	pr_out("       CRITERIA : = { type }\n");
-	pr_out("       COUNTER_SCOPE: = { link | dev }\n");
-	pr_out("Examples:\n");
-	pr_out("       %s statistic qp show\n", rd->filename);
-	pr_out("       %s statistic qp show link mlx5_2/1\n", rd->filename);
-	pr_out("       %s statistic qp mode\n", rd->filename);
-	pr_out("       %s statistic qp mode link mlx5_0\n", rd->filename);
-	pr_out("       %s statistic qp set link mlx5_2/1 auto type on\n", rd->filename);
-	pr_out("       %s statistic qp set link mlx5_2/1 auto off\n", rd->filename);
-	pr_out("       %s statistic qp bind link mlx5_2/1 lqpn 178\n", rd->filename);
-	pr_out("       %s statistic qp bind link mlx5_2/1 lqpn 178 cntn 4\n", rd->filename);
-	pr_out("       %s statistic qp unbind link mlx5_2/1 cntn 4\n", rd->filename);
-	pr_out("       %s statistic qp unbind link mlx5_2/1 cntn 4 lqpn 178\n", rd->filename);
-	pr_out("       %s statistic show\n", rd->filename);
-	pr_out("       %s statistic show link mlx5_2/1\n", rd->filename);
-
-	return 0;
-}
-
-struct counter_param {
-	char *name;
-	uint32_t attr;
-};
-
-static struct counter_param auto_params[] = {
-	{ "type", RDMA_COUNTER_MASK_QP_TYPE, },
-	{ NULL },
-};
-
-static int prepare_auto_mode_str(struct nlattr **tb, uint32_t mask,
-				 char *output, int len)
-{
-	char s[] = "qp auto";
-	int i, outlen = strlen(s);
-
-	memset(output, 0, len);
-	snprintf(output, len, "%s", s);
-
-	if (mask) {
-		for (i = 0; auto_params[i].name != NULL; i++) {
-			if (mask & auto_params[i].attr) {
-				outlen += strlen(auto_params[i].name) + 1;
-				if (outlen >= len)
-					return -EINVAL;
-				strcat(output, " ");
-				strcat(output, auto_params[i].name);
-			}
-		}
-
-		if (outlen + strlen(" on") >= len)
-			return -EINVAL;
-		strcat(output, " on");
-	} else {
-		if (outlen + strlen(" off") >= len)
-			return -EINVAL;
-		strcat(output, " off");
-	}
-
-	return 0;
-}
-
-static int qp_link_get_mode_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	uint32_t mode = 0, mask = 0;
-	char output[128] = {};
-	struct rd *rd = data;
-	uint32_t idx, port;
-	const char *name;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
-		return MNL_CB_ERROR;
-
-	if (!tb[RDMA_NLDEV_ATTR_PORT_INDEX]) {
-		pr_err("This tool doesn't support switches yet\n");
-		return MNL_CB_ERROR;
-	}
-
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	port = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	if (tb[RDMA_NLDEV_ATTR_STAT_MODE])
-		mode = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_STAT_MODE]);
-
-	if (mode == RDMA_COUNTER_MODE_AUTO) {
-		if (!tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK])
-			return MNL_CB_ERROR;
-		mask = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK]);
-		prepare_auto_mode_str(tb, mask, output, sizeof(output));
-	} else {
-		snprintf(output, sizeof(output), "qp auto off");
-	}
-
-	if (rd->json_output) {
-		jsonw_uint_field(rd->jw, "ifindex", idx);
-		jsonw_uint_field(rd->jw, "port", port);
-		jsonw_string_field(rd->jw, "mode", output);
-	} else {
-		pr_out("%u/%u: %s/%u: %s\n", idx, port, name, port, output);
-	}
-
-	return MNL_CB_OK;
-}
-
-static int stat_one_qp_link_get_mode(struct rd *rd)
-{
-	uint32_t seq;
-	int ret;
-
-	if (!rd->port_idx)
-		return 0;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_GET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	/* Make RDMA_NLDEV_ATTR_STAT_MODE valid so that kernel knows
-	 * return only mode instead of all counters
-	 */
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_MODE,
-			 RDMA_COUNTER_MODE_MANUAL);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES, RDMA_NLDEV_ATTR_RES_QP);
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	if (rd->json_output)
-		jsonw_start_object(rd->jw);
-	ret = rd_recv_msg(rd, qp_link_get_mode_parse_cb, rd, seq);
-	if (rd->json_output)
-		jsonw_end_object(rd->jw);
-
-	return ret;
-}
-
-static int stat_qp_link_get_mode(struct rd *rd)
-{
-	return rd_exec_link(rd, stat_one_qp_link_get_mode, false);
-}
-
-static int stat_qp_get_mode(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_qp_link_get_mode },
-		{ "link",	stat_qp_link_get_mode },
-		{ "help",	stat_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int res_get_hwcounters(struct rd *rd, struct nlattr *hwc_table, bool print)
-{
-	struct nlattr *nla_entry;
-	const char *nm;
-	uint64_t v;
-	int err;
-
-	mnl_attr_for_each_nested(nla_entry, hwc_table) {
-		struct nlattr *hw_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, hw_line);
-		if (err != MNL_CB_OK)
-			return -EINVAL;
-
-		if (!hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME] ||
-		    !hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_VALUE]) {
-			return -EINVAL;
-		}
-
-		if (!print)
-			continue;
-
-		nm = mnl_attr_get_str(hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME]);
-		v = mnl_attr_get_u64(hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_VALUE]);
-		if (rd->pretty_output && !rd->json_output)
-			newline_indent(rd);
-		res_print_uint(rd, nm, v, hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME]);
-	}
-
-	return MNL_CB_OK;
-}
-
-static int res_counter_line(struct rd *rd, const char *name, int index,
-		       struct nlattr **nla_line)
-{
-	uint32_t cntn, port = 0, pid = 0, qpn;
-	struct nlattr *hwc_table, *qp_table;
-	struct nlattr *nla_entry;
-	const char *comm = NULL;
-	bool isfirst;
-	int err;
-
-	if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-		port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
-
-	hwc_table = nla_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS];
-	qp_table = nla_line[RDMA_NLDEV_ATTR_RES_QP];
-	if (!hwc_table || !qp_table ||
-	    !nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID])
-		return MNL_CB_ERROR;
-
-	cntn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]);
-	if (rd_is_filtered_attr(rd, "cntn", cntn,
-				nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]))
-		return MNL_CB_OK;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-		comm = get_task_name(pid);
-	}
-	if (rd_is_filtered_attr(rd, "pid", pid,
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]))
-		return MNL_CB_OK;
-
-	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-		comm = (char *)mnl_attr_get_str(
-			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-	mnl_attr_for_each_nested(nla_entry, qp_table) {
-		struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, qp_line);
-		if (err != MNL_CB_OK)
-			return -EINVAL;
-
-		if (!qp_line[RDMA_NLDEV_ATTR_RES_LQPN])
-			return -EINVAL;
-
-		qpn = mnl_attr_get_u32(qp_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-		if (rd_is_filtered_attr(rd, "lqpn", qpn,
-					qp_line[RDMA_NLDEV_ATTR_RES_LQPN]))
-			return MNL_CB_OK;
-	}
-
-	err = res_get_hwcounters(rd, hwc_table, false);
-	if (err != MNL_CB_OK)
-		return err;
-
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "ifname", name);
-		if (port)
-			jsonw_uint_field(rd->jw, "port", port);
-		jsonw_uint_field(rd->jw, "cntn", cntn);
-	} else {
-		if (port)
-			pr_out("link %s/%u cntn %u ", name, port, cntn);
-		else
-			pr_out("dev %s cntn %u ", name, cntn);
-	}
-
-	res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-	print_comm(rd, comm, nla_line);
-
-	res_get_hwcounters(rd, hwc_table, true);
-
-	isfirst = true;
-	mnl_attr_for_each_nested(nla_entry, qp_table) {
-		struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		if (isfirst && !rd->json_output)
-			pr_out("\n    LQPN: <");
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, qp_line);
-		if (err != MNL_CB_OK)
-			return -EINVAL;
-
-		if (!qp_line[RDMA_NLDEV_ATTR_RES_LQPN])
-			return -EINVAL;
-
-		qpn = mnl_attr_get_u32(qp_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-		if (rd->json_output) {
-			jsonw_uint_field(rd->jw, "lqpn", qpn);
-		} else {
-			if (isfirst)
-				pr_out("%d", qpn);
-			else
-				pr_out(", %d", qpn);
-		}
-		isfirst = false;
-	}
-
-	if (!rd->json_output)
-		pr_out(">\n");
-	return MNL_CB_OK;
-}
-
-static int stat_qp_show_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-	int ret;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_STAT_COUNTER])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_STAT_COUNTER];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-
-		ret = res_counter_line(rd, name, idx, nla_line);
-		if (ret != MNL_CB_OK)
-			break;
-	}
-
-	return ret;
-}
-
-static const struct filters stat_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "cntn", .is_number = true },
-	{ .name = "lqpn", .is_number = true },
-	{ .name = "pid", .is_number = true },
-};
-
-static int stat_qp_show_one_link(struct rd *rd)
-{
-	int flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP;
-	uint32_t seq;
-	int ret;
-
-	if (!rd->port_idx)
-		return 0;
-
-	ret = rd_build_filter(rd, stat_valid_filters);
-	if (ret)
-		return ret;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_GET, &seq, flags);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES, RDMA_NLDEV_ATTR_RES_QP);
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	if (rd->json_output)
-		jsonw_start_object(rd->jw);
-	ret = rd_recv_msg(rd, stat_qp_show_parse_cb, rd, seq);
-	if (rd->json_output)
-		jsonw_end_object(rd->jw);
-
-	return ret;
-}
-
-static int stat_qp_show_link(struct rd *rd)
-{
-	return rd_exec_link(rd, stat_qp_show_one_link, false);
-}
-
-static int stat_qp_show(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_qp_show_link },
-		{ "link",	stat_qp_show_link },
-		{ "help",	stat_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_qp_set_link_auto_sendmsg(struct rd *rd, uint32_t mask)
-{
-	uint32_t seq;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_SET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES, RDMA_NLDEV_ATTR_RES_QP);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_MODE,
-			 RDMA_COUNTER_MODE_AUTO);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK, mask);
-
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int stat_one_qp_set_link_auto_off(struct rd *rd)
-{
-	return stat_qp_set_link_auto_sendmsg(rd, 0);
-}
-
-static int stat_one_qp_set_auto_type_on(struct rd *rd)
-{
-	return stat_qp_set_link_auto_sendmsg(rd, RDMA_COUNTER_MASK_QP_TYPE);
-}
-
-static int stat_one_qp_set_link_auto_type(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_help },
-		{ "on",		stat_one_qp_set_auto_type_on },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_one_qp_set_link_auto(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_one_qp_link_get_mode },
-		{ "off",	stat_one_qp_set_link_auto_off },
-		{ "type",	stat_one_qp_set_link_auto_type },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_one_qp_set_link(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_one_qp_link_get_mode },
-		{ "auto",	stat_one_qp_set_link_auto },
-		{ 0 }
-	};
-
-	if (!rd->port_idx)
-		return 0;
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_qp_set_link(struct rd *rd)
-{
-	return rd_exec_link(rd, stat_one_qp_set_link, false);
-}
-
-static int stat_qp_set(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_help },
-		{ "link",	stat_qp_set_link },
-		{ "help",	stat_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_get_arg(struct rd *rd, const char *arg)
-{
-	int value = 0;
-	char *endp;
-
-	if (strcmpx(rd_argv(rd), arg) != 0)
-		return -EINVAL;
-
-	rd_arg_inc(rd);
-	value = strtol(rd_argv(rd), &endp, 10);
-	rd_arg_inc(rd);
-
-	return value;
-}
-
-static int stat_one_qp_bind(struct rd *rd)
-{
-	int lqpn = 0, cntn = 0, ret;
-	uint32_t seq;
-
-	if (rd_no_arg(rd)) {
-		stat_help(rd);
-		return -EINVAL;
-	}
-
-	ret = rd_build_filter(rd, stat_valid_filters);
-	if (ret)
-		return ret;
-
-	lqpn = stat_get_arg(rd, "lqpn");
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_SET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_MODE,
-			 RDMA_COUNTER_MODE_MANUAL);
-
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES, RDMA_NLDEV_ATTR_RES_QP);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_RES_LQPN, lqpn);
-
-	if (rd_argc(rd)) {
-		cntn = stat_get_arg(rd, "cntn");
-		mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_COUNTER_ID,
-				 cntn);
-	}
-
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int do_stat_qp_unbind_lqpn(struct rd *rd, uint32_t cntn, uint32_t lqpn)
-{
-	uint32_t seq;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_DEL,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_MODE,
-			 RDMA_COUNTER_MODE_MANUAL);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES, RDMA_NLDEV_ATTR_RES_QP);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_COUNTER_ID, cntn);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_RES_LQPN, lqpn);
-
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static int stat_get_counter_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	uint32_t lqpn, cntn;
-	int err;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-
-	if (!tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID])
-		return MNL_CB_ERROR;
-	cntn = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]);
-
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_QP];
-	if (!nla_table)
-		return MNL_CB_ERROR;
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return -EINVAL;
-
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_LQPN])
-			return -EINVAL;
-
-		lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-		err = do_stat_qp_unbind_lqpn(rd, cntn, lqpn);
-		if (err)
-			return MNL_CB_ERROR;
-	}
-
-	return MNL_CB_OK;
-}
-
-static int stat_one_qp_unbind(struct rd *rd)
-{
-	int flags = NLM_F_REQUEST | NLM_F_ACK, ret;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	int lqpn = 0, cntn = 0;
-	unsigned int portid;
-	uint32_t seq;
-
-	ret = rd_build_filter(rd, stat_valid_filters);
-	if (ret)
-		return ret;
-
-	cntn = stat_get_arg(rd, "cntn");
-	if (rd_argc(rd)) {
-		lqpn = stat_get_arg(rd, "lqpn");
-		return do_stat_qp_unbind_lqpn(rd, cntn, lqpn);
-	}
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_GET, &seq, flags);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES, RDMA_NLDEV_ATTR_RES_QP);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_COUNTER_ID, cntn);
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-
-	/* Can't use rd_recv_msg() since the callback also calls it (recursively),
-	 * then rd_recv_msg() always return -1 here
-	 */
-	portid = mnl_socket_get_portid(rd->nl);
-	ret = mnl_socket_recvfrom(rd->nl, buf, sizeof(buf));
-	if (ret <= 0)
-		return ret;
-
-	ret = mnl_cb_run(buf, ret, seq, portid, stat_get_counter_parse_cb, rd);
-	mnl_socket_close(rd->nl);
-	if (ret != MNL_CB_OK)
-		return ret;
-
-	return 0;
-}
-
-static int stat_qp_bind_link(struct rd *rd)
-{
-	return rd_exec_link(rd, stat_one_qp_bind, true);
-}
-
-static int stat_qp_bind(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_help },
-		{ "link",	stat_qp_bind_link },
-		{ "help",	stat_help },
-		{ 0 },
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_qp_unbind_link(struct rd *rd)
-{
-	return rd_exec_link(rd, stat_one_qp_unbind, true);
-}
-
-static int stat_qp_unbind(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_help },
-		{ "link",	stat_qp_unbind_link },
-		{ "help",	stat_help },
-		{ 0 },
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_qp(struct rd *rd)
-{
-	const struct rd_cmd cmds[] =  {
-		{ NULL,		stat_qp_show },
-		{ "show",	stat_qp_show },
-		{ "list",	stat_qp_show },
-		{ "mode",	stat_qp_get_mode },
-		{ "set",	stat_qp_set },
-		{ "bind",	stat_qp_bind },
-		{ "unbind",	stat_qp_unbind },
-		{ "help",	stat_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int stat_show_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-	const char *name;
-	uint32_t port;
-	int ret;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_PORT_INDEX] ||
-	    !tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	port = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "ifname", name);
-		jsonw_uint_field(rd->jw, "port", port);
-	} else {
-		pr_out("link %s/%u ", name, port);
-	}
-
-	ret = res_get_hwcounters(rd, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS], true);
-
-	if (!rd->json_output)
-		pr_out("\n");
-	return ret;
-}
-
-static int stat_show_one_link(struct rd *rd)
-{
-	int flags = NLM_F_REQUEST | NLM_F_ACK;
-	uint32_t seq;
-	int ret;
-
-	if (!rd->port_idx)
-		return 0;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_GET, &seq,  flags);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
-	mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	return rd_recv_msg(rd, stat_show_parse_cb, rd, seq);
-}
-
-static int stat_show_link(struct rd *rd)
-{
-	return rd_exec_link(rd, stat_show_one_link, false);
-}
-
-static int stat_show(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		stat_show_link },
-		{ "link",	stat_show_link },
-		{ "help",	stat_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-int cmd_stat(struct rd *rd)
-{
-	const struct rd_cmd cmds[] =  {
-		{ NULL,		stat_show },
-		{ "show",	stat_show },
-		{ "list",	stat_show },
-		{ "help",	stat_help },
-		{ "qp",		stat_qp },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "statistic command");
-}
diff --git a/rdma/sys.c b/rdma/sys.c
deleted file mode 100644
index 1a434a2..0000000
--- a/rdma/sys.c
+++ /dev/null
@@ -1,138 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * sys.c	RDMA tool
- */
-
-#include "rdma.h"
-
-static int sys_help(struct rd *rd)
-{
-	pr_out("Usage: %s system show [ netns ]\n", rd->filename);
-	pr_out("       %s system set netns { shared | exclusive }\n", rd->filename);
-	return 0;
-}
-
-static const char *netns_modes_str[] = {
-	"exclusive",
-	"shared",
-};
-
-static int sys_show_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct rd *rd = data;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-
-	if (tb[RDMA_NLDEV_SYS_ATTR_NETNS_MODE]) {
-		const char *mode_str;
-		uint8_t netns_mode;
-
-		netns_mode =
-			mnl_attr_get_u8(tb[RDMA_NLDEV_SYS_ATTR_NETNS_MODE]);
-
-		if (netns_mode < ARRAY_SIZE(netns_modes_str))
-			mode_str = netns_modes_str[netns_mode];
-		else
-			mode_str = "unknown";
-
-		if (rd->json_output)
-			jsonw_string_field(rd->jw, "netns", mode_str);
-		else
-			pr_out("netns %s\n", mode_str);
-	}
-	return MNL_CB_OK;
-}
-
-static int sys_show_no_args(struct rd *rd)
-{
-	uint32_t seq;
-	int ret;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_SYS_GET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-	ret = rd_send_msg(rd);
-	if (ret)
-		return ret;
-
-	return rd_recv_msg(rd, sys_show_parse_cb, rd, seq);
-}
-
-static int sys_show(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		sys_show_no_args},
-		{ "netns",	sys_show_no_args},
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-static int sys_set_netns_cmd(struct rd *rd, bool enable)
-{
-	uint32_t seq;
-
-	rd_prepare_msg(rd, RDMA_NLDEV_CMD_SYS_SET,
-		       &seq, (NLM_F_REQUEST | NLM_F_ACK));
-	mnl_attr_put_u8(rd->nlh, RDMA_NLDEV_SYS_ATTR_NETNS_MODE, enable);
-
-	return rd_sendrecv_msg(rd, seq);
-}
-
-static bool sys_valid_netns_cmd(const char *cmd)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(netns_modes_str); i++) {
-		if (!strcmp(cmd, netns_modes_str[i]))
-			return true;
-	}
-	return false;
-}
-
-static int sys_set_netns_args(struct rd *rd)
-{
-	bool cmd;
-
-	if (rd_no_arg(rd) || !sys_valid_netns_cmd(rd_argv(rd))) {
-		pr_err("valid options are: { shared | exclusive }\n");
-		return -EINVAL;
-	}
-
-	cmd = (strcmp(rd_argv(rd), "shared") == 0) ? true : false;
-
-	return sys_set_netns_cmd(rd, cmd);
-}
-
-static int sys_set_help(struct rd *rd)
-{
-	pr_out("Usage: %s system set [PARAM] value\n", rd->filename);
-	pr_out("            system set netns { shared | exclusive }\n");
-	return 0;
-}
-
-static int sys_set(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,			sys_set_help },
-		{ "help",		sys_set_help },
-		{ "netns",		sys_set_netns_args},
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "parameter");
-}
-
-int cmd_sys(struct rd *rd)
-{
-	const struct rd_cmd cmds[] = {
-		{ NULL,		sys_show },
-		{ "show",	sys_show },
-		{ "set",	sys_set },
-		{ "help",	sys_help },
-		{ 0 }
-	};
-
-	return rd_exec_cmd(rd, cmds, "system command");
-}
diff --git a/rdma/utils.c b/rdma/utils.c
deleted file mode 100644
index 3765901..0000000
--- a/rdma/utils.c
+++ /dev/null
@@ -1,949 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/*
- * utils.c	RDMA tool
- * Authors:     Leon Romanovsky <leonro@mellanox.com>
- */
-
-#include "rdma.h"
-#include <ctype.h>
-#include <inttypes.h>
-
-int rd_argc(struct rd *rd)
-{
-	return rd->argc;
-}
-
-char *rd_argv(struct rd *rd)
-{
-	if (!rd_argc(rd))
-		return NULL;
-	return *rd->argv;
-}
-
-int strcmpx(const char *str1, const char *str2)
-{
-	if (strlen(str1) > strlen(str2))
-		return -1;
-	return strncmp(str1, str2, strlen(str1));
-}
-
-static bool rd_argv_match(struct rd *rd, const char *pattern)
-{
-	if (!rd_argc(rd))
-		return false;
-	return strcmpx(rd_argv(rd), pattern) == 0;
-}
-
-void rd_arg_inc(struct rd *rd)
-{
-	if (!rd_argc(rd))
-		return;
-	rd->argc--;
-	rd->argv++;
-}
-
-bool rd_no_arg(struct rd *rd)
-{
-	return rd_argc(rd) == 0;
-}
-
-/*
- * Possible input:output
- * dev/port    | first port | is_dump_all
- * mlx5_1      | 0          | true
- * mlx5_1/     | 0          | true
- * mlx5_1/0    | 0          | false
- * mlx5_1/1    | 1          | false
- * mlx5_1/-    | 0          | false
- *
- * In strict port mode, a non-0 port must be provided
- */
-static int get_port_from_argv(struct rd *rd, uint32_t *port,
-			      bool *is_dump_all, bool strict_port)
-{
-	char *slash;
-
-	*port = 0;
-	*is_dump_all = strict_port ? false : true;
-
-	slash = strchr(rd_argv(rd), '/');
-	/* if no port found, return 0 */
-	if (slash++) {
-		if (*slash == '-') {
-			if (strict_port)
-				return -EINVAL;
-			*is_dump_all = false;
-			return 0;
-		}
-
-		if (isdigit(*slash)) {
-			*is_dump_all = false;
-			*port = atoi(slash);
-		}
-		if (!*port && strlen(slash))
-			return -EINVAL;
-	}
-	if (strict_port && (*port == 0))
-		return -EINVAL;
-
-	return 0;
-}
-
-static struct dev_map *dev_map_alloc(const char *dev_name)
-{
-	struct dev_map *dev_map;
-
-	dev_map = calloc(1, sizeof(*dev_map));
-	if (!dev_map)
-		return NULL;
-	dev_map->dev_name = strdup(dev_name);
-	if (!dev_map->dev_name) {
-		free(dev_map);
-		return NULL;
-	}
-
-	return dev_map;
-}
-
-static void dev_map_cleanup(struct rd *rd)
-{
-	struct dev_map *dev_map, *tmp;
-
-	list_for_each_entry_safe(dev_map, tmp,
-				 &rd->dev_map_list, list) {
-		list_del(&dev_map->list);
-		free(dev_map->dev_name);
-		free(dev_map);
-	}
-}
-
-static int add_filter(struct rd *rd, char *key, char *value,
-		      const struct filters valid_filters[])
-{
-	char cset[] = "1234567890,-";
-	struct filter_entry *fe;
-	bool key_found = false;
-	int idx = 0;
-	char *endp;
-	int ret;
-
-	fe = calloc(1, sizeof(*fe));
-	if (!fe)
-		return -ENOMEM;
-
-	while (idx < MAX_NUMBER_OF_FILTERS && valid_filters[idx].name) {
-		if (!strcmpx(key, valid_filters[idx].name)) {
-			key_found = true;
-			break;
-		}
-		idx++;
-	}
-	if (!key_found) {
-		pr_err("Unsupported filter option: %s\n", key);
-		ret = -EINVAL;
-		goto err;
-	}
-
-	/*
-	 * Check the filter validity, not optimal, but works
-	 *
-	 * Actually, there are three types of filters
-	 *  numeric - for example PID or QPN
-	 *  string  - for example states
-	 *  link    - user requested to filter on specific link
-	 *            e.g. mlx5_1/1, mlx5_1/-, mlx5_1 ...
-	 */
-	if (valid_filters[idx].is_number &&
-	    strspn(value, cset) != strlen(value)) {
-		pr_err("%s filter accepts \"%s\" characters only\n", key, cset);
-		ret = -EINVAL;
-		goto err;
-	}
-
-	fe->key = strdup(key);
-	fe->value = strdup(value);
-	if (!fe->key || !fe->value) {
-		ret = -ENOMEM;
-		goto err_alloc;
-	}
-
-	errno = 0;
-	strtol(fe->value, &endp, 10);
-	if (valid_filters[idx].is_doit && !errno && *endp == '\0')
-		fe->is_doit = true;
-
-	for (idx = 0; idx < strlen(fe->value); idx++)
-		fe->value[idx] = tolower(fe->value[idx]);
-
-	list_add_tail(&fe->list, &rd->filter_list);
-	return 0;
-
-err_alloc:
-	free(fe->value);
-	free(fe->key);
-err:
-	free(fe);
-	return ret;
-}
-
-bool rd_doit_index(struct rd *rd, uint32_t *idx)
-{
-	struct filter_entry *fe;
-
-	list_for_each_entry(fe, &rd->filter_list, list) {
-		if (fe->is_doit) {
-			*idx = atoi(fe->value);
-			return true;
-		}
-	}
-
-	return false;
-}
-
-int rd_build_filter(struct rd *rd, const struct filters valid_filters[])
-{
-	int ret = 0;
-	int idx = 0;
-
-	if (!valid_filters || !rd_argc(rd))
-		goto out;
-
-	if (rd_argc(rd) == 1) {
-		pr_err("No filter data was supplied to filter option %s\n", rd_argv(rd));
-		ret = -EINVAL;
-		goto out;
-	}
-
-	if (rd_argc(rd) % 2) {
-		pr_err("There is filter option without data\n");
-		ret = -EINVAL;
-		goto out;
-	}
-
-	while (idx != rd_argc(rd)) {
-		/*
-		 * We can do micro-optimization and skip "dev"
-		 * and "link" filters, but it is not worth of it.
-		 */
-		ret = add_filter(rd, *(rd->argv + idx),
-				 *(rd->argv + idx + 1), valid_filters);
-		if (ret)
-			goto out;
-		idx += 2;
-	}
-
-out:
-	return ret;
-}
-
-static bool rd_check_is_key_exist(struct rd *rd, const char *key)
-{
-	struct filter_entry *fe;
-
-	list_for_each_entry(fe, &rd->filter_list, list) {
-		if (!strcmpx(fe->key, key))
-			return true;
-	}
-
-	return false;
-}
-
-/*
- * Check if string entry is filtered:
- *  * key doesn't exist -> user didn't request -> not filtered
- */
-static bool rd_check_is_string_filtered(struct rd *rd, const char *key,
-					const char *val)
-{
-	bool key_is_filtered = false;
-	struct filter_entry *fe;
-	char *p = NULL;
-	char *str;
-
-	list_for_each_entry(fe, &rd->filter_list, list) {
-		if (!strcmpx(fe->key, key)) {
-			/* We found the key */
-			p = strdup(fe->value);
-			key_is_filtered = true;
-			if (!p) {
-				/*
-				 * Something extremely wrong if we fail
-				 * to allocate small amount of bytes.
-				 */
-				pr_err("Found key, but failed to allocate memory to store value\n");
-				return key_is_filtered;
-			}
-
-			/*
-			 * Need to check if value in range
-			 * It can come in the following formats
-			 * and their permutations:
-			 * str
-			 * str1,str2
-			 */
-			str = strtok(p, ",");
-			while (str) {
-				if (strlen(str) == strlen(val) &&
-				    !strcasecmp(str, val)) {
-					key_is_filtered = false;
-					goto out;
-				}
-				str = strtok(NULL, ",");
-			}
-			goto out;
-		}
-	}
-
-out:
-	free(p);
-	return key_is_filtered;
-}
-
-/*
- * Check if key is filtered:
- * key doesn't exist -> user didn't request -> not filtered
- */
-static bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val)
-{
-	bool key_is_filtered = false;
-	struct filter_entry *fe;
-
-	list_for_each_entry(fe, &rd->filter_list, list) {
-		uint32_t left_val = 0, fe_value = 0;
-		bool range_check = false;
-		char *p = fe->value;
-
-		if (!strcmpx(fe->key, key)) {
-			/* We found the key */
-			key_is_filtered = true;
-			/*
-			 * Need to check if value in range
-			 * It can come in the following formats
-			 * (and their permutations):
-			 * numb
-			 * numb1,numb2
-			 * ,numb1,numb2
-			 * numb1-numb2
-			 * numb1,numb2-numb3,numb4-numb5
-			 */
-			while (*p) {
-				if (isdigit(*p)) {
-					fe_value = strtol(p, &p, 10);
-					if (fe_value == val ||
-					    (range_check && left_val < val &&
-					     val < fe_value)) {
-						key_is_filtered = false;
-						goto out;
-					}
-					range_check = false;
-				} else {
-					if (*p == '-') {
-						left_val = fe_value;
-						range_check = true;
-					}
-					p++;
-				}
-			}
-			goto out;
-		}
-	}
-
-out:
-	return key_is_filtered;
-}
-
-bool rd_is_filtered_attr(struct rd *rd, const char *key, uint32_t val,
-			 struct nlattr *attr)
-{
-	if (!attr)
-		return rd_check_is_key_exist(rd, key);
-
-	return rd_check_is_filtered(rd, key, val);
-}
-
-bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val,
-				struct nlattr *attr)
-{
-	if (!attr)
-		rd_check_is_key_exist(rd, key);
-
-	return rd_check_is_string_filtered(rd, key, val);
-}
-
-static void filters_cleanup(struct rd *rd)
-{
-	struct filter_entry *fe, *tmp;
-
-	list_for_each_entry_safe(fe, tmp,
-				 &rd->filter_list, list) {
-		list_del(&fe->list);
-		free(fe->key);
-		free(fe->value);
-		free(fe);
-	}
-}
-
-static const enum mnl_attr_data_type nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
-	[RDMA_NLDEV_ATTR_DEV_INDEX] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_PORT_INDEX] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_CAP_FLAGS] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_FW_VERSION] = MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_NODE_GUID] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_SYS_IMAGE_GUID] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_LID] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_SM_LID] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_LMC] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_PORT_STATE] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_PORT_PHYS_STATE] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_DEV_NODE_TYPE] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_RES_SUMMARY]	= MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY]	= MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME] = MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_RES_QP]		= MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_QP_ENTRY]		= MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_LQPN]	= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_RQPN]	= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_RQ_PSN]		= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_SQ_PSN]		= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]	= MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_RES_TYPE]		= MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_RES_STATE]		= MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_RES_PID]		= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_KERN_NAME]	= MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_RES_CM_ID]		= MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_CM_ID_ENTRY]	= MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_PS]		= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_SRC_ADDR]		= MNL_TYPE_UNSPEC,
-	[RDMA_NLDEV_ATTR_RES_DST_ADDR]		= MNL_TYPE_UNSPEC,
-	[RDMA_NLDEV_ATTR_RES_CQ] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_CQ_ENTRY] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_CQE] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_USECNT] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_RES_POLL_CTX] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_RES_MR] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_MR_ENTRY] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_RES_RKEY] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_LKEY] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_RES_IOVA] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_RES_MRLEN] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_NDEV_INDEX]		= MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_NDEV_NAME]		= MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_DRIVER] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_DRIVER_ENTRY] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_DRIVER_STRING] = MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_DRIVER_PRINT_TYPE] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_DRIVER_S32] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_DRIVER_U32] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_DRIVER_S64] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_DRIVER_U64] = MNL_TYPE_U64,
-	[RDMA_NLDEV_SYS_ATTR_NETNS_MODE] = MNL_TYPE_U8,
-	[RDMA_NLDEV_ATTR_STAT_COUNTER] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_STAT_COUNTER_ENTRY] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_STAT_COUNTER_ID] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY] = MNL_TYPE_NESTED,
-	[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME] = MNL_TYPE_NUL_STRING,
-	[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_VALUE] = MNL_TYPE_U64,
-	[RDMA_NLDEV_ATTR_STAT_MODE] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_STAT_RES] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK] = MNL_TYPE_U32,
-	[RDMA_NLDEV_ATTR_DEV_DIM] = MNL_TYPE_U8,
-};
-
-int rd_attr_check(const struct nlattr *attr, int *typep)
-{
-	int type;
-
-	if (mnl_attr_type_valid(attr, RDMA_NLDEV_ATTR_MAX) < 0)
-		return MNL_CB_ERROR;
-
-	type = mnl_attr_get_type(attr);
-
-	if (mnl_attr_validate(attr, nldev_policy[type]) < 0)
-		return MNL_CB_ERROR;
-
-	*typep = nldev_policy[type];
-	return MNL_CB_OK;
-}
-
-int rd_attr_cb(const struct nlattr *attr, void *data)
-{
-	const struct nlattr **tb = data;
-	int type;
-
-	if (mnl_attr_type_valid(attr, RDMA_NLDEV_ATTR_MAX - 1) < 0)
-		/* We received unknown attribute */
-		return MNL_CB_OK;
-
-	type = mnl_attr_get_type(attr);
-
-	if (mnl_attr_validate(attr, nldev_policy[type]) < 0)
-		return MNL_CB_ERROR;
-
-	tb[type] = attr;
-	return MNL_CB_OK;
-}
-
-int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct dev_map *dev_map;
-	struct rd *rd = data;
-	const char *dev_name;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_DEV_INDEX])
-		return MNL_CB_ERROR;
-	if (!tb[RDMA_NLDEV_ATTR_PORT_INDEX]) {
-		pr_err("This tool doesn't support switches yet\n");
-		return MNL_CB_ERROR;
-	}
-
-	dev_name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-
-	dev_map = dev_map_alloc(dev_name);
-	if (!dev_map)
-		/* The main function will cleanup the allocations */
-		return MNL_CB_ERROR;
-	list_add_tail(&dev_map->list, &rd->dev_map_list);
-
-	dev_map->num_ports = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
-	dev_map->idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	return MNL_CB_OK;
-}
-
-void rd_free(struct rd *rd)
-{
-	if (!rd)
-		return;
-	free(rd->buff);
-	dev_map_cleanup(rd);
-	filters_cleanup(rd);
-}
-
-int rd_set_arg_to_devname(struct rd *rd)
-{
-	int ret = 0;
-
-	while (!rd_no_arg(rd)) {
-		if (rd_argv_match(rd, "dev") || rd_argv_match(rd, "link")) {
-			rd_arg_inc(rd);
-			if (rd_no_arg(rd)) {
-				pr_err("No device name was supplied\n");
-				ret = -EINVAL;
-			}
-			goto out;
-		}
-		rd_arg_inc(rd);
-	}
-out:
-	return ret;
-}
-
-int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port)
-{
-	struct dev_map *dev_map;
-	uint32_t port;
-	int ret = 0;
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-	if (rd_no_arg(rd)) {
-		list_for_each_entry(dev_map, &rd->dev_map_list, list) {
-			rd->dev_idx = dev_map->idx;
-			port = (strict_port) ? 1 : 0;
-			for (; port < dev_map->num_ports + 1; port++) {
-				rd->port_idx = port;
-				ret = cb(rd);
-				if (ret)
-					goto out;
-			}
-		}
-
-	} else {
-		bool is_dump_all;
-
-		dev_map = dev_map_lookup(rd, true);
-		ret = get_port_from_argv(rd, &port, &is_dump_all, strict_port);
-		if (!dev_map || port > dev_map->num_ports || (!port && ret)) {
-			pr_err("Wrong device name\n");
-			ret = -ENOENT;
-			goto out;
-		}
-		rd_arg_inc(rd);
-		rd->dev_idx = dev_map->idx;
-		rd->port_idx = port;
-		for (; rd->port_idx < dev_map->num_ports + 1; rd->port_idx++) {
-			ret = cb(rd);
-			if (ret)
-				goto out;
-			if (!is_dump_all)
-				/*
-				 * We got request to show link for devname
-				 * with port index.
-				 */
-				break;
-		}
-	}
-
-out:
-	if (rd->json_output)
-		jsonw_end_array(rd->jw);
-	return ret;
-}
-
-int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd))
-{
-	struct dev_map *dev_map;
-	int ret = 0;
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-	if (rd_no_arg(rd)) {
-		list_for_each_entry(dev_map, &rd->dev_map_list, list) {
-			rd->dev_idx = dev_map->idx;
-			ret = cb(rd);
-			if (ret)
-				goto out;
-		}
-	} else {
-		dev_map = dev_map_lookup(rd, false);
-		if (!dev_map) {
-			pr_err("Wrong device name - %s\n", rd_argv(rd));
-			ret = -ENOENT;
-			goto out;
-		}
-		rd_arg_inc(rd);
-		rd->dev_idx = dev_map->idx;
-		ret = cb(rd);
-	}
-out:
-	if (rd->json_output)
-		jsonw_end_array(rd->jw);
-	return ret;
-}
-
-int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd))
-{
-	if (rd_no_arg(rd)) {
-		pr_err("Please provide device name.\n");
-		return -EINVAL;
-	}
-
-	return rd_exec_dev(rd, cb);
-}
-
-int rd_exec_cmd(struct rd *rd, const struct rd_cmd *cmds, const char *str)
-{
-	const struct rd_cmd *c;
-
-	/* First argument in objs table is default variant */
-	if (rd_no_arg(rd))
-		return cmds->func(rd);
-
-	for (c = cmds + 1; c->cmd; ++c) {
-		if (rd_argv_match(rd, c->cmd)) {
-			/* Move to next argument */
-			rd_arg_inc(rd);
-			return c->func(rd);
-		}
-	}
-
-	pr_err("Unknown %s '%s'.\n", str, rd_argv(rd));
-	return 0;
-}
-
-void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags)
-{
-	*seq = time(NULL);
-
-	rd->nlh = mnl_nlmsg_put_header(rd->buff);
-	rd->nlh->nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, cmd);
-	rd->nlh->nlmsg_seq = *seq;
-	rd->nlh->nlmsg_flags = flags;
-}
-
-int rd_send_msg(struct rd *rd)
-{
-	int ret;
-
-	rd->nl = mnl_socket_open(NETLINK_RDMA);
-	if (!rd->nl) {
-		pr_err("Failed to open NETLINK_RDMA socket\n");
-		return -ENODEV;
-	}
-
-	ret = mnl_socket_bind(rd->nl, 0, MNL_SOCKET_AUTOPID);
-	if (ret < 0) {
-		pr_err("Failed to bind socket with err %d\n", ret);
-		goto err;
-	}
-
-	ret = mnl_socket_sendto(rd->nl, rd->nlh, rd->nlh->nlmsg_len);
-	if (ret < 0) {
-		pr_err("Failed to send to socket with err %d\n", ret);
-		goto err;
-	}
-	return 0;
-
-err:
-	mnl_socket_close(rd->nl);
-	return ret;
-}
-
-int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, unsigned int seq)
-{
-	int ret;
-	unsigned int portid;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-
-	portid = mnl_socket_get_portid(rd->nl);
-	do {
-		ret = mnl_socket_recvfrom(rd->nl, buf, sizeof(buf));
-		if (ret <= 0)
-			break;
-
-		ret = mnl_cb_run(buf, ret, seq, portid, callback, data);
-	} while (ret > 0);
-
-	if (ret < 0 && !rd->suppress_errors)
-		perror("error");
-
-	mnl_socket_close(rd->nl);
-	return ret;
-}
-
-static int null_cb(const struct nlmsghdr *nlh, void *data)
-{
-	return MNL_CB_OK;
-}
-
-int rd_sendrecv_msg(struct rd *rd, unsigned int seq)
-{
-	int ret;
-
-	ret = rd_send_msg(rd);
-	if (!ret)
-		ret = rd_recv_msg(rd, null_cb, rd, seq);
-	return ret;
-}
-
-static struct dev_map *_dev_map_lookup(struct rd *rd, const char *dev_name)
-{
-	struct dev_map *dev_map;
-
-	list_for_each_entry(dev_map, &rd->dev_map_list, list)
-		if (strcmp(dev_name, dev_map->dev_name) == 0)
-			return dev_map;
-
-	return NULL;
-}
-
-struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index)
-{
-	struct dev_map *dev_map;
-	char *dev_name;
-	char *slash;
-
-	if (rd_no_arg(rd))
-		return NULL;
-
-	dev_name = strdup(rd_argv(rd));
-	if (allow_port_index) {
-		slash = strrchr(dev_name, '/');
-		if (slash)
-			*slash = '\0';
-	}
-
-	dev_map = _dev_map_lookup(rd, dev_name);
-	free(dev_name);
-	return dev_map;
-}
-
-#define nla_type(attr) ((attr)->nla_type & NLA_TYPE_MASK)
-
-void newline(struct rd *rd)
-{
-	if (rd->json_output)
-		jsonw_end_array(rd->jw);
-	else
-		pr_out("\n");
-}
-
-void newline_indent(struct rd *rd)
-{
-	newline(rd);
-	if (!rd->json_output)
-		pr_out("    ");
-}
-
-static int print_driver_string(struct rd *rd, const char *key_str,
-				 const char *val_str)
-{
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, key_str, val_str);
-		return 0;
-	} else {
-		return pr_out("%s %s ", key_str, val_str);
-	}
-}
-
-void print_on_off(struct rd *rd, const char *key_str, bool on)
-{
-	print_driver_string(rd, key_str, (on) ? "on":"off");
-}
-
-static int print_driver_s32(struct rd *rd, const char *key_str, int32_t val,
-			      enum rdma_nldev_print_type print_type)
-{
-	if (rd->json_output) {
-		jsonw_int_field(rd->jw, key_str, val);
-		return 0;
-	}
-	switch (print_type) {
-	case RDMA_NLDEV_PRINT_TYPE_UNSPEC:
-		return pr_out("%s %d ", key_str, val);
-	case RDMA_NLDEV_PRINT_TYPE_HEX:
-		return pr_out("%s 0x%x ", key_str, val);
-	default:
-		return -EINVAL;
-	}
-}
-
-static int print_driver_u32(struct rd *rd, const char *key_str, uint32_t val,
-			      enum rdma_nldev_print_type print_type)
-{
-	if (rd->json_output) {
-		jsonw_int_field(rd->jw, key_str, val);
-		return 0;
-	}
-	switch (print_type) {
-	case RDMA_NLDEV_PRINT_TYPE_UNSPEC:
-		return pr_out("%s %u ", key_str, val);
-	case RDMA_NLDEV_PRINT_TYPE_HEX:
-		return pr_out("%s 0x%x ", key_str, val);
-	default:
-		return -EINVAL;
-	}
-}
-
-static int print_driver_s64(struct rd *rd, const char *key_str, int64_t val,
-			      enum rdma_nldev_print_type print_type)
-{
-	if (rd->json_output) {
-		jsonw_int_field(rd->jw, key_str, val);
-		return 0;
-	}
-	switch (print_type) {
-	case RDMA_NLDEV_PRINT_TYPE_UNSPEC:
-		return pr_out("%s %" PRId64 " ", key_str, val);
-	case RDMA_NLDEV_PRINT_TYPE_HEX:
-		return pr_out("%s 0x%" PRIx64 " ", key_str, val);
-	default:
-		return -EINVAL;
-	}
-}
-
-static int print_driver_u64(struct rd *rd, const char *key_str, uint64_t val,
-			      enum rdma_nldev_print_type print_type)
-{
-	if (rd->json_output) {
-		jsonw_int_field(rd->jw, key_str, val);
-		return 0;
-	}
-	switch (print_type) {
-	case RDMA_NLDEV_PRINT_TYPE_UNSPEC:
-		return pr_out("%s %" PRIu64 " ", key_str, val);
-	case RDMA_NLDEV_PRINT_TYPE_HEX:
-		return pr_out("%s 0x%" PRIx64 " ", key_str, val);
-	default:
-		return -EINVAL;
-	}
-}
-
-static int print_driver_entry(struct rd *rd, struct nlattr *key_attr,
-				struct nlattr *val_attr,
-				enum rdma_nldev_print_type print_type)
-{
-	int attr_type = nla_type(val_attr);
-	int ret = -EINVAL;
-	char *key_str;
-
-	if (asprintf(&key_str, "drv_%s", mnl_attr_get_str(key_attr)) == -1)
-		return -ENOMEM;
-
-	switch (attr_type) {
-	case RDMA_NLDEV_ATTR_DRIVER_STRING:
-		ret = print_driver_string(rd, key_str,
-					  mnl_attr_get_str(val_attr));
-		break;
-	case RDMA_NLDEV_ATTR_DRIVER_S32:
-		ret = print_driver_s32(rd, key_str, mnl_attr_get_u32(val_attr),
-				       print_type);
-		break;
-	case RDMA_NLDEV_ATTR_DRIVER_U32:
-		ret = print_driver_u32(rd, key_str, mnl_attr_get_u32(val_attr),
-				       print_type);
-		break;
-	case RDMA_NLDEV_ATTR_DRIVER_S64:
-		ret = print_driver_s64(rd, key_str, mnl_attr_get_u64(val_attr),
-				       print_type);
-		break;
-	case RDMA_NLDEV_ATTR_DRIVER_U64:
-		ret = print_driver_u64(rd, key_str, mnl_attr_get_u64(val_attr),
-				       print_type);
-		break;
-	}
-	free(key_str);
-	return ret;
-}
-
-void print_driver_table(struct rd *rd, struct nlattr *tb)
-{
-	int print_type = RDMA_NLDEV_PRINT_TYPE_UNSPEC;
-	struct nlattr *tb_entry, *key = NULL, *val;
-	int type, cc = 0;
-	int ret;
-
-	if (!rd->show_driver_details || !tb)
-		return;
-
-	if (rd->pretty_output)
-		newline_indent(rd);
-
-	/*
-	 * Driver attrs are tuples of {key, [print-type], value}.
-	 * The key must be a string.  If print-type is present, it
-	 * defines an alternate printf format type vs the native format
-	 * for the attribute.  And the value can be any available
-	 * driver type.
-	 */
-	mnl_attr_for_each_nested(tb_entry, tb) {
-
-		if (cc > MAX_LINE_LENGTH) {
-			if (rd->pretty_output)
-				newline_indent(rd);
-			cc = 0;
-		}
-		if (rd_attr_check(tb_entry, &type) != MNL_CB_OK)
-			return;
-		if (!key) {
-			if (type != MNL_TYPE_NUL_STRING)
-				return;
-			key = tb_entry;
-		} else if (type == MNL_TYPE_U8) {
-			print_type = mnl_attr_get_u8(tb_entry);
-		} else {
-			val = tb_entry;
-			ret = print_driver_entry(rd, key, val, print_type);
-			if (ret < 0)
-				return;
-			cc += ret;
-			print_type = RDMA_NLDEV_PRINT_TYPE_UNSPEC;
-			key = NULL;
-		}
-	}
-	return;
-}
diff --git a/schema/bridge_fdb_schema.json b/schema/bridge_fdb_schema.json
deleted file mode 100644
index 3e5be8d..0000000
--- a/schema/bridge_fdb_schema.json
+++ /dev/null
@@ -1,62 +0,0 @@
-{
-    "$schema": "http://json-schema.org/draft-04/schema#",
-    "description": "bridge fdb show",
-    "type": "array",
-    "items": {
-        "type": "object",
-        "properties": {
-            "dev": {
-                "type": "string"
-            },
-            "dst": {
-                "description" : "host name or ip address",
-                "type": "string"
-            },
-            "flags": {
-                "type": "array",
-                "items": {
-                    "enum": ["self", "master", "router", "offload"]
-                },
-                "uniqueItems": true
-            },
-            "linkNetNsId": {
-                "type": "integer"
-            },
-            "mac": {
-                "type": "string"
-            },
-            "master": {
-                "type": "string"
-            },
-            "opCode": {
-                "description" : "used to indicate fdb entry del",
-                "enum": ["deleted"]
-            },
-            "port": {
-                "type": "integer"
-            },
-            "state": {
-                "description" : "permanent, static, stale, state=#x",
-                "type": "string"
-            },
-            "updated": {
-                "type": "integer"
-            },
-            "used": {
-                "type": "integer"
-            },
-            "viaIf": {
-                "type": "string"
-            },
-            "viaIfIndex": {
-                "type": "integer"
-            },
-            "vlan": {
-                "type": "integer"
-            },
-            "vni": {
-                "type": "integer"
-            }
-        }
-    }
-}
diff --git a/tc/Android.mk b/tc/Android.mk
index 5c62394..467b08a 100644
--- a/tc/Android.mk
+++ b/tc/Android.mk
@@ -1,48 +1,25 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
-LOCAL_SRC_FILES :=  tc.c tc_qdisc.c tc_class.c tc_filter.c tc_util.c tc_monitor.c \
-                    tc_exec.c m_police.c m_estimator.c m_action.c m_ematch.c \
-                    emp_ematch.yacc.c emp_ematch.lex.c
-LOCAL_TCLIB := tc_core.c tc_red.c tc_cbq.c tc_estimator.c tc_stab.c
-LOCAL_TCMODULES := q_fifo.c q_sfq.c q_red.c q_prio.c q_skbprio.c q_tbf.c q_cbq.c \
-                   q_rr.c q_multiq.c q_netem.c q_choke.c q_sfb.c f_rsvp.c f_u32.c \
-                   f_route.c f_fw.c f_basic.c f_bpf.c f_flow.c f_cgroup.c \
-                   f_flower.c q_dsmark.c q_gred.c f_tcindex.c q_ingress.c \
-                   q_hfsc.c q_htb.c q_drr.c q_qfq.c m_gact.c m_mirred.c m_mpls.c \
-                   m_nat.c m_pedit.c m_ife.c m_skbedit.c m_skbmod.c m_csum.c \
-                   m_simple.c m_vlan.c m_connmark.c m_ctinfo.c m_bpf.c \
-                   m_tunnel_key.c m_sample.c m_ct.c p_ip.c p_ip6.c p_icmp.c \
-                   p_eth.c p_tcp.c p_udp.c em_nbyte.c em_cmp.c em_u32.c \
-                   em_canid.c em_meta.c q_mqprio.c q_codel.c q_fq_codel.c q_fq.c \
-                   q_pie.c q_cake.c q_hhf.c q_nss.c q_clsact.c e_bpf.c \
-                   f_matchall.c q_cbs.c q_etf.c q_taprio.c q_plug.c q_arl.c
-
-# TC_CONFIG_XT and TC_CONFIG_IPSET depends on newer version of iptables
-# LOCAL_TCMODULES += em_ipt.c em_ipset.c
-# LOCAL_SHARED_LIB += m_xt
+LOCAL_SRC_FILES :=  tc.c tc_exec.c tc_qdisc.c q_cbq.c tc_util.c tc_class.c tc_core.c m_action.c \
+                    m_estimator.c tc_filter.c tc_monitor.c tc_stab.c tc_cbq.c \
+                    tc_estimator.c f_u32.c m_police.c q_ingress.c m_mirred.c q_htb.c
 
 LOCAL_MODULE := tc
-LOCAL_MODULE_TAGS := eng
 
-LOCAL_STATIC_LIBRARIES += libiprouteutil libnetlink
-LOCAL_SRC_FILES += $(LOCAL_TCLIB) $(LOCAL_TCMODULES)
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../include/uapi
-LOCAL_LDLIBS += -lm -dl
-LOCAL_LDFLAGS += -Wl,-export-dynamic
-LOCAL_CFLAGS += -O2 -g -W -Wall -Wstrict-prototypes  -Wmissing-prototypes \
-                -Wmissing-declarations -Wold-style-definition -Wformat=2 \
-                -Wno-uninitialized -DHAVE_SETNS -DNEED_STRLCPY \
-                -DCONFIG_GACT -DCONFIG_GACT_PROB -DYY_NO_INPUT
+LOCAL_SYSTEM_SHARED_LIBRARIES := \
+	libc libm libdl
 
-# LOCAL_CFLAGS := -Wall -Wno-pointer-arith -Wno-sign-compare -Werror \
-#                -Wno-missing-field-initializers -Wno-unused-parameter \
+LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
 
-%.yacc.c: %.y
-	bison -d -t -v -o$@ $<
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
 
-%.lex.c: %.l
-	flex -o$@ $<
+LOCAL_CFLAGS := -O2 -g -W -Wall -Wno-pointer-arith -Wno-sign-compare -Werror \
+    -Wno-unused-parameter \
+    -Wno-missing-field-initializers
+
+# This is a work around for b/18403920
+LOCAL_LDFLAGS := -Wl,--no-gc-sections
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/tc/Makefile b/tc/Makefile
index d6e6794..f5bea87 100644
--- a/tc/Makefile
+++ b/tc/Makefile
@@ -1,9 +1,12 @@
-# SPDX-License-Identifier: GPL-2.0
 TCOBJ= tc.o tc_qdisc.o tc_class.o tc_filter.o tc_util.o tc_monitor.o \
-       tc_exec.o m_police.o m_estimator.o m_action.o m_ematch.o \
+       tc_exec.o tc_bpf.o m_police.o m_estimator.o m_action.o m_ematch.o \
        emp_ematch.yacc.o emp_ematch.lex.o
 
-include ../config.mk
+include ../Config
+
+ifeq ($(IP_CONFIG_SETNS),y)
+	CFLAGS += -DHAVE_SETNS
+endif
 
 SHARED_LIBS ?= y
 
@@ -12,7 +15,6 @@
 TCMODULES += q_sfq.o
 TCMODULES += q_red.o
 TCMODULES += q_prio.o
-TCMODULES += q_skbprio.o
 TCMODULES += q_tbf.o
 TCMODULES += q_cbq.o
 TCMODULES += q_rr.o
@@ -39,25 +41,16 @@
 TCMODULES += q_qfq.o
 TCMODULES += m_gact.o
 TCMODULES += m_mirred.o
-TCMODULES += m_mpls.o
 TCMODULES += m_nat.o
 TCMODULES += m_pedit.o
-TCMODULES += m_ife.o
 TCMODULES += m_skbedit.o
-TCMODULES += m_skbmod.o
 TCMODULES += m_csum.o
 TCMODULES += m_simple.o
 TCMODULES += m_vlan.o
 TCMODULES += m_connmark.o
-TCMODULES += m_ctinfo.o
 TCMODULES += m_bpf.o
-TCMODULES += m_tunnel_key.o
-TCMODULES += m_sample.o
-TCMODULES += m_ct.o
 TCMODULES += p_ip.o
-TCMODULES += p_ip6.o
 TCMODULES += p_icmp.o
-TCMODULES += p_eth.o
 TCMODULES += p_tcp.o
 TCMODULES += p_udp.o
 TCMODULES += em_nbyte.o
@@ -70,46 +63,43 @@
 TCMODULES += q_fq_codel.o
 TCMODULES += q_fq.o
 TCMODULES += q_pie.o
-TCMODULES += q_cake.o
 TCMODULES += q_hhf.o
-TCMODULES += q_nss.o
 TCMODULES += q_clsact.o
 TCMODULES += e_bpf.o
-TCMODULES += f_matchall.o
-TCMODULES += q_cbs.o
-TCMODULES += q_etf.o
-TCMODULES += q_taprio.o
-TCMODULES += q_plug.o
-TCMODULES += q_arl.o
+
+ifeq ($(TC_CONFIG_IPSET), y)
+  ifeq ($(TC_CONFIG_XT), y)
+    TCMODULES += em_ipset.o
+  endif
+endif
 
 TCSO :=
 ifeq ($(TC_CONFIG_ATM),y)
   TCSO += q_atm.so
 endif
 
-ifneq ($(TC_CONFIG_NO_XT),y)
-  ifeq ($(TC_CONFIG_XT),y)
-    TCSO += m_xt.so
-    TCMODULES += em_ipt.o
-    ifeq ($(TC_CONFIG_IPSET),y)
-      TCMODULES += em_ipset.o
-    endif
+ifeq ($(TC_CONFIG_XT),y)
+  TCSO += m_xt.so
+else
+  ifeq ($(TC_CONFIG_XT_OLD),y)
+    TCSO += m_xt_old.so
   else
-    ifeq ($(TC_CONFIG_XT_OLD),y)
-      TCSO += m_xt_old.so
+    ifeq ($(TC_CONFIG_XT_OLD_H),y)
+	CFLAGS += -DTC_CONFIG_XT_H
+	TCSO += m_xt_old.so
     else
-      ifeq ($(TC_CONFIG_XT_OLD_H),y)
-        CFLAGS += -DTC_CONFIG_XT_H
-        TCSO += m_xt_old.so
-      else
-        TCMODULES += m_ipt.o
-      endif
+      TCMODULES += m_ipt.o
     endif
   endif
 endif
 
+ifeq ($(TC_CONFIG_ELF),y)
+  CFLAGS += -DHAVE_ELF
+  LDLIBS += -lelf
+endif
+
 TCOBJ += $(TCMODULES)
-LDLIBS += -L. -lm
+LDLIBS += -L. -ltc -lm
 
 ifeq ($(SHARED_LIBS),y)
 LDLIBS += -ldl
@@ -134,16 +124,15 @@
 MODDESTDIR := $(DESTDIR)$(LIBDIR)/tc
 
 %.so: %.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fpic $< -o $@
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic $< -o $@
 
 
-all: tc $(TCSO)
+all: libtc.a tc $(TCSO)
 
-tc: $(TCOBJ) $(LIBNETLINK) libtc.a
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
+tc: $(TCOBJ) $(TCLIB)
 
 libtc.a: $(TCLIB)
-	$(QUIET_AR)$(AR) rcs $@ $^
+	$(AR) rcs $@ $(TCLIB)
 
 install: all
 	mkdir -p $(MODDESTDIR)
@@ -164,27 +153,21 @@
 	rm -f emp_ematch.yacc.*
 
 q_atm.so: q_atm.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fpic -o q_atm.so q_atm.c -latm
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o q_atm.so q_atm.c -latm
 
 m_xt.so: m_xt.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fpic -o m_xt.so m_xt.c $$($(PKG_CONFIG) xtables --cflags --libs)
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt.so m_xt.c $$($(PKG_CONFIG) xtables --cflags --libs)
 
 m_xt_old.so: m_xt_old.c
-	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fpic -o m_xt_old.so m_xt_old.c $$($(PKG_CONFIG) xtables --cflags --libs)
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fpic -o m_xt_old.so m_xt_old.c $$($(PKG_CONFIG) xtables --cflags --libs)
 
 em_ipset.o: CFLAGS += $$($(PKG_CONFIG) xtables --cflags)
 
-em_ipt.o: CFLAGS += $$($(PKG_CONFIG) xtables --cflags)
-
-ifeq ($(TC_CONFIG_XT),y)
-  LDLIBS += $$($(PKG_CONFIG) xtables --libs)
-endif
-
 %.yacc.c: %.y
-	$(QUIET_YACC)$(YACC) $(YACCFLAGS) -o $@ $<
+	$(YACC) $(YACCFLAGS) -o $@ $<
 
 %.lex.c: %.l
-	$(QUIET_LEX)$(LEX) $(LEXFLAGS) -o$@ $<
+	$(LEX) $(LEXFLAGS) -o$@ $<
 
 # our lexer includes the header from yacc, so make sure
 # we don't attempt to compile it before the header has
diff --git a/tc/README.last b/tc/README.last
new file mode 100644
index 0000000..63f6f7b
--- /dev/null
+++ b/tc/README.last
@@ -0,0 +1,45 @@
+Kernel code and interface.
+--------------------------
+
+* Compile time switches
+
+There is only one, but very important, compile time switch.
+It is not settable by "make config", but should be selected
+manually and after a bit of thinking in <include/net/pkt_sched.h>
+
+PSCHED_CLOCK_SOURCE can take three values:
+
+	PSCHED_GETTIMEOFDAY
+	PSCHED_JIFFIES
+	PSCHED_CPU
+
+
+ PSCHED_GETTIMEOFDAY
+
+Default setting is the most conservative PSCHED_GETTIMEOFDAY.
+It is very slow both because of weird slowness of do_gettimeofday()
+and because it forces code to use unnatural "timeval" format,
+where microseconds and seconds fields are separate.
+Besides that, it will misbehave, when delays exceed 2 seconds
+(f.e. very slow links or classes bounded to small slice of bandwidth)
+To resume: as only you will get it working, select correct clock
+source and forget about PSCHED_GETTIMEOFDAY forever.
+
+
+ PSCHED_JIFFIES
+
+Clock is derived from jiffies. On architectures with HZ=100
+granularity of this clock is not enough to make reasonable
+bindings to real time. However, taking into account Linux
+architecture problems, which force us to use artificial
+integrated clock in any case, this switch is not so bad
+for schduling even on high speed networks, though policing
+is not reliable.
+
+
+ PSCHED_CPU
+
+It is available only for alpha and pentiums with correct
+CPU timestamp. It is the fastest way, use it when it is available,
+but remember: not all pentiums have this facility, and
+a lot of them have clock, broken by APM etc. etc.
diff --git a/tc/e_bpf.c b/tc/e_bpf.c
index a48393b..2d650a4 100644
--- a/tc/e_bpf.c
+++ b/tc/e_bpf.c
@@ -15,8 +15,8 @@
 #include "utils.h"
 
 #include "tc_util.h"
+#include "tc_bpf.h"
 
-#include "bpf_util.h"
 #include "bpf_elf.h"
 #include "bpf_scm.h"
 
@@ -26,21 +26,19 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... bpf [ import UDS_FILE ] [ run CMD ]\n"
-		"       ... bpf [ debug ]\n"
-		"       ... bpf [ graft MAP_FILE ] [ key KEY ]\n"
-		"          `... [ object-file OBJ_FILE ] [ type TYPE ] [ section NAME ] [ verbose ]\n"
-		"          `... [ object-pinned PROG_FILE ]\n"
-		"\n"
-		"Where UDS_FILE provides the name of a unix domain socket file\n"
-		"to import eBPF maps and the optional CMD denotes the command\n"
-		"to be executed (default: \'%s\').\n"
-		"Where MAP_FILE points to a pinned map, OBJ_FILE to an object file\n"
-		"and PROG_FILE to a pinned program. TYPE can be {cls, act}, where\n"
-		"\'cls\' is default. KEY is optional and can be inferred from the\n"
-		"section name, otherwise it needs to be provided.\n",
-		BPF_DEFAULT_CMD);
+	fprintf(stderr, "Usage: ... bpf [ import UDS_FILE ] [ run CMD ]\n");
+	fprintf(stderr, "       ... bpf [ debug ]\n");
+	fprintf(stderr, "       ... bpf [ graft MAP_FILE ] [ key KEY ]\n");
+	fprintf(stderr, "          `... [ object-file OBJ_FILE ] [ type TYPE ] [ section NAME ] [ verbose ]\n");
+	fprintf(stderr, "          `... [ object-pinned PROG_FILE ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where UDS_FILE provides the name of a unix domain socket file\n");
+	fprintf(stderr, "to import eBPF maps and the optional CMD denotes the command\n");
+	fprintf(stderr, "to be executed (default: \'%s\').\n", BPF_DEFAULT_CMD);
+	fprintf(stderr, "Where MAP_FILE points to a pinned map, OBJ_FILE to an object file\n");
+	fprintf(stderr, "and PROG_FILE to a pinned program. TYPE can be {cls, act}, where\n");
+	fprintf(stderr, "\'cls\' is default. KEY is optional and can be inferred from the\n");
+	fprintf(stderr, "section name, otherwise it needs to be provided.\n");
 }
 
 static int bpf_num_env_entries(void)
@@ -58,8 +56,8 @@
 	char **argv_run = argv_default, **envp_run, *tmp;
 	int ret, i, env_old, env_num, env_map;
 	const char *bpf_uds_name = NULL;
-	int fds[BPF_SCM_MAX_FDS] = {};
-	struct bpf_map_aux aux = {};
+	int fds[BPF_SCM_MAX_FDS];
+	struct bpf_map_aux aux;
 
 	if (argc == 0)
 		return 0;
@@ -117,6 +115,9 @@
 		return -1;
 	}
 
+	memset(fds, 0, sizeof(fds));
+	memset(&aux, 0, sizeof(aux));
+
 	ret = bpf_recv_map_fds(bpf_uds_name, fds, &aux, ARRAY_SIZE(fds));
 	if (ret < 0) {
 		fprintf(stderr, "bpf: Could not receive fds!\n");
diff --git a/tc/em_canid.c b/tc/em_canid.c
index 197c707..16f6ed5 100644
--- a/tc/em_canid.c
+++ b/tc/em_canid.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -105,8 +106,8 @@
 	if (args == NULL)
 		return PARSE_ERR(args, "canid: missing arguments");
 
-	rules.rules_raw = calloc(rules.rules_capacity,
-				 sizeof(struct can_filter));
+	rules.rules_raw = malloc(sizeof(struct can_filter) * rules.rules_capacity);
+	memset(rules.rules_raw, 0, sizeof(struct can_filter) * rules.rules_capacity);
 
 	do {
 		if (!bstrcmp(args, "sff")) {
diff --git a/tc/em_cmp.c b/tc/em_cmp.c
index e051656..3e6d00e 100644
--- a/tc/em_cmp.c
+++ b/tc/em_cmp.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -43,10 +44,12 @@
 	int align, opnd = 0;
 	unsigned long offset = 0, layer = TCF_LAYER_NETWORK, mask = 0, value = 0;
 	int offset_present = 0, value_present = 0;
-	struct tcf_em_cmp cmp = {};
+	struct tcf_em_cmp cmp;
+
+	memset(&cmp, 0, sizeof(cmp));
 
 #define PARSE_ERR(CARG, FMT, ARGS...) \
-	em_parse_error(EINVAL, args, CARG, &cmp_ematch_util, FMT, ##ARGS)
+	em_parse_error(EINVAL, args, CARG, &cmp_ematch_util, FMT ,##ARGS)
 
 	if (args == NULL)
 		return PARSE_ERR(args, "cmp: missing arguments");
diff --git a/tc/em_ipset.c b/tc/em_ipset.c
index 48b287f..a2d0d15 100644
--- a/tc/em_ipset.c
+++ b/tc/em_ipset.c
@@ -52,8 +52,8 @@
 
 #define IP_SET_OP_GET_BYNAME	0x00000006	/* Get set index by name */
 struct ip_set_req_get_set {
-	unsigned int op;
-	unsigned int version;
+	unsigned op;
+	unsigned version;
 	union ip_set_name_index set;
 };
 
@@ -62,14 +62,14 @@
 
 #define IP_SET_OP_VERSION	0x00000100	/* Ask kernel version */
 struct ip_set_req_version {
-	unsigned int op;
-	unsigned int version;
+	unsigned op;
+	unsigned version;
 };
 #endif /* IPSET_INVALID_ID */
 
 extern struct ematch_util ipset_ematch_util;
 
-static int get_version(unsigned int *version)
+static int get_version(unsigned *version)
 {
 	int res, sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
 	struct ip_set_req_version req_version;
@@ -84,7 +84,6 @@
 	res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req_version, &size);
 	if (res != 0) {
 		perror("xt_set getsockopt");
-		close(sockfd);
 		return -1;
 	}
 
@@ -96,7 +95,6 @@
 {
 	int sockfd, res;
 	socklen_t size = sizeof(struct ip_set_req_get_set);
-
 	sockfd = get_version(&req->version);
 	if (sockfd < 0)
 		return -1;
@@ -109,7 +107,8 @@
 
 	if (size != sizeof(struct ip_set_req_get_set)) {
 		fprintf(stderr,
-			"Incorrect return size from kernel during ipset lookup, (want %zu, got %zu)\n",
+			"Incorrect return size from kernel during ipset lookup, "
+			"(want %zu, got %zu)\n",
 			sizeof(struct ip_set_req_get_set), (size_t)size);
 		return -1;
 	}
@@ -145,7 +144,8 @@
 	int res;
 
 	req.op = IP_SET_OP_GET_BYNAME;
-	strlcpy(req.set.name, setname, IPSET_MAXNAMELEN);
+	strncpy(req.set.name, setname, IPSET_MAXNAMELEN);
+	req.set.name[IPSET_MAXNAMELEN - 1] = '\0';
 	res = do_getsockopt(&req);
 	if (res != 0)
 		return -1;
@@ -158,29 +158,29 @@
 static int
 parse_dirs(const char *opt_arg, struct xt_set_info *info)
 {
-	char *saved = strdup(opt_arg);
-	char *ptr, *tmp = saved;
+        char *saved = strdup(opt_arg);
+        char *ptr, *tmp = saved;
 
 	if (!tmp) {
 		perror("strdup");
 		return -1;
 	}
 
-	while (info->dim < IPSET_DIM_MAX && tmp != NULL) {
-		info->dim++;
-		ptr = strsep(&tmp, ",");
-		if (strncmp(ptr, "src", 3) == 0)
-			info->flags |= (1 << info->dim);
-		else if (strncmp(ptr, "dst", 3) != 0) {
-			fputs("You must specify (the comma separated list of) 'src' or 'dst'\n", stderr);
+        while (info->dim < IPSET_DIM_MAX && tmp != NULL) {
+                info->dim++;
+                ptr = strsep(&tmp, ",");
+                if (strncmp(ptr, "src", 3) == 0)
+                        info->flags |= (1 << info->dim);
+                else if (strncmp(ptr, "dst", 3) != 0) {
+                        fputs("You must specify (the comma separated list of) 'src' or 'dst'\n", stderr);
 			free(saved);
 			return -1;
 		}
-	}
+        }
 
-	if (tmp)
-		fprintf(stderr, "Can't be more src/dst options than %u", IPSET_DIM_MAX);
-	free(saved);
+        if (tmp)
+                fprintf(stderr, "Can't be more src/dst options than %u", IPSET_DIM_MAX);
+        free(saved);
 	return tmp ? -1 : 0;
 }
 
@@ -198,11 +198,13 @@
 static int ipset_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
 			    struct bstr *args)
 {
-	struct xt_set_info set_info = {};
+	struct xt_set_info set_info;
 	int ret;
 
+	memset(&set_info, 0, sizeof(set_info));
+
 #define PARSE_ERR(CARG, FMT, ARGS...) \
-	em_parse_error(EINVAL, args, CARG, &ipset_ematch_util, FMT, ##ARGS)
+	em_parse_error(EINVAL, args, CARG, &ipset_ematch_util, FMT ,##ARGS)
 
 	if (args == NULL)
 		return PARSE_ERR(args, "ipset: missing set name");
@@ -236,7 +238,7 @@
 			    int data_len)
 {
 	int i;
-	char setname[IPSET_MAXNAMELEN];
+        char setname[IPSET_MAXNAMELEN];
 	const struct xt_set_info *set_info = data;
 
 	if (data_len != sizeof(*set_info)) {
@@ -244,7 +246,7 @@
 		return -1;
 	}
 
-	if (get_set_byid(setname, set_info->index))
+        if (get_set_byid(setname, set_info->index))
 		return -1;
 	fputs(setname, fd);
 	for (i = 1; i <= set_info->dim; i++) {
diff --git a/tc/em_ipt.c b/tc/em_ipt.c
deleted file mode 100644
index b15c3ba..0000000
--- a/tc/em_ipt.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * em_ipt.c		IPtables extensions matching Ematch
- *
- * (C) 2018 Eyal Birger <eyal.birger@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <getopt.h>
-
-#include <linux/tc_ematch/tc_em_ipt.h>
-#include <linux/pkt_cls.h>
-#include <xtables.h>
-#include "m_ematch.h"
-
-static void em_ipt_print_usage(FILE *fd)
-{
-	fprintf(fd,
-		"Usage: ipt([-6] -m MATCH_NAME [MATCH_OPTS])\n"
-		"Example: 'ipt(-m policy --reqid 1 --pol ipsec --dir in)'\n");
-}
-
-static struct option original_opts[] = {
-	{
-		.name = "match",
-		.has_arg = 1,
-		.val = 'm'
-	},
-	{
-		.name = "ipv6",
-		.val = '6'
-	},
-	{}
-};
-
-static struct xtables_globals em_tc_ipt_globals = {
-	.option_offset = 0,
-	.program_name = "tc-em-ipt",
-	.program_version = "0.1",
-	.orig_opts = original_opts,
-	.opts = original_opts,
-#if (XTABLES_VERSION_CODE >= 11)
-	.compat_rev = xtables_compatible_revision,
-#endif
-};
-
-static struct xt_entry_match *fake_xt_entry_match(int data_size, void *data)
-{
-	struct xt_entry_match *m;
-
-	m = xtables_calloc(1, XT_ALIGN(sizeof(*m)) + data_size);
-	if (!m)
-		return NULL;
-
-	if (data)
-		memcpy(m->data, data, data_size);
-
-	m->u.user.match_size = data_size;
-	return m;
-}
-
-static void scrub_match(struct xtables_match *match)
-{
-	match->mflags = 0;
-	free(match->m);
-	match->m = NULL;
-}
-
-/* IPv4 and IPv6 share the same hooking enumeration */
-#define HOOK_PRE_ROUTING 0
-#define HOOK_POST_ROUTING 4
-
-static __u32 em_ipt_hook(struct nlmsghdr *n)
-{
-	struct tcmsg *t = NLMSG_DATA(n);
-
-	if (t->tcm_parent != TC_H_ROOT &&
-	    t->tcm_parent == TC_H_MAJ(TC_H_INGRESS))
-		return HOOK_PRE_ROUTING;
-
-	return HOOK_POST_ROUTING;
-}
-
-static int em_ipt_parse_eopt_argv(struct nlmsghdr *n,
-				  struct tcf_ematch_hdr *hdr,
-				  int argc, char **argv)
-{
-	struct xtables_globals tmp_tcipt_globals = em_tc_ipt_globals;
-	struct xtables_match *match = NULL;
-	__u8 nfproto = NFPROTO_IPV4;
-
-	while (1) {
-		struct option *opts;
-		int c;
-
-		c = getopt_long(argc, argv, "6m:", tmp_tcipt_globals.opts,
-				NULL);
-		if (c == -1)
-			break;
-
-		switch (c) {
-		case 'm':
-			xtables_init_all(&tmp_tcipt_globals, nfproto);
-
-			match = xtables_find_match(optarg, XTF_TRY_LOAD, NULL);
-			if (!match || !match->x6_parse) {
-				fprintf(stderr, " failed to find match %s\n\n",
-					optarg);
-				return -1;
-			}
-
-			match->m = fake_xt_entry_match(match->size, NULL);
-			if (!match->m) {
-				printf(" %s error\n", match->name);
-				return -1;
-			}
-
-			if (match->init)
-				match->init(match->m);
-
-			opts = xtables_options_xfrm(tmp_tcipt_globals.orig_opts,
-						    tmp_tcipt_globals.opts,
-						    match->x6_options,
-						    &match->option_offset);
-			if (!opts) {
-				scrub_match(match);
-				return -1;
-			}
-
-			tmp_tcipt_globals.opts = opts;
-			break;
-
-		case '6':
-			nfproto = NFPROTO_IPV6;
-			break;
-
-		default:
-			if (!match) {
-				fprintf(stderr, "failed to find match %s\n\n",
-					optarg);
-				return -1;
-
-			}
-			xtables_option_mpcall(c, argv, 0, match, NULL);
-			break;
-		}
-	}
-
-	if (!match) {
-		fprintf(stderr, " failed to parse parameters (%s)\n", *argv);
-		return -1;
-	}
-
-	/* check that we passed the correct parameters to the match */
-	xtables_option_mfcall(match);
-
-	addraw_l(n, MAX_MSG, hdr, sizeof(*hdr));
-	addattr32(n, MAX_MSG, TCA_EM_IPT_HOOK, em_ipt_hook(n));
-	addattrstrz(n, MAX_MSG, TCA_EM_IPT_MATCH_NAME, match->name);
-	addattr8(n, MAX_MSG, TCA_EM_IPT_MATCH_REVISION, match->revision);
-	addattr8(n, MAX_MSG, TCA_EM_IPT_NFPROTO, nfproto);
-	addattr_l(n, MAX_MSG, TCA_EM_IPT_MATCH_DATA, match->m->data,
-		  match->size);
-
-	xtables_free_opts(1);
-
-	scrub_match(match);
-	return 0;
-}
-
-static int em_ipt_print_epot(FILE *fd, struct tcf_ematch_hdr *hdr, void *data,
-			     int data_len)
-{
-	struct rtattr *tb[TCA_EM_IPT_MAX + 1];
-	struct xtables_match *match;
-	const char *mname;
-	__u8 nfproto;
-
-	if (parse_rtattr(tb, TCA_EM_IPT_MAX, data, data_len) < 0)
-		return -1;
-
-	nfproto = rta_getattr_u8(tb[TCA_EM_IPT_NFPROTO]);
-
-	xtables_init_all(&em_tc_ipt_globals, nfproto);
-
-	mname = rta_getattr_str(tb[TCA_EM_IPT_MATCH_NAME]);
-	match = xtables_find_match(mname, XTF_TRY_LOAD, NULL);
-	if (!match)
-		return -1;
-
-	match->m = fake_xt_entry_match(RTA_PAYLOAD(tb[TCA_EM_IPT_MATCH_DATA]),
-				       RTA_DATA(tb[TCA_EM_IPT_MATCH_DATA]));
-	if (!match->m)
-		return -1;
-
-	match->print(NULL, match->m, 0);
-
-	scrub_match(match);
-	return 0;
-}
-
-struct ematch_util ipt_ematch_util = {
-	.kind = "ipt",
-	.kind_num = TCF_EM_IPT,
-	.parse_eopt_argv = em_ipt_parse_eopt_argv,
-	.print_eopt = em_ipt_print_epot,
-	.print_usage = em_ipt_print_usage
-};
diff --git a/tc/em_meta.c b/tc/em_meta.c
index 2ddc65e..b64f333 100644
--- a/tc/em_meta.c
+++ b/tc/em_meta.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -38,11 +39,11 @@
 	    "For a list of meta identifiers, use meta(list).\n");
 }
 
-static const struct meta_entry {
+struct meta_entry {
 	int		id;
-	char *kind;
-	char *mask;
-	char *desc;
+	char *		kind;
+	char *		mask;
+	char *		desc;
 } meta_table[] = {
 #define TCF_META_ID_SECTION 0
 #define __A(id, name, mask, desc) { TCF_META_ID_##id, name, mask, desc }
@@ -101,7 +102,7 @@
 	__A(SK_RMEM_ALLOC,	"sk_rmem",	"i",	"RMEM"),
 	__A(SK_WMEM_ALLOC,	"sk_wmem",	"i",	"WMEM"),
 	__A(SK_OMEM_ALLOC,	"sk_omem",	"i",	"OMEM"),
-	__A(SK_WMEM_QUEUED,	"sk_wmem_queue", "i",	"WMEM queue"),
+	__A(SK_WMEM_QUEUED,	"sk_wmem_queue","i",	"WMEM queue"),
 	__A(SK_SND_QLEN,	"sk_snd_queue",	"i",	"Send queue length"),
 	__A(SK_RCV_QLEN,	"sk_rcv_queue",	"i",	"Receive queue length"),
 	__A(SK_ERR_QLEN,	"sk_err_queue",	"i",	"Error queue length"),
@@ -121,11 +122,11 @@
 	return INT_MAX;
 }
 
-static const struct meta_entry *lookup_meta_entry(struct bstr *kind)
+static struct meta_entry * lookup_meta_entry(struct bstr *kind)
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(meta_table); i++)
+	for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
 		if (!bstrcmp(kind, meta_table[i].kind) &&
 		    meta_table[i].id != 0)
 			return &meta_table[i];
@@ -133,11 +134,11 @@
 	return NULL;
 }
 
-static const struct meta_entry *lookup_meta_entry_byid(int id)
+static struct meta_entry * lookup_meta_entry_byid(int id)
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(meta_table); i++)
+	for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
 		if (meta_table[i].id == id)
 			return &meta_table[i];
 
@@ -158,7 +159,6 @@
 		case TCF_META_TYPE_VAR:
 			if (TCF_META_ID(hdr->kind) == TCF_META_ID_VALUE) {
 				struct bstr *a = (struct bstr *) val;
-
 				addattr_l(n, MAX_MSG, tlv, a->data, a->len);
 			}
 			break;
@@ -168,8 +168,8 @@
 static inline int is_compatible(struct tcf_meta_val *what,
 				struct tcf_meta_val *needed)
 {
-	const struct meta_entry *entry;
 	char *p;
+	struct meta_entry *entry;
 
 	entry = lookup_meta_entry_byid(TCF_META_ID(what->kind));
 
@@ -192,7 +192,7 @@
 	    "  ID               Type       Description\n" \
 	    "--------------------------------------------------------");
 
-	for (i = 0; i < ARRAY_SIZE(meta_table); i++) {
+	for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++) {
 		if (meta_table[i].id == TCF_META_ID_SECTION) {
 			fprintf(fd, "\n%s:\n", meta_table[i].kind);
 		} else {
@@ -231,7 +231,7 @@
 #define PARSE_FAILURE ((void *) (-1))
 
 #define PARSE_ERR(CARG, FMT, ARGS...) \
-	em_parse_error(EINVAL, args, CARG, &meta_ematch_util, FMT, ##ARGS)
+	em_parse_error(EINVAL, args, CARG, &meta_ematch_util, FMT ,##ARGS)
 
 static inline int can_adopt(struct tcf_meta_val *val)
 {
@@ -249,7 +249,7 @@
 parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj,
 	     unsigned long *dst, struct tcf_meta_val *left)
 {
-	const struct meta_entry *entry;
+	struct meta_entry *entry;
 	unsigned long num;
 	struct bstr *a;
 
@@ -308,7 +308,7 @@
 
 	a = bstr_next(arg);
 
-	while (a) {
+	while(a) {
 		if (!bstrcmp(a, "shift")) {
 			unsigned long shift;
 
@@ -360,9 +360,11 @@
 {
 	int opnd;
 	struct bstr *a;
-	struct tcf_meta_hdr meta_hdr = {};
+	struct tcf_meta_hdr meta_hdr;
 	unsigned long lvalue = 0, rvalue = 0;
 
+	memset(&meta_hdr, 0, sizeof(meta_hdr));
+
 	if (args == NULL)
 		return PARSE_ERR(args, "meta: missing arguments");
 
@@ -439,7 +441,7 @@
 		return -1;
 	}
 
-	switch (type) {
+	switch(type) {
 		case TCF_META_TYPE_INT:
 			if (RTA_PAYLOAD(rta) < sizeof(__u32)) {
 				fprintf(stderr, "meta int type value TLV " \
@@ -461,7 +463,7 @@
 {
 	int id = TCF_META_ID(obj->kind);
 	int type = TCF_META_TYPE(obj->kind);
-	const struct meta_entry *entry;
+	struct meta_entry *entry;
 
 	if (id == TCF_META_ID_VALUE)
 		return print_value(fd, type, rta);
@@ -482,9 +484,8 @@
 				if (RTA_PAYLOAD(rta) < sizeof(__u32))
 					goto size_mismatch;
 
-				if (rta_getattr_u32(rta))
-					fprintf(fd, " mask 0x%08x",
-						rta_getattr_u32(rta));
+				fprintf(fd, " mask 0x%08x",
+				    rta_getattr_u32(rta));
 			}
 			break;
 	}
diff --git a/tc/em_nbyte.c b/tc/em_nbyte.c
index 274d713..87f3e9d 100644
--- a/tc/em_nbyte.c
+++ b/tc/em_nbyte.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -43,10 +44,12 @@
 	struct bstr *needle = args;
 	unsigned long offset = 0, layer = TCF_LAYER_NETWORK;
 	int offset_present = 0;
-	struct tcf_em_nbyte nb = {};
+	struct tcf_em_nbyte nb;
+
+	memset(&nb, 0, sizeof(nb));
 
 #define PARSE_ERR(CARG, FMT, ARGS...) \
-	em_parse_error(EINVAL, args, CARG, &nbyte_ematch_util, FMT, ##ARGS)
+	em_parse_error(EINVAL, args, CARG, &nbyte_ematch_util, FMT ,##ARGS)
 
 	if (args == NULL)
 		return PARSE_ERR(args, "nbyte: missing arguments");
diff --git a/tc/em_u32.c b/tc/em_u32.c
index bc284af..21ed70f 100644
--- a/tc/em_u32.c
+++ b/tc/em_u32.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -38,10 +39,12 @@
 	struct bstr *a;
 	int align, nh_len;
 	unsigned long key, mask, offmask = 0, offset;
-	struct tc_u32_key u_key = {};
+	struct tc_u32_key u_key;
+
+	memset(&u_key, 0, sizeof(u_key));
 
 #define PARSE_ERR(CARG, FMT, ARGS...) \
-	em_parse_error(EINVAL, args, CARG, &u32_ematch_util, FMT, ##ARGS)
+	em_parse_error(EINVAL, args, CARG, &u32_ematch_util, FMT ,##ARGS)
 
 	if (args == NULL)
 		return PARSE_ERR(args, "u32: missing arguments");
@@ -82,7 +85,6 @@
 	nh_len = strlen("nexthdr+");
 	if (a->len > nh_len && !memcmp(a->data, "nexthdr+", nh_len)) {
 		char buf[a->len - nh_len + 1];
-
 		offmask = -1;
 		memcpy(buf, a->data + nh_len, a->len - nh_len);
 		offset = strtoul(buf, NULL, 0);
diff --git a/tc/emp_ematch.l b/tc/emp_ematch.l
index d7a9930..d9b45be 100644
--- a/tc/emp_ematch.l
+++ b/tc/emp_ematch.l
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 %{
  #include "emp_ematch.yacc.h"
  #include "m_ematch.h"
@@ -137,7 +136,7 @@
 ")"					{
 						return yylval.i = *yytext;
 					}
-[^" \t\r\n()][^ \t\r\n()]*		{
+[^ \t\r\n()]+				{
 						yylval.b = bstr_alloc(yytext);
 						if (yylval.b == NULL)
 							return ERROR;
diff --git a/tc/emp_ematch.y b/tc/emp_ematch.y
index a02e831..2e6cf35 100644
--- a/tc/emp_ematch.y
+++ b/tc/emp_ematch.y
@@ -8,8 +8,8 @@
 
 %locations
 %token-table
-%define parse.error verbose
-%define api.prefix {ematch_}
+%error-verbose
+%name-prefix "ematch_"
 
 %union {
 	unsigned int i;
diff --git a/tc/f_basic.c b/tc/f_basic.c
index 7b19cea..4adf1d2 100644
--- a/tc/f_basic.c
+++ b/tc/f_basic.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -26,15 +27,13 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... basic [ match EMATCH_TREE ]\n"
-		"                 [ action ACTION_SPEC ] [ classid CLASSID ]\n"
-		"\n"
-		"Where:	SELECTOR := SAMPLE SAMPLE ...\n"
-		"	FILTERID := X:Y:Z\n"
-		"	ACTION_SPEC := ... look at individual actions\n"
-		"\n"
-		"NOTE: CLASSID is parsed as hexadecimal input.\n");
+	fprintf(stderr, "Usage: ... basic [ match EMATCH_TREE ] \n");
+	fprintf(stderr, "                 [ action ACTION_SPEC ] [ classid CLASSID ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
+	fprintf(stderr, "       FILTERID := X:Y:Z\n");
+	fprintf(stderr, "       ACTION_SPEC := ... look at individual actions\n");
+	fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
 static int basic_parse_opt(struct filter_util *qu, char *handle,
@@ -57,7 +56,7 @@
 	if (argc == 0)
 		return 0;
 
-	tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
 	addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
@@ -70,8 +69,7 @@
 			continue;
 		} else if (matches(*argv, "classid") == 0 ||
 			   strcmp(*argv, "flowid") == 0) {
-			unsigned int handle;
-
+			unsigned handle;
 			NEXT_ARG();
 			if (get_tc_classid(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"classid\"\n");
@@ -104,7 +102,7 @@
 		argc--; argv++;
 	}
 
-	tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
+	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
 	return 0;
 }
 
@@ -136,7 +134,7 @@
 	}
 
 	if (tb[TCA_BASIC_ACT]) {
-		tc_print_action(f, tb[TCA_BASIC_ACT], 0);
+		tc_print_action(f, tb[TCA_BASIC_ACT]);
 	}
 
 	return 0;
diff --git a/tc/f_bpf.c b/tc/f_bpf.c
index 135271a..afc2e58 100644
--- a/tc/f_bpf.c
+++ b/tc/f_bpf.c
@@ -6,7 +6,7 @@
  *		as published by the Free Software Foundation; either version
  *		2 of the License, or (at your option) any later version.
  *
- * Authors:	Daniel Borkmann <daniel@iogearbox.net>
+ * Authors:	Daniel Borkmann <dborkman@redhat.com>
  */
 
 #include <stdio.h>
@@ -15,79 +15,65 @@
 #include <linux/bpf.h>
 
 #include "utils.h"
-
 #include "tc_util.h"
-#include "bpf_util.h"
+#include "tc_bpf.h"
 
 static const enum bpf_prog_type bpf_type = BPF_PROG_TYPE_SCHED_CLS;
 
+static const int nla_tbl[BPF_NLA_MAX] = {
+	[BPF_NLA_OPS_LEN]	= TCA_BPF_OPS_LEN,
+	[BPF_NLA_OPS]		= TCA_BPF_OPS,
+	[BPF_NLA_FD]		= TCA_BPF_FD,
+	[BPF_NLA_NAME]		= TCA_BPF_NAME,
+};
+
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... bpf ...\n"
-		"\n"
-		"BPF use case:\n"
-		" bytecode BPF_BYTECODE\n"
-		" bytecode-file FILE\n"
-		"\n"
-		"eBPF use case:\n"
-		" object-file FILE [ section CLS_NAME ] [ export UDS_FILE ]"
-		" [ verbose ] [ direct-action ] [ skip_hw | skip_sw ]\n"
-		" object-pinned FILE [ direct-action ] [ skip_hw | skip_sw ]\n"
-		"\n"
-		"Common remaining options:\n"
-		" [ action ACTION_SPEC ]\n"
-		" [ classid CLASSID ]\n"
-		"\n"
-		"Where BPF_BYTECODE := \'s,c t f k,c t f k,c t f k,...\'\n"
-		"c,t,f,k and s are decimals; s denotes number of 4-tuples\n"
-		"\n"
-		"Where FILE points to a file containing the BPF_BYTECODE string,\n"
-		"an ELF file containing eBPF map definitions and bytecode, or a\n"
-		"pinned eBPF program.\n"
-		"\n"
-		"Where CLS_NAME refers to the section name containing the\n"
-		"classifier (default \'%s\').\n"
-		"\n"
-		"Where UDS_FILE points to a unix domain socket file in order\n"
-		"to hand off control of all created eBPF maps to an agent.\n"
-		"\n"
-		"ACTION_SPEC := ... look at individual actions\n"
-		"NOTE: CLASSID is parsed as hexadecimal input.\n",
-		bpf_prog_to_default_section(bpf_type));
+	fprintf(stderr, "Usage: ... bpf ...\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "BPF use case:\n");
+	fprintf(stderr, " bytecode BPF_BYTECODE\n");
+	fprintf(stderr, " bytecode-file FILE\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "eBPF use case:\n");
+	fprintf(stderr, " object-file FILE [ section CLS_NAME ] [ export UDS_FILE ]");
+	fprintf(stderr, " [ verbose ] [ direct-action ]\n");
+	fprintf(stderr, " object-pinned FILE [ direct-action ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Common remaining options:\n");
+	fprintf(stderr, " [ action ACTION_SPEC ]\n");
+	fprintf(stderr, " [ classid CLASSID ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where BPF_BYTECODE := \'s,c t f k,c t f k,c t f k,...\'\n");
+	fprintf(stderr, "c,t,f,k and s are decimals; s denotes number of 4-tuples\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where FILE points to a file containing the BPF_BYTECODE string,\n");
+	fprintf(stderr, "an ELF file containing eBPF map definitions and bytecode, or a\n");
+	fprintf(stderr, "pinned eBPF program.\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where CLS_NAME refers to the section name containing the\n");
+	fprintf(stderr, "classifier (default \'%s\').\n", bpf_default_section(bpf_type));
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where UDS_FILE points to a unix domain socket file in order\n");
+	fprintf(stderr, "to hand off control of all created eBPF maps to an agent.\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "ACTION_SPEC := ... look at individual actions\n");
+	fprintf(stderr, "NOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
-static void bpf_cbpf_cb(void *nl, const struct sock_filter *ops, int ops_len)
-{
-	addattr16(nl, MAX_MSG, TCA_BPF_OPS_LEN, ops_len);
-	addattr_l(nl, MAX_MSG, TCA_BPF_OPS, ops,
-		  ops_len * sizeof(struct sock_filter));
-}
-
-static void bpf_ebpf_cb(void *nl, int fd, const char *annotation)
-{
-	addattr32(nl, MAX_MSG, TCA_BPF_FD, fd);
-	addattrstrz(nl, MAX_MSG, TCA_BPF_NAME, annotation);
-}
-
-static const struct bpf_cfg_ops bpf_cb_ops = {
-	.cbpf_cb = bpf_cbpf_cb,
-	.ebpf_cb = bpf_ebpf_cb,
-};
-
 static int bpf_parse_opt(struct filter_util *qu, char *handle,
 			 int argc, char **argv, struct nlmsghdr *n)
 {
 	const char *bpf_obj = NULL, *bpf_uds_name = NULL;
 	struct tcmsg *t = NLMSG_DATA(n);
-	unsigned int bpf_gen_flags = 0;
 	unsigned int bpf_flags = 0;
-	struct bpf_cfg_in cfg = {};
 	bool seen_run = false;
-	bool skip_sw = false;
 	struct rtattr *tail;
 	int ret = 0;
 
+	if (argc == 0)
+		return 0;
+
 	if (handle) {
 		if (get_u32(&t->tcm_handle, handle, 0)) {
 			fprintf(stderr, "Illegal \"handle\"\n");
@@ -95,35 +81,19 @@
 		}
 	}
 
-	if (argc == 0)
-		return 0;
-
 	tail = (struct rtattr *)(((void *)n) + NLMSG_ALIGN(n->nlmsg_len));
 	addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "run") == 0) {
 			NEXT_ARG();
-
-			if (seen_run)
-				duparg("run", *argv);
 opt_bpf:
 			seen_run = true;
-			cfg.type = bpf_type;
-			cfg.argc = argc;
-			cfg.argv = argv;
-
-			if (bpf_parse_common(&cfg, &bpf_cb_ops) < 0) {
-				fprintf(stderr,
-					"Unable to parse bpf command line\n");
+			if (bpf_parse_common(&argc, &argv, nla_tbl, bpf_type,
+					     &bpf_obj, &bpf_uds_name, n)) {
+				fprintf(stderr, "Failed to retrieve (e)BPF data!\n");
 				return -1;
 			}
-
-			argc = cfg.argc;
-			argv = cfg.argv;
-
-			bpf_obj = cfg.object;
-			bpf_uds_name = cfg.uds;
 		} else if (matches(*argv, "classid") == 0 ||
 			   matches(*argv, "flowid") == 0) {
 			unsigned int handle;
@@ -137,11 +107,6 @@
 		} else if (matches(*argv, "direct-action") == 0 ||
 			   matches(*argv, "da") == 0) {
 			bpf_flags |= TCA_BPF_FLAG_ACT_DIRECT;
-		} else if (matches(*argv, "skip_hw") == 0) {
-			bpf_gen_flags |= TCA_CLS_FLAGS_SKIP_HW;
-		} else if (matches(*argv, "skip_sw") == 0) {
-			bpf_gen_flags |= TCA_CLS_FLAGS_SKIP_SW;
-			skip_sw = true;
 		} else if (matches(*argv, "action") == 0) {
 			NEXT_ARG();
 			if (parse_action(&argc, &argv, TCA_BPF_ACT, n)) {
@@ -171,16 +136,7 @@
 		NEXT_ARG_FWD();
 	}
 
-	if (skip_sw)
-		cfg.ifindex = t->tcm_ifindex;
-	if (bpf_load_common(&cfg, &bpf_cb_ops, n) < 0) {
-		fprintf(stderr, "Unable to load program\n");
-		return -1;
-	}
-
-	if (bpf_gen_flags)
-		addattr32(n, MAX_MSG, TCA_BPF_FLAGS_GEN, bpf_gen_flags);
-	if (bpf_flags)
+	if (bpf_obj && bpf_flags)
 		addattr32(n, MAX_MSG, TCA_BPF_FLAGS, bpf_flags);
 
 	tail->rta_len = (((void *)n) + n->nlmsg_len) - (void *)tail;
@@ -195,7 +151,6 @@
 			 struct rtattr *opt, __u32 handle)
 {
 	struct rtattr *tb[TCA_BPF_MAX + 1];
-	int dump_ok = 0;
 
 	if (opt == NULL)
 		return 0;
@@ -213,6 +168,8 @@
 
 	if (tb[TCA_BPF_NAME])
 		fprintf(f, "%s ", rta_getattr_str(tb[TCA_BPF_NAME]));
+	else if (tb[TCA_BPF_FD])
+		fprintf(f, "pfd %u ", rta_getattr_u32(tb[TCA_BPF_FD]));
 
 	if (tb[TCA_BPF_FLAGS]) {
 		unsigned int flags = rta_getattr_u32(tb[TCA_BPF_FLAGS]);
@@ -221,34 +178,10 @@
 			fprintf(f, "direct-action ");
 	}
 
-	if (tb[TCA_BPF_FLAGS_GEN]) {
-		unsigned int flags =
-			rta_getattr_u32(tb[TCA_BPF_FLAGS_GEN]);
-
-		if (flags & TCA_CLS_FLAGS_SKIP_HW)
-			fprintf(f, "skip_hw ");
-		if (flags & TCA_CLS_FLAGS_SKIP_SW)
-			fprintf(f, "skip_sw ");
-
-		if (flags & TCA_CLS_FLAGS_IN_HW)
-			fprintf(f, "in_hw ");
-		else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
-			fprintf(f, "not_in_hw ");
-	}
-
-	if (tb[TCA_BPF_OPS] && tb[TCA_BPF_OPS_LEN])
-		bpf_print_ops(tb[TCA_BPF_OPS],
+	if (tb[TCA_BPF_OPS] && tb[TCA_BPF_OPS_LEN]) {
+		bpf_print_ops(f, tb[TCA_BPF_OPS],
 			      rta_getattr_u16(tb[TCA_BPF_OPS_LEN]));
-
-	if (tb[TCA_BPF_ID])
-		dump_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID]));
-	if (!dump_ok && tb[TCA_BPF_TAG]) {
-		SPRINT_BUF(b);
-
-		fprintf(f, "tag %s ",
-			hexstring_n2a(RTA_DATA(tb[TCA_BPF_TAG]),
-				      RTA_PAYLOAD(tb[TCA_BPF_TAG]),
-				      b, sizeof(b)));
+		fprintf(f, "\n");
 	}
 
 	if (tb[TCA_BPF_POLICE]) {
@@ -256,8 +189,9 @@
 		tc_print_police(f, tb[TCA_BPF_POLICE]);
 	}
 
-	if (tb[TCA_BPF_ACT])
-		tc_print_action(f, tb[TCA_BPF_ACT], 0);
+	if (tb[TCA_BPF_ACT]) {
+		tc_print_action(f, tb[TCA_BPF_ACT]);
+	}
 
 	return 0;
 }
diff --git a/tc/f_cgroup.c b/tc/f_cgroup.c
index 633700e..53f7406 100644
--- a/tc/f_cgroup.c
+++ b/tc/f_cgroup.c
@@ -40,7 +40,7 @@
 
 	t->tcm_handle = h;
 
-	tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
+	tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
 	addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
@@ -76,7 +76,7 @@
 		}
 	}
 
-	tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
+	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
 	return 0;
 }
 
@@ -102,7 +102,7 @@
 	}
 
 	if (tb[TCA_CGROUP_ACT])
-		tc_print_action(f, tb[TCA_CGROUP_ACT], 0);
+		tc_print_action(f, tb[TCA_CGROUP_ACT]);
 
 	return 0;
 }
diff --git a/tc/f_flow.c b/tc/f_flow.c
index 9dd50df..f398f55 100644
--- a/tc/f_flow.c
+++ b/tc/f_flow.c
@@ -21,21 +21,21 @@
 static void explain(void)
 {
 	fprintf(stderr,
-		"Usage: ... flow ...\n"
-		"\n"
-		" [mapping mode]: map key KEY [ OPS ] ...\n"
-		" [hashing mode]: hash keys KEY-LIST ... [ perturb SECS ]\n"
-		"\n"
-		"                 [ divisor NUM ] [ baseclass ID ] [ match EMATCH_TREE ]\n"
-		"                 [ action ACTION_SPEC ]\n"
-		"\n"
-		"KEY-LIST := [ KEY-LIST , ] KEY\n"
-		"KEY      := [ src | dst | proto | proto-src | proto-dst | iif | priority |\n"
-		"              mark | nfct | nfct-src | nfct-dst | nfct-proto-src |\n"
-		"              nfct-proto-dst | rt-classid | sk-uid | sk-gid |\n"
-		"              vlan-tag | rxhash ]\n"
-		"OPS      := [ or NUM | and NUM | xor NUM | rshift NUM | addend NUM ]\n"
-		"ID       := X:Y\n"
+"Usage: ... flow ...\n"
+"\n"
+" [mapping mode]: map key KEY [ OPS ] ...\n"
+" [hashing mode]: hash keys KEY-LIST ... [ perturb SECS ]\n"
+"\n"
+"                 [ divisor NUM ] [ baseclass ID ] [ match EMATCH_TREE ]\n"
+"                 [ action ACTION_SPEC ]\n"
+"\n"
+"KEY-LIST := [ KEY-LIST , ] KEY\n"
+"KEY      := [ src | dst | proto | proto-src | proto-dst | iif | priority | \n"
+"              mark | nfct | nfct-src | nfct-dst | nfct-proto-src | \n"
+"              nfct-proto-dst | rt-classid | sk-uid | sk-gid |\n"
+"              vlan-tag | rxhash ]\n"
+"OPS      := [ or NUM | and NUM | xor NUM | rshift NUM | addend NUM ]\n"
+"ID       := X:Y\n"
 	);
 }
 
@@ -133,6 +133,7 @@
 static int flow_parse_opt(struct filter_util *fu, char *handle,
 			  int argc, char **argv, struct nlmsghdr *n)
 {
+	struct tc_police tp;
 	struct tcmsg *t = NLMSG_DATA(n);
 	struct rtattr *tail;
 	__u32 mask = ~0U, xor = 0;
@@ -140,6 +141,8 @@
 	__u32 mode = FLOW_MODE_MAP;
 	__u32 tmp;
 
+	memset(&tp, 0, sizeof(tp));
+
 	if (handle) {
 		if (get_u32(&t->tcm_handle, handle, 0)) {
 			fprintf(stderr, "Illegal \"handle\"\n");
@@ -147,7 +150,8 @@
 		}
 	}
 
-	tail = addattr_nest(n, 4096, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "map") == 0) {
@@ -258,7 +262,7 @@
 		addattr32(n, 4096, TCA_FLOW_XOR, xor);
 	}
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
 	return 0;
 }
 
@@ -266,7 +270,6 @@
 			  __u32 handle)
 {
 	struct rtattr *tb[TCA_FLOW_MAX+1];
-
 	SPRINT_BUF(b1);
 	unsigned int i;
 	__u32 mask = ~0, val = 0;
@@ -346,7 +349,7 @@
 		tc_print_police(f, tb[TCA_FLOW_POLICE]);
 	if (tb[TCA_FLOW_ACT]) {
 		fprintf(f, "\n");
-		tc_print_action(f, tb[TCA_FLOW_ACT], 0);
+		tc_print_action(f, tb[TCA_FLOW_ACT]);
 	}
 	return 0;
 }
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 1b518ef..db9cc29 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -12,363 +12,51 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <string.h>
 #include <net/if.h>
-#include <linux/limits.h>
-#include <linux/if_arp.h>
 #include <linux/if_ether.h>
 #include <linux/ip.h>
-#include <linux/tc_act/tc_vlan.h>
-#include <linux/mpls.h>
 
 #include "utils.h"
 #include "tc_util.h"
 #include "rt_names.h"
 
-enum flower_matching_flags {
-	FLOWER_IP_FLAGS,
-};
-
-enum flower_endpoint {
-	FLOWER_ENDPOINT_SRC,
-	FLOWER_ENDPOINT_DST
-};
-
-enum flower_icmp_field {
-	FLOWER_ICMP_FIELD_TYPE,
-	FLOWER_ICMP_FIELD_CODE
-};
-
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... flower	[ MATCH-LIST ] [ verbose ]\n"
-		"			[ skip_sw | skip_hw ]\n"
-		"			[ action ACTION-SPEC ] [ classid CLASSID ]\n"
-		"\n"
-		"Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n"
-		"       MATCH      := {	indev DEV-NAME |\n"
-		"			vlan_id VID |\n"
-		"			vlan_prio PRIORITY |\n"
-		"			vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
-		"			cvlan_id VID |\n"
-		"			cvlan_prio PRIORITY |\n"
-		"			cvlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
-		"			dst_mac MASKED-LLADDR |\n"
-		"			src_mac MASKED-LLADDR |\n"
-		"			ip_proto [tcp | udp | sctp | icmp | icmpv6 | IP-PROTO ] |\n"
-		"			ip_tos MASKED-IP_TOS |\n"
-		"			ip_ttl MASKED-IP_TTL |\n"
-		"			mpls_label LABEL |\n"
-		"			mpls_tc TC |\n"
-		"			mpls_bos BOS |\n"
-		"			mpls_ttl TTL |\n"
-		"			dst_ip PREFIX |\n"
-		"			src_ip PREFIX |\n"
-		"			dst_port PORT-NUMBER |\n"
-		"			src_port PORT-NUMBER |\n"
-		"			tcp_flags MASKED-TCP_FLAGS |\n"
-		"			type MASKED-ICMP-TYPE |\n"
-		"			code MASKED-ICMP-CODE |\n"
-		"			arp_tip IPV4-PREFIX |\n"
-		"			arp_sip IPV4-PREFIX |\n"
-		"			arp_op [ request | reply | OP ] |\n"
-		"			arp_tha MASKED-LLADDR |\n"
-		"			arp_sha MASKED-LLADDR |\n"
-		"			enc_dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
-		"			enc_src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
-		"			enc_key_id [ KEY-ID ] |\n"
-		"			enc_tos MASKED-IP_TOS |\n"
-		"			enc_ttl MASKED-IP_TTL |\n"
-		"			geneve_opts MASKED-OPTIONS |\n"
-		"			ip_flags IP-FLAGS | \n"
-		"			enc_dst_port [ port_number ] |\n"
-		"			ct_state MASKED_CT_STATE |\n"
-		"			ct_label MASKED_CT_LABEL |\n"
-		"			ct_mark MASKED_CT_MARK |\n"
-		"			ct_zone MASKED_CT_ZONE }\n"
-		"	FILTERID := X:Y:Z\n"
-		"	MASKED_LLADDR := { LLADDR | LLADDR/MASK | LLADDR/BITS }\n"
-		"	MASKED_CT_STATE := combination of {+|-} and flags trk,est,new\n"
-		"	ACTION-SPEC := ... look at individual actions\n"
-		"\n"
-		"NOTE:	CLASSID, IP-PROTO are parsed as hexadecimal input.\n"
-		"NOTE:	There can be only used one mask per one prio. If user needs\n"
-		"	to specify different mask, he has to use different prio.\n");
+	fprintf(stderr, "Usage: ... flower [ MATCH-LIST ]\n");
+	fprintf(stderr, "                  [ action ACTION-SPEC ] [ classid CLASSID ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n");
+	fprintf(stderr, "       MATCH      := { indev DEV-NAME | \n");
+	fprintf(stderr, "                       dst_mac MAC-ADDR | \n");
+	fprintf(stderr, "                       src_mac MAC-ADDR | \n");
+	fprintf(stderr, "                       [ipv4 | ipv6 ] | \n");
+	fprintf(stderr, "                       ip_proto [tcp | udp | IP-PROTO ] | \n");
+	fprintf(stderr, "                       dst_ip [ IPV4-ADDR | IPV6-ADDR ] | \n");
+	fprintf(stderr, "                       src_ip [ IPV4-ADDR | IPV6-ADDR ] | \n");
+	fprintf(stderr, "                       dst_port PORT-NUMBER | \n");
+	fprintf(stderr, "                       src_port PORT-NUMBER }\n");
+	fprintf(stderr,	"       FILTERID := X:Y:Z\n");
+	fprintf(stderr,	"       ACTION-SPEC := ... look at individual actions\n");
+	fprintf(stderr,	"\n");
+	fprintf(stderr,	"NOTE: CLASSID, ETH-TYPE, IP-PROTO are parsed as hexadecimal input.\n");
+	fprintf(stderr,	"NOTE: There can be only used one mask per one prio. If user needs\n");
+	fprintf(stderr,	"      to specify different mask, he has to use different prio.\n");
 }
 
 static int flower_parse_eth_addr(char *str, int addr_type, int mask_type,
 				 struct nlmsghdr *n)
 {
-	int ret, err = -1;
-	char addr[ETH_ALEN], *slash;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
+	int ret;
+	char addr[ETH_ALEN];
 
 	ret = ll_addr_a2n(addr, sizeof(addr), str);
 	if (ret < 0)
-		goto err;
+		return -1;
 	addattr_l(n, MAX_MSG, addr_type, addr, sizeof(addr));
-
-	if (slash) {
-		unsigned bits;
-
-		if (!get_unsigned(&bits, slash + 1, 10)) {
-			uint64_t mask;
-
-			/* Extra 16 bit shift to push mac address into
-			 * high bits of uint64_t
-			 */
-			mask = htonll(0xffffffffffffULL << (16 + 48 - bits));
-			memcpy(addr, &mask, ETH_ALEN);
-		} else {
-			ret = ll_addr_a2n(addr, sizeof(addr), slash + 1);
-			if (ret < 0)
-				goto err;
-		}
-	} else {
-		memset(addr, 0xff, ETH_ALEN);
-	}
+	memset(addr, 0xff, ETH_ALEN);
 	addattr_l(n, MAX_MSG, mask_type, addr, sizeof(addr));
-
-	err = 0;
-err:
-	if (slash)
-		*slash = '/';
-	return err;
-}
-
-static bool eth_type_vlan(__be16 ethertype)
-{
-	return ethertype == htons(ETH_P_8021Q) ||
-	       ethertype == htons(ETH_P_8021AD);
-}
-
-static int flower_parse_vlan_eth_type(char *str, __be16 eth_type, int type,
-				      __be16 *p_vlan_eth_type,
-				      struct nlmsghdr *n)
-{
-	__be16 vlan_eth_type;
-
-	if (!eth_type_vlan(eth_type)) {
-		fprintf(stderr, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD\n",
-			type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "vlan_ethtype" : "cvlan_ethtype");
-		return -1;
-	}
-
-	if (ll_proto_a2n(&vlan_eth_type, str))
-		invarg("invalid vlan_ethtype", str);
-	addattr16(n, MAX_MSG, type, vlan_eth_type);
-	*p_vlan_eth_type = vlan_eth_type;
-	return 0;
-}
-
-struct flag_to_string {
-	int flag;
-	enum flower_matching_flags type;
-	char *string;
-};
-
-static struct flag_to_string flags_str[] = {
-	{ TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT, FLOWER_IP_FLAGS, "frag" },
-	{ TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST, FLOWER_IP_FLAGS, "firstfrag" },
-};
-
-static int flower_parse_matching_flags(char *str,
-				       enum flower_matching_flags type,
-				       __u32 *mtf, __u32 *mtf_mask)
-{
-	char *token;
-	bool no;
-	bool found;
-	int i;
-
-	token = strtok(str, "/");
-
-	while (token) {
-		if (!strncmp(token, "no", 2)) {
-			no = true;
-			token += 2;
-		} else
-			no = false;
-
-		found = false;
-		for (i = 0; i < ARRAY_SIZE(flags_str); i++) {
-			if (type != flags_str[i].type)
-				continue;
-
-			if (!strcmp(token, flags_str[i].string)) {
-				if (no)
-					*mtf &= ~flags_str[i].flag;
-				else
-					*mtf |= flags_str[i].flag;
-
-				*mtf_mask |= flags_str[i].flag;
-				found = true;
-				break;
-			}
-		}
-		if (!found)
-			return -1;
-
-		token = strtok(NULL, "/");
-	}
-
-	return 0;
-}
-
-static int flower_parse_u16(char *str, int value_type, int mask_type,
-			    struct nlmsghdr *n)
-{
-	__u16 value, mask;
-	char *slash;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
-
-	if (get_u16(&value, str, 0))
-		return -1;
-
-	if (slash) {
-		if (get_u16(&mask, slash + 1, 0))
-			return -1;
-	} else {
-		mask = UINT16_MAX;
-	}
-
-	addattr16(n, MAX_MSG, value_type, value);
-	addattr16(n, MAX_MSG, mask_type, mask);
-
-	return 0;
-}
-
-static int flower_parse_u32(char *str, int value_type, int mask_type,
-			    struct nlmsghdr *n)
-{
-	__u32 value, mask;
-	char *slash;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
-
-	if (get_u32(&value, str, 0))
-		return -1;
-
-	if (slash) {
-		if (get_u32(&mask, slash + 1, 0))
-			return -1;
-	} else {
-		mask = UINT32_MAX;
-	}
-
-	addattr32(n, MAX_MSG, value_type, value);
-	addattr32(n, MAX_MSG, mask_type, mask);
-
-	return 0;
-}
-
-static int flower_parse_ct_mark(char *str, struct nlmsghdr *n)
-{
-	return flower_parse_u32(str,
-				TCA_FLOWER_KEY_CT_MARK,
-				TCA_FLOWER_KEY_CT_MARK_MASK,
-				n);
-}
-
-static int flower_parse_ct_zone(char *str, struct nlmsghdr *n)
-{
-	return flower_parse_u16(str,
-				TCA_FLOWER_KEY_CT_ZONE,
-				TCA_FLOWER_KEY_CT_ZONE_MASK,
-				n);
-}
-
-static int flower_parse_ct_labels(char *str, struct nlmsghdr *n)
-{
-#define LABELS_SIZE	16
-	uint8_t labels[LABELS_SIZE], lmask[LABELS_SIZE];
-	char *slash, *mask = NULL;
-	size_t slen, slen_mask = 0;
-
-	slash = index(str, '/');
-	if (slash) {
-		*slash = 0;
-		mask = slash + 1;
-		slen_mask = strlen(mask);
-	}
-
-	slen = strlen(str);
-	if (slen > LABELS_SIZE * 2 || slen_mask > LABELS_SIZE * 2) {
-		char errmsg[128];
-
-		snprintf(errmsg, sizeof(errmsg),
-				"%zd Max allowed size %d",
-				slen, LABELS_SIZE*2);
-		invarg(errmsg, str);
-	}
-
-	if (hex2mem(str, labels, slen / 2) < 0)
-		invarg("labels must be a hex string\n", str);
-	addattr_l(n, MAX_MSG, TCA_FLOWER_KEY_CT_LABELS, labels, slen / 2);
-
-	if (mask) {
-		if (hex2mem(mask, lmask, slen_mask / 2) < 0)
-			invarg("labels mask must be a hex string\n", mask);
-	} else {
-		memset(lmask, 0xff, sizeof(lmask));
-		slen_mask = sizeof(lmask) * 2;
-	}
-	addattr_l(n, MAX_MSG, TCA_FLOWER_KEY_CT_LABELS_MASK, lmask,
-		  slen_mask / 2);
-
-	return 0;
-}
-
-static struct flower_ct_states {
-	char *str;
-	int flag;
-} flower_ct_states[] = {
-	{ "trk", TCA_FLOWER_KEY_CT_FLAGS_TRACKED },
-	{ "new", TCA_FLOWER_KEY_CT_FLAGS_NEW },
-	{ "est", TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED },
-};
-
-static int flower_parse_ct_state(char *str, struct nlmsghdr *n)
-{
-	int flags = 0, mask = 0,  len, i;
-	bool p;
-
-	while (*str != '\0') {
-		if (*str == '+')
-			p = true;
-		else if (*str == '-')
-			p = false;
-		else
-			return -1;
-
-		for (i = 0; i < ARRAY_SIZE(flower_ct_states); i++) {
-			len = strlen(flower_ct_states[i].str);
-			if (strncmp(str + 1, flower_ct_states[i].str, len))
-				continue;
-
-			if (p)
-				flags |= flower_ct_states[i].flag;
-			mask |= flower_ct_states[i].flag;
-			break;
-		}
-
-		if (i == ARRAY_SIZE(flower_ct_states))
-			return -1;
-
-		str += len + 1;
-	}
-
-	addattr16(n, MAX_MSG, TCA_FLOWER_KEY_CT_STATE, flags);
-	addattr16(n, MAX_MSG, TCA_FLOWER_KEY_CT_STATE_MASK, mask);
 	return 0;
 }
 
@@ -378,23 +66,14 @@
 	int ret;
 	__u8 ip_proto;
 
-	if (eth_type != htons(ETH_P_IP) && eth_type != htons(ETH_P_IPV6))
-		goto err;
-
+	if (eth_type != htons(ETH_P_IP) && eth_type != htons(ETH_P_IPV6)) {
+		fprintf(stderr, "Illegal \"eth_type\" for ip proto\n");
+		return -1;
+	}
 	if (matches(str, "tcp") == 0) {
 		ip_proto = IPPROTO_TCP;
 	} else if (matches(str, "udp") == 0) {
 		ip_proto = IPPROTO_UDP;
-	} else if (matches(str, "sctp") == 0) {
-		ip_proto = IPPROTO_SCTP;
-	} else if (matches(str, "icmp") == 0) {
-		if (eth_type != htons(ETH_P_IP))
-			goto err;
-		ip_proto = IPPROTO_ICMP;
-	} else if (matches(str, "icmpv6") == 0) {
-		if (eth_type != htons(ETH_P_IPV6))
-			goto err;
-		ip_proto = IPPROTO_ICMPV6;
 	} else {
 		ret = get_u8(&ip_proto, str, 16);
 		if (ret)
@@ -403,30 +82,34 @@
 	addattr8(n, MAX_MSG, type, ip_proto);
 	*p_ip_proto = ip_proto;
 	return 0;
-
-err:
-	fprintf(stderr, "Illegal \"eth_type\" for ip proto\n");
-	return -1;
 }
 
-static int __flower_parse_ip_addr(char *str, int family,
-				  int addr4_type, int mask4_type,
-				  int addr6_type, int mask6_type,
-				  struct nlmsghdr *n)
+static int flower_parse_ip_addr(char *str, __be16 eth_type,
+				int addr4_type, int mask4_type,
+				int addr6_type, int mask6_type,
+				struct nlmsghdr *n)
 {
 	int ret;
 	inet_prefix addr;
+	int family;
 	int bits;
 	int i;
 
+	if (eth_type == htons(ETH_P_IP)) {
+		family = AF_INET;
+	} else if (eth_type == htons(ETH_P_IPV6)) {
+		family = AF_INET6;
+	} else {
+		fprintf(stderr, "Illegal \"eth_type\" for ip address\n");
+		return -1;
+	}
+
 	ret = get_prefix(&addr, str, family);
 	if (ret)
 		return -1;
 
-	if (family && (addr.family != family)) {
-		fprintf(stderr, "Illegal \"eth_type\" for ip address\n");
+	if (addr.family != family)
 		return -1;
-	}
 
 	addattr_l(n, MAX_MSG, addr.family == AF_INET ? addr4_type : addr6_type,
 		  addr.data, addr.bytelen);
@@ -451,530 +134,27 @@
 	return 0;
 }
 
-static int flower_parse_ip_addr(char *str, __be16 eth_type,
-				int addr4_type, int mask4_type,
-				int addr6_type, int mask6_type,
-				struct nlmsghdr *n)
-{
-	int family;
-
-	if (eth_type == htons(ETH_P_IP)) {
-		family = AF_INET;
-	} else if (eth_type == htons(ETH_P_IPV6)) {
-		family = AF_INET6;
-	} else if (!eth_type) {
-		family = AF_UNSPEC;
-	} else {
-		return -1;
-	}
-
-	return __flower_parse_ip_addr(str, family, addr4_type, mask4_type,
-				      addr6_type, mask6_type, n);
-}
-
-static bool flower_eth_type_arp(__be16 eth_type)
-{
-	return eth_type == htons(ETH_P_ARP) || eth_type == htons(ETH_P_RARP);
-}
-
-static int flower_parse_arp_ip_addr(char *str, __be16 eth_type,
-				    int addr_type, int mask_type,
-				    struct nlmsghdr *n)
-{
-	if (!flower_eth_type_arp(eth_type))
-		return -1;
-
-	return __flower_parse_ip_addr(str, AF_INET, addr_type, mask_type,
-				      TCA_FLOWER_UNSPEC, TCA_FLOWER_UNSPEC, n);
-}
-
-static int flower_parse_u8(char *str, int value_type, int mask_type,
-			   int (*value_from_name)(const char *str,
-						 __u8 *value),
-			   bool (*value_validate)(__u8 value),
-			   struct nlmsghdr *n)
-{
-	char *slash;
-	int ret, err = -1;
-	__u8 value, mask;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
-
-	ret = value_from_name ? value_from_name(str, &value) : -1;
-	if (ret < 0) {
-		ret = get_u8(&value, str, 10);
-		if (ret)
-			goto err;
-	}
-
-	if (value_validate && !value_validate(value))
-		goto err;
-
-	if (slash) {
-		ret = get_u8(&mask, slash + 1, 10);
-		if (ret)
-			goto err;
-	}
-	else {
-		mask = UINT8_MAX;
-	}
-
-	addattr8(n, MAX_MSG, value_type, value);
-	addattr8(n, MAX_MSG, mask_type, mask);
-
-	err = 0;
-err:
-	if (slash)
-		*slash = '/';
-	return err;
-}
-
-static const char *flower_print_arp_op_to_name(__u8 op)
-{
-	switch (op) {
-	case ARPOP_REQUEST:
-		return "request";
-	case ARPOP_REPLY:
-		return "reply";
-	default:
-		return NULL;
-	}
-}
-
-static int flower_arp_op_from_name(const char *name, __u8 *op)
-{
-	if (!strcmp(name, "request"))
-		*op = ARPOP_REQUEST;
-	else if (!strcmp(name, "reply"))
-		*op = ARPOP_REPLY;
-	else
-		return -1;
-
-	return 0;
-}
-
-static bool flow_arp_op_validate(__u8 op)
-{
-	return !op || op == ARPOP_REQUEST || op == ARPOP_REPLY;
-}
-
-static int flower_parse_arp_op(char *str, __be16 eth_type,
-			       int op_type, int mask_type,
-			       struct nlmsghdr *n)
-{
-	if (!flower_eth_type_arp(eth_type))
-		return -1;
-
-	return flower_parse_u8(str, op_type, mask_type, flower_arp_op_from_name,
-			       flow_arp_op_validate, n);
-}
-
-static int flower_icmp_attr_type(__be16 eth_type, __u8 ip_proto,
-				 enum flower_icmp_field field)
-{
-	if (eth_type == htons(ETH_P_IP) && ip_proto == IPPROTO_ICMP)
-		return field == FLOWER_ICMP_FIELD_CODE ?
-			TCA_FLOWER_KEY_ICMPV4_CODE :
-			TCA_FLOWER_KEY_ICMPV4_TYPE;
-	else if (eth_type == htons(ETH_P_IPV6) && ip_proto == IPPROTO_ICMPV6)
-		return field == FLOWER_ICMP_FIELD_CODE ?
-			TCA_FLOWER_KEY_ICMPV6_CODE :
-			TCA_FLOWER_KEY_ICMPV6_TYPE;
-
-	return -1;
-}
-
-static int flower_icmp_attr_mask_type(__be16 eth_type, __u8 ip_proto,
-				      enum flower_icmp_field field)
-{
-	if (eth_type == htons(ETH_P_IP) && ip_proto == IPPROTO_ICMP)
-		return field == FLOWER_ICMP_FIELD_CODE ?
-			TCA_FLOWER_KEY_ICMPV4_CODE_MASK :
-			TCA_FLOWER_KEY_ICMPV4_TYPE_MASK;
-	else if (eth_type == htons(ETH_P_IPV6) && ip_proto == IPPROTO_ICMPV6)
-		return field == FLOWER_ICMP_FIELD_CODE ?
-			TCA_FLOWER_KEY_ICMPV6_CODE_MASK :
-			TCA_FLOWER_KEY_ICMPV6_TYPE_MASK;
-
-	return -1;
-}
-
-static int flower_parse_icmp(char *str, __u16 eth_type, __u8 ip_proto,
-			     enum flower_icmp_field field, struct nlmsghdr *n)
-{
-	int value_type, mask_type;
-
-	value_type = flower_icmp_attr_type(eth_type, ip_proto, field);
-	mask_type = flower_icmp_attr_mask_type(eth_type, ip_proto, field);
-	if (value_type < 0 || mask_type < 0)
-		return -1;
-
-	return flower_parse_u8(str, value_type, mask_type, NULL, NULL, n);
-}
-
-static int flower_port_attr_type(__u8 ip_proto, enum flower_endpoint endpoint)
-{
-	if (ip_proto == IPPROTO_TCP)
-		return endpoint == FLOWER_ENDPOINT_SRC ?
-			TCA_FLOWER_KEY_TCP_SRC :
-			TCA_FLOWER_KEY_TCP_DST;
-	else if (ip_proto == IPPROTO_UDP)
-		return endpoint == FLOWER_ENDPOINT_SRC ?
-			TCA_FLOWER_KEY_UDP_SRC :
-			TCA_FLOWER_KEY_UDP_DST;
-	else if (ip_proto == IPPROTO_SCTP)
-		return endpoint == FLOWER_ENDPOINT_SRC ?
-			TCA_FLOWER_KEY_SCTP_SRC :
-			TCA_FLOWER_KEY_SCTP_DST;
-	else
-		return -1;
-}
-
-static int flower_port_range_attr_type(__u8 ip_proto, enum flower_endpoint type,
-				       __be16 *min_port_type,
-				       __be16 *max_port_type)
-{
-	if (ip_proto == IPPROTO_TCP || ip_proto == IPPROTO_UDP ||
-	    ip_proto == IPPROTO_SCTP) {
-		if (type == FLOWER_ENDPOINT_SRC) {
-			*min_port_type = TCA_FLOWER_KEY_PORT_SRC_MIN;
-			*max_port_type = TCA_FLOWER_KEY_PORT_SRC_MAX;
-		} else {
-			*min_port_type = TCA_FLOWER_KEY_PORT_DST_MIN;
-			*max_port_type = TCA_FLOWER_KEY_PORT_DST_MAX;
-		}
-	} else {
-		return -1;
-	}
-	return 0;
-}
-
-/* parse range args in format 10-20 */
-static int parse_range(char *str, __be16 *min, __be16 *max)
-{
-	char *sep;
-
-	sep = strchr(str, '-');
-	if (sep) {
-		*sep = '\0';
-
-		if (get_be16(min, str, 10))
-			return -1;
-
-		if (get_be16(max, sep + 1, 10))
-			return -1;
-	} else {
-		if (get_be16(min, str, 10))
-			return -1;
-	}
-	return 0;
-}
-
-static int flower_parse_port(char *str, __u8 ip_proto,
-			     enum flower_endpoint endpoint,
-			     struct nlmsghdr *n)
-{
-	__be16 min = 0;
-	__be16 max = 0;
-	int ret;
-
-	ret = parse_range(str, &min, &max);
-	if (ret)
-		return -1;
-
-	if (min && max) {
-		__be16 min_port_type, max_port_type;
-
-		if (max <= min) {
-			fprintf(stderr, "max value should be greater than min value\n");
-			return -1;
-		}
-		if (flower_port_range_attr_type(ip_proto, endpoint,
-						&min_port_type, &max_port_type))
-			return -1;
-
-		addattr16(n, MAX_MSG, min_port_type, min);
-		addattr16(n, MAX_MSG, max_port_type, max);
-	} else if (min && !max) {
-		int type;
-
-		type = flower_port_attr_type(ip_proto, endpoint);
-		if (type < 0)
-			return -1;
-		addattr16(n, MAX_MSG, type, min);
-	} else {
-		return -1;
-	}
-	return 0;
-}
-
-#define TCP_FLAGS_MAX_MASK 0xfff
-
-static int flower_parse_tcp_flags(char *str, int flags_type, int mask_type,
-				  struct nlmsghdr *n)
-{
-	char *slash;
-	int ret, err = -1;
-	__u16 flags;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
-
-	ret = get_u16(&flags, str, 16);
-	if (ret < 0 || flags & ~TCP_FLAGS_MAX_MASK)
-		goto err;
-
-	addattr16(n, MAX_MSG, flags_type, htons(flags));
-
-	if (slash) {
-		ret = get_u16(&flags, slash + 1, 16);
-		if (ret < 0 || flags & ~TCP_FLAGS_MAX_MASK)
-			goto err;
-	} else {
-		flags = TCP_FLAGS_MAX_MASK;
-	}
-	addattr16(n, MAX_MSG, mask_type, htons(flags));
-
-	err = 0;
-err:
-	if (slash)
-		*slash = '/';
-	return err;
-}
-
-static int flower_parse_ip_tos_ttl(char *str, int key_type, int mask_type,
-				   struct nlmsghdr *n)
-{
-	char *slash;
-	int ret, err = -1;
-	__u8 tos_ttl;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
-
-	ret = get_u8(&tos_ttl, str, 10);
-	if (ret < 0)
-		ret = get_u8(&tos_ttl, str, 16);
-	if (ret < 0)
-		goto err;
-
-	addattr8(n, MAX_MSG, key_type, tos_ttl);
-
-	if (slash) {
-		ret = get_u8(&tos_ttl, slash + 1, 16);
-		if (ret < 0)
-			goto err;
-	} else {
-		tos_ttl = 0xff;
-	}
-	addattr8(n, MAX_MSG, mask_type, tos_ttl);
-
-	err = 0;
-err:
-	if (slash)
-		*slash = '/';
-	return err;
-}
-
-static int flower_parse_key_id(const char *str, int type, struct nlmsghdr *n)
+static int flower_parse_port(char *str, __u8 ip_port,
+			     int tcp_type, int udp_type, struct nlmsghdr *n)
 {
 	int ret;
-	__be32 key_id;
-
-	ret = get_be32(&key_id, str, 10);
-	if (!ret)
-		addattr32(n, MAX_MSG, type, key_id);
-
-	return ret;
-}
-
-static int flower_parse_enc_port(char *str, int type, struct nlmsghdr *n)
-{
-	int ret;
+	int type;
 	__be16 port;
 
-	ret = get_be16(&port, str, 10);
+	if (ip_port == IPPROTO_TCP) {
+		type = tcp_type;
+	} else if (ip_port == IPPROTO_UDP) {
+		type = udp_type;
+	} else {
+		fprintf(stderr, "Illegal \"ip_proto\" for port\n");
+		return -1;
+	}
+
+	ret = get_u16(&port, str, 10);
 	if (ret)
 		return -1;
 
-	addattr16(n, MAX_MSG, type, port);
-
-	return 0;
-}
-
-static int flower_parse_geneve_opts(char *str, struct nlmsghdr *n)
-{
-	struct rtattr *nest;
-	char *token;
-	int i, err;
-
-	nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS_GENEVE);
-
-	i = 1;
-	token = strsep(&str, ":");
-	while (token) {
-		switch (i) {
-		case TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS:
-		{
-			__be16 opt_class;
-
-			if (!strlen(token))
-				break;
-			err = get_be16(&opt_class, token, 16);
-			if (err)
-				return err;
-
-			addattr16(n, MAX_MSG, i, opt_class);
-			break;
-		}
-		case TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE:
-		{
-			__u8 opt_type;
-
-			if (!strlen(token))
-				break;
-			err = get_u8(&opt_type, token, 16);
-			if (err)
-				return err;
-
-			addattr8(n, MAX_MSG, i, opt_type);
-			break;
-		}
-		case TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA:
-		{
-			size_t token_len = strlen(token);
-			__u8 *opts;
-
-			if (!token_len)
-				break;
-			opts = malloc(token_len / 2);
-			if (!opts)
-				return -1;
-			if (hex2mem(token, opts, token_len / 2) < 0) {
-				free(opts);
-				return -1;
-			}
-			addattr_l(n, MAX_MSG, i, opts, token_len / 2);
-			free(opts);
-
-			break;
-		}
-		default:
-			fprintf(stderr, "Unknown \"geneve_opts\" type\n");
-			return -1;
-		}
-
-		token = strsep(&str, ":");
-		i++;
-	}
-	addattr_nest_end(n, nest);
-
-	return 0;
-}
-
-static int flower_parse_enc_opt_part(char *str, struct nlmsghdr *n)
-{
-	char *token;
-	int err;
-
-	token = strsep(&str, ",");
-	while (token) {
-		err = flower_parse_geneve_opts(token, n);
-		if (err)
-			return err;
-
-		token = strsep(&str, ",");
-	}
-
-	return 0;
-}
-
-static int flower_check_enc_opt_key(char *key)
-{
-	int key_len, col_cnt = 0;
-
-	key_len = strlen(key);
-	while ((key = strchr(key, ':'))) {
-		if (strlen(key) == key_len)
-			return -1;
-
-		key_len = strlen(key) - 1;
-		col_cnt++;
-		key++;
-	}
-
-	if (col_cnt != 2 || !key_len)
-		return -1;
-
-	return 0;
-}
-
-static int flower_parse_enc_opts(char *str, struct nlmsghdr *n)
-{
-	char key[XATTR_SIZE_MAX], mask[XATTR_SIZE_MAX];
-	int data_len, key_len, mask_len, err;
-	char *token, *slash;
-	struct rtattr *nest;
-
-	key_len = 0;
-	mask_len = 0;
-	token = strsep(&str, ",");
-	while (token) {
-		slash = strchr(token, '/');
-		if (slash)
-			*slash = '\0';
-
-		if ((key_len + strlen(token) > XATTR_SIZE_MAX) ||
-		    flower_check_enc_opt_key(token))
-			return -1;
-
-		strcpy(&key[key_len], token);
-		key_len += strlen(token) + 1;
-		key[key_len - 1] = ',';
-
-		if (!slash) {
-			/* Pad out mask when not provided */
-			if (mask_len + strlen(token) > XATTR_SIZE_MAX)
-				return -1;
-
-			data_len = strlen(rindex(token, ':'));
-			sprintf(&mask[mask_len], "ffff:ff:");
-			mask_len += 8;
-			memset(&mask[mask_len], 'f', data_len - 1);
-			mask_len += data_len;
-			mask[mask_len - 1] = ',';
-			token = strsep(&str, ",");
-			continue;
-		}
-
-		if (mask_len + strlen(slash + 1) > XATTR_SIZE_MAX)
-			return -1;
-
-		strcpy(&mask[mask_len], slash + 1);
-		mask_len += strlen(slash + 1) + 1;
-		mask[mask_len - 1] = ',';
-
-		*slash = '/';
-		token = strsep(&str, ",");
-	}
-	key[key_len - 1] = '\0';
-	mask[mask_len - 1] = '\0';
-
-	nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS);
-	err = flower_parse_enc_opt_part(key, n);
-	if (err)
-		return err;
-	addattr_nest_end(n, nest);
-
-	nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS_MASK);
-	err = flower_parse_enc_opt_part(mask, n);
-	if (err)
-		return err;
-	addattr_nest_end(n, nest);
+	addattr16(n, MAX_MSG, type, htons(port));
 
 	return 0;
 }
@@ -986,12 +166,7 @@
 	struct tcmsg *t = NLMSG_DATA(n);
 	struct rtattr *tail;
 	__be16 eth_type = TC_H_MIN(t->tcm_info);
-	__be16 vlan_ethtype = 0;
-	__be16 cvlan_ethtype = 0;
 	__u8 ip_proto = 0xff;
-	__u32 flags = 0;
-	__u32 mtf = 0;
-	__u32 mtf_mask = 0;
 
 	if (handle) {
 		ret = get_u32(&t->tcm_handle, handle, 0);
@@ -1012,7 +187,7 @@
 	while (argc > 0) {
 		if (matches(*argv, "classid") == 0 ||
 		    matches(*argv, "flowid") == 0) {
-			unsigned int handle;
+			unsigned handle;
 
 			NEXT_ARG();
 			ret = get_tc_classid(&handle, *argv);
@@ -1021,210 +196,13 @@
 				return -1;
 			}
 			addattr_l(n, MAX_MSG, TCA_FLOWER_CLASSID, &handle, 4);
-		} else if (matches(*argv, "hw_tc") == 0) {
-			unsigned int handle;
-			__u32 tc;
-			char *end;
-
-			NEXT_ARG();
-			tc = strtoul(*argv, &end, 0);
-			if (*end) {
-				fprintf(stderr, "Illegal TC index\n");
-				return -1;
-			}
-			if (tc >= TC_QOPT_MAX_QUEUE) {
-				fprintf(stderr, "TC index exceeds max range\n");
-				return -1;
-			}
-			handle = TC_H_MAKE(TC_H_MAJ(t->tcm_parent),
-					   TC_H_MIN(tc + TC_H_MIN_PRIORITY));
-			addattr_l(n, MAX_MSG, TCA_FLOWER_CLASSID, &handle,
-				  sizeof(handle));
-		} else if (matches(*argv, "ip_flags") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_matching_flags(*argv,
-							  FLOWER_IP_FLAGS,
-							  &mtf,
-							  &mtf_mask);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ip_flags\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "verbose") == 0) {
-			flags |= TCA_CLS_FLAGS_VERBOSE;
-		} else if (matches(*argv, "skip_hw") == 0) {
-			flags |= TCA_CLS_FLAGS_SKIP_HW;
-		} else if (matches(*argv, "skip_sw") == 0) {
-			flags |= TCA_CLS_FLAGS_SKIP_SW;
-		} else if (matches(*argv, "ct_state") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ct_state(*argv, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ct_state\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "ct_zone") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ct_zone(*argv, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ct_zone\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "ct_mark") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ct_mark(*argv, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ct_mark\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "ct_label") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ct_labels(*argv, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ct_label\"\n");
-				return -1;
-			}
 		} else if (matches(*argv, "indev") == 0) {
-			NEXT_ARG();
-			if (check_ifname(*argv))
-				invarg("\"indev\" not a valid ifname", *argv);
-			addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, *argv);
-		} else if (matches(*argv, "vlan_id") == 0) {
-			__u16 vid;
+			char ifname[IFNAMSIZ];
 
 			NEXT_ARG();
-			if (!eth_type_vlan(eth_type)) {
-				fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD\n");
-				return -1;
-			}
-			ret = get_u16(&vid, *argv, 10);
-			if (ret < 0 || vid & ~0xfff) {
-				fprintf(stderr, "Illegal \"vlan_id\"\n");
-				return -1;
-			}
-			addattr16(n, MAX_MSG, TCA_FLOWER_KEY_VLAN_ID, vid);
-		} else if (matches(*argv, "vlan_prio") == 0) {
-			__u8 vlan_prio;
-
-			NEXT_ARG();
-			if (!eth_type_vlan(eth_type)) {
-				fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD\n");
-				return -1;
-			}
-			ret = get_u8(&vlan_prio, *argv, 10);
-			if (ret < 0 || vlan_prio & ~0x7) {
-				fprintf(stderr, "Illegal \"vlan_prio\"\n");
-				return -1;
-			}
-			addattr8(n, MAX_MSG,
-				 TCA_FLOWER_KEY_VLAN_PRIO, vlan_prio);
-		} else if (matches(*argv, "vlan_ethtype") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_vlan_eth_type(*argv, eth_type,
-						 TCA_FLOWER_KEY_VLAN_ETH_TYPE,
-						 &vlan_ethtype, n);
-			if (ret < 0)
-				return -1;
-		} else if (matches(*argv, "cvlan_id") == 0) {
-			__u16 vid;
-
-			NEXT_ARG();
-			if (!eth_type_vlan(vlan_ethtype)) {
-				fprintf(stderr, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n");
-				return -1;
-			}
-			ret = get_u16(&vid, *argv, 10);
-			if (ret < 0 || vid & ~0xfff) {
-				fprintf(stderr, "Illegal \"cvlan_id\"\n");
-				return -1;
-			}
-			addattr16(n, MAX_MSG, TCA_FLOWER_KEY_CVLAN_ID, vid);
-		} else if (matches(*argv, "cvlan_prio") == 0) {
-			__u8 cvlan_prio;
-
-			NEXT_ARG();
-			if (!eth_type_vlan(vlan_ethtype)) {
-				fprintf(stderr, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n");
-				return -1;
-			}
-			ret = get_u8(&cvlan_prio, *argv, 10);
-			if (ret < 0 || cvlan_prio & ~0x7) {
-				fprintf(stderr, "Illegal \"cvlan_prio\"\n");
-				return -1;
-			}
-			addattr8(n, MAX_MSG,
-				 TCA_FLOWER_KEY_CVLAN_PRIO, cvlan_prio);
-		} else if (matches(*argv, "cvlan_ethtype") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_vlan_eth_type(*argv, vlan_ethtype,
-						 TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
-						 &cvlan_ethtype, n);
-			if (ret < 0)
-				return -1;
-		} else if (matches(*argv, "mpls_label") == 0) {
-			__u32 label;
-
-			NEXT_ARG();
-			if (eth_type != htons(ETH_P_MPLS_UC) &&
-			    eth_type != htons(ETH_P_MPLS_MC)) {
-				fprintf(stderr,
-					"Can't set \"mpls_label\" if ethertype isn't MPLS\n");
-				return -1;
-			}
-			ret = get_u32(&label, *argv, 10);
-			if (ret < 0 || label & ~(MPLS_LS_LABEL_MASK >> MPLS_LS_LABEL_SHIFT)) {
-				fprintf(stderr, "Illegal \"mpls_label\"\n");
-				return -1;
-			}
-			addattr32(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_LABEL, label);
-		} else if (matches(*argv, "mpls_tc") == 0) {
-			__u8 tc;
-
-			NEXT_ARG();
-			if (eth_type != htons(ETH_P_MPLS_UC) &&
-			    eth_type != htons(ETH_P_MPLS_MC)) {
-				fprintf(stderr,
-					"Can't set \"mpls_tc\" if ethertype isn't MPLS\n");
-				return -1;
-			}
-			ret = get_u8(&tc, *argv, 10);
-			if (ret < 0 || tc & ~(MPLS_LS_TC_MASK >> MPLS_LS_TC_SHIFT)) {
-				fprintf(stderr, "Illegal \"mpls_tc\"\n");
-				return -1;
-			}
-			addattr8(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_TC, tc);
-		} else if (matches(*argv, "mpls_bos") == 0) {
-			__u8 bos;
-
-			NEXT_ARG();
-			if (eth_type != htons(ETH_P_MPLS_UC) &&
-			    eth_type != htons(ETH_P_MPLS_MC)) {
-				fprintf(stderr,
-					"Can't set \"mpls_bos\" if ethertype isn't MPLS\n");
-				return -1;
-			}
-			ret = get_u8(&bos, *argv, 10);
-			if (ret < 0 || bos & ~(MPLS_LS_S_MASK >> MPLS_LS_S_SHIFT)) {
-				fprintf(stderr, "Illegal \"mpls_bos\"\n");
-				return -1;
-			}
-			addattr8(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_BOS, bos);
-		} else if (matches(*argv, "mpls_ttl") == 0) {
-			__u8 ttl;
-
-			NEXT_ARG();
-			if (eth_type != htons(ETH_P_MPLS_UC) &&
-			    eth_type != htons(ETH_P_MPLS_MC)) {
-				fprintf(stderr,
-					"Can't set \"mpls_ttl\" if ethertype isn't MPLS\n");
-				return -1;
-			}
-			ret = get_u8(&ttl, *argv, 10);
-			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
-				fprintf(stderr, "Illegal \"mpls_ttl\"\n");
-				return -1;
-			}
-			addattr8(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_TTL, ttl);
+			memset(ifname, 0, sizeof(ifname));
+			strncpy(ifname, *argv, sizeof(ifname) - 1);
+			addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, ifname);
 		} else if (matches(*argv, "dst_mac") == 0) {
 			NEXT_ARG();
 			ret = flower_parse_eth_addr(*argv,
@@ -1247,40 +225,16 @@
 			}
 		} else if (matches(*argv, "ip_proto") == 0) {
 			NEXT_ARG();
-			ret = flower_parse_ip_proto(*argv, cvlan_ethtype ?
-						    cvlan_ethtype : vlan_ethtype ?
-						    vlan_ethtype : eth_type,
+			ret = flower_parse_ip_proto(*argv, eth_type,
 						    TCA_FLOWER_KEY_IP_PROTO,
 						    &ip_proto, n);
 			if (ret < 0) {
 				fprintf(stderr, "Illegal \"ip_proto\"\n");
 				return -1;
 			}
-		} else if (matches(*argv, "ip_tos") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ip_tos_ttl(*argv,
-						      TCA_FLOWER_KEY_IP_TOS,
-						      TCA_FLOWER_KEY_IP_TOS_MASK,
-						      n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ip_tos\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "ip_ttl") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ip_tos_ttl(*argv,
-						      TCA_FLOWER_KEY_IP_TTL,
-						      TCA_FLOWER_KEY_IP_TTL_MASK,
-						      n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ip_ttl\"\n");
-				return -1;
-			}
 		} else if (matches(*argv, "dst_ip") == 0) {
 			NEXT_ARG();
-			ret = flower_parse_ip_addr(*argv, cvlan_ethtype ?
-						   cvlan_ethtype : vlan_ethtype ?
-						   vlan_ethtype : eth_type,
+			ret = flower_parse_ip_addr(*argv, eth_type,
 						   TCA_FLOWER_KEY_IPV4_DST,
 						   TCA_FLOWER_KEY_IPV4_DST_MASK,
 						   TCA_FLOWER_KEY_IPV6_DST,
@@ -1292,9 +246,7 @@
 			}
 		} else if (matches(*argv, "src_ip") == 0) {
 			NEXT_ARG();
-			ret = flower_parse_ip_addr(*argv, cvlan_ethtype ?
-						   cvlan_ethtype : vlan_ethtype ?
-						   vlan_ethtype : eth_type,
+			ret = flower_parse_ip_addr(*argv, eth_type,
 						   TCA_FLOWER_KEY_IPV4_SRC,
 						   TCA_FLOWER_KEY_IPV4_SRC_MASK,
 						   TCA_FLOWER_KEY_IPV6_SRC,
@@ -1307,7 +259,8 @@
 		} else if (matches(*argv, "dst_port") == 0) {
 			NEXT_ARG();
 			ret = flower_parse_port(*argv, ip_proto,
-						FLOWER_ENDPOINT_DST, n);
+						TCA_FLOWER_KEY_TCP_DST,
+						TCA_FLOWER_KEY_UDP_DST, n);
 			if (ret < 0) {
 				fprintf(stderr, "Illegal \"dst_port\"\n");
 				return -1;
@@ -1315,157 +268,12 @@
 		} else if (matches(*argv, "src_port") == 0) {
 			NEXT_ARG();
 			ret = flower_parse_port(*argv, ip_proto,
-						FLOWER_ENDPOINT_SRC, n);
+						TCA_FLOWER_KEY_TCP_SRC,
+						TCA_FLOWER_KEY_UDP_SRC, n);
 			if (ret < 0) {
 				fprintf(stderr, "Illegal \"src_port\"\n");
 				return -1;
 			}
-		} else if (matches(*argv, "tcp_flags") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_tcp_flags(*argv,
-						     TCA_FLOWER_KEY_TCP_FLAGS,
-						     TCA_FLOWER_KEY_TCP_FLAGS_MASK,
-						     n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"tcp_flags\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "type") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_icmp(*argv, eth_type, ip_proto,
-						FLOWER_ICMP_FIELD_TYPE, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"icmp type\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "code") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_icmp(*argv, eth_type, ip_proto,
-						FLOWER_ICMP_FIELD_CODE, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"icmp code\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "arp_tip") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_arp_ip_addr(*argv, vlan_ethtype ?
-						       vlan_ethtype : eth_type,
-						       TCA_FLOWER_KEY_ARP_TIP,
-						       TCA_FLOWER_KEY_ARP_TIP_MASK,
-						       n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"arp_tip\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "arp_sip") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_arp_ip_addr(*argv, vlan_ethtype ?
-						       vlan_ethtype : eth_type,
-						       TCA_FLOWER_KEY_ARP_SIP,
-						       TCA_FLOWER_KEY_ARP_SIP_MASK,
-						       n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"arp_sip\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "arp_op") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_arp_op(*argv, vlan_ethtype ?
-						  vlan_ethtype : eth_type,
-						  TCA_FLOWER_KEY_ARP_OP,
-						  TCA_FLOWER_KEY_ARP_OP_MASK,
-						  n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"arp_op\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "arp_tha") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_eth_addr(*argv,
-						    TCA_FLOWER_KEY_ARP_THA,
-						    TCA_FLOWER_KEY_ARP_THA_MASK,
-						    n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"arp_tha\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "arp_sha") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_eth_addr(*argv,
-						    TCA_FLOWER_KEY_ARP_SHA,
-						    TCA_FLOWER_KEY_ARP_SHA_MASK,
-						    n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"arp_sha\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "enc_dst_ip") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ip_addr(*argv, 0,
-						   TCA_FLOWER_KEY_ENC_IPV4_DST,
-						   TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,
-						   TCA_FLOWER_KEY_ENC_IPV6_DST,
-						   TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,
-						   n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"enc_dst_ip\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "enc_src_ip") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ip_addr(*argv, 0,
-						   TCA_FLOWER_KEY_ENC_IPV4_SRC,
-						   TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,
-						   TCA_FLOWER_KEY_ENC_IPV6_SRC,
-						   TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,
-						   n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"enc_src_ip\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "enc_key_id") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_key_id(*argv,
-						  TCA_FLOWER_KEY_ENC_KEY_ID, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"enc_key_id\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "enc_dst_port") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_enc_port(*argv,
-						    TCA_FLOWER_KEY_ENC_UDP_DST_PORT, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"enc_dst_port\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "enc_tos") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ip_tos_ttl(*argv,
-						      TCA_FLOWER_KEY_ENC_IP_TOS,
-						      TCA_FLOWER_KEY_ENC_IP_TOS_MASK,
-						      n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"enc_tos\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "enc_ttl") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_ip_tos_ttl(*argv,
-						      TCA_FLOWER_KEY_ENC_IP_TTL,
-						      TCA_FLOWER_KEY_ENC_IP_TTL_MASK,
-						      n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"enc_ttl\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "geneve_opts") == 0) {
-			NEXT_ARG();
-			ret = flower_parse_enc_opts(*argv, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"geneve_opts\"\n");
-				return -1;
-			}
 		} else if (matches(*argv, "action") == 0) {
 			NEXT_ARG();
 			ret = parse_action(&argc, &argv, TCA_FLOWER_ACT, n);
@@ -1486,27 +294,14 @@
 	}
 
 parse_done:
-	ret = addattr32(n, MAX_MSG, TCA_FLOWER_FLAGS, flags);
-	if (ret)
-		return ret;
-
-	if (mtf_mask) {
-		ret = addattr32(n, MAX_MSG, TCA_FLOWER_KEY_FLAGS, htonl(mtf));
-		if (ret)
-			return ret;
-
-		ret = addattr32(n, MAX_MSG, TCA_FLOWER_KEY_FLAGS_MASK, htonl(mtf_mask));
-		if (ret)
-			return ret;
+	ret = addattr16(n, MAX_MSG, TCA_FLOWER_KEY_ETH_TYPE, eth_type);
+	if (ret) {
+		fprintf(stderr, "Illegal \"eth_type\"(0x%x)\n",
+			ntohs(eth_type));
+		return -1;
 	}
 
-	if (eth_type != htons(ETH_P_ALL)) {
-		ret = addattr16(n, MAX_MSG, TCA_FLOWER_KEY_ETH_TYPE, eth_type);
-		if (ret)
-			return ret;
-	}
-
-	tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
+	tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
 
 	return 0;
 }
@@ -1534,144 +329,74 @@
 	return bits;
 }
 
-static void flower_print_eth_addr(char *name, struct rtattr *addr_attr,
+static void flower_print_eth_addr(FILE *f, char *name,
+				  struct rtattr *addr_attr,
 				  struct rtattr *mask_attr)
 {
-	SPRINT_BUF(namefrm);
-	SPRINT_BUF(out);
 	SPRINT_BUF(b1);
-	size_t done;
 	int bits;
 
 	if (!addr_attr || RTA_PAYLOAD(addr_attr) != ETH_ALEN)
 		return;
-	done = sprintf(out, "%s",
-		       ll_addr_n2a(RTA_DATA(addr_attr), ETH_ALEN,
-				   0, b1, sizeof(b1)));
-	if (mask_attr && RTA_PAYLOAD(mask_attr) == ETH_ALEN) {
-		bits = __mask_bits(RTA_DATA(mask_attr), ETH_ALEN);
-		if (bits < 0)
-			sprintf(out + done, "/%s",
-				ll_addr_n2a(RTA_DATA(mask_attr), ETH_ALEN,
-					    0, b1, sizeof(b1)));
-		else if (bits < ETH_ALEN * 8)
-			sprintf(out + done, "/%d", bits);
-	}
-
-	sprintf(namefrm, "\n  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
+	fprintf(f, "\n  %s %s", name, ll_addr_n2a(RTA_DATA(addr_attr), ETH_ALEN,
+						  0, b1, sizeof(b1)));
+	if (!mask_attr || RTA_PAYLOAD(mask_attr) != ETH_ALEN)
+		return;
+	bits = __mask_bits(RTA_DATA(mask_attr), ETH_ALEN);
+	if (bits < 0)
+		fprintf(f, "/%s", ll_addr_n2a(RTA_DATA(mask_attr), ETH_ALEN,
+					      0, b1, sizeof(b1)));
+	else if (bits < ETH_ALEN * 8)
+		fprintf(f, "/%d", bits);
 }
 
-static void flower_print_eth_type(__be16 *p_eth_type,
+static void flower_print_eth_type(FILE *f, __be16 *p_eth_type,
 				  struct rtattr *eth_type_attr)
 {
-	SPRINT_BUF(out);
 	__be16 eth_type;
 
 	if (!eth_type_attr)
 		return;
 
 	eth_type = rta_getattr_u16(eth_type_attr);
+	fprintf(f, "\n  eth_type ");
 	if (eth_type == htons(ETH_P_IP))
-		sprintf(out, "ipv4");
+		fprintf(f, "ipv4");
 	else if (eth_type == htons(ETH_P_IPV6))
-		sprintf(out, "ipv6");
-	else if (eth_type == htons(ETH_P_ARP))
-		sprintf(out, "arp");
-	else if (eth_type == htons(ETH_P_RARP))
-		sprintf(out, "rarp");
+		fprintf(f, "ipv6");
 	else
-		sprintf(out, "%04x", ntohs(eth_type));
-
-	print_string(PRINT_ANY, "eth_type", "\n  eth_type %s", out);
+		fprintf(f, "%04x", ntohs(eth_type));
 	*p_eth_type = eth_type;
 }
 
-static void flower_print_ip_proto(__u8 *p_ip_proto,
+static void flower_print_ip_proto(FILE *f, __u8 *p_ip_proto,
 				  struct rtattr *ip_proto_attr)
 {
-	SPRINT_BUF(out);
 	__u8 ip_proto;
 
 	if (!ip_proto_attr)
 		return;
 
 	ip_proto = rta_getattr_u8(ip_proto_attr);
+	fprintf(f, "\n  ip_proto ");
 	if (ip_proto == IPPROTO_TCP)
-		sprintf(out, "tcp");
+		fprintf(f, "tcp");
 	else if (ip_proto == IPPROTO_UDP)
-		sprintf(out, "udp");
-	else if (ip_proto == IPPROTO_SCTP)
-		sprintf(out, "sctp");
-	else if (ip_proto == IPPROTO_ICMP)
-		sprintf(out, "icmp");
-	else if (ip_proto == IPPROTO_ICMPV6)
-		sprintf(out, "icmpv6");
+		fprintf(f, "udp");
 	else
-		sprintf(out, "%02x", ip_proto);
-
-	print_string(PRINT_ANY, "ip_proto", "\n  ip_proto %s", out);
+		fprintf(f, "%02x", ip_proto);
 	*p_ip_proto = ip_proto;
 }
 
-static void flower_print_ip_attr(const char *name, struct rtattr *key_attr,
-				 struct rtattr *mask_attr)
-{
-	print_masked_u8(name, key_attr, mask_attr, true);
-}
-
-static void flower_print_matching_flags(char *name,
-					enum flower_matching_flags type,
-					struct rtattr *attr,
-					struct rtattr *mask_attr)
-{
-	int i;
-	int count = 0;
-	__u32 mtf;
-	__u32 mtf_mask;
-
-	if (!mask_attr || RTA_PAYLOAD(mask_attr) != 4)
-		return;
-
-	mtf = ntohl(rta_getattr_u32(attr));
-	mtf_mask = ntohl(rta_getattr_u32(mask_attr));
-
-	for (i = 0; i < ARRAY_SIZE(flags_str); i++) {
-		if (type != flags_str[i].type)
-			continue;
-		if (mtf_mask & flags_str[i].flag) {
-			if (++count == 1) {
-				print_string(PRINT_FP, NULL, "\n  %s ", name);
-				open_json_object(name);
-			} else {
-				print_string(PRINT_FP, NULL, "/", NULL);
-			}
-
-			print_bool(PRINT_JSON, flags_str[i].string, NULL,
-				   mtf & flags_str[i].flag);
-			if (mtf & flags_str[i].flag)
-				print_string(PRINT_FP, NULL, "%s",
-					     flags_str[i].string);
-			else
-				print_string(PRINT_FP, NULL, "no%s",
-					     flags_str[i].string);
-		}
-	}
-	if (count)
-		close_json_object();
-}
-
-static void flower_print_ip_addr(char *name, __be16 eth_type,
+static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
 				 struct rtattr *addr4_attr,
 				 struct rtattr *mask4_attr,
 				 struct rtattr *addr6_attr,
 				 struct rtattr *mask6_attr)
 {
+	SPRINT_BUF(b1);
 	struct rtattr *addr_attr;
 	struct rtattr *mask_attr;
-	SPRINT_BUF(namefrm);
-	SPRINT_BUF(out);
-	size_t done;
 	int family;
 	size_t len;
 	int bits;
@@ -1691,328 +416,43 @@
 	}
 	if (!addr_attr || RTA_PAYLOAD(addr_attr) != len)
 		return;
+	fprintf(f, "\n  %s %s", name, rt_addr_n2a(family,
+						  RTA_PAYLOAD(addr_attr),
+						  RTA_DATA(addr_attr),
+						  b1, sizeof(b1)));
 	if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
 		return;
-	done = sprintf(out, "%s", rt_addr_n2a_rta(family, addr_attr));
 	bits = __mask_bits(RTA_DATA(mask_attr), len);
 	if (bits < 0)
-		sprintf(out + done, "/%s", rt_addr_n2a_rta(family, mask_attr));
+		fprintf(f, "/%s", rt_addr_n2a(family,
+					      RTA_PAYLOAD(mask_attr),
+					      RTA_DATA(mask_attr),
+					      b1, sizeof(b1)));
 	else if (bits < len * 8)
-		sprintf(out + done, "/%d", bits);
-
-	sprintf(namefrm, "\n  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
-}
-static void flower_print_ip4_addr(char *name, struct rtattr *addr_attr,
-				  struct rtattr *mask_attr)
-{
-	return flower_print_ip_addr(name, htons(ETH_P_IP),
-				    addr_attr, mask_attr, 0, 0);
+		fprintf(f, "/%d", bits);
 }
 
-static void flower_print_port(char *name, struct rtattr *attr)
+static void flower_print_port(FILE *f, char *name, __u8 ip_proto,
+			      struct rtattr *tcp_attr,
+			      struct rtattr *udp_attr)
 {
-	SPRINT_BUF(namefrm);
+	struct rtattr *attr;
 
-	if (!attr)
-		return;
-
-	sprintf(namefrm,"\n  %s %%u", name);
-	print_hu(PRINT_ANY, name, namefrm, rta_getattr_be16(attr));
-}
-
-static void flower_print_port_range(char *name, struct rtattr *min_attr,
-				    struct rtattr *max_attr)
-{
-	if (!min_attr || !max_attr)
-		return;
-
-	if (is_json_context()) {
-		open_json_object(name);
-		print_hu(PRINT_JSON, "start", NULL, rta_getattr_be16(min_attr));
-		print_hu(PRINT_JSON, "end", NULL, rta_getattr_be16(max_attr));
-		close_json_object();
-	} else {
-		SPRINT_BUF(namefrm);
-		SPRINT_BUF(out);
-		size_t done;
-
-		done = sprintf(out, "%u", rta_getattr_be16(min_attr));
-		sprintf(out + done, "-%u", rta_getattr_be16(max_attr));
-		sprintf(namefrm, "\n  %s %%s", name);
-		print_string(PRINT_ANY, name, namefrm, out);
-	}
-}
-
-static void flower_print_tcp_flags(const char *name, struct rtattr *flags_attr,
-				   struct rtattr *mask_attr)
-{
-	SPRINT_BUF(namefrm);
-	SPRINT_BUF(out);
-	size_t done;
-
-	if (!flags_attr)
-		return;
-
-	done = sprintf(out, "0x%x", rta_getattr_be16(flags_attr));
-	if (mask_attr)
-		sprintf(out + done, "/%x", rta_getattr_be16(mask_attr));
-
-	print_string(PRINT_FP, NULL, "%s  ", _SL_);
-	sprintf(namefrm, "%s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
-}
-
-static void flower_print_ct_state(struct rtattr *flags_attr,
-				  struct rtattr *mask_attr)
-{
-	SPRINT_BUF(out);
-	uint16_t state;
-	uint16_t state_mask;
-	size_t done = 0;
-	int i;
-
-	if (!flags_attr)
-		return;
-
-	state = rta_getattr_u16(flags_attr);
-	if (mask_attr)
-		state_mask = rta_getattr_u16(mask_attr);
+	if (ip_proto == IPPROTO_TCP)
+		attr = tcp_attr;
+	else if (ip_proto == IPPROTO_UDP)
+		attr = udp_attr;
 	else
-		state_mask = UINT16_MAX;
-
-	for (i = 0; i < ARRAY_SIZE(flower_ct_states); i++) {
-		if (!(state_mask & flower_ct_states[i].flag))
-			continue;
-
-		if (state & flower_ct_states[i].flag)
-			done += sprintf(out + done, "+%s",
-					flower_ct_states[i].str);
-		else
-			done += sprintf(out + done, "-%s",
-					flower_ct_states[i].str);
-	}
-
-	print_string(PRINT_ANY, "ct_state", "\n  ct_state %s", out);
-}
-
-static void flower_print_ct_label(struct rtattr *attr,
-				  struct rtattr *mask_attr)
-{
-	const unsigned char *str;
-	bool print_mask = false;
-	int data_len, i;
-	SPRINT_BUF(out);
-	char *p;
-
+		return;
 	if (!attr)
 		return;
-
-	data_len = RTA_PAYLOAD(attr);
-	hexstring_n2a(RTA_DATA(attr), data_len, out, sizeof(out));
-	p = out + data_len*2;
-
-	data_len = RTA_PAYLOAD(attr);
-	str = RTA_DATA(mask_attr);
-	if (data_len != 16)
-		print_mask = true;
-	for (i = 0; !print_mask && i < data_len; i++) {
-		if (str[i] != 0xff)
-			print_mask = true;
-	}
-	if (print_mask) {
-		*p++ = '/';
-		hexstring_n2a(RTA_DATA(mask_attr), data_len, p,
-			      sizeof(out)-(p-out));
-		p += data_len*2;
-	}
-	*p = '\0';
-
-	print_string(PRINT_ANY, "ct_label", "\n  ct_label %s", out);
-}
-
-static void flower_print_ct_zone(struct rtattr *attr,
-				 struct rtattr *mask_attr)
-{
-	print_masked_u16("ct_zone", attr, mask_attr, true);
-}
-
-static void flower_print_ct_mark(struct rtattr *attr,
-				 struct rtattr *mask_attr)
-{
-	print_masked_u32("ct_mark", attr, mask_attr, true);
-}
-
-static void flower_print_key_id(const char *name, struct rtattr *attr)
-{
-	SPRINT_BUF(namefrm);
-
-	if (!attr)
-		return;
-
-	sprintf(namefrm,"\n  %s %%u", name);
-	print_uint(PRINT_ANY, name, namefrm, rta_getattr_be32(attr));
-}
-
-static void flower_print_geneve_opts(const char *name, struct rtattr *attr,
-				     char *strbuf)
-{
-	struct rtattr *tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX + 1];
-	int ii, data_len, offset = 0, slen = 0;
-	struct rtattr *i = RTA_DATA(attr);
-	int rem = RTA_PAYLOAD(attr);
-	__u8 type, data_r[rem];
-	char data[rem * 2 + 1];
-	__u16 class;
-
-	open_json_array(PRINT_JSON, name);
-	while (rem) {
-		parse_rtattr(tb, TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX, i, rem);
-		class = rta_getattr_be16(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS]);
-		type = rta_getattr_u8(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE]);
-		data_len = RTA_PAYLOAD(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA]);
-		hexstring_n2a(RTA_DATA(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA]),
-			      data_len, data, sizeof(data));
-		hex2mem(data, data_r, data_len);
-		offset += data_len + 20;
-		rem -= data_len + 20;
-		i = RTA_DATA(attr) + offset;
-
-		open_json_object(NULL);
-		print_uint(PRINT_JSON, "class", NULL, class);
-		print_uint(PRINT_JSON, "type", NULL, type);
-		open_json_array(PRINT_JSON, "data");
-		for (ii = 0; ii < data_len; ii++)
-			print_uint(PRINT_JSON, NULL, NULL, data_r[ii]);
-		close_json_array(PRINT_JSON, "data");
-		close_json_object();
-
-		slen += sprintf(strbuf + slen, "%04x:%02x:%s",
-				class, type, data);
-		if (rem)
-			slen += sprintf(strbuf + slen, ",");
-	}
-	close_json_array(PRINT_JSON, name);
-}
-
-static void flower_print_geneve_parts(const char *name, struct rtattr *attr,
-				      char *key, char *mask)
-{
-	char *namefrm = "\n  geneve_opt %s";
-	char *key_token, *mask_token, *out;
-	int len;
-
-	out = malloc(RTA_PAYLOAD(attr) * 4 + 3);
-	if (!out)
-		return;
-
-	len = 0;
-	key_token = strsep(&key, ",");
-	mask_token = strsep(&mask, ",");
-	while (key_token) {
-		len += sprintf(&out[len], "%s/%s,", key_token, mask_token);
-		mask_token = strsep(&mask, ",");
-		key_token = strsep(&key, ",");
-	}
-
-	out[len - 1] = '\0';
-	print_string(PRINT_FP, name, namefrm, out);
-	free(out);
-}
-
-static void flower_print_enc_opts(const char *name, struct rtattr *attr,
-				  struct rtattr *mask_attr)
-{
-	struct rtattr *key_tb[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1];
-	struct rtattr *msk_tb[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1];
-	char *key, *msk;
-
-	if (!attr)
-		return;
-
-	key = malloc(RTA_PAYLOAD(attr) * 2 + 1);
-	if (!key)
-		return;
-
-	msk = malloc(RTA_PAYLOAD(attr) * 2 + 1);
-	if (!msk)
-		goto err_key_free;
-
-	parse_rtattr_nested(key_tb, TCA_FLOWER_KEY_ENC_OPTS_MAX, attr);
-	flower_print_geneve_opts("geneve_opt_key",
-				 key_tb[TCA_FLOWER_KEY_ENC_OPTS_GENEVE], key);
-
-	parse_rtattr_nested(msk_tb, TCA_FLOWER_KEY_ENC_OPTS_MAX, mask_attr);
-	flower_print_geneve_opts("geneve_opt_mask",
-				 msk_tb[TCA_FLOWER_KEY_ENC_OPTS_GENEVE], msk);
-
-	flower_print_geneve_parts(name, attr, key, msk);
-
-	free(msk);
-err_key_free:
-	free(key);
-}
-
-static void flower_print_masked_u8(const char *name, struct rtattr *attr,
-				   struct rtattr *mask_attr,
-				   const char *(*value_to_str)(__u8 value))
-{
-	const char *value_str = NULL;
-	__u8 value, mask;
-	SPRINT_BUF(namefrm);
-	SPRINT_BUF(out);
-	size_t done;
-
-	if (!attr)
-		return;
-
-	value = rta_getattr_u8(attr);
-	mask = mask_attr ? rta_getattr_u8(mask_attr) : UINT8_MAX;
-	if (mask == UINT8_MAX && value_to_str)
-		value_str = value_to_str(value);
-
-	if (value_str)
-		done = sprintf(out, "%s", value_str);
-	else
-		done = sprintf(out, "%d", value);
-
-	if (mask != UINT8_MAX)
-		sprintf(out + done, "/%d", mask);
-
-	sprintf(namefrm,"\n  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
-}
-
-static void flower_print_u8(const char *name, struct rtattr *attr)
-{
-	flower_print_masked_u8(name, attr, NULL, NULL);
-}
-
-static void flower_print_u32(const char *name, struct rtattr *attr)
-{
-	SPRINT_BUF(namefrm);
-
-	if (!attr)
-		return;
-
-	sprintf(namefrm,"\n  %s %%u", name);
-	print_uint(PRINT_ANY, name, namefrm, rta_getattr_u32(attr));
-}
-
-static void flower_print_arp_op(const char *name,
-				struct rtattr *op_attr,
-				struct rtattr *mask_attr)
-{
-	flower_print_masked_u8(name, op_attr, mask_attr,
-			       flower_print_arp_op_to_name);
+	fprintf(f, "\n  %s %d", name, ntohs(rta_getattr_u16(attr)));
 }
 
 static int flower_print_opt(struct filter_util *qu, FILE *f,
 			    struct rtattr *opt, __u32 handle)
 {
 	struct rtattr *tb[TCA_FLOWER_MAX + 1];
-	__be16 min_port_type, max_port_type;
-	int nl_type, nl_mask_type;
 	__be16 eth_type = 0;
 	__u8 ip_proto = 0xff;
 
@@ -2022,221 +462,53 @@
 	parse_rtattr_nested(tb, TCA_FLOWER_MAX, opt);
 
 	if (handle)
-		print_uint(PRINT_ANY, "handle", "handle 0x%x ", handle);
+		fprintf(f, "handle 0x%x ", handle);
 
 	if (tb[TCA_FLOWER_CLASSID]) {
-		__u32 h = rta_getattr_u32(tb[TCA_FLOWER_CLASSID]);
-
-		if (TC_H_MIN(h) < TC_H_MIN_PRIORITY ||
-		    TC_H_MIN(h) > (TC_H_MIN_PRIORITY + TC_QOPT_MAX_QUEUE - 1)) {
-			SPRINT_BUF(b1);
-			print_string(PRINT_ANY, "classid", "classid %s ",
-				     sprint_tc_classid(h, b1));
-		} else {
-			print_uint(PRINT_ANY, "hw_tc", "hw_tc %u ",
-				   TC_H_MIN(h) - TC_H_MIN_PRIORITY);
-		}
+		SPRINT_BUF(b1);
+		fprintf(f, "classid %s ",
+			sprint_tc_classid(rta_getattr_u32(tb[TCA_FLOWER_CLASSID]),
+					  b1));
 	}
 
 	if (tb[TCA_FLOWER_INDEV]) {
 		struct rtattr *attr = tb[TCA_FLOWER_INDEV];
 
-		print_string(PRINT_ANY, "indev", "\n  indev %s",
-			     rta_getattr_str(attr));
+		fprintf(f, "\n  indev %s", rta_getattr_str(attr));
 	}
 
-	open_json_object("keys");
-
-	if (tb[TCA_FLOWER_KEY_VLAN_ID]) {
-		struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ID];
-
-		print_uint(PRINT_ANY, "vlan_id", "\n  vlan_id %u",
-			   rta_getattr_u16(attr));
-	}
-
-	if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) {
-		struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_PRIO];
-
-		print_uint(PRINT_ANY, "vlan_prio", "\n  vlan_prio %d",
-			   rta_getattr_u8(attr));
-	}
-
-	if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) {
-		SPRINT_BUF(buf);
-		struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE];
-
-		print_string(PRINT_ANY, "vlan_ethtype", "\n  vlan_ethtype %s",
-			     ll_proto_n2a(rta_getattr_u16(attr),
-			     buf, sizeof(buf)));
-	}
-
-	if (tb[TCA_FLOWER_KEY_CVLAN_ID]) {
-		struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ID];
-
-		print_uint(PRINT_ANY, "cvlan_id", "\n  cvlan_id %u",
-			   rta_getattr_u16(attr));
-	}
-
-	if (tb[TCA_FLOWER_KEY_CVLAN_PRIO]) {
-		struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_PRIO];
-
-		print_uint(PRINT_ANY, "cvlan_prio", "\n  cvlan_prio %d",
-			   rta_getattr_u8(attr));
-	}
-
-	if (tb[TCA_FLOWER_KEY_CVLAN_ETH_TYPE]) {
-		SPRINT_BUF(buf);
-		struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ETH_TYPE];
-
-		print_string(PRINT_ANY, "cvlan_ethtype", "\n  cvlan_ethtype %s",
-			     ll_proto_n2a(rta_getattr_u16(attr),
-			     buf, sizeof(buf)));
-	}
-
-	flower_print_eth_addr("dst_mac", tb[TCA_FLOWER_KEY_ETH_DST],
+	flower_print_eth_addr(f, "dst_mac", tb[TCA_FLOWER_KEY_ETH_DST],
 			      tb[TCA_FLOWER_KEY_ETH_DST_MASK]);
-	flower_print_eth_addr("src_mac", tb[TCA_FLOWER_KEY_ETH_SRC],
+	flower_print_eth_addr(f, "src_mac", tb[TCA_FLOWER_KEY_ETH_SRC],
 			      tb[TCA_FLOWER_KEY_ETH_SRC_MASK]);
 
-	flower_print_eth_type(&eth_type, tb[TCA_FLOWER_KEY_ETH_TYPE]);
-	flower_print_ip_proto(&ip_proto, tb[TCA_FLOWER_KEY_IP_PROTO]);
+	flower_print_eth_type(f, &eth_type, tb[TCA_FLOWER_KEY_ETH_TYPE]);
+	flower_print_ip_proto(f, &ip_proto, tb[TCA_FLOWER_KEY_IP_PROTO]);
 
-	flower_print_ip_attr("ip_tos", tb[TCA_FLOWER_KEY_IP_TOS],
-			    tb[TCA_FLOWER_KEY_IP_TOS_MASK]);
-	flower_print_ip_attr("ip_ttl", tb[TCA_FLOWER_KEY_IP_TTL],
-			    tb[TCA_FLOWER_KEY_IP_TTL_MASK]);
-
-	flower_print_u32("mpls_label", tb[TCA_FLOWER_KEY_MPLS_LABEL]);
-	flower_print_u8("mpls_tc", tb[TCA_FLOWER_KEY_MPLS_TC]);
-	flower_print_u8("mpls_bos", tb[TCA_FLOWER_KEY_MPLS_BOS]);
-	flower_print_u8("mpls_ttl", tb[TCA_FLOWER_KEY_MPLS_TTL]);
-
-	flower_print_ip_addr("dst_ip", eth_type,
+	flower_print_ip_addr(f, "dst_ip", eth_type,
 			     tb[TCA_FLOWER_KEY_IPV4_DST],
 			     tb[TCA_FLOWER_KEY_IPV4_DST_MASK],
 			     tb[TCA_FLOWER_KEY_IPV6_DST],
 			     tb[TCA_FLOWER_KEY_IPV6_DST_MASK]);
 
-	flower_print_ip_addr("src_ip", eth_type,
+	flower_print_ip_addr(f, "src_ip", eth_type,
 			     tb[TCA_FLOWER_KEY_IPV4_SRC],
 			     tb[TCA_FLOWER_KEY_IPV4_SRC_MASK],
 			     tb[TCA_FLOWER_KEY_IPV6_SRC],
 			     tb[TCA_FLOWER_KEY_IPV6_SRC_MASK]);
 
-	nl_type = flower_port_attr_type(ip_proto, FLOWER_ENDPOINT_DST);
-	if (nl_type >= 0)
-		flower_print_port("dst_port", tb[nl_type]);
-	nl_type = flower_port_attr_type(ip_proto, FLOWER_ENDPOINT_SRC);
-	if (nl_type >= 0)
-		flower_print_port("src_port", tb[nl_type]);
+	flower_print_port(f, "dst_port", ip_proto,
+			  tb[TCA_FLOWER_KEY_TCP_DST],
+			  tb[TCA_FLOWER_KEY_UDP_DST]);
 
-	if (!flower_port_range_attr_type(ip_proto, FLOWER_ENDPOINT_DST,
-					 &min_port_type, &max_port_type))
-		flower_print_port_range("dst_port",
-					tb[min_port_type], tb[max_port_type]);
+	flower_print_port(f, "src_port", ip_proto,
+			  tb[TCA_FLOWER_KEY_TCP_SRC],
+			  tb[TCA_FLOWER_KEY_UDP_SRC]);
 
-	if (!flower_port_range_attr_type(ip_proto, FLOWER_ENDPOINT_SRC,
-					 &min_port_type, &max_port_type))
-		flower_print_port_range("src_port",
-					tb[min_port_type], tb[max_port_type]);
-
-	flower_print_tcp_flags("tcp_flags", tb[TCA_FLOWER_KEY_TCP_FLAGS],
-			       tb[TCA_FLOWER_KEY_TCP_FLAGS_MASK]);
-
-	nl_type = flower_icmp_attr_type(eth_type, ip_proto,
-					FLOWER_ICMP_FIELD_TYPE);
-	nl_mask_type = flower_icmp_attr_mask_type(eth_type, ip_proto,
-						  FLOWER_ICMP_FIELD_TYPE);
-	if (nl_type >= 0 && nl_mask_type >= 0)
-		flower_print_masked_u8("icmp_type", tb[nl_type],
-				       tb[nl_mask_type], NULL);
-
-	nl_type = flower_icmp_attr_type(eth_type, ip_proto,
-					FLOWER_ICMP_FIELD_CODE);
-	nl_mask_type = flower_icmp_attr_mask_type(eth_type, ip_proto,
-						  FLOWER_ICMP_FIELD_CODE);
-	if (nl_type >= 0 && nl_mask_type >= 0)
-		flower_print_masked_u8("icmp_code", tb[nl_type],
-				       tb[nl_mask_type], NULL);
-
-	flower_print_ip4_addr("arp_sip", tb[TCA_FLOWER_KEY_ARP_SIP],
-			     tb[TCA_FLOWER_KEY_ARP_SIP_MASK]);
-	flower_print_ip4_addr("arp_tip", tb[TCA_FLOWER_KEY_ARP_TIP],
-			     tb[TCA_FLOWER_KEY_ARP_TIP_MASK]);
-	flower_print_arp_op("arp_op", tb[TCA_FLOWER_KEY_ARP_OP],
-			    tb[TCA_FLOWER_KEY_ARP_OP_MASK]);
-	flower_print_eth_addr("arp_sha", tb[TCA_FLOWER_KEY_ARP_SHA],
-			      tb[TCA_FLOWER_KEY_ARP_SHA_MASK]);
-	flower_print_eth_addr("arp_tha", tb[TCA_FLOWER_KEY_ARP_THA],
-			      tb[TCA_FLOWER_KEY_ARP_THA_MASK]);
-
-	flower_print_ip_addr("enc_dst_ip",
-			     tb[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK] ?
-			     htons(ETH_P_IP) : htons(ETH_P_IPV6),
-			     tb[TCA_FLOWER_KEY_ENC_IPV4_DST],
-			     tb[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK],
-			     tb[TCA_FLOWER_KEY_ENC_IPV6_DST],
-			     tb[TCA_FLOWER_KEY_ENC_IPV6_DST_MASK]);
-
-	flower_print_ip_addr("enc_src_ip",
-			     tb[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK] ?
-			     htons(ETH_P_IP) : htons(ETH_P_IPV6),
-			     tb[TCA_FLOWER_KEY_ENC_IPV4_SRC],
-			     tb[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK],
-			     tb[TCA_FLOWER_KEY_ENC_IPV6_SRC],
-			     tb[TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK]);
-
-	flower_print_key_id("enc_key_id", tb[TCA_FLOWER_KEY_ENC_KEY_ID]);
-
-	flower_print_port("enc_dst_port", tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]);
-
-	flower_print_ip_attr("enc_tos", tb[TCA_FLOWER_KEY_ENC_IP_TOS],
-			    tb[TCA_FLOWER_KEY_ENC_IP_TOS_MASK]);
-	flower_print_ip_attr("enc_ttl", tb[TCA_FLOWER_KEY_ENC_IP_TTL],
-			    tb[TCA_FLOWER_KEY_ENC_IP_TTL_MASK]);
-	flower_print_enc_opts("enc_opt", tb[TCA_FLOWER_KEY_ENC_OPTS],
-			      tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]);
-
-	flower_print_matching_flags("ip_flags", FLOWER_IP_FLAGS,
-				    tb[TCA_FLOWER_KEY_FLAGS],
-				    tb[TCA_FLOWER_KEY_FLAGS_MASK]);
-
-	flower_print_ct_state(tb[TCA_FLOWER_KEY_CT_STATE],
-			      tb[TCA_FLOWER_KEY_CT_STATE_MASK]);
-	flower_print_ct_zone(tb[TCA_FLOWER_KEY_CT_ZONE],
-			     tb[TCA_FLOWER_KEY_CT_ZONE_MASK]);
-	flower_print_ct_mark(tb[TCA_FLOWER_KEY_CT_MARK],
-			     tb[TCA_FLOWER_KEY_CT_MARK_MASK]);
-	flower_print_ct_label(tb[TCA_FLOWER_KEY_CT_LABELS],
-			      tb[TCA_FLOWER_KEY_CT_LABELS_MASK]);
-
-	close_json_object();
-
-	if (tb[TCA_FLOWER_FLAGS]) {
-		__u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]);
-
-		if (flags & TCA_CLS_FLAGS_SKIP_HW)
-			print_bool(PRINT_ANY, "skip_hw", "\n  skip_hw", true);
-		if (flags & TCA_CLS_FLAGS_SKIP_SW)
-			print_bool(PRINT_ANY, "skip_sw", "\n  skip_sw", true);
-
-		if (flags & TCA_CLS_FLAGS_IN_HW) {
-			print_bool(PRINT_ANY, "in_hw", "\n  in_hw", true);
-
-			if (tb[TCA_FLOWER_IN_HW_COUNT]) {
-				__u32 count = rta_getattr_u32(tb[TCA_FLOWER_IN_HW_COUNT]);
-
-				print_uint(PRINT_ANY, "in_hw_count",
-					   " in_hw_count %u", count);
-			}
-		}
-		else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
-			print_bool(PRINT_ANY, "not_in_hw", "\n  not_in_hw", true);
+	if (tb[TCA_FLOWER_ACT]) {
+		tc_print_action(f, tb[TCA_FLOWER_ACT]);
 	}
 
-	if (tb[TCA_FLOWER_ACT])
-		tc_print_action(f, tb[TCA_FLOWER_ACT], 0);
-
 	return 0;
 }
 
diff --git a/tc/f_fw.c b/tc/f_fw.c
index 688364f..165f489 100644
--- a/tc/f_fw.c
+++ b/tc/f_fw.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -24,26 +25,24 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... fw [ classid CLASSID ] [ indev DEV ] [ action ACTION_SPEC ]\n"
-		"	CLASSID := Push matching packets to the class identified by CLASSID with format X:Y\n"
-		"		CLASSID is parsed as hexadecimal input.\n"
-		"	DEV := specify device for incoming device classification.\n"
-		"	ACTION_SPEC := Apply an action on matching packets.\n"
-		"	NOTE: handle is represented as HANDLE[/FWMASK].\n"
-		"		FWMASK is 0xffffffff by default.\n");
+	fprintf(stderr, "Usage: ... fw [ classid CLASSID ] [ action ACTION_SPEC ]\n");
+	fprintf(stderr, "       ACTION_SPEC := ... look at individual actions\n");
+	fprintf(stderr, "       CLASSID := X:Y\n");
+	fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
 static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
 {
+	struct tc_police tp;
 	struct tcmsg *t = NLMSG_DATA(n);
 	struct rtattr *tail;
 	__u32 mask = 0;
 	int mask_set = 0;
 
+	memset(&tp, 0, sizeof(tp));
+
 	if (handle) {
 		char *slash;
-
 		if ((slash = strchr(handle, '/')) != NULL)
 			*slash = '\0';
 		if (get_u32(&t->tcm_handle, handle, 0)) {
@@ -62,7 +61,8 @@
 	if (argc == 0)
 		return 0;
 
-	tail = addattr_nest(n, 4096, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	if (mask_set)
 		addattr32(n, MAX_MSG, TCA_FW_MASK, mask);
@@ -70,8 +70,7 @@
 	while (argc > 0) {
 		if (matches(*argv, "classid") == 0 ||
 		    matches(*argv, "flowid") == 0) {
-			unsigned int handle;
-
+			unsigned handle;
 			NEXT_ARG();
 			if (get_tc_classid(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"classid\"\n");
@@ -93,15 +92,15 @@
 			}
 			continue;
 		} else if (strcmp(*argv, "indev") == 0) {
-			char d[IFNAMSIZ+1] = {};
-
+			char d[IFNAMSIZ+1];
+			memset(d, 0, sizeof (d));
 			argc--;
 			argv++;
 			if (argc < 1) {
 				fprintf(stderr, "Illegal indev\n");
 				return -1;
 			}
-			strncpy(d, *argv, sizeof(d) - 1);
+			strncpy(d, *argv, sizeof (d) - 1);
 			addattr_l(n, MAX_MSG, TCA_FW_INDEV, d, strlen(d) + 1);
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
@@ -113,7 +112,7 @@
 		}
 		argc--; argv++;
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -128,10 +127,9 @@
 
 	if (handle || tb[TCA_FW_MASK]) {
 		__u32 mark = 0, mask = 0;
-
-		if (handle)
+		if(handle)
 			mark = handle;
-		if (tb[TCA_FW_MASK] &&
+		if(tb[TCA_FW_MASK] &&
 		    (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF)
 			fprintf(f, "handle 0x%x/0x%x ", mark, mask);
 		else
@@ -147,13 +145,12 @@
 		tc_print_police(f, tb[TCA_FW_POLICE]);
 	if (tb[TCA_FW_INDEV]) {
 		struct rtattr *idev = tb[TCA_FW_INDEV];
-
-		fprintf(f, "input dev %s ", rta_getattr_str(idev));
+		fprintf(f, "input dev %s ",rta_getattr_str(idev));
 	}
 
 	if (tb[TCA_FW_ACT]) {
 		fprintf(f, "\n");
-		tc_print_action(f, tb[TCA_FW_ACT], 0);
+		tc_print_action(f, tb[TCA_FW_ACT]);
 	}
 	return 0;
 }
diff --git a/tc/f_matchall.c b/tc/f_matchall.c
deleted file mode 100644
index 253ed5c..0000000
--- a/tc/f_matchall.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * f_matchall.c		Match-all Classifier
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Jiri Pirko <jiri@mellanox.com>, Yotam Gigi <yotamg@mellanox.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <linux/if.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: ... matchall [skip_sw | skip_hw]\n"
-		"                 [ action ACTION_SPEC ] [ classid CLASSID ]\n"
-		"\n"
-		"Where: SELECTOR := SAMPLE SAMPLE ...\n"
-		"       FILTERID := X:Y:Z\n"
-		"       ACTION_SPEC := ... look at individual actions\n"
-		"\n"
-		"NOTE: CLASSID is parsed as hexadecimal input.\n");
-}
-
-static int matchall_parse_opt(struct filter_util *qu, char *handle,
-			   int argc, char **argv, struct nlmsghdr *n)
-{
-	struct tcmsg *t = NLMSG_DATA(n);
-	struct rtattr *tail;
-	__u32 flags = 0;
-	long h = 0;
-
-	if (handle) {
-		h = strtol(handle, NULL, 0);
-		if (h == LONG_MIN || h == LONG_MAX) {
-			fprintf(stderr, "Illegal handle \"%s\", must be numeric.\n",
-			    handle);
-			return -1;
-		}
-	}
-	t->tcm_handle = h;
-
-	if (argc == 0)
-		return 0;
-
-	tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
-	addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
-
-	while (argc > 0) {
-		if (matches(*argv, "classid") == 0 ||
-			   strcmp(*argv, "flowid") == 0) {
-			unsigned int handle;
-
-			NEXT_ARG();
-			if (get_tc_classid(&handle, *argv)) {
-				fprintf(stderr, "Illegal \"classid\"\n");
-				return -1;
-			}
-			addattr_l(n, MAX_MSG, TCA_MATCHALL_CLASSID, &handle, 4);
-		} else if (matches(*argv, "action") == 0) {
-			NEXT_ARG();
-			if (parse_action(&argc, &argv, TCA_MATCHALL_ACT, n)) {
-				fprintf(stderr, "Illegal \"action\"\n");
-				return -1;
-			}
-			continue;
-
-		} else if (strcmp(*argv, "skip_hw") == 0) {
-			NEXT_ARG();
-			flags |= TCA_CLS_FLAGS_SKIP_HW;
-			continue;
-		} else if (strcmp(*argv, "skip_sw") == 0) {
-			NEXT_ARG();
-			flags |= TCA_CLS_FLAGS_SKIP_SW;
-			continue;
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (flags) {
-		if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW |
-			       TCA_CLS_FLAGS_SKIP_SW))) {
-			fprintf(stderr,
-				"skip_hw and skip_sw are mutually exclusive\n");
-			return -1;
-		}
-		addattr_l(n, MAX_MSG, TCA_MATCHALL_FLAGS, &flags, 4);
-	}
-
-	tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
-	return 0;
-}
-
-static int matchall_print_opt(struct filter_util *qu, FILE *f,
-			   struct rtattr *opt, __u32 handle)
-{
-	struct rtattr *tb[TCA_MATCHALL_MAX+1];
-	struct tc_matchall_pcnt *pf = NULL;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_MATCHALL_MAX, opt);
-
-	if (handle)
-		print_uint(PRINT_ANY, "handle", "handle 0x%x ", handle);
-
-	if (tb[TCA_MATCHALL_CLASSID]) {
-		SPRINT_BUF(b1);
-		print_string(PRINT_ANY, "flowid", "flowid %s ",
-			sprint_tc_classid(rta_getattr_u32(tb[TCA_MATCHALL_CLASSID]), b1));
-	}
-
-	if (tb[TCA_MATCHALL_FLAGS]) {
-		__u32 flags = rta_getattr_u32(tb[TCA_MATCHALL_FLAGS]);
-
-		if (flags & TCA_CLS_FLAGS_SKIP_HW)
-			print_bool(PRINT_ANY, "skip_hw", "\n  skip_hw", true);
-		if (flags & TCA_CLS_FLAGS_SKIP_SW)
-			print_bool(PRINT_ANY, "skip_sw", "\n  skip_sw", true);
-
-		if (flags & TCA_CLS_FLAGS_IN_HW)
-			print_bool(PRINT_ANY, "in_hw", "\n  in_hw", true);
-		else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
-			print_bool(PRINT_ANY, "not_in_hw", "\n  not_in_hw", true);
-	}
-
-	if (tb[TCA_MATCHALL_PCNT]) {
-		if (RTA_PAYLOAD(tb[TCA_MATCHALL_PCNT])  < sizeof(*pf)) {
-			print_string(PRINT_FP, NULL, "Broken perf counters\n", NULL);
-			return -1;
-		}
-		pf = RTA_DATA(tb[TCA_MATCHALL_PCNT]);
-	}
-
-	if (show_stats && NULL != pf)
-		print_u64(PRINT_ANY, "rule_hit", " (rule hit %llu)",
-			(unsigned long long) pf->rhit);
-
-
-	if (tb[TCA_MATCHALL_ACT])
-		tc_print_action(f, tb[TCA_MATCHALL_ACT], 0);
-
-	return 0;
-}
-
-struct filter_util matchall_filter_util = {
-	.id = "matchall",
-	.parse_fopt = matchall_parse_opt,
-	.print_fopt = matchall_print_opt,
-};
diff --git a/tc/f_route.c b/tc/f_route.c
index 31fa96a..4e9032c 100644
--- a/tc/f_route.c
+++ b/tc/f_route.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -26,22 +27,23 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... route [ from REALM | fromif TAG ] [ to REALM ]\n"
-		"                [ classid CLASSID ] [ action ACTION_SPEC ]\n"
-		"       ACTION_SPEC := ... look at individual actions\n"
-		"       CLASSID := X:Y\n"
-		"\n"
-		"NOTE: CLASSID is parsed as hexadecimal input.\n");
+	fprintf(stderr, "Usage: ... route [ from REALM | fromif TAG ] [ to REALM ]\n");
+	fprintf(stderr, "                [ classid CLASSID ] [ action ACTION_SPEC ]\n");
+	fprintf(stderr, "       ACTION_SPEC := ... look at individual actions\n");
+	fprintf(stderr, "       CLASSID := X:Y\n");
+	fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
 static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
 {
+	struct tc_police tp;
 	struct tcmsg *t = NLMSG_DATA(n);
 	struct rtattr *tail;
 	__u32 fh = 0xFFFF8000;
 	__u32 order = 0;
 
+	memset(&tp, 0, sizeof(tp));
+
 	if (handle) {
 		if (get_u32(&t->tcm_handle, handle, 0)) {
 			fprintf(stderr, "Illegal \"handle\"\n");
@@ -52,12 +54,12 @@
 	if (argc == 0)
 		return 0;
 
-	tail = addattr_nest(n, 4096, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "to") == 0) {
 			__u32 id;
-
 			NEXT_ARG();
 			if (rtnl_rtrealm_a2n(&id, *argv)) {
 				fprintf(stderr, "Illegal \"to\"\n");
@@ -68,7 +70,6 @@
 			fh |= id&0xFF;
 		} else if (matches(*argv, "from") == 0) {
 			__u32 id;
-
 			NEXT_ARG();
 			if (rtnl_rtrealm_a2n(&id, *argv)) {
 				fprintf(stderr, "Illegal \"from\"\n");
@@ -79,10 +80,9 @@
 			fh |= id<<16;
 		} else if (matches(*argv, "fromif") == 0) {
 			__u32 id;
-
 			NEXT_ARG();
 			ll_init_map(&rth);
-			if ((id = ll_name_to_index(*argv)) <= 0) {
+			if ((id=ll_name_to_index(*argv)) <= 0) {
 				fprintf(stderr, "Illegal \"fromif\"\n");
 				return -1;
 			}
@@ -91,8 +91,7 @@
 			fh |= (0x8000|id)<<16;
 		} else if (matches(*argv, "classid") == 0 ||
 			   strcmp(*argv, "flowid") == 0) {
-			unsigned int handle;
-
+			unsigned handle;
 			NEXT_ARG();
 			if (get_tc_classid(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"classid\"\n");
@@ -129,7 +128,7 @@
 		}
 		argc--; argv++;
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	if (order) {
 		fh &= ~0x7F00;
 		fh |= (order<<8)&0x7F00;
@@ -142,7 +141,6 @@
 static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle)
 {
 	struct rtattr *tb[TCA_ROUTE4_MAX+1];
-
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
@@ -164,11 +162,11 @@
 	if (tb[TCA_ROUTE4_FROM])
 		fprintf(f, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1)));
 	if (tb[TCA_ROUTE4_IIF])
-		fprintf(f, "fromif %s", ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF])));
+		fprintf(f, "fromif %s", ll_index_to_name(*(int*)RTA_DATA(tb[TCA_ROUTE4_IIF])));
 	if (tb[TCA_ROUTE4_POLICE])
 		tc_print_police(f, tb[TCA_ROUTE4_POLICE]);
 	if (tb[TCA_ROUTE4_ACT])
-		tc_print_action(f, tb[TCA_ROUTE4_ACT], 0);
+		tc_print_action(f, tb[TCA_ROUTE4_ACT]);
 	return 0;
 }
 
diff --git a/tc/f_rsvp.c b/tc/f_rsvp.c
index 388e9ee..1fe9b15 100644
--- a/tc/f_rsvp.c
+++ b/tc/f_rsvp.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -25,19 +26,18 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage:	... rsvp ipproto PROTOCOL session DST[/PORT | GPI ]\n"
-		"		[ sender SRC[/PORT | GPI ] ]\n"
-		"		[ classid CLASSID ] [ action ACTION_SPEC ]\n"
-		"		[ tunnelid ID ] [ tunnel ID skip NUMBER ]\n"
-		"Where:	GPI := { flowlabel NUMBER | spi/ah SPI | spi/esp SPI |\n"
-		"		u{8|16|32} NUMBER mask MASK at OFFSET}\n"
-		"	ACTION_SPEC := ... look at individual actions\n"
-		"	FILTERID := X:Y\n"
-		"\nNOTE: CLASSID is parsed as hexadecimal input.\n");
+	fprintf(stderr, "Usage: ... rsvp ipproto PROTOCOL session DST[/PORT | GPI ]\n");
+	fprintf(stderr, "                [ sender SRC[/PORT | GPI ] ]\n");
+	fprintf(stderr, "                [ classid CLASSID ] [ action ACTION_SPEC ]\n");
+	fprintf(stderr, "                [ tunnelid ID ] [ tunnel ID skip NUMBER ]\n");
+	fprintf(stderr, "Where: GPI := { flowlabel NUMBER | spi/ah SPI | spi/esp SPI |\n");
+	fprintf(stderr, "                u{8|16|32} NUMBER mask MASK at OFFSET}\n");
+	fprintf(stderr, "       ACTION_SPEC := ... look at individual actions\n");
+	fprintf(stderr, "       FILTERID := X:Y\n");
+	fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
-static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix *addr,
+static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
 		    struct tc_rsvp_pinfo *pinfo, int dir, int family)
 {
 	int argc = *argc_p;
@@ -76,7 +76,6 @@
 	if (strcmp(*argv, "spi/ah") == 0 ||
 	    strcmp(*argv, "gpi/ah") == 0) {
 		__u32 gpi;
-
 		NEXT_ARG();
 		if (get_u32(&gpi, *argv, 0))
 			return -1;
@@ -89,7 +88,6 @@
 	} else if (strcmp(*argv, "spi/esp") == 0 ||
 		   strcmp(*argv, "gpi/esp") == 0) {
 		__u32 gpi;
-
 		NEXT_ARG();
 		if (get_u32(&gpi, *argv, 0))
 			return -1;
@@ -101,7 +99,6 @@
 		argc--; argv++;
 	} else if (strcmp(*argv, "flowlabel") == 0) {
 		__u32 flabel;
-
 		NEXT_ARG();
 		if (get_u32(&flabel, *argv, 0))
 			return -1;
@@ -117,7 +114,6 @@
 		int sz = 1;
 		__u32 tmp;
 		__u32 mask = 0xff;
-
 		if (strcmp(*argv, "u32") == 0) {
 			sz = 4;
 			mask = 0xffff;
@@ -170,15 +166,18 @@
 }
 
 
-static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc,
-			  char **argv, struct nlmsghdr *n)
+static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
 {
 	int family = strcmp(qu->id, "rsvp") == 0 ? AF_INET : AF_INET6;
-	struct tc_rsvp_pinfo pinfo = {};
+	struct tc_rsvp_pinfo pinfo;
+	struct tc_police tp;
 	struct tcmsg *t = NLMSG_DATA(n);
 	int pinfo_ok = 0;
 	struct rtattr *tail;
 
+	memset(&pinfo, 0, sizeof(pinfo));
+	memset(&tp, 0, sizeof(tp));
+
 	if (handle) {
 		if (get_u32(&t->tcm_handle, handle, 0)) {
 			fprintf(stderr, "Illegal \"handle\"\n");
@@ -189,12 +188,12 @@
 	if (argc == 0)
 		return 0;
 
-	tail = addattr_nest(n, 4096, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "session") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (get_addr_and_pi(&argc, &argv, &addr, &pinfo, 1, family)) {
 				fprintf(stderr, "Illegal \"session\"\n");
@@ -207,7 +206,6 @@
 		} else if (matches(*argv, "sender") == 0 ||
 			   matches(*argv, "flowspec") == 0) {
 			inet_prefix addr;
-
 			NEXT_ARG();
 			if (get_addr_and_pi(&argc, &argv, &addr, &pinfo, 0, family)) {
 				fprintf(stderr, "Illegal \"sender\"\n");
@@ -219,7 +217,6 @@
 			continue;
 		} else if (matches("ipproto", *argv) == 0) {
 			int num;
-
 			NEXT_ARG();
 			num = inet_proto_a2n(*argv);
 			if (num < 0) {
@@ -230,8 +227,7 @@
 			pinfo_ok++;
 		} else if (matches(*argv, "classid") == 0 ||
 			   strcmp(*argv, "flowid") == 0) {
-			unsigned int handle;
-
+			unsigned handle;
 			NEXT_ARG();
 			if (get_tc_classid(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"classid\"\n");
@@ -239,8 +235,7 @@
 			}
 			addattr_l(n, 4096, TCA_RSVP_CLASSID, &handle, 4);
 		} else if (strcmp(*argv, "tunnelid") == 0) {
-			unsigned int tid;
-
+			unsigned tid;
 			NEXT_ARG();
 			if (get_unsigned(&tid, *argv, 0)) {
 				fprintf(stderr, "Illegal \"tunnelid\"\n");
@@ -249,8 +244,7 @@
 			pinfo.tunnelid = tid;
 			pinfo_ok++;
 		} else if (strcmp(*argv, "tunnel") == 0) {
-			unsigned int tid;
-
+			unsigned tid;
 			NEXT_ARG();
 			if (get_unsigned(&tid, *argv, 0)) {
 				fprintf(stderr, "Illegal \"tunnel\"\n");
@@ -294,11 +288,11 @@
 
 	if (pinfo_ok)
 		addattr_l(n, 4096, TCA_RSVP_PINFO, &pinfo, sizeof(pinfo));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
-static char *sprint_spi(struct tc_rsvp_gpi *pi, int dir, char *buf)
+static char * sprint_spi(struct tc_rsvp_gpi *pi, int dir, char *buf)
 {
 	if (pi->offset == 0) {
 		if (dir && pi->mask == htonl(0xFFFF)) {
@@ -357,7 +351,6 @@
 
 	if (tb[TCA_RSVP_DST]) {
 		char buf[128];
-
 		fprintf(f, "session ");
 		if (inet_ntop(family, RTA_DATA(tb[TCA_RSVP_DST]), buf, sizeof(buf)) == 0)
 			fprintf(f, " [INVALID DADDR] ");
@@ -384,7 +377,6 @@
 		fprintf(f, "tunnelid %d ", pinfo->tunnelid);
 	if (tb[TCA_RSVP_SRC]) {
 		char buf[128];
-
 		fprintf(f, "sender ");
 		if (inet_ntop(family, RTA_DATA(tb[TCA_RSVP_SRC]), buf, sizeof(buf)) == 0) {
 			fprintf(f, "[BAD]");
@@ -402,7 +394,7 @@
 	}
 
 	if (tb[TCA_RSVP_ACT]) {
-		tc_print_action(f, tb[TCA_RSVP_ACT], 0);
+		tc_print_action(f, tb[TCA_RSVP_ACT]);
 	}
 	if (tb[TCA_RSVP_POLICE])
 		tc_print_police(f, tb[TCA_RSVP_POLICE]);
diff --git a/tc/f_tcindex.c b/tc/f_tcindex.c
index ae4cbf1..b1847c8 100644
--- a/tc/f_tcindex.c
+++ b/tc/f_tcindex.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * f_tcindex.c		Traffic control index filter
  *
@@ -8,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <netinet/in.h>
@@ -17,109 +17,117 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		" Usage: ... tcindex	[ hash SIZE ] [ mask MASK ] [ shift SHIFT ]\n"
-		"			[ pass_on | fall_through ]\n"
-		"			[ classid CLASSID ] [ action ACTION_SPEC ]\n");
+	fprintf(stderr," Usage: ... tcindex [ hash SIZE ] [ mask MASK ]"
+	    " [ shift SHIFT ]\n");
+	fprintf(stderr,"                    [ pass_on | fall_through ]\n");
+	fprintf(stderr,"                    [ classid CLASSID ] "
+	    "[ action ACTION_SPEC ]\n");
 }
 
 static int tcindex_parse_opt(struct filter_util *qu, char *handle, int argc,
-			     char **argv, struct nlmsghdr *n)
+    char **argv, struct nlmsghdr *n)
 {
 	struct tcmsg *t = NLMSG_DATA(n);
 	struct rtattr *tail;
 	char *end;
 
 	if (handle) {
-		t->tcm_handle = strtoul(handle, &end, 0);
+		t->tcm_handle = strtoul(handle,&end,0);
 		if (*end) {
 			fprintf(stderr, "Illegal filter ID\n");
 			return -1;
 		}
 	}
 	if (!argc) return 0;
-	tail = addattr_nest(n, 4096, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n,4096,TCA_OPTIONS,NULL,0);
 	while (argc) {
-		if (!strcmp(*argv, "hash")) {
+		if (!strcmp(*argv,"hash")) {
 			int hash;
 
 			NEXT_ARG();
-			hash = strtoul(*argv, &end, 0);
+			hash = strtoul(*argv,&end,0);
 			if (*end || !hash || hash > 0x10000) {
 				explain();
 				return -1;
 			}
-			addattr_l(n, 4096, TCA_TCINDEX_HASH, &hash,
-				  sizeof(hash));
-		} else if (!strcmp(*argv,"mask")) {
+			addattr_l(n,4096,TCA_TCINDEX_HASH,&hash,sizeof(hash));
+		}
+		else if (!strcmp(*argv,"mask")) {
 			__u16 mask;
 
 			NEXT_ARG();
-			mask = strtoul(*argv, &end, 0);
+			mask = strtoul(*argv,&end,0);
 			if (*end) {
 				explain();
 				return -1;
 			}
-			addattr_l(n, 4096, TCA_TCINDEX_MASK, &mask,
-				  sizeof(mask));
-		} else if (!strcmp(*argv,"shift")) {
+			addattr_l(n,4096,TCA_TCINDEX_MASK,&mask,sizeof(mask));
+		}
+		else if (!strcmp(*argv,"shift")) {
 			int shift;
 
 			NEXT_ARG();
-			shift = strtoul(*argv, &end, 0);
+			shift = strtoul(*argv,&end,0);
 			if (*end) {
 				explain();
 				return -1;
 			}
-			addattr_l(n, 4096, TCA_TCINDEX_SHIFT, &shift,
+			addattr_l(n,4096,TCA_TCINDEX_SHIFT,&shift,
 			    sizeof(shift));
-		} else if (!strcmp(*argv,"fall_through")) {
+		}
+		else if (!strcmp(*argv,"fall_through")) {
 			int value = 1;
 
-			addattr_l(n, 4096, TCA_TCINDEX_FALL_THROUGH, &value,
+			addattr_l(n,4096,TCA_TCINDEX_FALL_THROUGH,&value,
 			    sizeof(value));
-		} else if (!strcmp(*argv,"pass_on")) {
+		}
+		else if (!strcmp(*argv,"pass_on")) {
 			int value = 0;
 
-			addattr_l(n, 4096, TCA_TCINDEX_FALL_THROUGH, &value,
+			addattr_l(n,4096,TCA_TCINDEX_FALL_THROUGH,&value,
 			    sizeof(value));
-		} else if (!strcmp(*argv,"classid")) {
+		}
+		else if (!strcmp(*argv,"classid")) {
 			__u32 handle;
 
 			NEXT_ARG();
-			if (get_tc_classid(&handle, *argv)) {
+			if (get_tc_classid(&handle,*argv)) {
 				fprintf(stderr, "Illegal \"classid\"\n");
 				return -1;
 			}
 			addattr_l(n, 4096, TCA_TCINDEX_CLASSID, &handle, 4);
-		} else if (!strcmp(*argv,"police")) {
+		}
+		else if (!strcmp(*argv,"police")) {
 			NEXT_ARG();
 			if (parse_police(&argc, &argv, TCA_TCINDEX_POLICE, n)) {
 				fprintf(stderr, "Illegal \"police\"\n");
 				return -1;
 			}
 			continue;
-		} else if (!strcmp(*argv,"action")) {
+		}
+		else if (!strcmp(*argv,"action")) {
 			NEXT_ARG();
-			if (parse_action(&argc, &argv, TCA_TCINDEX_ACT, n)) {
+			if (parse_police(&argc, &argv, TCA_TCINDEX_ACT, n)) {
 				fprintf(stderr, "Illegal \"action\"\n");
 				return -1;
 			}
 			continue;
-		} else {
+		}
+		else {
 			explain();
 			return -1;
 		}
 		argc--;
 		argv++;
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
 
 static int tcindex_print_opt(struct filter_util *qu, FILE *f,
-			     struct rtattr *opt, __u32 handle)
+     struct rtattr *opt, __u32 handle)
 {
 	struct rtattr *tb[TCA_TCINDEX_MAX+1];
 
@@ -128,14 +136,14 @@
 
 	parse_rtattr_nested(tb, TCA_TCINDEX_MAX, opt);
 
-	if (handle != ~0) fprintf(f, "handle 0x%04x ", handle);
+	if (handle != ~0) fprintf(f,"handle 0x%04x ",handle);
 	if (tb[TCA_TCINDEX_HASH]) {
 		__u16 hash;
 
 		if (RTA_PAYLOAD(tb[TCA_TCINDEX_HASH]) < sizeof(hash))
 			return -1;
 		hash = rta_getattr_u16(tb[TCA_TCINDEX_HASH]);
-		fprintf(f, "hash %d ", hash);
+		fprintf(f,"hash %d ",hash);
 	}
 	if (tb[TCA_TCINDEX_MASK]) {
 		__u16 mask;
@@ -143,15 +151,15 @@
 		if (RTA_PAYLOAD(tb[TCA_TCINDEX_MASK]) < sizeof(mask))
 			return -1;
 		mask = rta_getattr_u16(tb[TCA_TCINDEX_MASK]);
-		fprintf(f, "mask 0x%04x ", mask);
+		fprintf(f,"mask 0x%04x ",mask);
 	}
 	if (tb[TCA_TCINDEX_SHIFT]) {
 		int shift;
 
 		if (RTA_PAYLOAD(tb[TCA_TCINDEX_SHIFT]) < sizeof(shift))
 			return -1;
-		shift = rta_getattr_u32(tb[TCA_TCINDEX_SHIFT]);
-		fprintf(f, "shift %d ", shift);
+		shift = *(int *) RTA_DATA(tb[TCA_TCINDEX_SHIFT]);
+		fprintf(f,"shift %d ",shift);
 	}
 	if (tb[TCA_TCINDEX_FALL_THROUGH]) {
 		int fall_through;
@@ -159,12 +167,12 @@
 		if (RTA_PAYLOAD(tb[TCA_TCINDEX_FALL_THROUGH]) <
 		    sizeof(fall_through))
 			return -1;
-		fall_through = rta_getattr_u32(tb[TCA_TCINDEX_FALL_THROUGH]);
-		fprintf(f, fall_through ? "fall_through " : "pass_on ");
+		fall_through = *(int *) RTA_DATA(tb[TCA_TCINDEX_FALL_THROUGH]);
+		fprintf(f,fall_through ? "fall_through " : "pass_on ");
 	}
 	if (tb[TCA_TCINDEX_CLASSID]) {
 		SPRINT_BUF(b1);
-		fprintf(f, "classid %s ", sprint_tc_classid(*(__u32 *)
+		fprintf(f, "classid %s ",sprint_tc_classid(*(__u32 *)
 		    RTA_DATA(tb[TCA_TCINDEX_CLASSID]), b1));
 	}
 	if (tb[TCA_TCINDEX_POLICE]) {
@@ -173,7 +181,7 @@
 	}
 	if (tb[TCA_TCINDEX_ACT]) {
 		fprintf(f, "\n");
-		tc_print_action(f, tb[TCA_TCINDEX_ACT], 0);
+		tc_print_police(f, tb[TCA_TCINDEX_ACT]);
 	}
 	return 0;
 }
diff --git a/tc/f_u32.c b/tc/f_u32.c
index e0a322d..0b97678 100644
--- a/tc/f_u32.c
+++ b/tc/f_u32.c
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -25,25 +26,28 @@
 #include "utils.h"
 #include "tc_util.h"
 
+extern int show_pretty;
+
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... u32 [ match SELECTOR ... ] [ link HTID ] [ classid CLASSID ]\n"
-		"               [ action ACTION_SPEC ] [ offset OFFSET_SPEC ]\n"
-		"               [ ht HTID ] [ hashkey HASHKEY_SPEC ]\n"
-		"               [ sample SAMPLE ] [skip_hw | skip_sw]\n"
-		"or         u32 divisor DIVISOR\n"
-		"\n"
-		"Where: SELECTOR := SAMPLE SAMPLE ...\n"
-		"       SAMPLE := { ip | ip6 | udp | tcp | icmp | u{32|16|8} | mark }\n"
-		"                 SAMPLE_ARGS [ divisor DIVISOR ]\n"
-		"       FILTERID := X:Y:Z\n"
-		"\nNOTE: CLASSID is parsed at hexadecimal input.\n");
+	fprintf(stderr, "Usage: ... u32 [ match SELECTOR ... ] [ link HTID ]"
+		" [ classid CLASSID ]\n");
+	fprintf(stderr, "               [ action ACTION_SPEC ]"
+		" [ offset OFFSET_SPEC ]\n");
+	fprintf(stderr, "               [ ht HTID ] [ hashkey HASHKEY_SPEC ]\n");
+	fprintf(stderr, "               [ sample SAMPLE ]\n");
+	fprintf(stderr, "or         u32 divisor DIVISOR\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
+	fprintf(stderr, "       SAMPLE := { ip | ip6 | udp | tcp | icmp |"
+		" u{32|16|8} | mark } SAMPLE_ARGS [divisor DIVISOR]\n");
+	fprintf(stderr, "       FILTERID := X:Y:Z\n");
+	fprintf(stderr, "\nNOTE: CLASSID is parsed at hexadecimal input.\n");
 }
 
 static int get_u32_handle(__u32 *handle, const char *str)
 {
-	__u32 htid = 0, hash = 0, nodeid = 0;
+	__u32 htid=0, hash=0, nodeid=0;
 	char *tmp = strchr(str, ':');
 
 	if (tmp == NULL) {
@@ -54,21 +58,21 @@
 	htid = strtoul(str, &tmp, 16);
 	if (tmp == str && *str != ':' && *str != 0)
 		return -1;
-	if (htid >= 0x1000)
+	if (htid>=0x1000)
 		return -1;
 	if (*tmp) {
 		str = tmp + 1;
 		hash = strtoul(str, &tmp, 16);
 		if (tmp == str && *str != ':' && *str != 0)
 			return -1;
-		if (hash >= 0x100)
+		if (hash>=0x100)
 			return -1;
 		if (*tmp) {
 			str = tmp + 1;
 			nodeid = strtoul(str, &tmp, 16);
 			if (tmp == str && *str != 0)
 				return -1;
-			if (nodeid >= 0x1000)
+			if (nodeid>=0x1000)
 				return -1;
 		}
 	}
@@ -76,7 +80,7 @@
 	return 0;
 }
 
-static char *sprint_u32_handle(__u32 handle, char *buf)
+static char * sprint_u32_handle(__u32 handle, char *buf)
 {
 	int bsize = SPRINT_BSIZE-1;
 	__u32 htid = TC_U32_HTID(handle);
@@ -90,20 +94,17 @@
 	}
 	if (htid) {
 		int l = snprintf(b, bsize, "%x:", htid>>20);
-
 		bsize -= l;
 		b += l;
 	}
 	if (nodeid|hash) {
 		if (hash) {
 			int l = snprintf(b, bsize, "%x", hash);
-
 			bsize -= l;
 			b += l;
 		}
 		if (nodeid) {
 			int l = snprintf(b, bsize, ":%x", nodeid);
-
 			bsize -= l;
 			b += l;
 		}
@@ -121,7 +122,7 @@
 
 	key &= mask;
 
-	for (i = 0; i < hwm; i++) {
+	for (i=0; i<hwm; i++) {
 		if (sel->keys[i].off == off && sel->keys[i].offmask == offmask) {
 			__u32 intersect = mask & sel->keys[i].mask;
 
@@ -170,8 +171,7 @@
 	return pack_key(sel, key, mask, off, offmask);
 }
 
-static int pack_key8(struct tc_u32_sel *sel, __u32 key, __u32 mask, int off,
-		     int offmask)
+static int pack_key8(struct tc_u32_sel *sel, __u32 key, __u32 mask, int off, int offmask)
 {
 	if (key > 0xFF || mask > 0xFF)
 		return -1;
@@ -382,14 +382,14 @@
 
 	plen = addr.bitlen;
 	for (i = 0; i < plen; i += 32) {
-		if (i + 31 < plen) {
+//		if (((i + 31) & ~0x1F) <= plen) {
+		if (i + 31 <= plen) {
 			res = pack_key(sel, addr.data[i / 32],
 				       0xFFFFFFFF, off + 4 * (i / 32), offmask);
 			if (res < 0)
 				return -1;
 		} else if (i < plen) {
 			__u32 mask = htonl(0xFFFFFFFF << (32 - (plen - i)));
-
 			res = pack_key(sel, addr.data[i / 32],
 				       mask, off + 4 * (i / 32), offmask);
 			if (res < 0)
@@ -712,7 +712,7 @@
 	} else if (matches(*argv, "ip") == 0) {
 		NEXT_ARG();
 		res = parse_ip(&argc, &argv, sel);
-	} else	if (matches(*argv, "ip6") == 0) {
+	} else 	if (matches(*argv, "ip6") == 0) {
 		NEXT_ARG();
 		res = parse_ip6(&argc, &argv, sel);
 	} else if (matches(*argv, "udp") == 0) {
@@ -746,7 +746,6 @@
 	while (argc > 0) {
 		if (matches(*argv, "plus") == 0) {
 			int off;
-
 			NEXT_ARG();
 			if (get_integer(&off, *argv, 0))
 				return -1;
@@ -754,7 +753,6 @@
 			sel->flags |= TC_U32_OFFSET;
 		} else if (matches(*argv, "at") == 0) {
 			int off;
-
 			NEXT_ARG();
 			if (get_integer(&off, *argv, 0))
 				return -1;
@@ -765,13 +763,14 @@
 			}
 			sel->flags |= TC_U32_VAROFFSET;
 		} else if (matches(*argv, "mask") == 0) {
+			__u16 mask;
 			NEXT_ARG();
-			if (get_be16(&sel->offmask, *argv, 16))
+			if (get_u16(&mask, *argv, 16))
 				return -1;
+			sel->offmask = htons(mask);
 			sel->flags |= TC_U32_VAROFFSET;
 		} else if (matches(*argv, "shift") == 0) {
 			int shift;
-
 			NEXT_ARG();
 			if (get_integer(&shift, *argv, 0))
 				return -1;
@@ -797,12 +796,13 @@
 
 	while (argc > 0) {
 		if (matches(*argv, "mask") == 0) {
+			__u32 mask;
 			NEXT_ARG();
-			if (get_be32(&sel->hmask, *argv, 16))
+			if (get_u32(&mask, *argv, 16))
 				return -1;
+			sel->hmask = htonl(mask);
 		} else if (matches(*argv, "at") == 0) {
 			int num;
-
 			NEXT_ARG();
 			if (get_integer(&num, *argv, 0))
 				return -1;
@@ -828,26 +828,22 @@
 	case 0:
 		switch (ntohl(key->mask)) {
 		case 0x0f000000:
-			fprintf(f, "\n  match IP ihl %u",
-				ntohl(key->val) >> 24);
+			fprintf(f, "\n  match IP ihl %u", ntohl(key->val) >> 24);
 			return;
 		case 0x00ff0000:
-			fprintf(f, "\n  match IP dsfield %#x",
-				ntohl(key->val) >> 16);
+			fprintf(f, "\n  match IP dsfield %#x", ntohl(key->val) >> 16);
 			return;
 		}
 		break;
 	case 8:
 		if (ntohl(key->mask) == 0x00ff0000) {
-			fprintf(f, "\n  match IP protocol %d",
-				ntohl(key->val) >> 16);
+			fprintf(f, "\n  match IP protocol %d", ntohl(key->val) >> 16);
 			return;
 		}
 		break;
 	case 12:
 	case 16: {
 			int bits = mask2bits(key->mask);
-
 			if (bits >= 0) {
 				fprintf(f, "\n  %s %s/%d",
 					key->off == 12 ? "match IP src" : "match IP dst",
@@ -888,26 +884,22 @@
 	case 0:
 		switch (ntohl(key->mask)) {
 		case 0x0f000000:
-			fprintf(f, "\n  match IP ihl %u",
-				ntohl(key->val) >> 24);
+			fprintf(f, "\n  match IP ihl %u", ntohl(key->val) >> 24);
 			return;
 		case 0x00ff0000:
-			fprintf(f, "\n  match IP dsfield %#x",
-				ntohl(key->val) >> 16);
+			fprintf(f, "\n  match IP dsfield %#x", ntohl(key->val) >> 16);
 			return;
 		}
 		break;
 	case 8:
 		if (ntohl(key->mask) == 0x00ff0000) {
-			fprintf(f, "\n  match IP protocol %d",
-				ntohl(key->val) >> 16);
+			fprintf(f, "\n  match IP protocol %d", ntohl(key->val) >> 16);
 			return;
 		}
 		break;
 	case 12:
 	case 16: {
 			int bits = mask2bits(key->mask);
-
 			if (bits >= 0) {
 				fprintf(f, "\n  %s %s/%d",
 					key->off == 12 ? "match IP src" : "match IP dst",
@@ -954,7 +946,7 @@
 	__u16 pad;
 	void (*pprinter)(FILE *f, const struct tc_u32_key *key);
 } u32_pprinters[] = {
-	{0,	   0, print_raw},
+	{0, 	   0, print_raw},
 	{ETH_P_IP, 0, print_ipv4},
 	{ETH_P_IPV6, 0, print_ipv6},
 };
@@ -963,10 +955,10 @@
 {
 	int i = 0;
 
-	if (!pretty)
+	if (!show_pretty)
 		goto show_k;
 
-	for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) {
+	for (i = 0; i < sizeof(u32_pprinters) / sizeof(u32_pprinters[0]); i++) {
 		if (u32_pprinters[i].proto == ntohs(f_proto)) {
 show_k:
 			u32_pprinters[i].pprinter(f, key);
@@ -984,14 +976,15 @@
 	struct {
 		struct tc_u32_sel sel;
 		struct tc_u32_key keys[128];
-	} sel = {};
+	} sel;
 	struct tcmsg *t = NLMSG_DATA(n);
 	struct rtattr *tail;
 	int sel_ok = 0, terminal_ok = 0;
 	int sample_ok = 0;
 	__u32 htid = 0;
 	__u32 order = 0;
-	__u32 flags = 0;
+
+	memset(&sel, 0, sizeof(sel));
 
 	if (handle && get_u32_handle(&t->tcm_handle, handle)) {
 		fprintf(stderr, "Illegal filter ID\n");
@@ -1001,7 +994,8 @@
 	if (argc == 0)
 		return 0;
 
-	tail = addattr_nest(n, MAX_MSG, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "match") == 0) {
@@ -1028,18 +1022,16 @@
 			continue;
 		} else if (matches(*argv, "classid") == 0 ||
 			   strcmp(*argv, "flowid") == 0) {
-			unsigned int flowid;
-
+			unsigned handle;
 			NEXT_ARG();
-			if (get_tc_classid(&flowid, *argv)) {
+			if (get_tc_classid(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"classid\"\n");
 				return -1;
 			}
-			addattr_l(n, MAX_MSG, TCA_U32_CLASSID, &flowid, 4);
+			addattr_l(n, MAX_MSG, TCA_U32_CLASSID, &handle, 4);
 			sel.sel.flags |= TC_U32_TERMINAL;
 		} else if (matches(*argv, "divisor") == 0) {
-			unsigned int divisor;
-
+			unsigned divisor;
 			NEXT_ARG();
 			if (get_unsigned(&divisor, *argv, 0) ||
 			    divisor == 0 ||
@@ -1055,56 +1047,55 @@
 				return -1;
 			}
 		} else if (strcmp(*argv, "link") == 0) {
-			unsigned int linkid;
-
+			unsigned handle;
 			NEXT_ARG();
-			if (get_u32_handle(&linkid, *argv)) {
+			if (get_u32_handle(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"link\"\n");
 				return -1;
 			}
-			if (linkid && TC_U32_NODE(linkid)) {
+			if (handle && TC_U32_NODE(handle)) {
 				fprintf(stderr, "\"link\" must be a hash table.\n");
 				return -1;
 			}
-			addattr_l(n, MAX_MSG, TCA_U32_LINK, &linkid, 4);
+			addattr_l(n, MAX_MSG, TCA_U32_LINK, &handle, 4);
 		} else if (strcmp(*argv, "ht") == 0) {
-			unsigned int ht;
-
+			unsigned handle;
 			NEXT_ARG();
-			if (get_u32_handle(&ht, *argv)) {
+			if (get_u32_handle(&handle, *argv)) {
 				fprintf(stderr, "Illegal \"ht\"\n");
 				return -1;
 			}
-			if (handle && TC_U32_NODE(ht)) {
+			if (handle && TC_U32_NODE(handle)) {
 				fprintf(stderr, "\"ht\" must be a hash table.\n");
 				return -1;
 			}
 			if (sample_ok)
-				htid = (htid & 0xFF000) | (ht & 0xFFF00000);
+				htid = (htid & 0xFF000) | (handle & 0xFFF00000);
 			else
-				htid = (ht & 0xFFFFF000);
+				htid = (handle & 0xFFFFF000);
 		} else if (strcmp(*argv, "sample") == 0) {
 			__u32 hash;
-			unsigned int divisor = 0x100;
+			unsigned divisor = 0x100;
+
 			struct {
 				struct tc_u32_sel sel;
 				struct tc_u32_key keys[4];
-			} sel2 = {};
-
+			} sel2;
+			memset(&sel2, 0, sizeof(sel2));
 			NEXT_ARG();
 			if (parse_selector(&argc, &argv, &sel2.sel, n)) {
 				fprintf(stderr, "Illegal \"sample\"\n");
 				return -1;
 			}
 			if (sel2.sel.nkeys != 1) {
-				fprintf(stderr, "\"sample\" must contain exactly ONE key.\n");
+				fprintf(stderr, "\"sample\" must contain"
+					" exactly ONE key.\n");
 				return -1;
 			}
 			if (*argv != 0 && strcmp(*argv, "divisor") == 0) {
 				NEXT_ARG();
-				if (get_unsigned(&divisor, *argv, 0) ||
-				    divisor == 0 || divisor > 0x100 ||
-				    ((divisor - 1) & divisor)) {
+				if (get_unsigned(&divisor, *argv, 0) || divisor == 0 ||
+				    divisor > 0x100 || ((divisor - 1) & divisor)) {
 					fprintf(stderr, "Illegal sample \"divisor\"\n");
 					return -1;
 				}
@@ -1117,17 +1108,16 @@
 			sample_ok = 1;
 			continue;
 		} else if (strcmp(*argv, "indev") == 0) {
-			char ind[IFNAMSIZ + 1] = {};
-
+			char ind[IFNAMSIZ + 1];
+			memset(ind, 0, sizeof (ind));
 			argc--;
 			argv++;
 			if (argc < 1) {
 				fprintf(stderr, "Illegal indev\n");
 				return -1;
 			}
-			strncpy(ind, *argv, sizeof(ind) - 1);
-			addattr_l(n, MAX_MSG, TCA_U32_INDEV, ind,
-				  strlen(ind) + 1);
+			strncpy(ind, *argv, sizeof (ind) - 1);
+			addattr_l(n, MAX_MSG, TCA_U32_INDEV, ind, strlen(ind) + 1);
 
 		} else if (matches(*argv, "action") == 0) {
 			NEXT_ARG();
@@ -1146,10 +1136,6 @@
 			}
 			terminal_ok++;
 			continue;
-		} else if (strcmp(*argv, "skip_hw") == 0) {
-			flags |= TCA_CLS_FLAGS_SKIP_HW;
-		} else if (strcmp(*argv, "skip_sw") == 0) {
-			flags |= TCA_CLS_FLAGS_SKIP_SW;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -1161,13 +1147,12 @@
 		argc--; argv++;
 	}
 
-	/* We don't necessarily need class/flowids */
+	/* We dont necessarily need class/flowids */
 	if (terminal_ok)
 		sel.sel.flags |= TC_U32_TERMINAL;
 
 	if (order) {
-		if (TC_U32_NODE(t->tcm_handle) &&
-		    order != TC_U32_NODE(t->tcm_handle)) {
+		if (TC_U32_NODE(t->tcm_handle) && order != TC_U32_NODE(t->tcm_handle)) {
 			fprintf(stderr, "\"order\" contradicts \"handle\"\n");
 			return -1;
 		}
@@ -1178,19 +1163,8 @@
 		addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4);
 	if (sel_ok)
 		addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel,
-			  sizeof(sel.sel) +
-			  sel.sel.nkeys * sizeof(struct tc_u32_key));
-	if (flags) {
-		if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW |
-			       TCA_CLS_FLAGS_SKIP_SW))) {
-			fprintf(stderr,
-				"skip_hw and skip_sw are mutually exclusive\n");
-			return -1;
-		}
-		addattr_l(n, MAX_MSG, TCA_U32_FLAGS, &flags, 4);
-	}
-
-	addattr_nest_end(n, tail);
+			  sizeof(sel.sel) + sel.sel.nkeys * sizeof(struct tc_u32_key));
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -1210,9 +1184,9 @@
 		SPRINT_BUF(b1);
 		fprintf(f, "fh %s ", sprint_u32_handle(handle, b1));
 	}
-
-	if (TC_U32_NODE(handle))
+	if (TC_U32_NODE(handle)) {
 		fprintf(f, "order %d ", TC_U32_NODE(handle));
+	}
 
 	if (tb[TCA_U32_SEL]) {
 		if (RTA_PAYLOAD(tb[TCA_U32_SEL])  < sizeof(*sel))
@@ -1222,11 +1196,9 @@
 	}
 
 	if (tb[TCA_U32_DIVISOR]) {
-		fprintf(f, "ht divisor %d ",
-			rta_getattr_u32(tb[TCA_U32_DIVISOR]));
+		fprintf(f, "ht divisor %d ", rta_getattr_u32(tb[TCA_U32_DIVISOR]));
 	} else if (tb[TCA_U32_HASH]) {
 		__u32 htid = rta_getattr_u32(tb[TCA_U32_HASH]);
-
 		fprintf(f, "key ht %x bkt %x ", TC_U32_USERHTID(htid),
 			TC_U32_HASH(htid));
 	} else {
@@ -1236,35 +1208,19 @@
 		SPRINT_BUF(b1);
 		fprintf(f, "%sflowid %s ",
 			!sel || !(sel->flags & TC_U32_TERMINAL) ? "*" : "",
-			sprint_tc_classid(rta_getattr_u32(tb[TCA_U32_CLASSID]),
-					  b1));
+			sprint_tc_classid(rta_getattr_u32(tb[TCA_U32_CLASSID]), b1));
 	} else if (sel && sel->flags & TC_U32_TERMINAL) {
 		fprintf(f, "terminal flowid ??? ");
 	}
 	if (tb[TCA_U32_LINK]) {
 		SPRINT_BUF(b1);
 		fprintf(f, "link %s ",
-			sprint_u32_handle(rta_getattr_u32(tb[TCA_U32_LINK]),
-					  b1));
-	}
-
-	if (tb[TCA_U32_FLAGS]) {
-		__u32 flags = rta_getattr_u32(tb[TCA_U32_FLAGS]);
-
-		if (flags & TCA_CLS_FLAGS_SKIP_HW)
-			fprintf(f, "skip_hw ");
-		if (flags & TCA_CLS_FLAGS_SKIP_SW)
-			fprintf(f, "skip_sw ");
-
-		if (flags & TCA_CLS_FLAGS_IN_HW)
-			fprintf(f, "in_hw ");
-		else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
-			fprintf(f, "not_in_hw ");
+			sprint_u32_handle(rta_getattr_u32(tb[TCA_U32_LINK]), b1));
 	}
 
 	if (tb[TCA_U32_PCNT]) {
 		if (RTA_PAYLOAD(tb[TCA_U32_PCNT])  < sizeof(*pf)) {
-			fprintf(f, "Broken perf counters\n");
+			fprintf(f, "Broken perf counters \n");
 			return -1;
 		}
 		pf = RTA_DATA(tb[TCA_U32_PCNT]);
@@ -1277,7 +1233,6 @@
 
 	if (tb[TCA_U32_MARK]) {
 		struct tc_u32_mark *mark = RTA_DATA(tb[TCA_U32_MARK]);
-
 		if (RTA_PAYLOAD(tb[TCA_U32_MARK]) < sizeof(*mark)) {
 			fprintf(f, "\n  Invalid mark (kernel&iproute2 mismatch)\n");
 		} else {
@@ -1289,8 +1244,7 @@
 	if (sel) {
 		if (sel->nkeys) {
 			int i;
-
-			for (i = 0; i < sel->nkeys; i++) {
+			for (i=0; i<sel->nkeys; i++) {
 				show_keys(f, sel->keys + i);
 				if (show_stats && NULL != pf)
 					fprintf(f, " (success %llu ) ",
@@ -1320,15 +1274,13 @@
 		fprintf(f, "\n");
 		tc_print_police(f, tb[TCA_U32_POLICE]);
 	}
-
 	if (tb[TCA_U32_INDEV]) {
 		struct rtattr *idev = tb[TCA_U32_INDEV];
-
 		fprintf(f, "\n  input dev %s\n", rta_getattr_str(idev));
 	}
-
-	if (tb[TCA_U32_ACT])
-		tc_print_action(f, tb[TCA_U32_ACT], 0);
+	if (tb[TCA_U32_ACT]) {
+		tc_print_action(f, tb[TCA_U32_ACT]);
+	}
 
 	return 0;
 }
diff --git a/tc/m_action.c b/tc/m_action.c
index 36c744b..8d3d51e 100644
--- a/tc/m_action.c
+++ b/tc/m_action.c
@@ -11,12 +11,12 @@
  * TODO:
  * - parse to be passed a filedescriptor for logging purposes
  *
- */
+*/
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -28,11 +28,16 @@
 #include "tc_common.h"
 #include "tc_util.h"
 
-static struct action_util *action_list;
-#ifdef CONFIG_GACT
-static int gact_ld; /* f*ckin backward compatibility */
+static struct action_util * action_list;
+
+#ifdef ANDROID
+extern struct action_util mirred_action_util;
 #endif
-static int tab_flush;
+
+#ifdef CONFIG_GACT
+int gact_ld = 0 ; //fuckin backward compatibility
+#endif
+int tab_flush = 0;
 
 static void act_usage(void)
 {
@@ -42,21 +47,21 @@
 	 * with any action .so from the old days. But if someone really
 	 * does that, they would know how to fix this ..
 	 *
-	 */
+	*/
+	fprintf (stderr, "usage: tc actions <ACTSPECOP>*\n");
 	fprintf(stderr,
-		"usage: tc actions <ACTSPECOP>*\n"
-		"Where: 	ACTSPECOP := ACR | GD | FL\n"
-		"	ACR := add | change | replace <ACTSPEC>*\n"
-		"	GD := get | delete | <ACTISPEC>*\n"
-		"	FL := ls | list | flush | <ACTNAMESPEC>\n"
-		"	ACTNAMESPEC :=  action <ACTNAME>\n"
-		"	ACTISPEC := <ACTNAMESPEC> <INDEXSPEC>\n"
-		"	ACTSPEC := action <ACTDETAIL> [INDEXSPEC]\n"
-		"	INDEXSPEC := index <32 bit indexvalue>\n"
-		"	ACTDETAIL := <ACTNAME> <ACTPARAMS>\n"
-		"		Example ACTNAME is gact, mirred, bpf, etc\n"
-		"		Each action has its own parameters (ACTPARAMS)\n"
-		"\n");
+		"Where: \tACTSPECOP := ACR | GD | FL\n"
+			"\tACR := add | change | replace <ACTSPEC>* \n"
+			"\tGD := get | delete | <ACTISPEC>*\n"
+			"\tFL := ls | list | flush | <ACTNAMESPEC>\n"
+			"\tACTNAMESPEC :=  action <ACTNAME>\n"
+			"\tACTISPEC := <ACTNAMESPEC> <INDEXSPEC>\n"
+			"\tACTSPEC := action <ACTDETAIL> [INDEXSPEC]\n"
+			"\tINDEXSPEC := index <32 bit indexvalue>\n"
+			"\tACTDETAIL := <ACTNAME> <ACTPARAMS>\n"
+			"\t\tExample ACTNAME is gact, mirred, bpf, etc\n"
+			"\t\tEach action has its own parameters (ACTPARAMS)\n"
+			"\n");
 
 	exit(-1);
 }
@@ -65,28 +70,33 @@
 {
 	if (opt && RTA_PAYLOAD(opt))
 		fprintf(f, "[Unknown action, optlen=%u] ",
-			(unsigned int) RTA_PAYLOAD(opt));
+			(unsigned) RTA_PAYLOAD(opt));
 	return 0;
 }
 
-static int parse_noaopt(struct action_util *au, int *argc_p,
-			char ***argv_p, int code, struct nlmsghdr *n)
+static int parse_noaopt(struct action_util *au, int *argc_p, char ***argv_p, int code, struct nlmsghdr *n)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
 
-	if (argc)
-		fprintf(stderr,
-			"Unknown action \"%s\", hence option \"%s\" is unparsable\n",
-			au->id, *argv);
-	else
+	if (argc) {
+		fprintf(stderr, "Unknown action \"%s\", hence option \"%s\" is unparsable\n", au->id, *argv);
+	} else {
 		fprintf(stderr, "Unknown action \"%s\"\n", au->id);
-
+	}
 	return -1;
 }
 
 static struct action_util *get_action_kind(char *str)
 {
+#ifdef ANDROID
+	if (!strcmp(str, "mirred")) {
+		return &mirred_action_util;
+	} else {
+		fprintf(stderr, "Android does not support action '%s'", str);
+		return NULL;
+	}
+#endif
 	static void *aBODY;
 	void *dlh;
 	char buf[256];
@@ -125,12 +135,13 @@
 #ifdef CONFIG_GACT
 	if (!looked4gact) {
 		looked4gact = 1;
-		strcpy(str, "gact");
+		strcpy(str,"gact");
 		goto restart_s;
 	}
 #endif
-	a = calloc(1, sizeof(*a));
+	a = malloc(sizeof(*a));
 	if (a) {
+		memset(a, 0, sizeof(*a));
 		strncpy(a->id, "noact", 15);
 		a->parse_aopt = parse_noaopt;
 		a->print_aopt = print_noaopt;
@@ -139,46 +150,52 @@
 	return a;
 }
 
-static bool
+static int
 new_cmd(char **argv)
 {
-	return (matches(*argv, "change") == 0) ||
-		(matches(*argv, "replace") == 0) ||
-		(matches(*argv, "delete") == 0) ||
-		(matches(*argv, "get") == 0) ||
-		(matches(*argv, "add") == 0);
+	if ((matches(*argv, "change") == 0) ||
+		(matches(*argv, "replace") == 0)||
+		(matches(*argv, "delete") == 0)||
+		(matches(*argv, "get") == 0)||
+		(matches(*argv, "add") == 0))
+			return 1;
+
+	return 0;
+
 }
 
-int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
+int
+parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	struct rtattr *tail, *tail2;
-	char k[FILTER_NAMESZ];
-	int act_ck_len = 0;
+	char k[16];
 	int ok = 0;
 	int eap = 0; /* expect action parameters */
 
 	int ret = 0;
 	int prio = 0;
-	unsigned char act_ck[TC_COOKIE_MAX_SIZE];
 
 	if (argc <= 0)
 		return -1;
 
-	tail2 = addattr_nest(n, MAX_MSG, tca_id);
+	tail = tail2 = NLMSG_TAIL(n);
+
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 
 	while (argc > 0) {
 
-		memset(k, 0, sizeof(k));
+		memset(k, 0, sizeof (k));
 
-		if (strcmp(*argv, "action") == 0) {
+		if (strcmp(*argv, "action") == 0 ) {
 			argc--;
 			argv++;
 			eap = 1;
 #ifdef CONFIG_GACT
-			if (!gact_ld)
+			if (!gact_ld) {
 				get_action_kind("gact");
+			}
 #endif
 			continue;
 		} else if (strcmp(*argv, "flowid") == 0) {
@@ -191,13 +208,9 @@
 			goto done0;
 		} else {
 			struct action_util *a = NULL;
-
-			if (!action_a2n(*argv, NULL, false))
-				strncpy(k, "gact", sizeof(k) - 1);
-			else
-				strncpy(k, *argv, sizeof(k) - 1);
+			strncpy(k, *argv, sizeof (k) - 1);
 			eap = 0;
-			if (argc > 0) {
+			if (argc > 0 ) {
 				a = get_action_kind(k);
 			} else {
 done0:
@@ -207,60 +220,32 @@
 					goto done;
 			}
 
-			if (a == NULL)
+			if (NULL == a) {
 				goto bad_val;
+			}
 
-
-			tail = addattr_nest(n, MAX_MSG, ++prio);
+			tail = NLMSG_TAIL(n);
+			addattr_l(n, MAX_MSG, ++prio, NULL, 0);
 			addattr_l(n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
 
-			ret = a->parse_aopt(a, &argc, &argv,
-					    TCA_ACT_OPTIONS | NLA_F_NESTED,
-					    n);
+			ret = a->parse_aopt(a,&argc, &argv, TCA_ACT_OPTIONS, n);
 
 			if (ret < 0) {
-				fprintf(stderr, "bad action parsing\n");
+				fprintf(stderr,"bad action parsing\n");
 				goto bad_val;
 			}
-
-			if (*argv && strcmp(*argv, "cookie") == 0) {
-				size_t slen;
-
-				NEXT_ARG();
-				slen = strlen(*argv);
-				if (slen > TC_COOKIE_MAX_SIZE * 2) {
-					char cookie_err_m[128];
-
-					snprintf(cookie_err_m, 128,
-						 "%zd Max allowed size %d",
-						 slen, TC_COOKIE_MAX_SIZE*2);
-					invarg(cookie_err_m, *argv);
-				}
-
-				if (hex2mem(*argv, act_ck, slen / 2) < 0)
-					invarg("cookie must be a hex string\n",
-					       *argv);
-
-				act_ck_len = slen / 2;
-				argc--;
-				argv++;
-			}
-
-			if (act_ck_len)
-				addattr_l(n, MAX_MSG, TCA_ACT_COOKIE,
-					  &act_ck, act_ck_len);
-
-			addattr_nest_end(n, tail);
+			tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 			ok++;
 		}
+
 	}
 
 	if (eap > 0) {
-		fprintf(stderr, "bad action empty %d\n", eap);
+		fprintf(stderr,"bad action empty %d\n",eap);
 		goto bad_val;
 	}
 
-	addattr_nest_end(n, tail2);
+	tail2->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail2;
 
 done:
 	*argc_p = argc;
@@ -268,13 +253,13 @@
 	return 0;
 bad_val:
 	/* no need to undo things, returning from here should
-	 * cause enough pain
-	 */
-	fprintf(stderr, "parse_action: bad value (%d:%s)!\n", argc, *argv);
+	 * cause enough pain */
+	fprintf(stderr, "parse_action: bad value (%d:%s)!\n",argc,*argv);
 	return -1;
 }
 
-static int tc_print_one_action(FILE *f, struct rtattr *arg)
+static int
+tc_print_one_action(FILE * f, struct rtattr *arg)
 {
 
 	struct rtattr *tb[TCA_ACT_MAX + 1];
@@ -293,30 +278,18 @@
 
 
 	a = get_action_kind(RTA_DATA(tb[TCA_ACT_KIND]));
-	if (a == NULL)
+	if (NULL == a)
 		return err;
 
 	err = a->print_aopt(a, f, tb[TCA_ACT_OPTIONS]);
 
-	if (err < 0)
+	if (0 > err)
 		return err;
 
 	if (show_stats && tb[TCA_ACT_STATS]) {
-		print_string(PRINT_FP, NULL, "\tAction statistics:", NULL);
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-		open_json_object("stats");
+		fprintf(f, "\tAction statistics:\n");
 		print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL);
-		close_json_object();
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-	}
-	if (tb[TCA_ACT_COOKIE]) {
-		int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]);
-		char b1[strsz * 2 + 1];
-
-		print_string(PRINT_ANY, "cookie", "\tcookie %s",
-			     hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),
-					   strsz, b1, sizeof(b1)));
-		print_string(PRINT_FP, NULL, "%s", _SL_);
+		fprintf(f, "\n");
 	}
 
 	return 0;
@@ -339,61 +312,51 @@
 	}
 
 	a = get_action_kind(RTA_DATA(tb[TCA_KIND]));
-	if (a == NULL)
+	if (NULL == a)
 		return err;
 
 	delete_count = RTA_DATA(tb[TCA_FCNT]);
-	fprintf(f, " %s (%d entries)\n", a->id, *delete_count);
+	fprintf(f," %s (%d entries)\n", a->id, *delete_count);
 	tab_flush = 0;
 	return 0;
 }
 
 int
-tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
+tc_print_action(FILE *f, const struct rtattr *arg)
 {
 
 	int i;
+	struct rtattr *tb[TCA_ACT_MAX_PRIO + 1];
 
 	if (arg == NULL)
 		return 0;
 
-	if (!tot_acts)
-		tot_acts = TCA_ACT_MAX_PRIO;
+	parse_rtattr_nested(tb, TCA_ACT_MAX_PRIO, arg);
 
-	struct rtattr *tb[tot_acts + 1];
-
-	parse_rtattr_nested(tb, tot_acts, arg);
-
-	if (tab_flush && tb[0] && !tb[1])
+	if (tab_flush && NULL != tb[0]  && NULL == tb[1])
 		return tc_print_action_flush(f, tb[0]);
 
-	open_json_array(PRINT_JSON, "actions");
-	for (i = 0; i <= tot_acts; i++) {
+	for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
 		if (tb[i]) {
-			open_json_object(NULL);
-			print_string(PRINT_FP, NULL, "%s", _SL_);
-			print_uint(PRINT_ANY, "order",
-				   "\taction order %u: ", i);
-			if (tc_print_one_action(f, tb[i]) < 0) {
-				print_string(PRINT_FP, NULL,
-					     "Error printing action\n", NULL);
+			fprintf(f, "\n\taction order %d: ", i);
+			if (0 > tc_print_one_action(f, tb[i])) {
+				fprintf(f, "Error printing action\n");
 			}
-			close_json_object();
 		}
 
 	}
-	close_json_array(PRINT_JSON, NULL);
 
 	return 0;
 }
 
-int print_action(struct nlmsghdr *n, void *arg)
+int print_action(const struct sockaddr_nl *who,
+			   struct nlmsghdr *n,
+			   void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct tcamsg *t = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	__u32 *tot_acts = NULL;
-	struct rtattr *tb[TCA_ROOT_MAX+1];
+	struct rtattr * tb[TCAA_MAX+1];
 
 	len -= NLMSG_LENGTH(sizeof(*t));
 
@@ -402,17 +365,9 @@
 		return -1;
 	}
 
-	parse_rtattr(tb, TCA_ROOT_MAX, TA_RTA(t), len);
+	parse_rtattr(tb, TCAA_MAX, TA_RTA(t), len);
 
-	if (tb[TCA_ROOT_COUNT])
-		tot_acts = RTA_DATA(tb[TCA_ROOT_COUNT]);
-
-	open_json_object(NULL);
-	print_uint(PRINT_ANY, "total acts", "total acts %u",
-		   tot_acts ? *tot_acts : 0);
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	close_json_object();
-	if (tb[TCA_ACT_TAB] == NULL) {
+	if (NULL == tb[TCA_ACT_TAB]) {
 		if (n->nlmsg_type != RTM_GETACTION)
 			fprintf(stderr, "print_action: NULL kind\n");
 		return -1;
@@ -423,36 +378,27 @@
 			fprintf(fp, "Flushed table ");
 			tab_flush = 1;
 		} else {
-			fprintf(fp, "Deleted action ");
+			fprintf(fp, "deleted action ");
 		}
 	}
 
-	if (n->nlmsg_type == RTM_NEWACTION) {
-		if ((n->nlmsg_flags & NLM_F_CREATE) &&
-		    !(n->nlmsg_flags & NLM_F_REPLACE)) {
-			fprintf(fp, "Added action ");
-		} else if (n->nlmsg_flags & NLM_F_REPLACE) {
-			fprintf(fp, "Replaced action ");
-		}
-	}
-
-	open_json_object(NULL);
-	tc_print_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0);
-	close_json_object();
+	if (n->nlmsg_type == RTM_NEWACTION)
+		fprintf(fp, "Added action ");
+	tc_print_action(fp, tb[TCA_ACT_TAB]);
 
 	return 0;
 }
 
-static int tc_action_gd(int cmd, unsigned int flags,
-			int *argc_p, char ***argv_p)
+static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
 {
-	char k[FILTER_NAMESZ];
+	char k[16];
 	struct action_util *a = NULL;
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int prio = 0;
 	int ret = 0;
-	__u32 i = 0;
+	__u32 i;
+	struct sockaddr_nl nladdr;
 	struct rtattr *tail;
 	struct rtattr *tail2;
 	struct nlmsghdr *ans = NULL;
@@ -461,21 +407,27 @@
 		struct nlmsghdr         n;
 		struct tcamsg           t;
 		char                    buf[MAX_MSG];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.t.tca_family = AF_UNSPEC,
-	};
+	} req;
 
-	argc -= 1;
-	argv += 1;
+	req.t.tca_family = AF_UNSPEC;
+
+	memset(&req, 0, sizeof(req));
+
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	argc -=1;
+	argv +=1;
 
 
-	tail = addattr_nest(&req.n, MAX_MSG, TCA_ACT_TAB);
+	tail = NLMSG_TAIL(&req.n);
+	addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0);
 
 	while (argc > 0) {
-		if (strcmp(*argv, "action") == 0) {
+		if (strcmp(*argv, "action") == 0 ) {
 			argc--;
 			argv++;
 			continue;
@@ -483,24 +435,23 @@
 			return -1;
 		}
 
-		strncpy(k, *argv, sizeof(k) - 1);
+		strncpy(k, *argv, sizeof (k) - 1);
 		a = get_action_kind(k);
-		if (a == NULL) {
-			fprintf(stderr, "Error: non existent action: %s\n", k);
+		if (NULL == a) {
+			fprintf(stderr, "Error: non existent action: %s\n",k);
 			ret = -1;
 			goto bad_val;
 		}
 		if (strcmp(a->id, k) != 0) {
-			fprintf(stderr, "Error: non existent action: %s\n", k);
+			fprintf(stderr, "Error: non existent action: %s\n",k);
 			ret = -1;
 			goto bad_val;
 		}
 
-		argc -= 1;
-		argv += 1;
+		argc -=1;
+		argv +=1;
 		if (argc <= 0) {
-			fprintf(stderr,
-				"Error: no index specified action: %s\n", k);
+			fprintf(stderr, "Error: no index specified action: %s\n",k);
 			ret = -1;
 			goto bad_val;
 		}
@@ -512,44 +463,37 @@
 				ret = -1;
 				goto bad_val;
 			}
-			argc -= 1;
-			argv += 1;
+			argc -=1;
+			argv +=1;
 		} else {
-			fprintf(stderr,
-				"Error: no index specified action: %s\n", k);
+			fprintf(stderr, "Error: no index specified action: %s\n",k);
 			ret = -1;
 			goto bad_val;
 		}
 
-		tail2 = addattr_nest(&req.n, MAX_MSG, ++prio);
+		tail2 = NLMSG_TAIL(&req.n);
+		addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
 		addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
-		if (i > 0)
-			addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i);
-		addattr_nest_end(&req.n, tail2);
+		addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i);
+		tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
 
 	}
 
-	addattr_nest_end(&req.n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
 
 	req.n.nlmsg_seq = rth.dump = ++rth.seq;
+	if (cmd == RTM_GETACTION)
+		ans = &req.n;
 
-	if (rtnl_talk(&rth, &req.n, cmd == RTM_DELACTION ? NULL : &ans) < 0) {
+	if (rtnl_talk(&rth, &req.n, ans, MAX_MSG) < 0) {
 		fprintf(stderr, "We have an error talking to the kernel\n");
 		return 1;
 	}
 
-	if (cmd == RTM_GETACTION) {
-		new_json_obj(json);
-		ret = print_action(ans, stdout);
-		if (ret < 0) {
-			fprintf(stderr, "Dump terminated\n");
-			free(ans);
-			delete_json_obj();
-			return 1;
-		}
-		delete_json_obj();
+	if (ans && print_action(NULL, &req.n, (void*)stdout) < 0) {
+		fprintf(stderr, "Dump terminated\n");
+		return 1;
 	}
-	free(ans);
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -557,33 +501,36 @@
 	return ret;
 }
 
-static int tc_action_modify(int cmd, unsigned int flags,
-			    int *argc_p, char ***argv_p)
+static int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int ret = 0;
+
+	struct rtattr *tail;
 	struct {
 		struct nlmsghdr         n;
 		struct tcamsg           t;
 		char                    buf[MAX_MSG];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.t.tca_family = AF_UNSPEC,
-	};
-	struct rtattr *tail = NLMSG_TAIL(&req.n);
+	} req;
 
-	argc -= 1;
-	argv += 1;
+	req.t.tca_family = AF_UNSPEC;
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	tail = NLMSG_TAIL(&req.n);
+	argc -=1;
+	argv +=1;
 	if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) {
 		fprintf(stderr, "Illegal \"action\"\n");
 		return -1;
 	}
 	tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0) {
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
 		fprintf(stderr, "We have an error talking to the kernel\n");
 		ret = -1;
 	}
@@ -594,82 +541,58 @@
 	return ret;
 }
 
-static int tc_act_list_or_flush(int *argc_p, char ***argv_p, int event)
+static int tc_act_list_or_flush(int argc, char **argv, int event)
 {
-	struct rtattr *tail, *tail2, *tail3, *tail4;
 	int ret = 0, prio = 0, msg_size = 0;
+	char k[16];
+	struct rtattr *tail,*tail2;
 	struct action_util *a = NULL;
-	struct nla_bitfield32 flag_select = { 0 };
-	char **argv = *argv_p;
-	__u32 msec_since = 0;
-	int argc = *argc_p;
-	char k[FILTER_NAMESZ];
 	struct {
 		struct nlmsghdr         n;
 		struct tcamsg           t;
 		char                    buf[MAX_MSG];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
-		.t.tca_family = AF_UNSPEC,
-	};
+	} req;
 
-	tail = addattr_nest(&req.n, MAX_MSG, TCA_ACT_TAB);
+	req.t.tca_family = AF_UNSPEC;
+
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
+
+	tail = NLMSG_TAIL(&req.n);
+	addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0);
 	tail2 = NLMSG_TAIL(&req.n);
 
-	strncpy(k, *argv, sizeof(k) - 1);
+	strncpy(k, *argv, sizeof (k) - 1);
 #ifdef CONFIG_GACT
-	if (!gact_ld)
+	if (!gact_ld) {
 		get_action_kind("gact");
-
+	}
 #endif
 	a = get_action_kind(k);
-	if (a == NULL) {
-		fprintf(stderr, "bad action %s\n", k);
+	if (NULL == a) {
+		fprintf(stderr,"bad action %s\n",k);
 		goto bad_val;
 	}
 	if (strcmp(a->id, k) != 0) {
-		fprintf(stderr, "bad action %s\n", k);
+		fprintf(stderr,"bad action %s\n",k);
 		goto bad_val;
 	}
-	strncpy(k, *argv, sizeof(k) - 1);
-
-	argc -= 1;
-	argv += 1;
-
-	if (argc && (strcmp(*argv, "since") == 0)) {
-		NEXT_ARG();
-		if (get_u32(&msec_since, *argv, 0))
-			invarg("dump time \"since\" is invalid", *argv);
-	}
+	strncpy(k, *argv, sizeof (k) - 1);
 
 	addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
 	addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
 	tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
-	addattr_nest_end(&req.n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
 
-	tail3 = NLMSG_TAIL(&req.n);
-	flag_select.value |= TCA_FLAG_LARGE_DUMP_ON;
-	flag_select.selector |= TCA_FLAG_LARGE_DUMP_ON;
-	addattr_l(&req.n, MAX_MSG, TCA_ROOT_FLAGS, &flag_select,
-		  sizeof(struct nla_bitfield32));
-	tail3->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail3;
-	if (msec_since) {
-		tail4 = NLMSG_TAIL(&req.n);
-		addattr32(&req.n, MAX_MSG, TCA_ROOT_TIME_DELTA, msec_since);
-		tail4->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail4;
-	}
-	msg_size = NLMSG_ALIGN(req.n.nlmsg_len)
-		- NLMSG_ALIGN(sizeof(struct nlmsghdr));
+	msg_size = NLMSG_ALIGN(req.n.nlmsg_len) - NLMSG_ALIGN(sizeof(struct nlmsghdr));
 
 	if (event == RTM_GETACTION) {
-		if (rtnl_dump_request(&rth, event,
-				      (void *)&req.t, msg_size) < 0) {
+		if (rtnl_dump_request(&rth, event, (void *)&req.t, msg_size) < 0) {
 			perror("Cannot send dump request");
 			return 1;
 		}
-		new_json_obj(json);
 		ret = rtnl_dump_filter(&rth, print_action, stdout);
-		delete_json_obj();
 	}
 
 	if (event == RTM_DELACTION) {
@@ -677,7 +600,7 @@
 		req.n.nlmsg_type = RTM_DELACTION;
 		req.n.nlmsg_flags |= NLM_F_ROOT;
 		req.n.nlmsg_flags |= NLM_F_REQUEST;
-		if (rtnl_talk(&rth, &req.n, NULL) < 0) {
+		if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
 			fprintf(stderr, "We have an error flushing\n");
 			return 1;
 		}
@@ -686,8 +609,6 @@
 
 bad_val:
 
-	*argc_p = argc;
-	*argv_p = argv;
 	return ret;
 }
 
@@ -699,56 +620,43 @@
 	while (argc > 0) {
 
 		if (matches(*argv, "add") == 0) {
-			ret =  tc_action_modify(RTM_NEWACTION,
-						NLM_F_EXCL | NLM_F_CREATE,
-						&argc, &argv);
+			ret =  tc_action_modify(RTM_NEWACTION, NLM_F_EXCL|NLM_F_CREATE, &argc, &argv);
 		} else if (matches(*argv, "change") == 0 ||
 			  matches(*argv, "replace") == 0) {
-			ret = tc_action_modify(RTM_NEWACTION,
-					       NLM_F_CREATE | NLM_F_REPLACE,
-					       &argc, &argv);
+			ret = tc_action_modify(RTM_NEWACTION, NLM_F_CREATE|NLM_F_REPLACE, &argc, &argv);
 		} else if (matches(*argv, "delete") == 0) {
-			argc -= 1;
-			argv += 1;
+			argc -=1;
+			argv +=1;
 			ret = tc_action_gd(RTM_DELACTION, 0,  &argc, &argv);
 		} else if (matches(*argv, "get") == 0) {
-			argc -= 1;
-			argv += 1;
+			argc -=1;
+			argv +=1;
 			ret = tc_action_gd(RTM_GETACTION, 0,  &argc, &argv);
-		} else if (matches(*argv, "list") == 0 ||
-			   matches(*argv, "show") == 0 ||
-			   matches(*argv, "lst") == 0) {
+		} else if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
+						|| matches(*argv, "lst") == 0) {
 			if (argc <= 2) {
 				act_usage();
 				return -1;
 			}
-
-			argc -= 2;
-			argv += 2;
-			return tc_act_list_or_flush(&argc, &argv,
-						    RTM_GETACTION);
+			return tc_act_list_or_flush(argc-2, argv+2, RTM_GETACTION);
 		} else if (matches(*argv, "flush") == 0) {
 			if (argc <= 2) {
 				act_usage();
 				return -1;
 			}
-
-			argc -= 2;
-			argv += 2;
-			return tc_act_list_or_flush(&argc, &argv,
-						    RTM_DELACTION);
+			return tc_act_list_or_flush(argc-2, argv+2, RTM_DELACTION);
 		} else if (matches(*argv, "help") == 0) {
 			act_usage();
 			return -1;
 		} else {
-			fprintf(stderr,
-				"Command \"%s\" is unknown, try \"tc actions help\".\n",
-				*argv);
-			return -1;
+
+			ret = -1;
 		}
 
-		if (ret < 0)
+		if (ret < 0) {
+			fprintf(stderr, "Command \"%s\" is unknown, try \"tc actions help\".\n", *argv);
 			return -1;
+		}
 	}
 
 	return 0;
diff --git a/tc/m_bpf.c b/tc/m_bpf.c
index e8d704b..c5e2fa5 100644
--- a/tc/m_bpf.c
+++ b/tc/m_bpf.c
@@ -17,68 +17,53 @@
 #include <linux/tc_act/tc_bpf.h>
 
 #include "utils.h"
-
 #include "tc_util.h"
-#include "bpf_util.h"
+#include "tc_bpf.h"
 
 static const enum bpf_prog_type bpf_type = BPF_PROG_TYPE_SCHED_ACT;
 
+static const int nla_tbl[BPF_NLA_MAX] = {
+	[BPF_NLA_OPS_LEN]	= TCA_ACT_BPF_OPS_LEN,
+	[BPF_NLA_OPS]		= TCA_ACT_BPF_OPS,
+	[BPF_NLA_FD]		= TCA_ACT_BPF_FD,
+	[BPF_NLA_NAME]		= TCA_ACT_BPF_NAME,
+};
+
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... bpf ... [ index INDEX ]\n"
-		"\n"
-		"BPF use case:\n"
-		" bytecode BPF_BYTECODE\n"
-		" bytecode-file FILE\n"
-		"\n"
-		"eBPF use case:\n"
-		" object-file FILE [ section ACT_NAME ] [ export UDS_FILE ]"
-		" [ verbose ]\n"
-		" object-pinned FILE\n"
-		"\n"
-		"Where BPF_BYTECODE := \'s,c t f k,c t f k,c t f k,...\'\n"
-		"c,t,f,k and s are decimals; s denotes number of 4-tuples\n"
-		"\n"
-		"Where FILE points to a file containing the BPF_BYTECODE string,\n"
-		"an ELF file containing eBPF map definitions and bytecode, or a\n"
-		"pinned eBPF program.\n"
-		"\n"
-		"Where ACT_NAME refers to the section name containing the\n"
-		"action (default \'%s\').\n"
-		"\n"
-		"Where UDS_FILE points to a unix domain socket file in order\n"
-		"to hand off control of all created eBPF maps to an agent.\n"
-		"\n"
-		"Where optionally INDEX points to an existing action, or\n"
-		"explicitly specifies an action index upon creation.\n",
-		bpf_prog_to_default_section(bpf_type));
+	fprintf(stderr, "Usage: ... bpf ... [ index INDEX ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "BPF use case:\n");
+	fprintf(stderr, " bytecode BPF_BYTECODE\n");
+	fprintf(stderr, " bytecode-file FILE\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "eBPF use case:\n");
+	fprintf(stderr, " object-file FILE [ section ACT_NAME ] [ export UDS_FILE ]");
+	fprintf(stderr, " [ verbose ]\n");
+	fprintf(stderr, " object-pinned FILE\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where BPF_BYTECODE := \'s,c t f k,c t f k,c t f k,...\'\n");
+	fprintf(stderr, "c,t,f,k and s are decimals; s denotes number of 4-tuples\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where FILE points to a file containing the BPF_BYTECODE string,\n");
+	fprintf(stderr, "an ELF file containing eBPF map definitions and bytecode, or a\n");
+	fprintf(stderr, "pinned eBPF program.\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where ACT_NAME refers to the section name containing the\n");
+	fprintf(stderr, "action (default \'%s\').\n", bpf_default_section(bpf_type));
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where UDS_FILE points to a unix domain socket file in order\n");
+	fprintf(stderr, "to hand off control of all created eBPF maps to an agent.\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Where optionally INDEX points to an existing action, or\n");
+	fprintf(stderr, "explicitly specifies an action index upon creation.\n");
 }
 
-static void bpf_cbpf_cb(void *nl, const struct sock_filter *ops, int ops_len)
-{
-	addattr16(nl, MAX_MSG, TCA_ACT_BPF_OPS_LEN, ops_len);
-	addattr_l(nl, MAX_MSG, TCA_ACT_BPF_OPS, ops,
-		  ops_len * sizeof(struct sock_filter));
-}
-
-static void bpf_ebpf_cb(void *nl, int fd, const char *annotation)
-{
-	addattr32(nl, MAX_MSG, TCA_ACT_BPF_FD, fd);
-	addattrstrz(nl, MAX_MSG, TCA_ACT_BPF_NAME, annotation);
-}
-
-static const struct bpf_cfg_ops bpf_cb_ops = {
-	.cbpf_cb = bpf_cbpf_cb,
-	.ebpf_cb = bpf_ebpf_cb,
-};
-
 static int bpf_parse_opt(struct action_util *a, int *ptr_argc, char ***ptr_argv,
 			 int tca_id, struct nlmsghdr *n)
 {
 	const char *bpf_obj = NULL, *bpf_uds_name = NULL;
-	struct tc_act_bpf parm = {};
-	struct bpf_cfg_in cfg = {};
+	struct tc_act_bpf parm;
 	bool seen_run = false;
 	struct rtattr *tail;
 	int argc, ret = 0;
@@ -92,28 +77,19 @@
 
 	NEXT_ARG();
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "run") == 0) {
 			NEXT_ARG();
-
-			if (seen_run)
-				duparg("run", *argv);
 opt_bpf:
 			seen_run = true;
-			cfg.type = bpf_type;
-			cfg.argc = argc;
-			cfg.argv = argv;
-
-			if (bpf_parse_and_load_common(&cfg, &bpf_cb_ops, n))
+			if (bpf_parse_common(&argc, &argv, nla_tbl, bpf_type,
+					     &bpf_obj, &bpf_uds_name, n)) {
+				fprintf(stderr, "Failed to retrieve (e)BPF data!\n");
 				return -1;
-
-			argc = cfg.argc;
-			argv = cfg.argv;
-
-			bpf_obj = cfg.object;
-			bpf_uds_name = cfg.uds;
+			}
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -128,8 +104,29 @@
 		NEXT_ARG_FWD();
 	}
 
-	parse_action_control_dflt(&argc, &argv, &parm.action,
-				  false, TC_ACT_PIPE);
+	memset(&parm, 0, sizeof(parm));
+	parm.action = TC_ACT_PIPE;
+
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			parm.action = TC_ACT_RECLASSIFY;
+			NEXT_ARG_FWD();
+		} else if (matches(*argv, "pipe") == 0) {
+			parm.action = TC_ACT_PIPE;
+			NEXT_ARG_FWD();
+		} else if (matches(*argv, "drop") == 0 ||
+			   matches(*argv, "shot") == 0) {
+			parm.action = TC_ACT_SHOT;
+			NEXT_ARG_FWD();
+		} else if (matches(*argv, "continue") == 0) {
+			parm.action = TC_ACT_UNSPEC;
+			NEXT_ARG_FWD();
+		} else if (matches(*argv, "pass") == 0 ||
+			   matches(*argv, "ok") == 0) {
+			parm.action = TC_ACT_OK;
+			NEXT_ARG_FWD();
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
@@ -144,7 +141,7 @@
 	}
 
 	addattr_l(n, MAX_MSG, TCA_ACT_BPF_PARMS, &parm, sizeof(parm));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	if (bpf_uds_name)
 		ret = bpf_send_map_fds(bpf_uds_name, bpf_obj);
@@ -159,7 +156,7 @@
 {
 	struct rtattr *tb[TCA_ACT_BPF_MAX + 1];
 	struct tc_act_bpf *parm;
-	int d_ok = 0;
+	SPRINT_BUF(action_buf);
 
 	if (arg == NULL)
 		return -1;
@@ -167,43 +164,32 @@
 	parse_rtattr_nested(tb, TCA_ACT_BPF_MAX, arg);
 
 	if (!tb[TCA_ACT_BPF_PARMS]) {
-		fprintf(stderr, "Missing bpf parameters\n");
+		fprintf(f, "[NULL bpf parameters]");
 		return -1;
 	}
 
 	parm = RTA_DATA(tb[TCA_ACT_BPF_PARMS]);
-	print_string(PRINT_ANY, "kind", "%s ", "bpf");
+	fprintf(f, "bpf ");
 
 	if (tb[TCA_ACT_BPF_NAME])
-		print_string(PRINT_ANY, "bpf_name", "%s ",
-			     rta_getattr_str(tb[TCA_ACT_BPF_NAME]));
+		fprintf(f, "%s ", rta_getattr_str(tb[TCA_ACT_BPF_NAME]));
+	else if (tb[TCA_ACT_BPF_FD])
+		fprintf(f, "pfd %u ", rta_getattr_u32(tb[TCA_ACT_BPF_FD]));
+
 	if (tb[TCA_ACT_BPF_OPS] && tb[TCA_ACT_BPF_OPS_LEN]) {
-		bpf_print_ops(tb[TCA_ACT_BPF_OPS],
+		bpf_print_ops(f, tb[TCA_ACT_BPF_OPS],
 			      rta_getattr_u16(tb[TCA_ACT_BPF_OPS_LEN]));
-		print_string(PRINT_FP, NULL, "%s", " ");
+		fprintf(f, " ");
 	}
 
-	if (tb[TCA_ACT_BPF_ID])
-		d_ok = bpf_dump_prog_info(f,
-					  rta_getattr_u32(tb[TCA_ACT_BPF_ID]));
-	if (!d_ok && tb[TCA_ACT_BPF_TAG]) {
-		SPRINT_BUF(b);
-
-		print_string(PRINT_ANY, "tag", "tag %s ",
-			     hexstring_n2a(RTA_DATA(tb[TCA_ACT_BPF_TAG]),
-			     RTA_PAYLOAD(tb[TCA_ACT_BPF_TAG]),
-			     b, sizeof(b)));
-	}
-
-	print_action_control(f, "default-action ", parm->action, _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", parm->index);
-	print_int(PRINT_ANY, "ref", " ref %d", parm->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);
+	fprintf(f, "default-action %s\n", action_n2a(parm->action, action_buf,
+		sizeof(action_buf)));
+	fprintf(f, "\tindex %d ref %d bind %d", parm->index, parm->refcnt,
+		parm->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_ACT_BPF_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_ACT_BPF_TM]);
-
 			print_tm(f, tm);
 		}
 	}
diff --git a/tc/m_connmark.c b/tc/m_connmark.c
index eac2348..6974c9b 100644
--- a/tc/m_connmark.c
+++ b/tc/m_connmark.c
@@ -27,12 +27,10 @@
 static void
 explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... connmark [zone ZONE] [CONTROL] [index <INDEX>]\n"
-		"where :\n"
+	fprintf(stderr, "Usage: ... connmark [zone ZONE] [BRANCH] [index <INDEX>]\n");
+	fprintf(stderr, "where :\n"
 		"\tZONE is the conntrack zone\n"
-		"\tCONTROL := reclassify | pipe | drop | continue | ok |\n"
-		"\t           goto chain <CHAIN_INDEX>\n");
+		"\tBRANCH := reclassify|pipe|drop|continue|ok\n");
 }
 
 static void
@@ -74,7 +72,7 @@
 		if (matches(*argv, "zone") == 0) {
 			NEXT_ARG();
 			if (get_u16(&sel.zone, *argv, 10)) {
-				fprintf(stderr, "connmark: Illegal \"zone\"\n");
+				fprintf(stderr, "simple: Illegal \"index\"\n");
 				return -1;
 			}
 			argc--;
@@ -82,13 +80,37 @@
 		}
 	}
 
-	parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_PIPE);
+	sel.action = TC_ACT_PIPE;
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			sel.action = TC_ACT_RECLASSIFY;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pipe") == 0) {
+			sel.action = TC_ACT_PIPE;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "drop") == 0 ||
+			   matches(*argv, "shot") == 0) {
+			sel.action = TC_ACT_SHOT;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "continue") == 0) {
+			sel.action = TC_ACT_UNSPEC;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pass") == 0) {
+			sel.action = TC_ACT_OK;
+			argc--;
+			argv++;
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
 			NEXT_ARG();
 			if (get_u32(&sel.index, *argv, 10)) {
-				fprintf(stderr, "connmark: Illegal \"index\"\n");
+				fprintf(stderr, "simple: Illegal \"index\"\n");
 				return -1;
 			}
 			argc--;
@@ -96,9 +118,10 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_CONNMARK_PARMS, &sel, sizeof(sel));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -115,29 +138,23 @@
 
 	parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg);
 	if (tb[TCA_CONNMARK_PARMS] == NULL) {
-		fprintf(stderr, "Missing connmark parameters\n");
+		fprintf(f, "[NULL connmark parameters]");
 		return -1;
 	}
 
 	ci = RTA_DATA(tb[TCA_CONNMARK_PARMS]);
 
-	print_string(PRINT_ANY, "kind", "%s ", "connmark");
-	print_uint(PRINT_ANY, "zone", "zone %u", ci->zone);
-	print_action_control(f, " ", ci->action, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", ci->index);
-	print_int(PRINT_ANY, "ref", " ref %d", ci->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", ci->bindcnt);
+	fprintf(f, " connmark zone %d\n", ci->zone);
+	fprintf(f, "\t index %d ref %d bind %d", ci->index,
+		ci->refcnt, ci->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_CONNMARK_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_CONNMARK_TM]);
-
 			print_tm(f, tm);
 		}
 	}
-	print_string(PRINT_FP, NULL, "%s", _SL_);
+	fprintf(f, "\n");
 
 	return 0;
 }
diff --git a/tc/m_csum.c b/tc/m_csum.c
index 3e3dc25..f7da6f0 100644
--- a/tc/m_csum.c
+++ b/tc/m_csum.c
@@ -24,7 +24,8 @@
 {
 	fprintf(stderr, "Usage: ... csum <UPDATE>\n"
 			"Where: UPDATE := <TARGET> [<UPDATE>]\n"
-			"       TARGET := { ip4h | icmp | igmp | tcp | udp | udplite | sctp | <SWEETS> }\n"
+			"       TARGET := { ip4h | icmp | igmp |"
+				" tcp | udp | udplite | <SWEETS> }\n"
 			"       SWEETS := { and | or | \'+\' }\n");
 }
 
@@ -44,7 +45,7 @@
 	if (argc <= 0)
 		return -1;
 
-	while (argc > 0) {
+	while(argc > 0) {
 		if ((matches(*argv, "iph") == 0) ||
 		    (matches(*argv, "ip4h") == 0) ||
 		    (matches(*argv, "ipv4h") == 0))
@@ -65,9 +66,6 @@
 		else if (matches(*argv, "udplite") == 0)
 			sel->update_flags |= TCA_CSUM_UPDATE_FLAG_UDPLITE;
 
-		else if (matches(*argv, "sctp") == 0)
-			sel->update_flags |= TCA_CSUM_UPDATE_FLAG_SCTP;
-
 		else if ((matches(*argv, "and") == 0) ||
 			 (matches(*argv, "or") == 0) ||
 			 (matches(*argv, "+") == 0))
@@ -88,13 +86,15 @@
 parse_csum(struct action_util *a, int *argc_p,
 	   char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
-	struct tc_csum sel = {};
+	struct tc_csum sel;
 
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int ok = 0;
 	struct rtattr *tail;
 
+	memset(&sel, 0, sizeof(sel));
+
 	while (argc > 0) {
 		if (matches(*argv, "csum") == 0) {
 			NEXT_ARG();
@@ -108,7 +108,8 @@
 			continue;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
-		} else {
+		}
+		else {
 			break;
 		}
 	}
@@ -123,7 +124,30 @@
 		return -1;
 	}
 
-	parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_OK);
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			sel.action = TC_ACT_RECLASSIFY;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pipe") == 0) {
+			sel.action = TC_ACT_PIPE;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "drop") == 0 ||
+			matches(*argv, "shot") == 0) {
+			sel.action = TC_ACT_SHOT;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "continue") == 0) {
+			sel.action = TC_ACT_UNSPEC;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pass") == 0) {
+			sel.action = TC_ACT_OK;
+			argc--;
+			argv++;
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
@@ -138,9 +162,10 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_CSUM_PARMS, &sel, sizeof(sel));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -149,7 +174,7 @@
 }
 
 static int
-print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
+print_csum(struct action_util *au, FILE * f, struct rtattr *arg)
 {
 	struct tc_csum *sel;
 
@@ -161,8 +186,7 @@
 	char *uflag_4 = "";
 	char *uflag_5 = "";
 	char *uflag_6 = "";
-	char *uflag_7 = "";
-	SPRINT_BUF(buf);
+	SPRINT_BUF(action_buf);
 
 	int uflag_count = 0;
 
@@ -172,7 +196,7 @@
 	parse_rtattr_nested(tb, TCA_CSUM_MAX, arg);
 
 	if (tb[TCA_CSUM_PARMS] == NULL) {
-		fprintf(stderr, "Missing csum parameters\n");
+		fprintf(f, "[NULL csum parameters]");
 		return -1;
 	}
 	sel = RTA_DATA(tb[TCA_CSUM_PARMS]);
@@ -188,36 +212,29 @@
 					", " flag_string : flag_string; \
 				uflag_count++;				\
 			}						\
-		} while (0)
+		} while(0)
 	CSUM_UFLAG_BUFFER(uflag_2, TCA_CSUM_UPDATE_FLAG_ICMP, "icmp");
 	CSUM_UFLAG_BUFFER(uflag_3, TCA_CSUM_UPDATE_FLAG_IGMP, "igmp");
 	CSUM_UFLAG_BUFFER(uflag_4, TCA_CSUM_UPDATE_FLAG_TCP, "tcp");
 	CSUM_UFLAG_BUFFER(uflag_5, TCA_CSUM_UPDATE_FLAG_UDP, "udp");
 	CSUM_UFLAG_BUFFER(uflag_6, TCA_CSUM_UPDATE_FLAG_UDPLITE, "udplite");
-	CSUM_UFLAG_BUFFER(uflag_7, TCA_CSUM_UPDATE_FLAG_SCTP, "sctp");
 	if (!uflag_count) {
 		uflag_1 = "?empty";
 	}
 
-	print_string(PRINT_ANY, "kind", "%s ", "csum");
-	snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s",
-		 uflag_1, uflag_2, uflag_3,
-		 uflag_4, uflag_5, uflag_6, uflag_7);
-	print_string(PRINT_ANY, "csum", "(%s) ", buf);
-
-	print_action_control(f, "action ", sel->action, "\n");
-	print_uint(PRINT_ANY, "index", "\tindex %u", sel->index);
-	print_int(PRINT_ANY, "ref", " ref %d", sel->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", sel->bindcnt);
+	fprintf(f, "csum (%s%s%s%s%s%s) action %s\n",
+		uflag_1, uflag_2, uflag_3,
+		uflag_4, uflag_5, uflag_6,
+		action_n2a(sel->action, action_buf, sizeof(action_buf)));
+	fprintf(f, "\tindex %d ref %d bind %d", sel->index, sel->refcnt, sel->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_CSUM_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_CSUM_TM]);
-
-			print_tm(f, tm);
+			print_tm(f,tm);
 		}
 	}
-	print_string(PRINT_FP, NULL, "%s", "\n");
+	fprintf(f, "\n");
 
 	return 0;
 }
diff --git a/tc/m_ct.c b/tc/m_ct.c
deleted file mode 100644
index 8df2f61..0000000
--- a/tc/m_ct.c
+++ /dev/null
@@ -1,496 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/* -
- * m_ct.c     Connection tracking action
- *
- * Authors:   Paul Blakey <paulb@mellanox.com>
- *            Yossi Kuperman <yossiku@mellanox.com>
- *            Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include "utils.h"
-#include "tc_util.h"
-#include <linux/tc_act/tc_ct.h>
-
-static void
-usage(void)
-{
-	fprintf(stderr,
-		"Usage: ct clear\n"
-		"	ct commit [force] [zone ZONE] [mark MASKED_MARK] [label MASKED_LABEL] [nat NAT_SPEC]\n"
-		"	ct [nat] [zone ZONE]\n"
-		"Where: ZONE is the conntrack zone table number\n"
-		"	NAT_SPEC is {src|dst} addr addr1[-addr2] [port port1[-port2]]\n"
-		"\n");
-	exit(-1);
-}
-
-static int ct_parse_nat_addr_range(const char *str, struct nlmsghdr *n)
-{
-	inet_prefix addr = { .family = AF_UNSPEC, };
-	char *addr1, *addr2 = 0;
-	SPRINT_BUF(buffer);
-	int attr;
-	int ret;
-
-	strncpy(buffer, str, sizeof(buffer) - 1);
-
-	addr1 = buffer;
-	addr2 = strchr(addr1, '-');
-	if (addr2) {
-		*addr2 = '\0';
-		addr2++;
-	}
-
-	ret = get_addr(&addr, addr1, AF_UNSPEC);
-	if (ret)
-		return ret;
-	attr = addr.family == AF_INET ? TCA_CT_NAT_IPV4_MIN :
-					TCA_CT_NAT_IPV6_MIN;
-	addattr_l(n, MAX_MSG, attr, addr.data, addr.bytelen);
-
-	if (addr2) {
-		ret = get_addr(&addr, addr2, addr.family);
-		if (ret)
-			return ret;
-	}
-	attr = addr.family == AF_INET ? TCA_CT_NAT_IPV4_MAX :
-					TCA_CT_NAT_IPV6_MAX;
-	addattr_l(n, MAX_MSG, attr, addr.data, addr.bytelen);
-
-	return 0;
-}
-
-static int ct_parse_nat_port_range(const char *str, struct nlmsghdr *n)
-{
-	char *port1, *port2 = 0;
-	SPRINT_BUF(buffer);
-	__be16 port;
-	int ret;
-
-	strncpy(buffer, str, sizeof(buffer) - 1);
-
-	port1 = buffer;
-	port2 = strchr(port1, '-');
-	if (port2) {
-		*port2 = '\0';
-		port2++;
-	}
-
-	ret = get_be16(&port, port1, 10);
-	if (ret)
-		return -1;
-	addattr16(n, MAX_MSG, TCA_CT_NAT_PORT_MIN, port);
-
-	if (port2) {
-		ret = get_be16(&port, port2, 10);
-		if (ret)
-			return -1;
-	}
-	addattr16(n, MAX_MSG, TCA_CT_NAT_PORT_MAX, port);
-
-	return 0;
-}
-
-
-static int ct_parse_u16(char *str, int value_type, int mask_type,
-			struct nlmsghdr *n)
-{
-	__u16 value, mask;
-	char *slash = 0;
-
-	if (mask_type != TCA_CT_UNSPEC) {
-		slash = strchr(str, '/');
-		if (slash)
-			*slash = '\0';
-	}
-
-	if (get_u16(&value, str, 0))
-		return -1;
-
-	if (slash) {
-		if (get_u16(&mask, slash + 1, 0))
-			return -1;
-	} else {
-		mask = UINT16_MAX;
-	}
-
-	addattr16(n, MAX_MSG, value_type, value);
-	if (mask_type != TCA_CT_UNSPEC)
-		addattr16(n, MAX_MSG, mask_type, mask);
-
-	return 0;
-}
-
-static int ct_parse_u32(char *str, int value_type, int mask_type,
-			struct nlmsghdr *n)
-{
-	__u32 value, mask;
-	char *slash;
-
-	slash = strchr(str, '/');
-	if (slash)
-		*slash = '\0';
-
-	if (get_u32(&value, str, 0))
-		return -1;
-
-	if (slash) {
-		if (get_u32(&mask, slash + 1, 0))
-			return -1;
-	} else {
-		mask = UINT32_MAX;
-	}
-
-	addattr32(n, MAX_MSG, value_type, value);
-	addattr32(n, MAX_MSG, mask_type, mask);
-
-	return 0;
-}
-
-static int ct_parse_mark(char *str, struct nlmsghdr *n)
-{
-	return ct_parse_u32(str, TCA_CT_MARK, TCA_CT_MARK_MASK, n);
-}
-
-static int ct_parse_labels(char *str, struct nlmsghdr *n)
-{
-#define LABELS_SIZE	16
-	uint8_t labels[LABELS_SIZE], lmask[LABELS_SIZE];
-	char *slash, *mask = NULL;
-	size_t slen, slen_mask = 0;
-
-	slash = index(str, '/');
-	if (slash) {
-		*slash = 0;
-		mask = slash+1;
-		slen_mask = strlen(mask);
-	}
-
-	slen = strlen(str);
-	if (slen > LABELS_SIZE*2 || slen_mask > LABELS_SIZE*2) {
-		char errmsg[128];
-
-		snprintf(errmsg, sizeof(errmsg),
-				"%zd Max allowed size %d",
-				slen, LABELS_SIZE*2);
-		invarg(errmsg, str);
-	}
-
-	if (hex2mem(str, labels, slen/2) < 0)
-		invarg("ct: labels must be a hex string\n", str);
-	addattr_l(n, MAX_MSG, TCA_CT_LABELS, labels, slen/2);
-
-	if (mask) {
-		if (hex2mem(mask, lmask, slen_mask/2) < 0)
-			invarg("ct: labels mask must be a hex string\n", mask);
-	} else {
-		memset(lmask, 0xff, sizeof(lmask));
-		slen_mask = sizeof(lmask)*2;
-	}
-	addattr_l(n, MAX_MSG, TCA_CT_LABELS_MASK, lmask, slen_mask/2);
-
-	return 0;
-}
-
-static int
-parse_ct(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
-		struct nlmsghdr *n)
-{
-	struct tc_ct sel = {};
-	char **argv = *argv_p;
-	struct rtattr *tail;
-	int argc = *argc_p;
-	int ct_action = 0;
-	int ret;
-
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-
-	if (argc && matches(*argv, "ct") == 0)
-		NEXT_ARG_FWD();
-
-	while (argc > 0) {
-		if (matches(*argv, "zone") == 0) {
-			NEXT_ARG();
-
-			if (ct_parse_u16(*argv,
-					 TCA_CT_ZONE, TCA_CT_UNSPEC, n)) {
-				fprintf(stderr, "ct: Illegal \"zone\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "nat") == 0) {
-			ct_action |= TCA_CT_ACT_NAT;
-
-			NEXT_ARG();
-			if (matches(*argv, "src") == 0)
-				ct_action |= TCA_CT_ACT_NAT_SRC;
-			else if (matches(*argv, "dst") == 0)
-				ct_action |= TCA_CT_ACT_NAT_DST;
-			else
-				continue;
-
-			NEXT_ARG();
-			if (matches(*argv, "addr") != 0)
-				usage();
-
-			NEXT_ARG();
-			ret = ct_parse_nat_addr_range(*argv, n);
-			if (ret) {
-				fprintf(stderr, "ct: Illegal nat address range\n");
-				return -1;
-			}
-
-			NEXT_ARG_FWD();
-			if (matches(*argv, "port") != 0)
-				continue;
-
-			NEXT_ARG();
-			ret = ct_parse_nat_port_range(*argv, n);
-			if (ret) {
-				fprintf(stderr, "ct: Illegal nat port range\n");
-				return -1;
-			}
-		} else if (matches(*argv, "clear") == 0) {
-			ct_action |= TCA_CT_ACT_CLEAR;
-		} else if (matches(*argv, "commit") == 0) {
-			ct_action |= TCA_CT_ACT_COMMIT;
-		} else if (matches(*argv, "force") == 0) {
-			ct_action |= TCA_CT_ACT_FORCE;
-		} else if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&sel.index, *argv, 10)) {
-				fprintf(stderr, "ct: Illegal \"index\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "mark") == 0) {
-			NEXT_ARG();
-
-			ret = ct_parse_mark(*argv, n);
-			if (ret) {
-				fprintf(stderr, "ct: Illegal \"mark\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "label") == 0) {
-			NEXT_ARG();
-
-			ret = ct_parse_labels(*argv, n);
-			if (ret) {
-				fprintf(stderr, "ct: Illegal \"label\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			break;
-		}
-		NEXT_ARG_FWD();
-	}
-
-	if (ct_action & TCA_CT_ACT_CLEAR &&
-	    ct_action & ~TCA_CT_ACT_CLEAR) {
-		fprintf(stderr, "ct: clear can only be used alone\n");
-		return -1;
-	}
-
-	if (ct_action & TCA_CT_ACT_NAT_SRC &&
-	    ct_action & TCA_CT_ACT_NAT_DST) {
-		fprintf(stderr, "ct: src and dst nat can't be used together\n");
-		return -1;
-	}
-
-	if ((ct_action & TCA_CT_ACT_COMMIT) &&
-	    (ct_action & TCA_CT_ACT_NAT) &&
-	    !(ct_action & (TCA_CT_ACT_NAT_SRC | TCA_CT_ACT_NAT_DST))) {
-		fprintf(stderr, "ct: commit and nat must set src or dst\n");
-		return -1;
-	}
-
-	if (!(ct_action & TCA_CT_ACT_COMMIT) &&
-	    (ct_action & (TCA_CT_ACT_NAT_SRC | TCA_CT_ACT_NAT_DST))) {
-		fprintf(stderr, "ct: src or dst is only valid if commit is set\n");
-		return -1;
-	}
-
-	parse_action_control_dflt(&argc, &argv, &sel.action, false,
-				  TC_ACT_PIPE);
-
-	addattr16(n, MAX_MSG, TCA_CT_ACTION, ct_action);
-	addattr_l(n, MAX_MSG, TCA_CT_PARMS, &sel, sizeof(sel));
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-static int ct_sprint_port(char *buf, const char *prefix, struct rtattr *attr)
-{
-	if (!attr)
-		return 0;
-
-	return sprintf(buf, "%s%d", prefix, rta_getattr_be16(attr));
-}
-
-static int ct_sprint_ip_addr(char *buf, const char *prefix,
-			     struct rtattr *attr)
-{
-	int family;
-	size_t len;
-
-	if (!attr)
-		return 0;
-
-	len = RTA_PAYLOAD(attr);
-
-	if (len == 4)
-		family = AF_INET;
-	else if (len == 16)
-		family = AF_INET6;
-	else
-		return 0;
-
-	return sprintf(buf, "%s%s", prefix, rt_addr_n2a_rta(family, attr));
-}
-
-static void ct_print_nat(int ct_action, struct rtattr **tb)
-{
-	size_t done = 0;
-	char out[256] = "";
-	bool nat;
-
-	if (!(ct_action & TCA_CT_ACT_NAT))
-		return;
-
-	if (ct_action & TCA_CT_ACT_NAT_SRC) {
-		nat = true;
-		done += sprintf(out + done, "src");
-	} else if (ct_action & TCA_CT_ACT_NAT_DST) {
-		nat = true;
-		done += sprintf(out + done, "dst");
-	}
-
-	if (nat) {
-		done += ct_sprint_ip_addr(out + done, " addr ",
-					  tb[TCA_CT_NAT_IPV4_MIN]);
-		done += ct_sprint_ip_addr(out + done, " addr ",
-					  tb[TCA_CT_NAT_IPV6_MIN]);
-		if (tb[TCA_CT_NAT_IPV4_MAX] &&
-		    memcmp(RTA_DATA(tb[TCA_CT_NAT_IPV4_MIN]),
-			   RTA_DATA(tb[TCA_CT_NAT_IPV4_MAX]), 4))
-			done += ct_sprint_ip_addr(out + done, "-",
-						  tb[TCA_CT_NAT_IPV4_MAX]);
-		else if (tb[TCA_CT_NAT_IPV6_MAX] &&
-			    memcmp(RTA_DATA(tb[TCA_CT_NAT_IPV6_MIN]),
-				   RTA_DATA(tb[TCA_CT_NAT_IPV6_MAX]), 16))
-			done += ct_sprint_ip_addr(out + done, "-",
-						  tb[TCA_CT_NAT_IPV6_MAX]);
-		done += ct_sprint_port(out + done, " port ",
-				       tb[TCA_CT_NAT_PORT_MIN]);
-		if (tb[TCA_CT_NAT_PORT_MAX] &&
-		    memcmp(RTA_DATA(tb[TCA_CT_NAT_PORT_MIN]),
-			   RTA_DATA(tb[TCA_CT_NAT_PORT_MAX]), 2))
-			done += ct_sprint_port(out + done, "-",
-					       tb[TCA_CT_NAT_PORT_MAX]);
-	}
-
-	if (done)
-		print_string(PRINT_ANY, "nat", " nat %s", out);
-	else
-		print_string(PRINT_ANY, "nat", " nat", "");
-}
-
-static void ct_print_labels(struct rtattr *attr,
-			    struct rtattr *mask_attr)
-{
-	const unsigned char *str;
-	bool print_mask = false;
-	char out[256], *p;
-	int data_len, i;
-
-	if (!attr)
-		return;
-
-	data_len = RTA_PAYLOAD(attr);
-	hexstring_n2a(RTA_DATA(attr), data_len, out, sizeof(out));
-	p = out + data_len*2;
-
-	data_len = RTA_PAYLOAD(attr);
-	str = RTA_DATA(mask_attr);
-	if (data_len != 16)
-		print_mask = true;
-	for (i = 0; !print_mask && i < data_len; i++) {
-		if (str[i] != 0xff)
-			print_mask = true;
-	}
-	if (print_mask) {
-		*p++ = '/';
-		hexstring_n2a(RTA_DATA(mask_attr), data_len, p,
-			      sizeof(out)-(p-out));
-		p += data_len*2;
-	}
-	*p = '\0';
-
-	print_string(PRINT_ANY, "label", " label %s", out);
-}
-
-static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	struct rtattr *tb[TCA_CT_MAX + 1];
-	const char *commit;
-	struct tc_ct *p;
-	int ct_action = 0;
-
-	if (arg == NULL)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_CT_MAX, arg);
-	if (tb[TCA_CT_PARMS] == NULL) {
-		print_string(PRINT_FP, NULL, "%s", "[NULL ct parameters]");
-		return -1;
-	}
-
-	p = RTA_DATA(tb[TCA_CT_PARMS]);
-
-	print_string(PRINT_ANY, "kind", "%s", "ct");
-
-	if (tb[TCA_CT_ACTION])
-		ct_action = rta_getattr_u16(tb[TCA_CT_ACTION]);
-	if (ct_action & TCA_CT_ACT_COMMIT) {
-		commit = ct_action & TCA_CT_ACT_FORCE ?
-			 "commit force" : "commit";
-		print_string(PRINT_ANY, "action", " %s", commit);
-	} else if (ct_action & TCA_CT_ACT_CLEAR) {
-		print_string(PRINT_ANY, "action", " %s", "clear");
-	}
-
-	print_masked_u32("mark", tb[TCA_CT_MARK], tb[TCA_CT_MARK_MASK], false);
-	print_masked_u16("zone", tb[TCA_CT_ZONE], NULL, false);
-	ct_print_labels(tb[TCA_CT_LABELS], tb[TCA_CT_LABELS_MASK]);
-	ct_print_nat(ct_action, tb);
-
-	print_action_control(f, " ", p->action, "");
-
-	print_uint(PRINT_ANY, "index", "\n\t index %u", p->index);
-	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
-
-	if (show_stats) {
-		if (tb[TCA_CT_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_CT_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-	print_string(PRINT_FP, NULL, "%s", "\n ");
-
-	return 0;
-}
-
-struct action_util ct_action_util = {
-	.id = "ct",
-	.parse_aopt = parse_ct,
-	.print_aopt = print_ct,
-};
diff --git a/tc/m_ctinfo.c b/tc/m_ctinfo.c
deleted file mode 100644
index 5e451f8..0000000
--- a/tc/m_ctinfo.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * m_ctinfo.c		netfilter ctinfo mark action
- *
- * Copyright (c) 2019 Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include "utils.h"
-#include "tc_util.h"
-#include <linux/tc_act/tc_ctinfo.h>
-
-static void
-explain(void)
-{
-	fprintf(stderr,
-		"Usage: ... ctinfo [dscp mask [statemask]] [cpmark [mask]] [zone ZONE] [CONTROL] [index <INDEX>]\n"
-		"where :\n"
-		"\tdscp   MASK bitmask location of stored DSCP\n"
-		"\t       STATEMASK bitmask to determine conditional restoring\n"
-		"\tcpmark MASK mask applied to mark on restoration\n"
-		"\tZONE is the conntrack zone\n"
-		"\tCONTROL := reclassify | pipe | drop | continue | ok |\n"
-		"\t           goto chain <CHAIN_INDEX>\n");
-}
-
-static void
-usage(void)
-{
-	explain();
-	exit(-1);
-}
-
-static int
-parse_ctinfo(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
-	     struct nlmsghdr *n)
-{
-	unsigned int cpmarkmask = 0, dscpmask = 0, dscpstatemask = 0;
-	struct tc_ctinfo sel = {};
-	unsigned short zone = 0;
-	char **argv = *argv_p;
-	struct rtattr *tail;
-	int argc = *argc_p;
-	int ok = 0;
-	__u8 i;
-
-	while (argc > 0) {
-		if (matches(*argv, "ctinfo") == 0) {
-			ok = 1;
-			NEXT_ARG_FWD();
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			break;
-		}
-
-	}
-
-	if (!ok) {
-		explain();
-		return -1;
-	}
-
-	if (argc) {
-		if (matches(*argv, "dscp") == 0) {
-			NEXT_ARG();
-			if (get_u32(&dscpmask, *argv, 0)) {
-				fprintf(stderr,
-					"ctinfo: Illegal dscp \"mask\"\n");
-				return -1;
-			}
-			if (NEXT_ARG_OK()) {
-				NEXT_ARG_FWD();
-				if (!get_u32(&dscpstatemask, *argv, 0))
-					NEXT_ARG_FWD(); /* was a statemask */
-			} else {
-				NEXT_ARG_FWD();
-			}
-		}
-	}
-
-	/* cpmark has optional mask parameter, so the next arg might not  */
-	/* exist, or it might be the next option, or it may actually be a */
-	/* 32bit mask */
-	if (argc) {
-		if (matches(*argv, "cpmark") == 0) {
-			cpmarkmask = ~0;
-			if (NEXT_ARG_OK()) {
-				NEXT_ARG_FWD();
-				if (!get_u32(&cpmarkmask, *argv, 0))
-					NEXT_ARG_FWD(); /* was a mask */
-			} else {
-				NEXT_ARG_FWD();
-			}
-		}
-	}
-
-	if (argc) {
-		if (matches(*argv, "zone") == 0) {
-			NEXT_ARG();
-			if (get_u16(&zone, *argv, 10)) {
-				fprintf(stderr, "ctinfo: Illegal \"zone\"\n");
-				return -1;
-			}
-			NEXT_ARG_FWD();
-		}
-	}
-
-	parse_action_control_dflt(&argc, &argv, &sel.action,
-				  false, TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&sel.index, *argv, 10)) {
-				fprintf(stderr, "ctinfo: Illegal \"index\"\n");
-				return -1;
-			}
-			NEXT_ARG_FWD();
-		}
-	}
-
-	if (dscpmask & dscpstatemask) {
-		fprintf(stderr,
-			"ctinfo: dscp mask & statemask must NOT overlap\n");
-		return -1;
-	}
-
-	i = ffs(dscpmask);
-	if (i && ((~0 & (dscpmask >> (i - 1))) != 0x3f)) {
-		fprintf(stderr,
-			"ctinfo: dscp mask must be 6 contiguous bits long\n");
-		return -1;
-	}
-
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	addattr_l(n, MAX_MSG, TCA_CTINFO_ACT, &sel, sizeof(sel));
-	addattr16(n, MAX_MSG, TCA_CTINFO_ZONE, zone);
-
-	if (dscpmask)
-		addattr32(n, MAX_MSG,
-			  TCA_CTINFO_PARMS_DSCP_MASK, dscpmask);
-
-	if (dscpstatemask)
-		addattr32(n, MAX_MSG,
-			  TCA_CTINFO_PARMS_DSCP_STATEMASK, dscpstatemask);
-
-	if (cpmarkmask)
-		addattr32(n, MAX_MSG,
-			  TCA_CTINFO_PARMS_CPMARK_MASK, cpmarkmask);
-
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-static void print_ctinfo_stats(FILE *f, struct rtattr *tb[TCA_CTINFO_MAX + 1])
-{
-	struct tcf_t *tm;
-
-	if (tb[TCA_CTINFO_TM]) {
-		tm = RTA_DATA(tb[TCA_CTINFO_TM]);
-
-		print_tm(f, tm);
-	}
-
-	if (tb[TCA_CTINFO_STATS_DSCP_SET])
-		print_lluint(PRINT_ANY, "dscpset", " DSCP set %llu",
-			     rta_getattr_u64(tb[TCA_CTINFO_STATS_DSCP_SET]));
-	if (tb[TCA_CTINFO_STATS_DSCP_ERROR])
-		print_lluint(PRINT_ANY, "dscperror", " error %llu",
-			     rta_getattr_u64(tb[TCA_CTINFO_STATS_DSCP_ERROR]));
-
-	if (tb[TCA_CTINFO_STATS_CPMARK_SET])
-		print_lluint(PRINT_ANY, "cpmarkset", " CPMARK set %llu",
-			     rta_getattr_u64(tb[TCA_CTINFO_STATS_CPMARK_SET]));
-}
-
-static int print_ctinfo(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	unsigned int cpmarkmask = ~0, dscpmask = 0, dscpstatemask = 0;
-	struct rtattr *tb[TCA_CTINFO_MAX + 1];
-	unsigned short zone = 0;
-	struct tc_ctinfo *ci;
-
-	if (arg == NULL)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_CTINFO_MAX, arg);
-	if (!tb[TCA_CTINFO_ACT]) {
-		print_string(PRINT_FP, NULL, "%s",
-			     "[NULL ctinfo action parameters]");
-		return -1;
-	}
-
-	ci = RTA_DATA(tb[TCA_CTINFO_ACT]);
-
-	if (tb[TCA_CTINFO_PARMS_DSCP_MASK]) {
-		if (RTA_PAYLOAD(tb[TCA_CTINFO_PARMS_DSCP_MASK]) >=
-		    sizeof(__u32))
-			dscpmask = rta_getattr_u32(
-					tb[TCA_CTINFO_PARMS_DSCP_MASK]);
-		else
-			print_string(PRINT_FP, NULL, "%s",
-				     "[invalid dscp mask parameter]");
-	}
-
-	if (tb[TCA_CTINFO_PARMS_DSCP_STATEMASK]) {
-		if (RTA_PAYLOAD(tb[TCA_CTINFO_PARMS_DSCP_STATEMASK]) >=
-		    sizeof(__u32))
-			dscpstatemask = rta_getattr_u32(
-					tb[TCA_CTINFO_PARMS_DSCP_STATEMASK]);
-		else
-			print_string(PRINT_FP, NULL, "%s",
-				     "[invalid dscp statemask parameter]");
-	}
-
-	if (tb[TCA_CTINFO_PARMS_CPMARK_MASK]) {
-		if (RTA_PAYLOAD(tb[TCA_CTINFO_PARMS_CPMARK_MASK]) >=
-		    sizeof(__u32))
-			cpmarkmask = rta_getattr_u32(
-					tb[TCA_CTINFO_PARMS_CPMARK_MASK]);
-		else
-			print_string(PRINT_FP, NULL, "%s",
-				     "[invalid cpmark mask parameter]");
-	}
-
-	if (tb[TCA_CTINFO_ZONE] && RTA_PAYLOAD(tb[TCA_CTINFO_ZONE]) >=
-	    sizeof(__u16))
-		zone = rta_getattr_u16(tb[TCA_CTINFO_ZONE]);
-
-	print_string(PRINT_ANY, "kind", "%s ", "ctinfo");
-	print_hu(PRINT_ANY, "zone", "zone %u", zone);
-	print_action_control(f, " ", ci->action, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", ci->index);
-	print_int(PRINT_ANY, "ref", " ref %d", ci->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", ci->bindcnt);
-
-	if (tb[TCA_CTINFO_PARMS_DSCP_MASK]) {
-		print_0xhex(PRINT_ANY, "dscpmask", " dscp %#010llx", dscpmask);
-		print_0xhex(PRINT_ANY, "dscpstatemask", " %#010llx",
-			    dscpstatemask);
-	}
-
-	if (tb[TCA_CTINFO_PARMS_CPMARK_MASK])
-		print_0xhex(PRINT_ANY, "cpmark", " cpmark %#010llx",
-			    cpmarkmask);
-
-	if (show_stats)
-		print_ctinfo_stats(f, tb);
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	return 0;
-}
-
-struct action_util ctinfo_action_util = {
-	.id = "ctinfo",
-	.parse_aopt = parse_ctinfo,
-	.print_aopt = print_ctinfo,
-};
diff --git a/tc/m_ematch.c b/tc/m_ematch.c
index 8840a0d..4c3acf8 100644
--- a/tc/m_ematch.c
+++ b/tc/m_ematch.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -32,14 +33,12 @@
 /* export to bison parser */
 int ematch_argc;
 char **ematch_argv;
-char *ematch_err;
+char *ematch_err = NULL;
 struct ematch *ematch_root;
 
 static int begin_argc;
 static char **begin_argv;
 
-static void bstr_print(FILE *fd, const struct bstr *b, int ascii);
-
 static inline void map_warning(int num, char *kind)
 {
 	fprintf(stderr,
@@ -163,7 +162,7 @@
 
 static struct ematch_util *get_ematch_kind_num(__u16 kind)
 {
-	char name[513];
+	char name[32];
 
 	if (lookup_map(kind, name, sizeof(name), EMATCH_MAP) < 0)
 		return NULL;
@@ -171,48 +170,24 @@
 	return get_ematch_kind(name);
 }
 
-static int em_parse_call(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
-			 struct ematch_util *e, struct ematch *t)
-{
-	if (e->parse_eopt_argv) {
-		int argc = 0, i = 0, ret;
-		struct bstr *args;
-		char **argv;
-
-		for (args = t->args; args; args = bstr_next(args))
-			argc++;
-		argv = calloc(argc, sizeof(char *));
-		if (!argv)
-			return -1;
-		for (args = t->args; args; args = bstr_next(args))
-			argv[i++] = args->data;
-
-		ret = e->parse_eopt_argv(n, hdr, argc, argv);
-
-		free(argv);
-		return ret;
-	}
-
-	return e->parse_eopt(n, hdr, t->args->next);
-}
-
 static int parse_tree(struct nlmsghdr *n, struct ematch *tree)
 {
 	int index = 1;
 	struct ematch *t;
 
 	for (t = tree; t; t = t->next) {
-		struct rtattr *tail;
-		struct tcf_ematch_hdr hdr = { .flags = t->relation };
+		struct rtattr *tail = NLMSG_TAIL(n);
+		struct tcf_ematch_hdr hdr = {
+			.flags = t->relation
+		};
 
 		if (t->inverted)
 			hdr.flags |= TCF_EM_INVERT;
 
-		tail = addattr_nest(n, MAX_MSG, index++);
+		addattr_l(n, MAX_MSG, index++, NULL, 0);
 
 		if (t->child) {
 			__u32 r = t->child_ref;
-
 			addraw_l(n, MAX_MSG, &hdr, sizeof(hdr));
 			addraw_l(n, MAX_MSG, &r, sizeof(r));
 		} else {
@@ -223,7 +198,7 @@
 			if (t->args == NULL)
 				return -1;
 
-			strncpy(buf, (char *) t->args->data, sizeof(buf)-1);
+			strncpy(buf, (char*) t->args->data, sizeof(buf)-1);
 			e = get_ematch_kind(buf);
 			if (e == NULL) {
 				fprintf(stderr, "Unknown ematch \"%s\"\n",
@@ -239,11 +214,11 @@
 			}
 
 			hdr.kind = num;
-			if (em_parse_call(n, &hdr, e, t) < 0)
+			if (e->parse_eopt(n, &hdr, t->args->next) < 0)
 				return -1;
 		}
 
-		addattr_nest_end(n, tail);
+		tail->rta_len = (void*) NLMSG_TAIL(n) - (void*) tail;
 	}
 
 	return 0;
@@ -279,7 +254,6 @@
 	return count;
 }
 
-__attribute__((format(printf, 5, 6)))
 int em_parse_error(int err, struct bstr *args, struct bstr *carg,
 		   struct ematch_util *e, char *fmt, ...)
 {
@@ -369,16 +343,18 @@
 			.progid = TCF_EM_PROG_TC
 		};
 
-		tail = addattr_nest(n, MAX_MSG, tca_id);
+		tail = NLMSG_TAIL(n);
+		addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 		addattr_l(n, MAX_MSG, TCA_EMATCH_TREE_HDR, &hdr, sizeof(hdr));
 
-		tail_list = addattr_nest(n, MAX_MSG, TCA_EMATCH_TREE_LIST);
+		tail_list = NLMSG_TAIL(n);
+		addattr_l(n, MAX_MSG, TCA_EMATCH_TREE_LIST, NULL, 0);
 
 		if (parse_tree(n, ematch_root) < 0)
 			return -1;
 
-		addattr_nest_end(n, tail_list);
-		addattr_nest_end(n, tail);
+		tail_list->rta_len = (void*) NLMSG_TAIL(n) - (void*) tail_list;
+		tail->rta_len = (void*) NLMSG_TAIL(n) - (void*) tail;
 	}
 
 	*argc_p = ematch_argc;
@@ -516,7 +492,7 @@
 	return print_ematch_list(fd, hdr, tb[TCA_EMATCH_TREE_LIST]);
 }
 
-struct bstr *bstr_alloc(const char *text)
+struct bstr * bstr_alloc(const char *text)
 {
 	struct bstr *b = calloc(1, sizeof(*b));
 
@@ -550,7 +526,7 @@
 	return l;
 }
 
-static void bstr_print(FILE *fd, const struct bstr *b, int ascii)
+void bstr_print(FILE *fd, const struct bstr *b, int ascii)
 {
 	int i;
 	char *s = b->data;
@@ -567,3 +543,28 @@
 		fprintf(fd, "\"");
 	}
 }
+
+void print_ematch_tree(const struct ematch *tree)
+{
+	const struct ematch *t;
+
+	for (t = tree; t; t = t->next) {
+		if (t->inverted)
+			printf("NOT ");
+
+		if (t->child) {
+			printf("(");
+			print_ematch_tree(t->child);
+			printf(")");
+		} else {
+			struct bstr *b;
+			for (b = t->args; b; b = b->next)
+				printf("%s%s", b->data, b->next ? " " : "");
+		}
+
+		if (t->relation == TCF_EM_REL_AND)
+			printf(" AND ");
+		else if (t->relation == TCF_EM_REL_OR)
+			printf(" OR ");
+	}
+}
diff --git a/tc/m_ematch.h b/tc/m_ematch.h
index c4443ee..81456aa 100644
--- a/tc/m_ematch.h
+++ b/tc/m_ematch.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __TC_EMATCH_H_
 #define __TC_EMATCH_H_
 
@@ -12,16 +11,17 @@
 
 #define EMATCHKINDSIZ 16
 
-struct bstr {
+struct bstr
+{
 	char	*data;
 	unsigned int	len;
 	int		quoted;
 	struct bstr	*next;
 };
 
-struct bstr *bstr_alloc(const char *text);
+extern struct bstr * bstr_alloc(const char *text);
 
-static inline struct bstr *bstr_new(char *data, unsigned int len)
+static inline struct bstr * bstr_new(char *data, unsigned int len)
 {
 	struct bstr *b = calloc(1, sizeof(*b));
 
@@ -34,7 +34,7 @@
 	return b;
 }
 
-static inline int bstrcmp(const struct bstr *b, const char *text)
+static inline int bstrcmp(struct bstr *b, const char *text)
 {
 	int len = strlen(text);
 	int d = b->len - len;
@@ -50,9 +50,12 @@
 	return b->next;
 }
 
-unsigned long bstrtoul(const struct bstr *b);
+extern unsigned long bstrtoul(const struct bstr *b);
+extern void bstr_print(FILE *fd, const struct bstr *b, int ascii);
 
-struct ematch {
+
+struct ematch
+{
 	struct bstr	*args;
 	int		index;
 	int		inverted;
@@ -62,7 +65,7 @@
 	struct ematch	*next;
 };
 
-static inline struct ematch *new_ematch(struct bstr *args, int inverted)
+static inline struct ematch * new_ematch(struct bstr *args, int inverted)
 {
 	struct ematch *e = calloc(1, sizeof(*e));
 
@@ -75,21 +78,21 @@
 	return e;
 }
 
-void print_ematch_tree(const struct ematch *tree);
+extern void print_ematch_tree(const struct ematch *tree);
 
-struct ematch_util {
+
+struct ematch_util
+{
 	char			kind[EMATCHKINDSIZ];
 	int			kind_num;
-	int	(*parse_eopt)(struct nlmsghdr *, struct tcf_ematch_hdr *,
+	int	(*parse_eopt)(struct nlmsghdr *,struct tcf_ematch_hdr *,
 			      struct bstr *);
-	int	(*parse_eopt_argv)(struct nlmsghdr *, struct tcf_ematch_hdr *,
-				   int, char **);
 	int	(*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int);
 	void	(*print_usage)(FILE *);
 	struct ematch_util	*next;
 };
 
-static inline int parse_layer(const struct bstr *b)
+static inline int parse_layer(struct bstr *b)
 {
 	if (*((char *) b->data) == 'l')
 		return TCF_LAYER_LINK;
@@ -101,10 +104,9 @@
 		return INT_MAX;
 }
 
-__attribute__((format(printf, 5, 6)))
-int em_parse_error(int err, struct bstr *args, struct bstr *carg,
+extern int em_parse_error(int err, struct bstr *args, struct bstr *carg,
 		   struct ematch_util *, char *fmt, ...);
-int print_ematch(FILE *, const struct rtattr *);
-int parse_ematch(int *, char ***, int, struct nlmsghdr *);
+extern int print_ematch(FILE *, const struct rtattr *);
+extern int parse_ematch(int *, char ***, int, struct nlmsghdr *);
 
 #endif
diff --git a/tc/m_estimator.c b/tc/m_estimator.c
index ef62e1b..3dc8624 100644
--- a/tc/m_estimator.c
+++ b/tc/m_estimator.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,18 +28,17 @@
 
 static void est_help(void)
 {
-	fprintf(stderr,
-		"Usage: ... estimator INTERVAL TIME-CONST\n"
-		"  INTERVAL is interval between measurements\n"
-		"  TIME-CONST is averaging time constant\n"
-		"Example: ... est 1sec 8sec\n");
+	fprintf(stderr, "Usage: ... estimator INTERVAL TIME-CONST\n");
+	fprintf(stderr, "  INTERVAL is interval between measurements\n");
+	fprintf(stderr, "  TIME-CONST is averaging time constant\n");
+	fprintf(stderr, "Example: ... est 1sec 8sec\n");
 }
 
 int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est)
 {
 	int argc = *p_argc;
 	char **argv = *p_argv;
-	unsigned int A, time_const;
+	unsigned A, time_const;
 
 	NEXT_ARG();
 	if (est->ewma_log)
diff --git a/tc/m_gact.c b/tc/m_gact.c
index b06e8ee..94bd5e7 100644
--- a/tc/m_gact.c
+++ b/tc/m_gact.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -44,20 +45,17 @@
 #ifdef CONFIG_GACT_PROB
 	fprintf(stderr, "Usage: ... gact <ACTION> [RAND] [INDEX]\n");
 	fprintf(stderr,
-		"Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
-		"       \t          goto chain <CHAIN_INDEX> | jump <JUMP_COUNT>\n"
-			"\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
-			"\tRANDTYPE := netrand | determ\n"
+		"Where: \tACTION := reclassify | drop | continue | pass \n"
+		        "\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
+		        "\tRANDTYPE := netrand | determ\n"
 			"\tVAL : = value not exceeding 10000\n"
-			"\tJUMP_COUNT := Absolute jump from start of action list\n"
 			"\tINDEX := index value used\n"
 			"\n");
 #else
-	fprintf(stderr, "Usage: ... gact <ACTION> [INDEX]\n"
-		"Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
-		"       \t          goto chain <CHAIN_INDEX> | jump <JUMP_COUNT>\n"
+	fprintf(stderr, "Usage: ... gact <ACTION> [INDEX]\n");
+	fprintf(stderr,
+		"Where: \tACTION := reclassify | drop | continue | pass \n"
 		"\tINDEX := index value used\n"
-		"\tJUMP_COUNT := Absolute jump from start of action list\n"
 		"\n");
 #endif
 }
@@ -71,31 +69,68 @@
 }
 
 static int
+get_act(char ***argv_p)
+{
+	char **argv = *argv_p;
+
+	if (matches(*argv, "reclassify") == 0) {
+		return TC_ACT_RECLASSIFY;
+	} else if (matches(*argv, "drop") == 0 || matches(*argv, "shot") == 0) {
+		return TC_ACT_SHOT;
+	} else if (matches(*argv, "continue") == 0) {
+		return TC_ACT_UNSPEC;
+	} else if (matches(*argv, "pipe") == 0) {
+		return TC_ACT_PIPE;
+	} else if (matches(*argv, "pass") == 0 || matches(*argv, "ok") == 0)  {
+		return TC_ACT_OK;
+	} else {
+		fprintf(stderr,"bad action type %s\n",*argv);
+		return -10;
+	}
+}
+
+static int
 parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
 	   int tca_id, struct nlmsghdr *n)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
-	struct tc_gact p = { 0 };
+	int ok = 0;
+	int action = TC_POLICE_RECLASSIFY;
+	struct tc_gact p;
 #ifdef CONFIG_GACT_PROB
 	int rd = 0;
 	struct tc_gact_p pp;
 #endif
 	struct rtattr *tail;
 
+	memset(&p, 0, sizeof (p));
+	p.action = TC_POLICE_RECLASSIFY;
+
 	if (argc < 0)
 		return -1;
 
-	if (!matches(*argv, "gact"))
-		NEXT_ARG();
-	/* we're binding existing gact action to filter by index. */
-	if (!matches(*argv, "index"))
-		goto skip_args;
-	if (parse_action_control(&argc, &argv, &p.action, false))
-		usage();	/* does not return */
+
+	if (matches(*argv, "gact") == 0) {
+		ok++;
+	} else {
+		action = get_act(&argv);
+		if (action != -10) {
+			p.action = action;
+			ok++;
+		} else {
+			explain();
+			return action;
+		}
+	}
+
+	if (ok) {
+		argc--;
+		argv++;
+	}
 
 #ifdef CONFIG_GACT_PROB
-	if (argc > 0) {
+	if (ok && argc > 0) {
 		if (matches(*argv, "random") == 0) {
 			rd = 1;
 			NEXT_ARG();
@@ -110,32 +145,33 @@
 				return -1;
 			}
 
-			if (parse_action_control(&argc, &argv,
-						 &pp.paction, false) == -1)
-				usage();
+			action = get_act(&argv);
+			if (action != -10) { /* FIXME */
+				pp.paction = action;
+			} else {
+				explain();
+				return -1;
+			}
+			argc--;
+			argv++;
 			if (get_u16(&pp.pval, *argv, 10)) {
-				fprintf(stderr,
-					"Illegal probability val 0x%x\n",
-					pp.pval);
+				fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
 				return -1;
 			}
 			if (pp.pval > 10000) {
-				fprintf(stderr,
-					"Illegal probability val  0x%x\n",
-					pp.pval);
+				fprintf(stderr, "Illegal probability val  0x%x\n",pp.pval);
 				return -1;
 			}
 			argc--;
 			argv++;
 		} else if (matches(*argv, "help") == 0) {
-			usage();
+				usage();
 		}
 	}
 #endif
 
 	if (argc > 0) {
 		if (matches(*argv, "index") == 0) {
-skip_args:
 			NEXT_ARG();
 			if (get_u32(&p.index, *argv, 10)) {
 				fprintf(stderr, "Illegal \"index\"\n");
@@ -143,18 +179,24 @@
 			}
 			argc--;
 			argv++;
+			ok++;
 		} else if (matches(*argv, "help") == 0) {
-			usage();
+				usage();
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof(p));
+	if (!ok)
+		return -1;
+
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+	addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof (p));
 #ifdef CONFIG_GACT_PROB
-	if (rd)
-		addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof(pp));
+	if (rd) {
+		addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof (pp));
+	}
 #endif
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -162,9 +204,11 @@
 }
 
 static int
-print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
+print_gact(struct action_util *au,FILE * f, struct rtattr *arg)
 {
+	SPRINT_BUF(b1);
 #ifdef CONFIG_GACT_PROB
+	SPRINT_BUF(b2);
 	struct tc_gact_p *pp = NULL;
 	struct tc_gact_p pp_dummy;
 #endif
@@ -177,39 +221,30 @@
 	parse_rtattr_nested(tb, TCA_GACT_MAX, arg);
 
 	if (tb[TCA_GACT_PARMS] == NULL) {
-		fprintf(stderr, "Missing gact parameters\n");
+		fprintf(f, "[NULL gact parameters]");
 		return -1;
 	}
 	p = RTA_DATA(tb[TCA_GACT_PARMS]);
 
-	print_string(PRINT_ANY, "kind", "%s ", "gact");
-	print_action_control(f, "action ", p->action, "");
+	fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof (b1)));
 #ifdef CONFIG_GACT_PROB
-	if (tb[TCA_GACT_PROB] != NULL) {
+	if (NULL != tb[TCA_GACT_PROB]) {
 		pp = RTA_DATA(tb[TCA_GACT_PROB]);
 	} else {
 		/* need to keep consistent output */
-		memset(&pp_dummy, 0, sizeof(pp_dummy));
+		memset(&pp_dummy, 0, sizeof (pp_dummy));
 		pp = &pp_dummy;
 	}
-	open_json_object("prob");
-	print_string(PRINT_ANY, "random_type", "\n\t random type %s",
-		     prob_n2a(pp->ptype));
-	print_action_control(f, " ", pp->paction, " ");
-	print_int(PRINT_ANY, "val", "val %d", pp->pval);
-	close_json_object();
+	fprintf(f, "\n\t random type %s %s val %d",prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
 #endif
-	print_uint(PRINT_ANY, "index", "\n\t index %u", p->index);
-	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
+	fprintf(f, "\n\t index %d ref %d bind %d",p->index, p->refcnt, p->bindcnt);
 	if (show_stats) {
 		if (tb[TCA_GACT_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_GACT_TM]);
-
-			print_tm(f, tm);
+			print_tm(f,tm);
 		}
 	}
-	print_string(PRINT_FP, NULL, "%s", "\n");
+	fprintf(f, "\n ");
 	return 0;
 }
 
diff --git a/tc/m_ife.c b/tc/m_ife.c
deleted file mode 100644
index 7c612c0..0000000
--- a/tc/m_ife.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * m_ife.c	IFE actions module
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:  J Hadi Salim (jhs@mojatatu.com)
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <linux/netdevice.h>
-
-#include "rt_names.h"
-#include "utils.h"
-#include "tc_util.h"
-#include <linux/tc_act/tc_ife.h>
-
-static void ife_explain(void)
-{
-	fprintf(stderr,
-		"Usage:... ife {decode|encode} [{ALLOW|USE} ATTR] [dst DMAC] [src SMAC] [type TYPE] [CONTROL] [index INDEX]\n"
-		"\tALLOW := Encode direction. Allows encoding specified metadata\n"
-		"\t\t e.g \"allow mark\"\n"
-		"\tUSE := Encode direction. Enforce Static encoding of specified metadata\n"
-		"\t\t e.g \"use mark 0x12\"\n"
-		"\tATTR := mark (32-bit), prio (32-bit), tcindex (16-bit)\n"
-		"\tDMAC := 6 byte Destination MAC address to encode\n"
-		"\tSMAC := optional 6 byte Source MAC address to encode\n"
-		"\tTYPE := optional 16 bit ethertype to encode\n"
-		"\tCONTROL := reclassify|pipe|drop|continue|ok\n"
-		"\tINDEX := optional IFE table index value used\n"
-		"encode is used for sending IFE packets\n"
-		"decode is used for receiving IFE packets\n");
-}
-
-static void ife_usage(void)
-{
-	ife_explain();
-	exit(-1);
-}
-
-static int parse_ife(struct action_util *a, int *argc_p, char ***argv_p,
-		     int tca_id, struct nlmsghdr *n)
-{
-	int argc = *argc_p;
-	char **argv = *argv_p;
-	int ok = 0;
-	struct tc_ife p = { 0 };
-	struct rtattr *tail;
-	struct rtattr *tail2;
-	char dbuf[ETH_ALEN];
-	char sbuf[ETH_ALEN];
-	__u16 ife_type = 0;
-	int user_type = 0;
-	__u32 ife_prio = 0;
-	__u32 ife_prio_v = 0;
-	__u32 ife_mark = 0;
-	__u32 ife_mark_v = 0;
-	__u16 ife_tcindex = 0;
-	__u16 ife_tcindex_v = 0;
-	char *daddr = NULL;
-	char *saddr = NULL;
-
-	if (argc <= 0)
-		return -1;
-
-	while (argc > 0) {
-		if (matches(*argv, "ife") == 0) {
-			NEXT_ARG();
-			continue;
-		} else if (matches(*argv, "decode") == 0) {
-			p.flags = IFE_DECODE; /* readability aid */
-			ok++;
-		} else if (matches(*argv, "encode") == 0) {
-			p.flags = IFE_ENCODE;
-			ok++;
-		} else if (matches(*argv, "allow") == 0) {
-			NEXT_ARG();
-			if (matches(*argv, "mark") == 0) {
-				ife_mark = IFE_META_SKBMARK;
-			} else if (matches(*argv, "prio") == 0) {
-				ife_prio = IFE_META_PRIO;
-			} else if (matches(*argv, "tcindex") == 0) {
-				ife_tcindex = IFE_META_TCINDEX;
-			} else {
-				invarg("Illegal meta define", *argv);
-			}
-		} else if (matches(*argv, "use") == 0) {
-			NEXT_ARG();
-			if (matches(*argv, "mark") == 0) {
-				NEXT_ARG();
-				if (get_u32(&ife_mark_v, *argv, 0))
-					invarg("ife mark val is invalid",
-					       *argv);
-			} else if (matches(*argv, "prio") == 0) {
-				NEXT_ARG();
-				if (get_u32(&ife_prio_v, *argv, 0))
-					invarg("ife prio val is invalid",
-					       *argv);
-			} else if (matches(*argv, "tcindex") == 0) {
-				NEXT_ARG();
-				if (get_u16(&ife_tcindex_v, *argv, 0))
-					invarg("ife tcindex val is invalid",
-					       *argv);
-			} else {
-				invarg("Illegal meta use type", *argv);
-			}
-		} else if (matches(*argv, "type") == 0) {
-			NEXT_ARG();
-			if (get_u16(&ife_type, *argv, 0))
-				invarg("ife type is invalid", *argv);
-			fprintf(stderr, "IFE type 0x%04X\n", ife_type);
-			user_type = 1;
-		} else if (matches(*argv, "dst") == 0) {
-			NEXT_ARG();
-			daddr = *argv;
-			if (sscanf(daddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-				   dbuf, dbuf + 1, dbuf + 2,
-				   dbuf + 3, dbuf + 4, dbuf + 5) != 6) {
-				invarg("Invalid mac address", *argv);
-			}
-			fprintf(stderr, "dst MAC address <%s>\n", daddr);
-
-		} else if (matches(*argv, "src") == 0) {
-			NEXT_ARG();
-			saddr = *argv;
-			if (sscanf(saddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-				   sbuf, sbuf + 1, sbuf + 2,
-				   sbuf + 3, sbuf + 4, sbuf + 5) != 6) {
-				invarg("Invalid mac address", *argv);
-			}
-			fprintf(stderr, "src MAC address <%s>\n", saddr);
-		} else if (matches(*argv, "help") == 0) {
-			ife_usage();
-		} else {
-			break;
-		}
-
-		argc--;
-		argv++;
-	}
-
-	parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&p.index, *argv, 0)) {
-				fprintf(stderr, "ife: Illegal \"index\"\n");
-				return -1;
-			}
-			ok++;
-			argc--;
-			argv++;
-		}
-	}
-
-	if (!ok) {
-		fprintf(stderr, "IFE requires decode/encode specified\n");
-		ife_usage();
-	}
-
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	addattr_l(n, MAX_MSG, TCA_IFE_PARMS, &p, sizeof(p));
-
-	if (!(p.flags & IFE_ENCODE))
-		goto skip_encode;
-
-	if (daddr)
-		addattr_l(n, MAX_MSG, TCA_IFE_DMAC, dbuf, ETH_ALEN);
-	if (user_type)
-		addattr_l(n, MAX_MSG, TCA_IFE_TYPE, &ife_type, 2);
-	else
-		fprintf(stderr, "IFE type 0x%04X\n", ETH_P_IFE);
-	if (saddr)
-		addattr_l(n, MAX_MSG, TCA_IFE_SMAC, sbuf, ETH_ALEN);
-
-	tail2 = addattr_nest(n, MAX_MSG, TCA_IFE_METALST);
-	if (ife_mark || ife_mark_v) {
-		if (ife_mark_v)
-			addattr_l(n, MAX_MSG, IFE_META_SKBMARK, &ife_mark_v, 4);
-		else
-			addattr_l(n, MAX_MSG, IFE_META_SKBMARK, NULL, 0);
-	}
-	if (ife_prio || ife_prio_v) {
-		if (ife_prio_v)
-			addattr_l(n, MAX_MSG, IFE_META_PRIO, &ife_prio_v, 4);
-		else
-			addattr_l(n, MAX_MSG, IFE_META_PRIO, NULL, 0);
-	}
-	if (ife_tcindex || ife_tcindex_v) {
-		if (ife_tcindex_v)
-			addattr_l(n, MAX_MSG, IFE_META_TCINDEX, &ife_tcindex_v,
-				  2);
-		else
-			addattr_l(n, MAX_MSG, IFE_META_TCINDEX, NULL, 0);
-	}
-
-	addattr_nest_end(n, tail2);
-
-skip_encode:
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	struct tc_ife *p;
-	struct rtattr *tb[TCA_IFE_MAX + 1];
-	__u16 ife_type = 0;
-	__u32 mmark = 0;
-	__u16 mtcindex = 0;
-	__u32 mprio = 0;
-	int has_optional = 0;
-	SPRINT_BUF(b2);
-
-	if (arg == NULL)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_IFE_MAX, arg);
-
-	if (tb[TCA_IFE_PARMS] == NULL) {
-		fprintf(stderr, "Missing ife parameters\n");
-		return -1;
-	}
-	p = RTA_DATA(tb[TCA_IFE_PARMS]);
-
-	print_string(PRINT_ANY, "kind", "%s ", "ife");
-	print_string(PRINT_ANY, "mode", "%s ",
-		     p->flags & IFE_ENCODE ? "encode" : "decode");
-	print_action_control(f, "action ", p->action, " ");
-
-	if (tb[TCA_IFE_TYPE]) {
-		ife_type = rta_getattr_u16(tb[TCA_IFE_TYPE]);
-		has_optional = 1;
-		print_0xhex(PRINT_ANY, "type", "type %#llX ", ife_type);
-	}
-
-	if (has_optional)
-		print_string(PRINT_FP, NULL, "%s\t", _SL_);
-
-	if (tb[TCA_IFE_METALST]) {
-		struct rtattr *metalist[IFE_META_MAX + 1];
-		int len = 0;
-
-		parse_rtattr_nested(metalist, IFE_META_MAX,
-				    tb[TCA_IFE_METALST]);
-
-		if (metalist[IFE_META_SKBMARK]) {
-			len = RTA_PAYLOAD(metalist[IFE_META_SKBMARK]);
-			if (len) {
-				mmark = rta_getattr_u32(metalist[IFE_META_SKBMARK]);
-				print_uint(PRINT_ANY, "mark", "use mark %u ",
-					   mmark);
-			} else
-				print_string(PRINT_ANY, "mark", "%s mark ",
-					     "allow");
-		}
-
-		if (metalist[IFE_META_TCINDEX]) {
-			len = RTA_PAYLOAD(metalist[IFE_META_TCINDEX]);
-			if (len) {
-				mtcindex =
-					rta_getattr_u16(metalist[IFE_META_TCINDEX]);
-				print_uint(PRINT_ANY, "tcindex",
-					   "use tcindex %u ", mtcindex);
-			} else
-				print_string(PRINT_ANY, "tcindex",
-					     "%s tcindex ", "allow");
-		}
-
-		if (metalist[IFE_META_PRIO]) {
-			len = RTA_PAYLOAD(metalist[IFE_META_PRIO]);
-			if (len) {
-				mprio = rta_getattr_u32(metalist[IFE_META_PRIO]);
-				print_uint(PRINT_ANY, "prio", "use prio %u ",
-					   mprio);
-			} else
-				print_string(PRINT_ANY, "prio", "%s prio ",
-					     "allow");
-		}
-
-	}
-
-	if (tb[TCA_IFE_DMAC]) {
-		has_optional = 1;
-		print_string(PRINT_ANY, "dst", "dst %s ",
-			     ll_addr_n2a(RTA_DATA(tb[TCA_IFE_DMAC]),
-					 RTA_PAYLOAD(tb[TCA_IFE_DMAC]), 0, b2,
-					 sizeof(b2)));
-	}
-
-	if (tb[TCA_IFE_SMAC]) {
-		has_optional = 1;
-		print_string(PRINT_ANY, "src", "src %s ",
-			     ll_addr_n2a(RTA_DATA(tb[TCA_IFE_SMAC]),
-					 RTA_PAYLOAD(tb[TCA_IFE_SMAC]), 0, b2,
-					 sizeof(b2)));
-	}
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", p->index);
-	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
-
-	if (show_stats) {
-		if (tb[TCA_IFE_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_IFE_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	return 0;
-}
-
-struct action_util ife_action_util = {
-	.id = "ife",
-	.parse_aopt = parse_ife,
-	.print_aopt = print_ife,
-};
diff --git a/tc/m_ipt.c b/tc/m_ipt.c
index cc95eab..948becb 100644
--- a/tc/m_ipt.c
+++ b/tc/m_ipt.c
@@ -10,9 +10,11 @@
  * Authors:  J Hadi Salim (hadi@cyberus.ca)
  */
 
+#include <syslog.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <linux/if.h>
 #include <iptables.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
@@ -49,29 +51,40 @@
 	{0, 0, 0, 0}
 };
 
-static struct xtables_target *t_list;
+static struct iptables_target *t_list = NULL;
 static struct option *opts = original_opts;
-static unsigned int global_option_offset;
+static unsigned int global_option_offset = 0;
 #define OPTION_OFFSET 256
 
 char *lib_dir;
 
 void
-xtables_register_target(struct xtables_target *me)
+register_target(struct iptables_target *me)
 {
+/*      fprintf(stderr, "\nDummy register_target %s \n", me->name);
+*/
 	me->next = t_list;
 	t_list = me;
 
 }
 
-static void exit_tryhelp(int status)
+void
+xtables_register_target(struct iptables_target *me)
+{
+	me->next = t_list;
+	t_list = me;
+}
+
+void
+exit_tryhelp(int status)
 {
 	fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
 		pname, pname);
 	exit(status);
 }
 
-static void exit_error(enum xtables_exittype status, char *msg, ...)
+void
+exit_error(enum exittype status, char *msg, ...)
 {
 	va_list args;
 
@@ -93,6 +106,61 @@
 Email them next time i remember
 */
 
+char *
+addr_to_dotted(const struct in_addr *addrp)
+{
+	static char buf[20];
+	const unsigned char *bytep;
+
+	bytep = (const unsigned char *) &(addrp->s_addr);
+	sprintf(buf, "%d.%d.%d.%d", bytep[0], bytep[1], bytep[2], bytep[3]);
+	return buf;
+}
+
+int string_to_number_ll(const char *s, unsigned long long min,
+			unsigned long long max,
+		 unsigned long long *ret)
+{
+	unsigned long long number;
+	char *end;
+
+	/* Handle hex, octal, etc. */
+	errno = 0;
+	number = strtoull(s, &end, 0);
+	if (*end == '\0' && end != s) {
+		/* we parsed a number, let's see if we want this */
+		if (errno != ERANGE && min <= number && (!max || number <= max)) {
+			*ret = number;
+			return 0;
+		}
+	}
+	return -1;
+}
+
+int string_to_number_l(const char *s, unsigned long min, unsigned long max,
+		       unsigned long *ret)
+{
+	int result;
+	unsigned long long number;
+
+	result = string_to_number_ll(s, min, max, &number);
+	*ret = (unsigned long)number;
+
+	return result;
+}
+
+int string_to_number(const char *s, unsigned int min, unsigned int max,
+		unsigned int *ret)
+{
+	int result;
+	unsigned long number;
+
+	result = string_to_number_l(s, min, max, &number);
+	*ret = (unsigned int)number;
+
+	return result;
+}
+
 static void free_opts(struct option *local_opts)
 {
 	if (local_opts != original_opts) {
@@ -109,18 +177,18 @@
 	struct option *merge;
 	unsigned int num_old, num_new, i;
 
-	for (num_old = 0; oldopts[num_old].name; num_old++);
-	for (num_new = 0; newopts[num_new].name; num_new++);
+	for (num_old = 0; oldopts[num_old].name; num_old++) ;
+	for (num_new = 0; newopts[num_new].name; num_new++) ;
 
 	*option_offset = global_option_offset + OPTION_OFFSET;
 
-	merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
-	memcpy(merge, oldopts, num_old * sizeof(struct option));
+	merge = malloc(sizeof (struct option) * (num_new + num_old + 1));
+	memcpy(merge, oldopts, num_old * sizeof (struct option));
 	for (i = 0; i < num_new; i++) {
 		merge[num_old + i] = newopts[i];
 		merge[num_old + i].val += *option_offset;
 	}
-	memset(merge + num_old + num_new, 0, sizeof(struct option));
+	memset(merge + num_old + num_new, 0, sizeof (struct option));
 
 	return merge;
 }
@@ -137,11 +205,10 @@
 	return p;
 }
 
-static struct xtables_target *
+static struct iptables_target *
 find_t(char *name)
 {
-	struct xtables_target *m;
-
+	struct iptables_target *m;
 	for (m = t_list; m; m = m->next) {
 		if (strcmp(m->name, name) == 0)
 			return m;
@@ -150,24 +217,29 @@
 	return NULL;
 }
 
-static struct xtables_target *
+static struct iptables_target *
 get_target_name(const char *name)
 {
 	void *handle;
 	char *error;
 	char *new_name, *lname;
-	struct xtables_target *m;
-	char path[strlen(lib_dir) + sizeof("/libipt_.so") + strlen(name)];
+	struct iptables_target *m;
+	char path[strlen(lib_dir) + sizeof ("/libipt_.so") + strlen(name)];
 
 #ifdef NO_SHARED_LIBS
 	return NULL;
 #endif
 
-	new_name = calloc(1, strlen(name) + 1);
-	lname = calloc(1, strlen(name) + 1);
-	if (!new_name)
+	new_name = malloc(strlen(name) + 1);
+	lname = malloc(strlen(name) + 1);
+	if (new_name)
+		memset(new_name, '\0', strlen(name) + 1);
+	else
 		exit_error(PARAMETER_PROBLEM, "get_target_name");
-	if (!lname)
+
+	if (lname)
+		memset(lname, '\0', strlen(name) + 1);
+	else
 		exit_error(PARAMETER_PROBLEM, "get_target_name");
 
 	strcpy(new_name, name);
@@ -175,7 +247,6 @@
 
 	if (isupper(lname[0])) {
 		int i;
-
 		for (i = 0; i < strlen(name); i++) {
 			lname[i] = tolower(lname[i]);
 		}
@@ -183,7 +254,6 @@
 
 	if (islower(new_name[0])) {
 		int i;
-
 		for (i = 0; i < strlen(new_name); i++) {
 			new_name[i] = toupper(new_name[i]);
 		}
@@ -198,12 +268,12 @@
 		handle = dlopen(path, RTLD_LAZY);
 
 		if (!handle) {
-			sprintf(path, "%s/libxt_%s.so", lib_dir, lname);
+			sprintf(path, "%s/libxt_%s.so", lib_dir , lname);
 			handle = dlopen(path, RTLD_LAZY);
 		}
 
 		if (!handle) {
-			sprintf(path, "%s/libipt_%s.so", lib_dir, lname);
+			sprintf(path, "%s/libipt_%s.so", lib_dir , lname);
 			handle = dlopen(path, RTLD_LAZY);
 		}
 		/* ok, lets give up .. */
@@ -218,12 +288,12 @@
 
 	m = dlsym(handle, new_name);
 	if ((error = dlerror()) != NULL) {
-		m = (struct xtables_target *) dlsym(handle, lname);
+		m = (struct iptables_target *) dlsym(handle, lname);
 		if ((error = dlerror()) != NULL) {
 			m = find_t(new_name);
-			if (m == NULL) {
+			if (NULL == m) {
 				m = find_t(lname);
-				if (m == NULL) {
+				if (NULL == m) {
 					fputs(error, stderr);
 					fprintf(stderr, "\n");
 					dlclose(handle);
@@ -240,6 +310,42 @@
 	return m;
 }
 
+
+struct in_addr *dotted_to_addr(const char *dotted)
+{
+	static struct in_addr addr;
+	unsigned char *addrp;
+	char *p, *q;
+	unsigned int onebyte;
+	int i;
+	char buf[20];
+
+	/* copy dotted string, because we need to modify it */
+	strncpy(buf, dotted, sizeof (buf) - 1);
+	addrp = (unsigned char *) &(addr.s_addr);
+
+	p = buf;
+	for (i = 0; i < 3; i++) {
+		if ((q = strchr(p, '.')) == NULL)
+			return (struct in_addr *) NULL;
+
+		*q = '\0';
+		if (string_to_number(p, 0, 255, &onebyte) == -1)
+			return (struct in_addr *) NULL;
+
+		addrp[i] = (unsigned char) onebyte;
+		p = q + 1;
+	}
+
+	/* we've checked 3 bytes, now we check the last one */
+	if (string_to_number(p, 0, 255, &onebyte) == -1)
+		return (struct in_addr *) NULL;
+
+	addrp[3] = (unsigned char) onebyte;
+
+	return &addr;
+}
+
 static void set_revision(char *name, u_int8_t revision)
 {
 	/* Old kernel sources don't have ".revision" field,
@@ -251,20 +357,23 @@
 /*
  * we may need to check for version mismatch
 */
-static int build_st(struct xtables_target *target, struct ipt_entry_target *t)
+int
+build_st(struct iptables_target *target, struct ipt_entry_target *t)
 {
+	unsigned int nfcache = 0;
+
 	if (target) {
 		size_t size;
 
 		size =
-		    XT_ALIGN(sizeof(struct ipt_entry_target)) + target->size;
+		    IPT_ALIGN(sizeof (struct ipt_entry_target)) + target->size;
 
-		if (t == NULL) {
+		if (NULL == t) {
 			target->t = fw_calloc(1, size);
 			target->t->u.target_size = size;
 
 			if (target->init != NULL)
-				target->init(target->t);
+				target->init(target->t, &nfcache);
 			set_revision(target->t->u.user.name, target->revision);
 		} else {
 			target->t = t;
@@ -276,17 +385,17 @@
 	return -1;
 }
 
-static int parse_ipt(struct action_util *a, int *argc_p,
+static int parse_ipt(struct action_util *a,int *argc_p,
 		     char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
-	struct xtables_target *m = NULL;
+	struct iptables_target *m = NULL;
 	struct ipt_entry fw;
 	struct rtattr *tail;
 	int c;
 	int rargc = *argc_p;
 	char **argv = *argv_p;
 	int argc = 0, iargc = 0;
-	char k[FILTER_NAMESZ];
+	char k[16];
 	int size = 0;
 	int iok = 0, ok = 0;
 	__u32 hook = 0, index = 0;
@@ -297,16 +406,16 @@
 
 	{
 		int i;
-
 		for (i = 0; i < rargc; i++) {
-			if (!argv[i] || strcmp(argv[i], "action") == 0)
+			if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
 				break;
+			}
 		}
 		iargc = argc = i;
 	}
 
 	if (argc <= 2) {
-		fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
+		fprintf(stderr,"bad arguments to ipt %d vs %d \n", argc, rargc);
 		return -1;
 	}
 
@@ -317,29 +426,29 @@
 		switch (c) {
 		case 'j':
 			m = get_target_name(optarg);
-			if (m != NULL) {
+			if (NULL != m) {
 
-				if (build_st(m, NULL) < 0) {
-					printf(" %s error\n", m->name);
+				if (0 > build_st(m, NULL)) {
+					printf(" %s error \n", m->name);
 					return -1;
 				}
 				opts =
 				    merge_options(opts, m->extra_opts,
 						  &m->option_offset);
 			} else {
-				fprintf(stderr, " failed to find target %s\n\n", optarg);
+				fprintf(stderr," failed to find target %s\n\n", optarg);
 				return -1;
 			}
 			ok++;
 			break;
 
 		default:
-			memset(&fw, 0, sizeof(fw));
+			memset(&fw, 0, sizeof (fw));
 			if (m) {
 				m->parse(c - m->option_offset, argv, 0,
 					 &m->tflags, NULL, &m->t);
 			} else {
-				fprintf(stderr, " failed to find target %s\n\n", optarg);
+				fprintf(stderr," failed to find target %s\n\n", optarg);
 				return -1;
 
 			}
@@ -363,7 +472,7 @@
 	}
 
 	if (!ok && !iok) {
-		fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
+		fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
 		return -1;
 	}
 
@@ -373,7 +482,6 @@
 
 	{
 		struct tcmsg *t = NLMSG_DATA(n);
-
 		if (t->tcm_parent != TC_H_ROOT
 		    && t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
 			hook = NF_IP_PRE_ROUTING;
@@ -382,7 +490,8 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]);
 	fprintf(stdout, "\ttarget: ");
 
@@ -403,7 +512,7 @@
 	addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4);
 	if (m)
 		addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size);
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	argc -= optind;
 	argv += optind;
@@ -413,11 +522,11 @@
 	optind = 0;
 	free_opts(opts);
 	/* Clear flags if target will be used again */
-        m->tflags = 0;
-        m->used = 0;
+        m->tflags=0;
+        m->used=0;
 	/* Free allocated memory */
-	if (m->t)
-	    free(m->t);
+        if (m->t)
+            free(m->t);
 
 
 	return 0;
@@ -425,12 +534,10 @@
 }
 
 static int
-print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
+print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
 {
 	struct rtattr *tb[TCA_IPT_MAX + 1];
 	struct ipt_entry_target *t = NULL;
-	struct xtables_target *m;
-	__u32 hook;
 
 	if (arg == NULL)
 		return -1;
@@ -442,75 +549,72 @@
 	parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
 
 	if (tb[TCA_IPT_TABLE] == NULL) {
-		fprintf(stderr,  "Missing ipt table name, assuming mangle\n");
+		fprintf(f, "[NULL ipt table name ] assuming mangle ");
 	} else {
 		fprintf(f, "tablename: %s ",
 			rta_getattr_str(tb[TCA_IPT_TABLE]));
 	}
 
 	if (tb[TCA_IPT_HOOK] == NULL) {
-		fprintf(stderr, "Missing ipt hook name\n ");
+		fprintf(f, "[NULL ipt hook name ]\n ");
 		return -1;
+	} else {
+		__u32 hook;
+		hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+		fprintf(f, " hook: %s \n", ipthooks[hook]);
 	}
 
-	hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
-	fprintf(f, " hook: %s\n", ipthooks[hook]);
-
 	if (tb[TCA_IPT_TARG] == NULL) {
-		fprintf(stderr, "Missing ipt target parameters\n");
+		fprintf(f, "\t[NULL ipt target parameters ] \n");
 		return -1;
-	}
+	} else {
+		struct iptables_target *m = NULL;
+		t = RTA_DATA(tb[TCA_IPT_TARG]);
+		m = get_target_name(t->u.user.name);
+		if (NULL != m) {
+			if (0 > build_st(m, t)) {
+				fprintf(stderr, " %s error \n", m->name);
+				return -1;
+			}
 
-
-	t = RTA_DATA(tb[TCA_IPT_TARG]);
-	m = get_target_name(t->u.user.name);
-	if (m != NULL) {
-		if (build_st(m, t) < 0) {
-			fprintf(stderr, " %s error\n", m->name);
+			opts =
+			    merge_options(opts, m->extra_opts,
+					  &m->option_offset);
+		} else {
+			fprintf(stderr, " failed to find target %s\n\n",
+				t->u.user.name);
 			return -1;
 		}
-
-		opts =
-			merge_options(opts, m->extra_opts,
-				      &m->option_offset);
-	} else {
-		fprintf(stderr, " failed to find target %s\n\n",
-			t->u.user.name);
-		return -1;
-	}
-
-	fprintf(f, "\ttarget ");
-	m->print(NULL, m->t, 0);
-	if (tb[TCA_IPT_INDEX] == NULL) {
-		fprintf(stderr, "Missing ipt target index\n");
-	} else {
-		__u32 index;
-
-		index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
-		fprintf(f, "\n\tindex %u", index);
-	}
-
-	if (tb[TCA_IPT_CNT]) {
-		struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);
-
-		fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
-	}
-	if (show_stats) {
-		if (tb[TCA_IPT_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
-
-			print_tm(f, tm);
+		fprintf(f, "\ttarget ");
+		m->print(NULL, m->t, 0);
+		if (tb[TCA_IPT_INDEX] == NULL) {
+			fprintf(f, " [NULL ipt target index ]\n");
+		} else {
+			__u32 index;
+			index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
+			fprintf(f, " \n\tindex %d", index);
 		}
-	}
-	fprintf(f, "\n");
 
+		if (tb[TCA_IPT_CNT]) {
+			struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);;
+			fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
+		}
+		if (show_stats) {
+			if (tb[TCA_IPT_TM]) {
+				struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+				print_tm(f,tm);
+			}
+		}
+		fprintf(f, " \n");
+
+	}
 	free_opts(opts);
 
 	return 0;
 }
 
 struct action_util ipt_action_util = {
-	.id = "ipt",
-	.parse_aopt = parse_ipt,
-	.print_aopt = print_ipt,
+        .id = "ipt",
+        .parse_aopt = parse_ipt,
+        .print_aopt = print_ipt,
 };
diff --git a/tc/m_mirred.c b/tc/m_mirred.c
index 1320952..dc231d7 100644
--- a/tc/m_mirred.c
+++ b/tc/m_mirred.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -28,13 +29,13 @@
 static void
 explain(void)
 {
-	fprintf(stderr,
-		"Usage: mirred <DIRECTION> <ACTION> [index INDEX] <dev DEVICENAME>\n"
-		"where:\n"
-		"\tDIRECTION := <ingress | egress>\n"
-		"\tACTION := <mirror | redirect>\n"
-		"\tINDEX  is the specific policy instance id\n"
-		"\tDEVICENAME is the devicename\n");
+	fprintf(stderr, "Usage: mirred <DIRECTION> <ACTION> [index INDEX] <dev DEVICENAME> \n");
+	fprintf(stderr, "where: \n");
+	fprintf(stderr, "\tDIRECTION := <ingress | egress>\n");
+	fprintf(stderr, "\tACTION := <mirror | redirect>\n");
+	fprintf(stderr, "\tINDEX  is the specific policy instance id\n");
+	fprintf(stderr, "\tDEVICENAME is the devicename \n");
+
 }
 
 static void
@@ -60,68 +61,26 @@
 	}
 }
 
-static const char *mirred_direction(int action)
-{
-	switch (action) {
-	case TCA_EGRESS_REDIR:
-	case TCA_EGRESS_MIRROR:
-		return "egress";
-	case TCA_INGRESS_REDIR:
-	case TCA_INGRESS_MIRROR:
-		return "ingress";
-	default:
-		return "unknown";
-	}
-}
-
-static const char *mirred_action(int action)
-{
-	switch (action) {
-	case TCA_EGRESS_REDIR:
-	case TCA_INGRESS_REDIR:
-		return "redirect";
-	case TCA_EGRESS_MIRROR:
-	case TCA_INGRESS_MIRROR:
-		return "mirror";
-	default:
-		return "unknown";
-	}
-}
-
 static int
-parse_direction(struct action_util *a, int *argc_p, char ***argv_p,
-		int tca_id, struct nlmsghdr *n)
+parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
+	     int tca_id, struct nlmsghdr *n)
 {
 
 	int argc = *argc_p;
 	char **argv = *argv_p;
-	int ok = 0, iok = 0, mirror = 0, redir = 0, ingress = 0, egress = 0;
-	struct tc_mirred p = {};
+	int ok = 0, iok = 0, mirror=0,redir=0;
+	struct tc_mirred p;
 	struct rtattr *tail;
-	char d[IFNAMSIZ] = {};
+	char d[16];
+
+	memset(d,0,sizeof(d)-1);
+	memset(&p,0,sizeof(struct tc_mirred));
 
 	while (argc > 0) {
 
 		if (matches(*argv, "action") == 0) {
-			NEXT_ARG();
 			break;
-		} else if (!egress && matches(*argv, "egress") == 0) {
-			egress = 1;
-			if (ingress) {
-				fprintf(stderr,
-					"Can't have both egress and ingress\n");
-				return -1;
-			}
-			NEXT_ARG();
-			ok++;
-			continue;
-		} else if (!ingress && matches(*argv, "ingress") == 0) {
-			ingress = 1;
-			if (egress) {
-				fprintf(stderr,
-					"Can't have both ingress and egress\n");
-				return -1;
-			}
+		} else if (matches(*argv, "egress") == 0) {
 			NEXT_ARG();
 			ok++;
 			continue;
@@ -139,36 +98,29 @@
 					argv++;
 					break;
 				}
-			} else if (!ok) {
-				fprintf(stderr,
-					"was expecting egress or ingress (%s)\n",
-					*argv);
+			} else if(!ok) {
+				fprintf(stderr, "was expecting egress (%s)\n", *argv);
 				break;
 
 			} else if (!mirror && matches(*argv, "mirror") == 0) {
-				mirror = 1;
+				mirror=1;
 				if (redir) {
-					fprintf(stderr,
-						"Can't have both mirror and redir\n");
+					fprintf(stderr, "Can't have both mirror and redir\n");
 					return -1;
 				}
-				p.eaction = egress ? TCA_EGRESS_MIRROR :
-					TCA_INGRESS_MIRROR;
+				p.eaction = TCA_EGRESS_MIRROR;
 				p.action = TC_ACT_PIPE;
 				ok++;
 			} else if (!redir && matches(*argv, "redirect") == 0) {
-				redir = 1;
+				redir=1;
 				if (mirror) {
-					fprintf(stderr,
-						"Can't have both mirror and redir\n");
+					fprintf(stderr, "Can't have both mirror and redir\n");
 					return -1;
 				}
-				p.eaction = egress ? TCA_EGRESS_REDIR :
-					TCA_INGRESS_REDIR;
+				p.eaction = TCA_EGRESS_REDIR;
 				p.action = TC_ACT_STOLEN;
 				ok++;
-			} else if ((redir || mirror) &&
-				   matches(*argv, "dev") == 0) {
+			} else if ((redir || mirror) && matches(*argv, "dev") == 0) {
 				NEXT_ARG();
 				if (strlen(d))
 					duparg("dev", *argv);
@@ -185,47 +137,68 @@
 		NEXT_ARG();
 	}
 
-	if (!ok && !iok)
+	if (!ok && !iok) {
 		return -1;
+	}
+
+
 
 	if (d[0])  {
 		int idx;
-
 		ll_init_map(&rth);
 
-		idx = ll_name_to_index(d);
-		if (!idx)
-			return nodev(d);
+		if ((idx = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
+			return -1;
+		}
 
 		p.ifindex = idx;
 	}
 
 
-	if (p.eaction == TCA_EGRESS_MIRROR || p.eaction == TCA_INGRESS_MIRROR)
-		parse_action_control_dflt(&argc, &argv, &p.action, false,
-					  TC_ACT_PIPE);
+	if (argc && p.eaction == TCA_EGRESS_MIRROR) {
+
+		if (matches(*argv, "reclassify") == 0) {
+			p.action = TC_POLICE_RECLASSIFY;
+			NEXT_ARG();
+		} else if (matches(*argv, "pipe") == 0) {
+			p.action = TC_POLICE_PIPE;
+			NEXT_ARG();
+		} else if (matches(*argv, "drop") == 0 ||
+			   matches(*argv, "shot") == 0) {
+			p.action = TC_POLICE_SHOT;
+			NEXT_ARG();
+		} else if (matches(*argv, "continue") == 0) {
+			p.action = TC_POLICE_UNSPEC;
+			NEXT_ARG();
+		} else if (matches(*argv, "pass") == 0) {
+			p.action = TC_POLICE_OK;
+			NEXT_ARG();
+		}
+
+	}
 
 	if (argc) {
 		if (iok && matches(*argv, "index") == 0) {
 			fprintf(stderr, "mirred: Illegal double index\n");
 			return -1;
-		}
-
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&p.index, *argv, 10)) {
-				fprintf(stderr,
-					"mirred: Illegal \"index\"\n");
-				return -1;
+		} else {
+			if (matches(*argv, "index") == 0) {
+				NEXT_ARG();
+				if (get_u32(&p.index, *argv, 10)) {
+					fprintf(stderr, "mirred: Illegal \"index\"\n");
+					return -1;
+				}
+				argc--;
+				argv++;
 			}
-			argc--;
-			argv++;
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	addattr_l(n, MAX_MSG, TCA_MIRRED_PARMS, &p, sizeof(p));
-	addattr_nest_end(n, tail);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+	addattr_l(n, MAX_MSG, TCA_MIRRED_PARMS, &p, sizeof (p));
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -242,32 +215,32 @@
 	char **argv = *argv_p;
 
 	if (argc < 0) {
-		fprintf(stderr, "mirred bad argument count %d\n", argc);
+		fprintf(stderr,"mirred bad argument count %d\n", argc);
 		return -1;
 	}
 
 	if (matches(*argv, "mirred") == 0) {
 		NEXT_ARG();
 	} else {
-		fprintf(stderr, "mirred bad argument %s\n", *argv);
+		fprintf(stderr,"mirred bad argument %s\n", *argv);
 		return -1;
 	}
 
 
-	if (matches(*argv, "egress") == 0 || matches(*argv, "ingress") == 0 ||
-	    matches(*argv, "index") == 0) {
-		int ret = parse_direction(a, &argc, &argv, tca_id, n);
-
+	if (matches(*argv, "egress") == 0 || matches(*argv, "index") == 0) {
+		int ret = parse_egress(a, &argc, &argv, tca_id, n);
 		if (ret == 0) {
 			*argc_p = argc;
 			*argv_p = argv;
 			return 0;
 		}
 
+	} else if (matches(*argv, "ingress") == 0) {
+		fprintf(stderr,"mirred ingress not supported at the moment\n");
 	} else if (matches(*argv, "help") == 0) {
 		usage();
 	} else {
-		fprintf(stderr, "mirred option not supported %s\n", *argv);
+		fprintf(stderr,"mirred option not supported %s\n", *argv);
 	}
 
 	return -1;
@@ -275,11 +248,12 @@
 }
 
 static int
-print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
+print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
 {
 	struct tc_mirred *p;
 	struct rtattr *tb[TCA_MIRRED_MAX + 1];
 	const char *dev;
+	SPRINT_BUF(b1);
 
 	if (arg == NULL)
 		return -1;
@@ -287,38 +261,33 @@
 	parse_rtattr_nested(tb, TCA_MIRRED_MAX, arg);
 
 	if (tb[TCA_MIRRED_PARMS] == NULL) {
-		fprintf(stderr, "Missing mirred parameters\n");
+		fprintf(f, "[NULL mirred parameters]");
 		return -1;
 	}
 	p = RTA_DATA(tb[TCA_MIRRED_PARMS]);
 
-	dev = ll_index_to_name(p->ifindex);
-	if (dev == 0) {
+	/*
+	ll_init_map(&rth);
+	*/
+
+
+	if ((dev = ll_index_to_name(p->ifindex)) == 0) {
 		fprintf(stderr, "Cannot find device %d\n", p->ifindex);
 		return -1;
 	}
 
-	print_string(PRINT_ANY, "kind", "%s ", "mirred");
-	print_string(PRINT_FP, NULL, "(%s", mirred_n2a(p->eaction));
-	print_string(PRINT_JSON, "mirred_action", NULL,
-		     mirred_action(p->eaction));
-	print_string(PRINT_JSON, "direction", NULL,
-		     mirred_direction(p->eaction));
-	print_string(PRINT_ANY, "to_dev", " to device %s)", dev);
-	print_action_control(f, " ", p->action, "");
+	fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev,action_n2a(p->action, b1, sizeof (b1)));
 
-	print_uint(PRINT_ANY, "index", "\n \tindex %u", p->index);
-	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
+	fprintf(f, "\n ");
+	fprintf(f, "\tindex %d ref %d bind %d",p->index,p->refcnt,p->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_MIRRED_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_MIRRED_TM]);
-
-			print_tm(f, tm);
+			print_tm(f,tm);
 		}
 	}
-	print_string(PRINT_FP, NULL, "%s", "\n ");
+	fprintf(f, "\n ");
 	return 0;
 }
 
diff --git a/tc/m_mpls.c b/tc/m_mpls.c
deleted file mode 100644
index 4b1ec70..0000000
--- a/tc/m_mpls.c
+++ /dev/null
@@ -1,276 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-/* Copyright (C) 2019 Netronome Systems, Inc. */
-
-#include <linux/if_ether.h>
-#include <linux/tc_act/tc_mpls.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "utils.h"
-#include "rt_names.h"
-#include "tc_util.h"
-
-static const char * const action_names[] = {
-	[TCA_MPLS_ACT_POP] = "pop",
-	[TCA_MPLS_ACT_PUSH] = "push",
-	[TCA_MPLS_ACT_MODIFY] = "modify",
-	[TCA_MPLS_ACT_DEC_TTL] = "dec_ttl",
-};
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: mpls pop [ protocol MPLS_PROTO ]\n"
-		"       mpls push [ protocol MPLS_PROTO ] [ label MPLS_LABEL ] [ tc MPLS_TC ]\n"
-		"                 [ ttl MPLS_TTL ] [ bos MPLS_BOS ] [CONTROL]\n"
-		"       mpls modify [ label MPLS_LABEL ] [ tc MPLS_TC ] [ ttl MPLS_TTL ] [CONTROL]\n"
-		"           for pop MPLS_PROTO is next header of packet - e.g. ip or mpls_uc\n"
-		"           for push MPLS_PROTO is one of mpls_uc or mpls_mc\n"
-		"               with default: mpls_uc\n"
-		"       CONTROL := reclassify | pipe | drop | continue | pass |\n"
-		"                  goto chain <CHAIN_INDEX>\n");
-}
-
-static void usage(void)
-{
-	explain();
-	exit(-1);
-}
-
-static bool can_modify_mpls_fields(unsigned int action)
-{
-	return action == TCA_MPLS_ACT_PUSH || action == TCA_MPLS_ACT_MODIFY;
-}
-
-static bool can_modify_ethtype(unsigned int action)
-{
-	return action == TCA_MPLS_ACT_PUSH || action == TCA_MPLS_ACT_POP;
-}
-
-static bool is_valid_label(__u32 label)
-{
-	return label <= 0xfffff;
-}
-
-static bool check_double_action(unsigned int action, const char *arg)
-{
-	if (!action)
-		return false;
-
-	fprintf(stderr,
-		"Error: got \"%s\" but action already set to \"%s\"\n",
-		arg, action_names[action]);
-	explain();
-	return true;
-}
-
-static int parse_mpls(struct action_util *a, int *argc_p, char ***argv_p,
-		      int tca_id, struct nlmsghdr *n)
-{
-	struct tc_mpls parm = {};
-	__u32 label = 0xffffffff;
-	unsigned int action = 0;
-	char **argv = *argv_p;
-	struct rtattr *tail;
-	int argc = *argc_p;
-	__u16 proto = 0;
-	__u8 bos = 0xff;
-	__u8 tc = 0xff;
-	__u8 ttl = 0;
-
-	if (matches(*argv, "mpls") != 0)
-		return -1;
-
-	NEXT_ARG();
-
-	while (argc > 0) {
-		if (matches(*argv, "pop") == 0) {
-			if (check_double_action(action, *argv))
-				return -1;
-			action = TCA_MPLS_ACT_POP;
-		} else if (matches(*argv, "push") == 0) {
-			if (check_double_action(action, *argv))
-				return -1;
-			action = TCA_MPLS_ACT_PUSH;
-		} else if (matches(*argv, "modify") == 0) {
-			if (check_double_action(action, *argv))
-				return -1;
-			action = TCA_MPLS_ACT_MODIFY;
-		} else if (matches(*argv, "dec_ttl") == 0) {
-			if (check_double_action(action, *argv))
-				return -1;
-			action = TCA_MPLS_ACT_DEC_TTL;
-		} else if (matches(*argv, "label") == 0) {
-			if (!can_modify_mpls_fields(action))
-				invarg("only valid for push/modify", *argv);
-			NEXT_ARG();
-			if (get_u32(&label, *argv, 0) || !is_valid_label(label))
-				invarg("label must be <=0xFFFFF", *argv);
-		} else if (matches(*argv, "tc") == 0) {
-			if (!can_modify_mpls_fields(action))
-				invarg("only valid for push/modify", *argv);
-			NEXT_ARG();
-			if (get_u8(&tc, *argv, 0) || (tc & ~0x7))
-				invarg("tc field is 3 bits max", *argv);
-		} else if (matches(*argv, "ttl") == 0) {
-			if (!can_modify_mpls_fields(action))
-				invarg("only valid for push/modify", *argv);
-			NEXT_ARG();
-			if (get_u8(&ttl, *argv, 0) || !ttl)
-				invarg("ttl must be >0 and <=255", *argv);
-		} else if (matches(*argv, "bos") == 0) {
-			if (!can_modify_mpls_fields(action))
-				invarg("only valid for push/modify", *argv);
-			NEXT_ARG();
-			if (get_u8(&bos, *argv, 0) || (bos & ~0x1))
-				invarg("bos must be 0 or 1", *argv);
-		} else if (matches(*argv, "protocol") == 0) {
-			if (!can_modify_ethtype(action))
-				invarg("only valid for push/pop", *argv);
-			NEXT_ARG();
-			if (ll_proto_a2n(&proto, *argv))
-				invarg("protocol is invalid", *argv);
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			break;
-		}
-
-		NEXT_ARG_FWD();
-	}
-
-	if (!action)
-		incomplete_command();
-
-	parse_action_control_dflt(&argc, &argv, &parm.action,
-				  false, TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&parm.index, *argv, 10))
-				invarg("illegal index", *argv);
-			NEXT_ARG_FWD();
-		}
-	}
-
-	if (action == TCA_MPLS_ACT_PUSH && !label)
-		missarg("label");
-
-	if (action == TCA_MPLS_ACT_PUSH && proto &&
-	    proto != htons(ETH_P_MPLS_UC) && proto != htons(ETH_P_MPLS_MC)) {
-		fprintf(stderr,
-			"invalid push protocol \"0x%04x\" - use mpls_(uc|mc)\n",
-			ntohs(proto));
-		return -1;
-	}
-
-	if (action == TCA_MPLS_ACT_POP && !proto)
-		missarg("protocol");
-
-	parm.m_action = action;
-	tail = addattr_nest(n, MAX_MSG, tca_id | NLA_F_NESTED);
-	addattr_l(n, MAX_MSG, TCA_MPLS_PARMS, &parm, sizeof(parm));
-	if (label != 0xffffffff)
-		addattr_l(n, MAX_MSG, TCA_MPLS_LABEL, &label, sizeof(label));
-	if (proto)
-		addattr_l(n, MAX_MSG, TCA_MPLS_PROTO, &proto, sizeof(proto));
-	if (tc != 0xff)
-		addattr8(n, MAX_MSG, TCA_MPLS_TC, tc);
-	if (ttl)
-		addattr8(n, MAX_MSG, TCA_MPLS_TTL, ttl);
-	if (bos != 0xff)
-		addattr8(n, MAX_MSG, TCA_MPLS_BOS, bos);
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-static int print_mpls(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	struct rtattr *tb[TCA_MPLS_MAX + 1];
-	struct tc_mpls *parm;
-	SPRINT_BUF(b1);
-	__u32 val;
-
-	if (!arg)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_MPLS_MAX, arg);
-
-	if (!tb[TCA_MPLS_PARMS]) {
-		fprintf(stderr, "[NULL mpls parameters]\n");
-		return -1;
-	}
-	parm = RTA_DATA(tb[TCA_MPLS_PARMS]);
-
-	print_string(PRINT_ANY, "kind", "%s ", "mpls");
-	print_string(PRINT_ANY, "mpls_action", " %s",
-		     action_names[parm->m_action]);
-
-	switch (parm->m_action) {
-	case TCA_MPLS_ACT_POP:
-		if (tb[TCA_MPLS_PROTO]) {
-			__u16 proto;
-
-			proto = rta_getattr_u16(tb[TCA_MPLS_PROTO]);
-			print_string(PRINT_ANY, "protocol", " protocol %s",
-				     ll_proto_n2a(proto, b1, sizeof(b1)));
-		}
-		break;
-	case TCA_MPLS_ACT_PUSH:
-		if (tb[TCA_MPLS_PROTO]) {
-			__u16 proto;
-
-			proto = rta_getattr_u16(tb[TCA_MPLS_PROTO]);
-			print_string(PRINT_ANY, "protocol", " protocol %s",
-				     ll_proto_n2a(proto, b1, sizeof(b1)));
-		}
-		/* Fallthrough */
-	case TCA_MPLS_ACT_MODIFY:
-		if (tb[TCA_MPLS_LABEL]) {
-			val = rta_getattr_u32(tb[TCA_MPLS_LABEL]);
-			print_uint(PRINT_ANY, "label", " label %u", val);
-		}
-		if (tb[TCA_MPLS_TC]) {
-			val = rta_getattr_u8(tb[TCA_MPLS_TC]);
-			print_uint(PRINT_ANY, "tc", " tc %u", val);
-		}
-		if (tb[TCA_MPLS_BOS]) {
-			val = rta_getattr_u8(tb[TCA_MPLS_BOS]);
-			print_uint(PRINT_ANY, "bos", " bos %u", val);
-		}
-		if (tb[TCA_MPLS_TTL]) {
-			val = rta_getattr_u8(tb[TCA_MPLS_TTL]);
-			print_uint(PRINT_ANY, "ttl", " ttl %u", val);
-		}
-		break;
-	}
-	print_action_control(f, " ", parm->action, "");
-
-	print_uint(PRINT_ANY, "index", "\n\t index %u", parm->index);
-	print_int(PRINT_ANY, "ref", " ref %d", parm->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);
-
-	if (show_stats) {
-		if (tb[TCA_MPLS_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_MPLS_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	return 0;
-}
-
-struct action_util mpls_action_util = {
-	.id = "mpls",
-	.parse_aopt = parse_mpls,
-	.print_aopt = print_mpls,
-};
diff --git a/tc/m_nat.c b/tc/m_nat.c
index c4b02a8..d502a81 100644
--- a/tc/m_nat.c
+++ b/tc/m_nat.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -40,7 +41,7 @@
 }
 
 static int
-parse_nat_args(int *argc_p, char ***argv_p, struct tc_nat *sel)
+parse_nat_args(int *argc_p, char ***argv_p,struct tc_nat *sel)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
@@ -83,18 +84,20 @@
 static int
 parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
-	struct tc_nat sel = {};
+	struct tc_nat sel;
 
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int ok = 0;
 	struct rtattr *tail;
 
+	memset(&sel, 0, sizeof(sel));
+
 	while (argc > 0) {
 		if (matches(*argv, "nat") == 0) {
 			NEXT_ARG();
 			if (parse_nat_args(&argc, &argv, &sel)) {
-				fprintf(stderr, "Illegal nat construct (%s)\n",
+				fprintf(stderr, "Illegal nat construct (%s) \n",
 					*argv);
 				explain();
 				return -1;
@@ -114,7 +117,30 @@
 		return -1;
 	}
 
-	parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_OK);
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			sel.action = TC_ACT_RECLASSIFY;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pipe") == 0) {
+			sel.action = TC_ACT_PIPE;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "drop") == 0 ||
+			matches(*argv, "shot") == 0) {
+			sel.action = TC_ACT_SHOT;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "continue") == 0) {
+			sel.action = TC_ACT_UNSPEC;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pass") == 0) {
+			sel.action = TC_ACT_OK;
+			argc--;
+			argv++;
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
@@ -128,9 +154,10 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_NAT_PARMS, &sel, sizeof(sel));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -138,12 +165,13 @@
 }
 
 static int
-print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
+print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
 {
 	struct tc_nat *sel;
 	struct rtattr *tb[TCA_NAT_MAX + 1];
-	SPRINT_BUF(buf1);
-	SPRINT_BUF(buf2);
+	char buf1[256];
+	char buf2[256];
+	SPRINT_BUF(buf3);
 	int len;
 
 	if (arg == NULL)
@@ -152,7 +180,7 @@
 	parse_rtattr_nested(tb, TCA_NAT_MAX, arg);
 
 	if (tb[TCA_NAT_PARMS] == NULL) {
-		fprintf(stderr, "Missing nat parameters\n");
+		fprintf(f, "[NULL nat parameters]");
 		return -1;
 	}
 	sel = RTA_DATA(tb[TCA_NAT_PARMS]);
@@ -160,33 +188,20 @@
 	len = ffs(sel->mask);
 	len = len ? 33 - len : 0;
 
-	print_string(PRINT_ANY, "type", " %s ", "nat");
-	print_string(PRINT_ANY, "direction", "%s",
-		     sel->flags & TCA_NAT_FLAG_EGRESS ? "egress" : "ingress");
-
-	snprintf(buf2, sizeof(buf2), "%s/%d",
-		 format_host_r(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
-		 len);
-	print_string(PRINT_ANY, "old_addr", " %s", buf2);
-	print_string(PRINT_ANY, "new_addr", " %s",
-		     format_host_r(AF_INET, 4, &sel->new_addr, buf1, sizeof(buf1)));
-
-	print_action_control(f, " ", sel->action, "");
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", sel->index);
-	print_int(PRINT_ANY, "ref", " ref %d", sel->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", sel->bindcnt);
+	fprintf(f, " nat %s %s/%d %s %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
+					  "egress" : "ingress",
+		format_host(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
+		len,
+		format_host(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
+		action_n2a(sel->action, buf3, sizeof (buf3)));
 
 	if (show_stats) {
 		if (tb[TCA_NAT_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_NAT_TM]);
-
-			print_tm(f, tm);
+			print_tm(f,tm);
 		}
 	}
 
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
 	return 0;
 }
 
diff --git a/tc/m_pedit.c b/tc/m_pedit.c
index 1cd2d16..4fdd189 100644
--- a/tc/m_pedit.c
+++ b/tc/m_pedit.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,48 +28,45 @@
 #include "utils.h"
 #include "tc_util.h"
 #include "m_pedit.h"
-#include "rt_names.h"
 
 static struct m_pedit_util *pedit_list;
 static int pedit_debug;
 
-static void explain(void)
+static void
+explain(void)
 {
+	fprintf(stderr, "Usage: ... pedit munge <MUNGE>\n");
 	fprintf(stderr,
-		"Usage: ... pedit munge [ex] <MUNGE> [CONTROL]\n"
 		"Where: MUNGE := <RAW>|<LAYERED>\n"
-		"\t<RAW>:= <OFFSETC>[ATC]<CMD>\n \t\tOFFSETC:= offset <offval> <u8|u16|u32>\n"
-		"\t\tATC:= at <atval> offmask <maskval> shift <shiftval>\n"
-		"\t\tNOTE: offval is byte offset, must be multiple of 4\n"
-		"\t\tNOTE: maskval is a 32 bit hex number\n \t\tNOTE: shiftval is a shift value\n"
-		"\t\tCMD:= clear | invert | set <setval>| add <addval> | retain\n"
-		"\t<LAYERED>:= ip <ipdata> | ip6 <ip6data>\n"
-		" \t\t| udp <udpdata> | tcp <tcpdata> | icmp <icmpdata>\n"
-		"\tCONTROL:= reclassify | pipe | drop | continue | pass |\n"
-		"\t          goto chain <CHAIN_INDEX>\n"
-		"\tNOTE: if 'ex' is set, extended functionality will be supported (kernel >= 4.11)\n"
+		"\t<RAW>:= <OFFSETC>[ATC]<CMD>\n "
+		"\t\tOFFSETC:= offset <offval> <u8|u16|u32>\n "
+		"\t\tATC:= at <atval> offmask <maskval> shift <shiftval>\n "
+		"\t\tNOTE: offval is byte offset, must be multiple of 4\n "
+		"\t\tNOTE: maskval is a 32 bit hex number\n "
+		"\t\tNOTE: shiftval is a is a shift value\n "
+		"\t\tCMD:= clear | invert | set <setval>| retain\n "
+		"\t<LAYERED>:= ip <ipdata> | ip6 <ip6data> \n "
+		" \t\t| udp <udpdata> | tcp <tcpdata> | icmp <icmpdata> \n"
 		"For Example usage look at the examples directory\n");
 
 }
 
-static void usage(void)
+static void
+usage(void)
 {
 	explain();
 	exit(-1);
 }
 
-static int pedit_parse_nopopt(int *argc_p, char ***argv_p,
-			      struct m_pedit_sel *sel,
-			      struct m_pedit_key *tkey)
+static int
+pedit_parse_nopopt (int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
 
 	if (argc) {
-		fprintf(stderr,
-			"Unknown action  hence option \"%s\" is unparsable\n",
-			*argv);
-		return -1;
+		fprintf(stderr, "Unknown action  hence option \"%s\" is unparsable\n", *argv);
+			return -1;
 	}
 
 	return 0;
@@ -80,7 +78,7 @@
 	static void *pBODY;
 	void *dlh;
 	char buf[256];
-	struct m_pedit_util *p;
+	struct  m_pedit_util *p;
 
 	for (p = pedit_list; p; p = p->next) {
 		if (strcmp(p->id, str) == 0)
@@ -109,19 +107,19 @@
 	return p;
 
 noexist:
-	p = calloc(1, sizeof(*p));
+	p = malloc(sizeof(*p));
 	if (p) {
-		strlcpy(p->id, str, sizeof(p->id));
+		memset(p, 0, sizeof(*p));
+		strncpy(p->id, str, sizeof(p->id)-1);
 		p->parse_peopt = pedit_parse_nopopt;
 		goto reg;
 	}
 	return p;
 }
 
-static int pack_key(struct m_pedit_sel *_sel, struct m_pedit_key *tkey)
+int
+pack_key(struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
-	struct tc_pedit_sel *sel = &_sel->sel;
-	struct m_pedit_key_ex *keys_ex = _sel->keys_ex;
 	int hwm = sel->nkeys;
 
 	if (hwm >= MAX_OFFS)
@@ -138,25 +136,13 @@
 	sel->keys[hwm].at = tkey->at;
 	sel->keys[hwm].offmask = tkey->offmask;
 	sel->keys[hwm].shift = tkey->shift;
-
-	if (_sel->extended) {
-		keys_ex[hwm].htype = tkey->htype;
-		keys_ex[hwm].cmd = tkey->cmd;
-	} else {
-		if (tkey->htype != TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK ||
-		    tkey->cmd != TCA_PEDIT_KEY_EX_CMD_SET) {
-			fprintf(stderr,
-				"Munge parameters not supported. Use 'pedit ex munge ...'.\n");
-			return -1;
-		}
-	}
-
 	sel->nkeys++;
 	return 0;
 }
 
-static int pack_key32(__u32 retain, struct m_pedit_sel *sel,
-		      struct m_pedit_key *tkey)
+
+int
+pack_key32(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	if (tkey->off > (tkey->off & ~3)) {
 		fprintf(stderr,
@@ -166,14 +152,16 @@
 
 	tkey->val = htonl(tkey->val & retain);
 	tkey->mask = htonl(tkey->mask | ~retain);
-	return pack_key(sel, tkey);
+	/* jamal remove this - it is not necessary given the if check above */
+	tkey->off &= ~3;
+	return pack_key(sel,tkey);
 }
 
-static int pack_key16(__u32 retain, struct m_pedit_sel *sel,
-		      struct m_pedit_key *tkey)
+int
+pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int ind, stride;
-	__u32 m[4] = { 0x0000FFFF, 0xFF0000FF, 0xFFFF0000 };
+	__u32 m[4] = {0xFFFF0000,0xFF0000FF,0x0000FFFF};
 
 	if (tkey->val > 0xFFFF || tkey->mask > 0xFFFF) {
 		fprintf(stderr, "pack_key16 bad value\n");
@@ -183,107 +171,53 @@
 	ind = tkey->off & 3;
 
 	if (ind == 3) {
-		fprintf(stderr, "pack_key16 bad index value %d\n", ind);
+		fprintf(stderr, "pack_key16 bad index value %d\n",ind);
 		return -1;
 	}
 
-	stride = 8 * (2 - ind);
-	tkey->val = htonl((tkey->val & retain) << stride);
-	tkey->mask = htonl(((tkey->mask | ~retain) << stride) | m[ind]);
+	stride = 8 * ind;
+	tkey->val = htons(tkey->val);
+	tkey->val <<= stride;
+	tkey->mask <<= stride;
+	retain <<= stride;
+	tkey->mask = retain|m[ind];
 
 	tkey->off &= ~3;
 
 	if (pedit_debug)
-		printf("pack_key16: Final val %08x mask %08x\n",
-		       tkey->val, tkey->mask);
-	return pack_key(sel, tkey);
+		printf("pack_key16: Final val %08x mask %08x \n",tkey->val,tkey->mask);
+	return pack_key(sel,tkey);
+
 }
 
-static int pack_key8(__u32 retain, struct m_pedit_sel *sel,
-		     struct m_pedit_key *tkey)
+int
+pack_key8(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int ind, stride;
-	__u32 m[4] = { 0x00FFFFFF, 0xFF00FFFF, 0xFFFF00FF, 0xFFFFFF00 };
+	__u32 m[4] = {0xFFFFFF00,0xFFFF00FF,0xFF00FFFF,0x00FFFFFF};
 
 	if (tkey->val > 0xFF || tkey->mask > 0xFF) {
-		fprintf(stderr, "pack_key8 bad value (val %x mask %x\n",
-			tkey->val, tkey->mask);
+		fprintf(stderr, "pack_key8 bad value (val %x mask %x\n", tkey->val, tkey->mask);
 		return -1;
 	}
 
 	ind = tkey->off & 3;
 
-	stride = 8 * (3 - ind);
-	tkey->val = htonl((tkey->val & retain) << stride);
-	tkey->mask = htonl(((tkey->mask | ~retain) << stride) | m[ind]);
+	stride = 8 * ind;
+	tkey->val <<= stride;
+	tkey->mask <<= stride;
+	retain <<= stride;
+	tkey->mask = retain|m[ind];
 
 	tkey->off &= ~3;
 
 	if (pedit_debug)
-		printf("pack_key8: Final word off %d  val %08x mask %08x\n",
-		       tkey->off, tkey->val, tkey->mask);
-	return pack_key(sel, tkey);
+		printf("pack_key8: Final word off %d  val %08x mask %08x \n",tkey->off , tkey->val,tkey->mask);
+	return pack_key(sel,tkey);
 }
 
-static int pack_mac(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
-		    __u8 *mac)
-{
-	int ret = 0;
-
-	if (!(tkey->off & 0x3)) {
-		tkey->mask = 0;
-		tkey->val = ntohl(*((__u32 *)mac));
-		ret |= pack_key32(~0, sel, tkey);
-
-		tkey->off += 4;
-		tkey->mask = 0;
-		tkey->val = ntohs(*((__u16 *)&mac[4]));
-		ret |= pack_key16(~0, sel, tkey);
-	} else if (!(tkey->off & 0x1)) {
-		tkey->mask = 0;
-		tkey->val = ntohs(*((__u16 *)mac));
-		ret |= pack_key16(~0, sel, tkey);
-
-		tkey->off += 4;
-		tkey->mask = 0;
-		tkey->val = ntohl(*((__u32 *)(mac + 2)));
-		ret |= pack_key32(~0, sel, tkey);
-	} else {
-		fprintf(stderr,
-			"pack_mac: mac offsets must begin in 32bit or 16bit boundaries\n");
-		return -1;
-	}
-
-	return ret;
-}
-
-static int pack_ipv6(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
-		     __u32 *ipv6)
-{
-	int ret = 0;
-	int i;
-
-	if (tkey->off & 0x3) {
-		fprintf(stderr,
-			"pack_ipv6: IPv6 offsets must begin in 32bit boundaries\n");
-		return -1;
-	}
-
-	for (i = 0; i < 4; i++) {
-		tkey->mask = 0;
-		tkey->val = ntohl(ipv6[i]);
-
-		ret = pack_key32(~0, sel, tkey);
-		if (ret)
-			return ret;
-
-		tkey->off += 4;
-	}
-
-	return 0;
-}
-
-static int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
+int
+parse_val(int *argc_p, char ***argv_p, __u32 * val, int type)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
@@ -291,51 +225,32 @@
 	if (argc <= 0)
 		return -1;
 
-	if (type == TINT)
-		return get_integer((int *)val, *argv, 0);
+	if (TINT == type)
+		return get_integer((int *) val, *argv, 0);
 
-	if (type == TU32)
+	if (TU32 == type)
 		return get_u32(val, *argv, 0);
 
-	if (type == TIPV4) {
+	if (TIPV4 == type) {
 		inet_prefix addr;
-
-		if (get_prefix_1(&addr, *argv, AF_INET))
+		if (get_prefix_1(&addr, *argv, AF_INET)) {
 			return -1;
-
-		*val = addr.data[0];
+		}
+		*val=addr.data[0];
 		return 0;
 	}
-
-	if (type == TIPV6) {
-		inet_prefix addr;
-
-		if (get_prefix_1(&addr, *argv, AF_INET6))
-			return -1;
-
-		memcpy(val, addr.data, addr.bytelen);
-
-		return 0;
-	}
-
-	if (type == TMAC) {
-#define MAC_ALEN 6
-		int ret = ll_addr_a2n((char *)val, MAC_ALEN, *argv);
-
-		if (ret == MAC_ALEN)
-			return 0;
+	if (TIPV6 == type) {
+		/* not implemented yet */
+		return -1;
 	}
 
 	return -1;
 }
 
-int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type, __u32 retain,
-	      struct m_pedit_sel *sel, struct m_pedit_key *tkey)
+int
+parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
-	__u32 mask[4] = { 0 };
-	__u32 val[4] = { 0 };
-	__u32 *m = &mask[0];
-	__u32 *v = &val[0];
+	__u32 mask = 0, val = 0;
 	__u32 o = 0xFF;
 	int res = -1;
 	int argc = *argc_p;
@@ -345,8 +260,7 @@
 		return -1;
 
 	if (pedit_debug)
-		printf("parse_cmd argc %d %s offset %d length %d\n",
-		       argc, *argv, tkey->off, len);
+		printf("parse_cmd argc %d %s offset %d length %d\n",argc,*argv,tkey->off,len);
 
 	if (len == 2)
 		o = 0xFFFF;
@@ -354,87 +268,57 @@
 		o = 0xFFFFFFFF;
 
 	if (matches(*argv, "invert") == 0) {
-		*v = *m = o;
-	} else if (matches(*argv, "set") == 0 ||
-		   matches(*argv, "add") == 0) {
-		if (matches(*argv, "add") == 0)
-			tkey->cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
-
-		if (!sel->extended && tkey->cmd) {
-			fprintf(stderr,
-				"Non extended mode. only 'set' command is supported\n");
-			return -1;
-		}
-
+		retain = val = mask = o;
+	} else if (matches(*argv, "set") == 0) {
 		NEXT_ARG();
-		if (parse_val(&argc, &argv, val, type))
+		if (parse_val(&argc, &argv, &val, type))
 			return -1;
 	} else if (matches(*argv, "preserve") == 0) {
-		retain = 0;
+		retain = mask = o;
 	} else {
 		if (matches(*argv, "clear") != 0)
 			return -1;
 	}
 
-	argc--;
-	argv++;
+	argc--; argv++;
 
 	if (argc && matches(*argv, "retain") == 0) {
 		NEXT_ARG();
 		if (parse_val(&argc, &argv, &retain, TU32))
 			return -1;
-		argc--;
-		argv++;
+		argc--; argv++;
 	}
 
-	if (len > 4 && retain != ~0) {
-		fprintf(stderr,
-			"retain is not supported for fields longer the 32 bits\n");
-		return -1;
-	}
-
-	if (type == TMAC) {
-		res = pack_mac(sel, tkey, (__u8 *)val);
-		goto done;
-	}
-
-	if (type == TIPV6) {
-		res = pack_ipv6(sel, tkey, val);
-		goto done;
-	}
-
-	tkey->val = *v;
-	tkey->mask = *m;
-
-	if (type == TIPV4)
-		tkey->val = ntohl(tkey->val);
+	tkey->val = val;
 
 	if (len == 1) {
-		res = pack_key8(retain, sel, tkey);
+		tkey->mask = 0xFF;
+		res = pack_key8(retain,sel,tkey);
 		goto done;
 	}
 	if (len == 2) {
-		res = pack_key16(retain, sel, tkey);
+		tkey->mask = mask;
+		res = pack_key16(retain,sel,tkey);
 		goto done;
 	}
 	if (len == 4) {
-		res = pack_key32(retain, sel, tkey);
+		tkey->mask = mask;
+		res = pack_key32(retain,sel,tkey);
 		goto done;
 	}
 
 	return -1;
 done:
 	if (pedit_debug)
-		printf("parse_cmd done argc %d %s offset %d length %d\n",
-		       argc, *argv, tkey->off, len);
+		printf("parse_cmd done argc %d %s offset %d length %d\n",argc,*argv,tkey->off,len);
 	*argc_p = argc;
 	*argv_p = argv;
 	return res;
 
 }
 
-static int parse_offset(int *argc_p, char ***argv_p, struct m_pedit_sel *sel,
-			struct m_pedit_key *tkey)
+int
+parse_offset(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int off;
 	__u32 len, retain;
@@ -455,6 +339,7 @@
 	if (argc <= 0)
 		return -1;
 
+
 	if (matches(*argv, "u32") == 0) {
 		len = 4;
 		retain = 0xFFFFFFFF;
@@ -462,12 +347,12 @@
 	}
 	if (matches(*argv, "u16") == 0) {
 		len = 2;
-		retain = 0xffff;
+		retain = 0x0;
 		goto done;
 	}
 	if (matches(*argv, "u8") == 0) {
 		len = 1;
-		retain = 0xff;
+		retain = 0x0;
 		goto done;
 	}
 
@@ -480,7 +365,7 @@
 	/* [at <someval> offmask <maskval> shift <shiftval>] */
 	if (matches(*argv, "at") == 0) {
 
-		__u32 atv = 0, offmask = 0x0, shift = 0;
+		__u32 atv=0,offmask=0x0,shift=0;
 
 		NEXT_ARG();
 		if (get_u32(&atv, *argv, 0))
@@ -502,16 +387,17 @@
 		NEXT_ARG();
 	}
 
-	res = parse_cmd(&argc, &argv, len, TU32, retain, sel, tkey);
+	res = parse_cmd(&argc, &argv, len, TU32,retain,sel,tkey);
 
 	*argc_p = argc;
 	*argv_p = argv;
 	return res;
 }
 
-static int parse_munge(int *argc_p, char ***argv_p, struct m_pedit_sel *sel)
+static int
+parse_munge(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel)
 {
-	struct m_pedit_key tkey = {};
+	struct tc_pedit_key tkey;
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int res = -1;
@@ -519,24 +405,25 @@
 	if (argc <= 0)
 		return -1;
 
+	memset(&tkey, 0, sizeof(tkey));
+
 	if (matches(*argv, "offset") == 0) {
 		NEXT_ARG();
-		res = parse_offset(&argc, &argv, sel, &tkey);
+		res = parse_offset(&argc, &argv,sel,&tkey);
 		goto done;
 	} else {
-		char k[FILTER_NAMESZ];
+		char k[16];
 		struct m_pedit_util *p = NULL;
 
-		strncpy(k, *argv, sizeof(k) - 1);
+		strncpy(k, *argv, sizeof (k) - 1);
 
-		if (argc > 0) {
+		if (argc > 0 ) {
 			p = get_pedit_kind(k);
-			if (p == NULL)
+			if (NULL == p)
 				goto bad_val;
-			NEXT_ARG();
-			res = p->parse_peopt(&argc, &argv, sel, &tkey);
+			res = p->parse_peopt(&argc, &argv, sel,&tkey);
 			if (res < 0) {
-				fprintf(stderr, "bad pedit parsing\n");
+				fprintf(stderr,"bad pedit parsing\n");
 				goto bad_val;
 			}
 			goto done;
@@ -553,108 +440,39 @@
 	return res;
 }
 
-static int pedit_keys_ex_getattr(struct rtattr *attr,
-				 struct m_pedit_key_ex *keys_ex, int n)
+int
+parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
-	struct rtattr *i;
-	int rem = RTA_PAYLOAD(attr);
-	struct rtattr *tb[TCA_PEDIT_KEY_EX_MAX + 1];
-	struct m_pedit_key_ex *k = keys_ex;
-
-	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
-		if (!n)
-			return -1;
-
-		if (i->rta_type != TCA_PEDIT_KEY_EX)
-			return -1;
-
-		parse_rtattr_nested(tb, TCA_PEDIT_KEY_EX_MAX, i);
-
-		k->htype = rta_getattr_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]);
-		k->cmd = rta_getattr_u16(tb[TCA_PEDIT_KEY_EX_CMD]);
-
-		k++;
-		n--;
-	}
-
-	return !!n;
-}
-
-static int pedit_keys_ex_addattr(struct m_pedit_sel *sel, struct nlmsghdr *n)
-{
-	struct m_pedit_key_ex *k = sel->keys_ex;
-	struct rtattr *keys_start;
-	int i;
-
-	if (!sel->extended)
-		return 0;
-
-	keys_start = addattr_nest(n, MAX_MSG, TCA_PEDIT_KEYS_EX | NLA_F_NESTED);
-
-	for (i = 0; i < sel->sel.nkeys; i++) {
-		struct rtattr *key_start;
-
-		key_start = addattr_nest(n, MAX_MSG,
-					 TCA_PEDIT_KEY_EX | NLA_F_NESTED);
-
-		if (addattr16(n, MAX_MSG, TCA_PEDIT_KEY_EX_HTYPE, k->htype) ||
-		    addattr16(n, MAX_MSG, TCA_PEDIT_KEY_EX_CMD, k->cmd)) {
-			return -1;
-		}
-
-		addattr_nest_end(n, key_start);
-
-		k++;
-	}
-
-	addattr_nest_end(n, keys_start);
-
-	return 0;
-}
-
-static int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p,
-		       int tca_id, struct nlmsghdr *n)
-{
-	struct m_pedit_sel sel = {};
+	struct {
+		struct tc_pedit_sel sel;
+		struct tc_pedit_key keys[MAX_OFFS];
+	} sel;
 
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int ok = 0, iok = 0;
 	struct rtattr *tail;
 
+	memset(&sel, 0, sizeof(sel));
+
 	while (argc > 0) {
 		if (pedit_debug > 1)
-			fprintf(stderr, "while pedit (%d:%s)\n", argc, *argv);
+			fprintf(stderr, "while pedit (%d:%s)\n",argc, *argv);
 		if (matches(*argv, "pedit") == 0) {
 			NEXT_ARG();
 			ok++;
-
-			if (matches(*argv, "ex") == 0) {
-				if (ok > 1) {
-					fprintf(stderr,
-						"'ex' must be before first 'munge'\n");
-					explain();
-					return -1;
-				}
-				sel.extended = true;
-				NEXT_ARG();
-			}
-
 			continue;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else if (matches(*argv, "munge") == 0) {
 			if (!ok) {
-				fprintf(stderr, "Bad pedit construct (%s)\n",
-					*argv);
+				fprintf(stderr, "Illegal pedit construct (%s) \n", *argv);
 				explain();
 				return -1;
 			}
 			NEXT_ARG();
-
-			if (parse_munge(&argc, &argv, &sel)) {
-				fprintf(stderr, "Bad pedit construct (%s)\n",
-					*argv);
+			if (parse_munge(&argc, &argv,&sel.sel)) {
+				fprintf(stderr, "Illegal pedit construct (%s) \n", *argv);
 				explain();
 				return -1;
 			}
@@ -670,7 +488,25 @@
 		return -1;
 	}
 
-	parse_action_control_dflt(&argc, &argv, &sel.sel.action, false, TC_ACT_OK);
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			sel.sel.action = TC_ACT_RECLASSIFY;
+			NEXT_ARG();
+		} else if (matches(*argv, "pipe") == 0) {
+			sel.sel.action = TC_ACT_PIPE;
+			NEXT_ARG();
+		} else if (matches(*argv, "drop") == 0 ||
+			matches(*argv, "shot") == 0) {
+			sel.sel.action = TC_ACT_SHOT;
+			NEXT_ARG();
+		} else if (matches(*argv, "continue") == 0) {
+			sel.sel.action = TC_ACT_UNSPEC;
+			NEXT_ARG();
+		} else if (matches(*argv, "pass") == 0) {
+			sel.sel.action = TC_ACT_OK;
+			NEXT_ARG();
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
@@ -685,144 +521,66 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	if (!sel.extended) {
-		addattr_l(n, MAX_MSG, TCA_PEDIT_PARMS, &sel,
-			  sizeof(sel.sel) +
-			  sel.sel.nkeys * sizeof(struct tc_pedit_key));
-	} else {
-		addattr_l(n, MAX_MSG, TCA_PEDIT_PARMS_EX, &sel,
-			  sizeof(sel.sel) +
-			  sel.sel.nkeys * sizeof(struct tc_pedit_key));
-
-		pedit_keys_ex_addattr(&sel, n);
-	}
-
-	addattr_nest_end(n, tail);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+	addattr_l(n, MAX_MSG, TCA_PEDIT_PARMS,&sel, sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_pedit_key));
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
 	return 0;
 }
 
-static const char * const pedit_htype_str[] = {
-	[TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK] = "",
-	[TCA_PEDIT_KEY_EX_HDR_TYPE_ETH] = "eth",
-	[TCA_PEDIT_KEY_EX_HDR_TYPE_IP4] = "ipv4",
-	[TCA_PEDIT_KEY_EX_HDR_TYPE_IP6] = "ipv6",
-	[TCA_PEDIT_KEY_EX_HDR_TYPE_TCP] = "tcp",
-	[TCA_PEDIT_KEY_EX_HDR_TYPE_UDP] = "udp",
-};
-
-static void print_pedit_location(FILE *f,
-				 enum pedit_header_type htype, __u32 off)
-{
-	if (htype == TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK) {
-		fprintf(f, "%d", (unsigned int)off);
-		return;
-	}
-
-	if (htype < ARRAY_SIZE(pedit_htype_str))
-		fprintf(f, "%s", pedit_htype_str[htype]);
-	else
-		fprintf(f, "unknown(%d)", htype);
-
-	fprintf(f, "%c%d", (int)off  >= 0 ? '+' : '-', abs((int)off));
-}
-
-static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
+int
+print_pedit(struct action_util *au,FILE * f, struct rtattr *arg)
 {
 	struct tc_pedit_sel *sel;
 	struct rtattr *tb[TCA_PEDIT_MAX + 1];
-	struct m_pedit_key_ex *keys_ex = NULL;
+	SPRINT_BUF(b1);
 
 	if (arg == NULL)
 		return -1;
 
 	parse_rtattr_nested(tb, TCA_PEDIT_MAX, arg);
 
-	if (!tb[TCA_PEDIT_PARMS] && !tb[TCA_PEDIT_PARMS_EX]) {
-		fprintf(stderr, "Missing pedit parameters\n");
+	if (tb[TCA_PEDIT_PARMS] == NULL) {
+		fprintf(f, "[NULL pedit parameters]");
 		return -1;
 	}
+	sel = RTA_DATA(tb[TCA_PEDIT_PARMS]);
 
-	if (tb[TCA_PEDIT_PARMS]) {
-		sel = RTA_DATA(tb[TCA_PEDIT_PARMS]);
-	} else {
-		int err;
-
-		sel = RTA_DATA(tb[TCA_PEDIT_PARMS_EX]);
-
-		if (!tb[TCA_PEDIT_KEYS_EX]) {
-			fprintf(f, "Netlink error\n");
-			return -1;
-		}
-
-		keys_ex = calloc(sel->nkeys, sizeof(*keys_ex));
-		if (!keys_ex) {
-			fprintf(f, "Out of memory\n");
-			return -1;
-		}
-
-		err = pedit_keys_ex_getattr(tb[TCA_PEDIT_KEYS_EX], keys_ex,
-					    sel->nkeys);
-		if (err) {
-			fprintf(f, "Netlink error\n");
-
-			free(keys_ex);
-			return -1;
-		}
-	}
-
-	fprintf(f, " pedit ");
-	print_action_control(f, "action ", sel->action, " ");
-	fprintf(f,"keys %d\n ", sel->nkeys);
-	fprintf(f, "\t index %u ref %d bind %d", sel->index, sel->refcnt,
-		sel->bindcnt);
+	fprintf(f, " pedit action %s keys %d\n ", action_n2a(sel->action, b1, sizeof (b1)),sel->nkeys);
+	fprintf(f, "\t index %d ref %d bind %d", sel->index,sel->refcnt, sel->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_PEDIT_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_PEDIT_TM]);
-
-			print_tm(f, tm);
+			print_tm(f,tm);
 		}
 	}
 	if (sel->nkeys) {
 		int i;
 		struct tc_pedit_key *key = sel->keys;
-		struct m_pedit_key_ex *key_ex = keys_ex;
 
-		for (i = 0; i < sel->nkeys; i++, key++) {
-			enum pedit_header_type htype =
-				TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
-			enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;
-
-			if (keys_ex) {
-				htype = key_ex->htype;
-				cmd = key_ex->cmd;
-
-				key_ex++;
-			}
-
-			fprintf(f, "\n\t key #%d", i);
-
-			fprintf(f, "  at ");
-
-			print_pedit_location(f, htype, key->off);
-
-			fprintf(f, ": %s %08x mask %08x",
-				cmd ? "add" : "val",
-				(unsigned int)ntohl(key->val),
-				(unsigned int)ntohl(key->mask));
+		for (i=0; i<sel->nkeys; i++, key++) {
+			fprintf(f, "\n\t key #%d",i);
+			fprintf(f, "  at %d: val %08x mask %08x",
+			(unsigned int)key->off,
+			(unsigned int)ntohl(key->val),
+			(unsigned int)ntohl(key->mask));
 		}
 	} else {
-		fprintf(f, "\npedit %x keys %d is not LEGIT", sel->index,
-			sel->nkeys);
+		fprintf(f, "\npedit %x keys %d is not LEGIT", sel->index,sel->nkeys);
 	}
 
-	fprintf(f, "\n ");
 
-	free(keys_ex);
+	fprintf(f, "\n ");
+	return 0;
+}
+
+int
+pedit_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats)
+{
 	return 0;
 }
 
diff --git a/tc/m_pedit.h b/tc/m_pedit.h
index 5d3628a..1698c95 100644
--- a/tc/m_pedit.h
+++ b/tc/m_pedit.h
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -31,7 +32,6 @@
 #define TIPV6 2
 #define TINT 3
 #define TU32 4
-#define TMAC 5
 
 #define RU32 0xFFFFFFFF
 #define RU16 0xFFFF
@@ -39,39 +39,24 @@
 
 #define PEDITKINDSIZ 16
 
-struct m_pedit_key {
-	__u32           mask;  /* AND */
-	__u32           val;   /*XOR */
-	__u32           off;  /*offset */
-	__u32           at;
-	__u32           offmask;
-	__u32           shift;
-
-	enum pedit_header_type htype;
-	enum pedit_cmd cmd;
-};
-
-struct m_pedit_key_ex {
-	enum pedit_header_type htype;
-	enum pedit_cmd cmd;
-};
-
-struct m_pedit_sel {
-	struct tc_pedit_sel sel;
-	struct tc_pedit_key keys[MAX_OFFS];
-	struct m_pedit_key_ex keys_ex[MAX_OFFS];
-	bool extended;
-};
-
-struct m_pedit_util {
+struct m_pedit_util
+{
 	struct m_pedit_util *next;
 	char    id[PEDITKINDSIZ];
-	int     (*parse_peopt)(int *argc_p, char ***argv_p,
-			       struct m_pedit_sel *sel,
-			       struct m_pedit_key *tkey);
+	int     (*parse_peopt)(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
 };
 
-int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,
-	      __u32 retain,
-	      struct m_pedit_sel *sel, struct m_pedit_key *tkey);
+
+extern int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+extern int pack_key(struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+extern int pack_key32(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+extern int pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+extern int pack_key8(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+extern int parse_val(int *argc_p, char ***argv_p, __u32 * val, int type);
+extern int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+extern int parse_offset(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey);
+int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
+extern int print_pedit(struct action_util *au,FILE * f, struct rtattr *arg);
+extern int pedit_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats);
+
 #endif
diff --git a/tc/m_police.c b/tc/m_police.c
index a5bc20c..915f1a5 100644
--- a/tc/m_police.c
+++ b/tc/m_police.c
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -25,10 +26,6 @@
 #include "utils.h"
 #include "tc_util.h"
 
-static int act_parse_police(struct action_util *a, int *argc_p,
-			    char ***argv_p, int tca_id, struct nlmsghdr *n);
-static int print_police(struct action_util *a, FILE *f, struct rtattr *tb);
-
 struct action_util police_action_util = {
 	.id = "police",
 	.parse_aopt = act_parse_police,
@@ -37,36 +34,112 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: ... police rate BPS burst BYTES[/BYTES] [ mtu BYTES[/BYTES] ]\n"
-		"		[ peakrate BPS ] [ avrate BPS ] [ overhead BYTES ]\n"
-		"		[ linklayer TYPE ] [ CONTROL ]\n"
-		"Where: CONTROL := conform-exceed <EXCEEDACT>[/NOTEXCEEDACT]\n"
-		"		  Define how to handle packets which exceed (<EXCEEDACT>)\n"
-		"		  or conform (<NOTEXCEEDACT>) the configured bandwidth limit.\n"
-		"       EXCEEDACT/NOTEXCEEDACT := { pipe | ok | reclassify | drop | continue |\n"
-		"				   goto chain <CHAIN_INDEX> }\n");
+	fprintf(stderr, "Usage: ... police rate BPS burst BYTES[/BYTES] [ mtu BYTES[/BYTES] ]\n");
+	fprintf(stderr, "                [ peakrate BPS ] [ avrate BPS ] [ overhead BYTES ]\n");
+	fprintf(stderr, "                [ linklayer TYPE ] [ ACTIONTERM ]\n");
+
+	fprintf(stderr, "New Syntax ACTIONTERM := conform-exceed <EXCEEDACT>[/NOTEXCEEDACT] \n");
+	fprintf(stderr, "Where: *EXCEEDACT := pipe | ok | reclassify | drop | continue \n");
+	fprintf(stderr, "Where:  pipe is only valid for new syntax \n");
 	exit(-1);
 }
 
-static int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p,
-			    int tca_id, struct nlmsghdr *n)
+static void explain1(char *arg)
+{
+	fprintf(stderr, "Illegal \"%s\"\n", arg);
+}
+
+static const char *police_action_n2a(int action, char *buf, int len)
+{
+	switch (action) {
+	case -1:
+		return "continue";
+		break;
+	case TC_POLICE_OK:
+		return "pass";
+		break;
+	case TC_POLICE_SHOT:
+		return "drop";
+		break;
+	case TC_POLICE_RECLASSIFY:
+		return "reclassify";
+	case TC_POLICE_PIPE:
+		return "pipe";
+	default:
+		snprintf(buf, len, "%d", action);
+		return buf;
+	}
+}
+
+static int police_action_a2n(const char *arg, int *result)
+{
+	int res;
+
+	if (matches(arg, "continue") == 0)
+		res = -1;
+	else if (matches(arg, "drop") == 0)
+		res = TC_POLICE_SHOT;
+	else if (matches(arg, "shot") == 0)
+		res = TC_POLICE_SHOT;
+	else if (matches(arg, "pass") == 0)
+		res = TC_POLICE_OK;
+	else if (strcmp(arg, "ok") == 0)
+		res = TC_POLICE_OK;
+	else if (matches(arg, "reclassify") == 0)
+		res = TC_POLICE_RECLASSIFY;
+	else if (matches(arg, "pipe") == 0)
+		res = TC_POLICE_PIPE;
+	else {
+		char dummy;
+		if (sscanf(arg, "%d%c", &res, &dummy) != 1)
+			return -1;
+	}
+	*result = res;
+	return 0;
+}
+
+
+static int get_police_result(int *action, int *result, char *arg)
+{
+	char *p = strchr(arg, '/');
+
+	if (p)
+		*p = 0;
+
+	if (police_action_a2n(arg, action)) {
+		if (p)
+			*p = '/';
+		return -1;
+	}
+
+	if (p) {
+		*p = '/';
+		if (police_action_a2n(p+1, result))
+			return -1;
+	}
+	return 0;
+}
+
+
+int act_parse_police(struct action_util *a,int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
 	int argc = *argc_p;
 	char **argv = *argv_p;
 	int res = -1;
-	int ok = 0;
-	struct tc_police p = { .action = TC_POLICE_RECLASSIFY };
+	int ok=0;
+	struct tc_police p;
 	__u32 rtab[256];
 	__u32 ptab[256];
 	__u32 avrate = 0;
 	int presult = 0;
-	unsigned buffer = 0, mtu = 0, mpu = 0;
-	unsigned short overhead = 0;
+	unsigned buffer=0, mtu=0, mpu=0;
+	unsigned short overhead=0;
 	unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
-	int Rcell_log =  -1, Pcell_log = -1;
+	int Rcell_log=-1, Pcell_log = -1;
 	struct rtattr *tail;
-	__u64 rate64 = 0, prate64 = 0;
+
+	memset(&p, 0, sizeof(p));
+	p.action = TC_POLICE_RECLASSIFY;
 
 	if (a) /* new way of doing things */
 		NEXT_ARG();
@@ -78,102 +151,118 @@
 
 		if (matches(*argv, "index") == 0) {
 			NEXT_ARG();
-			if (get_u32(&p.index, *argv, 10))
-				invarg("index", *argv);
+			if (get_u32(&p.index, *argv, 10)) {
+				fprintf(stderr, "Illegal \"index\"\n");
+				return -1;
+			}
 		} else if (matches(*argv, "burst") == 0 ||
 			strcmp(*argv, "buffer") == 0 ||
 			strcmp(*argv, "maxburst") == 0) {
 			NEXT_ARG();
-			if (buffer)
-				duparg("buffer/burst", *argv);
-			if (get_size_and_cell(&buffer, &Rcell_log, *argv) < 0)
-				invarg("buffer", *argv);
+			if (buffer) {
+				fprintf(stderr, "Double \"buffer/burst\" spec\n");
+				return -1;
+			}
+			if (get_size_and_cell(&buffer, &Rcell_log, *argv) < 0) {
+				explain1("buffer");
+				return -1;
+			}
 		} else if (strcmp(*argv, "mtu") == 0 ||
 			   strcmp(*argv, "minburst") == 0) {
 			NEXT_ARG();
-			if (mtu)
-				duparg("mtu/minburst", *argv);
-			if (get_size_and_cell(&mtu, &Pcell_log, *argv) < 0)
-				invarg("mtu", *argv);
+			if (mtu) {
+				fprintf(stderr, "Double \"mtu/minburst\" spec\n");
+				return -1;
+			}
+			if (get_size_and_cell(&mtu, &Pcell_log, *argv) < 0) {
+				explain1("mtu");
+				return -1;
+			}
 		} else if (strcmp(*argv, "mpu") == 0) {
 			NEXT_ARG();
-			if (mpu)
-				duparg("mpu", *argv);
-			if (get_size(&mpu, *argv))
-				invarg("mpu", *argv);
+			if (mpu) {
+				fprintf(stderr, "Double \"mpu\" spec\n");
+				return -1;
+			}
+			if (get_size(&mpu, *argv)) {
+				explain1("mpu");
+				return -1;
+			}
 		} else if (strcmp(*argv, "rate") == 0) {
 			NEXT_ARG();
-			if (rate64)
-				duparg("rate", *argv);
-			if (get_rate64(&rate64, *argv))
-				invarg("rate", *argv);
+			if (p.rate.rate) {
+				fprintf(stderr, "Double \"rate\" spec\n");
+				return -1;
+			}
+			if (get_rate(&p.rate.rate, *argv)) {
+				explain1("rate");
+				return -1;
+			}
 		} else if (strcmp(*argv, "avrate") == 0) {
 			NEXT_ARG();
-			if (avrate)
-				duparg("avrate", *argv);
-			if (get_rate(&avrate, *argv))
-				invarg("avrate", *argv);
+			if (avrate) {
+				fprintf(stderr, "Double \"avrate\" spec\n");
+				return -1;
+			}
+			if (get_rate(&avrate, *argv)) {
+				explain1("avrate");
+				return -1;
+			}
 		} else if (matches(*argv, "peakrate") == 0) {
 			NEXT_ARG();
-			if (prate64)
-				duparg("peakrate", *argv);
-			if (get_rate64(&prate64, *argv))
-				invarg("peakrate", *argv);
-		} else if (matches(*argv, "reclassify") == 0 ||
-			   matches(*argv, "drop") == 0 ||
-			   matches(*argv, "shot") == 0 ||
-			   matches(*argv, "continue") == 0 ||
-			   matches(*argv, "pass") == 0 ||
-			   matches(*argv, "ok") == 0 ||
-			   matches(*argv, "pipe") == 0 ||
-			   matches(*argv, "goto") == 0) {
-			if (!parse_action_control(&argc, &argv, &p.action, false))
-				goto action_ctrl_ok;
-			return -1;
+			if (p.peakrate.rate) {
+				fprintf(stderr, "Double \"peakrate\" spec\n");
+				return -1;
+			}
+			if (get_rate(&p.peakrate.rate, *argv)) {
+				explain1("peakrate");
+				return -1;
+			}
+		} else if (matches(*argv, "reclassify") == 0) {
+			p.action = TC_POLICE_RECLASSIFY;
+		} else if (matches(*argv, "drop") == 0 ||
+			   matches(*argv, "shot") == 0) {
+			p.action = TC_POLICE_SHOT;
+		} else if (matches(*argv, "continue") == 0) {
+			p.action = TC_POLICE_UNSPEC;
+		} else if (matches(*argv, "pass") == 0) {
+			p.action = TC_POLICE_OK;
+		} else if (matches(*argv, "pipe") == 0) {
+			p.action = TC_POLICE_PIPE;
 		} else if (strcmp(*argv, "conform-exceed") == 0) {
 			NEXT_ARG();
-			if (!parse_action_control_slash(&argc, &argv, &p.action,
-							&presult, true))
-				goto action_ctrl_ok;
-			return -1;
+			if (get_police_result(&p.action, &presult, *argv)) {
+				fprintf(stderr, "Illegal \"action\"\n");
+				return -1;
+			}
 		} else if (matches(*argv, "overhead") == 0) {
 			NEXT_ARG();
-			if (get_u16(&overhead, *argv, 10))
-				invarg("overhead", *argv);
+			if (get_u16(&overhead, *argv, 10)) {
+				explain1("overhead"); return -1;
+			}
 		} else if (matches(*argv, "linklayer") == 0) {
 			NEXT_ARG();
-			if (get_linklayer(&linklayer, *argv))
-				invarg("linklayer", *argv);
+			if (get_linklayer(&linklayer, *argv)) {
+				explain1("linklayer"); return -1;
+			}
 		} else if (strcmp(*argv, "help") == 0) {
 			usage();
 		} else {
 			break;
 		}
-		NEXT_ARG_FWD();
-action_ctrl_ok:
 		ok++;
+		argc--; argv++;
 	}
 
 	if (!ok)
 		return -1;
 
-	if (rate64 && avrate)
-		return -1;
-
-	/* Must at least do late binding, use TB or ewma policing */
-	if (!rate64 && !avrate && !p.index) {
-		fprintf(stderr, "\"rate\" or \"avrate\" MUST be specified.\n");
-		return -1;
-	}
-
-	/* When the TB policer is used, burst is required */
-	if (rate64 && !buffer && !avrate) {
+	if (p.rate.rate && !buffer) {
 		fprintf(stderr, "\"burst\" requires \"rate\".\n");
 		return -1;
 	}
-
-	if (prate64) {
-		if (!rate64) {
+	if (p.peakrate.rate) {
+		if (!p.rate.rate) {
 			fprintf(stderr, "\"peakrate\" requires \"rate\".\n");
 			return -1;
 		}
@@ -183,47 +272,38 @@
 		}
 	}
 
-	if (rate64) {
-		p.rate.rate = (rate64 >= (1ULL << 32)) ? ~0U : rate64;
+	if (p.rate.rate) {
 		p.rate.mpu = mpu;
 		p.rate.overhead = overhead;
-		if (tc_calc_rtable_64(&p.rate, rtab, Rcell_log, mtu,
-				   linklayer, rate64) < 0) {
-			fprintf(stderr, "POLICE: failed to calculate rate table.\n");
+		if (tc_calc_rtable(&p.rate, rtab, Rcell_log, mtu, linklayer) < 0) {
+			fprintf(stderr, "TBF: failed to calculate rate table.\n");
 			return -1;
 		}
-		p.burst = tc_calc_xmittime(rate64, buffer);
+		p.burst = tc_calc_xmittime(p.rate.rate, buffer);
 	}
 	p.mtu = mtu;
-	if (prate64) {
-		p.peakrate.rate = (prate64 >= (1ULL << 32)) ? ~0U : prate64;
+	if (p.peakrate.rate) {
 		p.peakrate.mpu = mpu;
 		p.peakrate.overhead = overhead;
-		if (tc_calc_rtable_64(&p.peakrate, ptab, Pcell_log, mtu,
-				   linklayer, prate64) < 0) {
+		if (tc_calc_rtable(&p.peakrate, ptab, Pcell_log, mtu, linklayer) < 0) {
 			fprintf(stderr, "POLICE: failed to calculate peak rate table.\n");
 			return -1;
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_POLICE_TBF, &p, sizeof(p));
-	if (rate64) {
+	if (p.rate.rate)
 		addattr_l(n, MAX_MSG, TCA_POLICE_RATE, rtab, 1024);
-		if (rate64 >= (1ULL << 32))
-			addattr64(n, MAX_MSG, TCA_POLICE_RATE64, rate64);
-	}
-	if (prate64) {
-		addattr_l(n, MAX_MSG, TCA_POLICE_PEAKRATE, ptab, 1024);
-		if (prate64 >= (1ULL << 32))
-			addattr64(n, MAX_MSG, TCA_POLICE_PEAKRATE64, prate64);
-	}
+	if (p.peakrate.rate)
+                addattr_l(n, MAX_MSG, TCA_POLICE_PEAKRATE, ptab, 1024);
 	if (avrate)
 		addattr32(n, MAX_MSG, TCA_POLICE_AVRATE, avrate);
 	if (presult)
 		addattr32(n, MAX_MSG, TCA_POLICE_RESULT, presult);
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	res = 0;
 
 	*argc_p = argc;
@@ -233,18 +313,18 @@
 
 int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
-	return act_parse_police(NULL, argc_p, argv_p, tca_id, n);
+	return act_parse_police(NULL,argc_p,argv_p,tca_id,n);
 }
 
-static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
+int
+print_police(struct action_util *a, FILE *f, struct rtattr *arg)
 {
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
 	struct tc_police *p;
 	struct rtattr *tb[TCA_POLICE_MAX+1];
-	unsigned int buffer;
+	unsigned buffer;
 	unsigned int linklayer;
-	__u64 rate64, prate64;
 
 	if (arg == NULL)
 		return 0;
@@ -263,60 +343,32 @@
 #endif
 	p = RTA_DATA(tb[TCA_POLICE_TBF]);
 
-	rate64 = p->rate.rate;
-	if (tb[TCA_POLICE_RATE64] &&
-	    RTA_PAYLOAD(tb[TCA_POLICE_RATE64]) >= sizeof(rate64))
-		rate64 = rta_getattr_u64(tb[TCA_POLICE_RATE64]);
-
 	fprintf(f, " police 0x%x ", p->index);
-	fprintf(f, "rate %s ", sprint_rate(rate64, b1));
-	buffer = tc_calc_xmitsize(rate64, p->burst);
+	fprintf(f, "rate %s ", sprint_rate(p->rate.rate, b1));
+	buffer = tc_calc_xmitsize(p->rate.rate, p->burst);
 	fprintf(f, "burst %s ", sprint_size(buffer, b1));
 	fprintf(f, "mtu %s ", sprint_size(p->mtu, b1));
 	if (show_raw)
 		fprintf(f, "[%08x] ", p->burst);
-
-	prate64 = p->peakrate.rate;
-	if (tb[TCA_POLICE_PEAKRATE64] &&
-	    RTA_PAYLOAD(tb[TCA_POLICE_PEAKRATE64]) >= sizeof(prate64))
-		prate64 = rta_getattr_u64(tb[TCA_POLICE_PEAKRATE64]);
-
-	if (prate64)
-		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
-
+	if (p->peakrate.rate)
+		fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1));
 	if (tb[TCA_POLICE_AVRATE])
-		fprintf(f, "avrate %s ",
-			sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]),
-				    b1));
-
-	print_action_control(f, "action ", p->action, "");
-
+		fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1));
+	fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1)));
 	if (tb[TCA_POLICE_RESULT]) {
-		__u32 action = rta_getattr_u32(tb[TCA_POLICE_RESULT]);
-
-		print_action_control(f, "/", action, " ");
+		fprintf(f, "/%s ", police_action_n2a(*(int*)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1)));
 	} else
 		fprintf(f, " ");
-
 	fprintf(f, "overhead %ub ", p->rate.overhead);
 	linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK);
 	if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
 		fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
-	fprintf(f, "\n\tref %d bind %d", p->refcnt, p->bindcnt);
-	if (show_stats) {
-		if (tb[TCA_POLICE_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_POLICE_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-	fprintf(f, "\n");
-
+	fprintf(f, "\nref %d bind %d\n",p->refcnt, p->bindcnt);
 
 	return 0;
 }
 
-int tc_print_police(FILE *f, struct rtattr *arg)
-{
-	return print_police(&police_action_util, f, arg);
+int
+tc_print_police(FILE *f, struct rtattr *arg) {
+	return print_police(&police_action_util,f,arg);
 }
diff --git a/tc/m_sample.c b/tc/m_sample.c
deleted file mode 100644
index c068e63..0000000
--- a/tc/m_sample.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * m_sample.c		ingress/egress packet sampling module
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Yotam Gigi <yotamg@mellanox.com>
- *
- */
-
-#include <stdio.h>
-#include "utils.h"
-#include "tc_util.h"
-#include "tc_common.h"
-#include <linux/tc_act/tc_sample.h>
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: sample SAMPLE_CONF\n"
-		"where:\n"
-		"\tSAMPLE_CONF := SAMPLE_PARAMS | SAMPLE_INDEX\n"
-		"\tSAMPLE_PARAMS := rate RATE group GROUP [trunc SIZE] [SAMPLE_INDEX]\n"
-		"\tSAMPLE_INDEX := index INDEX\n"
-		"\tRATE := The ratio of packets observed at the data source to the samples generated.\n"
-		"\tGROUP := the psample sampling group\n"
-		"\tSIZE := the truncation size\n"
-		"\tINDEX := integer index of the sample action\n");
-}
-
-static void usage(void)
-{
-	explain();
-	exit(-1);
-}
-
-static int parse_sample(struct action_util *a, int *argc_p, char ***argv_p,
-			int tca_id, struct nlmsghdr *n)
-{
-	struct tc_sample p = { 0 };
-	bool trunc_set = false;
-	bool group_set = false;
-	bool rate_set = false;
-	char **argv = *argv_p;
-	struct rtattr *tail;
-	int argc = *argc_p;
-	__u32 trunc;
-	__u32 group;
-	__u32 rate;
-
-	if (argc <= 1) {
-		fprintf(stderr, "sample bad argument count %d\n", argc);
-		usage();
-		return -1;
-	}
-
-	if (matches(*argv, "sample") == 0) {
-		NEXT_ARG();
-	} else {
-		fprintf(stderr, "sample bad argument %s\n", *argv);
-		return -1;
-	}
-
-	while (argc > 0) {
-		if (matches(*argv, "rate") == 0) {
-			NEXT_ARG();
-			if (get_u32(&rate, *argv, 10) != 0) {
-				fprintf(stderr, "Illegal rate %s\n", *argv);
-				usage();
-				return -1;
-			}
-			rate_set = true;
-		} else if (matches(*argv, "group") == 0) {
-			NEXT_ARG();
-			if (get_u32(&group, *argv, 10) != 0) {
-				fprintf(stderr, "Illegal group num %s\n",
-					*argv);
-				usage();
-				return -1;
-			}
-			group_set = true;
-		} else if (matches(*argv, "trunc") == 0) {
-			NEXT_ARG();
-			if (get_u32(&trunc, *argv, 10) != 0) {
-				fprintf(stderr, "Illegal truncation size %s\n",
-					*argv);
-				usage();
-				return -1;
-			}
-			trunc_set = true;
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			break;
-		}
-
-		NEXT_ARG_FWD();
-	}
-
-	parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&p.index, *argv, 10)) {
-				fprintf(stderr, "sample: Illegal \"index\"\n");
-				return -1;
-			}
-			NEXT_ARG_FWD();
-		}
-	}
-
-	if (!p.index && !group_set) {
-		fprintf(stderr, "param \"group\" not set\n");
-		usage();
-	}
-
-	if (!p.index && !rate_set) {
-		fprintf(stderr, "param \"rate\" not set\n");
-		usage();
-	}
-
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	addattr_l(n, MAX_MSG, TCA_SAMPLE_PARMS, &p, sizeof(p));
-	if (rate_set)
-		addattr32(n, MAX_MSG, TCA_SAMPLE_RATE, rate);
-	if (group_set)
-		addattr32(n, MAX_MSG, TCA_SAMPLE_PSAMPLE_GROUP, group);
-	if (trunc_set)
-		addattr32(n, MAX_MSG, TCA_SAMPLE_TRUNC_SIZE, trunc);
-
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	struct rtattr *tb[TCA_SAMPLE_MAX + 1];
-	struct tc_sample *p;
-
-	if (arg == NULL)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_SAMPLE_MAX, arg);
-
-	if (!tb[TCA_SAMPLE_PARMS] || !tb[TCA_SAMPLE_RATE] ||
-	    !tb[TCA_SAMPLE_PSAMPLE_GROUP]) {
-		fprintf(stderr, "Missing sample parameters\n");
-		return -1;
-	}
-	p = RTA_DATA(tb[TCA_SAMPLE_PARMS]);
-
-	print_string(PRINT_ANY, "kind", "%s ", "sample");
-	print_uint(PRINT_ANY, "rate", "rate 1/%u ",
-		   rta_getattr_u32(tb[TCA_SAMPLE_RATE]));
-	print_uint(PRINT_ANY, "group", "group %u",
-		   rta_getattr_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]));
-
-	if (tb[TCA_SAMPLE_TRUNC_SIZE])
-		print_uint(PRINT_ANY, "trunc_size", " trunc_size %u",
-			   rta_getattr_u32(tb[TCA_SAMPLE_TRUNC_SIZE]));
-
-	print_action_control(f, " ", p->action, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", p->index);
-	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
-
-	if (show_stats) {
-		if (tb[TCA_SAMPLE_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_SAMPLE_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	return 0;
-}
-
-struct action_util sample_action_util = {
-	.id = "sample",
-	.parse_aopt = parse_sample,
-	.print_aopt = print_sample,
-};
diff --git a/tc/m_simple.c b/tc/m_simple.c
index 49e2504..1ad5526 100644
--- a/tc/m_simple.c
+++ b/tc/m_simple.c
@@ -66,6 +66,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -80,11 +81,9 @@
 #endif
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage:... simple [sdata STRING] [index INDEX] [CONTROL]\n"
-		"\tSTRING being an arbitrary string\n"
-		"\tINDEX := optional index value used\n"
-		"\tCONTROL := reclassify|pipe|drop|continue|ok\n");
+	fprintf(stderr, "Usage: ... simple STRING\n"
+		"STRING being an arbitrary string\n"
+		"example: \"simple blah\"\n");
 }
 
 static void usage(void)
@@ -104,37 +103,21 @@
 	struct rtattr *tail;
 	char *simpdata = NULL;
 
+
 	while (argc > 0) {
 		if (matches(*argv, "simple") == 0) {
 			NEXT_ARG();
-		} else if (matches(*argv, "sdata") == 0) {
-			NEXT_ARG();
-			ok += 1;
 			simpdata = *argv;
+			ok = 1;
 			argc--;
 			argv++;
+			break;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
 			break;
 		}
-	}
 
-	parse_action_control_dflt(&argc, &argv, &sel.action, false,
-				  TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&sel.index, *argv, 10)) {
-				fprintf(stderr, "simple: Illegal \"index\" (%s)\n",
-					*argv);
-				return -1;
-			}
-			ok += 1;
-			argc--;
-			argv++;
-		}
 	}
 
 	if (!ok) {
@@ -142,24 +125,38 @@
 		return -1;
 	}
 
-	if (simpdata && (strlen(simpdata) > (SIMP_MAX_DATA - 1))) {
-		fprintf(stderr, "simple: Illegal string len %zu <%s>\n",
+	if (argc) {
+		if (matches(*argv, "index") == 0) {
+			NEXT_ARG();
+			if (get_u32(&sel.index, *argv, 10)) {
+				fprintf(stderr, "simple: Illegal \"index\"\n");
+				return -1;
+			}
+			argc--;
+			argv++;
+		}
+	}
+
+	if (strlen(simpdata) > (SIMP_MAX_DATA - 1)) {
+		fprintf(stderr, "simple: Illegal string len %zu <%s> \n",
 			strlen(simpdata), simpdata);
 		return -1;
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	sel.action = TC_ACT_PIPE;
+
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_DEF_PARMS, &sel, sizeof(sel));
-	if (simpdata)
-		addattr_l(n, MAX_MSG, TCA_DEF_DATA, simpdata, SIMP_MAX_DATA);
-	addattr_nest_end(n, tail);
+	addattr_l(n, MAX_MSG, TCA_DEF_DATA, simpdata, SIMP_MAX_DATA);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
 	return 0;
 }
 
-static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg)
+static int print_simple(struct action_util *au, FILE * f, struct rtattr *arg)
 {
 	struct tc_defact *sel;
 	struct rtattr *tb[TCA_DEF_MAX + 1];
@@ -171,26 +168,25 @@
 	parse_rtattr_nested(tb, TCA_DEF_MAX, arg);
 
 	if (tb[TCA_DEF_PARMS] == NULL) {
-		fprintf(stderr, "Missing simple parameters\n");
+		fprintf(f, "[NULL simple parameters]");
 		return -1;
 	}
 	sel = RTA_DATA(tb[TCA_DEF_PARMS]);
 
 	if (tb[TCA_DEF_DATA] == NULL) {
-		fprintf(stderr, "Missing simple string\n");
+		fprintf(f, "[missing simple string]");
 		return -1;
 	}
 
 	simpdata = RTA_DATA(tb[TCA_DEF_DATA]);
 
 	fprintf(f, "Simple <%s>\n", simpdata);
-	fprintf(f, "\t index %u ref %d bind %d", sel->index,
+	fprintf(f, "\t index %d ref %d bind %d", sel->index,
 		sel->refcnt, sel->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_DEF_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_DEF_TM]);
-
 			print_tm(f, tm);
 		}
 	}
diff --git a/tc/m_skbedit.c b/tc/m_skbedit.c
index 761cad5..36323a9 100644
--- a/tc/m_skbedit.c
+++ b/tc/m_skbedit.c
@@ -26,23 +26,17 @@
 #include "utils.h"
 #include "tc_util.h"
 #include <linux/tc_act/tc_skbedit.h>
-#include <linux/if_packet.h>
 
-static void explain(void)
+static void
+explain(void)
 {
-	fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM] [PT] [IF]>\n"
+	fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM]>\n"
 		"QM = queue_mapping QUEUE_MAPPING\n"
-		"PM = priority PRIORITY\n"
-		"MM = mark MARK[/MASK]\n"
-		"PT = ptype PACKETYPE\n"
-		"IF = inheritdsfield\n"
-		"PACKETYPE = is one of:\n"
-		"  host, otherhost, broadcast, multicast\n"
+		"PM = priority PRIORITY \n"
+		"MM = mark MARK \n"
 		"QUEUE_MAPPING = device transmit queue to use\n"
 		"PRIORITY = classID to assign to priority field\n"
-		"MARK = firewall mark to set\n"
-		"MASK = mask applied to firewall mark (0xffffffff by default)\n"
-		"note: inheritdsfield maps DS field to skb->priority\n");
+		"MARK = firewall mark to set\n");
 }
 
 static void
@@ -61,9 +55,8 @@
 	int ok = 0;
 	struct rtattr *tail;
 	unsigned int tmp;
-	__u16 queue_mapping, ptype;
-	__u32 flags = 0, priority, mark, mask;
-	__u64 pure_flags = 0;
+	__u16 queue_mapping;
+	__u32 flags = 0, priority, mark;
 	struct tc_skbedit sel = { 0 };
 
 	if (matches(*argv, "skbedit") != 0)
@@ -90,47 +83,12 @@
 			}
 			ok++;
 		} else if (matches(*argv, "mark") == 0) {
-			char *slash;
-
-			NEXT_ARG();
-			slash = strchr(*argv, '/');
-			if (slash)
-				*slash = '\0';
-
 			flags |= SKBEDIT_F_MARK;
+			NEXT_ARG();
 			if (get_u32(&mark, *argv, 0)) {
 				fprintf(stderr, "Illegal mark\n");
 				return -1;
 			}
-
-			if (slash) {
-				if (get_u32(&mask, slash + 1, 0)) {
-					fprintf(stderr, "Illegal mask\n");
-					return -1;
-				}
-				flags |= SKBEDIT_F_MASK;
-			}
-			ok++;
-		} else if (matches(*argv, "ptype") == 0) {
-
-			NEXT_ARG();
-			if (matches(*argv, "host") == 0) {
-				ptype = PACKET_HOST;
-			} else if (matches(*argv, "broadcast") == 0) {
-				ptype = PACKET_BROADCAST;
-			} else if (matches(*argv, "multicast") == 0) {
-				ptype = PACKET_MULTICAST;
-			} else if (matches(*argv, "otherhost") == 0) {
-				ptype = PACKET_OTHERHOST;
-			} else {
-				fprintf(stderr, "Illegal ptype (%s)\n",
-					*argv);
-				return -1;
-			}
-			flags |= SKBEDIT_F_PTYPE;
-			ok++;
-		} else if (matches(*argv, "inheritdsfield") == 0) {
-			pure_flags |= SKBEDIT_F_INHERITDSFIELD;
 			ok++;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
@@ -141,14 +99,32 @@
 		argv++;
 	}
 
-	parse_action_control_dflt(&argc, &argv, &sel.action,
-				  false, TC_ACT_PIPE);
+	sel.action = TC_ACT_PIPE;
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			sel.action = TC_ACT_RECLASSIFY;
+			NEXT_ARG();
+		} else if (matches(*argv, "pipe") == 0) {
+			sel.action = TC_ACT_PIPE;
+			NEXT_ARG();
+		} else if (matches(*argv, "drop") == 0 ||
+			matches(*argv, "shot") == 0) {
+			sel.action = TC_ACT_SHOT;
+			NEXT_ARG();
+		} else if (matches(*argv, "continue") == 0) {
+			sel.action = TC_ACT_UNSPEC;
+			NEXT_ARG();
+		} else if (matches(*argv, "pass") == 0) {
+			sel.action = TC_ACT_OK;
+			NEXT_ARG();
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
 			NEXT_ARG();
 			if (get_u32(&sel.index, *argv, 10)) {
-				fprintf(stderr, "skbedit: Illegal \"index\"\n");
+				fprintf(stderr, "Pedit: Illegal \"index\"\n");
 				return -1;
 			}
 			argc--;
@@ -163,7 +139,8 @@
 	}
 
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_SKBEDIT_PARMS, &sel, sizeof(sel));
 	if (flags & SKBEDIT_F_QUEUE_MAPPING)
 		addattr_l(n, MAX_MSG, TCA_SKBEDIT_QUEUE_MAPPING,
@@ -174,15 +151,7 @@
 	if (flags & SKBEDIT_F_MARK)
 		addattr_l(n, MAX_MSG, TCA_SKBEDIT_MARK,
 			  &mark, sizeof(mark));
-	if (flags & SKBEDIT_F_MASK)
-		addattr_l(n, MAX_MSG, TCA_SKBEDIT_MASK,
-			  &mask, sizeof(mask));
-	if (flags & SKBEDIT_F_PTYPE)
-		addattr_l(n, MAX_MSG, TCA_SKBEDIT_PTYPE,
-			  &ptype, sizeof(ptype));
-	if (pure_flags != 0)
-		addattr64(n, MAX_MSG, TCA_SKBEDIT_FLAGS, pure_flags);
-	addattr_nest_end(n, tail);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -192,11 +161,11 @@
 static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
 {
 	struct rtattr *tb[TCA_SKBEDIT_MAX + 1];
-
 	SPRINT_BUF(b1);
-	__u32 priority;
-	__u16 ptype;
-	struct tc_skbedit *p;
+	__u32 *priority;
+	__u32 *mark;
+	__u16 *queue_mapping;
+	struct tc_skbedit *p = NULL;
 
 	if (arg == NULL)
 		return -1;
@@ -204,70 +173,36 @@
 	parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg);
 
 	if (tb[TCA_SKBEDIT_PARMS] == NULL) {
-		fprintf(stderr, "Missing skbedit parameters\n");
+		fprintf(f, "[NULL skbedit parameters]");
 		return -1;
 	}
 	p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]);
 
-	print_string(PRINT_ANY, "kind", "%s ", "skbedit");
+	fprintf(f, " skbedit");
 
 	if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
-		print_uint(PRINT_ANY, "queue_mapping", "queue_mapping %u",
-			   rta_getattr_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]));
+		queue_mapping = RTA_DATA(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
+		fprintf(f, " queue_mapping %u", *queue_mapping);
 	}
 	if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
-		priority = rta_getattr_u32(tb[TCA_SKBEDIT_PRIORITY]);
-		print_string(PRINT_ANY, "priority", " priority %s",
-			     sprint_tc_classid(priority, b1));
+		priority = RTA_DATA(tb[TCA_SKBEDIT_PRIORITY]);
+		fprintf(f, " priority %s", sprint_tc_classid(*priority, b1));
 	}
 	if (tb[TCA_SKBEDIT_MARK] != NULL) {
-		print_uint(PRINT_ANY, "mark", " mark %u",
-			   rta_getattr_u32(tb[TCA_SKBEDIT_MARK]));
-	}
-	if (tb[TCA_SKBEDIT_MASK]) {
-		print_hex(PRINT_ANY, "mask", "/%#x",
-			  rta_getattr_u32(tb[TCA_SKBEDIT_MASK]));
-	}
-	if (tb[TCA_SKBEDIT_PTYPE] != NULL) {
-		ptype = rta_getattr_u16(tb[TCA_SKBEDIT_PTYPE]);
-		if (ptype == PACKET_HOST)
-			print_string(PRINT_ANY, "ptype", " ptype %s", "host");
-		else if (ptype == PACKET_BROADCAST)
-			print_string(PRINT_ANY, "ptype", " ptype %s",
-				     "broadcast");
-		else if (ptype == PACKET_MULTICAST)
-			print_string(PRINT_ANY, "ptype", " ptype %s",
-				     "multicast");
-		else if (ptype == PACKET_OTHERHOST)
-			print_string(PRINT_ANY, "ptype", " ptype %s",
-				     "otherhost");
-		else
-			print_uint(PRINT_ANY, "ptype", " ptype %u", ptype);
-	}
-	if (tb[TCA_SKBEDIT_FLAGS] != NULL) {
-		__u64 flags = rta_getattr_u64(tb[TCA_SKBEDIT_FLAGS]);
-
-		if (flags & SKBEDIT_F_INHERITDSFIELD)
-			print_null(PRINT_ANY, "inheritdsfield", " %s",
-				     "inheritdsfield");
+		mark = RTA_DATA(tb[TCA_SKBEDIT_MARK]);
+		fprintf(f, " mark %d", *mark);
 	}
 
-	print_action_control(f, " ", p->action, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", p->index);
-	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
+	fprintf(f, "\n\t index %d ref %d bind %d", p->index, p->refcnt, p->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_SKBEDIT_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_SKBEDIT_TM]);
-
 			print_tm(f, tm);
 		}
 	}
 
-	print_string(PRINT_FP, NULL, "%s", _SL_);
+	fprintf(f, "\n ");
 
 	return 0;
 }
diff --git a/tc/m_skbmod.c b/tc/m_skbmod.c
deleted file mode 100644
index d38a5c1..0000000
--- a/tc/m_skbmod.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * m_skbmod.c	skb modifier action module
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:  J Hadi Salim (jhs@mojatatu.com)
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <linux/netdevice.h>
-
-#include "rt_names.h"
-#include "utils.h"
-#include "tc_util.h"
-#include <linux/tc_act/tc_skbmod.h>
-
-static void skbmod_explain(void)
-{
-	fprintf(stderr,
-		"Usage:... skbmod {[set <SETTABLE>] [swap <SWAPABLE>]} [CONTROL] [index INDEX]\n"
-		"where SETTABLE is: [dmac DMAC] [smac SMAC] [etype ETYPE]\n"
-		"where SWAPABLE is: \"mac\" to swap mac addresses\n"
-		"note: \"swap mac\" is done after any outstanding D/SMAC change\n"
-		"\tDMAC := 6 byte Destination MAC address\n"
-		"\tSMAC := optional 6 byte Source MAC address\n"
-		"\tETYPE := optional 16 bit ethertype\n"
-		"\tCONTROL := reclassify | pipe | drop | continue | ok |\n"
-		"\t           goto chain <CHAIN_INDEX>\n"
-		"\tINDEX := skbmod index value to use\n");
-}
-
-static void skbmod_usage(void)
-{
-	skbmod_explain();
-	exit(-1);
-}
-
-static int parse_skbmod(struct action_util *a, int *argc_p, char ***argv_p,
-			int tca_id, struct nlmsghdr *n)
-{
-	int argc = *argc_p;
-	char **argv = *argv_p;
-	int ok = 0;
-	struct tc_skbmod p;
-	struct rtattr *tail;
-	char dbuf[ETH_ALEN];
-	char sbuf[ETH_ALEN];
-	__u16 skbmod_etype = 0;
-	char *daddr = NULL;
-	char *saddr = NULL;
-
-	memset(&p, 0, sizeof(p));
-
-	if (argc <= 0)
-		return -1;
-
-	while (argc > 0) {
-		if (matches(*argv, "skbmod") == 0) {
-			NEXT_ARG();
-			continue;
-		} else if (matches(*argv, "swap") == 0) {
-			NEXT_ARG();
-			continue;
-		} else if (matches(*argv, "mac") == 0) {
-			p.flags |= SKBMOD_F_SWAPMAC;
-			ok += 1;
-		} else if (matches(*argv, "set") == 0) {
-			NEXT_ARG();
-			continue;
-		} else if (matches(*argv, "etype") == 0) {
-			NEXT_ARG();
-			if (get_u16(&skbmod_etype, *argv, 0))
-				invarg("ethertype is invalid", *argv);
-			fprintf(stderr, "skbmod etype 0x%x\n", skbmod_etype);
-			p.flags |= SKBMOD_F_ETYPE;
-			ok += 1;
-		} else if (matches(*argv, "dmac") == 0) {
-			NEXT_ARG();
-			daddr = *argv;
-			if (sscanf(daddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-				   dbuf, dbuf + 1, dbuf + 2,
-				   dbuf + 3, dbuf + 4, dbuf + 5) != 6) {
-				fprintf(stderr, "Invalid dst mac address %s\n",
-					daddr);
-				return -1;
-			}
-			p.flags |= SKBMOD_F_DMAC;
-			fprintf(stderr, "dst MAC address <%s>\n", daddr);
-			ok += 1;
-
-		} else if (matches(*argv, "smac") == 0) {
-			NEXT_ARG();
-			saddr = *argv;
-			if (sscanf(saddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-				   sbuf, sbuf + 1, sbuf + 2,
-				   sbuf + 3, sbuf + 4, sbuf + 5) != 6) {
-				fprintf(stderr, "Invalid smac address %s\n",
-					saddr);
-				return -1;
-			}
-			p.flags |= SKBMOD_F_SMAC;
-			fprintf(stderr, "src MAC address <%s>\n", saddr);
-			ok += 1;
-		} else if (matches(*argv, "help") == 0) {
-			skbmod_usage();
-		} else {
-			break;
-		}
-
-		argc--;
-		argv++;
-	}
-
-	parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&p.index, *argv, 0)) {
-				fprintf(stderr, "skbmod: Illegal \"index\"\n");
-				return -1;
-			}
-			ok++;
-			argc--;
-			argv++;
-		}
-	}
-
-	if (!ok) {
-		fprintf(stderr, "skbmod requires at least one option\n");
-		skbmod_usage();
-	}
-
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-	addattr_l(n, MAX_MSG, TCA_SKBMOD_PARMS, &p, sizeof(p));
-
-	if (daddr)
-		addattr_l(n, MAX_MSG, TCA_SKBMOD_DMAC, dbuf, ETH_ALEN);
-	if (skbmod_etype)
-		addattr16(n, MAX_MSG, TCA_SKBMOD_ETYPE, skbmod_etype);
-	if (saddr)
-		addattr_l(n, MAX_MSG, TCA_SKBMOD_SMAC, sbuf, ETH_ALEN);
-
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-static int print_skbmod(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	struct tc_skbmod *p;
-	struct rtattr *tb[TCA_SKBMOD_MAX + 1];
-	__u16 skbmod_etype = 0;
-	int has_optional = 0;
-	SPRINT_BUF(b1);
-	SPRINT_BUF(b2);
-
-	if (arg == NULL)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_SKBMOD_MAX, arg);
-
-	if (tb[TCA_SKBMOD_PARMS] == NULL) {
-		fprintf(stderr, "Missing skbmod parameters\n");
-		return -1;
-	}
-
-	p = RTA_DATA(tb[TCA_SKBMOD_PARMS]);
-
-	fprintf(f, "skbmod ");
-	print_action_control(f, "", p->action, " ");
-
-	if (tb[TCA_SKBMOD_ETYPE]) {
-		skbmod_etype = rta_getattr_u16(tb[TCA_SKBMOD_ETYPE]);
-		has_optional = 1;
-		fprintf(f, "set etype 0x%X ", skbmod_etype);
-	}
-
-	if (has_optional)
-		fprintf(f, "\n\t ");
-
-	if (tb[TCA_SKBMOD_DMAC]) {
-		has_optional = 1;
-		fprintf(f, "set dmac %s ",
-			ll_addr_n2a(RTA_DATA(tb[TCA_SKBMOD_DMAC]),
-				    RTA_PAYLOAD(tb[TCA_SKBMOD_DMAC]), 0, b1,
-				    sizeof(b1)));
-
-	}
-
-	if (tb[TCA_SKBMOD_SMAC]) {
-		has_optional = 1;
-		fprintf(f, "set smac %s ",
-			ll_addr_n2a(RTA_DATA(tb[TCA_SKBMOD_SMAC]),
-				    RTA_PAYLOAD(tb[TCA_SKBMOD_SMAC]), 0, b2,
-				    sizeof(b2)));
-	}
-
-	if (p->flags & SKBMOD_F_SWAPMAC)
-		fprintf(f, "swap mac ");
-
-	fprintf(f, "\n\t index %u ref %d bind %d", p->index, p->refcnt,
-		p->bindcnt);
-	if (show_stats) {
-		if (tb[TCA_SKBMOD_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_SKBMOD_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-
-	fprintf(f, "\n");
-
-	return 0;
-}
-
-struct action_util skbmod_action_util = {
-	.id = "skbmod",
-	.parse_aopt = parse_skbmod,
-	.print_aopt = print_skbmod,
-};
diff --git a/tc/m_tunnel_key.c b/tc/m_tunnel_key.c
deleted file mode 100644
index 4e65e44..0000000
--- a/tc/m_tunnel_key.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * m_tunnel_key.c	ip tunnel manipulation module
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
- * Authors:     Amir Vadai <amir@vadai.me>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <linux/if_ether.h>
-#include "utils.h"
-#include "rt_names.h"
-#include "tc_util.h"
-#include <linux/tc_act/tc_tunnel_key.h>
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: tunnel_key unset\n"
-		"       tunnel_key set <TUNNEL_KEY>\n"
-		"Where TUNNEL_KEY is a combination of:\n"
-		"id <TUNNELID>\n"
-		"src_ip <IP> (mandatory)\n"
-		"dst_ip <IP> (mandatory)\n"
-		"dst_port <UDP_PORT>\n"
-		"geneve_opts <OPTIONS>\n"
-		"csum | nocsum (default is \"csum\")\n");
-}
-
-static void usage(void)
-{
-	explain();
-	exit(-1);
-}
-
-static int tunnel_key_parse_ip_addr(const char *str, int addr4_type,
-				    int addr6_type, struct nlmsghdr *n)
-{
-	inet_prefix addr;
-	int ret;
-
-	ret = get_addr(&addr, str, AF_UNSPEC);
-	if (ret)
-		return ret;
-
-	addattr_l(n, MAX_MSG, addr.family == AF_INET ? addr4_type : addr6_type,
-		  addr.data, addr.bytelen);
-
-	return 0;
-}
-
-static int tunnel_key_parse_key_id(const char *str, int type,
-				   struct nlmsghdr *n)
-{
-	__be32 key_id;
-	int ret;
-
-	ret = get_be32(&key_id, str, 10);
-	if (!ret)
-		addattr32(n, MAX_MSG, type, key_id);
-
-	return ret;
-}
-
-static int tunnel_key_parse_dst_port(char *str, int type, struct nlmsghdr *n)
-{
-	int ret;
-	__be16 dst_port;
-
-	ret = get_be16(&dst_port, str, 10);
-	if (ret)
-		return -1;
-
-	addattr16(n, MAX_MSG, type, dst_port);
-
-	return 0;
-}
-
-static int tunnel_key_parse_be16(char *str, int base, int type,
-				 struct nlmsghdr *n)
-{
-	int ret;
-	__be16 value;
-
-	ret = get_be16(&value, str, base);
-	if (ret)
-		return ret;
-
-	addattr16(n, MAX_MSG, type, value);
-
-	return 0;
-}
-
-static int tunnel_key_parse_u8(char *str, int base, int type,
-			       struct nlmsghdr *n)
-{
-	int ret;
-	__u8 value;
-
-	ret = get_u8(&value, str, base);
-	if (ret)
-		return ret;
-
-	addattr8(n, MAX_MSG, type, value);
-
-	return 0;
-}
-
-static int tunnel_key_parse_geneve_opt(char *str, struct nlmsghdr *n)
-{
-	char *token, *saveptr = NULL;
-	struct rtattr *nest;
-	int i, ret;
-
-	nest = addattr_nest(n, MAX_MSG, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE);
-
-	token = strtok_r(str, ":", &saveptr);
-	i = 1;
-	while (token) {
-		switch (i) {
-		case TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS:
-		{
-			ret = tunnel_key_parse_be16(token, 16, i, n);
-			if (ret)
-				return ret;
-			break;
-		}
-		case TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE:
-		{
-			ret = tunnel_key_parse_u8(token, 16, i, n);
-			if (ret)
-				return ret;
-			break;
-		}
-		case TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA:
-		{
-			size_t token_len = strlen(token);
-			uint8_t *opts;
-
-			opts = malloc(token_len / 2);
-			if (!opts)
-				return -1;
-			if (hex2mem(token, opts, token_len / 2) < 0) {
-				free(opts);
-				return -1;
-			}
-			addattr_l(n, MAX_MSG, i, opts, token_len / 2);
-			free(opts);
-
-			break;
-		}
-		default:
-			return -1;
-		}
-
-		token = strtok_r(NULL, ":", &saveptr);
-		i++;
-	}
-
-	addattr_nest_end(n, nest);
-
-	return 0;
-}
-
-static int tunnel_key_parse_geneve_opts(char *str, struct nlmsghdr *n)
-{
-	char *token, *saveptr = NULL;
-	struct rtattr *nest;
-	int ret;
-
-	nest = addattr_nest(n, MAX_MSG, TCA_TUNNEL_KEY_ENC_OPTS);
-
-	token = strtok_r(str, ",", &saveptr);
-	while (token) {
-		ret = tunnel_key_parse_geneve_opt(token, n);
-		if (ret)
-			return ret;
-
-		token = strtok_r(NULL, ",", &saveptr);
-	}
-
-	addattr_nest_end(n, nest);
-
-	return 0;
-}
-
-static int tunnel_key_parse_tos_ttl(char *str, int type, struct nlmsghdr *n)
-{
-	int ret;
-	__u8 val;
-
-	ret = get_u8(&val, str, 10);
-	if (ret)
-		ret = get_u8(&val, str, 16);
-	if (ret)
-		return -1;
-
-	addattr8(n, MAX_MSG, type, val);
-
-	return 0;
-}
-
-static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
-			    int tca_id, struct nlmsghdr *n)
-{
-	struct tc_tunnel_key parm = {};
-	char **argv = *argv_p;
-	int argc = *argc_p;
-	struct rtattr *tail;
-	int action = 0;
-	int ret;
-	int has_src_ip = 0;
-	int has_dst_ip = 0;
-	int csum = 1;
-
-	if (matches(*argv, "tunnel_key") != 0)
-		return -1;
-
-	tail = addattr_nest(n, MAX_MSG, tca_id);
-
-	NEXT_ARG();
-
-	while (argc > 0) {
-		if (matches(*argv, "unset") == 0) {
-			if (action) {
-				fprintf(stderr, "unexpected \"%s\" - action already specified\n",
-					*argv);
-				explain();
-				return -1;
-			}
-			action = TCA_TUNNEL_KEY_ACT_RELEASE;
-		} else if (matches(*argv, "set") == 0) {
-			if (action) {
-				fprintf(stderr, "unexpected \"%s\" - action already specified\n",
-					*argv);
-				explain();
-				return -1;
-			}
-			action = TCA_TUNNEL_KEY_ACT_SET;
-		} else if (matches(*argv, "src_ip") == 0) {
-			NEXT_ARG();
-			ret = tunnel_key_parse_ip_addr(*argv,
-						       TCA_TUNNEL_KEY_ENC_IPV4_SRC,
-						       TCA_TUNNEL_KEY_ENC_IPV6_SRC,
-						       n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"src_ip\"\n");
-				return -1;
-			}
-			has_src_ip = 1;
-		} else if (matches(*argv, "dst_ip") == 0) {
-			NEXT_ARG();
-			ret = tunnel_key_parse_ip_addr(*argv,
-						       TCA_TUNNEL_KEY_ENC_IPV4_DST,
-						       TCA_TUNNEL_KEY_ENC_IPV6_DST,
-						       n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"dst_ip\"\n");
-				return -1;
-			}
-			has_dst_ip = 1;
-		} else if (matches(*argv, "id") == 0) {
-			NEXT_ARG();
-			ret = tunnel_key_parse_key_id(*argv, TCA_TUNNEL_KEY_ENC_KEY_ID, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"id\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "dst_port") == 0) {
-			NEXT_ARG();
-			ret = tunnel_key_parse_dst_port(*argv,
-							TCA_TUNNEL_KEY_ENC_DST_PORT, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"dst port\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "geneve_opts") == 0) {
-			NEXT_ARG();
-
-			if (tunnel_key_parse_geneve_opts(*argv, n)) {
-				fprintf(stderr, "Illegal \"geneve_opts\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "tos") == 0) {
-			NEXT_ARG();
-			ret = tunnel_key_parse_tos_ttl(*argv,
-							TCA_TUNNEL_KEY_ENC_TOS, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"tos\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "ttl") == 0) {
-			NEXT_ARG();
-			ret = tunnel_key_parse_tos_ttl(*argv,
-							TCA_TUNNEL_KEY_ENC_TTL, n);
-			if (ret < 0) {
-				fprintf(stderr, "Illegal \"ttl\"\n");
-				return -1;
-			}
-		} else if (matches(*argv, "csum") == 0) {
-			csum = 1;
-		} else if (matches(*argv, "nocsum") == 0) {
-			csum = 0;
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-		} else {
-			break;
-		}
-		NEXT_ARG_FWD();
-	}
-
-	addattr8(n, MAX_MSG, TCA_TUNNEL_KEY_NO_CSUM, !csum);
-
-	parse_action_control_dflt(&argc, &argv, &parm.action,
-				  false, TC_ACT_PIPE);
-
-	if (argc) {
-		if (matches(*argv, "index") == 0) {
-			NEXT_ARG();
-			if (get_u32(&parm.index, *argv, 10)) {
-				fprintf(stderr, "tunnel_key: Illegal \"index\"\n");
-				return -1;
-			}
-
-			NEXT_ARG_FWD();
-		}
-	}
-
-	if (action == TCA_TUNNEL_KEY_ACT_SET &&
-	    (!has_src_ip || !has_dst_ip)) {
-		fprintf(stderr, "set needs tunnel_key parameters\n");
-		explain();
-		return -1;
-	}
-
-	parm.t_action = action;
-	addattr_l(n, MAX_MSG, TCA_TUNNEL_KEY_PARMS, &parm, sizeof(parm));
-	addattr_nest_end(n, tail);
-
-	*argc_p = argc;
-	*argv_p = argv;
-
-	return 0;
-}
-
-static void tunnel_key_print_ip_addr(FILE *f, const char *name,
-				     struct rtattr *attr)
-{
-	int family;
-	size_t len;
-
-	if (!attr)
-		return;
-
-	len = RTA_PAYLOAD(attr);
-
-	if (len == 4)
-		family = AF_INET;
-	else if (len == 16)
-		family = AF_INET6;
-	else
-		return;
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	if (matches(name, "src_ip") == 0)
-		print_string(PRINT_ANY, "src_ip", "\tsrc_ip %s",
-			     rt_addr_n2a_rta(family, attr));
-	else if (matches(name, "dst_ip") == 0)
-		print_string(PRINT_ANY, "dst_ip", "\tdst_ip %s",
-			     rt_addr_n2a_rta(family, attr));
-}
-
-static void tunnel_key_print_key_id(FILE *f, const char *name,
-				    struct rtattr *attr)
-{
-	if (!attr)
-		return;
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "key_id", "\tkey_id %u", rta_getattr_be32(attr));
-}
-
-static void tunnel_key_print_dst_port(FILE *f, char *name,
-				      struct rtattr *attr)
-{
-	if (!attr)
-		return;
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "dst_port", "\tdst_port %u",
-		   rta_getattr_be16(attr));
-}
-
-static void tunnel_key_print_flag(FILE *f, const char *name_on,
-				  const char *name_off,
-				  struct rtattr *attr)
-{
-	if (!attr)
-		return;
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_string(PRINT_ANY, "flag", "\t%s",
-		     rta_getattr_u8(attr) ? name_on : name_off);
-}
-
-static void tunnel_key_print_geneve_options(const char *name,
-					    struct rtattr *attr)
-{
-	struct rtattr *tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1];
-	struct rtattr *i = RTA_DATA(attr);
-	int ii, data_len = 0, offset = 0;
-	int rem = RTA_PAYLOAD(attr);
-	char strbuf[rem * 2 + 1];
-	char data[rem * 2 + 1];
-	uint8_t data_r[rem];
-	uint16_t clss;
-	uint8_t type;
-
-	open_json_array(PRINT_JSON, name);
-	print_string(PRINT_FP, name, "\n\t%s ", "geneve_opt");
-
-	while (rem) {
-		parse_rtattr(tb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX, i, rem);
-		clss = rta_getattr_be16(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS]);
-		type = rta_getattr_u8(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE]);
-		data_len = RTA_PAYLOAD(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]);
-		hexstring_n2a(RTA_DATA(tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA]),
-			      data_len, data, sizeof(data));
-		hex2mem(data, data_r, data_len);
-		offset += data_len + 20;
-		rem -= data_len + 20;
-		i = RTA_DATA(attr) + offset;
-
-		open_json_object(NULL);
-		print_uint(PRINT_JSON, "class", NULL, clss);
-		print_uint(PRINT_JSON, "type", NULL, type);
-		open_json_array(PRINT_JSON, "data");
-		for (ii = 0; ii < data_len; ii++)
-			print_uint(PRINT_JSON, NULL, NULL, data_r[ii]);
-		close_json_array(PRINT_JSON, "data");
-		close_json_object();
-
-		sprintf(strbuf, "%04x:%02x:%s", clss, type, data);
-		if (rem)
-			print_string(PRINT_FP, NULL, "%s,", strbuf);
-		else
-			print_string(PRINT_FP, NULL, "%s", strbuf);
-	}
-
-	close_json_array(PRINT_JSON, name);
-}
-
-static void tunnel_key_print_key_opt(const char *name, struct rtattr *attr)
-{
-	struct rtattr *tb[TCA_TUNNEL_KEY_ENC_OPTS_MAX + 1];
-
-	if (!attr)
-		return;
-
-	parse_rtattr_nested(tb, TCA_TUNNEL_KEY_ENC_OPTS_MAX, attr);
-	tunnel_key_print_geneve_options(name,
-					tb[TCA_TUNNEL_KEY_ENC_OPTS_GENEVE]);
-}
-
-static void tunnel_key_print_tos_ttl(FILE *f, char *name,
-				     struct rtattr *attr)
-{
-	if (!attr)
-		return;
-
-	if (matches(name, "tos") == 0 && rta_getattr_u8(attr) != 0) {
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-		print_uint(PRINT_ANY, "tos", "\ttos 0x%x",
-			   rta_getattr_u8(attr));
-	} else if (matches(name, "ttl") == 0 && rta_getattr_u8(attr) != 0) {
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-		print_uint(PRINT_ANY, "ttl", "\tttl %u",
-			   rta_getattr_u8(attr));
-	}
-}
-
-static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
-{
-	struct rtattr *tb[TCA_TUNNEL_KEY_MAX + 1];
-	struct tc_tunnel_key *parm;
-
-	if (!arg)
-		return -1;
-
-	parse_rtattr_nested(tb, TCA_TUNNEL_KEY_MAX, arg);
-
-	if (!tb[TCA_TUNNEL_KEY_PARMS]) {
-		fprintf(stderr, "Missing tunnel_key parameters\n");
-		return -1;
-	}
-	parm = RTA_DATA(tb[TCA_TUNNEL_KEY_PARMS]);
-
-	print_string(PRINT_ANY, "kind", "%s ", "tunnel_key");
-
-	switch (parm->t_action) {
-	case TCA_TUNNEL_KEY_ACT_RELEASE:
-		print_string(PRINT_ANY, "mode", " %s", "unset");
-		break;
-	case TCA_TUNNEL_KEY_ACT_SET:
-		print_string(PRINT_ANY, "mode", " %s", "set");
-		tunnel_key_print_ip_addr(f, "src_ip",
-					 tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC]);
-		tunnel_key_print_ip_addr(f, "dst_ip",
-					 tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]);
-		tunnel_key_print_ip_addr(f, "src_ip",
-					 tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC]);
-		tunnel_key_print_ip_addr(f, "dst_ip",
-					 tb[TCA_TUNNEL_KEY_ENC_IPV6_DST]);
-		tunnel_key_print_key_id(f, "key_id",
-					tb[TCA_TUNNEL_KEY_ENC_KEY_ID]);
-		tunnel_key_print_dst_port(f, "dst_port",
-					  tb[TCA_TUNNEL_KEY_ENC_DST_PORT]);
-		tunnel_key_print_key_opt("geneve_opts",
-					 tb[TCA_TUNNEL_KEY_ENC_OPTS]);
-		tunnel_key_print_flag(f, "nocsum", "csum",
-				      tb[TCA_TUNNEL_KEY_NO_CSUM]);
-		tunnel_key_print_tos_ttl(f, "tos",
-					  tb[TCA_TUNNEL_KEY_ENC_TOS]);
-		tunnel_key_print_tos_ttl(f, "ttl",
-					  tb[TCA_TUNNEL_KEY_ENC_TTL]);
-		break;
-	}
-	print_action_control(f, " ", parm->action, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_uint(PRINT_ANY, "index", "\t index %u", parm->index);
-	print_int(PRINT_ANY, "ref", " ref %d", parm->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);
-
-	if (show_stats) {
-		if (tb[TCA_TUNNEL_KEY_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_TUNNEL_KEY_TM]);
-
-			print_tm(f, tm);
-		}
-	}
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	return 0;
-}
-
-struct action_util tunnel_key_action_util = {
-	.id = "tunnel_key",
-	.parse_aopt = parse_tunnel_key,
-	.print_aopt = print_tunnel_key,
-};
diff --git a/tc/m_vlan.c b/tc/m_vlan.c
index 9c8071e..32db5ed 100644
--- a/tc/m_vlan.c
+++ b/tc/m_vlan.c
@@ -19,22 +19,12 @@
 #include "tc_util.h"
 #include <linux/tc_act/tc_vlan.h>
 
-static const char * const action_names[] = {
-	[TCA_VLAN_ACT_POP] = "pop",
-	[TCA_VLAN_ACT_PUSH] = "push",
-	[TCA_VLAN_ACT_MODIFY] = "modify",
-};
-
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: vlan pop\n"
-		"       vlan push [ protocol VLANPROTO ] id VLANID [ priority VLANPRIO ] [CONTROL]\n"
-		"       vlan modify [ protocol VLANPROTO ] id VLANID [ priority VLANPRIO ] [CONTROL]\n"
-		"       VLANPROTO is one of 802.1Q or 802.1AD\n"
-		"            with default: 802.1Q\n"
-		"       CONTROL := reclassify | pipe | drop | continue | pass |\n"
-		"                  goto chain <CHAIN_INDEX>\n");
+	fprintf(stderr, "Usage: vlan pop\n");
+	fprintf(stderr, "       vlan push [ protocol VLANPROTO ] id VLANID\n");
+	fprintf(stderr, "       VLANPROTO is one of 802.1Q or 802.1AD\n");
+	fprintf(stderr, "            with default: 802.1Q\n");
 }
 
 static void usage(void)
@@ -43,19 +33,6 @@
 	exit(-1);
 }
 
-static bool has_push_attribs(int action)
-{
-	return action == TCA_VLAN_ACT_PUSH || action == TCA_VLAN_ACT_MODIFY;
-}
-
-static void unexpected(const char *arg)
-{
-	fprintf(stderr,
-		"unexpected \"%s\" - action already specified\n",
-		arg);
-	explain();
-}
-
 static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p,
 		      int tca_id, struct nlmsghdr *n)
 {
@@ -67,9 +44,7 @@
 	int id_set = 0;
 	__u16 proto;
 	int proto_set = 0;
-	__u8 prio;
-	int prio_set = 0;
-	struct tc_vlan parm = {};
+	struct tc_vlan parm = { 0 };
 
 	if (matches(*argv, "vlan") != 0)
 		return -1;
@@ -79,46 +54,42 @@
 	while (argc > 0) {
 		if (matches(*argv, "pop") == 0) {
 			if (action) {
-				unexpected(*argv);
+				fprintf(stderr, "unexpected \"%s\" - action already specified\n",
+					*argv);
+				explain();
 				return -1;
 			}
 			action = TCA_VLAN_ACT_POP;
 		} else if (matches(*argv, "push") == 0) {
 			if (action) {
-				unexpected(*argv);
+				fprintf(stderr, "unexpected \"%s\" - action already specified\n",
+					*argv);
+				explain();
 				return -1;
 			}
 			action = TCA_VLAN_ACT_PUSH;
-		} else if (matches(*argv, "modify") == 0) {
-			if (action) {
-				unexpected(*argv);
+		} else if (matches(*argv, "id") == 0) {
+			if (action != TCA_VLAN_ACT_PUSH) {
+				fprintf(stderr, "\"%s\" is only valid for push\n",
+					*argv);
+				explain();
 				return -1;
 			}
-			action = TCA_VLAN_ACT_MODIFY;
-		} else if (matches(*argv, "id") == 0) {
-			if (!has_push_attribs(action))
-				invarg("only valid for push/modify", *argv);
-
 			NEXT_ARG();
 			if (get_u16(&id, *argv, 0))
 				invarg("id is invalid", *argv);
 			id_set = 1;
 		} else if (matches(*argv, "protocol") == 0) {
-			if (!has_push_attribs(action))
-				invarg("only valid for push/modify", *argv);
-
+			if (action != TCA_VLAN_ACT_PUSH) {
+				fprintf(stderr, "\"%s\" is only valid for push\n",
+					*argv);
+				explain();
+				return -1;
+			}
 			NEXT_ARG();
 			if (ll_proto_a2n(&proto, *argv))
 				invarg("protocol is invalid", *argv);
 			proto_set = 1;
-		} else if (matches(*argv, "priority") == 0) {
-			if (!has_push_attribs(action))
-				invarg("only valid for push/modify", *argv);
-
-			NEXT_ARG();
-			if (get_u8(&prio, *argv, 0) || (prio & ~0x7))
-				invarg("prio is invalid", *argv);
-			prio_set = 1;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
@@ -128,8 +99,31 @@
 		argv++;
 	}
 
-	parse_action_control_dflt(&argc, &argv, &parm.action,
-				  false, TC_ACT_PIPE);
+	parm.action = TC_ACT_PIPE;
+	if (argc) {
+		if (matches(*argv, "reclassify") == 0) {
+			parm.action = TC_ACT_RECLASSIFY;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pipe") == 0) {
+			parm.action = TC_ACT_PIPE;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "drop") == 0 ||
+			   matches(*argv, "shot") == 0) {
+			parm.action = TC_ACT_SHOT;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "continue") == 0) {
+			parm.action = TC_ACT_UNSPEC;
+			argc--;
+			argv++;
+		} else if (matches(*argv, "pass") == 0) {
+			parm.action = TC_ACT_OK;
+			argc--;
+			argv++;
+		}
+	}
 
 	if (argc) {
 		if (matches(*argv, "index") == 0) {
@@ -143,15 +137,15 @@
 		}
 	}
 
-	if (has_push_attribs(action) && !id_set) {
-		fprintf(stderr, "id needs to be set for %s\n",
-			action_names[action]);
+	if (action == TCA_VLAN_ACT_PUSH && !id_set) {
+		fprintf(stderr, "id needs to be set for push\n");
 		explain();
 		return -1;
 	}
 
 	parm.v_action = action;
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	addattr_l(n, MAX_MSG, TCA_VLAN_PARMS, &parm, sizeof(parm));
 	if (id_set)
 		addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_ID, &id, 2);
@@ -165,10 +159,7 @@
 
 		addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2);
 	}
-	if (prio_set)
-		addattr8(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PRIORITY, prio);
-
-	addattr_nest_end(n, tail);
+	tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
 
 	*argc_p = argc;
 	*argv_p = argv;
@@ -188,50 +179,43 @@
 	parse_rtattr_nested(tb, TCA_VLAN_MAX, arg);
 
 	if (!tb[TCA_VLAN_PARMS]) {
-		fprintf(stderr, "Missing vlanparameters\n");
+		fprintf(f, "[NULL vlan parameters]");
 		return -1;
 	}
 	parm = RTA_DATA(tb[TCA_VLAN_PARMS]);
 
-	print_string(PRINT_ANY, "kind", "%s ", "vlan");
-	print_string(PRINT_ANY, "vlan_action", " %s",
-		     action_names[parm->v_action]);
+	fprintf(f, " vlan");
 
-	switch (parm->v_action) {
+	switch(parm->v_action) {
+	case TCA_VLAN_ACT_POP:
+		fprintf(f, " pop");
+		break;
 	case TCA_VLAN_ACT_PUSH:
-	case TCA_VLAN_ACT_MODIFY:
+		fprintf(f, " push");
 		if (tb[TCA_VLAN_PUSH_VLAN_ID]) {
 			val = rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_ID]);
-			print_uint(PRINT_ANY, "id", " id %u", val);
+			fprintf(f, " id %u", val);
 		}
 		if (tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]) {
-			__u16 proto;
-
-			proto = rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]);
-			print_string(PRINT_ANY, "protocol", " protocol %s",
-				     ll_proto_n2a(proto, b1, sizeof(b1)));
-		}
-		if (tb[TCA_VLAN_PUSH_VLAN_PRIORITY]) {
-			val = rta_getattr_u8(tb[TCA_VLAN_PUSH_VLAN_PRIORITY]);
-			print_uint(PRINT_ANY, "priority", " priority %u", val);
+			fprintf(f, " protocol %s",
+				ll_proto_n2a(rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]),
+					     b1, sizeof(b1)));
 		}
 		break;
 	}
-	print_action_control(f, " ", parm->action, "");
+	fprintf(f, " %s", action_n2a(parm->action, b1, sizeof (b1)));
 
-	print_uint(PRINT_ANY, "index", "\n\t index %u", parm->index);
-	print_int(PRINT_ANY, "ref", " ref %d", parm->refcnt);
-	print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);
+	fprintf(f, "\n\t index %d ref %d bind %d", parm->index, parm->refcnt,
+		parm->bindcnt);
 
 	if (show_stats) {
 		if (tb[TCA_VLAN_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_VLAN_TM]);
-
 			print_tm(f, tm);
 		}
 	}
 
-	print_string(PRINT_FP, NULL, "%s", "\n");
+	fprintf(f, "\n ");
 
 	return 0;
 }
diff --git a/tc/m_xt.c b/tc/m_xt.c
index bf0db2b..bf603fc 100644
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -10,6 +10,7 @@
  * Authors:  J Hadi Salim (hadi@cyberus.ca)
  */
 
+#include <syslog.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -38,21 +39,19 @@
 #endif
 
 #ifndef __ALIGN_KERNEL
-#define __ALIGN_KERNEL(x, a)	\
-	__ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
-#define __ALIGN_KERNEL_MASK(x, mask) \
-	(((x) + (mask)) & ~(mask))
+#define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
 #endif
 
 #ifndef ALIGN
-#define ALIGN(x, a)	__ALIGN_KERNEL((x), (a))
+#define ALIGN(x,a)	__ALIGN_KERNEL((x), (a))
 #endif
 
 static const char *tname = "mangle";
 
 char *lib_dir;
 
-static const char * const ipthooks[] = {
+static const char *ipthooks[] = {
 	"NF_IP_PRE_ROUTING",
 	"NF_IP_LOCAL_IN",
 	"NF_IP_FORWARD",
@@ -76,9 +75,6 @@
 	.orig_opts = original_opts,
 	.opts = original_opts,
 	.exit_err = NULL,
-#if XTABLES_VERSION_CODE >= 11
-	.compat_rev = xtables_compatible_revision,
-#endif
 };
 
 /*
@@ -89,13 +85,12 @@
 {
 
 	size_t size =
-		    XT_ALIGN(sizeof(struct xt_entry_target)) + target->size;
+		    XT_ALIGN(sizeof (struct xt_entry_target)) + target->size;
 
-	if (t == NULL) {
+	if (NULL == t) {
 		target->t = xtables_calloc(1, size);
 		target->t->u.target_size = size;
-		strncpy(target->t->u.user.name, target->name,
-			sizeof(target->t->u.user.name) - 1);
+		strcpy(target->t->u.user.name, target->name);
 		target->t->u.user.revision = target->revision;
 
 		if (target->init != NULL)
@@ -114,110 +109,95 @@
 	if (!lib_dir) {
 		lib_dir = getenv("IPTABLES_LIB_DIR");
 		if (lib_dir)
-			fprintf(stderr, "using deprecated IPTABLES_LIB_DIR\n");
+			fprintf(stderr, "using deprecated IPTABLES_LIB_DIR \n");
 	}
 	if (lib_dir == NULL)
 		lib_dir = XT_LIB_DIR;
 
 }
 
-static int get_xtables_target_opts(struct xtables_globals *globals,
-				   struct xtables_target *m)
-{
-	struct option *opts;
-
-#if XTABLES_VERSION_CODE >= 6
-	opts = xtables_options_xfrm(globals->orig_opts,
-				    globals->opts,
-				    m->x6_options,
-				    &m->option_offset);
-#else
-	opts = xtables_merge_options(globals->opts,
-				     m->extra_opts,
-				     &m->option_offset);
-#endif
-	if (!opts)
-		return -1;
-	globals->opts = opts;
-	return 0;
-}
-
-static int parse_ipt(struct action_util *a, int *argc_p,
+static int parse_ipt(struct action_util *a,int *argc_p,
 		     char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
 	struct xtables_target *m = NULL;
-#if XTABLES_VERSION_CODE >= 6
-	struct ipt_entry fw = {};
-#endif
+	struct ipt_entry fw;
 	struct rtattr *tail;
 
 	int c;
+	int rargc = *argc_p;
 	char **argv = *argv_p;
-	int argc;
-	char k[FILTER_NAMESZ];
+	int argc = 0, iargc = 0;
+	char k[16];
 	int size = 0;
 	int iok = 0, ok = 0;
 	__u32 hook = 0, index = 0;
+	struct option *opts = NULL;
 
-	/* copy tcipt_globals because .opts will be modified by iptables */
-	struct xtables_globals tmp_tcipt_globals = tcipt_globals;
-
-	xtables_init_all(&tmp_tcipt_globals, NFPROTO_IPV4);
+	xtables_init_all(&tcipt_globals, NFPROTO_IPV4);
 	set_lib_dir();
 
-	/* parse only up until the next action */
-	for (argc = 0; argc < *argc_p; argc++) {
-		if (!argv[argc] || !strcmp(argv[argc], "action"))
-			break;
+	{
+		int i;
+		for (i = 0; i < rargc; i++) {
+			if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
+				break;
+			}
+		}
+		iargc = argc = i;
 	}
 
 	if (argc <= 2) {
-		fprintf(stderr,
-			"too few arguments for xt, need at least '-j <target>'\n");
+		fprintf(stderr,"bad arguments to ipt %d vs %d \n", argc, rargc);
 		return -1;
 	}
 
 	while (1) {
-		c = getopt_long(argc, argv, "j:", tmp_tcipt_globals.opts, NULL);
+		c = getopt_long(argc, argv, "j:", tcipt_globals.opts, NULL);
 		if (c == -1)
 			break;
 		switch (c) {
 		case 'j':
 			m = xtables_find_target(optarg, XTF_TRY_LOAD);
-			if (!m) {
-				fprintf(stderr,
-					" failed to find target %s\n\n",
-					optarg);
-				return -1;
-			}
+			if (NULL != m) {
 
-			if (build_st(m, NULL) < 0) {
-				printf(" %s error\n", m->name);
+				if (0 > build_st(m, NULL)) {
+					printf(" %s error \n", m->name);
+					return -1;
+				}
+#if (XTABLES_VERSION_CODE >= 6)
+			opts = xtables_options_xfrm(tcipt_globals.orig_opts,
+						    tcipt_globals.opts,
+						    m->x6_options,
+						    &m->option_offset);
+#else
+			opts = xtables_merge_options(tcipt_globals.opts,
+						     m->extra_opts,
+						     &m->option_offset);
+#endif
+			if (opts == NULL) {
+				fprintf(stderr, " failed to find additional options for target %s\n\n", optarg);
 				return -1;
-			}
-
-			if (get_xtables_target_opts(&tmp_tcipt_globals,
-						    m) < 0) {
-				fprintf(stderr,
-					" failed to find additional options for target %s\n\n",
-					optarg);
+			} else
+				tcipt_globals.opts = opts;
+			} else {
+				fprintf(stderr," failed to find target %s\n\n", optarg);
 				return -1;
 			}
 			ok++;
 			break;
 
 		default:
-#if XTABLES_VERSION_CODE >= 6
-			if (m != NULL && m->x6_parse != NULL) {
-				xtables_option_tpcall(c, argv, 0, m, &fw);
+			memset(&fw, 0, sizeof (fw));
+#if (XTABLES_VERSION_CODE >= 6)
+		if (m != NULL && m->x6_parse != NULL ) {
+			xtables_option_tpcall(c, argv, 0 , m, NULL);
 #else
-			if (m != NULL && m->parse != NULL) {
-				m->parse(c - m->option_offset, argv, 0,
-					 &m->tflags, NULL, &m->t);
+		if (m != NULL && m->parse != NULL ) {
+			m->parse(c - m->option_offset, argv, 0, &m->tflags,
+				 NULL, &m->t);
 #endif
 			} else {
-				fprintf(stderr,
-					"failed to find target %s\n\n", optarg);
+				fprintf(stderr,"failed to find target %s\n\n", optarg);
 				return -1;
 
 			}
@@ -226,7 +206,7 @@
 		}
 	}
 
-	if (argc > optind) {
+	if (iargc > optind) {
 		if (matches(argv[optind], "index") == 0) {
 			if (get_u32(&index, argv[optind + 1], 10)) {
 				fprintf(stderr, "Illegal \"index\"\n");
@@ -240,12 +220,12 @@
 	}
 
 	if (!ok && !iok) {
-		fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
+		fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
 		return -1;
 	}
 
 	/* check that we passed the correct parameters to the target */
-#if XTABLES_VERSION_CODE >= 6
+#if (XTABLES_VERSION_CODE >= 6)
 	if (m)
 		xtables_option_tfcall(m);
 #else
@@ -255,7 +235,6 @@
 
 	{
 		struct tcmsg *t = NLMSG_DATA(n);
-
 		if (t->tcm_parent != TC_H_ROOT
 		    && t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
 			hook = NF_IP_PRE_ROUTING;
@@ -264,20 +243,17 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]);
 	fprintf(stdout, "\ttarget: ");
 
-	if (m) {
-		if (m->print)
-			m->print(NULL, m->t, 0);
-		else
-			printf("%s ", m->name);
-	}
+	if (m)
+		m->print(NULL, m->t, 0);
 	fprintf(stdout, " index %d\n", index);
 
-	if (strlen(tname) >= 16) {
-		size = 15;
+	if (strlen(tname) > 16) {
+		size = 16;
 		k[15] = 0;
 	} else {
 		size = 1 + strlen(tname);
@@ -289,10 +265,11 @@
 	addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4);
 	if (m)
 		addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size);
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
+	argc -= optind;
 	argv += optind;
-	*argc_p -= argc;
+	*argc_p = rargc - iargc;
 	*argv_p = argv;
 
 	optind = 0;
@@ -312,12 +289,11 @@
 }
 
 static int
-print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
+print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
 {
-	struct xtables_target *m;
 	struct rtattr *tb[TCA_IPT_MAX + 1];
 	struct xt_entry_target *t = NULL;
-	__u32 hook;
+	struct option *opts = NULL;
 
 	if (arg == NULL)
 		return -1;
@@ -331,75 +307,84 @@
 	parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
 
 	if (tb[TCA_IPT_TABLE] == NULL) {
-		fprintf(stderr, "Missing ipt table name, assuming mangle\n");
+		fprintf(f, "[NULL ipt table name ] assuming mangle ");
 	} else {
 		fprintf(f, "tablename: %s ",
 			rta_getattr_str(tb[TCA_IPT_TABLE]));
 	}
 
 	if (tb[TCA_IPT_HOOK] == NULL) {
-		fprintf(stderr, "Missing ipt hook name\n ");
+		fprintf(f, "[NULL ipt hook name ]\n ");
 		return -1;
+	} else {
+		__u32 hook;
+		hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+		fprintf(f, " hook: %s \n", ipthooks[hook]);
 	}
 
 	if (tb[TCA_IPT_TARG] == NULL) {
-		fprintf(stderr, "Missing ipt target parameters\n");
+		fprintf(f, "\t[NULL ipt target parameters ] \n");
 		return -1;
-	}
-
-	hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
-	fprintf(f, " hook: %s\n", ipthooks[hook]);
-
-	t = RTA_DATA(tb[TCA_IPT_TARG]);
-	m = xtables_find_target(t->u.user.name, XTF_TRY_LOAD);
-	if (!m) {
-		fprintf(stderr, " failed to find target %s\n\n",
-			t->u.user.name);
-		return -1;
-	}
-	if (build_st(m, t) < 0) {
-		fprintf(stderr, " %s error\n", m->name);
-		return -1;
-	}
-
-	if (get_xtables_target_opts(&tmp_tcipt_globals, m) < 0) {
-		fprintf(stderr,
-			" failed to find additional options for target %s\n\n",
-			t->u.user.name);
-		return -1;
-	}
-	fprintf(f, "\ttarget ");
-	m->print(NULL, m->t, 0);
-	if (tb[TCA_IPT_INDEX] == NULL) {
-		fprintf(f, " [NULL ipt target index ]\n");
 	} else {
-		__u32 index;
+		struct xtables_target *m = NULL;
+		t = RTA_DATA(tb[TCA_IPT_TARG]);
+		m = xtables_find_target(t->u.user.name, XTF_TRY_LOAD);
+		if (NULL != m) {
+			if (0 > build_st(m, t)) {
+				fprintf(stderr, " %s error \n", m->name);
+				return -1;
+			}
 
-		index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
-		fprintf(f, "\n\tindex %u", index);
-	}
-
-	if (tb[TCA_IPT_CNT]) {
-		struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);
-
-		fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
-	}
-	if (show_stats) {
-		if (tb[TCA_IPT_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
-
-			print_tm(f, tm);
+#if (XTABLES_VERSION_CODE >= 6)
+		opts = xtables_options_xfrm(tmp_tcipt_globals.orig_opts,
+					    tmp_tcipt_globals.opts,
+					    m->x6_options,
+					    &m->option_offset);
+#else
+		opts = xtables_merge_options(tmp_tcipt_globals.opts,
+					     m->extra_opts,
+					     &m->option_offset);
+#endif
+	if (opts == NULL) {
+		fprintf(stderr, " failed to find additional options for target %s\n\n", optarg);
+		return -1;
+	} else
+		tmp_tcipt_globals.opts = opts;
+		} else {
+			fprintf(stderr, " failed to find target %s\n\n",
+				t->u.user.name);
+			return -1;
 		}
-	}
-	fprintf(f, "\n");
+		fprintf(f, "\ttarget ");
+		m->print(NULL, m->t, 0);
+		if (tb[TCA_IPT_INDEX] == NULL) {
+			fprintf(f, " [NULL ipt target index ]\n");
+		} else {
+			__u32 index;
+			index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
+			fprintf(f, " \n\tindex %d", index);
+		}
 
+		if (tb[TCA_IPT_CNT]) {
+			struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);;
+			fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
+		}
+		if (show_stats) {
+			if (tb[TCA_IPT_TM]) {
+				struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+				print_tm(f,tm);
+			}
+		}
+		fprintf(f, " \n");
+
+	}
 	xtables_free_opts(1);
 
 	return 0;
 }
 
 struct action_util xt_action_util = {
-	.id = "xt",
-	.parse_aopt = parse_ipt,
-	.print_aopt = print_ipt,
+        .id = "xt",
+        .parse_aopt = parse_ipt,
+        .print_aopt = print_ipt,
 };
diff --git a/tc/m_xt_old.c b/tc/m_xt_old.c
index 6a4509a..6e64308 100644
--- a/tc/m_xt_old.c
+++ b/tc/m_xt_old.c
@@ -13,6 +13,7 @@
 /*XXX: in the future (xtables 1.4.3?) get rid of everything tagged
  * as TC_CONFIG_XT_H */
 
+#include <syslog.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -40,8 +41,8 @@
 #endif
 
 #ifndef ALIGN
-#define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a)-1)
-#define __ALIGN_MASK(x, mask)	(((x)+(mask))&~(mask))
+#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
+#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
 #endif
 
 static const char *pname = "tc-ipt";
@@ -62,7 +63,7 @@
 };
 
 static struct option *opts = original_opts;
-static unsigned int global_option_offset;
+static unsigned int global_option_offset = 0;
 char *lib_dir;
 const char *program_version = XTABLES_VERSION;
 const char *program_name = "tc-ipt";
@@ -95,18 +96,18 @@
 	struct option *merge;
 	unsigned int num_old, num_new, i;
 
-	for (num_old = 0; oldopts[num_old].name; num_old++);
-	for (num_new = 0; newopts[num_new].name; num_new++);
+	for (num_old = 0; oldopts[num_old].name; num_old++) ;
+	for (num_new = 0; newopts[num_new].name; num_new++) ;
 
 	*option_offset = global_option_offset + OPTION_OFFSET;
 
-	merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
-	memcpy(merge, oldopts, num_old * sizeof(struct option));
+	merge = malloc(sizeof (struct option) * (num_new + num_old + 1));
+	memcpy(merge, oldopts, num_old * sizeof (struct option));
 	for (i = 0; i < num_new; i++) {
 		merge[num_old + i] = newopts[i];
 		merge[num_old + i].val += *option_offset;
 	}
-	memset(merge + num_old + num_new, 0, sizeof(struct option));
+	memset(merge + num_old + num_new, 0, sizeof (struct option));
 
 	return merge;
 }
@@ -124,35 +125,35 @@
 int
 check_inverse(const char option[], int *invert, int *my_optind, int argc)
 {
-	if (option && strcmp(option, "!") == 0) {
-		if (*invert)
-			exit_error(PARAMETER_PROBLEM,
-				   "Multiple `!' flags not allowed");
-		*invert = TRUE;
-		if (my_optind != NULL) {
-			++*my_optind;
-			if (argc && *my_optind > argc)
-				exit_error(PARAMETER_PROBLEM,
-					   "no argument following `!'");
-		}
+        if (option && strcmp(option, "!") == 0) {
+                if (*invert)
+                        exit_error(PARAMETER_PROBLEM,
+                                   "Multiple `!' flags not allowed");
+                *invert = TRUE;
+                if (my_optind != NULL) {
+                        ++*my_optind;
+                        if (argc && *my_optind > argc)
+                                exit_error(PARAMETER_PROBLEM,
+                                           "no argument following `!'");
+                }
 
-		return TRUE;
-	}
-	return FALSE;
+                return TRUE;
+        }
+        return FALSE;
 }
 
 /*XXX: TC_CONFIG_XT_H */
 void exit_error(enum exittype status, const char *msg, ...)
 {
-	va_list args;
+        va_list args;
 
-	va_start(args, msg);
-	fprintf(stderr, "%s v%s: ", pname, pversion);
-	vfprintf(stderr, msg, args);
-	va_end(args);
-	fprintf(stderr, "\n");
-	/* On error paths, make sure that we don't leak memory */
-	exit(status);
+        va_start(args, msg);
+        fprintf(stderr, "%s v%s: ", pname, pversion);
+        vfprintf(stderr, msg, args);
+        va_end(args);
+        fprintf(stderr, "\n");
+        /* On error paths, make sure that we don't leak memory */
+        exit(status);
 }
 
 /*XXX: TC_CONFIG_XT_H */
@@ -172,9 +173,9 @@
 {
 
 	size_t size =
-		    XT_ALIGN(sizeof(struct xt_entry_target)) + target->size;
+		    XT_ALIGN(sizeof (struct xt_entry_target)) + target->size;
 
-	if (t == NULL) {
+	if (NULL == t) {
 		target->t = fw_calloc(1, size);
 		target->t->u.target_size = size;
 		strcpy(target->t->u.user.name, target->name);
@@ -196,14 +197,14 @@
 	if (!lib_dir) {
 		lib_dir = getenv("IPTABLES_LIB_DIR");
 		if (lib_dir)
-			fprintf(stderr, "using deprecated IPTABLES_LIB_DIR\n");
+			fprintf(stderr, "using deprecated IPTABLES_LIB_DIR \n");
 	}
 	if (lib_dir == NULL)
 		lib_dir = XT_LIB_DIR;
 
 }
 
-static int parse_ipt(struct action_util *a, int *argc_p,
+static int parse_ipt(struct action_util *a,int *argc_p,
 		     char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
 	struct xtables_target *m = NULL;
@@ -213,7 +214,7 @@
 	int rargc = *argc_p;
 	char **argv = *argv_p;
 	int argc = 0, iargc = 0;
-	char k[FILTER_NAMESZ];
+	char k[16];
 	int size = 0;
 	int iok = 0, ok = 0;
 	__u32 hook = 0, index = 0;
@@ -222,16 +223,16 @@
 
 	{
 		int i;
-
 		for (i = 0; i < rargc; i++) {
-			if (!argv[i] || strcmp(argv[i], "action") == 0)
+			if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
 				break;
+			}
 		}
 		iargc = argc = i;
 	}
 
 	if (argc <= 2) {
-		fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
+		fprintf(stderr,"bad arguments to ipt %d vs %d \n", argc, rargc);
 		return -1;
 	}
 
@@ -242,29 +243,29 @@
 		switch (c) {
 		case 'j':
 			m = find_target(optarg, TRY_LOAD);
-			if (m != NULL) {
+			if (NULL != m) {
 
-				if (build_st(m, NULL) < 0) {
-					printf(" %s error\n", m->name);
+				if (0 > build_st(m, NULL)) {
+					printf(" %s error \n", m->name);
 					return -1;
 				}
 				opts =
 				    merge_options(opts, m->extra_opts,
 						  &m->option_offset);
 			} else {
-				fprintf(stderr, " failed to find target %s\n\n", optarg);
+				fprintf(stderr," failed to find target %s\n\n", optarg);
 				return -1;
 			}
 			ok++;
 			break;
 
 		default:
-			memset(&fw, 0, sizeof(fw));
+			memset(&fw, 0, sizeof (fw));
 			if (m) {
 				m->parse(c - m->option_offset, argv, 0,
 					 &m->tflags, NULL, &m->t);
 			} else {
-				fprintf(stderr, " failed to find target %s\n\n", optarg);
+				fprintf(stderr," failed to find target %s\n\n", optarg);
 				return -1;
 
 			}
@@ -288,7 +289,7 @@
 	}
 
 	if (!ok && !iok) {
-		fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
+		fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
 		return -1;
 	}
 
@@ -298,7 +299,6 @@
 
 	{
 		struct tcmsg *t = NLMSG_DATA(n);
-
 		if (t->tcm_parent != TC_H_ROOT
 		    && t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
 			hook = NF_IP_PRE_ROUTING;
@@ -307,7 +307,8 @@
 		}
 	}
 
-	tail = addattr_nest(n, MAX_MSG, tca_id);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, MAX_MSG, tca_id, NULL, 0);
 	fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]);
 	fprintf(stdout, "\ttarget: ");
 
@@ -328,7 +329,7 @@
 	addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4);
 	if (m)
 		addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size);
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 
 	argc -= optind;
 	argv += optind;
@@ -338,11 +339,11 @@
 	optind = 0;
 	free_opts(opts);
 	/* Clear flags if target will be used again */
-        m->tflags = 0;
-        m->used = 0;
+        m->tflags=0;
+        m->used=0;
 	/* Free allocated memory */
-	if (m->t)
-	    free(m->t);
+        if (m->t)
+            free(m->t);
 
 
 	return 0;
@@ -350,12 +351,10 @@
 }
 
 static int
-print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
+print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
 {
 	struct rtattr *tb[TCA_IPT_MAX + 1];
 	struct xt_entry_target *t = NULL;
-	struct xtables_target *m;
-	__u32 hook;
 
 	if (arg == NULL)
 		return -1;
@@ -365,73 +364,72 @@
 	parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
 
 	if (tb[TCA_IPT_TABLE] == NULL) {
-		fprintf(stderr, "Missing ipt table name, assuming mangle\n");
+		fprintf(f, "[NULL ipt table name ] assuming mangle ");
 	} else {
 		fprintf(f, "tablename: %s ",
 			rta_getattr_str(tb[TCA_IPT_TABLE]));
 	}
 
 	if (tb[TCA_IPT_HOOK] == NULL) {
-		fprintf(stderr, "Missing ipt hook name\n");
+		fprintf(f, "[NULL ipt hook name ]\n ");
 		return -1;
+	} else {
+		__u32 hook;
+		hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+		fprintf(f, " hook: %s \n", ipthooks[hook]);
 	}
 
 	if (tb[TCA_IPT_TARG] == NULL) {
-		fprintf(stderr, "Missing ipt target parameters\n");
+		fprintf(f, "\t[NULL ipt target parameters ] \n");
 		return -1;
-	}
+	} else {
+		struct xtables_target *m = NULL;
+		t = RTA_DATA(tb[TCA_IPT_TARG]);
+		m = find_target(t->u.user.name, TRY_LOAD);
+		if (NULL != m) {
+			if (0 > build_st(m, t)) {
+				fprintf(stderr, " %s error \n", m->name);
+				return -1;
+			}
 
-	hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
-	fprintf(f, " hook: %s\n", ipthooks[hook]);
-
-	t = RTA_DATA(tb[TCA_IPT_TARG]);
-	m = find_target(t->u.user.name, TRY_LOAD);
-	if (m != NULL) {
-		if (build_st(m, t) < 0) {
-			fprintf(stderr, " %s error\n", m->name);
+			opts =
+			    merge_options(opts, m->extra_opts,
+					  &m->option_offset);
+		} else {
+			fprintf(stderr, " failed to find target %s\n\n",
+				t->u.user.name);
 			return -1;
 		}
-
-		opts =
-			merge_options(opts, m->extra_opts,
-				      &m->option_offset);
-	} else {
-		fprintf(stderr, " failed to find target %s\n\n",
-			t->u.user.name);
-		return -1;
-	}
-	fprintf(f, "\ttarget ");
-	m->print(NULL, m->t, 0);
-	if (tb[TCA_IPT_INDEX] == NULL) {
-		fprintf(f, " [NULL ipt target index ]\n");
-	} else {
-		__u32 index;
-
-		index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
-		fprintf(f, "\n\tindex %u", index);
-	}
-
-	if (tb[TCA_IPT_CNT]) {
-		struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);
-
-		fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
-	}
-	if (show_stats) {
-		if (tb[TCA_IPT_TM]) {
-			struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
-
-			print_tm(f, tm);
+		fprintf(f, "\ttarget ");
+		m->print(NULL, m->t, 0);
+		if (tb[TCA_IPT_INDEX] == NULL) {
+			fprintf(f, " [NULL ipt target index ]\n");
+		} else {
+			__u32 index;
+			index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
+			fprintf(f, " \n\tindex %d", index);
 		}
-	}
-	fprintf(f, "\n");
 
+		if (tb[TCA_IPT_CNT]) {
+			struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);;
+			fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
+		}
+		if (show_stats) {
+			if (tb[TCA_IPT_TM]) {
+				struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+				print_tm(f,tm);
+			}
+		}
+		fprintf(f, " \n");
+
+	}
 	free_opts(opts);
 
 	return 0;
 }
 
 struct action_util ipt_action_util = {
-	.id = "ipt",
-	.parse_aopt = parse_ipt,
-	.print_aopt = print_ipt,
+        .id = "ipt",
+        .parse_aopt = parse_ipt,
+        .print_aopt = print_ipt,
 };
diff --git a/tc/p_eth.c b/tc/p_eth.c
deleted file mode 100644
index 674f9c1..0000000
--- a/tc/p_eth.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * m_pedit_eth.c	packet editor: ETH header
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:  Amir Vadai (amir@vadai.me)
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include "utils.h"
-#include "tc_util.h"
-#include "m_pedit.h"
-
-static int
-parse_eth(int *argc_p, char ***argv_p,
-	  struct m_pedit_sel *sel, struct m_pedit_key *tkey)
-{
-	int res = -1;
-	int argc = *argc_p;
-	char **argv = *argv_p;
-
-	if (argc < 2)
-		return -1;
-
-	if (!sel->extended)
-		return -1;
-
-	tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
-
-	if (strcmp(*argv, "type") == 0) {
-		NEXT_ARG();
-		tkey->off = 12;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
-		goto done;
-	}
-
-	if (strcmp(*argv, "dst") == 0) {
-		NEXT_ARG();
-		tkey->off = 0;
-		res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey);
-		goto done;
-	}
-
-	if (strcmp(*argv, "src") == 0) {
-		NEXT_ARG();
-		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 6, TMAC, RU32, sel, tkey);
-		goto done;
-	}
-
-	return -1;
-
-done:
-	*argc_p = argc;
-	*argv_p = argv;
-	return res;
-}
-
-struct m_pedit_util p_pedit_eth = {
-	.id = "eth",
-	.parse_peopt = parse_eth,
-};
diff --git a/tc/p_icmp.c b/tc/p_icmp.c
index 15ce323..a4b80c2 100644
--- a/tc/p_icmp.c
+++ b/tc/p_icmp.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -24,8 +25,7 @@
 
 
 static int
-parse_icmp(int *argc_p, char ***argv_p,
-	   struct m_pedit_sel *sel, struct m_pedit_key *tkey)
+parse_icmp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int res = -1;
 #if 0
@@ -47,7 +47,7 @@
 	}
 	return -1;
 
-done:
+      done:
 	*argc_p = argc;
 	*argv_p = argv;
 #endif
@@ -55,6 +55,7 @@
 }
 
 struct m_pedit_util p_pedit_icmp = {
-	.id = "icmp",
-	.parse_peopt = parse_icmp,
+	NULL,
+	"icmp",
+	parse_icmp,
 };
diff --git a/tc/p_ip.c b/tc/p_ip.c
index c385ac6..08fdbaa 100644
--- a/tc/p_ip.c
+++ b/tc/p_ip.c
@@ -1,5 +1,5 @@
 /*
- * p_ip.c		packet editor: IPV4 header
+ * m_pedit.c		packet editor: IPV4/6 header
  *
  *		This program is free software; you can distribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -23,8 +24,7 @@
 #include "m_pedit.h"
 
 static int
-parse_ip(int *argc_p, char ***argv_p,
-	 struct m_pedit_sel *sel, struct m_pedit_key *tkey)
+parse_ip(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int res = -1;
 	int argc = *argc_p;
@@ -33,129 +33,127 @@
 	if (argc < 2)
 		return -1;
 
-	tkey->htype = sel->extended ?
-		TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 :
-		TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
-
 	if (strcmp(*argv, "src") == 0) {
 		NEXT_ARG();
 		tkey->off = 12;
-		res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
+		res = parse_cmd(&argc, &argv, 4, TIPV4,RU32,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "dst") == 0) {
 		NEXT_ARG();
 		tkey->off = 16;
-		res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
+		res = parse_cmd(&argc, &argv, 4, TIPV4,RU32,sel,tkey);
 		goto done;
 	}
 	/* jamal - look at these and make them either old or new
 	** scheme given diffserv
-	** don't forget the CE bit
+	** dont forget the CE bit
 	*/
 	if (strcmp(*argv, "tos") == 0 || matches(*argv, "dsfield") == 0) {
 		NEXT_ARG();
 		tkey->off = 1;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+		res = parse_cmd(&argc, &argv,  1, TU32,RU8,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "ihl") == 0) {
 		NEXT_ARG();
 		tkey->off = 0;
-		res = parse_cmd(&argc, &argv, 1, TU32, 0x0f, sel, tkey);
-		goto done;
-	}
-	if (strcmp(*argv, "ttl") == 0) {
-		NEXT_ARG();
-		tkey->off = 8;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "protocol") == 0) {
 		NEXT_ARG();
 		tkey->off = 9;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
 		goto done;
 	}
 	/* jamal - fix this */
 	if (matches(*argv, "precedence") == 0) {
 		NEXT_ARG();
 		tkey->off = 1;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
 		goto done;
 	}
 	/* jamal - validate this at some point */
 	if (strcmp(*argv, "nofrag") == 0) {
 		NEXT_ARG();
 		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 1, TU32, 0x3F, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,0x3F,sel,tkey);
 		goto done;
 	}
 	/* jamal - validate this at some point */
 	if (strcmp(*argv, "firstfrag") == 0) {
 		NEXT_ARG();
 		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 1, TU32, 0x1F, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,0x1F,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "ce") == 0) {
 		NEXT_ARG();
 		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 1, TU32, 0x80, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,0x80,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "df") == 0) {
 		NEXT_ARG();
 		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 1, TU32, 0x40, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,0x40,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "mf") == 0) {
 		NEXT_ARG();
 		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 1, TU32, 0x20, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,0x20,sel,tkey);
 		goto done;
 	}
-
-	if (sel->extended)
-		return -1; /* fields located outside IP header should be
-			    * addressed using the relevant header type in
-			    * extended pedit kABI
-			    */
-
 	if (strcmp(*argv, "dport") == 0) {
 		NEXT_ARG();
 		tkey->off = 22;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
+		res = parse_cmd(&argc, &argv, 2, TU32,RU16,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "sport") == 0) {
 		NEXT_ARG();
 		tkey->off = 20;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
+		res = parse_cmd(&argc, &argv, 2, TU32,RU16,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "icmp_type") == 0) {
 		NEXT_ARG();
 		tkey->off = 20;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
 		goto done;
 	}
 	if (strcmp(*argv, "icmp_code") == 0) {
 		NEXT_ARG();
 		tkey->off = 20;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+		res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
 		goto done;
 	}
 	return -1;
 
-done:
+      done:
 	*argc_p = argc;
 	*argv_p = argv;
 	return res;
 }
 
+static int
+parse_ip6(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
+{
+	int res = -1;
+	return res;
+}
+
 struct m_pedit_util p_pedit_ip = {
-	.id = "ip",
-	.parse_peopt = parse_ip,
+	NULL,
+	"ip",
+	parse_ip,
+};
+
+
+struct m_pedit_util p_pedit_ip6 = {
+	NULL,
+	"ip6",
+	parse_ip6,
 };
diff --git a/tc/p_ip6.c b/tc/p_ip6.c
deleted file mode 100644
index 7cc7997..0000000
--- a/tc/p_ip6.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * p_ip6.c		packet editor: IPV6 header
- *
- *		This program is free software; you can distribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:  Amir Vadai <amir@vadai.me>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include "utils.h"
-#include "tc_util.h"
-#include "m_pedit.h"
-
-static int
-parse_ip6(int *argc_p, char ***argv_p,
-	  struct m_pedit_sel *sel, struct m_pedit_key *tkey)
-{
-	int res = -1;
-	int argc = *argc_p;
-	char **argv = *argv_p;
-
-	if (argc < 2)
-		return -1;
-
-	if (!sel->extended)
-		return -1;
-
-	tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
-
-	if (strcmp(*argv, "src") == 0) {
-		NEXT_ARG();
-		tkey->off = 8;
-		res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey);
-		goto done;
-	}
-	if (strcmp(*argv, "dst") == 0) {
-		NEXT_ARG();
-		tkey->off = 24;
-		res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey);
-		goto done;
-	}
-	if (strcmp(*argv, "flow_lbl") == 0) {
-		NEXT_ARG();
-		tkey->off = 0;
-		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
-		goto done;
-	}
-	if (strcmp(*argv, "payload_len") == 0) {
-		NEXT_ARG();
-		tkey->off = 4;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
-		goto done;
-	}
-	if (strcmp(*argv, "nexthdr") == 0) {
-		NEXT_ARG();
-		tkey->off = 6;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
-		goto done;
-	}
-	if (strcmp(*argv, "hoplimit") == 0) {
-		NEXT_ARG();
-		tkey->off = 7;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
-		goto done;
-	}
-
-	return -1;
-
-done:
-	*argc_p = argc;
-	*argv_p = argv;
-	return res;
-}
-
-struct m_pedit_util p_pedit_ip6 = {
-	.id = "ip6",
-	.parse_peopt = parse_ip6,
-};
diff --git a/tc/p_tcp.c b/tc/p_tcp.c
index d2dbfd7..32ffc02 100644
--- a/tc/p_tcp.c
+++ b/tc/p_tcp.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -23,50 +24,13 @@
 #include "m_pedit.h"
 
 static int
-parse_tcp(int *argc_p, char ***argv_p,
-	  struct m_pedit_sel *sel, struct m_pedit_key *tkey)
+parse_tcp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int res = -1;
-	int argc = *argc_p;
-	char **argv = *argv_p;
-
-	if (argc < 2)
-		return -1;
-
-	if (!sel->extended)
-		return -1;
-
-	tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_TCP;
-
-	if (strcmp(*argv, "sport") == 0) {
-		NEXT_ARG();
-		tkey->off = 0;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
-		goto done;
-	}
-
-	if (strcmp(*argv, "dport") == 0) {
-		NEXT_ARG();
-		tkey->off = 2;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
-		goto done;
-	}
-
-	if (strcmp(*argv, "flags") == 0) {
-		NEXT_ARG();
-		tkey->off = 13;
-		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
-		goto done;
-	}
-
-	return -1;
-
-done:
-	*argc_p = argc;
-	*argv_p = argv;
 	return res;
 }
 struct m_pedit_util p_pedit_tcp = {
-	.id = "tcp",
-	.parse_peopt = parse_tcp,
+	NULL,
+	"tcp",
+	parse_tcp,
 };
diff --git a/tc/p_udp.c b/tc/p_udp.c
index bab456d..2b9b88f 100644
--- a/tc/p_udp.c
+++ b/tc/p_udp.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -23,44 +24,14 @@
 #include "m_pedit.h"
 
 static int
-parse_udp(int *argc_p, char ***argv_p,
-	  struct m_pedit_sel *sel, struct m_pedit_key *tkey)
+parse_udp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
 	int res = -1;
-	int argc = *argc_p;
-	char **argv = *argv_p;
-
-	if (argc < 2)
-		return -1;
-
-	if (!sel->extended)
-		return -1;
-
-	tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_UDP;
-
-	if (strcmp(*argv, "sport") == 0) {
-		NEXT_ARG();
-		tkey->off = 0;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
-		goto done;
-	}
-
-	if (strcmp(*argv, "dport") == 0) {
-		NEXT_ARG();
-		tkey->off = 2;
-		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
-		goto done;
-	}
-
-	return -1;
-
-done:
-	*argc_p = argc;
-	*argv_p = argv;
 	return res;
 }
 
 struct m_pedit_util p_pedit_udp = {
-	.id = "udp",
-	.parse_peopt = parse_udp,
+	NULL,
+	"udp",
+	parse_udp,
 };
diff --git a/tc/q_arl.c b/tc/q_arl.c
deleted file mode 100644
index 4ba63a9..0000000
--- a/tc/q_arl.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * Copyright 2018 Google LLC.
- * Author:	Kan Yan <kyan@google.com>
- *
- */
-
-#include <stdio.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-static const char * const arl_state_names[] = {
-	"STABLE",
-	"DRAIN",
-	"BW_PROBE",
-	"LATENCY_PROBE",
-	"UNTHROTTLED",
-	"UNDEFINED",
-};
-
-static void explain(void)
-{
-	fprintf(stderr, "Usage: ... arl [ limit PACKETS] [ buffer TIME ]");
-	fprintf(stderr, " [ minrate KBPS ] [ maxbw KBPS ]\n");
-	fprintf(stderr, "               [ latency TIME ] ");
-	fprintf(stderr, "[ latency_hysteresis TIME ]\n");
-	fprintf(stderr, "[ codel_target TIME ]\n");
-	fprintf(stderr, "[ ingress ]\n");
-}
-
-static int arl_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n)
-{
-	unsigned int buffer = 0, limit = 0, latency = 0, latency_hysteresis = 0,
-		mode = 0, codel_target = 0;
-	__u64 min_rate = 0, max_bw = 0;
-	struct rtattr *tail;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "buffer") == 0) {
-			NEXT_ARG();
-			if (get_time(&buffer, *argv)) {
-				fprintf(stderr, "Illegal \"buffer\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "minrate") == 0) {
-			NEXT_ARG();
-			if (get_rate64(&min_rate, *argv)) {
-				fprintf(stderr, "Illegal \"minrate\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "maxbw") == 0) {
-			NEXT_ARG();
-			if (get_rate64(&max_bw, *argv)) {
-				fprintf(stderr, "Illegal \"max_bw\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "limit") == 0) {
-			NEXT_ARG();
-			if (get_unsigned(&limit, *argv, 0)) {
-				fprintf(stderr, "Illegal \"limit\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "latency") == 0) {
-			NEXT_ARG();
-			if (get_time(&latency, *argv)) {
-				fprintf(stderr, "Illegal \"latency\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "latency_hysteresis") == 0) {
-			NEXT_ARG();
-			if (get_time(&latency_hysteresis, *argv)) {
-				fprintf(stderr,
-					"Illegal \"latency hysteresis\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "codel_target") == 0) {
-			NEXT_ARG();
-			if (get_time(&codel_target, *argv)) {
-				fprintf(stderr, "Illegal \"codel_target\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "ingress") == 0) {
-			mode = 1;
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "arl: unknown parameter \"%s\"\n",
-				*argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	if (buffer)
-		addattr_l(n, 1024, TCA_ARL_BUFFER, &buffer, sizeof(__u32));
-	if (min_rate)
-		addattr_l(n, 1024, TCA_ARL_MIN_RATE, &min_rate, sizeof(__u64));
-	if (max_bw)
-		addattr_l(n, 1024, TCA_ARL_MAX_BW, &max_bw, sizeof(__u64));
-	if (limit)
-		addattr_l(n, 1024, TCA_ARL_LIMIT, &limit, sizeof(__u32));
-	if (latency)
-		addattr_l(n, 1024, TCA_ARL_MAX_LATENCY, &latency,
-			  sizeof(__u32));
-	if (latency_hysteresis)
-		addattr_l(n, 1024, TCA_ARL_LATENCY_HYSTERESIS,
-			  &latency_hysteresis, sizeof(__u32));
-	if (codel_target)
-		addattr_l(n, 1024, TCA_ARL_CODEL_TARGET, &codel_target,
-			  sizeof(__u32));
-	if (mode)
-		addattr_l(n, 1024, TCA_ARL_MODE, &mode, sizeof(__u32));
-
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int arl_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	unsigned int buffer, limit, latency, latency_hysteresis, mode,
-		     codel_target;
-	__u64 min_rate = 0, max_bw;
-	struct rtattr *tb[TCA_ARL_MAX + 1];
-
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_ARL_MAX, opt);
-	if (tb[TCA_ARL_MIN_RATE] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_MIN_RATE]) >= sizeof(__u64)) {
-		min_rate = rta_getattr_u64(tb[TCA_ARL_MIN_RATE]);
-		fprintf(f, "minrate %s ", sprint_rate(min_rate, b1));
-	}
-
-	if (tb[TCA_ARL_BUFFER] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_BUFFER]) >= sizeof(__u32)) {
-		buffer = rta_getattr_u32(tb[TCA_ARL_BUFFER]);
-		fprintf(f, "buffer %s ", sprint_time(buffer, b1));
-	}
-
-	if (tb[TCA_ARL_MAX_BW] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_MAX_BW]) >= sizeof(__u64)) {
-		max_bw = rta_getattr_u64(tb[TCA_ARL_MAX_BW]);
-		fprintf(f, "max_bw %s ", sprint_rate(max_bw, b1));
-	}
-
-	if (tb[TCA_ARL_LIMIT] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_LIMIT]) >= sizeof(__u32)) {
-		limit = rta_getattr_u32(tb[TCA_ARL_LIMIT]);
-		fprintf(f, "limit %u ", limit);
-	}
-
-	if (tb[TCA_ARL_MAX_LATENCY] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_MAX_LATENCY]) >= sizeof(__u32)) {
-		latency = rta_getattr_u32(tb[TCA_ARL_MAX_LATENCY]);
-		fprintf(f, "latency %s ", sprint_time(latency, b1));
-	}
-
-	if (tb[TCA_ARL_LATENCY_HYSTERESIS] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_LATENCY_HYSTERESIS]) >= sizeof(__u32)) {
-		latency_hysteresis =
-			rta_getattr_u32(tb[TCA_ARL_LATENCY_HYSTERESIS]);
-		fprintf(f, "latency_hysteresis %s ",
-			sprint_time(latency_hysteresis, b1));
-	}
-
-	if (tb[TCA_ARL_CODEL_TARGET] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_CODEL_TARGET]) >= sizeof(__u32)) {
-		codel_target = rta_getattr_u32(tb[TCA_ARL_CODEL_TARGET]);
-		fprintf(f, "codel_target %s ", sprint_time(codel_target, b1));
-	}
-
-	if (tb[TCA_ARL_MODE] &&
-	    RTA_PAYLOAD(tb[TCA_ARL_MODE]) >= sizeof(__u32)) {
-		mode = rta_getattr_u32(tb[TCA_ARL_MODE]);
-		if (mode)
-			fprintf(f, "mode ingress");
-		else
-			fprintf(f, "mode egress");
-	}
-
-	return 0;
-}
-
-static int arl_print_xstats(struct qdisc_util *qu, FILE *f,
-			    struct rtattr *xstats)
-{
-	struct tc_arl_xstats *st;
-
-	if (xstats == NULL)
-		return 0;
-
-	if (RTA_PAYLOAD(xstats) < sizeof(*st))
-		return -1;
-
-	st = RTA_DATA(xstats);
-
-	fprintf(f, "state %s base_rate %uKbit current_rate %uKbit latency %uus bw %uKbit",
-		arl_state_names[st->state], st->base_rate, st->current_rate,
-		st->latency, st->current_bw);
-	if (st->max_bw)
-		fprintf(f, " max_bw %uKbit", st->max_bw);
-
-	if (st->min_rate)
-		fprintf(f, " min_base_rate %uKbit", st->min_rate);
-
-	return 0;
-}
-
-struct qdisc_util arl_qdisc_util = {
-	.id		= "arl",
-	.parse_qopt	= arl_parse_opt,
-	.print_qopt	= arl_print_opt,
-	.print_xstats	= arl_print_xstats,
-};
diff --git a/tc/q_atm.c b/tc/q_atm.c
index 77b5682..2598e29 100644
--- a/tc/q_atm.c
+++ b/tc/q_atm.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * q_atm.c		ATM.
  *
@@ -10,6 +9,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
@@ -27,11 +27,10 @@
 #define MAX_HDR_LEN 64
 
 
-static int atm_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+static int atm_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	if (argc) {
-		fprintf(stderr, "Usage: atm\n");
+		fprintf(stderr,"Usage: atm\n");
 		return -1;
 	}
 	return 0;
@@ -40,16 +39,17 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... atm ( pvc ADDR | svc ADDR [ sap SAP ] ) [ qos QOS ] [ sndbuf BYTES ]\n"
-		"  [ hdr HEX... ] [ excess ( CLASSID | clp ) ] [ clip ]\n");
+	fprintf(stderr, "Usage: ... atm ( pvc ADDR | svc ADDR [ sap SAP ] ) "
+	    "[ qos QOS ] [ sndbuf BYTES ]\n");
+	fprintf(stderr, "  [ hdr HEX... ] [ excess ( CLASSID | clp ) ] "
+	  "[ clip ]\n");
 }
 
 
 static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
-	struct nlmsghdr *n, const char *dev)
+   struct nlmsghdr *n)
 {
-	struct sockaddr_atmsvc addr = {};
+	struct sockaddr_atmsvc addr;
 	struct atm_qos qos;
 	struct atm_sap sap;
 	unsigned char hdr[MAX_HDR_LEN];
@@ -60,46 +60,52 @@
 	int set_clip = 0;
 	int s;
 
-	(void) text2qos("aal5,ubr:sdu=9180,rx:none", &qos, 0);
-	(void) text2sap("blli:l2=iso8802", &sap, 0);
+	memset(&addr,0,sizeof(addr));
+	(void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
+	(void) text2sap("blli:l2=iso8802",&sap,0);
 	while (argc > 0) {
-		if (!strcmp(*argv, "pvc")) {
+		if (!strcmp(*argv,"pvc")) {
 			NEXT_ARG();
-			if (text2atm(*argv, (struct sockaddr *) &addr,
-			    sizeof(addr), T2A_PVC | T2A_NAME) < 0) {
+			if (text2atm(*argv,(struct sockaddr *) &addr,
+			    sizeof(addr),T2A_PVC | T2A_NAME) < 0) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"svc")) {
+		}
+		else if (!strcmp(*argv,"svc")) {
 			NEXT_ARG();
-			if (text2atm(*argv, (struct sockaddr *) &addr,
-			    sizeof(addr), T2A_SVC | T2A_NAME) < 0) {
+			if (text2atm(*argv,(struct sockaddr *) &addr,
+			    sizeof(addr),T2A_SVC | T2A_NAME) < 0) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"qos")) {
+		}
+		else if (!strcmp(*argv,"qos")) {
 			NEXT_ARG();
-			if (text2qos(*argv, &qos, 0) < 0) {
+			if (text2qos(*argv,&qos,0) < 0) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"sndbuf")) {
+		}
+		else if (!strcmp(*argv,"sndbuf")) {
 			char *end;
 
 			NEXT_ARG();
-			sndbuf = strtol(*argv, &end, 0);
+			sndbuf = strtol(*argv,&end,0);
 			if (*end) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"sap")) {
+		}
+		else if (!strcmp(*argv,"sap")) {
 			NEXT_ARG();
 			if (addr.sas_family != AF_ATMSVC ||
-			    text2sap(*argv, &sap, T2A_NAME) < 0) {
+			    text2sap(*argv,&sap,T2A_NAME) < 0) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"hdr")) {
+		}
+		else if (!strcmp(*argv,"hdr")) {
 			unsigned char *ptr;
 			char *walk;
 
@@ -109,7 +115,7 @@
 				int tmp;
 
 				if (ptr == hdr+MAX_HDR_LEN) {
-					fprintf(stderr, "header is too long\n");
+					fprintf(stderr,"header is too long\n");
 					return -1;
 				}
 				if (*walk == '.') continue;
@@ -118,63 +124,65 @@
 					explain();
 					return -1;
 				}
-				sscanf(walk, "%2x", &tmp);
+				sscanf(walk,"%2x",&tmp);
 				*ptr++ = tmp;
 				walk++;
 			}
 			hdr_len = ptr-hdr;
-		} else if (!strcmp(*argv,"excess")) {
+		}
+		else if (!strcmp(*argv,"excess")) {
 			NEXT_ARG();
-			if (!strcmp(*argv, "clp")) excess = 0;
-			else if (get_tc_classid(&excess, *argv)) {
+			if (!strcmp(*argv,"clp")) excess = 0;
+			else if (get_tc_classid(&excess,*argv)) {
 					explain();
 					return -1;
 				}
-		} else if (!strcmp(*argv,"clip")) {
+		}
+		else if (!strcmp(*argv,"clip")) {
 			set_clip = 1;
-		} else {
+		}
+		else {
 			explain();
 			return 1;
 		}
 		argc--;
 		argv++;
 	}
-	s = socket(addr.sas_family, SOCK_DGRAM, 0);
+	s = socket(addr.sas_family,SOCK_DGRAM,0);
 	if (s < 0) {
 		perror("socket");
 		return -1;
 	}
-	if (setsockopt(s, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0) {
+	if (setsockopt(s,SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0) {
 		perror("SO_ATMQOS");
 		return -1;
 	}
 	if (sndbuf)
-	    if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) {
+	    if (setsockopt(s,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
 		perror("SO_SNDBUF");
 	    return -1;
 	}
-	if (addr.sas_family == AF_ATMSVC && setsockopt(s, SOL_ATM, SO_ATMSAP,
-	    &sap, sizeof(sap)) < 0) {
+	if (addr.sas_family == AF_ATMSVC && setsockopt(s,SOL_ATM,SO_ATMSAP,
+	    &sap,sizeof(sap)) < 0) {
 		perror("SO_ATMSAP");
 		return -1;
 	}
-	if (connect(s, (struct sockaddr *) &addr, addr.sas_family == AF_ATMPVC ?
+	if (connect(s,(struct sockaddr *) &addr,addr.sas_family == AF_ATMPVC ?
 	    sizeof(struct sockaddr_atmpvc) : sizeof(addr)) < 0) {
 		perror("connect");
 		return -1;
 	}
 	if (set_clip)
-		if (ioctl(s, ATMARP_MKIP, 0) < 0) {
+		if (ioctl(s,ATMARP_MKIP,0) < 0) {
 			perror("ioctl ATMARP_MKIP");
 			return -1;
 		}
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
-	addattr_l(n, 1024, TCA_ATM_FD, &s, sizeof(s));
-	if (excess)
-		addattr_l(n, 1024, TCA_ATM_EXCESS, &excess, sizeof(excess));
-	if (hdr_len != -1)
-		addattr_l(n, 1024, TCA_ATM_HDR, hdr, hdr_len);
-	addattr_nest_end(n, tail);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
+	addattr_l(n,1024,TCA_ATM_FD,&s,sizeof(s));
+	if (excess) addattr_l(n,1024,TCA_ATM_EXCESS,&excess,sizeof(excess));
+	if (hdr_len != -1) addattr_l(n,1024,TCA_ATM_HDR,hdr,hdr_len);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -192,37 +200,37 @@
 	if (tb[TCA_ATM_ADDR]) {
 		if (RTA_PAYLOAD(tb[TCA_ATM_ADDR]) <
 		    sizeof(struct sockaddr_atmpvc))
-			fprintf(stderr, "ATM: address too short\n");
+			fprintf(stderr,"ATM: address too short\n");
 		else {
-			if (atm2text(buffer, MAX_ATM_ADDR_LEN,
-			    RTA_DATA(tb[TCA_ATM_ADDR]), A2T_PRETTY | A2T_NAME) <
-			    0) fprintf(stderr, "atm2text error\n");
-			fprintf(f, "pvc %s ", buffer);
+			if (atm2text(buffer,MAX_ATM_ADDR_LEN,
+			    RTA_DATA(tb[TCA_ATM_ADDR]),A2T_PRETTY | A2T_NAME) <
+			    0) fprintf(stderr,"atm2text error\n");
+			fprintf(f,"pvc %s ",buffer);
 		}
 	}
 	if (tb[TCA_ATM_HDR]) {
 		int i;
 		const __u8 *hdr = RTA_DATA(tb[TCA_ATM_HDR]);
 
-		fprintf(f, "hdr");
+		fprintf(f,"hdr");
 		for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++)
-			fprintf(f, "%c%02x", i ? '.' : ' ', hdr[i]);
-		if (!i) fprintf(f, " .");
-		fprintf(f, " ");
+			fprintf(f,"%c%02x", i ? '.' : ' ', hdr[i]);
+		if (!i) fprintf(f," .");
+		fprintf(f," ");
 	}
 	if (tb[TCA_ATM_EXCESS]) {
 		__u32 excess;
 
 		if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS]) < sizeof(excess))
-			fprintf(stderr, "ATM: excess class ID too short\n");
+			fprintf(stderr,"ATM: excess class ID too short\n");
 		else {
 			excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]);
-			if (!excess) fprintf(f, "excess clp ");
+			if (!excess) fprintf(f,"excess clp ");
 			else {
 				char buf[64];
 
-				print_tc_classid(buf, sizeof(buf), excess);
-				fprintf(f, "excess %s ", buf);
+				print_tc_classid(buf,sizeof(buf),excess);
+				fprintf(f,"excess %s ",buf);
 			}
 		}
 	}
@@ -231,10 +239,10 @@
 		int state;
 
 		if (RTA_PAYLOAD(tb[TCA_ATM_STATE]) < sizeof(state))
-			fprintf(stderr, "ATM: state field too short\n");
+			fprintf(stderr,"ATM: state field too short\n");
 		else {
-			state = rta_getattr_u32(tb[TCA_ATM_STATE]);
-			fprintf(f, "%s ", map[state]);
+			state = *(int *) RTA_DATA(tb[TCA_ATM_STATE]);
+			fprintf(f,"%s ",map[state]);
 		}
 	}
 	return 0;
@@ -242,7 +250,7 @@
 
 
 struct qdisc_util atm_qdisc_util = {
-	.id		= "atm",
+	.id 		= "atm",
 	.parse_qopt	= atm_parse_opt,
 	.print_qopt	= atm_print_opt,
 	.parse_copt	= atm_parse_class_opt,
diff --git a/tc/q_cake.c b/tc/q_cake.c
deleted file mode 100644
index 65ea07e..0000000
--- a/tc/q_cake.c
+++ /dev/null
@@ -1,829 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
-
-/*
- * Common Applications Kept Enhanced  --  CAKE
- *
- *  Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
- *  Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
- */
-
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-struct cake_preset {
-	char *name;
-	unsigned int target;
-	unsigned int interval;
-};
-
-static struct cake_preset presets[] = {
-	{"datacentre",		5,		100},
-	{"lan",			50,		1000},
-	{"metro",		500,		10000},
-	{"regional",		1500,		30000},
-	{"internet",		5000,		100000},
-	{"oceanic",		15000,		300000},
-	{"satellite",		50000,		1000000},
-	{"interplanetary",	50000000,	1000000000},
-};
-
-static const char * diffserv_names[CAKE_DIFFSERV_MAX] = {
-	[CAKE_DIFFSERV_DIFFSERV3] = "diffserv3",
-	[CAKE_DIFFSERV_DIFFSERV4] = "diffserv4",
-	[CAKE_DIFFSERV_DIFFSERV8] = "diffserv8",
-	[CAKE_DIFFSERV_BESTEFFORT] = "besteffort",
-	[CAKE_DIFFSERV_PRECEDENCE] = "precedence",
-};
-
-static const char * flowmode_names[CAKE_FLOW_MAX] = {
-	[CAKE_FLOW_NONE] = "flowblind",
-	[CAKE_FLOW_SRC_IP] = "srchost",
-	[CAKE_FLOW_DST_IP] = "dsthost",
-	[CAKE_FLOW_HOSTS] = "hosts",
-	[CAKE_FLOW_FLOWS] = "flows",
-	[CAKE_FLOW_DUAL_SRC] = "dual-srchost",
-	[CAKE_FLOW_DUAL_DST] = "dual-dsthost",
-	[CAKE_FLOW_TRIPLE] = "triple-isolate",
-};
-
-static struct cake_preset *find_preset(char *argv)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(presets); i++)
-		if (!strcmp(argv, presets[i].name))
-			return &presets[i];
-	return NULL;
-}
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: ... cake [ bandwidth RATE | unlimited* | autorate-ingress ]\n"
-		"                [ rtt TIME | datacentre | lan | metro | regional |\n"
-		"                  internet* | oceanic | satellite | interplanetary ]\n"
-		"                [ besteffort | diffserv8 | diffserv4 | diffserv3* ]\n"
-		"                [ flowblind | srchost | dsthost | hosts | flows |\n"
-		"                  dual-srchost | dual-dsthost | triple-isolate* ]\n"
-		"                [ nat | nonat* ]\n"
-		"                [ wash | nowash* ]\n"
-		"                [ split-gso* | no-split-gso ]\n"
-		"                [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
-		"                [ memlimit LIMIT ]\n"
-		"                [ fwmark MASK ]\n"
-		"                [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
-		"                [ mpu N ] [ ingress | egress* ]\n"
-		"                (* marks defaults)\n");
-}
-
-static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			  struct nlmsghdr *n, const char *dev)
-{
-	struct cake_preset *preset, *preset_set = NULL;
-	bool overhead_override = false;
-	bool overhead_set = false;
-	unsigned int interval = 0;
-	unsigned int diffserv = 0;
-	unsigned int memlimit = 0;
-	unsigned int target = 0;
-	__u64 bandwidth = 0;
-	int ack_filter = -1;
-	struct rtattr *tail;
-	int split_gso = -1;
-	int unlimited = 0;
-	int flowmode = -1;
-	int autorate = -1;
-	int ingress = -1;
-	int overhead = 0;
-	int fwmark = -1;
-	int wash = -1;
-	int nat = -1;
-	int atm = -1;
-	int mpu = 0;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "bandwidth") == 0) {
-			NEXT_ARG();
-			if (get_rate64(&bandwidth, *argv)) {
-				fprintf(stderr, "Illegal \"bandwidth\"\n");
-				return -1;
-			}
-			unlimited = 0;
-			autorate = 0;
-		} else if (strcmp(*argv, "unlimited") == 0) {
-			bandwidth = 0;
-			unlimited = 1;
-			autorate = 0;
-		} else if (strcmp(*argv, "autorate-ingress") == 0) {
-			autorate = 1;
-		} else if (strcmp(*argv, "rtt") == 0) {
-			NEXT_ARG();
-			if (get_time(&interval, *argv)) {
-				fprintf(stderr, "Illegal \"rtt\"\n");
-				return -1;
-			}
-			target = interval / 20;
-			if (!target)
-				target = 1;
-		} else if ((preset = find_preset(*argv))) {
-			if (preset_set)
-				duparg(*argv, preset_set->name);
-			preset_set = preset;
-			target = preset->target;
-			interval = preset->interval;
-		} else if (strcmp(*argv, "besteffort") == 0) {
-			diffserv = CAKE_DIFFSERV_BESTEFFORT;
-		} else if (strcmp(*argv, "precedence") == 0) {
-			diffserv = CAKE_DIFFSERV_PRECEDENCE;
-		} else if (strcmp(*argv, "diffserv8") == 0) {
-			diffserv = CAKE_DIFFSERV_DIFFSERV8;
-		} else if (strcmp(*argv, "diffserv4") == 0) {
-			diffserv = CAKE_DIFFSERV_DIFFSERV4;
-		} else if (strcmp(*argv, "diffserv") == 0) {
-			diffserv = CAKE_DIFFSERV_DIFFSERV4;
-		} else if (strcmp(*argv, "diffserv3") == 0) {
-			diffserv = CAKE_DIFFSERV_DIFFSERV3;
-		} else if (strcmp(*argv, "nowash") == 0) {
-			wash = 0;
-		} else if (strcmp(*argv, "wash") == 0) {
-			wash = 1;
-		} else if (strcmp(*argv, "split-gso") == 0) {
-			split_gso = 1;
-		} else if (strcmp(*argv, "no-split-gso") == 0) {
-			split_gso = 0;
-		} else if (strcmp(*argv, "flowblind") == 0) {
-			flowmode = CAKE_FLOW_NONE;
-		} else if (strcmp(*argv, "srchost") == 0) {
-			flowmode = CAKE_FLOW_SRC_IP;
-		} else if (strcmp(*argv, "dsthost") == 0) {
-			flowmode = CAKE_FLOW_DST_IP;
-		} else if (strcmp(*argv, "hosts") == 0) {
-			flowmode = CAKE_FLOW_HOSTS;
-		} else if (strcmp(*argv, "flows") == 0) {
-			flowmode = CAKE_FLOW_FLOWS;
-		} else if (strcmp(*argv, "dual-srchost") == 0) {
-			flowmode = CAKE_FLOW_DUAL_SRC;
-		} else if (strcmp(*argv, "dual-dsthost") == 0) {
-			flowmode = CAKE_FLOW_DUAL_DST;
-		} else if (strcmp(*argv, "triple-isolate") == 0) {
-			flowmode = CAKE_FLOW_TRIPLE;
-		} else if (strcmp(*argv, "nat") == 0) {
-			nat = 1;
-		} else if (strcmp(*argv, "nonat") == 0) {
-			nat = 0;
-		} else if (strcmp(*argv, "ptm") == 0) {
-			atm = CAKE_ATM_PTM;
-		} else if (strcmp(*argv, "atm") == 0) {
-			atm = CAKE_ATM_ATM;
-		} else if (strcmp(*argv, "noatm") == 0) {
-			atm = CAKE_ATM_NONE;
-		} else if (strcmp(*argv, "raw") == 0) {
-			atm = CAKE_ATM_NONE;
-			overhead = 0;
-			overhead_set = true;
-			overhead_override = true;
-		} else if (strcmp(*argv, "conservative") == 0) {
-			/*
-			 * Deliberately over-estimate overhead:
-			 * one whole ATM cell plus ATM framing.
-			 * A safe choice if the actual overhead is unknown.
-			 */
-			atm = CAKE_ATM_ATM;
-			overhead = 48;
-			overhead_set = true;
-
-		/* Various ADSL framing schemes, all over ATM cells */
-		} else if (strcmp(*argv, "ipoa-vcmux") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 8;
-			overhead_set = true;
-		} else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 16;
-			overhead_set = true;
-		} else if (strcmp(*argv, "bridged-vcmux") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 24;
-			overhead_set = true;
-		} else if (strcmp(*argv, "bridged-llcsnap") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 32;
-			overhead_set = true;
-		} else if (strcmp(*argv, "pppoa-vcmux") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 10;
-			overhead_set = true;
-		} else if (strcmp(*argv, "pppoa-llc") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 14;
-			overhead_set = true;
-		} else if (strcmp(*argv, "pppoe-vcmux") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 32;
-			overhead_set = true;
-		} else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
-			atm = CAKE_ATM_ATM;
-			overhead += 40;
-			overhead_set = true;
-
-		/* Typical VDSL2 framing schemes, both over PTM */
-		/* PTM has 64b/65b coding which absorbs some bandwidth */
-		} else if (strcmp(*argv, "pppoe-ptm") == 0) {
-			/* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
-			 * + 2B ethertype + 4B Frame Check Sequence
-			 * + 1B Start of Frame (S) + 1B End of Frame (Ck)
-			 * + 2B TC-CRC (PTM-FCS) = 30B
-			 */
-			atm = CAKE_ATM_PTM;
-			overhead += 30;
-			overhead_set = true;
-		} else if (strcmp(*argv, "bridged-ptm") == 0) {
-			/* 6B dest MAC + 6B src MAC + 2B ethertype
-			 * + 4B Frame Check Sequence
-			 * + 1B Start of Frame (S) + 1B End of Frame (Ck)
-			 * + 2B TC-CRC (PTM-FCS) = 22B
-			 */
-			atm = CAKE_ATM_PTM;
-			overhead += 22;
-			overhead_set = true;
-		} else if (strcmp(*argv, "via-ethernet") == 0) {
-			/*
-			 * We used to use this flag to manually compensate for
-			 * Linux including the Ethernet header on Ethernet-type
-			 * interfaces, but not on IP-type interfaces.
-			 *
-			 * It is no longer needed, because Cake now adjusts for
-			 * that automatically, and is thus ignored.
-			 *
-			 * It would be deleted entirely, but it appears in the
-			 * stats output when the automatic compensation is
-			 * active.
-			 */
-		} else if (strcmp(*argv, "ethernet") == 0) {
-			/* ethernet pre-amble & interframe gap & FCS
-			 * you may need to add vlan tag
-			 */
-			overhead += 38;
-			overhead_set = true;
-			mpu = 84;
-
-		/* Additional Ethernet-related overhead used by some ISPs */
-		} else if (strcmp(*argv, "ether-vlan") == 0) {
-			/* 802.1q VLAN tag - may be repeated */
-			overhead += 4;
-			overhead_set = true;
-
-		/*
-		 * DOCSIS cable shapers account for Ethernet frame with FCS,
-		 * but not interframe gap or preamble.
-		 */
-		} else if (strcmp(*argv, "docsis") == 0) {
-			atm = CAKE_ATM_NONE;
-			overhead += 18;
-			overhead_set = true;
-			mpu = 64;
-		} else if (strcmp(*argv, "overhead") == 0) {
-			char *p = NULL;
-
-			NEXT_ARG();
-			overhead = strtol(*argv, &p, 10);
-			if (!p || *p || !*argv ||
-			    overhead < -64 || overhead > 256) {
-				fprintf(stderr,
-					"Illegal \"overhead\", valid range is -64 to 256\\n");
-				return -1;
-			}
-			overhead_set = true;
-
-		} else if (strcmp(*argv, "mpu") == 0) {
-			char *p = NULL;
-
-			NEXT_ARG();
-			mpu = strtol(*argv, &p, 10);
-			if (!p || *p || !*argv || mpu < 0 || mpu > 256) {
-				fprintf(stderr,
-					"Illegal \"mpu\", valid range is 0 to 256\\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "ingress") == 0) {
-			ingress = 1;
-		} else if (strcmp(*argv, "egress") == 0) {
-			ingress = 0;
-		} else if (strcmp(*argv, "no-ack-filter") == 0) {
-			ack_filter = CAKE_ACK_NONE;
-		} else if (strcmp(*argv, "ack-filter") == 0) {
-			ack_filter = CAKE_ACK_FILTER;
-		} else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
-			ack_filter = CAKE_ACK_AGGRESSIVE;
-		} else if (strcmp(*argv, "memlimit") == 0) {
-			NEXT_ARG();
-			if (get_size(&memlimit, *argv)) {
-				fprintf(stderr,
-					"Illegal value for \"memlimit\": \"%s\"\n", *argv);
-				return -1;
-			}
-		} else if (strcmp(*argv, "fwmark") == 0) {
-			unsigned int fwm;
-
-			NEXT_ARG();
-			if (get_u32(&fwm, *argv, 0)) {
-				fprintf(stderr,
-					"Illegal value for \"fwmark\": \"%s\"\n", *argv);
-				return -1;
-			}
-			fwmark = fwm;
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	if (bandwidth || unlimited)
-		addattr_l(n, 1024, TCA_CAKE_BASE_RATE64, &bandwidth,
-			  sizeof(bandwidth));
-	if (diffserv)
-		addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv,
-			  sizeof(diffserv));
-	if (atm != -1)
-		addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
-	if (flowmode != -1)
-		addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode,
-			  sizeof(flowmode));
-	if (overhead_set)
-		addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead,
-			  sizeof(overhead));
-	if (overhead_override) {
-		unsigned int zero = 0;
-
-		addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
-	}
-	if (mpu > 0)
-		addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
-	if (interval)
-		addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
-	if (target)
-		addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
-	if (autorate != -1)
-		addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate,
-			  sizeof(autorate));
-	if (memlimit)
-		addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit,
-			  sizeof(memlimit));
-	if (fwmark != -1)
-		addattr_l(n, 1024, TCA_CAKE_FWMARK, &fwmark,
-			  sizeof(fwmark));
-	if (nat != -1)
-		addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
-	if (wash != -1)
-		addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
-	if (split_gso != -1)
-		addattr_l(n, 1024, TCA_CAKE_SPLIT_GSO, &split_gso,
-			  sizeof(split_gso));
-	if (ingress != -1)
-		addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
-	if (ack_filter != -1)
-		addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter,
-			  sizeof(ack_filter));
-
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static void cake_print_mode(unsigned int value, unsigned int max,
-			    const char *key, const char **table)
-{
-	if (value < max && table[value]) {
-		print_string(PRINT_ANY, key, "%s ", table[value]);
-	} else {
-		print_string(PRINT_JSON, key, NULL, "unknown");
-		print_string(PRINT_FP, NULL, "(?%s?)", key);
-	}
-}
-
-static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_CAKE_MAX + 1];
-	unsigned int interval = 0;
-	unsigned int memlimit = 0;
-	unsigned int fwmark = 0;
-	__u64 bandwidth = 0;
-	int ack_filter = 0;
-	int split_gso = 0;
-	int overhead = 0;
-	int autorate = 0;
-	int ingress = 0;
-	int wash = 0;
-	int raw = 0;
-	int mpu = 0;
-	int atm = 0;
-	int nat = 0;
-
-	SPRINT_BUF(b1);
-	SPRINT_BUF(b2);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
-
-	if (tb[TCA_CAKE_BASE_RATE64] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE64]) >= sizeof(bandwidth)) {
-		bandwidth = rta_getattr_u64(tb[TCA_CAKE_BASE_RATE64]);
-		if (bandwidth) {
-			print_uint(PRINT_JSON, "bandwidth", NULL, bandwidth);
-			print_string(PRINT_FP, NULL, "bandwidth %s ",
-				     sprint_rate(bandwidth, b1));
-		} else
-			print_string(PRINT_ANY, "bandwidth", "bandwidth %s ",
-				     "unlimited");
-	}
-	if (tb[TCA_CAKE_AUTORATE] &&
-		RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
-		autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
-		if (autorate == 1)
-			print_string(PRINT_ANY, "autorate", "%s ",
-				     "autorate-ingress");
-		else if (autorate)
-			print_string(PRINT_ANY, "autorate", "(?autorate?) ",
-				     "unknown");
-	}
-	if (tb[TCA_CAKE_DIFFSERV_MODE] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
-		cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]),
-				CAKE_DIFFSERV_MAX, "diffserv", diffserv_names);
-	}
-	if (tb[TCA_CAKE_FLOW_MODE] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
-		cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]),
-				CAKE_FLOW_MAX, "flowmode", flowmode_names);
-	}
-
-	if (tb[TCA_CAKE_NAT] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_NAT]) >= sizeof(__u32)) {
-		nat = rta_getattr_u32(tb[TCA_CAKE_NAT]);
-	}
-
-	if (nat)
-		print_string(PRINT_FP, NULL, "nat ", NULL);
-	else
-		print_string(PRINT_FP, NULL, "nonat ", NULL);
-	print_bool(PRINT_JSON, "nat", NULL, nat);
-
-	if (tb[TCA_CAKE_WASH] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
-		wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
-	}
-	if (tb[TCA_CAKE_ATM] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
-		atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
-	}
-	if (tb[TCA_CAKE_OVERHEAD] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__s32)) {
-		overhead = *(__s32 *) RTA_DATA(tb[TCA_CAKE_OVERHEAD]);
-	}
-	if (tb[TCA_CAKE_MPU] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
-		mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
-	}
-	if (tb[TCA_CAKE_INGRESS] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
-		ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
-	}
-	if (tb[TCA_CAKE_ACK_FILTER] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
-		ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
-	}
-	if (tb[TCA_CAKE_SPLIT_GSO] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_SPLIT_GSO]) >= sizeof(__u32)) {
-		split_gso = rta_getattr_u32(tb[TCA_CAKE_SPLIT_GSO]);
-	}
-	if (tb[TCA_CAKE_RAW]) {
-		raw = 1;
-	}
-	if (tb[TCA_CAKE_RTT] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
-		interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
-	}
-	if (tb[TCA_CAKE_FWMARK] &&
-	    RTA_PAYLOAD(tb[TCA_CAKE_FWMARK]) >= sizeof(__u32)) {
-		fwmark = rta_getattr_u32(tb[TCA_CAKE_FWMARK]);
-	}
-
-	if (wash)
-		print_string(PRINT_FP, NULL, "wash ", NULL);
-	else
-		print_string(PRINT_FP, NULL, "nowash ", NULL);
-	print_bool(PRINT_JSON, "wash", NULL, wash);
-
-	if (ingress)
-		print_string(PRINT_FP, NULL, "ingress ", NULL);
-	print_bool(PRINT_JSON, "ingress", NULL, ingress);
-
-	if (ack_filter == CAKE_ACK_AGGRESSIVE)
-		print_string(PRINT_ANY, "ack-filter", "ack-filter-%s ",
-			     "aggressive");
-	else if (ack_filter == CAKE_ACK_FILTER)
-		print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
-	else
-		print_string(PRINT_ANY, "ack-filter", "no-ack-filter ", "disabled");
-
-	if (split_gso)
-		print_string(PRINT_FP, NULL, "split-gso ", NULL);
-	else
-		print_string(PRINT_FP, NULL, "no-split-gso ", NULL);
-	print_bool(PRINT_JSON, "split_gso", NULL, split_gso);
-
-	if (interval)
-		print_string(PRINT_FP, NULL, "rtt %s ",
-			     sprint_time(interval, b2));
-	print_uint(PRINT_JSON, "rtt", NULL, interval);
-
-	if (raw)
-		print_string(PRINT_FP, NULL, "raw ", NULL);
-	print_bool(PRINT_JSON, "raw", NULL, raw);
-
-	if (atm == CAKE_ATM_ATM)
-		print_string(PRINT_ANY, "atm", "%s ", "atm");
-	else if (atm == CAKE_ATM_PTM)
-		print_string(PRINT_ANY, "atm", "%s ", "ptm");
-	else if (!raw)
-		print_string(PRINT_ANY, "atm", "%s ", "noatm");
-
-	print_int(PRINT_ANY, "overhead", "overhead %d ", overhead);
-
-	if (mpu)
-		print_uint(PRINT_ANY, "mpu", "mpu %u ", mpu);
-
-	if (memlimit) {
-		print_uint(PRINT_JSON, "memlimit", NULL, memlimit);
-		print_string(PRINT_FP, NULL, "memlimit %s",
-			     sprint_size(memlimit, b1));
-	}
-
-	if (fwmark)
-		print_uint(PRINT_FP, NULL, "fwmark 0x%x ", fwmark);
-	print_0xhex(PRINT_JSON, "fwmark", NULL, fwmark);
-
-	return 0;
-}
-
-static void cake_print_json_tin(struct rtattr **tstat)
-{
-#define PRINT_TSTAT_JSON(type, name, attr) if (tstat[TCA_CAKE_TIN_STATS_ ## attr]) \
-		print_u64(PRINT_JSON, name, NULL,			\
-			rta_getattr_ ## type((struct rtattr *)		\
-					     tstat[TCA_CAKE_TIN_STATS_ ## attr]))
-
-	open_json_object(NULL);
-	PRINT_TSTAT_JSON(u64, "threshold_rate", THRESHOLD_RATE64);
-	PRINT_TSTAT_JSON(u64, "sent_bytes", SENT_BYTES64);
-	PRINT_TSTAT_JSON(u32, "backlog_bytes", BACKLOG_BYTES);
-	PRINT_TSTAT_JSON(u32, "target_us", TARGET_US);
-	PRINT_TSTAT_JSON(u32, "interval_us", INTERVAL_US);
-	PRINT_TSTAT_JSON(u32, "peak_delay_us", PEAK_DELAY_US);
-	PRINT_TSTAT_JSON(u32, "avg_delay_us", AVG_DELAY_US);
-	PRINT_TSTAT_JSON(u32, "base_delay_us", BASE_DELAY_US);
-	PRINT_TSTAT_JSON(u32, "sent_packets", SENT_PACKETS);
-	PRINT_TSTAT_JSON(u32, "way_indirect_hits", WAY_INDIRECT_HITS);
-	PRINT_TSTAT_JSON(u32, "way_misses", WAY_MISSES);
-	PRINT_TSTAT_JSON(u32, "way_collisions", WAY_COLLISIONS);
-	PRINT_TSTAT_JSON(u32, "drops", DROPPED_PACKETS);
-	PRINT_TSTAT_JSON(u32, "ecn_mark", ECN_MARKED_PACKETS);
-	PRINT_TSTAT_JSON(u32, "ack_drops", ACKS_DROPPED_PACKETS);
-	PRINT_TSTAT_JSON(u32, "sparse_flows", SPARSE_FLOWS);
-	PRINT_TSTAT_JSON(u32, "bulk_flows", BULK_FLOWS);
-	PRINT_TSTAT_JSON(u32, "unresponsive_flows", UNRESPONSIVE_FLOWS);
-	PRINT_TSTAT_JSON(u32, "max_pkt_len", MAX_SKBLEN);
-	PRINT_TSTAT_JSON(u32, "flow_quantum", FLOW_QUANTUM);
-	close_json_object();
-
-#undef PRINT_TSTAT_JSON
-}
-
-static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
-			     struct rtattr *xstats)
-{
-	struct rtattr *st[TCA_CAKE_STATS_MAX + 1];
-	SPRINT_BUF(b1);
-	int i;
-
-	if (xstats == NULL)
-		return 0;
-
-#define GET_STAT_U32(attr) rta_getattr_u32(st[TCA_CAKE_STATS_ ## attr])
-#define GET_STAT_S32(attr) (*(__s32 *)RTA_DATA(st[TCA_CAKE_STATS_ ## attr]))
-#define GET_STAT_U64(attr) rta_getattr_u64(st[TCA_CAKE_STATS_ ## attr])
-
-	parse_rtattr_nested(st, TCA_CAKE_STATS_MAX, xstats);
-
-	if (st[TCA_CAKE_STATS_MEMORY_USED] &&
-	    st[TCA_CAKE_STATS_MEMORY_LIMIT]) {
-		print_string(PRINT_FP, NULL, " memory used: %s",
-			sprint_size(GET_STAT_U32(MEMORY_USED), b1));
-
-		print_string(PRINT_FP, NULL, " of %s\n",
-			sprint_size(GET_STAT_U32(MEMORY_LIMIT), b1));
-
-		print_uint(PRINT_JSON, "memory_used", NULL,
-			GET_STAT_U32(MEMORY_USED));
-		print_uint(PRINT_JSON, "memory_limit", NULL,
-			GET_STAT_U32(MEMORY_LIMIT));
-	}
-
-	if (st[TCA_CAKE_STATS_CAPACITY_ESTIMATE64]) {
-		print_string(PRINT_FP, NULL, " capacity estimate: %s\n",
-			sprint_rate(GET_STAT_U64(CAPACITY_ESTIMATE64), b1));
-		print_uint(PRINT_JSON, "capacity_estimate", NULL,
-			GET_STAT_U64(CAPACITY_ESTIMATE64));
-	}
-
-	if (st[TCA_CAKE_STATS_MIN_NETLEN] &&
-	    st[TCA_CAKE_STATS_MAX_NETLEN]) {
-		print_uint(PRINT_ANY, "min_network_size",
-			   " min/max network layer size: %12u",
-			   GET_STAT_U32(MIN_NETLEN));
-		print_uint(PRINT_ANY, "max_network_size",
-			   " /%8u\n", GET_STAT_U32(MAX_NETLEN));
-	}
-
-	if (st[TCA_CAKE_STATS_MIN_ADJLEN] &&
-	    st[TCA_CAKE_STATS_MAX_ADJLEN]) {
-		print_uint(PRINT_ANY, "min_adj_size",
-			   " min/max overhead-adjusted size: %8u",
-			   GET_STAT_U32(MIN_ADJLEN));
-		print_uint(PRINT_ANY, "max_adj_size",
-			   " /%8u\n", GET_STAT_U32(MAX_ADJLEN));
-	}
-
-	if (st[TCA_CAKE_STATS_AVG_NETOFF])
-		print_uint(PRINT_ANY, "avg_hdr_offset",
-			   " average network hdr offset: %12u\n\n",
-			   GET_STAT_U32(AVG_NETOFF));
-
-	/* class stats */
-	if (st[TCA_CAKE_STATS_DEFICIT])
-		print_int(PRINT_ANY, "deficit", "  deficit %u",
-			  GET_STAT_S32(DEFICIT));
-	if (st[TCA_CAKE_STATS_COBALT_COUNT])
-		print_uint(PRINT_ANY, "count", " count %u",
-			   GET_STAT_U32(COBALT_COUNT));
-
-	if (st[TCA_CAKE_STATS_DROPPING] && GET_STAT_U32(DROPPING)) {
-		print_bool(PRINT_ANY, "dropping", " dropping", true);
-		if (st[TCA_CAKE_STATS_DROP_NEXT_US]) {
-			int drop_next = GET_STAT_S32(DROP_NEXT_US);
-
-			if (drop_next < 0) {
-				print_string(PRINT_FP, NULL, " drop_next -%s",
-					sprint_time(drop_next, b1));
-			} else {
-				print_uint(PRINT_JSON, "drop_next", NULL,
-					drop_next);
-				print_string(PRINT_FP, NULL, " drop_next %s",
-					sprint_time(drop_next, b1));
-			}
-		}
-	}
-
-	if (st[TCA_CAKE_STATS_P_DROP]) {
-		print_uint(PRINT_ANY, "blue_prob", " blue_prob %u",
-			   GET_STAT_U32(P_DROP));
-		if (st[TCA_CAKE_STATS_BLUE_TIMER_US]) {
-			int blue_timer = GET_STAT_S32(BLUE_TIMER_US);
-
-			if (blue_timer < 0) {
-				print_string(PRINT_FP, NULL, " blue_timer -%s",
-					sprint_time(blue_timer, b1));
-			} else {
-				print_uint(PRINT_JSON, "blue_timer", NULL,
-					blue_timer);
-				print_string(PRINT_FP, NULL, " blue_timer %s",
-					sprint_time(blue_timer, b1));
-			}
-		}
-	}
-
-#undef GET_STAT_U32
-#undef GET_STAT_S32
-#undef GET_STAT_U64
-
-	if (st[TCA_CAKE_STATS_TIN_STATS]) {
-		struct rtattr *tstat[TC_CAKE_MAX_TINS][TCA_CAKE_TIN_STATS_MAX + 1];
-		struct rtattr *tins[TC_CAKE_MAX_TINS + 1];
-		int num_tins = 0;
-
-		parse_rtattr_nested(tins, TC_CAKE_MAX_TINS,
-				    st[TCA_CAKE_STATS_TIN_STATS]);
-
-		for (i = 1; i <= TC_CAKE_MAX_TINS && tins[i]; i++) {
-			parse_rtattr_nested(tstat[i-1], TCA_CAKE_TIN_STATS_MAX,
-					    tins[i]);
-			num_tins++;
-		}
-
-		if (!num_tins)
-			return 0;
-
-		if (is_json_context()) {
-			open_json_array(PRINT_JSON, "tins");
-			for (i = 0; i < num_tins; i++)
-				cake_print_json_tin(tstat[i]);
-			close_json_array(PRINT_JSON, NULL);
-
-			return 0;
-		}
-
-
-		switch (num_tins) {
-		case 3:
-			fprintf(f, "                   Bulk  Best Effort        Voice\n");
-			break;
-
-		case 4:
-			fprintf(f, "                   Bulk  Best Effort        Video        Voice\n");
-			break;
-
-		default:
-			fprintf(f, "          ");
-			for (i = 0; i < num_tins; i++)
-				fprintf(f, "        Tin %u", i);
-			fprintf(f, "\n");
-		};
-
-#define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
-#define PRINT_TSTAT(name, attr, fmts, val)	do {		\
-			if (GET_TSTAT(0, attr)) {		\
-				fprintf(f, name);		\
-				for (i = 0; i < num_tins; i++)	\
-					fprintf(f, " %12" fmts,	val);	\
-				fprintf(f, "\n");			\
-			}						\
-		} while (0)
-
-#define SPRINT_TSTAT(pfunc, type, name, attr) PRINT_TSTAT(		\
-			name, attr, "s", sprint_ ## pfunc(		\
-				rta_getattr_ ## type(GET_TSTAT(i, attr)), b1))
-
-#define PRINT_TSTAT_U32(name, attr)	PRINT_TSTAT(			\
-			name, attr, "u", rta_getattr_u32(GET_TSTAT(i, attr)))
-
-#define PRINT_TSTAT_U64(name, attr)	PRINT_TSTAT(			\
-			name, attr, "llu", rta_getattr_u64(GET_TSTAT(i, attr)))
-
-		SPRINT_TSTAT(rate, u64, "  thresh  ", THRESHOLD_RATE64);
-		SPRINT_TSTAT(time, u32, "  target  ", TARGET_US);
-		SPRINT_TSTAT(time, u32, "  interval", INTERVAL_US);
-		SPRINT_TSTAT(time, u32, "  pk_delay", PEAK_DELAY_US);
-		SPRINT_TSTAT(time, u32, "  av_delay", AVG_DELAY_US);
-		SPRINT_TSTAT(time, u32, "  sp_delay", BASE_DELAY_US);
-		SPRINT_TSTAT(size, u32, "  backlog ", BACKLOG_BYTES);
-
-		PRINT_TSTAT_U32("  pkts    ", SENT_PACKETS);
-		PRINT_TSTAT_U64("  bytes   ", SENT_BYTES64);
-
-		PRINT_TSTAT_U32("  way_inds", WAY_INDIRECT_HITS);
-		PRINT_TSTAT_U32("  way_miss", WAY_MISSES);
-		PRINT_TSTAT_U32("  way_cols", WAY_COLLISIONS);
-		PRINT_TSTAT_U32("  drops   ", DROPPED_PACKETS);
-		PRINT_TSTAT_U32("  marks   ", ECN_MARKED_PACKETS);
-		PRINT_TSTAT_U32("  ack_drop", ACKS_DROPPED_PACKETS);
-		PRINT_TSTAT_U32("  sp_flows", SPARSE_FLOWS);
-		PRINT_TSTAT_U32("  bk_flows", BULK_FLOWS);
-		PRINT_TSTAT_U32("  un_flows", UNRESPONSIVE_FLOWS);
-		PRINT_TSTAT_U32("  max_len ", MAX_SKBLEN);
-		PRINT_TSTAT_U32("  quantum ", FLOW_QUANTUM);
-
-#undef GET_STAT
-#undef PRINT_TSTAT
-#undef SPRINT_TSTAT
-#undef PRINT_TSTAT_U32
-#undef PRINT_TSTAT_U64
-	}
-	return 0;
-}
-
-struct qdisc_util cake_qdisc_util = {
-	.id		= "cake",
-	.parse_qopt	= cake_parse_opt,
-	.print_qopt	= cake_print_opt,
-	.print_xstats	= cake_print_xstats,
-};
diff --git a/tc/q_cbq.c b/tc/q_cbq.c
index 6518ef4..38a6163 100644
--- a/tc/q_cbq.c
+++ b/tc/q_cbq.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -25,21 +26,19 @@
 
 static void explain_class(void)
 {
-	fprintf(stderr,
-		"Usage: ... cbq	bandwidth BPS rate BPS maxburst PKTS [ avpkt BYTES ]\n"
-		"		[ minburst PKTS ] [ bounded ] [ isolated ]\n"
-		"		[ allot BYTES ] [ mpu BYTES ] [ weight RATE ]\n"
-		"		[ prio NUMBER ] [ cell BYTES ] [ ewma LOG ]\n"
-		"		[ estimator INTERVAL TIME_CONSTANT ]\n"
-		"		[ split CLASSID ] [ defmap MASK/CHANGE ]\n"
-		"		[ overhead BYTES ] [ linklayer TYPE ]\n");
+	fprintf(stderr, "Usage: ... cbq bandwidth BPS rate BPS maxburst PKTS [ avpkt BYTES ]\n");
+	fprintf(stderr, "               [ minburst PKTS ] [ bounded ] [ isolated ]\n");
+	fprintf(stderr, "               [ allot BYTES ] [ mpu BYTES ] [ weight RATE ]\n");
+	fprintf(stderr, "               [ prio NUMBER ] [ cell BYTES ] [ ewma LOG ]\n");
+	fprintf(stderr, "               [ estimator INTERVAL TIME_CONSTANT ]\n");
+	fprintf(stderr, "               [ split CLASSID ] [ defmap MASK/CHANGE ]\n");
+	fprintf(stderr, "               [ overhead BYTES ] [ linklayer TYPE ]\n");
 }
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... cbq bandwidth BPS avpkt BYTES [ mpu BYTES ]\n"
-		"               [ cell BYTES ] [ ewma LOG ]\n");
+	fprintf(stderr, "Usage: ... cbq bandwidth BPS avpkt BYTES [ mpu BYTES ]\n");
+	fprintf(stderr, "               [ cell BYTES ] [ ewma LOG ]\n");
 }
 
 static void explain1(char *arg)
@@ -48,28 +47,26 @@
 }
 
 
-static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
+static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	struct tc_ratespec r = {};
-	struct tc_cbq_lssopt lss = {};
+	struct tc_ratespec r;
+	struct tc_cbq_lssopt lss;
 	__u32 rtab[256];
-	unsigned mpu = 0, avpkt = 0, allot = 0;
-	unsigned short overhead = 0;
+	unsigned mpu=0, avpkt=0, allot=0;
+	unsigned short overhead=0;
 	unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
-	int cell_log =  -1;
-	int ewma_log =  -1;
+	int cell_log=-1;
+	int ewma_log=-1;
 	struct rtattr *tail;
 
+	memset(&lss, 0, sizeof(lss));
+	memset(&r, 0, sizeof(r));
+
 	while (argc > 0) {
 		if (matches(*argv, "bandwidth") == 0 ||
 		    matches(*argv, "rate") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&r.rate, *argv, dev)) {
-					explain1("bandwidth");
-					return -1;
-				}
-			} else if (get_rate(&r.rate, *argv)) {
+			if (get_rate(&r.rate, *argv)) {
 				explain1("bandwidth");
 				return -1;
 			}
@@ -84,18 +81,17 @@
 				return -1;
 			}
 		} else if (matches(*argv, "cell") == 0) {
-			unsigned int cell;
+			unsigned cell;
 			int i;
-
 			NEXT_ARG();
 			if (get_size(&cell, *argv)) {
 				explain1("cell");
 				return -1;
 			}
-			for (i = 0; i < 32; i++)
+			for (i=0; i<32; i++)
 				if ((1<<i) == cell)
 					break;
-			if (i >= 32) {
+			if (i>=32) {
 				fprintf(stderr, "cell must be 2^n\n");
 				return -1;
 			}
@@ -167,58 +163,55 @@
 	lss.change = TCF_CBQ_LSS_MAXIDLE|TCF_CBQ_LSS_EWMA|TCF_CBQ_LSS_AVPKT;
 	lss.avpkt = avpkt;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_CBQ_RATE, &r, sizeof(r));
 	addattr_l(n, 1024, TCA_CBQ_LSSOPT, &lss, sizeof(lss));
 	addattr_l(n, 3024, TCA_CBQ_RTAB, rtab, 1024);
 	if (show_raw) {
 		int i;
-
-		for (i = 0; i < 256; i++)
+		for (i=0; i<256; i++)
 			printf("%u ", rtab[i]);
 		printf("\n");
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
-static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
+static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	int wrr_ok = 0, fopt_ok = 0;
-	struct tc_ratespec r = {};
-	struct tc_cbq_lssopt lss = {};
-	struct tc_cbq_wrropt wrr = {};
-	struct tc_cbq_fopt fopt = {};
+	int wrr_ok=0, fopt_ok=0;
+	struct tc_ratespec r;
+	struct tc_cbq_lssopt lss;
+	struct tc_cbq_wrropt wrr;
+	struct tc_cbq_fopt fopt;
+	struct tc_cbq_ovl ovl;
 	__u32 rtab[256];
-	unsigned mpu = 0;
-	int cell_log =  -1;
-	int ewma_log =  -1;
-	unsigned int bndw = 0;
-	unsigned minburst = 0, maxburst = 0;
-	unsigned short overhead = 0;
+	unsigned mpu=0;
+	int cell_log=-1;
+	int ewma_log=-1;
+	unsigned bndw = 0;
+	unsigned minburst=0, maxburst=0;
+	unsigned short overhead=0;
 	unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
 	struct rtattr *tail;
 
+	memset(&r, 0, sizeof(r));
+	memset(&lss, 0, sizeof(lss));
+	memset(&wrr, 0, sizeof(wrr));
+	memset(&fopt, 0, sizeof(fopt));
+	memset(&ovl, 0, sizeof(ovl));
+
 	while (argc > 0) {
 		if (matches(*argv, "rate") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&r.rate, *argv, dev)) {
-					explain1("rate");
-					return -1;
-				}
-			} else if (get_rate(&r.rate, *argv)) {
+			if (get_rate(&r.rate, *argv)) {
 				explain1("rate");
 				return -1;
 			}
 		} else if (matches(*argv, "bandwidth") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&bndw, *argv, dev)) {
-					explain1("bandwidth");
-					return -1;
-				}
-			} else if (get_rate(&bndw, *argv)) {
+			if (get_rate(&bndw, *argv)) {
 				explain1("bandwidth");
 				return -1;
 			}
@@ -267,25 +260,23 @@
 			}
 			lss.change |= TCF_CBQ_LSS_EWMA;
 		} else if (matches(*argv, "cell") == 0) {
-			unsigned int cell;
+			unsigned cell;
 			int i;
-
 			NEXT_ARG();
 			if (get_size(&cell, *argv)) {
 				explain1("cell");
 				return -1;
 			}
-			for (i = 0; i < 32; i++)
+			for (i=0; i<32; i++)
 				if ((1<<i) == cell)
 					break;
-			if (i >= 32) {
+			if (i>=32) {
 				fprintf(stderr, "cell must be 2^n\n");
 				return -1;
 			}
 			cell_log = i;
 		} else if (matches(*argv, "prio") == 0) {
-			unsigned int prio;
-
+			unsigned prio;
 			NEXT_ARG();
 			if (get_u32(&prio, *argv, 0)) {
 				explain1("prio");
@@ -332,7 +323,6 @@
 			fopt_ok++;
 		} else if (matches(*argv, "defmap") == 0) {
 			int err;
-
 			NEXT_ARG();
 			err = sscanf(*argv, "%08x/%08x", &fopt.defmap, &fopt.defchange);
 			if (err < 1) {
@@ -367,8 +357,7 @@
 
 	/* 1. Prepare link sharing scheduler parameters */
 	if (r.rate) {
-		unsigned int pktsize = wrr.allot;
-
+		unsigned pktsize = wrr.allot;
 		if (wrr.allot < (lss.avpkt*3)/2)
 			wrr.allot = (lss.avpkt*3)/2;
 		r.mpu = mpu;
@@ -386,7 +375,7 @@
 			fprintf(stderr, "CBQ: avpkt is required for max/minburst.\n");
 			return -1;
 		}
-		if (bndw == 0 || r.rate == 0) {
+		if (bndw==0 || r.rate == 0) {
 			fprintf(stderr, "CBQ: bandwidth&rate are required for max/minburst.\n");
 			return -1;
 		}
@@ -420,7 +409,8 @@
 		lss.change |= TCF_CBQ_LSS_EWMA;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (lss.change) {
 		lss.change |= TCF_CBQ_LSS_FLAGS;
 		addattr_l(n, 1024, TCA_CBQ_LSSOPT, &lss, sizeof(lss));
@@ -434,13 +424,12 @@
 		addattr_l(n, 3024, TCA_CBQ_RTAB, rtab, 1024);
 		if (show_raw) {
 			int i;
-
-			for (i = 0; i < 256; i++)
+			for (i=0; i<256; i++)
 				printf("%u ", rtab[i]);
 			printf("\n");
 		}
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -454,7 +443,6 @@
 	struct tc_cbq_fopt *fopt = NULL;
 	struct tc_cbq_ovl *ovl = NULL;
 	unsigned int linklayer;
-
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
 
@@ -490,15 +478,14 @@
 	if (tb[TCA_CBQ_OVL_STRATEGY]) {
 		if (RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(*ovl))
 			fprintf(stderr, "CBQ: too short overlimit strategy %u/%u\n",
-				(unsigned int) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
-				(unsigned int) sizeof(*ovl));
+				(unsigned) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
+				(unsigned) sizeof(*ovl));
 		else
 			ovl = RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY]);
 	}
 
 	if (r) {
 		char buf[64];
-
 		print_rate(buf, sizeof(buf), r->rate);
 		fprintf(f, "rate %s ", buf);
 		linklayer = (r->linklayer & TC_LINKLAYER_MASK);
@@ -513,12 +500,11 @@
 		}
 	}
 	if (lss && lss->flags) {
-		int comma = 0;
-
+		int comma=0;
 		fprintf(f, "(");
 		if (lss->flags&TCF_CBQ_LSS_BOUNDED) {
 			fprintf(f, "bounded");
-			comma = 1;
+			comma=1;
 		}
 		if (lss->flags&TCF_CBQ_LSS_ISOLATED) {
 			if (comma)
@@ -534,7 +520,6 @@
 			fprintf(f, "prio no-transmit");
 		if (show_details) {
 			char buf[64];
-
 			fprintf(f, "/%u ", wrr->cpriority);
 			if (wrr->weight != 1) {
 				print_rate(buf, sizeof(buf), wrr->weight);
@@ -551,7 +536,7 @@
 			if (show_raw)
 				fprintf(f, "[%08x] ", lss->maxidle);
 		}
-		if (lss->minidle != 0x7fffffff) {
+		if (lss->minidle!=0x7fffffff) {
 			fprintf(f, "minidle %s ", sprint_ticks(lss->minidle>>lss->ewma_log, b1));
 			if (show_raw)
 				fprintf(f, "[%08x] ", lss->minidle);
@@ -564,7 +549,6 @@
 	}
 	if (fopt && show_details) {
 		char buf[64];
-
 		print_tc_classid(buf, sizeof(buf), fopt->split);
 		fprintf(f, "\nsplit %s ", buf);
 		if (fopt->defmap) {
diff --git a/tc/q_cbs.c b/tc/q_cbs.c
deleted file mode 100644
index 9515a1f..0000000
--- a/tc/q_cbs.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * q_cbs.c		CBS.
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Vinicius Costa Gomes <vinicius.gomes@intel.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: ... cbs hicredit BYTES locredit BYTES sendslope BPS idleslope BPS\n"
-		"	   [offload 0|1]\n");
-}
-
-static void explain1(const char *arg, const char *val)
-{
-	fprintf(stderr, "cbs: illegal value for \"%s\": \"%s\"\n", arg, val);
-}
-
-static int cbs_parse_opt(struct qdisc_util *qu, int argc,
-			 char **argv, struct nlmsghdr *n, const char *dev)
-{
-	struct tc_cbs_qopt opt = {};
-	struct rtattr *tail;
-
-	while (argc > 0) {
-		if (matches(*argv, "offload") == 0) {
-			NEXT_ARG();
-			if (opt.offload) {
-				fprintf(stderr, "cbs: duplicate \"offload\" specification\n");
-				return -1;
-			}
-			if (get_u8(&opt.offload, *argv, 0)) {
-				explain1("offload", *argv);
-				return -1;
-			}
-		} else if (matches(*argv, "hicredit") == 0) {
-			NEXT_ARG();
-			if (opt.hicredit) {
-				fprintf(stderr, "cbs: duplicate \"hicredit\" specification\n");
-				return -1;
-			}
-			if (get_s32(&opt.hicredit, *argv, 0)) {
-				explain1("hicredit", *argv);
-				return -1;
-			}
-		} else if (matches(*argv, "locredit") == 0) {
-			NEXT_ARG();
-			if (opt.locredit) {
-				fprintf(stderr, "cbs: duplicate \"locredit\" specification\n");
-				return -1;
-			}
-			if (get_s32(&opt.locredit, *argv, 0)) {
-				explain1("locredit", *argv);
-				return -1;
-			}
-		} else if (matches(*argv, "sendslope") == 0) {
-			NEXT_ARG();
-			if (opt.sendslope) {
-				fprintf(stderr, "cbs: duplicate \"sendslope\" specification\n");
-				return -1;
-			}
-			if (get_s32(&opt.sendslope, *argv, 0)) {
-				explain1("sendslope", *argv);
-				return -1;
-			}
-		} else if (matches(*argv, "idleslope") == 0) {
-			NEXT_ARG();
-			if (opt.idleslope) {
-				fprintf(stderr, "cbs: duplicate \"idleslope\" specification\n");
-				return -1;
-			}
-			if (get_s32(&opt.idleslope, *argv, 0)) {
-				explain1("idleslope", *argv);
-				return -1;
-			}
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "cbs: unknown parameter \"%s\"\n", *argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
-	addattr_l(n, 2024, TCA_CBS_PARMS, &opt, sizeof(opt));
-	addattr_nest_end(n, tail);
-	return 0;
-}
-
-static int cbs_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_CBS_MAX+1];
-	struct tc_cbs_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_CBS_MAX, opt);
-
-	if (tb[TCA_CBS_PARMS] == NULL)
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_CBS_PARMS]);
-	if (RTA_PAYLOAD(tb[TCA_CBS_PARMS])  < sizeof(*qopt))
-		return -1;
-
-	fprintf(f, "hicredit %d ", qopt->hicredit);
-	fprintf(f, "locredit %d ", qopt->locredit);
-	fprintf(f, "sendslope %d ", qopt->sendslope);
-	fprintf(f, "idleslope %d ", qopt->idleslope);
-	fprintf(f, "offload %d ", qopt->offload);
-
-	return 0;
-}
-
-struct qdisc_util cbs_qdisc_util = {
-	.id		= "cbs",
-	.parse_qopt	= cbs_parse_opt,
-	.print_qopt	= cbs_print_opt,
-};
diff --git a/tc/q_choke.c b/tc/q_choke.c
index 648d9ad..bd9ceb8 100644
--- a/tc/q_choke.c
+++ b/tc/q_choke.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -26,25 +27,26 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... choke limit PACKETS bandwidth KBPS [ecn]\n"
-		"		 [ min PACKETS ] [ max PACKETS ] [ burst PACKETS ]\n");
+	fprintf(stderr, "Usage: ... choke limit PACKETS bandwidth KBPS [ecn]\n");
+	fprintf(stderr, "                 [ min PACKETS ] [ max PACKETS ] [ burst PACKETS ]\n");
 }
 
 static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			   struct nlmsghdr *n, const char *dev)
+			   struct nlmsghdr *n)
 {
-	struct tc_red_qopt opt = {};
-	unsigned int burst = 0;
-	unsigned int avpkt = 1000;
+	struct tc_red_qopt opt;
+	unsigned burst = 0;
+	unsigned avpkt = 1000;
 	double probability = 0.02;
-	unsigned int rate = 0;
+	unsigned rate = 0;
 	int ecn_ok = 0;
 	int wlog;
 	__u8 sbuf[256];
 	__u32 max_P;
 	struct rtattr *tail;
 
+	memset(&opt, 0, sizeof(opt));
+
 	while (argc > 0) {
 		if (strcmp(*argv, "limit") == 0) {
 			NEXT_ARG();
@@ -54,12 +56,7 @@
 			}
 		} else if (strcmp(*argv, "bandwidth") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&rate, *argv, dev)) {
-					fprintf(stderr, "Illegal \"bandwidth\"\n");
-					return -1;
-				}
-			} else if (get_rate(&rate, *argv)) {
+			if (get_rate(&rate, *argv)) {
 				fprintf(stderr, "Illegal \"bandwidth\"\n");
 				return -1;
 			}
@@ -157,12 +154,13 @@
 	if (ecn_ok)
 		opt.flags |= TC_RED_ECN;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_CHOKE_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 1024, TCA_CHOKE_STAB, sbuf, 256);
 	max_P = probability * pow(2, 32);
 	addattr_l(n, 1024, TCA_CHOKE_MAX_P, &max_P, sizeof(max_P));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -189,7 +187,8 @@
 	fprintf(f, "limit %up min %up max %up ",
 		qopt->limit, qopt->qth_min, qopt->qth_max);
 
-	tc_red_print_flags(qopt->flags);
+	if (qopt->flags & TC_RED_ECN)
+		fprintf(f, "ecn ");
 
 	if (show_details) {
 		fprintf(f, "ewma %u ", qopt->Wlog);
diff --git a/tc/q_clsact.c b/tc/q_clsact.c
index 341f653..0c05dbd 100644
--- a/tc/q_clsact.c
+++ b/tc/q_clsact.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #include <stdio.h>
 #include <string.h>
 
@@ -11,7 +10,7 @@
 }
 
 static int clsact_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			    struct nlmsghdr *n, const char *dev)
+			    struct nlmsghdr *n)
 {
 	if (argc > 0) {
 		fprintf(stderr, "What is \"%s\"?\n", *argv);
@@ -19,6 +18,7 @@
 		return -1;
 	}
 
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	return 0;
 }
 
diff --git a/tc/q_codel.c b/tc/q_codel.c
index 849cc04..c24246c 100644
--- a/tc/q_codel.c
+++ b/tc/q_codel.c
@@ -41,6 +41,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -52,19 +53,18 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... codel [ limit PACKETS ] [ target TIME ]\n"
-		"		 [ interval TIME ] [ ecn | noecn ]\n"
-		"		 [ ce_threshold TIME ]\n");
+	fprintf(stderr, "Usage: ... codel [ limit PACKETS ] [ target TIME]\n");
+	fprintf(stderr, "                 [ interval TIME ] [ ecn | noecn ]\n");
+	fprintf(stderr, "                 [ ce_threshold TIME ]\n");
 }
 
 static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			   struct nlmsghdr *n, const char *dev)
+			   struct nlmsghdr *n)
 {
-	unsigned int limit = 0;
-	unsigned int target = 0;
-	unsigned int interval = 0;
-	unsigned int ce_threshold = ~0U;
+	unsigned limit = 0;
+	unsigned target = 0;
+	unsigned interval = 0;
+	unsigned ce_threshold = ~0U;
 	int ecn = -1;
 	struct rtattr *tail;
 
@@ -108,7 +108,8 @@
 		argc--; argv++;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (limit)
 		addattr_l(n, 1024, TCA_CODEL_LIMIT, &limit, sizeof(limit));
 	if (interval)
@@ -121,19 +122,18 @@
 		addattr_l(n, 1024, TCA_CODEL_CE_THRESHOLD,
 			  &ce_threshold, sizeof(ce_threshold));
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
 static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 {
 	struct rtattr *tb[TCA_CODEL_MAX + 1];
-	unsigned int limit;
-	unsigned int interval;
-	unsigned int target;
-	unsigned int ecn;
-	unsigned int ce_threshold;
-
+	unsigned limit;
+	unsigned interval;
+	unsigned target;
+	unsigned ecn;
+	unsigned ce_threshold;
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
@@ -174,8 +174,7 @@
 static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
 			      struct rtattr *xstats)
 {
-	struct tc_codel_xstats _st = {}, *st;
-
+	struct tc_codel_xstats _st, *st;
 	SPRINT_BUF(b1);
 
 	if (xstats == NULL)
@@ -183,6 +182,7 @@
 
 	st = RTA_DATA(xstats);
 	if (RTA_PAYLOAD(xstats) < sizeof(*st)) {
+		memset(&_st, 0, sizeof(_st));
 		memcpy(&_st, st, RTA_PAYLOAD(xstats));
 		st = &_st;
 	}
diff --git a/tc/q_drr.c b/tc/q_drr.c
index f9c90f3..746736d 100644
--- a/tc/q_drr.c
+++ b/tc/q_drr.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -33,8 +34,7 @@
 }
 
 
-static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	while (argc) {
 		if (strcmp(*argv, "help") == 0) {
@@ -50,12 +50,13 @@
 }
 
 static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
-			       struct nlmsghdr *n, const char *dev)
+			       struct nlmsghdr *n)
 {
 	struct rtattr *tail;
 	__u32 tmp;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (strcmp(*argv, "quantum") == 0) {
@@ -76,14 +77,13 @@
 		argc--; argv++;
 	}
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail;
 	return 0;
 }
 
 static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 {
 	struct rtattr *tb[TCA_DRR_MAX + 1];
-
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
@@ -100,7 +100,6 @@
 static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
 {
 	struct tc_drr_stats *x;
-
 	SPRINT_BUF(b1);
 
 	if (xstats == NULL)
diff --git a/tc/q_dsmark.c b/tc/q_dsmark.c
index d3e8292..05185c0 100644
--- a/tc/q_dsmark.c
+++ b/tc/q_dsmark.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * q_dsmark.c		Differentiated Services field marking.
  *
@@ -9,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -21,39 +21,43 @@
 
 static void explain(void)
 {
-	fprintf(stderr,"Usage: dsmark indices INDICES [ default_index DEFAULT_INDEX ] [ set_tc_index ]\n");
+	fprintf(stderr,"Usage: dsmark indices INDICES [ default_index "
+	    "DEFAULT_INDEX ] [ set_tc_index ]\n");
 }
 
 
 static int dsmark_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-	struct nlmsghdr *n, const char *dev)
+    struct nlmsghdr *n)
 {
 	struct rtattr *tail;
 	__u16 ind;
 	char *end;
-	int dflt, set_tc_index;
+	int dflt,set_tc_index;
 
 	ind = set_tc_index = 0;
 	dflt = -1;
 	while (argc > 0) {
-		if (!strcmp(*argv, "indices")) {
+		if (!strcmp(*argv,"indices")) {
 			NEXT_ARG();
-			ind = strtoul(*argv, &end, 0);
+			ind = strtoul(*argv,&end,0);
 			if (*end) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"default_index") || !strcmp(*argv,
+		}
+		else if (!strcmp(*argv,"default_index") || !strcmp(*argv,
 		    "default")) {
 			NEXT_ARG();
-			dflt = strtoul(*argv, &end, 0);
+			dflt = strtoul(*argv,&end,0);
 			if (*end) {
 				explain();
 				return -1;
 			}
-		} else if (!strcmp(*argv,"set_tc_index")) {
+		}
+		else if (!strcmp(*argv,"set_tc_index")) {
 			set_tc_index = 1;
-		} else {
+		}
+		else {
 			explain();
 			return -1;
 		}
@@ -64,16 +68,16 @@
 		explain();
 		return -1;
 	}
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
-	addattr_l(n, 1024, TCA_DSMARK_INDICES, &ind, sizeof(ind));
+	tail = NLMSG_TAIL(n);
+	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
+	addattr_l(n,1024,TCA_DSMARK_INDICES,&ind,sizeof(ind));
 	if (dflt != -1) {
 	    __u16 tmp = dflt;
 
-	    addattr_l(n, 1024, TCA_DSMARK_DEFAULT_INDEX, &tmp, sizeof(tmp));
+	    addattr_l(n,1024,TCA_DSMARK_DEFAULT_INDEX,&tmp,sizeof(tmp));
 	}
-	if (set_tc_index)
-		addattr_l(n, 1024, TCA_DSMARK_SET_TC_INDEX, NULL, 0);
-	addattr_nest_end(n, tail);
+	if (set_tc_index) addattr_l(n,1024,TCA_DSMARK_SET_TC_INDEX,NULL,0);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -85,38 +89,41 @@
 
 
 static int dsmark_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
-	struct nlmsghdr *n, const char *dev)
+   struct nlmsghdr *n)
 {
 	struct rtattr *tail;
 	__u8 tmp;
 	char *end;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
 	while (argc > 0) {
-		if (!strcmp(*argv, "mask")) {
+		if (!strcmp(*argv,"mask")) {
 			NEXT_ARG();
-			tmp = strtoul(*argv, &end, 0);
+			tmp = strtoul(*argv,&end,0);
 			if (*end) {
 				explain_class();
 				return -1;
 			}
-			addattr_l(n, 1024, TCA_DSMARK_MASK, &tmp, 1);
-		} else if (!strcmp(*argv,"value")) {
+			addattr_l(n,1024,TCA_DSMARK_MASK,&tmp,1);
+		}
+		else if (!strcmp(*argv,"value")) {
 			NEXT_ARG();
-			tmp = strtoul(*argv, &end, 0);
+			tmp = strtoul(*argv,&end,0);
 			if (*end) {
 				explain_class();
 				return -1;
 			}
-			addattr_l(n, 1024, TCA_DSMARK_VALUE, &tmp, 1);
-		} else {
+			addattr_l(n,1024,TCA_DSMARK_VALUE,&tmp,1);
+		}
+		else {
 			explain_class();
 			return -1;
 		}
 		argc--;
 		argv++;
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -127,32 +134,33 @@
 	struct rtattr *tb[TCA_DSMARK_MAX+1];
 
 	if (!opt) return 0;
+	memset(tb, 0, sizeof(tb));
 	parse_rtattr(tb, TCA_DSMARK_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt));
 	if (tb[TCA_DSMARK_MASK]) {
 		if (!RTA_PAYLOAD(tb[TCA_DSMARK_MASK]))
-			fprintf(stderr, "dsmark: empty mask\n");
-		else fprintf(f, "mask 0x%02x ",
+			fprintf(stderr,"dsmark: empty mask\n");
+		else fprintf(f,"mask 0x%02x ",
 			    rta_getattr_u8(tb[TCA_DSMARK_MASK]));
 	}
 	if (tb[TCA_DSMARK_VALUE]) {
 		if (!RTA_PAYLOAD(tb[TCA_DSMARK_VALUE]))
-			fprintf(stderr, "dsmark: empty value\n");
-		else fprintf(f, "value 0x%02x ",
+			fprintf(stderr,"dsmark: empty value\n");
+		else fprintf(f,"value 0x%02x ",
 			    rta_getattr_u8(tb[TCA_DSMARK_VALUE]));
 	}
 	if (tb[TCA_DSMARK_INDICES]) {
 		if (RTA_PAYLOAD(tb[TCA_DSMARK_INDICES]) < sizeof(__u16))
-			fprintf(stderr, "dsmark: indices too short\n");
-		else fprintf(f, "indices 0x%04x ",
+			fprintf(stderr,"dsmark: indices too short\n");
+		else fprintf(f,"indices 0x%04x ",
 			    rta_getattr_u16(tb[TCA_DSMARK_INDICES]));
 	}
 	if (tb[TCA_DSMARK_DEFAULT_INDEX]) {
 		if (RTA_PAYLOAD(tb[TCA_DSMARK_DEFAULT_INDEX]) < sizeof(__u16))
-			fprintf(stderr, "dsmark: default_index too short\n");
-		else fprintf(f, "default_index 0x%04x ",
+			fprintf(stderr,"dsmark: default_index too short\n");
+		else fprintf(f,"default_index 0x%04x ",
 			    rta_getattr_u16(tb[TCA_DSMARK_DEFAULT_INDEX]));
 	}
-	if (tb[TCA_DSMARK_SET_TC_INDEX]) fprintf(f, "set_tc_index ");
+	if (tb[TCA_DSMARK_SET_TC_INDEX]) fprintf(f,"set_tc_index ");
 	return 0;
 }
 
diff --git a/tc/q_etf.c b/tc/q_etf.c
deleted file mode 100644
index c209058..0000000
--- a/tc/q_etf.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * q_etf.c		Earliest TxTime First (ETF).
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Vinicius Costa Gomes <vinicius.gomes@intel.com>
- *		Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-#define CLOCKID_INVALID (-1)
-static const struct static_clockid {
-	const char *name;
-	clockid_t clockid;
-} clockids_sysv[] = {
-	{ "REALTIME", CLOCK_REALTIME },
-	{ "TAI", CLOCK_TAI },
-	{ "BOOTTIME", CLOCK_BOOTTIME },
-	{ "MONOTONIC", CLOCK_MONOTONIC },
-	{ NULL }
-};
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: ... etf delta NANOS clockid CLOCKID [offload] [deadline_mode]\n"
-		"CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
-}
-
-static void explain1(const char *arg, const char *val)
-{
-	fprintf(stderr, "etf: illegal value for \"%s\": \"%s\"\n", arg, val);
-}
-
-static void explain_clockid(const char *val)
-{
-	fprintf(stderr,
-		"etf: illegal value for \"clockid\": \"%s\".\n"
-		"It must be a valid SYS-V id (i.e. CLOCK_TAI)\n",
-		val);
-}
-
-static int get_clockid(__s32 *val, const char *arg)
-{
-	const struct static_clockid *c;
-
-	/* Drop the CLOCK_ prefix if that is being used. */
-	if (strcasestr(arg, "CLOCK_") != NULL)
-		arg += sizeof("CLOCK_") - 1;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (strcasecmp(c->name, arg) == 0) {
-			*val = c->clockid;
-
-			return 0;
-		}
-	}
-
-	return -1;
-}
-
-static const char* get_clock_name(clockid_t clockid)
-{
-	const struct static_clockid *c;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (clockid == c->clockid)
-			return c->name;
-	}
-
-	return "invalid";
-}
-
-static int etf_parse_opt(struct qdisc_util *qu, int argc,
-			 char **argv, struct nlmsghdr *n, const char *dev)
-{
-	struct tc_etf_qopt opt = {
-		.clockid = CLOCKID_INVALID,
-	};
-	struct rtattr *tail;
-
-	while (argc > 0) {
-		if (matches(*argv, "offload") == 0) {
-			if (opt.flags & TC_ETF_OFFLOAD_ON) {
-				fprintf(stderr, "etf: duplicate \"offload\" specification\n");
-				return -1;
-			}
-
-			opt.flags |= TC_ETF_OFFLOAD_ON;
-		} else if (matches(*argv, "deadline_mode") == 0) {
-			if (opt.flags & TC_ETF_DEADLINE_MODE_ON) {
-				fprintf(stderr, "etf: duplicate \"deadline_mode\" specification\n");
-				return -1;
-			}
-
-			opt.flags |= TC_ETF_DEADLINE_MODE_ON;
-		} else if (matches(*argv, "delta") == 0) {
-			NEXT_ARG();
-			if (opt.delta) {
-				fprintf(stderr, "etf: duplicate \"delta\" specification\n");
-				return -1;
-			}
-			if (get_s32(&opt.delta, *argv, 0)) {
-				explain1("delta", *argv);
-				return -1;
-			}
-		} else if (matches(*argv, "clockid") == 0) {
-			NEXT_ARG();
-			if (opt.clockid != CLOCKID_INVALID) {
-				fprintf(stderr, "etf: duplicate \"clockid\" specification\n");
-				return -1;
-			}
-			if (get_clockid(&opt.clockid, *argv)) {
-				explain_clockid(*argv);
-				return -1;
-			}
-		} else if (strcmp(*argv, "skip_sock_check") == 0) {
-			if (opt.flags & TC_ETF_SKIP_SOCK_CHECK) {
-				fprintf(stderr, "etf: duplicate \"skip_sock_check\" specification\n");
-				return -1;
-			}
-
-			opt.flags |= TC_ETF_SKIP_SOCK_CHECK;
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "etf: unknown parameter \"%s\"\n", *argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 2024, TCA_ETF_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_ETF_MAX+1];
-	struct tc_etf_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_ETF_MAX, opt);
-
-	if (tb[TCA_ETF_PARMS] == NULL)
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_ETF_PARMS]);
-	if (RTA_PAYLOAD(tb[TCA_ETF_PARMS])  < sizeof(*qopt))
-		return -1;
-
-	print_string(PRINT_ANY, "clockid", "clockid %s ",
-		     get_clock_name(qopt->clockid));
-
-	print_uint(PRINT_ANY, "delta", "delta %d ", qopt->delta);
-	print_string(PRINT_ANY, "offload", "offload %s ",
-				(qopt->flags & TC_ETF_OFFLOAD_ON) ? "on" : "off");
-	print_string(PRINT_ANY, "deadline_mode", "deadline_mode %s ",
-				(qopt->flags & TC_ETF_DEADLINE_MODE_ON) ? "on" : "off");
-	print_string(PRINT_ANY, "skip_sock_check", "skip_sock_check %s",
-				(qopt->flags & TC_ETF_SKIP_SOCK_CHECK) ? "on" : "off");
-
-	return 0;
-}
-
-struct qdisc_util etf_qdisc_util = {
-	.id		= "etf",
-	.parse_qopt	= etf_parse_opt,
-	.print_qopt	= etf_print_opt,
-};
diff --git a/tc/q_fifo.c b/tc/q_fifo.c
index 61493fb..c9ab123 100644
--- a/tc/q_fifo.c
+++ b/tc/q_fifo.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,11 +28,11 @@
 	fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n");
 }
 
-static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			  struct nlmsghdr *n, const char *dev)
+static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	int ok = 0;
-	struct tc_fifo_qopt opt = {};
+	int ok=0;
+	struct tc_fifo_qopt opt;
+	memset(&opt, 0, sizeof(opt));
 
 	while (argc > 0) {
 		if (strcmp(*argv, "limit") == 0) {
@@ -69,12 +70,9 @@
 	qopt = RTA_DATA(opt);
 	if (strcmp(qu->id, "bfifo") == 0) {
 		SPRINT_BUF(b1);
-		print_uint(PRINT_JSON, "limit", NULL, qopt->limit);
-		print_string(PRINT_FP, NULL, "limit %s",
-			     sprint_size(qopt->limit, b1));
-	} else {
-		print_uint(PRINT_ANY, "limit", "limit %up", qopt->limit);
-	}
+		fprintf(f, "limit %s", sprint_size(qopt->limit, b1));
+	} else
+		fprintf(f, "limit %up", qopt->limit);
 	return 0;
 }
 
@@ -97,6 +95,7 @@
 	.print_qopt = fifo_print_opt,
 };
 
+extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
 struct qdisc_util pfifo_fast_qdisc_util = {
 	.id = "pfifo_fast",
 	.print_qopt = prio_print_opt,
diff --git a/tc/q_fq.c b/tc/q_fq.c
index caf232e..2a370b3 100644
--- a/tc/q_fq.c
+++ b/tc/q_fq.c
@@ -38,6 +38,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -50,14 +51,11 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... fq	[ limit PACKETS ] [ flow_limit PACKETS ]\n"
-		"		[ quantum BYTES ] [ initial_quantum BYTES ]\n"
-		"		[ maxrate RATE  ] [ buckets NUMBER ]\n"
-		"		[ [no]pacing ] [ refill_delay TIME ]\n"
-		"		[ low_rate_threshold RATE ]\n"
-		"		[ orphan_mask MASK]\n"
-		"		[ ce_threshold TIME ]\n");
+	fprintf(stderr, "Usage: ... fq [ limit PACKETS ] [ flow_limit PACKETS ]\n");
+	fprintf(stderr, "              [ quantum BYTES ] [ initial_quantum BYTES ]\n");
+	fprintf(stderr, "              [ maxrate RATE  ] [ buckets NUMBER ]\n");
+	fprintf(stderr, "              [ [no]pacing ] [ refill_delay TIME ]\n");
+	fprintf(stderr, "              [ orphan_mask MASK]\n");
 }
 
 static unsigned int ilog2(unsigned int val)
@@ -73,7 +71,7 @@
 }
 
 static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			struct nlmsghdr *n, const char *dev)
+			struct nlmsghdr *n)
 {
 	unsigned int plimit;
 	unsigned int flow_plimit;
@@ -81,11 +79,9 @@
 	unsigned int initial_quantum;
 	unsigned int buckets = 0;
 	unsigned int maxrate;
-	unsigned int low_rate_threshold;
 	unsigned int defrate;
 	unsigned int refill_delay;
 	unsigned int orphan_mask;
-	unsigned int ce_threshold;
 	bool set_plimit = false;
 	bool set_flow_plimit = false;
 	bool set_quantum = false;
@@ -94,8 +90,6 @@
 	bool set_defrate = false;
 	bool set_refill_delay = false;
 	bool set_orphan_mask = false;
-	bool set_low_rate_threshold = false;
-	bool set_ce_threshold = false;
 	int pacing = -1;
 	struct rtattr *tail;
 
@@ -122,38 +116,14 @@
 			}
 		} else if (strcmp(*argv, "maxrate") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&maxrate, *argv, dev)) {
-					fprintf(stderr, "Illegal \"maxrate\"\n");
-					return -1;
-				}
-			} else if (get_rate(&maxrate, *argv)) {
+			if (get_rate(&maxrate, *argv)) {
 				fprintf(stderr, "Illegal \"maxrate\"\n");
 				return -1;
 			}
 			set_maxrate = true;
-		} else if (strcmp(*argv, "low_rate_threshold") == 0) {
-			NEXT_ARG();
-			if (get_rate(&low_rate_threshold, *argv)) {
-				fprintf(stderr, "Illegal \"low_rate_threshold\"\n");
-				return -1;
-			}
-			set_low_rate_threshold = true;
-		} else if (strcmp(*argv, "ce_threshold") == 0) {
-			NEXT_ARG();
-			if (get_time(&ce_threshold, *argv)) {
-				fprintf(stderr, "Illegal \"ce_threshold\"\n");
-				return -1;
-			}
-			set_ce_threshold = true;
 		} else if (strcmp(*argv, "defrate") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&defrate, *argv, dev)) {
-					fprintf(stderr, "Illegal \"defrate\"\n");
-					return -1;
-				}
-			} else if (get_rate(&defrate, *argv)) {
+			if (get_rate(&defrate, *argv)) {
 				fprintf(stderr, "Illegal \"defrate\"\n");
 				return -1;
 			}
@@ -201,7 +171,8 @@
 		argc--; argv++;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (buckets) {
 		unsigned int log = ilog2(buckets);
 
@@ -225,9 +196,6 @@
 	if (set_maxrate)
 		addattr_l(n, 1024, TCA_FQ_FLOW_MAX_RATE,
 			  &maxrate, sizeof(maxrate));
-	if (set_low_rate_threshold)
-		addattr_l(n, 1024, TCA_FQ_LOW_RATE_THRESHOLD,
-			  &low_rate_threshold, sizeof(low_rate_threshold));
 	if (set_defrate)
 		addattr_l(n, 1024, TCA_FQ_FLOW_DEFAULT_RATE,
 			  &defrate, sizeof(defrate));
@@ -237,10 +205,7 @@
 	if (set_orphan_mask)
 		addattr_l(n, 1024, TCA_FQ_ORPHAN_MASK,
 			  &orphan_mask, sizeof(refill_delay));
-	if (set_ce_threshold)
-		addattr_l(n, 1024, TCA_FQ_CE_THRESHOLD,
-			  &ce_threshold, sizeof(ce_threshold));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -253,8 +218,6 @@
 	unsigned int rate, quantum;
 	unsigned int refill_delay;
 	unsigned int orphan_mask;
-	unsigned int ce_threshold;
-
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
@@ -312,41 +275,27 @@
 		if (rate != 0)
 			fprintf(f, "defrate %s ", sprint_rate(rate, b1));
 	}
-	if (tb[TCA_FQ_LOW_RATE_THRESHOLD] &&
-	    RTA_PAYLOAD(tb[TCA_FQ_LOW_RATE_THRESHOLD]) >= sizeof(__u32)) {
-		rate = rta_getattr_u32(tb[TCA_FQ_LOW_RATE_THRESHOLD]);
-
-		if (rate != 0)
-			fprintf(f, "low_rate_threshold %s ", sprint_rate(rate, b1));
-	}
 	if (tb[TCA_FQ_FLOW_REFILL_DELAY] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_FLOW_REFILL_DELAY]) >= sizeof(__u32)) {
 		refill_delay = rta_getattr_u32(tb[TCA_FQ_FLOW_REFILL_DELAY]);
 		fprintf(f, "refill_delay %s ", sprint_time(refill_delay, b1));
 	}
 
-	if (tb[TCA_FQ_CE_THRESHOLD] &&
-	    RTA_PAYLOAD(tb[TCA_FQ_CE_THRESHOLD]) >= sizeof(__u32)) {
-		ce_threshold = rta_getattr_u32(tb[TCA_FQ_CE_THRESHOLD]);
-		if (ce_threshold != ~0U)
-			fprintf(f, "ce_threshold %s ", sprint_time(ce_threshold, b1));
-	}
-
 	return 0;
 }
 
 static int fq_print_xstats(struct qdisc_util *qu, FILE *f,
 			   struct rtattr *xstats)
 {
-	struct tc_fq_qd_stats *st, _st;
+	struct tc_fq_qd_stats *st;
 
 	if (xstats == NULL)
 		return 0;
 
-	memset(&_st, 0, sizeof(_st));
-	memcpy(&_st, RTA_DATA(xstats), min(RTA_PAYLOAD(xstats), sizeof(*st)));
+	if (RTA_PAYLOAD(xstats) < sizeof(*st))
+		return -1;
 
-	st = &_st;
+	st = RTA_DATA(xstats);
 
 	fprintf(f, "  %u flows (%u inactive, %u throttled)",
 		st->flows, st->inactive_flows, st->throttled_flows);
@@ -362,12 +311,6 @@
 
 	fprintf(f, ", %llu throttled", st->throttled);
 
-	if (st->unthrottle_latency_ns)
-		fprintf(f, ", %u ns latency", st->unthrottle_latency_ns);
-
-	if (st->ce_mark)
-		fprintf(f, ", %llu ce_mark", st->ce_mark);
-
 	if (st->flows_plimit)
 		fprintf(f, ", %llu flows_plimit", st->flows_plimit);
 
diff --git a/tc/q_fq_codel.c b/tc/q_fq_codel.c
index 376ac50..4f747eb 100644
--- a/tc/q_fq_codel.c
+++ b/tc/q_fq_codel.c
@@ -38,6 +38,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -49,24 +50,21 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... fq_codel	[ limit PACKETS ] [ flows NUMBER ]\n"
-					"[ memory_limit BYTES ]\n"
-					"[ target TIME ] [ interval TIME ]\n"
-					"[ quantum BYTES ] [ [no]ecn ]\n"
-					"[ ce_threshold TIME ]\n");
+	fprintf(stderr, "Usage: ... fq_codel [ limit PACKETS ] [ flows NUMBER ]\n");
+	fprintf(stderr, "                    [ target TIME] [ interval TIME ]\n");
+	fprintf(stderr, "                    [ quantum BYTES ] [ [no]ecn ]\n");
+	fprintf(stderr, "                    [ ce_threshold TIME ]\n");
 }
 
 static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			      struct nlmsghdr *n, const char *dev)
+			      struct nlmsghdr *n)
 {
-	unsigned int limit = 0;
-	unsigned int flows = 0;
-	unsigned int target = 0;
-	unsigned int interval = 0;
-	unsigned int quantum = 0;
-	unsigned int ce_threshold = ~0U;
-	unsigned int memory = ~0U;
+	unsigned limit = 0;
+	unsigned flows = 0;
+	unsigned target = 0;
+	unsigned interval = 0;
+	unsigned quantum = 0;
+	unsigned ce_threshold = ~0U;
 	int ecn = -1;
 	struct rtattr *tail;
 
@@ -101,12 +99,6 @@
 				fprintf(stderr, "Illegal \"ce_threshold\"\n");
 				return -1;
 			}
-		} else if (strcmp(*argv, "memory_limit") == 0) {
-			NEXT_ARG();
-			if (get_size(&memory, *argv)) {
-				fprintf(stderr, "Illegal \"memory_limit\"\n");
-				return -1;
-			}
 		} else if (strcmp(*argv, "interval") == 0) {
 			NEXT_ARG();
 			if (get_time(&interval, *argv)) {
@@ -128,7 +120,8 @@
 		argc--; argv++;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (limit)
 		addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit));
 	if (flows)
@@ -144,26 +137,20 @@
 	if (ce_threshold != ~0U)
 		addattr_l(n, 1024, TCA_FQ_CODEL_CE_THRESHOLD,
 			  &ce_threshold, sizeof(ce_threshold));
-	if (memory != ~0U)
-		addattr_l(n, 1024, TCA_FQ_CODEL_MEMORY_LIMIT,
-			  &memory, sizeof(memory));
-
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
 static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 {
 	struct rtattr *tb[TCA_FQ_CODEL_MAX + 1];
-	unsigned int limit;
-	unsigned int flows;
-	unsigned int interval;
-	unsigned int target;
-	unsigned int ecn;
-	unsigned int quantum;
-	unsigned int ce_threshold;
-	unsigned int memory_limit;
-
+	unsigned limit;
+	unsigned flows;
+	unsigned interval;
+	unsigned target;
+	unsigned ecn;
+	unsigned quantum;
+	unsigned ce_threshold;
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
@@ -174,51 +161,38 @@
 	if (tb[TCA_FQ_CODEL_LIMIT] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) {
 		limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]);
-		print_uint(PRINT_ANY, "limit", "limit %up ", limit);
+		fprintf(f, "limit %up ", limit);
 	}
 	if (tb[TCA_FQ_CODEL_FLOWS] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) {
 		flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]);
-		print_uint(PRINT_ANY, "flows", "flows %u ", flows);
+		fprintf(f, "flows %u ", flows);
 	}
 	if (tb[TCA_FQ_CODEL_QUANTUM] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) {
 		quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]);
-		print_uint(PRINT_ANY, "quantum", "quantum %u ", quantum);
+		fprintf(f, "quantum %u ", quantum);
 	}
 	if (tb[TCA_FQ_CODEL_TARGET] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) {
 		target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]);
-		print_uint(PRINT_JSON, "target", NULL, target);
-		print_string(PRINT_FP, NULL, "target %s ",
-			     sprint_time(target, b1));
+		fprintf(f, "target %s ", sprint_time(target, b1));
 	}
 	if (tb[TCA_FQ_CODEL_CE_THRESHOLD] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) {
 		ce_threshold = rta_getattr_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]);
-		print_uint(PRINT_JSON, "ce_threshold", NULL, ce_threshold);
-		print_string(PRINT_FP, NULL, "ce_threshold %s ",
-			     sprint_time(ce_threshold, b1));
+		fprintf(f, "ce_threshold %s ", sprint_time(ce_threshold, b1));
 	}
 	if (tb[TCA_FQ_CODEL_INTERVAL] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) {
 		interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]);
-		print_uint(PRINT_JSON, "interval", NULL, interval);
-		print_string(PRINT_FP, NULL, "interval %s ",
-			     sprint_time(interval, b1));
-	}
-	if (tb[TCA_FQ_CODEL_MEMORY_LIMIT] &&
-	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_MEMORY_LIMIT]) >= sizeof(__u32)) {
-		memory_limit = rta_getattr_u32(tb[TCA_FQ_CODEL_MEMORY_LIMIT]);
-		print_uint(PRINT_JSON, "memory_limit", NULL, memory_limit);
-		print_string(PRINT_FP, NULL, "memory_limit %s ",
-			     sprint_size(memory_limit, b1));
+		fprintf(f, "interval %s ", sprint_time(interval, b1));
 	}
 	if (tb[TCA_FQ_CODEL_ECN] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) {
 		ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]);
 		if (ecn)
-			print_bool(PRINT_ANY, "ecn", "ecn ", true);
+			fprintf(f, "ecn ");
 	}
 
 	return 0;
@@ -227,8 +201,7 @@
 static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
 				 struct rtattr *xstats)
 {
-	struct tc_fq_codel_xstats _st = {}, *st;
-
+	struct tc_fq_codel_xstats _st, *st;
 	SPRINT_BUF(b1);
 
 	if (xstats == NULL)
@@ -236,54 +209,36 @@
 
 	st = RTA_DATA(xstats);
 	if (RTA_PAYLOAD(xstats) < sizeof(*st)) {
+		memset(&_st, 0, sizeof(_st));
 		memcpy(&_st, st, RTA_PAYLOAD(xstats));
 		st = &_st;
 	}
 	if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) {
-		print_uint(PRINT_ANY, "maxpacket", "  maxpacket %u",
-			st->qdisc_stats.maxpacket);
-		print_uint(PRINT_ANY, "drop_overlimit", " drop_overlimit %u",
-			st->qdisc_stats.drop_overlimit);
-		print_uint(PRINT_ANY, "new_flow_count", " new_flow_count %u",
-			st->qdisc_stats.new_flow_count);
-		print_uint(PRINT_ANY, "ecn_mark", " ecn_mark %u",
+		fprintf(f, "  maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
+			st->qdisc_stats.maxpacket,
+			st->qdisc_stats.drop_overlimit,
+			st->qdisc_stats.new_flow_count,
 			st->qdisc_stats.ecn_mark);
 		if (st->qdisc_stats.ce_mark)
-			print_uint(PRINT_ANY, "ce_mark", " ce_mark %u",
-				st->qdisc_stats.ce_mark);
-		if (st->qdisc_stats.memory_usage)
-			print_uint(PRINT_ANY, "memory_used", " memory_used %u",
-				st->qdisc_stats.memory_usage);
-		if (st->qdisc_stats.drop_overmemory)
-			print_uint(PRINT_ANY, "drop_overmemory", " drop_overmemory %u",
-				st->qdisc_stats.drop_overmemory);
-		print_uint(PRINT_ANY, "new_flows_len", "\n  new_flows_len %u",
-			st->qdisc_stats.new_flows_len);
-		print_uint(PRINT_ANY, "old_flows_len", " old_flows_len %u",
+			fprintf(f, " ce_mark %u", st->qdisc_stats.ce_mark);
+		fprintf(f, "\n  new_flows_len %u old_flows_len %u",
+			st->qdisc_stats.new_flows_len,
 			st->qdisc_stats.old_flows_len);
 	}
 	if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) {
-		print_uint(PRINT_ANY, "deficit", "  deficit %u",
-			st->class_stats.deficit);
-		print_uint(PRINT_ANY, "count", " count %u",
-			st->class_stats.count);
-		print_uint(PRINT_ANY, "lastcount", " lastcount %u",
-			st->class_stats.lastcount);
-		print_uint(PRINT_JSON, "ldelay", NULL,
-			st->class_stats.ldelay);
-		print_string(PRINT_FP, NULL, " ldelay %s",
+		fprintf(f, "  deficit %d count %u lastcount %u ldelay %s",
+			st->class_stats.deficit,
+			st->class_stats.count,
+			st->class_stats.lastcount,
 			sprint_time(st->class_stats.ldelay, b1));
 		if (st->class_stats.dropping) {
-			print_bool(PRINT_ANY, "dropping", " dropping", true);
+			fprintf(f, " dropping");
 			if (st->class_stats.drop_next < 0)
-				print_string(PRINT_FP, NULL, " drop_next -%s",
+				fprintf(f, " drop_next -%s",
 					sprint_time(-st->class_stats.drop_next, b1));
-			else {
-				print_uint(PRINT_JSON, "drop_next", NULL,
-					st->class_stats.drop_next);
-				print_string(PRINT_FP, NULL, " drop_next %s",
+			else
+				fprintf(f, " drop_next %s",
 					sprint_time(st->class_stats.drop_next, b1));
-			}
 		}
 	}
 	return 0;
diff --git a/tc/q_gred.c b/tc/q_gred.c
index 8a1cecf..f31daa3 100644
--- a/tc/q_gred.c
+++ b/tc/q_gred.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -29,19 +30,18 @@
 
 
 #if 0
-#define DPRINTF(format, args...) fprintf(stderr, format, ##args)
+#define DPRINTF(format,args...) fprintf(stderr,format,##args)
 #else
-#define DPRINTF(format, args...)
+#define DPRINTF(format,args...)
 #endif
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: tc qdisc { add | replace | change } ... gred setup vqs NUMBER\n"
-		"           default DEFAULT_VQ [ grio ] [ limit BYTES ] [ecn] [harddrop]\n"
-		"       tc qdisc change ... gred vq VQ [ prio VALUE ] limit BYTES\n"
-		"           min BYTES max BYTES avpkt BYTES [ burst PACKETS ]\n"
-		"           [ probability PROBABILITY ] [ bandwidth KBPS ] [ecn] [harddrop]\n");
+	fprintf(stderr, "Usage: tc qdisc { add | replace | change } ... gred setup vqs NUMBER\n");
+	fprintf(stderr, "           default DEFAULT_VQ [ grio ] [ limit BYTES ]\n");
+	fprintf(stderr, "       tc qdisc change ... gred vq VQ [ prio VALUE ] limit BYTES\n");
+	fprintf(stderr, "           min BYTES max BYTES avpkt BYTES [ burst PACKETS ]\n");
+	fprintf(stderr, "           [ probability PROBABILITY ] [ bandwidth KBPS ]\n");
 }
 
 static int init_gred(struct qdisc_util *qu, int argc, char **argv,
@@ -55,7 +55,7 @@
 	opt.def_DP = MAX_DPs;
 
 	while (argc > 0) {
-		DPRINTF(stderr, "init_gred: invoked with %s\n", *argv);
+		DPRINTF(stderr,"init_gred: invoked with %s\n",*argv);
 		if (strcmp(*argv, "vqs") == 0 ||
 		    strcmp(*argv, "DPs") == 0) {
 			NEXT_ARG();
@@ -63,13 +63,14 @@
 				fprintf(stderr, "Illegal \"vqs\"\n");
 				return -1;
 			} else if (opt.DPs > MAX_DPs) {
-				fprintf(stderr, "GRED: only %u VQs are currently supported\n",
-					MAX_DPs);
+				fprintf(stderr, "GRED: only %u VQs are "
+					"currently supported\n", MAX_DPs);
 				return -1;
 			}
 		} else if (strcmp(*argv, "default") == 0) {
 			if (opt.DPs == 0) {
-				fprintf(stderr, "\"default\" must be defined after \"vqs\"\n");
+				fprintf(stderr, "\"default\" must be defined "
+					"after \"vqs\"\n");
 				return -1;
 			}
 			NEXT_ARG();
@@ -77,7 +78,8 @@
 				fprintf(stderr, "Illegal \"default\"\n");
 				return -1;
 			} else if (opt.def_DP >= opt.DPs) {
-				fprintf(stderr, "\"default\" must be less than \"vqs\"\n");
+				fprintf(stderr, "\"default\" must be less than "
+					"\"vqs\"\n");
 				return -1;
 			}
 		} else if (strcmp(*argv, "grio") == 0) {
@@ -88,10 +90,6 @@
 				fprintf(stderr, "Illegal \"limit\"\n");
 				return -1;
 			}
-		} else if (strcmp(*argv, "ecn") == 0) {
-			opt.flags |= TC_RED_ECN;
-		} else if (strcmp(*argv, "harddrop") == 0) {
-			opt.flags |= TC_RED_HARDDROP;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -104,34 +102,34 @@
 	}
 
 	if (!opt.DPs || opt.def_DP == MAX_DPs) {
-		fprintf(stderr, "Illegal gred setup parameters\n");
+		fprintf(stderr, "Illegal gred setup parameters \n");
 		return -1;
 	}
 
-	DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n", opt.DPs, opt.def_DP);
-	n->nlmsg_flags |= NLM_F_CREATE;
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n",opt.DPs,opt.def_DP);
+	n->nlmsg_flags|=NLM_F_CREATE;
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt));
 	if (limit)
 		addattr32(n, 1024, TCA_GRED_LIMIT, limit);
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 /*
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 */
-static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
+static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	struct rtattr *tail, *entry, *vqs;
-	int ok = 0;
+	int ok=0;
 	struct tc_gred_qopt opt = { 0 };
-	unsigned int burst = 0;
-	unsigned int avpkt = 0;
-	unsigned int flags = 0;
+	unsigned burst = 0;
+	unsigned avpkt = 0;
 	double probability = 0.02;
-	unsigned int rate = 0;
+	unsigned rate = 0;
 	int parm;
 	__u8 sbuf[256];
+	struct rtattr *tail;
 	__u32 max_P;
 
 	opt.DP = MAX_DPs;
@@ -171,8 +169,8 @@
 				fprintf(stderr, "Illegal \"vq\"\n");
 				return -1;
 			} else if (opt.DP >= MAX_DPs) {
-				fprintf(stderr, "GRED: only %u VQs are currently supported\n",
-					MAX_DPs);
+				fprintf(stderr, "GRED: only %u VQs are "
+					"currently supported\n", MAX_DPs);
 				return -1;
 			} /* need a better error check */
 			ok++;
@@ -199,25 +197,16 @@
 			ok++;
 		} else if (strcmp(*argv, "prio") == 0) {
 			NEXT_ARG();
-			opt.prio = strtol(*argv, (char **)NULL, 10);
+			opt.prio=strtol(*argv, (char **)NULL, 10);
 			/* some error check here */
 			ok++;
 		} else if (strcmp(*argv, "bandwidth") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&rate, *argv, dev)) {
-					fprintf(stderr, "Illegal \"bandwidth\"\n");
-					return -1;
-				}
-			} else if (get_rate(&rate, *argv)) {
+			if (get_rate(&rate, *argv)) {
 				fprintf(stderr, "Illegal \"bandwidth\"\n");
 				return -1;
 			}
 			ok++;
-		} else if (strcmp(*argv, "ecn") == 0) {
-			flags |= TC_RED_ECN;
-		} else if (strcmp(*argv, "harddrop") == 0) {
-			flags |= TC_RED_HARDDROP;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -235,7 +224,8 @@
 	}
 	if (opt.DP == MAX_DPs || !opt.limit || !opt.qth_min || !opt.qth_max ||
 	    !avpkt) {
-		fprintf(stderr, "Required parameter (vq, limit, min, max, avpkt) is missing\n");
+		fprintf(stderr, "Required parameter (vq, limit, min, max, "
+			"avpkt) is missing\n");
 		return -1;
 	}
 	if (!burst) {
@@ -251,8 +241,8 @@
 		return -1;
 	}
 	if (parm >= 10)
-		fprintf(stderr, "GRED: WARNING. Burst %u seems to be too large.\n",
-		    burst);
+		fprintf(stderr, "GRED: WARNING. Burst %u seems to be too "
+		    "large.\n", burst);
 	opt.Wlog = parm;
 	if ((parm = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
 		fprintf(stderr, "GRED: failed to calculate probability.\n");
@@ -261,177 +251,33 @@
 	opt.Plog = parm;
 	if ((parm = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0)
 	    {
-		fprintf(stderr, "GRED: failed to calculate idle damping table.\n");
+		fprintf(stderr, "GRED: failed to calculate idle damping "
+		    "table.\n");
 		return -1;
 	}
 	opt.Scell_log = parm;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_GRED_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 1024, TCA_GRED_STAB, sbuf, 256);
 	max_P = probability * pow(2, 32);
 	addattr32(n, 1024, TCA_GRED_MAX_P, max_P);
-
-	vqs = addattr_nest(n, 1024, TCA_GRED_VQ_LIST);
-	entry = addattr_nest(n, 1024, TCA_GRED_VQ_ENTRY);
-	addattr32(n, 1024, TCA_GRED_VQ_DP, opt.DP);
-	addattr32(n, 1024, TCA_GRED_VQ_FLAGS, flags);
-	addattr_nest_end(n, entry);
-	addattr_nest_end(n, vqs);
-
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
-struct tc_gred_info {
-	bool	flags_present;
-	__u64	bytes;
-	__u32	packets;
-	__u32	backlog;
-	__u32	prob_drop;
-	__u32	prob_mark;
-	__u32	forced_drop;
-	__u32	forced_mark;
-	__u32	pdrop;
-	__u32	other;
-	__u32	flags;
-};
-
-static void
-gred_parse_vqs(struct tc_gred_info *info, struct rtattr *vqs)
-{
-	int rem = RTA_PAYLOAD(vqs);
-	unsigned int offset = 0;
-
-	while (rem > offset) {
-		struct rtattr *tb_entry[TCA_GRED_VQ_ENTRY_MAX + 1] = {};
-		struct rtattr *tb[TCA_GRED_VQ_MAX + 1] = {};
-		struct rtattr *entry;
-		unsigned int len;
-		unsigned int dp;
-
-		entry = RTA_DATA(vqs) + offset;
-
-		parse_rtattr(tb_entry, TCA_GRED_VQ_ENTRY_MAX, entry,
-			     rem - offset);
-		len = RTA_LENGTH(RTA_PAYLOAD(entry));
-		offset += len;
-
-		if (!tb_entry[TCA_GRED_VQ_ENTRY]) {
-			fprintf(stderr,
-				"ERROR: Failed to parse Virtual Queue entry\n");
-			continue;
-		}
-
-		parse_rtattr_nested(tb, TCA_GRED_VQ_MAX,
-				    tb_entry[TCA_GRED_VQ_ENTRY]);
-
-		if (!tb[TCA_GRED_VQ_DP]) {
-			fprintf(stderr,
-				"ERROR: Virtual Queue without DP attribute\n");
-			continue;
-		}
-
-		dp = rta_getattr_u32(tb[TCA_GRED_VQ_DP]);
-
-		if (tb[TCA_GRED_VQ_STAT_BYTES])
-			info[dp].bytes =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_BYTES]);
-		if (tb[TCA_GRED_VQ_STAT_PACKETS])
-			info[dp].packets =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PACKETS]);
-		if (tb[TCA_GRED_VQ_STAT_BACKLOG])
-			info[dp].backlog =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_BACKLOG]);
-		if (tb[TCA_GRED_VQ_STAT_PROB_DROP])
-			info[dp].prob_drop =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PROB_DROP]);
-		if (tb[TCA_GRED_VQ_STAT_PROB_MARK])
-			info[dp].prob_mark =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PROB_MARK]);
-		if (tb[TCA_GRED_VQ_STAT_FORCED_DROP])
-			info[dp].forced_drop =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_FORCED_DROP]);
-		if (tb[TCA_GRED_VQ_STAT_FORCED_MARK])
-			info[dp].forced_mark =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_FORCED_MARK]);
-		if (tb[TCA_GRED_VQ_STAT_PDROP])
-			info[dp].pdrop =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PDROP]);
-		if (tb[TCA_GRED_VQ_STAT_OTHER])
-			info[dp].other =
-				rta_getattr_u32(tb[TCA_GRED_VQ_STAT_OTHER]);
-		info[dp].flags_present = !!tb[TCA_GRED_VQ_FLAGS];
-		if (tb[TCA_GRED_VQ_FLAGS])
-			info[dp].flags =
-				rta_getattr_u32(tb[TCA_GRED_VQ_FLAGS]);
-	}
-}
-
-static void
-gred_print_stats(struct tc_gred_info *info, struct tc_gred_qopt *qopt)
-{
-	__u64 bytes = info ? info->bytes : qopt->bytesin;
-
-	SPRINT_BUF(b1);
-
-	if (!is_json_context())
-		printf("\n  Queue size: ");
-
-	print_uint(PRINT_JSON, "qave", NULL, qopt->qave);
-	print_string(PRINT_FP, NULL, "average %s ",
-		     sprint_size(qopt->qave, b1));
-
-	print_uint(PRINT_JSON, "backlog", NULL, qopt->backlog);
-	print_string(PRINT_FP, NULL, "current %s ",
-		     sprint_size(qopt->backlog, b1));
-
-	if (!is_json_context())
-		printf("\n  Dropped packets: ");
-
-	if (info) {
-		print_uint(PRINT_ANY, "forced_drop", "forced %u ",
-			   info->forced_drop);
-		print_uint(PRINT_ANY, "prob_drop", "early %u ",
-			   info->prob_drop);
-		print_uint(PRINT_ANY, "pdrop", "pdrop %u ", info->pdrop);
-		print_uint(PRINT_ANY, "other", "other %u ", info->other);
-
-		if (!is_json_context())
-			printf("\n  Marked packets: ");
-		print_uint(PRINT_ANY, "forced_mark", "forced %u ",
-			   info->forced_mark);
-		print_uint(PRINT_ANY, "prob_mark", "early %u ",
-			   info->prob_mark);
-	} else {
-		print_uint(PRINT_ANY, "forced_drop", "forced %u ",
-			   qopt->forced);
-		print_uint(PRINT_ANY, "prob_drop", "early %u ", qopt->early);
-		print_uint(PRINT_ANY, "pdrop", "pdrop %u ", qopt->pdrop);
-		print_uint(PRINT_ANY, "other", "other %u ", qopt->other);
-	}
-
-	if (!is_json_context())
-		printf("\n  Total packets: ");
-
-	print_uint(PRINT_ANY, "packets", "%u ", qopt->packets);
-
-	print_uint(PRINT_JSON, "bytes", NULL, bytes);
-	print_string(PRINT_FP, NULL, "(%s) ", sprint_size(bytes, b1));
-}
-
 static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 {
-	struct tc_gred_info infos[MAX_DPs] = {};
 	struct rtattr *tb[TCA_GRED_MAX + 1];
 	struct tc_gred_sopt *sopt;
 	struct tc_gred_qopt *qopt;
-	bool vq_info = false;
 	__u32 *max_p = NULL;
 	__u32 *limit = NULL;
-	unsigned int i;
-
+	unsigned i;
 	SPRINT_BUF(b1);
+	SPRINT_BUF(b2);
+	SPRINT_BUF(b3);
 
 	if (opt == NULL)
 		return 0;
@@ -453,73 +299,51 @@
 	qopt = RTA_DATA(tb[TCA_GRED_PARMS]);
 	if (RTA_PAYLOAD(tb[TCA_GRED_DPS]) < sizeof(*sopt) ||
 	    RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) {
-		fprintf(f, "\n GRED received message smaller than expected\n");
+		fprintf(f,"\n GRED received message smaller than expected\n");
 		return -1;
 	}
 
-	if (tb[TCA_GRED_VQ_LIST]) {
-		gred_parse_vqs(infos, tb[TCA_GRED_VQ_LIST]);
-		vq_info = true;
-	}
+/* Bad hack! should really return a proper message as shown above*/
 
-	print_uint(PRINT_ANY, "dp_cnt", "vqs %u ", sopt->DPs);
-	print_uint(PRINT_ANY, "dp_default", "default %u ", sopt->def_DP);
+	fprintf(f, "vqs %u default %u %s",
+		sopt->DPs,
+		sopt->def_DP,
+		sopt->grio ? "grio " : "");
 
-	if (sopt->grio)
-		print_bool(PRINT_ANY, "grio", "grio ", true);
-	else
-		print_bool(PRINT_ANY, "grio", NULL, false);
+	if (limit)
+		fprintf(f, "limit %s ",
+			sprint_size(*limit, b1));
 
-	if (limit) {
-		print_uint(PRINT_JSON, "limit", NULL, *limit);
-		print_string(PRINT_FP, NULL, "limit %s ",
-			     sprint_size(*limit, b1));
-	}
-
-	tc_red_print_flags(sopt->flags);
-
-	open_json_array(PRINT_JSON, "vqs");
-	for (i = 0; i < MAX_DPs; i++, qopt++) {
-		if (qopt->DP >= MAX_DPs)
-			continue;
-
-		open_json_object(NULL);
-
-		print_uint(PRINT_ANY, "vq", "\n vq %u ", qopt->DP);
-		print_hhu(PRINT_ANY, "prio", "prio %hhu ", qopt->prio);
-
-		print_uint(PRINT_JSON, "limit", NULL, qopt->limit);
-		print_string(PRINT_FP, NULL, "limit %s ",
-			     sprint_size(qopt->limit, b1));
-
-		print_uint(PRINT_JSON, "min", NULL, qopt->qth_min);
-		print_string(PRINT_FP, NULL, "min %s ",
-			     sprint_size(qopt->qth_min, b1));
-
-		print_uint(PRINT_JSON, "max", NULL, qopt->qth_max);
-		print_string(PRINT_FP, NULL, "max %s ",
-			     sprint_size(qopt->qth_max, b1));
-
-		if (infos[i].flags_present)
-			tc_red_print_flags(infos[i].flags);
-
+	for (i=0;i<MAX_DPs;i++, qopt++) {
+		if (qopt->DP >= MAX_DPs) continue;
+		fprintf(f, "\n vq %u prio %hhu limit %s min %s max %s ",
+			qopt->DP,
+			qopt->prio,
+			sprint_size(qopt->limit, b1),
+			sprint_size(qopt->qth_min, b2),
+			sprint_size(qopt->qth_max, b3));
 		if (show_details) {
-			print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt->Wlog);
+			fprintf(f, "ewma %u ", qopt->Wlog);
 			if (max_p)
-				print_float(PRINT_ANY, "probability",
-					    "probability %lg ",
-					    max_p[i] / pow(2, 32));
+				fprintf(f, "probability %lg ", max_p[i] / pow(2, 32));
 			else
-				print_uint(PRINT_ANY, "Plog", "Plog %u ",
-					   qopt->Plog);
-			print_uint(PRINT_ANY, "Scell_log", "Scell_log %u ",
-				   qopt->Scell_log);
+				fprintf(f, "Plog %u ", qopt->Plog);
+			fprintf(f, "Scell_log %u ", qopt->Scell_log);
 		}
-		if (show_stats)
-			gred_print_stats(vq_info ? &infos[i] : NULL, qopt);
-		close_json_object();
+		if (show_stats) {
+			fprintf(f, "\n  Queue size: average %s current %s ",
+				sprint_size(qopt->qave, b1),
+				sprint_size(qopt->backlog, b2));
+			fprintf(f, "\n  Dropped packets: forced %u early %u pdrop %u other %u ",
+				qopt->forced,
+				qopt->early,
+				qopt->pdrop,
+				qopt->other);
+			fprintf(f, "\n  Total packets: %u (%s) ",
+				qopt->packets,
+				sprint_size(qopt->bytesin, b1));
+		}
 	}
-	close_json_array(PRINT_JSON, "vqs");
 	return 0;
 }
 
diff --git a/tc/q_hfsc.c b/tc/q_hfsc.c
index f34b1b2..03539ec 100644
--- a/tc/q_hfsc.c
+++ b/tc/q_hfsc.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -23,8 +24,8 @@
 #include "utils.h"
 #include "tc_util.h"
 
-static int hfsc_get_sc(int *, char ***,
-		       struct tc_service_curve *, const char *);
+static int hfsc_get_sc(int *, char ***, struct tc_service_curve *);
+
 
 static void
 explain_qdisc(void)
@@ -70,10 +71,11 @@
 }
 
 static int
-hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-	       struct nlmsghdr *n, const char *dev)
+hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	struct tc_hfsc_qopt qopt = {};
+	struct tc_hfsc_qopt qopt;
+
+	memset(&qopt, 0, sizeof(qopt));
 
 	while (argc > 0) {
 		if (matches(*argv, "default") == 0) {
@@ -142,30 +144,35 @@
 
 static int
 hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
-		     struct nlmsghdr *n, const char *dev)
+                     struct nlmsghdr *n)
 {
-	struct tc_service_curve rsc = {}, fsc = {}, usc = {};
-	int rsc_ok = 0, fsc_ok = 0, usc_ok = 0;
+	struct tc_service_curve rsc, fsc, usc;
+	int rsc_ok, fsc_ok, usc_ok;
 	struct rtattr *tail;
 
+	memset(&rsc, 0, sizeof(rsc));
+	memset(&fsc, 0, sizeof(fsc));
+	memset(&usc, 0, sizeof(usc));
+	rsc_ok = fsc_ok = usc_ok = 0;
+
 	while (argc > 0) {
 		if (matches(*argv, "rt") == 0) {
 			NEXT_ARG();
-			if (hfsc_get_sc(&argc, &argv, &rsc, dev) < 0) {
+			if (hfsc_get_sc(&argc, &argv, &rsc) < 0) {
 				explain1("rt");
 				return -1;
 			}
 			rsc_ok = 1;
 		} else if (matches(*argv, "ls") == 0) {
 			NEXT_ARG();
-			if (hfsc_get_sc(&argc, &argv, &fsc, dev) < 0) {
+			if (hfsc_get_sc(&argc, &argv, &fsc) < 0) {
 				explain1("ls");
 				return -1;
 			}
 			fsc_ok = 1;
 		} else if (matches(*argv, "sc") == 0) {
 			NEXT_ARG();
-			if (hfsc_get_sc(&argc, &argv, &rsc, dev) < 0) {
+			if (hfsc_get_sc(&argc, &argv, &rsc) < 0) {
 				explain1("sc");
 				return -1;
 			}
@@ -174,7 +181,7 @@
 			fsc_ok = 1;
 		} else if (matches(*argv, "ul") == 0) {
 			NEXT_ARG();
-			if (hfsc_get_sc(&argc, &argv, &usc, dev) < 0) {
+			if (hfsc_get_sc(&argc, &argv, &usc) < 0) {
 				explain1("ul");
 				return -1;
 			}
@@ -196,12 +203,15 @@
 		return -1;
 	}
 	if (usc_ok && !fsc_ok) {
-		fprintf(stderr, "HFSC: Upper-limit Service Curve without Link-Share Service Curve\n");
+		fprintf(stderr, "HFSC: Upper-limit Service Curve without "
+		                "Link-Share Service Curve\n");
 		explain_class();
 		return -1;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (rsc_ok)
 		addattr_l(n, 1024, TCA_HFSC_RSC, &rsc, sizeof(rsc));
 	if (fsc_ok)
@@ -209,7 +219,7 @@
 	if (usc_ok)
 		addattr_l(n, 1024, TCA_HFSC_USC, &usc, sizeof(usc));
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -280,8 +290,7 @@
 };
 
 static int
-hfsc_get_sc1(int *argcp, char ***argvp,
-	     struct tc_service_curve *sc, const char *dev)
+hfsc_get_sc1(int *argcp, char ***argvp, struct tc_service_curve *sc)
 {
 	char **argv = *argvp;
 	int argc = *argcp;
@@ -289,12 +298,7 @@
 
 	if (matches(*argv, "m1") == 0) {
 		NEXT_ARG();
-		if (strchr(*argv, '%')) {
-			if (get_percent_rate(&m1, *argv, dev)) {
-				explain1("m1");
-				return -1;
-			}
-		} else if (get_rate(&m1, *argv) < 0) {
+		if (get_rate(&m1, *argv) < 0) {
 			explain1("m1");
 			return -1;
 		}
@@ -312,12 +316,7 @@
 
 	if (matches(*argv, "m2") == 0) {
 		NEXT_ARG();
-		if (strchr(*argv, '%')) {
-			if (get_percent_rate(&m2, *argv, dev)) {
-				explain1("m2");
-				return -1;
-			}
-		} else if (get_rate(&m2, *argv) < 0) {
+		if (get_rate(&m2, *argv) < 0) {
 			explain1("m2");
 			return -1;
 		}
@@ -334,7 +333,7 @@
 }
 
 static int
-hfsc_get_sc2(int *argcp, char ***argvp, struct tc_service_curve *sc, const char *dev)
+hfsc_get_sc2(int *argcp, char ***argvp, struct tc_service_curve *sc)
 {
 	char **argv = *argvp;
 	int argc = *argcp;
@@ -360,12 +359,7 @@
 
 	if (matches(*argv, "rate") == 0) {
 		NEXT_ARG();
-		if (strchr(*argv, '%')) {
-			if (get_percent_rate(&rate, *argv, dev)) {
-				explain1("rate");
-				return -1;
-			}
-		} else if (get_rate(&rate, *argv) < 0) {
+		if (get_rate(&rate, *argv) < 0) {
 			explain1("rate");
 			return -1;
 		}
@@ -401,10 +395,10 @@
 }
 
 static int
-hfsc_get_sc(int *argcp, char ***argvp, struct tc_service_curve *sc, const char *dev)
+hfsc_get_sc(int *argcp, char ***argvp, struct tc_service_curve *sc)
 {
-	if (hfsc_get_sc1(argcp, argvp, sc, dev) < 0 &&
-	    hfsc_get_sc2(argcp, argvp, sc, dev) < 0)
+	if (hfsc_get_sc1(argcp, argvp, sc) < 0 &&
+	    hfsc_get_sc2(argcp, argvp, sc) < 0)
 		return -1;
 
 	if (sc->m1 == 0 && sc->m2 == 0) {
diff --git a/tc/q_hhf.c b/tc/q_hhf.c
index 5ee6642..06ec8a2 100644
--- a/tc/q_hhf.c
+++ b/tc/q_hhf.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /* q_hhf.c		Heavy-Hitter Filter (HHF)
  *
  * Copyright (C) 2013 Terry Lam <vtlam@google.com>
@@ -6,6 +5,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -17,25 +17,24 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... hhf	[ limit PACKETS ] [ quantum BYTES]\n"
-		"		[ hh_limit NUMBER ]\n"
-		"		[ reset_timeout TIME ]\n"
-		"		[ admit_bytes BYTES ]\n"
-		"		[ evict_timeout TIME ]\n"
-		"		[ non_hh_weight NUMBER ]\n");
+	fprintf(stderr, "Usage: ... hhf [ limit PACKETS ] [ quantum BYTES]\n");
+	fprintf(stderr, "               [ hh_limit NUMBER ]\n");
+	fprintf(stderr, "               [ reset_timeout TIME ]\n");
+	fprintf(stderr, "               [ admit_bytes BYTES ]\n");
+	fprintf(stderr, "               [ evict_timeout TIME ]\n");
+	fprintf(stderr, "               [ non_hh_weight NUMBER ]\n");
 }
 
 static int hhf_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+			 struct nlmsghdr *n)
 {
-	unsigned int limit = 0;
-	unsigned int quantum = 0;
-	unsigned int hh_limit = 0;
-	unsigned int reset_timeout = 0;
-	unsigned int admit_bytes = 0;
-	unsigned int evict_timeout = 0;
-	unsigned int non_hh_weight = 0;
+	unsigned limit = 0;
+	unsigned quantum = 0;
+	unsigned hh_limit = 0;
+	unsigned reset_timeout = 0;
+	unsigned admit_bytes = 0;
+	unsigned evict_timeout = 0;
+	unsigned non_hh_weight = 0;
 	struct rtattr *tail;
 
 	while (argc > 0) {
@@ -92,7 +91,8 @@
 		argc--; argv++;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (limit)
 		addattr_l(n, 1024, TCA_HHF_BACKLOG_LIMIT, &limit,
 			  sizeof(limit));
@@ -113,21 +113,20 @@
 	if (non_hh_weight)
 		addattr_l(n, 1024, TCA_HHF_NON_HH_WEIGHT, &non_hh_weight,
 			  sizeof(non_hh_weight));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
 static int hhf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 {
 	struct rtattr *tb[TCA_HHF_MAX + 1];
-	unsigned int limit;
-	unsigned int quantum;
-	unsigned int hh_limit;
-	unsigned int reset_timeout;
-	unsigned int admit_bytes;
-	unsigned int evict_timeout;
-	unsigned int non_hh_weight;
-
+	unsigned limit;
+	unsigned quantum;
+	unsigned hh_limit;
+	unsigned reset_timeout;
+	unsigned admit_bytes;
+	unsigned evict_timeout;
+	unsigned non_hh_weight;
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
diff --git a/tc/q_htb.c b/tc/q_htb.c
index 5205222..7075a4c 100644
--- a/tc/q_htb.c
+++ b/tc/q_htb.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -48,7 +49,7 @@
 		" mtu      max packet size we create rate map for {1600}\n"
 		" prio     priority of leaf; lower are served first {0}\n"
 		" quantum  how much bytes to serve from leaf at once {use r2q}\n"
-		"\nTC HTB version %d.%d\n", HTB_TC_VER>>16, HTB_TC_VER&0xffff
+		"\nTC HTB version %d.%d\n",HTB_TC_VER>>16,HTB_TC_VER&0xffff
 		);
 }
 
@@ -58,16 +59,16 @@
     explain();
 }
 
-static int htb_parse_opt(struct qdisc_util *qu, int argc,
-			 char **argv, struct nlmsghdr *n, const char *dev)
+
+static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	unsigned int direct_qlen = ~0U;
-	struct tc_htb_glob opt = {
-		.rate2quantum = 10,
-		.version = 3,
-	};
+	struct tc_htb_glob opt;
 	struct rtattr *tail;
-	unsigned int i; char *p;
+	unsigned i; char *p;
+	memset(&opt,0,sizeof(opt));
+	opt.rate2quantum = 10;
+	opt.version = 3;
 
 	while (argc > 0) {
 		if (matches(*argv, "r2q") == 0) {
@@ -82,8 +83,8 @@
 			}
 		} else if (matches(*argv, "debug") == 0) {
 			NEXT_ARG(); p = *argv;
-			for (i = 0; i < 16; i++, p++) {
-				if (*p < '0' || *p > '3') break;
+			for (i=0; i<16; i++,p++) {
+				if (*p<'0' || *p>'3') break;
 				opt.debug |= (*p-'0')<<(2*i);
 			}
 		} else if (matches(*argv, "direct_qlen") == 0) {
@@ -98,34 +99,39 @@
 		}
 		argc--; argv++;
 	}
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt)));
 	if (direct_qlen != ~0U)
 		addattr_l(n, 2024, TCA_HTB_DIRECT_QLEN,
 			  &direct_qlen, sizeof(direct_qlen));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
-static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
+static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	struct tc_htb_opt opt = {};
-	__u32 rtab[256], ctab[256];
-	unsigned buffer = 0, cbuffer = 0;
-	int cell_log =  -1, ccell_log = -1;
-	unsigned int mtu = 1600; /* eth packet len */
+	int ok=0;
+	struct tc_htb_opt opt;
+	__u32 rtab[256],ctab[256];
+	unsigned buffer=0,cbuffer=0;
+	int cell_log=-1,ccell_log = -1;
+	unsigned mtu;
 	unsigned short mpu = 0;
 	unsigned short overhead = 0;
 	unsigned int linklayer  = LINKLAYER_ETHERNET; /* Assume ethernet */
 	struct rtattr *tail;
 	__u64 ceil64 = 0, rate64 = 0;
 
+	memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
+
 	while (argc > 0) {
 		if (matches(*argv, "prio") == 0) {
 			NEXT_ARG();
 			if (get_u32(&opt.prio, *argv, 10)) {
 				explain1("prio"); return -1;
 			}
+			ok++;
 		} else if (matches(*argv, "mtu") == 0) {
 			NEXT_ARG();
 			if (get_u32(&mtu, *argv, 10)) {
@@ -159,6 +165,7 @@
 				explain1("buffer");
 				return -1;
 			}
+			ok++;
 		} else if (matches(*argv, "cburst") == 0 ||
 			   strcmp(*argv, "cbuffer") == 0 ||
 			   strcmp(*argv, "cmaxburst") == 0) {
@@ -167,36 +174,29 @@
 				explain1("cbuffer");
 				return -1;
 			}
+			ok++;
 		} else if (strcmp(*argv, "ceil") == 0) {
 			NEXT_ARG();
 			if (ceil64) {
 				fprintf(stderr, "Double \"ceil\" spec\n");
 				return -1;
 			}
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate64(&ceil64, *argv, dev)) {
-					explain1("ceil");
-					return -1;
-				}
-			} else if (get_rate64(&ceil64, *argv)) {
+			if (get_rate64(&ceil64, *argv)) {
 				explain1("ceil");
 				return -1;
 			}
+			ok++;
 		} else if (strcmp(*argv, "rate") == 0) {
 			NEXT_ARG();
 			if (rate64) {
 				fprintf(stderr, "Double \"rate\" spec\n");
 				return -1;
 			}
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate64(&rate64, *argv, dev)) {
-					explain1("rate");
-					return -1;
-				}
-			} else if (get_rate64(&rate64, *argv)) {
+			if (get_rate64(&rate64, *argv)) {
 				explain1("rate");
 				return -1;
 			}
+			ok++;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -208,6 +208,9 @@
 		argc--; argv++;
 	}
 
+	/*	if (!ok)
+		return 0;*/
+
 	if (!rate64) {
 		fprintf(stderr, "\"rate\" is required.\n");
 		return -1;
@@ -244,7 +247,8 @@
 	}
 	opt.cbuffer = tc_calc_xmittime(ceil64, cbuffer);
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 
 	if (rate64 >= (1ULL << 32))
 		addattr_l(n, 1124, TCA_HTB_RATE64, &rate64, sizeof(rate64));
@@ -255,7 +259,7 @@
 	addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024);
 	addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024);
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -264,13 +268,13 @@
 	struct rtattr *tb[TCA_HTB_MAX + 1];
 	struct tc_htb_opt *hopt;
 	struct tc_htb_glob *gopt;
-	double buffer, cbuffer;
+	double buffer,cbuffer;
 	unsigned int linklayer;
 	__u64 rate64, ceil64;
-
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
 	SPRINT_BUF(b3);
+	SPRINT_BUF(b4);
 
 	if (opt == NULL)
 		return 0;
@@ -282,10 +286,9 @@
 		if (RTA_PAYLOAD(tb[TCA_HTB_PARMS])  < sizeof(*hopt)) return -1;
 
 		if (!hopt->level) {
-			print_int(PRINT_ANY, "prio", "prio %d ", (int)hopt->prio);
+			fprintf(f, "prio %d ", (int)hopt->prio);
 			if (show_details)
-				print_int(PRINT_ANY, "quantum", "quantum %d ",
-					  (int)hopt->quantum);
+				fprintf(f, "quantum %d ", (int)hopt->quantum);
 		}
 
 		rate64 = hopt->rate.rate;
@@ -308,16 +311,18 @@
 		cbuffer = tc_calc_xmitsize(ceil64, hopt->cbuffer);
 		linklayer = (hopt->rate.linklayer & TC_LINKLAYER_MASK);
 		if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
-			fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b3));
+			fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b4));
 		if (show_details) {
-			fprintf(f, "burst %s/%u mpu %s ",
+			fprintf(f, "burst %s/%u mpu %s overhead %s ",
 				sprint_size(buffer, b1),
 				1<<hopt->rate.cell_log,
-				sprint_size(hopt->rate.mpu, b2));
-			fprintf(f, "cburst %s/%u mpu %s ",
+				sprint_size(hopt->rate.mpu&0xFF, b2),
+				sprint_size((hopt->rate.mpu>>8)&0xFF, b3));
+			fprintf(f, "cburst %s/%u mpu %s overhead %s ",
 				sprint_size(cbuffer, b1),
 				1<<hopt->ceil.cell_log,
-				sprint_size(hopt->ceil.mpu, b2));
+				sprint_size(hopt->ceil.mpu&0xFF, b2),
+				sprint_size((hopt->ceil.mpu>>8)&0xFF, b3));
 			fprintf(f, "level %d ", (int)hopt->level);
 		} else {
 			fprintf(f, "burst %s ", sprint_size(buffer, b1));
@@ -325,27 +330,22 @@
 		}
 		if (show_raw)
 			fprintf(f, "buffer [%08x] cbuffer [%08x] ",
-				hopt->buffer, hopt->cbuffer);
+				hopt->buffer,hopt->cbuffer);
 	}
 	if (tb[TCA_HTB_INIT]) {
 		gopt = RTA_DATA(tb[TCA_HTB_INIT]);
 		if (RTA_PAYLOAD(tb[TCA_HTB_INIT])  < sizeof(*gopt)) return -1;
 
-		print_int(PRINT_ANY, "r2q", "r2q %d", gopt->rate2quantum);
-		print_0xhex(PRINT_ANY, "default", " default %#llx", gopt->defcls);
-		print_uint(PRINT_ANY, "direct_packets_stat",
-			   " direct_packets_stat %u", gopt->direct_pkts);
-		if (show_details) {
-			sprintf(b1, "%d.%d", gopt->version >> 16, gopt->version & 0xffff);
-			print_string(PRINT_ANY, "ver", " ver %s", b1);
-		}
+		fprintf(f, "r2q %d default %x direct_packets_stat %u",
+			gopt->rate2quantum,gopt->defcls,gopt->direct_pkts);
+		if (show_details)
+			fprintf(f," ver %d.%d",gopt->version >> 16,gopt->version & 0xffff);
 	}
 	if (tb[TCA_HTB_DIRECT_QLEN] &&
 	    RTA_PAYLOAD(tb[TCA_HTB_DIRECT_QLEN]) >= sizeof(__u32)) {
 		__u32 direct_qlen = rta_getattr_u32(tb[TCA_HTB_DIRECT_QLEN]);
 
-		print_uint(PRINT_ANY, "direct_qlen", " direct_qlen %u",
-			   direct_qlen);
+		fprintf(f, " direct_qlen %u", direct_qlen);
 	}
 	return 0;
 }
@@ -353,7 +353,6 @@
 static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
 {
 	struct tc_htb_xstats *st;
-
 	if (xstats == NULL)
 		return 0;
 
@@ -362,16 +361,16 @@
 
 	st = RTA_DATA(xstats);
 	fprintf(f, " lended: %u borrowed: %u giants: %u\n",
-		st->lends, st->borrows, st->giants);
-	fprintf(f, " tokens: %d ctokens: %d\n", st->tokens, st->ctokens);
+		st->lends,st->borrows,st->giants);
+	fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
 	return 0;
 }
 
 struct qdisc_util htb_qdisc_util = {
-	.id		= "htb",
+	.id 		= "htb",
 	.parse_qopt	= htb_parse_opt,
 	.print_qopt	= htb_print_opt,
-	.print_xstats	= htb_print_xstats,
+	.print_xstats 	= htb_print_xstats,
 	.parse_copt	= htb_parse_class_opt,
 	.print_copt	= htb_print_opt,
 };
diff --git a/tc/q_ingress.c b/tc/q_ingress.c
index 93313c9..c3c9b40 100644
--- a/tc/q_ingress.c
+++ b/tc/q_ingress.c
@@ -21,7 +21,7 @@
 }
 
 static int ingress_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			     struct nlmsghdr *n, const char *dev)
+			     struct nlmsghdr *n)
 {
 	while (argc > 0) {
 		if (strcmp(*argv, "handle") == 0) {
@@ -34,13 +34,14 @@
 		}
 	}
 
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	return 0;
 }
 
 static int ingress_print_opt(struct qdisc_util *qu, FILE *f,
 			     struct rtattr *opt)
 {
-	print_string(PRINT_FP, NULL, "---------------- ", NULL);
+	fprintf(f, "---------------- ");
 	return 0;
 }
 
diff --git a/tc/q_mqprio.c b/tc/q_mqprio.c
index 0eb4130..fa1022b 100644
--- a/tc/q_mqprio.c
+++ b/tc/q_mqprio.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -23,33 +24,20 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... mqprio	[num_tc NUMBER] [map P0 P1 ...]\n"
-		"			[queues count1@offset1 count2@offset2 ...] "
-		"[hw 1|0]\n"
-		"			[mode dcb|channel]\n"
-		"			[shaper bw_rlimit SHAPER_PARAMS]\n"
-		"Where: SHAPER_PARAMS := { min_rate MIN_RATE1 MIN_RATE2 ...|\n"
-		"			  max_rate MAX_RATE1 MAX_RATE2 ... }\n");
+	fprintf(stderr, "Usage: ... mqprio [num_tc NUMBER] [map P0 P1 ...]\n");
+	fprintf(stderr, "                  [queues count1@offset1 count2@offset2 ...] ");
+	fprintf(stderr, "[hw 1|0]\n");
 }
 
 static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
-			    char **argv, struct nlmsghdr *n, const char *dev)
+			    char **argv, struct nlmsghdr *n)
 {
 	int idx;
 	struct tc_mqprio_qopt opt = {
-		.num_tc = 8,
-		.prio_tc_map = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 1, 3, 3, 3, 3 },
-		.hw = 1,
-		.count = { },
-		.offset = { },
-	};
-	__u64 min_rate64[TC_QOPT_MAX_QUEUE] = {0};
-	__u64 max_rate64[TC_QOPT_MAX_QUEUE] = {0};
-	__u16 shaper = TC_MQPRIO_SHAPER_DCB;
-	__u16 mode = TC_MQPRIO_MODE_DCB;
-	struct rtattr *tail;
-	__u32 flags = 0;
+				     8,
+				     {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 1, 3, 3, 3, 3},
+				     1,
+				    };
 
 	while (argc > 0) {
 		idx = 0;
@@ -102,115 +90,17 @@
 				return -1;
 			}
 			idx++;
-		} else if (opt.hw && strcmp(*argv, "mode") == 0) {
-			NEXT_ARG();
-			if (matches(*argv, "dcb") == 0) {
-				mode = TC_MQPRIO_MODE_DCB;
-			} else if (matches(*argv, "channel") == 0) {
-				mode = TC_MQPRIO_MODE_CHANNEL;
-			}  else {
-				fprintf(stderr, "Illegal mode (%s)\n",
-					*argv);
-				return -1;
-			}
-			if (mode != TC_MQPRIO_MODE_DCB)
-				flags |= TC_MQPRIO_F_MODE;
-			idx++;
-		} else if (opt.hw && strcmp(*argv, "shaper") == 0) {
-			NEXT_ARG();
-			if (matches(*argv, "dcb") == 0) {
-				shaper = TC_MQPRIO_SHAPER_DCB;
-			} else if (matches(*argv, "bw_rlimit") == 0) {
-				shaper = TC_MQPRIO_SHAPER_BW_RATE;
-				if (!NEXT_ARG_OK()) {
-					fprintf(stderr, "Incomplete shaper arguments\n");
-					return -1;
-				}
-			}  else {
-				fprintf(stderr, "Illegal shaper (%s)\n",
-					*argv);
-				return -1;
-			}
-			if (shaper != TC_MQPRIO_SHAPER_DCB)
-				flags |= TC_MQPRIO_F_SHAPER;
-			idx++;
-		} else if ((shaper == TC_MQPRIO_SHAPER_BW_RATE) &&
-			   strcmp(*argv, "min_rate") == 0) {
-			while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
-				NEXT_ARG();
-				if (get_rate64(&min_rate64[idx], *argv)) {
-					PREV_ARG();
-					break;
-				}
-				idx++;
-			}
-			if (idx < opt.num_tc && !NEXT_ARG_OK()) {
-				fprintf(stderr, "Incomplete arguments, min_rate values expected\n");
-				return -1;
-			}
-			flags |= TC_MQPRIO_F_MIN_RATE;
-		} else if ((shaper == TC_MQPRIO_SHAPER_BW_RATE) &&
-			   strcmp(*argv, "max_rate") == 0) {
-			while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
-				NEXT_ARG();
-				if (get_rate64(&max_rate64[idx], *argv)) {
-					PREV_ARG();
-					break;
-				}
-				idx++;
-			}
-			if (idx < opt.num_tc && !NEXT_ARG_OK()) {
-				fprintf(stderr, "Incomplete arguments, max_rate values expected\n");
-				return -1;
-			}
-			flags |= TC_MQPRIO_F_MAX_RATE;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
 		} else {
-			invarg("unknown argument", *argv);
+			fprintf(stderr, "Unknown argument\n");
+			return -1;
 		}
 		argc--; argv++;
 	}
 
-	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
-
-	if (flags & TC_MQPRIO_F_MODE)
-		addattr_l(n, 1024, TCA_MQPRIO_MODE,
-			  &mode, sizeof(mode));
-	if (flags & TC_MQPRIO_F_SHAPER)
-		addattr_l(n, 1024, TCA_MQPRIO_SHAPER,
-			  &shaper, sizeof(shaper));
-
-	if (flags & TC_MQPRIO_F_MIN_RATE) {
-		struct rtattr *start;
-
-		start = addattr_nest(n, 1024,
-				     TCA_MQPRIO_MIN_RATE64 | NLA_F_NESTED);
-
-		for (idx = 0; idx < TC_QOPT_MAX_QUEUE; idx++)
-			addattr_l(n, 1024, TCA_MQPRIO_MIN_RATE64,
-				  &min_rate64[idx], sizeof(min_rate64[idx]));
-
-		addattr_nest_end(n, start);
-	}
-
-	if (flags & TC_MQPRIO_F_MAX_RATE) {
-		struct rtattr *start;
-
-		start = addattr_nest(n, 1024,
-				     TCA_MQPRIO_MAX_RATE64 | NLA_F_NESTED);
-
-		for (idx = 0; idx < TC_QOPT_MAX_QUEUE; idx++)
-			addattr_l(n, 1024, TCA_MQPRIO_MAX_RATE64,
-				  &max_rate64[idx], sizeof(max_rate64[idx]));
-
-		addattr_nest_end(n, start);
-	}
-
-	tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
-
 	return 0;
 }
 
@@ -218,21 +108,10 @@
 {
 	int i;
 	struct tc_mqprio_qopt *qopt;
-	__u64 min_rate64[TC_QOPT_MAX_QUEUE] = {0};
-	__u64 max_rate64[TC_QOPT_MAX_QUEUE] = {0};
-	int len;
-
-	SPRINT_BUF(b1);
 
 	if (opt == NULL)
 		return 0;
 
-	len = RTA_PAYLOAD(opt) - RTA_ALIGN(sizeof(*qopt));
-	if (len < 0) {
-		fprintf(stderr, "options size error\n");
-		return -1;
-	}
-
 	qopt = RTA_DATA(opt);
 
 	fprintf(f, " tc %u map ", qopt->num_tc);
@@ -242,64 +121,6 @@
 	for (i = 0; i < qopt->num_tc; i++)
 		fprintf(f, "(%u:%u) ", qopt->offset[i],
 			qopt->offset[i] + qopt->count[i] - 1);
-
-	if (len > 0) {
-		struct rtattr *tb[TCA_MQPRIO_MAX + 1];
-
-		parse_rtattr(tb, TCA_MQPRIO_MAX,
-			     RTA_DATA(opt) + RTA_ALIGN(sizeof(*qopt)),
-			     len);
-
-		if (tb[TCA_MQPRIO_MODE]) {
-			__u16 *mode = RTA_DATA(tb[TCA_MQPRIO_MODE]);
-
-			if (*mode == TC_MQPRIO_MODE_CHANNEL)
-				fprintf(f, "\n             mode:channel");
-		} else {
-			fprintf(f, "\n             mode:dcb");
-		}
-
-		if (tb[TCA_MQPRIO_SHAPER]) {
-			__u16 *shaper = RTA_DATA(tb[TCA_MQPRIO_SHAPER]);
-
-			if (*shaper == TC_MQPRIO_SHAPER_BW_RATE)
-				fprintf(f, "\n             shaper:bw_rlimit");
-		} else {
-			fprintf(f, "\n             shaper:dcb");
-		}
-
-		if (tb[TCA_MQPRIO_MIN_RATE64]) {
-			struct rtattr *r;
-			int rem = RTA_PAYLOAD(tb[TCA_MQPRIO_MIN_RATE64]);
-			__u64 *min = min_rate64;
-
-			for (r = RTA_DATA(tb[TCA_MQPRIO_MIN_RATE64]);
-			     RTA_OK(r, rem); r = RTA_NEXT(r, rem)) {
-				if (r->rta_type != TCA_MQPRIO_MIN_RATE64)
-					return -1;
-				*(min++) = rta_getattr_u64(r);
-			}
-			fprintf(f, "	min_rate:");
-			for (i = 0; i < qopt->num_tc; i++)
-				fprintf(f, "%s ", sprint_rate(min_rate64[i], b1));
-		}
-
-		if (tb[TCA_MQPRIO_MAX_RATE64]) {
-			struct rtattr *r;
-			int rem = RTA_PAYLOAD(tb[TCA_MQPRIO_MAX_RATE64]);
-			__u64 *max = max_rate64;
-
-			for (r = RTA_DATA(tb[TCA_MQPRIO_MAX_RATE64]);
-			     RTA_OK(r, rem); r = RTA_NEXT(r, rem)) {
-				if (r->rta_type != TCA_MQPRIO_MAX_RATE64)
-					return -1;
-				*(max++) = rta_getattr_u64(r);
-			}
-			fprintf(f, "	max_rate:");
-			for (i = 0; i < qopt->num_tc; i++)
-				fprintf(f, "%s ", sprint_rate(max_rate64[i], b1));
-		}
-	}
 	return 0;
 }
 
diff --git a/tc/q_multiq.c b/tc/q_multiq.c
index 8ad9e0b..f4f41f7 100644
--- a/tc/q_multiq.c
+++ b/tc/q_multiq.c
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -40,9 +41,9 @@
 }
 
 static int multiq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			    struct nlmsghdr *n, const char *dev)
+			    struct nlmsghdr *n)
 {
-	struct tc_multiq_qopt opt = {};
+	struct tc_multiq_qopt opt;
 
 	if (argc) {
 		if (strcmp(*argv, "help") == 0) {
@@ -76,7 +77,7 @@
 }
 
 struct qdisc_util multiq_qdisc_util = {
-	.id		= "multiq",
+	.id	 	= "multiq",
 	.parse_qopt	= multiq_parse_opt,
 	.print_qopt	= multiq_print_opt,
 };
diff --git a/tc/q_netem.c b/tc/q_netem.c
index d01450f..7bc8c6a 100644
--- a/tc/q_netem.c
+++ b/tc/q_netem.c
@@ -15,8 +15,8 @@
 #include <math.h>
 #include <ctype.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
-#include <stdint.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -30,22 +30,17 @@
 static void explain(void)
 {
 	fprintf(stderr,
-		"Usage: ... netem	[ limit PACKETS ]\n" \
-		"			[ delay TIME [ JITTER [CORRELATION]]]\n" \
-		"			[ distribution {uniform|normal|pareto|paretonormal} ]\n" \
-		"			[ corrupt PERCENT [CORRELATION]]\n" \
-		"			[ duplicate PERCENT [CORRELATION]]\n" \
-		"			[ loss random PERCENT [CORRELATION]]\n" \
-		"			[ loss state P13 [P31 [P32 [P23 P14]]]\n" \
-		"			[ loss gemodel PERCENT [R [1-H [1-K]]]\n" \
-		"			[ ecn ]\n" \
-		"			[ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]\n" \
-		"			[ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n" \
-		"			[ slot MIN_DELAY [MAX_DELAY] [packets MAX_PACKETS]" \
-		" [bytes MAX_BYTES]]\n" \
-		"		[ slot distribution" \
-		" {uniform|normal|pareto|paretonormal|custom} DELAY JITTER" \
-		" [packets MAX_PACKETS] [bytes MAX_BYTES]]\n");
+"Usage: ... netem [ limit PACKETS ] \n" \
+"                 [ delay TIME [ JITTER [CORRELATION]]]\n" \
+"                 [ distribution {uniform|normal|pareto|paretonormal} ]\n" \
+"                 [ corrupt PERCENT [CORRELATION]] \n" \
+"                 [ duplicate PERCENT [CORRELATION]]\n" \
+"                 [ loss random PERCENT [CORRELATION]]\n" \
+"                 [ loss state P13 [P31 [P32 [P23 P14]]]\n" \
+"                 [ loss gemodel PERCENT [R [1-H [1-K]]]\n" \
+"                 [ ecn ]\n" \
+"                 [ reorder PRECENT [CORRELATION] [ gap DISTANCE ]]\n" \
+"                 [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n");
 }
 
 static void explain1(const char *arg)
@@ -58,47 +53,27 @@
  */
 #define MAX_DIST	(16*1024)
 
-/* Print values only if they are non-zero */
-static void __print_int_opt(const char *label_json, const char *label_fp,
-			    int val)
-{
-	print_int(PRINT_ANY, label_json, val ? label_fp : "", val);
-}
-#define PRINT_INT_OPT(label, val)			\
-	__print_int_opt(label, " " label " %d", (val))
-
-/* Time print prints normally with varying units, but for JSON prints
- * in seconds (1ms vs 0.001).
- */
-static void __print_time64(const char *label_json, const char *label_fp,
-			   __u64 val)
-{
-	SPRINT_BUF(b1);
-
-	print_string(PRINT_FP, NULL, label_fp, sprint_time64(val, b1));
-	print_float(PRINT_JSON, label_json, NULL, val / 1000000000.);
-}
-#define __PRINT_TIME64(label_json, label_fp, val)	\
-	__print_time64(label_json, label_fp " %s", (val))
-#define PRINT_TIME64(label, val) __PRINT_TIME64(label, " " label, (val))
-
-/* Percent print prints normally in percentage points, but for JSON prints
- * an absolute value (1% vs 0.01).
- */
-static void __print_percent(const char *label_json, const char *label_fp,
-			    __u32 per)
-{
-	print_float(PRINT_FP, NULL, label_fp, (100. * per) / UINT32_MAX);
-	print_float(PRINT_JSON, label_json, NULL, (1. * per) / UINT32_MAX);
-}
-#define __PRINT_PERCENT(label_json, label_fp, per)		\
-	__print_percent(label_json, label_fp " %g%%", (per))
-#define PRINT_PERCENT(label, per) __PRINT_PERCENT(label, " " label, (per))
+static const double max_percent_value = 0xffffffff;
 
 /* scaled value used to percent of maximum. */
 static void set_percent(__u32 *percent, double per)
 {
-	*percent = rint(per * UINT32_MAX);
+	*percent = (unsigned) rint(per * max_percent_value);
+}
+
+
+/* Parse either a fraction '.3' or percent '30%
+ * return: 0 = ok, -1 = error, 1 = out of range
+ */
+static int parse_percent(double *val, const char *str)
+{
+	char *p;
+
+	*val = strtod(str, &p) / 100.;
+	if (*p && strcmp(p, "%") )
+		return -1;
+
+	return 0;
 }
 
 static int get_percent(__u32 *percent, const char *str)
@@ -112,14 +87,15 @@
 	return 0;
 }
 
-static void print_corr(bool present, __u32 value)
+static void print_percent(char *buf, int len, __u32 per)
 {
-	if (!is_json_context()) {
-		if (present)
-			__PRINT_PERCENT("", "", value);
-	} else {
-		PRINT_PERCENT("correlation", value);
-	}
+	snprintf(buf, len, "%g%%", 100. * (double) per / max_percent_value);
+}
+
+static char * sprint_percent(__u32 per, char *buf)
+{
+	print_percent(buf, SPRINT_BSIZE-1, per);
+	return buf;
 }
 
 /*
@@ -147,7 +123,6 @@
 	n = 0;
 	while (getline(&line, &len, f) != -1) {
 		char *p, *endp;
-
 		if (*line == '\n' || *line == '#')
 			continue;
 
@@ -179,9 +154,9 @@
    (based on kernel PSCHED_CLOCK configuration */
 static int get_ticks(__u32 *ticks, const char *str)
 {
-	unsigned int t;
+	unsigned t;
 
-	if (get_time(&t, str))
+	if(get_time(&t, str))
 		return -1;
 
 	if (tc_core_time2big(t)) {
@@ -194,26 +169,29 @@
 }
 
 static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			   struct nlmsghdr *n, const char *dev)
+			   struct nlmsghdr *n)
 {
 	int dist_size = 0;
-	int slot_dist_size = 0;
 	struct rtattr *tail;
 	struct tc_netem_qopt opt = { .limit = 1000 };
-	struct tc_netem_corr cor = {};
-	struct tc_netem_reorder reorder = {};
-	struct tc_netem_corrupt corrupt = {};
+	struct tc_netem_corr cor;
+	struct tc_netem_reorder reorder;
+	struct tc_netem_corrupt corrupt;
 	struct tc_netem_gimodel gimodel;
 	struct tc_netem_gemodel gemodel;
-	struct tc_netem_rate rate = {};
-	struct tc_netem_slot slot = {};
+	struct tc_netem_rate rate;
 	__s16 *dist_data = NULL;
-	__s16 *slot_dist_data = NULL;
 	__u16 loss_type = NETEM_LOSS_UNSPEC;
-	int present[__TCA_NETEM_MAX] = {};
+	int present[__TCA_NETEM_MAX];
 	__u64 rate64 = 0;
 
-	for ( ; argc > 0; --argc, ++argv) {
+	memset(&cor, 0, sizeof(cor));
+	memset(&reorder, 0, sizeof(reorder));
+	memset(&corrupt, 0, sizeof(corrupt));
+	memset(&rate, 0, sizeof(rate));
+	memset(present, 0, sizeof(present));
+
+	for( ; argc > 0; --argc, ++argv) {
 		if (matches(*argv, "limit") == 0) {
 			NEXT_ARG();
 			if (get_size(&opt.limit, *argv)) {
@@ -258,7 +236,7 @@
 
 			if (!strcmp(*argv, "random")) {
 				NEXT_ARG();
-			random_loss_model:
+	random_loss_model:
 				if (get_percent(&opt.loss, *argv)) {
 					explain1("loss percent");
 					return -1;
@@ -320,17 +298,14 @@
 				}
 
 			} else if (!strcmp(*argv, "gemodel")) {
-				double p;
-
 				NEXT_ARG();
-				if (parse_percent(&p, *argv)) {
+				if (get_percent(&gemodel.p, *argv)) {
 					explain1("loss gemodel p");
 					return -1;
 				}
-				set_percent(&gemodel.p, p);
 
 				/* set defaults */
-				set_percent(&gemodel.r, 1. - p);
+				set_percent(&gemodel.r, 1.);
 				set_percent(&gemodel.h, 0);
 				set_percent(&gemodel.k1, 0);
 				loss_type = NETEM_LOSS_GE;
@@ -353,7 +328,7 @@
 				/* netem option is "1-h" but kernel
 				 * expects "h".
 				 */
-				gemodel.h = UINT32_MAX - gemodel.h;
+				gemodel.h = max_percent_value - gemodel.h;
 
 				if (!NEXT_IS_NUMBER())
 					continue;
@@ -368,7 +343,7 @@
 				return -1;
 			}
 		} else if (matches(*argv, "ecn") == 0) {
-			present[TCA_NETEM_ECN] = 1;
+				present[TCA_NETEM_ECN] = 1;
 		} else if (matches(*argv, "reorder") == 0) {
 			NEXT_ARG();
 			present[TCA_NETEM_REORDER] = 1;
@@ -429,12 +404,7 @@
 		} else if (matches(*argv, "rate") == 0) {
 			++present[TCA_NETEM_RATE];
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate64(&rate64, *argv, dev)) {
-					explain1("rate");
-					return -1;
-				}
-			} else if (get_rate64(&rate64, *argv)) {
+			if (get_rate64(&rate64, *argv)) {
 				explain1("rate");
 				return -1;
 			}
@@ -459,79 +429,6 @@
 					return -1;
 				}
 			}
-		} else if (matches(*argv, "slot") == 0) {
-			if (NEXT_IS_NUMBER()) {
-				NEXT_ARG();
-				present[TCA_NETEM_SLOT] = 1;
-				if (get_time64(&slot.min_delay, *argv)) {
-					explain1("slot min_delay");
-					return -1;
-				}
-				if (NEXT_IS_NUMBER()) {
-					NEXT_ARG();
-					if (get_time64(&slot.max_delay, *argv) ||
-					    slot.max_delay < slot.min_delay) {
-						explain1("slot max_delay");
-						return -1;
-					}
-				} else {
-					slot.max_delay = slot.min_delay;
-				}
-			} else {
-				NEXT_ARG();
-				if (strcmp(*argv, "distribution") == 0) {
-					present[TCA_NETEM_SLOT] = 1;
-					NEXT_ARG();
-					slot_dist_data = calloc(sizeof(slot_dist_data[0]), MAX_DIST);
-					if (!slot_dist_data)
-						return -1;
-					slot_dist_size = get_distribution(*argv, slot_dist_data, MAX_DIST);
-					if (slot_dist_size <= 0) {
-						free(slot_dist_data);
-						return -1;
-					}
-					NEXT_ARG();
-					if (get_time64(&slot.dist_delay, *argv)) {
-						explain1("slot delay");
-						return -1;
-					}
-					NEXT_ARG();
-					if (get_time64(&slot.dist_jitter, *argv)) {
-						explain1("slot jitter");
-						return -1;
-					}
-					if (slot.dist_jitter <= 0) {
-						fprintf(stderr, "Non-positive jitter\n");
-						return -1;
-					}
-				} else {
-					fprintf(stderr, "Unknown slot parameter: %s\n",
-						*argv);
-					return -1;
-				}
-			}
-			if (NEXT_ARG_OK() &&
-			    matches(*(argv+1), "packets") == 0) {
-				NEXT_ARG();
-				if (!NEXT_ARG_OK() ||
-				    get_s32(&slot.max_packets, *(argv+1), 0)) {
-					explain1("slot packets");
-					return -1;
-				}
-				NEXT_ARG();
-			}
-			if (NEXT_ARG_OK() &&
-			    matches(*(argv+1), "bytes") == 0) {
-				unsigned int max_bytes;
-				NEXT_ARG();
-				if (!NEXT_ARG_OK() ||
-				    get_size(&max_bytes, *(argv+1))) {
-					explain1("slot bytes");
-					return -1;
-				}
-				slot.max_bytes = (int) max_bytes;
-				NEXT_ARG();
-			}
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -577,7 +474,7 @@
 
 	if (present[TCA_NETEM_CORR] &&
 	    addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0)
-		return -1;
+			return -1;
 
 	if (present[TCA_NETEM_REORDER] &&
 	    addattr_l(n, 1024, TCA_NETEM_REORDER, &reorder, sizeof(reorder)) < 0)
@@ -586,16 +483,12 @@
 	if (present[TCA_NETEM_ECN] &&
 	    addattr_l(n, 1024, TCA_NETEM_ECN, &present[TCA_NETEM_ECN],
 		      sizeof(present[TCA_NETEM_ECN])) < 0)
-		return -1;
+			return -1;
 
 	if (present[TCA_NETEM_CORRUPT] &&
 	    addattr_l(n, 1024, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0)
 		return -1;
 
-	if (present[TCA_NETEM_SLOT] &&
-	    addattr_l(n, 1024, TCA_NETEM_SLOT, &slot, sizeof(slot)) < 0)
-		return -1;
-
 	if (loss_type != NETEM_LOSS_UNSPEC) {
 		struct rtattr *start;
 
@@ -603,11 +496,11 @@
 		if (loss_type == NETEM_LOSS_GI) {
 			if (addattr_l(n, 1024, NETEM_LOSS_GI,
 				      &gimodel, sizeof(gimodel)) < 0)
-				return -1;
+			    return -1;
 		} else if (loss_type == NETEM_LOSS_GE) {
 			if (addattr_l(n, 1024, NETEM_LOSS_GE,
 				      &gemodel, sizeof(gemodel)) < 0)
-				return -1;
+			    return -1;
 		} else {
 			fprintf(stderr, "loss in the weeds!\n");
 			return -1;
@@ -636,14 +529,6 @@
 			return -1;
 		free(dist_data);
 	}
-
-	if (slot_dist_data) {
-		if (addattr_l(n, MAX_DIST * sizeof(slot_dist_data[0]),
-			      TCA_NETEM_SLOT_DIST,
-			      slot_dist_data, slot_dist_size * sizeof(slot_dist_data[0])) < 0)
-			return -1;
-		free(slot_dist_data);
-	}
 	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
@@ -658,16 +543,13 @@
 	int *ecn = NULL;
 	struct tc_netem_qopt qopt;
 	const struct tc_netem_rate *rate = NULL;
-	const struct tc_netem_slot *slot = NULL;
-	int len;
+	int len = RTA_PAYLOAD(opt) - sizeof(qopt);
 	__u64 rate64 = 0;
-
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
 		return 0;
 
-	len = RTA_PAYLOAD(opt) - sizeof(qopt);
 	if (len < 0) {
 		fprintf(stderr, "options size error\n");
 		return -1;
@@ -676,7 +558,6 @@
 
 	if (len > 0) {
 		struct rtattr *tb[TCA_NETEM_MAX+1];
-
 		parse_rtattr(tb, TCA_NETEM_MAX, RTA_DATA(opt) + sizeof(qopt),
 			     len);
 
@@ -719,122 +600,91 @@
 				return -1;
 			rate64 = rta_getattr_u64(tb[TCA_NETEM_RATE64]);
 		}
-		if (tb[TCA_NETEM_SLOT]) {
-			if (RTA_PAYLOAD(tb[TCA_NETEM_SLOT]) < sizeof(*slot))
-				return -1;
-			slot = RTA_DATA(tb[TCA_NETEM_SLOT]);
-		}
 	}
 
-	print_uint(PRINT_ANY, "limit", "limit %d", qopt.limit);
+	fprintf(f, "limit %d", qopt.limit);
 
 	if (qopt.latency) {
-		open_json_object("delay");
-		if (!is_json_context()) {
-			print_string(PRINT_FP, NULL, " delay %s",
-				     sprint_ticks(qopt.latency, b1));
+		fprintf(f, " delay %s", sprint_ticks(qopt.latency, b1));
 
-			if (qopt.jitter)
-				print_string(PRINT_FP, NULL, "  %s",
-					     sprint_ticks(qopt.jitter, b1));
-		} else {
-			print_float(PRINT_JSON, "delay", NULL,
-				    tc_core_tick2time(qopt.latency) /
-				    1000000.);
-			print_float(PRINT_JSON, "jitter", NULL,
-				    tc_core_tick2time(qopt.jitter) /
-				    1000000.);
+		if (qopt.jitter) {
+			fprintf(f, "  %s", sprint_ticks(qopt.jitter, b1));
+			if (cor && cor->delay_corr)
+				fprintf(f, " %s", sprint_percent(cor->delay_corr, b1));
 		}
-		print_corr(qopt.jitter && cor && cor->delay_corr,
-			   cor ? cor->delay_corr : 0);
-		close_json_object();
 	}
 
 	if (qopt.loss) {
-		open_json_object("loss-random");
-		PRINT_PERCENT("loss", qopt.loss);
-		print_corr(cor && cor->loss_corr, cor ? cor->loss_corr : 0);
-		close_json_object();
+		fprintf(f, " loss %s", sprint_percent(qopt.loss, b1));
+		if (cor && cor->loss_corr)
+			fprintf(f, " %s", sprint_percent(cor->loss_corr, b1));
 	}
 
 	if (gimodel) {
-		open_json_object("loss-state");
-		__PRINT_PERCENT("p13", " loss state p13", gimodel->p13);
-		PRINT_PERCENT("p31", gimodel->p31);
-		PRINT_PERCENT("p32", gimodel->p32);
-		PRINT_PERCENT("p23", gimodel->p23);
-		PRINT_PERCENT("p14", gimodel->p14);
-		close_json_object();
+		fprintf(f, " loss state p13 %s", sprint_percent(gimodel->p13, b1));
+		fprintf(f, " p31 %s", sprint_percent(gimodel->p31, b1));
+		fprintf(f, " p32 %s", sprint_percent(gimodel->p32, b1));
+		fprintf(f, " p23 %s", sprint_percent(gimodel->p23, b1));
+		fprintf(f, " p14 %s", sprint_percent(gimodel->p14, b1));
 	}
 
 	if (gemodel) {
-		open_json_object("loss-gemodel");
-		__PRINT_PERCENT("p", " loss gemodel p", gemodel->p);
-		PRINT_PERCENT("r", gemodel->r);
-		PRINT_PERCENT("1-h", UINT32_MAX - gemodel->h);
-		PRINT_PERCENT("1-k", gemodel->k1);
-		close_json_object();
+		fprintf(f, " loss gemodel p %s",
+			sprint_percent(gemodel->p, b1));
+		fprintf(f, " r %s", sprint_percent(gemodel->r, b1));
+		fprintf(f, " 1-h %s", sprint_percent(max_percent_value -
+						     gemodel->h, b1));
+		fprintf(f, " 1-k %s", sprint_percent(gemodel->k1, b1));
 	}
 
 	if (qopt.duplicate) {
-		open_json_object("duplicate");
-		PRINT_PERCENT("duplicate", qopt.duplicate);
-		print_corr(cor && cor->dup_corr, cor ? cor->dup_corr : 0);
-		close_json_object();
+		fprintf(f, " duplicate %s",
+			sprint_percent(qopt.duplicate, b1));
+		if (cor && cor->dup_corr)
+			fprintf(f, " %s", sprint_percent(cor->dup_corr, b1));
 	}
 
 	if (reorder && reorder->probability) {
-		open_json_object("reorder");
-		PRINT_PERCENT("reorder", reorder->probability);
-		print_corr(reorder->correlation, reorder->correlation);
-		close_json_object();
+		fprintf(f, " reorder %s",
+			sprint_percent(reorder->probability, b1));
+		if (reorder->correlation)
+			fprintf(f, " %s",
+				sprint_percent(reorder->correlation, b1));
 	}
 
 	if (corrupt && corrupt->probability) {
-		open_json_object("corrupt");
-		PRINT_PERCENT("corrupt", corrupt->probability);
-		print_corr(corrupt->correlation, corrupt->correlation);
-		close_json_object();
+		fprintf(f, " corrupt %s",
+			sprint_percent(corrupt->probability, b1));
+		if (corrupt->correlation)
+			fprintf(f, " %s",
+				sprint_percent(corrupt->correlation, b1));
 	}
 
 	if (rate && rate->rate) {
-		open_json_object("rate");
-		rate64 = rate64 ? : rate->rate;
-		print_string(PRINT_FP, NULL, " rate %s",
-			     sprint_rate(rate64, b1));
-		print_lluint(PRINT_JSON, "rate", NULL, rate64);
-		PRINT_INT_OPT("packetoverhead", rate->packet_overhead);
-		print_uint(PRINT_ANY, "cellsize",
-			   rate->cell_size ? " cellsize %u" : "",
-			   rate->cell_size);
-		PRINT_INT_OPT("celloverhead", rate->cell_overhead);
-		close_json_object();
+		if (rate64)
+			fprintf(f, " rate %s", sprint_rate(rate64, b1));
+		else
+			fprintf(f, " rate %s", sprint_rate(rate->rate, b1));
+		if (rate->packet_overhead)
+			fprintf(f, " packetoverhead %d", rate->packet_overhead);
+		if (rate->cell_size)
+			fprintf(f, " cellsize %u", rate->cell_size);
+		if (rate->cell_overhead)
+			fprintf(f, " celloverhead %d", rate->cell_overhead);
 	}
 
-	if (slot) {
-		open_json_object("slot");
-		if (slot->dist_jitter > 0) {
-			__PRINT_TIME64("distribution", " slot distribution",
-				       slot->dist_delay);
-			__PRINT_TIME64("jitter", "", slot->dist_jitter);
-		} else {
-			__PRINT_TIME64("min-delay", " slot", slot->min_delay);
-			__PRINT_TIME64("max-delay", "", slot->max_delay);
-		}
-		PRINT_INT_OPT("packets", slot->max_packets);
-		PRINT_INT_OPT("bytes", slot->max_bytes);
-		close_json_object();
-	}
+	if (ecn)
+		fprintf(f, " ecn ");
 
-	print_bool(PRINT_ANY, "ecn", ecn ? " ecn " : "", ecn);
-	print_luint(PRINT_ANY, "gap", qopt.gap ? " gap %lu" : "",
-		    (unsigned long)qopt.gap);
+	if (qopt.gap)
+		fprintf(f, " gap %lu", (unsigned long)qopt.gap);
+
 
 	return 0;
 }
 
 struct qdisc_util netem_qdisc_util = {
-	.id		= "netem",
+	.id	   	= "netem",
 	.parse_qopt	= netem_parse_opt,
 	.print_qopt	= netem_print_opt,
 };
diff --git a/tc/q_nss.c b/tc/q_nss.c
deleted file mode 100644
index e84166d..0000000
--- a/tc/q_nss.c
+++ /dev/null
@@ -1,1411 +0,0 @@
-/*
- **************************************************************************
- * Copyright (c) 2015, The Linux Foundation. All rights reserved.
- * Permission to use, copy, modify, and/or distribute this software for
- * any purpose with or without fee is hereby granted, provided that the
- * above copyright notice and this permission notice appear in all copies.
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- **************************************************************************
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <math.h>
-
-#include "utils.h"
-#include "tc_util.h"
-#include "tc_red.h"
-
-/* ======================== NSSWRED =======================*/
-
-static void nssred_explain(void)
-{
-	fprintf(stderr, "Usage: ...  nssred limit BYTES avpkt BYTES [ min BYTES ] [ max BYTES ] [ probability VALUE ]\n");
-	fprintf(stderr, "                   [ burst PACKETS ] [ecn] [ set_default ]\n");
-}
-
-static void nsswred_explain(void)
-{
-	fprintf(stderr, "Usage: ...  nsswred setup DPs NUMBER dp_default NUMBER [ weight_mode dscp ] [ecn] [ set_default ]\n");
-	fprintf(stderr, "            nsswred limit BYTES DP NUMBER min BYTES max BYTES avpkt BYTES dscp NUMBER [ probability VALUE ] [ burst PACKETS ]\n");
-}
-
-static int nsswred_setup(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct rtattr *tail;
-	struct tc_nsswred_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-	unsigned int dps = 0;
-	unsigned int def_dp = 0;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "DPs") == 0) {
-			NEXT_ARG();
-			if (get_unsigned(&dps, *argv, 0) || dps > NSSWRED_CLASS_MAX) {
-
-				fprintf(stderr, "NSSWRED: DPs should be between 1 - %d\n", NSSWRED_CLASS_MAX);
-				return -1;
-			}
-		} else if (strcmp(*argv, "weight_mode") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "dscp") == 0) {
-				opt.weight_mode = TC_NSSWRED_WEIGHT_MODE_DSCP;
-			} else {
-				fprintf(stderr, "Illegal \"weight_mode\", we only support dscp at this moment\n");
-			}
-		} else if (strcmp(*argv, "ecn") == 0) {
-			opt.ecn = 1;
-		} else if (strcmp(*argv, "dp_default") == 0) {
-			NEXT_ARG();
-			if (get_unsigned(&def_dp, *argv, 0) || def_dp > dps) {
-				fprintf(stderr, "NSSWRED: Illegal dp_default value\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "help") == 0) {
-			nsswred_explain();
-			return -1;
-		} else if (strcmp(*argv, "set_default") == 0) {
-			opt.set_default = 1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nsswred_explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!dps || !def_dp) {
-		fprintf(stderr, "NSSWRED: Illegal nsswred setup parameters\n");
-		return -1;
-	}
-	opt.traffic_classes = dps;
-	opt.def_traffic_class = def_dp;
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSWRED_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsswred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct rtattr *tail;
-	struct tc_nsswred_qopt opt;
-
-	int total_args = argc;
-	unsigned burst = 0;
-	unsigned avpkt = 0;
-	double probability = 0.0;
-	unsigned char weighted = (strcmp(qu->id, "nsswred") == 0);
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "limit") == 0) {
-			NEXT_ARG();
-			if (get_size(&opt.limit, *argv)) {
-				fprintf(stderr, "Illegal \"limit\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "set_default") == 0) {
-			opt.set_default = 1;
-		} else if (strcmp(*argv, "min") == 0) {
-			NEXT_ARG();
-			if (get_size(&opt.rap.min, *argv)) {
-				fprintf(stderr, "Illegal \"min\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "max") == 0) {
-			NEXT_ARG();
-			if (get_size(&opt.rap.max, *argv)) {
-				fprintf(stderr, "Illegal \"max\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "burst") == 0) {
-			NEXT_ARG();
-			if (get_unsigned(&burst, *argv, 0)) {
-				fprintf(stderr, "Illegal \"burst\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "avpkt") == 0) {
-			NEXT_ARG();
-			if (get_size(&avpkt, *argv)) {
-				fprintf(stderr, "Illegal \"avpkt\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "probability") == 0) {
-			NEXT_ARG();
-			if (sscanf(*argv, "%lg", &probability) != 1) {
-				fprintf(stderr, "Illegal \"probability\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "ecn") == 0) {
-			opt.ecn = 1;
-		} else if (strcmp(*argv, "help") == 0) {
-			if (weighted) {
-				nsswred_explain();
-			} else {
-				nssred_explain();
-			}
-			return -1;
-		} else if (weighted) {
-			if (strcmp(*argv, "setup") == 0) {
-				if (argc != total_args) {
-					fprintf(stderr, "Setup command must be the first parameter\n");
-					return -1;
-				}
-				return nsswred_setup(qu, argc-1, argv+1, n);
-			} else if (strcmp(*argv, "DP") == 0) {
-				NEXT_ARG();
-				if (get_unsigned(&opt.traffic_id, *argv, 0)) {
-					fprintf(stderr, "Illegal \"DP\"");
-					return -1;
-				}
-			} else if (strcmp(*argv, "dscp") == 0) {
-				NEXT_ARG();
-				if (get_unsigned(&opt.weight_mode_value, *argv, 0)) {
-					fprintf(stderr, "Illegal \"dscp\" value\n");
-					return -1;
-				}
-			}
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			if (weighted) {
-				nsswred_explain();
-			} else {
-				nssred_explain();
-			}
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (weighted) {
-		if (!opt.limit || !opt.rap.min || !opt.rap.max || !opt.traffic_id || !avpkt || !opt.weight_mode_value) {
-			fprintf(stderr, "NSSWRED: Require limit, min, max, avpkt, DP, weight_mode_value\n");
-			return -1;
-		}
-	} else {
-		if (!opt.limit || !avpkt) {
-			fprintf(stderr, "NSSRED: Require limit, avpkt");
-			return -1;
-		}
-	}
-
-	/*
-	 * Compute default min/max thresholds based on
-	 * Sally Floyd's recommendations:
-	 * http://www.icir.org/floyd/REDparameters.txt
-	 */
-	if (!opt.rap.max)
-		opt.rap.max = opt.rap.min ? opt.rap.min * 3 : opt.limit / 4;
-	if (!opt.rap.min)
-		opt.rap.min = opt.rap.max / 3;
-	if (!burst)
-		burst = (2 * opt.rap.min + opt.rap.max) / (3 * avpkt);
-	if ((opt.rap.exp_weight_factor = tc_red_eval_ewma(opt.rap.min, burst, avpkt)) < 0) {
-		fprintf(stderr, "RED: failed to calculate EWMA constant.\n");
-		return -1;
-	}
-
-	/*
-	 * project [0.0-1.0] to [0-255] to avoid floating point calculation
-	 */
-	opt.rap.probability = probability * (pow(2, 8)-1);
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSWRED_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsswred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSWRED_MAX + 1];
-	struct tc_nsswred_qopt *qopt;
-	int i;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSWRED_MAX, opt);
-
-	if (tb[TCA_NSSWRED_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSWRED_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSWRED_PARMS]);
-
-	if (strcmp(qu->id, "nsswred") == 0) {
-		fprintf(f, "DPs %d def_DP %d weight mode: " , qopt->traffic_classes, qopt->def_traffic_class);
-		if (qopt->weight_mode == TC_NSSWRED_WEIGHT_MODE_DSCP)
-			fprintf(f, "DSCP\n");
-		else
-			fprintf(f, "Unknown\n");
-		for (i = 0;i < qopt->traffic_classes; i ++) {
-			if (qopt->tntc[i].rap.exp_weight_factor) {
-				double prob = (double)qopt->tntc[i].rap.probability;
-				fprintf(f, "DP %d: limit %d, weight mode value: %d min: %d max: %d exp_weight_factor: %d probability %.2f\n", i+1, qopt->tntc[i].limit, qopt->tntc[i].weight_mode_value
-						, qopt->tntc[i].rap.min,qopt->tntc[i].rap.max,qopt->tntc[i].rap.exp_weight_factor,prob/255);
-			}
-		}
-	} else {
-		double prob = (double)qopt->rap.probability;
-		fprintf(f, "limit %d, min: %d max: %d exp_weight_factor: %d probability %.2f\n", qopt->limit, qopt->rap.min,qopt->rap.max,qopt->rap.exp_weight_factor,prob/255);
-	}
-
-	if (qopt->ecn)
-		fprintf(f, "ECN enabled ");
-        if (qopt->set_default)
-                fprintf(f, "set_default ");
-
-	return 0;
-}
-
-struct qdisc_util nssred_qdisc_util = {
-	.id		= "nssred",
-	.parse_qopt	= nsswred_parse_opt,
-	.print_qopt	= nsswred_print_opt,
-};
-
-struct qdisc_util nsswred_qdisc_util = {
-	.id		= "nsswred",
-	.parse_qopt	= nsswred_parse_opt,
-	.print_qopt	= nsswred_print_opt,
-};
-
-/* ======================== NSSFIFO =======================*/
-
-static void nssfifo_explain(void)
-{
-	fprintf(stderr, "Usage: ...  nsspfifo [ limit PACKETS ] [ set_default ]\n");
-}
-
-static int nssfifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct rtattr *tail;
-	struct tc_nssfifo_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "limit") == 0) {
-			NEXT_ARG();
-			if (get_size(&opt.limit, *argv) || opt.limit == 0) {
-				fprintf(stderr, "Illegal \"limit\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "set_default") == 0) {
-			opt.set_default = 1;
-		} else if (strcmp(*argv, "help") == 0) {
-			nssfifo_explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nssfifo_explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSFIFO_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nssfifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSFIFO_MAX + 1];
-	struct tc_nssfifo_qopt *qopt;
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSFIFO_MAX, opt);
-
-	if (tb[TCA_NSSFIFO_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSFIFO_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSFIFO_PARMS]);
-
-	if (strcmp(qu->id, "nssbfifo") == 0)
-		fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));
-	else
-		fprintf(f, "limit %up ", qopt->limit);
-
-	if (qopt->set_default)
-		fprintf(f, "set_default ");
-
-	return 0;
-}
-
-struct qdisc_util nsspfifo_qdisc_util = {
-	.id		= "nsspfifo",
-	.parse_qopt	= nssfifo_parse_opt,
-	.print_qopt	= nssfifo_print_opt,
-};
-
-struct qdisc_util nssbfifo_qdisc_util = {
-	.id		= "nssbfifo",
-	.parse_qopt	= nssfifo_parse_opt,
-	.print_qopt	= nssfifo_print_opt,
-};
-
-/* ======================== NSSCODEL =======================*/
-
-static void nsscodel_explain(void)
-{
-	fprintf(stderr, "Usage: ... nsscodel target TIME interval TIME [ limit PACKETS ] [ set_default ]\n");
-}
-
-static void nsscodel_explain_err1(void)
-{
-	fprintf(stderr, "Value of target and interval should be greater than 1ms\n");
-}
-
-static int nsscodel_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct rtattr *tail;
-	struct tc_nsscodel_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "target") == 0) {
-			NEXT_ARG();
-			if (get_time(&opt.target, *argv)) {
-				fprintf(stderr, "Illegal \"target\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "limit") == 0) {
-			NEXT_ARG();
-			if (get_size(&opt.limit, *argv) || opt.limit == 0) {
-				fprintf(stderr, "Illegal \"limit\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "interval") == 0) {
-			NEXT_ARG();
-			if (get_time(&opt.interval, *argv)) {
-				fprintf(stderr, "Illegal \"interval\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "set_default") == 0) {
-			opt.set_default = 1;
-		} else if (strcmp(*argv, "help") == 0) {
-			nsscodel_explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nsscodel_explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!opt.target || !opt.interval) {
-		nsscodel_explain();
-		return -1;
-	}
-
-	if (opt.target < 1000 || opt.interval < 1000) {
-		nsscodel_explain_err1();
-		return -1;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSCODEL_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsscodel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSCODEL_MAX + 1];
-	struct tc_nsscodel_qopt *qopt;
-	SPRINT_BUF(b1);
-	SPRINT_BUF(b2);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSCODEL_MAX, opt);
-
-	if (tb[TCA_NSSCODEL_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSCODEL_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSCODEL_PARMS]);
-
-	fprintf(f, "target %s limit %up interval %s ",
-		sprint_time(qopt->target, b1),
-		qopt->limit,
-		sprint_time(qopt->interval, b2));
-
-	if (qopt->set_default)
-		fprintf(f, "set_default ");
-
-	return 0;
-}
-
-static int nsscodel_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
-{
-	struct tc_nsscodel_xstats *st;
-
-	if (xstats == NULL)
-		return 0;
-
-	if (RTA_PAYLOAD(xstats) < sizeof(*st))
-		return -1;
-
-	st = RTA_DATA(xstats);
-	fprintf(f, " peak queue delay %ums peak drop delay %ums",
-			st->peak_queue_delay, st->peak_drop_delay);
-
-	return 0;
-}
-
-struct qdisc_util nsscodel_qdisc_util = {
-	.id		= "nsscodel",
-	.parse_qopt	= nsscodel_parse_opt,
-	.print_qopt	= nsscodel_print_opt,
-	.print_xstats	= nsscodel_print_xstats,
-};
-
-/* ======================== NSSTBL =======================*/
-
-static void nsstbl_explain(void)
-{
-	fprintf(stderr, "Usage: ... nsstbl burst BYTES rate BPS [ mtu BYTES ]\n");
-}
-
-static int nsstbl_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	int ok = 0;
-	struct rtattr *tail;
-	struct tc_nsstbl_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "burst") == 0 ||
-			   strcmp(*argv, "buffer") == 0 ||
-			   strcmp(*argv, "maxburst") == 0) {
-			NEXT_ARG();
-			if (opt.burst) {
-				fprintf(stderr, "Double \"buffer/burst\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.burst, *argv)) {
-				fprintf(stderr, "Illegal \"burst\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "mtu") == 0 ||
-			   strcmp(*argv, "minburst") == 0) {
-			NEXT_ARG();
-			if (opt.mtu) {
-				fprintf(stderr, "Double \"mtu/minburst\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.mtu, *argv)) {
-				fprintf(stderr, "Illegal \"mtu\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "rate") == 0) {
-			NEXT_ARG();
-			if (opt.rate) {
-				fprintf(stderr, "Double \"rate\" spec\n");
-				return -1;
-			}
-			if (get_rate(&opt.rate, *argv)) {
-				fprintf(stderr, "Illegal \"rate\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			nsstbl_explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nsstbl_explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!ok) {
-		nsstbl_explain();
-		return -1;
-	}
-
-	if (!opt.rate || !opt.burst) {
-		fprintf(stderr, "Both \"rate\" and \"burst\" are required.\n");
-		return -1;
-	}
-
-	if (opt.peakrate) {
-		if (!opt.mtu) {
-			fprintf(stderr, "\"mtu\" is required, if \"peakrate\" is requested.\n");
-			return -1;
-		}
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSTBL_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsstbl_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSTBL_MAX + 1];
-	struct tc_nsstbl_qopt *qopt;
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSTBL_MAX, opt);
-
-	if (tb[TCA_NSSTBL_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSTBL_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSTBL_PARMS]);
-
-	fprintf(f, "buffer/maxburst %s ", sprint_size(qopt->burst, b1));
-	fprintf(f, "rate %s ", sprint_rate(qopt->rate, b1));
-	fprintf(f, "peakrate %s ", sprint_rate(qopt->peakrate, b1));
-	fprintf(f, "mtu/minburst %s ", sprint_size(qopt->mtu, b1));
-	return 0;
-}
-
-struct qdisc_util nsstbl_qdisc_util = {
-	.id		= "nsstbl",
-	.parse_qopt	= nsstbl_parse_opt,
-	.print_qopt	= nsstbl_print_opt,
-};
-
-/* ======================== NSSPRIO =======================*/
-
-static void nssprio_explain(void)
-{
-	fprintf(stderr, "Usage: ... nssprio [ bands NUMBER (default 256) ]\n");
-}
-
-static int nssprio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	int ok = 0;
-	struct rtattr *tail;
-	struct tc_nssprio_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "bands") == 0) {
-			NEXT_ARG();
-			if (get_integer(&opt.bands, *argv, 10)) {
-				fprintf(stderr, "Illegal \"limit\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			nssprio_explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nssprio_explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!ok) {
-		opt.bands = TCA_NSSPRIO_MAX_BANDS;
-	} else if (opt.bands > TCA_NSSPRIO_MAX_BANDS) {
-		nssprio_explain();
-		return -1;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSPRIO_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nssprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSPRIO_MAX + 1];
-	struct tc_nssprio_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSPRIO_MAX, opt);
-
-	if (tb[TCA_NSSPRIO_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSPRIO_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSPRIO_PARMS]);
-
-	fprintf(f, "bands %u ", qopt->bands);
-
-	return 0;
-}
-
-struct qdisc_util nssprio_qdisc_util = {
-	.id		= "nssprio",
-	.parse_qopt	= nssprio_parse_opt,
-	.print_qopt	= nssprio_print_opt,
-};
-
-/* ======================== NSSBF =======================*/
-
-static void nssbf_explain_qdisc(void)
-{
-	fprintf(stderr,
-		"Usage: ... nssbf \n"
-	);
-}
-
-static void nssbf_explain_class(void)
-{
-	fprintf(stderr, "Usage: ... nssbf rate BPS burst BYTES [ mtu BYTES ]\n");
-	fprintf(stderr, "                 [ quantum BYTES ]\n");
-}
-
-static void nssbf_explain1(char *arg)
-{
-	fprintf(stderr, "NSSBF: Illegal \"%s\"\n", arg);
-}
-
-static int nssbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct tc_nssbf_qopt opt;
-	struct rtattr *tail;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (matches(*argv, "default") == 0) {
-			NEXT_ARG();
-			if (opt.defcls != 0) {
-				fprintf(stderr, "NSSBF: Double \"default\"\n");
-				return -1;
-			}
-			if (get_u16(&opt.defcls, *argv, 16) < 0) {
-				nssbf_explain1("default");
-				return -1;
-			}
-		} else if (matches(*argv, "help") == 0) {
-			nssbf_explain_qdisc();
-			return -1;
-		} else {
-			fprintf(stderr, "NSSBF: What is \"%s\" ?\n", *argv);
-			nssbf_explain_qdisc();
-			return -1;
-		}
-		argc--, argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSBF_QDISC_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nssbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct tc_nssbf_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-	if (RTA_PAYLOAD(opt) < sizeof(*qopt))
-		return -1;
-	qopt = RTA_DATA(opt);
-
-	if (qopt->defcls != 0)
-		fprintf(f, "default %x ", qopt->defcls);
-
-	return 0;
-}
-
-static int nssbf_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	int ok = 0;
-	struct rtattr *tail;
-	struct tc_nssbf_class_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "burst") == 0 ||
-			   strcmp(*argv, "buffer") == 0 ||
-			   strcmp(*argv, "maxburst") == 0) {
-			NEXT_ARG();
-			if (opt.burst) {
-				fprintf(stderr, "Double \"buffer/burst\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.burst, *argv)) {
-				fprintf(stderr, "Illegal \"burst\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "mtu") == 0) {
-			NEXT_ARG();
-			if (opt.mtu) {
-				fprintf(stderr, "Double \"mtu\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.mtu, *argv)) {
-				fprintf(stderr, "Illegal \"mtu\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "quantum") == 0) {
-			NEXT_ARG();
-			if (opt.quantum) {
-				fprintf(stderr, "Double \"quantum\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.quantum, *argv)) {
-				fprintf(stderr, "Illegal \"quantum\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "rate") == 0) {
-			NEXT_ARG();
-			if (opt.rate) {
-				fprintf(stderr, "Double \"rate\" spec\n");
-				return -1;
-			}
-			if (get_rate(&opt.rate, *argv)) {
-				fprintf(stderr, "Illegal \"rate\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			nssbf_explain_class();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nssbf_explain_class();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!ok) {
-		nssbf_explain_class();
-		return -1;
-	}
-
-	if (!opt.rate || !opt.burst) {
-		fprintf(stderr, "Both \"rate\" and \"burst\" are required.\n");
-		return -1;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSBF_CLASS_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nssbf_print_class_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSBF_MAX + 1];
-	struct tc_nssbf_class_qopt *qopt;
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSBF_MAX, opt);
-
-	if (tb[TCA_NSSBF_CLASS_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSBF_CLASS_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSBF_CLASS_PARMS]);
-
-	fprintf(f, "burst %s ", sprint_size(qopt->burst, b1));
-	fprintf(f, "rate %s ", sprint_rate(qopt->rate, b1));
-	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
-	fprintf(f, "mtu %s ", sprint_size(qopt->mtu, b1));
-	return 0;
-}
-
-struct qdisc_util nssbf_qdisc_util = {
-	.id		= "nssbf",
-	.parse_qopt	= nssbf_parse_opt,
-	.print_qopt	= nssbf_print_opt,
-	.parse_copt	= nssbf_parse_class_opt,
-	.print_copt	= nssbf_print_class_opt,
-};
-
-/* ======================== NSSWRR =======================*/
-
-static void nsswrr_explain_qdisc(void)
-{
-	fprintf(stderr,
-		"Usage (qdisc): ... nsswrr\n"
-		"\n"
-		"nsswrr qdisc does not take in any parameters\n"
-	);
-}
-
-static void nsswrr_explain_class(void)
-{
-	fprintf(stderr, "Usage (class): ... nsswrr quantum PACKETS ]\n");
-}
-
-static int nsswrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	while (argc > 0) {
-		if (matches(*argv, "help") == 0) {
-			nsswrr_explain_qdisc();
-			return -1;
-		} else {
-			fprintf(stderr, "NSSWRR: What is \"%s\" ?\n", *argv);
-			nsswrr_explain_qdisc();
-			return -1;
-		}
-		argc--, argv++;
-	}
-
-	return 0;
-}
-
-static int nsswrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	/*
-	 * We currently dont have any parameters to print
-	 */
-
-	return 0;
-}
-
-static int nsswrr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	int ok = 0;
-	struct rtattr *tail;
-	struct tc_nsswrr_class_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "quantum") == 0) {
-			NEXT_ARG();
-			if (get_u32(&opt.quantum, *argv, 10)) {
-				fprintf(stderr, "Illegal \"quantum\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			nsswrr_explain_class();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nsswrr_explain_class();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!ok) {
-		nsswrr_explain_class();
-		return -1;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSWRR_CLASS_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsswrr_print_class_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSWRR_MAX + 1];
-	struct tc_nsswrr_class_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSWRR_MAX, opt);
-
-	if (tb[TCA_NSSWRR_CLASS_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSWRR_CLASS_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSWRR_CLASS_PARMS]);
-
-	fprintf(f, "quantum %up ", qopt->quantum);
-	return 0;
-}
-
-struct qdisc_util nsswrr_qdisc_util = {
-	.id		= "nsswrr",
-	.parse_qopt	= nsswrr_parse_opt,
-	.print_qopt	= nsswrr_print_opt,
-	.parse_copt	= nsswrr_parse_class_opt,
-	.print_copt	= nsswrr_print_class_opt,
-};
-
-/* ======================== NSSWFQ =======================*/
-
-static void nsswfq_explain_qdisc(void)
-{
-	fprintf(stderr,
-		"Usage (qdisc): ... nsswfq\n"
-		"\n"
-		"nsswfq qdisc does not take in any parameters\n"
-	);
-}
-
-static void nsswfq_explain_class(void)
-{
-	fprintf(stderr, "Usage (class): ... nsswfq quantum BYTES ]\n");
-}
-
-static int nsswfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	while (argc > 0) {
-		if (matches(*argv, "help") == 0) {
-			nsswfq_explain_qdisc();
-			return -1;
-		} else {
-			fprintf(stderr, "NSSWFQ: What is \"%s\" ?\n", *argv);
-			nsswfq_explain_qdisc();
-			return -1;
-		}
-		argc--, argv++;
-	}
-	return 0;
-}
-
-static int nsswfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	/*
-	 * We currently dont have any parameters to print
-	 */
-	return 0;
-}
-
-static int nsswfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	int ok = 0;
-	struct rtattr *tail;
-	struct tc_nsswfq_class_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "quantum") == 0) {
-			NEXT_ARG();
-			if (get_u32(&opt.quantum, *argv, 10)) {
-				fprintf(stderr, "Illegal \"quantum\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			nsswfq_explain_class();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nsswfq_explain_class();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!ok) {
-		nsswfq_explain_class();
-		return -1;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSWFQ_CLASS_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsswfq_print_class_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSWFQ_MAX + 1];
-	struct tc_nsswfq_class_qopt *qopt;
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSWFQ_MAX, opt);
-
-	if (tb[TCA_NSSWFQ_CLASS_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSWFQ_CLASS_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSWFQ_CLASS_PARMS]);
-
-	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
-	return 0;
-}
-
-struct qdisc_util nsswfq_qdisc_util = {
-	.id		= "nsswfq",
-	.parse_qopt	= nsswfq_parse_opt,
-	.print_qopt	= nsswfq_print_opt,
-	.parse_copt	= nsswfq_parse_class_opt,
-	.print_copt	= nsswfq_print_class_opt,
-};
-
-/* ======================== NSSHTB =======================*/
-
-static void nsshtb_explain_qdisc(void)
-{
-	fprintf(stderr,
-		"Usage: ... nsshtb [ r2q ]\n"
-	);
-}
-
-static void nsshtb_explain_class(void)
-{
-	fprintf(stderr, "Usage: ... nsshtb priority 0-3 [ quantum BYTES ] [ rate BPS ] [ burst BYTES ] [crate BPS ] [ cburst BYTES ]\n");
-	fprintf(stderr, "                 [ overhead BYTES ] \n");
-}
-
-static void nsshtb_explain1(char *arg)
-{
-	fprintf(stderr, "NSSHTB: Illegal \"%s\"\n", arg);
-}
-
-static int nsshtb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct tc_nsshtb_qopt opt;
-	struct rtattr *tail;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "r2q") == 0) {
-			NEXT_ARG();
-			if (opt.r2q != 0) {
-				fprintf(stderr, "NSSHTB: Double \"r2q\"\n");
-				return -1;
-			}
-			if (get_u32(&opt.r2q, *argv, 10) < 0) {
-				nsshtb_explain1("r2q");
-				return -1;
-			}
-		} else if (strcmp(*argv, "help") == 0) {
-			nsshtb_explain_qdisc();
-			return -1;
-		} else {
-			fprintf(stderr, "NSSHTB: What is \"%s\" ?\n", *argv);
-			nsshtb_explain_qdisc();
-			return -1;
-		}
-		argc--, argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSHTB_QDISC_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsshtb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct tc_nsshtb_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-	if (RTA_PAYLOAD(opt) < sizeof(*qopt))
-		return -1;
-	qopt = RTA_DATA(opt);
-
-	if (qopt->r2q != 0)
-		fprintf(f, "r2q %x ", qopt->r2q);
-
-	return 0;
-}
-
-static int nsshtb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	int ok = 0;
-	struct rtattr *tail;
-	struct tc_nsshtb_class_qopt opt;
-	int crate = 0;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "burst") == 0) {
-			NEXT_ARG();
-			if (opt.burst) {
-				fprintf(stderr, "Double \"burst\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.burst, *argv)) {
-				fprintf(stderr, "Illegal \"burst\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "rate") == 0) {
-			NEXT_ARG();
-			if (opt.rate) {
-				fprintf(stderr, "Double \"rate\" spec\n");
-				return -1;
-			}
-			if (get_rate(&opt.rate, *argv)) {
-				fprintf(stderr, "Illegal \"rate\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "cburst") == 0) {
-			NEXT_ARG();
-			if (opt.cburst) {
-				fprintf(stderr, "Double \"cburst\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.cburst, *argv)) {
-				fprintf(stderr, "Illegal \"cburst\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "crate") == 0) {
-			NEXT_ARG();
-			if (opt.crate) {
-				fprintf(stderr, "Double \"crate\" spec\n");
-				return -1;
-			}
-			if (get_rate(&opt.crate, *argv)) {
-				fprintf(stderr, "Illegal \"crate\"\n");
-				return -1;
-			}
-			crate++;
-			ok++;
-		} else if (strcmp(*argv, "priority") == 0) {
-			NEXT_ARG();
-			if (opt.priority) {
-				fprintf(stderr, "Double \"priority\" spec\n");
-				return -1;
-			}
-			if (get_u32(&opt.priority, *argv, 10) < 0) {
-				fprintf(stderr, "Illegal \"priority\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "quantum") == 0) {
-			NEXT_ARG();
-			if (opt.quantum) {
-				fprintf(stderr, "Double \"quantum\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.quantum, *argv)) {
-				fprintf(stderr, "Illegal \"quantum\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "overhead") == 0) {
-			NEXT_ARG();
-			if (opt.overhead) {
-				fprintf(stderr, "Double \"overhead\" spec\n");
-				return -1;
-			}
-			if (get_size(&opt.overhead, *argv)) {
-				fprintf(stderr, "Illegal \"overhead\"\n");
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			nsshtb_explain_class();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nsshtb_explain_class();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (!ok) {
-		nsshtb_explain_class();
-		return -1;
-	}
-
-	if (opt.rate && !opt.burst) {
-		fprintf(stderr, "\"burst\" required if \"rate\" is specified.\n");
-		return -1;
-	}
-
-	if (!crate) {
-		fprintf(stderr, "\"crate\" is required.\n");
-		return -1;
-	}
-
-	if (opt.crate && !opt.cburst) {
-		fprintf(stderr, "\"cburst\" required if \"crate\" is non-zero.\n");
-		return -1;
-	}
-
-	if (opt.priority > 3) {
-		fprintf(stderr, "\"priority\" should be an integer between 0 and 3.\n");
-		return -1;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSHTB_CLASS_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nsshtb_print_class_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSHTB_MAX + 1];
-	struct tc_nsshtb_class_qopt *qopt;
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSHTB_MAX, opt);
-
-	if (tb[TCA_NSSHTB_CLASS_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSHTB_CLASS_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSHTB_CLASS_PARMS]);
-
-	fprintf(f, "burst %s ", sprint_size(qopt->burst, b1));
-	fprintf(f, "rate %s ", sprint_rate(qopt->rate, b1));
-	fprintf(f, "cburst %s ", sprint_size(qopt->cburst, b1));
-	fprintf(f, "crate %s ", sprint_rate(qopt->crate, b1));
-	fprintf(f, "priority %u ", qopt->priority);
-	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
-	fprintf(f, "overhead %s ", sprint_size(qopt->overhead, b1));
-	return 0;
-}
-
-struct qdisc_util nsshtb_qdisc_util = {
-	.id		= "nsshtb",
-	.parse_qopt	= nsshtb_parse_opt,
-	.print_qopt	= nsshtb_print_opt,
-	.parse_copt	= nsshtb_parse_class_opt,
-	.print_copt	= nsshtb_print_class_opt,
-};
-
-/* ======================== NSSBLACKHOLE ======================= */
-
-static void nssblackhole_explain(void)
-{
-	fprintf(stderr, "Usage: ...  nssblackhole [ set_default ]\n");
-}
-
-static int nssblackhole_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-{
-	struct rtattr *tail;
-	struct tc_nssblackhole_qopt opt;
-
-	memset(&opt, 0, sizeof(opt));
-
-	while (argc > 0) {
-		if (strcmp(*argv, "set_default") == 0) {
-			opt.set_default = 1;
-		} else if (strcmp(*argv, "help") == 0) {
-			nssblackhole_explain();
-			return -1;
-		} else {
-			fprintf(stderr, "What is \"%s\"?\n", *argv);
-			nssblackhole_explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-	addattr_l(n, 1024, TCA_NSSBLACKHOLE_PARMS, &opt, sizeof(opt));
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-	return 0;
-}
-
-static int nssblackhole_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_NSSBLACKHOLE_MAX + 1];
-	struct tc_nssblackhole_qopt *qopt;
-	SPRINT_BUF(b1);
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_NSSBLACKHOLE_MAX, opt);
-
-	if (tb[TCA_NSSBLACKHOLE_PARMS] == NULL)
-		return -1;
-
-	if (RTA_PAYLOAD(tb[TCA_NSSBLACKHOLE_PARMS]) < sizeof(*qopt))
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_NSSBLACKHOLE_PARMS]);
-
-	if (qopt->set_default)
-		fprintf(f, "set_default ");
-
-	return 0;
-}
-
-struct qdisc_util nssblackhole_qdisc_util = {
-	.id		= "nssblackhole",
-	.parse_qopt	= nssblackhole_parse_opt,
-	.print_qopt	= nssblackhole_print_opt,
-};
diff --git a/tc/q_pie.c b/tc/q_pie.c
index 40982f9..193b05d 100644
--- a/tc/q_pie.c
+++ b/tc/q_pie.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -30,17 +31,18 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... pie	[ limit PACKETS ][ target TIME us]\n"
-		"		[ tupdate TIME us][ alpha ALPHA ]"
-		"[beta BETA ][bytemode | nobytemode][ecn | noecn ]\n");
+	fprintf(stderr, "Usage: ... pie [ limit PACKETS ][ target TIME us]\n");
+	fprintf(stderr, "              [ tupdate TIME us][ alpha ALPHA ]");
+	fprintf(stderr, "[beta BETA ][bytemode | nobytemode][ecn | noecn ]\n");
 }
 
 #define ALPHA_MAX 32
+#define ALPHA_MIN 0
 #define BETA_MAX 32
+#define BETA_MIN 0
 
 static int pie_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+			 struct nlmsghdr *n)
 {
 	unsigned int limit   = 0;
 	unsigned int target  = 0;
@@ -73,14 +75,14 @@
 		} else if (strcmp(*argv, "alpha") == 0) {
 			NEXT_ARG();
 			if (get_unsigned(&alpha, *argv, 0) ||
-			    (alpha > ALPHA_MAX)) {
+			    (alpha > ALPHA_MAX) || (alpha < ALPHA_MIN)) {
 				fprintf(stderr, "Illegal \"alpha\"\n");
 				return -1;
 			}
 		} else if (strcmp(*argv, "beta") == 0) {
 			NEXT_ARG();
 			if (get_unsigned(&beta, *argv, 0) ||
-			    (beta > BETA_MAX)) {
+			    (beta > BETA_MAX) || (beta < BETA_MIN)) {
 				fprintf(stderr, "Illegal \"beta\"\n");
 				return -1;
 			}
@@ -104,7 +106,8 @@
 		argv++;
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	if (limit)
 		addattr_l(n, 1024, TCA_PIE_LIMIT, &limit, sizeof(limit));
 	if (tupdate)
@@ -121,7 +124,7 @@
 		addattr_l(n, 1024, TCA_PIE_BYTEMODE, &bytemode,
 			  sizeof(bytemode));
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
 	return 0;
 }
 
@@ -133,9 +136,8 @@
 	unsigned int target;
 	unsigned int alpha;
 	unsigned int beta;
-	unsigned int ecn;
-	unsigned int bytemode;
-
+	unsigned ecn;
+	unsigned bytemode;
 	SPRINT_BUF(b1);
 
 	if (opt == NULL)
@@ -199,7 +201,7 @@
 	st = RTA_DATA(xstats);
 	/*prob is returned as a fracion of maximum integer value */
 	fprintf(f, "prob %f delay %uus avg_dq_rate %u\n",
-		(double)st->prob / UINT64_MAX, st->delay,
+		(double)st->prob / (double)0xffffffff, st->delay,
 		st->avg_dq_rate);
 	fprintf(f, "pkts_in %u overlimit %u dropped %u maxq %u ecn_mark %u\n",
 		st->packets_in, st->overlimit, st->dropped, st->maxq,
diff --git a/tc/q_plug.c b/tc/q_plug.c
deleted file mode 100644
index 2c1c1a0..0000000
--- a/tc/q_plug.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * q_log.c		plug scheduler
- *
- * Copyright (C) 2019	Paolo Abeni <pabeni@redhat.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-static void explain(void)
-{
-	fprintf(stderr, "Usage: ... plug [block | release | release_indefinite | limit NUMBER]\n");
-}
-
-static int plug_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			  struct nlmsghdr *n, const char *dev)
-{
-	struct tc_plug_qopt opt = {};
-	int ok = 0;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "block") == 0) {
-			opt.action = TCQ_PLUG_BUFFER;
-			ok++;
-		} else if (strcmp(*argv, "release") == 0) {
-			opt.action = TCQ_PLUG_RELEASE_ONE;
-			ok++;
-		} else if (strcmp(*argv, "release_indefinite") == 0) {
-			opt.action = TCQ_PLUG_RELEASE_INDEFINITE;
-			ok++;
-		} else if (strcmp(*argv, "limit") == 0) {
-			opt.action = TCQ_PLUG_LIMIT;
-			NEXT_ARG();
-			if (get_size(&opt.limit, *argv)) {
-				fprintf(stderr, "Illegal value for \"limit\": \"%s\"\n", *argv);
-				return -1;
-			}
-			ok++;
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (ok)
-		addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
-	return 0;
-}
-
-static int plug_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	/* dummy implementation as sch_plug does not implement a dump op */
-	return 0;
-}
-
-
-struct qdisc_util plug_qdisc_util = {
-	.id = "plug",
-	.parse_qopt = plug_parse_opt,
-	.print_qopt = plug_print_opt,
-};
diff --git a/tc/q_prio.c b/tc/q_prio.c
index 8ef7cfa..3236bec 100644
--- a/tc/q_prio.c
+++ b/tc/q_prio.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,12 +28,11 @@
 	fprintf(stderr, "Usage: ... prio bands NUMBER priomap P1 P2...[multiqueue]\n");
 }
 
-static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			  struct nlmsghdr *n, const char *dev)
+static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	int pmap_mode = 0;
 	int idx = 0;
-	struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
+	struct tc_prio_qopt opt={3,{ 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }};
 	struct rtattr *nest;
 	unsigned char mq = 0;
 
@@ -57,8 +57,7 @@
 			explain();
 			return -1;
 		} else {
-			unsigned int band;
-
+			unsigned band;
 			if (!pmap_mode) {
 				fprintf(stderr, "What is \"%s\"?\n", *argv);
 				explain();
@@ -105,25 +104,21 @@
 
 	if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt,
 					sizeof(*qopt)))
-		return -1;
+                return -1;
 
-	print_uint(PRINT_ANY, "bands", "bands %u ", qopt->bands);
-	open_json_array(PRINT_ANY, "priomap ");
-	for (i = 0; i <= TC_PRIO_MAX; i++)
-		print_uint(PRINT_ANY, NULL, " %d", qopt->priomap[i]);
-	close_json_array(PRINT_ANY, "");
+	fprintf(f, "bands %u priomap ", qopt->bands);
+	for (i=0; i<=TC_PRIO_MAX; i++)
+		fprintf(f, " %d", qopt->priomap[i]);
 
 	if (tb[TCA_PRIO_MQ])
-		print_string(PRINT_FP, NULL, " multiqueue: %s ",
-			     rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off");
-	print_bool(PRINT_JSON, "multiqueue", NULL,
-		   tb[TCA_PRIO_MQ] && rta_getattr_u8(tb[TCA_PRIO_MQ]));
+		fprintf(f, " multiqueue: %s ",
+			rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off");
 
 	return 0;
 }
 
 struct qdisc_util prio_qdisc_util = {
-	.id		= "prio",
+	.id	 	= "prio",
 	.parse_qopt	= prio_parse_opt,
 	.print_qopt	= prio_print_opt,
 };
diff --git a/tc/q_qfq.c b/tc/q_qfq.c
index eb8fa4b..05b4d84 100644
--- a/tc/q_qfq.c
+++ b/tc/q_qfq.c
@@ -10,6 +10,7 @@
  *		Fabio Checconi <fabio@gandalf.sssup.it>
  *
  */
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -35,25 +36,31 @@
 }
 
 static int qfq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+			 struct nlmsghdr *n)
 {
-	if (argc > 0) {
-		if (matches(*argv, "help") != 0)
+	while (argc > 0) {
+		if (matches(*argv, "help") == 0) {
+			explain();
+			return -1;
+		} else {
 			fprintf(stderr, "What is \"%s\"?\n", *argv);
-		explain();
-		return -1;
+			explain();
+			return -1;
+		}
+		argc--; argv++;
 	}
 
 	return 0;
 }
 
 static int qfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
-			       struct nlmsghdr *n, const char *dev)
+			       struct nlmsghdr *n)
 {
 	struct rtattr *tail;
 	__u32 tmp;
 
-	tail = addattr_nest(n, 4096, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
 
 	while (argc > 0) {
 		if (matches(*argv, "weight") == 0) {
@@ -79,7 +86,7 @@
 		argc--; argv++;
 	}
 
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
 
 	return 0;
 }
diff --git a/tc/q_red.c b/tc/q_red.c
index 6256420..abd86c7 100644
--- a/tc/q_red.c
+++ b/tc/q_red.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,25 +28,25 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... red	limit BYTES [min BYTES] [max BYTES] avpkt BYTES [burst PACKETS]\n"
-		"		[adaptive] [probability PROBABILITY] [bandwidth KBPS]\n"
-		"		[ecn] [harddrop]\n");
+	fprintf(stderr, "Usage: ... red limit BYTES [min BYTES] [max BYTES] avpkt BYTES [burst PACKETS]\n");
+	fprintf(stderr, "               [adaptive] [probability PROBABILITY] [bandwidth KBPS]\n");
+	fprintf(stderr, "               [ecn] [harddrop]\n");
 }
 
-static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	struct tc_red_qopt opt = {};
-	unsigned int burst = 0;
-	unsigned int avpkt = 0;
+	struct tc_red_qopt opt;
+	unsigned burst = 0;
+	unsigned avpkt = 0;
 	double probability = 0.02;
-	unsigned int rate = 0;
+	unsigned rate = 0;
 	int parm;
 	__u8 sbuf[256];
 	__u32 max_P;
 	struct rtattr *tail;
 
+	memset(&opt, 0, sizeof(opt));
+
 	while (argc > 0) {
 		if (strcmp(*argv, "limit") == 0) {
 			NEXT_ARG();
@@ -85,12 +86,7 @@
 			}
 		} else if (strcmp(*argv, "bandwidth") == 0) {
 			NEXT_ARG();
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate(&rate, *argv, dev)) {
-					fprintf(stderr, "Illegal \"bandwidth\"\n");
-					return -1;
-				}
-			} else if (get_rate(&rate, *argv)) {
+			if (get_rate(&rate, *argv)) {
 				fprintf(stderr, "Illegal \"bandwidth\"\n");
 				return -1;
 			}
@@ -149,12 +145,13 @@
 	}
 	opt.Scell_log = parm;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_RED_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 1024, TCA_RED_STAB, sbuf, 256);
 	max_P = probability * pow(2, 32);
 	addattr_l(n, 1024, TCA_RED_MAX_P, &max_P, sizeof(max_P));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -163,7 +160,6 @@
 	struct rtattr *tb[TCA_RED_MAX + 1];
 	struct tc_red_qopt *qopt;
 	__u32 max_P = 0;
-
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
 	SPRINT_BUF(b3);
@@ -183,24 +179,23 @@
 	    RTA_PAYLOAD(tb[TCA_RED_MAX_P]) >= sizeof(__u32))
 		max_P = rta_getattr_u32(tb[TCA_RED_MAX_P]);
 
-	print_uint(PRINT_JSON, "limit", NULL, qopt->limit);
-	print_string(PRINT_FP, NULL, "limit %s ", sprint_size(qopt->limit, b1));
-	print_uint(PRINT_JSON, "min", NULL, qopt->qth_min);
-	print_string(PRINT_FP, NULL, "min %s ", sprint_size(qopt->qth_min, b2));
-	print_uint(PRINT_JSON, "max", NULL, qopt->qth_max);
-	print_string(PRINT_FP, NULL, "max %s ", sprint_size(qopt->qth_max, b3));
-
-	tc_red_print_flags(qopt->flags);
-
+	fprintf(f, "limit %s min %s max %s ",
+		sprint_size(qopt->limit, b1),
+		sprint_size(qopt->qth_min, b2),
+		sprint_size(qopt->qth_max, b3));
+	if (qopt->flags & TC_RED_ECN)
+		fprintf(f, "ecn ");
+	if (qopt->flags & TC_RED_HARDDROP)
+		fprintf(f, "harddrop ");
+	if (qopt->flags & TC_RED_ADAPTATIVE)
+		fprintf(f, "adaptive ");
 	if (show_details) {
-		print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt->Wlog);
+		fprintf(f, "ewma %u ", qopt->Wlog);
 		if (max_P)
-			print_float(PRINT_ANY, "probability",
-				    "probability %lg ", max_P / pow(2, 32));
+			fprintf(f, "probability %lg ", max_P / pow(2, 32));
 		else
-			print_uint(PRINT_ANY, "Plog", "Plog %u ", qopt->Plog);
-		print_uint(PRINT_ANY, "Scell_log", "Scell_log %u",
-			   qopt->Scell_log);
+			fprintf(f, "Plog %u ", qopt->Plog);
+		fprintf(f, "Scell_log %u", qopt->Scell_log);
 	}
 	return 0;
 }
@@ -217,10 +212,10 @@
 		return -1;
 
 	st = RTA_DATA(xstats);
-	print_uint(PRINT_ANY, "marked", "  marked %u ", st->marked);
-	print_uint(PRINT_ANY, "early", "early %u ", st->early);
-	print_uint(PRINT_ANY, "pdrop", "pdrop %u ", st->pdrop);
-	print_uint(PRINT_ANY, "other", "other %u ", st->other);
+	fprintf(f, "  marked %u early %u pdrop %u other %u",
+		st->marked, st->early, st->pdrop, st->other);
+	return 0;
+
 #endif
 	return 0;
 }
diff --git a/tc/q_rr.c b/tc/q_rr.c
index 843a4fa..e8a9165 100644
--- a/tc/q_rr.c
+++ b/tc/q_rr.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -28,11 +29,11 @@
 }
 
 
-static int rr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
+static int rr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	int pmap_mode = 0;
 	int idx = 0;
-	struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
+	struct tc_prio_qopt opt={3,{ 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }};
 	struct rtattr *nest;
 	unsigned char mq = 0;
 
@@ -57,8 +58,7 @@
 		} else if (strcmp(*argv, "multiqueue") == 0) {
 			mq = 1;
 		} else {
-			unsigned int band;
-
+			unsigned band;
 			if (!pmap_mode) {
 				fprintf(stderr, "What is \"%s\"?\n", *argv);
 				explain();
@@ -102,7 +102,7 @@
 		return -1;
 
 	fprintf(f, "bands %u priomap ", qopt->bands);
-	for (i = 0; i <= TC_PRIO_MAX; i++)
+	for (i=0; i <= TC_PRIO_MAX; i++)
 		fprintf(f, " %d", qopt->priomap[i]);
 
 	if (tb[TCA_PRIO_MQ])
@@ -113,7 +113,7 @@
 }
 
 struct qdisc_util rr_qdisc_util = {
-	.id		= "rr",
+	.id	 	= "rr",
 	.parse_qopt	= rr_parse_opt,
 	.print_qopt	= rr_print_opt,
 };
diff --git a/tc/q_sfb.c b/tc/q_sfb.c
index 7f48c6e..f11c33a 100644
--- a/tc/q_sfb.c
+++ b/tc/q_sfb.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -48,18 +49,19 @@
 }
 
 static int sfb_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+			 struct nlmsghdr *n)
 {
-	struct tc_sfb_qopt opt = {
-		.rehash_interval = 600*1000,
-		.warmup_time = 60*1000,
-		.penalty_rate = 10,
-		.penalty_burst = 20,
-		.increment = (SFB_MAX_PROB + 1000) / 2000,
-		.decrement = (SFB_MAX_PROB + 10000) / 20000,
-	};
+	struct tc_sfb_qopt opt;
 	struct rtattr *tail;
 
+	memset(&opt, 0, sizeof(opt));
+	opt.rehash_interval = 600*1000;
+	opt.warmup_time = 60*1000;
+	opt.penalty_rate = 10;
+	opt.penalty_burst = 20;
+	opt.increment = (SFB_MAX_PROB + 1000) / 2000;
+	opt.decrement = (SFB_MAX_PROB + 10000) / 20000;
+
 	while (argc > 0) {
 	    if (strcmp(*argv, "rehash") == 0) {
 			NEXT_ARG();
@@ -132,9 +134,10 @@
 	if (opt.bin_size == 0)
 		opt.bin_size = (opt.max * 4 + 3) / 5;
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 1024, TCA_SFB_PARMS, &opt, sizeof(opt));
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -155,7 +158,8 @@
 
 	fprintf(f,
 		"limit %d max %d target %d\n"
-		"  increment %.5f decrement %.5f penalty rate %d burst %d (%ums %ums)",
+		"  increment %.5f decrement %.5f penalty rate %d burst %d "
+		"(%ums %ums)",
 		qopt->limit, qopt->max, qopt->bin_size,
 		(double)qopt->increment / SFB_MAX_PROB,
 		(double)qopt->decrement / SFB_MAX_PROB,
diff --git a/tc/q_sfq.c b/tc/q_sfq.c
index 4998921..50846a9 100644
--- a/tc/q_sfq.c
+++ b/tc/q_sfq.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -26,24 +27,25 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... sfq	[ limit NUMBER ] [ perturb SECS ] [ quantum BYTES ]\n"
-		"		[ divisor NUMBER ] [ flows NUMBER] [ depth NUMBER ]\n"
-		"		[ headdrop ]\n"
-		"		[ redflowlimit BYTES ] [ min BYTES ] [ max BYTES ]\n"
-		"		[ avpkt BYTES ] [ burst PACKETS ] [ probability P ]\n"
-		"		[ ecn ] [ harddrop ]\n");
+	fprintf(stderr, "Usage: ... sfq [ limit NUMBER ] [ perturb SECS ] [ quantum BYTES ]\n");
+	fprintf(stderr, "               [ divisor NUMBER ] [ flows NUMBER] [ depth NUMBER ]\n");
+	fprintf(stderr, "               [ headdrop ]\n");
+	fprintf(stderr, "               [ redflowlimit BYTES ] [ min BYTES ] [ max BYTES ]\n");
+	fprintf(stderr, "               [ avpkt BYTES ] [ burst PACKETS ] [ probability P ]\n");
+	fprintf(stderr, "               [ ecn ] [ harddrop ]\n");
 }
 
-static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
+static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	int ok = 0, red = 0;
-	struct tc_sfq_qopt_v1 opt = {};
+	struct tc_sfq_qopt_v1 opt;
 	unsigned int burst = 0;
 	int wlog;
 	unsigned int avpkt = 1000;
 	double probability = 0.02;
 
+	memset(&opt, 0, sizeof(opt));
+
 	while (argc > 0) {
 		if (strcmp(*argv, "quantum") == 0) {
 			NEXT_ARG();
@@ -205,7 +207,6 @@
 {
 	struct tc_sfq_qopt *qopt;
 	struct tc_sfq_qopt_v1 *qopt_ext = NULL;
-
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
 	SPRINT_BUF(b3);
@@ -236,7 +237,8 @@
 			sprint_size(qopt_ext->qth_min, b2),
 			sprint_size(qopt_ext->qth_max, b3),
 			qopt_ext->max_P / pow(2, 32));
-		tc_red_print_flags(qopt_ext->flags);
+		if (qopt_ext->flags & TC_RED_ECN)
+			fprintf(f, "ecn ");
 		if (show_stats) {
 			fprintf(f, "\n prob_mark %u prob_mark_head %u prob_drop %u",
 				qopt_ext->stats.prob_mark,
diff --git a/tc/q_skbprio.c b/tc/q_skbprio.c
deleted file mode 100644
index 2e65a58..0000000
--- a/tc/q_skbprio.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * q_skbprio.c		SKB PRIORITY QUEUE.
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Nishanth Devarajan, <ndev2021@gmail.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include "utils.h"
-#include "tc_util.h"
-
-static void explain(void)
-{
-	fprintf(stderr, "Usage: ... <skbprio> [ limit NUMBER ]\n");
-}
-
-static int skbprio_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			     struct nlmsghdr *n, const char *dev)
-{
-	int ok = 0;
-	struct tc_skbprio_qopt opt = {};
-
-	while (argc > 0) {
-		if (strcmp(*argv, "limit") == 0) {
-			NEXT_ARG();
-			if (get_size(&opt.limit, *argv)) {
-				fprintf(stderr,
-					"%s: Illegal \"limit\" value:\"%s\"\n",
-					 qu->id, *argv);
-				return -1;
-			}
-			ok++;
-		}
-		else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr,
-				"%s: unknown parameter \"%s\"\n",
-				qu->id, *argv);
-			explain();
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	if (ok)
-		addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
-	return 0;
-}
-
-static int skbprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct tc_skbprio_qopt *qopt;
-
-	if (opt == NULL)
-		return 0;
-
-	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
-		return -1;
-	qopt = RTA_DATA(opt);
-	fprintf(f, "limit %u ", qopt->limit);
-	return 0;
-}
-
-struct qdisc_util skbprio_qdisc_util = {
-	.id = "skbprio",
-	.parse_qopt = skbprio_parse_opt,
-	.print_qopt = skbprio_print_opt,
-};
diff --git a/tc/q_taprio.c b/tc/q_taprio.c
deleted file mode 100644
index b995443..0000000
--- a/tc/q_taprio.c
+++ /dev/null
@@ -1,511 +0,0 @@
-/*
- * q_taprio.c	Time Aware Priority Scheduler
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Vinicius Costa Gomes <vinicius.gomes@intel.com>
- * 		Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include "utils.h"
-#include "tc_util.h"
-#include "list.h"
-
-struct sched_entry {
-	struct list_head list;
-	uint32_t index;
-	uint32_t interval;
-	uint32_t gatemask;
-	uint8_t cmd;
-};
-
-#define CLOCKID_INVALID (-1)
-static const struct static_clockid {
-	const char *name;
-	clockid_t clockid;
-} clockids_sysv[] = {
-	{ "REALTIME", CLOCK_REALTIME },
-	{ "TAI", CLOCK_TAI },
-	{ "BOOTTIME", CLOCK_BOOTTIME },
-	{ "MONOTONIC", CLOCK_MONOTONIC },
-	{ NULL }
-};
-
-static void explain(void)
-{
-	fprintf(stderr,
-		"Usage: ... taprio clockid CLOCKID\n"
-		"		[num_tc NUMBER] [map P0 P1 ...] "
-		"		[queues COUNT@OFFSET COUNT@OFFSET COUNT@OFFSET ...] "
-		"		[ [sched-entry index cmd gate-mask interval] ... ] "
-		"		[base-time time] [txtime-delay delay]"
-		"\n"
-		"CLOCKID must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
-}
-
-static void explain_clockid(const char *val)
-{
-	fprintf(stderr, "taprio: illegal value for \"clockid\": \"%s\".\n", val);
-	fprintf(stderr, "It must be a valid SYS-V id (i.e. CLOCK_TAI)\n");
-}
-
-static int get_clockid(__s32 *val, const char *arg)
-{
-	const struct static_clockid *c;
-
-	/* Drop the CLOCK_ prefix if that is being used. */
-	if (strcasestr(arg, "CLOCK_") != NULL)
-		arg += sizeof("CLOCK_") - 1;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (strcasecmp(c->name, arg) == 0) {
-			*val = c->clockid;
-
-			return 0;
-		}
-	}
-
-	return -1;
-}
-
-static const char* get_clock_name(clockid_t clockid)
-{
-	const struct static_clockid *c;
-
-	for (c = clockids_sysv; c->name; c++) {
-		if (clockid == c->clockid)
-			return c->name;
-	}
-
-	return "invalid";
-}
-
-static const char *entry_cmd_to_str(__u8 cmd)
-{
-	switch (cmd) {
-	case TC_TAPRIO_CMD_SET_GATES:
-		return "S";
-	default:
-		return "Invalid";
-	}
-}
-
-static int str_to_entry_cmd(const char *str)
-{
-	if (strcmp(str, "S") == 0)
-		return TC_TAPRIO_CMD_SET_GATES;
-
-	return -1;
-}
-
-static int add_sched_list(struct list_head *sched_entries, struct nlmsghdr *n)
-{
-	struct sched_entry *e;
-
-	list_for_each_entry(e, sched_entries, list) {
-		struct rtattr *a;
-
-		a = addattr_nest(n, 1024, TCA_TAPRIO_SCHED_ENTRY);
-
-		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_CMD, &e->cmd, sizeof(e->cmd));
-		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_GATE_MASK, &e->gatemask, sizeof(e->gatemask));
-		addattr_l(n, 1024, TCA_TAPRIO_SCHED_ENTRY_INTERVAL, &e->interval, sizeof(e->interval));
-
-		addattr_nest_end(n, a);
-	}
-
-	return 0;
-}
-
-static void explain_sched_entry(void)
-{
-	fprintf(stderr, "Usage: ... taprio ... sched-entry <cmd> <gate mask> <interval>\n");
-}
-
-static struct sched_entry *create_entry(uint32_t gatemask, uint32_t interval, uint8_t cmd)
-{
-	struct sched_entry *e;
-
-	e = calloc(1, sizeof(*e));
-	if (!e)
-		return NULL;
-
-	e->gatemask = gatemask;
-	e->interval = interval;
-	e->cmd = cmd;
-
-	return e;
-}
-
-static int taprio_parse_opt(struct qdisc_util *qu, int argc,
-			    char **argv, struct nlmsghdr *n, const char *dev)
-{
-	__s32 clockid = CLOCKID_INVALID;
-	struct tc_mqprio_qopt opt = { };
-	__s64 cycle_time_extension = 0;
-	struct list_head sched_entries;
-	struct rtattr *tail, *l;
-	__u32 taprio_flags = 0;
-	__u32 txtime_delay = 0;
-	__s64 cycle_time = 0;
-	__s64 base_time = 0;
-	int err, idx;
-
-	INIT_LIST_HEAD(&sched_entries);
-
-	while (argc > 0) {
-		idx = 0;
-		if (strcmp(*argv, "num_tc") == 0) {
-			NEXT_ARG();
-			if (get_u8(&opt.num_tc, *argv, 10)) {
-				fprintf(stderr, "Illegal \"num_tc\"\n");
-				return -1;
-			}
-		} else if (strcmp(*argv, "map") == 0) {
-			while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
-				NEXT_ARG();
-				if (get_u8(&opt.prio_tc_map[idx], *argv, 10)) {
-					PREV_ARG();
-					break;
-				}
-				idx++;
-			}
-			for ( ; idx < TC_QOPT_MAX_QUEUE; idx++)
-				opt.prio_tc_map[idx] = 0;
-		} else if (strcmp(*argv, "queues") == 0) {
-			char *tmp, *tok;
-
-			while (idx < TC_QOPT_MAX_QUEUE && NEXT_ARG_OK()) {
-				NEXT_ARG();
-
-				tmp = strdup(*argv);
-				if (!tmp)
-					break;
-
-				tok = strtok(tmp, "@");
-				if (get_u16(&opt.count[idx], tok, 10)) {
-					free(tmp);
-					PREV_ARG();
-					break;
-				}
-				tok = strtok(NULL, "@");
-				if (get_u16(&opt.offset[idx], tok, 10)) {
-					free(tmp);
-					PREV_ARG();
-					break;
-				}
-				free(tmp);
-				idx++;
-			}
-		} else if (strcmp(*argv, "sched-entry") == 0) {
-			uint32_t mask, interval;
-			struct sched_entry *e;
-			uint8_t cmd;
-
-			NEXT_ARG();
-			err = str_to_entry_cmd(*argv);
-			if (err < 0) {
-				explain_sched_entry();
-				return  -1;
-			}
-			cmd = err;
-
-			NEXT_ARG();
-			if (get_u32(&mask, *argv, 16)) {
-				explain_sched_entry();
-				return -1;
-			}
-
-			NEXT_ARG();
-			if (get_u32(&interval, *argv, 0)) {
-				explain_sched_entry();
-				return -1;
-			}
-
-			e = create_entry(mask, interval, cmd);
-			if (!e) {
-				fprintf(stderr, "taprio: not enough memory for new schedule entry\n");
-				return -1;
-			}
-
-			list_add_tail(&e->list, &sched_entries);
-
-		} else if (strcmp(*argv, "base-time") == 0) {
-			NEXT_ARG();
-			if (get_s64(&base_time, *argv, 10)) {
-				PREV_ARG();
-				break;
-			}
-		} else if (strcmp(*argv, "cycle-time") == 0) {
-			NEXT_ARG();
-			if (cycle_time) {
-				fprintf(stderr, "taprio: duplicate \"cycle-time\" specification\n");
-				return -1;
-			}
-
-			if (get_s64(&cycle_time, *argv, 10)) {
-				PREV_ARG();
-				break;
-			}
-
-		} else if (strcmp(*argv, "cycle-time-extension") == 0) {
-			NEXT_ARG();
-			if (cycle_time_extension) {
-				fprintf(stderr, "taprio: duplicate \"cycle-time-extension\" specification\n");
-				return -1;
-			}
-
-			if (get_s64(&cycle_time_extension, *argv, 10)) {
-				PREV_ARG();
-				break;
-			}
-		} else if (strcmp(*argv, "clockid") == 0) {
-			NEXT_ARG();
-			if (clockid != CLOCKID_INVALID) {
-				fprintf(stderr, "taprio: duplicate \"clockid\" specification\n");
-				return -1;
-			}
-			if (get_clockid(&clockid, *argv)) {
-				explain_clockid(*argv);
-				return -1;
-			}
-		} else if (strcmp(*argv, "flags") == 0) {
-			NEXT_ARG();
-			if (taprio_flags) {
-				fprintf(stderr, "taprio: duplicate \"flags\" specification\n");
-				return -1;
-			}
-			if (get_u32(&taprio_flags, *argv, 0)) {
-				PREV_ARG();
-				return -1;
-			}
-
-		} else if (strcmp(*argv, "txtime-delay") == 0) {
-			NEXT_ARG();
-			if (txtime_delay != 0) {
-				fprintf(stderr, "taprio: duplicate \"txtime-delay\" specification\n");
-				return -1;
-			}
-			if (get_u32(&txtime_delay, *argv, 0)) {
-				PREV_ARG();
-				return -1;
-			}
-
-		} else if (strcmp(*argv, "help") == 0) {
-			explain();
-			return -1;
-		} else {
-			fprintf(stderr, "Unknown argument\n");
-			return -1;
-		}
-		argc--; argv++;
-	}
-
-	tail = NLMSG_TAIL(n);
-	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-
-	if (clockid != CLOCKID_INVALID)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CLOCKID, &clockid, sizeof(clockid));
-
-	if (taprio_flags)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_FLAGS, &taprio_flags, sizeof(taprio_flags));
-
-	if (opt.num_tc > 0)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_PRIOMAP, &opt, sizeof(opt));
-
-	if (txtime_delay)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_TXTIME_DELAY, &txtime_delay, sizeof(txtime_delay));
-
-	if (base_time)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_BASE_TIME, &base_time, sizeof(base_time));
-
-	if (cycle_time)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME,
-			  &cycle_time, sizeof(cycle_time));
-
-	if (cycle_time_extension)
-		addattr_l(n, 1024, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION,
-			  &cycle_time_extension, sizeof(cycle_time_extension));
-
-	l = addattr_nest(n, 1024, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST | NLA_F_NESTED);
-
-	err = add_sched_list(&sched_entries, n);
-	if (err < 0) {
-		fprintf(stderr, "Could not add schedule to netlink message\n");
-		return -1;
-	}
-
-	addattr_nest_end(n, l);
-
-	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
-
-	return 0;
-}
-
-static int print_sched_list(FILE *f, struct rtattr *list)
-{
-	struct rtattr *item;
-	int rem;
-
-	if (list == NULL)
-		return 0;
-
-	rem = RTA_PAYLOAD(list);
-
-	open_json_array(PRINT_JSON, "schedule");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	for (item = RTA_DATA(list); RTA_OK(item, rem); item = RTA_NEXT(item, rem)) {
-		struct rtattr *tb[TCA_TAPRIO_SCHED_ENTRY_MAX + 1];
-		__u32 index = 0, gatemask = 0, interval = 0;
-		__u8 command = 0;
-
-		parse_rtattr_nested(tb, TCA_TAPRIO_SCHED_ENTRY_MAX, item);
-
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_INDEX])
-			index = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_INDEX]);
-
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_CMD])
-			command = rta_getattr_u8(tb[TCA_TAPRIO_SCHED_ENTRY_CMD]);
-
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK])
-			gatemask = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_GATE_MASK]);
-
-		if (tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL])
-			interval = rta_getattr_u32(tb[TCA_TAPRIO_SCHED_ENTRY_INTERVAL]);
-
-		open_json_object(NULL);
-		print_uint(PRINT_ANY, "index", "\tindex %u", index);
-		print_string(PRINT_ANY, "cmd", " cmd %s", entry_cmd_to_str(command));
-		print_0xhex(PRINT_ANY, "gatemask", " gatemask %#llx", gatemask);
-		print_uint(PRINT_ANY, "interval", " interval %u", interval);
-		close_json_object();
-
-		print_string(PRINT_FP, NULL, "%s", _SL_);
-	}
-
-	close_json_array(PRINT_ANY, "");
-
-	return 0;
-}
-
-static int print_schedule(FILE *f, struct rtattr **tb)
-{
-	int64_t base_time = 0, cycle_time = 0, cycle_time_extension = 0;
-
-	if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME])
-		base_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
-
-	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME])
-		cycle_time = rta_getattr_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]);
-
-	if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION])
-		cycle_time_extension = rta_getattr_s64(
-			tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION]);
-
-	print_lluint(PRINT_ANY, "base_time", "\tbase-time %lld", base_time);
-
-	print_lluint(PRINT_ANY, "cycle_time", " cycle-time %lld", cycle_time);
-
-	print_lluint(PRINT_ANY, "cycle_time_extension",
-		     " cycle-time-extension %lld", cycle_time_extension);
-
-	print_sched_list(f, tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]);
-
-	return 0;
-}
-
-static int taprio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-{
-	struct rtattr *tb[TCA_TAPRIO_ATTR_MAX + 1];
-	struct tc_mqprio_qopt *qopt = 0;
-	__s32 clockid = CLOCKID_INVALID;
-	int i;
-
-	if (opt == NULL)
-		return 0;
-
-	parse_rtattr_nested(tb, TCA_TAPRIO_ATTR_MAX, opt);
-
-	if (tb[TCA_TAPRIO_ATTR_PRIOMAP] == NULL)
-		return -1;
-
-	qopt = RTA_DATA(tb[TCA_TAPRIO_ATTR_PRIOMAP]);
-
-	print_uint(PRINT_ANY, "tc", "tc %u ", qopt->num_tc);
-
-	open_json_array(PRINT_ANY, "map");
-	for (i = 0; i <= TC_PRIO_MAX; i++)
-		print_uint(PRINT_ANY, NULL, " %u", qopt->prio_tc_map[i]);
-	close_json_array(PRINT_ANY, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	open_json_array(PRINT_ANY, "queues");
-	for (i = 0; i < qopt->num_tc; i++) {
-		open_json_object(NULL);
-		print_uint(PRINT_ANY, "offset", " offset %u", qopt->offset[i]);
-		print_uint(PRINT_ANY, "count", " count %u", qopt->count[i]);
-		close_json_object();
-	}
-	close_json_array(PRINT_ANY, "");
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-
-	if (tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID])
-		clockid = rta_getattr_s32(tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]);
-
-	print_string(PRINT_ANY, "clockid", "clockid %s", get_clock_name(clockid));
-
-	if (tb[TCA_TAPRIO_ATTR_FLAGS]) {
-		__u32 flags;
-
-		flags = rta_getattr_u32(tb[TCA_TAPRIO_ATTR_FLAGS]);
-		print_0xhex(PRINT_ANY, "flags", " flags %#x", flags);
-	}
-
-	if (tb[TCA_TAPRIO_ATTR_TXTIME_DELAY]) {
-		__u32 txtime_delay;
-
-		txtime_delay = rta_getattr_s32(tb[TCA_TAPRIO_ATTR_TXTIME_DELAY]);
-		print_uint(PRINT_ANY, "txtime_delay", " txtime delay %d", txtime_delay);
-	}
-
-	print_schedule(f, tb);
-
-	if (tb[TCA_TAPRIO_ATTR_ADMIN_SCHED]) {
-		struct rtattr *t[TCA_TAPRIO_ATTR_MAX + 1];
-
-		parse_rtattr_nested(t, TCA_TAPRIO_ATTR_MAX,
-				    tb[TCA_TAPRIO_ATTR_ADMIN_SCHED]);
-
-		open_json_object(NULL);
-
-		print_schedule(f, t);
-
-		close_json_object();
-	}
-
-	return 0;
-}
-
-struct qdisc_util taprio_qdisc_util = {
-	.id		= "taprio",
-	.parse_qopt	= taprio_parse_opt,
-	.print_qopt	= taprio_print_opt,
-};
diff --git a/tc/q_tbf.c b/tc/q_tbf.c
index 57a9736..0981e6f 100644
--- a/tc/q_tbf.c
+++ b/tc/q_tbf.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -24,10 +25,9 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... tbf limit BYTES burst BYTES[/BYTES] rate KBPS [ mtu BYTES[/BYTES] ]\n"
-		"	[ peakrate KBPS ] [ latency TIME ] "
-		"[ overhead BYTES ] [ linklayer TYPE ]\n");
+	fprintf(stderr, "Usage: ... tbf limit BYTES burst BYTES[/BYTES] rate KBPS [ mtu BYTES[/BYTES] ]\n");
+	fprintf(stderr, "               [ peakrate KBPS ] [ latency TIME ] ");
+	fprintf(stderr, "[ overhead BYTES ] [ linklayer TYPE ]\n");
 }
 
 static void explain1(const char *arg, const char *val)
@@ -36,20 +36,21 @@
 }
 
 
-static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv,
-			 struct nlmsghdr *n, const char *dev)
+static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
-	int ok = 0;
-	struct tc_tbf_qopt opt = {};
+	int ok=0;
+	struct tc_tbf_qopt opt;
 	__u32 rtab[256];
 	__u32 ptab[256];
-	unsigned buffer = 0, mtu = 0, mpu = 0, latency = 0;
-	int Rcell_log =  -1, Pcell_log = -1;
-	unsigned short overhead = 0;
+	unsigned buffer=0, mtu=0, mpu=0, latency=0;
+	int Rcell_log=-1, Pcell_log = -1;
+	unsigned short overhead=0;
 	unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
 	struct rtattr *tail;
 	__u64 rate64 = 0, prate64 = 0;
 
+	memset(&opt, 0, sizeof(opt));
+
 	while (argc > 0) {
 		if (matches(*argv, "limit") == 0) {
 			NEXT_ARG();
@@ -85,7 +86,6 @@
 			strcmp(*argv, "buffer") == 0 ||
 			strcmp(*argv, "maxburst") == 0) {
 			const char *parm_name = *argv;
-
 			NEXT_ARG();
 			if (buffer) {
 				fprintf(stderr, "tbf: duplicate \"buffer/burst/maxburst\" specification\n");
@@ -99,7 +99,6 @@
 		} else if (strcmp(*argv, "mtu") == 0 ||
 			   strcmp(*argv, "minburst") == 0) {
 			const char *parm_name = *argv;
-
 			NEXT_ARG();
 			if (mtu) {
 				fprintf(stderr, "tbf: duplicate \"mtu/minburst\" specification\n");
@@ -127,12 +126,7 @@
 				fprintf(stderr, "tbf: duplicate \"rate\" specification\n");
 				return -1;
 			}
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate64(&rate64, *argv, dev)) {
-					explain1("rate", *argv);
-					return -1;
-				}
-			} else if (get_rate64(&rate64, *argv)) {
+			if (get_rate64(&rate64, *argv)) {
 				explain1("rate", *argv);
 				return -1;
 			}
@@ -143,12 +137,7 @@
 				fprintf(stderr, "tbf: duplicate \"peakrate\" specification\n");
 				return -1;
 			}
-			if (strchr(*argv, '%')) {
-				if (get_percent_rate64(&prate64, *argv, dev)) {
-					explain1("peakrate", *argv);
-					return -1;
-				}
-			} else if (get_rate64(&prate64, *argv)) {
+			if (get_rate64(&prate64, *argv)) {
 				explain1("peakrate", *argv);
 				return -1;
 			}
@@ -178,12 +167,12 @@
 		argc--; argv++;
 	}
 
-	int verdict = 0;
+        int verdict = 0;
 
-	/* Be nice to the user: try to emit all error messages in
-	 * one go rather than reveal one more problem when a
-	 * previous one has been fixed.
-	 */
+        /* Be nice to the user: try to emit all error messages in
+         * one go rather than reveal one more problem when a
+         * previous one has been fixed.
+         */
 	if (rate64 == 0) {
 		fprintf(stderr, "tbf: the \"rate\" parameter is mandatory.\n");
 		verdict = -1;
@@ -204,20 +193,18 @@
 		verdict = -1;
 	}
 
-	if (verdict != 0) {
-		explain();
-		return verdict;
-	}
+        if (verdict != 0) {
+                explain();
+                return verdict;
+        }
 
 	opt.rate.rate = (rate64 >= (1ULL << 32)) ? ~0U : rate64;
 	opt.peakrate.rate = (prate64 >= (1ULL << 32)) ? ~0U : prate64;
 
 	if (opt.limit == 0) {
 		double lim = rate64*(double)latency/TIME_UNITS_PER_SEC + buffer;
-
 		if (prate64) {
 			double lim2 = prate64*(double)latency/TIME_UNITS_PER_SEC + mtu;
-
 			if (lim2 < lim)
 				lim = lim2;
 		}
@@ -242,7 +229,8 @@
 		opt.mtu = tc_calc_xmittime(opt.peakrate.rate, mtu);
 	}
 
-	tail = addattr_nest(n, 1024, TCA_OPTIONS);
+	tail = NLMSG_TAIL(n);
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
 	addattr_l(n, 2024, TCA_TBF_PARMS, &opt, sizeof(opt));
 	addattr_l(n, 2124, TCA_TBF_BURST, &buffer, sizeof(buffer));
 	if (rate64 >= (1ULL << 32))
@@ -254,7 +242,7 @@
 		addattr_l(n, 3224, TCA_TBF_PBURST, &mtu, sizeof(mtu));
 		addattr_l(n, 4096, TCA_TBF_PTAB, ptab, 1024);
 	}
-	addattr_nest_end(n, tail);
+	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
 	return 0;
 }
 
@@ -266,7 +254,6 @@
 	double buffer, mtu;
 	double latency;
 	__u64 rate64 = 0, prate64 = 0;
-
 	SPRINT_BUF(b1);
 	SPRINT_BUF(b2);
 	SPRINT_BUF(b3);
@@ -318,7 +305,6 @@
 	latency = TIME_UNITS_PER_SEC*(qopt->limit/(double)rate64) - tc_core_tick2time(qopt->buffer);
 	if (prate64) {
 		double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)prate64) - tc_core_tick2time(qopt->mtu);
-
 		if (lat2 > latency)
 			latency = lat2;
 	}
diff --git a/tc/static-syms.c b/tc/static-syms.c
index 47c4092..0bc8074 100644
--- a/tc/static-syms.c
+++ b/tc/static-syms.c
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * This file creates a dummy version of dynamic loading
  * for environments where dynamic linking
diff --git a/tc/tc.c b/tc/tc.c
index 37294b3..e1d4bc3 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <dlfcn.h>
 #include <sys/socket.h>
@@ -30,45 +31,47 @@
 #include "tc_common.h"
 #include "namespace.h"
 
-int show_stats;
-int show_details;
-int show_raw;
-int show_graph;
+int show_stats = 0;
+int show_details = 0;
+int show_raw = 0;
+int show_pretty = 0;
+int show_graph = 0;
 int timestamp;
 
-int batch_mode;
-int use_iec;
-int force;
-bool use_names;
-int json;
-int color;
-int oneline;
-int numeric;
+int batch_mode = 0;
+int resolve_hosts = 0;
+int use_iec = 0;
+int force = 0;
+bool use_names = false;
 
 static char *conf_file;
 
 struct rtnl_handle rth;
 
-static void *BODY;	/* cached handle dlopen(NULL) */
-static struct qdisc_util *qdisc_list;
-static struct filter_util *filter_list;
+static void *BODY = NULL;	/* cached handle dlopen(NULL) */
+static struct qdisc_util * qdisc_list;
+static struct filter_util * filter_list;
+
+#ifdef ANDROID
+extern struct qdisc_util cbq_qdisc_util;
+extern struct qdisc_util htb_qdisc_util;
+extern struct qdisc_util ingress_qdisc_util;
+extern struct filter_util u32_filter_util;
+#endif
 
 static int print_noqopt(struct qdisc_util *qu, FILE *f,
 			struct rtattr *opt)
 {
 	if (opt && RTA_PAYLOAD(opt))
 		fprintf(f, "[Unknown qdisc, optlen=%u] ",
-			(unsigned int) RTA_PAYLOAD(opt));
+			(unsigned) RTA_PAYLOAD(opt));
 	return 0;
 }
 
-static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv,
-			struct nlmsghdr *n, const char *dev)
+static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
 {
 	if (argc) {
-		fprintf(stderr,
-			"Unknown qdisc \"%s\", hence option \"%s\" is unparsable\n",
-			qu->id, *argv);
+		fprintf(stderr, "Unknown qdisc \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv);
 		return -1;
 	}
 	return 0;
@@ -78,26 +81,22 @@
 {
 	if (opt && RTA_PAYLOAD(opt))
 		fprintf(f, "fh %08x [Unknown filter, optlen=%u] ",
-			fhandle, (unsigned int) RTA_PAYLOAD(opt));
+			fhandle, (unsigned) RTA_PAYLOAD(opt));
 	else if (fhandle)
 		fprintf(f, "fh %08x ", fhandle);
 	return 0;
 }
 
-static int parse_nofopt(struct filter_util *qu, char *fhandle,
-			int argc, char **argv, struct nlmsghdr *n)
+static int parse_nofopt(struct filter_util *qu, char *fhandle, int argc, char **argv, struct nlmsghdr *n)
 {
 	__u32 handle;
 
 	if (argc) {
-		fprintf(stderr,
-			"Unknown filter \"%s\", hence option \"%s\" is unparsable\n",
-			qu->id, *argv);
+		fprintf(stderr, "Unknown filter \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv);
 		return -1;
 	}
 	if (fhandle) {
 		struct tcmsg *t = NLMSG_DATA(n);
-
 		if (get_u32(&handle, fhandle, 16)) {
 			fprintf(stderr, "Unparsable filter ID \"%s\"\n", fhandle);
 			return -1;
@@ -113,6 +112,18 @@
 	char buf[256];
 	struct qdisc_util *q;
 
+#ifdef ANDROID
+	if (!strcmp(str, "cbq"))
+		return &cbq_qdisc_util;
+	else if (!strcmp(str, "htb"))
+		return &htb_qdisc_util;
+	else if (!strcmp(str, "ingress"))
+		return &ingress_qdisc_util;
+	else {
+		fprintf(stderr, "Android does not support qdisc '%s'\n", str);
+		return NULL;
+	}
+#endif
 	for (q = qdisc_list; q; q = q->next)
 		if (strcmp(q->id, str) == 0)
 			return q;
@@ -140,9 +151,11 @@
 	return q;
 
 noexist:
-	q = calloc(1, sizeof(*q));
+	q = malloc(sizeof(*q));
 	if (q) {
-		q->id = strdup(str);
+
+		memset(q, 0, sizeof(*q));
+		q->id = strcpy(malloc(strlen(str)+1), str);
 		q->parse_qopt = parse_noqopt;
 		q->print_qopt = print_noqopt;
 		goto reg;
@@ -156,6 +169,14 @@
 	void *dlh;
 	char buf[256];
 	struct filter_util *q;
+#ifdef ANDROID
+	if (!strcmp(str, "u32"))
+		return &u32_filter_util;
+	else {
+		fprintf(stderr, "Android does not support filter '%s'\n", str);
+		return NULL;
+	}
+#endif
 
 	for (q = filter_list; q; q = q->next)
 		if (strcmp(q->id, str) == 0)
@@ -182,8 +203,9 @@
 	filter_list = q;
 	return q;
 noexist:
-	q = calloc(1, sizeof(*q));
+	q = malloc(sizeof(*q));
 	if (q) {
+		memset(q, 0, sizeof(*q));
 		strncpy(q->id, str, 15);
 		q->parse_fopt = parse_nofopt;
 		q->print_fopt = print_nofopt;
@@ -194,15 +216,16 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage:	tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
-		"	tc [-force] -batch filename\n"
-		"where  OBJECT := { qdisc | class | filter | chain |\n"
-		"		    action | monitor | exec }\n"
-		"       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[aw] |\n"
-		"		    -o[neline] | -j[son] | -p[retty] | -c[olor]\n"
-		"		    -b[atch] [filename] | -n[etns] name | -N[umeric] |\n"
-		"		     -nm | -nam[es] | { -cf | -conf } path }\n");
+	fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
+#ifdef ANDROID
+			"       tc [-force]\n"
+#else
+			"       tc [-force] -batch filename\n"
+#endif
+	                "where  OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
+	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | "
+			"-n[etns] name |\n"
+			"                    -nm | -nam[es] | { -cf | -conf } path }\n");
 }
 
 static int do_cmd(int argc, char **argv)
@@ -213,8 +236,6 @@
 		return do_class(argc-1, argv+1);
 	if (matches(*argv, "filter") == 0)
 		return do_filter(argc-1, argv+1);
-	if (matches(*argv, "chain") == 0)
-		return do_chain(argc-1, argv+1);
 	if (matches(*argv, "actions") == 0)
 		return do_action(argc-1, argv+1);
 	if (matches(*argv, "monitor") == 0)
@@ -231,6 +252,7 @@
 	return -1;
 }
 
+#ifndef ANDROID
 static int batch(const char *name)
 {
 	char *line = NULL;
@@ -240,8 +262,7 @@
 	batch_mode = 1;
 	if (name && strcmp(name, "-") != 0) {
 		if (freopen(name, "r", stdin) == NULL) {
-			fprintf(stderr,
-				"Cannot open file \"%s\" for reading: %s\n",
+			fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
 				name, strerror(errno));
 			return -1;
 		}
@@ -264,25 +285,27 @@
 			continue;	/* blank line */
 
 		if (do_cmd(largc, largv)) {
-			fprintf(stderr, "Command failed %s:%d\n",
-				name, cmdlineno);
+			fprintf(stderr, "Command failed %s:%d\n", name, cmdlineno);
 			ret = 1;
 			if (!force)
 				break;
 		}
-		fflush(stdout);
 	}
+	if (line)
+		free(line);
 
-	free(line);
 	rtnl_close(&rth);
 	return ret;
 }
+#endif
 
 
 int main(int argc, char **argv)
 {
 	int ret;
+#ifndef ANDROID
 	char *batch_file = NULL;
+#endif
 
 	while (argc > 1) {
 		if (argv[1][0] != '-')
@@ -295,7 +318,7 @@
 		} else if (matches(argv[1], "-raw") == 0) {
 			++show_raw;
 		} else if (matches(argv[1], "-pretty") == 0) {
-			++pretty;
+			++show_pretty;
 		} else if (matches(argv[1], "-graph") == 0) {
 			show_graph = 1;
 		} else if (matches(argv[1], "-Version") == 0) {
@@ -308,17 +331,17 @@
 			return 0;
 		} else if (matches(argv[1], "-force") == 0) {
 			++force;
+#ifndef ANDROID
 		} else if (matches(argv[1], "-batch") == 0) {
 			argc--;	argv++;
 			if (argc <= 1)
 				usage();
 			batch_file = argv[1];
+#endif
 		} else if (matches(argv[1], "-netns") == 0) {
 			NEXT_ARG();
 			if (netns_switch(argv[1]))
 				return -1;
-		} else if (matches(argv[1], "-Numeric") == 0) {
-			++numeric;
 		} else if (matches(argv[1], "-names") == 0 ||
 				matches(argv[1], "-nm") == 0) {
 			use_names = true;
@@ -326,31 +349,22 @@
 				matches(argv[1], "-conf") == 0) {
 			NEXT_ARG();
 			conf_file = argv[1];
-		} else if (matches_color(argv[1], &color)) {
 		} else if (matches(argv[1], "-timestamp") == 0) {
 			timestamp++;
 		} else if (matches(argv[1], "-tshort") == 0) {
 			++timestamp;
 			++timestamp_short;
-		} else if (matches(argv[1], "-json") == 0) {
-			++json;
-		} else if (matches(argv[1], "-oneline") == 0) {
-			++oneline;
 		} else {
-			fprintf(stderr,
-				"Option \"%s\" is unknown, try \"tc -help\".\n",
-				argv[1]);
+			fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
 			return -1;
 		}
 		argc--;	argv++;
 	}
 
-	_SL_ = oneline ? "\\" : "\n";
-
-	check_enable_color(color, json);
-
+#ifndef ANDROID
 	if (batch_file)
 		return batch(batch_file);
+#endif
 
 	if (argc <= 1) {
 		usage();
diff --git a/tc/tc_bpf.c b/tc/tc_bpf.c
new file mode 100644
index 0000000..42c8841
--- /dev/null
+++ b/tc/tc_bpf.c
@@ -0,0 +1,1892 @@
+/*
+ * tc_bpf.c	BPF common code
+ *
+ *		This program is free software; you can distribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ *
+ * Authors:	Daniel Borkmann <dborkman@redhat.com>
+ *		Jiri Pirko <jiri@resnulli.us>
+ *		Alexei Starovoitov <ast@plumgrid.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+
+#ifdef HAVE_ELF
+#include <libelf.h>
+#include <gelf.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+#include <sys/vfs.h>
+#include <sys/mount.h>
+#include <sys/syscall.h>
+#include <sys/sendfile.h>
+#include <sys/resource.h>
+
+#include <linux/bpf.h>
+#include <linux/filter.h>
+#include <linux/if_alg.h>
+
+#include <arpa/inet.h>
+
+#include "utils.h"
+
+#include "bpf_elf.h"
+#include "bpf_scm.h"
+
+#include "tc_util.h"
+#include "tc_bpf.h"
+
+#ifdef HAVE_ELF
+static int bpf_obj_open(const char *path, enum bpf_prog_type type,
+			const char *sec, bool verbose);
+#else
+static int bpf_obj_open(const char *path, enum bpf_prog_type type,
+			const char *sec, bool verbose)
+{
+	fprintf(stderr, "No ELF library support compiled in.\n");
+	errno = ENOSYS;
+	return -1;
+}
+#endif
+
+static inline __u64 bpf_ptr_to_u64(const void *ptr)
+{
+	return (__u64)(unsigned long)ptr;
+}
+
+static int bpf(int cmd, union bpf_attr *attr, unsigned int size)
+{
+#ifdef __NR_bpf
+	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	fprintf(stderr, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+
+static int bpf_map_update(int fd, const void *key, const void *value,
+			  uint64_t flags)
+{
+	union bpf_attr attr = {
+		.map_fd		= fd,
+		.key		= bpf_ptr_to_u64(key),
+		.value		= bpf_ptr_to_u64(value),
+		.flags		= flags,
+	};
+
+	return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
+}
+
+static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
+			    char **bpf_string, bool *need_release,
+			    const char separator)
+{
+	char sp;
+
+	if (from_file) {
+		size_t tmp_len, op_len = sizeof("65535 255 255 4294967295,");
+		char *tmp_string;
+		FILE *fp;
+
+		tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len;
+		tmp_string = malloc(tmp_len);
+		if (tmp_string == NULL)
+			return -ENOMEM;
+
+		memset(tmp_string, 0, tmp_len);
+
+		fp = fopen(arg, "r");
+		if (fp == NULL) {
+			perror("Cannot fopen");
+			free(tmp_string);
+			return -ENOENT;
+		}
+
+		if (!fgets(tmp_string, tmp_len, fp)) {
+			free(tmp_string);
+			fclose(fp);
+			return -EIO;
+		}
+
+		fclose(fp);
+
+		*need_release = true;
+		*bpf_string = tmp_string;
+	} else {
+		*need_release = false;
+		*bpf_string = arg;
+	}
+
+	if (sscanf(*bpf_string, "%hu%c", bpf_len, &sp) != 2 ||
+	    sp != separator) {
+		if (*need_release)
+			free(*bpf_string);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int bpf_ops_parse(int argc, char **argv, struct sock_filter *bpf_ops,
+			 bool from_file)
+{
+	char *bpf_string, *token, separator = ',';
+	int ret = 0, i = 0;
+	bool need_release;
+	__u16 bpf_len = 0;
+
+	if (argc < 1)
+		return -EINVAL;
+	if (bpf_parse_string(argv[0], from_file, &bpf_len, &bpf_string,
+			     &need_release, separator))
+		return -EINVAL;
+	if (bpf_len == 0 || bpf_len > BPF_MAXINSNS) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	token = bpf_string;
+	while ((token = strchr(token, separator)) && (++token)[0]) {
+		if (i >= bpf_len) {
+			fprintf(stderr, "Real program length exceeds encoded "
+				"length parameter!\n");
+			ret = -EINVAL;
+			goto out;
+		}
+
+		if (sscanf(token, "%hu %hhu %hhu %u,",
+			   &bpf_ops[i].code, &bpf_ops[i].jt,
+			   &bpf_ops[i].jf, &bpf_ops[i].k) != 4) {
+			fprintf(stderr, "Error at instruction %d!\n", i);
+			ret = -EINVAL;
+			goto out;
+		}
+
+		i++;
+	}
+
+	if (i != bpf_len) {
+		fprintf(stderr, "Parsed program length is less than encoded"
+			"length parameter!\n");
+		ret = -EINVAL;
+		goto out;
+	}
+	ret = bpf_len;
+out:
+	if (need_release)
+		free(bpf_string);
+
+	return ret;
+}
+
+void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len)
+{
+	struct sock_filter *ops = (struct sock_filter *) RTA_DATA(bpf_ops);
+	int i;
+
+	if (len == 0)
+		return;
+
+	fprintf(f, "bytecode \'%u,", len);
+
+	for (i = 0; i < len - 1; i++)
+		fprintf(f, "%hu %hhu %hhu %u,", ops[i].code, ops[i].jt,
+			ops[i].jf, ops[i].k);
+
+	fprintf(f, "%hu %hhu %hhu %u\'", ops[i].code, ops[i].jt,
+		ops[i].jf, ops[i].k);
+}
+
+static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
+				    int length)
+{
+	char file[PATH_MAX], buff[4096];
+	struct bpf_elf_map tmp, zero;
+	unsigned int val;
+	FILE *fp;
+
+	snprintf(file, sizeof(file), "/proc/%d/fdinfo/%d", getpid(), fd);
+
+	fp = fopen(file, "r");
+	if (!fp) {
+		fprintf(stderr, "No procfs support?!\n");
+		return -EIO;
+	}
+
+	memset(&tmp, 0, sizeof(tmp));
+	while (fgets(buff, sizeof(buff), fp)) {
+		if (sscanf(buff, "map_type:\t%u", &val) == 1)
+			tmp.type = val;
+		else if (sscanf(buff, "key_size:\t%u", &val) == 1)
+			tmp.size_key = val;
+		else if (sscanf(buff, "value_size:\t%u", &val) == 1)
+			tmp.size_value = val;
+		else if (sscanf(buff, "max_entries:\t%u", &val) == 1)
+			tmp.max_elem = val;
+	}
+
+	fclose(fp);
+
+	if (!memcmp(&tmp, map, length)) {
+		return 0;
+	} else {
+		memset(&zero, 0, sizeof(zero));
+		/* If kernel doesn't have eBPF-related fdinfo, we cannot do much,
+		 * so just accept it. We know we do have an eBPF fd and in this
+		 * case, everything is 0. It is guaranteed that no such map exists
+		 * since map type of 0 is unloadable BPF_MAP_TYPE_UNSPEC.
+		 */
+		if (!memcmp(&tmp, &zero, length))
+			return 0;
+
+		fprintf(stderr, "Map specs from pinned file differ!\n");
+		return -EINVAL;
+	}
+}
+
+static int bpf_mnt_fs(const char *target)
+{
+	bool bind_done = false;
+
+	while (mount("", target, "none", MS_PRIVATE | MS_REC, NULL)) {
+		if (errno != EINVAL || bind_done) {
+			fprintf(stderr, "mount --make-private %s failed: %s\n",
+				target,	strerror(errno));
+			return -1;
+		}
+
+		if (mount(target, target, "none", MS_BIND, NULL)) {
+			fprintf(stderr, "mount --bind %s %s failed: %s\n",
+				target,	target, strerror(errno));
+			return -1;
+		}
+
+		bind_done = true;
+	}
+
+	if (mount("bpf", target, "bpf", 0, NULL)) {
+		fprintf(stderr, "mount -t bpf bpf %s failed: %s\n",
+			target,	strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int bpf_valid_mntpt(const char *mnt, unsigned long magic)
+{
+	struct statfs st_fs;
+
+	if (statfs(mnt, &st_fs) < 0)
+		return -ENOENT;
+	if ((unsigned long)st_fs.f_type != magic)
+		return -ENOENT;
+
+	return 0;
+}
+
+static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
+				  char *mnt, int len,
+				  const char * const *known_mnts)
+{
+	const char * const *ptr;
+	char type[100];
+	FILE *fp;
+
+	if (known_mnts) {
+		ptr = known_mnts;
+		while (*ptr) {
+			if (bpf_valid_mntpt(*ptr, magic) == 0) {
+				strncpy(mnt, *ptr, len - 1);
+				mnt[len - 1] = 0;
+				return mnt;
+			}
+			ptr++;
+		}
+	}
+
+	fp = fopen("/proc/mounts", "r");
+	if (fp == NULL || len != PATH_MAX)
+		return NULL;
+
+	while (fscanf(fp, "%*s %" textify(PATH_MAX) "s %99s %*s %*d %*d\n",
+		      mnt, type) == 2) {
+		if (strcmp(type, fstype) == 0)
+			break;
+	}
+
+	fclose(fp);
+	if (strcmp(type, fstype) != 0)
+		return NULL;
+
+	return mnt;
+}
+
+int bpf_trace_pipe(void)
+{
+	char tracefs_mnt[PATH_MAX] = TRACE_DIR_MNT;
+	static const char * const tracefs_known_mnts[] = {
+		TRACE_DIR_MNT,
+		"/sys/kernel/debug/tracing",
+		"/tracing",
+		"/trace",
+		0,
+	};
+	char tpipe[PATH_MAX];
+	const char *mnt;
+	int fd;
+
+	mnt = bpf_find_mntpt("tracefs", TRACEFS_MAGIC, tracefs_mnt,
+			     sizeof(tracefs_mnt), tracefs_known_mnts);
+	if (!mnt) {
+		fprintf(stderr, "tracefs not mounted?\n");
+		return -1;
+	}
+
+	snprintf(tpipe, sizeof(tpipe), "%s/trace_pipe", mnt);
+
+	fd = open(tpipe, O_RDONLY);
+	if (fd < 0)
+		return -1;
+
+	fprintf(stderr, "Running! Hang up with ^C!\n\n");
+	while (1) {
+		static char buff[4096];
+		ssize_t ret;
+
+		ret = read(fd, buff, sizeof(buff) - 1);
+		if (ret > 0) {
+			write(2, buff, ret);
+			fflush(stderr);
+		}
+	}
+
+	return 0;
+}
+
+static const char *bpf_get_tc_dir(void)
+{
+	static bool bpf_mnt_cached = false;
+	static char bpf_tc_dir[PATH_MAX];
+	static const char *mnt;
+	static const char * const bpf_known_mnts[] = {
+		BPF_DIR_MNT,
+		0,
+	};
+	char bpf_mnt[PATH_MAX] = BPF_DIR_MNT;
+	char bpf_glo_dir[PATH_MAX];
+	int ret;
+
+	if (bpf_mnt_cached)
+		goto done;
+
+	mnt = bpf_find_mntpt("bpf", BPF_FS_MAGIC, bpf_mnt, sizeof(bpf_mnt),
+			     bpf_known_mnts);
+	if (!mnt) {
+		mnt = getenv(BPF_ENV_MNT);
+		if (!mnt)
+			mnt = BPF_DIR_MNT;
+		ret = bpf_mnt_fs(mnt);
+		if (ret) {
+			mnt = NULL;
+			goto out;
+		}
+	}
+
+	snprintf(bpf_tc_dir, sizeof(bpf_tc_dir), "%s/%s", mnt, BPF_DIR_TC);
+	ret = mkdir(bpf_tc_dir, S_IRWXU);
+	if (ret && errno != EEXIST) {
+		fprintf(stderr, "mkdir %s failed: %s\n", bpf_tc_dir,
+			strerror(errno));
+		mnt = NULL;
+		goto out;
+	}
+
+	snprintf(bpf_glo_dir, sizeof(bpf_glo_dir), "%s/%s",
+		 bpf_tc_dir, BPF_DIR_GLOBALS);
+	ret = mkdir(bpf_glo_dir, S_IRWXU);
+	if (ret && errno != EEXIST) {
+		fprintf(stderr, "mkdir %s failed: %s\n", bpf_glo_dir,
+			strerror(errno));
+		mnt = NULL;
+		goto out;
+	}
+
+	mnt = bpf_tc_dir;
+out:
+	bpf_mnt_cached = true;
+done:
+	return mnt;
+}
+
+static int bpf_obj_get(const char *pathname)
+{
+	union bpf_attr attr;
+	char tmp[PATH_MAX];
+
+	if (strlen(pathname) > 2 && pathname[0] == 'm' &&
+	    pathname[1] == ':' && bpf_get_tc_dir()) {
+		snprintf(tmp, sizeof(tmp), "%s/%s",
+			 bpf_get_tc_dir(), pathname + 2);
+		pathname = tmp;
+	}
+
+	memset(&attr, 0, sizeof(attr));
+	attr.pathname = bpf_ptr_to_u64(pathname);
+
+	return bpf(BPF_OBJ_GET, &attr, sizeof(attr));
+}
+
+const char *bpf_default_section(const enum bpf_prog_type type)
+{
+	switch (type) {
+	case BPF_PROG_TYPE_SCHED_CLS:
+		return ELF_SECTION_CLASSIFIER;
+	case BPF_PROG_TYPE_SCHED_ACT:
+		return ELF_SECTION_ACTION;
+	default:
+		return NULL;
+	}
+}
+
+enum bpf_mode {
+	CBPF_BYTECODE = 0,
+	CBPF_FILE,
+	EBPF_OBJECT,
+	EBPF_PINNED,
+	__BPF_MODE_MAX,
+#define BPF_MODE_MAX	__BPF_MODE_MAX
+};
+
+static int bpf_parse(int *ptr_argc, char ***ptr_argv, const bool *opt_tbl,
+		     enum bpf_prog_type *type, enum bpf_mode *mode,
+		     const char **ptr_object, const char **ptr_section,
+		     const char **ptr_uds_name, struct sock_filter *opcodes)
+{
+	const char *file, *section, *uds_name;
+	bool verbose = false;
+	int ret, argc;
+	char **argv;
+
+	argv = *ptr_argv;
+	argc = *ptr_argc;
+
+	if (opt_tbl[CBPF_BYTECODE] &&
+	    (matches(*argv, "bytecode") == 0 ||
+	     strcmp(*argv, "bc") == 0)) {
+		*mode = CBPF_BYTECODE;
+	} else if (opt_tbl[CBPF_FILE] &&
+		   (matches(*argv, "bytecode-file") == 0 ||
+		    strcmp(*argv, "bcf") == 0)) {
+		*mode = CBPF_FILE;
+	} else if (opt_tbl[EBPF_OBJECT] &&
+		   (matches(*argv, "object-file") == 0 ||
+		    strcmp(*argv, "obj") == 0)) {
+		*mode = EBPF_OBJECT;
+	} else if (opt_tbl[EBPF_PINNED] &&
+		   (matches(*argv, "object-pinned") == 0 ||
+		    matches(*argv, "pinned") == 0 ||
+		    matches(*argv, "fd") == 0)) {
+		*mode = EBPF_PINNED;
+	} else {
+		fprintf(stderr, "What mode is \"%s\"?\n", *argv);
+		return -1;
+	}
+
+	NEXT_ARG();
+	file = section = uds_name = NULL;
+	if (*mode == EBPF_OBJECT || *mode == EBPF_PINNED) {
+		file = *argv;
+		NEXT_ARG_FWD();
+
+		if (*type == BPF_PROG_TYPE_UNSPEC) {
+			if (argc > 0 && matches(*argv, "type") == 0) {
+				NEXT_ARG();
+				if (matches(*argv, "cls") == 0) {
+					*type = BPF_PROG_TYPE_SCHED_CLS;
+				} else if (matches(*argv, "act") == 0) {
+					*type = BPF_PROG_TYPE_SCHED_ACT;
+				} else {
+					fprintf(stderr, "What type is \"%s\"?\n",
+						*argv);
+					return -1;
+				}
+				NEXT_ARG_FWD();
+			} else {
+				*type = BPF_PROG_TYPE_SCHED_CLS;
+			}
+		}
+
+		section = bpf_default_section(*type);
+		if (argc > 0 && matches(*argv, "section") == 0) {
+			NEXT_ARG();
+			section = *argv;
+			NEXT_ARG_FWD();
+		}
+
+		uds_name = getenv(BPF_ENV_UDS);
+		if (argc > 0 && !uds_name &&
+		    matches(*argv, "export") == 0) {
+			NEXT_ARG();
+			uds_name = *argv;
+			NEXT_ARG_FWD();
+		}
+
+		if (argc > 0 && matches(*argv, "verbose") == 0) {
+			verbose = true;
+			NEXT_ARG_FWD();
+		}
+
+		PREV_ARG();
+	}
+
+	if (*mode == CBPF_BYTECODE || *mode == CBPF_FILE)
+		ret = bpf_ops_parse(argc, argv, opcodes, *mode == CBPF_FILE);
+	else if (*mode == EBPF_OBJECT)
+		ret = bpf_obj_open(file, *type, section, verbose);
+	else if (*mode == EBPF_PINNED)
+		ret = bpf_obj_get(file);
+	else
+		return -1;
+
+	if (ptr_object)
+		*ptr_object = file;
+	if (ptr_section)
+		*ptr_section = section;
+	if (ptr_uds_name)
+		*ptr_uds_name = uds_name;
+
+	*ptr_argc = argc;
+	*ptr_argv = argv;
+
+	return ret;
+}
+
+int bpf_parse_common(int *ptr_argc, char ***ptr_argv, const int *nla_tbl,
+		     enum bpf_prog_type type, const char **ptr_object,
+		     const char **ptr_uds_name, struct nlmsghdr *n)
+{
+	struct sock_filter opcodes[BPF_MAXINSNS];
+	const bool opt_tbl[BPF_MODE_MAX] = {
+		[CBPF_BYTECODE]	= true,
+		[CBPF_FILE]	= true,
+		[EBPF_OBJECT]	= true,
+		[EBPF_PINNED]	= true,
+	};
+	char annotation[256];
+	const char *section;
+	enum bpf_mode mode;
+	int ret;
+
+	ret = bpf_parse(ptr_argc, ptr_argv, opt_tbl, &type, &mode,
+			ptr_object, &section, ptr_uds_name, opcodes);
+	if (ret < 0)
+		return ret;
+
+	if (mode == CBPF_BYTECODE || mode == CBPF_FILE) {
+		addattr16(n, MAX_MSG, nla_tbl[BPF_NLA_OPS_LEN], ret);
+		addattr_l(n, MAX_MSG, nla_tbl[BPF_NLA_OPS], opcodes,
+			  ret * sizeof(struct sock_filter));
+	}
+
+	if (mode == EBPF_OBJECT || mode == EBPF_PINNED) {
+		snprintf(annotation, sizeof(annotation), "%s:[%s]",
+			 basename(*ptr_object), mode == EBPF_PINNED ?
+			 "*fsobj" : section);
+
+		addattr32(n, MAX_MSG, nla_tbl[BPF_NLA_FD], ret);
+		addattrstrz(n, MAX_MSG, nla_tbl[BPF_NLA_NAME], annotation);
+	}
+
+	return 0;
+}
+
+int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv)
+{
+	enum bpf_prog_type type = BPF_PROG_TYPE_UNSPEC;
+	const bool opt_tbl[BPF_MODE_MAX] = {
+		[CBPF_BYTECODE]	= false,
+		[CBPF_FILE]	= false,
+		[EBPF_OBJECT]	= true,
+		[EBPF_PINNED]	= true,
+	};
+	const struct bpf_elf_map test = {
+		.type		= BPF_MAP_TYPE_PROG_ARRAY,
+		.size_key	= sizeof(int),
+		.size_value	= sizeof(int),
+	};
+	int ret, prog_fd, map_fd;
+	const char *section;
+	enum bpf_mode mode;
+	uint32_t map_key;
+
+	prog_fd = bpf_parse(&argc, &argv, opt_tbl, &type, &mode,
+			    NULL, &section, NULL, NULL);
+	if (prog_fd < 0)
+		return prog_fd;
+	if (key) {
+		map_key = *key;
+	} else {
+		ret = sscanf(section, "%*i/%i", &map_key);
+		if (ret != 1) {
+			fprintf(stderr, "Couldn\'t infer map key from section "
+				"name! Please provide \'key\' argument!\n");
+			ret = -EINVAL;
+			goto out_prog;
+		}
+	}
+
+	map_fd = bpf_obj_get(map_path);
+	if (map_fd < 0) {
+		fprintf(stderr, "Couldn\'t retrieve pinned map \'%s\': %s\n",
+			map_path, strerror(errno));
+		ret = map_fd;
+		goto out_prog;
+	}
+
+	ret = bpf_map_selfcheck_pinned(map_fd, &test,
+				       offsetof(struct bpf_elf_map, max_elem));
+	if (ret < 0) {
+		fprintf(stderr, "Map \'%s\' self-check failed!\n", map_path);
+		goto out_map;
+	}
+
+	ret = bpf_map_update(map_fd, &map_key, &prog_fd, BPF_ANY);
+	if (ret < 0)
+		fprintf(stderr, "Map update failed: %s\n", strerror(errno));
+out_map:
+	close(map_fd);
+out_prog:
+	close(prog_fd);
+	return ret;
+}
+
+#ifdef HAVE_ELF
+struct bpf_elf_prog {
+	enum bpf_prog_type	type;
+	const struct bpf_insn	*insns;
+	size_t			size;
+	const char		*license;
+};
+
+struct bpf_hash_entry {
+	unsigned int		pinning;
+	const char		*subpath;
+	struct bpf_hash_entry	*next;
+};
+
+struct bpf_elf_ctx {
+	Elf			*elf_fd;
+	GElf_Ehdr		elf_hdr;
+	Elf_Data		*sym_tab;
+	Elf_Data		*str_tab;
+	int			obj_fd;
+	int			map_fds[ELF_MAX_MAPS];
+	struct bpf_elf_map	maps[ELF_MAX_MAPS];
+	int			sym_num;
+	int			map_num;
+	bool			*sec_done;
+	int			sec_maps;
+	char			license[ELF_MAX_LICENSE_LEN];
+	enum bpf_prog_type	type;
+	bool			verbose;
+	struct bpf_elf_st	stat;
+	struct bpf_hash_entry	*ht[256];
+};
+
+struct bpf_elf_sec_data {
+	GElf_Shdr		sec_hdr;
+	Elf_Data		*sec_data;
+	const char		*sec_name;
+};
+
+struct bpf_map_data {
+	int			*fds;
+	const char		*obj;
+	struct bpf_elf_st	*st;
+	struct bpf_elf_map	*ent;
+};
+
+/* If we provide a small buffer with log level enabled, the kernel
+ * could fail program load as no buffer space is available for the
+ * log and thus verifier fails. In case something doesn't pass the
+ * verifier we still want to hand something descriptive to the user.
+ */
+static char bpf_log_buf[65536];
+
+static __check_format_string(1, 2) void bpf_dump_error(const char *format, ...)
+{
+	va_list vl;
+
+	va_start(vl, format);
+	vfprintf(stderr, format, vl);
+	va_end(vl);
+
+	if (bpf_log_buf[0]) {
+		fprintf(stderr, "%s\n", bpf_log_buf);
+		memset(bpf_log_buf, 0, sizeof(bpf_log_buf));
+	}
+}
+
+static int bpf_map_create(enum bpf_map_type type, unsigned int size_key,
+			  unsigned int size_value, unsigned int max_elem)
+{
+	union bpf_attr attr = {
+		.map_type	= type,
+		.key_size	= size_key,
+		.value_size	= size_value,
+		.max_entries	= max_elem,
+	};
+
+	return bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+}
+
+static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+			 size_t size, const char *license)
+{
+	union bpf_attr attr = {
+		.prog_type	= type,
+		.insns		= bpf_ptr_to_u64(insns),
+		.insn_cnt	= size / sizeof(struct bpf_insn),
+		.license	= bpf_ptr_to_u64(license),
+		.log_buf	= bpf_ptr_to_u64(bpf_log_buf),
+		.log_size	= sizeof(bpf_log_buf),
+		.log_level	= 1,
+	};
+
+	if (getenv(BPF_ENV_NOLOG)) {
+		attr.log_buf	= 0;
+		attr.log_size	= 0;
+		attr.log_level	= 0;
+	}
+
+	return bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
+}
+
+static int bpf_obj_pin(int fd, const char *pathname)
+{
+	union bpf_attr attr = {
+		.pathname	= bpf_ptr_to_u64(pathname),
+		.bpf_fd		= fd,
+	};
+
+	return bpf(BPF_OBJ_PIN, &attr, sizeof(attr));
+}
+
+static int bpf_obj_hash(const char *object, uint8_t *out, size_t len)
+{
+	struct sockaddr_alg alg = {
+		.salg_family	= AF_ALG,
+		.salg_type	= "hash",
+		.salg_name	= "sha1",
+	};
+	int ret, cfd, ofd, ffd;
+	struct stat stbuff;
+	ssize_t size;
+
+	if (!object || len != 20)
+		return -EINVAL;
+
+	cfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
+	if (cfd < 0) {
+		fprintf(stderr, "Cannot get AF_ALG socket: %s\n",
+			strerror(errno));
+		return cfd;
+	}
+
+	ret = bind(cfd, (struct sockaddr *)&alg, sizeof(alg));
+	if (ret < 0) {
+		fprintf(stderr, "Error binding socket: %s\n", strerror(errno));
+		goto out_cfd;
+	}
+
+	ofd = accept(cfd, NULL, 0);
+	if (ofd < 0) {
+		fprintf(stderr, "Error accepting socket: %s\n",
+			strerror(errno));
+		ret = ofd;
+		goto out_cfd;
+	}
+
+	ffd = open(object, O_RDONLY);
+	if (ffd < 0) {
+		fprintf(stderr, "Error opening object %s: %s\n",
+			object, strerror(errno));
+		ret = ffd;
+		goto out_ofd;
+	}
+
+        ret = fstat(ffd, &stbuff);
+	if (ret < 0) {
+		fprintf(stderr, "Error doing fstat: %s\n",
+			strerror(errno));
+		goto out_ffd;
+	}
+
+	size = sendfile(ofd, ffd, NULL, stbuff.st_size);
+	if (size != stbuff.st_size) {
+		fprintf(stderr, "Error from sendfile (%zd vs %zu bytes): %s\n",
+			size, stbuff.st_size, strerror(errno));
+		ret = -1;
+		goto out_ffd;
+	}
+
+	size = read(ofd, out, len);
+	if (size != len) {
+		fprintf(stderr, "Error from read (%zd vs %zu bytes): %s\n",
+			size, len, strerror(errno));
+		ret = -1;
+	} else {
+		ret = 0;
+	}
+out_ffd:
+	close(ffd);
+out_ofd:
+	close(ofd);
+out_cfd:
+	close(cfd);
+	return ret;
+}
+
+static const char *bpf_get_obj_uid(const char *pathname)
+{
+	static bool bpf_uid_cached = false;
+	static char bpf_uid[64];
+	uint8_t tmp[20];
+	int ret;
+
+	if (bpf_uid_cached)
+		goto done;
+
+	ret = bpf_obj_hash(pathname, tmp, sizeof(tmp));
+	if (ret) {
+		fprintf(stderr, "Object hashing failed!\n");
+		return NULL;
+	}
+
+	hexstring_n2a(tmp, sizeof(tmp), bpf_uid, sizeof(bpf_uid));
+	bpf_uid_cached = true;
+done:
+	return bpf_uid;
+}
+
+static int bpf_init_env(const char *pathname)
+{
+	struct rlimit limit = {
+		.rlim_cur = RLIM_INFINITY,
+		.rlim_max = RLIM_INFINITY,
+	};
+
+	/* Don't bother in case we fail! */
+	setrlimit(RLIMIT_MEMLOCK, &limit);
+
+	if (!bpf_get_tc_dir()) {
+		fprintf(stderr, "Continuing without mounted eBPF fs. "
+			"Too old kernel?\n");
+		return 0;
+	}
+
+	if (!bpf_get_obj_uid(pathname))
+		return -1;
+
+	return 0;
+}
+
+static const char *bpf_custom_pinning(const struct bpf_elf_ctx *ctx,
+				      uint32_t pinning)
+{
+	struct bpf_hash_entry *entry;
+
+	entry = ctx->ht[pinning & (ARRAY_SIZE(ctx->ht) - 1)];
+	while (entry && entry->pinning != pinning)
+		entry = entry->next;
+
+	return entry ? entry->subpath : NULL;
+}
+
+static bool bpf_no_pinning(const struct bpf_elf_ctx *ctx,
+			   uint32_t pinning)
+{
+	switch (pinning) {
+	case PIN_OBJECT_NS:
+	case PIN_GLOBAL_NS:
+		return false;
+	case PIN_NONE:
+		return true;
+	default:
+		return !bpf_custom_pinning(ctx, pinning);
+	}
+}
+
+static void bpf_make_pathname(char *pathname, size_t len, const char *name,
+			      const struct bpf_elf_ctx *ctx, uint32_t pinning)
+{
+	switch (pinning) {
+	case PIN_OBJECT_NS:
+		snprintf(pathname, len, "%s/%s/%s", bpf_get_tc_dir(),
+			 bpf_get_obj_uid(NULL), name);
+		break;
+	case PIN_GLOBAL_NS:
+		snprintf(pathname, len, "%s/%s/%s", bpf_get_tc_dir(),
+			 BPF_DIR_GLOBALS, name);
+		break;
+	default:
+		snprintf(pathname, len, "%s/../%s/%s", bpf_get_tc_dir(),
+			 bpf_custom_pinning(ctx, pinning), name);
+		break;
+	}
+}
+
+static int bpf_probe_pinned(const char *name, const struct bpf_elf_ctx *ctx,
+			    uint32_t pinning)
+{
+	char pathname[PATH_MAX];
+
+	if (bpf_no_pinning(ctx, pinning) || !bpf_get_tc_dir())
+		return 0;
+
+	bpf_make_pathname(pathname, sizeof(pathname), name, ctx, pinning);
+	return bpf_obj_get(pathname);
+}
+
+static int bpf_make_obj_path(void)
+{
+	char tmp[PATH_MAX];
+	int ret;
+
+	snprintf(tmp, sizeof(tmp), "%s/%s", bpf_get_tc_dir(),
+		 bpf_get_obj_uid(NULL));
+
+	ret = mkdir(tmp, S_IRWXU);
+	if (ret && errno != EEXIST) {
+		fprintf(stderr, "mkdir %s failed: %s\n", tmp, strerror(errno));
+		return ret;
+	}
+
+	return 0;
+}
+
+static int bpf_make_custom_path(const char *todo)
+{
+	char tmp[PATH_MAX], rem[PATH_MAX], *sub;
+	int ret;
+
+	snprintf(tmp, sizeof(tmp), "%s/../", bpf_get_tc_dir());
+	snprintf(rem, sizeof(rem), "%s/", todo);
+	sub = strtok(rem, "/");
+
+	while (sub) {
+		if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX)
+			return -EINVAL;
+
+		strcat(tmp, sub);
+		strcat(tmp, "/");
+
+		ret = mkdir(tmp, S_IRWXU);
+		if (ret && errno != EEXIST) {
+			fprintf(stderr, "mkdir %s failed: %s\n", tmp,
+				strerror(errno));
+			return ret;
+		}
+
+		sub = strtok(NULL, "/");
+	}
+
+	return 0;
+}
+
+static int bpf_place_pinned(int fd, const char *name,
+			    const struct bpf_elf_ctx *ctx, uint32_t pinning)
+{
+	char pathname[PATH_MAX];
+	const char *tmp;
+	int ret = 0;
+
+	if (bpf_no_pinning(ctx, pinning) || !bpf_get_tc_dir())
+		return 0;
+
+	if (pinning == PIN_OBJECT_NS)
+		ret = bpf_make_obj_path();
+	else if ((tmp = bpf_custom_pinning(ctx, pinning)))
+		ret = bpf_make_custom_path(tmp);
+	if (ret < 0)
+		return ret;
+
+	bpf_make_pathname(pathname, sizeof(pathname), name, ctx, pinning);
+	return bpf_obj_pin(fd, pathname);
+}
+
+static int bpf_prog_attach(const char *section,
+			   const struct bpf_elf_prog *prog, bool verbose)
+{
+	int fd;
+
+	/* We can add pinning here later as well, same as bpf_map_attach(). */
+	errno = 0;
+	fd = bpf_prog_load(prog->type, prog->insns, prog->size,
+			   prog->license);
+	if (fd < 0 || verbose) {
+		bpf_dump_error("Prog section \'%s\' (type:%u insns:%zu "
+			       "license:\'%s\') %s%s (%d)!\n\n",
+			       section, prog->type,
+			       prog->size / sizeof(struct bpf_insn),
+			       prog->license, fd < 0 ? "rejected: " :
+			       "loaded", fd < 0 ? strerror(errno) : "",
+			       fd < 0 ? errno : fd);
+	}
+
+	return fd;
+}
+
+static int bpf_map_attach(const char *name, const struct bpf_elf_map *map,
+			  const struct bpf_elf_ctx *ctx, bool verbose)
+{
+	int fd, ret;
+
+	fd = bpf_probe_pinned(name, ctx, map->pinning);
+	if (fd > 0) {
+		ret = bpf_map_selfcheck_pinned(fd, map,
+					       offsetof(struct bpf_elf_map,
+							id));
+		if (ret < 0) {
+			close(fd);
+			fprintf(stderr, "Map \'%s\' self-check failed!\n",
+				name);
+			return ret;
+		}
+		if (verbose)
+			fprintf(stderr, "Map \'%s\' loaded as pinned!\n",
+				name);
+		return fd;
+	}
+
+	errno = 0;
+	fd = bpf_map_create(map->type, map->size_key, map->size_value,
+			    map->max_elem);
+	if (fd < 0 || verbose) {
+		bpf_dump_error("Map \'%s\' (type:%u id:%u pinning:%u "
+			       "ksize:%u vsize:%u max-elems:%u) %s%s (%d)!\n",
+			       name, map->type, map->id, map->pinning,
+			       map->size_key, map->size_value, map->max_elem,
+			       fd < 0 ? "rejected: " : "loaded", fd < 0 ?
+			       strerror(errno) : "", fd < 0 ? errno : fd);
+		if (fd < 0)
+			return fd;
+	}
+
+	ret = bpf_place_pinned(fd, name, ctx, map->pinning);
+	if (ret < 0 && errno != EEXIST) {
+		fprintf(stderr, "Could not pin %s map: %s\n", name,
+			strerror(errno));
+		close(fd);
+		return ret;
+	}
+
+	return fd;
+}
+
+#define __ELF_ST_BIND(x)	((x) >> 4)
+#define __ELF_ST_TYPE(x)	(((unsigned int) x) & 0xf)
+
+static const char *bpf_str_tab_name(const struct bpf_elf_ctx *ctx,
+				    const GElf_Sym *sym)
+{
+	return ctx->str_tab->d_buf + sym->st_name;
+}
+
+static const char *bpf_map_fetch_name(struct bpf_elf_ctx *ctx, int which)
+{
+	GElf_Sym sym;
+	int i;
+
+	for (i = 0; i < ctx->sym_num; i++) {
+		if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
+			continue;
+
+		if (__ELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
+		    __ELF_ST_TYPE(sym.st_info) != STT_NOTYPE ||
+		    sym.st_shndx != ctx->sec_maps ||
+		    sym.st_value / sizeof(struct bpf_elf_map) != which)
+			continue;
+
+		return bpf_str_tab_name(ctx, &sym);
+	}
+
+	return NULL;
+}
+
+static int bpf_maps_attach_all(struct bpf_elf_ctx *ctx)
+{
+	const char *map_name;
+	int i, fd;
+
+	for (i = 0; i < ctx->map_num; i++) {
+		map_name = bpf_map_fetch_name(ctx, i);
+		if (!map_name)
+			return -EIO;
+
+		fd = bpf_map_attach(map_name, &ctx->maps[i], ctx,
+				    ctx->verbose);
+		if (fd < 0)
+			return fd;
+
+		ctx->map_fds[i] = fd;
+	}
+
+	return 0;
+}
+
+static int bpf_fill_section_data(struct bpf_elf_ctx *ctx, int section,
+				 struct bpf_elf_sec_data *data)
+{
+	Elf_Data *sec_edata;
+	GElf_Shdr sec_hdr;
+	Elf_Scn *sec_fd;
+	char *sec_name;
+
+	memset(data, 0, sizeof(*data));
+
+	sec_fd = elf_getscn(ctx->elf_fd, section);
+	if (!sec_fd)
+		return -EINVAL;
+	if (gelf_getshdr(sec_fd, &sec_hdr) != &sec_hdr)
+		return -EIO;
+
+	sec_name = elf_strptr(ctx->elf_fd, ctx->elf_hdr.e_shstrndx,
+			      sec_hdr.sh_name);
+	if (!sec_name || !sec_hdr.sh_size)
+		return -ENOENT;
+
+	sec_edata = elf_getdata(sec_fd, NULL);
+	if (!sec_edata || elf_getdata(sec_fd, sec_edata))
+		return -EIO;
+
+	memcpy(&data->sec_hdr, &sec_hdr, sizeof(sec_hdr));
+
+	data->sec_name = sec_name;
+	data->sec_data = sec_edata;
+	return 0;
+}
+
+static int bpf_fetch_maps(struct bpf_elf_ctx *ctx, int section,
+			  struct bpf_elf_sec_data *data)
+{
+	if (data->sec_data->d_size % sizeof(struct bpf_elf_map) != 0)
+		return -EINVAL;
+
+	ctx->map_num = data->sec_data->d_size / sizeof(struct bpf_elf_map);
+	ctx->sec_maps = section;
+	ctx->sec_done[section] = true;
+
+	if (ctx->map_num > ARRAY_SIZE(ctx->map_fds)) {
+		fprintf(stderr, "Too many BPF maps in ELF section!\n");
+		return -ENOMEM;
+	}
+
+	memcpy(ctx->maps, data->sec_data->d_buf, data->sec_data->d_size);
+	return 0;
+}
+
+static int bpf_fetch_license(struct bpf_elf_ctx *ctx, int section,
+			     struct bpf_elf_sec_data *data)
+{
+	if (data->sec_data->d_size > sizeof(ctx->license))
+		return -ENOMEM;
+
+	memcpy(ctx->license, data->sec_data->d_buf, data->sec_data->d_size);
+	ctx->sec_done[section] = true;
+	return 0;
+}
+
+static int bpf_fetch_symtab(struct bpf_elf_ctx *ctx, int section,
+			    struct bpf_elf_sec_data *data)
+{
+	ctx->sym_tab = data->sec_data;
+	ctx->sym_num = data->sec_hdr.sh_size / data->sec_hdr.sh_entsize;
+	ctx->sec_done[section] = true;
+	return 0;
+}
+
+static int bpf_fetch_strtab(struct bpf_elf_ctx *ctx, int section,
+			    struct bpf_elf_sec_data *data)
+{
+	ctx->str_tab = data->sec_data;
+	ctx->sec_done[section] = true;
+	return 0;
+}
+
+static int bpf_fetch_ancillary(struct bpf_elf_ctx *ctx)
+{
+	struct bpf_elf_sec_data data;
+	int i, ret = -1;
+
+	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
+		ret = bpf_fill_section_data(ctx, i, &data);
+		if (ret < 0)
+			continue;
+
+		if (data.sec_hdr.sh_type == SHT_PROGBITS &&
+		    !strcmp(data.sec_name, ELF_SECTION_MAPS))
+			ret = bpf_fetch_maps(ctx, i, &data);
+		else if (data.sec_hdr.sh_type == SHT_PROGBITS &&
+			 !strcmp(data.sec_name, ELF_SECTION_LICENSE))
+			ret = bpf_fetch_license(ctx, i, &data);
+		else if (data.sec_hdr.sh_type == SHT_SYMTAB &&
+			 !strcmp(data.sec_name, ".symtab"))
+			ret = bpf_fetch_symtab(ctx, i, &data);
+		else if (data.sec_hdr.sh_type == SHT_STRTAB &&
+			 !strcmp(data.sec_name, ".strtab"))
+			ret = bpf_fetch_strtab(ctx, i, &data);
+		if (ret < 0) {
+			fprintf(stderr, "Error parsing section %d! Perhaps"
+				"check with readelf -a?\n", i);
+			break;
+		}
+	}
+
+	if (ctx->sym_tab && ctx->str_tab && ctx->sec_maps) {
+		ret = bpf_maps_attach_all(ctx);
+		if (ret < 0) {
+			fprintf(stderr, "Error loading maps into kernel!\n");
+			return ret;
+		}
+	}
+
+	return ret;
+}
+
+static int bpf_fetch_prog(struct bpf_elf_ctx *ctx, const char *section)
+{
+	struct bpf_elf_sec_data data;
+	struct bpf_elf_prog prog;
+	int ret, i, fd = -1;
+
+	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
+		if (ctx->sec_done[i])
+			continue;
+
+		ret = bpf_fill_section_data(ctx, i, &data);
+		if (ret < 0 ||
+		    !(data.sec_hdr.sh_type == SHT_PROGBITS &&
+		      data.sec_hdr.sh_flags & SHF_EXECINSTR &&
+		      !strcmp(data.sec_name, section)))
+			continue;
+
+		memset(&prog, 0, sizeof(prog));
+		prog.type    = ctx->type;
+		prog.insns   = data.sec_data->d_buf;
+		prog.size    = data.sec_data->d_size;
+		prog.license = ctx->license;
+
+		fd = bpf_prog_attach(section, &prog, ctx->verbose);
+		if (fd < 0)
+			continue;
+
+		ctx->sec_done[i] = true;
+		break;
+	}
+
+	return fd;
+}
+
+static int bpf_apply_relo_data(struct bpf_elf_ctx *ctx,
+			       struct bpf_elf_sec_data *data_relo,
+			       struct bpf_elf_sec_data *data_insn)
+{
+	Elf_Data *idata = data_insn->sec_data;
+	GElf_Shdr *rhdr = &data_relo->sec_hdr;
+	int relo_ent, relo_num = rhdr->sh_size / rhdr->sh_entsize;
+	struct bpf_insn *insns = idata->d_buf;
+	unsigned int num_insns = idata->d_size / sizeof(*insns);
+
+	for (relo_ent = 0; relo_ent < relo_num; relo_ent++) {
+		unsigned int ioff, rmap;
+		GElf_Rel relo;
+		GElf_Sym sym;
+
+		if (gelf_getrel(data_relo->sec_data, relo_ent, &relo) != &relo)
+			return -EIO;
+
+		ioff = relo.r_offset / sizeof(struct bpf_insn);
+		if (ioff >= num_insns ||
+		    insns[ioff].code != (BPF_LD | BPF_IMM | BPF_DW))
+			return -EINVAL;
+
+		if (gelf_getsym(ctx->sym_tab, GELF_R_SYM(relo.r_info), &sym) != &sym)
+			return -EIO;
+
+		rmap = sym.st_value / sizeof(struct bpf_elf_map);
+		if (rmap >= ARRAY_SIZE(ctx->map_fds))
+			return -EINVAL;
+		if (!ctx->map_fds[rmap])
+			return -EINVAL;
+
+		if (ctx->verbose)
+			fprintf(stderr, "Map \'%s\' (%d) injected into prog "
+				"section \'%s\' at offset %u!\n",
+				bpf_str_tab_name(ctx, &sym), ctx->map_fds[rmap],
+				data_insn->sec_name, ioff);
+
+		insns[ioff].src_reg = BPF_PSEUDO_MAP_FD;
+		insns[ioff].imm     = ctx->map_fds[rmap];
+	}
+
+	return 0;
+}
+
+static int bpf_fetch_prog_relo(struct bpf_elf_ctx *ctx, const char *section)
+{
+	struct bpf_elf_sec_data data_relo, data_insn;
+	struct bpf_elf_prog prog;
+	int ret, idx, i, fd = -1;
+
+	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
+		ret = bpf_fill_section_data(ctx, i, &data_relo);
+		if (ret < 0 || data_relo.sec_hdr.sh_type != SHT_REL)
+			continue;
+
+		idx = data_relo.sec_hdr.sh_info;
+		ret = bpf_fill_section_data(ctx, idx, &data_insn);
+		if (ret < 0 ||
+		    !(data_insn.sec_hdr.sh_type == SHT_PROGBITS &&
+		      data_insn.sec_hdr.sh_flags & SHF_EXECINSTR &&
+		      !strcmp(data_insn.sec_name, section)))
+			continue;
+
+		ret = bpf_apply_relo_data(ctx, &data_relo, &data_insn);
+		if (ret < 0)
+			continue;
+
+		memset(&prog, 0, sizeof(prog));
+		prog.type    = ctx->type;
+		prog.insns   = data_insn.sec_data->d_buf;
+		prog.size    = data_insn.sec_data->d_size;
+		prog.license = ctx->license;
+
+		fd = bpf_prog_attach(section, &prog, ctx->verbose);
+		if (fd < 0)
+			continue;
+
+		ctx->sec_done[i]   = true;
+		ctx->sec_done[idx] = true;
+		break;
+	}
+
+	return fd;
+}
+
+static int bpf_fetch_prog_sec(struct bpf_elf_ctx *ctx, const char *section)
+{
+	int ret = -1;
+
+	if (ctx->sym_tab)
+		ret = bpf_fetch_prog_relo(ctx, section);
+	if (ret < 0)
+		ret = bpf_fetch_prog(ctx, section);
+
+	return ret;
+}
+
+static int bpf_find_map_by_id(struct bpf_elf_ctx *ctx, uint32_t id)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ctx->map_fds); i++)
+		if (ctx->map_fds[i] && ctx->maps[i].id == id &&
+		    ctx->maps[i].type == BPF_MAP_TYPE_PROG_ARRAY)
+			return i;
+	return -1;
+}
+
+static int bpf_fill_prog_arrays(struct bpf_elf_ctx *ctx)
+{
+	struct bpf_elf_sec_data data;
+	uint32_t map_id, key_id;
+	int fd, i, ret, idx;
+
+	for (i = 1; i < ctx->elf_hdr.e_shnum; i++) {
+		if (ctx->sec_done[i])
+			continue;
+
+		ret = bpf_fill_section_data(ctx, i, &data);
+		if (ret < 0)
+			continue;
+
+		ret = sscanf(data.sec_name, "%i/%i", &map_id, &key_id);
+		if (ret != 2)
+			continue;
+
+		idx = bpf_find_map_by_id(ctx, map_id);
+		if (idx < 0)
+			continue;
+
+		fd = bpf_fetch_prog_sec(ctx, data.sec_name);
+		if (fd < 0)
+			return -EIO;
+
+		ret = bpf_map_update(ctx->map_fds[idx], &key_id,
+				     &fd, BPF_ANY);
+		if (ret < 0)
+			return -ENOENT;
+
+		ctx->sec_done[i] = true;
+	}
+
+	return 0;
+}
+
+static void bpf_save_finfo(struct bpf_elf_ctx *ctx)
+{
+	struct stat st;
+	int ret;
+
+	memset(&ctx->stat, 0, sizeof(ctx->stat));
+
+	ret = fstat(ctx->obj_fd, &st);
+	if (ret < 0) {
+		fprintf(stderr, "Stat of elf file failed: %s\n",
+			strerror(errno));
+		return;
+	}
+
+	ctx->stat.st_dev = st.st_dev;
+	ctx->stat.st_ino = st.st_ino;
+}
+
+static int bpf_read_pin_mapping(FILE *fp, uint32_t *id, char *path)
+{
+	char buff[PATH_MAX];
+
+	while (fgets(buff, sizeof(buff), fp)) {
+		char *ptr = buff;
+
+		while (*ptr == ' ' || *ptr == '\t')
+			ptr++;
+
+		if (*ptr == '#' || *ptr == '\n' || *ptr == 0)
+			continue;
+
+		if (sscanf(ptr, "%i %s\n", id, path) != 2 &&
+		    sscanf(ptr, "%i %s #", id, path) != 2) {
+			strcpy(path, ptr);
+			return -1;
+		}
+
+		return 1;
+	}
+
+	return 0;
+}
+
+static bool bpf_pinning_reserved(uint32_t pinning)
+{
+	switch (pinning) {
+	case PIN_NONE:
+	case PIN_OBJECT_NS:
+	case PIN_GLOBAL_NS:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static void bpf_hash_init(struct bpf_elf_ctx *ctx, const char *db_file)
+{
+	struct bpf_hash_entry *entry;
+	char subpath[PATH_MAX];
+	uint32_t pinning;
+	FILE *fp;
+	int ret;
+
+	fp = fopen(db_file, "r");
+	if (!fp)
+		return;
+
+	memset(subpath, 0, sizeof(subpath));
+	while ((ret = bpf_read_pin_mapping(fp, &pinning, subpath))) {
+		if (ret == -1) {
+			fprintf(stderr, "Database %s is corrupted at: %s\n",
+				db_file, subpath);
+			fclose(fp);
+			return;
+		}
+
+		if (bpf_pinning_reserved(pinning)) {
+			fprintf(stderr, "Database %s, id %u is reserved - "
+				"ignoring!\n", db_file, pinning);
+			continue;
+		}
+
+		entry = malloc(sizeof(*entry));
+		if (!entry) {
+			fprintf(stderr, "No memory left for db entry!\n");
+			continue;
+		}
+
+		entry->pinning = pinning;
+		entry->subpath = strdup(subpath);
+		if (!entry->subpath) {
+			fprintf(stderr, "No memory left for db entry!\n");
+			free(entry);
+			continue;
+		}
+
+		entry->next = ctx->ht[pinning & (ARRAY_SIZE(ctx->ht) - 1)];
+		ctx->ht[pinning & (ARRAY_SIZE(ctx->ht) - 1)] = entry;
+	}
+
+	fclose(fp);
+}
+
+static void bpf_hash_destroy(struct bpf_elf_ctx *ctx)
+{
+	struct bpf_hash_entry *entry;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ctx->ht); i++) {
+		while ((entry = ctx->ht[i]) != NULL) {
+			ctx->ht[i] = entry->next;
+			free((char *)entry->subpath);
+			free(entry);
+		}
+	}
+}
+
+static int bpf_elf_check_ehdr(const struct bpf_elf_ctx *ctx)
+{
+	if (ctx->elf_hdr.e_type != ET_REL ||
+	    ctx->elf_hdr.e_machine != 0 ||
+	    ctx->elf_hdr.e_version != EV_CURRENT) {
+		fprintf(stderr, "ELF format error, ELF file not for eBPF?\n");
+		return -EINVAL;
+	}
+
+	switch (ctx->elf_hdr.e_ident[EI_DATA]) {
+	default:
+		fprintf(stderr, "ELF format error, wrong endianness info?\n");
+		return -EINVAL;
+	case ELFDATA2LSB:
+		if (htons(1) == 1) {
+			fprintf(stderr,
+				"We are big endian, eBPF object is little endian!\n");
+			return -EIO;
+		}
+		break;
+	case ELFDATA2MSB:
+		if (htons(1) != 1) {
+			fprintf(stderr,
+				"We are little endian, eBPF object is big endian!\n");
+			return -EIO;
+		}
+		break;
+	}
+
+	return 0;
+}
+
+static int bpf_elf_ctx_init(struct bpf_elf_ctx *ctx, const char *pathname,
+			    enum bpf_prog_type type, bool verbose)
+{
+	int ret = -EINVAL;
+
+	if (elf_version(EV_CURRENT) == EV_NONE ||
+	    bpf_init_env(pathname))
+		return ret;
+
+	memset(ctx, 0, sizeof(*ctx));
+	ctx->verbose = verbose;
+	ctx->type    = type;
+
+	ctx->obj_fd = open(pathname, O_RDONLY);
+	if (ctx->obj_fd < 0)
+		return ctx->obj_fd;
+
+	ctx->elf_fd = elf_begin(ctx->obj_fd, ELF_C_READ, NULL);
+	if (!ctx->elf_fd) {
+		ret = -EINVAL;
+		goto out_fd;
+	}
+
+	if (elf_kind(ctx->elf_fd) != ELF_K_ELF) {
+		ret = -EINVAL;
+		goto out_fd;
+	}
+
+	if (gelf_getehdr(ctx->elf_fd, &ctx->elf_hdr) !=
+	    &ctx->elf_hdr) {
+		ret = -EIO;
+		goto out_elf;
+	}
+
+	ret = bpf_elf_check_ehdr(ctx);
+	if (ret < 0)
+		goto out_elf;
+
+	ctx->sec_done = calloc(ctx->elf_hdr.e_shnum,
+			       sizeof(*(ctx->sec_done)));
+	if (!ctx->sec_done) {
+		ret = -ENOMEM;
+		goto out_elf;
+	}
+
+	bpf_save_finfo(ctx);
+	bpf_hash_init(ctx, CONFDIR "/bpf_pinning");
+
+	return 0;
+out_elf:
+	elf_end(ctx->elf_fd);
+out_fd:
+	close(ctx->obj_fd);
+	return ret;
+}
+
+static int bpf_maps_count(struct bpf_elf_ctx *ctx)
+{
+	int i, count = 0;
+
+	for (i = 0; i < ARRAY_SIZE(ctx->map_fds); i++) {
+		if (!ctx->map_fds[i])
+			break;
+		count++;
+	}
+
+	return count;
+}
+
+static void bpf_maps_teardown(struct bpf_elf_ctx *ctx)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ctx->map_fds); i++) {
+		if (ctx->map_fds[i])
+			close(ctx->map_fds[i]);
+	}
+}
+
+static void bpf_elf_ctx_destroy(struct bpf_elf_ctx *ctx, bool failure)
+{
+	if (failure)
+		bpf_maps_teardown(ctx);
+
+	bpf_hash_destroy(ctx);
+	free(ctx->sec_done);
+	elf_end(ctx->elf_fd);
+	close(ctx->obj_fd);
+}
+
+static struct bpf_elf_ctx __ctx;
+
+static int bpf_obj_open(const char *pathname, enum bpf_prog_type type,
+			const char *section, bool verbose)
+{
+	struct bpf_elf_ctx *ctx = &__ctx;
+	int fd = 0, ret;
+
+	ret = bpf_elf_ctx_init(ctx, pathname, type, verbose);
+	if (ret < 0) {
+		fprintf(stderr, "Cannot initialize ELF context!\n");
+		return ret;
+	}
+
+	ret = bpf_fetch_ancillary(ctx);
+	if (ret < 0) {
+		fprintf(stderr, "Error fetching ELF ancillary data!\n");
+		goto out;
+	}
+
+	fd = bpf_fetch_prog_sec(ctx, section);
+	if (fd < 0) {
+		fprintf(stderr, "Error fetching program/map!\n");
+		ret = fd;
+		goto out;
+	}
+
+	ret = bpf_fill_prog_arrays(ctx);
+	if (ret < 0)
+		fprintf(stderr, "Error filling program arrays!\n");
+out:
+	bpf_elf_ctx_destroy(ctx, ret < 0);
+	if (ret < 0) {
+		if (fd)
+			close(fd);
+		return ret;
+	}
+
+	return fd;
+}
+
+static int
+bpf_map_set_send(int fd, struct sockaddr_un *addr, unsigned int addr_len,
+		 const struct bpf_map_data *aux, unsigned int entries)
+{
+	struct bpf_map_set_msg msg;
+	int *cmsg_buf, min_fd;
+	char *amsg_buf;
+	int i;
+
+	memset(&msg, 0, sizeof(msg));
+
+	msg.aux.uds_ver = BPF_SCM_AUX_VER;
+	msg.aux.num_ent = entries;
+
+	strncpy(msg.aux.obj_name, aux->obj, sizeof(msg.aux.obj_name));
+	memcpy(&msg.aux.obj_st, aux->st, sizeof(msg.aux.obj_st));
+
+	cmsg_buf = bpf_map_set_init(&msg, addr, addr_len);
+	amsg_buf = (char *)msg.aux.ent;
+
+	for (i = 0; i < entries; i += min_fd) {
+		int ret;
+
+		min_fd = min(BPF_SCM_MAX_FDS * 1U, entries - i);
+		bpf_map_set_init_single(&msg, min_fd);
+
+		memcpy(cmsg_buf, &aux->fds[i], sizeof(aux->fds[0]) * min_fd);
+		memcpy(amsg_buf, &aux->ent[i], sizeof(aux->ent[0]) * min_fd);
+
+		ret = sendmsg(fd, &msg.hdr, 0);
+		if (ret <= 0)
+			return ret ? : -1;
+	}
+
+	return 0;
+}
+
+static int
+bpf_map_set_recv(int fd, int *fds,  struct bpf_map_aux *aux,
+		 unsigned int entries)
+{
+	struct bpf_map_set_msg msg;
+	int *cmsg_buf, min_fd;
+	char *amsg_buf, *mmsg_buf;
+	unsigned int needed = 1;
+	int i;
+
+	cmsg_buf = bpf_map_set_init(&msg, NULL, 0);
+	amsg_buf = (char *)msg.aux.ent;
+	mmsg_buf = (char *)&msg.aux;
+
+	for (i = 0; i < min(entries, needed); i += min_fd) {
+		struct cmsghdr *cmsg;
+		int ret;
+
+		min_fd = min(entries, entries - i);
+		bpf_map_set_init_single(&msg, min_fd);
+
+		ret = recvmsg(fd, &msg.hdr, 0);
+		if (ret <= 0)
+			return ret ? : -1;
+
+		cmsg = CMSG_FIRSTHDR(&msg.hdr);
+		if (!cmsg || cmsg->cmsg_type != SCM_RIGHTS)
+			return -EINVAL;
+		if (msg.hdr.msg_flags & MSG_CTRUNC)
+			return -EIO;
+		if (msg.aux.uds_ver != BPF_SCM_AUX_VER)
+			return -ENOSYS;
+
+		min_fd = (cmsg->cmsg_len - sizeof(*cmsg)) / sizeof(fd);
+		if (min_fd > entries || min_fd <= 0)
+			return -EINVAL;
+
+		memcpy(&fds[i], cmsg_buf, sizeof(fds[0]) * min_fd);
+		memcpy(&aux->ent[i], amsg_buf, sizeof(aux->ent[0]) * min_fd);
+		memcpy(aux, mmsg_buf, offsetof(struct bpf_map_aux, ent));
+
+		needed = aux->num_ent;
+	}
+
+	return 0;
+}
+
+int bpf_send_map_fds(const char *path, const char *obj)
+{
+	struct bpf_elf_ctx *ctx = &__ctx;
+	struct sockaddr_un addr;
+	struct bpf_map_data bpf_aux;
+	int fd, ret;
+
+	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+	if (fd < 0) {
+		fprintf(stderr, "Cannot open socket: %s\n",
+			strerror(errno));
+		return -1;
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sun_family = AF_UNIX;
+	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
+
+	ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+	if (ret < 0) {
+		fprintf(stderr, "Cannot connect to %s: %s\n",
+			path, strerror(errno));
+		return -1;
+	}
+
+	memset(&bpf_aux, 0, sizeof(bpf_aux));
+
+	bpf_aux.fds = ctx->map_fds;
+	bpf_aux.ent = ctx->maps;
+	bpf_aux.st  = &ctx->stat;
+	bpf_aux.obj = obj;
+
+	ret = bpf_map_set_send(fd, &addr, sizeof(addr), &bpf_aux,
+			       bpf_maps_count(ctx));
+	if (ret < 0)
+		fprintf(stderr, "Cannot send fds to %s: %s\n",
+			path, strerror(errno));
+
+	bpf_maps_teardown(ctx);
+	close(fd);
+	return ret;
+}
+
+int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
+		     unsigned int entries)
+{
+	struct sockaddr_un addr;
+	int fd, ret;
+
+	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+	if (fd < 0) {
+		fprintf(stderr, "Cannot open socket: %s\n",
+			strerror(errno));
+		return -1;
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sun_family = AF_UNIX;
+	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
+
+	ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
+	if (ret < 0) {
+		fprintf(stderr, "Cannot bind to socket: %s\n",
+			strerror(errno));
+		return -1;
+	}
+
+	ret = bpf_map_set_recv(fd, fds, aux, entries);
+	if (ret < 0)
+		fprintf(stderr, "Cannot recv fds from %s: %s\n",
+			path, strerror(errno));
+
+	unlink(addr.sun_path);
+	close(fd);
+	return ret;
+}
+#endif /* HAVE_ELF */
diff --git a/tc/tc_bpf.h b/tc/tc_bpf.h
new file mode 100644
index 0000000..526d0b1
--- /dev/null
+++ b/tc/tc_bpf.h
@@ -0,0 +1,79 @@
+/*
+ * tc_bpf.h	BPF common code
+ *
+ *		This program is free software; you can distribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ *
+ * Authors:	Daniel Borkmann <dborkman@redhat.com>
+ *		Jiri Pirko <jiri@resnulli.us>
+ */
+
+#ifndef _TC_BPF_H_
+#define _TC_BPF_H_ 1
+
+#include <linux/netlink.h>
+#include <linux/bpf.h>
+#include <linux/magic.h>
+
+#include "utils.h"
+#include "bpf_scm.h"
+
+enum {
+	BPF_NLA_OPS_LEN = 0,
+	BPF_NLA_OPS,
+	BPF_NLA_FD,
+	BPF_NLA_NAME,
+	__BPF_NLA_MAX,
+};
+
+#define BPF_NLA_MAX	__BPF_NLA_MAX
+
+#define BPF_ENV_UDS	"TC_BPF_UDS"
+#define BPF_ENV_MNT	"TC_BPF_MNT"
+#define BPF_ENV_NOLOG	"TC_BPF_NOLOG"
+
+#ifndef BPF_FS_MAGIC
+# define BPF_FS_MAGIC	0xcafe4a11
+#endif
+
+#define BPF_DIR_MNT	"/sys/fs/bpf"
+
+#define BPF_DIR_TC	"tc"
+#define BPF_DIR_GLOBALS	"globals"
+
+#ifndef TRACEFS_MAGIC
+# define TRACEFS_MAGIC	0x74726163
+#endif
+
+#define TRACE_DIR_MNT	"/sys/kernel/tracing"
+
+int bpf_trace_pipe(void);
+const char *bpf_default_section(const enum bpf_prog_type type);
+
+int bpf_parse_common(int *ptr_argc, char ***ptr_argv, const int *nla_tbl,
+		     enum bpf_prog_type type, const char **ptr_object,
+		     const char **ptr_uds_name, struct nlmsghdr *n);
+int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv);
+
+void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len);
+
+#ifdef HAVE_ELF
+int bpf_send_map_fds(const char *path, const char *obj);
+int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
+		     unsigned int entries);
+#else
+static inline int bpf_send_map_fds(const char *path, const char *obj)
+{
+	return 0;
+}
+
+static inline int bpf_recv_map_fds(const char *path, int *fds,
+				   struct bpf_map_aux *aux,
+				   unsigned int entries)
+{
+	return -1;
+}
+#endif /* HAVE_ELF */
+#endif /* _TC_BPF_H_ */
diff --git a/tc/tc_cbq.c b/tc/tc_cbq.c
index f56011a..0bb262e 100644
--- a/tc/tc_cbq.c
+++ b/tc/tc_cbq.c
@@ -1,5 +1,5 @@
 /*
- * tc_cbq.c		CBQ maintenance routines.
+ * tc_cbq.c		CBQ maintanance routines.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <math.h>
 #include <sys/socket.h>
@@ -20,12 +21,11 @@
 #include <arpa/inet.h>
 #include <string.h>
 
-#include "utils.h"
 #include "tc_core.h"
 #include "tc_cbq.h"
 
-unsigned int tc_cbq_calc_maxidle(unsigned int bndw, unsigned int rate, unsigned int avpkt,
-			     int ewma_log, unsigned int maxburst)
+unsigned tc_cbq_calc_maxidle(unsigned bndw, unsigned rate, unsigned avpkt,
+			     int ewma_log, unsigned maxburst)
 {
 	double maxidle;
 	double g = 1.0 - 1.0/(1<<ewma_log);
@@ -34,7 +34,6 @@
 	maxidle = xmt*(1-g);
 	if (bndw != rate && maxburst) {
 		double vxmt = (double)avpkt/rate - xmt;
-
 		vxmt *= (pow(g, -(double)maxburst) - 1);
 		if (vxmt > maxidle)
 			maxidle = vxmt;
@@ -42,8 +41,8 @@
 	return tc_core_time2tick(maxidle*(1<<ewma_log)*TIME_UNITS_PER_SEC);
 }
 
-unsigned int tc_cbq_calc_offtime(unsigned int bndw, unsigned int rate, unsigned int avpkt,
-			     int ewma_log, unsigned int minburst)
+unsigned tc_cbq_calc_offtime(unsigned bndw, unsigned rate, unsigned avpkt,
+			     int ewma_log, unsigned minburst)
 {
 	double g = 1.0 - 1.0/(1<<ewma_log);
 	double offtime = (double)avpkt/rate - (double)avpkt/bndw;
diff --git a/tc/tc_cbq.h b/tc/tc_cbq.h
index fa17d24..8f95649 100644
--- a/tc/tc_cbq.h
+++ b/tc/tc_cbq.h
@@ -1,4 +1,3 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _TC_CBQ_H_
 #define _TC_CBQ_H_ 1
 
diff --git a/tc/tc_class.c b/tc/tc_class.c
index c7e3cfd..3acd030 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -23,7 +24,7 @@
 #include "utils.h"
 #include "tc_util.h"
 #include "tc_common.h"
-#include "list.h"
+#include "hlist.h"
 
 struct graph_node {
 	struct hlist_node hlist;
@@ -43,33 +44,38 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: tc class [ add | del | change | replace | show ] dev STRING\n"
-		"       [ classid CLASSID ] [ root | parent CLASSID ]\n"
-		"       [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n"
-		"\n"
-		"       tc class show [ dev STRING ] [ root | parent CLASSID ]\n"
-		"Where:\n"
-		"QDISC_KIND := { prio | cbq | etc. }\n"
-		"OPTIONS := ... try tc class add <desired QDISC_KIND> help\n");
+	fprintf(stderr, "Usage: tc class [ add | del | change | replace | show ] dev STRING\n");
+	fprintf(stderr, "       [ classid CLASSID ] [ root | parent CLASSID ]\n");
+	fprintf(stderr, "       [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "       tc class show [ dev STRING ] [ root | parent CLASSID ]\n");
+	fprintf(stderr, "Where:\n");
+	fprintf(stderr, "QDISC_KIND := { prio | cbq | etc. }\n");
+	fprintf(stderr, "OPTIONS := ... try tc class add <desired QDISC_KIND> help\n");
+	return;
 }
 
-static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
+static int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
 {
 	struct {
-		struct nlmsghdr	n;
-		struct tcmsg		t;
-		char			buf[4096];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.t.tcm_family = AF_UNSPEC,
-	};
+		struct nlmsghdr 	n;
+		struct tcmsg 		t;
+		char   			buf[4096];
+	} req;
 	struct qdisc_util *q = NULL;
-	struct tc_estimator est = {};
-	char  d[IFNAMSIZ] = {};
-	char  k[FILTER_NAMESZ] = {};
+	struct tc_estimator est;
+	char  d[16];
+	char  k[16];
+
+	memset(&req, 0, sizeof(req));
+	memset(&est, 0, sizeof(est));
+	memset(d, 0, sizeof(d));
+	memset(k, 0, sizeof(k));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.t.tcm_family = AF_UNSPEC;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -79,7 +85,6 @@
 			strncpy(d, *argv, sizeof(d)-1);
 		} else if (strcmp(*argv, "classid") == 0) {
 			__u32 handle;
-
 			NEXT_ARG();
 			if (req.t.tcm_handle)
 				duparg("classid", *argv);
@@ -97,7 +102,6 @@
 			req.t.tcm_parent = TC_H_ROOT;
 		} else if (strcmp(*argv, "parent") == 0) {
 			__u32 handle;
-
 			NEXT_ARG();
 			if (req.t.tcm_parent)
 				duparg("parent", *argv);
@@ -129,7 +133,7 @@
 			fprintf(stderr, "Error: Qdisc \"%s\" is classless.\n", k);
 			return 1;
 		}
-		if (q->parse_copt(q, argc, argv, &req.n, d))
+		if (q->parse_copt(q, argc, argv, &req.n))
 			return 1;
 	} else {
 		if (argc) {
@@ -143,26 +147,28 @@
 	if (d[0])  {
 		ll_init_map(&rth);
 
-		req.t.tcm_ifindex = ll_name_to_index(d);
-		if (!req.t.tcm_ifindex)
-			return -nodev(d);
+		if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
+			return 1;
+		}
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return 2;
 
 	return 0;
 }
 
-static int filter_ifindex;
-static __u32 filter_qdisc;
-static __u32 filter_classid;
+int filter_ifindex;
+__u32 filter_qdisc;
+__u32 filter_classid;
 
 static void graph_node_add(__u32 parent_id, __u32 id, void *data,
 		int len)
 {
-	struct graph_node *node = calloc(1, sizeof(struct graph_node));
+	struct graph_node *node = malloc(sizeof(struct graph_node));
 
+	memset(node, 0, sizeof(*node));
 	node->id         = id;
 	node->parent_id  = parent_id;
 
@@ -217,9 +223,9 @@
 {
 	struct hlist_node *n, *tmp_cls;
 	char cls_id_str[256] = {};
-	struct rtattr *tb[TCA_MAX + 1];
+	struct rtattr *tb[TCA_MAX + 1] = {};
 	struct qdisc_util *q;
-	char str[300] = {};
+	char str[100] = {};
 
 	hlist_for_each_safe(n, tmp_cls, root_list) {
 		struct hlist_node *c, *tmp_chld;
@@ -242,8 +248,7 @@
 		graph_indent(buf, cls, 0, 0);
 
 		print_tc_classid(cls_id_str, sizeof(cls_id_str), cls->id);
-		snprintf(str, sizeof(str),
-			 "+---(%s)", cls_id_str);
+		sprintf(str, "+---(%s)", cls_id_str);
 		strcat(buf, str);
 
 		parse_rtattr(tb, TCA_MAX, (struct rtattr *)cls->data,
@@ -297,12 +302,13 @@
 	}
 }
 
-int print_class(struct nlmsghdr *n, void *arg)
+int print_class(const struct sockaddr_nl *who,
+		       struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct tcmsg *t = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[TCA_MAX + 1];
+	struct rtattr *tb[TCA_MAX + 1] = {};
 	struct qdisc_util *q;
 	char abuf[256];
 
@@ -387,10 +393,14 @@
 
 static int tc_class_list(int argc, char **argv)
 {
-	struct tcmsg t = { .tcm_family = AF_UNSPEC };
-	char d[IFNAMSIZ] = {};
+	struct tcmsg t;
+	char d[16];
 	char buf[1024] = {0};
 
+	memset(&t, 0, sizeof(t));
+	t.tcm_family = AF_UNSPEC;
+	memset(d, 0, sizeof(d));
+
 	filter_qdisc = 0;
 	filter_classid = 0;
 
@@ -420,7 +430,6 @@
 			t.tcm_parent = TC_H_ROOT;
 		} else if (strcmp(*argv, "parent") == 0) {
 			__u32 handle;
-
 			if (t.tcm_parent)
 				duparg("parent", *argv);
 			NEXT_ARG();
@@ -440,9 +449,10 @@
 	ll_init_map(&rth);
 
 	if (d[0]) {
-		t.tcm_ifindex = ll_name_to_index(d);
-		if (!t.tcm_ifindex)
-			return -nodev(d);
+		if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
+			return 1;
+		}
 		filter_ifindex = t.tcm_ifindex;
 	}
 
diff --git a/tc/tc_common.h b/tc/tc_common.h
index 802fb7f..a2f3898 100644
--- a/tc/tc_common.h
+++ b/tc/tc_common.h
@@ -1,29 +1,27 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 
 #define TCA_BUF_MAX	(64*1024)
 
 extern struct rtnl_handle rth;
 
-int do_qdisc(int argc, char **argv);
-int do_class(int argc, char **argv);
-int do_filter(int argc, char **argv);
-int do_chain(int argc, char **argv);
-int do_action(int argc, char **argv);
-int do_tcmonitor(int argc, char **argv);
-int do_exec(int argc, char **argv);
+extern int do_qdisc(int argc, char **argv);
+extern int do_class(int argc, char **argv);
+extern int do_filter(int argc, char **argv);
+extern int do_action(int argc, char **argv);
+extern int do_tcmonitor(int argc, char **argv);
+extern int do_exec(int argc, char **argv);
 
-int print_action(struct nlmsghdr *n, void *arg);
-int print_filter(struct nlmsghdr *n, void *arg);
-int print_qdisc(struct nlmsghdr *n, void *arg);
-int print_class(struct nlmsghdr *n, void *arg);
-void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta);
+extern int print_action(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+extern int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+extern int print_qdisc(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+extern int print_class(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+extern void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta);
 
 struct tc_estimator;
-int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est);
+extern int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est);
 
 struct tc_sizespec;
-int parse_size_table(int *p_argc, char ***p_argv, struct tc_sizespec *s);
-int check_size_table_opts(struct tc_sizespec *s);
+extern int parse_size_table(int *p_argc, char ***p_argv, struct tc_sizespec *s);
+extern int check_size_table_opts(struct tc_sizespec *s);
 
 extern int show_graph;
 extern bool use_names;
diff --git a/tc/tc_core.c b/tc/tc_core.c
index 498d35d..46eaefb 100644
--- a/tc/tc_core.c
+++ b/tc/tc_core.c
@@ -12,8 +12,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <math.h>
 #include <sys/socket.h>
@@ -21,14 +21,13 @@
 #include <arpa/inet.h>
 #include <string.h>
 
-#include "utils.h"
 #include "tc_core.h"
 #include <linux/atm.h>
 
 static double tick_in_usec = 1;
 static double clock_factor = 1;
 
-int tc_core_time2big(unsigned int time)
+int tc_core_time2big(unsigned time)
 {
 	__u64 t = time;
 
@@ -37,32 +36,32 @@
 }
 
 
-unsigned int tc_core_time2tick(unsigned int time)
+unsigned tc_core_time2tick(unsigned time)
 {
 	return time*tick_in_usec;
 }
 
-unsigned int tc_core_tick2time(unsigned int tick)
+unsigned tc_core_tick2time(unsigned tick)
 {
 	return tick/tick_in_usec;
 }
 
-unsigned int tc_core_time2ktime(unsigned int time)
+unsigned tc_core_time2ktime(unsigned time)
 {
 	return time * clock_factor;
 }
 
-unsigned int tc_core_ktime2time(unsigned int ktime)
+unsigned tc_core_ktime2time(unsigned ktime)
 {
 	return ktime / clock_factor;
 }
 
-unsigned int tc_calc_xmittime(__u64 rate, unsigned int size)
+unsigned tc_calc_xmittime(__u64 rate, unsigned size)
 {
 	return tc_core_time2tick(TIME_UNITS_PER_SEC*((double)size/(double)rate));
 }
 
-unsigned int tc_calc_xmitsize(__u64 rate, unsigned int ticks)
+unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks)
 {
 	return ((double)rate*tc_core_tick2time(ticks))/TIME_UNITS_PER_SEC;
 }
@@ -77,10 +76,9 @@
  * (as the table will always be aligned for 48 bytes).
  *  --Hawk, d.7/11-2004. <hawk@diku.dk>
  */
-static unsigned int tc_align_to_atm(unsigned int size)
+static unsigned tc_align_to_atm(unsigned size)
 {
 	int linksize, cells;
-
 	cells = size / ATM_CELL_PAYLOAD;
 	if ((size % ATM_CELL_PAYLOAD) > 0)
 		cells++;
@@ -89,7 +87,7 @@
 	return linksize;
 }
 
-static unsigned int tc_adjust_size(unsigned int sz, unsigned int mpu, enum link_layer linklayer)
+static unsigned tc_adjust_size(unsigned sz, unsigned mpu, enum link_layer linklayer)
 {
 	if (sz < mpu)
 		sz = mpu;
@@ -99,7 +97,7 @@
 		return tc_align_to_atm(sz);
 	case LINKLAYER_ETHERNET:
 	default:
-		/* No size adjustments on Ethernet */
+		// No size adjustments on Ethernet
 		return sz;
 	}
 }
@@ -124,13 +122,13 @@
  */
 
 int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab,
-		   int cell_log, unsigned int mtu,
+		   int cell_log, unsigned mtu,
 		   enum link_layer linklayer)
 {
 	int i;
-	unsigned int sz;
-	unsigned int bps = r->rate;
-	unsigned int mpu = r->mpu;
+	unsigned sz;
+	unsigned bps = r->rate;
+	unsigned mpu = r->mpu;
 
 	if (mtu == 0)
 		mtu = 2047;
@@ -141,42 +139,13 @@
 			cell_log++;
 	}
 
-	for (i = 0; i < 256; i++) {
+	for (i=0; i<256; i++) {
 		sz = tc_adjust_size((i + 1) << cell_log, mpu, linklayer);
 		rtab[i] = tc_calc_xmittime(bps, sz);
 	}
 
-	r->cell_align =  -1;
-	r->cell_log = cell_log;
-	r->linklayer = (linklayer & TC_LINKLAYER_MASK);
-	return cell_log;
-}
-
-int tc_calc_rtable_64(struct tc_ratespec *r, __u32 *rtab,
-		   int cell_log, unsigned int mtu,
-		   enum link_layer linklayer, __u64 rate)
-{
-	int i;
-	unsigned int sz;
-	__u64 bps = rate;
-	unsigned int mpu = r->mpu;
-
-	if (mtu == 0)
-		mtu = 2047;
-
-	if (cell_log < 0) {
-		cell_log = 0;
-		while ((mtu >> cell_log) > 255)
-			cell_log++;
-	}
-
-	for (i = 0; i < 256; i++) {
-		sz = tc_adjust_size((i + 1) << cell_log, mpu, linklayer);
-		rtab[i] = tc_calc_xmittime(bps, sz);
-	}
-
-	r->cell_align =  -1;
-	r->cell_log = cell_log;
+	r->cell_align=-1; // Due to the sz calc
+	r->cell_log=cell_log;
 	r->linklayer = (linklayer & TC_LINKLAYER_MASK);
 	return cell_log;
 }
@@ -224,7 +193,7 @@
 		(*stab)[i] = sz >> s->size_log;
 	}
 
-	s->cell_align = -1; /* Due to the sz calc */
+	s->cell_align = -1; // Due to the sz calc
 	return 0;
 }
 
diff --git a/tc/tc_core.h b/tc/tc_core.h
index 6dab272..8a63b79 100644
--- a/tc/tc_core.h
+++ b/tc/tc_core.h
@@ -1,10 +1,11 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _TC_CORE_H_
 #define _TC_CORE_H_ 1
 
 #include <asm/types.h>
 #include <linux/pkt_sched.h>
 
+#define TIME_UNITS_PER_SEC	1000000
+
 enum link_layer {
 	LINKLAYER_UNSPEC,
 	LINKLAYER_ETHERNET,
@@ -21,9 +22,6 @@
 unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks);
 int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab,
 		   int cell_log, unsigned mtu, enum link_layer link_layer);
-int tc_calc_rtable_64(struct tc_ratespec *r, __u32 *rtab,
-			int cell_log, unsigned mtu, enum link_layer link_layer,
-			__u64 rate);
 int tc_calc_size_table(struct tc_sizespec *s, __u16 **stab);
 
 int tc_setup_estimator(unsigned A, unsigned time_const, struct tc_estimator *est);
diff --git a/tc/tc_estimator.c b/tc/tc_estimator.c
index f494b7c..e559add 100644
--- a/tc/tc_estimator.c
+++ b/tc/tc_estimator.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <math.h>
 #include <sys/socket.h>
@@ -20,26 +21,24 @@
 #include <arpa/inet.h>
 #include <string.h>
 
-#include "utils.h"
 #include "tc_core.h"
 
-int tc_setup_estimator(unsigned int A, unsigned int time_const, struct tc_estimator *est)
+int tc_setup_estimator(unsigned A, unsigned time_const, struct tc_estimator *est)
 {
-	for (est->interval = 0; est->interval <= 5; est->interval++) {
+	for (est->interval=0; est->interval<=5; est->interval++) {
 		if (A <= (1<<est->interval)*(TIME_UNITS_PER_SEC/4))
 			break;
 	}
 	if (est->interval > 5)
 		return -1;
 	est->interval -= 2;
-	for (est->ewma_log = 1; est->ewma_log < 32; est->ewma_log++) {
+	for (est->ewma_log=1; est->ewma_log<32; est->ewma_log++) {
 		double w = 1.0 - 1.0/(1<<est->ewma_log);
-
 		if (A/(-log(w)) > time_const)
 			break;
 	}
 	est->ewma_log--;
-	if (est->ewma_log == 0 || est->ewma_log >= 31)
+	if (est->ewma_log==0 || est->ewma_log >= 31)
 		return -1;
 	return 0;
 }
diff --git a/tc/tc_exec.c b/tc/tc_exec.c
index 9b912ce..61be672 100644
--- a/tc/tc_exec.c
+++ b/tc/tc_exec.c
@@ -19,22 +19,21 @@
 #include "tc_common.h"
 
 static struct exec_util *exec_list;
-static void *BODY;
+static void *BODY = NULL;
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: tc exec [ EXEC_TYPE ] [ help | OPTIONS ]\n"
-		"Where:\n"
-		"EXEC_TYPE := { bpf | etc. }\n"
-		"OPTIONS := ... try tc exec <desired EXEC_KIND> help\n");
+	fprintf(stderr, "Usage: tc exec [ EXEC_TYPE ] [ help | OPTIONS ]\n");
+	fprintf(stderr, "Where:\n");
+	fprintf(stderr, "EXEC_TYPE := { bpf | etc. }\n");
+	fprintf(stderr, "OPTIONS := ... try tc exec <desired EXEC_KIND> help\n");
 }
 
 static int parse_noeopt(struct exec_util *eu, int argc, char **argv)
 {
 	if (argc) {
-		fprintf(stderr, "Unknown exec \"%s\", hence option \"%s\" is unparsable\n",
-			eu->id, *argv);
+		fprintf(stderr, "Unknown exec \"%s\", hence option \"%s\" "
+			"is unparsable\n", eu->id, *argv);
 		return -1;
 	}
 
@@ -72,8 +71,9 @@
 
 	return eu;
 noexist:
-	eu = calloc(1, sizeof(*eu));
+	eu = malloc(sizeof(*eu));
 	if (eu) {
+		memset(eu, 0, sizeof(*eu));
 		strncpy(eu->id, name, sizeof(eu->id) - 1);
 		eu->parse_eopt = parse_noeopt;
 		goto reg;
@@ -85,7 +85,7 @@
 int do_exec(int argc, char **argv)
 {
 	struct exec_util *eu;
-	char kind[FILTER_NAMESZ] = {};
+	char kind[16];
 
 	if (argc < 1) {
 		fprintf(stderr, "No command given, try \"tc exec help\".\n");
@@ -97,6 +97,7 @@
 		return 0;
 	}
 
+	memset(kind, 0, sizeof(kind));
 	strncpy(kind, *argv, sizeof(kind) - 1);
 
 	eu = get_exec_kind(kind);
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index f7d2e4a..1a1082b 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,60 +28,45 @@
 
 static void usage(void)
 {
-	fprintf(stderr,
-		"Usage: tc filter [ add | del | change | replace | show ] [ dev STRING ]\n"
-		"       tc filter [ add | del | change | replace | show ] [ block BLOCK_INDEX ]\n"
-		"       tc filter get dev STRING parent CLASSID protocol PROTO handle FILTERID pref PRIO FILTER_TYPE\n"
-		"       tc filter get block BLOCK_INDEX protocol PROTO handle FILTERID pref PRIO FILTER_TYPE\n"
-		"       [ pref PRIO ] protocol PROTO [ chain CHAIN_INDEX ]\n"
-		"       [ estimator INTERVAL TIME_CONSTANT ]\n"
-		"       [ root | ingress | egress | parent CLASSID ]\n"
-		"       [ handle FILTERID ] [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n"
-		"\n"
-		"       tc filter show [ dev STRING ] [ root | ingress | egress | parent CLASSID ]\n"
-		"       tc filter show [ block BLOCK_INDEX ]\n"
-		"Where:\n"
-		"FILTER_TYPE := { rsvp | u32 | bpf | fw | route | etc. }\n"
-		"FILTERID := ... format depends on classifier, see there\n"
-		"OPTIONS := ... try tc filter add <desired FILTER_KIND> help\n");
+	fprintf(stderr, "Usage: tc filter [ add | del | change | replace | show ] dev STRING\n");
+	fprintf(stderr, "       [ pref PRIO ] protocol PROTO\n");
+	fprintf(stderr, "       [ estimator INTERVAL TIME_CONSTANT ]\n");
+	fprintf(stderr, "       [ root | ingress | egress | parent CLASSID ]\n");
+	fprintf(stderr, "       [ handle FILTERID ] [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "       tc filter show [ dev STRING ] [ root | ingress | egress | parent CLASSID ]\n");
+	fprintf(stderr, "Where:\n");
+	fprintf(stderr, "FILTER_TYPE := { rsvp | u32 | bpf | fw | route | etc. }\n");
+	fprintf(stderr, "FILTERID := ... format depends on classifier, see there\n");
+	fprintf(stderr, "OPTIONS := ... try tc filter add <desired FILTER_KIND> help\n");
 }
 
-static void chain_usage(void)
-{
-	fprintf(stderr,
-		"Usage: tc chain [ add | del | get | show ] [ dev STRING ]\n"
-		"       tc chain [ add | del | get | show ] [ block BLOCK_INDEX ] ]\n");
-}
-
-struct tc_filter_req {
-	struct nlmsghdr		n;
-	struct tcmsg		t;
-	char			buf[MAX_MSG];
-};
-
-static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)
+static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
 {
 	struct {
-		struct nlmsghdr	n;
-		struct tcmsg		t;
-		char			buf[MAX_MSG];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.t.tcm_family = AF_UNSPEC,
-	};
+		struct nlmsghdr 	n;
+		struct tcmsg 		t;
+		char   			buf[MAX_MSG];
+	} req;
 	struct filter_util *q = NULL;
 	__u32 prio = 0;
 	__u32 protocol = 0;
 	int protocol_set = 0;
-	__u32 block_index = 0;
-	__u32 chain_index;
-	int chain_index_set = 0;
 	char *fhandle = NULL;
-	char  d[IFNAMSIZ] = {};
-	char  k[FILTER_NAMESZ] = {};
-	struct tc_estimator est = {};
+	char  d[16];
+	char  k[16];
+	struct tc_estimator est;
+
+	memset(&req, 0, sizeof(req));
+	memset(&est, 0, sizeof(est));
+	memset(d, 0, sizeof(d));
+	memset(k, 0, sizeof(k));
+	memset(&req, 0, sizeof(req));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.t.tcm_family = AF_UNSPEC;
 
 	if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE)
 		protocol = htons(ETH_P_ALL);
@@ -90,47 +76,29 @@
 			NEXT_ARG();
 			if (d[0])
 				duparg("dev", *argv);
-			if (block_index) {
-				fprintf(stderr, "Error: \"dev\" and \"block\" are mutually exclusive\n");
-				return -1;
-			}
 			strncpy(d, *argv, sizeof(d)-1);
-		} else if (matches(*argv, "block") == 0) {
-			NEXT_ARG();
-			if (block_index)
-				duparg("block", *argv);
-			if (d[0]) {
-				fprintf(stderr, "Error: \"dev\" and \"block\" are mutually exclusive\n");
-				return -1;
-			}
-			if (get_u32(&block_index, *argv, 0) || !block_index)
-				invarg("invalid block index value", *argv);
 		} else if (strcmp(*argv, "root") == 0) {
 			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"root\" is duplicate parent ID\n");
+				fprintf(stderr, "Error: \"root\" is duplicate parent ID\n");
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_ROOT;
 		} else if (strcmp(*argv, "ingress") == 0) {
 			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"ingress\" is duplicate parent ID\n");
+				fprintf(stderr, "Error: \"ingress\" is duplicate parent ID\n");
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
 						     TC_H_MIN_INGRESS);
 		} else if (strcmp(*argv, "egress") == 0) {
 			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"egress\" is duplicate parent ID\n");
+				fprintf(stderr, "Error: \"egress\" is duplicate parent ID\n");
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
 						     TC_H_MIN_EGRESS);
 		} else if (strcmp(*argv, "parent") == 0) {
 			__u32 handle;
-
 			NEXT_ARG();
 			if (req.t.tcm_parent)
 				duparg("parent", *argv);
@@ -151,7 +119,6 @@
 				invarg("invalid priority value", *argv);
 		} else if (matches(*argv, "protocol") == 0) {
 			__u16 id;
-
 			NEXT_ARG();
 			if (protocol_set)
 				duparg("protocol", *argv);
@@ -159,13 +126,6 @@
 				invarg("invalid protocol", *argv);
 			protocol = id;
 			protocol_set = 1;
-		} else if (matches(*argv, "chain") == 0) {
-			NEXT_ARG();
-			if (chain_index_set)
-				duparg("chain", *argv);
-			if (get_u32(&chain_index, *argv, 0))
-				invarg("invalid chain index value", *argv);
-			chain_index_set = 1;
 		} else if (matches(*argv, "estimator") == 0) {
 			if (parse_estimator(&argc, &argv, &est) < 0)
 				return -1;
@@ -185,48 +145,39 @@
 
 	req.t.tcm_info = TC_H_MAKE(prio<<16, protocol);
 
-	if (chain_index_set)
-		addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
-
 	if (k[0])
 		addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1);
 
-	if (d[0])  {
-		ll_init_map(&rth);
-
-		req.t.tcm_ifindex = ll_name_to_index(d);
-		if (req.t.tcm_ifindex == 0) {
-			fprintf(stderr, "Cannot find device \"%s\"\n", d);
-			return 1;
-		}
-	} else if (block_index) {
-		req.t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
-		req.t.tcm_block_index = block_index;
-	}
-
 	if (q) {
 		if (q->parse_fopt(q, fhandle, argc, argv, &req.n))
 			return 1;
 	} else {
 		if (fhandle) {
-			fprintf(stderr,
-				"Must specify filter type when using \"handle\"\n");
+			fprintf(stderr, "Must specify filter type when using "
+				"\"handle\"\n");
 			return -1;
 		}
 		if (argc) {
 			if (matches(*argv, "help") == 0)
 				usage();
-			fprintf(stderr,
-				"Garbage instead of arguments \"%s ...\". Try \"tc filter help\".\n",
-				*argv);
+			fprintf(stderr, "Garbage instead of arguments \"%s ...\". Try \"tc filter help\".\n", *argv);
 			return -1;
 		}
 	}
-
 	if (est.ewma_log)
 		addattr_l(&req.n, sizeof(req), TCA_RATE, &est, sizeof(est));
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0) {
+
+	if (d[0])  {
+		ll_init_map(&rth);
+
+		if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
+			return 1;
+		}
+	}
+
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
 		fprintf(stderr, "We have an error talking to the kernel\n");
 		return 2;
 	}
@@ -238,27 +189,21 @@
 static int filter_ifindex;
 static __u32 filter_prio;
 static __u32 filter_protocol;
-static __u32 filter_chain_index;
-static int filter_chain_index_set;
-static __u32 filter_block_index;
-__u16 f_proto;
+__u16 f_proto = 0;
 
-int print_filter(struct nlmsghdr *n, void *arg)
+int print_filter(const struct sockaddr_nl *who,
+			struct nlmsghdr *n,
+			void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct tcmsg *t = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[TCA_MAX+1];
+	struct rtattr * tb[TCA_MAX+1];
 	struct filter_util *q;
 	char abuf[256];
 
-	if (n->nlmsg_type != RTM_NEWTFILTER &&
-	    n->nlmsg_type != RTM_GETTFILTER &&
-	    n->nlmsg_type != RTM_DELTFILTER &&
-	    n->nlmsg_type != RTM_NEWCHAIN &&
-	    n->nlmsg_type != RTM_GETCHAIN &&
-	    n->nlmsg_type != RTM_DELCHAIN) {
-		fprintf(stderr, "Not a filter(cmd %d)\n", n->nlmsg_type);
+	if (n->nlmsg_type != RTM_NEWTFILTER && n->nlmsg_type != RTM_DELTFILTER) {
+		fprintf(stderr, "Not a filter\n");
 		return 0;
 	}
 	len -= NLMSG_LENGTH(sizeof(*t));
@@ -267,395 +212,116 @@
 		return -1;
 	}
 
+	memset(tb, 0, sizeof(tb));
 	parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
 
-	if (tb[TCA_KIND] == NULL && (n->nlmsg_type == RTM_NEWTFILTER ||
-				     n->nlmsg_type == RTM_GETTFILTER ||
-				     n->nlmsg_type == RTM_DELTFILTER)) {
+	if (tb[TCA_KIND] == NULL) {
 		fprintf(stderr, "print_filter: NULL kind\n");
 		return -1;
 	}
 
-	open_json_object(NULL);
+	if (n->nlmsg_type == RTM_DELTFILTER)
+		fprintf(fp, "deleted ");
 
-	if (n->nlmsg_type == RTM_DELTFILTER || n->nlmsg_type == RTM_DELCHAIN)
-		print_bool(PRINT_ANY, "deleted", "deleted ", true);
+	fprintf(fp, "filter ");
+	if (!filter_ifindex || filter_ifindex != t->tcm_ifindex)
+		fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex));
 
-	if ((n->nlmsg_type == RTM_NEWTFILTER ||
-	     n->nlmsg_type == RTM_NEWCHAIN) &&
-			(n->nlmsg_flags & NLM_F_CREATE) &&
-			!(n->nlmsg_flags & NLM_F_EXCL))
-		print_bool(PRINT_ANY, "replaced", "replaced ", true);
-
-	if ((n->nlmsg_type == RTM_NEWTFILTER ||
-	     n->nlmsg_type == RTM_NEWCHAIN) &&
-			(n->nlmsg_flags & NLM_F_CREATE) &&
-			(n->nlmsg_flags & NLM_F_EXCL))
-		print_bool(PRINT_ANY, "added", "added ", true);
-
-	if (n->nlmsg_type == RTM_NEWTFILTER ||
-	    n->nlmsg_type == RTM_GETTFILTER ||
-	    n->nlmsg_type == RTM_DELTFILTER)
-		print_string(PRINT_FP, NULL, "filter ", NULL);
-	else
-		print_string(PRINT_FP, NULL, "chain ", NULL);
-	if (t->tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK) {
-		if (!filter_block_index ||
-		    filter_block_index != t->tcm_block_index)
-			print_uint(PRINT_ANY, "block", "block %u ",
-				   t->tcm_block_index);
-	} else {
-		if (!filter_ifindex || filter_ifindex != t->tcm_ifindex)
-			print_devname(PRINT_ANY, t->tcm_ifindex);
-
-		if (!filter_parent || filter_parent != t->tcm_parent) {
-			if (t->tcm_parent == TC_H_ROOT)
-				print_bool(PRINT_ANY, "root", "root ", true);
-			else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS))
-				print_bool(PRINT_ANY, "ingress", "ingress ", true);
-			else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_EGRESS))
-				print_bool(PRINT_ANY, "egress", "egress ", true);
-			else {
-				print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
-				print_string(PRINT_ANY, "parent", "parent %s ", abuf);
-			}
+	if (!filter_parent || filter_parent != t->tcm_parent) {
+		if (t->tcm_parent == TC_H_ROOT)
+			fprintf(fp, "root ");
+		else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS))
+			fprintf(fp, "ingress ");
+		else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_EGRESS))
+			fprintf(fp, "egress ");
+		else {
+			print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
+			fprintf(fp, "parent %s ", abuf);
 		}
 	}
 
-	if (t->tcm_info && (n->nlmsg_type == RTM_NEWTFILTER ||
-			    n->nlmsg_type == RTM_DELTFILTER ||
-			    n->nlmsg_type == RTM_GETTFILTER)) {
+	if (t->tcm_info) {
 		f_proto = TC_H_MIN(t->tcm_info);
 		__u32 prio = TC_H_MAJ(t->tcm_info)>>16;
-
 		if (!filter_protocol || filter_protocol != f_proto) {
 			if (f_proto) {
 				SPRINT_BUF(b1);
-				print_string(PRINT_ANY, "protocol",
-					     "protocol %s ",
-					     ll_proto_n2a(f_proto, b1, sizeof(b1)));
+				fprintf(fp, "protocol %s ",
+					ll_proto_n2a(f_proto, b1, sizeof(b1)));
 			}
 		}
 		if (!filter_prio || filter_prio != prio) {
 			if (prio)
-				print_uint(PRINT_ANY, "pref", "pref %u ", prio);
+				fprintf(fp, "pref %u ", prio);
 		}
 	}
-	if (tb[TCA_KIND])
-		print_string(PRINT_ANY, "kind", "%s ", rta_getattr_str(tb[TCA_KIND]));
-
-	if (tb[TCA_CHAIN]) {
-		__u32 chain_index = rta_getattr_u32(tb[TCA_CHAIN]);
-
-		if (!filter_chain_index_set ||
-		    filter_chain_index != chain_index)
-			print_uint(PRINT_ANY, "chain", "chain %u ",
-				   chain_index);
+	fprintf(fp, "%s ", rta_getattr_str(tb[TCA_KIND]));
+	q = get_filter_kind(RTA_DATA(tb[TCA_KIND]));
+	if (tb[TCA_OPTIONS]) {
+		if (q)
+			q->print_fopt(q, fp, tb[TCA_OPTIONS], t->tcm_handle);
+		else
+			fprintf(fp, "[cannot parse parameters]");
 	}
-
-	if (tb[TCA_KIND]) {
-		q = get_filter_kind(RTA_DATA(tb[TCA_KIND]));
-		if (tb[TCA_OPTIONS]) {
-			open_json_object("options");
-			if (q)
-				q->print_fopt(q, fp, tb[TCA_OPTIONS], t->tcm_handle);
-			else
-				fprintf(stderr, "cannot parse option parameters\n");
-			close_json_object();
-		}
-	}
-	print_string(PRINT_FP, NULL, "\n", NULL);
+	fprintf(fp, "\n");
 
 	if (show_stats && (tb[TCA_STATS] || tb[TCA_STATS2])) {
 		print_tcstats_attr(fp, tb, " ", NULL);
-		print_string(PRINT_FP, NULL, "\n", NULL);
+		fprintf(fp, "\n");
 	}
 
-	close_json_object();
 	fflush(fp);
 	return 0;
 }
 
-static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)
+static int tc_filter_list(int argc, char **argv)
 {
-	struct {
-		struct nlmsghdr	n;
-		struct tcmsg		t;
-		char			buf[MAX_MSG];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
-		/* NLM_F_ECHO is for backward compatibility. old kernels never
-		 * respond without it and newer kernels will ignore it.
-		 * In old kernels there is a side effect:
-		 * In addition to a response to the GET you will receive an
-		 * event (if you do tc mon).
-		 */
-		.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ECHO | flags,
-		.n.nlmsg_type = cmd,
-		.t.tcm_parent = TC_H_UNSPEC,
-		.t.tcm_family = AF_UNSPEC,
-	};
-	struct nlmsghdr *answer;
-	struct filter_util *q = NULL;
+	struct tcmsg t;
+	char d[16];
 	__u32 prio = 0;
 	__u32 protocol = 0;
-	int protocol_set = 0;
-	__u32 chain_index;
-	int chain_index_set = 0;
-	__u32 block_index = 0;
-	__u32 parent_handle = 0;
 	char *fhandle = NULL;
-	char  d[IFNAMSIZ] = {};
-	char  k[FILTER_NAMESZ] = {};
+
+	memset(&t, 0, sizeof(t));
+	t.tcm_family = AF_UNSPEC;
+	memset(d, 0, sizeof(d));
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			if (d[0])
 				duparg("dev", *argv);
-			if (block_index) {
-				fprintf(stderr, "Error: \"dev\" and \"block\" are mutually exclusive\n");
-				return -1;
-			}
 			strncpy(d, *argv, sizeof(d)-1);
-		} else if (matches(*argv, "block") == 0) {
-			NEXT_ARG();
-			if (block_index)
-				duparg("block", *argv);
-			if (d[0]) {
-				fprintf(stderr, "Error: \"dev\" and \"block\" are mutually exclusive\n");
-				return -1;
-			}
-			if (get_u32(&block_index, *argv, 0) || !block_index)
-				invarg("invalid block index value", *argv);
 		} else if (strcmp(*argv, "root") == 0) {
-			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"root\" is duplicate parent ID\n");
+			if (t.tcm_parent) {
+				fprintf(stderr, "Error: \"root\" is duplicate parent ID\n");
 				return -1;
 			}
-			req.t.tcm_parent = TC_H_ROOT;
+			filter_parent = t.tcm_parent = TC_H_ROOT;
 		} else if (strcmp(*argv, "ingress") == 0) {
-			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"ingress\" is duplicate parent ID\n");
-				return -1;
-			}
-			req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
-						     TC_H_MIN_INGRESS);
-		} else if (strcmp(*argv, "egress") == 0) {
-			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"egress\" is duplicate parent ID\n");
-				return -1;
-			}
-			req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
-						     TC_H_MIN_EGRESS);
-		} else if (strcmp(*argv, "parent") == 0) {
-
-			NEXT_ARG();
-			if (req.t.tcm_parent)
-				duparg("parent", *argv);
-			if (get_tc_classid(&parent_handle, *argv))
-				invarg("Invalid parent ID", *argv);
-			req.t.tcm_parent = parent_handle;
-		} else if (strcmp(*argv, "handle") == 0) {
-			NEXT_ARG();
-			if (fhandle)
-				duparg("handle", *argv);
-			fhandle = *argv;
-		} else if (matches(*argv, "preference") == 0 ||
-			   matches(*argv, "priority") == 0) {
-			NEXT_ARG();
-			if (prio)
-				duparg("priority", *argv);
-			if (get_u32(&prio, *argv, 0) || prio > 0xFFFF)
-				invarg("invalid priority value", *argv);
-		} else if (matches(*argv, "protocol") == 0) {
-			__u16 id;
-
-			NEXT_ARG();
-			if (protocol_set)
-				duparg("protocol", *argv);
-			if (ll_proto_a2n(&id, *argv))
-				invarg("invalid protocol", *argv);
-			protocol = id;
-			protocol_set = 1;
-		} else if (matches(*argv, "chain") == 0) {
-			NEXT_ARG();
-			if (chain_index_set)
-				duparg("chain", *argv);
-			if (get_u32(&chain_index, *argv, 0))
-				invarg("invalid chain index value", *argv);
-			chain_index_set = 1;
-		} else if (matches(*argv, "help") == 0) {
-			usage();
-			return 0;
-		} else {
-			if (!**argv)
-				invarg("invalid filter name", *argv);
-
-			strncpy(k, *argv, sizeof(k)-1);
-
-			q = get_filter_kind(k);
-			argc--; argv++;
-			break;
-		}
-
-		argc--; argv++;
-	}
-
-	if (cmd == RTM_GETTFILTER) {
-		if (!protocol_set) {
-			fprintf(stderr, "Must specify filter protocol\n");
-			return -1;
-		}
-
-		if (!prio) {
-			fprintf(stderr, "Must specify filter priority\n");
-			return -1;
-		}
-
-		req.t.tcm_info = TC_H_MAKE(prio<<16, protocol);
-	}
-
-	if (chain_index_set)
-		addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
-
-	if (req.t.tcm_parent == TC_H_UNSPEC) {
-		fprintf(stderr, "Must specify filter parent\n");
-		return -1;
-	}
-
-	if (cmd == RTM_GETTFILTER) {
-		if (k[0])
-			addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1);
-		else {
-			fprintf(stderr, "Must specify filter type\n");
-			return -1;
-		}
-	}
-
-	if (d[0])  {
-		ll_init_map(&rth);
-
-		req.t.tcm_ifindex = ll_name_to_index(d);
-		if (!req.t.tcm_ifindex)
-			return -nodev(d);
-		filter_ifindex = req.t.tcm_ifindex;
-	} else if (block_index) {
-		req.t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
-		req.t.tcm_block_index = block_index;
-		filter_block_index = block_index;
-	} else {
-		fprintf(stderr, "Must specify netdevice \"dev\" or block index \"block\"\n");
-		return -1;
-	}
-
-	if (cmd == RTM_GETTFILTER &&
-	    q->parse_fopt(q, fhandle, argc, argv, &req.n))
-		return 1;
-
-	if (!fhandle && cmd == RTM_GETTFILTER) {
-		fprintf(stderr, "Must specify filter \"handle\"\n");
-		return -1;
-	}
-
-	if (argc) {
-		if (matches(*argv, "help") == 0)
-			usage();
-		fprintf(stderr,
-			"Garbage instead of arguments \"%s ...\". Try \"tc filter help\".\n",
-			*argv);
-		return -1;
-	}
-
-	if (rtnl_talk(&rth, &req.n, &answer) < 0) {
-		fprintf(stderr, "We have an error talking to the kernel\n");
-		return 2;
-	}
-
-	new_json_obj(json);
-	print_filter(answer, (void *)stdout);
-	delete_json_obj();
-
-	free(answer);
-	return 0;
-}
-
-static int tc_filter_list(int cmd, int argc, char **argv)
-{
-	struct {
-		struct nlmsghdr n;
-		struct tcmsg t;
-		char buf[MAX_MSG];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
-		.n.nlmsg_type = cmd,
-		.t.tcm_parent = TC_H_UNSPEC,
-		.t.tcm_family = AF_UNSPEC,
-	};
-	char d[IFNAMSIZ] = {};
-	__u32 prio = 0;
-	__u32 protocol = 0;
-	__u32 chain_index;
-	__u32 block_index = 0;
-	char *fhandle = NULL;
-
-	while (argc > 0) {
-		if (strcmp(*argv, "dev") == 0) {
-			NEXT_ARG();
-			if (d[0])
-				duparg("dev", *argv);
-			if (block_index) {
-				fprintf(stderr, "Error: \"dev\" cannot be used in the same time as \"block\"\n");
-				return -1;
-			}
-			strncpy(d, *argv, sizeof(d)-1);
-		} else if (matches(*argv, "block") == 0) {
-			NEXT_ARG();
-			if (block_index)
-				duparg("block", *argv);
-			if (d[0]) {
-				fprintf(stderr, "Error: \"block\" cannot be used in the same time as \"dev\"\n");
-				return -1;
-			}
-			if (get_u32(&block_index, *argv, 0) || !block_index)
-				invarg("invalid block index value", *argv);
-		} else if (strcmp(*argv, "root") == 0) {
-			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"root\" is duplicate parent ID\n");
-				return -1;
-			}
-			filter_parent = req.t.tcm_parent = TC_H_ROOT;
-		} else if (strcmp(*argv, "ingress") == 0) {
-			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"ingress\" is duplicate parent ID\n");
+			if (t.tcm_parent) {
+				fprintf(stderr, "Error: \"ingress\" is duplicate parent ID\n");
 				return -1;
 			}
 			filter_parent = TC_H_MAKE(TC_H_CLSACT,
 						  TC_H_MIN_INGRESS);
-			req.t.tcm_parent = filter_parent;
+			t.tcm_parent = filter_parent;
 		} else if (strcmp(*argv, "egress") == 0) {
-			if (req.t.tcm_parent) {
-				fprintf(stderr,
-					"Error: \"egress\" is duplicate parent ID\n");
+			if (t.tcm_parent) {
+				fprintf(stderr, "Error: \"egress\" is duplicate parent ID\n");
 				return -1;
 			}
 			filter_parent = TC_H_MAKE(TC_H_CLSACT,
 						  TC_H_MIN_EGRESS);
-			req.t.tcm_parent = filter_parent;
+			t.tcm_parent = filter_parent;
 		} else if (strcmp(*argv, "parent") == 0) {
 			__u32 handle;
-
 			NEXT_ARG();
-			if (req.t.tcm_parent)
+			if (t.tcm_parent)
 				duparg("parent", *argv);
 			if (get_tc_classid(&handle, *argv))
 				invarg("invalid parent ID", *argv);
-			filter_parent = req.t.tcm_parent = handle;
+			filter_parent = t.tcm_parent = handle;
 		} else if (strcmp(*argv, "handle") == 0) {
 			NEXT_ARG();
 			if (fhandle)
@@ -671,7 +337,6 @@
 			filter_prio = prio;
 		} else if (matches(*argv, "protocol") == 0) {
 			__u16 res;
-
 			NEXT_ARG();
 			if (protocol)
 				duparg("protocol", *argv);
@@ -679,59 +344,37 @@
 				invarg("invalid protocol", *argv);
 			protocol = res;
 			filter_protocol = protocol;
-		} else if (matches(*argv, "chain") == 0) {
-			NEXT_ARG();
-			if (filter_chain_index_set)
-				duparg("chain", *argv);
-			if (get_u32(&chain_index, *argv, 0))
-				invarg("invalid chain index value", *argv);
-			filter_chain_index_set = 1;
-			filter_chain_index = chain_index;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
-			fprintf(stderr,
-				" What is \"%s\"? Try \"tc filter help\"\n",
-				*argv);
+			fprintf(stderr, " What is \"%s\"? Try \"tc filter help\"\n", *argv);
 			return -1;
 		}
 
 		argc--; argv++;
 	}
 
-	req.t.tcm_info = TC_H_MAKE(prio<<16, protocol);
+	t.tcm_info = TC_H_MAKE(prio<<16, protocol);
 
 	ll_init_map(&rth);
 
 	if (d[0]) {
-		req.t.tcm_ifindex = ll_name_to_index(d);
-		if (!req.t.tcm_ifindex)
-			return -nodev(d);
-		filter_ifindex = req.t.tcm_ifindex;
-	} else if (block_index) {
-		if (!tc_qdisc_block_exists(block_index)) {
-			fprintf(stderr, "Cannot find block \"%u\"\n", block_index);
+		if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
 			return 1;
 		}
-		req.t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
-		req.t.tcm_block_index = block_index;
-		filter_block_index = block_index;
+		filter_ifindex = t.tcm_ifindex;
 	}
 
-	if (filter_chain_index_set)
-		addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
-
-	if (rtnl_dump_request_n(&rth, &req.n) < 0) {
+	if (rtnl_dump_request(&rth, RTM_GETTFILTER, &t, sizeof(t)) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return 1;
 	}
-	delete_json_obj();
 
 	return 0;
 }
@@ -739,52 +382,26 @@
 int do_filter(int argc, char **argv)
 {
 	if (argc < 1)
-		return tc_filter_list(RTM_GETTFILTER, 0, NULL);
+		return tc_filter_list(0, NULL);
 	if (matches(*argv, "add") == 0)
-		return tc_filter_modify(RTM_NEWTFILTER, NLM_F_EXCL|NLM_F_CREATE,
-					argc-1, argv+1);
+		return tc_filter_modify(RTM_NEWTFILTER, NLM_F_EXCL|NLM_F_CREATE, argc-1, argv+1);
 	if (matches(*argv, "change") == 0)
 		return tc_filter_modify(RTM_NEWTFILTER, 0, argc-1, argv+1);
 	if (matches(*argv, "replace") == 0)
-		return tc_filter_modify(RTM_NEWTFILTER, NLM_F_CREATE, argc-1,
-					argv+1);
+		return tc_filter_modify(RTM_NEWTFILTER, NLM_F_CREATE, argc-1, argv+1);
 	if (matches(*argv, "delete") == 0)
 		return tc_filter_modify(RTM_DELTFILTER, 0,  argc-1, argv+1);
+#if 0
 	if (matches(*argv, "get") == 0)
 		return tc_filter_get(RTM_GETTFILTER, 0,  argc-1, argv+1);
+#endif
 	if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
 	    || matches(*argv, "lst") == 0)
-		return tc_filter_list(RTM_GETTFILTER, argc-1, argv+1);
+		return tc_filter_list(argc-1, argv+1);
 	if (matches(*argv, "help") == 0) {
 		usage();
 		return 0;
-	}
-	fprintf(stderr, "Command \"%s\" is unknown, try \"tc filter help\".\n",
-		*argv);
-	return -1;
-}
-
-int do_chain(int argc, char **argv)
-{
-	if (argc < 1)
-		return tc_filter_list(RTM_GETCHAIN, 0, NULL);
-	if (matches(*argv, "add") == 0) {
-		return tc_filter_modify(RTM_NEWCHAIN, NLM_F_EXCL | NLM_F_CREATE,
-					argc - 1, argv + 1);
-	} else if (matches(*argv, "delete") == 0) {
-		return tc_filter_modify(RTM_DELCHAIN, 0,
-					argc - 1, argv + 1);
-	} else if (matches(*argv, "get") == 0) {
-		return tc_filter_get(RTM_GETCHAIN, 0,
-				     argc - 1, argv + 1);
-	} else if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0 ||
-		   matches(*argv, "lst") == 0) {
-		return tc_filter_list(RTM_GETCHAIN, argc - 1, argv + 1);
-	} else if (matches(*argv, "help") == 0) {
-		chain_usage();
-		return 0;
-	}
-	fprintf(stderr, "Command \"%s\" is unknown, try \"tc chain help\".\n",
-		*argv);
+        }
+	fprintf(stderr, "Command \"%s\" is unknown, try \"tc filter help\".\n", *argv);
 	return -1;
 }
diff --git a/tc/tc_monitor.c b/tc/tc_monitor.c
index f8816cc..ebb9432 100644
--- a/tc/tc_monitor.c
+++ b/tc/tc_monitor.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -34,32 +35,30 @@
 }
 
 
-static int accept_tcmsg(struct rtnl_ctrl_data *ctrl,
+static int accept_tcmsg(const struct sockaddr_nl *who,
+			struct rtnl_ctrl_data *ctrl,
 			struct nlmsghdr *n, void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 
 	if (timestamp)
 		print_timestamp(fp);
 
-	if (n->nlmsg_type == RTM_NEWTFILTER ||
-	    n->nlmsg_type == RTM_DELTFILTER ||
-	    n->nlmsg_type == RTM_NEWCHAIN ||
-	    n->nlmsg_type == RTM_DELCHAIN) {
-		print_filter(n, arg);
+	if (n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) {
+		print_filter(who, n, arg);
 		return 0;
 	}
 	if (n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS) {
-		print_class(n, arg);
+		print_class(who, n, arg);
 		return 0;
 	}
 	if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC) {
-		print_qdisc(n, arg);
+		print_qdisc(who, n, arg);
 		return 0;
 	}
 	if (n->nlmsg_type == RTM_GETACTION || n->nlmsg_type == RTM_NEWACTION ||
 	    n->nlmsg_type == RTM_DELACTION) {
-		print_action(n, arg);
+		print_action(who, n, arg);
 		return 0;
 	}
 	if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
@@ -74,7 +73,7 @@
 {
 	struct rtnl_handle rth;
 	char *file = NULL;
-	unsigned int groups = nl_mgrp(RTNLGRP_TC);
+	unsigned groups = nl_mgrp(RTNLGRP_TC);
 
 	while (argc > 0) {
 		if (matches(*argv, "file") == 0) {
@@ -110,7 +109,7 @@
 
 	ll_init_map(&rth);
 
-	if (rtnl_listen(&rth, accept_tcmsg, (void *)stdout) < 0) {
+	if (rtnl_listen(&rth, accept_tcmsg, (void*)stdout) < 0) {
 		rtnl_close(&rth);
 		exit(2);
 	}
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 17e3998..cb861e0 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -27,44 +28,46 @@
 
 static int usage(void)
 {
-	fprintf(stderr,
-		"Usage: tc qdisc [ add | del | replace | change | show ] dev STRING\n"
-		"       [ handle QHANDLE ] [ root | ingress | clsact | parent CLASSID ]\n"
-		"       [ estimator INTERVAL TIME_CONSTANT ]\n"
-		"       [ stab [ help | STAB_OPTIONS] ]\n"
-		"       [ ingress_block BLOCK_INDEX ] [ egress_block BLOCK_INDEX ]\n"
-		"       [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n"
-		"\n"
-		"       tc qdisc show [ dev STRING ] [ ingress | clsact ] [ invisible ]\n"
-		"Where:\n"
-		"QDISC_KIND := { [p|b]fifo | tbf | prio | cbq | red | etc. }\n"
-		"OPTIONS := ... try tc qdisc add <desired QDISC_KIND> help\n"
-		"STAB_OPTIONS := ... try tc qdisc add stab help\n");
+	fprintf(stderr, "Usage: tc qdisc [ add | del | replace | change | show ] dev STRING\n");
+	fprintf(stderr, "       [ handle QHANDLE ] [ root | ingress | clsact | parent CLASSID ]\n");
+	fprintf(stderr, "       [ estimator INTERVAL TIME_CONSTANT ]\n");
+	fprintf(stderr, "       [ stab [ help | STAB_OPTIONS] ]\n");
+	fprintf(stderr, "       [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "       tc qdisc show [ dev STRING ] [ ingress | clsact ]\n");
+	fprintf(stderr, "Where:\n");
+	fprintf(stderr, "QDISC_KIND := { [p|b]fifo | tbf | prio | cbq | red | etc. }\n");
+	fprintf(stderr, "OPTIONS := ... try tc qdisc add <desired QDISC_KIND> help\n");
+	fprintf(stderr, "STAB_OPTIONS := ... try tc qdisc add stab help\n");
 	return -1;
 }
 
-static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
+static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
 {
 	struct qdisc_util *q = NULL;
-	struct tc_estimator est = {};
+	struct tc_estimator est;
 	struct {
 		struct tc_sizespec	szopts;
 		__u16			*data;
-	} stab = {};
-	char  d[IFNAMSIZ] = {};
-	char  k[FILTER_NAMESZ] = {};
+	} stab;
+	char  d[16];
+	char  k[16];
 	struct {
-		struct nlmsghdr	n;
-		struct tcmsg		t;
-		char			buf[TCA_BUF_MAX];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
-		.n.nlmsg_flags = NLM_F_REQUEST | flags,
-		.n.nlmsg_type = cmd,
-		.t.tcm_family = AF_UNSPEC,
-	};
-	__u32 ingress_block = 0;
-	__u32 egress_block = 0;
+		struct nlmsghdr 	n;
+		struct tcmsg 		t;
+		char   			buf[TCA_BUF_MAX];
+	} req;
+
+	memset(&req, 0, sizeof(req));
+	memset(&stab, 0, sizeof(stab));
+	memset(&est, 0, sizeof(est));
+	memset(&d, 0, sizeof(d));
+	memset(&k, 0, sizeof(k));
+
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+	req.n.nlmsg_type = cmd;
+	req.t.tcm_family = AF_UNSPEC;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -74,7 +77,6 @@
 			strncpy(d, *argv, sizeof(d)-1);
 		} else if (strcmp(*argv, "handle") == 0) {
 			__u32 handle;
-
 			if (req.t.tcm_handle)
 				duparg("handle", *argv);
 			NEXT_ARG();
@@ -111,7 +113,6 @@
 			break;
 		} else if (strcmp(*argv, "parent") == 0) {
 			__u32 handle;
-
 			NEXT_ARG();
 			if (req.t.tcm_parent)
 				duparg("parent", *argv);
@@ -125,14 +126,6 @@
 			if (parse_size_table(&argc, &argv, &stab.szopts) < 0)
 				return -1;
 			continue;
-		} else if (matches(*argv, "ingress_block") == 0) {
-			NEXT_ARG();
-			if (get_u32(&ingress_block, *argv, 0) || !ingress_block)
-				invarg("invalid ingress block index value", *argv);
-		} else if (matches(*argv, "egress_block") == 0) {
-			NEXT_ARG();
-			if (get_u32(&egress_block, *argv, 0) || !egress_block)
-				invarg("invalid egress block index value", *argv);
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
@@ -150,16 +143,9 @@
 	if (est.ewma_log)
 		addattr_l(&req.n, sizeof(req), TCA_RATE, &est, sizeof(est));
 
-	if (ingress_block)
-		addattr32(&req.n, sizeof(req),
-			  TCA_INGRESS_BLOCK, ingress_block);
-	if (egress_block)
-		addattr32(&req.n, sizeof(req),
-			  TCA_EGRESS_BLOCK, egress_block);
-
 	if (q) {
 		if (q->parse_qopt) {
-			if (q->parse_qopt(q, argc, argv, &req.n, d))
+			if (q->parse_qopt(q, argc, argv, &req.n))
 				return 1;
 		} else if (argc) {
 			fprintf(stderr, "qdisc '%s' does not support option parsing\n", k);
@@ -183,13 +169,14 @@
 			return -1;
 		}
 
-		tail = addattr_nest(&req.n, sizeof(req), TCA_STAB);
+		tail = NLMSG_TAIL(&req.n);
+		addattr_l(&req.n, sizeof(req), TCA_STAB, NULL, 0);
 		addattr_l(&req.n, sizeof(req), TCA_STAB_BASE, &stab.szopts,
 			  sizeof(stab.szopts));
 		if (stab.data)
 			addattr_l(&req.n, sizeof(req), TCA_STAB_DATA, stab.data,
 				  stab.szopts.tsize * sizeof(__u16));
-		addattr_nest_end(&req.n, tail);
+		tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail;
 		if (stab.data)
 			free(stab.data);
 	}
@@ -199,13 +186,14 @@
 
 		ll_init_map(&rth);
 
-		idx = ll_name_to_index(d);
-		if (!idx)
-			return -nodev(d);
+		if ((idx = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
+			return 1;
+		}
 		req.t.tcm_ifindex = idx;
 	}
 
-	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
 		return 2;
 
 	return 0;
@@ -213,12 +201,14 @@
 
 static int filter_ifindex;
 
-int print_qdisc(struct nlmsghdr *n, void *arg)
+int print_qdisc(const struct sockaddr_nl *who,
+		       struct nlmsghdr *n,
+		       void *arg)
 {
-	FILE *fp = (FILE *)arg;
+	FILE *fp = (FILE*)arg;
 	struct tcmsg *t = NLMSG_DATA(n);
 	int len = n->nlmsg_len;
-	struct rtattr *tb[TCA_MAX+1];
+	struct rtattr * tb[TCA_MAX+1];
 	struct qdisc_util *q;
 	char abuf[256];
 
@@ -235,6 +225,7 @@
 	if (filter_ifindex && filter_ifindex != t->tcm_ifindex)
 		return 0;
 
+	memset(tb, 0, sizeof(tb));
 	parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
 
 	if (tb[TCA_KIND] == NULL) {
@@ -242,127 +233,78 @@
 		return -1;
 	}
 
-	open_json_object(NULL);
-
 	if (n->nlmsg_type == RTM_DELQDISC)
-		print_bool(PRINT_ANY, "deleted", "deleted ", true);
+		fprintf(fp, "deleted ");
 
-	if (n->nlmsg_type == RTM_NEWQDISC &&
-			(n->nlmsg_flags & NLM_F_CREATE) &&
-			(n->nlmsg_flags & NLM_F_REPLACE))
-		print_bool(PRINT_ANY, "replaced", "replaced ", true);
-
-	if (n->nlmsg_type == RTM_NEWQDISC &&
-			(n->nlmsg_flags & NLM_F_CREATE) &&
-			(n->nlmsg_flags & NLM_F_EXCL))
-		print_bool(PRINT_ANY, "added", "added ", true);
-
-	print_string(PRINT_ANY, "kind", "qdisc %s",
-		     rta_getattr_str(tb[TCA_KIND]));
-	sprintf(abuf, "%x:", t->tcm_handle >> 16);
-	print_string(PRINT_ANY, "handle", " %s", abuf);
-	if (show_raw) {
-		sprintf(abuf, "[%08x]", t->tcm_handle);
-		print_string(PRINT_FP, NULL, "%s", abuf);
-	}
-	print_string(PRINT_FP, NULL, " ", NULL);
-
+	fprintf(fp, "qdisc %s %x: ", rta_getattr_str(tb[TCA_KIND]), t->tcm_handle>>16);
 	if (filter_ifindex == 0)
-		print_devname(PRINT_ANY, t->tcm_ifindex);
-
+		fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex));
 	if (t->tcm_parent == TC_H_ROOT)
-		print_bool(PRINT_ANY, "root", "root ", true);
+		fprintf(fp, "root ");
 	else if (t->tcm_parent) {
 		print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
-		print_string(PRINT_ANY, "parent", "parent %s ", abuf);
+		fprintf(fp, "parent %s ", abuf);
 	}
-
-	if (t->tcm_info != 1)
-		print_uint(PRINT_ANY, "refcnt", "refcnt %u ", t->tcm_info);
-
-	if (tb[TCA_HW_OFFLOAD] &&
-	    (rta_getattr_u8(tb[TCA_HW_OFFLOAD])))
-		print_bool(PRINT_ANY, "offloaded", "offloaded ", true);
-
-	if (tb[TCA_INGRESS_BLOCK] &&
-	    RTA_PAYLOAD(tb[TCA_INGRESS_BLOCK]) >= sizeof(__u32)) {
-		__u32 block = rta_getattr_u32(tb[TCA_INGRESS_BLOCK]);
-
-		if (block)
-			print_uint(PRINT_ANY, "ingress_block",
-				   "ingress_block %u ", block);
+	if (t->tcm_info != 1) {
+		fprintf(fp, "refcnt %d ", t->tcm_info);
 	}
-
-	if (tb[TCA_EGRESS_BLOCK] &&
-	    RTA_PAYLOAD(tb[TCA_EGRESS_BLOCK]) >= sizeof(__u32)) {
-		__u32 block = rta_getattr_u32(tb[TCA_EGRESS_BLOCK]);
-
-		if (block)
-			print_uint(PRINT_ANY, "egress_block",
-				   "egress_block %u ", block);
-	}
-
 	/* pfifo_fast is generic enough to warrant the hardcoding --JHS */
-	if (strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND])) == 0)
+
+	if (0 == strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND])))
 		q = get_qdisc_kind("prio");
 	else
 		q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]));
 
-	open_json_object("options");
 	if (tb[TCA_OPTIONS]) {
 		if (q)
 			q->print_qopt(q, fp, tb[TCA_OPTIONS]);
 		else
-			fprintf(stderr, "Cannot parse qdisc parameters\n");
+			fprintf(fp, "[cannot parse qdisc parameters]");
 	}
-	close_json_object();
-
-	print_string(PRINT_FP, NULL, "\n", NULL);
-
+	fprintf(fp, "\n");
 	if (show_details && tb[TCA_STAB]) {
 		print_size_table(fp, " ", tb[TCA_STAB]);
-		print_string(PRINT_FP, NULL, "\n", NULL);
+		fprintf(fp, "\n");
 	}
-
 	if (show_stats) {
 		struct rtattr *xstats = NULL;
 
 		if (tb[TCA_STATS] || tb[TCA_STATS2] || tb[TCA_XSTATS]) {
 			print_tcstats_attr(fp, tb, " ", &xstats);
-			print_string(PRINT_FP, NULL, "\n", NULL);
+			fprintf(fp, "\n");
 		}
 
 		if (q && xstats && q->print_xstats) {
 			q->print_xstats(q, fp, xstats);
-			print_string(PRINT_FP, NULL, "\n", NULL);
+			fprintf(fp, "\n");
 		}
 	}
-	close_json_object();
 	fflush(fp);
 	return 0;
 }
 
 static int tc_qdisc_list(int argc, char **argv)
 {
-	struct tcmsg t = { .tcm_family = AF_UNSPEC };
-	char d[IFNAMSIZ] = {};
-	bool dump_invisible = false;
+	struct tcmsg t;
+	char d[16];
+
+	memset(&t, 0, sizeof(t));
+	t.tcm_family = AF_UNSPEC;
+	memset(&d, 0, sizeof(d));
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			strncpy(d, *argv, sizeof(d)-1);
-		} else if (strcmp(*argv, "ingress") == 0 ||
+                } else if (strcmp(*argv, "ingress") == 0 ||
 			   strcmp(*argv, "clsact") == 0) {
-			if (t.tcm_parent) {
-				fprintf(stderr, "Duplicate parent ID\n");
-				usage();
-			}
-			t.tcm_parent = TC_H_INGRESS;
+                             if (t.tcm_parent) {
+                                     fprintf(stderr, "Duplicate parent ID\n");
+                                     usage();
+                             }
+                             t.tcm_parent = TC_H_INGRESS;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
-		} else if (strcmp(*argv, "invisible") == 0) {
-			dump_invisible = true;
 		} else {
 			fprintf(stderr, "What is \"%s\"? Try \"tc qdisc help\".\n", *argv);
 			return -1;
@@ -374,41 +316,22 @@
 	ll_init_map(&rth);
 
 	if (d[0]) {
-		t.tcm_ifindex = ll_name_to_index(d);
-		if (!t.tcm_ifindex)
-			return -nodev(d);
+		if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
+			fprintf(stderr, "Cannot find device \"%s\"\n", d);
+			return 1;
+		}
 		filter_ifindex = t.tcm_ifindex;
 	}
 
-	if (dump_invisible) {
-		struct {
-			struct nlmsghdr n;
-			struct tcmsg t;
-			char buf[256];
-		} req = {
-			.n.nlmsg_type = RTM_GETQDISC,
-			.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
-		};
-
-		req.t.tcm_family = AF_UNSPEC;
-
-		addattr(&req.n, 256, TCA_DUMP_INVISIBLE);
-		if (rtnl_dump_request_n(&rth, &req.n) < 0) {
-			perror("Cannot send dump request");
-			return 1;
-		}
-
-	} else if (rtnl_dump_request(&rth, RTM_GETQDISC, &t, sizeof(t)) < 0) {
+	if (rtnl_dump_request(&rth, RTM_GETQDISC, &t, sizeof(t)) < 0) {
 		perror("Cannot send dump request");
 		return 1;
 	}
 
-	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return 1;
 	}
-	delete_json_obj();
 
 	return 0;
 }
@@ -437,67 +360,7 @@
 	if (matches(*argv, "help") == 0) {
 		usage();
 		return 0;
-	}
+        }
 	fprintf(stderr, "Command \"%s\" is unknown, try \"tc qdisc help\".\n", *argv);
 	return -1;
 }
-
-struct tc_qdisc_block_exists_ctx {
-	__u32 block_index;
-	bool found;
-};
-
-static int tc_qdisc_block_exists_cb(struct nlmsghdr *n, void *arg)
-{
-	struct tc_qdisc_block_exists_ctx *ctx = arg;
-	struct tcmsg *t = NLMSG_DATA(n);
-	struct rtattr *tb[TCA_MAX+1];
-	int len = n->nlmsg_len;
-
-	if (n->nlmsg_type != RTM_NEWQDISC)
-		return 0;
-
-	len -= NLMSG_LENGTH(sizeof(*t));
-	if (len < 0)
-		return -1;
-
-	parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
-
-	if (tb[TCA_KIND] == NULL)
-		return -1;
-
-	if (tb[TCA_INGRESS_BLOCK] &&
-	    RTA_PAYLOAD(tb[TCA_INGRESS_BLOCK]) >= sizeof(__u32)) {
-		__u32 block = rta_getattr_u32(tb[TCA_INGRESS_BLOCK]);
-
-		if (block == ctx->block_index)
-			ctx->found = true;
-	}
-
-	if (tb[TCA_EGRESS_BLOCK] &&
-	    RTA_PAYLOAD(tb[TCA_EGRESS_BLOCK]) >= sizeof(__u32)) {
-		__u32 block = rta_getattr_u32(tb[TCA_EGRESS_BLOCK]);
-
-		if (block == ctx->block_index)
-			ctx->found = true;
-	}
-	return 0;
-}
-
-bool tc_qdisc_block_exists(__u32 block_index)
-{
-	struct tc_qdisc_block_exists_ctx ctx = { .block_index = block_index };
-	struct tcmsg t = { .tcm_family = AF_UNSPEC };
-
-	if (rtnl_dump_request(&rth, RTM_GETQDISC, &t, sizeof(t)) < 0) {
-		perror("Cannot send dump request");
-		return false;
-	}
-
-	if (rtnl_dump_filter(&rth, tc_qdisc_block_exists_cb, &ctx) < 0) {
-		perror("Dump terminated\n");
-		return false;
-	}
-
-	return ctx.found;
-}
diff --git a/tc/tc_red.c b/tc/tc_red.c
index 681ca29..81a83bd 100644
--- a/tc/tc_red.c
+++ b/tc/tc_red.c
@@ -1,5 +1,5 @@
 /*
- * tc_red.c		RED maintenance routines.
+ * tc_red.c		RED maintanance routines.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <math.h>
 #include <sys/socket.h>
@@ -20,31 +21,27 @@
 #include <arpa/inet.h>
 #include <string.h>
 
-#include "utils.h"
 #include "tc_core.h"
-#include "tc_util.h"
 #include "tc_red.h"
 
 /*
    Plog = log(prob/(qmax - qmin))
  */
-int tc_red_eval_P(unsigned int qmin, unsigned int qmax, double prob)
+int tc_red_eval_P(unsigned qmin, unsigned qmax, double prob)
 {
 	int i = qmax - qmin;
 
-	if (!i)
-		return 0;
-	if (i < 0)
+	if (i <= 0)
 		return -1;
 
 	prob /= i;
 
-	for (i = 0; i < 32; i++) {
+	for (i=0; i<32; i++) {
 		if (prob > 1.0)
 			break;
 		prob *= 2;
 	}
-	if (i >= 32)
+	if (i>=32)
 		return -1;
 	return i;
 }
@@ -53,18 +50,18 @@
    burst + 1 - qmin/avpkt < (1-(1-W)^burst)/W
  */
 
-int tc_red_eval_ewma(unsigned int qmin, unsigned int burst, unsigned int avpkt)
+int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt)
 {
 	int wlog = 1;
 	double W = 0.5;
 	double a = (double)burst + 1 - (double)qmin/avpkt;
 
 	if (a < 1.0) {
-		fprintf(stderr, "tc_red_eval_ewma() burst %u is too small ? Try burst %u\n",
-				burst, 1 + qmin/avpkt);
+		fprintf(stderr, "tc_red_eval_ewma() burst %u is too small ?"
+				" Try burst %u\n", burst, 1 + qmin/avpkt);
 		return -1;
 	}
-	for (wlog = 1; wlog < 32; wlog++, W /= 2) {
+	for (wlog=1; wlog<32; wlog++, W /= 2) {
 		if (a <= (1 - pow(1-W, burst))/W)
 			return wlog;
 	}
@@ -75,7 +72,7 @@
    Stab[t>>Scell_log] = -log(1-W) * t/xmit_time
  */
 
-int tc_red_eval_idle_damping(int Wlog, unsigned int avpkt, unsigned int bps, __u8 *sbuf)
+int tc_red_eval_idle_damping(int Wlog, unsigned avpkt, unsigned bps, __u8 *sbuf)
 {
 	double xmit_time = tc_calc_xmittime(bps, avpkt);
 	double lW = -log(1.0 - 1.0/(1<<Wlog))/xmit_time;
@@ -83,7 +80,7 @@
 	int clog;
 	int i;
 
-	for (clog = 0; clog < 32; clog++) {
+	for (clog=0; clog<32; clog++) {
 		if (maxtime/(1<<clog) < 512)
 			break;
 	}
@@ -91,7 +88,7 @@
 		return -1;
 
 	sbuf[0] = 0;
-	for (i = 1; i < 255; i++) {
+	for (i=1; i<255; i++) {
 		sbuf[i] = (i<<clog)*lW;
 		if (sbuf[i] > 31)
 			sbuf[i] = 31;
@@ -99,21 +96,3 @@
 	sbuf[255] = 31;
 	return clog;
 }
-
-void tc_red_print_flags(__u32 flags)
-{
-	if (flags & TC_RED_ECN)
-		print_bool(PRINT_ANY, "ecn", "ecn ", true);
-	else
-		print_bool(PRINT_ANY, "ecn", NULL, false);
-
-	if (flags & TC_RED_HARDDROP)
-		print_bool(PRINT_ANY, "harddrop", "harddrop ", true);
-	else
-		print_bool(PRINT_ANY, "harddrop", NULL, false);
-
-	if (flags & TC_RED_ADAPTATIVE)
-		print_bool(PRINT_ANY, "adaptive", "adaptive ", true);
-	else
-		print_bool(PRINT_ANY, "adaptive", NULL, false);
-}
diff --git a/tc/tc_red.h b/tc/tc_red.h
index 3882c83..6f6b09e 100644
--- a/tc/tc_red.h
+++ b/tc/tc_red.h
@@ -1,11 +1,8 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _TC_RED_H_
 #define _TC_RED_H_ 1
 
-int tc_red_eval_P(unsigned qmin, unsigned qmax, double prob);
-int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt);
-int tc_red_eval_idle_damping(int wlog, unsigned avpkt, unsigned bandwidth,
-			     __u8 *sbuf);
-void tc_red_print_flags(__u32 flags);
+extern int tc_red_eval_P(unsigned qmin, unsigned qmax, double prob);
+extern int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt);
+extern int tc_red_eval_idle_damping(int wlog, unsigned avpkt, unsigned bandwidth, __u8 *sbuf);
 
 #endif
diff --git a/tc/tc_stab.c b/tc/tc_stab.c
index c0f1f16..aba8ae8 100644
--- a/tc/tc_stab.c
+++ b/tc/tc_stab.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <math.h>
 #include <sys/socket.h>
@@ -30,7 +31,7 @@
 static void stab_help(void)
 {
 	fprintf(stderr,
-		"Usage: ... stab [ mtu BYTES ] [ tsize SLOTS ] [ mpu BYTES ]\n"
+		"Usage: ... stab [ mtu BYTES ] [ tsize SLOTS ] [ mpu BYTES ] \n"
 		"                [ overhead BYTES ] [ linklayer TYPE ] ...\n"
 		"   mtu       : max packet size we create rate map for {2047}\n"
 		"   tsize     : how many slots should size table have {512}\n"
@@ -39,6 +40,7 @@
 		"   linklayer : adapting to a linklayer e.g. atm\n"
 		"Example: ... stab overhead 20 linklayer atm\n");
 
+	return;
 }
 
 int check_size_table_opts(struct tc_sizespec *s)
@@ -51,7 +53,9 @@
 {
 	char **argv = *argvp;
 	int argc = *argcp;
-	struct tc_sizespec s = {};
+	struct tc_sizespec s;
+
+	memset(&s, 0, sizeof(s));
 
 	NEXT_ARG();
 	if (matches(*argv, "help") == 0) {
@@ -106,14 +110,12 @@
 void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta)
 {
 	struct rtattr *tb[TCA_STAB_MAX + 1];
-
 	SPRINT_BUF(b1);
 
 	parse_rtattr_nested(tb, TCA_STAB_MAX, rta);
 
 	if (tb[TCA_STAB_BASE]) {
 		struct tc_sizespec s = {0};
-
 		memcpy(&s, RTA_DATA(tb[TCA_STAB_BASE]),
 				MIN(RTA_PAYLOAD(tb[TCA_STAB_BASE]), sizeof(s)));
 
@@ -133,9 +135,8 @@
 
 #if 0
 	if (tb[TCA_STAB_DATA]) {
-		unsigned int i, j, dlen;
+		unsigned i, j, dlen;
 		__u16 *data = RTA_DATA(tb[TCA_STAB_DATA]);
-
 		dlen = RTA_PAYLOAD(tb[TCA_STAB_DATA]) / sizeof(__u16);
 
 		fprintf(fp, "\n%sstab data:", prefix);
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 393721e..4764ecc 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/param.h>
@@ -31,7 +32,7 @@
 #define LIBDIR "/usr/lib"
 #endif
 
-static struct db_names *cls_names;
+static struct db_names *cls_names = NULL;
 
 #define NAMES_DB "/etc/iproute2/tc_cls"
 
@@ -81,10 +82,10 @@
 	if (strcmp(str, "none") == 0)
 		goto ok;
 	maj = strtoul(str, &p, 16);
-	if (p == str || maj >= (1 << 16))
+	if (p == str)
 		return -1;
 	maj <<= 16;
-	if (*p != ':' && *p != 0)
+	if (*p != ':' && *p!=0)
 		return -1;
 ok:
 	*h = maj;
@@ -190,90 +191,8 @@
 	{ NULL }
 };
 
-/* Parse a percent e.g: '30%'
- * return: 0 = ok, -1 = error, 1 = out of range
- */
-int parse_percent(double *val, const char *str)
-{
-	char *p;
 
-	*val = strtod(str, &p) / 100.;
-	if (*val > 1.0 || *val < 0.0)
-		return 1;
-	if (*p && strcmp(p, "%"))
-		return -1;
-
-	return 0;
-}
-
-static int parse_percent_rate(char *rate, size_t len,
-			      const char *str, const char *dev)
-{
-	long dev_mbit;
-	int ret;
-	double perc, rate_bit;
-	char *str_perc = NULL;
-
-	if (!dev[0]) {
-		fprintf(stderr, "No device specified; specify device to rate limit by percentage\n");
-		return -1;
-	}
-
-	if (read_prop(dev, "speed", &dev_mbit))
-		return -1;
-
-	ret = sscanf(str, "%m[0-9.%]", &str_perc);
-	if (ret != 1)
-		goto malf;
-
-	ret = parse_percent(&perc, str_perc);
-	if (ret == 1) {
-		fprintf(stderr, "Invalid rate specified; should be between [0,100]%% but is %s\n", str);
-		goto err;
-	} else if (ret == -1) {
-		goto malf;
-	}
-
-	free(str_perc);
-
-	rate_bit = perc * dev_mbit * 1000 * 1000;
-
-	ret = snprintf(rate, len, "%lf", rate_bit);
-	if (ret <= 0 || ret >= len) {
-		fprintf(stderr, "Unable to parse calculated rate\n");
-		return -1;
-	}
-
-	return 0;
-
-malf:
-	fprintf(stderr, "Specified rate value could not be read or is malformed\n");
-err:
-	free(str_perc);
-	return -1;
-}
-
-int get_percent_rate(unsigned int *rate, const char *str, const char *dev)
-{
-	char r_str[20];
-
-	if (parse_percent_rate(r_str, sizeof(r_str), str, dev))
-		return -1;
-
-	return get_rate(rate, r_str);
-}
-
-int get_percent_rate64(__u64 *rate, const char *str, const char *dev)
-{
-	char r_str[20];
-
-	if (parse_percent_rate(r_str, sizeof(r_str), str, dev))
-		return -1;
-
-	return get_rate64(rate, r_str);
-}
-
-int get_rate(unsigned int *rate, const char *str)
+int get_rate(unsigned *rate, const char *str)
 {
 	char *p;
 	double bps = strtod(str, &p);
@@ -347,18 +266,64 @@
 	snprintf(buf, len, "%.0f%s%sbit", (double)rate, units[i], str);
 }
 
-char *sprint_rate(__u64 rate, char *buf)
+char * sprint_rate(__u64 rate, char *buf)
 {
 	print_rate(buf, SPRINT_BSIZE-1, rate);
 	return buf;
 }
 
-char *sprint_ticks(__u32 ticks, char *buf)
+int get_time(unsigned *time, const char *str)
+{
+	double t;
+	char *p;
+
+	t = strtod(str, &p);
+	if (p == str)
+		return -1;
+
+	if (*p) {
+		if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec")==0 ||
+		    strcasecmp(p, "secs")==0)
+			t *= TIME_UNITS_PER_SEC;
+		else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec")==0 ||
+			 strcasecmp(p, "msecs") == 0)
+			t *= TIME_UNITS_PER_SEC/1000;
+		else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec")==0 ||
+			 strcasecmp(p, "usecs") == 0)
+			t *= TIME_UNITS_PER_SEC/1000000;
+		else
+			return -1;
+	}
+
+	*time = t;
+	return 0;
+}
+
+
+void print_time(char *buf, int len, __u32 time)
+{
+	double tmp = time;
+
+	if (tmp >= TIME_UNITS_PER_SEC)
+		snprintf(buf, len, "%.1fs", tmp/TIME_UNITS_PER_SEC);
+	else if (tmp >= TIME_UNITS_PER_SEC/1000)
+		snprintf(buf, len, "%.1fms", tmp/(TIME_UNITS_PER_SEC/1000));
+	else
+		snprintf(buf, len, "%uus", time);
+}
+
+char * sprint_time(__u32 time, char *buf)
+{
+	print_time(buf, SPRINT_BSIZE-1, time);
+	return buf;
+}
+
+char * sprint_ticks(__u32 ticks, char *buf)
 {
 	return sprint_time(tc_core_tick2time(ticks), buf);
 }
 
-int get_size(unsigned int *size, const char *str)
+int get_size(unsigned *size, const char *str)
 {
 	double sz;
 	char *p;
@@ -368,13 +333,13 @@
 		return -1;
 
 	if (*p) {
-		if (strcasecmp(p, "kb") == 0 || strcasecmp(p, "k") == 0)
+		if (strcasecmp(p, "kb") == 0 || strcasecmp(p, "k")==0)
 			sz *= 1024;
-		else if (strcasecmp(p, "gb") == 0 || strcasecmp(p, "g") == 0)
+		else if (strcasecmp(p, "gb") == 0 || strcasecmp(p, "g")==0)
 			sz *= 1024*1024*1024;
 		else if (strcasecmp(p, "gbit") == 0)
 			sz *= 1024*1024*1024/8;
-		else if (strcasecmp(p, "mb") == 0 || strcasecmp(p, "m") == 0)
+		else if (strcasecmp(p, "mb") == 0 || strcasecmp(p, "m")==0)
 			sz *= 1024*1024;
 		else if (strcasecmp(p, "mbit") == 0)
 			sz *= 1024*1024/8;
@@ -388,9 +353,9 @@
 	return 0;
 }
 
-int get_size_and_cell(unsigned int *size, int *cell_log, char *str)
+int get_size_and_cell(unsigned *size, int *cell_log, char *str)
 {
-	char *slash = strchr(str, '/');
+	char * slash = strchr(str, '/');
 
 	if (slash)
 		*slash = 0;
@@ -406,7 +371,7 @@
 			return -1;
 		*slash = '/';
 
-		for (i = 0; i < 32; i++) {
+		for (i=0; i<32; i++) {
 			if ((1<<i) == cell) {
 				*cell_log = i;
 				return 0;
@@ -417,18 +382,7 @@
 	return 0;
 }
 
-void print_devname(enum output_type type, int ifindex)
-{
-	const char *ifname = ll_index_to_name(ifindex);
-
-	if (!is_json_context())
-		printf("dev ");
-
-	print_color_string(type, COLOR_IFNAME,
-			   "dev", "%s ", ifname);
-}
-
-static void print_size(char *buf, int len, __u32 sz)
+void print_size(char *buf, int len, __u32 sz)
 {
 	double tmp = sz;
 
@@ -440,267 +394,73 @@
 		snprintf(buf, len, "%ub", sz);
 }
 
-char *sprint_size(__u32 size, char *buf)
+char * sprint_size(__u32 size, char *buf)
 {
 	print_size(buf, SPRINT_BSIZE-1, size);
 	return buf;
 }
 
-static const char *action_n2a(int action)
+void print_qdisc_handle(char *buf, int len, __u32 h)
 {
-	static char buf[64];
+	snprintf(buf, len, "%x:", TC_H_MAJ(h)>>16);
+}
 
-	if (TC_ACT_EXT_CMP(action, TC_ACT_GOTO_CHAIN))
-		return "goto";
-	if (TC_ACT_EXT_CMP(action, TC_ACT_JUMP))
-		return "jump";
+char * sprint_qdisc_handle(__u32 h, char *buf)
+{
+	print_qdisc_handle(buf, SPRINT_BSIZE-1, h);
+	return buf;
+}
+
+char * action_n2a(int action, char *buf, int len)
+{
 	switch (action) {
-	case TC_ACT_UNSPEC:
+	case -1:
 		return "continue";
+		break;
 	case TC_ACT_OK:
 		return "pass";
+		break;
 	case TC_ACT_SHOT:
 		return "drop";
+		break;
 	case TC_ACT_RECLASSIFY:
 		return "reclassify";
 	case TC_ACT_PIPE:
 		return "pipe";
 	case TC_ACT_STOLEN:
 		return "stolen";
-	case TC_ACT_TRAP:
-		return "trap";
 	default:
-		snprintf(buf, 64, "%d", action);
+		snprintf(buf, len, "%d", action);
 		return buf;
 	}
 }
 
-/* Convert action branch name into numeric format.
- *
- * Parameters:
- * @arg - string to parse
- * @result - pointer to output variable
- * @allow_num - whether @arg may be in numeric format already
- *
- * In error case, returns -1 and does not touch @result. Otherwise returns 0.
- */
-int action_a2n(char *arg, int *result, bool allow_num)
+int action_a2n(char *arg, int *result)
 {
-	int n;
-	char dummy;
-	struct {
-		const char *a;
-		int n;
-	} a2n[] = {
-		{"continue", TC_ACT_UNSPEC},
-		{"drop", TC_ACT_SHOT},
-		{"shot", TC_ACT_SHOT},
-		{"pass", TC_ACT_OK},
-		{"ok", TC_ACT_OK},
-		{"reclassify", TC_ACT_RECLASSIFY},
-		{"pipe", TC_ACT_PIPE},
-		{"goto", TC_ACT_GOTO_CHAIN},
-		{"jump", TC_ACT_JUMP},
-		{"trap", TC_ACT_TRAP},
-		{ NULL },
-	}, *iter;
+	int res;
 
-	for (iter = a2n; iter->a; iter++) {
-		if (matches(arg, iter->a) != 0)
-			continue;
-		n = iter->n;
-		goto out_ok;
-	}
-	if (!allow_num || sscanf(arg, "%d%c", &n, &dummy) != 1)
-		return -1;
-
-out_ok:
-	if (result)
-		*result = n;
-	return 0;
-}
-
-static int __parse_action_control(int *argc_p, char ***argv_p, int *result_p,
-				  bool allow_num, bool ignore_a2n_miss)
-{
-	int argc = *argc_p;
-	char **argv = *argv_p;
-	int result;
-
-	if (!argc)
-		return -1;
-	if (action_a2n(*argv, &result, allow_num) == -1) {
-		if (!ignore_a2n_miss)
-			fprintf(stderr, "Bad action type %s\n", *argv);
-		return -1;
-	}
-	if (result == TC_ACT_GOTO_CHAIN) {
-		__u32 chain_index;
-
-		NEXT_ARG();
-		if (matches(*argv, "chain") != 0) {
-			fprintf(stderr, "\"chain index\" expected\n");
+	if (matches(arg, "continue") == 0)
+		res = -1;
+	else if (matches(arg, "drop") == 0)
+		res = TC_ACT_SHOT;
+	else if (matches(arg, "shot") == 0)
+		res = TC_ACT_SHOT;
+	else if (matches(arg, "pass") == 0)
+		res = TC_ACT_OK;
+	else if (strcmp(arg, "ok") == 0)
+		res = TC_ACT_OK;
+	else if (matches(arg, "reclassify") == 0)
+		res = TC_ACT_RECLASSIFY;
+	else {
+		char dummy;
+		if (sscanf(arg, "%d%c", &res, &dummy) != 1)
 			return -1;
-		}
-		NEXT_ARG();
-		if (get_u32(&chain_index, *argv, 10) ||
-		    chain_index > TC_ACT_EXT_VAL_MASK) {
-			fprintf(stderr, "Illegal \"chain index\"\n");
-			return -1;
-		}
-		result |= chain_index;
 	}
-	if (result == TC_ACT_JUMP) {
-		__u32 jump_cnt = 0;
-
-		NEXT_ARG();
-		if (get_u32(&jump_cnt, *argv, 10) ||
-		    jump_cnt > TC_ACT_EXT_VAL_MASK) {
-			fprintf(stderr, "Invalid \"jump count\" (%s)\n", *argv);
-			return -1;
-		}
-		result |= jump_cnt;
-	}
-	NEXT_ARG_FWD();
-	*argc_p = argc;
-	*argv_p = argv;
-	*result_p = result;
+	*result = res;
 	return 0;
 }
 
-/* Parse action control including possible options.
- *
- * Parameters:
- * @argc_p - pointer to argc to parse
- * @argv_p - pointer to argv to parse
- * @result_p - pointer to output variable
- * @allow_num - whether action may be in numeric format already
- *
- * In error case, returns -1 and does not touch @result_1p. Otherwise returns 0.
- */
-int parse_action_control(int *argc_p, char ***argv_p,
-			 int *result_p, bool allow_num)
-{
-	return __parse_action_control(argc_p, argv_p, result_p,
-				      allow_num, false);
-}
-
-/* Parse action control including possible options.
- *
- * Parameters:
- * @argc_p - pointer to argc to parse
- * @argv_p - pointer to argv to parse
- * @result_p - pointer to output variable
- * @allow_num - whether action may be in numeric format already
- * @default_result - set as a result in case of parsing error
- *
- * In case there is an error during parsing, the default result is used.
- */
-void parse_action_control_dflt(int *argc_p, char ***argv_p,
-			       int *result_p, bool allow_num,
-			       int default_result)
-{
-	if (__parse_action_control(argc_p, argv_p, result_p, allow_num, true))
-		*result_p = default_result;
-}
-
-static int parse_action_control_slash_spaces(int *argc_p, char ***argv_p,
-					     int *result1_p, int *result2_p,
-					     bool allow_num)
-{
-	int argc = *argc_p;
-	char **argv = *argv_p;
-	int result1 = -1, result2;
-	int *result_p = &result1;
-	int ok = 0;
-	int ret;
-
-	while (argc > 0) {
-		switch (ok) {
-		case 1:
-			if (strcmp(*argv, "/") != 0)
-				goto out;
-			result_p = &result2;
-			NEXT_ARG();
-			/* fall-through */
-		case 0: /* fall-through */
-		case 2:
-			ret = parse_action_control(&argc, &argv,
-						   result_p, allow_num);
-			if (ret)
-				return ret;
-			ok++;
-			break;
-		default:
-			goto out;
-		}
-	}
-out:
-	*result1_p = result1;
-	if (ok == 2)
-		*result2_p = result2;
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-/* Parse action control with slash including possible options.
- *
- * Parameters:
- * @argc_p - pointer to argc to parse
- * @argv_p - pointer to argv to parse
- * @result1_p - pointer to the first (before slash) output variable
- * @result2_p - pointer to the second (after slash) output variable
- * @allow_num - whether action may be in numeric format already
- *
- * In error case, returns -1 and does not touch @result*. Otherwise returns 0.
- */
-int parse_action_control_slash(int *argc_p, char ***argv_p,
-			       int *result1_p, int *result2_p, bool allow_num)
-{
-	int result1, result2, argc = *argc_p;
-	char **argv = *argv_p;
-	char *p = strchr(*argv, '/');
-
-	if (!p)
-		return parse_action_control_slash_spaces(argc_p, argv_p,
-							 result1_p, result2_p,
-							 allow_num);
-	*p = 0;
-	if (action_a2n(*argv, &result1, allow_num)) {
-		*p = '/';
-		return -1;
-	}
-
-	*p = '/';
-	if (action_a2n(p + 1, &result2, allow_num))
-		return -1;
-
-	*result1_p = result1;
-	*result2_p = result2;
-	NEXT_ARG_FWD();
-	*argc_p = argc;
-	*argv_p = argv;
-	return 0;
-}
-
-void print_action_control(FILE *f, const char *prefix,
-			  int action, const char *suffix)
-{
-	print_string(PRINT_FP, NULL, "%s", prefix);
-	open_json_object("control_action");
-	print_string(PRINT_ANY, "type", "%s", action_n2a(action));
-	if (TC_ACT_EXT_CMP(action, TC_ACT_GOTO_CHAIN))
-		print_uint(PRINT_ANY, "chain", " chain %u",
-			   action & TC_ACT_EXT_VAL_MASK);
-	if (TC_ACT_EXT_CMP(action, TC_ACT_JUMP))
-		print_uint(PRINT_ANY, "jump", " %u",
-			   action & TC_ACT_EXT_VAL_MASK);
-	close_json_object();
-	print_string(PRINT_FP, NULL, "%s", suffix);
-}
-
-int get_linklayer(unsigned int *val, const char *arg)
+int get_linklayer(unsigned *val, const char *arg)
 {
 	int res;
 
@@ -717,7 +477,7 @@
 	return 0;
 }
 
-static void print_linklayer(char *buf, int len, unsigned int linklayer)
+void print_linklayer(char *buf, int len, unsigned linklayer)
 {
 	switch (linklayer) {
 	case LINKLAYER_UNSPEC:
@@ -735,69 +495,21 @@
 	}
 }
 
-char *sprint_linklayer(unsigned int linklayer, char *buf)
+char *sprint_linklayer(unsigned linklayer, char *buf)
 {
 	print_linklayer(buf, SPRINT_BSIZE-1, linklayer);
 	return buf;
 }
 
-void print_tm(FILE *f, const struct tcf_t *tm)
+void print_tm(FILE * f, const struct tcf_t *tm)
 {
 	int hz = get_user_hz();
-
-	if (tm->install != 0) {
-		print_uint(PRINT_JSON, "installed", NULL, tm->install);
-		print_uint(PRINT_FP, NULL, " installed %u sec",
-			   (unsigned int)(tm->install/hz));
-	}
-	if (tm->lastuse != 0) {
-		print_uint(PRINT_JSON, "last_used", NULL, tm->lastuse);
-		print_uint(PRINT_FP, NULL, " used %u sec",
-			   (unsigned int)(tm->lastuse/hz));
-	}
-	if (tm->expires != 0) {
-		print_uint(PRINT_JSON, "expires", NULL, tm->expires);
-		print_uint(PRINT_FP, NULL, " expires %u sec",
-			   (unsigned int)(tm->expires/hz));
-	}
-}
-
-static void print_tcstats_basic_hw(struct rtattr **tbs, char *prefix)
-{
-	struct gnet_stats_basic bs_hw;
-
-	if (!tbs[TCA_STATS_BASIC_HW])
-		return;
-
-	memcpy(&bs_hw, RTA_DATA(tbs[TCA_STATS_BASIC_HW]),
-	       MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC_HW]), sizeof(bs_hw)));
-
-	if (bs_hw.bytes == 0 && bs_hw.packets == 0)
-		return;
-
-	if (tbs[TCA_STATS_BASIC]) {
-		struct gnet_stats_basic bs;
-
-		memcpy(&bs, RTA_DATA(tbs[TCA_STATS_BASIC]),
-		       MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC]),
-			   sizeof(bs)));
-
-		if (bs.bytes >= bs_hw.bytes && bs.packets >= bs_hw.packets) {
-			print_string(PRINT_FP, NULL, "%s", _SL_);
-			print_string(PRINT_FP, NULL, "%s", prefix);
-			print_lluint(PRINT_ANY, "sw_bytes",
-				     "Sent software %llu bytes",
-				     bs.bytes - bs_hw.bytes);
-			print_uint(PRINT_ANY, "sw_packets", " %u pkt",
-				   bs.packets - bs_hw.packets);
-		}
-	}
-
-	print_string(PRINT_FP, NULL, "%s", _SL_);
-	print_string(PRINT_FP, NULL, "%s", prefix);
-	print_lluint(PRINT_ANY, "hw_bytes", "Sent hardware %llu bytes",
-		     bs_hw.bytes);
-	print_uint(PRINT_ANY, "hw_packets", " %u pkt", bs_hw.packets);
+	if (tm->install != 0)
+		fprintf(f, " installed %u sec", (unsigned)(tm->install/hz));
+	if (tm->lastuse != 0)
+		fprintf(f, " used %u sec", (unsigned)(tm->lastuse/hz));
+	if (tm->expires != 0)
+		fprintf(f, " expires %u sec", (unsigned)(tm->expires/hz));
 }
 
 void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats)
@@ -809,61 +521,42 @@
 
 	if (tbs[TCA_STATS_BASIC]) {
 		struct gnet_stats_basic bs = {0};
-
 		memcpy(&bs, RTA_DATA(tbs[TCA_STATS_BASIC]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC]), sizeof(bs)));
-		print_string(PRINT_FP, NULL, "%s", prefix);
-		print_lluint(PRINT_ANY, "bytes", "Sent %llu bytes", bs.bytes);
-		print_uint(PRINT_ANY, "packets", " %u pkt", bs.packets);
+		fprintf(fp, "%sSent %llu bytes %u pkt",
+			prefix, (unsigned long long) bs.bytes, bs.packets);
 	}
 
 	if (tbs[TCA_STATS_QUEUE]) {
 		struct gnet_stats_queue q = {0};
-
 		memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q)));
-		print_uint(PRINT_ANY, "drops", " (dropped %u", q.drops);
-		print_uint(PRINT_ANY, "overlimits", ", overlimits %u",
-			   q.overlimits);
-		print_uint(PRINT_ANY, "requeues", " requeues %u) ", q.requeues);
+		fprintf(fp, " (dropped %u, overlimits %u requeues %u) ",
+			q.drops, q.overlimits, q.requeues);
 	}
 
-	if (tbs[TCA_STATS_BASIC_HW])
-		print_tcstats_basic_hw(tbs, prefix);
-
 	if (tbs[TCA_STATS_RATE_EST64]) {
 		struct gnet_stats_rate_est64 re = {0};
 
 		memcpy(&re, RTA_DATA(tbs[TCA_STATS_RATE_EST64]),
 		       MIN(RTA_PAYLOAD(tbs[TCA_STATS_RATE_EST64]),
 			   sizeof(re)));
-		print_string(PRINT_FP, NULL, "\n%s", prefix);
-		print_lluint(PRINT_JSON, "rate", NULL, re.bps);
-		print_string(PRINT_FP, NULL, "rate %s",
-			     sprint_rate(re.bps, b1));
-		print_lluint(PRINT_ANY, "pps", " %llupps", re.pps);
+		fprintf(fp, "\n%srate %s %llupps ",
+			prefix, sprint_rate(re.bps, b1), re.pps);
 	} else if (tbs[TCA_STATS_RATE_EST]) {
 		struct gnet_stats_rate_est re = {0};
 
 		memcpy(&re, RTA_DATA(tbs[TCA_STATS_RATE_EST]),
 		       MIN(RTA_PAYLOAD(tbs[TCA_STATS_RATE_EST]), sizeof(re)));
-		print_string(PRINT_FP, NULL, "\n%s", prefix);
-		print_uint(PRINT_JSON, "rate", NULL, re.bps);
-		print_string(PRINT_FP, NULL, "rate %s",
-			     sprint_rate(re.bps, b1));
-		print_uint(PRINT_ANY, "pps", " %upps", re.pps);
+		fprintf(fp, "\n%srate %s %upps ",
+			prefix, sprint_rate(re.bps, b1), re.pps);
 	}
 
 	if (tbs[TCA_STATS_QUEUE]) {
 		struct gnet_stats_queue q = {0};
-
 		memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q)));
 		if (!tbs[TCA_STATS_RATE_EST])
-			print_string(PRINT_FP, NULL, "\n", "");
-		print_uint(PRINT_JSON, "backlog", NULL, q.backlog);
-		print_string(PRINT_FP, NULL, "%s", prefix);
-		print_string(PRINT_FP, NULL, "backlog %s",
-			     sprint_size(q.backlog, b1));
-		print_uint(PRINT_ANY, "qlen", " %up", q.qlen);
-		print_uint(PRINT_FP, NULL, " requeues %u", q.requeues);
+			fprintf(fp, "\n%s", prefix);
+		fprintf(fp, "backlog %s %up requeues %u ",
+			sprint_size(q.backlog, b1), q.qlen, q.requeues);
 	}
 
 	if (xstats)
@@ -876,15 +569,16 @@
 
 	if (tb[TCA_STATS2]) {
 		print_tcstats2_attr(fp, tb[TCA_STATS2], prefix, xstats);
-		if (xstats && !*xstats)
+		if (xstats && NULL == *xstats)
 			goto compat_xstats;
 		return;
 	}
 	/* backward compatibility */
 	if (tb[TCA_STATS]) {
-		struct tc_stats st = {};
+		struct tc_stats st;
 
 		/* handle case where kernel returns more/less than we know about */
+		memset(&st, 0, sizeof(st));
 		memcpy(&st, RTA_DATA(tb[TCA_STATS]), MIN(RTA_PAYLOAD(tb[TCA_STATS]), sizeof(st)));
 
 		fprintf(fp, "%sSent %llu bytes %u pkts (dropped %u, overlimits %u) ",
@@ -914,74 +608,3 @@
 	if (tb[TCA_XSTATS] && xstats)
 		*xstats = tb[TCA_XSTATS];
 }
-
-static void print_masked_type(__u32 type_max,
-			      __u32 (*rta_getattr_type)(const struct rtattr *),
-			      const char *name, struct rtattr *attr,
-			      struct rtattr *mask_attr, bool newline)
-{
-	SPRINT_BUF(namefrm);
-	__u32 value, mask;
-	SPRINT_BUF(out);
-	size_t done;
-
-	if (!attr)
-		return;
-
-	value = rta_getattr_type(attr);
-	mask = mask_attr ? rta_getattr_type(mask_attr) : type_max;
-
-	if (is_json_context()) {
-		sprintf(namefrm, "\n  %s %%u", name);
-		print_hu(PRINT_ANY, name, namefrm,
-			 rta_getattr_type(attr));
-		if (mask != type_max) {
-			char mask_name[SPRINT_BSIZE-6];
-
-			sprintf(mask_name, "%s_mask", name);
-			if (newline)
-				print_string(PRINT_FP, NULL, "%s ", _SL_);
-			sprintf(namefrm, " %s %%u", mask_name);
-			print_hu(PRINT_ANY, mask_name, namefrm, mask);
-		}
-	} else {
-		done = sprintf(out, "%u", value);
-		if (mask != type_max)
-			sprintf(out + done, "/0x%x", mask);
-		if (newline)
-			print_string(PRINT_FP, NULL, "%s ", _SL_);
-		sprintf(namefrm, " %s %%s", name);
-		print_string(PRINT_ANY, name, namefrm, out);
-	}
-}
-
-void print_masked_u32(const char *name, struct rtattr *attr,
-		      struct rtattr *mask_attr, bool newline)
-{
-	print_masked_type(UINT32_MAX, rta_getattr_u32, name, attr, mask_attr,
-			  newline);
-}
-
-static __u32 __rta_getattr_u16_u32(const struct rtattr *attr)
-{
-	return rta_getattr_u16(attr);
-}
-
-void print_masked_u16(const char *name, struct rtattr *attr,
-		      struct rtattr *mask_attr, bool newline)
-{
-	print_masked_type(UINT16_MAX, __rta_getattr_u16_u32, name, attr,
-			  mask_attr, newline);
-}
-
-static __u32 __rta_getattr_u8_u32(const struct rtattr *attr)
-{
-	return rta_getattr_u8(attr);
-}
-
-void print_masked_u8(const char *name, struct rtattr *attr,
-		     struct rtattr *mask_attr, bool newline)
-{
-	print_masked_type(UINT8_MAX,  __rta_getattr_u8_u32, name, attr,
-			  mask_attr, newline);
-}
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 9adf2ab..61e60b1 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -1,17 +1,11 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _TC_UTIL_H_
 #define _TC_UTIL_H_ 1
 
 #define MAX_MSG 16384
-#include <limits.h>
-#include <linux/if.h>
-
 #include <linux/pkt_sched.h>
 #include <linux/pkt_cls.h>
 #include <linux/gen_stats.h>
-
 #include "tc_core.h"
-#include "json_print.h"
 
 /* This is the deprecated multiqueue interface */
 #ifndef TCA_PRIO_MAX
@@ -25,112 +19,92 @@
 #define TCA_PRIO_MAX    (__TCA_PRIO_MAX - 1)
 #endif
 
-#define FILTER_NAMESZ	16
-
 struct qdisc_util {
 	struct  qdisc_util *next;
 	const char *id;
-	int (*parse_qopt)(struct qdisc_util *qu, int argc,
-			  char **argv, struct nlmsghdr *n, const char *dev);
-	int (*print_qopt)(struct qdisc_util *qu,
-			  FILE *f, struct rtattr *opt);
-	int (*print_xstats)(struct qdisc_util *qu,
-			    FILE *f, struct rtattr *xstats);
+	int	(*parse_qopt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n);
+	int	(*print_qopt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
+	int 	(*print_xstats)(struct qdisc_util *qu, FILE *f, struct rtattr *xstats);
 
-	int (*parse_copt)(struct qdisc_util *qu, int argc,
-			  char **argv, struct nlmsghdr *n, const char *dev);
-	int (*print_copt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
+	int	(*parse_copt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n);
+	int	(*print_copt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
 };
 
 extern __u16 f_proto;
 struct filter_util {
 	struct filter_util *next;
-	char id[FILTER_NAMESZ];
-	int (*parse_fopt)(struct filter_util *qu, char *fhandle,
-			  int argc, char **argv, struct nlmsghdr *n);
-	int (*print_fopt)(struct filter_util *qu,
-			  FILE *f, struct rtattr *opt, __u32 fhandle);
+	char	id[16];
+	int	(*parse_fopt)(struct filter_util *qu, char *fhandle, int argc,
+			      char **argv, struct nlmsghdr *n);
+	int	(*print_fopt)(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 fhandle);
 };
 
 struct action_util {
-	struct action_util *next;
-	char id[FILTER_NAMESZ];
-	int (*parse_aopt)(struct action_util *a, int *argc,
-			  char ***argv, int code, struct nlmsghdr *n);
-	int (*print_aopt)(struct action_util *au, FILE *f, struct rtattr *opt);
-	int (*print_xstats)(struct action_util *au,
-			    FILE *f, struct rtattr *xstats);
+	struct  action_util *next;
+	char    id[16];
+	int     (*parse_aopt)(struct action_util *a, int *argc, char ***argv,
+			      int code, struct nlmsghdr *n);
+	int     (*print_aopt)(struct action_util *au, FILE *f, struct rtattr *opt);
+	int     (*print_xstats)(struct action_util *au, FILE *f, struct rtattr *xstats);
 };
 
 struct exec_util {
-	struct exec_util *next;
-	char id[FILTER_NAMESZ];
-	int (*parse_eopt)(struct exec_util *eu, int argc, char **argv);
+	struct	exec_util *next;
+	char	id[16];
+	int	(*parse_eopt)(struct exec_util *eu, int argc, char **argv);
 };
 
-const char *get_tc_lib(void);
+extern const char *get_tc_lib(void);
 
-struct qdisc_util *get_qdisc_kind(const char *str);
-struct filter_util *get_filter_kind(const char *str);
+extern struct qdisc_util *get_qdisc_kind(const char *str);
+extern struct filter_util *get_filter_kind(const char *str);
 
-int get_qdisc_handle(__u32 *h, const char *str);
-int get_rate(unsigned int *rate, const char *str);
-int get_percent_rate(unsigned int *rate, const char *str, const char *dev);
-int get_rate64(__u64 *rate, const char *str);
-int get_percent_rate64(__u64 *rate, const char *str, const char *dev);
-int get_size(unsigned int *size, const char *str);
-int get_size_and_cell(unsigned int *size, int *cell_log, char *str);
-int get_linklayer(unsigned int *val, const char *arg);
+extern int get_qdisc_handle(__u32 *h, const char *str);
+extern int get_rate(unsigned *rate, const char *str);
+extern int get_rate64(__u64 *rate, const char *str);
+extern int get_size(unsigned *size, const char *str);
+extern int get_size_and_cell(unsigned *size, int *cell_log, char *str);
+extern int get_time(unsigned *time, const char *str);
+extern int get_linklayer(unsigned *val, const char *arg);
 
-void print_rate(char *buf, int len, __u64 rate);
-void print_devname(enum output_type type, int ifindex);
+extern void print_rate(char *buf, int len, __u64 rate);
+extern void print_size(char *buf, int len, __u32 size);
+extern void print_qdisc_handle(char *buf, int len, __u32 h);
+extern void print_time(char *buf, int len, __u32 time);
+extern void print_linklayer(char *buf, int len, unsigned linklayer);
 
-char *sprint_rate(__u64 rate, char *buf);
-char *sprint_size(__u32 size, char *buf);
-char *sprint_tc_classid(__u32 h, char *buf);
-char *sprint_ticks(__u32 ticks, char *buf);
-char *sprint_linklayer(unsigned int linklayer, char *buf);
+extern char * sprint_rate(__u64 rate, char *buf);
+extern char * sprint_size(__u32 size, char *buf);
+extern char * sprint_qdisc_handle(__u32 h, char *buf);
+extern char * sprint_tc_classid(__u32 h, char *buf);
+extern char * sprint_time(__u32 time, char *buf);
+extern char * sprint_ticks(__u32 ticks, char *buf);
+extern char * sprint_linklayer(unsigned linklayer, char *buf);
 
-void print_tcstats_attr(FILE *fp, struct rtattr *tb[],
-			char *prefix, struct rtattr **xstats);
-void print_tcstats2_attr(FILE *fp, struct rtattr *rta,
-			 char *prefix, struct rtattr **xstats);
+extern void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtattr **xstats);
+extern void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats);
 
-int get_tc_classid(__u32 *h, const char *str);
-int print_tc_classid(char *buf, int len, __u32 h);
-char *sprint_tc_classid(__u32 h, char *buf);
+extern int get_tc_classid(__u32 *h, const char *str);
+extern int print_tc_classid(char *buf, int len, __u32 h);
+extern char * sprint_tc_classid(__u32 h, char *buf);
 
-int tc_print_police(FILE *f, struct rtattr *tb);
-int parse_percent(double *val, const char *str);
-int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
+extern int tc_print_police(FILE *f, struct rtattr *tb);
+extern int parse_police(int *, char ***, int, struct nlmsghdr *);
 
-int parse_action_control(int *argc_p, char ***argv_p,
-			 int *result_p, bool allow_num);
-void parse_action_control_dflt(int *argc_p, char ***argv_p,
-			       int *result_p, bool allow_num,
-			       int default_result);
-int parse_action_control_slash(int *argc_p, char ***argv_p,
-			       int *result1_p, int *result2_p, bool allow_num);
-void print_action_control(FILE *f, const char *prefix,
-			  int action, const char *suffix);
-int police_print_xstats(struct action_util *a, FILE *f, struct rtattr *tb);
-int tc_print_action(FILE *f, const struct rtattr *tb, unsigned short tot_acts);
-int tc_print_ipt(FILE *f, const struct rtattr *tb);
-int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
-void print_tm(FILE *f, const struct tcf_t *tm);
-int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
+extern char *action_n2a(int action, char *buf, int len);
+extern int  action_a2n(char *arg, int *result);
+extern int  act_parse_police(struct action_util *a,int *, char ***, int, struct nlmsghdr *);
+extern int  print_police(struct action_util *a, FILE *f,
+			 struct rtattr *tb);
+extern int  police_print_xstats(struct action_util *a,FILE *f,
+				struct rtattr *tb);
+extern int  tc_print_action(FILE *f, const struct rtattr *tb);
+extern int  tc_print_ipt(FILE *f, const struct rtattr *tb);
+extern int  parse_action(int *, char ***, int, struct nlmsghdr *);
+extern void print_tm(FILE *f, const struct tcf_t *tm);
+extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
 
-int cls_names_init(char *path);
-void cls_names_uninit(void);
+extern int cls_names_init(char *path);
+extern void cls_names_uninit(void);
 
-int action_a2n(char *arg, int *result, bool allow_num);
-
-bool tc_qdisc_block_exists(__u32 block_index);
-
-void print_masked_u32(const char *name, struct rtattr *attr,
-		      struct rtattr *mask_attr, bool newline);
-void print_masked_u16(const char *name, struct rtattr *attr,
-		      struct rtattr *mask_attr, bool newline);
-void print_masked_u8(const char *name, struct rtattr *attr,
-		     struct rtattr *mask_attr, bool newline);
 #endif
diff --git a/testsuite/Makefile b/testsuite/Makefile
index 4451f31..2027650 100644
--- a/testsuite/Makefile
+++ b/testsuite/Makefile
@@ -1,4 +1,3 @@
-# SPDX-License-Identifier: GPL-2.0
 ## -- Config --
 DEV := lo
 PREFIX := sudo -E unshare -n
@@ -14,83 +13,57 @@
 
 IPVERS := $(filter-out iproute2/Makefile,$(wildcard iproute2/*))
 
-KENVFN := $(shell mktemp /tmp/tc_testkenv.XXXXXX)
 ifneq (,$(wildcard /proc/config.gz))
-	KCPATH := /proc/config.gz
-else
-	KVER := $(shell uname -r)
-	KCPATHS := /lib/modules/$(KVER)/config /boot/config-$(KVER)
-	KCPATH := $(firstword $(wildcard $(KCPATHS)))
+	KENV := $(shell cat /proc/config.gz | gunzip | grep ^CONFIG)
 endif
 
 .PHONY: compile listtests alltests configure $(TESTS)
 
 configure:
-	$(MAKE) -C iproute2 configure
+	echo "Entering iproute2" && cd iproute2 && $(MAKE) configure && cd ..;
 
-compile: configure generate_nlmsg
-	$(MAKE) -C iproute2
+compile: configure
+	echo "Entering iproute2" && cd iproute2 && $(MAKE) && cd ..;
 
 listtests:
 	@for t in $(TESTS); do \
 		echo "$$t"; \
 	done
 
-generate_nlmsg:
-	$(MAKE) -C tools
+alltests: $(TESTS)
 
-alltests: generate_nlmsg $(TESTS)
-
-testclean:
+clean:
 	@echo "Removing $(RESULTS_DIR) dir ..."
 	@rm -rf $(RESULTS_DIR)
 
-clean: testclean
-	@rm -f iproute2/iproute2-this
-	@rm -f tests/ip/link/dev_wo_vf_rate.nl
-	$(MAKE) -C tools clean
-
 distclean: clean
-	$(MAKE) -C iproute2 distclean
+	echo "Entering iproute2" && cd iproute2 && $(MAKE) distclean && cd ..;
 
-$(TESTS): generate_nlmsg testclean
-ifeq (,$(IPVERS))
-	$(error Please run make first)
-endif
+$(TESTS): clean
 ifeq (,$(HAVE_UNSHARED_UTIL))
 	$(error Please install util-linux tools to run tests in separated network namespace)
 endif
-	@./tools/generate_nlmsg
-
 	@mkdir -p $(RESULTS_DIR)
-
+	
 	@for d in $(TESTS_DIR); do \
 	    mkdir -p $(RESULTS_DIR)/$$d; \
 	done
-
-	@if [ "$(KCPATH)" = "/proc/config.gz" ]; then \
-		gunzip -c $(KCPATH) >$(KENVFN); \
-	elif [ "$(KCPATH)" != "" ]; then \
-               cat $(KCPATH) >$(KENVFN); \
-	fi
-	@sed -i -e 's/^CONFIG_/export CONFIG_/' $(KENVFN)
-
+	
 	@for i in $(IPVERS); do \
 		o=`echo $$i | sed -e 's/iproute2\///'`; \
 		echo -n "Running $@ [$$o/`uname -r`]: "; \
 		TMP_ERR=`mktemp /tmp/tc_testsuite.XXXXXX`; \
 		TMP_OUT=`mktemp /tmp/tc_testsuite.XXXXXX`; \
-		. $(KENVFN); \
 		STD_ERR="$$TMP_ERR" STD_OUT="$$TMP_OUT" \
-		TC="$$i/tc/tc" IP="$$i/ip/ip" SS=$$i/misc/ss DEV="$(DEV)" IPVER="$@" SNAME="$$i" \
-		ERRF="$(RESULTS_DIR)/$@.$$o.err" $(PREFIX) tests/$@ > $(RESULTS_DIR)/$@.$$o.out; \
+		TC="$$i/tc/tc" IP="$$i/ip/ip" DEV="$(DEV)" IPVER="$@" SNAME="$$i" \
+		ERRF="$(RESULTS_DIR)/$@.$$o.err" $(KENV) $(PREFIX) tests/$@ > $(RESULTS_DIR)/$@.$$o.out; \
 		if [ "$$?" = "127" ]; then \
-			printf "\033[1;35mSKIPPED\033[0m\n"; \
+			echo "SKIPPED"; \
 		elif [ -e "$(RESULTS_DIR)/$@.$$o.err" ]; then \
-			printf "\033[0;31mFAILED\033[0m\n"; \
+			echo "FAILED"; \
 		else \
-			printf "\033[0;32mPASS\033[0m\n"; \
+			echo "PASS"; \
 		fi; \
 		rm "$$TMP_ERR" "$$TMP_OUT"; \
-		sudo dmesg > $(RESULTS_DIR)/$@.$$o.dmesg; \
+		dmesg > $(RESULTS_DIR)/$@.$$o.dmesg; \
 	done
diff --git a/testsuite/configs/all-2.4 b/testsuite/configs/all-2.4
new file mode 100644
index 0000000..cc4131c
--- /dev/null
+++ b/testsuite/configs/all-2.4
@@ -0,0 +1,848 @@
+#
+# Automatically generated by make menuconfig: don't edit
+#
+CONFIG_X86=y
+# CONFIG_SBUS is not set
+CONFIG_UID16=y
+
+#
+# Code maturity level options
+#
+CONFIG_EXPERIMENTAL=y
+
+#
+# Loadable module support
+#
+CONFIG_MODULES=y
+CONFIG_MODVERSIONS=y
+CONFIG_KMOD=y
+
+#
+# Processor type and features
+#
+# CONFIG_M386 is not set
+# CONFIG_M486 is not set
+# CONFIG_M586 is not set
+# CONFIG_M586TSC is not set
+# CONFIG_M586MMX is not set
+# CONFIG_M686 is not set
+# CONFIG_MPENTIUMIII is not set
+CONFIG_MPENTIUM4=y
+# CONFIG_MK6 is not set
+# CONFIG_MK7 is not set
+# CONFIG_MK8 is not set
+# CONFIG_MELAN is not set
+# CONFIG_MCRUSOE is not set
+# CONFIG_MWINCHIPC6 is not set
+# CONFIG_MWINCHIP2 is not set
+# CONFIG_MWINCHIP3D is not set
+# CONFIG_MCYRIXIII is not set
+# CONFIG_MVIAC3_2 is not set
+CONFIG_X86_WP_WORKS_OK=y
+CONFIG_X86_INVLPG=y
+CONFIG_X86_CMPXCHG=y
+CONFIG_X86_XADD=y
+CONFIG_X86_BSWAP=y
+CONFIG_X86_POPAD_OK=y
+# CONFIG_RWSEM_GENERIC_SPINLOCK is not set
+CONFIG_RWSEM_XCHGADD_ALGORITHM=y
+CONFIG_X86_L1_CACHE_SHIFT=7
+CONFIG_X86_HAS_TSC=y
+CONFIG_X86_GOOD_APIC=y
+CONFIG_X86_PGE=y
+CONFIG_X86_USE_PPRO_CHECKSUM=y
+CONFIG_X86_F00F_WORKS_OK=y
+CONFIG_X86_MCE=y
+# CONFIG_TOSHIBA is not set
+# CONFIG_I8K is not set
+# CONFIG_MICROCODE is not set
+# CONFIG_X86_MSR is not set
+# CONFIG_X86_CPUID is not set
+# CONFIG_EDD is not set
+CONFIG_NOHIGHMEM=y
+# CONFIG_HIGHMEM4G is not set
+# CONFIG_HIGHMEM64G is not set
+# CONFIG_HIGHMEM is not set
+# CONFIG_MATH_EMULATION is not set
+# CONFIG_MTRR is not set
+CONFIG_SMP=y
+CONFIG_NR_CPUS=32
+# CONFIG_X86_NUMA is not set
+# CONFIG_X86_TSC_DISABLE is not set
+CONFIG_X86_TSC=y
+CONFIG_HAVE_DEC_LOCK=y
+
+#
+# General setup
+#
+CONFIG_NET=y
+CONFIG_X86_IO_APIC=y
+CONFIG_X86_LOCAL_APIC=y
+CONFIG_PCI=y
+# CONFIG_PCI_GOBIOS is not set
+# CONFIG_PCI_GODIRECT is not set
+CONFIG_PCI_GOANY=y
+CONFIG_PCI_BIOS=y
+CONFIG_PCI_DIRECT=y
+CONFIG_ISA=y
+CONFIG_PCI_NAMES=y
+# CONFIG_EISA is not set
+# CONFIG_MCA is not set
+CONFIG_HOTPLUG=y
+
+#
+# PCMCIA/CardBus support
+#
+CONFIG_PCMCIA=y
+CONFIG_CARDBUS=y
+# CONFIG_TCIC is not set
+# CONFIG_I82092 is not set
+# CONFIG_I82365 is not set
+
+#
+# PCI Hotplug Support
+#
+# CONFIG_HOTPLUG_PCI is not set
+# CONFIG_HOTPLUG_PCI_COMPAQ is not set
+# CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM is not set
+# CONFIG_HOTPLUG_PCI_IBM is not set
+# CONFIG_HOTPLUG_PCI_SHPC is not set
+# CONFIG_HOTPLUG_PCI_SHPC_POLL_EVENT_MODE is not set
+# CONFIG_HOTPLUG_PCI_SHPC_PHPRM_LEGACY is not set
+# CONFIG_HOTPLUG_PCI_PCIE is not set
+# CONFIG_HOTPLUG_PCI_PCIE_POLL_EVENT_MODE is not set
+CONFIG_SYSVIPC=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+CONFIG_SYSCTL=y
+CONFIG_KCORE_ELF=y
+# CONFIG_KCORE_AOUT is not set
+CONFIG_BINFMT_AOUT=y
+CONFIG_BINFMT_ELF=y
+CONFIG_BINFMT_MISC=y
+# CONFIG_OOM_KILLER is not set
+CONFIG_PM=y
+# CONFIG_APM is not set
+
+#
+# ACPI Support
+#
+# CONFIG_ACPI is not set
+CONFIG_ACPI_BOOT=y
+
+#
+# Memory Technology Devices (MTD)
+#
+# CONFIG_MTD is not set
+
+#
+# Parallel port support
+#
+# CONFIG_PARPORT is not set
+
+#
+# Plug and Play configuration
+#
+CONFIG_PNP=y
+CONFIG_ISAPNP=y
+
+#
+# Block devices
+#
+CONFIG_BLK_DEV_FD=y
+# CONFIG_BLK_DEV_XD is not set
+# CONFIG_PARIDE is not set
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_CISS_SCSI_TAPE is not set
+# CONFIG_CISS_MONITOR_THREAD is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_UMEM is not set
+# CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_LOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_BLK_STATS is not set
+
+#
+# Multi-device support (RAID and LVM)
+#
+# CONFIG_MD is not set
+# CONFIG_BLK_DEV_MD is not set
+# CONFIG_MD_LINEAR is not set
+# CONFIG_MD_RAID0 is not set
+# CONFIG_MD_RAID1 is not set
+# CONFIG_MD_RAID5 is not set
+# CONFIG_MD_MULTIPATH is not set
+# CONFIG_BLK_DEV_LVM is not set
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+# CONFIG_NETLINK_DEV is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_FILTER is not set
+CONFIG_UNIX=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_IP_MULTIPLE_TABLES=y
+CONFIG_IP_ROUTE_NAT=y
+CONFIG_IP_ROUTE_MULTIPATH=y
+CONFIG_IP_ROUTE_TOS=y
+# CONFIG_IP_ROUTE_VERBOSE is not set
+# CONFIG_IP_PNP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_INET_ECN is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_IPV6 is not set
+# CONFIG_KHTTPD is not set
+
+#
+#    SCTP Configuration (EXPERIMENTAL)
+#
+# CONFIG_IP_SCTP is not set
+CONFIG_ATM=y
+CONFIG_ATM_CLIP=y
+# CONFIG_ATM_CLIP_NO_ICMP is not set
+# CONFIG_ATM_LANE is not set
+# CONFIG_ATM_BR2684 is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+
+#
+# Appletalk devices
+#
+# CONFIG_DEV_APPLETALK is not set
+# CONFIG_DECNET is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_LLC is not set
+# CONFIG_NET_DIVERT is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_FASTROUTE is not set
+# CONFIG_NET_HW_FLOWCONTROL is not set
+
+#
+# QoS and/or fair queueing
+#
+CONFIG_NET_SCHED=y
+CONFIG_NET_SCH_CBQ=y
+CONFIG_NET_SCH_HTB=y
+CONFIG_NET_SCH_CSZ=y
+CONFIG_NET_SCH_HFSC=y
+CONFIG_NET_SCH_ATM=y
+CONFIG_NET_SCH_PRIO=y
+CONFIG_NET_SCH_RED=y
+CONFIG_NET_SCH_SFQ=y
+CONFIG_NET_SCH_TEQL=y
+CONFIG_NET_SCH_TBF=y
+CONFIG_NET_SCH_GRED=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_NET_SCH_DSMARK=y
+CONFIG_NET_QOS=y
+CONFIG_NET_ESTIMATOR=y
+CONFIG_NET_CLS=y
+CONFIG_NET_CLS_TCINDEX=y
+CONFIG_NET_CLS_ROUTE4=y
+CONFIG_NET_CLS_ROUTE=y
+CONFIG_NET_CLS_FW=y
+CONFIG_NET_CLS_U32=y
+CONFIG_NET_CLS_RSVP=y
+CONFIG_NET_CLS_RSVP6=y
+CONFIG_NET_CLS_POLICE=y
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+
+#
+# Telephony Support
+#
+# CONFIG_PHONE is not set
+# CONFIG_PHONE_IXJ is not set
+# CONFIG_PHONE_IXJ_PCMCIA is not set
+
+#
+# ATA/IDE/MFM/RLL support
+#
+CONFIG_IDE=y
+
+#
+# IDE, ATA and ATAPI Block devices
+#
+CONFIG_BLK_DEV_IDE=y
+# CONFIG_BLK_DEV_HD_IDE is not set
+# CONFIG_BLK_DEV_HD is not set
+# CONFIG_BLK_DEV_IDE_SATA is not set
+CONFIG_BLK_DEV_IDEDISK=y
+CONFIG_IDEDISK_MULTI_MODE=y
+# CONFIG_IDEDISK_STROKE is not set
+# CONFIG_BLK_DEV_IDECS is not set
+# CONFIG_BLK_DEV_DELKIN is not set
+CONFIG_BLK_DEV_IDECD=y
+# CONFIG_BLK_DEV_IDETAPE is not set
+# CONFIG_BLK_DEV_IDEFLOPPY is not set
+# CONFIG_BLK_DEV_IDESCSI is not set
+# CONFIG_IDE_TASK_IOCTL is not set
+CONFIG_BLK_DEV_CMD640=y
+# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
+# CONFIG_BLK_DEV_ISAPNP is not set
+CONFIG_BLK_DEV_IDEPCI=y
+# CONFIG_BLK_DEV_GENERIC is not set
+CONFIG_IDEPCI_SHARE_IRQ=y
+CONFIG_BLK_DEV_IDEDMA_PCI=y
+# CONFIG_BLK_DEV_OFFBOARD is not set
+# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
+CONFIG_IDEDMA_PCI_AUTO=y
+# CONFIG_IDEDMA_ONLYDISK is not set
+CONFIG_BLK_DEV_IDEDMA=y
+# CONFIG_IDEDMA_PCI_WIP is not set
+# CONFIG_BLK_DEV_ADMA100 is not set
+# CONFIG_BLK_DEV_AEC62XX is not set
+# CONFIG_BLK_DEV_ALI15X3 is not set
+# CONFIG_WDC_ALI15X3 is not set
+# CONFIG_BLK_DEV_AMD74XX is not set
+# CONFIG_AMD74XX_OVERRIDE is not set
+# CONFIG_BLK_DEV_ATIIXP is not set
+# CONFIG_BLK_DEV_CMD64X is not set
+# CONFIG_BLK_DEV_TRIFLEX is not set
+# CONFIG_BLK_DEV_CY82C693 is not set
+# CONFIG_BLK_DEV_CS5530 is not set
+# CONFIG_BLK_DEV_HPT34X is not set
+# CONFIG_HPT34X_AUTODMA is not set
+# CONFIG_BLK_DEV_HPT366 is not set
+CONFIG_BLK_DEV_PIIX=y
+# CONFIG_BLK_DEV_NS87415 is not set
+# CONFIG_BLK_DEV_OPTI621 is not set
+# CONFIG_BLK_DEV_PDC202XX_OLD is not set
+# CONFIG_PDC202XX_BURST is not set
+# CONFIG_BLK_DEV_PDC202XX_NEW is not set
+CONFIG_BLK_DEV_RZ1000=y
+# CONFIG_BLK_DEV_SC1200 is not set
+# CONFIG_BLK_DEV_SVWKS is not set
+# CONFIG_BLK_DEV_SIIMAGE is not set
+# CONFIG_BLK_DEV_SIS5513 is not set
+# CONFIG_BLK_DEV_SLC90E66 is not set
+# CONFIG_BLK_DEV_TRM290 is not set
+# CONFIG_BLK_DEV_VIA82CXXX is not set
+# CONFIG_IDE_CHIPSETS is not set
+CONFIG_IDEDMA_AUTO=y
+# CONFIG_IDEDMA_IVB is not set
+# CONFIG_DMA_NONPCI is not set
+# CONFIG_BLK_DEV_ATARAID is not set
+# CONFIG_BLK_DEV_ATARAID_PDC is not set
+# CONFIG_BLK_DEV_ATARAID_HPT is not set
+# CONFIG_BLK_DEV_ATARAID_MEDLEY is not set
+# CONFIG_BLK_DEV_ATARAID_SII is not set
+
+#
+# SCSI support
+#
+# CONFIG_SCSI is not set
+
+#
+# Fusion MPT device support
+#
+# CONFIG_FUSION is not set
+# CONFIG_FUSION_BOOT is not set
+# CONFIG_FUSION_ISENSE is not set
+# CONFIG_FUSION_CTL is not set
+# CONFIG_FUSION_LAN is not set
+
+#
+# IEEE 1394 (FireWire) support (EXPERIMENTAL)
+#
+# CONFIG_IEEE1394 is not set
+
+#
+# I2O device support
+#
+# CONFIG_I2O is not set
+# CONFIG_I2O_PCI is not set
+# CONFIG_I2O_BLOCK is not set
+# CONFIG_I2O_LAN is not set
+# CONFIG_I2O_SCSI is not set
+# CONFIG_I2O_PROC is not set
+
+#
+# Network device support
+#
+CONFIG_NETDEVICES=y
+
+#
+# ARCnet devices
+#
+# CONFIG_ARCNET is not set
+CONFIG_DUMMY=m
+# CONFIG_BONDING is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_ETHERTAP is not set
+# CONFIG_NET_SB1000 is not set
+
+#
+# Ethernet (10 or 100Mbit)
+#
+CONFIG_NET_ETHERNET=y
+# CONFIG_SUNLANCE is not set
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_SUNBMAC is not set
+# CONFIG_SUNQE is not set
+# CONFIG_SUNGEM is not set
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_LANCE is not set
+# CONFIG_NET_VENDOR_SMC is not set
+# CONFIG_NET_VENDOR_RACAL is not set
+# CONFIG_AT1700 is not set
+# CONFIG_DEPCA is not set
+# CONFIG_HP100 is not set
+# CONFIG_NET_ISA is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_AMD8111_ETH is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_AC3200 is not set
+# CONFIG_APRICOT is not set
+# CONFIG_B44 is not set
+# CONFIG_CS89x0 is not set
+# CONFIG_TULIP is not set
+# CONFIG_DE4X5 is not set
+# CONFIG_DGRS is not set
+# CONFIG_DM9102 is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_EEPRO100_PIO is not set
+# CONFIG_E100 is not set
+# CONFIG_LNE390 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_FORCEDETH is not set
+# CONFIG_NE3210 is not set
+# CONFIG_ES3210 is not set
+# CONFIG_8139CP is not set
+CONFIG_8139TOO=y
+CONFIG_8139TOO_PIO=y
+# CONFIG_8139TOO_TUNE_TWISTER is not set
+# CONFIG_8139TOO_8129 is not set
+# CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_SUNDANCE_MMIO is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_VIA_RHINE_MMIO is not set
+# CONFIG_WINBOND_840 is not set
+# CONFIG_NET_POCKET is not set
+
+#
+# Ethernet (1000 Mbit)
+#
+# CONFIG_ACENIC is not set
+# CONFIG_DL2K is not set
+# CONFIG_E1000 is not set
+# CONFIG_MYRI_SBUS is not set
+# CONFIG_NS83820 is not set
+# CONFIG_HAMACHI is not set
+# CONFIG_YELLOWFIN is not set
+# CONFIG_R8169 is not set
+# CONFIG_SK98LIN is not set
+# CONFIG_TIGON3 is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+# CONFIG_PLIP is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+
+#
+# Wireless LAN (non-hamradio)
+#
+# CONFIG_NET_RADIO is not set
+
+#
+# Token Ring devices
+#
+# CONFIG_TR is not set
+# CONFIG_NET_FC is not set
+# CONFIG_RCPCI is not set
+# CONFIG_SHAPER is not set
+
+#
+# Wan interfaces
+#
+# CONFIG_WAN is not set
+
+#
+# PCMCIA network device support
+#
+# CONFIG_NET_PCMCIA is not set
+
+#
+# ATM drivers
+#
+# CONFIG_ATM_TCP is not set
+# CONFIG_ATM_LANAI is not set
+# CONFIG_ATM_ENI is not set
+# CONFIG_ATM_FIRESTREAM is not set
+# CONFIG_ATM_ZATM is not set
+# CONFIG_ATM_NICSTAR is not set
+# CONFIG_ATM_IDT77252 is not set
+# CONFIG_ATM_AMBASSADOR is not set
+# CONFIG_ATM_HORIZON is not set
+# CONFIG_ATM_IA is not set
+# CONFIG_ATM_FORE200E_MAYBE is not set
+# CONFIG_ATM_HE is not set
+
+#
+# Amateur Radio support
+#
+# CONFIG_HAMRADIO is not set
+
+#
+# IrDA (infrared) support
+#
+# CONFIG_IRDA is not set
+
+#
+# ISDN subsystem
+#
+# CONFIG_ISDN is not set
+
+#
+# Old CD-ROM drivers (not SCSI, not IDE)
+#
+# CONFIG_CD_NO_IDESCSI is not set
+
+#
+# Input core support
+#
+# CONFIG_INPUT is not set
+# CONFIG_INPUT_KEYBDEV is not set
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_UINPUT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_SERIAL=y
+# CONFIG_SERIAL_CONSOLE is not set
+# CONFIG_SERIAL_EXTENDED is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+CONFIG_UNIX98_PTYS=y
+CONFIG_UNIX98_PTY_COUNT=256
+
+#
+# I2C support
+#
+# CONFIG_I2C is not set
+
+#
+# Mice
+#
+# CONFIG_BUSMOUSE is not set
+CONFIG_MOUSE=y
+CONFIG_PSMOUSE=y
+# CONFIG_82C710_MOUSE is not set
+# CONFIG_PC110_PAD is not set
+# CONFIG_MK712_MOUSE is not set
+
+#
+# Joysticks
+#
+# CONFIG_INPUT_GAMEPORT is not set
+# CONFIG_QIC02_TAPE is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_IPMI_PANIC_EVENT is not set
+# CONFIG_IPMI_DEVICE_INTERFACE is not set
+# CONFIG_IPMI_KCS is not set
+# CONFIG_IPMI_WATCHDOG is not set
+
+#
+# Watchdog Cards
+#
+# CONFIG_WATCHDOG is not set
+# CONFIG_SCx200 is not set
+# CONFIG_SCx200_GPIO is not set
+# CONFIG_AMD_RNG is not set
+# CONFIG_INTEL_RNG is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_AMD_PM768 is not set
+# CONFIG_NVRAM is not set
+# CONFIG_RTC is not set
+# CONFIG_DTLK is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+# CONFIG_SONYPI is not set
+
+#
+# Ftape, the floppy tape device driver
+#
+# CONFIG_FTAPE is not set
+# CONFIG_AGP is not set
+
+#
+# Direct Rendering Manager (XFree86 DRI support)
+#
+# CONFIG_DRM is not set
+
+#
+# PCMCIA character devices
+#
+# CONFIG_PCMCIA_SERIAL_CS is not set
+# CONFIG_SYNCLINK_CS is not set
+# CONFIG_MWAVE is not set
+# CONFIG_OBMOUSE is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+
+#
+# File systems
+#
+# CONFIG_QUOTA is not set
+# CONFIG_QFMT_V2 is not set
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_REISERFS_CHECK is not set
+# CONFIG_REISERFS_PROC_INFO is not set
+# CONFIG_ADFS_FS is not set
+# CONFIG_ADFS_FS_RW is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BEFS_DEBUG is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_JBD is not set
+# CONFIG_JBD_DEBUG is not set
+# CONFIG_FAT_FS is not set
+# CONFIG_MSDOS_FS is not set
+# CONFIG_UMSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_JFFS_FS is not set
+# CONFIG_JFFS2_FS is not set
+# CONFIG_CRAMFS is not set
+CONFIG_TMPFS=y
+CONFIG_RAMFS=y
+CONFIG_ISO9660_FS=y
+# CONFIG_JOLIET is not set
+# CONFIG_ZISOFS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_JFS_DEBUG is not set
+# CONFIG_JFS_STATISTICS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_NTFS_FS is not set
+# CONFIG_NTFS_RW is not set
+# CONFIG_HPFS_FS is not set
+CONFIG_PROC_FS=y
+# CONFIG_DEVFS_FS is not set
+# CONFIG_DEVFS_MOUNT is not set
+# CONFIG_DEVFS_DEBUG is not set
+CONFIG_DEVPTS_FS=y
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_QNX4FS_RW is not set
+# CONFIG_ROMFS_FS is not set
+CONFIG_EXT2_FS=y
+# CONFIG_SYSV_FS is not set
+# CONFIG_UDF_FS is not set
+# CONFIG_UDF_RW is not set
+# CONFIG_UFS_FS is not set
+# CONFIG_UFS_FS_WRITE is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_XFS_QUOTA is not set
+# CONFIG_XFS_RT is not set
+# CONFIG_XFS_TRACE is not set
+# CONFIG_XFS_DEBUG is not set
+
+#
+# Network File Systems
+#
+# CONFIG_CODA_FS is not set
+# CONFIG_INTERMEZZO_FS is not set
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+# CONFIG_NFS_DIRECTIO is not set
+# CONFIG_ROOT_NFS is not set
+CONFIG_NFSD=y
+# CONFIG_NFSD_V3 is not set
+CONFIG_NFSD_TCP=y
+CONFIG_SUNRPC=y
+CONFIG_LOCKD=y
+# CONFIG_SMB_FS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_NCPFS_PACKET_SIGNING is not set
+# CONFIG_NCPFS_IOCTL_LOCKING is not set
+# CONFIG_NCPFS_STRONG is not set
+# CONFIG_NCPFS_NFS_NS is not set
+# CONFIG_NCPFS_OS2_NS is not set
+# CONFIG_NCPFS_SMALLDOS is not set
+# CONFIG_NCPFS_NLS is not set
+# CONFIG_NCPFS_EXTRAS is not set
+# CONFIG_ZISOFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_SMB_NLS is not set
+# CONFIG_NLS is not set
+
+#
+# Console drivers
+#
+CONFIG_VGA_CONSOLE=y
+# CONFIG_VIDEO_SELECT is not set
+# CONFIG_MDA_CONSOLE is not set
+
+#
+# Frame-buffer support
+#
+# CONFIG_FB is not set
+
+#
+# Sound
+#
+CONFIG_SOUND=y
+# CONFIG_SOUND_ALI5455 is not set
+# CONFIG_SOUND_BT878 is not set
+# CONFIG_SOUND_CMPCI is not set
+CONFIG_SOUND_EMU10K1=y
+CONFIG_MIDI_EMU10K1=y
+# CONFIG_SOUND_FUSION is not set
+# CONFIG_SOUND_CS4281 is not set
+# CONFIG_SOUND_ES1370 is not set
+# CONFIG_SOUND_ES1371 is not set
+# CONFIG_SOUND_ESSSOLO1 is not set
+# CONFIG_SOUND_MAESTRO is not set
+# CONFIG_SOUND_MAESTRO3 is not set
+# CONFIG_SOUND_FORTE is not set
+# CONFIG_SOUND_ICH is not set
+# CONFIG_SOUND_RME96XX is not set
+# CONFIG_SOUND_SONICVIBES is not set
+# CONFIG_SOUND_TRIDENT is not set
+# CONFIG_SOUND_MSNDCLAS is not set
+# CONFIG_SOUND_MSNDPIN is not set
+# CONFIG_SOUND_VIA82CXXX is not set
+# CONFIG_MIDI_VIA82CXXX is not set
+# CONFIG_SOUND_OSS is not set
+# CONFIG_SOUND_TVMIXER is not set
+# CONFIG_SOUND_AD1980 is not set
+# CONFIG_SOUND_WM97XX is not set
+
+#
+# USB support
+#
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_DEVICEFS is not set
+# CONFIG_USB_BANDWIDTH is not set
+# CONFIG_USB_EHCI_HCD is not set
+CONFIG_USB_UHCI_ALT=y
+# CONFIG_USB_OHCI is not set
+# CONFIG_USB_SL811HS_ALT is not set
+# CONFIG_USB_SL811HS is not set
+# CONFIG_USB_AUDIO is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_BLUETOOTH is not set
+# CONFIG_USB_MIDI is not set
+# CONFIG_USB_STORAGE is not set
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_HP8200e is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+# CONFIG_USB_HID is not set
+# CONFIG_USB_HIDINPUT is not set
+# CONFIG_USB_HIDDEV is not set
+# CONFIG_USB_KBD is not set
+# CONFIG_USB_MOUSE is not set
+# CONFIG_USB_AIPTEK is not set
+# CONFIG_USB_WACOM is not set
+# CONFIG_USB_KBTAB is not set
+# CONFIG_USB_POWERMATE is not set
+# CONFIG_USB_DC2XX is not set
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_SCANNER is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_HPUSBSCSI is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_CDCETHER is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_USB_USS720 is not set
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_TIGL is not set
+# CONFIG_USB_BRLVGER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_SPEEDTOUCH is not set
+
+#
+# Support for USB gadgets
+#
+# CONFIG_USB_GADGET is not set
+
+#
+# Bluetooth support
+#
+# CONFIG_BLUEZ is not set
+
+#
+# Kernel hacking
+#
+CONFIG_DEBUG_KERNEL=y
+CONFIG_DEBUG_STACKOVERFLOW=y
+CONFIG_DEBUG_HIGHMEM=y
+CONFIG_DEBUG_SLAB=y
+CONFIG_DEBUG_IOVIRT=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_SPINLOCK=y
+CONFIG_FRAME_POINTER=y
+CONFIG_LOG_BUF_SHIFT=0
+
+#
+# Cryptographic options
+#
+# CONFIG_CRYPTO is not set
+
+#
+# Library routines
+#
+CONFIG_CRC32=y
+# CONFIG_ZLIB_INFLATE is not set
+# CONFIG_ZLIB_DEFLATE is not set
+# CONFIG_FW_LOADER is not set
diff --git a/testsuite/configs/all-no-act b/testsuite/configs/all-no-act
new file mode 100644
index 0000000..baeed43
--- /dev/null
+++ b/testsuite/configs/all-no-act
@@ -0,0 +1,1499 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.10-rc2-bk13
+# Wed Dec  8 14:43:07 2004
+#
+CONFIG_X86=y
+CONFIG_MMU=y
+CONFIG_UID16=y
+CONFIG_GENERIC_ISA_DMA=y
+CONFIG_GENERIC_IOMAP=y
+
+#
+# Code maturity level options
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_CLEAN_COMPILE=y
+CONFIG_LOCK_KERNEL=y
+
+#
+# General setup
+#
+CONFIG_LOCALVERSION="no-act"
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+CONFIG_SYSCTL=y
+CONFIG_AUDIT=y
+CONFIG_AUDITSYSCALL=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_HOTPLUG=y
+CONFIG_KOBJECT_UEVENT=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+# CONFIG_EMBEDDED is not set
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SHMEM=y
+CONFIG_CC_ALIGN_FUNCTIONS=0
+CONFIG_CC_ALIGN_LABELS=0
+CONFIG_CC_ALIGN_LOOPS=0
+CONFIG_CC_ALIGN_JUMPS=0
+# CONFIG_TINY_SHMEM is not set
+
+#
+# Loadable module support
+#
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_OBSOLETE_MODPARM=y
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_STOP_MACHINE=y
+
+#
+# Processor type and features
+#
+CONFIG_X86_PC=y
+# CONFIG_X86_ELAN is not set
+# CONFIG_X86_VOYAGER is not set
+# CONFIG_X86_NUMAQ is not set
+# CONFIG_X86_SUMMIT is not set
+# CONFIG_X86_BIGSMP is not set
+# CONFIG_X86_VISWS is not set
+# CONFIG_X86_GENERICARCH is not set
+# CONFIG_X86_ES7000 is not set
+# CONFIG_M386 is not set
+# CONFIG_M486 is not set
+# CONFIG_M586 is not set
+# CONFIG_M586TSC is not set
+# CONFIG_M586MMX is not set
+# CONFIG_M686 is not set
+# CONFIG_MPENTIUMII is not set
+# CONFIG_MPENTIUMIII is not set
+# CONFIG_MPENTIUMM is not set
+CONFIG_MPENTIUM4=y
+# CONFIG_MK6 is not set
+# CONFIG_MK7 is not set
+# CONFIG_MK8 is not set
+# CONFIG_MCRUSOE is not set
+# CONFIG_MEFFICEON is not set
+# CONFIG_MWINCHIPC6 is not set
+# CONFIG_MWINCHIP2 is not set
+# CONFIG_MWINCHIP3D is not set
+# CONFIG_MCYRIXIII is not set
+# CONFIG_MVIAC3_2 is not set
+# CONFIG_X86_GENERIC is not set
+CONFIG_X86_CMPXCHG=y
+CONFIG_X86_XADD=y
+CONFIG_X86_L1_CACHE_SHIFT=7
+CONFIG_RWSEM_XCHGADD_ALGORITHM=y
+CONFIG_X86_WP_WORKS_OK=y
+CONFIG_X86_INVLPG=y
+CONFIG_X86_BSWAP=y
+CONFIG_X86_POPAD_OK=y
+CONFIG_X86_GOOD_APIC=y
+CONFIG_X86_INTEL_USERCOPY=y
+CONFIG_X86_USE_PPRO_CHECKSUM=y
+# CONFIG_HPET_TIMER is not set
+CONFIG_SMP=y
+CONFIG_NR_CPUS=8
+# CONFIG_SCHED_SMT is not set
+CONFIG_PREEMPT=y
+CONFIG_X86_LOCAL_APIC=y
+CONFIG_X86_IO_APIC=y
+CONFIG_X86_TSC=y
+CONFIG_X86_MCE=y
+CONFIG_X86_MCE_NONFATAL=y
+# CONFIG_X86_MCE_P4THERMAL is not set
+# CONFIG_TOSHIBA is not set
+# CONFIG_I8K is not set
+# CONFIG_MICROCODE is not set
+# CONFIG_X86_MSR is not set
+# CONFIG_X86_CPUID is not set
+
+#
+# Firmware Drivers
+#
+# CONFIG_EDD is not set
+CONFIG_NOHIGHMEM=y
+# CONFIG_HIGHMEM4G is not set
+# CONFIG_HIGHMEM64G is not set
+# CONFIG_MATH_EMULATION is not set
+CONFIG_MTRR=y
+# CONFIG_EFI is not set
+CONFIG_IRQBALANCE=y
+CONFIG_HAVE_DEC_LOCK=y
+# CONFIG_REGPARM is not set
+
+#
+# Power management options (ACPI, APM)
+#
+CONFIG_PM=y
+# CONFIG_PM_DEBUG is not set
+CONFIG_SOFTWARE_SUSPEND=y
+CONFIG_PM_STD_PARTITION=""
+
+#
+# ACPI (Advanced Configuration and Power Interface) Support
+#
+CONFIG_ACPI=y
+CONFIG_ACPI_BOOT=y
+CONFIG_ACPI_INTERPRETER=y
+CONFIG_ACPI_SLEEP=y
+CONFIG_ACPI_SLEEP_PROC_FS=y
+CONFIG_ACPI_AC=y
+CONFIG_ACPI_BATTERY=y
+CONFIG_ACPI_BUTTON=y
+CONFIG_ACPI_VIDEO=y
+CONFIG_ACPI_FAN=y
+CONFIG_ACPI_PROCESSOR=y
+CONFIG_ACPI_THERMAL=y
+# CONFIG_ACPI_ASUS is not set
+# CONFIG_ACPI_IBM is not set
+# CONFIG_ACPI_TOSHIBA is not set
+# CONFIG_ACPI_CUSTOM_DSDT is not set
+CONFIG_ACPI_BLACKLIST_YEAR=0
+# CONFIG_ACPI_DEBUG is not set
+CONFIG_ACPI_BUS=y
+CONFIG_ACPI_EC=y
+CONFIG_ACPI_POWER=y
+CONFIG_ACPI_PCI=y
+CONFIG_ACPI_SYSTEM=y
+# CONFIG_X86_PM_TIMER is not set
+
+#
+# APM (Advanced Power Management) BIOS Support
+#
+# CONFIG_APM is not set
+
+#
+# CPU Frequency scaling
+#
+# CONFIG_CPU_FREQ is not set
+
+#
+# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
+#
+CONFIG_PCI=y
+# CONFIG_PCI_GOBIOS is not set
+# CONFIG_PCI_GOMMCONFIG is not set
+# CONFIG_PCI_GODIRECT is not set
+CONFIG_PCI_GOANY=y
+CONFIG_PCI_BIOS=y
+CONFIG_PCI_DIRECT=y
+CONFIG_PCI_MMCONFIG=y
+# CONFIG_PCI_MSI is not set
+CONFIG_PCI_LEGACY_PROC=y
+CONFIG_PCI_NAMES=y
+CONFIG_ISA=y
+# CONFIG_EISA is not set
+# CONFIG_MCA is not set
+# CONFIG_SCx200 is not set
+
+#
+# PCCARD (PCMCIA/CardBus) support
+#
+# CONFIG_PCCARD is not set
+
+#
+# PC-card bridges
+#
+CONFIG_PCMCIA_PROBE=y
+
+#
+# PCI Hotplug Support
+#
+# CONFIG_HOTPLUG_PCI is not set
+
+#
+# Executable file formats
+#
+CONFIG_BINFMT_ELF=y
+CONFIG_BINFMT_AOUT=y
+CONFIG_BINFMT_MISC=y
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+# CONFIG_STANDALONE is not set
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=m
+# CONFIG_DEBUG_DRIVER is not set
+
+#
+# Memory Technology Devices (MTD)
+#
+# CONFIG_MTD is not set
+
+#
+# Parallel port support
+#
+# CONFIG_PARPORT is not set
+
+#
+# Plug and Play support
+#
+CONFIG_PNP=y
+# CONFIG_PNP_DEBUG is not set
+
+#
+# Protocols
+#
+# CONFIG_ISAPNP is not set
+# CONFIG_PNPBIOS is not set
+CONFIG_PNPACPI=y
+
+#
+# Block devices
+#
+CONFIG_BLK_DEV_FD=y
+# CONFIG_BLK_DEV_XD is not set
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_UMEM is not set
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_CRYPTOLOOP=y
+CONFIG_BLK_DEV_NBD=y
+# CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_UB is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=4096
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_LBD=y
+CONFIG_CDROM_PKTCDVD=y
+CONFIG_CDROM_PKTCDVD_BUFFERS=8
+# CONFIG_CDROM_PKTCDVD_WCACHE is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+
+#
+# ATA/ATAPI/MFM/RLL support
+#
+CONFIG_IDE=y
+CONFIG_BLK_DEV_IDE=y
+
+#
+# Please see Documentation/ide.txt for help/info on IDE drives
+#
+# CONFIG_BLK_DEV_IDE_SATA is not set
+# CONFIG_BLK_DEV_HD_IDE is not set
+CONFIG_BLK_DEV_IDEDISK=y
+CONFIG_IDEDISK_MULTI_MODE=y
+CONFIG_BLK_DEV_IDECD=y
+# CONFIG_BLK_DEV_IDETAPE is not set
+# CONFIG_BLK_DEV_IDEFLOPPY is not set
+# CONFIG_BLK_DEV_IDESCSI is not set
+# CONFIG_IDE_TASK_IOCTL is not set
+
+#
+# IDE chipset support/bugfixes
+#
+CONFIG_IDE_GENERIC=y
+CONFIG_BLK_DEV_CMD640=y
+# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
+# CONFIG_BLK_DEV_IDEPNP is not set
+CONFIG_BLK_DEV_IDEPCI=y
+CONFIG_IDEPCI_SHARE_IRQ=y
+# CONFIG_BLK_DEV_OFFBOARD is not set
+CONFIG_BLK_DEV_GENERIC=y
+# CONFIG_BLK_DEV_OPTI621 is not set
+# CONFIG_BLK_DEV_RZ1000 is not set
+CONFIG_BLK_DEV_IDEDMA_PCI=y
+# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
+CONFIG_IDEDMA_PCI_AUTO=y
+# CONFIG_IDEDMA_ONLYDISK is not set
+# CONFIG_BLK_DEV_AEC62XX is not set
+# CONFIG_BLK_DEV_ALI15X3 is not set
+# CONFIG_BLK_DEV_AMD74XX is not set
+# CONFIG_BLK_DEV_ATIIXP is not set
+# CONFIG_BLK_DEV_CMD64X is not set
+# CONFIG_BLK_DEV_TRIFLEX is not set
+# CONFIG_BLK_DEV_CY82C693 is not set
+# CONFIG_BLK_DEV_CS5520 is not set
+# CONFIG_BLK_DEV_CS5530 is not set
+# CONFIG_BLK_DEV_HPT34X is not set
+# CONFIG_BLK_DEV_HPT366 is not set
+# CONFIG_BLK_DEV_SC1200 is not set
+# CONFIG_BLK_DEV_PIIX is not set
+# CONFIG_BLK_DEV_NS87415 is not set
+# CONFIG_BLK_DEV_PDC202XX_OLD is not set
+# CONFIG_BLK_DEV_PDC202XX_NEW is not set
+# CONFIG_BLK_DEV_SVWKS is not set
+# CONFIG_BLK_DEV_SIIMAGE is not set
+CONFIG_BLK_DEV_SIS5513=y
+# CONFIG_BLK_DEV_SLC90E66 is not set
+# CONFIG_BLK_DEV_TRM290 is not set
+# CONFIG_BLK_DEV_VIA82CXXX is not set
+# CONFIG_IDE_ARM is not set
+# CONFIG_IDE_CHIPSETS is not set
+CONFIG_BLK_DEV_IDEDMA=y
+# CONFIG_IDEDMA_IVB is not set
+CONFIG_IDEDMA_AUTO=y
+# CONFIG_BLK_DEV_HD is not set
+
+#
+# SCSI device support
+#
+CONFIG_SCSI=y
+# CONFIG_SCSI_PROC_FS is not set
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+# CONFIG_BLK_DEV_SD is not set
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+
+#
+# SCSI Transport Attributes
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+
+#
+# SCSI low-level drivers
+#
+# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
+# CONFIG_SCSI_3W_9XXX is not set
+# CONFIG_SCSI_7000FASST is not set
+# CONFIG_SCSI_ACARD is not set
+# CONFIG_SCSI_AHA152X is not set
+# CONFIG_SCSI_AHA1542 is not set
+# CONFIG_SCSI_AACRAID is not set
+# CONFIG_SCSI_AIC7XXX is not set
+# CONFIG_SCSI_AIC7XXX_OLD is not set
+# CONFIG_SCSI_AIC79XX is not set
+# CONFIG_SCSI_DPT_I2O is not set
+# CONFIG_SCSI_IN2000 is not set
+# CONFIG_MEGARAID_NEWGEN is not set
+# CONFIG_MEGARAID_LEGACY is not set
+# CONFIG_SCSI_SATA is not set
+# CONFIG_SCSI_BUSLOGIC is not set
+# CONFIG_SCSI_DMX3191D is not set
+# CONFIG_SCSI_DTC3280 is not set
+# CONFIG_SCSI_EATA is not set
+# CONFIG_SCSI_EATA_PIO is not set
+# CONFIG_SCSI_FUTURE_DOMAIN is not set
+# CONFIG_SCSI_GDTH is not set
+# CONFIG_SCSI_GENERIC_NCR5380 is not set
+# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
+# CONFIG_SCSI_IPS is not set
+# CONFIG_SCSI_INITIO is not set
+# CONFIG_SCSI_INIA100 is not set
+# CONFIG_SCSI_NCR53C406A is not set
+# CONFIG_SCSI_SYM53C8XX_2 is not set
+# CONFIG_SCSI_IPR is not set
+# CONFIG_SCSI_PAS16 is not set
+# CONFIG_SCSI_PSI240I is not set
+# CONFIG_SCSI_QLOGIC_FAS is not set
+# CONFIG_SCSI_QLOGIC_ISP is not set
+# CONFIG_SCSI_QLOGIC_FC is not set
+# CONFIG_SCSI_QLOGIC_1280 is not set
+CONFIG_SCSI_QLA2XXX=y
+# CONFIG_SCSI_QLA21XX is not set
+# CONFIG_SCSI_QLA22XX is not set
+# CONFIG_SCSI_QLA2300 is not set
+# CONFIG_SCSI_QLA2322 is not set
+# CONFIG_SCSI_QLA6312 is not set
+# CONFIG_SCSI_QLA6322 is not set
+# CONFIG_SCSI_SYM53C416 is not set
+# CONFIG_SCSI_DC395x is not set
+# CONFIG_SCSI_DC390T is not set
+# CONFIG_SCSI_T128 is not set
+# CONFIG_SCSI_U14_34F is not set
+# CONFIG_SCSI_ULTRASTOR is not set
+# CONFIG_SCSI_NSP32 is not set
+# CONFIG_SCSI_DEBUG is not set
+
+#
+# Old CD-ROM drivers (not SCSI, not IDE)
+#
+# CONFIG_CD_NO_IDESCSI is not set
+
+#
+# Multi-device support (RAID and LVM)
+#
+# CONFIG_MD is not set
+
+#
+# Fusion MPT device support
+#
+# CONFIG_FUSION is not set
+
+#
+# IEEE 1394 (FireWire) support
+#
+# CONFIG_IEEE1394 is not set
+
+#
+# I2O device support
+#
+CONFIG_I2O=y
+CONFIG_I2O_CONFIG=y
+CONFIG_I2O_BLOCK=y
+# CONFIG_I2O_SCSI is not set
+CONFIG_I2O_PROC=y
+
+#
+# Networking support
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+# CONFIG_NETLINK_DEV is not set
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_IP_MULTIPLE_TABLES=y
+CONFIG_IP_ROUTE_FWMARK=y
+CONFIG_IP_ROUTE_MULTIPATH=y
+CONFIG_IP_ROUTE_VERBOSE=y
+# CONFIG_IP_PNP is not set
+CONFIG_NET_IPIP=y
+CONFIG_NET_IPGRE=y
+CONFIG_NET_IPGRE_BROADCAST=y
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
+CONFIG_ARPD=y
+CONFIG_SYN_COOKIES=y
+CONFIG_INET_AH=y
+CONFIG_INET_ESP=y
+CONFIG_INET_IPCOMP=y
+CONFIG_INET_TUNNEL=y
+CONFIG_IP_TCPDIAG=y
+CONFIG_IP_TCPDIAG_IPV6=y
+
+#
+# IP: Virtual Server Configuration
+#
+# CONFIG_IP_VS is not set
+CONFIG_IPV6=y
+CONFIG_IPV6_PRIVACY=y
+CONFIG_INET6_AH=y
+CONFIG_INET6_ESP=y
+CONFIG_INET6_IPCOMP=y
+CONFIG_INET6_TUNNEL=y
+CONFIG_IPV6_TUNNEL=y
+CONFIG_NETFILTER=y
+# CONFIG_NETFILTER_DEBUG is not set
+CONFIG_BRIDGE_NETFILTER=y
+
+#
+# IP: Netfilter Configuration
+#
+CONFIG_IP_NF_CONNTRACK=y
+CONFIG_IP_NF_CT_ACCT=y
+CONFIG_IP_NF_CONNTRACK_MARK=y
+# CONFIG_IP_NF_CT_PROTO_SCTP is not set
+CONFIG_IP_NF_FTP=y
+CONFIG_IP_NF_IRC=y
+CONFIG_IP_NF_TFTP=y
+# CONFIG_IP_NF_AMANDA is not set
+CONFIG_IP_NF_QUEUE=y
+CONFIG_IP_NF_IPTABLES=y
+CONFIG_IP_NF_MATCH_LIMIT=y
+CONFIG_IP_NF_MATCH_IPRANGE=y
+CONFIG_IP_NF_MATCH_MAC=y
+CONFIG_IP_NF_MATCH_PKTTYPE=y
+CONFIG_IP_NF_MATCH_MARK=y
+CONFIG_IP_NF_MATCH_MULTIPORT=y
+CONFIG_IP_NF_MATCH_TOS=y
+CONFIG_IP_NF_MATCH_RECENT=y
+CONFIG_IP_NF_MATCH_ECN=y
+CONFIG_IP_NF_MATCH_DSCP=y
+CONFIG_IP_NF_MATCH_AH_ESP=y
+CONFIG_IP_NF_MATCH_LENGTH=y
+CONFIG_IP_NF_MATCH_TTL=y
+CONFIG_IP_NF_MATCH_TCPMSS=y
+CONFIG_IP_NF_MATCH_HELPER=y
+CONFIG_IP_NF_MATCH_STATE=y
+CONFIG_IP_NF_MATCH_CONNTRACK=y
+CONFIG_IP_NF_MATCH_OWNER=y
+CONFIG_IP_NF_MATCH_PHYSDEV=y
+CONFIG_IP_NF_MATCH_ADDRTYPE=y
+CONFIG_IP_NF_MATCH_REALM=y
+# CONFIG_IP_NF_MATCH_SCTP is not set
+CONFIG_IP_NF_MATCH_COMMENT=y
+CONFIG_IP_NF_MATCH_CONNMARK=y
+CONFIG_IP_NF_MATCH_HASHLIMIT=y
+CONFIG_IP_NF_FILTER=y
+CONFIG_IP_NF_TARGET_REJECT=y
+CONFIG_IP_NF_TARGET_LOG=y
+CONFIG_IP_NF_TARGET_ULOG=y
+CONFIG_IP_NF_TARGET_TCPMSS=y
+CONFIG_IP_NF_NAT=y
+CONFIG_IP_NF_NAT_NEEDED=y
+CONFIG_IP_NF_TARGET_MASQUERADE=y
+CONFIG_IP_NF_TARGET_REDIRECT=y
+CONFIG_IP_NF_TARGET_NETMAP=y
+CONFIG_IP_NF_TARGET_SAME=y
+# CONFIG_IP_NF_NAT_LOCAL is not set
+# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
+CONFIG_IP_NF_NAT_IRC=y
+CONFIG_IP_NF_NAT_FTP=y
+CONFIG_IP_NF_NAT_TFTP=y
+CONFIG_IP_NF_MANGLE=y
+CONFIG_IP_NF_TARGET_TOS=y
+CONFIG_IP_NF_TARGET_ECN=y
+CONFIG_IP_NF_TARGET_DSCP=y
+CONFIG_IP_NF_TARGET_MARK=y
+CONFIG_IP_NF_TARGET_CLASSIFY=y
+CONFIG_IP_NF_TARGET_CONNMARK=y
+CONFIG_IP_NF_TARGET_CLUSTERIP=y
+CONFIG_IP_NF_RAW=y
+CONFIG_IP_NF_TARGET_NOTRACK=y
+CONFIG_IP_NF_ARPTABLES=y
+CONFIG_IP_NF_ARPFILTER=y
+CONFIG_IP_NF_ARP_MANGLE=y
+
+#
+# IPv6: Netfilter Configuration
+#
+CONFIG_IP6_NF_QUEUE=y
+CONFIG_IP6_NF_IPTABLES=y
+CONFIG_IP6_NF_MATCH_LIMIT=y
+CONFIG_IP6_NF_MATCH_MAC=y
+CONFIG_IP6_NF_MATCH_RT=y
+CONFIG_IP6_NF_MATCH_OPTS=y
+CONFIG_IP6_NF_MATCH_FRAG=y
+CONFIG_IP6_NF_MATCH_HL=y
+CONFIG_IP6_NF_MATCH_MULTIPORT=y
+CONFIG_IP6_NF_MATCH_OWNER=y
+CONFIG_IP6_NF_MATCH_MARK=y
+CONFIG_IP6_NF_MATCH_IPV6HEADER=y
+CONFIG_IP6_NF_MATCH_AHESP=y
+CONFIG_IP6_NF_MATCH_LENGTH=y
+CONFIG_IP6_NF_MATCH_EUI64=y
+CONFIG_IP6_NF_MATCH_PHYSDEV=y
+CONFIG_IP6_NF_FILTER=y
+CONFIG_IP6_NF_TARGET_LOG=y
+CONFIG_IP6_NF_MANGLE=y
+CONFIG_IP6_NF_TARGET_MARK=y
+CONFIG_IP6_NF_RAW=y
+
+#
+# Bridge: Netfilter Configuration
+#
+# CONFIG_BRIDGE_NF_EBTABLES is not set
+CONFIG_XFRM=y
+CONFIG_XFRM_USER=y
+
+#
+# SCTP Configuration (EXPERIMENTAL)
+#
+# CONFIG_IP_SCTP is not set
+CONFIG_ATM=y
+# CONFIG_ATM_CLIP is not set
+# CONFIG_ATM_LANE is not set
+# CONFIG_ATM_BR2684 is not set
+CONFIG_BRIDGE=y
+CONFIG_VLAN_8021Q=y
+# CONFIG_DECNET is not set
+CONFIG_LLC=y
+CONFIG_LLC2=y
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_NET_DIVERT is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+
+#
+# QoS and/or fair queueing
+#
+CONFIG_NET_SCHED=y
+CONFIG_NET_SCH_CLK_JIFFIES=y
+# CONFIG_NET_SCH_CLK_GETTIMEOFDAY is not set
+# CONFIG_NET_SCH_CLK_CPU is not set
+CONFIG_NET_SCH_CBQ=y
+CONFIG_NET_SCH_HTB=y
+CONFIG_NET_SCH_HFSC=y
+CONFIG_NET_SCH_ATM=y
+CONFIG_NET_SCH_PRIO=y
+CONFIG_NET_SCH_RED=y
+CONFIG_NET_SCH_SFQ=y
+CONFIG_NET_SCH_TEQL=y
+CONFIG_NET_SCH_TBF=y
+CONFIG_NET_SCH_GRED=y
+CONFIG_NET_SCH_DSMARK=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_NET_SCH_INGRESS=y
+CONFIG_NET_QOS=y
+CONFIG_NET_ESTIMATOR=y
+CONFIG_NET_CLS=y
+CONFIG_NET_CLS_TCINDEX=y
+CONFIG_NET_CLS_ROUTE4=y
+CONFIG_NET_CLS_ROUTE=y
+CONFIG_NET_CLS_FW=y
+CONFIG_NET_CLS_U32=y
+CONFIG_NET_CLS_EGP=y
+CONFIG_EGP_DEBUG=y
+CONFIG_NET_CLS_EGP_SIMPLE_CMP=y
+CONFIG_NET_CLS_EGP_NBYTE=y
+CONFIG_NET_CLS_EGP_KMP=y
+CONFIG_NET_CLS_EGP_REGEXP=y
+CONFIG_NET_CLS_EGP_CMD=y
+CONFIG_EGP_CMD_BACK_TTL=4096
+CONFIG_CLS_U32_PERF=y
+CONFIG_NET_CLS_IND=y
+CONFIG_NET_CLS_RSVP=y
+CONFIG_NET_CLS_RSVP6=y
+# CONFIG_NET_CLS_ACT is not set
+CONFIG_NET_CLS_POLICE=y
+
+#
+# Network testing
+#
+CONFIG_NET_PKTGEN=y
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+CONFIG_NETDEVICES=y
+CONFIG_DUMMY=y
+# CONFIG_BONDING is not set
+# CONFIG_EQUALIZER is not set
+CONFIG_TUN=y
+# CONFIG_NET_SB1000 is not set
+
+#
+# ARCnet devices
+#
+# CONFIG_ARCNET is not set
+
+#
+# Ethernet (10 or 100Mbit)
+#
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_SUNGEM is not set
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_LANCE is not set
+# CONFIG_NET_VENDOR_SMC is not set
+# CONFIG_NET_VENDOR_RACAL is not set
+
+#
+# Tulip family network device support
+#
+# CONFIG_NET_TULIP is not set
+# CONFIG_AT1700 is not set
+# CONFIG_DEPCA is not set
+# CONFIG_HP100 is not set
+# CONFIG_NET_ISA is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_AMD8111_ETH is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_AC3200 is not set
+# CONFIG_APRICOT is not set
+# CONFIG_B44 is not set
+# CONFIG_FORCEDETH is not set
+# CONFIG_CS89x0 is not set
+# CONFIG_DGRS is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_E100 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_8139CP is not set
+CONFIG_8139TOO=y
+CONFIG_8139TOO_PIO=y
+# CONFIG_8139TOO_TUNE_TWISTER is not set
+# CONFIG_8139TOO_8129 is not set
+# CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_NET_POCKET is not set
+
+#
+# Ethernet (1000 Mbit)
+#
+# CONFIG_ACENIC is not set
+# CONFIG_DL2K is not set
+# CONFIG_E1000 is not set
+# CONFIG_NS83820 is not set
+# CONFIG_HAMACHI is not set
+# CONFIG_YELLOWFIN is not set
+# CONFIG_R8169 is not set
+# CONFIG_SK98LIN is not set
+# CONFIG_VIA_VELOCITY is not set
+# CONFIG_TIGON3 is not set
+
+#
+# Ethernet (10000 Mbit)
+#
+# CONFIG_IXGB is not set
+# CONFIG_S2IO is not set
+
+#
+# Token Ring devices
+#
+# CONFIG_TR is not set
+
+#
+# Wireless LAN (non-hamradio)
+#
+# CONFIG_NET_RADIO is not set
+
+#
+# Wan interfaces
+#
+# CONFIG_WAN is not set
+
+#
+# ATM drivers
+#
+# CONFIG_ATM_TCP is not set
+# CONFIG_ATM_LANAI is not set
+# CONFIG_ATM_ENI is not set
+# CONFIG_ATM_FIRESTREAM is not set
+# CONFIG_ATM_ZATM is not set
+# CONFIG_ATM_NICSTAR is not set
+# CONFIG_ATM_IDT77252 is not set
+# CONFIG_ATM_AMBASSADOR is not set
+# CONFIG_ATM_HORIZON is not set
+# CONFIG_ATM_IA is not set
+# CONFIG_ATM_FORE200E_MAYBE is not set
+# CONFIG_ATM_HE is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+CONFIG_PPP=y
+CONFIG_PPP_MULTILINK=y
+CONFIG_PPP_FILTER=y
+# CONFIG_PPP_ASYNC is not set
+# CONFIG_PPP_SYNC_TTY is not set
+# CONFIG_PPP_DEFLATE is not set
+CONFIG_PPP_BSDCOMP=y
+# CONFIG_PPPOE is not set
+# CONFIG_PPPOATM is not set
+# CONFIG_SLIP is not set
+# CONFIG_NET_FC is not set
+CONFIG_SHAPER=y
+# CONFIG_NETCONSOLE is not set
+
+#
+# ISDN subsystem
+#
+# CONFIG_ISDN is not set
+
+#
+# Telephony Support
+#
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+CONFIG_INPUT_MOUSEDEV_PSAUX=y
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_TSDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input I/O drivers
+#
+# CONFIG_GAMEPORT is not set
+CONFIG_SOUND_GAMEPORT=y
+CONFIG_SERIO=y
+CONFIG_SERIO_I8042=y
+# CONFIG_SERIO_SERPORT is not set
+# CONFIG_SERIO_CT82C710 is not set
+# CONFIG_SERIO_PCIPS2 is not set
+# CONFIG_SERIO_RAW is not set
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+CONFIG_KEYBOARD_ATKBD=y
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+CONFIG_INPUT_MOUSE=y
+CONFIG_MOUSE_PS2=y
+# CONFIG_MOUSE_SERIAL is not set
+# CONFIG_MOUSE_INPORT is not set
+# CONFIG_MOUSE_LOGIBM is not set
+# CONFIG_MOUSE_PC110PAD is not set
+# CONFIG_MOUSE_VSXXXAA is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+# CONFIG_SERIAL_8250_CONSOLE is not set
+# CONFIG_SERIAL_8250_ACPI is not set
+CONFIG_SERIAL_8250_NR_UARTS=4
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+
+#
+# IPMI
+#
+# CONFIG_IPMI_HANDLER is not set
+
+#
+# Watchdog Cards
+#
+# CONFIG_WATCHDOG is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_RTC is not set
+# CONFIG_GEN_RTC is not set
+# CONFIG_DTLK is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+# CONFIG_SONYPI is not set
+
+#
+# Ftape, the floppy tape device driver
+#
+# CONFIG_AGP is not set
+# CONFIG_DRM is not set
+# CONFIG_MWAVE is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_HPET is not set
+# CONFIG_HANGCHECK_TIMER is not set
+
+#
+# I2C support
+#
+CONFIG_I2C=y
+CONFIG_I2C_CHARDEV=y
+
+#
+# I2C Algorithms
+#
+CONFIG_I2C_ALGOBIT=y
+# CONFIG_I2C_ALGOPCF is not set
+# CONFIG_I2C_ALGOPCA is not set
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+# CONFIG_I2C_I801 is not set
+# CONFIG_I2C_I810 is not set
+# CONFIG_I2C_ISA is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_SCx200_ACB is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+CONFIG_I2C_SIS96X=y
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_ISA is not set
+
+#
+# Hardware Sensors Chip support
+#
+CONFIG_I2C_SENSOR=y
+# CONFIG_SENSORS_ADM1021 is not set
+# CONFIG_SENSORS_ADM1025 is not set
+# CONFIG_SENSORS_ADM1031 is not set
+# CONFIG_SENSORS_ASB100 is not set
+# CONFIG_SENSORS_DS1621 is not set
+# CONFIG_SENSORS_FSCHER is not set
+# CONFIG_SENSORS_GL518SM is not set
+# CONFIG_SENSORS_IT87 is not set
+# CONFIG_SENSORS_LM63 is not set
+# CONFIG_SENSORS_LM75 is not set
+# CONFIG_SENSORS_LM77 is not set
+# CONFIG_SENSORS_LM78 is not set
+# CONFIG_SENSORS_LM80 is not set
+# CONFIG_SENSORS_LM83 is not set
+# CONFIG_SENSORS_LM85 is not set
+# CONFIG_SENSORS_LM87 is not set
+# CONFIG_SENSORS_LM90 is not set
+# CONFIG_SENSORS_MAX1619 is not set
+# CONFIG_SENSORS_PC87360 is not set
+# CONFIG_SENSORS_SMSC47M1 is not set
+# CONFIG_SENSORS_VIA686A is not set
+# CONFIG_SENSORS_W83781D is not set
+# CONFIG_SENSORS_W83L785TS is not set
+# CONFIG_SENSORS_W83627HF is not set
+
+#
+# Other I2C Chip support
+#
+CONFIG_SENSORS_EEPROM=y
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_RTC8564 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+
+#
+# Dallas's 1-wire bus
+#
+# CONFIG_W1 is not set
+
+#
+# Misc devices
+#
+# CONFIG_IBM_ASM is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+
+#
+# Digital Video Broadcasting Devices
+#
+# CONFIG_DVB is not set
+
+#
+# Graphics support
+#
+# CONFIG_FB is not set
+# CONFIG_VIDEO_SELECT is not set
+
+#
+# Console display driver support
+#
+CONFIG_VGA_CONSOLE=y
+# CONFIG_MDA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+CONFIG_SOUND=y
+
+#
+# Advanced Linux Sound Architecture
+#
+CONFIG_SND=y
+CONFIG_SND_TIMER=y
+CONFIG_SND_PCM=y
+CONFIG_SND_HWDEP=y
+CONFIG_SND_RAWMIDI=y
+CONFIG_SND_SEQUENCER=y
+# CONFIG_SND_SEQ_DUMMY is not set
+CONFIG_SND_OSSEMUL=y
+CONFIG_SND_MIXER_OSS=y
+CONFIG_SND_PCM_OSS=y
+CONFIG_SND_SEQUENCER_OSS=y
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+
+#
+# Generic devices
+#
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_VIRMIDI is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# ISA devices
+#
+# CONFIG_SND_AD1848 is not set
+# CONFIG_SND_CS4231 is not set
+# CONFIG_SND_CS4232 is not set
+# CONFIG_SND_CS4236 is not set
+# CONFIG_SND_ES1688 is not set
+# CONFIG_SND_ES18XX is not set
+# CONFIG_SND_GUSCLASSIC is not set
+# CONFIG_SND_GUSEXTREME is not set
+# CONFIG_SND_GUSMAX is not set
+# CONFIG_SND_INTERWAVE is not set
+# CONFIG_SND_INTERWAVE_STB is not set
+# CONFIG_SND_OPTI92X_AD1848 is not set
+# CONFIG_SND_OPTI92X_CS4231 is not set
+# CONFIG_SND_OPTI93X is not set
+# CONFIG_SND_SB8 is not set
+# CONFIG_SND_SB16 is not set
+# CONFIG_SND_SBAWE is not set
+# CONFIG_SND_WAVEFRONT is not set
+# CONFIG_SND_CMI8330 is not set
+# CONFIG_SND_OPL3SA2 is not set
+# CONFIG_SND_SGALAXY is not set
+# CONFIG_SND_SSCAPE is not set
+
+#
+# PCI devices
+#
+CONFIG_SND_AC97_CODEC=y
+# CONFIG_SND_ALI5451 is not set
+# CONFIG_SND_ATIIXP is not set
+# CONFIG_SND_ATIIXP_MODEM is not set
+# CONFIG_SND_AU8810 is not set
+# CONFIG_SND_AU8820 is not set
+# CONFIG_SND_AU8830 is not set
+# CONFIG_SND_AZT3328 is not set
+# CONFIG_SND_BT87X is not set
+# CONFIG_SND_CS46XX is not set
+# CONFIG_SND_CS4281 is not set
+CONFIG_SND_EMU10K1=y
+# CONFIG_SND_KORG1212 is not set
+# CONFIG_SND_MIXART is not set
+# CONFIG_SND_NM256 is not set
+# CONFIG_SND_RME32 is not set
+# CONFIG_SND_RME96 is not set
+# CONFIG_SND_RME9652 is not set
+# CONFIG_SND_HDSP is not set
+# CONFIG_SND_TRIDENT is not set
+# CONFIG_SND_YMFPCI is not set
+# CONFIG_SND_ALS4000 is not set
+# CONFIG_SND_CMIPCI is not set
+# CONFIG_SND_ENS1370 is not set
+# CONFIG_SND_ENS1371 is not set
+# CONFIG_SND_ES1938 is not set
+# CONFIG_SND_ES1968 is not set
+# CONFIG_SND_MAESTRO3 is not set
+# CONFIG_SND_FM801 is not set
+# CONFIG_SND_ICE1712 is not set
+# CONFIG_SND_ICE1724 is not set
+# CONFIG_SND_INTEL8X0 is not set
+# CONFIG_SND_INTEL8X0M is not set
+# CONFIG_SND_SONICVIBES is not set
+# CONFIG_SND_VIA82XX is not set
+# CONFIG_SND_VX222 is not set
+
+#
+# USB devices
+#
+# CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_USX2Y is not set
+
+#
+# Open Sound System
+#
+# CONFIG_SOUND_PRIME is not set
+
+#
+# USB support
+#
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+# CONFIG_USB_BANDWIDTH is not set
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_OTG is not set
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+
+#
+# USB Host Controller Drivers
+#
+CONFIG_USB_EHCI_HCD=y
+# CONFIG_USB_EHCI_SPLIT_ISO is not set
+# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
+# CONFIG_USB_OHCI_HCD is not set
+CONFIG_USB_UHCI_HCD=y
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_AUDIO is not set
+# CONFIG_USB_BLUETOOTH_TTY is not set
+# CONFIG_USB_MIDI is not set
+# CONFIG_USB_ACM is not set
+CONFIG_USB_PRINTER=y
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_RW_DETECT is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_HP8200e is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+CONFIG_USB_HIDINPUT=y
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+# CONFIG_USB_AIPTEK is not set
+# CONFIG_USB_WACOM is not set
+# CONFIG_USB_KBTAB is not set
+# CONFIG_USB_POWERMATE is not set
+# CONFIG_USB_MTOUCH is not set
+CONFIG_USB_EGALAX=m
+# CONFIG_USB_XPAD is not set
+# CONFIG_USB_ATI_REMOTE is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_HPUSBSCSI is not set
+
+#
+# USB Multimedia devices
+#
+# CONFIG_USB_DABUSB is not set
+
+#
+# Video4Linux support is needed for USB Multimedia device support
+#
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_TIGL is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_LED is not set
+CONFIG_USB_CYTHERM=m
+# CONFIG_USB_PHIDGETKIT is not set
+CONFIG_USB_PHIDGETSERVO=m
+# CONFIG_USB_TEST is not set
+
+#
+# USB ATM/DSL drivers
+#
+# CONFIG_USB_ATM is not set
+# CONFIG_USB_SPEEDTOUCH is not set
+
+#
+# USB Gadget Support
+#
+# CONFIG_USB_GADGET is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+CONFIG_EXT3_FS=y
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+# CONFIG_EXT3_FS_SECURITY is not set
+CONFIG_JBD=y
+# CONFIG_JBD_DEBUG is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=y
+
+#
+# CD-ROM/DVD Filesystems
+#
+CONFIG_ISO9660_FS=y
+CONFIG_JOLIET=y
+# CONFIG_ZISOFS is not set
+CONFIG_UDF_FS=y
+CONFIG_UDF_NLS=y
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_KCORE=y
+CONFIG_SYSFS=y
+# CONFIG_DEVFS_FS is not set
+# CONFIG_DEVPTS_FS_XATTR is not set
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_XATTR is not set
+# CONFIG_HUGETLBFS is not set
+# CONFIG_HUGETLB_PAGE is not set
+CONFIG_RAMFS=y
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Network File Systems
+#
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFS_DIRECTIO is not set
+CONFIG_NFSD=y
+# CONFIG_NFSD_V3 is not set
+CONFIG_NFSD_TCP=y
+CONFIG_LOCKD=y
+CONFIG_EXPORTFS=y
+CONFIG_SUNRPC=y
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+
+#
+# Native Language Support
+#
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Profiling support
+#
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+
+#
+# Kernel hacking
+#
+CONFIG_DEBUG_KERNEL=y
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_SCHEDSTATS is not set
+CONFIG_DEBUG_SLAB=y
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_KOBJECT is not set
+# CONFIG_DEBUG_INFO is not set
+CONFIG_FRAME_POINTER=y
+CONFIG_EARLY_PRINTK=y
+# CONFIG_DEBUG_STACKOVERFLOW is not set
+# CONFIG_KPROBES is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
+# CONFIG_DEBUG_PAGEALLOC is not set
+# CONFIG_4KSTACKS is not set
+CONFIG_X86_FIND_SMP_CONFIG=y
+CONFIG_X86_MPPARSE=y
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+CONFIG_SECURITY=y
+CONFIG_SECURITY_NETWORK=y
+CONFIG_SECURITY_CAPABILITIES=m
+CONFIG_SECURITY_ROOTPLUG=m
+# CONFIG_SECURITY_SECLVL is not set
+CONFIG_SECURITY_SELINUX=y
+# CONFIG_SECURITY_SELINUX_BOOTPARAM is not set
+CONFIG_SECURITY_SELINUX_DISABLE=y
+CONFIG_SECURITY_SELINUX_DEVELOP=y
+# CONFIG_SECURITY_SELINUX_MLS is not set
+
+#
+# Cryptographic options
+#
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_HMAC=y
+CONFIG_CRYPTO_NULL=y
+CONFIG_CRYPTO_MD4=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_SHA1=y
+CONFIG_CRYPTO_SHA256=y
+CONFIG_CRYPTO_SHA512=y
+CONFIG_CRYPTO_WP512=y
+CONFIG_CRYPTO_DES=y
+CONFIG_CRYPTO_BLOWFISH=y
+CONFIG_CRYPTO_TWOFISH=y
+CONFIG_CRYPTO_SERPENT=y
+CONFIG_CRYPTO_AES_586=y
+CONFIG_CRYPTO_CAST5=y
+CONFIG_CRYPTO_CAST6=y
+CONFIG_CRYPTO_TEA=y
+CONFIG_CRYPTO_ARC4=y
+CONFIG_CRYPTO_KHAZAD=y
+# CONFIG_CRYPTO_ANUBIS is not set
+CONFIG_CRYPTO_DEFLATE=y
+CONFIG_CRYPTO_MICHAEL_MIC=y
+CONFIG_CRYPTO_CRC32C=y
+CONFIG_CRYPTO_TEST=y
+
+#
+# Library routines
+#
+# CONFIG_CRC_CCITT is not set
+CONFIG_CRC32=y
+CONFIG_LIBCRC32C=y
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_X86_SMP=y
+CONFIG_X86_HT=y
+CONFIG_X86_BIOS_REBOOT=y
+CONFIG_X86_TRAMPOLINE=y
+CONFIG_PC=y
diff --git a/testsuite/configs/all-police-act b/testsuite/configs/all-police-act
new file mode 100644
index 0000000..1c84282
--- /dev/null
+++ b/testsuite/configs/all-police-act
@@ -0,0 +1,1504 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.10-rc2-bk13
+# Wed Dec  8 14:19:17 2004
+#
+CONFIG_X86=y
+CONFIG_MMU=y
+CONFIG_UID16=y
+CONFIG_GENERIC_ISA_DMA=y
+CONFIG_GENERIC_IOMAP=y
+
+#
+# Code maturity level options
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_CLEAN_COMPILE=y
+CONFIG_LOCK_KERNEL=y
+
+#
+# General setup
+#
+CONFIG_LOCALVERSION=""
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+CONFIG_SYSCTL=y
+CONFIG_AUDIT=y
+CONFIG_AUDITSYSCALL=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_HOTPLUG=y
+CONFIG_KOBJECT_UEVENT=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+# CONFIG_EMBEDDED is not set
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SHMEM=y
+CONFIG_CC_ALIGN_FUNCTIONS=0
+CONFIG_CC_ALIGN_LABELS=0
+CONFIG_CC_ALIGN_LOOPS=0
+CONFIG_CC_ALIGN_JUMPS=0
+# CONFIG_TINY_SHMEM is not set
+
+#
+# Loadable module support
+#
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_OBSOLETE_MODPARM=y
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_STOP_MACHINE=y
+
+#
+# Processor type and features
+#
+CONFIG_X86_PC=y
+# CONFIG_X86_ELAN is not set
+# CONFIG_X86_VOYAGER is not set
+# CONFIG_X86_NUMAQ is not set
+# CONFIG_X86_SUMMIT is not set
+# CONFIG_X86_BIGSMP is not set
+# CONFIG_X86_VISWS is not set
+# CONFIG_X86_GENERICARCH is not set
+# CONFIG_X86_ES7000 is not set
+# CONFIG_M386 is not set
+# CONFIG_M486 is not set
+# CONFIG_M586 is not set
+# CONFIG_M586TSC is not set
+# CONFIG_M586MMX is not set
+# CONFIG_M686 is not set
+# CONFIG_MPENTIUMII is not set
+# CONFIG_MPENTIUMIII is not set
+# CONFIG_MPENTIUMM is not set
+CONFIG_MPENTIUM4=y
+# CONFIG_MK6 is not set
+# CONFIG_MK7 is not set
+# CONFIG_MK8 is not set
+# CONFIG_MCRUSOE is not set
+# CONFIG_MEFFICEON is not set
+# CONFIG_MWINCHIPC6 is not set
+# CONFIG_MWINCHIP2 is not set
+# CONFIG_MWINCHIP3D is not set
+# CONFIG_MCYRIXIII is not set
+# CONFIG_MVIAC3_2 is not set
+# CONFIG_X86_GENERIC is not set
+CONFIG_X86_CMPXCHG=y
+CONFIG_X86_XADD=y
+CONFIG_X86_L1_CACHE_SHIFT=7
+CONFIG_RWSEM_XCHGADD_ALGORITHM=y
+CONFIG_X86_WP_WORKS_OK=y
+CONFIG_X86_INVLPG=y
+CONFIG_X86_BSWAP=y
+CONFIG_X86_POPAD_OK=y
+CONFIG_X86_GOOD_APIC=y
+CONFIG_X86_INTEL_USERCOPY=y
+CONFIG_X86_USE_PPRO_CHECKSUM=y
+# CONFIG_HPET_TIMER is not set
+CONFIG_SMP=y
+CONFIG_NR_CPUS=8
+# CONFIG_SCHED_SMT is not set
+CONFIG_PREEMPT=y
+CONFIG_X86_LOCAL_APIC=y
+CONFIG_X86_IO_APIC=y
+CONFIG_X86_TSC=y
+CONFIG_X86_MCE=y
+CONFIG_X86_MCE_NONFATAL=y
+# CONFIG_X86_MCE_P4THERMAL is not set
+# CONFIG_TOSHIBA is not set
+# CONFIG_I8K is not set
+# CONFIG_MICROCODE is not set
+# CONFIG_X86_MSR is not set
+# CONFIG_X86_CPUID is not set
+
+#
+# Firmware Drivers
+#
+# CONFIG_EDD is not set
+CONFIG_NOHIGHMEM=y
+# CONFIG_HIGHMEM4G is not set
+# CONFIG_HIGHMEM64G is not set
+# CONFIG_MATH_EMULATION is not set
+CONFIG_MTRR=y
+# CONFIG_EFI is not set
+CONFIG_IRQBALANCE=y
+CONFIG_HAVE_DEC_LOCK=y
+# CONFIG_REGPARM is not set
+
+#
+# Power management options (ACPI, APM)
+#
+CONFIG_PM=y
+# CONFIG_PM_DEBUG is not set
+CONFIG_SOFTWARE_SUSPEND=y
+CONFIG_PM_STD_PARTITION=""
+
+#
+# ACPI (Advanced Configuration and Power Interface) Support
+#
+CONFIG_ACPI=y
+CONFIG_ACPI_BOOT=y
+CONFIG_ACPI_INTERPRETER=y
+CONFIG_ACPI_SLEEP=y
+CONFIG_ACPI_SLEEP_PROC_FS=y
+CONFIG_ACPI_AC=y
+CONFIG_ACPI_BATTERY=y
+CONFIG_ACPI_BUTTON=y
+CONFIG_ACPI_VIDEO=y
+CONFIG_ACPI_FAN=y
+CONFIG_ACPI_PROCESSOR=y
+CONFIG_ACPI_THERMAL=y
+# CONFIG_ACPI_ASUS is not set
+# CONFIG_ACPI_IBM is not set
+# CONFIG_ACPI_TOSHIBA is not set
+# CONFIG_ACPI_CUSTOM_DSDT is not set
+CONFIG_ACPI_BLACKLIST_YEAR=0
+# CONFIG_ACPI_DEBUG is not set
+CONFIG_ACPI_BUS=y
+CONFIG_ACPI_EC=y
+CONFIG_ACPI_POWER=y
+CONFIG_ACPI_PCI=y
+CONFIG_ACPI_SYSTEM=y
+# CONFIG_X86_PM_TIMER is not set
+
+#
+# APM (Advanced Power Management) BIOS Support
+#
+# CONFIG_APM is not set
+
+#
+# CPU Frequency scaling
+#
+# CONFIG_CPU_FREQ is not set
+
+#
+# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
+#
+CONFIG_PCI=y
+# CONFIG_PCI_GOBIOS is not set
+# CONFIG_PCI_GOMMCONFIG is not set
+# CONFIG_PCI_GODIRECT is not set
+CONFIG_PCI_GOANY=y
+CONFIG_PCI_BIOS=y
+CONFIG_PCI_DIRECT=y
+CONFIG_PCI_MMCONFIG=y
+# CONFIG_PCI_MSI is not set
+CONFIG_PCI_LEGACY_PROC=y
+CONFIG_PCI_NAMES=y
+CONFIG_ISA=y
+# CONFIG_EISA is not set
+# CONFIG_MCA is not set
+# CONFIG_SCx200 is not set
+
+#
+# PCCARD (PCMCIA/CardBus) support
+#
+# CONFIG_PCCARD is not set
+
+#
+# PC-card bridges
+#
+CONFIG_PCMCIA_PROBE=y
+
+#
+# PCI Hotplug Support
+#
+# CONFIG_HOTPLUG_PCI is not set
+
+#
+# Executable file formats
+#
+CONFIG_BINFMT_ELF=y
+CONFIG_BINFMT_AOUT=y
+CONFIG_BINFMT_MISC=y
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+# CONFIG_STANDALONE is not set
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=m
+# CONFIG_DEBUG_DRIVER is not set
+
+#
+# Memory Technology Devices (MTD)
+#
+# CONFIG_MTD is not set
+
+#
+# Parallel port support
+#
+# CONFIG_PARPORT is not set
+
+#
+# Plug and Play support
+#
+CONFIG_PNP=y
+# CONFIG_PNP_DEBUG is not set
+
+#
+# Protocols
+#
+# CONFIG_ISAPNP is not set
+# CONFIG_PNPBIOS is not set
+CONFIG_PNPACPI=y
+
+#
+# Block devices
+#
+CONFIG_BLK_DEV_FD=y
+# CONFIG_BLK_DEV_XD is not set
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_UMEM is not set
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_CRYPTOLOOP=y
+CONFIG_BLK_DEV_NBD=y
+# CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_UB is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=4096
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_LBD=y
+CONFIG_CDROM_PKTCDVD=y
+CONFIG_CDROM_PKTCDVD_BUFFERS=8
+# CONFIG_CDROM_PKTCDVD_WCACHE is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+
+#
+# ATA/ATAPI/MFM/RLL support
+#
+CONFIG_IDE=y
+CONFIG_BLK_DEV_IDE=y
+
+#
+# Please see Documentation/ide.txt for help/info on IDE drives
+#
+# CONFIG_BLK_DEV_IDE_SATA is not set
+# CONFIG_BLK_DEV_HD_IDE is not set
+CONFIG_BLK_DEV_IDEDISK=y
+CONFIG_IDEDISK_MULTI_MODE=y
+CONFIG_BLK_DEV_IDECD=y
+# CONFIG_BLK_DEV_IDETAPE is not set
+# CONFIG_BLK_DEV_IDEFLOPPY is not set
+# CONFIG_BLK_DEV_IDESCSI is not set
+# CONFIG_IDE_TASK_IOCTL is not set
+
+#
+# IDE chipset support/bugfixes
+#
+CONFIG_IDE_GENERIC=y
+CONFIG_BLK_DEV_CMD640=y
+# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
+# CONFIG_BLK_DEV_IDEPNP is not set
+CONFIG_BLK_DEV_IDEPCI=y
+CONFIG_IDEPCI_SHARE_IRQ=y
+# CONFIG_BLK_DEV_OFFBOARD is not set
+CONFIG_BLK_DEV_GENERIC=y
+# CONFIG_BLK_DEV_OPTI621 is not set
+# CONFIG_BLK_DEV_RZ1000 is not set
+CONFIG_BLK_DEV_IDEDMA_PCI=y
+# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
+CONFIG_IDEDMA_PCI_AUTO=y
+# CONFIG_IDEDMA_ONLYDISK is not set
+# CONFIG_BLK_DEV_AEC62XX is not set
+# CONFIG_BLK_DEV_ALI15X3 is not set
+# CONFIG_BLK_DEV_AMD74XX is not set
+# CONFIG_BLK_DEV_ATIIXP is not set
+# CONFIG_BLK_DEV_CMD64X is not set
+# CONFIG_BLK_DEV_TRIFLEX is not set
+# CONFIG_BLK_DEV_CY82C693 is not set
+# CONFIG_BLK_DEV_CS5520 is not set
+# CONFIG_BLK_DEV_CS5530 is not set
+# CONFIG_BLK_DEV_HPT34X is not set
+# CONFIG_BLK_DEV_HPT366 is not set
+# CONFIG_BLK_DEV_SC1200 is not set
+# CONFIG_BLK_DEV_PIIX is not set
+# CONFIG_BLK_DEV_NS87415 is not set
+# CONFIG_BLK_DEV_PDC202XX_OLD is not set
+# CONFIG_BLK_DEV_PDC202XX_NEW is not set
+# CONFIG_BLK_DEV_SVWKS is not set
+# CONFIG_BLK_DEV_SIIMAGE is not set
+CONFIG_BLK_DEV_SIS5513=y
+# CONFIG_BLK_DEV_SLC90E66 is not set
+# CONFIG_BLK_DEV_TRM290 is not set
+# CONFIG_BLK_DEV_VIA82CXXX is not set
+# CONFIG_IDE_ARM is not set
+# CONFIG_IDE_CHIPSETS is not set
+CONFIG_BLK_DEV_IDEDMA=y
+# CONFIG_IDEDMA_IVB is not set
+CONFIG_IDEDMA_AUTO=y
+# CONFIG_BLK_DEV_HD is not set
+
+#
+# SCSI device support
+#
+CONFIG_SCSI=y
+# CONFIG_SCSI_PROC_FS is not set
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+# CONFIG_BLK_DEV_SD is not set
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+
+#
+# SCSI Transport Attributes
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+
+#
+# SCSI low-level drivers
+#
+# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
+# CONFIG_SCSI_3W_9XXX is not set
+# CONFIG_SCSI_7000FASST is not set
+# CONFIG_SCSI_ACARD is not set
+# CONFIG_SCSI_AHA152X is not set
+# CONFIG_SCSI_AHA1542 is not set
+# CONFIG_SCSI_AACRAID is not set
+# CONFIG_SCSI_AIC7XXX is not set
+# CONFIG_SCSI_AIC7XXX_OLD is not set
+# CONFIG_SCSI_AIC79XX is not set
+# CONFIG_SCSI_DPT_I2O is not set
+# CONFIG_SCSI_IN2000 is not set
+# CONFIG_MEGARAID_NEWGEN is not set
+# CONFIG_MEGARAID_LEGACY is not set
+# CONFIG_SCSI_SATA is not set
+# CONFIG_SCSI_BUSLOGIC is not set
+# CONFIG_SCSI_DMX3191D is not set
+# CONFIG_SCSI_DTC3280 is not set
+# CONFIG_SCSI_EATA is not set
+# CONFIG_SCSI_EATA_PIO is not set
+# CONFIG_SCSI_FUTURE_DOMAIN is not set
+# CONFIG_SCSI_GDTH is not set
+# CONFIG_SCSI_GENERIC_NCR5380 is not set
+# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
+# CONFIG_SCSI_IPS is not set
+# CONFIG_SCSI_INITIO is not set
+# CONFIG_SCSI_INIA100 is not set
+# CONFIG_SCSI_NCR53C406A is not set
+# CONFIG_SCSI_SYM53C8XX_2 is not set
+# CONFIG_SCSI_IPR is not set
+# CONFIG_SCSI_PAS16 is not set
+# CONFIG_SCSI_PSI240I is not set
+# CONFIG_SCSI_QLOGIC_FAS is not set
+# CONFIG_SCSI_QLOGIC_ISP is not set
+# CONFIG_SCSI_QLOGIC_FC is not set
+# CONFIG_SCSI_QLOGIC_1280 is not set
+CONFIG_SCSI_QLA2XXX=y
+# CONFIG_SCSI_QLA21XX is not set
+# CONFIG_SCSI_QLA22XX is not set
+# CONFIG_SCSI_QLA2300 is not set
+# CONFIG_SCSI_QLA2322 is not set
+# CONFIG_SCSI_QLA6312 is not set
+# CONFIG_SCSI_QLA6322 is not set
+# CONFIG_SCSI_SYM53C416 is not set
+# CONFIG_SCSI_DC395x is not set
+# CONFIG_SCSI_DC390T is not set
+# CONFIG_SCSI_T128 is not set
+# CONFIG_SCSI_U14_34F is not set
+# CONFIG_SCSI_ULTRASTOR is not set
+# CONFIG_SCSI_NSP32 is not set
+# CONFIG_SCSI_DEBUG is not set
+
+#
+# Old CD-ROM drivers (not SCSI, not IDE)
+#
+# CONFIG_CD_NO_IDESCSI is not set
+
+#
+# Multi-device support (RAID and LVM)
+#
+# CONFIG_MD is not set
+
+#
+# Fusion MPT device support
+#
+# CONFIG_FUSION is not set
+
+#
+# IEEE 1394 (FireWire) support
+#
+# CONFIG_IEEE1394 is not set
+
+#
+# I2O device support
+#
+CONFIG_I2O=y
+CONFIG_I2O_CONFIG=y
+CONFIG_I2O_BLOCK=y
+# CONFIG_I2O_SCSI is not set
+CONFIG_I2O_PROC=y
+
+#
+# Networking support
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+# CONFIG_NETLINK_DEV is not set
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_IP_MULTIPLE_TABLES=y
+CONFIG_IP_ROUTE_FWMARK=y
+CONFIG_IP_ROUTE_MULTIPATH=y
+CONFIG_IP_ROUTE_VERBOSE=y
+# CONFIG_IP_PNP is not set
+CONFIG_NET_IPIP=y
+CONFIG_NET_IPGRE=y
+CONFIG_NET_IPGRE_BROADCAST=y
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
+CONFIG_ARPD=y
+CONFIG_SYN_COOKIES=y
+CONFIG_INET_AH=y
+CONFIG_INET_ESP=y
+CONFIG_INET_IPCOMP=y
+CONFIG_INET_TUNNEL=y
+CONFIG_IP_TCPDIAG=y
+CONFIG_IP_TCPDIAG_IPV6=y
+
+#
+# IP: Virtual Server Configuration
+#
+# CONFIG_IP_VS is not set
+CONFIG_IPV6=y
+CONFIG_IPV6_PRIVACY=y
+CONFIG_INET6_AH=y
+CONFIG_INET6_ESP=y
+CONFIG_INET6_IPCOMP=y
+CONFIG_INET6_TUNNEL=y
+CONFIG_IPV6_TUNNEL=y
+CONFIG_NETFILTER=y
+# CONFIG_NETFILTER_DEBUG is not set
+CONFIG_BRIDGE_NETFILTER=y
+
+#
+# IP: Netfilter Configuration
+#
+CONFIG_IP_NF_CONNTRACK=y
+CONFIG_IP_NF_CT_ACCT=y
+CONFIG_IP_NF_CONNTRACK_MARK=y
+# CONFIG_IP_NF_CT_PROTO_SCTP is not set
+CONFIG_IP_NF_FTP=y
+CONFIG_IP_NF_IRC=y
+CONFIG_IP_NF_TFTP=y
+# CONFIG_IP_NF_AMANDA is not set
+CONFIG_IP_NF_QUEUE=y
+CONFIG_IP_NF_IPTABLES=y
+CONFIG_IP_NF_MATCH_LIMIT=y
+CONFIG_IP_NF_MATCH_IPRANGE=y
+CONFIG_IP_NF_MATCH_MAC=y
+CONFIG_IP_NF_MATCH_PKTTYPE=y
+CONFIG_IP_NF_MATCH_MARK=y
+CONFIG_IP_NF_MATCH_MULTIPORT=y
+CONFIG_IP_NF_MATCH_TOS=y
+CONFIG_IP_NF_MATCH_RECENT=y
+CONFIG_IP_NF_MATCH_ECN=y
+CONFIG_IP_NF_MATCH_DSCP=y
+CONFIG_IP_NF_MATCH_AH_ESP=y
+CONFIG_IP_NF_MATCH_LENGTH=y
+CONFIG_IP_NF_MATCH_TTL=y
+CONFIG_IP_NF_MATCH_TCPMSS=y
+CONFIG_IP_NF_MATCH_HELPER=y
+CONFIG_IP_NF_MATCH_STATE=y
+CONFIG_IP_NF_MATCH_CONNTRACK=y
+CONFIG_IP_NF_MATCH_OWNER=y
+CONFIG_IP_NF_MATCH_PHYSDEV=y
+CONFIG_IP_NF_MATCH_ADDRTYPE=y
+CONFIG_IP_NF_MATCH_REALM=y
+# CONFIG_IP_NF_MATCH_SCTP is not set
+CONFIG_IP_NF_MATCH_COMMENT=y
+CONFIG_IP_NF_MATCH_CONNMARK=y
+CONFIG_IP_NF_MATCH_HASHLIMIT=y
+CONFIG_IP_NF_FILTER=y
+CONFIG_IP_NF_TARGET_REJECT=y
+CONFIG_IP_NF_TARGET_LOG=y
+CONFIG_IP_NF_TARGET_ULOG=y
+CONFIG_IP_NF_TARGET_TCPMSS=y
+CONFIG_IP_NF_NAT=y
+CONFIG_IP_NF_NAT_NEEDED=y
+CONFIG_IP_NF_TARGET_MASQUERADE=y
+CONFIG_IP_NF_TARGET_REDIRECT=y
+CONFIG_IP_NF_TARGET_NETMAP=y
+CONFIG_IP_NF_TARGET_SAME=y
+# CONFIG_IP_NF_NAT_LOCAL is not set
+# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
+CONFIG_IP_NF_NAT_IRC=y
+CONFIG_IP_NF_NAT_FTP=y
+CONFIG_IP_NF_NAT_TFTP=y
+CONFIG_IP_NF_MANGLE=y
+CONFIG_IP_NF_TARGET_TOS=y
+CONFIG_IP_NF_TARGET_ECN=y
+CONFIG_IP_NF_TARGET_DSCP=y
+CONFIG_IP_NF_TARGET_MARK=y
+CONFIG_IP_NF_TARGET_CLASSIFY=y
+CONFIG_IP_NF_TARGET_CONNMARK=y
+CONFIG_IP_NF_TARGET_CLUSTERIP=y
+CONFIG_IP_NF_RAW=y
+CONFIG_IP_NF_TARGET_NOTRACK=y
+CONFIG_IP_NF_ARPTABLES=y
+CONFIG_IP_NF_ARPFILTER=y
+CONFIG_IP_NF_ARP_MANGLE=y
+
+#
+# IPv6: Netfilter Configuration
+#
+CONFIG_IP6_NF_QUEUE=y
+CONFIG_IP6_NF_IPTABLES=y
+CONFIG_IP6_NF_MATCH_LIMIT=y
+CONFIG_IP6_NF_MATCH_MAC=y
+CONFIG_IP6_NF_MATCH_RT=y
+CONFIG_IP6_NF_MATCH_OPTS=y
+CONFIG_IP6_NF_MATCH_FRAG=y
+CONFIG_IP6_NF_MATCH_HL=y
+CONFIG_IP6_NF_MATCH_MULTIPORT=y
+CONFIG_IP6_NF_MATCH_OWNER=y
+CONFIG_IP6_NF_MATCH_MARK=y
+CONFIG_IP6_NF_MATCH_IPV6HEADER=y
+CONFIG_IP6_NF_MATCH_AHESP=y
+CONFIG_IP6_NF_MATCH_LENGTH=y
+CONFIG_IP6_NF_MATCH_EUI64=y
+CONFIG_IP6_NF_MATCH_PHYSDEV=y
+CONFIG_IP6_NF_FILTER=y
+CONFIG_IP6_NF_TARGET_LOG=y
+CONFIG_IP6_NF_MANGLE=y
+CONFIG_IP6_NF_TARGET_MARK=y
+CONFIG_IP6_NF_RAW=y
+
+#
+# Bridge: Netfilter Configuration
+#
+# CONFIG_BRIDGE_NF_EBTABLES is not set
+CONFIG_XFRM=y
+CONFIG_XFRM_USER=y
+
+#
+# SCTP Configuration (EXPERIMENTAL)
+#
+# CONFIG_IP_SCTP is not set
+CONFIG_ATM=y
+# CONFIG_ATM_CLIP is not set
+# CONFIG_ATM_LANE is not set
+# CONFIG_ATM_BR2684 is not set
+CONFIG_BRIDGE=y
+CONFIG_VLAN_8021Q=y
+# CONFIG_DECNET is not set
+CONFIG_LLC=y
+CONFIG_LLC2=y
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_NET_DIVERT is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+
+#
+# QoS and/or fair queueing
+#
+CONFIG_NET_SCHED=y
+CONFIG_NET_SCH_CLK_JIFFIES=y
+# CONFIG_NET_SCH_CLK_GETTIMEOFDAY is not set
+# CONFIG_NET_SCH_CLK_CPU is not set
+CONFIG_NET_SCH_CBQ=y
+CONFIG_NET_SCH_HTB=y
+CONFIG_NET_SCH_HFSC=y
+CONFIG_NET_SCH_ATM=y
+CONFIG_NET_SCH_PRIO=y
+CONFIG_NET_SCH_RED=y
+CONFIG_NET_SCH_SFQ=y
+CONFIG_NET_SCH_TEQL=y
+CONFIG_NET_SCH_TBF=y
+CONFIG_NET_SCH_GRED=y
+CONFIG_NET_SCH_DSMARK=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_NET_SCH_INGRESS=y
+CONFIG_NET_QOS=y
+CONFIG_NET_ESTIMATOR=y
+CONFIG_NET_CLS=y
+CONFIG_NET_CLS_TCINDEX=y
+CONFIG_NET_CLS_ROUTE4=y
+CONFIG_NET_CLS_ROUTE=y
+CONFIG_NET_CLS_FW=y
+CONFIG_NET_CLS_U32=y
+CONFIG_NET_CLS_EGP=y
+CONFIG_EGP_DEBUG=y
+CONFIG_NET_CLS_EGP_SIMPLE_CMP=y
+CONFIG_NET_CLS_EGP_NBYTE=y
+CONFIG_NET_CLS_EGP_KMP=y
+CONFIG_NET_CLS_EGP_REGEXP=y
+CONFIG_NET_CLS_EGP_CMD=y
+CONFIG_EGP_CMD_BACK_TTL=4096
+CONFIG_CLS_U32_PERF=y
+CONFIG_NET_CLS_IND=y
+CONFIG_NET_CLS_RSVP=y
+CONFIG_NET_CLS_RSVP6=y
+CONFIG_NET_CLS_ACT=y
+CONFIG_NET_ACT_POLICE=y
+CONFIG_NET_ACT_GACT=y
+CONFIG_GACT_PROB=y
+CONFIG_NET_ACT_MIRRED=y
+CONFIG_NET_ACT_IPT=y
+CONFIG_NET_ACT_PEDIT=y
+
+#
+# Network testing
+#
+CONFIG_NET_PKTGEN=y
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+CONFIG_NETDEVICES=y
+CONFIG_DUMMY=y
+# CONFIG_BONDING is not set
+# CONFIG_EQUALIZER is not set
+CONFIG_TUN=y
+# CONFIG_NET_SB1000 is not set
+
+#
+# ARCnet devices
+#
+# CONFIG_ARCNET is not set
+
+#
+# Ethernet (10 or 100Mbit)
+#
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_SUNGEM is not set
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_LANCE is not set
+# CONFIG_NET_VENDOR_SMC is not set
+# CONFIG_NET_VENDOR_RACAL is not set
+
+#
+# Tulip family network device support
+#
+# CONFIG_NET_TULIP is not set
+# CONFIG_AT1700 is not set
+# CONFIG_DEPCA is not set
+# CONFIG_HP100 is not set
+# CONFIG_NET_ISA is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_AMD8111_ETH is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_AC3200 is not set
+# CONFIG_APRICOT is not set
+# CONFIG_B44 is not set
+# CONFIG_FORCEDETH is not set
+# CONFIG_CS89x0 is not set
+# CONFIG_DGRS is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_E100 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_8139CP is not set
+CONFIG_8139TOO=y
+CONFIG_8139TOO_PIO=y
+# CONFIG_8139TOO_TUNE_TWISTER is not set
+# CONFIG_8139TOO_8129 is not set
+# CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_NET_POCKET is not set
+
+#
+# Ethernet (1000 Mbit)
+#
+# CONFIG_ACENIC is not set
+# CONFIG_DL2K is not set
+# CONFIG_E1000 is not set
+# CONFIG_NS83820 is not set
+# CONFIG_HAMACHI is not set
+# CONFIG_YELLOWFIN is not set
+# CONFIG_R8169 is not set
+# CONFIG_SK98LIN is not set
+# CONFIG_VIA_VELOCITY is not set
+# CONFIG_TIGON3 is not set
+
+#
+# Ethernet (10000 Mbit)
+#
+# CONFIG_IXGB is not set
+# CONFIG_S2IO is not set
+
+#
+# Token Ring devices
+#
+# CONFIG_TR is not set
+
+#
+# Wireless LAN (non-hamradio)
+#
+# CONFIG_NET_RADIO is not set
+
+#
+# Wan interfaces
+#
+# CONFIG_WAN is not set
+
+#
+# ATM drivers
+#
+# CONFIG_ATM_TCP is not set
+# CONFIG_ATM_LANAI is not set
+# CONFIG_ATM_ENI is not set
+# CONFIG_ATM_FIRESTREAM is not set
+# CONFIG_ATM_ZATM is not set
+# CONFIG_ATM_NICSTAR is not set
+# CONFIG_ATM_IDT77252 is not set
+# CONFIG_ATM_AMBASSADOR is not set
+# CONFIG_ATM_HORIZON is not set
+# CONFIG_ATM_IA is not set
+# CONFIG_ATM_FORE200E_MAYBE is not set
+# CONFIG_ATM_HE is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+CONFIG_PPP=y
+CONFIG_PPP_MULTILINK=y
+CONFIG_PPP_FILTER=y
+# CONFIG_PPP_ASYNC is not set
+# CONFIG_PPP_SYNC_TTY is not set
+# CONFIG_PPP_DEFLATE is not set
+CONFIG_PPP_BSDCOMP=y
+# CONFIG_PPPOE is not set
+# CONFIG_PPPOATM is not set
+# CONFIG_SLIP is not set
+# CONFIG_NET_FC is not set
+CONFIG_SHAPER=y
+# CONFIG_NETCONSOLE is not set
+
+#
+# ISDN subsystem
+#
+# CONFIG_ISDN is not set
+
+#
+# Telephony Support
+#
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+CONFIG_INPUT_MOUSEDEV_PSAUX=y
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_TSDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input I/O drivers
+#
+# CONFIG_GAMEPORT is not set
+CONFIG_SOUND_GAMEPORT=y
+CONFIG_SERIO=y
+CONFIG_SERIO_I8042=y
+# CONFIG_SERIO_SERPORT is not set
+# CONFIG_SERIO_CT82C710 is not set
+# CONFIG_SERIO_PCIPS2 is not set
+# CONFIG_SERIO_RAW is not set
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+CONFIG_KEYBOARD_ATKBD=y
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+CONFIG_INPUT_MOUSE=y
+CONFIG_MOUSE_PS2=y
+# CONFIG_MOUSE_SERIAL is not set
+# CONFIG_MOUSE_INPORT is not set
+# CONFIG_MOUSE_LOGIBM is not set
+# CONFIG_MOUSE_PC110PAD is not set
+# CONFIG_MOUSE_VSXXXAA is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+# CONFIG_SERIAL_8250_CONSOLE is not set
+# CONFIG_SERIAL_8250_ACPI is not set
+CONFIG_SERIAL_8250_NR_UARTS=4
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+
+#
+# IPMI
+#
+# CONFIG_IPMI_HANDLER is not set
+
+#
+# Watchdog Cards
+#
+# CONFIG_WATCHDOG is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_RTC is not set
+# CONFIG_GEN_RTC is not set
+# CONFIG_DTLK is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+# CONFIG_SONYPI is not set
+
+#
+# Ftape, the floppy tape device driver
+#
+# CONFIG_AGP is not set
+# CONFIG_DRM is not set
+# CONFIG_MWAVE is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_HPET is not set
+# CONFIG_HANGCHECK_TIMER is not set
+
+#
+# I2C support
+#
+CONFIG_I2C=y
+CONFIG_I2C_CHARDEV=y
+
+#
+# I2C Algorithms
+#
+CONFIG_I2C_ALGOBIT=y
+# CONFIG_I2C_ALGOPCF is not set
+# CONFIG_I2C_ALGOPCA is not set
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+# CONFIG_I2C_I801 is not set
+# CONFIG_I2C_I810 is not set
+# CONFIG_I2C_ISA is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_SCx200_ACB is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+CONFIG_I2C_SIS96X=y
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_ISA is not set
+
+#
+# Hardware Sensors Chip support
+#
+CONFIG_I2C_SENSOR=y
+# CONFIG_SENSORS_ADM1021 is not set
+# CONFIG_SENSORS_ADM1025 is not set
+# CONFIG_SENSORS_ADM1031 is not set
+# CONFIG_SENSORS_ASB100 is not set
+# CONFIG_SENSORS_DS1621 is not set
+# CONFIG_SENSORS_FSCHER is not set
+# CONFIG_SENSORS_GL518SM is not set
+# CONFIG_SENSORS_IT87 is not set
+# CONFIG_SENSORS_LM63 is not set
+# CONFIG_SENSORS_LM75 is not set
+# CONFIG_SENSORS_LM77 is not set
+# CONFIG_SENSORS_LM78 is not set
+# CONFIG_SENSORS_LM80 is not set
+# CONFIG_SENSORS_LM83 is not set
+# CONFIG_SENSORS_LM85 is not set
+# CONFIG_SENSORS_LM87 is not set
+# CONFIG_SENSORS_LM90 is not set
+# CONFIG_SENSORS_MAX1619 is not set
+# CONFIG_SENSORS_PC87360 is not set
+# CONFIG_SENSORS_SMSC47M1 is not set
+# CONFIG_SENSORS_VIA686A is not set
+# CONFIG_SENSORS_W83781D is not set
+# CONFIG_SENSORS_W83L785TS is not set
+# CONFIG_SENSORS_W83627HF is not set
+
+#
+# Other I2C Chip support
+#
+CONFIG_SENSORS_EEPROM=y
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_RTC8564 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+
+#
+# Dallas's 1-wire bus
+#
+# CONFIG_W1 is not set
+
+#
+# Misc devices
+#
+# CONFIG_IBM_ASM is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+
+#
+# Digital Video Broadcasting Devices
+#
+# CONFIG_DVB is not set
+
+#
+# Graphics support
+#
+# CONFIG_FB is not set
+# CONFIG_VIDEO_SELECT is not set
+
+#
+# Console display driver support
+#
+CONFIG_VGA_CONSOLE=y
+# CONFIG_MDA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+CONFIG_SOUND=y
+
+#
+# Advanced Linux Sound Architecture
+#
+CONFIG_SND=y
+CONFIG_SND_TIMER=y
+CONFIG_SND_PCM=y
+CONFIG_SND_HWDEP=y
+CONFIG_SND_RAWMIDI=y
+CONFIG_SND_SEQUENCER=y
+# CONFIG_SND_SEQ_DUMMY is not set
+CONFIG_SND_OSSEMUL=y
+CONFIG_SND_MIXER_OSS=y
+CONFIG_SND_PCM_OSS=y
+CONFIG_SND_SEQUENCER_OSS=y
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+
+#
+# Generic devices
+#
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_VIRMIDI is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# ISA devices
+#
+# CONFIG_SND_AD1848 is not set
+# CONFIG_SND_CS4231 is not set
+# CONFIG_SND_CS4232 is not set
+# CONFIG_SND_CS4236 is not set
+# CONFIG_SND_ES1688 is not set
+# CONFIG_SND_ES18XX is not set
+# CONFIG_SND_GUSCLASSIC is not set
+# CONFIG_SND_GUSEXTREME is not set
+# CONFIG_SND_GUSMAX is not set
+# CONFIG_SND_INTERWAVE is not set
+# CONFIG_SND_INTERWAVE_STB is not set
+# CONFIG_SND_OPTI92X_AD1848 is not set
+# CONFIG_SND_OPTI92X_CS4231 is not set
+# CONFIG_SND_OPTI93X is not set
+# CONFIG_SND_SB8 is not set
+# CONFIG_SND_SB16 is not set
+# CONFIG_SND_SBAWE is not set
+# CONFIG_SND_WAVEFRONT is not set
+# CONFIG_SND_CMI8330 is not set
+# CONFIG_SND_OPL3SA2 is not set
+# CONFIG_SND_SGALAXY is not set
+# CONFIG_SND_SSCAPE is not set
+
+#
+# PCI devices
+#
+CONFIG_SND_AC97_CODEC=y
+# CONFIG_SND_ALI5451 is not set
+# CONFIG_SND_ATIIXP is not set
+# CONFIG_SND_ATIIXP_MODEM is not set
+# CONFIG_SND_AU8810 is not set
+# CONFIG_SND_AU8820 is not set
+# CONFIG_SND_AU8830 is not set
+# CONFIG_SND_AZT3328 is not set
+# CONFIG_SND_BT87X is not set
+# CONFIG_SND_CS46XX is not set
+# CONFIG_SND_CS4281 is not set
+CONFIG_SND_EMU10K1=y
+# CONFIG_SND_KORG1212 is not set
+# CONFIG_SND_MIXART is not set
+# CONFIG_SND_NM256 is not set
+# CONFIG_SND_RME32 is not set
+# CONFIG_SND_RME96 is not set
+# CONFIG_SND_RME9652 is not set
+# CONFIG_SND_HDSP is not set
+# CONFIG_SND_TRIDENT is not set
+# CONFIG_SND_YMFPCI is not set
+# CONFIG_SND_ALS4000 is not set
+# CONFIG_SND_CMIPCI is not set
+# CONFIG_SND_ENS1370 is not set
+# CONFIG_SND_ENS1371 is not set
+# CONFIG_SND_ES1938 is not set
+# CONFIG_SND_ES1968 is not set
+# CONFIG_SND_MAESTRO3 is not set
+# CONFIG_SND_FM801 is not set
+# CONFIG_SND_ICE1712 is not set
+# CONFIG_SND_ICE1724 is not set
+# CONFIG_SND_INTEL8X0 is not set
+# CONFIG_SND_INTEL8X0M is not set
+# CONFIG_SND_SONICVIBES is not set
+# CONFIG_SND_VIA82XX is not set
+# CONFIG_SND_VX222 is not set
+
+#
+# USB devices
+#
+# CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_USX2Y is not set
+
+#
+# Open Sound System
+#
+# CONFIG_SOUND_PRIME is not set
+
+#
+# USB support
+#
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+# CONFIG_USB_BANDWIDTH is not set
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_OTG is not set
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+
+#
+# USB Host Controller Drivers
+#
+CONFIG_USB_EHCI_HCD=y
+# CONFIG_USB_EHCI_SPLIT_ISO is not set
+# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
+# CONFIG_USB_OHCI_HCD is not set
+CONFIG_USB_UHCI_HCD=y
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_AUDIO is not set
+# CONFIG_USB_BLUETOOTH_TTY is not set
+# CONFIG_USB_MIDI is not set
+# CONFIG_USB_ACM is not set
+CONFIG_USB_PRINTER=y
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_RW_DETECT is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_HP8200e is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+CONFIG_USB_HIDINPUT=y
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+# CONFIG_USB_AIPTEK is not set
+# CONFIG_USB_WACOM is not set
+# CONFIG_USB_KBTAB is not set
+# CONFIG_USB_POWERMATE is not set
+# CONFIG_USB_MTOUCH is not set
+CONFIG_USB_EGALAX=m
+# CONFIG_USB_XPAD is not set
+# CONFIG_USB_ATI_REMOTE is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_HPUSBSCSI is not set
+
+#
+# USB Multimedia devices
+#
+# CONFIG_USB_DABUSB is not set
+
+#
+# Video4Linux support is needed for USB Multimedia device support
+#
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_TIGL is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_LED is not set
+CONFIG_USB_CYTHERM=m
+# CONFIG_USB_PHIDGETKIT is not set
+CONFIG_USB_PHIDGETSERVO=m
+# CONFIG_USB_TEST is not set
+
+#
+# USB ATM/DSL drivers
+#
+# CONFIG_USB_ATM is not set
+# CONFIG_USB_SPEEDTOUCH is not set
+
+#
+# USB Gadget Support
+#
+# CONFIG_USB_GADGET is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+CONFIG_EXT3_FS=y
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+# CONFIG_EXT3_FS_SECURITY is not set
+CONFIG_JBD=y
+# CONFIG_JBD_DEBUG is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=y
+
+#
+# CD-ROM/DVD Filesystems
+#
+CONFIG_ISO9660_FS=y
+CONFIG_JOLIET=y
+# CONFIG_ZISOFS is not set
+CONFIG_UDF_FS=y
+CONFIG_UDF_NLS=y
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_KCORE=y
+CONFIG_SYSFS=y
+# CONFIG_DEVFS_FS is not set
+# CONFIG_DEVPTS_FS_XATTR is not set
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_XATTR is not set
+# CONFIG_HUGETLBFS is not set
+# CONFIG_HUGETLB_PAGE is not set
+CONFIG_RAMFS=y
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Network File Systems
+#
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFS_DIRECTIO is not set
+CONFIG_NFSD=y
+# CONFIG_NFSD_V3 is not set
+CONFIG_NFSD_TCP=y
+CONFIG_LOCKD=y
+CONFIG_EXPORTFS=y
+CONFIG_SUNRPC=y
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+
+#
+# Native Language Support
+#
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Profiling support
+#
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+
+#
+# Kernel hacking
+#
+CONFIG_DEBUG_KERNEL=y
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_SCHEDSTATS is not set
+CONFIG_DEBUG_SLAB=y
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_KOBJECT is not set
+# CONFIG_DEBUG_INFO is not set
+CONFIG_FRAME_POINTER=y
+CONFIG_EARLY_PRINTK=y
+# CONFIG_DEBUG_STACKOVERFLOW is not set
+# CONFIG_KPROBES is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
+# CONFIG_DEBUG_PAGEALLOC is not set
+# CONFIG_4KSTACKS is not set
+CONFIG_X86_FIND_SMP_CONFIG=y
+CONFIG_X86_MPPARSE=y
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+CONFIG_SECURITY=y
+CONFIG_SECURITY_NETWORK=y
+CONFIG_SECURITY_CAPABILITIES=m
+CONFIG_SECURITY_ROOTPLUG=m
+# CONFIG_SECURITY_SECLVL is not set
+CONFIG_SECURITY_SELINUX=y
+# CONFIG_SECURITY_SELINUX_BOOTPARAM is not set
+CONFIG_SECURITY_SELINUX_DISABLE=y
+CONFIG_SECURITY_SELINUX_DEVELOP=y
+# CONFIG_SECURITY_SELINUX_MLS is not set
+
+#
+# Cryptographic options
+#
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_HMAC=y
+CONFIG_CRYPTO_NULL=y
+CONFIG_CRYPTO_MD4=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_SHA1=y
+CONFIG_CRYPTO_SHA256=y
+CONFIG_CRYPTO_SHA512=y
+CONFIG_CRYPTO_WP512=y
+CONFIG_CRYPTO_DES=y
+CONFIG_CRYPTO_BLOWFISH=y
+CONFIG_CRYPTO_TWOFISH=y
+CONFIG_CRYPTO_SERPENT=y
+CONFIG_CRYPTO_AES_586=y
+CONFIG_CRYPTO_CAST5=y
+CONFIG_CRYPTO_CAST6=y
+CONFIG_CRYPTO_TEA=y
+CONFIG_CRYPTO_ARC4=y
+CONFIG_CRYPTO_KHAZAD=y
+# CONFIG_CRYPTO_ANUBIS is not set
+CONFIG_CRYPTO_DEFLATE=y
+CONFIG_CRYPTO_MICHAEL_MIC=y
+CONFIG_CRYPTO_CRC32C=y
+CONFIG_CRYPTO_TEST=y
+
+#
+# Library routines
+#
+# CONFIG_CRC_CCITT is not set
+CONFIG_CRC32=y
+CONFIG_LIBCRC32C=y
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_X86_SMP=y
+CONFIG_X86_HT=y
+CONFIG_X86_BIOS_REBOOT=y
+CONFIG_X86_TRAMPOLINE=y
+CONFIG_PC=y
diff --git a/testsuite/iproute2/Makefile b/testsuite/iproute2/Makefile
index f894605..ba128aa 100644
--- a/testsuite/iproute2/Makefile
+++ b/testsuite/iproute2/Makefile
@@ -1,10 +1,9 @@
-# SPDX-License-Identifier: GPL-2.0
 SUBDIRS := $(filter-out Makefile,$(wildcard *))
 .PHONY: all configure clean distclean show $(SUBDIRS)
 
 all: configure
 	@for dir in $(SUBDIRS); do \
-		$(MAKE) -C $$dir; \
+		echo "Entering $$dir" && cd $$dir && $(MAKE) && cd ..; \
 	done
 
 link:
@@ -19,12 +18,12 @@
 
 clean: link
 	@for dir in $(SUBDIRS); do \
-		$(MAKE) -C $$dir clean; \
+		echo "Entering $$dir" && cd $$dir && $(MAKE) clean && cd ..; \
 	done
 
 distclean: clean
 	@for dir in $(SUBDIRS); do \
-		$(MAKE) -C $$dir distclean; \
+		echo "Entering $$dir" && cd $$dir && $(MAKE) distclean && cd ..; \
 	done
 
 show: link
diff --git a/testsuite/lib/generic.sh b/testsuite/lib/generic.sh
index f92260f..b7de704 100644
--- a/testsuite/lib/generic.sh
+++ b/testsuite/lib/generic.sh
@@ -26,17 +26,16 @@
     exit 127
 }
 
-__ts_cmd()
+ts_tc()
 {
-	CMD=$1; shift
 	SCRIPT=$1; shift
 	DESC=$1; shift
 
-	$CMD $@ 2> $STD_ERR > $STD_OUT
+	$TC $@ 2> $STD_ERR > $STD_OUT
 
 	if [ -s $STD_ERR ]; then
 		ts_err "${SCRIPT}: ${DESC} failed:"
-		ts_err "command: $CMD $@"
+		ts_err "command: $TC $@"
 		ts_err "stderr output:"
 		ts_err_cat $STD_ERR
 		if [ -s $STD_OUT ]; then
@@ -51,19 +50,29 @@
 	fi
 }
 
-ts_tc()
-{
-	__ts_cmd "$TC" "$@"
-}
-
 ts_ip()
 {
-	__ts_cmd "$IP" "$@"
-}
+	SCRIPT=$1; shift
+	DESC=$1; shift
 
-ts_ss()
-{
-	__ts_cmd "$SS" "$@"
+	$IP $@ 2> $STD_ERR > $STD_OUT
+        RET=$?
+
+	if [ -s $STD_ERR ] || [ "$RET" != "0" ]; then
+		ts_err "${SCRIPT}: ${DESC} failed:"
+		ts_err "command: $IP $@"
+		ts_err "stderr output:"
+		ts_err_cat $STD_ERR
+		if [ -s $STD_OUT ]; then
+			ts_err "stdout output:"
+			ts_err_cat $STD_OUT
+		fi
+	elif [ -s $STD_OUT ]; then
+		echo "${SCRIPT}: ${DESC} succeeded with output:"
+		cat $STD_OUT
+	else
+		echo "${SCRIPT}: ${DESC} succeeded"
+	fi
 }
 
 ts_qdisc_available()
@@ -78,11 +87,7 @@
 
 rand_dev()
 {
-    rnd=""
-    while [ ${#rnd} -ne 6 ]; do
-        rnd="$(head -c 250 /dev/urandom | tr -dc '[:alpha:]' | head -c 6)"
-    done
-    echo "dev-$rnd"
+    echo "dev-$(tr -dc "[:alpha:]" < /dev/urandom | head -c 6)"
 }
 
 pr_failed()
diff --git a/testsuite/tests/ip/link/add_type_xfrm.t b/testsuite/tests/ip/link/add_type_xfrm.t
deleted file mode 100755
index 78ce28e..0000000
--- a/testsuite/tests/ip/link/add_type_xfrm.t
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-. lib/generic.sh
-
-ts_log "[Testing Add XFRM Interface, With IF-ID]"
-
-PHYS_DEV="lo"
-NEW_DEV="$(rand_dev)"
-IF_ID="0xf"
-
-ts_ip "$0" "Add $NEW_DEV xfrm interface"    link add dev $NEW_DEV type xfrm dev $PHYS_DEV if_id $IF_ID
-
-ts_ip "$0" "Show $NEW_DEV xfrm interface"   -d link show dev $NEW_DEV
-test_on "$NEW_DEV"
-test_on "if_id $IF_ID"
-
-ts_ip "$0" "Del $NEW_DEV xfrm interface"   link del dev $NEW_DEV
-
-
-ts_log "[Testing Add XFRM Interface, No IF-ID]"
-
-PHYS_DEV="lo"
-NEW_DEV="$(rand_dev)"
-IF_ID="0xf"
-
-ts_ip "$0" "Add $NEW_DEV xfrm interface"    link add dev $NEW_DEV type xfrm dev $PHYS_DEV
-
-ts_ip "$0" "Show $NEW_DEV xfrm interface"   -d link show dev $NEW_DEV
-test_on "$NEW_DEV"
-test_on_not "if_id $IF_ID"
-
-ts_ip "$0" "Del $NEW_DEV xfrm interface"   link del dev $NEW_DEV
diff --git a/testsuite/tests/ip/link/dev_wo_vf_rate.nl b/testsuite/tests/ip/link/dev_wo_vf_rate.nl
new file mode 100644
index 0000000..40fa87f
--- /dev/null
+++ b/testsuite/tests/ip/link/dev_wo_vf_rate.nl
Binary files differ
diff --git a/testsuite/tests/ip/link/new_link.t b/testsuite/tests/ip/link/new_link.t
index c17650a..699adbc 100755
--- a/testsuite/tests/ip/link/new_link.t
+++ b/testsuite/tests/ip/link/new_link.t
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. lib/generic.sh
+source lib/generic.sh
 
 ts_log "[Testing add/del virtual links]"
 
diff --git a/testsuite/tests/ip/link/show_dev_wo_vf_rate.t b/testsuite/tests/ip/link/show_dev_wo_vf_rate.t
index 5b3c004..a600ba6 100755
--- a/testsuite/tests/ip/link/show_dev_wo_vf_rate.t
+++ b/testsuite/tests/ip/link/show_dev_wo_vf_rate.t
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. lib/generic.sh
+source lib/generic.sh
 
 NL_FILE="tests/ip/link/dev_wo_vf_rate.nl"
 ts_ip "$0" "Show VF devices w/o VF rate info" -d monitor file $NL_FILE
diff --git a/testsuite/tests/ip/netns/set_nsid.t b/testsuite/tests/ip/netns/set_nsid.t
deleted file mode 100755
index 8f8c779..0000000
--- a/testsuite/tests/ip/netns/set_nsid.t
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-. lib/generic.sh
-
-ts_log "[Testing netns nsid]"
-
-NS=testnsid
-NSID=99
-
-ts_ip "$0" "Add new netns $NS" netns add $NS
-ts_ip "$0" "Set $NS nsid to $NSID" netns set $NS $NSID
-
-ts_ip "$0" "List netns" netns list
-test_on "$NS \(id: $NSID\)"
-
-ts_ip "$0" "List netns without explicit list or show" netns
-test_on "$NS \(id: $NSID\)"
-
-ts_ip "$0" "List nsid" netns list-id
-test_on "$NSID \(iproute2 netns name: $NS\)"
-
-ts_ip "$0" "Delete netns $NS" netns del $NS
diff --git a/testsuite/tests/ip/netns/set_nsid_batch.t b/testsuite/tests/ip/netns/set_nsid_batch.t
deleted file mode 100755
index 196fd4b..0000000
--- a/testsuite/tests/ip/netns/set_nsid_batch.t
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-
-. lib/generic.sh
-
-ts_log "[Testing netns nsid in batch mode]"
-
-NS=testnsid
-NSID=99
-BATCHFILE=`mktemp`
-
-echo "netns add $NS" >> $BATCHFILE
-echo "netns set $NS $NSID" >> $BATCHFILE
-echo "netns list-id" >> $BATCHFILE
-ts_ip "$0" "Add ns, set nsid and list in batch mode" -b $BATCHFILE
-test_on "nsid $NSID \(iproute2 netns name: $NS\)"
-rm -f $BATCHFILE
-
-ts_ip "$0" "Delete netns $NS" netns del $NS
diff --git a/testsuite/tests/ip/route/add_default_route.t b/testsuite/tests/ip/route/add_default_route.t
index ded4edc..e5ea647 100755
--- a/testsuite/tests/ip/route/add_default_route.t
+++ b/testsuite/tests/ip/route/add_default_route.t
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. lib/generic.sh
+source lib/generic.sh
 
 ts_log "[Testing add default route]"
 
@@ -31,5 +31,3 @@
 ts_ip "$0" "Show IPv6 default route" -6 route show default
 test_on "default via dead:beef::2 dev $DEV"
 test_lines_count 1
-
-ts_ip "$0" "Del $DEV dummy interface"  link del dev $DEV
diff --git a/testsuite/tests/ip/tunnel/add_tunnel.t b/testsuite/tests/ip/tunnel/add_tunnel.t
index 65db431..18f6e37 100755
--- a/testsuite/tests/ip/tunnel/add_tunnel.t
+++ b/testsuite/tests/ip/tunnel/add_tunnel.t
@@ -1,18 +1,8 @@
 #!/bin/sh
 
-. lib/generic.sh
+source lib/generic.sh
 
 TUNNEL_NAME="tunnel_test_ip"
-KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre"
-
-# unload kernel modules to remove dummy interfaces only if they were not in use beforehand
-kmods_remove=
-# note that checkbashism reports command -v, but dash supports it and it's POSIX 2008 compliant
-if command -v lsmod >/dev/null 2>&1 && command -v rmmod >/dev/null 2>&1; then
-    for i in $KMODS; do
-        lsmod | grep -q "^$i" || kmods_remove="$kmods_remove $i";
-    done
-fi
 
 ts_log "[Testing add/del tunnels]"
 
@@ -22,6 +12,3 @@
 ts_ip "$0" "Add GRE tunnel over IPv6" tunnel add name $TUNNEL_NAME mode ip6gre local dead:beef::1 remote dead:beef::2
 ts_ip "$0" "Del GRE tunnel over IPv6" tunnel del $TUNNEL_NAME
 
-for mod in $kmods_remove; do
-    sudo rmmod "$mod"
-done
diff --git a/testsuite/tests/ss/ss1.dump b/testsuite/tests/ss/ss1.dump
deleted file mode 100644
index 9c27323..0000000
--- a/testsuite/tests/ss/ss1.dump
+++ /dev/null
Binary files differ
diff --git a/testsuite/tests/ss/ssfilter.t b/testsuite/tests/ss/ssfilter.t
deleted file mode 100755
index 3091054..0000000
--- a/testsuite/tests/ss/ssfilter.t
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-
-. lib/generic.sh
-
-# % ./misc/ss -Htna
-# LISTEN  0    128    0.0.0.0:22       0.0.0.0:*
-# ESTAB   0    0     10.0.0.1:22      10.0.0.1:36266
-# ESTAB   0    0     10.0.0.1:36266   10.0.0.1:22
-# ESTAB   0    0     10.0.0.1:22      10.0.0.2:50312
-export TCPDIAG_FILE="$(dirname $0)/ss1.dump"
-
-ts_log "[Testing ssfilter]"
-
-ts_ss "$0" "Match dport = 22" -Htna dport = 22
-test_on "ESTAB     0           0                10.0.0.1:36266           10.0.0.1:22"
-
-ts_ss "$0" "Match dport 22" -Htna dport 22
-test_on "ESTAB     0           0                10.0.0.1:36266           10.0.0.1:22"
-
-ts_ss "$0" "Match (dport)" -Htna '( dport = 22 )'
-test_on "ESTAB     0           0                10.0.0.1:36266           10.0.0.1:22"
-
-ts_ss "$0" "Match src = 0.0.0.0" -Htna src = 0.0.0.0
-test_on "LISTEN      0           128               0.0.0.0:22             0.0.0.0:*"
-
-ts_ss "$0" "Match src 0.0.0.0" -Htna src 0.0.0.0
-test_on "LISTEN      0           128               0.0.0.0:22             0.0.0.0:*"
-
-ts_ss "$0" "Match src sport" -Htna src 0.0.0.0 sport = 22
-test_on "LISTEN      0           128               0.0.0.0:22             0.0.0.0:*"
-
-ts_ss "$0" "Match src and sport" -Htna src 0.0.0.0 and sport = 22
-test_on "LISTEN      0           128               0.0.0.0:22             0.0.0.0:*"
-
-ts_ss "$0" "Match src and sport and dport" -Htna src 10.0.0.1 and sport = 22 and dport = 50312
-test_on "ESTAB     0           0                10.0.0.1:22           10.0.0.2:50312"
-
-ts_ss "$0" "Match src and sport and (dport)" -Htna 'src 10.0.0.1 and sport = 22 and ( dport = 50312 )'
-test_on "ESTAB     0           0                10.0.0.1:22           10.0.0.2:50312"
-
-ts_ss "$0" "Match src and (sport and dport)" -Htna 'src 10.0.0.1 and ( sport = 22 and dport = 50312 )'
-test_on "ESTAB     0           0                10.0.0.1:22           10.0.0.2:50312"
-
-ts_ss "$0" "Match (src and sport) and dport" -Htna '( src 10.0.0.1 and sport = 22 ) and dport = 50312'
-test_on "ESTAB     0           0                10.0.0.1:22           10.0.0.2:50312"
-
-ts_ss "$0" "Match (src or src) and dst" -Htna '( src 0.0.0.0 or src 10.0.0.1 ) and dst 10.0.0.2'
-test_on "ESTAB     0           0                10.0.0.1:22           10.0.0.2:50312"
diff --git a/testsuite/tests/tc/batch.t b/testsuite/tests/tc/batch.t
deleted file mode 100755
index 50e7ba3..0000000
--- a/testsuite/tests/tc/batch.t
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-. lib/generic.sh
-
-DEV="$(rand_dev)"
-ts_ip "$0" "Add $DEV dummy interface" link add dev $DEV type dummy
-ts_ip "$0" "Enable $DEV" link set $DEV up
-ts_tc "$0" "Add ingress qdisc" qdisc add dev $DEV clsact
-
-TMP="$(mktemp)"
-echo filt add dev $DEV ingress pref 1000 matchall action pass >> "$TMP"
-echo filt add dev $DEV ingress pref 1000 matchall action pass >> "$TMP"
-
-"$TC" -b "$TMP" 2> $STD_ERR > $STD_OUT
-if [ $? -eq 0 ]; then
-	ts_err "$0: batch passed when it should have failed"
-elif [ ! -s $STD_ERR ]; then
-	ts_err "$0: batch produced no error message"
-else
-	echo "$0: batch failed, as expected"
-fi
-
-rm "$TMP"
-ts_ip "$0" "Del $DEV dummy interface" link del dev $DEV
diff --git a/testsuite/tests/tc/cls-testbed.t b/testsuite/tests/tc/cls-testbed.t
new file mode 100755
index 0000000..2afc26f
--- /dev/null
+++ b/testsuite/tests/tc/cls-testbed.t
@@ -0,0 +1,73 @@
+#!/bin/bash
+# vim: ft=sh
+
+source lib/generic.sh
+
+QDISCS="cbq htb dsmark"
+
+if [ ! -d tests/cls ]; then
+    ts_log "tests/cls folder does not exist"
+    ts_skip
+fi
+
+for q in ${QDISCS}; do
+	ts_log "Preparing classifier testbed with qdisc $q"
+
+	for c in tests/cls/*.c; do
+
+		case "$q" in
+		cbq)
+			ts_tc "cls-testbed" "cbq root qdisc creation" \
+				qdisc add dev $DEV root handle 10:0 \
+				cbq bandwidth 100Mbit avpkt 1400 mpu 64
+			ts_tc "cls-testbed" "cbq root class creation" \
+				class add dev $DEV parent 10:0  classid 10:12 \
+				cbq bandwidth 100mbit rate 100mbit allot 1514 prio 3 \
+				maxburst 1 avpkt  500 bounded
+			;;
+		htb)
+			ts_qdisc_available "htb"
+			if [ $? -eq 0 ]; then
+				ts_log "cls-testbed: HTB is unsupported by $TC, skipping"
+				continue;
+			fi
+			ts_tc "cls-testbed" "htb root qdisc creation" \
+				qdisc add dev $DEV root handle 10:0 htb
+			ts_tc "cls-testbed" "htb root class creation" \
+				class add dev $DEV parent 10:0 classid 10:12 \
+				htb rate 100Mbit quantum 1514
+			;;
+		dsmark)
+			ts_qdisc_available "dsmark"
+			if [ $? -eq 0 ]; then
+				ts_log "cls-testbed: dsmark is unsupported by $TC, skipping"
+				continue;
+			fi
+			ts_tc "cls-testbed" "dsmark root qdisc creation" \
+				qdisc add dev $DEV root handle 20:0 \
+				dsmark indices 64 default_index 1 set_tc_index
+			ts_tc "cls-testbed" "dsmark class creation" \
+				class change dev $DEV parent 20:0 classid 20:12 \
+				dsmark mask 0xff value 2
+			ts_tc "cls-testbed" "prio inner qdisc creation" \
+				qdisc add dev $DEV parent 20:0 handle 10:0 prio
+			;;
+		*)
+			ts_err "cls-testbed: no testbed configuration found for qdisc $q"
+			continue
+			;;
+		esac
+
+		ts_tc "cls-testbed" "tree listing" qdisc list dev eth0
+		ts_tc "cls-testbed" "tree class listing" class list dev eth0
+		ts_log "cls-testbed: starting classifier test $c"
+		$c 
+
+		case "$q" in
+		*)
+			ts_tc "cls-testbed" "generic qdisc tree deletion" \
+				qdisc del dev $DEV root
+			;;
+		esac
+	done
+done
diff --git a/testsuite/tests/tc/dsmark.t b/testsuite/tests/tc/dsmark.t
index 3f1d5ef..6934165 100755
--- a/testsuite/tests/tc/dsmark.t
+++ b/testsuite/tests/tc/dsmark.t
@@ -1,7 +1,7 @@
-#!/bin/sh
+#!/bin/bash
 # vim: ft=sh
 
-. lib/generic.sh
+source lib/generic.sh
 
 ts_qdisc_available "dsmark"
 if [ $? -eq 0 ]; then
diff --git a/testsuite/tests/tc/pedit.t b/testsuite/tests/tc/pedit.t
deleted file mode 100755
index 8d531a0..0000000
--- a/testsuite/tests/tc/pedit.t
+++ /dev/null
@@ -1,217 +0,0 @@
-#!/bin/sh
-
-. lib/generic.sh
-
-DEV="$(rand_dev)"
-ts_ip "$0" "Add $DEV dummy interface" link add dev $DEV type dummy
-ts_ip "$0" "Enable $DEV" link set $DEV up
-ts_tc "pedit" "Add ingress qdisc" qdisc add dev $DEV ingress
-
-
-do_pedit() {
-	ts_tc "pedit" "Drop ingress qdisc" \
-		qdisc del dev $DEV ingress
-	ts_tc "pedit" "Add ingress qdisc" \
-		qdisc add dev $DEV ingress
-	ts_tc "pedit" "Add pedit action $*" \
-		filter add dev $DEV parent ffff: \
-		u32 match u32 0 0 \
-		action pedit munge $@
-	ts_tc "pedit" "Show ingress filters" \
-		filter show dev $DEV parent ffff:
-}
-
-do_pedit offset 12 u32 set 0x12345678
-test_on "key #0  at 12: val 12345678 mask 00000000"
-do_pedit offset 12 u16 set 0x1234
-test_on "key #0  at 12: val 12340000 mask 0000ffff"
-do_pedit offset 14 u16 set 0x1234
-test_on "key #0  at 12: val 00001234 mask ffff0000"
-do_pedit offset 12 u8 set 0x23
-test_on "key #0  at 12: val 23000000 mask 00ffffff"
-do_pedit offset 13 u8 set 0x23
-test_on "key #0  at 12: val 00230000 mask ff00ffff"
-do_pedit offset 14 u8 set 0x23
-test_on "key #0  at 12: val 00002300 mask ffff00ff"
-do_pedit offset 15 u8 set 0x23
-test_on "key #0  at 12: val 00000023 mask ffffff00"
-
-do_pedit offset 13 u8 invert
-test_on "key #0  at 12: val 00ff0000 mask ffffffff"
-do_pedit offset 13 u8 clear
-test_on "key #0  at 12: val 00000000 mask ff00ffff"
-do_pedit offset 13 u8 preserve
-test_on "key #0  at 12: val 00000000 mask ffffffff"
-
-# the following set of tests has been auto-generated by running this little
-# shell script:
-#
-# do_it() {
-#	echo "do_pedit $@"
-#	tc qd del dev veth0 ingress >/dev/null 2>&1
-#	tc qd add dev veth0 ingress >/dev/null 2>&1
-#	tc filter add dev veth0 parent ffff: u32 \
-#		match u32 0 0 \
-#		action pedit munge $@ >/dev/null 2>&1
-#	tc filter show dev veth0 parent ffff: | \
-#		sed -n 's/^[\t ]*\(key #0.*\)/test_on "\1"/p'
-# }
-#
-# do_it_all() { # (field, val1 [, val2, ...])
-#	local field=$1
-#	shift
-#	for val in $@; do
-#		do_it ip $field set $val
-#	done
-#	for i in preserve invert clear; do
-#		do_it ip $field $i
-#	done
-# }
-#
-# do_it_all ihl 0x04 0x40
-# do_it_all src 1.2.3.4
-# do_it_all dst 1.2.3.4
-# do_it_all tos 0x1 0x10
-# do_it_all protocol 0x23
-# do_it_all nofrag 0x23 0xf4
-# do_it_all firstfrag 0x03 0xfa
-# do_it_all ce 0x23 0x04 0xf3
-# do_it_all df 0x23 0x04 0xf3
-# do_it_all mf 0x23 0x04 0xf3
-# do_it_all dport 0x1234
-# do_it_all sport 0x1234
-# do_it_all icmp_type 0x23
-# do_it_all icmp_code 0x23
-
-do_pedit ip ihl set 0x04
-test_on "key #0  at 0: val 04000000 mask f0ffffff"
-do_pedit ip ihl set 0x40
-test_on "key #0  at 0: val 00000000 mask f0ffffff"
-do_pedit ip ihl preserve
-test_on "key #0  at 0: val 00000000 mask ffffffff"
-do_pedit ip ihl invert
-test_on "key #0  at 0: val 0f000000 mask ffffffff"
-do_pedit ip ihl clear
-test_on "key #0  at 0: val 00000000 mask f0ffffff"
-do_pedit ip src set 1.2.3.4
-test_on "key #0  at 12: val 01020304 mask 00000000"
-do_pedit ip src preserve
-test_on "key #0  at 12: val 00000000 mask ffffffff"
-do_pedit ip src invert
-test_on "key #0  at 12: val ffffffff mask ffffffff"
-do_pedit ip src clear
-test_on "key #0  at 12: val 00000000 mask 00000000"
-do_pedit ip dst set 1.2.3.4
-test_on "key #0  at 16: val 01020304 mask 00000000"
-do_pedit ip dst preserve
-test_on "key #0  at 16: val 00000000 mask ffffffff"
-do_pedit ip dst invert
-test_on "key #0  at 16: val ffffffff mask ffffffff"
-do_pedit ip dst clear
-test_on "key #0  at 16: val 00000000 mask 00000000"
-do_pedit ip tos set 0x1
-test_on "key #0  at 0: val 00010000 mask ff00ffff"
-do_pedit ip tos set 0x10
-test_on "key #0  at 0: val 00100000 mask ff00ffff"
-do_pedit ip tos preserve
-test_on "key #0  at 0: val 00000000 mask ffffffff"
-do_pedit ip tos invert
-test_on "key #0  at 0: val 00ff0000 mask ffffffff"
-do_pedit ip tos clear
-test_on "key #0  at 0: val 00000000 mask ff00ffff"
-do_pedit ip protocol set 0x23
-test_on "key #0  at 8: val 00230000 mask ff00ffff"
-do_pedit ip protocol preserve
-test_on "key #0  at 8: val 00000000 mask ffffffff"
-do_pedit ip protocol invert
-test_on "key #0  at 8: val 00ff0000 mask ffffffff"
-do_pedit ip protocol clear
-test_on "key #0  at 8: val 00000000 mask ff00ffff"
-do_pedit ip nofrag set 0x23
-test_on "key #0  at 4: val 00002300 mask ffffc0ff"
-do_pedit ip nofrag set 0xf4
-test_on "key #0  at 4: val 00003400 mask ffffc0ff"
-do_pedit ip nofrag preserve
-test_on "key #0  at 4: val 00000000 mask ffffffff"
-do_pedit ip nofrag invert
-test_on "key #0  at 4: val 00003f00 mask ffffffff"
-do_pedit ip nofrag clear
-test_on "key #0  at 4: val 00000000 mask ffffc0ff"
-do_pedit ip firstfrag set 0x03
-test_on "key #0  at 4: val 00000300 mask ffffe0ff"
-do_pedit ip firstfrag set 0xfa
-test_on "key #0  at 4: val 00001a00 mask ffffe0ff"
-do_pedit ip firstfrag preserve
-test_on "key #0  at 4: val 00000000 mask ffffffff"
-do_pedit ip firstfrag invert
-test_on "key #0  at 4: val 00001f00 mask ffffffff"
-do_pedit ip firstfrag clear
-test_on "key #0  at 4: val 00000000 mask ffffe0ff"
-do_pedit ip ce set 0x23
-test_on "key #0  at 4: val 00000000 mask ffff7fff"
-do_pedit ip ce set 0x04
-test_on "key #0  at 4: val 00000000 mask ffff7fff"
-do_pedit ip ce set 0xf3
-test_on "key #0  at 4: val 00008000 mask ffff7fff"
-do_pedit ip ce preserve
-test_on "key #0  at 4: val 00000000 mask ffffffff"
-do_pedit ip ce invert
-test_on "key #0  at 4: val 00008000 mask ffffffff"
-do_pedit ip ce clear
-test_on "key #0  at 4: val 00000000 mask ffff7fff"
-do_pedit ip df set 0x23
-test_on "key #0  at 4: val 00000000 mask ffffbfff"
-do_pedit ip df set 0x04
-test_on "key #0  at 4: val 00000000 mask ffffbfff"
-do_pedit ip df set 0xf3
-test_on "key #0  at 4: val 00004000 mask ffffbfff"
-do_pedit ip df preserve
-test_on "key #0  at 4: val 00000000 mask ffffffff"
-do_pedit ip df invert
-test_on "key #0  at 4: val 00004000 mask ffffffff"
-do_pedit ip df clear
-test_on "key #0  at 4: val 00000000 mask ffffbfff"
-do_pedit ip mf set 0x23
-test_on "key #0  at 4: val 00002000 mask ffffdfff"
-do_pedit ip mf set 0x04
-test_on "key #0  at 4: val 00000000 mask ffffdfff"
-do_pedit ip mf set 0xf3
-test_on "key #0  at 4: val 00002000 mask ffffdfff"
-do_pedit ip mf preserve
-test_on "key #0  at 4: val 00000000 mask ffffffff"
-do_pedit ip mf invert
-test_on "key #0  at 4: val 00002000 mask ffffffff"
-do_pedit ip mf clear
-test_on "key #0  at 4: val 00000000 mask ffffdfff"
-do_pedit ip dport set 0x1234
-test_on "key #0  at 20: val 00001234 mask ffff0000"
-do_pedit ip dport preserve
-test_on "key #0  at 20: val 00000000 mask ffffffff"
-do_pedit ip dport invert
-test_on "key #0  at 20: val 0000ffff mask ffffffff"
-do_pedit ip dport clear
-test_on "key #0  at 20: val 00000000 mask ffff0000"
-do_pedit ip sport set 0x1234
-test_on "key #0  at 20: val 12340000 mask 0000ffff"
-do_pedit ip sport preserve
-test_on "key #0  at 20: val 00000000 mask ffffffff"
-do_pedit ip sport invert
-test_on "key #0  at 20: val ffff0000 mask ffffffff"
-do_pedit ip sport clear
-test_on "key #0  at 20: val 00000000 mask 0000ffff"
-do_pedit ip icmp_type set 0x23
-test_on "key #0  at 20: val 23000000 mask 00ffffff"
-do_pedit ip icmp_type preserve
-test_on "key #0  at 20: val 00000000 mask ffffffff"
-do_pedit ip icmp_type invert
-test_on "key #0  at 20: val ff000000 mask ffffffff"
-do_pedit ip icmp_type clear
-test_on "key #0  at 20: val 00000000 mask 00ffffff"
-do_pedit ip icmp_code set 0x23
-test_on "key #0  at 20: val 23000000 mask 00ffffff"
-do_pedit ip icmp_code preserve
-test_on "key #0  at 20: val 00000000 mask ffffffff"
-do_pedit ip icmp_code invert
-test_on "key #0  at 20: val ff000000 mask ffffffff"
-do_pedit ip icmp_code clear
-test_on "key #0  at 20: val 00000000 mask 00ffffff"
diff --git a/testsuite/tools/Makefile b/testsuite/tools/Makefile
deleted file mode 100644
index e3e771d..0000000
--- a/testsuite/tools/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-CFLAGS=
-include ../../config.mk
-
-generate_nlmsg: generate_nlmsg.c ../../lib/libnetlink.c
-	$(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) -I../../include -I../../include/uapi -include../../include/uapi/linux/netlink.h -o $@ $^ -lmnl
-
-clean:
-	rm -f generate_nlmsg
diff --git a/testsuite/tools/generate_nlmsg.c b/testsuite/tools/generate_nlmsg.c
deleted file mode 100644
index fe96f26..0000000
--- a/testsuite/tools/generate_nlmsg.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * generate_nlmsg.c	Testsuite helper generating nlmsg blob
- *
- *		This program is free software; you can redistribute it and/or
- *		modify it under the terms of the GNU General Public License
- *		as published by the Free Software Foundation; either version
- *		2 of the License, or (at your option) any later version.
- *
- * Authors:	Phil Sutter <phil@nwl.cc>
- */
-
-#include <netinet/ether.h>
-#include <libnetlink.h>
-#include <sys/socket.h>
-#include <linux/if.h>
-#include <errno.h>
-#include <stdio.h>
-
-int fill_vf_rate_test(void *buf, size_t buflen)
-{
-	char bcmac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-	struct ifla_vf_mac vf_mac = {
-		.mac = { 0x0, 0x26, 0x6c, 0xff, 0xb5, 0xc0 },
-	};
-	struct ifla_vf_link_state vf_link_state = { 0 };
-	struct ifla_vf_tx_rate vf_tx_rate = { 0 };
-	struct ifla_vf_spoofchk vf_spoofchk = {
-		.setting = 1,
-	};
-	struct ifla_vf_vlan vf_vlan = { 0 };
-	struct rtattr *vfinfo_list, *vfinfo;
-	struct nlmsghdr *h = buf;
-	struct ifinfomsg *ifi;
-
-	h->nlmsg_type = RTM_NEWLINK;
-	h->nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
-
-	ifi = NLMSG_DATA(h);
-	ifi->ifi_type = ARPHRD_ETHER;
-	ifi->ifi_index = 1;
-	ifi->ifi_flags = IFF_RUNNING | IFF_BROADCAST |
-			 IFF_MULTICAST | IFF_UP | IFF_LOWER_UP;
-
-#define ASSERT(x) if (x < 0) return -1
-#define ATTR_L(t, v, l)	ASSERT(addattr_l(h, buflen, t, v, l))
-#define ATTR_8(t, v)	ASSERT(addattr8(h, buflen, t, v))
-#define ATTR_32(t, v)	ASSERT(addattr32(h, buflen, t, v))
-#define ATTR_STRZ(t, v)	ASSERT(addattrstrz(h, buflen, t, v))
-
-#define NEST(t) addattr_nest(h, buflen, t)
-#define NEST_END(t) addattr_nest_end(h, t)
-
-	ATTR_STRZ(IFLA_IFNAME, "eth0");
-	ATTR_32(IFLA_TXQLEN, 10000);
-	ATTR_8(IFLA_OPERSTATE, 6);
-	ATTR_8(IFLA_LINKMODE, 0);
-	ATTR_32(IFLA_MTU, 9000);
-	ATTR_32(IFLA_GROUP, 0);
-	ATTR_32(IFLA_PROMISCUITY, 0);
-	ATTR_32(IFLA_NUM_TX_QUEUES, 8);
-	ATTR_32(IFLA_NUM_RX_QUEUES, 8);
-	ATTR_8(IFLA_CARRIER, 1);
-	ATTR_STRZ(IFLA_QDISC, "mq");
-	ATTR_L(IFLA_ADDRESS, vf_mac.mac, ETH_ALEN);
-	ATTR_L(IFLA_BROADCAST, bcmac, sizeof(bcmac));
-	ATTR_32(IFLA_NUM_VF, 2);
-
-	vfinfo_list = NEST(IFLA_VFINFO_LIST);
-
-	vfinfo = NEST(IFLA_VF_INFO);
-	ATTR_L(IFLA_VF_MAC, &vf_mac, sizeof(vf_mac));
-	ATTR_L(IFLA_VF_VLAN, &vf_vlan, sizeof(vf_vlan));
-	ATTR_L(IFLA_VF_TX_RATE, &vf_tx_rate, sizeof(vf_tx_rate));
-	ATTR_L(IFLA_VF_SPOOFCHK, &vf_spoofchk, sizeof(vf_spoofchk));
-	ATTR_L(IFLA_VF_LINK_STATE, &vf_link_state, sizeof(vf_link_state));
-	NEST_END(vfinfo);
-
-	vf_mac.vf = vf_vlan.vf = vf_tx_rate.vf = 1;
-	vf_spoofchk.vf = vf_link_state.vf = 1;
-
-	vfinfo = NEST(IFLA_VF_INFO);
-	ATTR_L(IFLA_VF_MAC, &vf_mac, sizeof(vf_mac));
-	ATTR_L(IFLA_VF_VLAN, &vf_vlan, sizeof(vf_vlan));
-	ATTR_L(IFLA_VF_TX_RATE, &vf_tx_rate, sizeof(vf_tx_rate));
-	ATTR_L(IFLA_VF_SPOOFCHK, &vf_spoofchk, sizeof(vf_spoofchk));
-	ATTR_L(IFLA_VF_LINK_STATE, &vf_link_state, sizeof(vf_link_state));
-	NEST_END(vfinfo);
-
-	NEST_END(vfinfo_list);
-
-	return h->nlmsg_len;
-}
-
-int main(void)
-{
-	char buf[16384] = { 0 };
-	int msglen;
-	FILE *fp;
-
-	msglen = fill_vf_rate_test(buf, sizeof(buf));
-	if (msglen < 0) {
-		fprintf(stderr, "fill_vf_rate_test() failed!\n");
-		return 1;
-	}
-	fp = fopen("tests/ip/link/dev_wo_vf_rate.nl", "w");
-	if (!fp) {
-		perror("fopen()");
-		return 1;
-	}
-	if (fwrite(buf, msglen, 1, fp) != 1) {
-		perror("fwrite()");
-		return 1;
-	}
-	fclose(fp);
-	return 0;
-}
diff --git a/tipc/Makefile b/tipc/Makefile
index a10debe..f06dcb1 100644
--- a/tipc/Makefile
+++ b/tipc/Makefile
@@ -1,8 +1,4 @@
-# SPDX-License-Identifier: GPL-2.0
-include ../config.mk
-
-TARGETS :=
-
+include ../Config
 ifeq ($(HAVE_MNL),y)
 
 TIPCOBJ=bearer.o \
@@ -12,19 +8,20 @@
     node.o socket.o \
     peer.o tipc.o
 
-TARGETS += tipc
+include ../Config
+
+TARGETS=tipc
+CFLAGS += $(shell $(PKG_CONFIG) libmnl --cflags)
+LDLIBS += $(shell $(PKG_CONFIG) libmnl --libs)
 
 endif
 
 all: $(TARGETS) $(LIBS)
 
 tipc: $(TIPCOBJ)
-	$(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
 
 install: all
-	for i in $(TARGETS); \
-	do install -m 0755 $$i $(DESTDIR)$(SBINDIR); \
-	done
+	install -m 0755 $(TARGETS) $(DESTDIR)$(SBINDIR)
 
 clean:
 	rm -f $(TIPCOBJ) $(TARGETS)
diff --git a/tipc/bearer.c b/tipc/bearer.c
index 4470819..30b54d9 100644
--- a/tipc/bearer.c
+++ b/tipc/bearer.c
@@ -14,71 +14,73 @@
 #include <string.h>
 #include <netdb.h>
 #include <errno.h>
-#include <arpa/inet.h>
 
 #include <linux/tipc_netlink.h>
 #include <linux/tipc.h>
 #include <linux/genetlink.h>
-#include <linux/if.h>
 
 #include <libmnl/libmnl.h>
 #include <sys/socket.h>
 
-#include "utils.h"
 #include "cmdl.h"
 #include "msg.h"
 #include "bearer.h"
 
-#define UDP_PROP_IP 1
-#define UDP_PROP_PORT 2
-
-struct cb_data {
-	int attr;
-	int prop;
-	struct nlmsghdr *nlh;
-};
-
 static void _print_bearer_opts(void)
 {
 	fprintf(stderr,
-		"OPTIONS\n"
-		" priority		- Bearer link priority\n"
-		" tolerance		- Bearer link tolerance\n"
-		" window		- Bearer link window\n"
-		" mtu			- Bearer link mtu\n");
+		"\nOPTIONS\n"
+		" priority              - Bearer link priority\n"
+		" tolerance             - Bearer link tolerance\n"
+		" window                - Bearer link window\n");
 }
 
-void print_bearer_media(void)
+static void _print_bearer_media(void)
 {
 	fprintf(stderr,
 		"\nMEDIA\n"
-		" udp			- User Datagram Protocol\n"
-		" ib			- Infiniband\n"
-		" eth			- Ethernet\n");
+		" udp                   - User Datagram Protocol\n"
+		" ib                    - Infiniband\n"
+		" eth                   - Ethernet\n");
 }
 
-static void cmd_bearer_enable_l2_help(struct cmdl *cmdl, char *media)
+static void cmd_bearer_enable_l2_help(struct cmdl *cmdl)
 {
 	fprintf(stderr,
-		"Usage: %s bearer enable media %s device DEVICE [OPTIONS]\n"
+		"Usage: %s bearer enable media MEDIA device DEVICE [OPTIONS]\n"
 		"\nOPTIONS\n"
-		" domain DOMAIN		- Discovery domain\n"
-		" priority PRIORITY	- Bearer priority\n",
-		cmdl->argv[0], media);
+		" domain DOMAIN         - Discovery domain\n"
+		" priority PRIORITY     - Bearer priority\n",
+		cmdl->argv[0]);
 }
 
-static void cmd_bearer_enable_udp_help(struct cmdl *cmdl, char *media)
+static void cmd_bearer_enable_udp_help(struct cmdl *cmdl)
 {
 	fprintf(stderr,
-		"Usage: %s bearer enable [OPTIONS] media %s name NAME [localip IP|device DEVICE] [UDP OPTIONS]\n\n"
-		"OPTIONS\n"
-		" domain DOMAIN		- Discovery domain\n"
-		" priority PRIORITY	- Bearer priority\n\n"
-		"UDP OPTIONS\n"
-		" localport PORT	- Local UDP port (default 6118)\n"
-		" remoteip IP		- Remote IP address\n"
-		" remoteport PORT	- Remote UDP port (default 6118)\n",
-		cmdl->argv[0], media);
+		"Usage: %s bearer enable media udp name NAME localip IP [OPTIONS]\n"
+		"\nOPTIONS\n"
+		" domain DOMAIN         - Discovery domain\n"
+		" priority PRIORITY     - Bearer priority\n"
+		" localport PORT        - Local UDP port (default 6118)\n"
+		" remoteip IP           - Remote IP address\n"
+		" remoteport IP         - Remote UDP port (default 6118)\n",
+		cmdl->argv[0]);
+}
+
+static int enable_l2_bearer(struct nlmsghdr *nlh, struct opt *opts,
+			    struct cmdl *cmdl)
+{
+	struct opt *opt;
+	char id[TIPC_MAX_BEARER_NAME];
+
+	if (!(opt = get_opt(opts, "device"))) {
+		fprintf(stderr, "error: missing bearer device\n");
+		return -EINVAL;
+	}
+	snprintf(id, sizeof(id), "eth:%s", opt->val);
+	mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, id);
+
+	return 0;
 }
 
 static int get_netid_cb(const struct nlmsghdr *nlh, void *data)
@@ -121,78 +123,8 @@
 	return 0;
 }
 
-static struct ifreq ifr;
-static int nl_dump_req_filter(struct nlmsghdr *nlh, int reqlen)
-{
-	struct ifaddrmsg *ifa = NLMSG_DATA(nlh);
-
-	ifa->ifa_index = ifr.ifr_ifindex;
-
-	return 0;
-}
-
-static int nl_dump_addr_filter(struct nlmsghdr *nlh, void *arg)
-{
-	struct ifaddrmsg *ifa = NLMSG_DATA(nlh);
-	char *r_addr = (char *)arg;
-	int len = nlh->nlmsg_len;
-	struct rtattr *addr_attr;
-
-	if (ifr.ifr_ifindex != ifa->ifa_index)
-		return 0;
-
-	if (strlen(r_addr) > 0)
-		return 0;
-
-	addr_attr = parse_rtattr_one(IFA_ADDRESS, IFA_RTA(ifa),
-				     len - NLMSG_LENGTH(sizeof(*ifa)));
-	if (!addr_attr)
-		return 0;
-
-	if (ifa->ifa_family == AF_INET) {
-		struct sockaddr_in ip4addr;
-		memcpy(&ip4addr.sin_addr, RTA_DATA(addr_attr),
-		       sizeof(struct in_addr));
-		inet_ntop(AF_INET, &ip4addr.sin_addr, r_addr,
-			  INET_ADDRSTRLEN);
-	} else if (ifa->ifa_family == AF_INET6) {
-		struct sockaddr_in6 ip6addr;
-		memcpy(&ip6addr.sin6_addr, RTA_DATA(addr_attr),
-		       sizeof(struct in6_addr));
-		inet_ntop(AF_INET6, &ip6addr.sin6_addr, r_addr,
-			  INET6_ADDRSTRLEN);
-	}
-	return 0;
-}
-
-static int cmd_bearer_validate_and_get_addr(const char *name, char *r_addr)
-{
-	struct rtnl_handle rth = { .fd = -1 };
-	int err = -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-	if (!name || !r_addr || get_ifname(ifr.ifr_name, name))
-		return err;
-
-	ifr.ifr_ifindex = ll_name_to_index(ifr.ifr_name);
-	if (!ifr.ifr_ifindex)
-		return err;
-
-	/* remove from cache */
-	ll_drop_by_index(ifr.ifr_ifindex);
-
-	if ((err = rtnl_open(&rth, 0)) < 0)
-		return err;
-
-	if ((err = rtnl_addrdump_req(&rth, AF_UNSPEC, nl_dump_req_filter)) > 0)
-		err = rtnl_dump_filter(&rth, nl_dump_addr_filter, r_addr);
-
-	rtnl_close(&rth);
-	return err;
-}
-
-static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
-				  struct cmdl *cmdl)
+static int enable_udp_bearer(struct nlmsghdr *nlh, struct opt *opts,
+			     struct cmdl *cmdl)
 {
 	int err;
 	struct opt *opt;
@@ -202,31 +134,33 @@
 	char *remport = "6118";
 	char *locip = NULL;
 	char *remip = NULL;
+	char name[TIPC_MAX_BEARER_NAME];
 	struct addrinfo *loc = NULL;
 	struct addrinfo *rem = NULL;
 	struct addrinfo hints = {
 		.ai_family = AF_UNSPEC,
 		.ai_socktype = SOCK_DGRAM
 	};
-	char addr[INET6_ADDRSTRLEN] = {0};
 
-	opt = get_opt(opts, "device");
-	if (opt && cmd_bearer_validate_and_get_addr(opt->val, addr) < 0) {
-		fprintf(stderr, "error, no device name available\n");
+	if (help_flag) {
+		cmd_bearer_enable_udp_help(cmdl);
+		/* TODO find a better error code? */
 		return -EINVAL;
 	}
 
-	if (strlen(addr) > 0) {
-		locip = addr;
-	} else {
-		opt = get_opt(opts, "localip");
-		if (!opt) {
-			fprintf(stderr, "error, udp bearer localip/device missing\n");
-			cmd_bearer_enable_udp_help(cmdl, "udp");
-			return -EINVAL;
-		}
-		locip = opt->val;
+	if (!(opt = get_opt(opts, "name"))) {
+		fprintf(stderr, "error, udp bearer name missing\n");
+		cmd_bearer_enable_udp_help(cmdl);
+		return -EINVAL;
 	}
+	snprintf(name, sizeof(name), "udp:%s", opt->val);
+
+	if (!(opt = get_opt(opts, "localip"))) {
+		fprintf(stderr, "error, udp bearer localip missing\n");
+		cmd_bearer_enable_udp_help(cmdl);
+		return -EINVAL;
+	}
+	locip = opt->val;
 
 	if ((opt = get_opt(opts, "remoteip")))
 		remip = opt->val;
@@ -246,7 +180,6 @@
 	if (!remip) {
 		if (generate_multicast(loc->ai_family, buf, sizeof(buf))) {
 			fprintf(stderr, "Failed to generate multicast address\n");
-			freeaddrinfo(loc);
 			return -EINVAL;
 		}
 		remip = buf;
@@ -261,11 +194,11 @@
 
 	if (rem->ai_family != loc->ai_family) {
 		fprintf(stderr, "UDP local and remote AF mismatch\n");
-		freeaddrinfo(rem);
-		freeaddrinfo(loc);
 		return -EINVAL;
 	}
 
+	mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, name);
+
 	nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER_UDP_OPTS);
 	mnl_attr_put(nlh, TIPC_NLA_UDP_LOCAL, loc->ai_addrlen, loc->ai_addr);
 	mnl_attr_put(nlh, TIPC_NLA_UDP_REMOTE, rem->ai_addrlen, rem->ai_addr);
@@ -277,194 +210,6 @@
 	return 0;
 }
 
-static char *cmd_get_media_type(const struct cmd *cmd, struct cmdl *cmdl,
-				struct opt *opts)
-{
-	struct opt *opt = get_opt(opts, "media");
-
-	if (!opt) {
-		if (help_flag)
-			(cmd->help)(cmdl);
-		else
-			fprintf(stderr, "error, missing bearer media\n");
-		return NULL;
-	}
-	return opt->val;
-}
-
-static int nl_add_bearer_name(struct nlmsghdr *nlh, const struct cmd *cmd,
-			      struct cmdl *cmdl, struct opt *opts,
-			      const struct tipc_sup_media *sup_media)
-{
-	char bname[TIPC_MAX_BEARER_NAME];
-	int err;
-
-	if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname, sup_media)))
-		return err;
-
-	mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname);
-	return 0;
-}
-
-int cmd_get_unique_bearer_name(const struct cmd *cmd, struct cmdl *cmdl,
-			       struct opt *opts, char *bname,
-			       const struct tipc_sup_media *sup_media)
-{
-	char *media;
-	char *identifier;
-	struct opt *opt;
-	const struct tipc_sup_media *entry;
-
-	if (!(media = cmd_get_media_type(cmd, cmdl, opts)))
-		return -EINVAL;
-
-	for (entry = sup_media; entry->media; entry++) {
-		if (strcmp(entry->media, media))
-			continue;
-
-		if (!(opt = get_opt(opts, entry->identifier))) {
-			if (help_flag)
-				(entry->help)(cmdl, media);
-			else
-				fprintf(stderr, "error, missing bearer %s\n",
-					entry->identifier);
-			return -EINVAL;
-		}
-
-		identifier = opt->val;
-		snprintf(bname, TIPC_MAX_BEARER_NAME, "%s:%s", media, identifier);
-
-		return 0;
-	}
-
-	fprintf(stderr, "error, invalid media type %s\n", media);
-
-	return -EINVAL;
-}
-
-static void cmd_bearer_add_udp_help(struct cmdl *cmdl, char *media)
-{
-	fprintf(stderr, "Usage: %s bearer add media %s name NAME remoteip REMOTEIP\n\n",
-		cmdl->argv[0], media);
-}
-
-static void cmd_bearer_add_help(struct cmdl *cmdl)
-{
-	fprintf(stderr, "Usage: %s bearer add media udp name NAME remoteip REMOTEIP\n",
-		cmdl->argv[0]);
-}
-
-static int udp_bearer_add(struct nlmsghdr *nlh, struct opt *opts,
-			  struct cmdl *cmdl)
-{
-	int err;
-	struct opt *opt;
-	struct nlattr *opts_nest;
-	char *remport = "6118";
-
-	opts_nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER_UDP_OPTS);
-
-	if ((opt = get_opt(opts, "remoteport")))
-		remport = opt->val;
-
-	if ((opt = get_opt(opts, "remoteip"))) {
-		char *ip = opt->val;
-		struct addrinfo *addr = NULL;
-		struct addrinfo hints = {
-			.ai_family = AF_UNSPEC,
-			.ai_socktype = SOCK_DGRAM
-		};
-
-		if ((err = getaddrinfo(ip, remport, &hints, &addr))) {
-			fprintf(stderr, "UDP address error: %s\n",
-				gai_strerror(err));
-			freeaddrinfo(addr);
-			return err;
-		}
-
-		mnl_attr_put(nlh, TIPC_NLA_UDP_REMOTE, addr->ai_addrlen,
-			     addr->ai_addr);
-		freeaddrinfo(addr);
-	} else {
-		fprintf(stderr, "error, missing remoteip\n");
-		return -EINVAL;
-	}
-	mnl_attr_nest_end(nlh, opts_nest);
-
-	return 0;
-}
-
-static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd,
-				struct cmdl *cmdl, void *data)
-{
-	int err;
-	char *media;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct opt *opt;
-	struct nlattr *attrs;
-	struct opt opts[] = {
-		{ "remoteip",		OPT_KEYVAL,	NULL },
-		{ "remoteport",		OPT_KEYVAL,	NULL },
-		{ "name",		OPT_KEYVAL,	NULL },
-		{ "media",		OPT_KEYVAL,	NULL },
-		{ NULL }
-	};
-	const struct tipc_sup_media sup_media[] = {
-		{ "udp",	"name",		cmd_bearer_add_udp_help},
-		{ NULL, },
-	};
-
-	/* Rewind optind to include media in the option list */
-	cmdl->optind--;
-	if (parse_opts(opts, cmdl) < 0)
-		return -EINVAL;
-
-	if (!(opt = get_opt(opts, "media"))) {
-		fprintf(stderr, "error, missing media value\n");
-		return -EINVAL;
-	}
-	media = opt->val;
-
-	if (strcmp(media, "udp") != 0) {
-		fprintf(stderr, "error, no \"%s\" media specific options available\n",
-			media);
-		return -EINVAL;
-	}
-	if (!(opt = get_opt(opts, "name"))) {
-		fprintf(stderr, "error, missing media name\n");
-		return -EINVAL;
-	}
-
-	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ADD))) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
-	err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
-	if (err)
-		return err;
-
-	err = udp_bearer_add(nlh, opts, cmdl);
-	if (err)
-		return err;
-
-	mnl_attr_nest_end(nlh, attrs);
-
-	return msg_doit(nlh, NULL, NULL);
-}
-
-static int cmd_bearer_add(struct nlmsghdr *nlh, const struct cmd *cmd,
-			  struct cmdl *cmdl, void *data)
-{
-	const struct cmd cmds[] = {
-		{ "media",	cmd_bearer_add_media,	cmd_bearer_add_help },
-		{ NULL }
-	};
-
-	return run_cmd(nlh, cmd, cmds, cmdl, NULL);
-}
-
 static void cmd_bearer_enable_help(struct cmdl *cmdl)
 {
 	fprintf(stderr,
@@ -473,7 +218,7 @@
 		" domain DOMAIN         - Discovery domain\n"
 		" priority PRIORITY     - Bearer priority\n",
 		cmdl->argv[0]);
-	print_bearer_media();
+	_print_bearer_media();
 }
 
 static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd,
@@ -483,24 +228,19 @@
 	struct opt *opt;
 	struct nlattr *nest;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
+	char *media;
 	struct opt opts[] = {
-		{ "device",		OPT_KEYVAL,	NULL },
-		{ "domain",		OPT_KEYVAL,	NULL },
-		{ "localip",		OPT_KEYVAL,	NULL },
-		{ "localport",		OPT_KEYVAL,	NULL },
-		{ "media",		OPT_KEYVAL,	NULL },
-		{ "name",		OPT_KEYVAL,	NULL },
-		{ "priority",		OPT_KEYVAL,	NULL },
-		{ "remoteip",		OPT_KEYVAL,	NULL },
-		{ "remoteport",		OPT_KEYVAL,	NULL },
+		{ "device",		NULL },
+		{ "domain",		NULL },
+		{ "localip",		NULL },
+		{ "localport",		NULL },
+		{ "media",		NULL },
+		{ "name",		NULL },
+		{ "priority",		NULL },
+		{ "remoteip",		NULL },
+		{ "remoteport",		NULL },
 		{ NULL }
 	};
-	struct tipc_sup_media sup_media[] = {
-		{ "udp",        "name",         cmd_bearer_enable_udp_help},
-		{ "eth",        "device",       cmd_bearer_enable_l2_help },
-		{ "ib",         "device",       cmd_bearer_enable_l2_help },
-		{ NULL, },
-	};
 
 	if (parse_opts(opts, cmdl) < 0) {
 		if (help_flag)
@@ -508,6 +248,15 @@
 		return -EINVAL;
 	}
 
+	if (!(opt = get_opt(opts, "media"))) {
+		if (help_flag)
+			(cmd->help)(cmdl);
+		else
+			fprintf(stderr, "error, missing bearer media\n");
+		return -EINVAL;
+	}
+	media = opt->val;
+
 	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ENABLE))) {
 		fprintf(stderr, "error: message initialisation failed\n");
 		return -1;
@@ -525,58 +274,95 @@
 		mnl_attr_nest_end(nlh, props);
 	}
 
-	err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
-	if (err)
-		return err;
-
-	opt = get_opt(opts, "media");
-	if (opt && strcmp(opt->val, "udp") == 0) {
-		err = nl_add_udp_enable_opts(nlh, opts, cmdl);
-		if (err)
+	if (strcmp(media, "udp") == 0) {
+		if (help_flag) {
+			cmd_bearer_enable_udp_help(cmdl);
+			return -EINVAL;
+		}
+		if ((err = enable_udp_bearer(nlh, opts, cmdl)))
 			return err;
+	} else if ((strcmp(media, "eth") == 0) || (strcmp(media, "udp") == 0)) {
+		if (help_flag) {
+			cmd_bearer_enable_l2_help(cmdl);
+			return -EINVAL;
+		}
+		if ((err = enable_l2_bearer(nlh, opts, cmdl)))
+			return err;
+	} else {
+		fprintf(stderr, "error, invalid media type \"%s\"\n", media);
+		return -EINVAL;
 	}
+
 	mnl_attr_nest_end(nlh, nest);
 
 	return msg_doit(nlh, NULL, NULL);
 }
 
-static void cmd_bearer_disable_l2_help(struct cmdl *cmdl, char *media)
+static int add_l2_bearer(struct nlmsghdr *nlh, struct opt *opts)
 {
-	fprintf(stderr, "Usage: %s bearer disable media %s device DEVICE\n",
-		cmdl->argv[0], media);
+	struct opt *opt;
+	char id[TIPC_MAX_BEARER_NAME];
+
+	if (!(opt = get_opt(opts, "device"))) {
+		fprintf(stderr, "error: missing bearer device\n");
+		return -EINVAL;
+	}
+	snprintf(id, sizeof(id), "eth:%s", opt->val);
+
+	mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, id);
+
+	return 0;
 }
 
-static void cmd_bearer_disable_udp_help(struct cmdl *cmdl, char *media)
+static int add_udp_bearer(struct nlmsghdr *nlh, struct opt *opts)
 {
-	fprintf(stderr, "Usage: %s bearer disable media %s name NAME\n",
-		cmdl->argv[0], media);
+	struct opt *opt;
+	char id[TIPC_MAX_BEARER_NAME];
+
+	if (!(opt = get_opt(opts, "name"))) {
+		fprintf(stderr, "error: missing bearer name\n");
+		return -EINVAL;
+	}
+	snprintf(id, sizeof(id), "udp:%s", opt->val);
+
+	mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, id);
+
+	return 0;
+}
+
+static void cmd_bearer_disable_l2_help(struct cmdl *cmdl)
+{
+	fprintf(stderr, "Usage: %s bearer disable media udp device DEVICE\n",
+		cmdl->argv[0]);
+}
+
+static void cmd_bearer_disable_udp_help(struct cmdl *cmdl)
+{
+	fprintf(stderr, "Usage: %s bearer disable media udp name NAME\n",
+		cmdl->argv[0]);
 }
 
 static void cmd_bearer_disable_help(struct cmdl *cmdl)
 {
 	fprintf(stderr, "Usage: %s bearer disable media MEDIA ARGS...\n",
 		cmdl->argv[0]);
-	print_bearer_media();
+	_print_bearer_media();
 }
 
 static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd,
 			      struct cmdl *cmdl, void *data)
 {
 	int err;
+	char *media;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlattr *nest;
+	struct opt *opt;
 	struct opt opts[] = {
-		{ "device",		OPT_KEYVAL,	NULL },
-		{ "name",		OPT_KEYVAL,	NULL },
-		{ "media",		OPT_KEYVAL,	NULL },
+		{ "device",		NULL },
+		{ "name",		NULL },
+		{ "media",		NULL },
 		{ NULL }
 	};
-	struct tipc_sup_media sup_media[] = {
-		{ "udp",        "name",         cmd_bearer_disable_udp_help},
-		{ "eth",        "device",       cmd_bearer_disable_l2_help },
-		{ "ib",         "device",       cmd_bearer_disable_l2_help },
-		{ NULL, },
-	};
 
 	if (parse_opts(opts, cmdl) < 0) {
 		if (help_flag)
@@ -584,15 +370,40 @@
 		return -EINVAL;
 	}
 
+	if (!(opt = get_opt(opts, "media"))) {
+		if (help_flag)
+			(cmd->help)(cmdl);
+		else
+			fprintf(stderr, "error, missing bearer media\n");
+		return -EINVAL;
+	}
+	media = opt->val;
+
 	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
 
 	nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
-	err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
-	if (err)
-		return err;
+
+	if (strcmp(media, "udp") == 0) {
+		if (help_flag) {
+			cmd_bearer_disable_udp_help(cmdl);
+			return -EINVAL;
+		}
+		if ((err = add_udp_bearer(nlh, opts)))
+			return err;
+	} else if ((strcmp(media, "eth") == 0) || (strcmp(media, "udp") == 0)) {
+		if (help_flag) {
+			cmd_bearer_disable_l2_help(cmdl);
+			return -EINVAL;
+		}
+		if ((err = add_l2_bearer(nlh, opts)))
+			return err;
+	} else {
+		fprintf(stderr, "error, invalid media type \"%s\"\n", media);
+		return -EINVAL;
+	}
 	mnl_attr_nest_end(nlh, nest);
 
 	return msg_doit(nlh, NULL, NULL);
@@ -604,13 +415,13 @@
 	fprintf(stderr, "Usage: %s bearer set OPTION media MEDIA ARGS...\n",
 		cmdl->argv[0]);
 	_print_bearer_opts();
-	print_bearer_media();
+	_print_bearer_media();
 }
 
-static void cmd_bearer_set_udp_help(struct cmdl *cmdl, char *media)
+static void cmd_bearer_set_udp_help(struct cmdl *cmdl)
 {
-	fprintf(stderr, "Usage: %s bearer set OPTION media %s name NAME\n\n",
-		cmdl->argv[0], media);
+	fprintf(stderr, "Usage: %s bearer set OPTION media udp name NAME\n\n",
+		cmdl->argv[0]);
 	_print_bearer_opts();
 }
 
@@ -623,26 +434,22 @@
 }
 
 static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
-			       struct cmdl *cmdl, void *data)
+			 struct cmdl *cmdl, void *data)
 {
 	int err;
 	int val;
 	int prop;
+	char *media;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlattr *props;
 	struct nlattr *attrs;
+	struct opt *opt;
 	struct opt opts[] = {
-		{ "device",		OPT_KEYVAL,	NULL },
-		{ "media",		OPT_KEYVAL,	NULL },
-		{ "name",		OPT_KEYVAL,	NULL },
+		{ "device",		NULL },
+		{ "media",		NULL },
+		{ "name",		NULL },
 		{ NULL }
 	};
-	struct tipc_sup_media sup_media[] = {
-		{ "udp",        "name",         cmd_bearer_set_udp_help},
-		{ "eth",        "device",       cmd_bearer_set_l2_help },
-		{ "ib",         "device",       cmd_bearer_set_l2_help },
-		{ NULL, },
-	};
 
 	if (strcmp(cmd->cmd, "priority") == 0)
 		prop = TIPC_NLA_PROP_PRIO;
@@ -650,11 +457,14 @@
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
-	else if ((strcmp(cmd->cmd, "mtu") == 0))
-		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
+	if (help_flag) {
+		(cmd->help)(cmdl);
+		return -EINVAL;
+	}
+
 	if (cmdl->optind >= cmdl->argc) {
 		fprintf(stderr, "error, missing value\n");
 		return -EINVAL;
@@ -664,17 +474,6 @@
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
-	if (prop == TIPC_NLA_PROP_MTU) {
-		char *media = cmd_get_media_type(cmd, cmdl, opts);
-
-		if (!media)
-			return -EINVAL;
-		else if (strcmp(media, "udp")) {
-			fprintf(stderr, "error, not supported for media\n");
-			return -EINVAL;
-		}
-	}
-
 	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
@@ -685,10 +484,30 @@
 	mnl_attr_put_u32(nlh, prop, val);
 	mnl_attr_nest_end(nlh, props);
 
-	err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
-	if (err)
-		return err;
+	if (!(opt = get_opt(opts, "media"))) {
+		fprintf(stderr, "error, missing media\n");
+		return -EINVAL;
+	}
+	media = opt->val;
 
+	if (strcmp(media, "udp") == 0) {
+		if (help_flag) {
+			cmd_bearer_set_udp_help(cmdl);
+			return -EINVAL;
+		}
+		if ((err = add_udp_bearer(nlh, opts)))
+			return err;
+	} else if ((strcmp(media, "eth") == 0) || (strcmp(media, "udp") == 0)) {
+		if (help_flag) {
+			cmd_bearer_set_l2_help(cmdl, media);
+			return -EINVAL;
+		}
+		if ((err = add_l2_bearer(nlh, opts)))
+			return err;
+	} else {
+		fprintf(stderr, "error, invalid media type \"%s\"\n", media);
+		return -EINVAL;
+	}
 	mnl_attr_nest_end(nlh, attrs);
 
 	return msg_doit(nlh, NULL, NULL);
@@ -701,7 +520,6 @@
 		{ "priority",	cmd_bearer_set_prop,	cmd_bearer_set_help },
 		{ "tolerance",	cmd_bearer_set_prop,	cmd_bearer_set_help },
 		{ "window",	cmd_bearer_set_prop,	cmd_bearer_set_help },
-		{ "mtu",	cmd_bearer_set_prop,	cmd_bearer_set_help },
 		{ NULL }
 	};
 
@@ -710,142 +528,27 @@
 
 static void cmd_bearer_get_help(struct cmdl *cmdl)
 {
-	fprintf(stderr, "Usage: %s bearer get [OPTION] media MEDIA ARGS...\n",
+	fprintf(stderr, "Usage: %s bearer get OPTION media MEDIA ARGS...\n",
 		cmdl->argv[0]);
 	_print_bearer_opts();
-	print_bearer_media();
+	_print_bearer_media();
 }
 
-static void cmd_bearer_get_udp_help(struct cmdl *cmdl, char *media)
+static void cmd_bearer_get_udp_help(struct cmdl *cmdl)
 {
-	fprintf(stderr, "Usage: %s bearer get [OPTION] media %s name NAME [UDP OPTIONS]\n\n",
-		cmdl->argv[0], media);
-	fprintf(stderr,
-		"UDP OPTIONS\n"
-		" remoteip              - Remote ip address\n"
-		" remoteport            - Remote port\n"
-		" localip               - Local ip address\n"
-		" localport             - Local port\n\n");
+	fprintf(stderr, "Usage: %s bearer get OPTION media udp name NAME\n\n",
+		cmdl->argv[0]);
 	_print_bearer_opts();
 }
 
 static void cmd_bearer_get_l2_help(struct cmdl *cmdl, char *media)
 {
 	fprintf(stderr,
-		"Usage: %s bearer get OPTION media %s device DEVICE\n",
+		"Usage: %s bearer get [OPTION]... media %s device DEVICE\n",
 		cmdl->argv[0], media);
 	_print_bearer_opts();
 }
 
-
-static int bearer_dump_udp_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct sockaddr_storage *addr;
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *info[TIPC_NLA_UDP_MAX + 1] = {};
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-
-	if (!info[TIPC_NLA_UDP_REMOTE])
-		return MNL_CB_ERROR;
-
-	addr = mnl_attr_get_payload(info[TIPC_NLA_UDP_REMOTE]);
-
-	if (addr->ss_family == AF_INET) {
-		struct sockaddr_in *ipv4 = (struct sockaddr_in *) addr;
-
-		printf("%s\n", inet_ntoa(ipv4->sin_addr));
-	} else if (addr->ss_family == AF_INET6) {
-		char straddr[INET6_ADDRSTRLEN];
-		struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) addr;
-
-		if (!inet_ntop(AF_INET6, &ipv6->sin6_addr, straddr,
-			       sizeof(straddr))) {
-			fprintf(stderr, "error, parsing IPv6 addr\n");
-			return MNL_CB_ERROR;
-		}
-		printf("%s\n", straddr);
-
-	} else {
-		return MNL_CB_ERROR;
-	}
-
-	return MNL_CB_OK;
-}
-
-static int bearer_get_udp_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct cb_data *cb_data = (struct cb_data *) data;
-	struct sockaddr_storage *addr;
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1] = {};
-	struct nlattr *opts[TIPC_NLA_UDP_MAX + 1] = {};
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-	if (!info[TIPC_NLA_BEARER])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(info[TIPC_NLA_BEARER], parse_attrs, attrs);
-	if (!attrs[TIPC_NLA_BEARER_UDP_OPTS])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(attrs[TIPC_NLA_BEARER_UDP_OPTS], parse_attrs, opts);
-	if (!opts[TIPC_NLA_UDP_LOCAL])
-		return MNL_CB_ERROR;
-
-	if ((cb_data->attr == TIPC_NLA_UDP_REMOTE) &&
-	    (cb_data->prop == UDP_PROP_IP) &&
-	    opts[TIPC_NLA_UDP_MULTI_REMOTEIP]) {
-		struct genlmsghdr *genl = mnl_nlmsg_get_payload(cb_data->nlh);
-
-		genl->cmd = TIPC_NL_UDP_GET_REMOTEIP;
-		return msg_dumpit(cb_data->nlh, bearer_dump_udp_cb, NULL);
-	}
-
-	addr = mnl_attr_get_payload(opts[cb_data->attr]);
-
-	if (addr->ss_family == AF_INET) {
-		struct sockaddr_in *ipv4 = (struct sockaddr_in *) addr;
-
-		switch (cb_data->prop) {
-		case UDP_PROP_IP:
-			printf("%s\n", inet_ntoa(ipv4->sin_addr));
-			break;
-		case UDP_PROP_PORT:
-			printf("%u\n", ntohs(ipv4->sin_port));
-			break;
-		default:
-			return MNL_CB_ERROR;
-		}
-
-	} else if (addr->ss_family == AF_INET6) {
-		char straddr[INET6_ADDRSTRLEN];
-		struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) addr;
-
-		switch (cb_data->prop) {
-		case UDP_PROP_IP:
-			if (!inet_ntop(AF_INET6, &ipv6->sin6_addr, straddr,
-				       sizeof(straddr))) {
-				fprintf(stderr, "error, parsing IPv6 addr\n");
-				return MNL_CB_ERROR;
-			}
-			printf("%s\n", straddr);
-			break;
-		case UDP_PROP_PORT:
-			printf("%u\n", ntohs(ipv6->sin6_port));
-			break;
-		default:
-			return MNL_CB_ERROR;
-		}
-
-	} else {
-		return MNL_CB_ERROR;
-	}
-
-	return MNL_CB_OK;
-}
-
 static int bearer_get_cb(const struct nlmsghdr *nlh, void *data)
 {
 	int *prop = data;
@@ -871,110 +574,21 @@
 	return MNL_CB_OK;
 }
 
-static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd,
-				struct cmdl *cmdl, void *data)
-{
-	int err;
-	char *media;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct opt *opt;
-	struct cb_data cb_data = {0};
-	struct nlattr *attrs;
-	struct opt opts[] = {
-		{ "localip",		OPT_KEY,	NULL },
-		{ "localport",		OPT_KEY,	NULL },
-		{ "remoteip",		OPT_KEY,	NULL },
-		{ "remoteport",		OPT_KEY,	NULL },
-		{ "name",		OPT_KEYVAL,	NULL },
-		{ "media",		OPT_KEYVAL,	NULL },
-		{ NULL }
-	};
-	struct tipc_sup_media sup_media[] = {
-		{ "udp",        "name",         cmd_bearer_get_udp_help},
-		{ NULL, },
-	};
-
-	/* Rewind optind to include media in the option list */
-	cmdl->optind--;
-	if (parse_opts(opts, cmdl) < 0)
-		return -EINVAL;
-
-	if (!(opt = get_opt(opts, "media"))) {
-		fprintf(stderr, "error, missing media value\n");
-		return -EINVAL;
-	}
-	media = opt->val;
-
-	if (help_flag) {
-		cmd_bearer_get_udp_help(cmdl, media);
-		return -EINVAL;
-	}
-	if (strcmp(media, "udp") != 0) {
-		fprintf(stderr, "error, no \"%s\" media specific options\n", media);
-		return -EINVAL;
-	}
-	if (!(opt = get_opt(opts, "name"))) {
-		fprintf(stderr, "error, missing media name\n");
-		return -EINVAL;
-	}
-
-	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
-	err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
-	if (err)
-		return err;
-	mnl_attr_nest_end(nlh, attrs);
-	cb_data.nlh = nlh;
-
-	if (has_opt(opts, "localip")) {
-		cb_data.attr = TIPC_NLA_UDP_LOCAL;
-		cb_data.prop = UDP_PROP_IP;
-		return msg_doit(nlh, bearer_get_udp_cb, &cb_data);
-	} else if (has_opt(opts, "localport")) {
-		cb_data.attr = TIPC_NLA_UDP_LOCAL;
-		cb_data.prop = UDP_PROP_PORT;
-		return msg_doit(nlh, bearer_get_udp_cb, &cb_data);
-	} else if (has_opt(opts, "remoteip")) {
-		cb_data.attr = TIPC_NLA_UDP_REMOTE;
-		cb_data.prop = UDP_PROP_IP;
-		return msg_doit(nlh, bearer_get_udp_cb, &cb_data);
-	} else if (has_opt(opts, "remoteport")) {
-		cb_data.attr = TIPC_NLA_UDP_REMOTE;
-		cb_data.prop = UDP_PROP_PORT;
-		return msg_doit(nlh, bearer_get_udp_cb, &cb_data);
-	}
-	fprintf(stderr, "error, missing UDP option\n");
-	return -EINVAL;
-}
-
 static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 			       struct cmdl *cmdl, void *data)
 {
 	int err;
 	int prop;
+	char *media;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlattr *attrs;
+	struct opt *opt;
 	struct opt opts[] = {
-		{ "device",		OPT_KEYVAL,	NULL },
-		{ "media",		OPT_KEYVAL,	NULL },
-		{ "name",		OPT_KEYVAL,	NULL },
+		{ "device",		NULL },
+		{ "media",		NULL },
+		{ "name",		NULL },
 		{ NULL }
 	};
-	struct tipc_sup_media sup_media[] = {
-		{ "udp",        "name",         cmd_bearer_get_udp_help},
-		{ "eth",        "device",       cmd_bearer_get_l2_help },
-		{ "ib",         "device",       cmd_bearer_get_l2_help },
-		{ NULL, },
-	};
-
-	if (help_flag) {
-		(cmd->help)(cmdl);
-		return -EINVAL;
-	}
 
 	if (strcmp(cmd->cmd, "priority") == 0)
 		prop = TIPC_NLA_PROP_PRIO;
@@ -982,34 +596,47 @@
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
-	else if ((strcmp(cmd->cmd, "mtu") == 0))
-		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
+	if (help_flag) {
+		(cmd->help)(cmdl);
+		return -EINVAL;
+	}
+
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
-	if (prop == TIPC_NLA_PROP_MTU) {
-		char *media = cmd_get_media_type(cmd, cmdl, opts);
-
-		if (!media)
-			return -EINVAL;
-		else if (strcmp(media, "udp")) {
-			fprintf(stderr, "error, not supported for media\n");
-			return -EINVAL;
-		}
-	}
-
 	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
 
+	if (!(opt = get_opt(opts, "media"))) {
+		fprintf(stderr, "error, missing media\n");
+		return -EINVAL;
+	}
+	media = opt->val;
+
 	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
-	err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
-	if (err)
-		return err;
+	if (strcmp(media, "udp") == 0) {
+		if (help_flag) {
+			cmd_bearer_get_udp_help(cmdl);
+			return -EINVAL;
+		}
+		if ((err = add_udp_bearer(nlh, opts)))
+			return err;
+	} else if ((strcmp(media, "eth") == 0) || (strcmp(media, "udp") == 0)) {
+		if (help_flag) {
+			cmd_bearer_get_l2_help(cmdl, media);
+			return -EINVAL;
+		}
+		if ((err = add_l2_bearer(nlh, opts)))
+			return err;
+	} else {
+		fprintf(stderr, "error, invalid media type \"%s\"\n", media);
+		return -EINVAL;
+	}
 	mnl_attr_nest_end(nlh, attrs);
 
 	return msg_doit(nlh, bearer_get_cb, &prop);
@@ -1022,8 +649,6 @@
 		{ "priority",	cmd_bearer_get_prop,	cmd_bearer_get_help },
 		{ "tolerance",	cmd_bearer_get_prop,	cmd_bearer_get_help },
 		{ "window",	cmd_bearer_get_prop,	cmd_bearer_get_help },
-		{ "mtu",	cmd_bearer_get_prop,	cmd_bearer_get_help },
-		{ "media",	cmd_bearer_get_media,	cmd_bearer_get_help },
 		{ NULL }
 	};
 
@@ -1077,19 +702,17 @@
 		"Usage: %s bearer COMMAND [ARGS] ...\n"
 		"\n"
 		"COMMANDS\n"
-		" add			- Add data to existing bearer\n"
-		" enable		- Enable a bearer\n"
-		" disable		- Disable a bearer\n"
-		" set			- Set various bearer properties\n"
-		" get			- Get various bearer properties\n"
-		" list			- List bearers\n", cmdl->argv[0]);
+		" enable                - Enable a bearer\n"
+		" disable               - Disable a bearer\n"
+		" set                   - Set various bearer properties\n"
+		" get                   - Get various bearer properties\n"
+		" list                  - List bearers\n", cmdl->argv[0]);
 }
 
 int cmd_bearer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
 	       void *data)
 {
 	const struct cmd cmds[] = {
-		{ "add",	cmd_bearer_add,		cmd_bearer_add_help },
 		{ "disable",	cmd_bearer_disable,	cmd_bearer_disable_help },
 		{ "enable",	cmd_bearer_enable,	cmd_bearer_enable_help },
 		{ "get",	cmd_bearer_get,		cmd_bearer_get_help },
diff --git a/tipc/bearer.h b/tipc/bearer.h
index c0d0996..9459d65 100644
--- a/tipc/bearer.h
+++ b/tipc/bearer.h
@@ -19,8 +19,4 @@
 int cmd_bearer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data);
 void cmd_bearer_help(struct cmdl *cmdl);
 
-void print_bearer_media(void);
-int cmd_get_unique_bearer_name(const struct cmd *cmd, struct cmdl *cmdl,
-			       struct opt *opts, char *bname,
-			       const struct tipc_sup_media *sup_media);
 #endif
diff --git a/tipc/cmdl.c b/tipc/cmdl.c
index f2f259c..b816f7d 100644
--- a/tipc/cmdl.c
+++ b/tipc/cmdl.c
@@ -17,7 +17,7 @@
 
 #include "cmdl.h"
 
-static const struct cmd *find_cmd(const struct cmd *cmds, char *str)
+const struct cmd *find_cmd(const struct cmd *cmds, char *str)
 {
 	const struct cmd *c;
 	const struct cmd *match = NULL;
@@ -62,11 +62,6 @@
 	return NULL;
 }
 
-bool has_opt(struct opt *opts, char *key)
-{
-	return get_opt(opts, key) ? true : false;
-}
-
 char *shift_cmdl(struct cmdl *cmdl)
 {
 	int next;
@@ -85,7 +80,7 @@
 	int i;
 	int cnt = 0;
 
-	for (i = cmdl->optind; i < cmdl->argc; i++) {
+	for (i = cmdl->optind; i < cmdl->argc; i += 2) {
 		struct opt *o;
 
 		o = find_opt(opts, cmdl->argv[i]);
@@ -94,13 +89,9 @@
 					cmdl->argv[i]);
 			return -EINVAL;
 		}
-		if (o->flag & OPT_KEYVAL) {
-			cmdl->optind++;
-			i++;
-		}
 		cnt++;
-		o->val = cmdl->argv[i];
-		cmdl->optind++;
+		o->val = cmdl->argv[i + 1];
+		cmdl->optind += 2;
 	}
 
 	return cnt;
diff --git a/tipc/cmdl.h b/tipc/cmdl.h
index 03db359..9f2666f 100644
--- a/tipc/cmdl.h
+++ b/tipc/cmdl.h
@@ -16,23 +16,12 @@
 
 extern int help_flag;
 
-enum {
-	OPT_KEY			= (1 << 0),
-	OPT_KEYVAL		= (1 << 1),
-};
-
 struct cmdl {
 	int optind;
 	int argc;
 	char **argv;
 };
 
-struct tipc_sup_media {
-	char *media;
-	char *identifier;
-	void (*help)(struct cmdl *cmdl, char *media);
-};
-
 struct cmd {
 	const char *cmd;
 	int (*func)(struct nlmsghdr *nlh, const struct cmd *cmd,
@@ -42,16 +31,16 @@
 
 struct opt {
 	const char *key;
-	uint16_t flag;
 	char *val;
 };
 
 struct opt *get_opt(struct opt *opts, char *key);
-bool has_opt(struct opt *opts, char *key);
 int parse_opts(struct opt *opts, struct cmdl *cmdl);
 char *shift_cmdl(struct cmdl *cmdl);
 
 int run_cmd(struct nlmsghdr *nlh, const struct cmd *caller,
 	    const struct cmd *cmds, struct cmdl *cmdl, void *data);
 
+const struct cmd *find_cmd(const struct cmd *cmds, char *str);
+
 #endif
diff --git a/tipc/link.c b/tipc/link.c
index e123c18..89fb4ff 100644
--- a/tipc/link.c
+++ b/tipc/link.c
@@ -22,15 +22,6 @@
 #include "cmdl.h"
 #include "msg.h"
 #include "link.h"
-#include "bearer.h"
-#include "utils.h"
-
-#define PRIORITY_STR "priority"
-#define TOLERANCE_STR "tolerance"
-#define WINDOW_STR "window"
-#define BROADCAST_STR "broadcast"
-
-static const char tipc_bclink_name[] = "broadcast-link";
 
 static int link_list_cb(const struct nlmsghdr *nlh, void *data)
 {
@@ -46,14 +37,13 @@
 	if (!attrs[TIPC_NLA_LINK_NAME])
 		return MNL_CB_ERROR;
 
-	print_string(PRINT_FP, NULL, "%s: ",
-			     mnl_attr_get_str(attrs[TIPC_NLA_LINK_NAME]));
+	printf("%s: ", mnl_attr_get_str(attrs[TIPC_NLA_LINK_NAME]));
+
 	if (attrs[TIPC_NLA_LINK_UP])
-		print_string(PRINT_ANY,
-			 mnl_attr_get_str(attrs[TIPC_NLA_LINK_NAME]),"%s\n", "up");
+		printf("up\n");
 	else
-		print_string(PRINT_ANY,
-			 mnl_attr_get_str(attrs[TIPC_NLA_LINK_NAME]), "%s\n", "down");
+		printf("down\n");
+
 	return MNL_CB_OK;
 }
 
@@ -61,25 +51,18 @@
 			 struct cmdl *cmdl, void *data)
 {
 	char buf[MNL_SOCKET_BUFFER_SIZE];
-	int err = 0;
 
 	if (help_flag) {
 		fprintf(stderr, "Usage: %s link list\n", cmdl->argv[0]);
 		return -EINVAL;
 	}
 
-	nlh = msg_init(buf, TIPC_NL_LINK_GET);
-	if (!nlh) {
+	if (!(nlh = msg_init(buf, TIPC_NL_LINK_GET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
 
-	new_json_obj(json);
-	open_json_object(NULL);
-	err = msg_dumpit(nlh, link_list_cb, NULL);
-	close_json_object();
-	delete_json_obj();
-	return err;
+	return msg_dumpit(nlh, link_list_cb, NULL);
 }
 
 static int link_get_cb(const struct nlmsghdr *nlh, void *data)
@@ -102,43 +85,28 @@
 	if (!props[*prop])
 		return MNL_CB_ERROR;
 
-	new_json_obj(json);
-	open_json_object(NULL);
-	switch (*prop) {
-		case TIPC_NLA_PROP_PRIO:
-			print_uint(PRINT_ANY, PRIORITY_STR, "%u\n", mnl_attr_get_u32(props[*prop]));
-		break;
-		case TIPC_NLA_PROP_TOL:
-			print_uint(PRINT_ANY, TOLERANCE_STR, "%u\n", mnl_attr_get_u32(props[*prop]));
-		break;
-		case TIPC_NLA_PROP_WIN:
-			print_uint(PRINT_ANY, WINDOW_STR, "%u\n", mnl_attr_get_u32(props[*prop]));
-		break;
-		default:
-			break;
-	}
-	close_json_object();
-	delete_json_obj();
+	printf("%u\n", mnl_attr_get_u32(props[*prop]));
+
 	return MNL_CB_OK;
 }
 
+
 static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 			     struct cmdl *cmdl, void *data)
 {
 	int prop;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlattr *attrs;
 	struct opt *opt;
 	struct opt opts[] = {
-		{ "link",		OPT_KEYVAL,	NULL },
+		{ "link",		NULL },
 		{ NULL }
 	};
 
-	if (strcmp(cmd->cmd, PRIORITY_STR) == 0)
+	if (strcmp(cmd->cmd, "priority") == 0)
 		prop = TIPC_NLA_PROP_PRIO;
-	else if ((strcmp(cmd->cmd, TOLERANCE_STR) == 0))
+	else if ((strcmp(cmd->cmd, "tolerance") == 0))
 		prop = TIPC_NLA_PROP_TOL;
-	else if ((strcmp(cmd->cmd, WINDOW_STR) == 0))
+	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
 	else
 		return -EINVAL;
@@ -151,20 +119,16 @@
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
-	nlh = msg_init(buf, TIPC_NL_LINK_GET);
-	if (!nlh) {
+	if (!(nlh = msg_init(buf, TIPC_NL_LINK_GET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
 
-	opt = get_opt(opts, "link");
-	if (!opt) {
+	if (!(opt = get_opt(opts, "link"))) {
 		fprintf(stderr, "error, missing link\n");
 		return -EINVAL;
 	}
-	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
 	mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, opt->val);
-	mnl_attr_nest_end(nlh, attrs);
 
 	return msg_doit(nlh, link_get_cb, &prop);
 }
@@ -175,100 +139,17 @@
 		"PROPERTIES\n"
 		" tolerance             - Get link tolerance\n"
 		" priority              - Get link priority\n"
-		" window                - Get link window\n"
-		" broadcast             - Get link broadcast\n",
+		" window                - Get link window\n",
 		cmdl->argv[0]);
 }
 
-static int cmd_link_get_bcast_cb(const struct nlmsghdr *nlh, void *data)
-{
-	int *prop = data;
-	int prop_ratio = TIPC_NLA_PROP_BROADCAST_RATIO;
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1] = {};
-	struct nlattr *props[TIPC_NLA_PROP_MAX + 1] = {};
-	int bc_mode;
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-	if (!info[TIPC_NLA_LINK])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(info[TIPC_NLA_LINK], parse_attrs, attrs);
-	if (!attrs[TIPC_NLA_LINK_PROP])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(attrs[TIPC_NLA_LINK_PROP], parse_attrs, props);
-	if (!props[*prop])
-		return MNL_CB_ERROR;
-
-	bc_mode = mnl_attr_get_u32(props[*prop]);
-
-	new_json_obj(json);
-	open_json_object(NULL);
-	switch (bc_mode) {
-	case 0x1:
-		print_string(PRINT_ANY, "method", "%s\n", "BROADCAST");
-		break;
-	case 0x2:
-		print_string(PRINT_ANY, "method", "%s\n", "REPLICAST");
-		break;
-	case 0x4:
-		print_string(PRINT_ANY, "method", "%s", "AUTOSELECT");
-		close_json_object();
-		open_json_object(NULL);
-		print_uint(PRINT_ANY, "ratio", " ratio:%u%\n",
-			   mnl_attr_get_u32(props[prop_ratio]));
-		break;
-	default:
-		print_string(PRINT_ANY, NULL, "UNKNOWN\n", NULL);
-		break;
-	}
-	close_json_object();
-	delete_json_obj();
-	return MNL_CB_OK;
-}
-
-static void cmd_link_get_bcast_help(struct cmdl *cmdl)
-{
-	fprintf(stderr, "Usage: %s link get PPROPERTY\n\n"
-		"PROPERTIES\n"
-		" broadcast             - Get link broadcast\n",
-		cmdl->argv[0]);
-}
-
-static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd,
-			     struct cmdl *cmdl, void *data)
-{
-	int prop = TIPC_NLA_PROP_BROADCAST;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlattr *attrs;
-
-	if (help_flag) {
-		(cmd->help)(cmdl);
-		return -EINVAL;
-	}
-
-	nlh = msg_init(buf, TIPC_NL_LINK_GET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
-	/* Direct to broadcast-link setting */
-	mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, tipc_bclink_name);
-	mnl_attr_nest_end(nlh, attrs);
-	return msg_doit(nlh, cmd_link_get_bcast_cb, &prop);
-}
-
 static int cmd_link_get(struct nlmsghdr *nlh, const struct cmd *cmd,
 			struct cmdl *cmdl, void *data)
 {
 	const struct cmd cmds[] = {
-		{ PRIORITY_STR,	cmd_link_get_prop,	cmd_link_get_help },
-		{ TOLERANCE_STR,	cmd_link_get_prop,	cmd_link_get_help },
-		{ WINDOW_STR,	cmd_link_get_prop,	cmd_link_get_help },
-		{ BROADCAST_STR, cmd_link_get_bcast, cmd_link_get_bcast_help },
+		{ "priority",	cmd_link_get_prop,	cmd_link_get_help },
+		{ "tolerance",	cmd_link_get_prop,	cmd_link_get_help },
+		{ "window",	cmd_link_get_prop,	cmd_link_get_help },
 		{ NULL }
 	};
 
@@ -288,7 +169,7 @@
 	struct opt *opt;
 	struct nlattr *nest;
 	struct opt opts[] = {
-		{ "link",		OPT_KEYVAL,	NULL },
+		{ "link",		NULL },
 		{ NULL }
 	};
 
@@ -302,14 +183,12 @@
 		return -EINVAL;
 	}
 
-	nlh = msg_init(buf, TIPC_NL_LINK_RESET_STATS);
-	if (!nlh) {
+	if (!(nlh = msg_init(buf, TIPC_NL_LINK_RESET_STATS))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
 
-	opt = get_opt(opts, "link");
-	if (!opt) {
+	if (!(opt = get_opt(opts, "link"))) {
 		fprintf(stderr, "error, missing link\n");
 		return -EINVAL;
 	}
@@ -327,178 +206,110 @@
 	return (count * 100 + (total / 2)) / total;
 }
 
-static int _show_link_stat(const char *name, struct nlattr *attrs[],
-			   struct nlattr *prop[], struct nlattr *stats[])
+static int _show_link_stat(struct nlattr *attrs[], struct nlattr *prop[],
+			   struct nlattr *stats[])
 {
 	uint32_t proft;
 
-	open_json_object(NULL);
-
-	print_string(PRINT_ANY, "link", "\nLink <%s>\n", name);
-	print_string(PRINT_JSON, "state", "", NULL);
-	open_json_array(PRINT_JSON, NULL);
 	if (attrs[TIPC_NLA_LINK_ACTIVE])
-		print_string(PRINT_ANY, NULL, "  %s", "ACTIVE");
+		printf("  ACTIVE");
 	else if (attrs[TIPC_NLA_LINK_UP])
-		print_string(PRINT_ANY, NULL, "  %s", "STANDBY");
+		printf("  STANDBY");
 	else
-		print_string(PRINT_ANY, NULL, "  %s", "DEFUNCT");
-	close_json_array(PRINT_JSON, NULL);
+		printf("  DEFUNCT");
 
-	print_uint(PRINT_ANY, "mtu", "  MTU:%u",
-			   mnl_attr_get_u32(attrs[TIPC_NLA_LINK_MTU]));
-	print_uint(PRINT_ANY, PRIORITY_STR, "  Priority:%u",
-			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_PRIO]));
-	print_uint(PRINT_ANY, TOLERANCE_STR, "  Tolerance:%u ms",
-			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_TOL]));
-	print_uint(PRINT_ANY, WINDOW_STR, "  Window:%u packets\n",
-			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));
+	printf("  MTU:%u  Priority:%u  Tolerance:%u ms  Window:%u packets\n",
+	       mnl_attr_get_u32(attrs[TIPC_NLA_LINK_MTU]),
+	       mnl_attr_get_u32(prop[TIPC_NLA_PROP_PRIO]),
+	       mnl_attr_get_u32(prop[TIPC_NLA_PROP_TOL]),
+	       mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));
 
-	open_json_object("rx packets");
-	print_uint(PRINT_ANY, "rx packets", "  RX packets:%u",
-			   mnl_attr_get_u32(attrs[TIPC_NLA_LINK_RX]) -
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_INFO]));
-	print_uint(PRINT_ANY, "fragments", " fragments:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]));
-	print_uint(PRINT_ANY, "fragmented", "/%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]));
-	print_uint(PRINT_ANY, "bundles", " bundles:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]));
-	print_uint(PRINT_ANY, "bundled", "/%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
-	close_json_object();
+	printf("  RX packets:%u fragments:%u/%u bundles:%u/%u\n",
+	       mnl_attr_get_u32(attrs[TIPC_NLA_LINK_RX]) -
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_INFO]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
 
-	open_json_object("tx packets");
-	print_uint(PRINT_ANY, "tx packets", "  TX packets:%u",
-			   mnl_attr_get_u32(attrs[TIPC_NLA_LINK_TX]) -
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_INFO]));
-	print_uint(PRINT_ANY, "fragments", " fragments:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]));
-	print_uint(PRINT_ANY, "fragmented", "/%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]));
-	print_uint(PRINT_ANY, "bundles", " bundles:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]));
-	print_uint(PRINT_ANY, "bundled", "/%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
-	close_json_object();
+	printf("  TX packets:%u fragments:%u/%u bundles:%u/%u\n",
+	       mnl_attr_get_u32(attrs[TIPC_NLA_LINK_TX]) -
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_INFO]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
 
 	proft = mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT]);
-	print_uint(PRINT_ANY, "tx profile sample", "  TX profile sample:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_CNT]));
-	print_uint(PRINT_ANY, "packets average", " packets average:%u octets\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_TOT]) / proft);
+	printf("  TX profile sample:%u packets  average:%u octets\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_CNT]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_TOT]) / proft);
 
-	print_uint(PRINT_ANY, "0-64", "  0-64:%u%%",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P0]), proft));
-	print_uint(PRINT_ANY, "-256", " -256:%u%%",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P1]), proft));
-	print_uint(PRINT_ANY, "-1024", " -1024:%u%%",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P2]), proft));
-	print_uint(PRINT_ANY, "-4096", " -4096:%u%%",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P3]), proft));
-	print_uint(PRINT_ANY, "-16384", " -16384:%u%%",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P4]), proft));
-	print_uint(PRINT_ANY, "-32768", " -32768:%u%%",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P5]), proft));
-	print_uint(PRINT_ANY, "-66000", " -66000:%u%%\n",
-			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P6]), proft));
+	printf("  0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
+	       "-16384:%u%% -32768:%u%% -66000:%u%%\n",
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P0]), proft),
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P1]), proft),
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P2]), proft),
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P3]), proft),
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P4]), proft),
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P5]), proft),
+	       perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P6]), proft));
 
-	open_json_object("rx states");
-	print_uint(PRINT_ANY, "rx states", "  RX states:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_STATES]));
-	print_uint(PRINT_ANY, "probes", " probes:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_PROBES]));
-	print_uint(PRINT_ANY, "naks", " naks:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]));
-	print_uint(PRINT_ANY, "defs", " defs:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]));
-	print_uint(PRINT_ANY, "dups", " dups:%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
-	close_json_object();
+	printf("  RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_STATES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_PROBES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
 
-	open_json_object("tx states");
-	print_uint(PRINT_ANY, "tx states", "  TX states:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_STATES]));
-	print_uint(PRINT_ANY, "probes", " probes:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_PROBES]));
-	print_uint(PRINT_ANY, "naks", " naks:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]));
-	print_uint(PRINT_ANY, "acks", " acks:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]));
-	print_uint(PRINT_ANY, "retrans", " retrans:%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
-	close_json_object();
+	printf("  TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_STATES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_PROBES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
 
-	print_uint(PRINT_ANY, "congestion link", "  Congestion link:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]));
-	print_uint(PRINT_ANY, "send queue max", "  Send queue max:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]));
-	print_uint(PRINT_ANY, "avg", " avg:%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
+	printf("  Congestion link:%u  Send queue max:%u avg:%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
 
-	close_json_object();
 	return MNL_CB_OK;
 }
 
-static int _show_bc_link_stat(const char *name, struct nlattr *prop[],
-			   struct nlattr *stats[])
+static int _show_bc_link_stat(struct nlattr *prop[], struct nlattr *stats[])
 {
-	open_json_object(NULL);
-	print_string(PRINT_ANY, "link", "Link <%s>\n", name);
-	print_uint(PRINT_ANY, WINDOW_STR, "  Window:%u packets\n",
-			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));
+	printf("  Window:%u packets\n",
+	       mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));
 
-	open_json_object("rx packets");
-	print_uint(PRINT_ANY, "rx packets", "  RX packets:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_INFO]));
-	print_uint(PRINT_ANY, "fragments", " fragments:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]));
-	print_uint(PRINT_ANY, "fragmented", "/%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]));
-	print_uint(PRINT_ANY, "bundles", " bundles:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]));
-	print_uint(PRINT_ANY, "bundled", "/%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
-	close_json_object();
+	printf("  RX packets:%u fragments:%u/%u bundles:%u/%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_INFO]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
 
-	open_json_object("tx packets");
-	print_uint(PRINT_ANY, "tx packets", "  TX packets:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_INFO]));
-	print_uint(PRINT_ANY, "fragments", " fragments:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]));
-	print_uint(PRINT_ANY, "fragmented", "/%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]));
-	print_uint(PRINT_ANY, "bundles", " bundles:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]));
-	print_uint(PRINT_ANY, "bundled", "/%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
-	close_json_object();
+	printf("  TX packets:%u fragments:%u/%u bundles:%u/%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_INFO]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
 
-	open_json_object("rx naks");
-	print_uint(PRINT_ANY, "rx naks", "  RX naks:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]));
-	print_uint(PRINT_ANY, "defs",  " defs:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]));
-	print_uint(PRINT_ANY, "dups",  " dups:%u\n",
-		   mnl_attr_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
-	close_json_object();
+	printf("  RX naks:%u defs:%u dups:%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
 
-	open_json_object("tx naks");
-	print_uint(PRINT_ANY, "tx naks", "  TX naks:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]));
-	print_uint(PRINT_ANY, "acks",  " acks:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]));
-	print_uint(PRINT_ANY, "retrans",  " retrans:%u\n",
-		   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
-	close_json_object();
+	printf("  TX naks:%u acks:%u dups:%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
 
-	print_uint(PRINT_ANY, "congestion link", "  Congestion link:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]));
-	print_uint(PRINT_ANY, "send queue max", "  Send queue max:%u",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]));
-	print_uint(PRINT_ANY, "avg", " avg:%u\n",
-			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
-	close_json_object();
+	printf("  Congestion link:%u  Send queue max:%u avg:%u\n",
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]),
+	       mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
 
 	return MNL_CB_OK;
 }
@@ -532,10 +343,13 @@
 		return MNL_CB_OK;
 
 	if (attrs[TIPC_NLA_LINK_BROADCAST]) {
-		return _show_bc_link_stat(name, prop, stats);
+		printf("Link <%s>\n", name);
+		return _show_bc_link_stat(prop, stats);
 	}
 
-	return _show_link_stat(name, attrs, prop, stats);
+	printf("\nLink <%s>\n", name);
+
+	return _show_link_stat(attrs, prop, stats);
 }
 
 static void cmd_link_stat_show_help(struct cmdl *cmdl)
@@ -551,18 +365,16 @@
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct opt *opt;
 	struct opt opts[] = {
-		{ "link",		OPT_KEYVAL,	NULL },
+		{ "link",		NULL },
 		{ NULL }
 	};
-	int err = 0;
 
 	if (help_flag) {
 		(cmd->help)(cmdl);
 		return -EINVAL;
 	}
 
-	nlh = msg_init(buf, TIPC_NL_LINK_GET);
-	if (!nlh) {
+	if (!(nlh = msg_init(buf, TIPC_NL_LINK_GET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
@@ -570,14 +382,10 @@
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
-	opt = get_opt(opts, "link");
-	if (opt)
+	if ((opt = get_opt(opts, "link")))
 		link = opt->val;
 
-	new_json_obj(json);
-	err = msg_dumpit(nlh, link_stat_show_cb, link);
-	delete_json_obj();
-	return err;
+	return msg_dumpit(nlh, link_stat_show_cb, link);
 }
 
 static void cmd_link_stat_help(struct cmdl *cmdl)
@@ -607,8 +415,7 @@
 		"PROPERTIES\n"
 		" tolerance TOLERANCE   - Set link tolerance\n"
 		" priority PRIORITY     - Set link priority\n"
-		" window WINDOW         - Set link window\n"
-		" broadcast BROADCAST   - Set link broadcast\n",
+		" window WINDOW         - Set link window\n",
 		cmdl->argv[0]);
 }
 
@@ -622,15 +429,15 @@
 	struct nlattr *attrs;
 	struct opt *opt;
 	struct opt opts[] = {
-		{ "link",		OPT_KEYVAL,	NULL },
+		{ "link",	NULL },
 		{ NULL }
 	};
 
-	if (strcmp(cmd->cmd, PRIORITY_STR) == 0)
+	if (strcmp(cmd->cmd, "priority") == 0)
 		prop = TIPC_NLA_PROP_PRIO;
-	else if ((strcmp(cmd->cmd, TOLERANCE_STR) == 0))
+	else if ((strcmp(cmd->cmd, "tolerance") == 0))
 		prop = TIPC_NLA_PROP_TOL;
-	else if ((strcmp(cmd->cmd, WINDOW_STR) == 0))
+	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
 	else
 		return -EINVAL;
@@ -649,15 +456,13 @@
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
-	nlh = msg_init(buf, TIPC_NL_LINK_SET);
-	if (!nlh) {
+	if (!(nlh = msg_init(buf, TIPC_NL_LINK_SET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
 	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
 
-	opt = get_opt(opts, "link");
-	if (!opt) {
+	if (!(opt = get_opt(opts, "link"))) {
 		fprintf(stderr, "error, missing link\n");
 		return -EINVAL;
 	}
@@ -670,545 +475,17 @@
 	mnl_attr_nest_end(nlh, attrs);
 
 	return msg_doit(nlh, link_get_cb, &prop);
-}
 
-static void cmd_link_set_bcast_help(struct cmdl *cmdl)
-{
-	fprintf(stderr, "Usage: %s link set broadcast PROPERTY\n\n"
-		"PROPERTIES\n"
-		" BROADCAST         - Forces all multicast traffic to be\n"
-		"                     transmitted via broadcast only,\n"
-		"                     irrespective of cluster size and number\n"
-		"                     of destinations\n\n"
-		" REPLICAST         - Forces all multicast traffic to be\n"
-		"                     transmitted via replicast only,\n"
-		"                     irrespective of cluster size and number\n"
-		"                     of destinations\n\n"
-		" AUTOSELECT        - Auto switching to broadcast or replicast\n"
-		"                     depending on cluster size and destination\n"
-		"                     node number\n\n"
-		" ratio SIZE        - Set the AUTOSELECT criteria, percentage of\n"
-		"                     destination nodes vs cluster size\n\n",
-		cmdl->argv[0]);
-}
-
-static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd,
-			     struct cmdl *cmdl, void *data)
-{
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlattr *props;
-	struct nlattr *attrs;
-	struct opt *opt;
-	struct opt opts[] = {
-		{ "BROADCAST",	OPT_KEY, NULL },
-		{ "REPLICAST",	OPT_KEY, NULL },
-		{ "AUTOSELECT",	OPT_KEY, NULL },
-		{ "ratio",	OPT_KEYVAL,	NULL },
-		{ NULL }
-	};
-	int method = 0;
-
-	if (help_flag) {
-		(cmd->help)(cmdl);
-		return -EINVAL;
-	}
-
-	if (parse_opts(opts, cmdl) < 0)
-		return -EINVAL;
-
-	for (opt = opts; opt->key; opt++)
-		if (opt->val)
-			break;
-
-	if (!opt || !opt->key) {
-		(cmd->help)(cmdl);
-		return -EINVAL;
-	}
-
-	nlh = msg_init(buf, TIPC_NL_LINK_SET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
-	/* Direct to broadcast-link setting */
-	mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, tipc_bclink_name);
-	props = mnl_attr_nest_start(nlh, TIPC_NLA_LINK_PROP);
-
-	if (get_opt(opts, "BROADCAST"))
-		method = 0x1;
-	else if (get_opt(opts, "REPLICAST"))
-		method = 0x2;
-	else if (get_opt(opts, "AUTOSELECT"))
-		method = 0x4;
-
-	opt = get_opt(opts, "ratio");
-	if (!method && !opt) {
-		(cmd->help)(cmdl);
-		return -EINVAL;
-	}
-
-	if (method)
-		mnl_attr_put_u32(nlh, TIPC_NLA_PROP_BROADCAST, method);
-
-	if (opt)
-		mnl_attr_put_u32(nlh, TIPC_NLA_PROP_BROADCAST_RATIO,
-				 atoi(opt->val));
-
-	mnl_attr_nest_end(nlh, props);
-	mnl_attr_nest_end(nlh, attrs);
-	return msg_doit(nlh, NULL, NULL);
+	return 0;
 }
 
 static int cmd_link_set(struct nlmsghdr *nlh, const struct cmd *cmd,
 			struct cmdl *cmdl, void *data)
 {
 	const struct cmd cmds[] = {
-		{ PRIORITY_STR,	cmd_link_set_prop,	cmd_link_set_help },
-		{ TOLERANCE_STR,	cmd_link_set_prop,	cmd_link_set_help },
-		{ WINDOW_STR,	cmd_link_set_prop,	cmd_link_set_help },
-		{ BROADCAST_STR, cmd_link_set_bcast, cmd_link_set_bcast_help },
-		{ NULL }
-	};
-
-	return run_cmd(nlh, cmd, cmds, cmdl, NULL);
-}
-
-static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
-				 struct cmdl *cmdl, void *data)
-{
-	int size;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlattr *attrs;
-
-	if (cmdl->argc != cmdl->optind + 1) {
-		fprintf(stderr, "error, missing value\n");
-		return -EINVAL;
-	}
-	size = atoi(shift_cmdl(cmdl));
-
-	nlh = msg_init(buf, TIPC_NL_MON_SET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_MON);
-
-	mnl_attr_put_u32(nlh, TIPC_NLA_MON_ACTIVATION_THRESHOLD, size);
-
-	mnl_attr_nest_end(nlh, attrs);
-
-	return msg_doit(nlh, NULL, NULL);
-}
-
-static int link_mon_summary_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-	if (!info[TIPC_NLA_MON])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);
-
-	open_json_object(NULL);
-	print_string(PRINT_ANY, "bearer", "\nbearer %s\n",
-		mnl_attr_get_str(attrs[TIPC_NLA_MON_BEARER_NAME]));
-
-	print_uint(PRINT_ANY, "table_generation", "    table_generation %u\n",
-	       mnl_attr_get_u32(attrs[TIPC_NLA_MON_LISTGEN]));
-	print_uint(PRINT_ANY, "cluster_size", "    cluster_size %u\n",
-		mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEERCNT]));
-	print_string(PRINT_ANY, "algorithm", "    algorithm %s\n",
-		attrs[TIPC_NLA_MON_ACTIVE] ? "overlapping-ring" : "full-mesh");
-	close_json_object();
-
-	return MNL_CB_OK;
-}
-
-static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd,
-				struct cmdl *cmdl, void *data)
-{
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	int err = 0;
-
-	if (help_flag) {
-		fprintf(stderr,	"Usage: %s monitor summary\n", cmdl->argv[0]);
-		return -EINVAL;
-	}
-
-	nlh = msg_init(buf, TIPC_NL_MON_GET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	new_json_obj(json);
-	err = msg_dumpit(nlh, link_mon_summary_cb, NULL);
-	delete_json_obj();
-
-	return err;
-}
-
-#define STATUS_WIDTH 7
-#define MAX_NODE_WIDTH 14 /* 255.4095.4095 */
-#define MAX_DOM_GEN_WIDTH 11 /* 65535 */
-#define DIRECTLY_MON_WIDTH 10
-
-#define APPL_NODE_STATUS_WIDTH 5
-
-static int map_get(uint64_t up_map, int i)
-{
-	return (up_map & (1 << i)) >> i;
-}
-
-/* print the applied members, since we know the the members
- * are listed in ascending order, we print only the state
- */
-static void link_mon_print_applied(uint16_t applied, uint64_t up_map)
-{
-	int i;
-
-	open_json_array(PRINT_JSON, "applied_node_status");
-	for (i = 0; i < applied; i++) {
-		char state_str[2] = {0};
-
-		/* print the delimiter for every -n- entry */
-		if (i && !(i % APPL_NODE_STATUS_WIDTH))
-			print_string(PRINT_FP, NULL, "%s", ",");
-
-		sprintf(state_str, "%c", map_get(up_map, i) ? 'U' : 'D');
-		print_string(PRINT_ANY, NULL, "%s", state_str);
-	}
-	close_json_array(PRINT_JSON, "applied_node_status");
-}
-
-/* print the non applied members, since we don't know
- * the members, we print them along with the state
- */
-static void link_mon_print_non_applied(uint16_t applied, uint16_t member_cnt,
-				       uint64_t up_map,  uint32_t *members)
-{
-	int i;
-	char state;
-
-	open_json_array(PRINT_JSON, "[non_applied_node:status]");
-	print_string(PRINT_FP, NULL, " %s", "[");
-	for (i = applied; i < member_cnt; i++) {
-		char addr_str[16];
-		char full_state[17] = {0};
-
-		/* print the delimiter for every entry */
-		if (i != applied)
-			print_string(PRINT_FP, NULL, "%s", ",");
-
-		sprintf(addr_str, "%x:", members[i]);
-		state = map_get(up_map, i) ? 'U' : 'D';
-		sprintf(full_state, "%s%c", addr_str, state);
-		print_string(PRINT_ANY, NULL, "%s", full_state);
-	}
-	print_string(PRINT_FP, NULL, "%s", "]");
-	close_json_array(PRINT_JSON, "[non_applied_node:status]");
-}
-
-static void link_mon_print_peer_state(const uint32_t addr, const char *status,
-				      const char *monitored,
-				      const uint32_t dom_gen)
-{
-	char addr_str[16];
-
-	sprintf(addr_str, "%u.%u.%u", tipc_zone(addr), tipc_cluster(addr),
-		tipc_node(addr));
-	if (is_json_context()) {
-		print_string(PRINT_JSON, "node", NULL, addr_str);
-		print_string(PRINT_JSON, "status", NULL, status);
-		print_string(PRINT_JSON, "monitored", NULL, monitored);
-		print_uint(PRINT_JSON, "generation", NULL, dom_gen);
-	} else {
-		printf("%-*s", MAX_NODE_WIDTH, addr_str);
-		printf("%-*s", STATUS_WIDTH, status);
-		printf("%-*s", DIRECTLY_MON_WIDTH, monitored);
-		printf("%-*u", MAX_DOM_GEN_WIDTH, dom_gen);
-	}
-}
-
-static int link_mon_peer_list_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *attrs[TIPC_NLA_MON_PEER_MAX + 1] = {};
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	uint16_t member_cnt;
-	uint32_t applied;
-	uint32_t dom_gen;
-	uint64_t up_map;
-	char status[16];
-	char monitored[16];
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-	if (!info[TIPC_NLA_MON_PEER])
-		return MNL_CB_ERROR;
-
-	open_json_object(NULL);
-	mnl_attr_parse_nested(info[TIPC_NLA_MON_PEER], parse_attrs, attrs);
-
-	(attrs[TIPC_NLA_MON_PEER_LOCAL] || attrs[TIPC_NLA_MON_PEER_HEAD]) ?
-		strcpy(monitored, "direct") :
-		strcpy(monitored, "indirect");
-
-	attrs[TIPC_NLA_MON_PEER_UP] ?
-		strcpy(status, "up") :
-		strcpy(status, "down");
-
-	dom_gen = attrs[TIPC_NLA_MON_PEER_DOMGEN] ?
-		mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEER_DOMGEN]) : 0;
-
-	link_mon_print_peer_state(mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEER_ADDR]),
-				  status, monitored, dom_gen);
-
-	applied = mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEER_APPLIED]);
-
-	if (!applied)
-		goto exit;
-
-	up_map = mnl_attr_get_u64(attrs[TIPC_NLA_MON_PEER_UPMAP]);
-
-	member_cnt = mnl_attr_get_payload_len(attrs[TIPC_NLA_MON_PEER_MEMBERS]);
-
-	/* each tipc address occupies 4 bytes of payload, hence compensate it */
-	member_cnt /= sizeof(uint32_t);
-
-	link_mon_print_applied(applied, up_map);
-
-	link_mon_print_non_applied(applied, member_cnt, up_map,
-				   mnl_attr_get_payload(attrs[TIPC_NLA_MON_PEER_MEMBERS]));
-
-exit:
-	print_string(PRINT_FP, NULL, "\n", "");
-
-	close_json_object();
-	return MNL_CB_OK;
-}
-
-static int link_mon_peer_list(uint32_t mon_ref)
-{
-	struct nlmsghdr *nlh;
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlattr *nest;
-	int err = 0;
-
-	nlh = msg_init(buf, TIPC_NL_MON_PEER_GET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	nest = mnl_attr_nest_start(nlh, TIPC_NLA_MON);
-	mnl_attr_put_u32(nlh, TIPC_NLA_MON_REF, mon_ref);
-	mnl_attr_nest_end(nlh, nest);
-
-	err = msg_dumpit(nlh, link_mon_peer_list_cb, NULL);
-	return err;
-}
-
-static int link_mon_list_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};
-	char *req_bearer = data;
-	const char *bname;
-	const char title[] =
-	  "node          status monitored generation applied_node_status [non_applied_node:status]";
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-	if (!info[TIPC_NLA_MON])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);
-
-	bname = mnl_attr_get_str(attrs[TIPC_NLA_MON_BEARER_NAME]);
-
-	if (*req_bearer && (strcmp(req_bearer, bname) != 0))
-		return MNL_CB_OK;
-
-	open_json_object(NULL);
-	print_string(PRINT_ANY, "bearer", "\nbearer %s\n", bname);
-	print_string(PRINT_FP, NULL, "%s\n", title);
-
-	open_json_array(PRINT_JSON, bname);
-	if (mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEERCNT]))
-		link_mon_peer_list(mnl_attr_get_u32(attrs[TIPC_NLA_MON_REF]));
-	close_json_array(PRINT_JSON, bname);
-
-	close_json_object();
-	return MNL_CB_OK;
-}
-
-static void cmd_link_mon_list_help(struct cmdl *cmdl)
-{
-	fprintf(stderr, "Usage: %s monitor list [ media MEDIA ARGS...]\n\n",
-		cmdl->argv[0]);
-	print_bearer_media();
-}
-
-static void cmd_link_mon_list_l2_help(struct cmdl *cmdl, char *media)
-{
-	fprintf(stderr,
-		"Usage: %s monitor list media %s device DEVICE [OPTIONS]\n",
-		cmdl->argv[0], media);
-}
-
-static void cmd_link_mon_list_udp_help(struct cmdl *cmdl, char *media)
-{
-	fprintf(stderr,
-		"Usage: %s monitor list media udp name NAME\n\n",
-		cmdl->argv[0]);
-}
-
-static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd,
-			     struct cmdl *cmdl, void *data)
-{
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	char bname[TIPC_MAX_BEARER_NAME] = {0};
-	struct opt opts[] = {
-		{ "media",	OPT_KEYVAL,	NULL },
-		{ "device",	OPT_KEYVAL,	NULL },
-		{ "name",	OPT_KEYVAL,	NULL },
-		{ NULL }
-	};
-	struct tipc_sup_media sup_media[] = {
-		{ "udp",        "name",         cmd_link_mon_list_udp_help},
-		{ "eth",        "device",       cmd_link_mon_list_l2_help },
-		{ "ib",         "device",       cmd_link_mon_list_l2_help },
-		{ NULL, },
-	};
-
-	int err;
-
-	if (parse_opts(opts, cmdl) < 0)
-		return -EINVAL;
-
-	if (get_opt(opts, "media")) {
-		err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname,
-						 sup_media);
-		if (err)
-			return err;
-	}
-
-	if (help_flag) {
-		cmd->help(cmdl);
-		return -EINVAL;
-	}
-
-	nlh = msg_init(buf, TIPC_NL_MON_GET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	new_json_obj(json);
-	err = msg_dumpit(nlh, link_mon_list_cb, bname);
-	delete_json_obj();
-	return err;
-}
-
-static void cmd_link_mon_set_help(struct cmdl *cmdl)
-{
-	fprintf(stderr, "Usage: %s monitor set PPROPERTY\n\n"
-		"PROPERTIES\n"
-		" threshold SIZE	- Set monitor activation threshold\n",
-		cmdl->argv[0]);
-}
-
-static int cmd_link_mon_set(struct nlmsghdr *nlh, const struct cmd *cmd,
-			    struct cmdl *cmdl, void *data)
-{
-	const struct cmd cmds[] = {
-		{ "threshold",	cmd_link_mon_set_prop,	NULL },
-		{ NULL }
-	};
-
-	return run_cmd(nlh, cmd, cmds, cmdl, NULL);
-}
-
-static void cmd_link_mon_get_help(struct cmdl *cmdl)
-{
-	fprintf(stderr, "Usage: %s monitor get PPROPERTY\n\n"
-		"PROPERTIES\n"
-		" threshold	- Get monitor activation threshold\n",
-		cmdl->argv[0]);
-}
-
-static int link_mon_get_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};
-
-	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
-	if (!info[TIPC_NLA_MON])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);
-	if (!attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD])
-		return MNL_CB_ERROR;
-
-	new_json_obj(json);
-	print_uint(PRINT_ANY, "threshold", "%u\n",
-			   mnl_attr_get_u32(attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]));
-	delete_json_obj();
-
-	return MNL_CB_OK;
-}
-
-static int cmd_link_mon_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
-				 struct cmdl *cmdl, void *data)
-{
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-
-	nlh = msg_init(buf, TIPC_NL_MON_GET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	return msg_doit(nlh,	link_mon_get_cb,	NULL);
-}
-
-static int cmd_link_mon_get(struct nlmsghdr *nlh, const struct cmd *cmd,
-			    struct cmdl *cmdl, void *data)
-{
-	const struct cmd cmds[] = {
-		{ "threshold",	cmd_link_mon_get_prop,	NULL},
-		{ NULL }
-	};
-
-	return run_cmd(nlh, cmd, cmds, cmdl, NULL);
-}
-
-static void cmd_link_mon_help(struct cmdl *cmdl)
-{
-	fprintf(stderr,
-		"Usage: %s montior COMMAND [ARGS] ...\n\n"
-		"COMMANDS\n"
-		" set			- Set monitor properties\n"
-		" get			- Get monitor properties\n"
-		" list			- List all cluster members\n"
-		" summary		- Show local node monitor summary\n",
-		cmdl->argv[0]);
-}
-
-static int cmd_link_mon(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
-			void *data)
-{
-	const struct cmd cmds[] = {
-		{ "set",	cmd_link_mon_set,	cmd_link_mon_set_help },
-		{ "get",	cmd_link_mon_get,	cmd_link_mon_get_help },
-		{ "list",	cmd_link_mon_list,	cmd_link_mon_list_help },
-		{ "summary",	cmd_link_mon_summary,	NULL },
+		{ "priority",	cmd_link_set_prop,	cmd_link_set_help },
+		{ "tolerance",	cmd_link_set_prop,	cmd_link_set_help },
+		{ "window",	cmd_link_set_prop,	cmd_link_set_help },
 		{ NULL }
 	};
 
@@ -1224,8 +501,7 @@
 		" list                  - List links\n"
 		" get                   - Get various link properties\n"
 		" set                   - Set various link properties\n"
-		" statistics            - Show or reset statistics\n"
-		" monitor               - Show or set link supervision\n",
+		" statistics            - Show or reset statistics\n",
 		cmdl->argv[0]);
 }
 
@@ -1237,7 +513,6 @@
 		{ "list",	cmd_link_list,	NULL },
 		{ "set",	cmd_link_set,	cmd_link_set_help },
 		{ "statistics", cmd_link_stat,	cmd_link_stat_help },
-		{ "monitor",	cmd_link_mon,	cmd_link_mon_help },
 		{ NULL }
 	};
 
diff --git a/tipc/media.c b/tipc/media.c
index 969ef65..a902ab7 100644
--- a/tipc/media.c
+++ b/tipc/media.c
@@ -93,7 +93,7 @@
 	struct nlattr *nest;
 	struct opt *opt;
 	struct opt opts[] = {
-		{ "media",		OPT_KEYVAL,	NULL },
+		{ "media",		NULL },
 		{ NULL }
 	};
 
@@ -103,8 +103,6 @@
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
-	else if ((strcmp(cmd->cmd, "mtu") == 0))
-		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
@@ -125,12 +123,6 @@
 		fprintf(stderr, "error, missing media\n");
 		return -EINVAL;
 	}
-
-	if ((prop == TIPC_NLA_PROP_MTU) &&
-	    (strcmp(opt->val, "udp"))) {
-		fprintf(stderr, "error, not supported for media\n");
-		return -EINVAL;
-	}
 	nest = mnl_attr_nest_start(nlh, TIPC_NLA_MEDIA);
 	mnl_attr_put_strz(nlh, TIPC_NLA_MEDIA_NAME, opt->val);
 	mnl_attr_nest_end(nlh, nest);
@@ -144,8 +136,7 @@
 		"PROPERTIES\n"
 		" tolerance             - Get media tolerance\n"
 		" priority              - Get media priority\n"
-		" window                - Get media window\n"
-		" mtu                   - Get media mtu\n",
+		" window                - Get media window\n",
 		cmdl->argv[0]);
 }
 
@@ -156,7 +147,6 @@
 		{ "priority",	cmd_media_get_prop,	cmd_media_get_help },
 		{ "tolerance",	cmd_media_get_prop,	cmd_media_get_help },
 		{ "window",	cmd_media_get_prop,	cmd_media_get_help },
-		{ "mtu",	cmd_media_get_prop,	cmd_media_get_help },
 		{ NULL }
 	};
 
@@ -169,8 +159,7 @@
 		"PROPERTIES\n"
 		" tolerance TOLERANCE   - Set media tolerance\n"
 		" priority PRIORITY     - Set media priority\n"
-		" window WINDOW         - Set media window\n"
-		" mtu MTU               - Set media mtu\n",
+		" window WINDOW         - Set media window\n",
 		cmdl->argv[0]);
 }
 
@@ -184,7 +173,7 @@
 	struct nlattr *attrs;
 	struct opt *opt;
 	struct opt opts[] = {
-		{ "media",		OPT_KEYVAL,	NULL },
+		{ "media",		NULL },
 		{ NULL }
 	};
 
@@ -194,8 +183,6 @@
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
-	else if ((strcmp(cmd->cmd, "mtu") == 0))
-		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
@@ -223,12 +210,6 @@
 		fprintf(stderr, "error, missing media\n");
 		return -EINVAL;
 	}
-
-	if ((prop == TIPC_NLA_PROP_MTU) &&
-	    (strcmp(opt->val, "udp"))) {
-		fprintf(stderr, "error, not supported for media\n");
-		return -EINVAL;
-	}
 	mnl_attr_put_strz(nlh, TIPC_NLA_MEDIA_NAME, opt->val);
 
 	props = mnl_attr_nest_start(nlh, TIPC_NLA_MEDIA_PROP);
@@ -247,7 +228,6 @@
 		{ "priority",	cmd_media_set_prop,	cmd_media_set_help },
 		{ "tolerance",	cmd_media_set_prop,	cmd_media_set_help },
 		{ "window",	cmd_media_set_prop,	cmd_media_set_help },
-		{ "mtu",	cmd_media_set_prop,	cmd_media_set_help },
 		{ NULL }
 	};
 
diff --git a/tipc/misc.c b/tipc/misc.c
index e4b1cd0..8091222 100644
--- a/tipc/misc.c
+++ b/tipc/misc.c
@@ -12,11 +12,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <linux/tipc.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <errno.h>
+
 #include "misc.h"
 
 #define IN_RANGE(val, low, high) ((val) <= (high) && (val) >= (low))
@@ -37,95 +33,3 @@
 	fprintf(stderr, "invalid network address \"%s\"\n", str);
 	return 0;
 }
-
-static int is_hex(char *arr, int last)
-{
-	int i;
-
-	while (!arr[last])
-		last--;
-
-	for (i = 0; i <= last; i++) {
-		if (!IN_RANGE(arr[i], '0', '9') &&
-		    !IN_RANGE(arr[i], 'a', 'f') &&
-		    !IN_RANGE(arr[i], 'A', 'F'))
-			return 0;
-	}
-	return 1;
-}
-
-static int is_name(char *arr, int last)
-{
-	int i;
-	char c;
-
-	while (!arr[last])
-		last--;
-
-	if (last > 15)
-		return 0;
-
-	for (i = 0; i <= last; i++) {
-		c = arr[i];
-		if (!IN_RANGE(c, '0', '9') && !IN_RANGE(c, 'a', 'z') &&
-		    !IN_RANGE(c, 'A', 'Z') && c != '-' && c != '_' &&
-		    c != '.' && c != ':' && c != '@')
-			return 0;
-	}
-	return 1;
-}
-
-int str2nodeid(char *str, uint8_t *id)
-{
-	int len = strlen(str);
-	int i;
-
-	if (len > 32)
-		return -1;
-
-	if (is_name(str, len - 1)) {
-		memcpy(id, str, len);
-		return 0;
-	}
-	if (!is_hex(str, len - 1))
-		return -1;
-
-	str[len] = '0';
-	for (i = 0; i < 16; i++) {
-		if (sscanf(&str[2 * i], "%2hhx", &id[i]) != 1)
-			break;
-	}
-	return 0;
-}
-
-void nodeid2str(uint8_t *id, char *str)
-{
-	int i;
-
-	if (is_name((char *)id, 15)) {
-		memcpy(str, id, 16);
-		return;
-	}
-
-	for (i = 0; i < 16; i++)
-		sprintf(&str[2 * i], "%02x", id[i]);
-
-	for (i = 31; str[i] == '0'; i--)
-		str[i] = 0;
-}
-
-void hash2nodestr(uint32_t hash, char *str)
-{
-	struct tipc_sioc_nodeid_req nr = {};
-	int sd;
-
-	sd = socket(AF_TIPC, SOCK_RDM, 0);
-	if (sd < 0) {
-		fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno));
-		return;
-	}
-	nr.peer = hash;
-	if (!ioctl(sd, SIOCGETNODEID, &nr))
-		nodeid2str((uint8_t *)nr.node_id, str);
-	close(sd);
-}
diff --git a/tipc/misc.h b/tipc/misc.h
index ff2f31f..585df74 100644
--- a/tipc/misc.h
+++ b/tipc/misc.h
@@ -15,8 +15,5 @@
 #include <stdint.h>
 
 uint32_t str2addr(char *str);
-int str2nodeid(char *str, uint8_t *id);
-void nodeid2str(uint8_t *id, char *str);
-void hash2nodestr(uint32_t hash, char *str);
 
 #endif
diff --git a/tipc/msg.c b/tipc/msg.c
index dc09d05..22c2222 100644
--- a/tipc/msg.c
+++ b/tipc/msg.c
@@ -125,7 +125,7 @@
 	genl->cmd = CTRL_CMD_GETFAMILY;
 	genl->version = 1;
 
-	mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL);
+	mnl_attr_put_u32(nlh, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL);
 	mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, TIPC_GENL_V2_NAME);
 
 	if ((err = msg_query(nlh, family_id_cb, &nl_family)))
diff --git a/tipc/nametable.c b/tipc/nametable.c
index d899eeb..770a644 100644
--- a/tipc/nametable.c
+++ b/tipc/nametable.c
@@ -20,20 +20,18 @@
 #include "cmdl.h"
 #include "msg.h"
 #include "nametable.h"
-#include "misc.h"
-#include "utils.h"
 
 #define PORTID_STR_LEN 45 /* Four u32 and five delimiter chars */
 
 static int nametable_show_cb(const struct nlmsghdr *nlh, void *data)
 {
 	int *iteration = data;
+	char port_id[PORTID_STR_LEN];
 	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
 	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
 	struct nlattr *attrs[TIPC_NLA_NAME_TABLE_MAX + 1] = {};
 	struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1] = {};
 	const char *scope[] = { "", "zone", "cluster", "node" };
-	char str[33] = {0,};
 
 	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
 	if (!info[TIPC_NLA_NAME_TABLE])
@@ -47,33 +45,26 @@
 	if (!publ[TIPC_NLA_NAME_TABLE_PUBL])
 		return MNL_CB_ERROR;
 
-	if (!*iteration && !is_json_context())
-		printf("%-10s %-10s %-10s %-8s %-10s %-33s\n",
-		       "Type", "Lower", "Upper", "Scope", "Port",
-		       "Node");
+	if (!*iteration)
+		printf("%-10s %-10s %-10s %-26s %-10s\n",
+		       "Type", "Lower", "Upper", "Port Identity",
+		       "Publication Scope");
 	(*iteration)++;
 
-	hash2nodestr(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE]), str);
+	snprintf(port_id, sizeof(port_id), "<%u.%u.%u:%u>",
+		 tipc_zone(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE])),
+		 tipc_cluster(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE])),
+		 tipc_node(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE])),
+		 mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF]));
 
-	open_json_object(NULL);
-	print_uint(PRINT_ANY, "type", "%-10u",
-			   mnl_attr_get_u32(publ[TIPC_NLA_PUBL_TYPE]));
-	print_string(PRINT_FP, NULL, " ", "");
-	print_uint(PRINT_ANY, "lower", "%-10u",
-			   mnl_attr_get_u32(publ[TIPC_NLA_PUBL_LOWER]));
-	print_string(PRINT_FP, NULL, " ", "");
-	print_uint(PRINT_ANY, "upper", "%-10u",
-			   mnl_attr_get_u32(publ[TIPC_NLA_PUBL_UPPER]));
-	print_string(PRINT_FP, NULL, " ", "");
-	print_string(PRINT_ANY, "scope", "%-8s",
-			     scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]);
-	print_string(PRINT_FP, NULL, " ", "");
-	print_uint(PRINT_ANY, "port", "%-10u",
-			   mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF]));
-	print_string(PRINT_FP, NULL, " ", "");
-	print_string(PRINT_ANY, "node", "%s", str);
-	print_string(PRINT_FP, NULL, "\n", "");
-	close_json_object();
+	printf("%-10u %-10u %-10u %-26s %-12u",
+	       mnl_attr_get_u32(publ[TIPC_NLA_PUBL_TYPE]),
+	       mnl_attr_get_u32(publ[TIPC_NLA_PUBL_LOWER]),
+	       mnl_attr_get_u32(publ[TIPC_NLA_PUBL_UPPER]),
+	       port_id,
+	       mnl_attr_get_u32(publ[TIPC_NLA_PUBL_KEY]));
+
+	printf("%s\n", scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]);
 
 	return MNL_CB_OK;
 }
@@ -83,7 +74,6 @@
 {
 	int iteration = 0;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
-	int rc = 0;
 
 	if (help_flag) {
 		fprintf(stderr, "Usage: %s nametable show\n", cmdl->argv[0]);
@@ -95,11 +85,7 @@
 		return -1;
 	}
 
-	new_json_obj(json);
-	rc = msg_dumpit(nlh, nametable_show_cb, &iteration);
-	delete_json_obj();
-
-	return rc;
+	return msg_dumpit(nlh, nametable_show_cb, &iteration);
 }
 
 void cmd_nametable_help(struct cmdl *cmdl)
diff --git a/tipc/node.c b/tipc/node.c
index 2fec675..201fe1a 100644
--- a/tipc/node.c
+++ b/tipc/node.c
@@ -26,12 +26,12 @@
 
 static int node_list_cb(const struct nlmsghdr *nlh, void *data)
 {
+	uint32_t addr;
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
 	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
 	struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1] = {};
-	char str[33] = {};
-	uint32_t addr;
 
-	mnl_attr_parse(nlh, sizeof(struct genlmsghdr), parse_attrs, info);
+	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
 	if (!info[TIPC_NLA_NODE])
 		return MNL_CB_ERROR;
 
@@ -40,12 +40,16 @@
 		return MNL_CB_ERROR;
 
 	addr = mnl_attr_get_u32(attrs[TIPC_NLA_NODE_ADDR]);
-	hash2nodestr(addr, str);
-	printf("%-32s %08x ", str, addr);
+	printf("<%u.%u.%u>: ",
+		tipc_zone(addr),
+		tipc_cluster(addr),
+		tipc_node(addr));
+
 	if (attrs[TIPC_NLA_NODE_UP])
 		printf("up\n");
 	else
 		printf("down\n");
+
 	return MNL_CB_OK;
 }
 
@@ -63,7 +67,7 @@
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
 	}
-	printf("Node Identity                    Hash     State\n");
+
 	return msg_dumpit(nlh, node_list_cb, NULL);
 }
 
@@ -105,8 +109,7 @@
 	socklen_t sz = sizeof(struct sockaddr_tipc);
 	struct sockaddr_tipc addr;
 
-	sk = socket(AF_TIPC, SOCK_RDM, 0);
-	if (sk < 0) {
+	if (!(sk = socket(AF_TIPC, SOCK_RDM, 0))) {
 		fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno));
 		return -1;
 	}
@@ -119,96 +122,21 @@
 	}
 	close(sk);
 
-	printf("%08x\n", addr.addr.id.node);
+	printf("<%u.%u.%u>\n",
+		tipc_zone(addr.addr.id.node),
+		tipc_cluster(addr.addr.id.node),
+		tipc_node(addr.addr.id.node));
+
 	return 0;
 }
 
-static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
-			       struct cmdl *cmdl, void *data)
-{
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-	uint8_t id[16] = {0,};
-	uint64_t *w0 = (uint64_t *) &id[0];
-	uint64_t *w1 = (uint64_t *) &id[8];
-	struct nlattr *nest;
-	char *str;
-
-	if (cmdl->argc != cmdl->optind + 1) {
-		fprintf(stderr, "Usage: %s node set nodeid NODE_ID\n",
-			cmdl->argv[0]);
-		return -EINVAL;
-	}
-
-	str = shift_cmdl(cmdl);
-	if (str2nodeid(str, id)) {
-		fprintf(stderr, "Invalid node identity\n");
-		return -EINVAL;
-	}
-
-	nlh = msg_init(buf, TIPC_NL_NET_SET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-	nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
-	mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID, *w0);
-	mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID_W1, *w1);
-	mnl_attr_nest_end(nlh, nest);
-	return msg_doit(nlh, NULL, NULL);
-}
-
-static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
-	struct nlattr *attrs[TIPC_NLA_NET_MAX + 1] = {};
-	char str[33] = {0,};
-	uint8_t id[16] = {0,};
-	uint64_t *w0 = (uint64_t *) &id[0];
-	uint64_t *w1 = (uint64_t *) &id[8];
-
-	mnl_attr_parse(nlh, sizeof(struct genlmsghdr), parse_attrs, info);
-	if (!info[TIPC_NLA_NET])
-		return MNL_CB_ERROR;
-
-	mnl_attr_parse_nested(info[TIPC_NLA_NET], parse_attrs, attrs);
-	if (!attrs[TIPC_NLA_NET_ID])
-		return MNL_CB_ERROR;
-
-	*w0 = mnl_attr_get_u64(attrs[TIPC_NLA_NET_NODEID]);
-	*w1 = mnl_attr_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
-	nodeid2str(id, str);
-	printf("Node Identity                    Hash\n");
-	printf("%-33s", str);
-	cmd_node_get_addr(NULL, NULL, NULL, NULL);
-	return MNL_CB_OK;
-}
-
-static int cmd_node_get_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
-			       struct cmdl *cmdl, void *data)
-{
-	char buf[MNL_SOCKET_BUFFER_SIZE];
-
-	if (help_flag) {
-		(cmd->help)(cmdl);
-		return -EINVAL;
-	}
-
-	nlh = msg_init(buf, TIPC_NL_NET_GET);
-	if (!nlh) {
-		fprintf(stderr, "error, message initialisation failed\n");
-		return -1;
-	}
-
-	return msg_dumpit(nlh, nodeid_get_cb, NULL);
-}
-
-
 static int netid_get_cb(const struct nlmsghdr *nlh, void *data)
 {
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
 	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
 	struct nlattr *attrs[TIPC_NLA_NET_MAX + 1] = {};
 
-	mnl_attr_parse(nlh, sizeof(struct genlmsghdr), parse_attrs, info);
+	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
 	if (!info[TIPC_NLA_NET])
 		return MNL_CB_ERROR;
 
@@ -275,8 +203,8 @@
 	fprintf(stderr,
 		"Usage: %s node set PROPERTY\n\n"
 		"PROPERTIES\n"
-		" identity NODEID       - Set node identity\n"
-		" clusterid CLUSTERID   - Set local cluster id\n",
+		" address ADDRESS       - Set local address\n"
+		" netid NETID           - Set local netid\n",
 		cmdl->argv[0]);
 }
 
@@ -284,10 +212,8 @@
 			struct cmdl *cmdl, void *data)
 {
 	const struct cmd cmds[] = {
-		{ "address",    cmd_node_set_addr,      NULL },
-		{ "identity",	cmd_node_set_nodeid,	NULL },
+		{ "address",	cmd_node_set_addr,	NULL },
 		{ "netid",	cmd_node_set_netid,	NULL },
-		{ "clusterid",	cmd_node_set_netid,	NULL },
 		{ NULL }
 	};
 
@@ -299,8 +225,8 @@
 	fprintf(stderr,
 		"Usage: %s node get PROPERTY\n\n"
 		"PROPERTIES\n"
-		" identity              - Get node identity\n"
-		" clusterid             - Get local clusterid\n",
+		" address               - Get local address\n"
+		" netid                 - Get local netid\n",
 		cmdl->argv[0]);
 }
 
@@ -309,9 +235,7 @@
 {
 	const struct cmd cmds[] = {
 		{ "address",	cmd_node_get_addr,	NULL },
-		{ "identity",	cmd_node_get_nodeid,	NULL },
 		{ "netid",	cmd_node_get_netid,	NULL },
-		{ "clusterid",	cmd_node_get_netid,	NULL },
 		{ NULL }
 	};
 
diff --git a/tipc/peer.c b/tipc/peer.c
index f638077..de0c73c 100644
--- a/tipc/peer.c
+++ b/tipc/peer.c
@@ -39,12 +39,8 @@
 	}
 
 	str = shift_cmdl(cmdl);
-
-	/* First try legacy Z.C.N format, then integer format */
 	addr = str2addr(str);
 	if (!addr)
-		addr = atoi(str);
-	if (!addr)
 		return -1;
 
 	if (!(nlh = msg_init(buf, TIPC_NL_PEER_REMOVE))) {
diff --git a/tipc/socket.c b/tipc/socket.c
index 852984e..48ba821 100644
--- a/tipc/socket.c
+++ b/tipc/socket.c
@@ -84,7 +84,8 @@
 		mnl_attr_parse_nested(attrs[TIPC_NLA_SOCK_CON], parse_attrs, con);
 		node = mnl_attr_get_u32(con[TIPC_NLA_CON_NODE]);
 
-		printf("  connected to %x:%u", node,
+		printf("  connected to <%u.%u.%u:%u>", tipc_zone(node),
+			tipc_cluster(node), tipc_node(node),
 			mnl_attr_get_u32(con[TIPC_NLA_CON_SOCK]));
 
 		if (con[TIPC_NLA_CON_FLAG])
diff --git a/tipc/tipc.c b/tipc/tipc.c
index f85ddee..600d5e2 100644
--- a/tipc/tipc.c
+++ b/tipc/tipc.c
@@ -24,8 +24,6 @@
 #include "cmdl.h"
 
 int help_flag;
-int json;
-int pretty;
 
 static void about(struct cmdl *cmdl)
 {
@@ -35,8 +33,6 @@
 		"\n"
 		"Options:\n"
 		" -h, --help \t\tPrint help for last given command\n"
-		" -j, --json \t\tJson format printouts\n"
-		" -p, --pretty \t\tpretty print\n"
 		"\n"
 		"Commands:\n"
 		" bearer                - Show or modify bearers\n"
@@ -57,8 +53,6 @@
 	const struct cmd cmd = {"tipc", NULL, about};
 	struct option long_options[] = {
 		{"help", no_argument, 0, 'h'},
-		{"json", no_argument, 0, 'j'},
-		{"pretty", no_argument, 0, 'p'},
 		{0, 0, 0, 0}
 	};
 	const struct cmd cmds[] = {
@@ -75,7 +69,7 @@
 	do {
 		int option_index = 0;
 
-		i = getopt_long(argc, argv, "hjp", long_options, &option_index);
+		i = getopt_long(argc, argv, "h", long_options, &option_index);
 
 		switch (i) {
 		case 'h':
@@ -85,18 +79,6 @@
 			 */
 			help_flag = 1;
 			break;
-		case 'j':
-			/*
-			 * Enable json format printouts
-			 */
-			json = 1;
-			break;
-		case 'p':
-			/*
-			 * Enable json pretty output
-			 */
-			pretty = 1;
-			break;
 		case -1:
 			/* End of options */
 			break;