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

Set mark during address selection #489

Merged

Conversation

flu0r1ne
Copy link
Contributor

@flu0r1ne flu0r1ne commented Oct 4, 2023

This PR addresses and resolves issue #485 concerning address selection when using a packet mark. While I believe there's a more "correct" way to fix this issue, the solution would require extensive changes that I currently do not have the time to implement.

This PR tackles the most prevalent variant of the issue. I plan to create a new issue outlining my ideal approach for resolving this problem. This will serve as a guide for anyone who might revisit the issue in the future, offering one potential solution and outlining the limitations of the current patch.

Changes

  • The patch makes minimal alterations, fixing the issue by setting the mark during the address selection process.
  • This fix only addresses the problem in mtr and not in mtr-packet.
  • The patch also adds support for parsing packet marks as hex values, which is a common way to refer to packet marks.

Testing

I tested these patches on Linux 6.1 and FreeBSD 13.2. As the changes only involve packet marking, they do not affect non-Linux operating systems. Therefore, FreeBSD can be used as a stand-in for NetBSD or Solaris.

Testing Steps:

Linux

I have a routing table with a unique default gateway corresponding to mark 2088138254. I tested the application both with and without the mark to ensure that it traced the correct path. mtr performed as expected in both scenarios.

make clean
make
MTR_PACKET="./mtr-packet" sudo -E ./mtr -t 1.1.1.1 # traces the expected route
MTR_PACKET="./mtr-packet" sudo -E ./mtr -t -M 2088138254 1.1.1.1 # traces the expected route
MTR_PACKET="./mtr-packet" sudo -E ./mtr -t -M 0x7c76760e 1.1.1.1 # traces the expected route

BSD

As FreeBSD does not support routing marks, my test on this OS involved merely compiling mtr and confirming that it could trace a route, thereby triggering the address selection logic.

make clean
make
MTR_PACKET="./mtr-packet" sudo -E ./mtr 1.1.1.1 # traces the expected route
MTR_PACKET="./mtr-packet" sudo -E ./mtr -I vtnet0 1.1.1.1 # traces the expected route

It is typical to store and manipulate Linux packet marks using unsigned values.
In certain scenarios, the routing policy database may affect packet
routing. When selecting an address in `mtr`, assign a packet mark if
`SO_MARK` is defined and a mark has been supplied.
Packet marks are often specified in hexadecimal format. Update the
`strtonum_or_err` function to parse both hexadecimal and decimal
values.
@flu0r1ne
Copy link
Contributor Author

flu0r1ne commented Oct 4, 2023

See #491 for the limitations of this fix.

@rewolff rewolff merged commit 6e659b8 into traviscross:master Oct 4, 2023
2 checks passed
@yvs2014
Copy link

yvs2014 commented Oct 5, 2023

Therefore, FreeBSD can be used as a stand-in for NetBSD or Solaris.

Mmm... nope. NetBSD is a bit more friendly to port on, Solaris is a tottally different beast.

@rewolff
Copy link
Collaborator

rewolff commented Oct 6, 2023

Right. SunOS was based on BSD. But Solaris is sysV based.

@flu0r1ne
Copy link
Contributor Author

flu0r1ne commented Oct 6, 2023

Mmm... nope. NetBSD is a bit more friendly to port on, Solaris is a tottally different beast.

Thank you, I will keep that in mind. In this case, the code I added only affects address selection when SO_MARK is defined. This is Linux-specific so in this regard all non-Linux operating systems should function the same way. Effectively, I was testing that none of the SO_MARK code bled into the regular control flow.

@flu0r1ne
Copy link
Contributor Author

flu0r1ne commented Oct 6, 2023

I recognize that this does not validate that the other socket operations work. My assumption is that these worked on HEAD prior to this commit.

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