openziti / ziti-tunnel-sdk-c

Apache License 2.0
43 stars 16 forks source link

tun and dns IP addresses are not incremented when last octet in dns range CIDR is odd #419

Closed scareything closed 1 year ago

scareything commented 2 years ago
ziti-edge-tunnel run -i /media/psf/Home/.ziti/shawns-m1-mbp/scarey@fedora-36-vm.json -v4 -d 100.64.0.23/24
[        0.000]   DEBUG ziti-edge-tunnel:utils.c:32 run_command_va() system(ip link set tun0 up) returned 0
[        0.000]   DEBUG ziti-edge-tunnel:utils.c:32 run_command_va() system(ip addr add 100.64.0.23 dev tun0) returned 0
[        0.000]   DEBUG ziti-edge-tunnel:tun.c:214 init_dns_maintainer() setting up NETLINK listener
Error: Invalid prefix for given prefix length.
[        0.000]   ERROR ziti-edge-tunnel:utils.c:30 run_command_va() cmd{ip route add 100.64.0.23/24 dev tun0} failed: 512/0/Success

[        0.000]   DEBUG ziti-edge-tunnel:utils.c:32 run_command_va() system(ip route add 100.64.0.23/24 dev tun0) returned 512
[        0.000]    INFO tunnel-sdk:ziti_tunnel.c:60 create_tunneler_ctx() Ziti Tunneler SDK (v0.0.0-unknown)
[        0.000]    INFO tunnel-cbs:ziti_dns.c:145 seed_dns() DNS configured with range 100.64.0.0 - 100.64.0.255
[        0.000]   DEBUG tunnel-sdk:ziti_tunnel.c:306 ziti_tunneler_intercept() intercepting address[udp:100.64.0.23/32:53] service[ziti:dns-resolver]

At the very least the tun and DNS IPs should be calculated with numeric addition (and checked for overflow outside the CIDR block), or the last octet in the dns range CIDR should be checked for evenness.

Also note that the route add command fails when the specified IP contains non-zero host address bits.

scareything commented 1 year ago

this was fixed with #499