endpoint.rs 1.0 KB

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