christgau / wsdd

A Web Service Discovery host daemon.
MIT License
814 stars 98 forks source link

Fixing scoped address with embedded interface index on BSD/macOS #144

Closed gershnik closed 1 year ago

gershnik commented 2 years ago

From man inet6 on FreeBSD/macOS

Scoped addresses are handled specially in the kernel. In kernel structures like routing tables or interface structures, a scoped address will have its interface index embedded into the address. Therefore, the address in some kernel structures is not the same as that on the wire. The embedded index will become visible through a PF_ROUTE socket, kernel memory accesses via kvm(3) and on some other occasions. HOWEVER, users should never use the embedded form. For details please consult IMPLEMENTATION supplied with KAME kit.

In our case the embedded addresses are being reported from sysctl/PF_ROUTE. Mostly they work fine, except that they leak into HTTP URLs passed to Windows. Which doesn't know how to handle them.

Following to KAME kit (e.g. https://github.com/kame/kame/blob/master/IMPLEMENTATION) one discovers function in6_clearscope that can be used to clear the embedded scope.

This change applies its ported implementation to the addresses we get.