transport/{TCP,TLS}: optional IP_FREEBIND / IP_BINDANY bind socketops

Allows to bind to an address even if it is not actually (yet or ever)
configured. Fixes #238

Rationale:
https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/#whatdoesthismeanformeadeveloper
This commit is contained in:
Juergen Hoetzel
2019-12-30 19:42:17 +01:00
committed by Christian Schwarz
parent 47ed599db7
commit d35e2400b2
16 changed files with 123 additions and 20 deletions
+2 -5
View File
@@ -8,6 +8,7 @@ import (
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/transport"
"github.com/zrepl/zrepl/util/tcpsock"
)
type ipMapEntry struct {
@@ -44,16 +45,12 @@ func (m *ipMap) Get(ip net.IP) (string, error) {
}
func TCPListenerFactoryFromConfig(c *config.Global, in *config.TCPServe) (transport.AuthenticatedListenerFactory, error) {
addr, err := net.ResolveTCPAddr("tcp", in.Listen)
if err != nil {
return nil, errors.Wrap(err, "cannot parse listen address")
}
clientMap, err := ipMapFromConfig(in.Clients)
if err != nil {
return nil, errors.Wrap(err, "cannot parse client IP map")
}
lf := func() (transport.AuthenticatedListener, error) {
l, err := net.ListenTCP("tcp", addr)
l, err := tcpsock.Listen(in.Listen, in.ListenFreeBind)
if err != nil {
return nil, err
}