Merge branch 'strawberry-dev' of git.yelpcorp.com:hackathon/toaruos into strawberry-dev
This commit is contained in:
commit
9ff190a819
@ -377,9 +377,9 @@ static int net_send_ip(struct socket *socket, int proto, void* payload, uint32_t
|
|||||||
.tcp_len = htons(payload_size),
|
.tcp_len = htons(payload_size),
|
||||||
};
|
};
|
||||||
|
|
||||||
fprintf(_atty, "net_send_ip: Payload size: %d\n", payload_size);
|
// fprintf(_atty, "net_send_ip: Payload size: %d\n", payload_size);
|
||||||
struct tcp_header* tcp_hdr = (struct tcp_header*)payload;
|
struct tcp_header* tcp_hdr = (struct tcp_header*)payload;
|
||||||
fprintf(_atty, "net_send_ip: Header len htons: %d\n", TCP_HEADER_LENGTH_FLIPPED(tcp_hdr));
|
// fprintf(_atty, "net_send_ip: Header len htons: %d\n", TCP_HEADER_LENGTH_FLIPPED(tcp_hdr));
|
||||||
size_t orig_payload_size = payload_size - TCP_HEADER_LENGTH_FLIPPED(tcp_hdr);
|
size_t orig_payload_size = payload_size - TCP_HEADER_LENGTH_FLIPPED(tcp_hdr);
|
||||||
|
|
||||||
uint16_t chk = calculate_tcp_checksum(&check_hd, tcp_hdr, tcp_hdr->payload, orig_payload_size);
|
uint16_t chk = calculate_tcp_checksum(&check_hd, tcp_hdr, tcp_hdr->payload, orig_payload_size);
|
||||||
@ -441,51 +441,38 @@ int net_send(struct socket* socket, uint8_t* payload, size_t payload_size, int f
|
|||||||
size_t net_recv(struct socket* socket, uint8_t* buffer, size_t len) {
|
size_t net_recv(struct socket* socket, uint8_t* buffer, size_t len) {
|
||||||
tcpdata_t *tcpdata = NULL;
|
tcpdata_t *tcpdata = NULL;
|
||||||
node_t *node = NULL;
|
node_t *node = NULL;
|
||||||
fprintf(_atty, "net_recv: ENTER\n");
|
|
||||||
spin_lock(socket->packet_queue_lock);
|
spin_lock(socket->packet_queue_lock);
|
||||||
fprintf(_atty, "net_recv: Got lock\n");
|
|
||||||
do {
|
do {
|
||||||
fprintf(_atty, "net_recv: check length: %d\n", socket->packet_queue->length);
|
|
||||||
if (socket->packet_queue->length > 0) {
|
if (socket->packet_queue->length > 0) {
|
||||||
fprintf(_atty, "net_recv: Packet in recv queue\n");
|
|
||||||
node = list_dequeue(socket->packet_queue);
|
node = list_dequeue(socket->packet_queue);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
fprintf(_atty, "net_recv: Aint got nothin, go to sleep son.\n");
|
|
||||||
spin_unlock(socket->packet_queue_lock);
|
spin_unlock(socket->packet_queue_lock);
|
||||||
sleep_on(socket->packet_wait);
|
sleep_on(socket->packet_wait);
|
||||||
spin_lock(socket->packet_queue_lock);
|
spin_lock(socket->packet_queue_lock);
|
||||||
fprintf(_atty, "net_recv: Annnnnnd we're back\n");
|
|
||||||
}
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
fprintf(_atty, "net_recv: About to unlock\n");
|
|
||||||
spin_unlock(socket->packet_queue_lock);
|
spin_unlock(socket->packet_queue_lock);
|
||||||
|
|
||||||
|
|
||||||
tcpdata = node->value;
|
tcpdata = node->value;
|
||||||
|
|
||||||
fprintf(_atty, "net_recv: Got packet with len: %d\n", tcpdata->payload_size);
|
|
||||||
|
|
||||||
if (tcpdata->payload != 0) {
|
if (tcpdata->payload != 0) {
|
||||||
memcpy(buffer, tcpdata->payload, len < tcpdata->payload_size ? len : tcpdata->payload_size);
|
memcpy(buffer, tcpdata->payload, len < tcpdata->payload_size ? len : tcpdata->payload_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(_atty, "net_recv: About to free the node value\n");
|
|
||||||
|
|
||||||
free(node->value);
|
free(node->value);
|
||||||
|
|
||||||
fprintf(_atty, "net_recv: About to free the node\n");
|
|
||||||
free(node);
|
free(node);
|
||||||
|
|
||||||
return tcpdata->payload_size;
|
return tcpdata->payload_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void net_handle_tcp(struct tcp_header * tcp, size_t length) {
|
static void net_handle_tcp(struct tcp_header * tcp, size_t length) {
|
||||||
fprintf(_atty, "net_handle_tcp: ENTER\n");
|
|
||||||
|
|
||||||
size_t data_length = length - TCP_HEADER_LENGTH_FLIPPED(tcp);
|
size_t data_length = length - TCP_HEADER_LENGTH_FLIPPED(tcp);
|
||||||
|
|
||||||
fprintf(_atty, "net_handle_tcp: Got src port: %d | dst port: %d\n", ntohs(tcp->source_port), ntohs(tcp->destination_port));
|
|
||||||
/* Find socket */
|
/* Find socket */
|
||||||
if (hashmap_has(_tcp_sockets, (void *)ntohs(tcp->destination_port))) {
|
if (hashmap_has(_tcp_sockets, (void *)ntohs(tcp->destination_port))) {
|
||||||
struct socket *socket = hashmap_get(_tcp_sockets, (void *)ntohs(tcp->destination_port));
|
struct socket *socket = hashmap_get(_tcp_sockets, (void *)ntohs(tcp->destination_port));
|
||||||
@ -498,7 +485,6 @@ static void net_handle_tcp(struct tcp_header * tcp, size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((htons(tcp->flags) & TCP_FLAGS_SYN) && (htons(tcp->flags) & TCP_FLAGS_ACK)) {
|
if ((htons(tcp->flags) & TCP_FLAGS_SYN) && (htons(tcp->flags) & TCP_FLAGS_ACK)) {
|
||||||
fprintf(_atty, "net_handle_tcp: SYN-ACK data_length: %d\n", data_length);
|
|
||||||
socket->proto_sock.tcp_socket.ack_no = ntohl(tcp->seq_number) + data_length + 1;
|
socket->proto_sock.tcp_socket.ack_no = ntohl(tcp->seq_number) + data_length + 1;
|
||||||
net_send_tcp(socket, TCP_FLAGS_ACK, NULL, 0);
|
net_send_tcp(socket, TCP_FLAGS_ACK, NULL, 0);
|
||||||
wakeup_queue(socket->proto_sock.tcp_socket.is_connected);
|
wakeup_queue(socket->proto_sock.tcp_socket.is_connected);
|
||||||
@ -519,10 +505,9 @@ static void net_handle_tcp(struct tcp_header * tcp, size_t length) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(_atty, "net_handle_tcp: payload length: %d\n", length);
|
// fprintf(_atty, "net_handle_tcp: payload length: %d\n", length);
|
||||||
fprintf(_atty, "net_handle_tcp: tcp flags hdr len: %d\n", TCP_HEADER_LENGTH(tcp));
|
// fprintf(_atty, "net_handle_tcp: flipped tcp flags hdr len: %d\n", TCP_HEADER_LENGTH_FLIPPED(tcp));
|
||||||
fprintf(_atty, "net_handle_tcp: flipped tcp flags hdr len: %d\n", TCP_HEADER_LENGTH_FLIPPED(tcp));
|
// fprintf(_atty, "net_handle_tcp: tcpdata->payload_size: %d\n", tcpdata->payload_size);
|
||||||
fprintf(_atty, "net_handle_tcp: tcpdata->payload_size: %d\n", tcpdata->payload_size);
|
|
||||||
|
|
||||||
if (tcpdata->payload_size > 0) {
|
if (tcpdata->payload_size > 0) {
|
||||||
tcpdata->payload = malloc(tcpdata->payload_size);
|
tcpdata->payload = malloc(tcpdata->payload_size);
|
||||||
@ -531,29 +516,26 @@ static void net_handle_tcp(struct tcp_header * tcp, size_t length) {
|
|||||||
tcpdata->payload = NULL;
|
tcpdata->payload = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(_atty, "net_handle_tcp: data_length: %d\n", data_length);
|
|
||||||
socket->proto_sock.tcp_socket.ack_no = ntohl(tcp->seq_number) + data_length;
|
socket->proto_sock.tcp_socket.ack_no = ntohl(tcp->seq_number) + data_length;
|
||||||
|
|
||||||
fprintf(_atty, "net_handle_tcp: set ack: %d\n", socket->proto_sock.tcp_socket.ack_no);
|
|
||||||
if ((htons(tcp->flags) & TCP_FLAGS_SYN) && (htons(tcp->flags) & TCP_FLAGS_ACK) && data_length == 0) {
|
if ((htons(tcp->flags) & TCP_FLAGS_SYN) && (htons(tcp->flags) & TCP_FLAGS_ACK) && data_length == 0) {
|
||||||
fprintf(_atty, "net_handle_tcp: adding 1 to ack\n");
|
|
||||||
socket->proto_sock.tcp_socket.ack_no += 1;
|
socket->proto_sock.tcp_socket.ack_no += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(_atty, "net_handle_tcp: set ack: %d\n", socket->proto_sock.tcp_socket.ack_no);
|
|
||||||
socket->proto_sock.tcp_socket.ack_no = ntohl(tcp->seq_number) + tcpdata->payload_size;
|
socket->proto_sock.tcp_socket.ack_no = ntohl(tcp->seq_number) + tcpdata->payload_size;
|
||||||
fprintf(_atty, "net_handle_tcp: new ack: %d\n", socket->proto_sock.tcp_socket.ack_no);
|
|
||||||
|
|
||||||
spin_lock(socket->packet_queue_lock);
|
spin_lock(socket->packet_queue_lock);
|
||||||
list_insert(socket->packet_queue, tcpdata);
|
list_insert(socket->packet_queue, tcpdata);
|
||||||
spin_unlock(socket->packet_queue_lock);
|
spin_unlock(socket->packet_queue_lock);
|
||||||
|
|
||||||
|
// Send acknowledgement of receiving data
|
||||||
|
net_send_tcp(socket, TCP_FLAGS_ACK, NULL, 0);
|
||||||
|
|
||||||
wakeup_queue(socket->packet_wait);
|
wakeup_queue(socket->packet_wait);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(_atty, "net_handle_tcp: Received packet not associated with a socket!\n");
|
fprintf(_atty, "net_handle_tcp: Received packet not associated with a socket!\n");
|
||||||
}
|
}
|
||||||
fprintf(_atty, "net_handle_tcp: RETURN\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void net_handle_udp(struct udp_packet * udp, size_t length) {
|
static void net_handle_udp(struct udp_packet * udp, size_t length) {
|
||||||
@ -574,7 +556,6 @@ static void net_handle_ipv4(struct ipv4_packet * ipv4) {
|
|||||||
fprintf(_atty, "net_handle_ipv4: ENTER\n");
|
fprintf(_atty, "net_handle_ipv4: ENTER\n");
|
||||||
switch (ipv4->protocol) {
|
switch (ipv4->protocol) {
|
||||||
case IPV4_PROT_TCP:
|
case IPV4_PROT_TCP:
|
||||||
fprintf(_atty, "net_handle_ipv4: about to handle TCP packet\n");
|
|
||||||
net_handle_tcp((struct tcp_header *)ipv4->payload, ntohs(ipv4->length) - sizeof(struct ipv4_packet));
|
net_handle_tcp((struct tcp_header *)ipv4->payload, ntohs(ipv4->length) - sizeof(struct ipv4_packet));
|
||||||
break;
|
break;
|
||||||
case IPV4_PROT_UDP:
|
case IPV4_PROT_UDP:
|
||||||
@ -584,8 +565,6 @@ static void net_handle_ipv4(struct ipv4_packet * ipv4) {
|
|||||||
/* XXX */
|
/* XXX */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(_atty, "net_handle_ipv4: RETURN\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ethernet_packet* net_receive(void) {
|
static struct ethernet_packet* net_receive(void) {
|
||||||
@ -633,8 +612,8 @@ DEFINE_SHELL_FUNCTION(conn, "Do connection") {
|
|||||||
struct socket* socket = net_open(SOCK_STREAM);
|
struct socket* socket = net_open(SOCK_STREAM);
|
||||||
|
|
||||||
fprintf(_atty, "conn: Make connection\n");
|
fprintf(_atty, "conn: Make connection\n");
|
||||||
// ret = net_connect(socket, ip_aton("192.168.134.129"), 12345);
|
ret = net_connect(socket, ip_aton("192.168.134.129"), 12345);
|
||||||
ret = net_connect(socket, ip_aton("10.255.50.206"), 12345);
|
// ret = net_connect(socket, ip_aton("10.255.50.206"), 12345);
|
||||||
|
|
||||||
fprintf(_atty, "conn: connection ret: %d\n", ret);
|
fprintf(_atty, "conn: connection ret: %d\n", ret);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user