Coder Social home page Coder Social logo

johnyburd / net-route Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 12.0 59 KB

Rust crate providing a cross platform interface for interacting with the routing table

Home Page: https://docs.rs/net-route/

Rust 72.24% C 27.76%
linux macos networking routing-table rust windows

net-route's People

Contributors

dawson-jones avatar flier avatar gregor-netdebug avatar harryjph avatar hsqstephenzhang avatar johnyburd avatar matt3o12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

net-route's Issues

The `Handle::add` returns an error on macOs when setting the route to `0.0.0.0/0`

The way of setting routes to make all traffic reach the specified tun interface is suggested to be:

 let if_name = CString::new("utun6")?;
let tun_ifindex = unsafe{
	libc::if_nametoindex(if_name.as_ptr())
};
let handle = Handle::new()?;
let route = Route::new("0.0.0.0".parse().unwrap(), 0).with_ifindex(tun_ifindex);
handle.add(&route).await  // #1

However, #1 just returns an error Err(Custom { kind: AlreadyExists, error: "rtm_errno 17" }). If set the routing with Route::new("20.0.0.0".parse().unwrap(), 24).with_ifindex(tun_ifindex); then it's OK.

In both case, there is a panic at

.cargo/registry/src/index.crates.io-6f17d22bba15001f/net-route-0.2.11/src/platform_impl/macos/macos.rs:254:25:
index out of bounds: the len is 12 but the index is 12
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

IPv6 is broken on macOS

IPv6 LAN-local routes come back with either /0 or /128 prefix and no interface index. I'm investigating to see if I can do a PR.

Make the routing table recoverable after the program exits with exceptions

I found that the routing table cannot be recovered once the program setting the routing table with net-route exits without being correct to call delete API, the only approach is to restart the system. net-route seems can record the original associated setting to disk such that the routing table can be recoverable after the next time the program run.

Doesn't compile on macOS 14.2.1

OS: macOS 14.2.1 (23C71)
CPU: Apple M1

error[E0560]: struct `bind::rt_metrics` has no field named `rmx_state`
   --> /Users/frost/.cargo/registry/src/index.crates.io-6f17d22bba15001f/net-route-0.2.8/src/platform_impl/macos/macos.rs:231:13
    |
231 |             rmx_state: 0,
    |             ^^^^^^^^^ `bind::rt_metrics` does not have this field
    |
    = note: all struct fields are already assigned
error[E0308]: mismatched types
   --> /Users/frost/.cargo/registry/src/index.crates.io-6f17d22bba15001f/net-route-0.2.8/src/platform_impl/macos/macos.rs:232:25
    |
232 |             rmx_filler: [0u32; 3],
    |                         ^^^^^^^^^ expected an array with a fixed size of 4 elements, found one with 3 elements

new rt_metrics struct

struct rt_metrics {
	u_int32_t       rmx_locks;      /* Kernel leaves these values alone */
	u_int32_t       rmx_mtu;        /* MTU for this path */
	u_int32_t       rmx_hopcount;   /* max hops expected */
	int32_t         rmx_expire;     /* lifetime for route, e.g. redirect */
	u_int32_t       rmx_recvpipe;   /* inbound delay-bandwidth product */
	u_int32_t       rmx_sendpipe;   /* outbound delay-bandwidth product */
	u_int32_t       rmx_ssthresh;   /* outbound gateway buffer limit */
	u_int32_t       rmx_rtt;        /* estimated round trip time */
	u_int32_t       rmx_rttvar;     /* estimated rtt variance */
	u_int32_t       rmx_pksent;     /* packets sent using this route */
	u_int32_t       rmx_filler[4];  /* will be used for TCP's peer-MSS cache */
};

Setting route `0.0.0.0/1` makes the `bind_device_by_index_v4` of socket2 unusable

When setting 0.0.0.0/1, almost traffic are routing to tun, and bind_device_by_index_v4 is used to make the socket binding to the specified network interface such that the traffic of the socket does not pass through the routing table. However, it seems not work when using net-route, the approach does work when using tproxy-config.

The error is

called Result::unwrap() on an Err value: Os { code: 51, kind: NetworkUnreachable, message: "Network is unreachable" }

recv data would block

use futures::StreamExt;
use net_route::Handle;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let handle = Handle::new()?;
    let stream = handle.route_listen_stream();

    futures::pin_mut!(stream);

    println!("Listening for route events, press Ctrl+C to cancel...");
    while let Some(value) = stream.next().await {
        println!("{:?}", value);
    }
    Ok(())
}

this is code from examples/listen.rs, It would block when you switch the wifi, this bug is 100% reproducible

bindings.rs: No such file or directory (os error 2) on macOs

target/debug/build/net-route-02f35d3dceb1c1e4/out/bindings.rs: No such file or directory (os error 2)
  |
5 | include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.