76 Commits

Author SHA1 Message Date
Jackson-Wang-K cc322252d1 Optimize ROM
Signed-off-by: Jackson-Wang-K <wanglu292@huawei.com>
2026-07-11 10:54:38 +08:00
Jackson-Wang-K 71fed398ec update: 更新文件 BUILD.gn
Signed-off-by: Jackson-Wang-K <wanglu292@huawei.com>
2026-06-30 20:55:42 +08:00
hhd227 30abb26fbb 回退iptables
Signed-off-by: hhd227 <3216023252@qq.com>
2026-02-25 21:12:19 +08:00
hhd227 92615dcbc8 update: 更新文件 xtoptions.c
Signed-off-by: hhd227 <3216023252@qq.com>
2026-02-24 19:24:50 +08:00
HuangHaitao 231b82f5e3 customized files and fix musl build error
Signed-off-by: HuangHaitao <huanghaitao16@huawei.com>
2025-07-03 01:21:58 +08:00
HuangHaitao e4107a428d upgrade iptables to 1.8.11
Signed-off-by: HuangHaitao <huanghaitao16@huawei.com>
2025-07-03 01:20:09 +08:00
maosiping d0aaba08cd update to 1.8.7-5.oe2203
Signed-off-by: maosiping <maosiping@huawei.com>
Signed-off-by: liyufan <liyufan5@huawei.com>
Signed-off-by: maosiping <maosiping@huawei.com>
2023-04-21 09:29:01 +08:00
maosiping 40ea77dc7b build添加许可证声明
Signed-off-by: maosiping <maosiping@huawei.com>
2022-06-16 14:55:59 +08:00
maosiping 16b345a8ba OpenHarmony编译适配
Signed-off-by: maosiping <maosiping@huawei.com>
2022-05-12 17:02:26 +08:00
Phil Sutter 1bdb5535f5 libxtables: Extend MAC address printing/parsing support
Adding a parser which supports common names for special MAC/mask
combinations and a print routine detecting those special addresses and
printing the respective name allows to consolidate all the various
duplicated implementations.

The side-effects of this change are manageable:

* arptables now accepts "BGA" as alias for the bridge group address
* "mac" match now prints MAC addresses in lower-case which is consistent
  with the remaining code at least

Signed-off-by: Phil Sutter <phil@nwl.cc>
2020-12-03 00:27:46 +01:00
Phil Sutter b5f1a3beac libxtables: Register multiple extensions in ascending order
The newly introduced ordered insert algorithm in
xtables_register_{match,target}() works best if extensions of same name
are passed in ascending revisions. Since this is the case in about all
extensions' arrays, iterate over them from beginning to end.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2020-10-07 12:38:45 +02:00
Phil Sutter a1eaaceb04 libxtables: Simplify pending extension registration
Assuming that pending extensions are sorted by first name and family,
then descending revision, the decision where to insert a newly
registered extension may be simplified by memorizing the previous
registration (which obviously is of same name and family and higher
revision).

As a side-effect, fix for unsupported old extension revisions lingering
in pending extension list forever and being retried with every use of
the given extension. Any revision being rejected by the kernel may
safely be dropped iff a previous (read: higher) revision was accepted
already.

Yet another side-effect of this change is the removal of an unwanted
recursion by xtables_fully_register_pending_*() into itself via
xtables_find_*().

Signed-off-by: Phil Sutter <phil@nwl.cc>
2020-10-07 12:38:35 +02:00
Phil Sutter b3ac87038f libxtables: Make sure extensions register in revision order
Insert extensions into pending lists in ordered fashion: Group by
extension name (and, for matches, family) and order groups by descending
revision number.

This allows to simplify the later full registration considerably. Since
that involves kernel compatibility checks, the extra cycles here pay off
eventually.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2020-10-07 12:38:28 +02:00
Maciej Żenczykowski 6cb8af1ff3 libxtables: compiler warning fixes for NO_SHARED_LIBS
Fixes two issues with NO_SHARED_LIBS:
 - #include <dlfcn.h> is ifdef'ed out and thus dlclose()
   triggers an undeclared function compiler warning
 - dlreg_add() is unused and thus triggers an unused
   function warning

Test: builds without warnings
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-06-30 18:38:44 +02:00
Phil Sutter 7db4333dc0 libxtables: Introduce xtables_fini()
Record handles of loaded shared objects in a linked list and dlclose()
them from the newly introduced function. While functionally not
necessary, this clears up valgrind's memcheck output when also
displaying reachable memory.

Since this is an extra function that doesn't change the existing API,
increment both current and age.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2020-05-11 14:28:29 +02:00
Phil Sutter f7d3dbb82e libxtables: Avoid buffer overrun in xtables_compatible_revision()
The function is exported and accepts arbitrary strings as input. Calling
strcpy() without length checks is not OK.
2019-12-06 12:12:08 +01:00
Phil Sutter 148131f204 xtables: Fix for false-positive rule matching
When comparing two rules with non-standard targets, differences in
targets' payloads wasn't respected.

The cause is a rather hideous one: Unlike xtables_find_match(),
xtables_find_target() did not care whether the found target was already
in use or not, so the same target instance was assigned to both rules
and therefore payload comparison happened over the same memory location.

With legacy iptables it is not possible to reuse a target: The only case
where two rules (i.e., iptables_command_state instances) could exist at
the same time is when comparing rules, but that's handled using libiptc.

The above change clashes with ebtables-nft's reuse of target objects:
While input parsing still just assigns the object from xtables_targets
list, rule conversion from nftnl to iptables_command_state allocates new
data. To fix this, make ebtables-nft input parsing use the common
command_jump() routine instead of its own simplified copy. In turn, this
also eliminates the ebtables-nft-specific variants of parse_target(),
though with a slight change of behaviour: Names of user-defined chains
are no longer allowed to contain up to 31 but merely 28 characters.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2019-02-05 16:09:41 +01:00
Florian Westphal 5edb249b25 libxtables: xlate: init buffer to zero
Doesn't affect iptables-xlate, but nft (when built w. xtables support).

Without this, nft can print random content if an extension doesn't
add anything to the output xlate buffer, e.g.

-p mh -m mh

can cause nft to print random data after "meta l4proto mobility",
as mh ->xlate doesn't do anything in this case.

Signed-off-by: Florian Westphal <fw@strlen.de>
2018-11-12 18:27:12 +01:00
Florian Westphal 7bd9febf65 libxtables: add and use mac print helpers
This changes ebtables-nft to consistently print mac
address with two characters, i.e.
00:01:02:03:04:0a, not 0:1:2:3:4:a.

Will require another bump of vcurrent/vage.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fw@strlen.de>
2018-11-07 20:08:15 +01:00
Pablo Neira Ayuso abae556c88 libxtables: expose new etherdb lookup function through libxtables API
This is used from extensions and included in libxtables, so we have to
make them public.

Fixes: 31f1434dfe ("libxtables: Integrate getethertype.c from xtables core")
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
2018-10-20 11:14:15 +02:00
Pablo Neira Ayuso c2d9ed9931 libxtables: prefix exported new functions for etherdb lookups
To avoid symbol pollution, place them under the xt_ and xtables_ prefix
name.

Fixes: 31f1434dfe ("libxtables: Integrate getethertype.c from xtables core")
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
2018-10-20 11:14:10 +02:00
Phil Sutter a3716cc1a5 libxtables: Check extension real_name length
Just like with 'name', if given check 'real_name' to not exceed max length.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-25 16:26:08 +02:00
Phil Sutter d95c1e8b65 libxtables: Use posix_spawn() instead of vfork()
According to covscan, vfork() may lead to a deadlock in the parent
process. It suggests to use posix_spawn() instead. Since the latter
combines vfork() and exec() calls, use it for xtables_insmod().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-24 11:49:58 +02:00
Phil Sutter 7e50ebabbf Fix a few cases of pointless assignments
This gets rid of a number of assignments which are either redundant or
not used afterwards.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-24 11:49:57 +02:00
Phil Sutter 61ebf3f72a libxtables: Don't read garbage in xtables_strtoui()
If xtables_strtoul() fails, it returns false and data pointed to by
parameter 'value' is undefined. Hence avoid copying that data in
xtables_strtoui() if the call failed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-24 11:24:09 +02:00
Phil Sutter ab639f236f libxtables: Avoid calling memcpy() with NULL source
Both affected functions check if 'oldopts' is NULL once but later seem
to ignore that possibility. To catch up on that, increment the pointer
only if it isn't NULL, also don't copy its content into the merged
options buffer in that case.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-24 11:24:07 +02:00
Phil Sutter 31f1434dfe libxtables: Integrate getethertype.c from xtables core
This moves getethertype.c into libxtables so that both extensions and
xtables-nft-multi may use the implementations therein. New users are
libebt_arp and libebt_vlan which drop their own duplicated
implementations of getethertypebyname() for the shared one.

This change originated from a covscan report of extensions'
implementations not checking fopen() return value which should be
implicitly fixed by this as well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-24 11:23:46 +02:00
Phil Sutter 4144571f87 libxtables: Fix potential array overrun in xtables_option_parse()
If entry->type is to be used as array index, it needs to be at max one
less than that array's size.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-13 10:47:42 +02:00
Florian Westphal 1a696c99d2 libxtables: store all requested match types
iptables and ip6tables don't need this because iptables is AF_INET,
ip6tables AF_INET6, etc.

But tools that can change af in-between such as nftables will then
may then find to find such module.

One example is conntrack, it offsers NFPROTO_IPV4 and NFPROTO_IPV6.
When first loading with NFPROTO_IPV6, the IPV4 would be discarded.

Signed-off-by: Florian Westphal <fw@strlen.de>
2018-05-14 01:24:26 +02:00
Serhey Popovych 12a52ff9cc xtables: Fix rules print/save after iptables update
Updating iptables from 1.4.x to 1.6.x brokes rules print/save output
and causes rules load after reboot to fail. Here is example from
iptables-save(8) output after update:

  -A CHAIN1 -m set [unsupported revision] -j DROP
  -A CHAIN1 -m set [unsupported revision] -j DROP

Similar output could be obtained via iptables -L CHAIN1. While issue
reproduced with xt_set match it is not specific to any match or
target module: it is related on how xtables handles revisions.

In this particular case we have following situation:

  1) Kernel supports revisions from 1 to 4.

  2) Rules configured with iptables 1.4.x supporting only
     revisions from 1 to 3. Choosen highest possible revision 3.

  3) Rules printed/saved with iptables 1.6.x supporting revisions
     from 1 to 4.

  4) Xtables registers matches/targets with highest supported
     revision by the kernel. This is 4 in our case after update to
     iptables 1.6.x.

  5) When printing/saving kernel submits match/target with revision
     it is configured (3), while iptables thinks that rules configured
     with highest supported (4). That's causes revision mismatch in
     during print and "[unsupported revision]" output.

To fix this issue we now store all supported by kernel and xtables
revisions in xt_matches/xt_targets list sorted in descending order.

Introduce helper routines to find match/target with given revision
and use them to find right revision to print submitted by kernel
entry.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-04-27 18:56:27 +02:00
Serhey Popovych 1197c5e35c xtables: Register all match/target revisions supported by us and kernel
Keep the order of matches by appending them; keep order between
revisions of same match from most to least recent. All of this
keeps xtables_find_match() happy to find most recent supported
by kernel revision in the given order.

Apply the same for targets, except prepend targets; order between
revisions preserved too.

