Skip to content

Commit

Permalink
simplify gz_address() and dns_address() to return addresses rather than
Browse files Browse the repository at this point in the history
subnets
  • Loading branch information
ahl committed May 24, 2024
1 parent f4648ef commit 266771a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
22 changes: 7 additions & 15 deletions common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,16 @@ impl DnsSubnet {
/// Returns the DNS server address within the subnet.
///
/// This is the first address within the subnet.
pub fn dns_address(&self) -> Ipv6Net {
Ipv6Net::new(
self.subnet.net().nth(DNS_ADDRESS_INDEX as u128).unwrap(),
SLED_PREFIX,
)
.unwrap()
pub fn dns_address(&self) -> Ipv6Addr {
self.subnet.net().nth(DNS_ADDRESS_INDEX as u128).unwrap()
}

/// Returns the address which the Global Zone should create
/// to be able to contact the DNS server.
///
/// This is the second address within the subnet.
pub fn gz_address(&self) -> Ipv6Net {
Ipv6Net::new(
self.subnet.net().nth(GZ_ADDRESS_INDEX as u128).unwrap(),
SLED_PREFIX,
)
.unwrap()
pub fn gz_address(&self) -> Ipv6Addr {
self.subnet.net().nth(GZ_ADDRESS_INDEX as u128).unwrap()
}
}

Expand Down Expand Up @@ -304,7 +296,7 @@ pub fn get_internal_dns_server_addresses(addr: Ipv6Addr) -> Vec<IpAddr> {
&reserved_rack_subnet.get_dns_subnets()[0..DNS_REDUNDANCY];
dns_subnets
.iter()
.map(|dns_subnet| IpAddr::from(dns_subnet.dns_address().addr()))
.map(|dns_subnet| IpAddr::from(dns_subnet.dns_address()))
.collect()
}

Expand Down Expand Up @@ -686,11 +678,11 @@ mod test {

// The DNS address and GZ address should be only differing by one.
assert_eq!(
"fd00:1122:3344:0001::1/64".parse::<Ipv6Net>().unwrap(),
"fd00:1122:3344:0001::1".parse::<Ipv6Addr>().unwrap(),
dns_subnets[0].dns_address(),
);
assert_eq!(
"fd00:1122:3344:0001::2/64".parse::<Ipv6Net>().unwrap(),
"fd00:1122:3344:0001::2".parse::<Ipv6Addr>().unwrap(),
dns_subnets[0].gz_address(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion internal-dns/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Resolver {
.get_dns_subnets()
.into_iter()
.map(|dns_subnet| {
let ip_addr = IpAddr::V6(dns_subnet.dns_address().addr());
let ip_addr = IpAddr::V6(dns_subnet.dns_address());
SocketAddr::new(ip_addr, DNS_PORT)
})
.collect()
Expand Down
6 changes: 3 additions & 3 deletions sled-agent/src/rack_setup/plan/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ impl Plan {
&reserved_rack_subnet.get_dns_subnets()[0..DNS_REDUNDANCY];
let rack_dns_servers = dns_subnets
.into_iter()
.map(|dns_subnet| dns_subnet.dns_address().addr().into())
.map(|dns_subnet| dns_subnet.dns_address().into())
.collect::<Vec<IpAddr>>();
for i in 0..dns_subnets.len() {
let dns_subnet = &dns_subnets[i];
let ip = dns_subnet.dns_address().addr();
let ip = dns_subnet.dns_address();
let sled = {
let which_sled =
sled_allocator.next().ok_or(PlanError::NotEnoughSleds)?;
Expand Down Expand Up @@ -419,7 +419,7 @@ impl Plan {
},
http_address,
dns_address,
gz_address: dns_subnet.gz_address().addr(),
gz_address: dns_subnet.gz_address(),
gz_address_index: i.try_into().expect("Giant indices?"),
},
});
Expand Down

0 comments on commit 266771a

Please sign in to comment.