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 {
...
@@ -384,22 +384,23 @@ func flattenValidEndpoints(endpoints []hostPortPair) []string {
return
result
return
result
}
}
// servicePortToServiceChain takes the ServicePortName for a
// servicePortToServiceChain takes the ServicePortName for a
service and
//
service and returns the associated iptables chain
//
returns the associated iptables chain. This is computed by hashing (sha256)
// th
is is computed by hashing (sha256) then encoding to base64 and
// th
en encoding to base32 and truncating with the prefix "KUBE-SVC-". We do
// t
runcating with the prefix "KUBE-SVC-"
// t
his because Iptables Chain Names must be <= 28 chars long, and the longer
//
We do this because Iptables Chain Names must be <= 28 chars long
//
they are the harder they are to read.
func
servicePortToServiceChain
(
s
proxy
.
ServicePortName
)
utiliptables
.
Chain
{
func
servicePortToServiceChain
(
s
proxy
.
ServicePortName
,
protocol
string
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()))
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()
+
protocol
))
encoded
:=
base32
.
StdEncoding
.
EncodeToString
(
hash
[
:
])
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
// This is the same as servicePortToServiceChain but with the endpoint
func
servicePortAndEndpointToServiceChain
(
s
proxy
.
ServicePortName
,
endpoint
string
)
utiliptables
.
Chain
{
// included.
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()
+
"_"
+
endpoint
))
func
servicePortAndEndpointToServiceChain
(
s
proxy
.
ServicePortName
,
protocol
string
,
endpoint
string
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
s
.
String
()
+
protocol
+
endpoint
))
encoded
:=
base32
.
StdEncoding
.
EncodeToString
(
hash
[
:
])
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.
// This is where all of the iptables-save/restore calls happen.
...
@@ -480,10 +481,10 @@ func (proxier *Proxier) syncProxyRules() error {
...
@@ -480,10 +481,10 @@ func (proxier *Proxier) syncProxyRules() error {
// Build rules for each service.
// Build rules for each service.
for
name
,
info
:=
range
proxier
.
serviceMap
{
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.
// Create the per-service chain, retaining counters if possible.
svcChain
:=
servicePortToServiceChain
(
name
)
svcChain
:=
servicePortToServiceChain
(
name
,
protocol
)
if
chain
,
ok
:=
existingChains
[
svcChain
];
ok
{
if
chain
,
ok
:=
existingChains
[
svcChain
];
ok
{
writeLine
(
chainsLines
,
chain
)
writeLine
(
chainsLines
,
chain
)
}
else
{
}
else
{
...
@@ -560,7 +561,7 @@ func (proxier *Proxier) syncProxyRules() error {
...
@@ -560,7 +561,7 @@ func (proxier *Proxier) syncProxyRules() error {
endpointChains
:=
make
([]
utiliptables
.
Chain
,
0
)
endpointChains
:=
make
([]
utiliptables
.
Chain
,
0
)
for
_
,
ep
:=
range
info
.
endpoints
{
for
_
,
ep
:=
range
info
.
endpoints
{
endpoints
=
append
(
endpoints
,
ep
)
endpoints
=
append
(
endpoints
,
ep
)
endpointChain
:=
servicePortAndEndpointToServiceChain
(
name
,
ep
)
endpointChain
:=
servicePortAndEndpointToServiceChain
(
name
,
protocol
,
ep
)
endpointChains
=
append
(
endpointChains
,
endpointChain
)
endpointChains
=
append
(
endpointChains
,
endpointChain
)
// Create the endpoint chain, retaining counters if possible.
// 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