Skip to content

Commit

Permalink
Bump the netlink group with 2 updates
Browse files Browse the repository at this point in the history
Bumps the netlink group with 2 updates: [netlink-packet-route](https://github.com/rust-netlink/netlink-packet-route) and [rtnetlink](https://github.com/rust-netlink/rtnetlink).

Updates `netlink-packet-route` from 0.17.1 to 0.18.1
- [Release notes](https://github.com/rust-netlink/netlink-packet-route/releases)
- [Changelog](https://github.com/rust-netlink/netlink-packet-route/blob/main/CHANGELOG)
- [Commits](rust-netlink/netlink-packet-route@v0.17.1...v0.18.1)

Updates `rtnetlink` from 0.13.1 to 0.14.0
- [Release notes](https://github.com/rust-netlink/rtnetlink/releases)
- [Changelog](https://github.com/rust-netlink/rtnetlink/blob/main/CHANGELOG)
- [Commits](rust-netlink/rtnetlink@v0.13.1...v0.14.0)

---
updated-dependencies:
- dependency-name: netlink-packet-route
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: netlink
- dependency-name: rtnetlink
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: netlink
...

Co-authored-by: Martin Kröning <[email protected]>
  • Loading branch information
dependabot[bot] and mkroening committed Jan 2, 2024
1 parent 8b6e14e commit 6e346fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
34 changes: 8 additions & 26 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ goblin = { version = "0.8", default-features = false, features = ["elf64", "elf3
libc = "0.2"
log = { version = "0.4", features = ["std"] }
netlink-packet-core = "0.7"
netlink-packet-route = "0.17"
netlink-packet-route = "0.18"
nix = { version = "0.27", features = [
"hostname",
"ioctl",
Expand All @@ -38,7 +38,7 @@ nix = { version = "0.27", features = [
oci-spec = "0.6"
path-clean = "1.0"
procfs = { version = "0.15", default-features = false }
rtnetlink = "0.13"
rtnetlink = "0.14"
serde_json = "1.0"
serde = "1.0"
time = { version = "0.3", features = ["formatting"] }
Expand Down
30 changes: 21 additions & 9 deletions src/network.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use futures::TryStreamExt;
use netlink_packet_core::ErrorMessage;
use netlink_packet_route::{address, link, route, MACVLAN_MODE_PASSTHRU};
use netlink_packet_route::address::AddressAttribute;
use netlink_packet_route::link::LinkAttribute;
use netlink_packet_route::route::{RouteAddress, RouteAttribute};
use nix::sys::stat::SFlag;
use rtnetlink::Error::NetlinkError;
use std::net::IpAddr;
use std::num::NonZeroI32;
use std::path::PathBuf;
use std::{error::Error, fmt, net::Ipv4Addr};

// FIXME: https://github.com/rust-netlink/netlink-packet-route/issues/88
const MACVLAN_MODE_PASSTHRU: u32 = 8;

#[derive(Debug)]
struct VirtioNetworkError {
details: String,
Expand Down Expand Up @@ -117,19 +123,25 @@ pub async fn create_tap() -> Result<VirtioNetworkConfig, Box<dyn std::error::Err
.expect("Could not read address info for interface eth0!");

// Extract IP address from address info
for nla in device_addr_msg.nlas.iter() {
if let address::nlas::Nla::Address(addr) = nla {
ip_address = Some(Ipv4Addr::from([addr[0], addr[1], addr[2], addr[3]]));
for address_attribute in device_addr_msg.attributes.into_iter() {
if let AddressAttribute::Address(addr) = address_attribute {
match addr {
IpAddr::V4(addr) => ip_address = Some(addr),
IpAddr::V6(_) => panic!(),
}
prefix_length = Some(device_addr_msg.header.prefix_len);
}
}

// Get route info and extract gateway address
let mut route_get_req = handle.route().get(rtnetlink::IpVersion::V4).execute();
while let Some(route_msg) = route_get_req.try_next().await? {
for nla in route_msg.nlas.into_iter() {
if let route::Nla::Gateway(addr) = nla {
gateway_address = Some(Ipv4Addr::from([addr[0], addr[1], addr[2], addr[3]]));
for route_attribute in route_msg.attributes.into_iter() {
if let RouteAttribute::Gateway(addr) = route_attribute {
match addr {
RouteAddress::Inet(addr) => gateway_address = Some(addr),
_ => panic!(),
}
break;
}
}
Expand Down Expand Up @@ -158,8 +170,8 @@ pub async fn create_tap() -> Result<VirtioNetworkConfig, Box<dyn std::error::Err
let macvtap_index = macvtap_link_info.header.index;

// Extract mac from macvtap
for nla in macvtap_link_info.nlas.into_iter() {
if let link::nlas::Nla::Address(addr) = nla {
for link_attribute in macvtap_link_info.attributes.into_iter() {
if let LinkAttribute::Address(addr) = link_attribute {
if addr.len() != 6 {
return Err(Box::new(VirtioNetworkError::from(format!(
"Received invalid MAC address {addr:?} for macvtap device!"
Expand Down

0 comments on commit 6e346fe

Please sign in to comment.