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
d14c98f6
Commit
d14c98f6
authored
Aug 14, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add nodepoprt chain and link it in, add unused MASQ rule
parent
60e17a54
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
12 deletions
+37
-12
proxier.go
pkg/proxy/iptables/proxier.go
+37
-12
No files found.
pkg/proxy/iptables/proxier.go
View file @
d14c98f6
...
@@ -48,12 +48,16 @@ import (
...
@@ -48,12 +48,16 @@ import (
// features are backported in various distros and this could get pretty hairy.
// features are backported in various distros and this could get pretty hairy.
// However iptables-1.4.0 was released 2007-Dec-22 and appears to have every feature we use,
// However iptables-1.4.0 was released 2007-Dec-22 and appears to have every feature we use,
// so this seems prefectly reasonable for now.
// so this seems prefectly reasonable for now.
const
(
const
IPTABLES_MIN_VERSION
string
=
"1.4.0"
IPTABLES_MIN_VERSION
string
=
"1.4.0"
)
// the services chain
// the services chain
var
iptablesServicesChain
utiliptables
.
Chain
=
"KUBE-SERVICES"
const
iptablesServicesChain
utiliptables
.
Chain
=
"KUBE-SERVICES"
// the nodeports chain
const
iptablesNodePortsChain
utiliptables
.
Chain
=
"KUBE-NODEPORTS"
// the mark we apply to traffic needing SNAT
const
iptablesMasqueradeMark
=
"0x4d415351"
// ShouldUseIptablesProxier returns true if we should use the iptables Proxier instead of
// ShouldUseIptablesProxier returns true if we should use the iptables Proxier instead of
// the userspace Proxier.
// the userspace Proxier.
...
@@ -411,16 +415,37 @@ func (proxier *Proxier) syncProxyRules() error {
...
@@ -411,16 +415,37 @@ func (proxier *Proxier) syncProxyRules() error {
}
}
glog
.
V
(
4
)
.
Infof
(
"Syncing iptables rules."
)
glog
.
V
(
4
)
.
Infof
(
"Syncing iptables rules."
)
// ensure main chain and rule connecting to output
// Ensure main chains and rules are installed.
args
:=
[]
string
{
"-j"
,
string
(
iptablesServicesChain
)}
inputChains
:=
[]
utiliptables
.
Chain
{
utiliptables
.
ChainOutput
,
utiliptables
.
ChainPrerouting
}
if
_
,
err
:=
proxier
.
iptables
.
EnsureChain
(
utiliptables
.
TableNAT
,
iptablesServicesChain
);
err
!=
nil
{
// Link the services chain.
return
err
for
_
,
chain
:=
range
inputChains
{
if
_
,
err
:=
proxier
.
iptables
.
EnsureChain
(
utiliptables
.
TableNAT
,
iptablesServicesChain
);
err
!=
nil
{
return
err
}
comment
:=
"kubernetes service portals; must be before nodeports"
args
:=
[]
string
{
"-m"
,
"comment"
,
"--comment"
,
comment
,
"-j"
,
string
(
iptablesServicesChain
)}
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Prepend
,
utiliptables
.
TableNAT
,
chain
,
args
...
);
err
!=
nil
{
return
err
}
}
}
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Prepend
,
utiliptables
.
TableNAT
,
utiliptables
.
ChainOutput
,
args
...
);
err
!=
nil
{
// Link the nodeports chain.
return
err
for
_
,
chain
:=
range
inputChains
{
if
_
,
err
:=
proxier
.
iptables
.
EnsureChain
(
utiliptables
.
TableNAT
,
iptablesNodePortsChain
);
err
!=
nil
{
return
err
}
comment
:=
"kubernetes service nodeports; must be after portals"
args
:=
[]
string
{
"-m"
,
"comment"
,
"--comment"
,
comment
,
"-m"
,
"addrtype"
,
"--dst-type"
,
"LOCAL"
,
"-j"
,
string
(
iptablesNodePortsChain
)}
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Append
,
utiliptables
.
TableNAT
,
chain
,
args
...
);
err
!=
nil
{
return
err
}
}
}
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Prepend
,
utiliptables
.
TableNAT
,
utiliptables
.
ChainPrerouting
,
args
...
);
err
!=
nil
{
// Link the output rules.
return
err
{
comment
:=
"kubernetes service traffic requiring SNAT"
args
:=
[]
string
{
"-m"
,
"comment"
,
"--comment"
,
comment
,
"-m"
,
"mark"
,
"--mark"
,
iptablesMasqueradeMark
,
"-j"
,
"MASQUERADE"
}
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Append
,
utiliptables
.
TableNAT
,
utiliptables
.
ChainPostrouting
,
args
...
);
err
!=
nil
{
return
err
}
}
}
// Get iptables-save output so we can check for existing chains and rules.
// Get iptables-save output so we can check for existing chains and rules.
...
...
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