tcp: initial implementation

This commit is contained in:
Matheus
2024-06-03 22:02:58 -03:00
parent 7053ed68af
commit 7cad8f53f2
7 changed files with 1729 additions and 53 deletions
+1 -2
View File
@@ -8,7 +8,7 @@ Astral is a 64 bit operating system with its own kernel written in C for the x86
## Features
- SMP capable preemptible kernel
- Networking (UDP, DHCP)
- Networking (TCP, UDP, DHCP)
- POSIX compatibility
- Ports: X.org, fvwm3, gcc, bash, quake, vim and more
- Filesystems: tmpfs, devfs, ext2
@@ -17,7 +17,6 @@ Astral is a 64 bit operating system with its own kernel written in C for the x86
## Current Goals
- TCP
- Fat32
## Building
+1
View File
@@ -83,6 +83,7 @@ void kernel_entry() {
arp_init();
ipv4_init();
udp_init();
tcp_init();
block_init();
pseudodevices_init();
+3
View File
@@ -49,6 +49,7 @@ typedef struct {
#define SOCKET_TYPE_UDP 0
#define SOCKET_TYPE_LOCAL 1
#define SOCKET_TYPE_TCP 2
#define SOCKFS_SOCKET_FROM_NODE(nodep) (((socketnode_t *)(nodep))->socket)
static inline int sock_convertaddress(sockaddr_t *sockaddr, abisockaddr_t *abisockaddr) {
@@ -72,6 +73,7 @@ static inline int sock_convertaddress(sockaddr_t *sockaddr, abisockaddr_t *abiso
static inline int sock_addrtoabiaddr(int socktype, sockaddr_t *sockaddr, abisockaddr_t *abisockaddr) {
switch (socktype) {
case SOCKET_TYPE_UDP:
case SOCKET_TYPE_TCP:
inaddr_t *inaddr = (inaddr_t *)abisockaddr;
inaddr->sin_addr = cpu_to_be_d(sockaddr->ipv4addr.addr);
inaddr->sin_port = cpu_to_be_w(sockaddr->ipv4addr.port);
@@ -117,6 +119,7 @@ static inline void sock_freemsghdr(msghdr_t *hdr) {
void localsock_leavebinding(vnode_t *vnode);
socket_t *localsock_createsocket();
socket_t *udp_createsocket();
socket_t *tcp_createsocket();
socket_t *socket_create(int type);
int sockfs_newsocket(vnode_t **vnodep, socket_t *socket);
void sockfs_init();
+20 -2
View File
@@ -127,6 +127,7 @@ void ipv4_process(netdev_t *netdev, void *buff) {
ipv4frame_t *frame = buff;
if (checksum(frame, sizeof(ipv4frame_t)) != 0) {
printf("ipv4: bad checksum\n");
return;
}
@@ -135,7 +136,7 @@ void ipv4_process(netdev_t *netdev, void *buff) {
uint16_t flagsfrag = be_to_cpu_w(frame->flags_fragoffset);
if ((GET_FLAGS(flagsfrag) & FLAG_MF) || (GET_FRAGOFFSET(flagsfrag) > 0)) {
printf("ipv4: reassembly not yet supported\n");
printf("ipv4: reassembly not yet supported!\n");
return;
}
@@ -151,9 +152,26 @@ void ipv4_process(netdev_t *netdev, void *buff) {
case IPV4_PROTO_UDP:
udp_process(netdev, nextbuff, srcip);
break;
case IPV4_PROTO_TCP:
tcp_process(netdev, nextbuff, frame);
break;
}
}
return;
size_t ipv4_getmtu(uint32_t ip) {
routingentry_t entry = getroute(ip);
if (entry.netdev == NULL)
return 0;
return entry.netdev->mtu;
}
uint32_t ipv4_getnetdevip(uint32_t ip) {
routingentry_t entry = getroute(ip);
if (entry.netdev == NULL)
return 0;
return entry.netdev->ip;
}
int ipv4_sendpacket(void *buffer, size_t packetsize, uint32_t ip, int proto, netdev_t *broadcastdev) {
+2 -2
View File
@@ -3,10 +3,10 @@
static socket_t *(*createsocket[])() = {
udp_createsocket,
localsock_createsocket
localsock_createsocket,
tcp_createsocket
};
socket_t *socket_create(int type) {
__assert(type < sizeof(createsocket) / sizeof(createsocket[0]));
socket_t *socket = createsocket[type]();
+1693 -39
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -544,6 +544,7 @@ static void yield(context_t *context, void *) {
}
int sched_yield() {
__assert(_cpu()->ipl == IPL_NORMAL);
bool sleeping = _cpu()->thread->flags & SCHED_THREAD_FLAGS_SLEEP;
bool old = sleeping ? _cpu()->thread->sleepintstatus : interrupt_set(false);
arch_context_saveandcall(yield, _cpu()->schedulerstack, NULL);