Skip to content

Commit 9b206c8

Browse files
committed
feat: Enable ipv6 and add address family sorting option
1 parent 59db80a commit 9b206c8

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

mgmtd/assets/beegfs-mgmtd.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
# The interfaces are reported in the given order. If not given, all suitable interfaces can be used.
4242
# interfaces = ["eth0", "eth1"]
4343

44+
# Prefers an interfaces ipv6 addresses over ipv4.
45+
# By default, ipv4 addresses are preferred. If the interface filter is given, the interface
46+
# order has higher priority than the address family, which is sorted per interface.
47+
# interfaces_prefer_ipv6 = false
48+
4449
# Maximum number of outgoing connections per node.
4550
# connection-limit = 12
4651

mgmtd/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ generate_structs! {
212212
#[arg(value_delimiter = ',')]
213213
interfaces: Vec<String> = vec![],
214214

215+
/// Prefers an interfaces ipv6 addresses over ipv4.
216+
///
217+
/// By default, ipv4 addresses are preferred. If the interface filter is given, the interface
218+
/// order has higher priority than the address family, which is sorted per interface.
219+
#[arg(long)]
220+
#[arg(num_args = 0..=1, default_missing_value = "true")]
221+
interfaces_prefer_ipv6: bool = false,
222+
215223
/// Maximum number of outgoing BeeMsg connections per node. [default: 12]
216224
#[arg(long)]
217225
#[arg(value_name = "LIMIT")]

mgmtd/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub async fn start(info: StaticInfo, license: LicenseVerifier) -> Result<RunCont
6363
// UDP socket for in- and outgoing messages
6464
let udp_socket = Arc::new(
6565
UdpSocket::bind(SocketAddr::new(
66-
"0.0.0.0".parse()?,
66+
"::0".parse()?,
6767
info.user_config.beemsg_port,
6868
))
6969
.await?,
@@ -122,7 +122,7 @@ pub async fn start(info: StaticInfo, license: LicenseVerifier) -> Result<RunCont
122122

123123
// Listen for incoming TCP connections
124124
incoming::listen_tcp(
125-
SocketAddr::new("0.0.0.0".parse()?, ctx.info.user_config.beemsg_port),
125+
SocketAddr::new("::0".parse()?, ctx.info.user_config.beemsg_port),
126126
ctx.clone(),
127127
info.auth_secret.is_some(),
128128
run_state.clone(),

mgmtd/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ doc.beegfs.io.",
9797
None
9898
};
9999

100-
let network_addrs = shared::ethernet_interfaces(&user_config.interfaces)?;
100+
let network_addrs =
101+
shared::ethernet_interfaces(&user_config.interfaces, user_config.interfaces_prefer_ipv6)?;
101102

102103
// Configure the tokio runtime
103104
let rt = tokio::runtime::Builder::new_multi_thread()

shared/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ pub struct NetworkAddr {
3030
///
3131
/// Only interfaces matching one of the given names in `filter` will be returned, unless the list
3232
/// is empty.
33-
pub fn ethernet_interfaces(filter: &[impl AsRef<str>]) -> Result<Vec<NetworkAddr>> {
33+
pub fn ethernet_interfaces(
34+
filter: &[impl AsRef<str>],
35+
prefer_ipv6: bool,
36+
) -> Result<Vec<NetworkAddr>> {
3437
let mut filtered_nics = vec![];
3538
for interface in pnet_datalink::interfaces() {
3639
if !filter.is_empty() && !filter.iter().any(|e| interface.name == e.as_ref()) {
3740
continue;
3841
}
3942

4043
for ip in interface.ips {
41-
// TODO Ipv6: Remove the Ipv4 filter when protocol changes (https://github.com/ThinkParQ/beegfs-rs/issues/145)
42-
if !ip.is_ipv4() {
43-
continue;
44-
}
45-
4644
filtered_nics.push(NetworkAddr {
4745
addr: ip.ip(),
4846
name: interface.name.clone(),
@@ -58,8 +56,11 @@ pub fn ethernet_interfaces(filter: &[impl AsRef<str>]) -> Result<Vec<NetworkAddr
5856
bail!("At least one network interface doesn't exist");
5957
}
6058

59+
// Sort by address family
60+
filtered_nics.sort_unstable_by_key(|k| (prefer_ipv6 ^ k.addr.is_ipv6()) as usize);
61+
6162
// Sort
62-
filtered_nics.sort_unstable_by_key(|k| {
63+
filtered_nics.sort_by_key(|k| {
6364
if filter.is_empty() {
6465
// Move loopbacks to the back
6566
k.addr.is_loopback() as usize

0 commit comments

Comments
 (0)