diff --git a/src/service/local.rs b/src/service/local.rs index c4ef99acfde7..92aa8847812b 100644 --- a/src/service/local.rs +++ b/src/service/local.rs @@ -176,6 +176,14 @@ pub fn define_command_line_options(mut app: Command) -> Command { .requires("SERVER_ADDR") .help("SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"), ) + .arg( + Arg::new("PLUGIN_MODE") + .long("plugin-mode") + .num_args(1) + .action(ArgAction::Set) + .requires("PLUGIN") + .help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"), + ) .arg( Arg::new("PLUGIN_OPT") .long("plugin-opts") @@ -623,7 +631,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future("PLUGIN_OPT").cloned(), plugin_args: Vec::new(), - plugin_mode: Mode::TcpOnly, + plugin_mode: matches.get_one::("PLUGIN_MODE") + .map(|x| x.parse::().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`")) + .unwrap_or(Mode::TcpOnly), }; sc.set_plugin(plugin); diff --git a/src/service/manager.rs b/src/service/manager.rs index ebf7a2ff8eae..83c6ee03294c 100644 --- a/src/service/manager.rs +++ b/src/service/manager.rs @@ -95,6 +95,14 @@ pub fn define_command_line_options(mut app: Command) -> Command { .value_hint(ValueHint::CommandName) .help("Default SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"), ) + .arg( + Arg::new("PLUGIN_MODE") + .long("plugin-mode") + .num_args(1) + .action(ArgAction::Set) + .requires("PLUGIN") + .help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"), + ) .arg( Arg::new("PLUGIN_OPT") .long("plugin-opts") @@ -377,7 +385,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future("PLUGIN_OPT").cloned(), plugin_args: Vec::new(), - plugin_mode: Mode::TcpOnly, + plugin_mode: matches.get_one::("PLUGIN_MODE") + .map(|x| x.parse::().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`")) + .unwrap_or(Mode::TcpOnly), }); } diff --git a/src/service/server.rs b/src/service/server.rs index 6f1fa842f878..7c32c98fe205 100644 --- a/src/service/server.rs +++ b/src/service/server.rs @@ -123,6 +123,14 @@ pub fn define_command_line_options(mut app: Command) -> Command { .requires("SERVER_ADDR") .help("SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"), ) + .arg( + Arg::new("PLUGIN_MODE") + .long("plugin-mode") + .num_args(1) + .action(ArgAction::Set) + .requires("PLUGIN") + .help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"), + ) .arg( Arg::new("PLUGIN_OPT") .long("plugin-opts") @@ -358,7 +366,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future("PLUGIN_OPT").cloned(), plugin_args: Vec::new(), - plugin_mode: Mode::TcpOnly, + plugin_mode: matches.get_one::("PLUGIN_MODE") + .map(|x| x.parse::().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`")) + .unwrap_or(Mode::TcpOnly), }; sc.set_plugin(plugin);