pkg/iptables: clean up, remove NAT

This commit cleans up the iptables package to allow other packages to
create rules.

This commit also removes all NAT from Kilo.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
Lucas Servén Marín
2020-02-20 12:24:52 +01:00
parent 2603cd50db
commit 4857d10da1
6 changed files with 77 additions and 133 deletions

View File

@@ -41,7 +41,7 @@ type fakeClient struct {
storage []Rule
}
var _ iptablesClient = &fakeClient{}
var _ Client = &fakeClient{}
func (f *fakeClient) AppendUnique(table, chain string, spec ...string) error {
exists, err := f.Exists(table, chain, spec...)
@@ -51,12 +51,12 @@ func (f *fakeClient) AppendUnique(table, chain string, spec ...string) error {
if exists {
return nil
}
f.storage = append(f.storage, &rule{table, chain, spec, nil})
f.storage = append(f.storage, &rule{table, chain, spec})
return nil
}
func (f *fakeClient) Delete(table, chain string, spec ...string) error {
r := &rule{table, chain, spec, nil}
r := &rule{table, chain, spec}
for i := range f.storage {
if f.storage[i].String() == r.String() {
copy(f.storage[i:], f.storage[i+1:])
@@ -69,7 +69,7 @@ func (f *fakeClient) Delete(table, chain string, spec ...string) error {
}
func (f *fakeClient) Exists(table, chain string, spec ...string) (bool, error) {
r := &rule{table, chain, spec, nil}
r := &rule{table, chain, spec}
for i := range f.storage {
if f.storage[i].String() == r.String() {
return true, nil
@@ -103,7 +103,7 @@ func (f *fakeClient) DeleteChain(table, name string) error {
return fmt.Errorf("cannot delete chain %s; rules exist", name)
}
}
c := &chain{table, name, nil}
c := &chain{table, name}
for i := range f.storage {
if f.storage[i].String() == c.String() {
copy(f.storage[i:], f.storage[i+1:])
@@ -116,7 +116,7 @@ func (f *fakeClient) DeleteChain(table, name string) error {
}
func (f *fakeClient) NewChain(table, name string) error {
c := &chain{table, name, nil}
c := &chain{table, name}
for i := range f.storage {
if f.storage[i].String() == c.String() {
return statusError(1)