From 8ff63b062d724826d8017504063df9b92f8e6703 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 21 Feb 2024 00:14:29 +0100 Subject: New clang-format options --- kernel/network/arp.c | 12 ++++++++---- kernel/network/ethernet.c | 3 ++- kernel/network/ipv4.c | 3 ++- kernel/network/tcp.c | 9 ++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) (limited to 'kernel/network') 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); -- cgit v1.2.3