Skip to content

Commit

Permalink
fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sabify committed Mar 5, 2024
1 parent df033ca commit 0adb31e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions shared/src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ fn if_nametoindex(interface: &InterfaceName) -> Result<u32, io::Error> {

pub fn set_up(interface: &InterfaceName, mtu: u32) -> Result<(), io::Error> {
let index = if_nametoindex(interface)?;
let mut header = LinkHeader::default();
header.index = index;
header.flags = IFF_UP;
let header = LinkHeader {
index,
flags: IFF_UP,
..Default::default()
};
let mut message = LinkMessage::default();
message.header = header;
message.nlas = vec![link::nlas::Nla::Mtu(mtu)];
Expand All @@ -55,11 +57,13 @@ pub fn set_addr(interface: &InterfaceName, addr: IpNet) -> Result<(), io::Error>
vec![address::Nla::Address(network.addr().octets().to_vec())],
),
};
let mut header = AddressHeader::default();
header.index = index;
header.family = family;
header.prefix_len = addr.prefix_len();
header.scope = RT_SCOPE_UNIVERSE;
let header = AddressHeader {
index,
family,
prefix_len: addr.prefix_len(),
scope: RT_SCOPE_UNIVERSE,
..Default::default()
};

let mut message = AddressMessage::default();
message.header = header;
Expand All @@ -78,13 +82,15 @@ pub fn add_route(interface: &InterfaceName, cidr: IpNet) -> Result<bool, io::Err
IpNet::V4(network) => (AF_INET as u8, network.network().octets().to_vec()),
IpNet::V6(network) => (AF_INET6 as u8, network.network().octets().to_vec()),
};
let mut header = RouteHeader::default();
header.table = RT_TABLE_MAIN;
header.protocol = RTPROT_BOOT;
header.scope = RT_SCOPE_LINK;
header.kind = RTN_UNICAST;
header.destination_prefix_length = cidr.prefix_len();
header.address_family = address_family;
let header = RouteHeader {
table: RT_TABLE_MAIN,
protocol: RTPROT_BOOT,
scope: RT_SCOPE_LINK,
kind: RTN_UNICAST,
destination_prefix_length: cidr.prefix_len(),
address_family,
..Default::default()
};
let mut message = RouteMessage::default();
message.header = header;
message.nlas = vec![route::Nla::Destination(dst), route::Nla::Oif(if_index)];
Expand Down

0 comments on commit 0adb31e

Please sign in to comment.