Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Feb 5, 2024
1 parent a8b31fd commit 6abd0e7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion runtime/docker/firewall/iptables/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,38 @@ const (
iptCheckCmd = "-vL DOCKER-USER"
iptAllowCmd = "-I DOCKER-USER -o %s -j ACCEPT -m comment --comment \"" + definitions.IPTablesRuleComment + "\""
iptDelCmd = "-D DOCKER-USER -o %s -j ACCEPT -m comment --comment \"" + definitions.IPTablesRuleComment + "\""
ipTables = "ip_tables"
)

// IpTablesClient is a client for iptables.
type IpTablesClient struct {
bridgeName string
}

// NewIpTablesClient returns a new IpTablesClient.
func NewIpTablesClient(bridgeName string) (*IpTablesClient, error) {
loaded, err := utils.IsKernelModuleLoaded("ip_tables")
if err != nil {
return nil, err
}

if !loaded {
log.Debug("ip_tables kernel module not available")
// module is not loaded
return nil, definitions.ErrNotAvailabel
}

return &IpTablesClient{
bridgeName: bridgeName,
}, nil
}

// Name returns the name of the firewall client.
func (*IpTablesClient) Name() string {
return "ip_tables"
return ipTables
}

// InstallForwardingRules installs the forwarding rules.
func (c *IpTablesClient) InstallForwardingRules() error {
// first check if a rule already exists to not create duplicates
res, err := exec.Command("iptables", strings.Split(iptCheckCmd, " ")...).Output()
Expand All @@ -66,9 +73,11 @@ func (c *IpTablesClient) InstallForwardingRules() error {
log.Warnf("Iptables install stdout/stderr result is: %s", stdOutErr)
return fmt.Errorf("unable to install iptables rule using '%s' command: %w", cmd, err)
}

return nil
}

// DeleteForwardingRules deletes the forwarding rules.
func (c *IpTablesClient) DeleteForwardingRules() error {
// first check if a rule exists before trying to delete it
res, err := exec.Command("iptables", strings.Split(iptCheckCmd, " ")...).Output()
Expand Down

0 comments on commit 6abd0e7

Please sign in to comment.