linux add to arp-list
This commit is contained in:
parent
d1e30370fc
commit
07c6536d5a
@ -2,7 +2,8 @@ use etherparse::ether_type::ARP;
|
||||
use etherparse::{Ethernet2Header, IpHeaders};
|
||||
use sdlan_sn_rs::config::SDLAN_DEFAULT_TTL;
|
||||
use sdlan_sn_rs::utils::{
|
||||
aes_encrypt, ip_to_string, is_multi_broadcast, net_bit_len_to_mask, SDLanError, BROADCAST_MAC,
|
||||
aes_encrypt, ip_to_string, is_ipv6_multicast, is_multi_broadcast, net_bit_len_to_mask,
|
||||
SDLanError, BROADCAST_MAC,
|
||||
};
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::{c_char, c_int};
|
||||
@ -19,8 +20,8 @@ use tracing::{debug, error, info};
|
||||
|
||||
use crate::get_edge;
|
||||
use crate::network::{
|
||||
generate_arp_request, send_arp_request, send_packet_to_net, ArpHdr, ArpRequestInfo,
|
||||
ArpResponse, ARP_REPLY, ARP_REQUEST,
|
||||
add_to_arp_wait_list, arp_arrived, generate_arp_request, send_arp_request, send_packet_to_net,
|
||||
ArpHdr, ArpRequestInfo, ArpResponse, ARP_REPLY, ARP_REQUEST,
|
||||
};
|
||||
use crate::pb::{encode_to_udp_message, SdlData};
|
||||
use crate::tcp::PacketType;
|
||||
@ -182,13 +183,13 @@ impl TunTapPacketHandler for Iface {
|
||||
}
|
||||
async fn handle_packet_from_device(
|
||||
&self,
|
||||
data: &[u8],
|
||||
data: Vec<u8>,
|
||||
encrypt_key: &[u8],
|
||||
) -> std::io::Result<()> {
|
||||
debug!("in tap mode2");
|
||||
let edge = get_edge();
|
||||
|
||||
match Ethernet2Header::from_slice(data) {
|
||||
match Ethernet2Header::from_slice(&data) {
|
||||
Ok((hdr, _)) => {
|
||||
let target = hdr.destination;
|
||||
if is_ipv6_multicast(&target) {
|
||||
@ -196,7 +197,7 @@ impl TunTapPacketHandler for Iface {
|
||||
}
|
||||
let size = data.len();
|
||||
|
||||
let Ok(encrypted) = aes_encrypt(encrypt_key, data) else {
|
||||
let Ok(encrypted) = aes_encrypt(encrypt_key, &data) else {
|
||||
error!("failed to encrypt packet request");
|
||||
return Ok(());
|
||||
};
|
||||
@ -275,6 +276,7 @@ impl TunTapPacketHandler for Iface {
|
||||
mac: arp.shwaddr,
|
||||
})
|
||||
.await;
|
||||
|
||||
// target to us
|
||||
arp.opcode = ARP_REPLY;
|
||||
arp.dhwaddr = arp.shwaddr;
|
||||
@ -324,6 +326,7 @@ impl TunTapPacketHandler for Iface {
|
||||
mac: arp.shwaddr,
|
||||
})
|
||||
.await;
|
||||
arp_arrived(from_ip, arp.shwaddr).await;
|
||||
}
|
||||
}
|
||||
_other => {
|
||||
@ -373,7 +376,7 @@ impl TunTapPacketHandler for Iface {
|
||||
|
||||
async fn handle_packet_from_device(
|
||||
&self,
|
||||
data: &[u8],
|
||||
data: Vec<u8>,
|
||||
encrypt_key: &[u8],
|
||||
) -> std::io::Result<()> {
|
||||
let eee = get_edge();
|
||||
@ -407,6 +410,7 @@ impl TunTapPacketHandler for Iface {
|
||||
do_arp_request,
|
||||
} => {
|
||||
if do_arp_request {
|
||||
add_to_arp_wait_list(dstip, data);
|
||||
println!(
|
||||
"find ip: {:?} => {:?}",
|
||||
src.to_be_bytes(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user