aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-10-23 09:58:38 -0400
committersotech117 <michael_foiani@brown.edu>2023-10-23 09:58:38 -0400
commit2809c966d60a562525ca11d87c208531fba96649 (patch)
tree80cb650bb8d63edceb7c96f3052a23be7b0375cd
parentfce81b0ba78d52427fc2ba43af63732d3205dcf1 (diff)
fix sent to other iface bug
-rw-r--r--pkg/ipstack/ipstack.go28
-rw-r--r--r2h2/binaries.example.json14
-rw-r--r--r2h2/nodes.json6
-rwxr-xr-xvhostbin3104927 -> 3095810 bytes
-rwxr-xr-xvrouterbin3104919 -> 3095810 bytes
5 files changed, 33 insertions, 15 deletions
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
--- a/vhost
+++ b/vhost
Binary files differ
diff --git a/vrouter b/vrouter
index 88ed19c..8f8c956 100755
--- a/vrouter
+++ b/vrouter
Binary files differ