Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get default route example #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

daniel-noland
Copy link
Contributor

This example was created in response to issue #63

This example was created in response to [issue rust-netlink#63](rust-netlink#63)
@daniel-noland daniel-noland force-pushed the default-route-example branch from e2bcfc8 to b758332 Compare May 12, 2024 23:07
Copy link
Member

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example could be a perfect place to demonstrate both kernel space route filtering and use space route filtering.

The table ID could be done by kernel filtering.
The destination_prefix_length == 0 cannot be use for kernel filter(because kernel only filter non-zero property).

This is example of kernel filtering on route table:

// SPDX-License-Identifier: MIT

use futures::stream::TryStreamExt;
use netlink_sys::AsyncSocket;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (mut connection, handle, _) = rtnetlink::new_connection()?;
    connection
        .socket_mut()
        .socket_mut()
        .set_netlink_get_strict_chk(true)?;
    tokio::spawn(connection);
    let mut rt_handle = handle.route().get(rtnetlink::IpVersion::V4);
    let rt_nlmsg = rt_handle.message_mut();
    rt_nlmsg.header.table = 254;
    rt_nlmsg.header.destination_prefix_length = 0;

    let mut route_getter = rt_handle.execute();

    while let Some(rt_msg) = route_getter.try_next().await? {
        println!("HAHA {:?}", rt_msg);
    }
    Ok(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants