diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-03-18 21:58:45 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-03-18 21:58:45 +0100 |
commit | 190f2587d5620e86cc9d0868314d08f922217b9e (patch) | |
tree | 95e65d9f39989343694756b2de2eb7d1af821dbc /pkg/tcpip/sample | |
parent | 13a2f2ef6cfac923b1382d6939646f8dfd22e3df (diff) |
WIP add Netplan to config struct
Diffstat (limited to 'pkg/tcpip/sample')
-rw-r--r-- | pkg/tcpip/sample/wg_tunnel/main.go | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/pkg/tcpip/sample/wg_tunnel/main.go b/pkg/tcpip/sample/wg_tunnel/main.go index 47d0b40dc..618fa31f3 100644 --- a/pkg/tcpip/sample/wg_tunnel/main.go +++ b/pkg/tcpip/sample/wg_tunnel/main.go @@ -23,7 +23,6 @@ import ( "context" "flag" "fmt" - "io/ioutil" "log" "math/rand" "net" @@ -44,9 +43,6 @@ import ( "gvisor.dev/gvisor/pkg/tcpip/transport/udp" "gvisor.dev/gvisor/pkg/waiter" - - "gopkg.in/yaml.v3" - "github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv6" "github.com/insomniacslk/dhcp/dhcpv6/nclient6" @@ -170,17 +166,18 @@ func dumpRoutes(s *stack.Stack) { } } -func KeepAliveTunnel(np *config.Netplan) { - KeepAliveTunnelEx(np, true) +func KeepAliveTunnel(cfg *config.Config) { + KeepAliveTunnelEx(cfg, true) } -func KeepAliveTunnelEx(np *config.Netplan, debug bool) { - for _, tun := range np.Network.Tunnels { - if debug { - fmt.Println("Tunnel ", tun.Mode, tun.Local, tun.Remote, tun.Conn, tun.Sd) - } - runtime.KeepAlive(tun.Conn) - } +func KeepAliveTunnelEx(cfg *config.Config, debug bool) { + // FIXME + // for _, tun := range np.Network.Tunnels { + // if debug { + // fmt.Println("Tunnel ", tun.Mode, tun.Local, tun.Remote, tun.Conn, tun.Sd) + // } + // runtime.KeepAlive(tun.Conn) + // } } func withIAPD(iaid [4]byte, prefixLength int) dhcpv6.Modifier { @@ -428,16 +425,11 @@ func main() { log.Fatal("Usage: ", os.Args[0], " <local-port>") } - data, err := ioutil.ReadFile("config.yaml") + cfg, err := config.Load("config.yaml") if err != nil { - log.Fatalf("File reading error", err) + log.Fatal("Unable to load config.yaml") } - var np config.Netplan - err = yaml.Unmarshal(data, &np) - fmt.Println("err", err) - fmt.Println("res", np) - portName := flag.Arg(0) rand.Seed(time.Now().UnixNano()) @@ -447,8 +439,6 @@ func main() { log.Fatalf("Unable to convert port %v: %v", portName, err) } - cfg := config.Config{} - // Create the stack with ip and tcp protocols, then add a tun-based // NIC and address. s := stack.New(stack.Options{ @@ -463,15 +453,15 @@ func main() { }) // FIXME enable - cfg.Setup(s, &np) + cfg.Setup(s) - KeepAliveTunnel(&np) + KeepAliveTunnel(cfg) // FIXME disabled for now, to test startSolicitingRouters if false { // FIXME var wg2Nic tcpip.NICID = -1 - doClient(s, &cfg, wg2Nic) + doClient(s, cfg, wg2Nic) } cfg.SetRouteTable(s) @@ -479,11 +469,11 @@ func main() { dumpAddresses(s) dumpRoutes(s) - KeepAliveTunnel(&np) + KeepAliveTunnel(cfg) runtime.GC() - KeepAliveTunnel(&np) + KeepAliveTunnel(cfg) // Create TCP endpoint, bind it, then start listening. if true { @@ -522,7 +512,7 @@ func main() { log.Fatal("Accept() failed:", err) } - KeepAliveTunnelEx(&np, false) + KeepAliveTunnelEx(cfg, false) go echo(wq, n) } } |