177 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 6649292524 update: 更新文件 BUILD.gn
Signed-off-by: Jackson-Wang-K <wanglu292@huawei.com>
2026-06-30 20:55:24 +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 c6cff7ddd4 libiptc: Avoid gcc-10 zero-length array warning
Gcc-10 doesn't like the use of zero-length arrays as last struct member
to denote variable sized objects. The suggested alternative, namely to
use a flexible array member as defined by C99, is problematic as that
doesn't allow for said struct to be embedded into others. With the
relevant structs being part of kernel UAPI, this can't be precluded
though.

The call to memcpy() which triggers the warning copies data from one
struct xt_counters to another. Since this struct is flat and merely
contains two u64 fields, One can use direct assignment instead which
avoids the warning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2020-10-12 13:27:23 +02:00
Maciej Żenczykowski 9dd0c48476 libiptc: do not typedef socklen_t on Android
This is present in bionic header files regardless of compiler
being used (likely clang)

Test: builds
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-05-11 01:04:22 +02:00
Florian Westphal 03a4a20b67 libiptc: silence two comiler warnings
avoid hyptothetical truncation by leaving space for triling zero byte.
silcences:

In file included from libip4tc.c:113:
libiptc.c: In function ‘iptcc_alloc_chain_head’:
libiptc.c:163:2: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
  163 |  strncpy(c->name, name, TABLE_MAXNAMELEN);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libiptc.c: In function ‘iptc_rename_chain’:
libiptc.c:2388:2: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
 2388 |  strncpy(c->name, newname, sizeof(IPT_CHAINLABEL));
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Florian Westphal <fw@strlen.de>
2019-09-16 15:44:48 +02:00
Florian Westphal 7f97513ae2 libiptc: axe non-building debug code
hasn't built with IPTC_DEBUG=1 since at least 2004, so remove it.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1275
Signed-off-by: Florian Westphal <fw@strlen.de>
2019-09-16 14:16:20 +02:00
Jan Engelhardt a84b12c69d build: remove -Wl,--no-as-needed and libiptc.so
Despite the presence of --no-as-needed, the libiptc.so library as
produced inside the openSUSE Build Service has no links to
libip4tc.so or libip6tc.so. I have not looked into why --no-as-needed
is ignored in this instance, but likewise, the situation must have
been like that ever since openSUSE made as-needed a distro-wide
default (gcc 4.8 timeframe or so).

Since I am not aware of any problem reports within SUSE/openSUSE
about this whole situation, it seems safe to assume no one in the
larger scope is still using a bare "-liptc" on the linker command
line and that all parties have moved on to using pkg-config.

Therefore, libiptc.la/so is hereby removed, as are all parts
related to the -Wl,--no-as-needed flag.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
2019-05-30 22:43:13 +02:00
Phil Sutter 341279e090 libiptc: Extend struct xtc_ops
Add a few more callbacks used by iptables-save.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-11-13 12:12:47 +01:00
Phil Sutter a76ba54e28 libiptc: NULL-terminate errorname
In struct chain_head, field 'name' is of size TABLE_MAXNAMELEN, hence
copying its content into 'error_name' field of struct xt_error_target
which is two bytes shorter may overflow. Make sure this doesn't happen
by using strncpy() and set the last byte to zero.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-25 16:26:20 +02:00
Phil Sutter 22ef371abe libiptc: Simplify alloc_handle() function signature
This change originated from covscan complaining about the strcpy() call
with an unknown size source buffer. But in fact, the size is known (and
equal to the destination size), so pass a pointer to STRUCT_GETINFO to
alloc_handle() instead of it's fields separately. Hopefully this will
silence covscan.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-24 11:24:06 +02:00
Phil Sutter e6f9867626 libiptc: Avoid side-effect in memset() calls
These calls to memset() are passed a length argument which exceeds
t->target.u.user.name's length by one byte and hence overwrite
t->target.u.user.revision as well (relying upon no padding to happen
between both).

Avoid this obscure behaviour by passing the correct field size and
explicitly overwriting 'revision' field.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2018-09-13 10:47:52 +02:00
Dan Williams 9b8cb7564a libiptc: don't set_changed() when checking rules with module jumps
Checking a rule that includes a jump to a module-based target currently
sets the "changed" flag on the handle, which then causes TC_COMMIT() to
run through the whole SO_SET_REPLACE/SO_SET_ADD_COUNTERS path.  This
seems wrong for simply checking rules, an operation which is documented
as "...does not alter the existing iptables configuration..." but yet
it clearly could do so.

