Skip to content

Instantly share code, notes, and snippets.

@santosh
Created August 25, 2022 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santosh/293ac03b206b7df21d2faf46b34527c5 to your computer and use it in GitHub Desktop.
Save santosh/293ac03b206b7df21d2faf46b34527c5 to your computer and use it in GitHub Desktop.
go-iptables examples
package main
func main() {
// if ipt, err := iptables.NewWithProtocol(iptables.ProtocolIPv4); err == nil {
// rule := []string{"-m", "ttl", "--ttl-eq", "1", "-p", "tcp", "-d", raddr.IP.String(), "--dport", fmt.Sprint(raddr.Port), "-j", "DROP"}
// if exists, err := ipt.Exists("filter", "OUTPUT", rule...); err == nil {
// if !exists {
// if err = ipt.Append("filter", "OUTPUT", rule...); err == nil {
// conn.iprule = rule
// conn.iptables = ipt
// }
// }
// }
// }
}
/*
Links:
https://github.com/Azure/azure-container-networking/blob/877970022a66b3d402d08aee0afd3089d9f617a2/cns/restserver/internalapi_linux.go
https://github.com/yunionio/cloudpods/blob/84cdeff92b0ec64642e202d5fbd4e7c892427ba8/pkg/lbagent/ovn.go#L446
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment