Skip to content

feat: enable fwmark (SO_MARK) for outgoing sockets#202

Merged
sbruens merged 10 commits into
OutlineFoundation:masterfrom
sabify:master
Dec 16, 2024
Merged

feat: enable fwmark (SO_MARK) for outgoing sockets#202
sbruens merged 10 commits into
OutlineFoundation:masterfrom
sabify:master

Conversation

@sabify

@sabify sabify commented Aug 25, 2024

Copy link
Copy Markdown

No description provided.

@sabify sabify requested a review from a team as a code owner August 25, 2024 17:41
Comment thread service/tcp.go Outdated
Comment thread internal/integration_test/integration_test.go Outdated
Comment thread cmd/outline-ss-server/main.go Outdated
Comment thread cmd/outline-ss-server/main.go Outdated
@sbruens

sbruens commented Sep 4, 2024

Copy link
Copy Markdown

I have merged some large refactors we've been working on recently; apologies for the merge conflicts, and thank you for this contribution!

We may want to have some more dialer config options in future, so I suggest maybe a dialer wrapper in the config:

dialer:
  fwmark: ...

/cc @fortuna to weigh in on that

@fortuna

fortuna commented Sep 4, 2024

Copy link
Copy Markdown

@sabify thanks for the changes to inject the dialer. That's solid. As @sbruens pointed out, we need to pull the changes and I like the idea of putting the fwmark in a dialer config. That could be a place for other settings, like interface binding, routing, enable local network, etc)

@sabify

sabify commented Sep 9, 2024

Copy link
Copy Markdown
Author

@sbruens @fortuna I just made changes based on the refactored code.

Comment thread service/tcp.go Outdated
Comment thread service/udp.go Outdated
Comment thread service/udp.go Outdated
@fortuna

fortuna commented Sep 11, 2024

Copy link
Copy Markdown

By the way, for your use case, have you considered using a firewall rule based on the PID?

You can probably do things like:

sudo nft add rule filter output meta pid $PID mark set 0x1234

With iptables you can use cgroups and add the pid to it.

It's also possible to use network namespaces.

@sabify

sabify commented Sep 12, 2024

Copy link
Copy Markdown
Author

By the way, for your use case, have you considered using a firewall rule based on the PID?

You can probably do things like:

sudo nft add rule filter output meta pid $PID mark set 0x1234

With iptables you can use cgroups and add the pid to it.

It's also possible to use network namespaces.

This already adds too much complexity for even simple routing logic.

I made the changes to be linux-specific but it also opens room for other similar functionality in other platforms like freebsd's SO_USER_COOKIE.

@fortuna fortuna left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the changes. Looking good. I just have a few more tweaks.

Comment thread service/udp_linux.go Outdated
Comment thread service/udp_linux.go Outdated
Comment thread service/tcp_other.go
@sabify

sabify commented Sep 12, 2024

Copy link
Copy Markdown
Author

Changes applied.

Comment thread cmd/outline-ss-server/main.go Outdated
Comment thread cmd/outline-ss-server/main.go Outdated
Comment thread cmd/outline-ss-server/main.go Outdated
Comment thread service/socketopts_linux.go Outdated
@sabify

sabify commented Sep 28, 2024

Copy link
Copy Markdown
Author

@fortuna @sbruens I just gave you maintainer access to my fork and you are able to apply any of your concerns and code styles that fit best with the codebase. I may not be able to keep up with the rapid changes and requests in the codebase and this PR due to time constraints. Sorry for that and appreciate your work to land this feature. Thank you!

@fortuna fortuna requested a review from sbruens November 21, 2024 15:54
@sbruens

sbruens commented Dec 16, 2024

Copy link
Copy Markdown

@fortuna @sbruens I just gave you maintainer access to my fork and you are able to apply any of your concerns and code styles that fit best with the codebase. I may not be able to keep up with the rapid changes and requests in the codebase and this PR due to time constraints. Sorry for that and appreciate your work to land this feature. Thank you!

Thanks for all your hard work on this @sabify. I finally found some time to pick this up and merge in the changes.

@fortuna PTAL

@sbruens sbruens requested a review from fortuna December 16, 2024 16:39

@fortuna fortuna left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for updating this! We should probably release it soon after

@sbruens sbruens merged commit 98db5b4 into OutlineFoundation:master Dec 16, 2024
@sabify

sabify commented Dec 17, 2024

Copy link
Copy Markdown
Author

@sbruens Thanks for taking your time to land this feature.

How is it possible to take control of this feature from outline server (CLI and/or GUI)? https://github.com/Jigsaw-Code/outline-server

@sbruens

sbruens commented Dec 17, 2024

