Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rule: fix 32-bit platforms don't support adding rules with a mark 0xF0000000 #983

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

qxoqx
Copy link
Contributor

@qxoqx qxoqx commented Jun 14, 2024

rule: fix 32-bit platforms don't support adding rules with a mark value of 0x80000000/0xF0000000 ~ 0xF0000000/0xF0000000

Mask int

The maximum value for an int type on a 32-bit platform is 0x7FFFFFFF. Since 0xF0000000 exceeds this limit, we need to use uint instead of int to handle these values.

I also tried to use unit tests under x86 architecture and failed

$ GOARCH=386 go test -v
# github.com/vishvananda/netlink [github.com/vishvananda/netlink.test]
./route_test.go:2336:14: cannot use 0xFFFFFFFF (untyped int constant 4294967295) as int value in assignment (overflows)
FAIL	github.com/vishvananda/netlink [build failed]

rule.Mask = 0xFFFFFFFF

@antoninbas
Copy link

May be related to #528

route_linux.go Outdated Show resolved Hide resolved
rule.go Outdated Show resolved Hide resolved
@aboch
Copy link
Collaborator

aboch commented Jul 9, 2024

@antoninbas please check

route_linux.go Outdated Show resolved Hide resolved
rule.go Outdated Show resolved Hide resolved
Copy link

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

The API changes look good to me, but I am not a maintainer for this repo.
Hopefully users don't find it confusing that Rule{Mark: 0} means "match all marks" but Rule{Mark:1} means "match mark 1 exclusively". To match mark 0 exclusively, one needs to use Rule{Mark: 0, Mask: &mask} with mask := uint32(0xffffffff).
If other believe that this is confusing, the only solution is to make Mark a pointer as well, which also impacts usability to some extent.

rule_linux.go Outdated Show resolved Hide resolved
rule_test.go Outdated Show resolved Hide resolved
@qxoqx
Copy link
Contributor Author

qxoqx commented Aug 5, 2024

The API changes look good to me, but I am not a maintainer for this repo. Hopefully users don't find it confusing that Rule{Mark: 0} means "match all marks" but Rule{Mark:1} means "match mark 1 exclusively". To match mark 0 exclusively, one needs to use Rule{Mark: 0, Mask: &mask} with mask := uint32(0xffffffff). If other believe that this is confusing, the only solution is to make Mark a pointer as well, which also impacts usability to some extent.

~@ubuntu:~$ ip rule add fwmark 0 table 300 pref 120
~@ubuntu:~$ ip rule add fwmark 1 table 300 pref 120
~@ubuntu:~$ ip rule add fwmark 0/0xFFFFFFFF table 300 pref 130
~@ubuntu:~$ ip rule add fwmark 1/0xFFFFFFFF table 300 pref 130
~@ubuntu:~$ ip rule show
120:	from all lookup 300  <-------  mark 0 match all marks
120:	from all fwmark 0x1 lookup 300
130:	from all fwmark 0 lookup 300
130:	from all fwmark 0x1 lookup 300

I used the ip command to add rules with fwmark:0, fwmark:1, fwmark:0/0xFFFFFFFF, and fwmark: 1/0xFFFFFFFF. There's a similar confusing phenomenon here.
As an API interface, should we replicate the behavior of the ip command, or should we avoid potentially confusing behavior internally in the API.
What should be the decision?
@antoninbas

…alue of 0x80000000/0xF0000000 ~ 0xF0000000/0xF0000000

 The maximum value for an `int` type on a 32-bit platform is 0x7FFFFFFF. Since 0xF0000000 exceeds this limit, we need to use `uint` instead of `int` to handle these values.
@antoninbas
Copy link

@qxoqx I was unaware that there was a similar behavior with ip rule, thanks for pointing it out.
Then I would say the current version looks good to me, but again I am not a maintainer for this repo so the decision is not mine.

@aboch
Copy link
Collaborator

aboch commented Aug 5, 2024

Thanks @antoninbas

LGTM

@aboch aboch merged commit 8f96fd8 into vishvananda:main Aug 5, 2024
2 checks passed
@qxoqx
Copy link
Contributor Author

qxoqx commented Aug 7, 2024

Thank you all for review the PR!

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.

3 participants