summaryrefslogtreecommitdiff
path: root/kernel/network
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-02-21 00:14:29 +0100
committerAnton Kling <anton@kling.gg>2024-02-21 00:14:29 +0100
commit8ff63b062d724826d8017504063df9b92f8e6703 (patch)
tree03bf0b5a278a4908da8912f956e5651bea9412f1 /kernel/network
parenta85eacdd2406fede4d6ff5cb130b1758978cabb3 (diff)
New clang-format options
Diffstat (limited to 'kernel/network')
-rw-r--r--kernel/network/arp.c12
-rw-r--r--kernel/network/ethernet.c3
-rw-r--r--kernel/network/ipv4.c3
-rw-r--r--kernel/network/tcp.c9
4 files changed, 18 insertions, 9 deletions
diff --git a/kernel/network/arp.c b/kernel/network/arp.c
index 6e589ec..bd3cd24 100644
--- a/kernel/network/arp.c
+++ b/kernel/network/arp.c
@@ -46,8 +46,9 @@ void print_mac(const char *str, u8 *mac) {
kprintf("%s: ", str);
for (int i = 0; i < 6; i++) {
kprintf("%x", mac[i]);
- if (5 != i)
+ if (5 != i) {
kprintf(":");
+ }
}
kprintf("\n");
}
@@ -56,8 +57,9 @@ void print_ip(const char *str, const u8 *ip) {
kprintf("%s: ", str);
for (int i = 0; i < 4; i++) {
kprintf("%d", ip[i]);
- if (3 != i)
+ if (3 != i) {
kprintf(".");
+ }
}
kprintf("\n");
}
@@ -84,8 +86,9 @@ void send_arp_request(const u8 ip[4]) {
int get_mac_from_ip(const u8 ip[4], u8 mac[6]) {
for (int i = 0; i < 10; i++) {
- if (0 != memcmp(arp_table[i].ip, ip, sizeof(u8[4])))
+ if (0 != memcmp(arp_table[i].ip, ip, sizeof(u8[4]))) {
continue;
+ }
memcpy(mac, arp_table[i].mac, sizeof(u8[6]));
return 1;
}
@@ -93,8 +96,9 @@ int get_mac_from_ip(const u8 ip[4], u8 mac[6]) {
send_arp_request(ip);
// TODO: Maybe wait a bit?
for (int i = 0; i < 10; i++) {
- if (0 != memcmp(arp_table[i].ip, ip, sizeof(u8[4])))
+ if (0 != memcmp(arp_table[i].ip, ip, sizeof(u8[4]))) {
continue;
+ }
memcpy(mac, arp_table[i].mac, sizeof(u8[6]));
return 1;
}
diff --git a/kernel/network/ethernet.c b/kernel/network/ethernet.c
index 940802f..4fe6a94 100644
--- a/kernel/network/ethernet.c
+++ b/kernel/network/ethernet.c
@@ -28,8 +28,9 @@ u32 crc32(const char *buf, size_t len) {
if (rem & 1) {
rem >>= 1;
rem ^= 0xedb88320;
- } else
+ } else {
rem >>= 1;
+ }
}
table[i] = rem;
}
diff --git a/kernel/network/ipv4.c b/kernel/network/ipv4.c
index 6aa03ba..6335a09 100644
--- a/kernel/network/ipv4.c
+++ b/kernel/network/ipv4.c
@@ -73,8 +73,9 @@ void handle_ipv4(const u8 *payload, u32 packet_length) {
*(u16 *)(payload + 10) = 0;
u16 calc_checksum = ip_checksum((u8 *)payload, 20);
*(u16 *)(payload + 10) = saved_checksum;
- if (calc_checksum != saved_checksum)
+ if (calc_checksum != saved_checksum) {
return;
+ }
u8 version = (*payload & 0xF0) >> 4;
u8 IHL = (*payload & 0xF);
diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c
index a3ba7cd..f45d1af 100644
--- a/kernel/network/tcp.c
+++ b/kernel/network/tcp.c
@@ -55,8 +55,9 @@ u16 tcp_checksum(u16 *buffer, int size) {
cksum += *buffer++;
size -= sizeof(u16);
}
- if (size)
+ if (size) {
cksum += *(u8 *)buffer;
+ }
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
@@ -179,8 +180,9 @@ void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) {
if (SYN == flags) {
struct INCOMING_TCP_CONNECTION *inc;
- if (!(inc = handle_incoming_tcp_connection(src_ip, n_src_port, dst_port)))
+ if (!(inc = handle_incoming_tcp_connection(src_ip, n_src_port, dst_port))) {
return;
+ }
memcpy(inc->ip, src_ip, sizeof(u8[4]));
inc->seq_num = 0;
inc->ack_num = seq_num + 1;
@@ -192,8 +194,9 @@ void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) {
}
struct INCOMING_TCP_CONNECTION *inc =
get_incoming_tcp_connection(src_ip, n_src_port);
- if (!inc)
+ if (!inc) {
return;
+ }
if (flags == (FIN | ACK)) {
if (inc->requesting_connection_close) {
send_empty_tcp_message(inc, ACK, seq_num, n_dst_port, n_src_port);