[#9999] dialer: Define interface state (up/down) on initialization
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
f279b6249d
commit
276a87cde1
3 changed files with 10 additions and 1 deletions
|
@ -151,6 +151,7 @@ func NewDialer(c Config) (Multidialer, error) {
|
||||||
type iface struct {
|
type iface struct {
|
||||||
name string
|
name string
|
||||||
addrs []netip.Prefix
|
addrs []netip.Prefix
|
||||||
|
down bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func processIface(info Interface) (iface, error) {
|
func processIface(info Interface) (iface, error) {
|
||||||
|
@ -168,7 +169,7 @@ func processIface(info Interface) (iface, error) {
|
||||||
|
|
||||||
addrs = append(addrs, p)
|
addrs = append(addrs, p)
|
||||||
}
|
}
|
||||||
return iface{name: info.Name(), addrs: addrs}, nil
|
return iface{name: info.Name(), addrs: addrs, down: info.Down()}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSubnet(subnet string, sources []iface) (Subnet, error) {
|
func processSubnet(subnet string, sources []iface) (Subnet, error) {
|
||||||
|
@ -185,6 +186,7 @@ func processSubnet(subnet string, sources []iface) (Subnet, error) {
|
||||||
ifs = append(ifs, Source{
|
ifs = append(ifs, Source{
|
||||||
Name: source.name,
|
Name: source.name,
|
||||||
LocalAddr: &net.TCPAddr{IP: net.IP(src.AsSlice())},
|
LocalAddr: &net.TCPAddr{IP: net.IP(src.AsSlice())},
|
||||||
|
Down: source.down,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,10 +114,12 @@ func testInterfacesV6() ([]Interface, error) {
|
||||||
type testInterface struct {
|
type testInterface struct {
|
||||||
name string
|
name string
|
||||||
addrs []net.Addr
|
addrs []net.Addr
|
||||||
|
down bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *testInterface) Name() string { return i.name }
|
func (i *testInterface) Name() string { return i.name }
|
||||||
func (i *testInterface) Addrs() ([]net.Addr, error) { return i.addrs, nil }
|
func (i *testInterface) Addrs() ([]net.Addr, error) { return i.addrs, nil }
|
||||||
|
func (i *testInterface) Down() bool { return i.down }
|
||||||
|
|
||||||
type testAddr struct {
|
type testAddr struct {
|
||||||
network string
|
network string
|
||||||
|
|
|
@ -6,6 +6,7 @@ import "net"
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
Name() string
|
Name() string
|
||||||
Addrs() ([]net.Addr, error)
|
Addrs() ([]net.Addr, error)
|
||||||
|
Down() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type netInterface struct {
|
type netInterface struct {
|
||||||
|
@ -20,6 +21,10 @@ func (i *netInterface) Addrs() ([]net.Addr, error) {
|
||||||
return i.iface.Addrs()
|
return i.iface.Addrs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *netInterface) Down() bool {
|
||||||
|
return i.iface.Flags&net.FlagUp == 0
|
||||||
|
}
|
||||||
|
|
||||||
func systemInterfaces() ([]Interface, error) {
|
func systemInterfaces() ([]Interface, error) {
|
||||||
ifaces, err := net.Interfaces()
|
ifaces, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue