From 50adf7832004191cdaf5a908bd9a9c0b2373e993 Mon Sep 17 00:00:00 2001 From: David Ward Date: Mon, 31 Aug 2009 10:42:06 -0400 Subject: zebra: Fix router advertisements for non-Ethernet link layer addresses * rtadv.c: round up when calculating the link-layer address option length; add padding to the option if needed to end on an octet boundary --- zebra/rtadv.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'zebra') diff --git a/zebra/rtadv.c b/zebra/rtadv.c index ff96648a..0bcdafb0 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -292,19 +292,33 @@ rtadv_send_packet (int sock, struct interface *ifp) if (sdl != NULL && sdl->sdl_alen != 0) { buf[len++] = ND_OPT_SOURCE_LINKADDR; - buf[len++] = (sdl->sdl_alen + 2) >> 3; + + /* Option length should be rounded up to next octet if + the link address does not end on an octet boundary. */ + buf[len++] = (sdl->sdl_alen + 9) >> 3; memcpy (buf + len, LLADDR (sdl), sdl->sdl_alen); len += sdl->sdl_alen; + + /* Pad option to end on an octet boundary. */ + memset (buf + len, 0, -(sdl->sdl_alen + 2) & 0x7); + len += -(sdl->sdl_alen + 2) & 0x7; } #else if (ifp->hw_addr_len != 0) { buf[len++] = ND_OPT_SOURCE_LINKADDR; - buf[len++] = (ifp->hw_addr_len + 2) >> 3; + + /* Option length should be rounded up to next octet if + the link address does not end on an octet boundary. */ + buf[len++] = (ifp->hw_addr_len + 9) >> 3; memcpy (buf + len, ifp->hw_addr, ifp->hw_addr_len); len += ifp->hw_addr_len; + + /* Pad option to end on an octet boundary. */ + memset (buf + len, 0, -(ifp->hw_addr_len + 2) & 0x7); + len += -(ifp->hw_addr_len + 2) & 0x7; } #endif /* HAVE_STRUCT_SOCKADDR_DL */ -- cgit v1.2.1