mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
IPv6 By Default (#6808)
This commit is contained in:
@@ -147,16 +147,16 @@ pub fn cli_app() -> Command {
|
||||
.long("listen-address")
|
||||
.value_name("ADDRESS")
|
||||
.help("The address lighthouse will listen for UDP and TCP connections. To listen \
|
||||
over IpV4 and IpV6 set this flag twice with the different values.\n\
|
||||
over IPv4 and IPv6 set this flag twice with the different values.\n\
|
||||
Examples:\n\
|
||||
- --listen-address '0.0.0.0' will listen over IPv4.\n\
|
||||
- --listen-address '::' will listen over IPv6.\n\
|
||||
- --listen-address '0.0.0.0' --listen-address '::' will listen over both \
|
||||
IPv4 and IPv6. The order of the given addresses is not relevant. However, \
|
||||
multiple IPv4, or multiple IPv6 addresses will not be accepted.")
|
||||
multiple IPv4, or multiple IPv6 addresses will not be accepted. \
|
||||
If omitted, Lighthouse will listen on all interfaces, for both IPv4 and IPv6.")
|
||||
.action(ArgAction::Append)
|
||||
.num_args(0..=2)
|
||||
.default_value("0.0.0.0")
|
||||
.display_order(0)
|
||||
)
|
||||
.arg(
|
||||
|
||||
@@ -905,12 +905,13 @@ pub fn parse_listening_addresses(
|
||||
) -> Result<ListenAddress, String> {
|
||||
let listen_addresses_str = cli_args
|
||||
.get_many::<String>("listen-address")
|
||||
.expect("--listen_addresses has a default value");
|
||||
.unwrap_or_default();
|
||||
let use_zero_ports = parse_flag(cli_args, "zero-ports");
|
||||
|
||||
// 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}")
|
||||
@@ -920,8 +921,8 @@ pub fn parse_listening_addresses(
|
||||
IpAddr::V4(v4_addr) => match &maybe_ipv4 {
|
||||
Some(first_ipv4_addr) => {
|
||||
return Err(format!(
|
||||
"When setting the --listen-address option twice, use an IpV4 address and an Ipv6 address. \
|
||||
Got two IpV4 addresses {first_ipv4_addr} and {v4_addr}"
|
||||
"When setting the --listen-address option twice, use an IPv4 address and an IPv6 address. \
|
||||
Got two IPv4 addresses {first_ipv4_addr} and {v4_addr}"
|
||||
));
|
||||
}
|
||||
None => maybe_ipv4 = Some(v4_addr),
|
||||
@@ -929,8 +930,8 @@ pub fn parse_listening_addresses(
|
||||
IpAddr::V6(v6_addr) => match &maybe_ipv6 {
|
||||
Some(first_ipv6_addr) => {
|
||||
return Err(format!(
|
||||
"When setting the --listen-address option twice, use an IpV4 address and an Ipv6 address. \
|
||||
Got two IpV6 addresses {first_ipv6_addr} and {v6_addr}"
|
||||
"When setting the --listen-address option twice, use an IPv4 address and an IPv6 address. \
|
||||
Got two IPv6 addresses {first_ipv6_addr} and {v6_addr}"
|
||||
));
|
||||
}
|
||||
None => maybe_ipv6 = Some(v6_addr),
|
||||
@@ -984,11 +985,22 @@ pub fn parse_listening_addresses(
|
||||
format!("Failed to parse --quic6-port as an integer: {parse_error}")
|
||||
})?;
|
||||
|
||||
// Here we specify the default listening addresses for Lighthouse.
|
||||
// By default, we listen on 0.0.0.0.
|
||||
//
|
||||
// IF the host supports a globally routable IPv6 address, we also listen on ::.
|
||||
if matches!((maybe_ipv4, maybe_ipv6), (None, None)) {
|
||||
maybe_ipv4 = Some(Ipv4Addr::UNSPECIFIED);
|
||||
|
||||
if NetworkConfig::is_ipv6_supported() {
|
||||
maybe_ipv6 = Some(Ipv6Addr::UNSPECIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
// Now put everything together
|
||||
let listening_addresses = match (maybe_ipv4, maybe_ipv6) {
|
||||
(None, None) => {
|
||||
// This should never happen unless clap is broken
|
||||
return Err("No listening addresses provided".into());
|
||||
unreachable!("This path is handled above this match statement");
|
||||
}
|
||||
(None, Some(ipv6)) => {
|
||||
// A single ipv6 address was provided. Set the ports
|
||||
|
||||
Reference in New Issue
Block a user