diff --git a/init.go b/init.go index f3e7bda..5833379 100644 --- a/init.go +++ b/init.go @@ -21,7 +21,8 @@ func Init() { conf := DsnetConfig{ PrivateKey: GenerateJSONPrivateKey(), ListenPort: DEFAULT_LISTEN_PORT, - Network: getRandomNetwork(), + Network: getPrivateNet(), + Network6: getULA(), Peers: []PeerConfig{}, Domain: "dsnet", ReportFile: DEFAULT_REPORT_FILE, @@ -40,8 +41,8 @@ func Init() { fmt.Printf("Config written to %s. Please check/edit.", CONFIG_FILE) } -// get a random /22 subnet on 10.0.0.0 (1023 hosts) (or /24?) -func getRandomNetwork() JSONIPNet { +// get a random IPv4 /22 subnet on 10.0.0.0 (1023 hosts) (or /24?) +func getPrivateNet() JSONIPNet { rbs := make([]byte, 2) rand.Seed(time.Now().UTC().UnixNano()) rand.Read(rbs) @@ -54,6 +55,20 @@ func getRandomNetwork() JSONIPNet { } } +func getULA() JSONIPNet { + rbs := make([]byte, 5) + rand.Seed(time.Now().UTC().UnixNano()) + rand.Read(rbs) + + // fc00 prefix with 40 bit global id and zero (16 bit) subnet ID + return JSONIPNet{ + IPNet: net.IPNet{ + net.IP{0xfc, 0, rbs[0], rbs[1], rbs[2], rbs[3], rbs[4], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0}, + }, + } +} + // TODO support IPv6 func getExternalIP() net.IP { conn, err := net.Dial("udp", "8.8.8.8:80")