Skip to content

Commit 395ace5

Browse files
Merge pull request #978 from Luap99/sctp-test
fix ncat sctp test and update CI image
2 parents ed0c0ff + 87fe59f commit 395ace5

File tree

8 files changed

+44
-95
lines changed

8 files changed

+44
-95
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
CARGO_TARGET_DIR: "$CIRRUS_WORKING_DIR/targets"
1717
# Save a little typing (path relative to $CIRRUS_WORKING_DIR)
1818
SCRIPT_BASE: "./contrib/cirrus"
19-
IMAGE_SUFFIX: "c20240102t155643z-f39f38d13"
19+
IMAGE_SUFFIX: "c20240506t132946z-f40f39d13"
2020
FEDORA_NETAVARK_IMAGE: "fedora-netavark-${IMAGE_SUFFIX}"
2121
AARDVARK_DNS_BRANCH: "main"
2222
AARDVARK_DNS_URL: "https://api.cirrus-ci.com/v1/artifact/github/containers/aardvark-dns/success/binary.zip?branch=${AARDVARK_DNS_BRANCH}"

src/dhcp_proxy/ip.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,9 @@ use crate::network::netlink;
1212
use crate::network::netlink::Socket;
1313
use ipnet::IpNet;
1414
use log::debug;
15-
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
15+
use std::net::{IpAddr, Ipv4Addr};
1616
use std::str::FromStr;
1717

18-
trait IpConv {
19-
fn to_v4(&self) -> Result<&Ipv4Addr, ProxyError>;
20-
fn to_v6(&self) -> Result<&Ipv6Addr, ProxyError>;
21-
}
22-
23-
// Simple implementation for converting from IPAddr to
24-
// specific IP type
25-
impl IpConv for IpAddr {
26-
fn to_v4(&self) -> Result<&Ipv4Addr, ProxyError> {
27-
match self {
28-
IpAddr::V4(ip) => Ok(ip),
29-
IpAddr::V6(_) => Err(ProxyError::new(
30-
"invalid value for ipv4 conversion".to_string(),
31-
)),
32-
}
33-
}
34-
35-
fn to_v6(&self) -> Result<&Ipv6Addr, ProxyError> {
36-
match self {
37-
IpAddr::V4(_) => Err(ProxyError::new(
38-
"invalid value for ipv6 conversion".to_string(),
39-
)),
40-
IpAddr::V6(ip) => Ok(ip),
41-
}
42-
}
43-
}
44-
4518
/*
4619
Information that came back in the DHCP lease like name_servers,
4720
domain and host names, etc. will be implemented in podman; not here.
@@ -63,7 +36,6 @@ trait Address<T> {
6336
Self: Sized;
6437
fn add_ip(&self, nls: &mut Socket) -> Result<(), ProxyError>;
6538
fn add_gws(&self, nls: &mut Socket) -> Result<(), ProxyError>;
66-
fn remove(self) -> Result<(), ProxyError>;
6739
}
6840

6941
fn handle_gws(g: Vec<String>, netmask: &str) -> Result<Vec<IpNet>, ProxyError> {
@@ -122,7 +94,7 @@ impl Address<Ipv4Addr> for MacVLAN {
12294
let gateways = match handle_gws(l.gateways.clone(), &l.subnet_mask) {
12395
Ok(g) => g,
12496
Err(e) => {
125-
return Err(ProxyError::new(format!("bad gateways: {}", e.to_string())));
97+
return Err(ProxyError::new(format!("bad gateways: {}", e)));
12698
}
12799
};
128100
let prefix_length = match get_prefix_length_v4(&l.subnet_mask) {
@@ -158,15 +130,6 @@ impl Address<Ipv4Addr> for MacVLAN {
158130
Err(e) => Err(ProxyError::new(e.to_string())),
159131
}
160132
}
161-
162-
/*
163-
For now, nv will remove the interface; this causes all IP stuff
164-
to fold.
165-
*/
166-
fn remove(self) -> Result<(), ProxyError> {
167-
debug!("removing interface {}", self.interface);
168-
todo!()
169-
}
170133
}
171134

172135
// setup takes the DHCP lease and some additional information and

src/dhcp_proxy/lib.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use g_rpc::netavark_proxy_client::NetavarkProxyClient;
99
use log::debug;
1010
use std::fs::File;
1111
use std::net::AddrParseError;
12-
use std::net::{Ipv4Addr, Ipv6Addr};
12+
use std::net::Ipv4Addr;
1313
use std::str::FromStr;
1414
use tokio::net::UnixStream;
1515
use tonic::transport::{Channel, Endpoint, Uri};
@@ -271,7 +271,6 @@ impl NetworkConfig {
271271

272272
trait VectorConv {
273273
fn to_v4_addrs(&self) -> Result<Option<Vec<Ipv4Addr>>, AddrParseError>;
274-
fn to_v6_addrs(&self) -> Result<Option<Vec<Ipv6Addr>>, AddrParseError>;
275274
}
276275

277276
impl VectorConv for Vec<String> {
@@ -288,18 +287,4 @@ impl VectorConv for Vec<String> {
288287
}
289288
Ok(Some(out_addrs))
290289
}
291-
292-
fn to_v6_addrs(&self) -> Result<Option<Vec<Ipv6Addr>>, AddrParseError> {
293-
if self.is_empty() {
294-
return Ok(None);
295-
}
296-
let mut out_addrs = Vec::new();
297-
for ip in self {
298-
match Ipv6Addr::from_str(ip) {
299-
Ok(i) => out_addrs.push(i),
300-
Err(e) => return Err(e),
301-
};
302-
}
303-
Ok(Some(out_addrs))
304-
}
305290
}

