Categorygithub.com/admpub/iptables_parser
modulepackage
0.0.1
Repository: https://github.com/admpub/iptables_parser.git
Documentation: pkg.go.dev

# README

iptables-parser

Documentation

Parse lines generated by iptables-save. This parser is inspired by Ben Johnson's SQL Parser.

Description

This parser parses lines returned from iptables-save or iptables -S and returns a Line or an Error. A Line can be a Rule, Comment, Policy (default rule) or Header, all of them being structs.

Match Extensions

iptables has a lot of match extensions. Only a few are implemented. If one is not implemented, the parses returns an error for that line.

Target Extensions

Just like in Match Extensions, not all of the target extensions are implemented.

Example

package main

import (
	"fmt"
	"log"

	ipt "github.com/coreos/go-iptables/iptables"
	iptp "github.com/kilo-io/iptables_parser"
)

func main() {
	t, err := ipt.NewWithProtocol(ipt.ProtocolIPv4)
	if err != nil {
		log.Fatal(err.Error())
	}
	rs, err := t.List("filter", "DOCKER")
	if err != nil {
		log.Fatal(err.Error())
	}
	for _, r := range rs {
		fmt.Println(r)
		tr, err := iptp.NewFromString(r)
		if err != nil {
			fmt.Printf("Error: %v", err)
			continue
		}
		switch r := tr.(type) {
		case iptp.Rule:
			fmt.Printf("rule parsed: %v\n", r)
		case iptp.Policy:
			fmt.Printf("policy parsed: %v\n", r)
		default:
			fmt.Printf("something else happend: %v\n", r)
		}

	}
}

# Packages

No description provided by the author

# Functions

NewDNSOrIP takes a string and return a DNSOrIP, or an error.
NewFromString takes a string a parses it until the EOF or NEWLINE to return a Header, Policy or Rule.
NewParser returns a new instance of Parser.
NewRuleFromSpec returns a rule from a given rulespec and chain name.
NewRuleFromString returns a rule for the given string.

# Constants

No description provided by the author
\.
BUFSIZE is the max buffer size of the ring buffer in the parser.
:.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
#.
No description provided by the author
main.
Special tokens.
No description provided by the author
No description provided by the author
!.
".
Keywords.
No description provided by the author

# Structs

Comment represents a comment in an iptables dump.
Counter represents the package and byte counters.
DNSOrIP represents either a DNS name or an IP address.
DNSOrIPPair either holds an IP or DNS and a flag.
Flag is flag, e.g.
Header represents a header in an iptables dump and introduce a new table.
Match represents one match expression from the iptables-extension.
Parser represents a parser.
Policy represents a build-in policy.
Rule represents a rule in an iptables dump.
StringPair is a string with a flag.
Target represents a Target Extension.

# Interfaces

Line represents a line in a iptables dump, e.g.

# Type aliases

No description provided by the author