fix some warning, and tested with mac

This commit is contained in:
alex 2025-10-23 17:35:41 +08:00
parent 8db61a7bbb
commit c2a3048427
15 changed files with 63 additions and 24 deletions

View File

@ -3,7 +3,8 @@ linker = "x86_64-linux-musl-gcc"
[target.aarch64-unknown-linux-gnu] [target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc" linker = "aarch64-linux-gnu-gcc"
ar = "aarch64-linux-gnu-ar" ar = "aarch64-linux-gnu-gcc"
strip = { path = "aarch64-linux-gnu-strip" }
# ranlib = "aarch64-linux-gnu-ranlib" # ranlib = "aarch64-linux-gnu-ranlib"
[target.x86_64-pc-windows-gnu] [target.x86_64-pc-windows-gnu]

View File

@ -35,3 +35,19 @@ tun = []
[build-dependencies] [build-dependencies]
cargo-deb = "3.6.2" cargo-deb = "3.6.2"
[package.metadata.deb]
maintainer = "alex <asxalex@163.com>"
copyright = "2025, alex"
# license-file = ["MIT"]
depends = "$auto"
## assets
assets = [
# executable
["target/release/punchnet", "usr/local/punchnet/punchnet", "755"],
# lib
["libtuntap.so", "usr/lib/", "755"],
]
maintainer-scripts = "debian"

View File

@ -28,4 +28,11 @@ libtun-so-aarch64:
cd src/network && aarch64-linux-gnu-gcc -fPIC -shared -o libtuntap.so tuntap.c && cp libtuntap.so ../.. && cd - cd src/network && aarch64-linux-gnu-gcc -fPIC -shared -o libtuntap.so tuntap.c && cp libtuntap.so ../.. && cd -
pack: pack:
tar -czvf punchnet.tar.gz punchnet punchnet.service libtuntap.so install.sh tar -czvf punchnet.tar.gz punchnet punchnet.service libtuntap.so install.sh
deb: libtun-so
RUSTFLAGS="-L ." cargo deb
deb-aarch64: libtun-so-aarch64
RUSTFLAGS="-L ." cargo deb --target aarch64-unknown-linux-gnu

9
debian/postinst vendored Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
set -e
#DEBHELPER#
ln -sf /usr/local/punchnet/punchnet /usr/bin/punchnet
exit 0;

9
debian/postrm vendored Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
set -e
#DEBHELPER#
rm -rf /usr/lib/libswscale.so.5
exit 0;

View File

@ -1,4 +1,4 @@
use std::{fs, os}; use std::fs;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use sdlan_sn_rs::utils::Mac; use sdlan_sn_rs::utils::Mac;
@ -31,7 +31,7 @@ pub fn get_base_dir() -> &'static str {
pub fn set_base_dir(base_dir: &str) { pub fn set_base_dir(base_dir: &str) {
fs::create_dir_all(base_dir).unwrap(); fs::create_dir_all(base_dir).unwrap();
let base = base_dir.trim_end_matches("/"); let base = base_dir.trim_end_matches("/");
if let Err(e) = BASE_DIR.set(base.to_owned()) { if let Err(_) = BASE_DIR.set(base.to_owned()) {
println!("failed to set base dir"); println!("failed to set base dir");
} }
} }

View File

@ -1,3 +1,5 @@
#![allow(unused)]
use std::{ use std::{
collections::HashMap, collections::HashMap,
sync::atomic::{AtomicU8, Ordering}, sync::atomic::{AtomicU8, Ordering},
@ -35,7 +37,6 @@ const ETHER_TYPE_IP6: u16 = 0x86dd;
const ARP_MAX_AGE: u8 = 128; const ARP_MAX_AGE: u8 = 128;
const ARP_HWTYPE_ETH: u16 = 1; const ARP_HWTYPE_ETH: u16 = 1;
pub const ARP_REQUEST: u16 = 1; pub const ARP_REQUEST: u16 = 1;
pub const ARP_REPLY: u16 = 2; pub const ARP_REPLY: u16 = 2;

View File

@ -18,7 +18,7 @@ use crate::ConnectionState;
use sdlan_sn_rs::config::AF_INET; use sdlan_sn_rs::config::AF_INET;
use sdlan_sn_rs::peer::{SdlanSock, V6Info}; use sdlan_sn_rs::peer::{SdlanSock, V6Info};
use sdlan_sn_rs::utils::{get_current_timestamp, ip_to_string, is_multi_broadcast, rsa_decrypt}; use sdlan_sn_rs::utils::{get_current_timestamp, ip_to_string, is_multi_broadcast, rsa_decrypt};
use sdlan_sn_rs::utils::{Mac, Result, gen_rsa_keys}; use sdlan_sn_rs::utils::{Mac, Result};
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
@ -85,6 +85,7 @@ async fn handle_tcp_message(msg: SdlanTcp) {
send_stun_request(edge).await; send_stun_request(edge).await;
tokio::spawn(async { tokio::spawn(async {
let nattype = edge.probe_nat_type().await; let nattype = edge.probe_nat_type().await;
debug!("nat type is {:?}", nattype);
// println!("nat type is: {:?}", nattype); // println!("nat type is: {:?}", nattype);
}); });
} }

View File

@ -1,4 +1,3 @@
use std::sync::Mutex;
use std::{ use std::{
net::{IpAddr, Ipv6Addr}, net::{IpAddr, Ipv6Addr},
time::Duration, time::Duration,
@ -6,7 +5,7 @@ use std::{
use sdlan_sn_rs::{config::AF_INET6, peer::SdlanSock}; use sdlan_sn_rs::{config::AF_INET6, peer::SdlanSock};
use std::sync::Arc; use std::sync::Arc;
use tokio::{net::UdpSocket, sync::mpsc::Receiver}; use tokio::{sync::mpsc::Receiver};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
use tracing::error; use tracing::error;

View File

@ -15,7 +15,7 @@ use crate::pb::{
encode_to_tcp_message, encode_to_udp_message, SdlEmpty, SdlStunProbe, SdlStunProbeReply, encode_to_tcp_message, encode_to_udp_message, SdlEmpty, SdlStunProbe, SdlStunProbeReply,
}; };
use crate::tcp::{get_tcp_conn, NatType, PacketType, StunProbeAttr}; use crate::tcp::{get_tcp_conn, NatType, PacketType, StunProbeAttr};
use crate::utils::{PidRecorder, Socket}; use crate::utils::{Socket};
use sdlan_sn_rs::peer::{IpSubnet, V6Info}; use sdlan_sn_rs::peer::{IpSubnet, V6Info};

View File

@ -14,7 +14,7 @@ use crate::{
}; };
use etherparse::Ethernet2Header; use etherparse::Ethernet2Header;
use prost::Message; use prost::Message;
use sdlan_sn_rs::utils::{aes_encrypt, BROADCAST_MAC}; use sdlan_sn_rs::utils::{BROADCAST_MAC};
use sdlan_sn_rs::{ use sdlan_sn_rs::{
config::{AF_INET, AF_INET6}, config::{AF_INET, AF_INET6},
peer::{is_sdlan_sock_equal, SdlanSock, V6Info}, peer::{is_sdlan_sock_equal, SdlanSock, V6Info},
@ -809,7 +809,8 @@ async fn send_register(
*/ */
} }
pub fn printHex(key: &[u8]) { #[allow(unused)]
pub fn print_hex(key: &[u8]) {
let mut value = vec![]; let mut value = vec![];
for item in key { for item in key {
value.push(format!("0x{:02x}", item)) value.push(format!("0x{:02x}", item))
@ -1193,6 +1194,7 @@ pub async fn update_supernode_reg(eee: &Node) {
} }
*/ */
#[allow(unused)]
pub fn form_ethernet_packet(src_mac: Mac, dst_mac: Mac, data: &[u8]) -> Vec<u8> { pub fn form_ethernet_packet(src_mac: Mac, dst_mac: Mac, data: &[u8]) -> Vec<u8> {
let mut etherheader = Ethernet2Header::default(); let mut etherheader = Ethernet2Header::default();
etherheader.destination = dst_mac; etherheader.destination = dst_mac;

View File

@ -1,9 +1,8 @@
use etherparse::ether_type::ARP; use etherparse::{Ethernet2Header};
use etherparse::{Ethernet2Header, IpHeaders};
use sdlan_sn_rs::config::SDLAN_DEFAULT_TTL; use sdlan_sn_rs::config::SDLAN_DEFAULT_TTL;
use sdlan_sn_rs::utils::{ use sdlan_sn_rs::utils::{
aes_encrypt, ip_to_string, is_ipv6_multicast, is_multi_broadcast, net_bit_len_to_mask, aes_encrypt, ip_to_string, is_ipv6_multicast, net_bit_len_to_mask,
SDLanError, BROADCAST_MAC, SDLanError,
}; };
use std::ffi::CStr; use std::ffi::CStr;
use std::ffi::{c_char, c_int}; use std::ffi::{c_char, c_int};
@ -19,13 +18,9 @@ use std::process::Command;
use tracing::{debug, error, info}; use tracing::{debug, error, info};
use crate::get_edge; use crate::get_edge;
use crate::network::{ use crate::network::send_packet_to_net;
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::pb::{encode_to_udp_message, SdlData};
use crate::tcp::PacketType; use crate::tcp::PacketType;
use crate::utils::{caculate_crc, mac_to_string};
use super::device::{DeviceConfig, Mode}; use super::device::{DeviceConfig, Mode};
use super::TunTapPacketHandler; use super::TunTapPacketHandler;
@ -218,7 +213,7 @@ impl TunTapPacketHandler for Iface {
send_packet_to_net(edge, target, &msg, size as u64).await; send_packet_to_net(edge, target, &msg, size as u64).await;
} }
Err(e) => { Err(_) => {
error!("failed to parse packet from device"); error!("failed to parse packet from device");
} }
}; };

View File

@ -1,7 +1,6 @@
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use dashmap::DashMap; use dashmap::DashMap;
use etherparse::Ethernet2Header;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use sdlan_sn_rs::{ use sdlan_sn_rs::{
config::SDLAN_DEFAULT_TTL, config::SDLAN_DEFAULT_TTL,

View File

@ -8,7 +8,6 @@ use sdlan_sn_rs::utils::Mac;
pub use socks::*; pub use socks::*;
mod pid_recorder; mod pid_recorder;
pub use pid_recorder::PidRecorder;
// pub const CRC_HASH: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_XFER); // pub const CRC_HASH: crc::Crc<u32> = crc::Crc::<u32>::new(&crc::CRC_32_XFER);

View File

@ -2,8 +2,9 @@ use std::{
fs::{self, OpenOptions}, fs::{self, OpenOptions},
io::Write, io::Write,
}; };
use tracing::{debug, error}; use tracing::{error};
#[allow(unused)]
pub struct PidRecorder(String); pub struct PidRecorder(String);
impl PidRecorder { impl PidRecorder {