> On Jul 29, 2016, at 11:49 AM, Ben Pfaff <b...@ovn.org> wrote: > > On Thu, Jul 28, 2016 at 11:26:12PM -0700, Justin Pettit wrote: >> Rename "compose_nd" and "compose_na" to "compose_nd_ns" and >> "compose_nd_na", respecively, to be clearer about their functionality. >> This will also make it more consistent when we add Neighbor Discover >> Router Solicitation/Advertisement compose functions. >> >> Also change the source and destination IPv6 addresses to take >> "struct in6_addr" arguments, which are more common in the code base. >> >> Signed-off-by: Justin Pettit <jpet...@ovn.org> >> >> --- >> v1->v2: Renamed functions to be consistent when adding more ND messages. >> Fix alignment issues introduced with taking "struct in6_addr". > > I don't think that the ALIGNED_CASTs in compose_nd_ns() and > compose_nd_na() are necessarily safe, on a system that lacks s6_addr32.
Thanks for catching that. From a library perspective, I think we should change the arguments to packet_set_nd() to accept an in6_addr, but that's a more invasive change than I want to make right now. I'll put it on my todo list. How about the incremental below for now, though? --Justin -=-=-=-=-=-=-=-=-=- diff --git a/lib/packets.c b/lib/packets.c index b2316e7..d1e2a70 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -1371,8 +1371,11 @@ compose_nd_ns(struct dp_packet *b, const struct eth_addr eth nd_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR; nd_opt->nd_opt_len = 1; - packet_set_nd(b, ALIGNED_CAST(ovs_be32 *, ipv6_dst->s6_addr), - eth_src, eth_addr_zero); + /* Copy target address to temp buffer to prevent misaligned access. */ + ovs_be32 tbuf[4]; + memcpy(tbuf, ipv6_dst->s6_addr, sizeof tbuf); + packet_set_nd(b, tbuf, eth_src, eth_addr_zero); + ns->icmph.icmp6_cksum = 0; icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b)); ns->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, ns, @@ -1402,8 +1405,11 @@ compose_nd_na(struct dp_packet *b, nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR; nd_opt->nd_opt_len = 1; - packet_set_nd(b, ALIGNED_CAST(ovs_be32 *, ipv6_src->s6_addr), - eth_addr_zero, eth_src); + /* Copy target address to temp buffer to prevent misaligned access. */ + ovs_be32 tbuf[4]; + memcpy(tbuf, ipv6_src->s6_addr, sizeof tbuf); + packet_set_nd(b, tbuf, eth_addr_zero, eth_src); + na->icmph.icmp6_cksum = 0; icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b)); na->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, na, _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev