Skip to content

Commit 9cfec88

Browse files
add following support: (#342)
1. ip6table cmd support 2. wiat falg with timeout
1 parent 9d8a280 commit 9cfec88

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

npm/iptm/iptm.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ https://github.com/kubernetes/kubernetes/blob/master/pkg/util/iptables
77
package iptm
88

99
import (
10+
"fmt"
1011
"os"
1112
"os/exec"
13+
"strings"
1214
"syscall"
1315
"time"
1416

@@ -21,11 +23,13 @@ import (
2123

2224
// IptEntry represents an iptables rule.
2325
type IptEntry struct {
24-
Name string
25-
HashedName string
26-
Chain string
27-
Flag string
28-
Specs []string
26+
Command string
27+
Name string
28+
HashedName string
29+
Chain string
30+
Flag string
31+
LockWaitTimeInSeconds string
32+
Specs []string
2933
}
3034

3135
// IptablesManager stores iptables entries.
@@ -329,10 +333,15 @@ func (iptMgr *IptablesManager) Delete(entry *IptEntry) error {
329333

330334
// Run execute an iptables command to update iptables.
331335
func (iptMgr *IptablesManager) Run(entry *IptEntry) (int, error) {
332-
cmdName := util.Iptables
333-
cmdArgs := append([]string{util.IptablesWaitFlag, iptMgr.OperationFlag, entry.Chain}, entry.Specs...)
336+
if entry.Command == "" {
337+
entry.Command = util.Iptables
338+
}
339+
340+
waitFlag := fmt.Sprintf("%s %s", util.IptablesWaitFlag, entry.LockWaitTimeInSeconds)
341+
waitFlag = strings.TrimSpace(waitFlag)
342+
cmdArgs := append([]string{waitFlag, iptMgr.OperationFlag, entry.Chain}, entry.Specs...)
334343

335-
cmdOut, err := exec.Command(cmdName, cmdArgs...).Output()
344+
cmdOut, err := exec.Command(entry.Command, cmdArgs...).Output()
336345
log.Printf("%s\n", string(cmdOut))
337346

338347
if msg, failed := err.(*exec.ExitError); failed {

npm/util/const.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
//iptables related constants.
2020
const (
2121
Iptables string = "iptables"
22+
Ip6tables string = "ip6tables"
2223
IptablesSave string = "iptables-save"
2324
IptablesRestore string = "iptables-restore"
2425
IptablesConfigFile string = "/var/log/iptables.conf"
@@ -47,8 +48,11 @@ const (
4748
IptablesMatchSetFlag string = "--match-set"
4849
IptablesStateFlag string = "state"
4950
IptablesMatchStateFlag string = "--state"
51+
IptablesMultiportFlag string = "multiport"
52+
IptablesMultiDestportFlag string = "--dports"
5053
IptablesRelatedState string = "RELATED"
5154
IptablesEstablishedState string = "ESTABLISHED"
55+
IptablesFilterTable string = "filter"
5256
IptablesAzureChain string = "AZURE-NPM"
5357
IptablesAzureIngressPortChain string = "AZURE-NPM-INGRESS-PORT"
5458
IptablesAzureIngressFromChain string = "AZURE-NPM-INGRESS-FROM"
@@ -60,6 +64,7 @@ const (
6064
IptablesAzureEgressToPodChain string = "AZURE-NPM-EGRESS-TO-POD"
6165
IptablesAzureTargetSetsChain string = "AZURE-NPM-TARGET-SETS"
6266
IptablesForwardChain string = "FORWARD"
67+
IptablesInputChain string = "INPUT"
6368
)
6469

6570
//ipset related constants.

0 commit comments

Comments
 (0)