aboutsummaryrefslogtreecommitdiffstats
path: root/conf
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-28 17:41:30 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-01 01:38:30 +0100
commit1c56fb8996d9014e1b96332344f663fa201f3a5e (patch)
treedd411c7c77d655164621b5ed623d945346b2ebf7 /conf
parenttunnel: log the builtin go log to elog (diff)
downloadwireguard-windows-1c56fb8996d9014e1b96332344f663fa201f3a5e.tar.xz
wireguard-windows-1c56fb8996d9014e1b96332344f663fa201f3a5e.zip
tunnel: make winipcfg sort of work
The duplicate route thing is silly, and we currently don't do DNS or the fancy socket routing. But this is a step in the right direction, perhaps.
Diffstat (limited to 'conf')
-rw-r--r--conf/config.go15
-rw-r--r--conf/parser.go8
2 files changed, 21 insertions, 2 deletions
diff --git a/conf/config.go b/conf/config.go
index a321bc0c..d802ec61 100644
--- a/conf/config.go
+++ b/conf/config.go
@@ -64,6 +64,21 @@ func (r *IPCidr) String() string {
return fmt.Sprintf("%s/%d", r.IP.String(), r.Cidr)
}
+func (r *IPCidr) Bits() uint8 {
+ if r.IP.To4() != nil {
+ return 32
+ } else {
+ return 128
+ }
+}
+
+func (r *IPCidr) IPNet() net.IPNet {
+ return net.IPNet{
+ IP: r.IP,
+ Mask: net.CIDRMask(int(r.Cidr), int(r.Bits())),
+ }
+}
+
func (e *Endpoint) String() string {
if strings.IndexByte(e.Host, ':') > 0 {
return fmt.Sprintf("[%s]:%d", e.Host, e.Port)
diff --git a/conf/parser.go b/conf/parser.go
index 6a397a9d..48cf88b6 100644
--- a/conf/parser.go
+++ b/conf/parser.go
@@ -40,17 +40,21 @@ func parseIPCidr(s string) (ipcidr *IPCidr, err error) {
if addr == nil {
return
}
+ maybeV4 := addr.To4()
+ if maybeV4 != nil {
+ addr = maybeV4
+ }
if len(cidrStr) > 0 {
err = &ParseError{"Invalid network prefix length", s}
cidr, err = strconv.Atoi(cidrStr)
if err != nil || cidr < 0 || cidr > 128 {
return
}
- if cidr > 32 && addr.To4() != nil {
+ if cidr > 32 && maybeV4 != nil {
return
}
} else {
- if addr.To4() != nil {
+ if maybeV4 != nil {
cidr = 32
} else {
cidr = 128