Skip to content

Conversation

@MegaRedHand
Copy link
Owner

@MegaRedHand MegaRedHand commented Jun 2, 2025

This PR allows sending packets from a misconfigured router, enabling us to show the TTL making routers discard packets.

When a router is misconfigured, the table entry matching with the packet doesn't lead to the destination. In those cases, routers now try to resolve the next hop from the interface configured on the entry, instead of dropping the packet. Packets will still be dropped if the next hop is not a NetworkDevice.

@MegaRedHand MegaRedHand force-pushed the fix-router-forwarding branch from a996644 to 6bc55cf Compare June 2, 2025 02:44
@MegaRedHand MegaRedHand requested review from Manuel-Pol and Copilot and removed request for Copilot June 7, 2025 14:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the router view to track the ingress interface for each packet, adjust routing decisions (including TTL expiration), and display packets dropped by misconfiguration.

  • Introduces an iface parameter through the packet queuing and processing pipeline
  • Updates processPacket to detect and drop packets sent back out the same interface and deduce next-hop MAC when misconfigured
  • Adds a new PacketWithIface type and adjusts PacketQueue to store the ingress interface

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/types/view-devices/vRouter.ts Track and enqueue packets with their ingress interface and adapt forwarding logic
src/types/view-devices/vNetworkDevice.ts Removed an outdated // TODO comment
src/types/view-devices/vDevice.ts Cleared an obsolete // TODO in interface definition
src/types/graphs/viewgraph.ts Removed two stale // TODO comments
src/types/graphs/datagraph.ts Deleted unneeded // TODO comments
src/packets/ip.ts Removed a // TODO about checksum computation
Comments suppressed due to low confidence (4)

src/types/view-devices/vRouter.ts:177

  • [nitpick] The parameter name iface is abbreviated and may be unclear; consider renaming to interfaceIndex or ingressInterface for better readability.
addPacketToQueue(datagram: IPv4Packet, iface: number) {

src/types/view-devices/vRouter.ts:299

  • [nitpick] The type name PacketWithIface is ambiguous; a more descriptive name like QueuedPacket or PacketWithInterface would improve clarity.
interface PacketWithIface {

src/types/view-devices/vRouter.ts:179

  • The TTL decrement and drop-on-zero branch is new behavior; consider adding a unit or integration test that enqueues a packet with TTL=1 and verifies it is dropped with the correct debug message.
datagram.timeToLive -= 1;

src/types/view-devices/vRouter.ts:299

  • [nitpick] Add a brief JSDoc comment above PacketWithIface explaining its fields (packet and iface) and intended usage in the queue.
interface PacketWithIface {

@MegaRedHand MegaRedHand merged commit 526383f into main Jun 8, 2025
3 checks passed
@MegaRedHand MegaRedHand deleted the fix-router-forwarding branch June 8, 2025 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants