pkg/iptables: enable simultaneous ipv4 and ipv6

This commit enables simultaneously managing IPv4 and IPv6 iptables
rules. This makes it possible to have peers with IPv6 allowed IPs in an
otherwise IPv4 stack and vice versa.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
Lucas Servén Marín
2020-03-12 15:48:01 +01:00
parent 8e8eb1a213
commit b668c1ec3e
7 changed files with 108 additions and 43 deletions

View File

@@ -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})
f.storage = append(f.storage, &rule{table: table, chain: chain, spec: spec})
return nil
}
func (f *fakeClient) Delete(table, chain string, spec ...string) error {
r := &rule{table, chain, spec}
r := &rule{table: table, chain: chain, spec: 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}
r := &rule{table: table, chain: chain, spec: 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}
c := &chain{table: table, chain: 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}
c := &chain{table: table, chain: name}
for i := range f.storage {
if f.storage[i].String() == c.String() {
return statusError(1)