damob-byun / WireGuardNTSharp

WireGuard Simple Windows Cli and WireGuard NT Wrapper for C#(Csharp) with P/Invoke
GNU General Public License v2.0
46 stars 5 forks source link

config parsing dns missing searchdomain #1

Closed cocoon closed 1 year ago

cocoon commented 1 year ago

Hi, currently the parsing of the config file is missing the case, if there is a searchdomain added as string in DNS, and that can't be parsed as IP.

https://github.com/damob-byun/WireGuardNTSharp/blob/main/WireGuardNT-PInvoke/Adapter.cs#L185

                        case "dns":
                            wgConfig.DnsAddresses = value.Split(',').Select(dns => dns.Trim()).Select(dns => IPAddress.Parse(dns)).ToArray();
                            continue;

For reference see parsing in the go client: https://git.zx2c4.com/wireguard-windows/tree/conf/parser.go#n231

for _, address := range addresses {
                    a, err := netip.ParseAddr(address)
                    if err != nil {
                        conf.Interface.DNSSearch = append(conf.Interface.DNSSearch, address)
                    } else {
                        conf.Interface.DNS = append(conf.Interface.DNS, a)
                    }

Additionally maybe to allow running some command in posupt etc would also be nice to handle:

case "preup":
                conf.Interface.PreUp = val
            case "postup":
                conf.Interface.PostUp = val
            case "predown":
                conf.Interface.PreDown = val
            case "postdown":
                conf.Interface.PostDown = val
            case "table":

Override DNS for Specific Domains

If you use WireGuard to connect to an internal network, and that network includes a custom DNS resolver which resolves an internal domain name for hosts on that network, you can configure systemd-resolved to use that resolver for that particular domain name.

For example, if the resolver’s IP address is 10.0.0.2, and the domain name is internal.example.com, you might normally use the following DNS settting:

DNS = 10.0.0.2, internal.example.com

With systemd-resolved, however, instead of using the DNS setting, add the following PostUp command to the [Interface] section of your WireGuard config file:

PostUp = resolvectl dns %i 10.0.0.2; resolvectl domain %i ~internal.example.com

damob-byun commented 1 year ago

Hi, thanks for reporting the issue.

I've just added DNS support and committed it.

https://github.com/damob-byun/WireGuardNTSharp/commit/0f2453ade208effd853b16e946e1dc187fe8d4a9

cocoon commented 1 year ago

Great thank you very much!