Skip to content

Commit

Permalink
new argument -e for listen interface binding
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrchien committed Nov 22, 2024
1 parent 4093357 commit d5ce786
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
12 changes: 9 additions & 3 deletions src/cmd/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,27 @@ pub fn add_options(app: Command) -> Command {
Arg::new("interface")
.short('i')
.long("interface")
.help("bind to interface")
.help("send through interface")
.value_name("device")
.display_order(4),
Arg::new("listen_interface")
.short('e')
.long("listen-interface")
.help("listen interface")
.value_name("device")
.display_order(5),
Arg::new("listen_transport")
.short('a')
.long("listen-transport")
.help("listen transport")
.value_name("options")
.display_order(5),
.display_order(6),
Arg::new("remote_transport")
.short('b')
.long("remote-transport")
.help("remote transport")
.value_name("options")
.display_order(6),
.display_order(7),
])
}

Expand Down
4 changes: 1 addition & 3 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub enum CmdInput {

pub fn scan() -> CmdInput {
let ver = format!("{} {}", VERSION, FEATURES);
let app = Command::new("Realm")
.about("A high efficiency relay tool")
.version(ver);
let app = Command::new("Realm").about("A high efficiency relay tool").version(ver);

let app = app
.disable_help_flag(true)
Expand Down
15 changes: 10 additions & 5 deletions src/conf/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub struct EndpointConf {
#[serde(skip_serializing_if = "Option::is_none")]
pub interface: Option<String>,

#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub listen_interface: Option<String>,

#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub listen_transport: Option<String>,
Expand Down Expand Up @@ -155,16 +159,12 @@ impl Config for EndpointConf {

// build partial conn_opts from netconf
let NetInfo {
bind_opts,
mut bind_opts,
mut conn_opts,
no_tcp,
use_udp,
} = self.network.build();

// build left fields of conn_opts

conn_opts.bind_address = self.build_send_through();

#[cfg(feature = "balance")]
{
conn_opts.balancer = self.build_balancer();
Expand All @@ -175,7 +175,10 @@ impl Config for EndpointConf {
conn_opts.transport = self.build_transport();
}

// build left fields of bind_opts and conn_opts
conn_opts.bind_address = self.build_send_through();
conn_opts.bind_interface = self.interface;
bind_opts.bind_interface = self.listen_interface;

EndpointInfo {
no_tcp,
Expand Down Expand Up @@ -203,6 +206,7 @@ impl Config for EndpointConf {
let remote = matches.get_one("remote").cloned().unwrap();
let through = matches.get_one("through").cloned();
let interface = matches.get_one("interface").cloned();
let listen_interface = matches.get_one("listen_interface").cloned();
let listen_transport = matches.get_one("listen_transport").cloned();
let remote_transport = matches.get_one("remote_transport").cloned();

Expand All @@ -211,6 +215,7 @@ impl Config for EndpointConf {
remote,
through,
interface,
listen_interface,
listen_transport,
remote_transport,
network: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions src/conf/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl From<LegacyConf> for FullConf {
remote,
through: None,
interface: None,
listen_interface: None,
listen_transport: None,
remote_transport: None,
network: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/conf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl FullConf {
.filter_entry(|e| e.file_name().to_str().is_some_and(|x| !x.starts_with('.')))
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
.filter(|e| e.path().extension().map_or(false, |s| s == "toml" || s == "json"))
.filter(|e| e.path().extension().is_some_and(|s| s == "toml" || s == "json"))
{
let conf_part = fs::read_to_string(entry.path())
.unwrap_or_else(|e| panic!("failed to open {}: {}", entry.path().to_string_lossy(), e));
Expand Down
5 changes: 4 additions & 1 deletion src/conf/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ impl Config for NetConf {
let tcp_timeout = unbox!(tcp_timeout, TCP_TIMEOUT);
let udp_timeout = unbox!(udp_timeout, UDP_TIMEOUT);

let bind_opts = BindOpts { ipv6_only };
let bind_opts = BindOpts {
ipv6_only,
bind_interface: None,
};
let conn_opts = ConnectOpts {
tcp_keepalive: tcp_kpa,
tcp_keepalive_probe: tcp_kpa_probe,
Expand Down

0 comments on commit d5ce786

Please sign in to comment.