Copy link
Copy Markdown

You can't right now.

There is some work to be done to get this into outline-server, namely:

  • Move outline-server to the new service config format introduced in 9992735 to which you added this dial option. We haven't gotten around to this yet.
  • Add some new API endpoint to actually set/update the dial option(s) so you can call it via the command line.
  • Expose this in the Manager/GUI.

The first 2 seem feasible, but the latter requires more UX research and we may not want to expose such an advanced feature in the Manager anyway.

@sbruens

sbruens commented Dec 20, 2024

Copy link
Copy Markdown
  • Move outline-server to the new service config format introduced in 9992735 to which you added this dial option. We haven't gotten around to this yet.

OutlineFoundation/outline-server#1628

62w71st added a commit to JinaVPN/outline-ss-server-v2 that referenced this pull request Dec 29, 2024
feat: enable `fwmark` (`SO_MARK`) for outgoing sockets (OutlineFoundation#202)
ha-D pushed a commit to JinaVPN/outline-ss-server-v2 that referenced this pull request Jun 23, 2025
* source_file

* Add file source

* Supporting adding keys from a source.

* Add unit testing for cipher entry CRUD.

* Pass sources through to runConfig.

* Add a cipher entry from the source to per port cipherList

* Make tests pass and add a test for a (deprecated) config example.

* Change runConfig to runSource

* Add feature to dynamically add configs to outline server.

* Changing approach to minimal changes to runConfig

* Reverting changes in main.go

* Adds loadsource function.

* Add cipher updater skeleton.

* Add TODO for starting the SS service.

* Implement loadSource() -- Create an initial config object from the first key.

* server_test.go passes but with the deprecated config example yml file.

* Remove shadowsocks.AddKey() and RemoveKey().

* Pass in an empty config to runConfig. We will need synchronization for CipherList though.

* Use the new service config objects with listeners rather than the deprecated config.

* Create AddCipher in CipherUpdater for a cleaner interface.

* Implement key removal. Next: Make key removal faster by not traversing the whole linked list.

* Implement key removal. Next: Make key removal faster by not traversing the whole linked list.

* Cleanup

* Refactor source handling

* Added config_example_source.yml and updated source.go to use it.

* feat: enable `fwmark` (`SO_MARK`) for outgoing sockets (OutlineFoundation#202)

* feat: enable fwmark (SO_MARK) for outgoing sockets

* fix: make fwmark linux-specific functionality

* fix: minor improvements over handling fwmark

* Use `transport.PacketListener` as interface.

* Take the `syscall.RawConn` as input to `SetFwdmark()`.

* Some cleanup.

* Fix copyright dates for new files.

* Fix the error types.

* Revert changes to integration test.

* Optimize removing a cipher entry when a key is removed. (OutlineFoundation#101)

* Add fastAuth to tcp service
ha-D referenced this pull request in JinaVPN/outline-ss-server-v2 Jun 24, 2025
* source_file

* Add file source

* Supporting adding keys from a source.

* Add unit testing for cipher entry CRUD.

* Pass sources through to runConfig.

* Add a cipher entry from the source to per port cipherList

* Make tests pass and add a test for a (deprecated) config example.

* Change runConfig to runSource

* Add feature to dynamically add configs to outline server.

* Changing approach to minimal changes to runConfig

* Reverting changes in main.go

* Adds loadsource function.

* Add cipher updater skeleton.

* Add TODO for starting the SS service.

* Implement loadSource() -- Create an initial config object from the first key.

* server_test.go passes but with the deprecated config example yml file.

* Remove shadowsocks.AddKey() and RemoveKey().

* Pass in an empty config to runConfig. We will need synchronization for CipherList though.

* Use the new service config objects with listeners rather than the deprecated config.

* Create AddCipher in CipherUpdater for a cleaner interface.

* Implement key removal. Next: Make key removal faster by not traversing the whole linked list.

* Implement key removal. Next: Make key removal faster by not traversing the whole linked list.

* Cleanup

* Refactor source handling

* Added config_example_source.yml and updated source.go to use it.

* feat: enable `fwmark` (`SO_MARK`) for outgoing sockets (Jigsaw-Code#202)

* feat: enable fwmark (SO_MARK) for outgoing sockets

* fix: make fwmark linux-specific functionality

* fix: minor improvements over handling fwmark

* Use `transport.PacketListener` as interface.

* Take the `syscall.RawConn` as input to `SetFwdmark()`.

* Some cleanup.

* Fix copyright dates for new files.

* Fix the error types.

* Revert changes to integration test.

* Optimize removing a cipher entry when a key is removed. (Jigsaw-Code#101)

* Add fastAuth to tcp service
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