Skip to content

Commit dbd13ce

Browse files
committed
feat(net): extend metadata with PortIndex
* remove unused deprecated types * define new type PortIndex for the purpose of identifying ports generically in a driver-agnostic way. Drivers should be able to build and understand the PortIndex type, and map it to driver-specific types/entities. This type should be opaque and not be used, except by ingress/egress for translation purposes. * Add iport/oport PortIndex in metatdata so that the translation from PortIndex - InterfaceIndex can be done at egress/ingress, based on the configuration. We refrain from making such a translation in drivers for the moment, because that would require drivers have access to a translation table that may change depending on the configuration. This commit does not add any new functionality. Signed-off-by: Fredi Raspall <[email protected]>
1 parent fc55273 commit dbd13ce

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

net/src/packet/display.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::udp::{Udp, UdpEncap};
1515
use crate::buffer::PacketBufferMut;
1616
use crate::checksum::Checksum;
1717
#[allow(deprecated)]
18-
use crate::packet::InterfaceId;
1918
use crate::packet::{BridgeDomain, DoneReason, InvalidPacket, Packet, PacketMeta};
2019
use std::fmt::{Display, Formatter};
2120

@@ -223,12 +222,6 @@ fn fmt_opt<T: Display>(
223222
}
224223
}
225224
}
226-
#[allow(deprecated)]
227-
impl Display for InterfaceId {
228-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
229-
write!(f, "{}", self.get_id())
230-
}
231-
}
232225
impl Display for BridgeDomain {
233226
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
234227
write!(f, "{}", self.get_id())
@@ -237,15 +230,11 @@ impl Display for BridgeDomain {
237230
impl Display for PacketMeta {
238231
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
239232
writeln!(f, " metadata:")?;
240-
match self.iif {
241-
None => {
242-
write!(f, " iif: None")?;
243-
}
244-
Some(iif) => {
245-
write!(f, " iif: {iif}")?;
246-
}
247-
}
248-
fmt_opt(f, " oif", self.oif, true)?;
233+
write!(f, " ")?;
234+
fmt_opt(f, " iport", self.iport, false)?;
235+
fmt_opt(f, " iif", self.iif, false)?;
236+
fmt_opt(f, " oif", self.oif, false)?;
237+
fmt_opt(f, " oport", self.oport, true)?;
249238

250239
writeln!(f, " bcast: {}", self.is_l2bcast())?;
251240
fmt_opt(f, " src-vpcd", self.src_vpcd, false)?;

net/src/packet/meta.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ use tracing::error;
1717
/// Every VRF is univocally identified with a numerical VRF id
1818
pub type VrfId = u32;
1919

20-
#[deprecated = "use InterfaceIndex from net"]
21-
#[derive(Debug, Default, Copy, Clone)]
22-
pub struct InterfaceId(u32);
23-
#[allow(deprecated)]
24-
impl InterfaceId {
20+
/// A driver-agnostic, opaque identifier for a port. This type
21+
/// should only be read / written by drivers and ingress / egress stages.
22+
#[derive(Clone, Copy, Debug, PartialEq, Hash, Eq)]
23+
#[repr(transparent)]
24+
pub struct PortIndex(u16);
25+
impl PortIndex {
2526
#[must_use]
26-
pub fn new(val: u32) -> Self {
27-
Self(val)
27+
pub const fn new(value: u16) -> Self {
28+
Self(value)
2829
}
29-
#[must_use]
30-
pub fn get_id(&self) -> u32 {
31-
self.0
30+
}
31+
impl Display for PortIndex {
32+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33+
write!(f, "{}", self.0)
3234
}
3335
}
3436

@@ -133,10 +135,12 @@ bitflags! {
133135
#[derive(Debug, Default, Clone)]
134136
pub struct PacketMeta {
135137
flags: MetaFlags,
136-
pub iif: Option<InterfaceIndex>, /* incoming interface - set early */
137-
pub oif: Option<InterfaceIndex>, /* outgoing interface - set late */
138-
pub nh_addr: Option<IpAddr>, /* IP address of next-hop */
139-
pub vrf: Option<VrfId>, /* for IP packet, the VRF to use to route it */
138+
pub iport: Option<PortIndex>, /* ingress port index - set on rx by driver, read by ingress */
139+
pub iif: Option<InterfaceIndex>, /* incoming interface: set by ingress stage */
140+
pub oif: Option<InterfaceIndex>, /* outgoing interface - set by IO manager for outgoing traffic or forwarding functions */
141+
pub oport: Option<PortIndex>, /* egress port index - set by egress stage, read by driver for xmit */
142+
pub nh_addr: Option<IpAddr>, /* IP address of next-hop */
143+
pub vrf: Option<VrfId>, /* for IP packet, the VRF to use to route it */
140144
pub bridge: Option<BridgeDomain>, /* the bridge domain to forward the packet to */
141145
pub done: Option<DoneReason>, /* if Some, the reason why a packet was marked as done, including delivery to NF */
142146
pub src_vpcd: Option<VpcDiscriminant>, /* the vpc discriminant of a received encapsulated packet */

0 commit comments

Comments
 (0)