Skip to content

Commit 6fefb30

Browse files
committed
Formatting and docs
1 parent 61c14d4 commit 6fefb30

File tree

11 files changed

+62
-63
lines changed

11 files changed

+62
-63
lines changed

src/enc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl EncKeyId {
1212
/// Create a new `EncKeyId` without checking the validity of the ID value.
1313
///
1414
/// # Safety
15-
///
15+
///
1616
/// Failure to ensure the ID is within the valid range for the tunnel in
1717
/// question may lead to semantically invalid netlink messages.
1818
///
@@ -37,7 +37,7 @@ impl EncKeyId {
3737
/// of geneve vni values.
3838
///
3939
/// # Errors
40-
///
40+
///
4141
/// Returns an error if the ID is greater than or equal to 2^24.
4242
pub fn new_geneve_vni(id: u32) -> Result<Self, DecodeError> {
4343
match Self::new_nbit::<24>(id) {
@@ -49,9 +49,9 @@ impl EncKeyId {
4949
}
5050

5151
/// Create a new `EncKeyId` in the space of valid GRE keys.
52-
///
52+
///
5353
/// # Safety
54-
///
54+
///
5555
/// Since GRE keys are 32 bits and all values are legal, this method is not
5656
/// failable.
5757
#[must_use]
@@ -63,7 +63,7 @@ impl EncKeyId {
6363
/// of gtp tunnel key values.
6464
///
6565
/// # Errors
66-
///
66+
///
6767
/// Returns an error if the ID is zero.
6868
pub fn new_gtp_key(id: u32) -> Result<Self, DecodeError> {
6969
if id == 0 {
@@ -78,7 +78,7 @@ impl EncKeyId {
7878
/// of N bit values.
7979
///
8080
/// # Errors
81-
///
81+
///
8282
/// Returns an error if the ID is greater than or equal to 2^N.
8383
const fn new_nbit<const N: usize>(id: u32) -> Result<Self, KeyTooLarge> {
8484
if id >= (1 << N) {

src/message.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,16 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
193193
let msg = match RouteMessageBuffer::new_checked(&buf.inner()) {
194194
Ok(buf) => RouteMessage::parse(&buf)
195195
.context("invalid route message")?,
196-
// HACK: iproute2 sends invalid RTM_GETROUTE message, where
197-
// the header is limited to the
198-
// interface family (1 byte) and 3 bytes of padding.
196+
// HACK: iproute2 sends an invalid RTM_GETROUTE message,
197+
// where the header is limited to the interface family
198+
// (1 byte) and 3 bytes of padding.
199199
Err(e) => {
200-
// Not only does iproute2 sends invalid messages, it's
201-
// also inconsistent in
202-
// doing so: for link and address messages, the length
203-
// advertised in the
204-
// netlink header includes the 3 bytes of padding but it
205-
// does not seem to be the case
206-
// for the route message, hence the buf.length() == 1
207-
// check.
200+
// Not only does iproute2 send invalid messages, it's
201+
// also inconsistent in doing so: for link and address
202+
// messages, the length advertised in the netlink header
203+
// includes the 3 bytes of padding, but it does not seem
204+
// to be the case for the route message, hence the
205+
// `buf.length() == 1` check.
208206
if (buf.inner().len() == 4 || buf.inner().len() == 1)
209207
&& message_type == RTM_GETROUTE
210208
{
@@ -253,6 +251,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
253251
_ => unreachable!(),
254252
}
255253
}
254+
256255
// TC Messages
257256
RTM_NEWQDISC | RTM_DELQDISC | RTM_GETQDISC | RTM_NEWTCLASS
258257
| RTM_DELTCLASS | RTM_GETTCLASS | RTM_NEWTFILTER
@@ -292,13 +291,13 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
292291
}
293292
}
294293

294+
// TC action messages
295295
RTM_NEWACTION | RTM_DELACTION | RTM_GETACTION => {
296-
let err = "invalid tc action message";
297296
let msg = TcActionMessage::parse(
298297
&TcActionMessageBuffer::new_checked(&buf.inner())
299-
.context(err)?,
298+
.context("invalid tc action message buffer")?,
300299
)
301-
.context(err)?;
300+
.context("invalid tc action message")?;
302301
match message_type {
303302
RTM_NEWACTION => RouteNetlinkMessage::NewTrafficAction(msg),
304303
RTM_DELACTION => RouteNetlinkMessage::DelTrafficAction(msg),

src/net/arp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ const OP_EXP1: u8 = 24;
2626
const OP_EXP2: u8 = 25;
2727

2828
/// Enum of ARP operation codes.
29-
///
29+
///
3030
/// List from [iana.org][1]
31-
///
31+
///
3232
/// [1]: https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
3333
#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd, Hash)]
3434
#[non_exhaustive]

src/net/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
// General purpose networking abstractions.
2-
#![forbid(unsafe_code)]
3-
#![deny(
4-
clippy::all,
5-
clippy::pedantic,
6-
clippy::unwrap_used,
7-
clippy::expect_used,
8-
clippy::panic,
9-
)]
1+
//! General purpose networking abstractions.
102
113
pub mod arp;
124
pub mod ethernet;

src/net/vxlan.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Vni {
3535
pub fn new_unchecked(vni: u32) -> Self {
3636
Self(vni)
3737
}
38-
38+
3939
pub const MAX: u32 = (1 << 24) - 1;
4040
pub const MIN: u32 = 1;
4141
}
@@ -75,26 +75,25 @@ impl AsRef<u32> for Vni {
7575
#[cfg(test)]
7676
mod tests {
7777
use super::*;
78-
78+
7979
#[test]
8080
fn zero_vni_is_invalid() {
8181
assert!(Vni::new(0).is_err());
8282
}
83-
83+
8484
#[test]
8585
fn max_vni_is_valid() {
8686
assert!(Vni::new(Vni::MAX).is_ok());
8787
}
88-
88+
8989
#[test]
9090
fn vni_greater_than_max_is_invalid() {
9191
assert!(Vni::new(Vni::MAX + 1).is_err());
9292
}
93-
93+
9494
#[test]
9595
fn vni_is_converted_to_u32() {
9696
let vni = Vni::new_unchecked(42);
9797
assert_eq!(u32::from(vni), 42);
9898
}
99-
100-
}
99+
}

src/tc/actions/tests/nat.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ use crate::tc::{
1818
};
1919
use crate::AddressFamily;
2020

21+
/// # Setup
22+
///
2123
/// Capture of request for
2224
///
23-
/// ```bash
25+
/// ```shell
2426
/// tc actions add action nat ingress 1.2.3.4/32 5.6.7.0 index 1
2527
/// ```
28+
///
29+
/// # Packet Modification
30+
///
31+
/// * cooked header removed (16 bytes).
32+
/// * rtnetlink header removed (16 bytes).
2633
const TC_ACTION_NAT_EXAMPLE1: &str = "000000003c00010038000100080001006e6174002c0002802800010001000000000000000000000000000000000000000102030405060700ffffffff00000000";
2734

2835
fn tc_action_message_nat_example1() -> TcActionMessage {
@@ -70,11 +77,18 @@ fn emit_tc_action_nat_example1() {
7077
assert_eq!(buf, hex::decode(TC_ACTION_NAT_EXAMPLE1).unwrap());
7178
}
7279

80+
/// # Setup
81+
///
7382
/// Capture of request for
7483
///
75-
/// ```bash
84+
/// ```shell
7685
/// tc actions add action nat ingress 1.2.3.0/24 5.6.7.9 index 2
7786
/// ```
87+
///
88+
/// # Packet Modifications
89+
///
90+
/// * cooked header removed (16 bytes).
91+
/// * rtnetlink header removed (16 bytes).
7892
const TC_ACTION_NAT_EXAMPLE2: &str = "000000003c00010038000100080001006e6174002c0002802800010002000000000000000000000000000000000000000102030005060709ffffff0000000000";
7993

8094
fn tc_action_message_nat_example2() -> TcActionMessage {
@@ -124,7 +138,7 @@ fn emit_tc_action_nat_example2() {
124138

125139
/// Capture of request for
126140
///
127-
/// ```bash
141+
/// ```shell
128142
/// tc actions add action nat egress 2.3.4.0/24 5.6.7.9 index 3
129143
/// ```
130144
const TC_ACTION_NAT_EXAMPLE3: &str = "000000003c00010038000100080001006e6174002c0002802800010003000000000000000000000000000000000000000203040005060709ffffff0001000000";
@@ -260,20 +274,21 @@ fn tc_action_nat_option_emit_tm_uses_whole_buffer() {
260274
}
261275
}
262276

263-
/// Setup:
277+
/// # Setup
264278
///
265-
/// ```bash
279+
/// ```shell
266280
/// tc actions flush action nat
267281
/// tc actions add action nat ingress 192.0.2.1/32 203.0.113.1 index 1
268282
/// ```
269283
///
270284
/// Then capture netlink response message of this command:
271285
///
272-
/// ```bash
286+
/// ```shell
273287
/// tc -statistics actions get action nat index 1
274288
/// ```
275289
///
276-
/// Raw packet modification:
290+
/// # Packet Modifications
291+
///
277292
/// * cooked header removed (16 bytes).
278293
/// * rtnetlink header removed (16 bytes).
279294
#[test]

src/tc/filters/cls_flower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ impl TcFilterFlower {
162162
/// [2]: https://www.ieee802.org/1/pages/802.1ag.html
163163
pub type CfmOpCode = u8;
164164

165-
166165
bitflags! {
167166
// TcpFlags _ARE_ exactly 8 bits.
168167
// Why flower uses a 16-bit field is a mystery, but we deal with it.
@@ -705,8 +704,9 @@ impl Nla for TcFilterFlowerOption {
705704
(flags.bits() as u16).to_be_bytes().as_slice(),
706705
),
707706
Self::KeyTcpFlagsMask(flags) => {
708-
buffer
709-
.copy_from_slice(u16::from(*flags).to_be_bytes().as_slice());
707+
buffer.copy_from_slice(
708+
u16::from(*flags).to_be_bytes().as_slice(),
709+
);
710710
}
711711
Self::KeyIpTos(tos) => {
712712
buffer.copy_from_slice(tos.to_be_bytes().as_slice());

src/tc/filters/flower/encap/erspan.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ impl Nla for Direction {
146146
}
147147
}
148148

149-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
150-
for Direction
151-
{
149+
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Direction {
152150
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
153151
if buf.value().len() != 1 {
154152
return Err(DecodeError::from(format!(
@@ -261,9 +259,7 @@ impl Nla for Options {
261259
}
262260
}
263261

264-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
265-
for Options
266-
{
262+
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Options {
267263
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
268264
Ok(match buf.kind() {
269265
TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER => {

src/tc/filters/flower/encap/gtp.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Options {
5555
TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE => {
5656
Options::PduType(parse_u8(payload)?)
5757
}
58-
TCA_FLOWER_KEY_ENC_OPT_GTP_QFI => {
59-
Options::Qfi(parse_u8(payload)?)
60-
}
58+
TCA_FLOWER_KEY_ENC_OPT_GTP_QFI => Options::Qfi(parse_u8(payload)?),
6159
_ => Options::Other(
6260
DefaultNla::parse(buf).context("failed to parse gtp nla")?,
6361
),

src/tc/filters/flower/encap/vxlan.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use byteorder::{ByteOrder, NativeEndian};
22
use netlink_packet_utils::nla::{DefaultNla, Nla, NlaBuffer};
3-
use netlink_packet_utils::{DecodeError, Parseable};
43
use netlink_packet_utils::parsers::parse_u32;
4+
use netlink_packet_utils::{DecodeError, Parseable};
55

66
const TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GPB: u16 = 1; /* u32 */
77

@@ -12,7 +12,6 @@ pub enum Options {
1212
Other(DefaultNla),
1313
}
1414

15-
1615
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Options {
1716
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
1817
Ok(match buf.kind() {

0 commit comments

Comments
 (0)