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
28000f92
Commit
28000f92
authored
Oct 30, 2017
by
m1093782566
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix IPV6 judgement bug and add UTs
parent
5ad34ac6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
8 deletions
+109
-8
proxier.go
pkg/proxy/iptables/proxier.go
+1
-1
proxier.go
pkg/proxy/ipvs/proxier.go
+1
-1
conntrack.go
pkg/proxy/util/conntrack.go
+8
-4
conntrack_test.go
pkg/proxy/util/conntrack_test.go
+99
-2
No files found.
pkg/proxy/iptables/proxier.go
View file @
28000f92
...
@@ -1343,7 +1343,7 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1343,7 +1343,7 @@ func (proxier *Proxier) syncProxyRules() {
// This is very low impact. The NodePort range is intentionally obscure, and unlikely to actually collide with real Services.
// This is very low impact. The NodePort range is intentionally obscure, and unlikely to actually collide with real Services.
// This only affects UDP connections, which are not common.
// This only affects UDP connections, which are not common.
// See issue: https://github.com/kubernetes/kubernetes/issues/49881
// See issue: https://github.com/kubernetes/kubernetes/issues/49881
isIPv6
:=
svcInfo
.
clusterIP
.
To4
()
!=
nil
isIPv6
:=
utilproxy
.
IsIPv6
(
svcInfo
.
clusterIP
)
err
:=
utilproxy
.
ClearUDPConntrackForPort
(
proxier
.
exec
,
lp
.
Port
,
isIPv6
)
err
:=
utilproxy
.
ClearUDPConntrackForPort
(
proxier
.
exec
,
lp
.
Port
,
isIPv6
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to clear udp conntrack for port %d, error: %v"
,
lp
.
Port
,
err
)
glog
.
Errorf
(
"Failed to clear udp conntrack for port %d, error: %v"
,
lp
.
Port
,
err
)
...
...
pkg/proxy/ipvs/proxier.go
View file @
28000f92
...
@@ -1154,7 +1154,7 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1154,7 +1154,7 @@ func (proxier *Proxier) syncProxyRules() {
continue
continue
}
}
if
lp
.
Protocol
==
"udp"
{
if
lp
.
Protocol
==
"udp"
{
isIPv6
:=
svcInfo
.
clusterIP
.
To4
()
!=
nil
isIPv6
:=
utilproxy
.
IsIPv6
(
svcInfo
.
clusterIP
)
utilproxy
.
ClearUDPConntrackForPort
(
proxier
.
exec
,
lp
.
Port
,
isIPv6
)
utilproxy
.
ClearUDPConntrackForPort
(
proxier
.
exec
,
lp
.
Port
,
isIPv6
)
}
}
replacementPortsMap
[
lp
]
=
socket
replacementPortsMap
[
lp
]
=
socket
...
...
pkg/proxy/util/conntrack.go
View file @
28000f92
...
@@ -29,11 +29,15 @@ import (
...
@@ -29,11 +29,15 @@ import (
const
noConnectionToDelete
=
"0 flow entries have been deleted"
const
noConnectionToDelete
=
"0 flow entries have been deleted"
func
isIPv6
(
ip
string
)
bool
{
func
IsIPv6
(
netIP
net
.
IP
)
bool
{
netIP
:=
net
.
ParseIP
(
ip
)
return
netIP
!=
nil
&&
netIP
.
To4
()
==
nil
return
netIP
!=
nil
&&
netIP
.
To4
()
==
nil
}
}
func
IsIPv6String
(
ip
string
)
bool
{
netIP
:=
net
.
ParseIP
(
ip
)
return
IsIPv6
(
netIP
)
}
func
parametersWithFamily
(
isIPv6
bool
,
parameters
...
string
)
[]
string
{
func
parametersWithFamily
(
isIPv6
bool
,
parameters
...
string
)
[]
string
{
if
isIPv6
{
if
isIPv6
{
parameters
=
append
(
parameters
,
"-f"
,
"ipv6"
)
parameters
=
append
(
parameters
,
"-f"
,
"ipv6"
)
...
@@ -44,7 +48,7 @@ func parametersWithFamily(isIPv6 bool, parameters ...string) []string {
...
@@ -44,7 +48,7 @@ func parametersWithFamily(isIPv6 bool, parameters ...string) []string {
// ClearUDPConntrackForIP uses the conntrack tool to delete the conntrack entries
// ClearUDPConntrackForIP uses the conntrack tool to delete the conntrack entries
// for the UDP connections specified by the given service IP
// for the UDP connections specified by the given service IP
func
ClearUDPConntrackForIP
(
execer
exec
.
Interface
,
ip
string
)
error
{
func
ClearUDPConntrackForIP
(
execer
exec
.
Interface
,
ip
string
)
error
{
parameters
:=
parametersWithFamily
(
isIPv6
(
ip
),
"-D"
,
"--orig-dst"
,
ip
,
"-p"
,
"udp"
)
parameters
:=
parametersWithFamily
(
IsIPv6String
(
ip
),
"-D"
,
"--orig-dst"
,
ip
,
"-p"
,
"udp"
)
err
:=
ExecConntrackTool
(
execer
,
parameters
...
)
err
:=
ExecConntrackTool
(
execer
,
parameters
...
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
noConnectionToDelete
)
{
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
noConnectionToDelete
)
{
// TODO: Better handling for deletion failure. When failure occur, stale udp connection may not get flushed.
// TODO: Better handling for deletion failure. When failure occur, stale udp connection may not get flushed.
...
@@ -89,7 +93,7 @@ func ClearUDPConntrackForPort(execer exec.Interface, port int, isIPv6 bool) erro
...
@@ -89,7 +93,7 @@ func ClearUDPConntrackForPort(execer exec.Interface, port int, isIPv6 bool) erro
// ClearUDPConntrackForPeers uses the conntrack tool to delete the conntrack entries
// ClearUDPConntrackForPeers uses the conntrack tool to delete the conntrack entries
// for the UDP connections specified by the {origin, dest} IP pair.
// for the UDP connections specified by the {origin, dest} IP pair.
func
ClearUDPConntrackForPeers
(
execer
exec
.
Interface
,
origin
,
dest
string
)
error
{
func
ClearUDPConntrackForPeers
(
execer
exec
.
Interface
,
origin
,
dest
string
)
error
{
parameters
:=
parametersWithFamily
(
isIPv6
(
origin
),
"-D"
,
"--orig-dst"
,
origin
,
"--dst-nat"
,
dest
,
"-p"
,
"udp"
)
parameters
:=
parametersWithFamily
(
IsIPv6String
(
origin
),
"-D"
,
"--orig-dst"
,
origin
,
"--dst-nat"
,
dest
,
"-p"
,
"udp"
)
err
:=
ExecConntrackTool
(
execer
,
parameters
...
)
err
:=
ExecConntrackTool
(
execer
,
parameters
...
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
noConnectionToDelete
)
{
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
noConnectionToDelete
)
{
// TODO: Better handling for deletion failure. When failure occur, stale udp connection may not get flushed.
// TODO: Better handling for deletion failure. When failure occur, stale udp connection may not get flushed.
...
...
pkg/proxy/util/conntrack_test.go
View file @
28000f92
...
@@ -18,6 +18,7 @@ package util
...
@@ -18,6 +18,7 @@ package util
import
(
import
(
"fmt"
"fmt"
"net"
"strings"
"strings"
"testing"
"testing"
...
@@ -117,7 +118,7 @@ func TestClearUDPConntrackForIP(t *testing.T) {
...
@@ -117,7 +118,7 @@ func TestClearUDPConntrackForIP(t *testing.T) {
if
err
:=
ClearUDPConntrackForIP
(
&
fexec
,
tc
.
ip
);
err
!=
nil
{
if
err
:=
ClearUDPConntrackForIP
(
&
fexec
,
tc
.
ip
);
err
!=
nil
{
t
.
Errorf
(
"%s test case:, Unexpected error: %v"
,
tc
.
name
,
err
)
t
.
Errorf
(
"%s test case:, Unexpected error: %v"
,
tc
.
name
,
err
)
}
}
expectCommand
:=
fmt
.
Sprintf
(
"conntrack -D --orig-dst %s -p udp"
,
tc
.
ip
)
+
familyParamStr
(
isIPv6
(
tc
.
ip
))
expectCommand
:=
fmt
.
Sprintf
(
"conntrack -D --orig-dst %s -p udp"
,
tc
.
ip
)
+
familyParamStr
(
IsIPv6String
(
tc
.
ip
))
execCommand
:=
strings
.
Join
(
fcmd
.
CombinedOutputLog
[
svcCount
],
" "
)
execCommand
:=
strings
.
Join
(
fcmd
.
CombinedOutputLog
[
svcCount
],
" "
)
if
expectCommand
!=
execCommand
{
if
expectCommand
!=
execCommand
{
t
.
Errorf
(
"%s test case: Expect command: %s, but executed %s"
,
tc
.
name
,
expectCommand
,
execCommand
)
t
.
Errorf
(
"%s test case: Expect command: %s, but executed %s"
,
tc
.
name
,
expectCommand
,
execCommand
)
...
@@ -221,7 +222,7 @@ func TestDeleteUDPConnections(t *testing.T) {
...
@@ -221,7 +222,7 @@ func TestDeleteUDPConnections(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"%s test case: unexpected error: %v"
,
tc
.
name
,
err
)
t
.
Errorf
(
"%s test case: unexpected error: %v"
,
tc
.
name
,
err
)
}
}
expectCommand
:=
fmt
.
Sprintf
(
"conntrack -D --orig-dst %s --dst-nat %s -p udp"
,
tc
.
origin
,
tc
.
dest
)
+
familyParamStr
(
isIPv6
(
tc
.
origin
))
expectCommand
:=
fmt
.
Sprintf
(
"conntrack -D --orig-dst %s --dst-nat %s -p udp"
,
tc
.
origin
,
tc
.
dest
)
+
familyParamStr
(
IsIPv6String
(
tc
.
origin
))
execCommand
:=
strings
.
Join
(
fcmd
.
CombinedOutputLog
[
i
],
" "
)
execCommand
:=
strings
.
Join
(
fcmd
.
CombinedOutputLog
[
i
],
" "
)
if
expectCommand
!=
execCommand
{
if
expectCommand
!=
execCommand
{
t
.
Errorf
(
"%s test case: Expect command: %s, but executed %s"
,
tc
.
name
,
expectCommand
,
execCommand
)
t
.
Errorf
(
"%s test case: Expect command: %s, but executed %s"
,
tc
.
name
,
expectCommand
,
execCommand
)
...
@@ -232,3 +233,99 @@ func TestDeleteUDPConnections(t *testing.T) {
...
@@ -232,3 +233,99 @@ func TestDeleteUDPConnections(t *testing.T) {
t
.
Errorf
(
"Expect command executed %d times, but got %d"
,
svcCount
,
fexec
.
CommandCalls
)
t
.
Errorf
(
"Expect command executed %d times, but got %d"
,
svcCount
,
fexec
.
CommandCalls
)
}
}
}
}
func
TestIsIPv6String
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
ip
string
expectIPv6
bool
}{
{
ip
:
"127.0.0.1"
,
expectIPv6
:
false
,
},
{
ip
:
"192.168.0.0"
,
expectIPv6
:
false
,
},
{
ip
:
"1.2.3.4"
,
expectIPv6
:
false
,
},
{
ip
:
"bad ip"
,
expectIPv6
:
false
,
},
{
ip
:
"::1"
,
expectIPv6
:
true
,
},
{
ip
:
"fd00::600d:f00d"
,
expectIPv6
:
true
,
},
{
ip
:
"2001:db8::5"
,
expectIPv6
:
true
,
},
}
for
i
:=
range
testCases
{
isIPv6
:=
IsIPv6String
(
testCases
[
i
]
.
ip
)
if
isIPv6
!=
testCases
[
i
]
.
expectIPv6
{
t
.
Errorf
(
"[%d] Expect ipv6 %v, got %v"
,
i
+
1
,
testCases
[
i
]
.
expectIPv6
,
isIPv6
)
}
}
}
func
TestIsIPv6
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
ip
net
.
IP
expectIPv6
bool
}{
{
ip
:
net
.
IPv4zero
,
expectIPv6
:
false
,
},
{
ip
:
net
.
IPv4bcast
,
expectIPv6
:
false
,
},
{
ip
:
net
.
ParseIP
(
"127.0.0.1"
),
expectIPv6
:
false
,
},
{
ip
:
net
.
ParseIP
(
"10.20.40.40"
),
expectIPv6
:
false
,
},
{
ip
:
net
.
ParseIP
(
"172.17.3.0"
),
expectIPv6
:
false
,
},
{
ip
:
nil
,
expectIPv6
:
false
,
},
{
ip
:
net
.
IPv6loopback
,
expectIPv6
:
true
,
},
{
ip
:
net
.
IPv6zero
,
expectIPv6
:
true
,
},
{
ip
:
net
.
ParseIP
(
"fd00::600d:f00d"
),
expectIPv6
:
true
,
},
{
ip
:
net
.
ParseIP
(
"2001:db8::5"
),
expectIPv6
:
true
,
},
}
for
i
:=
range
testCases
{
isIPv6
:=
IsIPv6
(
testCases
[
i
]
.
ip
)
if
isIPv6
!=
testCases
[
i
]
.
expectIPv6
{
t
.
Errorf
(
"[%d] Expect ipv6 %v, got %v"
,
i
+
1
,
testCases
[
i
]
.
expectIPv6
,
isIPv6
)
}
}
}
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