From afdffaed77b0c17a12266ef2c8864be722023a53 Mon Sep 17 00:00:00 2001 From: Nikita Savchenko Date: Fri, 13 Jan 2023 20:05:51 +0400 Subject: [PATCH] fix hostname params and add full-disable params (#226) Signed-off-by: Nikita Savchenko --- cmd/attack/network.go | 1 + pkg/core/network.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/attack/network.go b/cmd/attack/network.go index b15d14eb..320a3bec 100644 --- a/cmd/attack/network.go +++ b/cmd/attack/network.go @@ -114,6 +114,7 @@ func NewNetworkLossCommand(dep fx.Option, options *core.NetworkCommand) *cobra.C cmd.Flags().StringVarP(&options.Hostname, "hostname", "H", "", "only impact traffic to these hostnames") cmd.Flags().StringVarP(&options.IPProtocol, "protocol", "p", "", "only impact traffic using this IP protocol, supported: tcp, udp, icmp, all") + cmd.Flags().BoolVar(&options.FullDisable, "full-disable", false, "full net on device disable flag") return cmd } diff --git a/pkg/core/network.go b/pkg/core/network.go index eae0e6cb..4a6ff6dc 100644 --- a/pkg/core/network.go +++ b/pkg/core/network.go @@ -43,7 +43,8 @@ type NetworkCommand struct { IPProtocol string `json:"ip-protocol,omitempty"` Hostname string `json:"hostname,omitempty"` - Direction string `json:"direction,omitempty"` + Direction string `json:"direction,omitempty"` + FullDisable bool `json:"full-disable,omitempty"` // used for DNS attack DNSServer string `json:"dns-server,omitempty"` @@ -174,6 +175,16 @@ func (n *NetworkCommand) validNetworkCommon() error { return errors.Errorf("ip addressed %s not valid", n.IPAddress) } + if len(n.Hostname) == 0 && len(n.IPAddress) == 0 && !n.FullDisable { + return errors.New("hostname or ip address is required") + } + + if n.FullDisable { + if len(n.Hostname) > 0 || len(n.IPAddress) > 0 { + return errors.New("the host and address are set, but the flag full-disable is enabled") + } + } + return checkProtocolAndPorts(n.IPProtocol, n.SourcePort, n.EgressPort) }