From 334f8ccbd3887aea46721206676a55ada229e256 Mon Sep 17 00:00:00 2001 From: Kevin Lange <klange@dakko.us> Date: Sun, 4 Sep 2016 13:32:29 +0900 Subject: [PATCH] Actually use proper MAC in packets. Also, assign mac early enough in rtl driver. --- modules/net.c | 11 ++++++----- modules/rtl.c | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/net.c b/modules/net.c index 3db75d5b..16f5bf88 100644 --- a/modules/net.c +++ b/modules/net.c @@ -12,8 +12,6 @@ static hashmap_t * dns_cache; -static uint8_t mac[6]; - static hashmap_t *_tcp_sockets = NULL; static hashmap_t *_udp_sockets = NULL; @@ -337,7 +335,8 @@ static size_t write_dns_packet(uint8_t * buffer, size_t queries_len, uint8_t * q /* Then, let's write an ethernet frame */ struct ethernet_packet eth_out = { - .source = { mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] }, + .source = { _netif.hwaddr[0], _netif.hwaddr[1], _netif.hwaddr[2], + _netif.hwaddr[3], _netif.hwaddr[4], _netif.hwaddr[5] }, .destination = BROADCAST_MAC, .type = htons(0x0800), }; @@ -769,7 +768,8 @@ size_t write_dhcp_packet(uint8_t * buffer) { /* Then, let's write an ethernet frame */ struct ethernet_packet eth_out = { - .source = { mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] }, + .source = { _netif.hwaddr[0], _netif.hwaddr[1], _netif.hwaddr[2], + _netif.hwaddr[3], _netif.hwaddr[4], _netif.hwaddr[5] }, .destination = BROADCAST_MAC, .type = htons(0x0800), }; @@ -832,7 +832,8 @@ size_t write_dhcp_packet(uint8_t * buffer) { .siaddr = 0x000000, .giaddr = 0x000000, - .chaddr = {mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], 0x00}, + .chaddr = { _netif.hwaddr[0], _netif.hwaddr[1], _netif.hwaddr[2], + _netif.hwaddr[3], _netif.hwaddr[4], _netif.hwaddr[5] }, .sname = {0}, .file = {0}, .magic = htonl(DHCP_MAGIC), diff --git a/modules/rtl.c b/modules/rtl.c index 274714a0..b9715aac 100644 --- a/modules/rtl.c +++ b/modules/rtl.c @@ -392,6 +392,9 @@ int init_rtl(void) { net_queue = list_create(); + debug_print(NOTICE, "Initializing netif functions\n"); + init_netif_funcs(rtl_get_mac, rtl_get_packet, rtl_send_packet); + #if 1 { debug_print(NOTICE, "Sending DHCP discover\n"); @@ -454,9 +457,6 @@ int init_rtl(void) { debug_print(NOTICE, "Card is configured, going to start worker thread now.\n"); - debug_print(NOTICE, "Initializing netif functions\n"); - - init_netif_funcs(rtl_get_mac, rtl_get_packet, rtl_send_packet); create_kernel_tasklet(net_handler, "[eth]", NULL); debug_print(NOTICE, "Back from starting the worker thread.\n");