Skip to content

Commit e664fb8

Browse files
committed
Listen by default if user does not specify
1 parent d544829 commit e664fb8

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

beacon_node/src/cli.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ pub fn cli_app() -> Command {
156156
.long("listen-address")
157157
.value_name("ADDRESS")
158158
.help("The address lighthouse will listen for UDP and TCP connections. To listen \
159-
over IpV4 and IpV6 set this flag twice with the different values.\n\
159+
over IPv4 and IPv6 set this flag twice with the different values.\n\
160160
Examples:\n\
161161
- --listen-address '0.0.0.0' will listen over IPv4.\n\
162162
- --listen-address '::' will listen over IPv6.\n\
163163
- --listen-address '0.0.0.0' --listen-address '::' will listen over both \
164164
IPv4 and IPv6. The order of the given addresses is not relevant. However, \
165-
multiple IPv4, or multiple IPv6 addresses will not be accepted.")
165+
multiple IPv4, or multiple IPv6 addresses will not be accepted. \
166+
If omitted, Lighthouse will listen on all interfaces, for both IPv4 and IPv6.")
166167
.action(ArgAction::Append)
167168
.num_args(0..=2)
168-
.default_value("0.0.0.0")
169169
.display_order(0)
170170
)
171171
.arg(
@@ -224,13 +224,6 @@ 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-
)
234227
.arg(
235228
Arg::new("target-peers")
236229
.long("target-peers")

beacon_node/src/config.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -913,37 +913,24 @@ pub fn parse_listening_addresses(
913913
IpAddr::V4(v4_addr) => match &maybe_ipv4 {
914914
Some(first_ipv4_addr) => {
915915
return Err(format!(
916-
"When setting the --listen-address option twice, use an IpV4 address and an Ipv6 address. \
917-
Got two IpV4 addresses {first_ipv4_addr} and {v4_addr}"
916+
"When setting the --listen-address option twice, use an IPv4 address and an IPv6 address. \
917+
Got two IPv4 addresses {first_ipv4_addr} and {v4_addr}"
918918
));
919919
}
920920
None => maybe_ipv4 = Some(v4_addr),
921921
},
922922
IpAddr::V6(v6_addr) => match &maybe_ipv6 {
923923
Some(first_ipv6_addr) => {
924924
return Err(format!(
925-
"When setting the --listen-address option twice, use an IpV4 address and an Ipv6 address. \
926-
Got two IpV6 addresses {first_ipv6_addr} and {v6_addr}"
925+
"When setting the --listen-address option twice, use an IPv4 address and an IPv6 address. \
926+
Got two IPv6 addresses {first_ipv6_addr} and {v6_addr}"
927927
));
928928
}
929929
None => maybe_ipv6 = Some(v6_addr),
930930
},
931931
}
932932
}
933933

934-
// If we have specified an IPv4 listen address and not an IPv6 address and the
935-
// host has a globally routeable IPv6 address and the CLI doesn't expressly disable IPv6,
936-
// then we also listen on IPv6.
937-
// Note that we will only listen on all interfaces if the IPv4 counterpart is also listening on
938-
// all interfaces, to prevent accidental exposure of ports.
939-
if maybe_ipv4 == Some(Ipv4Addr::UNSPECIFIED)
940-
&& maybe_ipv6.is_none()
941-
&& !cli_args.get_flag("disable_ipv6")
942-
&& NetworkConfig::is_ipv6_supported()
943-
{
944-
maybe_ipv6 = Some(Ipv6Addr::UNSPECIFIED);
945-
}
946-
947934
// parse the possible tcp ports
948935
let port = cli_args
949936
.get_one::<String>("port")
@@ -991,11 +978,22 @@ pub fn parse_listening_addresses(
991978
format!("Failed to parse --quic6-port as an integer: {parse_error}")
992979
})?;
993980

981+
// Here we specify the default listening addresses for Lighthouse.
982+
// By default, we listen on 0.0.0.0.
983+
//
984+
// IF the host supports a globally routable IPv6 address, we also listen on ::.
985+
if matches!((maybe_ipv4, maybe_ipv6), (None, None)) {
986+
maybe_ipv4 = Some(Ipv4Addr::UNSPECIFIED);
987+
988+
if NetworkConfig::is_ipv6_supported() {
989+
maybe_ipv6 = Some(Ipv6Addr::UNSPECIFIED);
990+
}
991+
}
992+
994993
// Now put everything together
995994
let listening_addresses = match (maybe_ipv4, maybe_ipv6) {
996995
(None, None) => {
997-
// This should never happen unless clap is broken
998-
return Err("No listening addresses provided".into());
996+
unreachable!("This path is handled above this match statement");
999997
}
1000998
(None, Some(ipv6)) => {
1001999
// A single ipv6 address was provided. Set the ports

0 commit comments

Comments
 (0)