Skip to content

Commit 81efff2

Browse files
committed
Support tc flower mpls matches
1 parent a206850 commit 81efff2

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/tc/filters/cls_flower.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ pub enum EthType {
149149
Arp = 0x0806,
150150
Vlan = 0x8100,
151151
Qinq = 0x88A8,
152+
MplsUnicast = 0x8847,
153+
MplsMulticast = 0x8848,
152154
Other(u16),
153155
}
154156

@@ -160,6 +162,8 @@ impl EthType {
160162
EthType::Arp => 0x0806,
161163
EthType::Vlan => 0x8100,
162164
EthType::Qinq => 0x88A8,
165+
EthType::MplsUnicast => 0x8847,
166+
EthType::MplsMulticast => 0x8848,
163167
EthType::Other(val) => *val,
164168
}
165169
}
@@ -175,6 +179,8 @@ impl From<u16> for EthType {
175179
0x0800 => Self::IPv4,
176180
0x86DD => Self::IPv6,
177181
0x0806 => Self::Arp,
182+
0x8847 => Self::MplsUnicast,
183+
0x8848 => Self::MplsMulticast,
178184
_ => Self::Other(val),
179185
}
180186
}
@@ -188,6 +194,8 @@ impl From<EthType> for u16 {
188194
EthType::Arp => 0x0806,
189195
EthType::Vlan => 0x8100,
190196
EthType::Qinq => 0x88A8,
197+
EthType::MplsUnicast => 0x8847,
198+
EthType::MplsMulticast => 0x8848,
191199
EthType::Other(val) => val,
192200
}
193201
}
@@ -196,6 +204,10 @@ impl From<EthType> for u16 {
196204
pub type TcpPort = u16;
197205
pub type UdpPort = u16;
198206
pub type SctpPort = u16;
207+
pub type MplsTtl = u8;
208+
pub type MplsBos = u8;
209+
pub type MplsTc = u8;
210+
pub type MplsLabel = u32;
199211

200212
// Lists sourced from https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml
201213
pub mod icmpv4 {
@@ -1333,6 +1345,10 @@ pub enum TcFilterFlowerOption {
13331345
KeyArpShaMask(arp::ShaMask),
13341346
KeyArpTha(arp::Tha),
13351347
KeyArpThaMask(arp::ThaMask),
1348+
KeyMplsTtl(MplsTtl),
1349+
KeyMplsBos(MplsBos),
1350+
KeyMplsTc(MplsTc),
1351+
KeyMplsLabel(MplsLabel),
13361352
}
13371353

13381354
impl Nla for TcFilterFlowerOption {
@@ -1402,6 +1418,10 @@ impl Nla for TcFilterFlowerOption {
14021418
Self::KeyArpShaMask(_) => 6,
14031419
Self::KeyArpTha(_) => 6,
14041420
Self::KeyArpThaMask(_) => 6,
1421+
Self::KeyMplsTtl(_) => 1,
1422+
Self::KeyMplsBos(_) => 1,
1423+
Self::KeyMplsTc(_) => 1,
1424+
Self::KeyMplsLabel(_) => 4,
14051425
Self::Other(attr) => attr.value_len(),
14061426
}
14071427
}
@@ -1476,6 +1496,10 @@ impl Nla for TcFilterFlowerOption {
14761496
Self::KeyArpShaMask(_) => TCA_FLOWER_KEY_ARP_SHA_MASK,
14771497
Self::KeyArpTha(_) => TCA_FLOWER_KEY_ARP_THA,
14781498
Self::KeyArpThaMask(_) => TCA_FLOWER_KEY_ARP_THA_MASK,
1499+
Self::KeyMplsTtl(_) => TCA_FLOWER_KEY_MPLS_TTL,
1500+
Self::KeyMplsBos(_) => TCA_FLOWER_KEY_MPLS_BOS,
1501+
Self::KeyMplsTc(_) => TCA_FLOWER_KEY_MPLS_TC,
1502+
Self::KeyMplsLabel(_) => TCA_FLOWER_KEY_MPLS_LABEL,
14791503
Self::Other(attr) => attr.kind(),
14801504
}
14811505
}
@@ -1607,6 +1631,20 @@ impl Nla for TcFilterFlowerOption {
16071631
Self::KeyArpShaMask(k) => buffer.copy_from_slice(k.as_slice()),
16081632
Self::KeyArpTha(k) => buffer.copy_from_slice(k.as_slice()),
16091633
Self::KeyArpThaMask(k) => buffer.copy_from_slice(k.as_slice()),
1634+
Self::KeyMplsTtl(ttl) => {
1635+
buffer.copy_from_slice(ttl.to_be_bytes().as_slice())
1636+
}
1637+
Self::KeyMplsBos(bos) => {
1638+
buffer.copy_from_slice(bos.to_be_bytes().as_slice())
1639+
}
1640+
Self::KeyMplsTc(tc) => {
1641+
buffer.copy_from_slice(tc.to_be_bytes().as_slice())
1642+
}
1643+
Self::KeyMplsLabel(label) => {
1644+
// TODO: I don't know why the yaml says this should be big endian
1645+
// but nothing works unless it's native endian. Bug report?
1646+
buffer.copy_from_slice(label.to_ne_bytes().as_slice())
1647+
}
16101648
Self::Other(attr) => attr.emit_value(buffer),
16111649
}
16121650
}
@@ -2167,6 +2205,31 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
21672205
Err(e) => return Err(e),
21682206
}
21692207
}
2208+
TCA_FLOWER_KEY_MPLS_TTL => {
2209+
if payload.len() != 1 {
2210+
return Err(DecodeError::from("invalid mpls ttl length"));
2211+
}
2212+
Self::KeyMplsTtl(payload[0])
2213+
}
2214+
TCA_FLOWER_KEY_MPLS_BOS => {
2215+
if payload.len() != 1 {
2216+
return Err(DecodeError::from("invalid mpls bos length"));
2217+
}
2218+
Self::KeyMplsBos(payload[0])
2219+
}
2220+
TCA_FLOWER_KEY_MPLS_TC => {
2221+
if payload.len() != 1 {
2222+
return Err(DecodeError::from("invalid mpls tc length"));
2223+
}
2224+
Self::KeyMplsTc(payload[0])
2225+
}
2226+
TCA_FLOWER_KEY_MPLS_LABEL => {
2227+
if payload.len() != 4 {
2228+
return Err(DecodeError::from("invalid mpls label length"));
2229+
}
2230+
let label = BigEndian::read_u32(payload);
2231+
Self::KeyMplsLabel(label)
2232+
}
21702233
_ => Self::Other(
21712234
DefaultNla::parse(buf).context("failed to parse flower nla")?,
21722235
),

0 commit comments

Comments
 (0)