Skip to content

Commit b8a59b1

Browse files
committed
Fix cargo clippy
Signed-off-by: Gris Ge <[email protected]>
1 parent 55e4835 commit b8a59b1

24 files changed

+53
-71
lines changed

src/address/attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Nla for AddressAttribute {
6060
IPV4_ADDR_LEN
6161
}
6262
}
63-
Self::Label(ref string) => string.as_bytes().len() + 1,
63+
Self::Label(ref string) => string.len() + 1,
6464

6565
Self::Flags(_) => size_of::<u32>(),
6666

src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
// SPDX-License-Identifier: MIT
22

3+
//! The `netlink-packet-route` crate is designed to abstract Netlink route
4+
//! protocol(`rtnetlink`) packet into Rust data types. The goal of this crate is
5+
//! saving netlink user from reading Kernel Netlink codes.
6+
//!
7+
//! This crate grouped Netlink route protocol into these modules:
8+
//! * `link`: NIC interface, similar to to `ip link` command.
9+
//! * `address`: IP address, similar to `ip address` command.
10+
//! * `route`: Route, similar to `ip route` command.
11+
//! * `rule`: Route rule, similar to `ip rule` command.
12+
//! * `tc`: Traffic control, similar to `tc` command.
13+
//! * `neighbour`: Neighbour, similar to `ip neighbour` command.
14+
//! * `neighbour_table`: Neighbour table, similar to `ip ntable` command.
15+
//! * `nsid`: Namespace, similar to `ip netns` command.
16+
//!
17+
//! At the top level of this crate, we also provide:
18+
//! * [AddressFamily]
19+
//!
20+
//! Normally, you should use [`rtnetlink`][rtnetlink_url] instead of using this
21+
//! crate directly.
22+
//!
23+
//! [rtnetlink_url]: https://docs.rs/rtnetlink
24+
325
pub mod address;
426
pub mod link;
527
pub mod neighbour;
@@ -42,28 +64,6 @@ pub use self::address_family_fallback::AddressFamily;
4264
pub use self::ip::IpProtocol;
4365
pub use self::message::{RouteNetlinkMessage, RouteNetlinkMessageBuffer};
4466

45-
/// The `netlink-packet-route` crate is designed to abstract Netlink route
46-
/// protocol(`rtnetlink`) packet into Rust data types. The goal of this crate is
47-
/// saving netlink user from reading Kernel Netlink codes.
48-
///
49-
/// This crate grouped Netlink route protocol into these modules:
50-
/// * `link`: NIC interface, similar to to `ip link` command.
51-
/// * `address`: IP address, similar to `ip address` command.
52-
/// * `route`: Route, similar to `ip route` command.
53-
/// * `rule`: Route rule, similar to `ip rule` command.
54-
/// * `tc`: Traffic control, similar to `tc` command.
55-
/// * `neighbour`: Neighbour, similar to `ip neighbour` command.
56-
/// * `neighbour_table`: Neighbour table, similar to `ip ntable` command.
57-
/// * `nsid`: Namespace, similar to `ip netns` command.
58-
///
59-
/// At the top level of this crate, we also provide:
60-
/// * [AddressFamily]
61-
///
62-
/// Normally, you should use [`rtnetlink`][rtnetlink_url] instead of using this
63-
/// crate directly.
64-
///
65-
/// [rtnetlink_url]: https://docs.rs/rtnetlink
66-
6767
#[macro_use]
6868
extern crate netlink_packet_utils;
6969

