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
1242e8ca
Commit
1242e8ca
authored
May 24, 2017
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor improvement for memory allocations
parent
cc432dbc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
proxier.go
pkg/proxy/iptables/proxier.go
+18
-4
save_restore.go
pkg/util/iptables/save_restore.go
+3
-1
No files found.
pkg/proxy/iptables/proxier.go
View file @
1242e8ca
...
@@ -156,6 +156,14 @@ type endpointsInfo struct {
...
@@ -156,6 +156,14 @@ type endpointsInfo struct {
isLocal
bool
isLocal
bool
}
}
// Returns just the IP part of the endpoint.
func
(
e
*
endpointsInfo
)
IPPart
()
string
{
if
index
:=
strings
.
Index
(
e
.
endpoint
,
":"
);
index
!=
-
1
{
return
e
.
endpoint
[
0
:
index
]
}
return
e
.
endpoint
}
func
(
e
*
endpointsInfo
)
String
()
string
{
func
(
e
*
endpointsInfo
)
String
()
string
{
return
fmt
.
Sprintf
(
"%v"
,
*
e
)
return
fmt
.
Sprintf
(
"%v"
,
*
e
)
}
}
...
@@ -751,8 +759,7 @@ func getLocalIPs(endpointsMap proxyEndpointsMap) map[types.NamespacedName]sets.S
...
@@ -751,8 +759,7 @@ func getLocalIPs(endpointsMap proxyEndpointsMap) map[types.NamespacedName]sets.S
if
localIPs
[
nsn
]
==
nil
{
if
localIPs
[
nsn
]
==
nil
{
localIPs
[
nsn
]
=
sets
.
NewString
()
localIPs
[
nsn
]
=
sets
.
NewString
()
}
}
ip
:=
strings
.
Split
(
ep
.
endpoint
,
":"
)[
0
]
// just the IP part
localIPs
[
nsn
]
.
Insert
(
ep
.
IPPart
())
// just the IP part
localIPs
[
nsn
]
.
Insert
(
ip
)
}
}
}
}
}
}
...
@@ -873,6 +880,13 @@ type endpointServicePair struct {
...
@@ -873,6 +880,13 @@ type endpointServicePair struct {
servicePortName
proxy
.
ServicePortName
servicePortName
proxy
.
ServicePortName
}
}
func
(
esp
*
endpointServicePair
)
IPPart
()
string
{
if
index
:=
strings
.
Index
(
esp
.
endpoint
,
":"
);
index
!=
-
1
{
return
esp
.
endpoint
[
0
:
index
]
}
return
esp
.
endpoint
}
const
noConnectionToDelete
=
"0 flow entries have been deleted"
const
noConnectionToDelete
=
"0 flow entries have been deleted"
// After a UDP endpoint has been removed, we must flush any pending conntrack entries to it, or else we
// After a UDP endpoint has been removed, we must flush any pending conntrack entries to it, or else we
...
@@ -881,7 +895,7 @@ const noConnectionToDelete = "0 flow entries have been deleted"
...
@@ -881,7 +895,7 @@ const noConnectionToDelete = "0 flow entries have been deleted"
func
(
proxier
*
Proxier
)
deleteEndpointConnections
(
connectionMap
map
[
endpointServicePair
]
bool
)
{
func
(
proxier
*
Proxier
)
deleteEndpointConnections
(
connectionMap
map
[
endpointServicePair
]
bool
)
{
for
epSvcPair
:=
range
connectionMap
{
for
epSvcPair
:=
range
connectionMap
{
if
svcInfo
,
ok
:=
proxier
.
serviceMap
[
epSvcPair
.
servicePortName
];
ok
&&
svcInfo
.
protocol
==
api
.
ProtocolUDP
{
if
svcInfo
,
ok
:=
proxier
.
serviceMap
[
epSvcPair
.
servicePortName
];
ok
&&
svcInfo
.
protocol
==
api
.
ProtocolUDP
{
endpointIP
:=
strings
.
Split
(
epSvcPair
.
endpoint
,
":"
)[
0
]
endpointIP
:=
epSvcPair
.
endpoint
[
0
:
strings
.
Index
(
epSvcPair
.
endpoint
,
":"
)
]
glog
.
V
(
2
)
.
Infof
(
"Deleting connection tracking state for service IP %s, endpoint IP %s"
,
svcInfo
.
clusterIP
.
String
(),
endpointIP
)
glog
.
V
(
2
)
.
Infof
(
"Deleting connection tracking state for service IP %s, endpoint IP %s"
,
svcInfo
.
clusterIP
.
String
(),
endpointIP
)
err
:=
utilproxy
.
ExecConntrackTool
(
proxier
.
exec
,
"-D"
,
"--orig-dst"
,
svcInfo
.
clusterIP
.
String
(),
"--dst-nat"
,
endpointIP
,
"-p"
,
"udp"
)
err
:=
utilproxy
.
ExecConntrackTool
(
proxier
.
exec
,
"-D"
,
"--orig-dst"
,
svcInfo
.
clusterIP
.
String
(),
"--dst-nat"
,
endpointIP
,
"-p"
,
"udp"
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
noConnectionToDelete
)
{
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
noConnectionToDelete
)
{
...
@@ -1371,7 +1385,7 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1371,7 +1385,7 @@ func (proxier *Proxier) syncProxyRules() {
}
}
// Handle traffic that loops back to the originator with SNAT.
// Handle traffic that loops back to the originator with SNAT.
writeLine
(
proxier
.
natRules
,
append
(
args
,
writeLine
(
proxier
.
natRules
,
append
(
args
,
"-s"
,
fmt
.
Sprintf
(
"%s/32"
,
strings
.
Split
(
endpoints
[
i
]
.
endpoint
,
":"
)[
0
]
),
"-s"
,
fmt
.
Sprintf
(
"%s/32"
,
endpoints
[
i
]
.
IPPart
()
),
"-j"
,
string
(
KubeMarkMasqChain
))
...
)
"-j"
,
string
(
KubeMarkMasqChain
))
...
)
// Update client-affinity lists.
// Update client-affinity lists.
if
svcInfo
.
sessionAffinityType
==
api
.
ServiceAffinityClientIP
{
if
svcInfo
.
sessionAffinityType
==
api
.
ServiceAffinityClientIP
{
...
...
pkg/util/iptables/save_restore.go
View file @
1242e8ca
...
@@ -52,7 +52,9 @@ func GetChainLines(table Table, save []byte) map[Chain]string {
...
@@ -52,7 +52,9 @@ func GetChainLines(table Table, save []byte) map[Chain]string {
}
else
if
strings
.
HasPrefix
(
line
,
"#"
)
{
}
else
if
strings
.
HasPrefix
(
line
,
"#"
)
{
continue
continue
}
else
if
strings
.
HasPrefix
(
line
,
":"
)
&&
len
(
line
)
>
1
{
}
else
if
strings
.
HasPrefix
(
line
,
":"
)
&&
len
(
line
)
>
1
{
chain
:=
Chain
(
strings
.
SplitN
(
line
[
1
:
],
" "
,
2
)[
0
])
// We assume that the <line> contains space - chain lines have 3 fields,
// space delimited. If there is no space, this line will panic.
chain
:=
Chain
(
line
[
1
:
strings
.
Index
(
line
,
" "
)])
chainsMap
[
chain
]
=
line
chainsMap
[
chain
]
=
line
}
}
}
}
...
...
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