Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 By Default #6808

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions beacon_node/lighthouse_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fnv = { workspace = true }
futures = { workspace = true }
gossipsub = { workspace = true }
hex = { workspace = true }
local-ip-address = "0.6"
itertools = { workspace = true }
libp2p-mplex = "0.42"
lighthouse_version = { workspace = true }
Expand Down
13 changes: 13 additions & 0 deletions beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use directory::{
DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_NETWORK, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR,
};
use libp2p::Multiaddr;
use local_ip_address::local_ipv6;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::net::{Ipv4Addr, Ipv6Addr};
Expand Down Expand Up @@ -265,6 +266,18 @@ impl Config {
}
}

/// A helper function to check if the local host has a globally routeable IPv6 address. If so,
/// returns true.
pub fn is_ipv6_supported() -> bool {
// If IPv6 is supported
let Ok(std::net::IpAddr::V6(local_ip)) = local_ipv6() else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we already depend on rtnetlink via rust-libp2p and if-watch.
There's an example on how to do it here, we could implement it here, or upsteam it as they mention in the discussion

return false;
};

// If its globally routable, return true
is_global_ipv6(&local_ip)
}

pub fn listen_addrs(&self) -> &ListenAddress {
&self.listen_addresses
}
Expand Down
7 changes: 7 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ pub fn cli_app() -> Command {
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::new("disable-ipv6")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking into consideration the description you wrote on the PR, should we then update this PR to make this optional? I.e add instead an option to enable ipv6

.long("disable-ipv6")
.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.")
.action(ArgAction::SetTrue)
.display_order(0)
)
.arg(
Arg::new("target-peers")
.long("target-peers")
Expand Down
14 changes: 14 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ pub fn parse_listening_addresses(
// parse the possible ips
let mut maybe_ipv4 = None;
let mut maybe_ipv6 = None;

for addr_str in listen_addresses_str {
let addr = addr_str.parse::<IpAddr>().map_err(|parse_error| {
format!("Failed to parse listen-address ({addr_str}) as an Ip address: {parse_error}")
Expand Down Expand Up @@ -926,6 +927,19 @@ pub fn parse_listening_addresses(
}
}

// If we have specified an IPv4 listen address and not an IPv6 address and the
// host has a globally routeable IPv6 address and the CLI doesn't expressly disable IPv6,
// then we also listen on IPv6.
// Note that we will only listen on all interfaces if the IPv4 counterpart is also listening on
// all interfaces, to prevent accidental exposure of ports.
if maybe_ipv4 == Some(Ipv4Addr::UNSPECIFIED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could then also re-write this logic to log when user enables ipv6 but doesn't support it

&& maybe_ipv6.is_none()
&& !cli_args.get_flag("disable_ipv6")
&& NetworkConfig::is_ipv6_supported()
{
maybe_ipv6 = Some(Ipv6Addr::UNSPECIFIED);
}

// parse the possible tcp ports
let port = cli_args
.get_one::<String>("port")
Expand Down
Loading