Example #1
0
func (*FakeIPTables) Destroy() {}

func getToken(line, seperator string) string {
	tokens := strings.Split(line, seperator)
	if len(tokens) == 2 {
		return strings.Split(tokens[1], " ")[0]
	}
	return ""
}

// GetChain returns a list of rules for the givne chain.
// The chain name must match exactly.
// The matching is pretty dumb, don't rely on it for anything but testing.
func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
	for _, l := range strings.Split(string(f.Lines), "\n") {
		if strings.Contains(l, fmt.Sprintf("-A %v", chainName)) {
			newRule := Rule(map[string]string{})
			for _, arg := range []string{Destination, Source, DPort, Protocol, Jump, ToDest} {
				tok := getToken(l, arg)
				if tok != "" {
					newRule[arg] = tok
				}
			}
			rules = append(rules, newRule)
		}
	}
	return
}

var _ = iptables.Interface(&FakeIPTables{})
Example #2
0
}

func (*fake) DeleteRule(table iptables.Table, chain iptables.Chain, args ...string) error {
	return nil
}

func (*fake) IsIpv6() bool {
	return false
}

func (*fake) Save(table iptables.Table) ([]byte, error) {
	return make([]byte, 0), nil
}

func (*fake) SaveAll() ([]byte, error) {
	return make([]byte, 0), nil
}

func (*fake) Restore(table iptables.Table, data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error {
	return nil
}

func (*fake) RestoreAll(data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error {
	return nil
}
func (*fake) AddReloadFunc(reloadFunc func()) {}

func (*fake) Destroy() {}

var _ = iptables.Interface(&fake{})