From 0adb31ea3ec887cb57a4fdff04677b11f4b469a4 Mon Sep 17 00:00:00 2001 From: Saber Haj Rabiee Date: Mon, 4 Mar 2024 23:04:29 -0800 Subject: [PATCH] fix clippy errors --- shared/src/netlink.rs | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/shared/src/netlink.rs b/shared/src/netlink.rs index 4bb86ff..5dcfc67 100644 --- a/shared/src/netlink.rs +++ b/shared/src/netlink.rs @@ -26,9 +26,11 @@ fn if_nametoindex(interface: &InterfaceName) -> Result { 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)]; @@ -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; @@ -78,13 +82,15 @@ pub fn add_route(interface: &InterfaceName, cidr: IpNet) -> Result (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)];