Commit 683e1d35 authored by nanamicat's avatar nanamicat

tcp

parent 55e8ed17
use anyhow::{bail, ensure, Result};
use anyhow::{Result, bail, ensure};
use socket2::{Domain, Protocol, SockAddr, SockFilter, Socket, Type};
use std::net::Shutdown;
use std::sync::Arc;
......@@ -14,10 +14,10 @@ use std::{
use tun::Device;
use crate::config::{ConfigRouter, Schema};
use crossbeam::epoch::{pin, Atomic};
use crossbeam::epoch::{Atomic, pin};
use libc::{
setsockopt, sock_filter, sock_fprog, socklen_t, BPF_ABS, BPF_B, BPF_IND, BPF_JEQ, BPF_JMP, BPF_K, BPF_LD, BPF_LDX, BPF_MSH, BPF_RET, BPF_W,
MSG_FASTOPEN, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF,
BPF_ABS, BPF_B, BPF_IND, BPF_JEQ, BPF_JMP, BPF_K, BPF_LD, BPF_LDX, BPF_MSH, BPF_RET, BPF_W, MSG_FASTOPEN, SO_ATTACH_REUSEPORT_CBPF, SOL_SOCKET, setsockopt,
sock_filter, sock_fprog, socklen_t,
};
pub const SECRET_LENGTH: usize = 32;
......@@ -106,6 +106,12 @@ impl Router {
let result = Socket::new(self.config.family, Type::STREAM, Some(Protocol::TCP)).unwrap();
result.set_tcp_nodelay(true).unwrap();
result.set_mark(self.config.mark).unwrap();
if self.config.src_port != 0 {
result.set_reuse_address(true).unwrap();
let addr = Self::bind_addr(&self.config);
result.bind(&addr)?;
}
let meta = Meta {
src_id: local_id,
dst_id: self.config.remote_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment