summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/sample/wg_tunnel
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/sample/wg_tunnel')
-rw-r--r--pkg/tcpip/sample/wg_tunnel/main.go38
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)