Compare commits
2 Commits
0b54ae3690
...
a29f511550
Author | SHA1 | Date | |
---|---|---|---|
a29f511550 | |||
fe92030438 |
@ -24,6 +24,8 @@ The program will convert IPv4-only wireguard-interfaces to IPv6. It converts and
|
|||||||
|
|
||||||
IPv6-Adresses are generated based on the IPv4-Adress.
|
IPv6-Adresses are generated based on the IPv4-Adress.
|
||||||
|
|
||||||
|
If not filtered out, then default routes (0.0.0.0/0) are handled specially and are converted to the IPv6 default route (::/0).
|
||||||
|
|
||||||
Beware: This program needs `NET_ADMIN` privileges for setting Adresses and to access the wireguard-daemon.
|
Beware: This program needs `NET_ADMIN` privileges for setting Adresses and to access the wireguard-daemon.
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
var envRequired = []string{
|
var envRequired = []string{
|
||||||
"INTERFACE",
|
"INTERFACE",
|
||||||
}
|
}
|
||||||
|
|
||||||
var envDefaults = map[string]string{
|
var envDefaults = map[string]string{
|
||||||
"IPV6_FORMAT": "fc12::%02x%02x:%02x%02x/%d",
|
"IPV6_FORMAT": "fc12::%02x%02x:%02x%02x/%d",
|
||||||
"FILTER_PREFIX": "100.100",
|
"FILTER_PREFIX": "100.100",
|
||||||
@ -111,7 +112,7 @@ func main() {
|
|||||||
|
|
||||||
for _, peer := range wgDevice.Peers {
|
for _, peer := range wgDevice.Peers {
|
||||||
// Create slice for 1 expected addition
|
// Create slice for 1 expected addition
|
||||||
var addAllowedIPs = make([]net.IPNet, 0, 1)
|
addAllowedIPs := make([]net.IPNet, 0, 1)
|
||||||
|
|
||||||
// Loop through the allowed-ips and add the ones starting with 100.100
|
// Loop through the allowed-ips and add the ones starting with 100.100
|
||||||
for _, allowedIP := range peer.AllowedIPs {
|
for _, allowedIP := range peer.AllowedIPs {
|
||||||
@ -162,6 +163,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func convertIPv4ToIPv6(ipv6Format *string, ipv4 *net.IPNet) *string {
|
func convertIPv4ToIPv6(ipv6Format *string, ipv4 *net.IPNet) *string {
|
||||||
|
// Check if this is a default route (0.0.0.0/0)
|
||||||
|
if ipv4.IP.Equal(net.IPv4zero) {
|
||||||
|
if ones, _ := ipv4.Mask.Size(); ones == 0 {
|
||||||
|
defaultRoute := "::/0"
|
||||||
|
return &defaultRoute
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user