Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwanmhks authored Nov 5, 2022
2 parents 353eb08 + 8ea3370 commit 1cf2d13
Show file tree
Hide file tree
Showing 22 changed files with 589 additions and 450 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
include:
- build: linux-pinned
os: ubuntu-20.04
rust: 1.60.0
rust: 1.63.0
- build: linux-stable
os: ubuntu-20.04
rust: stable
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, nightly, 1.60.0 ]
rust: [ stable, beta, nightly, 1.63.0 ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -69,7 +69,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, nightly, 1.60.0 ]
rust: [ stable, beta, nightly, 1.63.0 ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

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

17 changes: 10 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ name = "trip"

# Library dependencies
socket2 = { version = "0.4.7", features = [ "all" ] }
nix = { version = "0.25.0", default-features = false, features = [ "user", "poll", "net" ] }
thiserror = "1.0.32"
derive_more = "0.99.17"
arrayvec = "0.7.2"

# TUI dependancies
anyhow = "1.0.62"
anyhow = "1.0.66"
dns-lookup = "1.0.8"
trust-dns-resolver = "0.22.0"
crossbeam = "0.8.2"
clap = { version = "4.0.11", features = [ "derive", "wrap_help", "cargo" ] }
clap = { version = "4.0.18", features = [ "derive", "wrap_help", "cargo" ] }
humantime = "2.1.0"
parking_lot = "0.12.1"
tui = "0.18.0"
crossterm = "0.23.2"
chrono = { version = "0.4.22", default-features = false, features = [ "clock" ] }
itertools = "0.10.3"
serde = { version = "1.0.144", features = [ "derive" ] }
serde_json = "1.0.85"
comfy-table = "6.0.0"
serde = { version = "1.0.147", features = [ "derive" ] }
serde_json = "1.0.87"
comfy-table = "6.1.2"

# Library dependancies (Linux)
[target.'cfg(target_os = "linux")'.dependencies]
caps = "0.5.4"
caps = "0.5.5"

# Library dependancies (Unix)
[target.'cfg(target_family = "unix")'.dependencies]
nix = { version = "0.25.0", default-features = false, features = [ "user", "poll", "net" ] }

[dev-dependencies]
rand = "0.8.5"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.60.0 as build-env
FROM rust:1.63.0 as build-env
WORKDIR /app
COPY Cargo.toml /app
COPY Cargo.lock /app
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,50 @@ the [tracking issue](https://github.com/fujiapple852/trippy/issues/274)):

### Cargo

[![Crates.io](https://img.shields.io/crates/v/trippy)](https://crates.io/crates/trippy/0.6.0)

```shell
cargo install trippy
```

### Homebrew

[![homebrew version](https://img.shields.io/badge/homebrew-0.6.0-blue)](https://github.com/fujiapple852/homebrew-trippy)

```shell
brew tap fujiapple852/trippy && brew install trippy
```

### NetBSD

[![pkgsrc current package](https://repology.org/badge/version-for-repo/pkgsrc_current/trippy.svg)](https://repology.org/project/trippy/versions)

```shell
pkgin install trippy
```

### Pacman (Arch Linux)

[![Arch package](https://repology.org/badge/version-for-repo/arch/trippy.svg)](https://repology.org/project/trippy/versions)

```shell
pacman -S trippy
```

### Snap

[![trippy](https://snapcraft.io/trippy/badge.svg)](https://snapcraft.io/trippy)

```shell
snap install trippy
```

### Docker

[![Docker Image Version (latest by date)](https://img.shields.io/docker/v/fujiapple/trippy)](https://hub.docker.com/r/fujiapple/trippy/)

```shell
docker run -it fujiapple/trippy www.bitwizard.nl
docker run -it fujiapple/trippy
```

## Platforms
Expand Down
44 changes: 42 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
name: trippy
version: '0.7.0-dev'
summary: A network diagnostic tool
description: Trippy combines the functionality of traceroute and ping and is designed to assist with the diagnosis of network issues.
contact: fujiapple852@gmail.com
description: |
Trippy combines the functionality of traceroute and ping and is designed to
assist with the diagnosis of network issues.
Features:
- Trace using multiple protocols:
- `ICMP`, `UDP` & `TCP`
- `IPv4` & `IPv6`
- Customizable tracing options:
- packet size & payload pattern
- start and maximum time-to-live (TTL)
- minimum and maximum round duration
- round end grace period & maximum number of unknown hops
- source & destination port (`TCP` & `UDP`)
- Equal Cost Multi-path Routing strategies (`classic`, `paris` and `dublin`)
- source address and source interface
- `TOS` (aka `DSCP + ECN`)
- Tui interface:
- Trace multiple targets simultaneously from a single instance of Trippy
- Per hop stats (sent, received, loss%, last, avg, best, worst, stddev & status)
- Per hop round-trip-time (RTT) history and frequency distributing charts
- Zoom-able chart of RTT for all hops in a trace
- Multiple hosts per hop with ability to cap display to N hosts and show frequency %
- Freeze/unfreeze the Tui, reset the stats, flush the cache, preserve screen on exit
- Responsive UI with adjustable refresh rate
- DNS:
- use system, external (Google `8.8.8.8` or Cloudflare `1.1.1.1`) or custom resolver
- Lazy reverse DNS queries
- Lookup autonomous system number (ASN) and name
- Generate tracing reports:
- `json`, `csv` & tabular (pretty-printed and markdown)
- configurable reporting cycles
- Runs on multiple platform (macOS, Linux, NetBSD)
- Capabilities aware application (Linux only)
This package auto-connects to the following snap interfaces:
- `network`: to allow general outgoing network access
- `network-bind`: to allow binding to local ports
- `network-observe`: to allow enabling `CAP_NET_RAW` for using raw sockets
contact: mailto:fujiapple852@gmail.com
issues: https://github.com/fujiapple852/trippy/issues
license: Apache-2.0
source-code: https://github.com/fujiapple852/trippy
Expand Down
55 changes: 11 additions & 44 deletions src/tracing/net/channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::tracing::error::TracerError::InvalidSourceAddr;
use crate::tracing::error::{TraceResult, TracerError};
use crate::tracing::net::platform::PlatformIpv4FieldByteOrder;
use crate::tracing::net::{ipv4, ipv6, Network};
use crate::tracing::net::{ipv4, ipv6, platform, Network};
use crate::tracing::probe::ProbeResponse;
use crate::tracing::types::{PacketSize, PayloadPattern, Port, Sequence, TraceId, TypeOfService};
use crate::tracing::util::Required;
Expand All @@ -10,11 +10,8 @@ use crate::tracing::{
};
use arrayvec::ArrayVec;
use itertools::Itertools;
use nix::sys::select::FdSet;
use nix::sys::time::{TimeVal, TimeValLike};
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
use std::net::{IpAddr, SocketAddr};
use std::os::unix::io::AsRawFd;
use std::time::{Duration, SystemTime};

/// The maximum size of the IP packet we allow.
Expand Down Expand Up @@ -196,7 +193,7 @@ impl TracerChannel {

/// Generate a `ProbeResponse` for the next available ICMP packet, if any
fn recv_icmp_probe(&mut self) -> TraceResult<Option<ProbeResponse>> {
if is_readable(&self.recv_socket, self.read_timeout)? {
if platform::is_readable(&self.recv_socket, self.read_timeout)? {
match self.addr_family {
TracerAddrFamily::Ipv4 => ipv4::recv_icmp_probe(
&mut self.recv_socket,
Expand All @@ -222,7 +219,7 @@ impl TracerChannel {
let found_index = self
.tcp_probes
.iter()
.find_position(|&probe| is_writable(&probe.socket).unwrap_or_default())
.find_position(|&probe| platform::is_writable(&probe.socket).unwrap_or_default())
.map(|(i, _)| i);
if let Some(i) = found_index {
let probe = self.tcp_probes.remove(i);
Expand All @@ -249,36 +246,6 @@ impl TcpProbe {
}
}

/// Returns true if the socket becomes readable before the timeout, false otherwise.
fn is_readable(sock: &Socket, timeout: Duration) -> TraceResult<bool> {
let mut read = FdSet::new();
read.insert(sock.as_raw_fd());
let readable = nix::sys::select::select(
None,
Some(&mut read),
None,
None,
Some(&mut TimeVal::milliseconds(timeout.as_millis() as i64)),
)
.map_err(|err| TracerError::IoError(std::io::Error::from(err)))?;
Ok(readable == 1)
}

/// Returns true if the socket is currently writeable, false otherwise.
fn is_writable(sock: &Socket) -> TraceResult<bool> {
let mut write = FdSet::new();
write.insert(sock.as_raw_fd());
let writable = nix::sys::select::select(
None,
None,
Some(&mut write),
None,
Some(&mut TimeVal::zero()),
)
.map_err(|err| TracerError::IoError(std::io::Error::from(err)))?;
Ok(writable == 1)
}

/// Validate, Lookup or discover the source `IpAddr`.
fn make_src_addr(
source_addr: Option<IpAddr>,
Expand All @@ -302,8 +269,8 @@ fn make_src_addr(
/// Lookup the address for a named interface.
fn lookup_interface_addr(addr_family: TracerAddrFamily, name: &str) -> TraceResult<IpAddr> {
match addr_family {
TracerAddrFamily::Ipv4 => ipv4::lookup_interface_addr(name),
TracerAddrFamily::Ipv6 => ipv6::lookup_interface_addr(name),
TracerAddrFamily::Ipv4 => platform::lookup_interface_addr_ipv4(name),
TracerAddrFamily::Ipv6 => platform::lookup_interface_addr_ipv6(name),
}
}

Expand Down Expand Up @@ -341,23 +308,23 @@ fn udp_socket_for_addr_family(addr_family: TracerAddrFamily) -> TraceResult<Sock
/// Make a socket for sending raw `ICMP` packets.
fn make_icmp_send_socket(addr_family: TracerAddrFamily) -> TraceResult<Socket> {
match addr_family {
TracerAddrFamily::Ipv4 => ipv4::make_icmp_send_socket(),
TracerAddrFamily::Ipv6 => ipv6::make_icmp_send_socket(),
TracerAddrFamily::Ipv4 => platform::make_icmp_send_socket_ipv4(),
TracerAddrFamily::Ipv6 => platform::make_icmp_send_socket_ipv6(),
}
}

/// Make a socket for sending `UDP` packets.
fn make_udp_send_socket(addr_family: TracerAddrFamily) -> TraceResult<Socket> {
match addr_family {
TracerAddrFamily::Ipv4 => ipv4::make_udp_send_socket(),
TracerAddrFamily::Ipv6 => ipv6::make_udp_send_socket(),
TracerAddrFamily::Ipv4 => platform::make_udp_send_socket_ipv4(),
TracerAddrFamily::Ipv6 => platform::make_udp_send_socket_ipv6(),
}
}

/// Make a socket for receiving raw `ICMP` packets.
fn make_recv_socket(addr_family: TracerAddrFamily) -> TraceResult<Socket> {
match addr_family {
TracerAddrFamily::Ipv4 => ipv4::make_recv_socket(),
TracerAddrFamily::Ipv6 => ipv6::make_recv_socket(),
TracerAddrFamily::Ipv4 => platform::make_recv_socket_ipv4(),
TracerAddrFamily::Ipv6 => platform::make_recv_socket_ipv6(),
}
}
Loading

0 comments on commit 1cf2d13

Please sign in to comment.