BROADCAST ip to BROADCAST_MAC

This commit is contained in:
asxalex 2024-10-30 10:30:58 +08:00
parent f3cbc1def2
commit 966f054a63

View File

@ -171,6 +171,15 @@ impl ArpInfo {
if ip == BROADCAST_IPADDR { if ip == BROADCAST_IPADDR {
return (BROADCAST_MAC, ip, false); return (BROADCAST_MAC, ip, false);
} }
let edge = get_edge();
let netbit = edge.device_config.get_net_bit();
let host_netmask = net_bit_len_to_mask(netbit);
let host_netmask_reverse = !host_netmask;
if (ip & host_netmask_reverse) == host_netmask_reverse {
return (BROADCAST_MAC, ip, false);
}
let first_ip = (ip >> 24) as u8 & 0xff; let first_ip = (ip >> 24) as u8 & 0xff;
if first_ip >= 224 && first_ip <= 239 { if first_ip >= 224 && first_ip <= 239 {
let mut multi = MULTICAST_MAC; let mut multi = MULTICAST_MAC;
@ -180,10 +189,8 @@ impl ArpInfo {
return (multi, ip, false); return (multi, ip, false);
} }
let mut target_ip = 0; let mut target_ip = 0;
let edge = get_edge();
let host_ip = edge.device_config.get_ip(); let host_ip = edge.device_config.get_ip();
let host_netmask = net_bit_len_to_mask(edge.device_config.get_net_bit());
if (ip & host_netmask) == (host_ip & host_netmask) { if (ip & host_netmask) == (host_ip & host_netmask) {
target_ip = ip; target_ip = ip;