g3
g3 copied to clipboard
bind to specific interface for tcp listener
Correct me if I'm wrong, but currently it does not seem to be possible to bind a tcp listener (server), e.g. as used by a sni or http proxy, to a specific (network) interface. With escapers this is possible via bind_interface. Given you already have all the socks support under the hoodit should be trivial to add, but I would like to know your input on this and whether or not I am missing something here.
Alternatives options:
- do not do it
- bind to a specific address (e.g. instead of binding to
0.0.0.0or[::]one could bind to the address within the network interface- this is less ideal however as now you would need to know the IP that "you" have on that network interface.
I haven't tried this but it seems to be useful, so I'm OK to merge the PR.
One question here: will bind_interface conflict with bind address?
One question here: will bind_interface conflict with bind address?
Yes. But of course besides the interface there are other socket options that are not conflicting. So it could be something like:
bind: str | map
as map would be something like:
bind:
interface: str
.. opther options
where bind: str and interface: str could be either an address or a a network interface, don't think there is ambiguity there
Dunno what you think about that or how you see it.
Looks good. Only one suggestion for the map format:
bind:
interface: <ifname> # only parse as interface name
address: <addr str> # this is already existed and parsed as socket address string
.. opther options
What to do if both interface and address are defined? Error? Or one over another?
I think they can be set separately. There may be some cases that one want to listen on an interface but also with one fixed port, such as listen on eth0 and port 80. I'm not sure whether this is possible, can you do some test?