Skip to content

Commit 76962a4

Browse files
committed
Clean up EncOpts vs Options
1 parent 7989668 commit 76962a4

File tree

9 files changed

+109
-135
lines changed

9 files changed

+109
-135
lines changed

src/tc/actions/tunnel_key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use netlink_packet_utils::{
1111
DecodeError,
1212
};
1313

14-
use crate::tc::filters::flower::encap::{EncOpts, parse_enc_opts};
14+
use crate::tc::filters::flower::encap::{Options, parse_enc_opts};
1515
use crate::tc::{TcActionGenericBuffer};
1616
use crate::EncKeyId;
1717

@@ -167,7 +167,7 @@ pub enum TcActionTunnelKeyOption {
167167
KeyEncIpv6Src(Ipv6Addr),
168168
KeyEncDstPort(UdpPort),
169169
KeyNoChecksum(bool),
170-
KeyEncOpts(EncOpts),
170+
KeyEncOpts(Options),
171171
KeyEncTos(Tos),
172172
KeyEncTtl(Ttl),
173173
KeyNoFrag,

src/tc/filters/arp.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
///
33
/// [1]: https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
44
use crate::tc::filters::ethernet::Mac;
5-
use std::net::Ipv4Addr;
6-
7-
pub type Sip = Ipv4Addr;
8-
pub type SipMask = Ipv4Addr;
9-
pub type Tip = Ipv4Addr;
10-
pub type TipMask = Ipv4Addr;
115

126
const RESERVED: u8 = 0;
137
const REQUEST: u8 = 1;
@@ -36,7 +30,7 @@ const MAPO_SUNARP: u8 = 23;
3630
const OP_EXP1: u8 = 24;
3731
const OP_EXP2: u8 = 25;
3832

39-
#[derive(Debug, PartialEq, Eq, Clone)]
33+
#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd, Hash)]
4034
#[non_exhaustive]
4135
#[repr(u8)]
4236
pub enum Operation {
@@ -143,8 +137,6 @@ impl From<Operation> for u8 {
143137
}
144138
}
145139

146-
pub type OperationMask = u8;
147-
148140
pub type Sha = Mac;
149141
pub type ShaMask = Mac;
150142
pub type Tha = Mac;

src/tc/filters/cls_flower.rs

Lines changed: 66 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use netlink_packet_utils::{
1818
};
1919

2020
use crate::tc::filters::ethernet;
21-
use crate::tc::filters::flower::encap::EncOpts;
21+
use crate::tc::filters::flower::encap;
2222
use crate::tc::filters::flower::mpls;
2323
use crate::tc::{arp, icmpv4, icmpv6, TcAction, TcFlowerOptionFlags, TcHandle};
2424
use crate::{EncKeyId, IpProtocol};
@@ -141,21 +141,6 @@ impl TcFilterFlower {
141141
pub const KIND: &'static str = "flower";
142142
}
143143

144-
pub type AbstractPort = u16;
145-
pub type IpTos = u8;
146-
pub type IpTosMask = u8;
147-
pub type IpTtl = u8;
148-
pub type IpTtlMask = u8;
149-
pub type L2tpV3Sid = u32;
150-
pub type PppProtocol = u16;
151-
pub type PppoeSid = u16;
152-
pub type SctpPort = u16;
153-
pub type Spi = u32;
154-
pub type SpiMask = u32;
155-
pub type TcpFlagsMask = u8;
156-
pub type TcpPort = u16;
157-
pub type UdpPort = u16;
158-
159144
/// I can't figure out a better type than just `u8` for `CfmOpCode`.
160145
/// The only reserved values and meanings I was able to find were in
161146
/// [rfc7319][1], and that only specifies that values 64-95 are expressly
@@ -221,10 +206,10 @@ pub enum TcFilterFlowerOption {
221206
KeyIpv6SrcMask(Ipv6Addr),
222207
KeyIpv6Dst(Ipv6Addr),
223208
KeyIpv6DstMask(Ipv6Addr),
224-
KeyTcpSrc(TcpPort),
225-
KeyTcpDst(TcpPort),
226-
KeyUdpSrc(UdpPort),
227-
KeyUdpDst(UdpPort),
209+
KeyTcpSrc(u16),
210+
KeyTcpDst(u16),
211+
KeyUdpSrc(u16),
212+
KeyUdpDst(u16),
228213
Flags(TcFlowerOptionFlags),
229214
Other(DefaultNla),
230215
KeyVlanId(ethernet::VlanId),
@@ -239,80 +224,80 @@ pub enum TcFilterFlowerOption {
239224
KeyEncIpv6SrcMask(Ipv6Addr),
240225
KeyEncIpv6Dst(Ipv6Addr),
241226
KeyEncIpv6DstMask(Ipv6Addr),
242-
KeyTcpSrcMask(TcpPort),
243-
KeyTcpDstMask(TcpPort),
244-
KeyUdpSrcMask(UdpPort),
245-
KeyUdpDstMask(UdpPort),
246-
KeySctpSrcMask(SctpPort),
247-
KeySctpDstMask(SctpPort),
248-
KeySctpSrc(SctpPort),
249-
KeySctpDst(SctpPort),
250-
KeyEncUdpSrcPort(UdpPort),
251-
KeyEncUdpSrcPortMask(UdpPort),
252-
KeyEncUdpDstPort(UdpPort),
253-
KeyEncUdpDstPortMask(UdpPort),
227+
KeyTcpSrcMask(u16),
228+
KeyTcpDstMask(u16),
229+
KeyUdpSrcMask(u16),
230+
KeyUdpDstMask(u16),
231+
KeySctpSrcMask(u16),
232+
KeySctpDstMask(u16),
233+
KeySctpSrc(u16),
234+
KeySctpDst(u16),
235+
KeyEncUdpSrcPort(u16),
236+
KeyEncUdpSrcPortMask(u16),
237+
KeyEncUdpDstPort(u16),
238+
KeyEncUdpDstPortMask(u16),
254239
KeyFlags(FlowerKeyFlags),
255240
KeyFlagsMask(FlowerKeyFlags),
256241
KeyIcmpv4Code(icmpv4::Code),
257-
KeyIcmpv4CodeMask(icmpv4::CodeMask),
242+
KeyIcmpv4CodeMask(u8),
258243
KeyIcmpv4Type(icmpv4::Type),
259-
KeyIcmpv4TypeMask(icmpv4::TypeMask),
244+
KeyIcmpv4TypeMask(u8),
260245
KeyIcmpv6Code(icmpv6::Code),
261-
KeyIcmpv6CodeMask(icmpv6::CodeMask),
246+
KeyIcmpv6CodeMask(u8),
262247
KeyIcmpv6Type(icmpv6::Type),
263-
KeyIcmpv6TypeMask(icmpv6::TypeMask),
264-
KeyArpSip(arp::Sip),
265-
KeyArpSipMask(arp::SipMask),
266-
KeyArpTip(arp::Tip),
267-
KeyArpTipMask(arp::TipMask),
248+
KeyIcmpv6TypeMask(u8),
249+
KeyArpSip(Ipv4Addr),
250+
KeyArpSipMask(Ipv4Addr),
251+
KeyArpTip(Ipv4Addr),
252+
KeyArpTipMask(Ipv4Addr),
268253
KeyArpOp(arp::Operation),
269-
KeyArpOpMask(arp::OperationMask),
270-
KeyArpSha(arp::Sha),
271-
KeyArpShaMask(arp::ShaMask),
272-
KeyArpTha(arp::Tha),
273-
KeyArpThaMask(arp::ThaMask),
274-
KeyMplsTtl(mpls::MplsTtl),
254+
KeyArpOpMask(u8),
255+
KeyArpSha(ethernet::Mac),
256+
KeyArpShaMask(ethernet::Mac),
257+
KeyArpTha(ethernet::Mac),
258+
KeyArpThaMask(ethernet::Mac),
259+
KeyMplsTtl(u8),
275260
KeyMplsBos(mpls::BottomOfStack),
276-
KeyMplsTc(mpls::TrafficClass),
261+
KeyMplsTc(u8),
277262
KeyMplsLabel(mpls::Label),
278263
KeyTcpFlags(TcpFlags),
279-
KeyTcpFlagsMask(TcpFlagsMask),
280-
KeyIpTos(IpTos),
281-
KeyIpTosMask(IpTos),
282-
KeyIpTtl(IpTtl),
283-
KeyIpTtlMask(IpTtlMask),
264+
KeyTcpFlagsMask(u8),
265+
KeyIpTos(u8),
266+
KeyIpTosMask(u8),
267+
KeyIpTtl(u8),
268+
KeyIpTtlMask(u8),
284269
KeyCvlanId(ethernet::VlanId),
285270
KeyCvlanPrio(ethernet::VlanPrio),
286271
KeyCvlanEthType(ethernet::Ethertype),
287-
KeyEncIpTos(IpTos),
288-
KeyEncIpTosMask(IpTosMask),
289-
KeyEncIpTtl(IpTtl),
290-
KeyEncIpTtlMask(IpTtlMask),
291-
KeyEncOpts(EncOpts),
292-
KeyEncOptsMask(EncOpts),
293-
KeyPortSrcMin(AbstractPort),
294-
KeyPortSrcMax(AbstractPort),
295-
KeyPortDstMin(AbstractPort),
296-
KeyPortDstMax(AbstractPort),
272+
KeyEncIpTos(u8),
273+
KeyEncIpTosMask(u8),
274+
KeyEncIpTtl(u8),
275+
KeyEncIpTtlMask(u8),
276+
KeyEncOpts(encap::Options),
277+
KeyEncOptsMask(encap::Options),
278+
KeyPortSrcMin(u16),
279+
KeyPortSrcMax(u16),
280+
KeyPortDstMin(u16),
281+
KeyPortDstMax(u16),
297282
KeyCtState(ConnectionTrackingFlags),
298283
KeyCtStateMask(ConnectionTrackingFlags),
299-
KeyCtZone(ConnectionTrackingZone),
300-
KeyCtZoneMask(ConnectionTrackingZone),
301-
KeyCtMark(ConnectionTrackingMark),
302-
KeyCtMarkMask(ConnectionTrackingMark),
303-
KeyCtLabels(ConnectionTrackingLabel),
304-
KeyCtLabelsMask(ConnectionTrackingLabel),
284+
KeyCtZone(u16),
285+
KeyCtZoneMask(u16),
286+
KeyCtMark(u32),
287+
KeyCtMarkMask(u32),
288+
KeyCtLabels(u128),
289+
KeyCtLabelsMask(u128),
305290
KeyMplsOpts(mpls::Options),
306291
KeyHash(u32),
307292
KeyHashMask(u32),
308293
KeyNumOfVlans(u8),
309-
KeyPppoeSid(PppoeSid),
310-
KeyPppProto(PppProtocol),
311-
KeyL2tpv3Sid(L2tpV3Sid),
294+
KeyPppoeSid(u16),
295+
KeyPppProto(u16),
296+
KeyL2tpv3Sid(u32),
312297
L2Miss(L2Miss),
313298
KeyCfm(Vec<CfmAttribute>),
314-
KeySpi(Spi),
315-
KeySpiMask(SpiMask),
299+
KeySpi(u32),
300+
KeySpiMask(u32),
316301
InHwCount(u32),
317302
}
318303

@@ -1007,7 +992,8 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
1007992
}
1008993
let id = NativeEndian::read_u16(payload);
1009994
Self::KeyVlanId(
1010-
ethernet::VlanId::try_new(id).context("failed to parse vlan id")?,
995+
ethernet::VlanId::try_new(id)
996+
.context("failed to parse vlan id")?,
1011997
)
1012998
}
1013999
TCA_FLOWER_KEY_VLAN_PRIO => {
@@ -1460,7 +1446,8 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
14601446
}
14611447
let id = NativeEndian::read_u16(payload);
14621448
Self::KeyCvlanId(
1463-
ethernet::VlanId::try_new(id).context("failed to parse cvlan id")?,
1449+
ethernet::VlanId::try_new(id)
1450+
.context("failed to parse cvlan id")?,
14641451
)
14651452
}
14661453
TCA_FLOWER_KEY_CVLAN_PRIO => {
@@ -1514,9 +1501,11 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
15141501
}
15151502
Self::KeyEncIpTtlMask(payload[0])
15161503
}
1517-
TCA_FLOWER_KEY_ENC_OPTS => Self::KeyEncOpts(EncOpts::parse(buf)?),
1504+
TCA_FLOWER_KEY_ENC_OPTS => {
1505+
Self::KeyEncOpts(encap::Options::parse(buf)?)
1506+
}
15181507
TCA_FLOWER_KEY_ENC_OPTS_MASK => {
1519-
Self::KeyEncOptsMask(EncOpts::parse(buf)?)
1508+
Self::KeyEncOptsMask(encap::Options::parse(buf)?)
15201509
}
15211510
TCA_FLOWER_IN_HW_COUNT => Self::InHwCount(
15221511
parse_u32(payload)
@@ -1635,10 +1624,6 @@ bitflags! {
16351624
}
16361625
}
16371626

