From 4585cd3d62abff4f2c297eef17d90376c0ba74e3 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Tue, 12 May 2020 02:29:29 +0300 Subject: [PATCH] Fix ARP wrappers and add ARP test stub: test/025. --- shell.c | 33 +++++++++++++---- test/021_#i40_all.ref.log | 3 ++ test/025_#net_#arp_#f76_all.d | 69 +++++++++++++++++++++++++++++++++++ test/makefile | 10 ++++- umka.h | 15 +++++++- 5 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 test/021_#i40_all.ref.log create mode 100644 test/025_#net_#arp_#f76_all.d diff --git a/shell.c b/shell.c index 88d59c2..567ba69 100644 --- a/shell.c +++ b/shell.c @@ -1622,7 +1622,7 @@ void shell_net_arp_get_count(int argc, char **argv) { void shell_net_arp_get_entry(int argc, char **argv) { const char *usage = \ - "usage: net_arp_get_entry \n" + "usage: net_arp_get_entry \n" " dev_num device number as returned by net_add_device\n" " arp_num arp number as returned by net_add_device"; if (argc != 3) { @@ -1638,8 +1638,8 @@ void shell_net_arp_get_entry(int argc, char **argv) { } else { fprintf(fout, "arp #%u: IP %d.%d.%d.%d, " "mac %2.2" SCNu8 ":%2.2" SCNu8 ":%2.2" SCNu8 - ":%2.2" SCNu8 ":%2.2" SCNu8 ":%2.2" SCNu8 " " - "status %" PRIu16 " " + ":%2.2" SCNu8 ":%2.2" SCNu8 ":%2.2" SCNu8 ", " + "status %" PRIu16 ", " "ttl %" PRIu16 "\n", arp_num, (uint8_t)(arp.ip >> 0), (uint8_t)(arp.ip >> 8), @@ -1654,7 +1654,10 @@ void shell_net_arp_add_entry(int argc, char **argv) { const char *usage = \ "usage: net_arp_add_entry \n" " dev_num device number as returned by net_add_device\n" - " arp_num arp number as returned by net_add_device"; + " addr IP addr\n" + " mac ethernet addr\n" + " status see ARP.inc\n" + " ttl Time to live"; if (argc != 6) { puts(usage); return; @@ -1668,13 +1671,26 @@ void shell_net_arp_add_entry(int argc, char **argv) { arp.mac+3, arp.mac+4, arp.mac+5); arp.status = strtoul(argv[4], NULL, 0); arp.ttl = strtoul(argv[5], NULL, 0); -fprintf(fout, "## before\n"); f76ret_t r = umka_sys_net_arp_add_entry(dev_num, &arp); -fprintf(fout, "## after\n"); if (r.eax == UINT32_MAX) { fprintf(fout, "status: fail\n"); - } else { - fprintf(fout, "%" PRIi32 "\n", r.eax); + } +} + +void shell_net_arp_del_entry(int argc, char **argv) { + const char *usage = \ + "usage: net_arp_del_entry \n" + " dev_num device number as returned by net_add_device\n" + " arp_num arp number as returned by net_add_device"; + if (argc != 3) { + puts(usage); + return; + } + uint32_t dev_num = strtoul(argv[1], NULL, 0); + int32_t arp_num = strtoul(argv[2], NULL, 0); + f76ret_t r = umka_sys_net_arp_del_entry(dev_num, arp_num); + if (r.eax == UINT32_MAX) { + fprintf(fout, "status: fail\n"); } } @@ -1855,6 +1871,7 @@ func_table_t funcs[] = { { "net_arp_get_count", shell_net_arp_get_count }, { "net_arp_get_entry", shell_net_arp_get_entry }, { "net_arp_add_entry", shell_net_arp_add_entry }, + { "net_arp_del_entry", shell_net_arp_del_entry }, { "bg_set_size", shell_bg_set_size }, { "bg_put_pixel", shell_bg_put_pixel }, { "bg_redraw", shell_bg_redraw }, diff --git a/test/021_#i40_all.ref.log b/test/021_#i40_all.ref.log new file mode 100644 index 0000000..39d1a1c --- /dev/null +++ b/test/021_#i40_all.ref.log @@ -0,0 +1,3 @@ +/> i40 18 16 +eax = 00020000 131072 131072 +ebx = 00000010 16 16 diff --git a/test/025_#net_#arp_#f76_all.d b/test/025_#net_#arp_#f76_all.d new file mode 100644 index 0000000..8cf1339 --- /dev/null +++ b/test/025_#net_#arp_#f76_all.d @@ -0,0 +1,69 @@ +stack_init + +net_get_dev_count + +net_get_dev_name 0 + +net_add_device + +net_get_dev_count + +net_get_dev_name 1 + +net_dev_reset 1 + +net_arp_get_count 1 + +net_arp_add_entry 1 192.168.1.11 01:01:01:01:01:01 2 61 +net_arp_get_count 1 +net_arp_get_entry 1 0 + +net_arp_add_entry 1 192.168.1.12 02:02:02:02:02:02 2 62 +net_arp_get_count 1 +net_arp_get_entry 1 0 +net_arp_get_entry 1 1 + +net_arp_add_entry 1 192.168.1.13 03:03:03:03:03:03 2 63 +net_arp_get_count 1 +net_arp_get_entry 1 0 +net_arp_get_entry 1 1 +net_arp_get_entry 1 2 + +net_arp_del_entry 1 2 +net_arp_get_count 1 +net_arp_get_entry 1 0 +net_arp_get_entry 1 1 +net_arp_get_entry 1 2 + +net_arp_del_entry 1 1 +net_arp_get_count 1 +net_arp_get_entry 1 0 +net_arp_get_entry 1 1 +net_arp_get_entry 1 2 + +net_arp_del_entry 1 10 +net_arp_get_count 1 +net_arp_get_entry 1 0 +net_arp_get_entry 1 1 +net_arp_get_entry 1 2 + +net_arp_del_entry 1 20 +net_arp_get_count 1 +net_arp_get_entry 1 0 +net_arp_get_entry 1 1 +net_arp_get_entry 1 2 + + +net_arp_del_entry 1 0 +net_arp_get_count 1 +net_arp_get_entry 1 0 + +net_arp_add_entry 1 192.168.1.11 01:01:01:01:01:01 2 61 + +net_arp_add_entry 1 192.168.1.12 02:02:02:02:02:02 2 62 + +net_arp_get_count 1 + +net_arp_del_entry 1 -1 + +net_arp_get_count 1 diff --git a/test/makefile b/test/makefile index 1154b3f..3ce0833 100644 --- a/test/makefile +++ b/test/makefile @@ -19,8 +19,11 @@ unicode_tests := $(addsuffix .out.log, $(basename $(wildcard *\#unicode_*.t))) v5_tests := $(addsuffix .out.log, $(basename $(wildcard *\#v5_*.t))) draw_tests := $(addsuffix .out.log, $(basename $(wildcard *\#draw_*.t))) coverage_tests := $(addsuffix .out.log, $(basename $(wildcard *\#coverage_*.t))) +i40_tests := $(addsuffix .out.log, $(basename $(wildcard *\#i40_*.t))) +net_tests := $(addsuffix .out.log, $(basename $(wildcard *\#net_*.t))) +arp_tests := $(addsuffix .out.log, $(basename $(wildcard *\#arp_*.t))) -all: xfs s05k s4k f30 f70 f70s0 f70s1 f70s5 lookup bug xattr unicode v5 draw coverage +all: xfs s05k s4k f30 f70 f70s0 f70s1 f70s5 lookup bug xattr unicode v5 draw coverage i40 net arp @echo all tests passed xfs: $(xfs_tests) @@ -38,8 +41,11 @@ unicode: $(unicode_tests) v5: $(v5_tests) draw: $(draw_tests) coverage: $(coverage_tests) +i40: $(i40_tests) +net: $(net_tests) +arp: $(arp_tests) -%.out.log: %.ref.log %.t +%.out.log: %.t $(UMKA_SHELL) < $*.t > $@ @ cmp $*.{out,ref}.log @ if [ -f "$*.ref.png" ]; then cmp $*.{out,ref}.png; fi diff --git a/umka.h b/umka.h index 8f8b7d9..cceae08 100644 --- a/umka.h +++ b/umka.h @@ -1361,9 +1361,20 @@ static inline f76ret_t umka_sys_net_arp_add_entry(uint32_t dev_num, return r; } +static inline f76ret_t umka_sys_net_arp_del_entry(uint32_t dev_num, + int32_t arp_num) { + f76ret_t r; + __asm__ __inline__ __volatile__ ( + "call i40" + : "=a"(r.eax), + "=b"(r.ebx) + : "a"(76), + "b"((5 << 16) + (dev_num << 8) + 5), + "c"(arp_num) + : "memory"); + return r; +} -// Function 76, Protocol 5 - ARP, Subfunction 4, Add ARP entry ==== -// Function 76, Protocol 5 - ARP, Subfunction 5, Remove ARP entry ==== // Function 76, Protocol 5 - ARP, Subfunction 6, Send ARP announce == // Function 76, Protocol 5 - ARP, Subfunction 7, Read # conflicts ===