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
d72892d0
Commit
d72892d0
authored
Aug 14, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include protocol in the hash for chain names
parent
731d5e51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
15 deletions
+16
-15
proxier.go
pkg/proxy/iptables/proxier.go
+16
-15
No files found.
pkg/proxy/iptables/proxier.go
View file @
d72892d0
...
...
@@ -384,22 +384,23 @@ func flattenValidEndpoints(endpoints []hostPortPair) []string {
return
result
}
// servicePortToServiceChain takes the ServicePortName for a
//
service and returns the associated iptables chain
// th
is is computed by hashing (sha256) then encoding to base64 and
// t
runcating with the prefix "KUBE-SVC-"
//
We do this because Iptables Chain Names must be <= 28 chars long
func
servicePortToServiceChain
(
s
proxy
.
ServicePortName
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()))
// servicePortToServiceChain takes the ServicePortName for a
service and
//
returns the associated iptables chain. This is computed by hashing (sha256)
// th
en encoding to base32 and truncating with the prefix "KUBE-SVC-". We do
// t
his because Iptables Chain Names must be <= 28 chars long, and the longer
//
they are the harder they are to read.
func
servicePortToServiceChain
(
s
proxy
.
ServicePortName
,
protocol
string
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()
+
protocol
))
encoded
:=
base32
.
StdEncoding
.
EncodeToString
(
hash
[
:
])
return
utiliptables
.
Chain
(
"KUBE-SVC-"
+
encoded
[
:
1
9
])
return
utiliptables
.
Chain
(
"KUBE-SVC-"
+
encoded
[
:
1
6
])
}
// this is the same as servicePortToServiceChain but with the endpoint included essentially
func
servicePortAndEndpointToServiceChain
(
s
proxy
.
ServicePortName
,
endpoint
string
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()
+
"_"
+
endpoint
))
// This is the same as servicePortToServiceChain but with the endpoint
// included.
func
servicePortAndEndpointToServiceChain
(
s
proxy
.
ServicePortName
,
protocol
string
,
endpoint
string
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()
+
protocol
+
endpoint
))
encoded
:=
base32
.
StdEncoding
.
EncodeToString
(
hash
[
:
])
return
utiliptables
.
Chain
(
"KUBE-SEP-"
+
encoded
[
:
1
9
])
return
utiliptables
.
Chain
(
"KUBE-SEP-"
+
encoded
[
:
1
6
])
}
// This is where all of the iptables-save/restore calls happen.
...
...
@@ -480,10 +481,10 @@ func (proxier *Proxier) syncProxyRules() error {
// Build rules for each service.
for
name
,
info
:=
range
proxier
.
serviceMap
{
protocol
:=
strings
.
ToLower
(
(
string
)
(
info
.
protocol
))
protocol
:=
strings
.
ToLower
(
string
(
info
.
protocol
))
// Create the per-service chain, retaining counters if possible.
svcChain
:=
servicePortToServiceChain
(
name
)
svcChain
:=
servicePortToServiceChain
(
name
,
protocol
)
if
chain
,
ok
:=
existingChains
[
svcChain
];
ok
{
writeLine
(
chainsLines
,
chain
)
}
else
{
...
...
@@ -560,7 +561,7 @@ func (proxier *Proxier) syncProxyRules() error {
endpointChains
:=
make
([]
utiliptables
.
Chain
,
0
)
for
_
,
ep
:=
range
info
.
endpoints
{
endpoints
=
append
(
endpoints
,
ep
)
endpointChain
:=
servicePortAndEndpointToServiceChain
(
name
,
ep
)
endpointChain
:=
servicePortAndEndpointToServiceChain
(
name
,
protocol
,
ep
)
endpointChains
=
append
(
endpointChains
,
endpointChain
)
// Create the endpoint chain, retaining counters if possible.
...
...
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