tap mac
This commit is contained in:
parent
56d6a35fea
commit
302300294a
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1442,6 +1442,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"prost",
|
||||
"prost-build",
|
||||
"rand",
|
||||
"rsa",
|
||||
"sdlan-sn-rs",
|
||||
"structopt",
|
||||
|
||||
@ -13,6 +13,7 @@ num_enum = "0.7.2"
|
||||
once_cell = "1.19.0"
|
||||
prost = "0.12.6"
|
||||
prost-build = "0.12.6"
|
||||
rand = "0.8.5"
|
||||
rsa = "0.9.6"
|
||||
sdlan-sn-rs = { git = "ssh://git@git.asxalex.pw/sdlan-v2/sdlan-rs.git" }
|
||||
# sdlan-sn-rs = { git = "https://git.asxalex.pw/sdlan-v2/sdlan-rs.git" }
|
||||
|
||||
@ -4,6 +4,8 @@ use sdlan_rs::CommandLine;
|
||||
use sdlan_rs::CommandLineInput;
|
||||
use sdlan_sn_rs::log;
|
||||
|
||||
use tracing::{debug, error};
|
||||
|
||||
use std::process::exit;
|
||||
use std::time::Duration;
|
||||
use structopt::StructOpt;
|
||||
@ -26,7 +28,7 @@ async fn main() {
|
||||
mtu: 1290,
|
||||
name: "tau".to_owned(),
|
||||
tos: 0,
|
||||
token: "".to_owned(),
|
||||
token: "test-token".to_owned(),
|
||||
allow_p2p: true,
|
||||
},
|
||||
tx,
|
||||
@ -39,14 +41,20 @@ async fn main() {
|
||||
|
||||
let edge = get_edge();
|
||||
// let res = edge.start_without_feedback(cmd.token).await;
|
||||
let Ok(res) = edge
|
||||
/*
|
||||
let res = match edge
|
||||
.start_with_feedback(cmd.token, Duration::from_secs(3))
|
||||
.await
|
||||
else {
|
||||
println!("failed to start1");
|
||||
exit(0);
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
error!("failed to start: {:?}", e);
|
||||
exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
debug!("here1");
|
||||
|
||||
if res.result != 0 {
|
||||
println!("failed to start: {}", res.message);
|
||||
if res.should_exit {
|
||||
@ -55,6 +63,10 @@ async fn main() {
|
||||
// edge.stop().await;
|
||||
// exit(0);
|
||||
}
|
||||
*/
|
||||
if let Err(e) = edge.start_without_feedback(cmd.token).await {
|
||||
error!("failed to start: {:?}", e);
|
||||
}
|
||||
|
||||
/*
|
||||
tokio::time::sleep(Duration::from_secs(20)).await;
|
||||
|
||||
@ -162,7 +162,11 @@ impl ArpInfo {
|
||||
}
|
||||
let first_ip = (ip >> 24) as u8 & 0xff;
|
||||
if first_ip >= 224 && first_ip <= 239 {
|
||||
return (MULTICAST_MAC, ip, false);
|
||||
let mut multi = MULTICAST_MAC;
|
||||
multi[3] = (ip >> 16) as u8 & 0x7f;
|
||||
multi[4] = (ip >> 8) as u8 & 0xff;
|
||||
multi[5] = (ip) as u8 & 0xff;
|
||||
return (multi, ip, false);
|
||||
}
|
||||
let mut target_ip = 0;
|
||||
let edge = get_edge();
|
||||
|
||||
@ -76,7 +76,7 @@ async fn handle_tcp_message(msg: SdlanTcp) {
|
||||
Err(_) => NULL_MAC,
|
||||
Ok(m) => m,
|
||||
};
|
||||
*edge.device_config.mac.write().unwrap() = mac;
|
||||
// *edge.device_config.mac.write().unwrap() = mac;
|
||||
edge.device_config
|
||||
.ip
|
||||
.net_bit_len
|
||||
@ -304,7 +304,7 @@ pub async fn async_main(
|
||||
installed_channel,
|
||||
client_id: edge.config.node_uuid.clone(),
|
||||
dev_addr: Some(SdlDevAddr {
|
||||
mac: vec![],
|
||||
mac: Vec::from(edge.device_config.get_mac()),
|
||||
net_addr: 0,
|
||||
network_id: 0,
|
||||
net_bit_len: 0,
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
use std::sync::RwLock;
|
||||
|
||||
use crate::utils::mac_to_string;
|
||||
use sdlan_sn_rs::{peer::IpSubnet, utils::Mac};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::utils::generate_mac_address;
|
||||
|
||||
pub struct DeviceConfig {
|
||||
pub mac: RwLock<Mac>,
|
||||
@ -9,8 +13,10 @@ pub struct DeviceConfig {
|
||||
|
||||
impl DeviceConfig {
|
||||
pub fn new() -> Self {
|
||||
let mac = generate_mac_address();
|
||||
debug!("self mac: {}", mac_to_string(&mac));
|
||||
DeviceConfig {
|
||||
mac: RwLock::new([0; 6]),
|
||||
mac: RwLock::new(mac),
|
||||
ip: IpSubnet::new(0, 0),
|
||||
}
|
||||
}
|
||||
@ -34,7 +40,8 @@ impl DeviceConfig {
|
||||
}
|
||||
|
||||
pub fn get_mac(&self) -> Mac {
|
||||
*self.mac.read().unwrap()
|
||||
let mac = *self.mac.read().unwrap();
|
||||
mac
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ use std::time::Duration;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
use tokio::sync::oneshot;
|
||||
use tracing::error;
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::pb::{
|
||||
encode_to_tcp_message, encode_to_udp_message, SdlEmpty, SdlStunProbe, SdlStunProbeReply,
|
||||
@ -203,6 +203,7 @@ impl Node {
|
||||
pkt_id: Some(id),
|
||||
})
|
||||
.await;
|
||||
debug!("start with feedback");
|
||||
|
||||
tokio::select! {
|
||||
rx_info = rx => {
|
||||
|
||||
@ -59,7 +59,7 @@ impl ReadWriteActor {
|
||||
remote: remote.to_owned(),
|
||||
from_tcp,
|
||||
connecting_chan,
|
||||
ipv6_network_restarter
|
||||
ipv6_network_restarter,
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ impl ReadWriteActor {
|
||||
}
|
||||
}
|
||||
*/
|
||||
debug!("start stop chan recv none");
|
||||
debug!("start stop chan received: {}", started);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -136,6 +136,7 @@ impl ReadWriteActor {
|
||||
return;
|
||||
};
|
||||
self.connected.store(true, Ordering::Relaxed);
|
||||
debug!("connected");
|
||||
on_connected(&mut stream, start_pkt_id.take()).await;
|
||||
|
||||
if let Some(ref connecting_chan) = self.connecting_chan {
|
||||
@ -276,7 +277,15 @@ impl ReadWriterHandle {
|
||||
let (from_tcp, mut data_from_tcp) = channel(20);
|
||||
|
||||
let connected: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
|
||||
let actor = ReadWriteActor::new(cancel, addr, from_tcp, connected.clone(), pong_time, connecting_chan, ipv6_network_restarter);
|
||||
let actor = ReadWriteActor::new(
|
||||
cancel,
|
||||
addr,
|
||||
from_tcp,
|
||||
connected.clone(),
|
||||
pong_time,
|
||||
connecting_chan,
|
||||
ipv6_network_restarter,
|
||||
);
|
||||
tokio::spawn(async move {
|
||||
actor
|
||||
.run(true, to_tcp, on_connected, on_disconnected, start_stop_chan)
|
||||
|
||||
@ -2,6 +2,7 @@ mod command;
|
||||
pub use command::*;
|
||||
|
||||
mod socks;
|
||||
use rand::Rng;
|
||||
use sdlan_sn_rs::utils::Mac;
|
||||
pub use socks::*;
|
||||
|
||||
@ -14,3 +15,16 @@ pub fn mac_to_string(mac: &Mac) -> String {
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
|
||||
)
|
||||
}
|
||||
|
||||
pub fn generate_mac_address() -> Mac {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut mac = [0; 6];
|
||||
for i in 0..6 {
|
||||
let number: u8 = rng.gen();
|
||||
mac[i] = number;
|
||||
}
|
||||
mac[0] &= !0x01;
|
||||
mac[0] |= 0x02;
|
||||
|
||||
mac
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user