endpoint.rs 955 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use crate::{filesystem::vfs::InodeId, net::socket};
  2. use alloc::{string::String, sync::Arc};
  3. pub use smoltcp::wire::IpEndpoint;
  4. #[derive(Debug, Clone)]
  5. pub enum Endpoint {
  6. /// 链路层端点
  7. LinkLayer(LinkLayerEndpoint),
  8. /// 网络层端点
  9. Ip(IpEndpoint),
  10. /// inode端点,Unix实际保存的端点
  11. Inode((Arc<socket::Inode>, String)),
  12. /// Unix传递id索引和path所用的端点
  13. Unixpath((InodeId, String)),
  14. }
  15. /// @brief 链路层端点
  16. #[derive(Debug, Clone)]
  17. pub struct LinkLayerEndpoint {
  18. /// 网卡的接口号
  19. pub interface: usize,
  20. }
  21. impl LinkLayerEndpoint {
  22. /// @brief 创建一个链路层端点
  23. ///
  24. /// @param interface 网卡的接口号
  25. ///
  26. /// @return 返回创建的链路层端点
  27. pub fn new(interface: usize) -> Self {
  28. Self { interface }
  29. }
  30. }
  31. impl From<IpEndpoint> for Endpoint {
  32. fn from(endpoint: IpEndpoint) -> Self {
  33. Self::Ip(endpoint)
  34. }
  35. }