[radvd-devel-l] Supporting BSD link-local address

Eric Vyncke (evyncke) evyncke at cisco.com
Mon May 15 14:07:14 EDT 2017


I spent a couple of hours to be able to compile and run RADVD version 2.* on a Mac OS/X...

One issue was the lack of support of clock_gettime() on Mac OS/X and the other issue was that BSD embeds the interface index into the 3rd & 4th bytes of the source and destination link-local addresses (weird, really weird IMHO). https://www.freebsd.org/doc/en/books/developers-handbook/ipv6.html#ipv6-scope-index

When fixing those two issues, wireshard 2.* runs fine on Mac OS/X :-)

Here are the changes (I used __MACH__ but could be __BSD__ or whatever):

In UTILS.C, adding:

#ifdef __MACH__

int clock_gettime(int clk_id, struct timespec *t){

    mach_timebase_info_data_t timebase;

    mach_timebase_info(&timebase);

    uint64_t time;

    time = mach_absolute_time();

    double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom);

    double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9);

    t->tv_sec = seconds;

    t->tv_nsec = nseconds;

    return 0;

}

#endif


In SEND.C,  function SEND_RA:

        char dest_text[INET6_ADDRSTRLEN] = {""};

        char src_text[INET6_ADDRSTRLEN] = {""};

        addrtostr(dest, dest_text, INET6_ADDRSTRLEN);

        addrtostr(iface->props.if_addr_rasrc, src_text, INET6_ADDRSTRLEN);

#ifdef __MACH__

        /* Probably not the most suitable place to change the source Link Local address...

                but see https://www.freebsd.org/doc/en/books/developers-handbook/ipv6.html#ipv6-scope-index */

        iface->props.if_addr_rasrc->s6_addr[3] = iface->props.if_index % 256 ;

        iface->props.if_addr_rasrc->s6_addr[2] = iface->props.if_index >> 8 ;

#endif



        // Build RA header

        struct safe_buffer *ra_hdr = new_safe_buffer();

        add_ra_header(ra_hdr, &iface->ra_header_info, iface->state_info.cease_adv);

In SEND.C, function REALLY_SEND:



#ifdef HAVE_SIN6_SCOPE_ID

        if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&addr.sin6_addr)) {

                dlog(LOG_DEBUG, 5, "sending to a link scoped address for interface #%d", props->if_index) ;

                addr.sin6_scope_id = props->if_index;

#ifdef __MACH__

                /* According to https://www.freebsd.org/doc/en/books/developers-handbook/ipv6.html#ipv6-scope-index, BSD (including Mac OS/X needs to embed the interface index in the address !!! */

                addr.sin6_addr.s6_addr[3] = props->if_index % 256 ;

                addr.sin6_addr.s6_addr[2] = props->if_index >> 8 ;

                char dest_text[INET6_ADDRSTRLEN] = {""};

                addrtostr(&addr.sin6_addr, dest_text, INET6_ADDRSTRLEN);

                dlog(LOG_DEBUG, 5, "modified link-local destination address for BSD -> %s", dest_text) ;

#endif

        }

#endif


Hope this helps

-éric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.litech.org/pipermail/radvd-devel-l/attachments/20170515/259e025a/attachment.html>


More information about the radvd-devel-l mailing list