src/link/attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Nla for LinkAttribute {
188188
Self::IfName(string)
189189
| Self::Qdisc(string)
190190
| Self::IfAlias(string)
191-
| Self::PhysPortName(string) => string.as_bytes().len() + 1,
191+
| Self::PhysPortName(string) => string.len() + 1,
192192

193193
Self::Mode(_) | Self::Carrier(_) | Self::ProtoDown(_) => 1,
194194

src/link/prop_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Nla for Prop {
2222
fn value_len(&self) -> usize {
2323
use self::Prop::*;
2424
match self {
25-
AltIfName(ref string) => string.as_bytes().len() + 1,
25+
AltIfName(ref string) => string.len() + 1,
2626
Other(nla) => nla.value_len()
2727
}
2828
}

src/link/sriov/broadcast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ buffer!(VfInfoBroadcastBuffer(VF_INFO_BROADCAST_LEN) {
2626
addr: (slice, 0..VF_INFO_BROADCAST_LEN),
2727
});
2828

29-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoBroadcastBuffer<&'a T>>
29+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoBroadcastBuffer<&T>>
3030
for VfInfoBroadcast
3131
{
3232
fn parse(buf: &VfInfoBroadcastBuffer<&T>) -> Result<Self, DecodeError> {

src/link/sriov/guid.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ buffer!(VfInfoGuidBuffer(VF_INFO_GUID_LEN) {
2222
guid: (u64, 4..12),
2323
});
2424

25-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoGuidBuffer<&'a T>>
26-
for VfInfoGuid
27-
{
25+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoGuidBuffer<&T>> for VfInfoGuid {
2826
fn parse(buf: &VfInfoGuidBuffer<&T>) -> Result<Self, DecodeError> {
2927
Ok(Self::new(buf.vf_id(), buf.guid()))
3028
}

src/link/sriov/link_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buffer!(VfInfoLinkStateBuffer(VF_INFO_LINK_STATE_LEN) {
2222
state: (u32, 4..8),
2323
});
2424

25-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoLinkStateBuffer<&'a T>>
25+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoLinkStateBuffer<&T>>
2626
for VfInfoLinkState
2727
{
2828
fn parse(buf: &VfInfoLinkStateBuffer<&T>) -> Result<Self, DecodeError> {

src/link/sriov/mac.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ buffer!(VfInfoMacBuffer(VF_INFO_MAC_LEN) {
3333
mac: (slice, 4..VF_INFO_MAC_LEN),
3434
});
3535

36-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoMacBuffer<&'a T>>
37-
for VfInfoMac
38-
{
36+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoMacBuffer<&T>> for VfInfoMac {
3937
fn parse(buf: &VfInfoMacBuffer<&T>) -> Result<Self, DecodeError> {
4038
Ok(Self::new(buf.vf_id(), buf.mac()))
4139
}

src/link/sriov/rate.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ buffer!(VfInfoRateBuffer(VF_INFO_RATE_LEN) {
2828
max_tx_rate: (u32, 8..12)
2929
});
3030

31-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoRateBuffer<&'a T>>
32-
for VfInfoRate
33-
{
31+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoRateBuffer<&T>> for VfInfoRate {
3432
fn parse(buf: &VfInfoRateBuffer<&T>) -> Result<Self, DecodeError> {
3533
Ok(Self {
3634
vf_id: buf.vf_id(),

src/link/sriov/rss_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buffer!(VfInfoRssQueryEnBuffer(VF_INFO_RSS_QUERY_EN_LEN) {
2222
setting: (u32, 4..8),
2323
});
2424

25-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoRssQueryEnBuffer<&'a T>>
25+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoRssQueryEnBuffer<&T>>
2626
for VfInfoRssQueryEn
2727
{
2828
fn parse(buf: &VfInfoRssQueryEnBuffer<&T>) -> Result<Self, DecodeError> {

src/link/sriov/spoofchk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buffer!(VfInfoSpoofCheckBuffer(VF_INFO_SPOOFCHK_LEN) {
2222
setting: (u32, 4..8),
2323
});
2424

25-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoSpoofCheckBuffer<&'a T>>
25+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoSpoofCheckBuffer<&T>>
2626
for VfInfoSpoofCheck
2727
{
2828
fn parse(buf: &VfInfoSpoofCheckBuffer<&T>) -> Result<Self, DecodeError> {

src/link/sriov/trust.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ buffer!(VfInfoTrustBuffer(VF_INFO_TRUST_LEN) {
2222
setting: (u32, 4..8),
2323
});
2424

25-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoTrustBuffer<&'a T>>
26-
for VfInfoTrust
27-
{
25+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoTrustBuffer<&T>> for VfInfoTrust {
2826
fn parse(buf: &VfInfoTrustBuffer<&T>) -> Result<Self, DecodeError> {
2927
Ok(Self::new(
3028
buf.vf_id(),

src/link/sriov/tx_rate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buffer!(VfInfoTxRateBuffer(VF_INFO_TX_RATE_LEN) {
2222
rate: (u32, 4..8),
2323
});
2424

25-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoTxRateBuffer<&'a T>>
25+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoTxRateBuffer<&T>>
2626
for VfInfoTxRate
2727
{
2828
fn parse(buf: &VfInfoTxRateBuffer<&T>) -> Result<Self, DecodeError> {

src/link/sriov/vf_vlan.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ buffer!(VfVlanInfoBuffer(VF_VLAN_INFO_LEN) {
9090
protocol: (u16, 12..14),
9191
});
9292

93-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfVlanInfoBuffer<&'a T>>
94-
for VfVlanInfo
95-
{
93+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfVlanInfoBuffer<&T>> for VfVlanInfo {
9694
fn parse(buf: &VfVlanInfoBuffer<&T>) -> Result<Self, DecodeError> {
9795
Ok(Self {
9896
vf_id: buf.vf_id(),

src/link/sriov/vlan.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ buffer!(VfInfoVlanBuffer(VF_INFO_VLAN_LEN) {
2828
qos: (u32, 8..12)
2929
});
3030

31-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoVlanBuffer<&'a T>>
32-
for VfInfoVlan
33-
{
31+
impl<T: AsRef<[u8]> + ?Sized> Parseable<VfInfoVlanBuffer<&T>> for VfInfoVlan {
3432
fn parse(buf: &VfInfoVlanBuffer<&T>) -> Result<Self, DecodeError> {
3533
Ok(Self {
3634
vf_id: buf.vf_id(),

src/route/mpls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ impl From<u32> for MplsLabel {
138138

139139
impl From<MplsLabel> for u32 {
140140
fn from(v: MplsLabel) -> u32 {
141-
v.label << MPLS_LS_LABEL_SHIFT
142-
| (v.traffic_class as u32) << MPLS_LS_TC_SHIFT
143-
| (v.bottom_of_stack as u32) << MPLS_LS_S_SHIFT
144-
| (v.ttl as u32) << MPLS_LS_TTL_SHIFT
141+
(v.label << MPLS_LS_LABEL_SHIFT)
142+
| ((v.traffic_class as u32) << MPLS_LS_TC_SHIFT)
143+
| ((v.bottom_of_stack as u32) << MPLS_LS_S_SHIFT)
144+
| ((v.ttl as u32) << MPLS_LS_TTL_SHIFT)
145145
}
146146
}
147147

src/route/next_hops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ pub struct RouteNextHop {
9494
pub attributes: Vec<RouteAttribute>,
9595
}
9696

97-
impl<'a, T: AsRef<[u8]>>
97+
impl<T: AsRef<[u8]>>
9898
ParseableParametrized<
99-
RouteNextHopBuffer<&'a T>,
99+
RouteNextHopBuffer<&T>,
100100
(AddressFamily, RouteType, RouteLwEnCapType),
101101
> for RouteNextHop
102102
{

src/route/realm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Emitable for RouteRealm {
3434
}
3535

3636
fn emit(&self, buffer: &mut [u8]) {
37-
let all = (self.source as u32) << 16 | self.destination as u32;
37+
let all = ((self.source as u32) << 16) | self.destination as u32;
3838
buffer.copy_from_slice(&all.to_ne_bytes());
3939
}
4040
}

src/rule/attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Nla for RuleAttribute {
8080
Self::SourcePortRange(v) | Self::DestinationPortRange(v) => {
8181
v.buffer_len()
8282
}
83-
Self::Iifname(s) | Self::Oifname(s) => s.as_bytes().len() + 1,
83+
Self::Iifname(s) | Self::Oifname(s) => s.len() + 1,
8484
Self::Priority(_)
8585
| Self::FwMark(_)
8686
| Self::FwMask(_)

src/tc/actions/action.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ impl Nla for TcActionAttribute {
192192
match self {
193193
Self::Cookie(bytes) => buffer.copy_from_slice(bytes.as_slice()),
194194
Self::Kind(string) => {
195-
buffer[..string.as_bytes().len()]
196-
.copy_from_slice(string.as_bytes());
197-
buffer[string.as_bytes().len()] = 0;
195+
buffer[..string.len()].copy_from_slice(string.as_bytes());
196+
buffer[string.len()] = 0;
198197
}
199198
Self::Options(opt) => opt.as_slice().emit(buffer),
200199
Self::Index(value) | Self::InHwCount(value) => {
@@ -580,7 +579,7 @@ buffer!(TcfBuffer(TC_TCF_BUF_LEN) {
580579
firstuse: (u64, 24..32),
581580
});
582581

583-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<TcfBuffer<&'a T>> for Tcf {
582+
impl<T: AsRef<[u8]> + ?Sized> Parseable<TcfBuffer<&T>> for Tcf {
584583
fn parse(buf: &TcfBuffer<&T>) -> Result<Self, DecodeError> {
585584
Ok(Self {
586585
install: buf.install(),

src/tc/actions/mirror.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ impl Emitable for TcMirror {
116116
}
117117
}
118118

119-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<TcMirrorBuffer<&'a T>>
120-
for TcMirror
121-
{
119+
impl<T: AsRef<[u8]> + ?Sized> Parseable<TcMirrorBuffer<&T>> for TcMirror {
122120
fn parse(buf: &TcMirrorBuffer<&T>) -> Result<Self, DecodeError> {
123121
Ok(Self {
124122
generic: TcActionGeneric::parse(&TcActionGenericBuffer::new(

src/tc/actions/nat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Emitable for TcNat {
139139
}
140140
}
141141

142-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<TcNatBuffer<&'a T>> for TcNat {
142+
impl<T: AsRef<[u8]> + ?Sized> Parseable<TcNatBuffer<&T>> for TcNat {
143143
fn parse(buf: &TcNatBuffer<&T>) -> Result<Self, DecodeError> {
144144
Ok(Self {
145145
generic: TcActionGeneric::parse(&TcActionGenericBuffer::new(

src/tc/actions/tunnel_key.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ impl Emitable for TcTunnelKey {
189189
}
190190
}
191191

192-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<TcTunnelKeyBuffer<&'a T>>
193-
for TcTunnelKey
194-
{
192+
impl<T: AsRef<[u8]> + ?Sized> Parseable<TcTunnelKeyBuffer<&T>> for TcTunnelKey {
195193
fn parse(buf: &TcTunnelKeyBuffer<&T>) -> Result<Self, DecodeError> {
196194
Ok(Self {
197195
generic: TcActionGeneric::parse(&TcActionGenericBuffer::new(

src/tc/attribute.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Nla for TcAttribute {
6060
Self::HwOffload(_) => 1,
6161
Self::Stats2(ref v) => v.as_slice().buffer_len(),
6262
Self::Stats(ref v) => v.buffer_len(),
63-
Self::Kind(ref string) => string.as_bytes().len() + 1,
63+
Self::Kind(ref string) => string.len() + 1,
6464
Self::Options(ref opt) => opt.as_slice().buffer_len(),
6565
Self::DumpInvisible(_) => 0, // The existence of NLA means true
6666
Self::Other(ref attr) => attr.value_len(),
@@ -78,9 +78,8 @@ impl Nla for TcAttribute {
7878
Self::Stats2(ref stats) => stats.as_slice().emit(buffer),
7979
Self::Stats(ref stats) => stats.emit(buffer),
8080
Self::Kind(ref string) => {
81-
buffer[..string.as_bytes().len()]
82-
.copy_from_slice(string.as_bytes());
83-
buffer[string.as_bytes().len()] = 0;
81+
buffer[..string.len()].copy_from_slice(string.as_bytes());
82+
buffer[string.len()] = 0;
8483
}
8584
Self::Options(ref opt) => opt.as_slice().emit(buffer),
8685
Self::DumpInvisible(_) => (),

0 commit comments

Comments
 (0)