summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--src/user/app/netstack/netstack.c3
-rw-r--r--src/user/app/netstack/tcp.c36
3 files changed, 27 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 31b7c56..2ce559d 100644
--- a/Makefile
+++ b/Makefile
@@ -17,9 +17,12 @@ SPARSEFLAGS = -Wno-non-pointer-null
LFLAGS = -ffreestanding -O2 -nostdlib -lgcc -Wl,-zmax-page-size=4096 -Wl,--no-warn-mismatch
QFLAGS = -no-reboot
ifdef NET_DIRECT
-QFLAGS += -nic socket,model=rtl8139,connect=:1234,mac=52:54:00:ca:77:1a
+QFLAGS += -nic socket,model=rtl8139,connect=:1234,mac=52:54:00:ca:77:1a,id=n1
else
-QFLAGS += -nic user,model=rtl8139,mac=52:54:00:ca:77:1a,net=192.168.0.0/24,hostfwd=tcp::12380-192.168.0.11:80
+QFLAGS += -nic user,model=rtl8139,mac=52:54:00:ca:77:1a,net=192.168.0.0/24,hostfwd=tcp::12380-192.168.0.11:80,id=n1
+endif
+ifdef NET_PCAP
+QFLAGS += -object filter-dump,id=f1,netdev=n1,file=$(NET_PCAP)
endif
ifndef NO_KVM
QFLAGS += -enable-kvm
diff --git a/src/user/app/netstack/netstack.c b/src/user/app/netstack/netstack.c
index 75a5162..cc5247b 100644
--- a/src/user/app/netstack/netstack.c
+++ b/src/user/app/netstack/netstack.c
@@ -25,7 +25,10 @@ void network_thread(void *arg) { (void)arg;
void fs_thread(void *arg);
+__attribute__((visibility("hidden")))
+extern char _image_base[];
int main(int argc, char **argv) {
+ eprintf("0x%x", _image_base);
if (argc < 4) {
eprintf("usage: netstack iface ip gateway");
return 1;
diff --git a/src/user/app/netstack/tcp.c b/src/user/app/netstack/tcp.c
index dd6d121..daa728f 100644
--- a/src/user/app/netstack/tcp.c
+++ b/src/user/app/netstack/tcp.c
@@ -245,22 +245,24 @@ void tcp_parse(const uint8_t *buf, size_t len, struct ipv4 ip) {
}
}
- uint8_t *pkt = malloc(MinHdr);
- memset(pkt, 0, MinHdr);
- nput16(pkt + SrcPort, dstport);
- nput16(pkt + DstPort, srcport);
- nput32(pkt + Seq, acknum);
- nput32(pkt + AckNum, seq + 1);
- uint16_t pktflags = FlagRST | FlagACK;
- pktflags |= (MinHdr / 4) << 12;
- nput16(pkt + Flags, pktflags);
- nput16(pkt + Checksum, ip_checksumphdr(pkt, MinHdr, ip.src, ip.dst, 6));
+ if ((flags & FlagRST) == 0) {
+ uint8_t *pkt = malloc(MinHdr);
+ memset(pkt, 0, MinHdr);
+ nput16(pkt + SrcPort, dstport);
+ nput16(pkt + DstPort, srcport);
+ nput32(pkt + Seq, acknum);
+ nput32(pkt + AckNum, seq + 1);
+ uint16_t pktflags = FlagRST | FlagACK;
+ pktflags |= (MinHdr / 4) << 12;
+ nput16(pkt + Flags, pktflags);
+ nput16(pkt + Checksum, ip_checksumphdr(pkt, MinHdr, ip.src, ip.dst, 6));
- ipv4_send(pkt, MinHdr, (struct ipv4){
- .proto = 6,
- .src = ip.dst,
- .dst = ip.src,
- .e.dst = ip.e.src,
- });
- free(pkt);
+ ipv4_send(pkt, MinHdr, (struct ipv4){
+ .proto = 6,
+ .src = ip.dst,
+ .dst = ip.src,
+ .e.dst = ip.e.src,
+ });
+ free(pkt);
+ }
}