Fix that by ensuring that rule check operations for module targets
don't set the changed flag, and thus exit early from TC_COMMIT().

Signed-off-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2017-02-28 13:20:19 +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
Mike Frysinger 6028d4aa2d libiptc: fix fortify errors in debug code
When using open(O_CREAT), you must supply the mode bits, otherwise the
func will pull random garbage off the stack.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-08-26 21:08:05 +02:00
Arturo Borrero 86a65af62b list: fix prefetch dummy
linux_list.h:381:59: warning: right-hand operand of comma expression has no effect [-Wunused-value]
  for (pos = list_entry((head)->next, typeof(*pos), member), \
                                                           ^
libiptc.c:552:2: note: in expansion of macro 'list_for_each_entry'
  list_for_each_entry(c, &h->chains, list) {
  ^

[ Patch copied from one similar of Patrick McHardy on libnftnl ]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
2015-04-08 19:07:54 +02:00
Pablo Neira Ayuso cccfff9309 libip6t_NETMAP: Use xtables_ip6mask_to_cidr and get rid of libip6tc dependency
This patch changes the NETMAP target extension (IPv6 side) to use
the xtables_ip6mask_to_cidr available in libxtables.

As a side effect, we get rid of the libip6tc dependency.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2013-03-29 16:41:32 +01:00
Miguel GAIO 8db1044ba6 libiptc: fix retry path in TC_INIT
There is an issue on TC_INIT retry path:
In error case, TC_FREE is called and close sockfd.
The retry does not reopen then always fail.

The proposing patch reopens sockfd in retry patch.

Signed-off-by: Miguel GAIO <miguel.gaio@efixo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2012-04-19 18:54:20 +02:00
Maciej Żenczykowski c0aa38e22e src: mark newly opened fds as FD_CLOEXEC (close on exec)
By default, Unix-like systems leak file descriptors after fork/exec
call. I think this seem to result in SELinux spotting a strange AVC
log messages according to what I can find on the web.

Fedora 18 iptables source includes this change.

Maciej says:
"iptables does potentially fork/exec modprobe to load modules.
That can cause a selinux 'domain'/'role'/whatever-it-is-called crossing.
You can do automated inspection of what gets carried across such
privilege changes and any unexpected open file descriptors flag
problems, patches like this cut down on the noise."

Signed-off-by: Maciej  enczykowski <maze@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2012-03-23 11:24:30 +01:00
Franz Flasch 61b8f7ecb6 iptables: missing free() in function delete_entry()
Fixed a memory leak in the dry run path of function delete_entry().

Signed-off-by: Franz Flasch <franz.flasch@frequentis.com>
Signed-off-by: Christian Engelmayer <christian.engelmayer@frequentis.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2012-03-12 12:57:57 +01:00
Franz Flasch 1a7732f965 iptables: missing free() in function cache_add_entry()
Fixed a memory leak in the error path of function cache_add_entry().

Signed-off-by: Franz Flasch <franz.flasch@frequentis.com>
Signed-off-by: Christian Engelmayer <christian.engelmayer@frequentis.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2012-03-12 12:57:49 +01:00
Pablo Neira Ayuso 7c1b69b975 Revert "libiptc: Returns the position the entry was inserted"
This reverts commit d65702c5c5.

This is breaking my iptables scripts:

iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables: Incompatible with this kernel.
2012-03-01 00:27:50 +01:00
Jonh Wendell d65702c5c5 libiptc: Returns the position the entry was inserted
Jan Engelhardt showed no objections to this patch.
2012-02-29 13:48:00 +01:00
Jan Engelhardt 32a4b7dcaf Merge branch 'stable' 2011-12-18 03:10:57 +01:00
Jan Engelhardt b8c42eca0f libiptc: provide separate pkgconfig files
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-12-18 02:52:32 +01:00
Jan Engelhardt de4d2d3b71 libiptc: use a family-invariant xtc_ops struct for code reduction
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-09-11 17:31:35 +02:00
Jan Engelhardt 14da56743c src: resolve old macro names that are indirections
Command used:

	git grep -f <(pcregrep -hior
	'(?<=#define\s)IP6?(T_\w+)(?=\s+X\1)' include/)

and then fix all occurrences.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-09-11 17:31:35 +02:00
Jan Engelhardt 1639fe8657 libiptc: combine common types: _handle
No real API/ABI change incurred, since the definition of the structs'
types is not visible anyhow.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-09-11 17:31:35 +02:00
Jan Engelhardt 7e5e866a36 libiptc: replace ipt_chainlabel by xt_chainlabel
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-09-11 17:31:34 +02:00
Jan Engelhardt 160f25b09f libiptc: remove unused HOOK_DROPPING thing
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-09-11 17:31:34 +02:00
Jan Engelhardt 9cf67deb62 libiptc: resolve compile failure
CC     libip4tc.lo
In file included from libip4tc.c:118:0:
libiptc.c:70:8: error: redefinition of "struct xt_error_target"
../include/linux/netfilter/x_tables.h:69:8: note: originally defined here

Remove libiptc's duplicate definition and substitute names.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-09-11 17:31:34 +02:00
Jiri Popelka 96d0d0130a iptables: Coverity: DEADCODE
libiptc.c:407: dead_error_condition: On this path, the condition
"res > 0" cannot be false.
libiptc.c:396: at_least: After this line, the value of "res" is at
least 1.
libiptc.c:393: equality_cond: Condition "res == 0" is evaluated as
false.
libiptc.c:396: new_values: Noticing condition "res < 0".
libiptc.c:425: new_values: Noticing condition "res < 0".
libiptc.c:407: new_values: Noticing condition "res > 0".
libiptc.c:435: dead_error_line: Execution cannot reach this statement
"return list_pos;".

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-06-22 15:53:33 +02:00
Jan Engelhardt 38ffc9dc5b build: re-add missing CPPFLAGS for libiptc
These got lost on commit v1.4.11-12-g5c8f5b6.

Note: When /usr/include/libiptc/libiptc.h exists, this error is
masked away :-/  (IMO, #include-with-quotes "foo.h" should not
search system dirs...)

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-06-08 12:28:50 +02:00
Jan Engelhardt 5c8f5b60aa src: move all libiptc pieces into its directory
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-06-07 11:42:03 +02:00
Jan Engelhardt 7d91a2accc build: remove dead code parts
gcc-4.6 has a new warning, -Wunused-but-set-variable, which flags
no-op code.

  CC     libiptc/libip4tc.lo
In file included from libiptc/libip4tc.c:118:0:
libiptc/libiptc.c: In function "iptcc_chain_index_delete_chain":
libiptc/libiptc.c:611:32: warning: variable "index_ptr2" set but not used
libiptc/libiptc.c: In function "alloc_handle":
libiptc/libiptc.c:1282:9: warning: variable "len" set but not used
  CC     libiptc/libip6tc.lo
In file included from libiptc/libip6tc.c:113:0:
libiptc/libiptc.c: In function "iptcc_chain_index_delete_chain":
libiptc/libiptc.c:611:32: warning: variable "index_ptr2" set but not used
libiptc/libiptc.c: In function "alloc_handle":
libiptc/libiptc.c:1282:9: warning: variable "len" set but not used
  CC     xtables_multi-iptables-xml.o
iptables-xml.c: In function "do_rule_part":
iptables-xml.c:376:8: warning: variable "thisChain" set but not used
  CC     xtables_multi-ip6tables.o
ip6tables.c: In function "print_firewall":
ip6tables.c:552:10: warning: variable "flags" set but not used

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-05-30 01:39:54 +02:00
Jan Engelhardt dcd1ad8910 src: replace old IP*T_ALIGN macros
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-05-12 12:09:13 +02:00
Stefan Tomanek d59b9db031 iptables: add -C to check for existing rules
It is often useful to check whether a specific rule is already present
in a chain without actually modifying the iptables config.

Services like fail2ban usually employ techniques like grepping through
the output of "iptables -L" which is quite error prone.

This patch adds a new operation -C to the iptables command which
mostly works like -D; it can detect and indicate the existence of the
specified rule by modifying the exit code. The new operation
TC_CHECK_ENTRY uses the same code as the -D operation, whose functions
got a dry-run parameter appended.

Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-03-08 23:12:05 +01:00
Jan Engelhardt 7ac405297e src: use C99/POSIX types
"u_int" was a non-standardized extension predating C99 on some platforms.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2011-01-08 01:58:45 +01:00
Dmitry V. Levin 390755ded5 libip4tc: Add static qualifier to dump_entry()
Change dump_entry() signature defined in libip4tc.c to match prototype
declared in libiptc.c and another static dump_entry() function defined
in libip6tc.c.  This function is not a part of the public libiptc API.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-02-18 18:08:31 +01:00
Jan Engelhardt 7c4d668c9c libiptc: fix wrong maptype of base chain counters on restore
When a ruleset that does not reset any chain policies/counters, such as

	*filter
	COMMIT

is sourced by iptables-restore, the previous policy and counters
(i.e. the ones read from the kernel) are reused. The counter skew
offsetting is wrong however, causing the read value to be readded to
the kernel value. This manifests itself in practice by the counter
value almost doubling everytime iptables-restore is called.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2009-10-29 19:04:00 +01:00
Jan Engelhardt 51651b64ff libiptc: avoid strict-aliasing warnings
In file included from libiptc/libip4tc.c:117:0:
libiptc/libiptc.c: In function ‘__iptcc_p_del_policy’:
libiptc/libiptc.c:826:4: warning: dereferencing type-punned pointer will break
strict-aliasing rules
libiptc/libiptc.c: In function ‘iptc_get_target’:
libiptc/libiptc.c:1650:4: warning: dereferencing type-punned pointer will break
strict-aliasing rules
libiptc/libip4tc.c: In function ‘dump_entry’:
libiptc/libip4tc.c:157:3: warning: dereferencing type-punned pointer will break
strict-aliasing rules
  CC     libiptc/libip6tc.lo
In file included from libiptc/libip6tc.c:112:0:
libiptc/libiptc.c: In function ‘__iptcc_p_del_policy’:
libiptc/libiptc.c:826:4: warning: dereferencing type-punned pointer will break
strict-aliasing rules
libiptc/libiptc.c: In function ‘ip6tc_get_target’:
libiptc/libiptc.c:1650:4: warning: dereferencing type-punned pointer will break
strict-aliasing rules
libiptc/libip6tc.c: In function ‘dump_entry’:
libiptc/libip6tc.c:188:3: warning: dereferencing type-punned pointer will break
strict-aliasing rules

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2009-10-25 11:01:25 +01:00
Jan Engelhardt a9c79c7ba4 libiptc: remove unused functions
Fix the two warnings in libiptc.c:

  CC     libiptc/libip4tc.lo
libiptc/libiptc.c:1570:1: warning: ‘iptc_num_rules’ defined but not used
libiptc/libiptc.c:1586:1: warning: ‘iptc_get_rule’ defined but not used
  CC     libiptc/libip6tc.lo
libiptc/libiptc.c:1570:1: warning: ‘ip6tc_num_rules’ defined but not used
libiptc/libiptc.c:1586:1: warning: ‘ip6tc_get_rule’ defined but not used

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
2009-10-25 11:00:33 +01:00
Jesper Dangaard Brouer c9477d0dcd libiptc: give credits to my self
Add notes about my scalability work on the library libiptc.
This should make in more obvious who to complain to.

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2009-03-23 14:27:44 +01:00
Jesper Dangaard Brouer a9fe5b3d62 libiptc: fix whitespaces and typos
Cleanup whitespaces while going through the code.

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2009-03-23 14:26:56 +01:00
Jesper Dangaard Brouer 64ff47cde3 libiptc: fix chain rename bug in libiptc
Chain renaming (TC_RENAME_CHAIN) can result in an unsorted
chain list.  That breaks the requirement of the binary search
done in iptcc_bsearch_chain_index().

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2009-03-23 14:25:49 +01:00
Christoph Paasch 7cd15e367c libiptc: avoid compile warnings for iptc_insert_chain
iptc_insert_chain is too big to get inlined and so it generates
a warning while compiling.

Signed-off-by: Christoph Paasch <christoph.paasch@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2009-03-23 13:50:11 +01:00