|
|
|
@ -26,7 +26,7 @@ var envDefaults = map[string]string{
|
|
|
|
|
func main() {
|
|
|
|
|
// Environment-vars
|
|
|
|
|
err := envChecks.HandleRequired(envRequired)
|
|
|
|
|
if(err != nil){
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Error.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
envChecks.HandleDefaults(envDefaults)
|
|
|
|
@ -39,7 +39,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
if err != nil {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the WireGuard peers on the interface
|
|
|
|
|
wgDevice, err := client.Device(iface)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -136,7 +135,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(len(addAllowedIPs) > 0){
|
|
|
|
|
if len(addAllowedIPs) > 0 {
|
|
|
|
|
// Create peer-config
|
|
|
|
|
peerConfig := wgtypes.PeerConfig{
|
|
|
|
|
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")
|
|
|
|
|
} else {
|
|
|
|
|
err = client.ConfigureDevice(iface, wgConfig)
|
|
|
|
|
if(err != nil){
|
|
|
|
|
if err != nil {
|
|
|
|
|
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()
|
|
|
|
|
// 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))
|
|
|
|
|