All this needed to fix nasty bug related to iptables package update
and broken print/save output.

After this change all supported revisions of match/target stored
in corresponding list with following pattern:

         xt_matches                 xt_targets
         ==========                 ==========

     m1  m2  m3     mN             tN     t1  t2  t3
  +-----+--+---+---~~~---+    +---~~~---+---+----+--+
  |43210|10|210|revisions|    |revisions|210|3210|10|
  +-----+--+---+---~~~---+    +---~~~---+---+----+--+

Where new [m]atches added to the list tail and new [t]argets added
to the list head to preserve previous behaviour. Multiple revisions
of single match/target type are grouped together and sorted in
descending order. Both this ensures xtables_find_match() and
xtables_find_target() behaviour remains the same after change: find
highest supported match/target revision given by it's name.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-04-27 18:56:26 +02:00
Serhey Popovych e3bb24cbaa xtables: Check match/target size vs XT_ALIGN(size) at register time
Size is known at xtables_register_match()/xtables_register_target()
calls: no need to defer it to final registration steps.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-04-27 18:56:23 +02:00
Serhey Popovych 3b2530ce7a xtables: Do not register matches/targets with incompatible revision
If kernel tells revision isn't found/supported at the moment we should
keep entity in pending list, not register or bail to do so later.

Kernel might still load module for entity we asking it for and this
could be slow on some embedded devices.

Catch double registration attempts by checking me->next being non-NULL
in xtables_register_match() and xtables_register_target().

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-04-27 18:56:22 +02:00
Serhey Popovych d3f143727c xtables: Introduce and use common function to print val[/mask] arguments
There are number of places where argument is in val[/mask] format
printed in extensions and some of them may print corresponding symbolic
name.

By introducing common function for this task we eliminate custom code
parts in extensions to perform printing of arguments in required
formats.

Use xtables_print_mark_mask() helper for extensions without
symbolic name for val[/mask].

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-04-27 18:56:22 +02:00
Serhey Popovych 29b1d97764 xtables: Introduce and use common function to parse val[/mask] arguments
There are a couple of places in both core and extensions where arguments
in the form of val[/mask] is parsed (see XTTYPE_MARKMASK32).

In some cases symbolic name might be used which is mapped in code to
numeric value.

Introduce common function to handle both cases where value given is
either val[/mask] or symbolic name.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-04-27 18:56:20 +02:00
Oliver Ford c29d99c83d libxtables: Display weird character warning for wildcards
Change the scope of the weird character check loop so that
it checks for invalid characters when the interface name
contains a wildcard.

Fixes Bugzilla #1085.

Signed-off-by: Oliver Ford <ojford@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2017-05-08 20:01:38 +02:00
Jan Engelhardt 48ad179bfd libxtables: abolish AI_CANONNAME
ares->ai_canonname is never used, so there is no point in requesting
that piece of information with AI_CANONNAME.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2017-03-08 17:48:53 +01:00
Jan Engelhardt 9f50bbdfee libxtables: remove unnecessary nesting from host_to_ip(6)addr
The error path already terminally returns from the function, so there
is no point in having an explicit else block.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2017-03-08 17:48:51 +01:00
Shyam Saini 77db569dcd libxtables: xtables: Use getnameinfo()
Replace gethostbyaddr() with getnameinfo() as getnameinfo()
deprecates the former and allows programs to
eliminate IPv4-versus-IPv6 dependencies

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-12-20 00:36:38 +01:00
Shyam Saini 7f526c9373 libxtables: xtables: remove unnecessary debug code
Remove unnecessary debug code

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-12-20 00:32:54 +01:00
Arpan Kapoor 2d2b5e046a libxtables: Replace gethostbyname() with getaddrinfo()
Make the function host_to_ipaddr() similar to host_to_ip6addr(),
using getaddrinfo() instead of the obsoleted gethostbyname().

