Skip to content

Add iptables lock support and iptables_ext configuration options#107

Open
LaakkonenJussi wants to merge 13 commits intosailfishos:masterfrom
LaakkonenJussi:jb63544
Open

Add iptables lock support and iptables_ext configuration options#107
LaakkonenJussi wants to merge 13 commits intosailfishos:masterfrom
LaakkonenJussi:jb63544

Conversation

@LaakkonenJussi
Copy link
Copy Markdown
Contributor

@LaakkonenJussi LaakkonenJussi commented Jun 9, 2025

Use the xtables.lock with flock() to wait until other component has finished with iptables. This may happen if there are multiple components accessing iptables, which might result in a failure and misconfigured iptables.

Add two options for iptables extension:

  • IptablesPrefixesToExclude = list of prefixes in iptables rules to exclude
  • IptablesExtRuntimeOnly = do not restore/save iptables rules

Comment thread connman/src/iptables.c Outdated
Comment thread connman/src/shared/util.c Outdated
@LaakkonenJussi LaakkonenJussi force-pushed the jb63544 branch 2 times, most recently from 35ea997 to 5aacd0f Compare July 7, 2025 16:13
@LaakkonenJussi LaakkonenJussi changed the title Jb63544 Add iptables lock support and iptables_ext configuration options Jul 7, 2025
Add an "IptablesPrefixesToExclude" option to be used with Sailfish
Iptables extension to define the prefixes that are to be excluded from
table/chain/rule parsing.
Use the prefixes defined with IptablesPrefixesToExclude in configuration
to exclude the targets, chains and rules that have them. Those are to be
added by the component to which they belong and ConnMan should not take
part on restoring them, since the targets may not have been setup yet,
causing errors and maybe propagates to other bigger failures.
Add a boolean option to set sailfish iptables extension to runtime (no
save or restore) mode, by default the runtime mode is off and iptables
is saved and restored on boot. This is for the cases where ConnMan is
not meant to save or restore iptables because of other components are
also utilizing iptables.
When IptablesExtRuntimeOnly is set to true skip save and restore of
iptables.
[util] Add file lock and unlock functions. JB#63544

Add functions to lock and unlock a file. Simply use flock to gain
exclusive lock when locking is requested. If locking fails return
-ENOLCK.
[build] Add XT_LOCK_NAME to XTABLES build options. JB#63544

Define the xtables.lock with runstatedir and use it with build. Enable
this only when XTABLES is defined.
[iptables] Use util file locking when setting iptables rules. JB#63544

Utilize file locking in util before calling setsockopt. Release the lock
always.

Cleanup iptables_replace() code.
…JB#63544

When calling iptc_commit() use the file locking in util to wait for
other processes that access iptables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants