1
0
Fork 0
mirror of https://github.com/mdlayher/homelab.git synced 2024-12-14 11:47:32 +00:00

nixos/lib/vargen: remove wireguard

Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
Matt Layher 2023-09-15 20:07:19 -04:00
parent f8852486ad
commit d59a637484
No known key found for this signature in database
2 changed files with 2 additions and 82 deletions

View file

@ -4,7 +4,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
@ -79,12 +79,6 @@ func main() {
)
)
wg := wireguard{
Name: "wg0",
Subnet: wg0,
}
wg.addPeer("matt-3", "owbwahkmPWQg97iDSfn4dc80f2MYegEbnCAszExlbi8=")
// Set up the output structure and create host/infra records.
out := output{
// TODO: this is a hack, we should make a Service type or similar.
@ -173,7 +167,6 @@ func main() {
),
},
},
WireGuard: wg,
}
// Attach interface definitions from subnet definitions.
@ -199,7 +192,7 @@ func wanIPv6Prefix() netip.Prefix {
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalf("failed to read HTTP body: %v", err)
}
@ -223,7 +216,6 @@ type output struct {
DesktopIPv6 netip.Addr `json:"desktop_ipv6"`
Hosts hosts `json:"hosts"`
Interfaces map[string]iface `json:"interfaces"`
WireGuard wireguard `json:"wireguard"`
}
type hosts struct {
@ -360,51 +352,6 @@ type ipv6Prefixes struct {
LLA netip.Prefix `json:"lla"`
}
type wireguard struct {
Name string `json:"name"`
Subnet subnet `json:"subnet"`
Peers []wgPeer `json:"peers"`
idx int
}
func (wg *wireguard) addPeer(name, publicKey string) {
defer func() { wg.idx++ }()
const offset = 10
var ips []string
for _, ipp := range []netip.Prefix{
wg.Subnet.IPv4,
wg.Subnet.IPv6.GUA,
wg.Subnet.IPv6.ULA,
wg.Subnet.IPv6.LLA,
} {
// Router always has a .1 or ::1 suffix.
arr := ipp.Addr().As16()
arr[15] = byte(offset + wg.idx)
bits := 32
if ipp.Addr().Is6() {
bits = 128
}
ips = append(ips, netip.PrefixFrom(netip.AddrFrom16(arr).Unmap(), bits).String())
}
wg.Peers = append(wg.Peers, wgPeer{
Name: name,
PublicKey: publicKey,
AllowedIPs: ips,
})
}
type wgPeer struct {
Name string `json:"name"`
PublicKey string `json:"public_key"`
AllowedIPs []string `json:"allowed_ips"`
}
func mustStdIP(ip net.IP) netip.Addr {
out, ok := netip.AddrFromSlice(ip)
if !ok {

View file

@ -405,32 +405,5 @@
},
"hosts": []
}
},
"wireguard": {
"name": "wg0",
"subnet": {
"name": "wg0",
"preference": "medium",
"trusted": true,
"ipv4": "192.168.20.0/24",
"ipv6": {
"gua": "2600:6c4a:787f:414::/64",
"ula": "fd9e:1a04:f01d:20::/64",
"lla": "fe80::/64"
},
"hosts": []
},
"peers": [
{
"name": "matt-3",
"public_key": "owbwahkmPWQg97iDSfn4dc80f2MYegEbnCAszExlbi8=",
"allowed_ips": [
"192.168.20.10/32",
"2600:6c4a:787f:414::a/128",
"fd9e:1a04:f01d:20::a/128",
"fe80::a/128"
]
}
]
}
}