@@ -210,6 +210,23 @@ pub type MplsTtl = u8;
210
210
pub type MplsBos = u8 ;
211
211
pub type MplsTc = u8 ;
212
212
pub type MplsLabel = u32 ;
213
+ pub type TcpFlagsMask = u8 ;
214
+
215
+ bitflags ! {
216
+ // TcpFlags _ARE_ exactly 8 bits.
217
+ // Why flower uses a 16-bit field is a mystery, but we deal with it.
218
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
219
+ pub struct TcpFlags : u8 {
220
+ const Cwr = 1 << 0 ;
221
+ const Ece = 1 << 1 ;
222
+ const Urg = 1 << 2 ;
223
+ const Ack = 1 << 3 ;
224
+ const Psh = 1 << 4 ;
225
+ const Rst = 1 << 5 ;
226
+ const Syn = 1 << 6 ;
227
+ const Fin = 1 << 7 ;
228
+ }
229
+ }
213
230
214
231
// Lists sourced from https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml
215
232
pub mod icmpv4 {
@@ -1351,6 +1368,8 @@ pub enum TcFilterFlowerOption {
1351
1368
KeyMplsBos ( MplsBos ) ,
1352
1369
KeyMplsTc ( MplsTc ) ,
1353
1370
KeyMplsLabel ( MplsLabel ) ,
1371
+ KeyTcpFlags ( TcpFlags ) ,
1372
+ KeyTcpFlagsMask ( TcpFlagsMask ) ,
1354
1373
}
1355
1374
1356
1375
impl Nla for TcFilterFlowerOption {
@@ -1424,6 +1443,8 @@ impl Nla for TcFilterFlowerOption {
1424
1443
Self :: KeyMplsBos ( _) => 1 ,
1425
1444
Self :: KeyMplsTc ( _) => 1 ,
1426
1445
Self :: KeyMplsLabel ( _) => 4 ,
1446
+ Self :: KeyTcpFlags ( _) => 2 ,
1447
+ Self :: KeyTcpFlagsMask ( _) => 2 ,
1427
1448
Self :: Other ( attr) => attr. value_len ( ) ,
1428
1449
}
1429
1450
}
@@ -1502,6 +1523,8 @@ impl Nla for TcFilterFlowerOption {
1502
1523
Self :: KeyMplsBos ( _) => TCA_FLOWER_KEY_MPLS_BOS ,
1503
1524
Self :: KeyMplsTc ( _) => TCA_FLOWER_KEY_MPLS_TC ,
1504
1525
Self :: KeyMplsLabel ( _) => TCA_FLOWER_KEY_MPLS_LABEL ,
1526
+ Self :: KeyTcpFlags ( _) => TCA_FLOWER_KEY_TCP_FLAGS ,
1527
+ Self :: KeyTcpFlagsMask ( _) => TCA_FLOWER_KEY_TCP_FLAGS_MASK ,
1505
1528
Self :: Other ( attr) => attr. kind ( ) ,
1506
1529
}
1507
1530
}
@@ -1519,7 +1542,7 @@ impl Nla for TcFilterFlowerOption {
1519
1542
buffer. copy_from_slice ( eth_type. as_be_bytes ( ) . as_slice ( ) )
1520
1543
}
1521
1544
Self :: KeyIpProto ( proto) => {
1522
- buffer. copy_from_slice ( & [ ( i32:: from ( * proto) as u8 ) ] )
1545
+ buffer. copy_from_slice ( & [ i32:: from ( * proto) as u8 ] )
1523
1546
}
1524
1547
Self :: KeyIpv4Src ( ip) => buffer. copy_from_slice ( & ip. octets ( ) ) ,
1525
1548
Self :: KeyIpv4SrcMask ( ip) => buffer. copy_from_slice ( & ip. octets ( ) ) ,
@@ -1647,6 +1670,12 @@ impl Nla for TcFilterFlowerOption {
1647
1670
// but nothing works unless it's native endian. Bug report?
1648
1671
buffer. copy_from_slice ( label. to_ne_bytes ( ) . as_slice ( ) )
1649
1672
}
1673
+ Self :: KeyTcpFlags ( flags) => buffer. copy_from_slice (
1674
+ ( flags. bits ( ) as u16 ) . to_be_bytes ( ) . as_slice ( ) ,
1675
+ ) ,
1676
+ Self :: KeyTcpFlagsMask ( flags) => {
1677
+ buffer. copy_from_slice ( ( * flags as u16 ) . to_be_bytes ( ) . as_slice ( ) )
1678
+ }
1650
1679
Self :: Other ( attr) => attr. emit_value ( buffer) ,
1651
1680
}
1652
1681
}
@@ -2232,6 +2261,22 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
2232
2261
let label = BigEndian :: read_u32 ( payload) ;
2233
2262
Self :: KeyMplsLabel ( label)
2234
2263
}
2264
+ TCA_FLOWER_KEY_TCP_FLAGS => {
2265
+ if payload. len ( ) != 2 {
2266
+ return Err ( DecodeError :: from ( "invalid tcp flags length" ) ) ;
2267
+ }
2268
+ let flags = BigEndian :: read_u16 ( payload) ;
2269
+ Self :: KeyTcpFlags ( TcpFlags :: from_bits_retain ( flags as u8 ) )
2270
+ }
2271
+ TCA_FLOWER_KEY_TCP_FLAGS_MASK => {
2272
+ if payload. len ( ) != 2 {
2273
+ return Err ( DecodeError :: from (
2274
+ "invalid tcp flags mask length" ,
2275
+ ) ) ;
2276
+ }
2277
+ let flags = BigEndian :: read_u16 ( payload) ;
2278
+ Self :: KeyTcpFlagsMask ( flags as u8 )
2279
+ }
2235
2280
_ => Self :: Other (
2236
2281
DefaultNla :: parse ( buf) . context ( "failed to parse flower nla" ) ?,
2237
2282
) ,
0 commit comments