Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

libreswan: fix default subnet matching#29781

Open
dhrm1k wants to merge 1 commit into
openwrt:master from
dhrm1k:libreswan-subnet-default-match
Open

libreswan: fix default subnet matching #29781
dhrm1k wants to merge 1 commit into
openwrt:master from
dhrm1k:libreswan-subnet-default-match

Conversation

@dhrm1k

@dhrm1k dhrm1k commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Match only explicit default-route subnet tokens when normalizing leftsubnets
and rightsubnets.

The previous regex treated dots as wildcards, so values such as
10.250.0.0/16 and 10.0.0.0/8 could be rewritten to 0.0.0.0/0.

Fixes: openwrt/openwrt#23795

📦 Package Details

Maintainer: Lucian Cristian lucian.cristian@gmail.com (@lucize)

Description:
Fix the libreswan UCI init script so it only normalizes an explicit default
route subnet token, 0.0.0.0 or 0.0.0.0/0, instead of matching unrelated
private subnets that happen to contain 0.0.0.0 in the string.


🧪 Run Testing Details

  • OpenWrt Version: 25.12.2
  • OpenWrt Target/Subtarget: x86/64
  • OpenWrt Device: libvirt OpenWrt VM

Reproduced the issue on the VM with a temporary /etc/config/libreswan tunnel
containing:

list leftsubnets '10.250.0.0/16'
list rightsubnets '10.0.0.0/8'

Before this change, /etc/init.d/ipsec start generated:

leftsubnets={0.0.0.0/0}
rightsubnets={0.0.0.0/0}

Also tested the new subnet matching helper in the VM shell:

FIX_NO:10.250.0.0/16
FIX_NO:10.0.0.0/8
FIX_NO:192.168.0.0/16
FIX_MATCH:0.0.0.0/0
FIX_MATCH:0.0.0.0
FIX_MATCH:10.0.0.0/8 0.0.0.0/0

Local checks:

git diff --check
sh -n feeds/packages/net/libreswan/files/etc/init.d/ipsec
make package/feeds/packages/libreswan/download V=s
make package/feeds/packages/libreswan/check V=s

✅ Formalities

  • I have reviewed the CONTRIBUTING.md file for detailed contributing guidelines.

If your PR contains a patch:

  • Not applicable, this PR does not add or modify an upstream source patch.

Neustradamus reacted with heart emoji

@pprindeville pprindeville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand why a loop is used for a single argument...

Comment thread net/libreswan/files/etc/init.d/ipsec Outdated
has_default_subnet() {
local subnet

for subnet in 1ドル; do

@pprindeville pprindeville Jun 21, 2026
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a for loop if it's only 1ドル and not $@? Also there's no shift... Have a look at what net/strongswan/files/swanctl.init does with the same argument...

dhrm1k commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Not sure I understand why a loop is used for a single argument...

Ah yes. I was treating the value from config_get as a spaceseparated subnet
list and then looping over the words in 1ドル.

Would you prefer that I change this so the helper iterates over "$@", with the
call sites passing the subnet list as normal positional arguments?

That would make the intent clearer, and there would be no shift needed since
there is no leading argument to consume.

Copy link
Copy Markdown
Member

@dhrm1k: Since it's a list shouldn't we use config_list_foreach in that case?

Copy link
Copy Markdown

The left and right subnets are lists and I am not completely sure of the value searching for 0.0.0.0{/0}.
It seems to me just taking the value passed and using that would be the best.
Otherwise you should also check for an error like 10.250.0.0/16,10.250.1.0/24. or things like overlapping networks.
converting 0.0.0.0 to 0.0.0.0/0 may be a reasonable solution to people missing the /0.
Possibly a better check would be to disallow anything that does not have x.x.x.x/y.

Copy link
Copy Markdown
Member

Possibly a better check would be to disallow anything that does not have x.x.x.x/y.

I could live with that.

Match only explicit default-route subnet tokens when normalizing leftsubnets and rightsubnets.
The previous regex treated dots as wildcards.
Values such as 10.250.0.0/16 and 10.0.0.0/8 were rewritten to 0.0.0.0/0.
Fixes: openwrt/openwrt#23795
Signed-off-by: Dharmik Parmar <dharmikparmar2004@yahoo.com>
@dhrm1k dhrm1k force-pushed the libreswan-subnet-default-match branch from 69bdf97 to faa7df0 Compare June 22, 2026 02:55

dhrm1k commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

I changed this and pushed it again.

It now uses config_list_foreach for both leftsubnets and rightsubnets, so
each UCI list item is handled directly.

I kept the actual behavior change small. 0.0.0.0 is normalized to
0.0.0.0/0, 0.0.0.0/0 is left as-is, and other subnet values are passed
through unchanged.

lucize commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

LGTM, will see what will be pushed first #29806

Neustradamus and dhrm1k reacted with heart emoji

dhrm1k commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

LGTM, will see what will be pushed first #29806

sure. thanks for looking into it!

@pprindeville pprindeville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pprindeville pprindeville pprindeville approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

libreswan submet processing wrong

AltStyle によって変換されたページ (->オリジナル) /