src/dhcp_proxy/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl CustomErr for ProxyError {
4040
}
4141
}
4242

43-
impl ToString for ProxyError {
44-
fn to_string(&self) -> String {
45-
self.0.to_string()
43+
impl std::fmt::Display for ProxyError {
44+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45+
write!(f, "{}", self.0)
4646
}
4747
}
4848

src/dns/aardvark.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ impl Aardvark {
202202
.read(true)
203203
.write(true)
204204
.create(true)
205+
.truncate(true)
205206
.open(&lockfile_path)
206207
{
207208
Ok(file) => file,
@@ -355,7 +356,7 @@ impl Aardvark {
355356
pub fn modify_network_dns_servers(
356357
&self,
357358
network_name: &str,
358-
network_dns_servers: &Vec<String>,
359+
network_dns_servers: &[String],
359360
) -> NetavarkResult<()> {
360361
let mut dns_servers_modified = false;
361362
let path = Path::new(&self.config).join(network_name);

src/network/macvlan_dhcp.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ pub fn get_dhcp_lease(
4242
container_iface: container_network_interface.to_string(),
4343
container_mac_addr: container_macvlan_mac.to_string(),
4444
};
45-
let lease = match {
46-
tokio::task::LocalSet::new().block_on(
47-
match &tokio::runtime::Builder::new_current_thread()
48-
.enable_io()
49-
.build()
50-
{
51-
Ok(r) => r,
52-
Err(e) => {
53-
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
54-
}
55-
},
56-
nvp_config.get_lease(DEFAULT_UDS_PATH),
57-
)
58-
} {
45+
let lease = match tokio::task::LocalSet::new().block_on(
46+
match &tokio::runtime::Builder::new_current_thread()
47+
.enable_io()
48+
.build()
49+
{
50+
Ok(r) => r,
51+
Err(e) => {
52+
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
53+
}
54+
},
55+
nvp_config.get_lease(DEFAULT_UDS_PATH),
56+
) {
5957
Ok(l) => l,
6058
Err(e) => {
6159
return Err(NetavarkError::msg(format!("unable to obtain lease: {e}")));
@@ -114,20 +112,18 @@ pub fn release_dhcp_lease(
114112
container_iface: container_network_interface.to_string(),
115113
container_mac_addr: container_macvlan_mac.to_string(),
116114
};
117-
match {
118-
tokio::task::LocalSet::new().block_on(
119-
match &tokio::runtime::Builder::new_current_thread()
120-
.enable_io()
121-
.build()
122-
{
123-
Ok(r) => r,
124-
Err(e) => {
125-
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
126-
}
127-
},
128-
nvp_config.drop_lease(DEFAULT_UDS_PATH),
129-
)
130-
} {
115+
match tokio::task::LocalSet::new().block_on(
116+
match &tokio::runtime::Builder::new_current_thread()
117+
.enable_io()
118+
.build()
119+
{
120+
Ok(r) => r,
121+
Err(e) => {
122+
return Err(NetavarkError::msg(format!("unable to build thread: {e}")));
123+
}
124+
},
125+
nvp_config.drop_lease(DEFAULT_UDS_PATH),
126+
) {
131127
Ok(_) => {}
132128
Err(e) => {
133129
return Err(NetavarkError::Message(e.to_string()));

src/network/vlan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn setup(
307307
let random = Alphanumeric.sample_string(&mut rand::thread_rng(), 10);
308308
let tmp_name = "mv-".to_string() + &random;
309309
let mut opts = opts.clone();
310-
opts.name = tmp_name.clone();
310+
opts.name.clone_from(&tmp_name);
311311
result = host.create_link(opts);
312312
if let Err(ref e) = result {
313313
// if last element return directly

test/helpers.bash

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,18 @@ function run_nc_test() {
621621
local host_port=$5
622622

623623
local nc_common_args=""
624-
local stdin=/dev/null
624+
exec {stdin}<>/dev/null
625625

626626
case $proto in
627627
tcp) ;; # nothing to do (default)
628628
udp) nc_common_args=--udp ;;
629629
sctp)
630630
nc_common_args=--sctp
631-
# for some reason we have to attach STDIN to the server only for the sctp proto
632-
# otherwise it will just exit for unknown reasons. However we must not add STDIN
633-
# to udp and tcp otherwise those tests will fail.
634-
stdin=/dev/zero
631+
# For some reason we have to attach a empty STDIN (not /dev/null and not something with data in it)
632+
# to the server only for the sctp proto otherwise it will just exit for weird reasons.
633+
# As such create a empty anonymous pipe to work around that.
634+
# https://github.com/nmap/nmap/issues/2829
635+
exec {stdin}<> <(:)
635636
;;
636637
*) die "unknown port proto '$proto'" ;;
637638
esac
@@ -644,7 +645,7 @@ function run_nc_test() {
644645
fi
645646

646647
nsenter -n -t "${CONTAINER_NS_PIDS[$container_ns]}" timeout --foreground -v --kill=10 5 \
647-
nc $nc_common_args -l -p $container_port &>"$NETAVARK_TMPDIR/nc-out" <$stdin &
648+
nc $nc_common_args -l -p $container_port &>"$NETAVARK_TMPDIR/nc-out" <&$stdin &
648649

649650
# make sure to wait until port is bound otherwise test can flake
650651
# https://github.com/containers/netavark/issues/433
@@ -661,6 +662,9 @@ function run_nc_test() {
661662

662663
got=$(cat "$NETAVARK_TMPDIR/nc-out")
663664
assert "$got" == "$data" "ncat received data"
665+
666+
# close the fd
667+
exec {stdin}>&-
664668
}
665669

666670
#################

0 commit comments

Comments
 (0)