mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
Adjustments on the road to testing
This commit is contained in:
@@ -26,7 +26,7 @@ type WgData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SiteConfig struct {
|
type SiteConfig struct {
|
||||||
SiteId string `json:"siteId"`
|
SiteId int `json:"siteId"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
PublicKey string `json:"publicKey"`
|
PublicKey string `json:"publicKey"`
|
||||||
ServerIP string `json:"serverIP"`
|
ServerIP string `json:"serverIP"`
|
||||||
|
|||||||
20
main.go
20
main.go
@@ -31,7 +31,6 @@ import (
|
|||||||
// ConfigureInterface configures a network interface with an IP address and brings it up
|
// ConfigureInterface configures a network interface with an IP address and brings it up
|
||||||
func ConfigureInterface(interfaceName string, wgData WgData) error {
|
func ConfigureInterface(interfaceName string, wgData WgData) error {
|
||||||
var ipAddr string = wgData.TunnelIP
|
var ipAddr string = wgData.TunnelIP
|
||||||
var destIP string = wgData.ServerIP
|
|
||||||
|
|
||||||
// Parse the IP address and network
|
// Parse the IP address and network
|
||||||
ip, ipNet, err := net.ParseCIDR(ipAddr)
|
ip, ipNet, err := net.ParseCIDR(ipAddr)
|
||||||
@@ -43,7 +42,7 @@ func ConfigureInterface(interfaceName string, wgData WgData) error {
|
|||||||
case "linux":
|
case "linux":
|
||||||
return configureLinux(interfaceName, ip, ipNet)
|
return configureLinux(interfaceName, ip, ipNet)
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return configureDarwin(interfaceName, ip, destIP)
|
return configureDarwin(interfaceName, ip, ipNet, wgData.TunnelIP) // TODO: is tunnelip correct here? I think it has to do with the route addition in macos
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
|
return fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
|
||||||
}
|
}
|
||||||
@@ -72,18 +71,13 @@ func findUnusedUTUN() (string, error) {
|
|||||||
return "", fmt.Errorf("no unused utun interface found")
|
return "", fmt.Errorf("no unused utun interface found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureDarwin(interfaceName string, ip net.IP, destIp string) error {
|
func configureDarwin(interfaceName string, ip net.IP, ipNet *net.IPNet, destIp string) error {
|
||||||
logger.Info("Configuring darwin interface: %s", interfaceName)
|
logger.Info("Configuring darwin interface: %s", interfaceName)
|
||||||
|
|
||||||
iface, err := net.InterfaceByName(interfaceName)
|
_, cidr := ipNet.Mask.Size()
|
||||||
if err != nil {
|
ipStr := fmt.Sprintf("%s/%d", ip.String(), cidr)
|
||||||
return fmt.Errorf("failed to get interface %s: %v", interfaceName, err)
|
|
||||||
}
|
|
||||||
logger.Info("Interface %s: %v", interfaceName, iface)
|
|
||||||
|
|
||||||
ipStr := ip.String()
|
cmd := exec.Command("ifconfig", interfaceName, ipStr, destIp, "up")
|
||||||
|
|
||||||
cmd := exec.Command("ifconfig", interfaceName, ipStr+"/24", destIp, "up") // TODO: dont hard code /24
|
|
||||||
// print the command used
|
// print the command used
|
||||||
logger.Info("Running command: %v", cmd)
|
logger.Info("Running command: %v", cmd)
|
||||||
|
|
||||||
@@ -400,12 +394,12 @@ func main() {
|
|||||||
for _, site := range wgData.Sites {
|
for _, site := range wgData.Sites {
|
||||||
siteHost, err := resolveDomain(site.Endpoint)
|
siteHost, err := resolveDomain(site.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("Failed to resolve endpoint for site %s: %v", site.SiteId, err)
|
logger.Warn("Failed to resolve endpoint for site %d: %v", site.SiteId, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include peer info
|
// Include peer info
|
||||||
configBuilder.WriteString(fmt.Sprintf("\n# Site %s\n", site.SiteId))
|
// configBuilder.WriteString(fmt.Sprintf("\n# Site %d\n", site.SiteId))
|
||||||
configBuilder.WriteString(fmt.Sprintf("public_key=%s\n", fixKey(site.PublicKey)))
|
configBuilder.WriteString(fmt.Sprintf("public_key=%s\n", fixKey(site.PublicKey)))
|
||||||
configBuilder.WriteString(fmt.Sprintf("allowed_ip=%s/32\n", site.ServerIP))
|
configBuilder.WriteString(fmt.Sprintf("allowed_ip=%s/32\n", site.ServerIP))
|
||||||
configBuilder.WriteString(fmt.Sprintf("endpoint=%s\n", siteHost))
|
configBuilder.WriteString(fmt.Sprintf("endpoint=%s\n", siteHost))
|
||||||
|
|||||||
Reference in New Issue
Block a user