The pointer to pbr was helpful. But there are still some unclear details.
My plan and understanding so far is: following https://openwrt.org/docs/guide-user/network/routing/pbr_app, I would set up pbr and VPN:
opkg update
opkg install pbr
# Enable PBR
uci set pbr.config.enabled="1"
uci commit pbr
service pbr restart
# Support unmanaged protocols like OpenVPN.
uci add_list pbr.config.supported_interface="tun*"
uci commit pbr
service pbr restart
# Disable gateway redirection in the VPN client configuration
# To unset an OpenVPN tunnel as default route, set the following to the appropriate section of your /etc/config/openvpn:
# list pull_filter 'ignore "redirect-gateway"'
# Also add the socks pointer to the VPN config in /etc/config/openvpn:
# add "socks-proxy 127.0.0.1 6876"
Then I would need to add a routing rule from LAN to VPN tun interface:
# Route LAN 192.168.1.0/24 to VPN.
uci add pbr policy
uci set pbr.@policy[-1].src_addr="192.168.1.0/24"
uci set pbr.@policy[-1].interface="vpn" # destination for route?
uci commit pbr
service pbr restart
So far all fine and logical?
Socks proxy still should be able to talk to the internet via WAN,
VPN talks to socks proxy via localhost,
LAN is forwarded to VPN.
Open questions:
How to ensure ssh into the OpenWrt box still works?
I found several potential ways, but I don't understand yet which ones to use single/in combination etc:
One way could be to modify the PBR route policy from above, to include something like dst_addr="!192.168.1.0/32"
, but I did not find any mentioning of logical (boolean) invert operators in the docu.
Another way could be to add an extra RBR policy before the LAN to tun PBR policy. Something like this.
uci add pbr policy
uci set pbr.@policy[-1].dst_addr="192.168.1.1"
uci set pbr.@policy[-1].dst_port="22"
uci set pbr.@policy[-1].proto="tcp"
uci set pbr.@policy[-1].interface="lan" # source? destination?
uci reorder pbr.@policy[-1]="1"
uci commit pbr
service pbr restart
But as you see from the comment, it's unclear to me what I should choose as the destination, when it should be "no routing, keep on this host".
Do I need any additonal firewall rules?
It seems forwarding can also be done using the firewall rule set.
My understanding is, when solving the issue by using PBR, I do not need additional firewall rules to support that (as long as the FW does not block anything by default, i.e. is left as is in original fw image).
Otherwise I'd be included to add something like this in /etc/config/firewall
:
config rule
option name 'Allow-ssh-Inbound'
option target 'ACCEPT'
option src '192.168.1.0/24'
option src '192.168.1.1/32'
option proto 'tcp'
option dest_port '22'
But this only tells the FW to accept ssh connections to openWRT, not how to route these... right?
What happens if the tun device is not up at system boot time?
This only will come up after OpenVPN has established the tunnel. Will the routing then start automatically, or will PBN give up on the tun interface if it is not there at boot time? Will I need to add some kind of if-up scrips?