mirror of https://github.com/xqemu/xqemu.git
slirp: Add RDNSS advertisement
This adds the RDNSS option to IPv6 router advertisements, so that the guest can autoconfigure the DNS server address. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: Thomas Huth <thuth@redhat.com> --- Changes since last submission: - Disable on windows, until we have support for it
This commit is contained in:
parent
ef763fa4bd
commit
f7725df387
|
@ -148,7 +148,11 @@ void ndp_send_ra(Slirp *slirp)
|
||||||
rip->ip_nh = IPPROTO_ICMPV6;
|
rip->ip_nh = IPPROTO_ICMPV6;
|
||||||
rip->ip_pl = htons(ICMP6_NDP_RA_MINLEN
|
rip->ip_pl = htons(ICMP6_NDP_RA_MINLEN
|
||||||
+ NDPOPT_LINKLAYER_LEN
|
+ NDPOPT_LINKLAYER_LEN
|
||||||
+ NDPOPT_PREFIXINFO_LEN);
|
+ NDPOPT_PREFIXINFO_LEN
|
||||||
|
#ifndef _WIN32
|
||||||
|
+ NDPOPT_RDNSS_LEN
|
||||||
|
#endif
|
||||||
|
);
|
||||||
t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl);
|
t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl);
|
||||||
|
|
||||||
/* Build ICMPv6 packet */
|
/* Build ICMPv6 packet */
|
||||||
|
@ -166,16 +170,16 @@ void ndp_send_ra(Slirp *slirp)
|
||||||
ricmp->icmp6_nra.lifetime = htons(NDP_AdvDefaultLifetime);
|
ricmp->icmp6_nra.lifetime = htons(NDP_AdvDefaultLifetime);
|
||||||
ricmp->icmp6_nra.reach_time = htonl(NDP_AdvReachableTime);
|
ricmp->icmp6_nra.reach_time = htonl(NDP_AdvReachableTime);
|
||||||
ricmp->icmp6_nra.retrans_time = htonl(NDP_AdvRetransTime);
|
ricmp->icmp6_nra.retrans_time = htonl(NDP_AdvRetransTime);
|
||||||
|
t->m_data += ICMP6_NDP_RA_MINLEN;
|
||||||
|
|
||||||
/* Source link-layer address (NDP option) */
|
/* Source link-layer address (NDP option) */
|
||||||
t->m_data += ICMP6_NDP_RA_MINLEN;
|
|
||||||
struct ndpopt *opt = mtod(t, struct ndpopt *);
|
struct ndpopt *opt = mtod(t, struct ndpopt *);
|
||||||
opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE;
|
opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE;
|
||||||
opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8;
|
opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8;
|
||||||
in6_compute_ethaddr(rip->ip_src, opt->ndpopt_linklayer);
|
in6_compute_ethaddr(rip->ip_src, opt->ndpopt_linklayer);
|
||||||
|
t->m_data += NDPOPT_LINKLAYER_LEN;
|
||||||
|
|
||||||
/* Prefix information (NDP option) */
|
/* Prefix information (NDP option) */
|
||||||
t->m_data += NDPOPT_LINKLAYER_LEN;
|
|
||||||
struct ndpopt *opt2 = mtod(t, struct ndpopt *);
|
struct ndpopt *opt2 = mtod(t, struct ndpopt *);
|
||||||
opt2->ndpopt_type = NDPOPT_PREFIX_INFO;
|
opt2->ndpopt_type = NDPOPT_PREFIX_INFO;
|
||||||
opt2->ndpopt_len = NDPOPT_PREFIXINFO_LEN / 8;
|
opt2->ndpopt_len = NDPOPT_PREFIXINFO_LEN / 8;
|
||||||
|
@ -187,8 +191,25 @@ void ndp_send_ra(Slirp *slirp)
|
||||||
opt2->ndpopt_prefixinfo.pref_lt = htonl(NDP_AdvPrefLifetime);
|
opt2->ndpopt_prefixinfo.pref_lt = htonl(NDP_AdvPrefLifetime);
|
||||||
opt2->ndpopt_prefixinfo.reserved2 = 0;
|
opt2->ndpopt_prefixinfo.reserved2 = 0;
|
||||||
opt2->ndpopt_prefixinfo.prefix = slirp->vprefix_addr6;
|
opt2->ndpopt_prefixinfo.prefix = slirp->vprefix_addr6;
|
||||||
|
t->m_data += NDPOPT_PREFIXINFO_LEN;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
/* Prefix information (NDP option) */
|
||||||
|
/* disabled for windows for now, until get_dns6_addr is implemented */
|
||||||
|
struct ndpopt *opt3 = mtod(t, struct ndpopt *);
|
||||||
|
opt3->ndpopt_type = NDPOPT_RDNSS;
|
||||||
|
opt3->ndpopt_len = NDPOPT_RDNSS_LEN / 8;
|
||||||
|
opt3->ndpopt_rdnss.reserved = 0;
|
||||||
|
opt3->ndpopt_rdnss.lifetime = htonl(2 * NDP_MaxRtrAdvInterval);
|
||||||
|
opt3->ndpopt_rdnss.addr = slirp->vnameserver_addr6;
|
||||||
|
t->m_data += NDPOPT_RDNSS_LEN;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ICMPv6 Checksum */
|
/* 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 -= NDPOPT_LINKLAYER_LEN;
|
||||||
t->m_data -= ICMP6_NDP_RA_MINLEN;
|
t->m_data -= ICMP6_NDP_RA_MINLEN;
|
||||||
t->m_data -= sizeof(struct ip6);
|
t->m_data -= sizeof(struct ip6);
|
||||||
|
|
|
@ -122,6 +122,7 @@ struct ndpopt {
|
||||||
uint8_t ndpopt_len; /* /!\ In units of 8 octets */
|
uint8_t ndpopt_len; /* /!\ In units of 8 octets */
|
||||||
union {
|
union {
|
||||||
unsigned char linklayer_addr[6]; /* Source/Target Link-layer */
|
unsigned char linklayer_addr[6]; /* Source/Target Link-layer */
|
||||||
|
#define ndpopt_linklayer ndpopt_body.linklayer_addr
|
||||||
struct prefixinfo { /* Prefix Information */
|
struct prefixinfo { /* Prefix Information */
|
||||||
uint8_t prefix_length;
|
uint8_t prefix_length;
|
||||||
#ifdef HOST_WORDS_BIGENDIAN
|
#ifdef HOST_WORDS_BIGENDIAN
|
||||||
|
@ -134,19 +135,26 @@ struct ndpopt {
|
||||||
uint32_t reserved2;
|
uint32_t reserved2;
|
||||||
struct in6_addr prefix;
|
struct in6_addr prefix;
|
||||||
} QEMU_PACKED prefixinfo;
|
} QEMU_PACKED prefixinfo;
|
||||||
} ndpopt_body;
|
|
||||||
#define ndpopt_linklayer ndpopt_body.linklayer_addr
|
|
||||||
#define ndpopt_prefixinfo ndpopt_body.prefixinfo
|
#define ndpopt_prefixinfo ndpopt_body.prefixinfo
|
||||||
|
struct rdnss {
|
||||||
|
uint16_t reserved;
|
||||||
|
uint32_t lifetime;
|
||||||
|
struct in6_addr addr;
|
||||||
|
} QEMU_PACKED rdnss;
|
||||||
|
#define ndpopt_rdnss ndpopt_body.rdnss
|
||||||
|
} ndpopt_body;
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
/* NDP options type */
|
/* NDP options type */
|
||||||
#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */
|
#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */
|
||||||
#define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */
|
#define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */
|
||||||
#define NDPOPT_PREFIX_INFO 3 /* Prefix Information */
|
#define NDPOPT_PREFIX_INFO 3 /* Prefix Information */
|
||||||
|
#define NDPOPT_RDNSS 25 /* Recursive DNS Server Address */
|
||||||
|
|
||||||
/* NDP options size, in octets. */
|
/* NDP options size, in octets. */
|
||||||
#define NDPOPT_LINKLAYER_LEN 8
|
#define NDPOPT_LINKLAYER_LEN 8
|
||||||
#define NDPOPT_PREFIXINFO_LEN 32
|
#define NDPOPT_PREFIXINFO_LEN 32
|
||||||
|
#define NDPOPT_RDNSS_LEN 24
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Definition of type and code field values.
|
* Definition of type and code field values.
|
||||||
|
|
Loading…
Reference in New Issue