Skip to content

Commit 018b25d

Browse files
committed
mctp-linux: Add MctpLinuxListener::new_with_eid
and MctpLinuxAsyncListener::new_with_eid This binds to a local EID rather than MCTP_ADDR_ANY. Signed-off-by: Matt Johnston <[email protected]>
1 parent d8385ad commit 018b25d

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

mctp-linux/src/lib.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,24 @@ impl MctpLinuxListener {
547547
/// This will listen for MCTP message type `typ`, on an optional
548548
/// Linux network `net`. `None` network defaults to `MCTP_NET_ANY`.
549549
pub fn new(typ: MsgType, net: Option<u32>) -> Result<Self> {
550+
Self::new_with_eid(typ, MCTP_ADDR_ANY, net)
551+
}
552+
553+
/// Create a new `MctpLinuxListener` bound to a local address.
554+
///
555+
/// This will listen for MCTP message type `typ`, on an optional
556+
/// Linux network `net`. `None` network defaults to `MCTP_NET_ANY`.
557+
/// The listener will be bound to `local_addr`.
558+
pub fn new_with_eid(
559+
typ: MsgType,
560+
local_addr: Eid,
561+
net: Option<u32>,
562+
) -> Result<Self> {
550563
let sock = MctpSocket::new()?;
551564
// Linux requires MCTP_ADDR_ANY for binds.
552565
let net = net.unwrap_or(MCTP_NET_ANY);
553-
let addr = MctpSockAddr::new(
554-
MCTP_ADDR_ANY.0,
555-
net,
556-
typ.0,
557-
mctp::MCTP_TAG_OWNER,
558-
);
566+
let addr =
567+
MctpSockAddr::new(local_addr.0, net, typ.0, mctp::MCTP_TAG_OWNER);
559568
sock.bind(&addr)?;
560569
Ok(Self { sock, net, typ })
561570
}
@@ -617,15 +626,24 @@ impl MctpLinuxAsyncListener {
617626
/// This will listen for MCTP message type `typ`, on an optional
618627
/// Linux network `net`. `None` network defaults to `MCTP_NET_ANY`.
619628
pub fn new(typ: MsgType, net: Option<u32>) -> Result<Self> {
629+
Self::new_with_eid(typ, MCTP_ADDR_ANY, net)
630+
}
631+
632+
/// Create a new `MctpLinuxAsyncListener` bound to a local address.
633+
///
634+
/// This will listen for MCTP message type `typ`, on an optional
635+
/// Linux network `net`. `None` network defaults to `MCTP_NET_ANY`.
636+
/// The listener will be bound to `local_addr`.
637+
pub fn new_with_eid(
638+
typ: MsgType,
639+
local_addr: Eid,
640+
net: Option<u32>,
641+
) -> Result<Self> {
620642
let sock = MctpSocketAsync::new()?;
621643
// Linux requires MCTP_ADDR_ANY for binds.
622644
let net = net.unwrap_or(MCTP_NET_ANY);
623-
let addr = MctpSockAddr::new(
624-
MCTP_ADDR_ANY.0,
625-
net,
626-
typ.0,
627-
mctp::MCTP_TAG_OWNER,
628-
);
645+
let addr =
646+
MctpSockAddr::new(local_addr.0, net, typ.0, mctp::MCTP_TAG_OWNER);
629647
sock.bind(&addr)?;
630648
Ok(Self { sock, net, typ })
631649
}

0 commit comments

Comments
 (0)