1638-
type ConnectionTrackingZone = u16;
1639-
type ConnectionTrackingMark = u32;
1640-
type ConnectionTrackingLabel = u128;
1641-
16421627
fn parse_u128_be(slice: &[u8]) -> Result<u128, DecodeError> {
16431628
if slice.len() != 16 {
16441629
return Err(DecodeError::from("invalid u128 length"));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ impl ErspanHwid {
221221

222222
#[derive(Debug, PartialEq, Eq, Clone)]
223223
#[non_exhaustive]
224-
pub enum EncOpts {
224+
pub enum Options {
225225
Ver(Version),
226226
Index(Index),
227227
Direction(Direction),
228228
Hwid(ErspanHwid),
229229
Other(DefaultNla),
230230
}
231231

232-
impl Nla for EncOpts {
232+
impl Nla for Options {
233233
fn value_len(&self) -> usize {
234234
match self {
235235
Self::Ver(v) => v.value_len(),
@@ -262,7 +262,7 @@ impl Nla for EncOpts {
262262
}
263263

264264
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
265-
for EncOpts
265+
for Options
266266
{
267267
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
268268
Ok(match buf.kind() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA: u16 = 3; /* 4 to 128 bytes */
99

1010
#[derive(Debug, PartialEq, Eq, Clone)]
1111
#[non_exhaustive]
12-
pub enum EncOpts {
12+
pub enum Options {
1313
Class(Class),
1414
Type(Type),
1515
Data(Data),
@@ -20,7 +20,7 @@ pub enum EncOpts {
2020
pub struct Class(u16);
2121

2222
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
23-
for EncOpts
23+
for Options
2424
{
2525
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
2626
Ok(match buf.kind() {
@@ -167,7 +167,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Data {
167167
}
168168
}
169169

170-
impl Nla for EncOpts {
170+
impl Nla for Options {
171171
fn value_len(&self) -> usize {
172172
match self {
173173
Self::Class(c) => c.value_len(),

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,49 @@ const TCA_FLOWER_KEY_ENC_OPT_GTP_QFI: u16 = 2; /* u8 */
1616

1717
#[derive(Debug, PartialEq, Eq, Clone)]
1818
#[non_exhaustive]
19-
pub enum EncOpts {
19+
pub enum Options {
2020
PduType(u8),
2121
Qfi(u8),
2222
Other(DefaultNla),
2323
}
2424

25-
impl Nla for EncOpts {
25+
impl Nla for Options {
2626
fn value_len(&self) -> usize {
2727
1
2828
}
2929

3030
fn kind(&self) -> u16 {
3131
match self {
32-
EncOpts::PduType(_) => TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE,
33-
EncOpts::Qfi(_) => TCA_FLOWER_KEY_ENC_OPT_GTP_QFI,
34-
EncOpts::Other(nla) => nla.kind(),
32+
Options::PduType(_) => TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE,
33+
Options::Qfi(_) => TCA_FLOWER_KEY_ENC_OPT_GTP_QFI,
34+
Options::Other(nla) => nla.kind(),
3535
}
3636
}
3737

3838
fn emit_value(&self, buffer: &mut [u8]) {
3939
match self {
40-
EncOpts::PduType(pdu_type) => {
40+
Options::PduType(pdu_type) => {
4141
buffer[0] = *pdu_type;
4242
}
43-
EncOpts::Qfi(qfi) => {
43+
Options::Qfi(qfi) => {
4444
buffer[0] = *qfi;
4545
}
46-
EncOpts::Other(nla) => nla.emit_value(buffer),
46+
Options::Other(nla) => nla.emit_value(buffer),
4747
}
4848
}
4949
}
5050

51-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for EncOpts {
51+
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Options {
5252
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
5353
let payload = buf.value();
5454
Ok(match buf.kind() {
5555
TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE => {
56-
EncOpts::PduType(parse_u8(payload)?)
56+
Options::PduType(parse_u8(payload)?)
5757
}
5858
TCA_FLOWER_KEY_ENC_OPT_GTP_QFI => {
59-
EncOpts::Qfi(parse_u8(payload)?)
59+
Options::Qfi(parse_u8(payload)?)
6060
}
61-
_ => EncOpts::Other(
61+
_ => Options::Other(
6262
DefaultNla::parse(buf).context("failed to parse gtp nla")?,
6363
),
6464
})

0 commit comments

Comments
 (0)