Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added support for FreeBSD/OpenBSD (#200).
FreeBSD
Tested with FreeBSD 14.0, ipfw, with
redirector=generic
.The main point is setting "IP_BINDANY" to avoid os error 49 (Can't assign requested address) at bound_udp_get(). Also,
sizeof(struct sockaddr_in)
seems to be required to avoid "Invalid address" error.This is my script for ipfw/ifconfig.
FreeBSD has firewalls other than IPFW, i.e. pf and ipfilter (ipf).
pf partially worked but destination addresses were obtained as the transparent proxy port (127.0.0.1:22222), useless in actual cases. For TCP, there is a way to get the original destination, but this seems not work for UDP (https://stackoverflow.com/questions/46675715/how-do-i-get-the-original-destination-ip-of-a-redirected-connection-with-pf-on-f#comment119982054_56689694).
FYI, this is my pf configiration.
For ipfilter, I couldn't figure out how to set it up for transparent proxy (though it seems supported by redsocks according to documentation).
I also tried pfSense, but strangely, only UDP worked. (TCP packets won't be received by redsocks).
OpenBSD
Tested with OpenBSD 7.5 and pf,
redirector=generic
.I added 10.0.2.25 as before, and this is the configuration.
To make it work, I added some options like IP_RECVDSTADDR for sockets, according to man page documentation on
divert-to
syntax. ge9@65fa263Currently it support only IPv4. (IPv6 udp relay seems not supported by redsocks itself)
Also, similarly to FreeBSD, SO_BINDANY is set to avoid os error 49.
If we use
rdr-to
instead ofdivert-to
here, the destination addresses are obtained as 127.0.0.1:22222, much like the behavior of FreeBSD's pf.redirector=pf
doesn't work correctly for TCP, because it's for FreeBSD's pf.I also tried NetBSD which OpenBSD originates from, but it seems that there are no
divert-to
in NetBSD's pf.