Skip to content

Commit

Permalink
Fix multiple mutable references to iface
Browse files Browse the repository at this point in the history
Also cleaned up some linter errors to make clippy happy.
  • Loading branch information
Molter73 committed Jun 17, 2024
1 parent a039cfa commit 61136fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Get tag
run: |
TAG="$(make tag)"
echo "TAG=$TAG" >> $GITHUB_ENV
echo "TAG=$TAG" >> "$GITHUB_ENV"
- name: Retag and push stackrox-io
uses: stackrox/actions/images/retag-and-push@v1
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ fn main() {
let elapsed = duration_timer.elapsed().unwrap().as_secs();

if elapsed > config.duration {
for handle in processes.into_iter().flatten() {
for handle in processes.iter().flatten() {
info!("Terminating: {}", *handle);
match kill(Pid::from_raw(*handle), Signal::SIGTERM) {
Ok(()) => {
continue;
}
Err(e) => {
Err(_) => {
continue;
}
}
Expand All @@ -125,7 +125,7 @@ fn main() {
}

s.spawn(move || {
for handle in processes.into_iter().flatten() {
for handle in processes.iter().flatten() {
info!("waitpid: {}", *handle);
waitpid(Pid::from_raw(*handle), None).unwrap();
}
Expand Down
27 changes: 17 additions & 10 deletions src/worker/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl NetworkWorker {
pub fn new(workload: WorkloadConfig, cpu: CoreId, process: usize) -> Self {
NetworkWorker {
config: BaseConfig { cpu, process },
workload: workload,
workload,
}
}

Expand Down Expand Up @@ -94,8 +94,8 @@ impl NetworkWorker {
server: _,
address: _,
target_port: _,
arrival_rate: arrival_rate,
departure_rate: departure_rate,
arrival_rate,
departure_rate,
nconnections,
send_interval,
} = self.workload.workload
Expand All @@ -106,7 +106,6 @@ impl NetworkWorker {
debug!("Starting client at {:?}:{:?}", addr, target_port);

let (mut iface, mut device, fd) = self.setup_tuntap(addr);
let cx = iface.context();

// Dynamic sockets are going to be responsible for connections that
// will be opened/closed during the test. Every record contains:
Expand Down Expand Up @@ -137,7 +136,11 @@ impl NetworkWorker {
self.get_local_addr_port(addr, index);
info!("connecting from {}:{}", local_addr, local_port);
socket
.connect(cx, (addr, target_port), (local_addr, local_port))
.connect(
iface.context(),
(addr, target_port),
(local_addr, local_port),
)
.unwrap();
}

Expand Down Expand Up @@ -169,7 +172,7 @@ impl NetworkWorker {
if elapsed > (interval * 1000.0).round() as u128 {
// Time for a new connection, add a socket, it state is going
// to be updated during the next loop round
total_conns = total_conns + 1;
total_conns += 1;

let tcp_rx_buffer = tcp::SocketBuffer::new(vec![0; 1024]);
let tcp_tx_buffer = tcp::SocketBuffer::new(vec![0; 1024]);
Expand All @@ -180,7 +183,11 @@ impl NetworkWorker {
self.get_local_addr_port(addr, index);

socket
.connect(cx, (addr, target_port), (local_addr, local_port))
.connect(
iface.context(),
(addr, target_port),
(local_addr, local_port),
)
.unwrap();

let handle = sockets.add(socket);
Expand Down Expand Up @@ -269,7 +276,7 @@ impl NetworkWorker {
info!("Close handle {}", h);
// TODO: reuse sockets
sockets.remove(h);
total_conns = total_conns - 1;
total_conns -= 1;
}

info!("Sockets: {}", total_conns);
Expand All @@ -293,7 +300,7 @@ impl NetworkWorker {
addr: Ipv4Address,
) -> (Interface, FaultInjector<Tracer<TunTapInterface>>, i32) {
let device_name = "tun0";
let device = TunTapInterface::new(&device_name, Medium::Ip).unwrap();
let device = TunTapInterface::new(device_name, Medium::Ip).unwrap();
let fd = device.as_raw_fd();

let seed = SystemTime::now()
Expand Down Expand Up @@ -350,7 +357,7 @@ impl NetworkWorker {
(((index / 100) + 2) % 255) as u8,
);

return (local_addr, local_port);
(local_addr, local_port)
}
}

Expand Down

0 comments on commit 61136fc

Please sign in to comment.