reject with reset

This commit is contained in:
William Banfield
2022-11-30 20:15:10 -05:00
parent d2ef43b449
commit f9799ca469
2 changed files with 16 additions and 9 deletions

View File

@@ -44,15 +44,13 @@ func (p Provider) KillTendermint(ctx context.Context, n *e2e.Node) error {
}
func (p Provider) Disconnect(ctx context.Context, n *e2e.Node) error {
return e2essh.MultiExec(p.SSHConfig, fmt.Sprintf("%s:%d", n.IP, sshPort),
"iptables -A INPUT -p tcp --destination-port 26656 -j DROP",
"iptables -A OUTPUT -p tcp --destination-port 26656 -j DROP",
"service iptables save",
"iptables -A INPUT -p tcp --destination-port 26656 -j REJECT --reject-with tcp-reset",
"iptables -A OUTPUT -p tcp --destination-port 26656 -j REJECT --reject-with tcp-reset",
)
}
func (p Provider) Connect(ctx context.Context, n *e2e.Node) error {
return e2essh.MultiExec(p.SSHConfig, fmt.Sprintf("%s:%d", n.IP, sshPort),
"iptables -D INPUT -p tcp --destination-port 26656 -j DROP",
"iptables -D OUTPUT -p tcp --destination-port 26656 -j DROP",
"service iptables save",
"iptables -D INPUT -p tcp --destination-port 26656 -j REJECT --reject-with tcp-reset",
"iptables -D OUTPUT -p tcp --destination-port 26656 -j REJECT --reject-with tcp-reset",
)
}

View File

@@ -18,7 +18,11 @@ func Exec(cfg *ssh.ClientConfig, addr, cmd string) error {
if err != nil {
return err
}
defer c.Close()
s, err := c.NewSession()
if err != nil {
return err
}
defer s.Close()
err = s.Run(cmd)
if err != nil {
@@ -29,16 +33,21 @@ func Exec(cfg *ssh.ClientConfig, addr, cmd string) error {
func MultiExec(cfg *ssh.ClientConfig, addr string, cmds ...string) error {
c, err := ssh.Dial("tcp", addr, cfg)
s, err := c.NewSession()
if err != nil {
return err
}
defer s.Close()
defer c.Close()
for _, cmd := range cmds {
err := s.Run(cmd)
s, err := c.NewSession()
if err != nil {
return err
}
err = s.Run(cmd)
if err != nil {
s.Close()
return err
}
s.Close()
}
return nil
}