Skip to content

Commit 7ee6a71

Browse files
committed
Ipv6 dual-stack by default
1 parent 06e4d22 commit 7ee6a71

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

Cargo.lock

Lines changed: 40 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/lighthouse_network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fnv = { workspace = true }
1919
futures = { workspace = true }
2020
gossipsub = { workspace = true }
2121
hex = { workspace = true }
22+
local-ip-address = "0.6"
2223
itertools = { workspace = true }
2324
libp2p-mplex = "0.42"
2425
lighthouse_version = { workspace = true }

beacon_node/lighthouse_network/src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use directory::{
66
DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_NETWORK, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR,
77
};
88
use libp2p::Multiaddr;
9+
use local_ip_address::local_ipv6;
910
use serde::{Deserialize, Serialize};
1011
use sha2::{Digest, Sha256};
1112
use std::net::{Ipv4Addr, Ipv6Addr};
@@ -265,6 +266,18 @@ impl Config {
265266
}
266267
}
267268

269+
/// A helper function to check if the local host has a globally routeable IPv6 address. If so,
270+
/// returns true.
271+
pub fn is_ipv6_supported() -> bool {
272+
// If IPv6 is supported
273+
let Ok(std::net::IpAddr::V6(local_ip)) = local_ipv6() else {
274+
return false;
275+
};
276+
277+
// If its globally routable, return true
278+
is_global_ipv6(&local_ip)
279+
}
280+
268281
pub fn listen_addrs(&self) -> &ListenAddress {
269282
&self.listen_addresses
270283
}

beacon_node/src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ pub fn cli_app() -> Command {
224224
.action(ArgAction::Set)
225225
.display_order(0)
226226
)
227+
.arg(
228+
Arg::new("disable-ipv6")
229+
.long("disable-ipv6")
230+
.help("If 0.0.0.0 is set as the IPv4 listening address and the host has a globally routeable IPv6 address, Lighthouse will listen on :: by default, in dual-stack mode. This flag prevents this.")
231+
.action(ArgAction::SetTrue)
232+
.display_order(0)
233+
)
227234
.arg(
228235
Arg::new("target-peers")
229236
.long("target-peers")

beacon_node/src/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ pub fn parse_listening_addresses(
899899
// parse the possible ips
900900
let mut maybe_ipv4 = None;
901901
let mut maybe_ipv6 = None;
902+
902903
for addr_str in listen_addresses_str {
903904
let addr = addr_str.parse::<IpAddr>().map_err(|parse_error| {
904905
format!("Failed to parse listen-address ({addr_str}) as an Ip address: {parse_error}")
@@ -926,6 +927,19 @@ pub fn parse_listening_addresses(
926927
}
927928
}
928929

930+
// If we have specified an IPv4 listen address and not an IPv6 address and the
931+
// host has a globally routeable IPv6 address and the CLI doesn't expressly disable IPv6,
932+
// then we also listen on IPv6.
933+
// Note that we will only listen on all interfaces if the IPv4 counterpart is also listening on
934+
// all interfaces, to prevent accidental exposure of ports.
935+
if maybe_ipv4 == Some(Ipv4Addr::UNSPECIFIED)
936+
&& maybe_ipv6.is_none()
937+
&& !cli_args.get_flag("disable_ipv6")
938+
&& NetworkConfig::is_ipv6_supported()
939+
{
940+
maybe_ipv6 = Some(Ipv6Addr::UNSPECIFIED);
941+
}
942+
929943
// parse the possible tcp ports
930944
let port = cli_args
931945
.get_one::<String>("port")

0 commit comments

Comments
 (0)