Skip to content

Commit

Permalink
slirp: Make RA build more flexible
Browse files Browse the repository at this point in the history
Do not hardcode the RA size at all, use a pl_size variable which
accounts the accumulated size, and fill rip->ip_pl at the end.

This will allow to make some blocks optional.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
  • Loading branch information
sthibaul committed Mar 28, 2017
1 parent 51149a2 commit e42f869
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions slirp/ip6_icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,10 @@ void ndp_send_ra(Slirp *slirp)
/* Build IPv6 packet */
struct mbuf *t = m_get(slirp);
struct ip6 *rip = mtod(t, struct ip6 *);
size_t pl_size = 0;
rip->ip_src = (struct in6_addr)LINKLOCAL_ADDR;
rip->ip_dst = (struct in6_addr)ALLNODES_MULTICAST;
rip->ip_nh = IPPROTO_ICMPV6;
rip->ip_pl = htons(ICMP6_NDP_RA_MINLEN
+ NDPOPT_LINKLAYER_LEN
+ NDPOPT_PREFIXINFO_LEN
#ifndef _WIN32
+ NDPOPT_RDNSS_LEN
#endif
);
t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl);

/* Build ICMPv6 packet */
t->m_data += sizeof(struct ip6);
Expand All @@ -171,13 +164,15 @@ void ndp_send_ra(Slirp *slirp)
ricmp->icmp6_nra.reach_time = htonl(NDP_AdvReachableTime);
ricmp->icmp6_nra.retrans_time = htonl(NDP_AdvRetransTime);
t->m_data += ICMP6_NDP_RA_MINLEN;
pl_size += ICMP6_NDP_RA_MINLEN;

/* Source link-layer address (NDP option) */
struct ndpopt *opt = mtod(t, struct ndpopt *);
opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE;
opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8;
in6_compute_ethaddr(rip->ip_src, opt->ndpopt_linklayer);
t->m_data += NDPOPT_LINKLAYER_LEN;
pl_size += NDPOPT_LINKLAYER_LEN;

/* Prefix information (NDP option) */
struct ndpopt *opt2 = mtod(t, struct ndpopt *);
Expand All @@ -192,6 +187,7 @@ void ndp_send_ra(Slirp *slirp)
opt2->ndpopt_prefixinfo.reserved2 = 0;
opt2->ndpopt_prefixinfo.prefix = slirp->vprefix_addr6;
t->m_data += NDPOPT_PREFIXINFO_LEN;
pl_size += NDPOPT_PREFIXINFO_LEN;

#ifndef _WIN32
/* Prefix information (NDP option) */
Expand All @@ -203,16 +199,14 @@ void ndp_send_ra(Slirp *slirp)
opt3->ndpopt_rdnss.lifetime = htonl(2 * NDP_MaxRtrAdvInterval);
opt3->ndpopt_rdnss.addr = slirp->vnameserver_addr6;
t->m_data += NDPOPT_RDNSS_LEN;
pl_size += NDPOPT_RDNSS_LEN;
#endif

rip->ip_pl = htons(pl_size);
t->m_data -= sizeof(struct ip6) + pl_size;
t->m_len = sizeof(struct ip6) + pl_size;

/* ICMPv6 Checksum */
#ifndef _WIN32
t->m_data -= NDPOPT_RDNSS_LEN;
#endif
t->m_data -= NDPOPT_PREFIXINFO_LEN;
t->m_data -= NDPOPT_LINKLAYER_LEN;
t->m_data -= ICMP6_NDP_RA_MINLEN;
t->m_data -= sizeof(struct ip6);
ricmp->icmp6_cksum = ip6_cksum(t);

ip6_output(NULL, t, 0);
Expand Down

0 comments on commit e42f869

Please sign in to comment.