Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
update dependencies, release flow now builds on tags also, 1.0.1
Browse files Browse the repository at this point in the history
lint fixes
  • Loading branch information
aviramha committed Mar 10, 2022
1 parent 9b714b3 commit 3b79af6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ on:
push:
branches:
- main

tags:
- "*.*.*"
env:
IMAGE_NAME: mirrord-agent

Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## [Unreleased]

## 1.0.0 - 21/02/2021
## 1.0.1 - 10/3/2022
### Changed
* Update dependencies
* CI now builds from tag also.
## 1.0.0 - 21/02/2022
Initial release
54 changes: 27 additions & 27 deletions 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
@@ -1,6 +1,6 @@
[package]
name = "mirrord-agent"
version = "0.1.0"
version = "1.0.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
23 changes: 12 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn prepare_sniffer(ports: &[u16]) -> Result<Capture<pcap::Active>> {
let interface = interfaces
.into_iter()
.find(interface_names_match)
.ok_or(anyhow!("Interface not found"))?;
.ok_or_else(|| anyhow!("Interface not found"))?;

let mut cap = Capture::from_device(interface)?
.immediate_mode(true)
Expand Down Expand Up @@ -144,14 +144,13 @@ impl ConnectionManager {

fn handle_packet(&mut self, eth_packet: &EthernetPacket) -> Result<()> {
let ip_packet = match eth_packet.get_ethertype() {
EtherTypes::Ipv4 => {
Ipv4Packet::new(eth_packet.payload()).ok_or(anyhow!("Invalid IPv4 Packet"))?
}
EtherTypes::Ipv4 => Ipv4Packet::new(eth_packet.payload())
.ok_or_else(|| anyhow!("Invalid IPv4 Packet"))?,
_ => return Err(anyhow!("Not IPv4 Packet")),
};
let tcp_packet = match ip_packet.get_next_level_protocol() {
IpNextHeaderProtocols::Tcp => {
TcpPacket::new(ip_packet.payload()).ok_or(anyhow!("Invalid TCP Packet"))?
TcpPacket::new(ip_packet.payload()).ok_or_else(|| anyhow!("Invalid TCP Packet"))?
}
_ => return Err(anyhow!("Not TCP Packet")),
};
Expand Down Expand Up @@ -206,8 +205,8 @@ impl ConnectionManager {
fn capture(mut sniffer: Capture<Active>, ports: &[u16]) -> Result<()> {
let mut connection_manager = ConnectionManager::new(ports.to_owned());
while let Ok(packet) = sniffer.next() {
let packet =
EthernetPacket::new(&packet).ok_or(anyhow!("Packet is not an ethernet packet"))?;
let packet = EthernetPacket::new(&packet)
.ok_or_else(|| anyhow!("Packet is not an ethernet packet"))?;
let _ = connection_manager.handle_packet(&packet);
}
Ok(())
Expand All @@ -220,22 +219,24 @@ async fn get_container_namespace(container_id: String) -> Result<String> {
let request = with_namespace!(request, DEFAULT_CONTAINERD_NAMESPACE);
let resp = client.get(request).await?;
let resp = resp.into_inner();
let container = resp.container.ok_or(anyhow!("container not found"))?;
let container = resp
.container
.ok_or_else(|| anyhow!("container not found"))?;
let spec: Spec = serde_json::from_slice(
&container
.spec
.ok_or(anyhow!("invalid data from containerd"))?
.ok_or_else(|| anyhow!("invalid data from containerd"))?
.value,
)?;
let ns_path = spec
.linux
.namespaces
.iter()
.find(|ns| ns.ns_type == "network")
.ok_or(anyhow!("network namespace not found"))?
.ok_or_else(|| anyhow!("network namespace not found"))?
.path
.as_ref()
.ok_or(anyhow!("no network namespace path"))?;
.ok_or_else(|| anyhow!("no network namespace path"))?;
Ok(ns_path.to_owned())
}

Expand Down

0 comments on commit 3b79af6

Please sign in to comment.