Signed-off-by: Arpan Kapoor <rpnkpr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-07-03 11:07:16 +02:00
Pablo Neira Ayuso c93850d1d7 libxtables: missing comment initialization in xt_xlate_alloc()
Initialize comment buffer when allocation the xt translation structure.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-03-25 18:46:52 +01:00
Shivani Bhardwaj a9a599ab67 comment: Add translation to nft
Add translation for match comment to nftables.
This patch also adds the relevant infrastructure for carrying out
the translation.

Example:

$ sudo iptables-translate -A INPUT -s 192.168.0.0 -m comment --comment "A privatized IP block"
nft add rule ip filter INPUT ip saddr 192.168.0.0 counter comment \"A privatized IP block\"

Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-02-29 13:32:48 +01:00
Pablo Neira Ayuso e9855aaeac xtables: add xt_xlate_add_comment()
This new function allows us to add comments to the nft rule. This
can be used to provide a translation for the comment match.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-02-16 19:30:25 +01:00
Pablo Neira Ayuso 6b60dc5be5 extensions: rename xt_buf to xt_xlate
Use a more generic name for this object to prepare the introduction of
other translation specific fields.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-02-16 19:30:25 +01:00
Pablo Neira Ayuso ca9a1a6a9f libxtables: fix leak in xt_buf object
Release data area that is allocated by xt_buf_alloc().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-02-16 19:30:25 +01:00
Pablo Neira Ayuso 933400b37d nft: xtables: add the infrastructure to translate from iptables to nft
This patch provides the infrastructure and two new utilities to
translate iptables commands to nft, they are:

1) iptables-restore-translate which basically takes a file that contains
   the ruleset in iptables-restore format and converts it to the nft
   syntax, eg.

 % iptables-restore-translate -f ipt-ruleset > nft-ruleset
 % cat nft-ruleset
 # Translated by iptables-restore-translate v1.4.21 on Mon Apr 14 12:18:14 2014
 add table ip filter
 add chain ip filter INPUT { type filter hook input priority 0; }
 add chain ip filter FORWARD { type filter hook forward priority 0; }
 add chain ip filter OUTPUT { type filter hook output priority 0; }
 add rule ip filter INPUT iifname lo counter accept
 # -t filter -A INPUT -m state --state INVALID -j LOG --log-prefix invalid:
 ...

The rules that cannot be translated are left commented. Users should be able
to run this to track down the nft progress to see at what point it can fully
replace iptables and their filtering policy.

2) iptables-translate which suggests a translation for an iptables
   command:

 $ iptables-translate -I OUTPUT -p udp -d 8.8.8.8 -j ACCEPT
 nft add rule filter OUTPUT ip protocol udp ip dst 8.8.8.8 counter accept

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-02-16 19:30:21 +01:00
Ville Skyttä 92dc4f6e0e iptables: Spelling fixes
While at it, update comment format for the respective blocks.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-09-07 20:24:59 +02:00
Arturo Borrero 06d14d702e libxtables: find extensions based on family too
When using libxtables with an external program (nft) which switches family
contexts (using xtables_set_nfproto()), the xtables_find_{match,target}
functions need to compare the family too.

We want to avoid this situation:

 1) user first sets afinfo to IPv6
 2) xtables_find_target() finds & load ip6t_REJECT and uses it
 3) afinfo change to IPv4
 4) user then tries to use ipt_REJECT
 5) xtables_find_target() finds ip6t_REJECT instead (same target name)
 6) using ip6t_REJECT as ipt_REJECT can cause a lot of troubles

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-04-09 19:03:07 +02:00
Pablo Neira Ayuso 2c6334181d xtables-compat: remove unused fields from bridge and arp families
These two families only work under nft compat, so leave unset the fields
that we don't use. Basically, we need neither the module autoload code
nor the native get/setsockopt() revision infrastructure since we use the
one that nft_compat provides through nfnetlink.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-02-18 23:43:13 +01:00