|
|
@ -4,8 +4,8 @@ use super::*;
|
|
|
|
use crate::drivers::SOCKET_ACTIVITY;
|
|
|
|
use crate::drivers::SOCKET_ACTIVITY;
|
|
|
|
use crate::fs::FileLike;
|
|
|
|
use crate::fs::FileLike;
|
|
|
|
use crate::net::{
|
|
|
|
use crate::net::{
|
|
|
|
Endpoint, LinkLevelEndpoint, PacketSocketState, RawSocketState, Socket, TcpSocketState,
|
|
|
|
Endpoint, LinkLevelEndpoint, NetlinkEndpoint, NetlinkSocketState, PacketSocketState,
|
|
|
|
UdpSocketState, SOCKETS,
|
|
|
|
RawSocketState, Socket, TcpSocketState, UdpSocketState, SOCKETS,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use crate::sync::{MutexGuard, SpinNoIrq, SpinNoIrqLock as Mutex};
|
|
|
|
use crate::sync::{MutexGuard, SpinNoIrq, SpinNoIrqLock as Mutex};
|
|
|
|
use alloc::boxed::Box;
|
|
|
|
use alloc::boxed::Box;
|
|
|
@ -15,24 +15,27 @@ use smoltcp::wire::*;
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_socket(domain: usize, socket_type: usize, protocol: usize) -> SysResult {
|
|
|
|
pub fn sys_socket(domain: usize, socket_type: usize, protocol: usize) -> SysResult {
|
|
|
|
let domain = AddressFamily::from(domain as u16);
|
|
|
|
let domain = AddressFamily::from(domain as u16);
|
|
|
|
|
|
|
|
let socket_type = SocketType::from(socket_type as u8 & SOCK_TYPE_MASK);
|
|
|
|
info!(
|
|
|
|
info!(
|
|
|
|
"socket: domain: {:?}, socket_type: {}, protocol: {}",
|
|
|
|
"socket: domain: {:?}, socket_type: {:?}, protocol: {}",
|
|
|
|
domain, socket_type, protocol
|
|
|
|
domain, socket_type, protocol
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let mut proc = process();
|
|
|
|
let mut proc = process();
|
|
|
|
let socket: Box<dyn Socket> = match domain {
|
|
|
|
let socket: Box<dyn Socket> = match domain {
|
|
|
|
AddressFamily::Internet | AddressFamily::Unix => {
|
|
|
|
AddressFamily::Internet | AddressFamily::Unix => match socket_type {
|
|
|
|
match SocketType::from(socket_type as u8 & SOCK_TYPE_MASK) {
|
|
|
|
SocketType::Stream => Box::new(TcpSocketState::new()),
|
|
|
|
SocketType::Stream => Box::new(TcpSocketState::new()),
|
|
|
|
SocketType::Datagram => Box::new(UdpSocketState::new()),
|
|
|
|
SocketType::Datagram => Box::new(UdpSocketState::new()),
|
|
|
|
SocketType::Raw => Box::new(RawSocketState::new(protocol as u8)),
|
|
|
|
SocketType::Raw => Box::new(RawSocketState::new(protocol as u8)),
|
|
|
|
_ => return Err(SysError::EINVAL),
|
|
|
|
_ => return Err(SysError::EINVAL),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
AddressFamily::Packet => match socket_type {
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressFamily::Packet => match SocketType::from(socket_type as u8 & SOCK_TYPE_MASK) {
|
|
|
|
|
|
|
|
SocketType::Raw => Box::new(PacketSocketState::new()),
|
|
|
|
SocketType::Raw => Box::new(PacketSocketState::new()),
|
|
|
|
_ => return Err(SysError::EINVAL),
|
|
|
|
_ => return Err(SysError::EINVAL),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
AddressFamily::Netlink => match socket_type {
|
|
|
|
|
|
|
|
SocketType::Raw => Box::new(NetlinkSocketState::new()),
|
|
|
|
|
|
|
|
_ => return Err(SysError::EINVAL),
|
|
|
|
|
|
|
|
},
|
|
|
|
_ => return Err(SysError::EAFNOSUPPORT),
|
|
|
|
_ => return Err(SysError::EAFNOSUPPORT),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let fd = proc.get_free_fd();
|
|
|
|
let fd = proc.get_free_fd();
|
|
|
@ -300,11 +303,20 @@ pub struct SockAddrLl {
|
|
|
|
pub sll_addr: [u8; 8],
|
|
|
|
pub sll_addr: [u8; 8],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cancel alignment
|
|
|
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
|
|
|
pub struct SockAddrNl {
|
|
|
|
|
|
|
|
nl_pad: u16,
|
|
|
|
|
|
|
|
nl_pid: u32,
|
|
|
|
|
|
|
|
nl_groups: u32,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub union SockAddrPayload {
|
|
|
|
pub union SockAddrPayload {
|
|
|
|
pub addr_in: SockAddrIn,
|
|
|
|
pub addr_in: SockAddrIn,
|
|
|
|
pub addr_un: SockAddrUn,
|
|
|
|
pub addr_un: SockAddrUn,
|
|
|
|
pub addr_ll: SockAddrLl,
|
|
|
|
pub addr_ll: SockAddrLl,
|
|
|
|
|
|
|
|
pub addr_nl: SockAddrNl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[repr(C)]
|
|
|
@ -373,6 +385,15 @@ fn sockaddr_to_endpoint(
|
|
|
|
(*addr).payload.addr_ll.sll_ifindex as usize,
|
|
|
|
(*addr).payload.addr_ll.sll_ifindex as usize,
|
|
|
|
)))
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressFamily::Netlink => {
|
|
|
|
|
|
|
|
if len < size_of::<u16>() + size_of::<SockAddrNl>() {
|
|
|
|
|
|
|
|
return Err(SysError::EINVAL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Endpoint::Netlink(NetlinkEndpoint::new(
|
|
|
|
|
|
|
|
(*addr).payload.addr_nl.nl_pid,
|
|
|
|
|
|
|
|
(*addr).payload.addr_nl.nl_groups,
|
|
|
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
}
|
|
|
|
_ => Err(SysError::EINVAL),
|
|
|
|
_ => Err(SysError::EINVAL),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -421,6 +442,8 @@ enum_with_unknown! {
|
|
|
|
Unix = 1,
|
|
|
|
Unix = 1,
|
|
|
|
/// Internet IP Protocol
|
|
|
|
/// Internet IP Protocol
|
|
|
|
Internet = 2,
|
|
|
|
Internet = 2,
|
|
|
|
|
|
|
|
/// Netlink
|
|
|
|
|
|
|
|
Netlink = 16,
|
|
|
|
/// Packet family
|
|
|
|
/// Packet family
|
|
|
|
Packet = 17,
|
|
|
|
Packet = 17,
|
|
|
|
}
|
|
|
|
}
|
|
|
|