From: Lennart Poettering Date: Fri, 12 Dec 2008 20:29:30 +0000 (+0100) Subject: Fix pfroute IPv6 code X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=cb1da7c5462716c12638c29d9a76e065684e0e6a;p=catta Fix pfroute IPv6 code Quoting Joe Marcus Clarke: "There are two problems in the iface-pfroute.c IPv6 detection code. The first is that the KAME stack embeds a scope ID into IPv6 addresses. This can cause certain hosts not to be able to recognize the address. The second is that global_scope is always set to 1 even for link-local addresses. The attached patch fixes both problems. The KAME fix was submitted by Hajimu UMEMOTO." Patch from Joe Marcus Clarke/Hajimu UMEMOTO. --- diff --git a/avahi-core/iface-pfroute.c b/avahi-core/iface-pfroute.c index f96bfc2..391081e 100644 --- a/avahi-core/iface-pfroute.c +++ b/avahi-core/iface-pfroute.c @@ -125,7 +125,7 @@ static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) int raddr_valid = 0; struct ifa_msghdr *ifam = (struct ifa_msghdr *) rtm; char *cp = (char *)(ifam + 1); - int addrs = ifam->ifam_addrs; + char *cp0; int i; int prefixlen = 0; struct sockaddr *sa =NULL; @@ -135,17 +135,30 @@ static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) ((struct sockaddr *)cp)->sa_family = AF_INET; #endif - if(((struct sockaddr *)cp)->sa_family != AF_INET && ((struct sockaddr *)cp)->sa_family != AF_INET6) + for (cp0 = cp, i = 0; i < RTAX_MAX; i++) { + if (!(ifam->ifam_addrs & (1<sa_family != AF_INET && sa->sa_family != AF_INET6) return; - if (!(iface = avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifam->ifam_index, avahi_af_to_proto(((struct sockaddr *)cp)->sa_family)))) + if (!(iface = avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifam->ifam_index, avahi_af_to_proto(sa->sa_family)))) return; - raddr.proto = avahi_af_to_proto(((struct sockaddr *)cp)->sa_family); + raddr.proto = avahi_af_to_proto(sa->sa_family); - for(i = 0; addrs != 0 && i < RTAX_MAX; addrs &= ~(1<ifam_addrs & (1<sin6_addr, sizeof(struct in6_addr)); +#ifdef __KAME__ + if (IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)raddr.data.data)) + { + ((struct in6_addr *)raddr.data.data)->s6_addr[2] = 0; + ((struct in6_addr *)raddr.data.data)->s6_addr[3] = 0; + } +#endif raddr_valid = 1; default: break; @@ -196,9 +216,12 @@ static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) if (!(addriface = avahi_interface_monitor_get_address(m, iface, &raddr))) if (!(addriface = avahi_interface_address_new(m, iface, &raddr, prefixlen))) return; /* OOM */ - /* FIXME */ - /* addriface->global_scope = ifaddrmsg->ifa_scope == RT_SCOPE_UNIVERSE || ifaddrmsg->ifa_scope == RT_SCOPE_SITE; */ - addriface->global_scope = 1; + if (raddr.proto == AVAHI_PROTO_INET6) + { + addriface->global_scope = !(IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)raddr.data.data) || IN6_IS_ADDR_MULTICAST((struct in6_addr *)raddr.data.data)); + } + else + addriface->global_scope = 1; } else {