implement getULA
This commit is contained in:
parent
330b986aa4
commit
cb44ff1472
21
init.go
21
init.go
@ -21,7 +21,8 @@ func Init() {
|
|||||||
conf := DsnetConfig{
|
conf := DsnetConfig{
|
||||||
PrivateKey: GenerateJSONPrivateKey(),
|
PrivateKey: GenerateJSONPrivateKey(),
|
||||||
ListenPort: DEFAULT_LISTEN_PORT,
|
ListenPort: DEFAULT_LISTEN_PORT,
|
||||||
Network: getRandomNetwork(),
|
Network: getPrivateNet(),
|
||||||
|
Network6: getULA(),
|
||||||
Peers: []PeerConfig{},
|
Peers: []PeerConfig{},
|
||||||
Domain: "dsnet",
|
Domain: "dsnet",
|
||||||
ReportFile: DEFAULT_REPORT_FILE,
|
ReportFile: DEFAULT_REPORT_FILE,
|
||||||
@ -40,8 +41,8 @@ func Init() {
|
|||||||
fmt.Printf("Config written to %s. Please check/edit.", CONFIG_FILE)
|
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?)
|
// get a random IPv4 /22 subnet on 10.0.0.0 (1023 hosts) (or /24?)
|
||||||
func getRandomNetwork() JSONIPNet {
|
func getPrivateNet() JSONIPNet {
|
||||||
rbs := make([]byte, 2)
|
rbs := make([]byte, 2)
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
rand.Read(rbs)
|
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
|
// TODO support IPv6
|
||||||
func getExternalIP() net.IP {
|
func getExternalIP() net.IP {
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||||
|
Loading…
Reference in New Issue
Block a user