// destroy GRE tunnel func destroy(tun *gretun.Tunnel) { if tun.Destroy() { log.Println("GRE Tunnel destroyed.") } else { log.Println("Failed destroying GRE Tunnel.") } }
// register at server and create GRE tunnel func register(tun *gretun.Tunnel) { log.Println("Requesting GRE IP from server ..") var greIp net.IP = nil statusCode, body := httpReq("http://" + serverIp + ":8080/reg") if statusCode != 0 { log.Printf("Response: %d (%s): %s\n", statusCode, http.StatusText(statusCode), body) greIp = net.ParseIP(string(body)) } if greIp != nil { tun.CGreIp = greIp if tun.Create() { log.Println("GRE Tunnel created.") } else { log.Println("Failed creating GRE Tunnel.") } } else { log.Fatalln("Did not get a GRE IP address from server.") } }
// unsets remote IP to free GRE IP func (tunList *TunList) free(tun *gretun.Tunnel) { tun.RemoteIp = nil }