|
|
@ -26,7 +26,7 @@ var envDefaults = map[string]string{
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
// Environment-vars
|
|
|
|
// Environment-vars
|
|
|
|
err := envChecks.HandleRequired(envRequired)
|
|
|
|
err := envChecks.HandleRequired(envRequired)
|
|
|
|
if(err != nil){
|
|
|
|
if err != nil {
|
|
|
|
logger.Error.Fatal(err)
|
|
|
|
logger.Error.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
envChecks.HandleDefaults(envDefaults)
|
|
|
|
envChecks.HandleDefaults(envDefaults)
|
|
|
@ -39,7 +39,7 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ipv6Format := os.Getenv("IPV6_FORMAT")
|
|
|
|
ipv6Format := os.Getenv("IPV6_FORMAT")
|
|
|
|
ipv6TestStr := *convertIPv4ToIPv6(&ipv6Format, &net.IPNet{IP: net.IPv4(1,1,1,1), Mask: net.CIDRMask(24, net.IPv4len)})
|
|
|
|
ipv6TestStr := *convertIPv4ToIPv6(&ipv6Format, &net.IPNet{IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, net.IPv4len)})
|
|
|
|
_, err = netlink.ParseIPNet(ipv6TestStr)
|
|
|
|
_, err = netlink.ParseIPNet(ipv6TestStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger.Error.Fatalf("IPV6_FORMAT is invalid: %s", err)
|
|
|
|
logger.Error.Fatalf("IPV6_FORMAT is invalid: %s", err)
|
|
|
@ -100,7 +100,6 @@ func main() {
|
|
|
|
logger.Warn.Printf("Not all Interface-Addresses were processed. Summary: %d processed, %d filtered, %d failed", processedCount, filteredCount, len(addrs)-processedCount-filteredCount)
|
|
|
|
logger.Warn.Printf("Not all Interface-Addresses were processed. Summary: %d processed, %d filtered, %d failed", processedCount, filteredCount, len(addrs)-processedCount-filteredCount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the WireGuard peers on the interface
|
|
|
|
// Get the WireGuard peers on the interface
|
|
|
|
wgDevice, err := client.Device(iface)
|
|
|
|
wgDevice, err := client.Device(iface)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -136,7 +135,7 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(len(addAllowedIPs) > 0){
|
|
|
|
if len(addAllowedIPs) > 0 {
|
|
|
|
// Create peer-config
|
|
|
|
// Create peer-config
|
|
|
|
peerConfig := wgtypes.PeerConfig{
|
|
|
|
peerConfig := wgtypes.PeerConfig{
|
|
|
|
PublicKey: peer.PublicKey,
|
|
|
|
PublicKey: peer.PublicKey,
|
|
|
@ -148,11 +147,11 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(len(wgConfig.Peers) == 0){
|
|
|
|
if len(wgConfig.Peers) == 0 {
|
|
|
|
logger.Info.Println("No changes, skipping")
|
|
|
|
logger.Info.Println("No changes, skipping")
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
err = client.ConfigureDevice(iface, wgConfig)
|
|
|
|
err = client.ConfigureDevice(iface, wgConfig)
|
|
|
|
if(err != nil){
|
|
|
|
if err != nil {
|
|
|
|
logger.Error.Fatalf("Error configuring wg-device '%s': %s", iface, err)
|
|
|
|
logger.Error.Fatalf("Error configuring wg-device '%s': %s", iface, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -162,7 +161,7 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func convertIPv4ToIPv6(ipv6Format *string, ipv4 *net.IPNet) (*string) {
|
|
|
|
func convertIPv4ToIPv6(ipv6Format *string, ipv4 *net.IPNet) *string {
|
|
|
|
CIDR, _ := ipv4.Mask.Size()
|
|
|
|
CIDR, _ := ipv4.Mask.Size()
|
|
|
|
// Run format
|
|
|
|
// Run format
|
|
|
|
ipv6Str := fmt.Sprintf(*ipv6Format, (*ipv4).IP[0], (*ipv4).IP[1], (*ipv4).IP[2], (*ipv4).IP[3], net.IPv6len*8-(net.IPv4len*8-CIDR))
|
|
|
|
ipv6Str := fmt.Sprintf(*ipv6Format, (*ipv4).IP[0], (*ipv4).IP[1], (*ipv4).IP[2], (*ipv4).IP[3], net.IPv6len*8-(net.IPv4len*8-CIDR))
|
|
|
|