Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3e471378
Commit
3e471378
authored
May 12, 2015
by
Derek Carr
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7436 from akram/fix_port_forward_listens_ipv_and_ipv4
Port forward now listens on IPv4 and IPv6 localhost address
parents
c0f04f36
a788002d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
22 deletions
+23
-22
portforward.go
pkg/client/portforward/portforward.go
+15
-6
portforward_test.go
pkg/client/portforward/portforward_test.go
+8
-16
No files found.
pkg/client/portforward/portforward.go
View file @
3e471378
...
...
@@ -183,17 +183,26 @@ func (pf *PortForwarder) forward() error {
return
nil
}
// listenOnPort delegates
listener creation and waits for new connections
//
in the backgroun
d.
// listenOnPort delegates
tcp4 and tcp6 listener creation and waits for connections on both of these addresses.
//
If both listener creation fail, an error is raise
d.
func
(
pf
*
PortForwarder
)
listenOnPort
(
port
*
ForwardedPort
)
error
{
listener
,
err
:=
pf
.
getListener
(
"tcp"
,
"localhost"
,
port
)
errTcp4
:=
pf
.
listenOnPortAndAddress
(
port
,
"tcp4"
,
"127.0.0.1"
)
errTcp6
:=
pf
.
listenOnPortAndAddress
(
port
,
"tcp6"
,
"[::1]"
)
if
errTcp4
!=
nil
&&
errTcp6
!=
nil
{
return
fmt
.
Errorf
(
"All listeners failed to create with the following errors: %s, %s"
,
errTcp4
,
errTcp6
)
}
return
nil
}
// listenOnPortAndAddress delegates listener creation and waits for new connections
// in the background f
func
(
pf
*
PortForwarder
)
listenOnPortAndAddress
(
port
*
ForwardedPort
,
protocol
string
,
address
string
)
error
{
listener
,
err
:=
pf
.
getListener
(
protocol
,
address
,
port
)
if
err
!=
nil
{
return
err
}
pf
.
listeners
=
append
(
pf
.
listeners
,
listener
)
go
pf
.
waitForConnection
(
listener
,
*
port
)
return
nil
}
...
...
@@ -213,7 +222,7 @@ func (pf *PortForwarder) getListener(protocol string, hostname string, port *For
return
nil
,
fmt
.
Errorf
(
"Error parsing local port: %s from %s (%s)"
,
err
,
listenerAddress
,
host
)
}
port
.
Local
=
uint16
(
localPortUInt
)
glog
.
Infof
(
"Forwarding from %
d -> %d"
,
localPortUInt
,
port
.
Remote
)
glog
.
Infof
(
"Forwarding from %
s:%d -> %d"
,
hostname
,
localPortUInt
,
port
.
Remote
)
return
listener
,
nil
}
...
...
pkg/client/portforward/portforward_test.go
View file @
3e471378
...
...
@@ -209,7 +209,7 @@ func (s *fakeUpgradeStream) Headers() http.Header {
return
http
.
Header
{}
}
type
TestCase
struct
{
type
GetListener
TestCase
struct
{
Hostname
string
Protocol
string
ShouldRaiseError
bool
...
...
@@ -218,7 +218,7 @@ type TestCase struct {
func
TestGetListener
(
t
*
testing
.
T
)
{
var
pf
PortForwarder
testCases
:=
[]
TestCase
{
testCases
:=
[]
GetListener
TestCase
{
{
Hostname
:
"localhost"
,
Protocol
:
"tcp4"
,
...
...
@@ -247,20 +247,12 @@ func TestGetListener(t *testing.T) {
Protocol
:
"tcp6"
,
ShouldRaiseError
:
true
,
},
}
// On some linux systems, ::1 does not resolve to localhost but to localhost6 or
// ip6-localhost. To make the test case portable, we need to do a reverse lookup on ::1 and
// trying to bind a port with the name.
names
,
err
:=
net
.
LookupAddr
(
"::1"
)
if
err
==
nil
&&
len
(
names
)
>
0
{
ipv6TestCase
:=
TestCase
{
Hostname
:
names
[
0
],
Protocol
:
"tcp6"
,
ShouldRaiseError
:
false
,
ExpectedListenerAddress
:
"::1"
,
}
testCases
=
append
(
testCases
,
ipv6TestCase
)
{
// IPv6 address must be put into brackets. This test reveals this.
Hostname
:
"::1"
,
Protocol
:
"tcp6"
,
ShouldRaiseError
:
true
,
},
}
for
i
,
testCase
:=
range
testCases
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment