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
6a3ad1d6
Commit
6a3ad1d6
authored
May 11, 2016
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add hostport support for kubenet
parent
6528a4a6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
108 deletions
+131
-108
kubenet_linux.go
pkg/kubelet/network/kubenet/kubenet_linux.go
+0
-0
proxier.go
pkg/proxy/iptables/proxier.go
+21
-106
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+2
-2
save_restore.go
pkg/util/iptables/save_restore.go
+108
-0
No files found.
pkg/kubelet/network/kubenet/kubenet_linux.go
View file @
6a3ad1d6
This diff is collapsed.
Click to expand it.
pkg/proxy/iptables/proxier.go
View file @
6a3ad1d6
This diff is collapsed.
Click to expand it.
pkg/proxy/iptables/proxier_test.go
View file @
6a3ad1d6
...
@@ -30,7 +30,7 @@ import (
...
@@ -30,7 +30,7 @@ import (
)
)
func
checkAllLines
(
t
*
testing
.
T
,
table
utiliptables
.
Table
,
save
[]
byte
,
expectedLines
map
[
utiliptables
.
Chain
]
string
)
{
func
checkAllLines
(
t
*
testing
.
T
,
table
utiliptables
.
Table
,
save
[]
byte
,
expectedLines
map
[
utiliptables
.
Chain
]
string
)
{
chainLines
:=
g
etChainLines
(
table
,
save
)
chainLines
:=
utiliptables
.
G
etChainLines
(
table
,
save
)
for
chain
,
line
:=
range
chainLines
{
for
chain
,
line
:=
range
chainLines
{
if
expected
,
exists
:=
expectedLines
[
chain
];
exists
{
if
expected
,
exists
:=
expectedLines
[
chain
];
exists
{
if
expected
!=
line
{
if
expected
!=
line
{
...
@@ -47,7 +47,7 @@ func TestReadLinesFromByteBuffer(t *testing.T) {
...
@@ -47,7 +47,7 @@ func TestReadLinesFromByteBuffer(t *testing.T) {
index
:=
0
index
:=
0
readIndex
:=
0
readIndex
:=
0
for
;
readIndex
<
len
(
byteArray
);
index
++
{
for
;
readIndex
<
len
(
byteArray
);
index
++
{
line
,
n
:=
r
eadLine
(
readIndex
,
byteArray
)
line
,
n
:=
utiliptables
.
R
eadLine
(
readIndex
,
byteArray
)
readIndex
=
n
readIndex
=
n
if
expected
[
index
]
!=
line
{
if
expected
[
index
]
!=
line
{
t
.
Errorf
(
"expected:%q, actual:%q"
,
expected
[
index
],
line
)
t
.
Errorf
(
"expected:%q, actual:%q"
,
expected
[
index
],
line
)
...
...
pkg/util/iptables/save_restore.go
0 → 100644
View file @
6a3ad1d6
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
iptables
import
(
"fmt"
"strings"
)
// MakeChainLine return an iptables-save/restore formatted chain line given a Chain
func
MakeChainLine
(
chain
Chain
)
string
{
return
fmt
.
Sprintf
(
":%s - [0:0]"
,
chain
)
}
// GetChainLines parses a table's iptables-save data to find chains in the table.
// It returns a map of iptables.Chain to string where the string is the chain line from the save (with counters etc).
func
GetChainLines
(
table
Table
,
save
[]
byte
)
map
[
Chain
]
string
{
chainsMap
:=
make
(
map
[
Chain
]
string
)
tablePrefix
:=
"*"
+
string
(
table
)
readIndex
:=
0
// find beginning of table
for
readIndex
<
len
(
save
)
{
line
,
n
:=
ReadLine
(
readIndex
,
save
)
readIndex
=
n
if
strings
.
HasPrefix
(
line
,
tablePrefix
)
{
break
}
}
// parse table lines
for
readIndex
<
len
(
save
)
{
line
,
n
:=
ReadLine
(
readIndex
,
save
)
readIndex
=
n
if
len
(
line
)
==
0
{
continue
}
if
strings
.
HasPrefix
(
line
,
"COMMIT"
)
||
strings
.
HasPrefix
(
line
,
"*"
)
{
break
}
else
if
strings
.
HasPrefix
(
line
,
"#"
)
{
continue
}
else
if
strings
.
HasPrefix
(
line
,
":"
)
&&
len
(
line
)
>
1
{
chain
:=
Chain
(
strings
.
SplitN
(
line
[
1
:
],
" "
,
2
)[
0
])
chainsMap
[
chain
]
=
line
}
}
return
chainsMap
}
func
ReadLine
(
readIndex
int
,
byteArray
[]
byte
)
(
string
,
int
)
{
currentReadIndex
:=
readIndex
// consume left spaces
for
currentReadIndex
<
len
(
byteArray
)
{
if
byteArray
[
currentReadIndex
]
==
' '
{
currentReadIndex
++
}
else
{
break
}
}
// leftTrimIndex stores the left index of the line after the line is left-trimmed
leftTrimIndex
:=
currentReadIndex
// rightTrimIndex stores the right index of the line after the line is right-trimmed
// it is set to -1 since the correct value has not yet been determined.
rightTrimIndex
:=
-
1
for
;
currentReadIndex
<
len
(
byteArray
);
currentReadIndex
++
{
if
byteArray
[
currentReadIndex
]
==
' '
{
// set rightTrimIndex
if
rightTrimIndex
==
-
1
{
rightTrimIndex
=
currentReadIndex
}
}
else
if
(
byteArray
[
currentReadIndex
]
==
'\n'
)
||
(
currentReadIndex
==
(
len
(
byteArray
)
-
1
))
{
// end of line or byte buffer is reached
if
currentReadIndex
<=
leftTrimIndex
{
return
""
,
currentReadIndex
+
1
}
// set the rightTrimIndex
if
rightTrimIndex
==
-
1
{
rightTrimIndex
=
currentReadIndex
if
currentReadIndex
==
(
len
(
byteArray
)
-
1
)
&&
(
byteArray
[
currentReadIndex
]
!=
'\n'
)
{
// ensure that the last character is part of the returned string,
// unless the last character is '\n'
rightTrimIndex
=
currentReadIndex
+
1
}
}
return
string
(
byteArray
[
leftTrimIndex
:
rightTrimIndex
]),
currentReadIndex
+
1
}
else
{
// unset rightTrimIndex
rightTrimIndex
=
-
1
}
}
return
""
,
currentReadIndex
}
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