Skip to content

Commit

Permalink
Avoid a few unnecessary clones.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Vogel committed Sep 20, 2023
1 parent c4a5ebb commit 3e732a6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ x509-certificate = "0.21.0"
x509-parser = "0.15.1"

[build-dependencies]
libbpf-cargo = "0.21.1"
libbpf-cargo = "0.21.2"

11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
rebuild:

build:
cargo libbpf build
cargo build
sudo setcap cap_perfmon,cap_bpf+ep ./target/debug/certspook
sudo setcap cap_sys_admin=ep ./target/debug/certspook

rebuild:
make clean
make build

debug:
./target/debug/certspook
Expand All @@ -12,4 +17,4 @@ run:
clean:
cargo clean

.PHONY: clean debug rebuild run
.PHONY: clean debug gen_activity rebuild run
34 changes: 16 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl CmdArgs {
Result::from_iter(
self.included_networks
.split_terminator(',')
.map(|cidrstr| IpCidr::from_str(cidrstr))
.map(IpCidr::from_str)
.collect::<Vec<Result<IpCidr, IpCidrError>>>(),
)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ fn bump_memlock_rlimit() -> Result<()> {
}

fn handle_record(
log: Logger,
log: &Logger,
bytes: &[u8],
filter: &RemoteConnectionFilter,
tx_rconn: &Sender<RemoteConnection>,
Expand All @@ -114,7 +114,7 @@ fn handle_record(
}

fn handle_gai_result(
log: Logger,
log: &Logger,
bytes: &[u8],
filter: &RemoteConnectionFilter,
tx_chkque: &Sender<CheckDatum>,
Expand Down Expand Up @@ -179,16 +179,19 @@ fn main() -> Result<()> {
);

let (tx_chkque, rx_chkque) = channel::<CheckDatum>();
let tx_chkque1 = tx_chkque.clone();
let _check_thread = spawn_check_thread(log_root.clone(), expiration_threshold, rx_chkque);

let (tx_rconn, rx_rconn) = channel::<RemoteConnection>();
let _squelch_thread = spawn_squelch_thread(
log_root.clone(),
Duration::from_secs(cmd_args.squelch_seconds as u64),
rx_rconn,
tx_chkque,
);
let _squelch_thread = {
let tx_chkque = tx_chkque.clone();

spawn_squelch_thread(
log_root.clone(),
Duration::from_secs(cmd_args.squelch_seconds as u64),
rx_rconn,
tx_chkque,
)
};

bump_memlock_rlimit()?;

Expand Down Expand Up @@ -218,19 +221,14 @@ fn main() -> Result<()> {

let mut connaddr_ringbuf_builder = RingBufferBuilder::new();
connaddr_ringbuf_builder.add(map_handles.connaddrs(), {
let log_root = log_root.clone();
move |bytes| {
let log_root = log_root.clone();
let rconn_filter = rconn_filter.clone();
handle_record(log_root, bytes, &rconn_filter, &tx_rconn)
}
|bytes| handle_record(&log_root, bytes, &rconn_filter, &tx_rconn)
})?;
let connaddrs = connaddr_ringbuf_builder.build()?;

let gai_filter = RemoteConnectionFilter::new(cmd_args.included_networks()?.clone(), Vec::new());
let mut ex_gai_ringbuf_builder = RingBufferBuilder::new();
ex_gai_ringbuf_builder.add(map_handles.exported_gai_results(), move |bytes| {
handle_gai_result(log_root.clone(), bytes, &gai_filter, &tx_chkque1)
ex_gai_ringbuf_builder.add(map_handles.exported_gai_results(), |bytes| {
handle_gai_result(&log_root, bytes, &gai_filter, &tx_chkque)
})?;
let exported_gai_results = ex_gai_ringbuf_builder.build()?;

Expand Down
2 changes: 1 addition & 1 deletion src/remote_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl RemoteConnectionFilter {
}

pub fn allows_addr(&self, addr: &IpAddr) -> bool {
match self.cidr_list.iter().find(|c| c.contains(addr.clone())) {
match self.cidr_list.iter().find(|c| c.contains(*addr)) {
Some(_) => true,
None => false,
}
Expand Down

0 comments on commit 3e732a6

Please sign in to comment.