From 7483470f4508a2a56492b00b1ccde0f24c14a4e2 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 27 Aug 2022 15:46:58 +0200 Subject: user/netstack: don't respond to RST --- src/user/app/netstack/netstack.c | 3 +++ src/user/app/netstack/tcp.c | 36 +++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'src') 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); + } } -- cgit v1.2.3