Go to file
Dmitrii Stepanov 21841df9f7 [#9] go.mod: Fix Go version
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-11-14 15:38:48 +03:00
testdata [#3] dialer: Add `gopatch`s patch. 2023-11-02 13:25:54 +03:00
Makefile [#3] dialer: Add `gopatch`s patch. 2023-11-02 13:25:54 +03:00
README.md [#3] dialer: Add `gopatch`s patch. 2023-11-02 13:25:54 +03:00
balancer.go [#4] dialer: Fix typo 2023-10-26 11:13:42 +03:00
default.go [#3] dialer: Add default dialer. 2023-11-02 13:25:54 +03:00
default_test.go [#3] dialer: Add default dialer. 2023-11-02 13:25:54 +03:00
dialer.go [#4] dialer: Add hostname resolve tests 2023-10-26 11:13:42 +03:00
dialer_hostname_test.go [#4] dialer: Add hostname resolve tests 2023-10-26 11:13:42 +03:00
dialer_integration_test.go [#4] dialer: Move tests to integration tests 2023-10-26 11:13:42 +03:00
go.mod [#9] go.mod: Fix Go version 2023-11-14 15:38:48 +03:00
go.sum [#4] dialer: Add hostname resolve tests 2023-10-26 11:13:42 +03:00
health.go Initial commit 2023-08-16 20:10:49 +03:00
health_integration_test.go [#4] dialer: Add hostname resolve tests 2023-10-26 11:13:42 +03:00
interface.go [#4] dialer: Add hostname resolve tests 2023-10-26 11:13:42 +03:00
multinet.patch [#3] dialer: Add `gopatch`s patch. 2023-11-02 13:25:54 +03:00

README.md

Source-based routing in Golang

Consider this routing table:

10.11.70.0/23 dev data0 proto kernel scope link src 10.11.70.42
10.11.70.0/23 dev data1 proto kernel scope link src 10.11.71.42
192.168.123.0/24 dev internal0 proto kernel scope link src 192.168.123.42
192.168.123.0/24 dev internal1 proto kernel scope link src 192.168.123.142

Simple net.Dial to either 10.11.70.42 or 10.11.71.42 will match the first subnet and be routed via data0. This problems is usually solved by bonds. But sometimes you need to invent a bicycle.

Usage

import "git.frostfs.info/TrueCloudLab/multinet"

d, err := multinet.NewDialer(Config{
    Subnets:  []string{"10.11.70.0/23", "192.168.123.0/24"},
    Balancer: multinet.BalancerTypeRoundRobin,
})
if err != nil {
    // handle error
}

conn, err := d.DialContext(ctx, "tcp", "10.11.70.42")
if err != nil {
    // handle error
}
// do stuff

Updating interface state

Multidialer exposes UpdateInterface() method for updating state of a single link. NetlinkWatcher can wrap Multidialer type and perform all updates automatically.

TODO: describe needed capabilities here.

Patch

To perform refactoring (use multinet.Dial instead of net.Dial) using gopatch:

gopatch -p ./multinet.patch <project directory>