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
2ec87999
Commit
2ec87999
authored
Mar 20, 2017
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Install a REJECT rule for nodeport with no backend
Rather than actually accepting the connection, REJECT. This will avoid CLOSE_WAIT.
parent
e668ee11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
proxier.go
pkg/proxy/iptables/proxier.go
+17
-0
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+19
-0
No files found.
pkg/proxy/iptables/proxier.go
View file @
2ec87999
...
@@ -1108,6 +1108,21 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1108,6 +1108,21 @@ func (proxier *Proxier) syncProxyRules() {
// Currently we only create it for loadbalancers (#33586).
// Currently we only create it for loadbalancers (#33586).
writeLine
(
natRules
,
append
(
args
,
"-j"
,
string
(
svcXlbChain
))
...
)
writeLine
(
natRules
,
append
(
args
,
"-j"
,
string
(
svcXlbChain
))
...
)
}
}
// If the service has no endpoints then reject packets. The filter
// table doesn't currently have the same per-service structure that
// the nat table does, so we just stick this into the kube-services
// chain.
if
len
(
proxier
.
endpointsMap
[
svcName
])
==
0
{
writeLine
(
filterRules
,
"-A"
,
string
(
kubeServicesChain
),
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"%s has no endpoints"`
,
svcName
.
String
()),
"-m"
,
"addrtype"
,
"--dst-type"
,
"LOCAL"
,
"-m"
,
protocol
,
"-p"
,
protocol
,
"--dport"
,
fmt
.
Sprintf
(
"%d"
,
svcInfo
.
nodePort
),
"-j"
,
"REJECT"
,
)
}
}
}
// If the service has no endpoints then reject packets.
// If the service has no endpoints then reject packets.
...
@@ -1123,6 +1138,8 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1123,6 +1138,8 @@ func (proxier *Proxier) syncProxyRules() {
continue
continue
}
}
// From here on, we assume there are active endpoints.
// Generate the per-endpoint chains. We do this in multiple passes so we
// Generate the per-endpoint chains. We do this in multiple passes so we
// can group rules together.
// can group rules together.
// These two slices parallel each other - keep in sync
// These two slices parallel each other - keep in sync
...
...
pkg/proxy/iptables/proxier_test.go
View file @
2ec87999
...
@@ -694,6 +694,25 @@ func TestNodePort(t *testing.T) {
...
@@ -694,6 +694,25 @@ func TestNodePort(t *testing.T) {
}
}
}
}
func
TestNodePortReject
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
)
svcName
:=
"svc1"
svcIP
:=
net
.
IPv4
(
10
,
20
,
30
,
41
)
svc
:=
proxy
.
ServicePortName
{
NamespacedName
:
types
.
NamespacedName
{
Namespace
:
"ns1"
,
Name
:
svcName
},
Port
:
"p80"
}
svcInfo
:=
newFakeServiceInfo
(
svc
,
svcIP
,
80
,
api
.
ProtocolTCP
,
false
)
svcInfo
.
nodePort
=
3001
fp
.
serviceMap
[
svc
]
=
svcInfo
fp
.
syncProxyRules
()
kubeSvcRules
:=
ipt
.
GetRules
(
string
(
kubeServicesChain
))
if
!
hasJump
(
kubeSvcRules
,
iptablestest
.
Reject
,
svcIP
.
String
(),
3001
)
{
errorf
(
fmt
.
Sprintf
(
"Failed to find a %v rule for service %v with no endpoints"
,
iptablestest
.
Reject
,
svcName
),
kubeSvcRules
,
t
)
}
}
func
strPtr
(
s
string
)
*
string
{
func
strPtr
(
s
string
)
*
string
{
return
&
s
return
&
s
}
}
...
...
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