net: we really need some proper blocking queue primitives

This commit is contained in:
K. Lange 2021-06-14 20:13:14 +09:00
parent 222c39bc6b
commit 23e1b8811e
4 changed files with 8 additions and 17 deletions

View File

@ -28,6 +28,6 @@ typedef struct SockData {
} sock_t;
void net_sock_alert(sock_t * sock);
void net_sock_add(sock_t * sock, void * frame);
void net_sock_add(sock_t * sock, void * frame, size_t size);
void * net_sock_get(sock_t * sock);
sock_t * net_sock_create(void);

View File

@ -22,7 +22,6 @@ struct ethernet_packet {
extern spin_lock_t net_raw_sockets_lock;
extern list_t * net_raw_sockets_list;
extern void net_sock_add(sock_t * sock, void * frame);
extern void net_ipv4_handle(void * packet, fs_node_t * nic);
extern void net_arp_handle(void * packet, fs_node_t * nic);
@ -31,7 +30,7 @@ void net_eth_handle(struct ethernet_packet * frame, fs_node_t * nic) {
foreach(node, net_raw_sockets_list) {
sock_t * sock = node->value;
if (!sock->_fnode.device || sock->_fnode.device == nic) {
net_sock_add(sock, frame);
net_sock_add(sock, frame, 8092);
}
}
spin_unlock(net_raw_sockets_lock);

View File

@ -194,8 +194,6 @@ static void icmp_handle(struct ipv4_packet * packet, const char * src, const cha
}
}
extern void net_sock_add(sock_t * sock, void * frame);
static hashmap_t * udp_sockets = NULL;
static hashmap_t * tcp_sockets = NULL;
@ -257,9 +255,7 @@ static void tcp_ack(fs_node_t * nic, sock_t * sock, struct ipv4_packet * packet)
net_eth_send((struct EthernetDevice*)nic->device, ntohs(response->length), response, ETHERNET_TYPE_IPV4, ETHERNET_BROADCAST_MAC);
void * tmp = malloc(ntohs(packet->length));
memcpy(tmp, packet, ntohs(packet->length));
net_sock_add(sock, tmp);
net_sock_add(sock, packet, ntohs(packet->length));
}
void net_ipv4_handle(struct ipv4_packet * packet, fs_node_t * nic) {
@ -279,10 +275,8 @@ void net_ipv4_handle(struct ipv4_packet * packet, fs_node_t * nic) {
printf("net: ipv4: %s: %s -> %s udp %d to %d\n", nic->name, src, dest, ntohs(((uint16_t*)&packet->payload)[0]), dest_port);
if (udp_sockets && hashmap_has(udp_sockets, (void*)(uintptr_t)dest_port)) {
printf("net: udp: received and have a waiting endpoint!\n");
void * tmp = malloc(ntohs(packet->length));
memcpy(tmp, packet, ntohs(packet->length));
sock_t * sock = hashmap_get(udp_sockets, (void*)(uintptr_t)dest_port);
net_sock_add(sock, tmp);
net_sock_add(sock, packet, ntohs(packet->length));
}
break;
}
@ -302,9 +296,7 @@ void net_ipv4_handle(struct ipv4_packet * packet, fs_node_t * nic) {
tcp_ack(nic, sock, packet);
}
} else if (sock->priv[1] == 2) {
void * tmp = malloc(ntohs(packet->length));
memcpy(tmp, packet, ntohs(packet->length));
net_sock_add(sock, tmp);
net_sock_add(sock, packet, ntohs(packet->length));
}
}
break;

View File

@ -40,10 +40,10 @@ void net_sock_alert(sock_t * sock) {
spin_unlock(sock->alert_lock);
}
void net_sock_add(sock_t * sock, void * frame) {
void net_sock_add(sock_t * sock, void * frame, size_t size) {
spin_lock(sock->rx_lock);
char * bleh = malloc(8092);
memcpy(bleh, frame, 8092);
char * bleh = malloc(size);
memcpy(bleh, frame, size);
list_insert(sock->rx_queue, bleh);
wakeup_queue(sock->rx_wait);
net_sock_alert(sock);