From 2809c966d60a562525ca11d87c208531fba96649 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 23 Oct 2023 09:58:38 -0400 Subject: fix sent to other iface bug --- pkg/ipstack/ipstack.go | 28 +++++++++++++--------------- r2h2/binaries.example.json | 14 ++++++++++++++ r2h2/nodes.json | 6 ++++++ vhost | Bin 3104927 -> 3095810 bytes vrouter | Bin 3104919 -> 3095810 bytes 5 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 r2h2/binaries.example.json create mode 100644 r2h2/nodes.json diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index e949824..59afbcd 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -455,16 +455,12 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de } func RecvIP(iface *Interface, isOpen *bool) error { - // deconstruct interface - prefix := iface.IpPrefix - conn := iface.RecvSocket - buffer := make([]byte, MAX_IP_PACKET_SIZE) // TODO: fix wordking // Read on the UDP port // Too much printing so I commented it out // fmt.Println("wating to read from UDP socket") - _, _, err := conn.ReadFromUDP(buffer) + _, _, err := iface.RecvSocket.ReadFromUDP(buffer) if err != nil { return err } @@ -520,18 +516,20 @@ func RecvIP(iface *Interface, isOpen *bool) error { if hdr.Protocol != RIP_PROTOCOL { fmt.Println("I see a non-rip packet") } - if hdr.Dst == prefix.Addr() { - // see if there is a handler for this protocol - if handler, ok := protocolHandlers[hdr.Protocol]; ok { - if hdr.Protocol != RIP_PROTOCOL { - // fmt.Println("this test packet is exactly for me") - } - err := handler(iface, nil, message, hdr) - if err != nil { - fmt.Println(err) + for _, myIface := range myInterfaces { + if hdr.Dst == myIface.IpPrefix.Addr() { + // see if there is a handler for this protocol + if handler, ok := protocolHandlers[hdr.Protocol]; ok { + if hdr.Protocol != RIP_PROTOCOL { + // fmt.Println("this test packet is exactly for me") + } + err := handler(myIface, nil, message, hdr) + if err != nil { + fmt.Println(err) + } } + return nil } - return nil } // 4) check forwarding table. diff --git a/r2h2/binaries.example.json b/r2h2/binaries.example.json new file mode 100644 index 0000000..59223ba --- /dev/null +++ b/r2h2/binaries.example.json @@ -0,0 +1,14 @@ +{ + "h1": { + "binary_path": "./vhost" + }, + "h2": { + "binary_path": "./vhost" + }, + "r1": { + "binary_path": "./vrouter" + }, + "r2": { + "binary_path": "./vrouter" + } +} \ No newline at end of file diff --git a/r2h2/nodes.json b/r2h2/nodes.json new file mode 100644 index 0000000..282ab86 --- /dev/null +++ b/r2h2/nodes.json @@ -0,0 +1,6 @@ +{ + "h1": "host", + "h2": "host", + "r1": "router", + "r2": "router" +} \ No newline at end of file diff --git a/vhost b/vhost index c61fd2b..8df4716 100755 Binary files a/vhost and b/vhost differ diff --git a/vrouter b/vrouter index 88ed19c..8f8c956 100755 Binary files a/vrouter and b/vrouter differ -- cgit v1.2.3-70-g09d2