Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sabify committed Mar 5, 2024
1 parent 513abbd commit 806065e
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions shared/src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ 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 mut message = LinkMessage::default();
message.header = header;
message.nlas = vec![link::nlas::Nla::Mtu(mtu)];
let mut header = LinkHeader {
index,
flags: IFF_UP,
..Default::default()
};
let mut message = LinkMessage {
header,
nlas: vec![link::nlas::Nla::Mtu(mtu)],
..Default::default()
};
netlink_request_rtnl(RtnlMessage::SetLink(message), None)?;
log::debug!("set interface {} up with mtu {}", interface, mtu);
Ok(())
Expand All @@ -55,15 +59,18 @@ 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 mut message = AddressMessage::default();
message.header = header;
message.nlas = nlas;
let mut header = AddressHeader {
index,
family,
prefix_len: addr.prefix_len(),
scope: RT_SCOPE_UNIVERSE,
..Default::default()
};
let mut message = AddressMessage {
header,
nlas,
..Default::default()
};
netlink_request_rtnl(
RtnlMessage::NewAddress(message),
Some(NLM_F_REQUEST | NLM_F_ACK | NLM_F_REPLACE | NLM_F_CREATE),
Expand All @@ -78,17 +85,20 @@ 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 mut message = RouteMessage::default();
message.header = header;
message.nlas = vec![route::Nla::Destination(dst), route::Nla::Oif(if_index)];

let mut 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 {
header,
nlas: vec![route::Nla::Destination(dst), route::Nla::Oif(if_index)],
..Default::default()
};
match netlink_request_rtnl(RtnlMessage::NewRoute(message), None) {
Ok(_) => {
log::debug!("added route {} to interface {}", cidr, interface);
Expand Down

0 comments on commit 806065e

Please sign in to comment.