summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/init/init.c2
-rw-r--r--src/cmd/netstack/netstack.c44
-rw-r--r--src/kernel/arch/amd64/driver/rtl8139.c8
3 files changed, 41 insertions, 13 deletions
diff --git a/src/cmd/init/init.c b/src/cmd/init/init.c
index 2bef5d8..0a64054 100644
--- a/src/cmd/init/init.c
+++ b/src/cmd/init/init.c
@@ -125,7 +125,7 @@ int main(void) {
}
MOUNT_AT("/net/") {
const char *allow[] = {"/bin/netstack", "/dev/eth/", NULL};
- const char *argv[] = {"/bin/netstack", "/dev/eth/net", "192.168.0.11", "192.168.0.2", NULL};
+ const char *argv[] = {"/bin/netstack", "/dev/eth/", "192.168.0.11", "192.168.0.2", NULL};
MOUNT_AT("/") { fs_whitelist(allow); }
execv(argv[0], (void*)argv);
}
diff --git a/src/cmd/netstack/netstack.c b/src/cmd/netstack/netstack.c
index a8e011e..3876df9 100644
--- a/src/cmd/netstack/netstack.c
+++ b/src/cmd/netstack/netstack.c
@@ -10,10 +10,7 @@
#include <string.h>
#include <thread.h>
-struct net_state state = {
- // TODO dynamically get mac
- .mac = {0x52, 0x54, 0x00, 0xCA, 0x77, 0x1A},
-};
+struct net_state state = {0};
void network_thread(void *arg) { (void)arg;
const size_t buflen = 4096;
@@ -29,24 +26,51 @@ void network_thread(void *arg) { (void)arg;
void fs_thread(void *arg);
int main(int argc, char **argv) {
+ char *path;
if (argc < 4) {
fprintf(stderr, "usage: netstack iface ip gateway\n");
return 1;
}
- state.raw_h = camellia_open(argv[1], OPEN_RW);
+
+ if (asprintf(&path, "%s/net", argv[1]) < 0) {
+ errx(1, "asprintf failed for some reason");
+ }
+ state.raw_h = camellia_open(path, OPEN_RW);
if (state.raw_h < 0) {
- err(1, "open %s", argv[1]);
+ err(1, "open %s", path);
+ return 1;
+ }
+ free(path);
+
+ if (asprintf(&path, "%s/mac", argv[1]) < 0) {
+ errx(1, "asprintf failed for some reason");
+ }
+ hid_t h = camellia_open(path, OPEN_READ);
+ if (h < 0) {
+ err(1, "open %s", path);
return 1;
}
+ if (_sys_read(h, state.mac, 6, 0) != 6) {
+ errx(1, "can't read mac", path);
+ return 1;
+ }
+ _sys_close(h);
+ free(path);
+
if (ip_parse(argv[2], &state.ip) < 0) {
errx(1, "invalid ip: %s", argv[2]);
- return -1;
+ return 1;
}
if (ip_parse(argv[3], &state.gateway) < 0) {
- errx(1, "invalid gateway: %s", argv[2]);
- return -1;
+ errx(1, "invalid gateway: %s", argv[3]);
+ return 1;
}
- setproctitle(argv[2]);
+
+ setproctitle(
+ "ip=%s gw=%s mac=%02x:%02x:%02x:%02x:%02x:%02x", argv[2], argv[3],
+ state.mac[0], state.mac[1], state.mac[2], state.mac[3], state.mac[4],
+ state.mac[5]
+ );
arp_request(state.gateway);
thread_create(0, network_thread, NULL);
thread_create(0, fs_thread, NULL);
diff --git a/src/kernel/arch/amd64/driver/rtl8139.c b/src/kernel/arch/amd64/driver/rtl8139.c
index d1054a4..a005df5 100644
--- a/src/kernel/arch/amd64/driver/rtl8139.c
+++ b/src/kernel/arch/amd64/driver/rtl8139.c
@@ -85,7 +85,6 @@ void rtl8139_init(uint32_t bdf) {
for (int i = 0; i < 6; i++) {
mac[i] = port_in8(iobase + Mac + i);
}
- kprintf("%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
vfs_root_register("/dev/eth/", accept);
}
@@ -174,6 +173,7 @@ static int try_tx(Proc *proc, const void __user *src, size_t slen) {
enum {
HandleRoot,
HandleNet,
+ HandleMac,
};
static void accept(VfsReq *req) {
@@ -189,12 +189,13 @@ static void accept(VfsReq *req) {
case VFSOP_OPEN:
if (reqpathcmp(req, "")) ret = HandleRoot;
else if (reqpathcmp(req, "net")) ret = HandleNet;
+ else if (reqpathcmp(req, "mac")) ret = HandleMac;
else ret = -ENOENT;
vfsreq_finish_short(req, ret);
break;
case VFSOP_READ:
if (id == HandleRoot) {
- const char data[] = "net";
+ const char data[] = "mac\0net";
ret = req_readcopy(req, data, sizeof data);
vfsreq_finish_short(req, ret);
} else if (id == HandleNet) {
@@ -205,6 +206,9 @@ static void accept(VfsReq *req) {
} else {
vfsreq_finish_short(req, ret);
}
+ } else if (id == HandleMac) {
+ ret = req_readcopy(req, mac, sizeof mac);
+ vfsreq_finish_short(req, ret);
} else panic_invalid_state();
break;
case VFSOP_WRITE: