Skip to content

Commit f256ec7

Browse files
committed
fix: device use the dstMac found in it arp table when sending a icmp packet
1 parent 5ecf301 commit f256ec7

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

src/programs/echo_sender.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ export class SingleEcho extends ProgramBase {
8282

8383
// Resolve destination MAC address
8484
const dstMac = srcDevice.resolveAddress(dst.ip);
85-
if (!dstMac) {
85+
if (!dstMac || !dstMac.mac) {
8686
console.debug(
8787
`Device ${this.srcId} couldn't resolve MAC address for device with IP ${dst.ip.toString()}. Program cancelled`,
8888
);
8989
return;
9090
}
9191

9292
// Wrap in Ethernet frame
93-
const ethernetFrame = new EthernetFrame(src.mac, dst.mac, ipPacket);
93+
const ethernetFrame = new EthernetFrame(src.mac, dstMac.mac, ipPacket);
9494
sendViewPacket(this.viewgraph, this.srcId, ethernetFrame, sendingIface);
9595
}
9696

src/types/data-devices/dNetworkDevice.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export abstract class DataNetworkDevice extends DataDevice {
5353
): { mac: MacAddress; edited: boolean } | undefined {
5454
const entry = this.arpTable.get(ip.toString());
5555
if (!entry) {
56-
// Buscar el dispositivo y la MAC real si no está en la tabla
56+
// Search for the device and the real MAC if it is not in the table
5757
const device = this.datagraph.getDeviceByIP(ip);
5858
if (!device) {
5959
console.warn(`Device with ip ${ip.toString()} not found in DataGraph`);
@@ -62,8 +62,13 @@ export abstract class DataNetworkDevice extends DataDevice {
6262
const iface = device.interfaces.find((iface) => iface.ip?.equals(ip));
6363
return iface ? { mac: iface.mac, edited: false } : undefined;
6464
}
65-
// Si la entrada existe pero la MAC es "", se considera eliminada
66-
if (entry.mac === "") return undefined;
65+
// If the entry exists but the MAC is "", it is considered deleted
66+
if (entry.mac === "") {
67+
console.debug(
68+
`Interface ${ip.toString()} from device ${this.id} is deleted`,
69+
);
70+
return undefined;
71+
}
6772
return { mac: MacAddress.parse(entry.mac), edited: entry.edited };
6873
}
6974

src/types/network-modules/tables/arp_table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function removeArpTableEntry(
5252
): void {
5353
const device = dataGraph.getDevice(deviceId);
5454
if (!device || !(device instanceof DataNetworkDevice)) {
55-
console.warn(`Device with ID ${deviceId} is not a network device.`);
55+
console.error(`Network Device with ID ${deviceId} not found.`);
5656
return;
5757
}
5858
device.arpTable.add({ ip, mac: "", edited: false });

src/types/view-devices/vNetworkDevice.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { Texture } from "pixi.js";
2-
import {
3-
ICMP_PROTOCOL_NUMBER,
4-
IpAddress,
5-
IPv4Packet,
6-
TCP_PROTOCOL_NUMBER,
7-
} from "../../packets/ip";
2+
import { ICMP_PROTOCOL_NUMBER, IpAddress, IPv4Packet } from "../../packets/ip";
83
import { DeviceId, NetworkInterfaceData } from "../graphs/datagraph";
94
import { ViewDevice } from "./vDevice";
105
import { ViewGraph } from "../graphs/viewgraph";

src/types/view-devices/vSwitch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export class ViewSwitch extends ViewDevice {
8989
) {
9090
if (sendingIface === iface || sendingIface >= this.interfaces.length) {
9191
// Packet would be sent to the interface where it came, discard it
92-
dropPacket(this.viewgraph, this.id, frame);
9392
return;
9493
}
9594

0 commit comments

Comments
 (0)