Skip to content

Commit c6ff7b9

Browse files
authored
fixed configure's outbound port behavior (#47)
1 parent b8825f9 commit c6ff7b9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/cmd/configure.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func init() {
7777

7878
configureCmd.Flags().StringSliceVarP(&configureCmdArgs.allowedIPs, "routes", "r", configureCmdArgs.allowedIPs, "[REQUIRED] CIDR IP ranges that will be routed through wiretap (example \"10.0.0.1/24\")")
7979
configureCmd.Flags().StringVarP(&configureCmdArgs.endpoint, "endpoint", "e", configureCmdArgs.endpoint, "[REQUIRED] IP:PORT (or [IP]:PORT for IPv6) of wireguard listener that server will connect to (example \"1.2.3.4:51820\")")
80-
configureCmd.Flags().BoolVar(&configureCmdArgs.outbound, "outbound", configureCmdArgs.outbound, "client will initiate handshake to server; --endpoint now specifies server's listening socket instead of client's")
81-
configureCmd.Flags().IntVarP(&configureCmdArgs.port, "port", "p", configureCmdArgs.port, "listener port for local wireguard relay; default is to use the same port specified by --endpoint")
80+
configureCmd.Flags().BoolVar(&configureCmdArgs.outbound, "outbound", configureCmdArgs.outbound, "client will initiate handshake to server; --endpoint now specifies server's listening socket instead of client's, and --port assigns the server's listening port instead of client's")
81+
configureCmd.Flags().IntVarP(&configureCmdArgs.port, "port", "p", configureCmdArgs.port, "listener port for wireguard relay. Default is to copy the --endpoint port. If --outbound, sets port for the server; else for the client.")
8282
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileRelay, "relay-output", "", configureCmdArgs.configFileRelay, "wireguard relay config output filename")
8383
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileE2EE, "e2ee-output", "", configureCmdArgs.configFileE2EE, "wireguard E2EE config output filename")
8484
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileServer, "server-output", "s", configureCmdArgs.configFileServer, "wiretap server config output filename")
@@ -175,15 +175,28 @@ func (c configureCmdConfig) Run() {
175175
}
176176

177177
if c.port == USE_ENDPOINT_PORT {
178-
c.port = portFromEndpoint(c.endpoint);
178+
c.port = portFromEndpoint(c.endpoint)
179179
}
180180

181-
err = serverConfigRelay.SetPort(Port)
181+
// We only configure one of these (based on --outbound or not)
182+
// The other must be manually changed in the configs/command/envs
183+
var clientPort int;
184+
var serverPort int;
185+
186+
if c.outbound {
187+
clientPort = Port
188+
serverPort = c.port
189+
} else {
190+
clientPort = c.port
191+
serverPort = Port
192+
}
193+
194+
err = serverConfigRelay.SetPort(serverPort)
182195
check("failed to set port", err)
183196

184197

185198
clientConfigRelayArgs := peer.ConfigArgs{
186-
ListenPort: c.port,
199+
ListenPort: clientPort,
187200
Peers: []peer.PeerConfigArgs{
188201
{
189202
PublicKey: serverConfigRelay.GetPublicKey(),

0 commit comments

Comments
 (0)