diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-03-18 21:46:40 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-03-18 21:46:40 +0100 |
commit | 13a2f2ef6cfac923b1382d6939646f8dfd22e3df (patch) | |
tree | 5f72638566a1fbdbc67654739d146c4c6e62d9fc /pkg/tcpip/sample/wg_tunnel/main.go | |
parent | 1d171254911cfcd62926f43938edde2ad20e64fc (diff) |
WIP create Config struct
Diffstat (limited to 'pkg/tcpip/sample/wg_tunnel/main.go')
-rw-r--r-- | pkg/tcpip/sample/wg_tunnel/main.go | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/pkg/tcpip/sample/wg_tunnel/main.go b/pkg/tcpip/sample/wg_tunnel/main.go index 066216dfb..47d0b40dc 100644 --- a/pkg/tcpip/sample/wg_tunnel/main.go +++ b/pkg/tcpip/sample/wg_tunnel/main.go @@ -29,7 +29,6 @@ import ( "net" "os" "runtime" - "sort" "strconv" "time" @@ -248,7 +247,7 @@ func NewDHCPv4Query(flags uint32, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message return msg, nil } -func doClient(s *stack.Stack, routes *config.Routes, nic tcpip.NICID) { +func doClient(s *stack.Stack, cfg *config.Config, nic tcpip.NICID) { fmt.Println("doClient start") // TODO use link local address @@ -361,20 +360,13 @@ func doClient(s *stack.Stack, routes *config.Routes, nic tcpip.NICID) { // client.Close() fmt.Println("doClient end", ack.YourIPAddr, ack.SubnetMask()) ip := net.IPNet{IP: ack.YourIPAddr, Mask:ack.SubnetMask()} - routes.AddAddress(s, nic, ip.String()) + cfg.AddAddress(s, nic, ip.String()) iana := msg.GetOneOption(dhcpv6.OptionIANA).(*dhcpv6.OptIANA) for _, addr := range iana.Options.Get(dhcpv6.OptionIAAddr) { str := addr.(*dhcpv6.OptIAAddress).IPv6Addr.String() + "/128" - routes.AddAddress(s, nic, str) - - _, dest, _ := config.ParseSubnet(addr.(*dhcpv6.OptIAAddress).IPv6Addr.String() + "/64") - route := tcpip.Route{ - Destination: dest, - NIC: nic, - } - - *routes = append(*routes, route) + cfg.AddAddress(s, nic, str) + cfg.AddRoute(nic, addr.(*dhcpv6.OptIAAddress).IPv6Addr.String() + "/64") } var loNic tcpip.NICID = 0 @@ -382,7 +374,7 @@ func doClient(s *stack.Stack, routes *config.Routes, nic tcpip.NICID) { for _, opt := range iapd.Options.Get(dhcpv6.OptionIAPrefix) { prefix := opt.(*dhcpv6.OptIAPrefix) str := prefix.Prefix.IP.String()+"1"+"/128" - routes.AddAddress(s, loNic, str) + cfg.AddAddress(s, loNic, str) } dumpAddresses(s) @@ -455,7 +447,7 @@ func main() { log.Fatalf("Unable to convert port %v: %v", portName, err) } - routes := config.Routes{} + cfg := config.Config{} // Create the stack with ip and tcp protocols, then add a tun-based // NIC and address. @@ -471,30 +463,18 @@ func main() { }) // FIXME enable - routes.Setup(s, &np) + cfg.Setup(s, &np) KeepAliveTunnel(&np) - // Sort route table for longest prefix match - sort.Slice(routes, func(i, j int) bool { - return routes[i].Destination.Prefix() > routes[j].Destination.Prefix() - }) - - s.SetRouteTable(routes) - // FIXME disabled for now, to test startSolicitingRouters if false { // FIXME var wg2Nic tcpip.NICID = -1 - doClient(s, &routes, wg2Nic) + doClient(s, &cfg, wg2Nic) } - // Sort route table for longest prefix match - sort.Slice(routes, func(i, j int) bool { - return routes[i].Destination.Prefix() > routes[j].Destination.Prefix() - }) - - s.SetRouteTable(routes) + cfg.SetRouteTable(s) dumpAddresses(s) dumpRoutes(s) |