From e7715f72b9e10b5dd22c09516b73c3029ddd5878 Mon Sep 17 00:00:00 2001 From: Cwen Yin Date: Wed, 8 Feb 2023 16:10:04 +0800 Subject: [PATCH] Revert "fix hostname params and add full-disable params (#226) (#227)" (#235) This reverts commit 6c378aaed61963ff1e46e2356a8a400cc2fd0012. --- cmd/attack/network.go | 6 ++---- pkg/core/network.go | 33 +++----------------------------- test/integration_test/jvm/run.sh | 2 +- 3 files changed, 6 insertions(+), 35 deletions(-) diff --git a/cmd/attack/network.go b/cmd/attack/network.go index d935f6c..b15d14e 100644 --- a/cmd/attack/network.go +++ b/cmd/attack/network.go @@ -85,7 +85,6 @@ func NewNetworkDelayCommand(dep fx.Option, options *core.NetworkCommand) *cobra. cmd.Flags().StringVarP(&options.IPProtocol, "protocol", "p", "", "only impact traffic using this IP protocol, supported: tcp, udp, icmp, all") cmd.Flags().StringVarP(&options.AcceptTCPFlags, "accept-tcp-flags", "", "", "only the packet which match the tcp flag can be accepted, others will be dropped. only set when the protocol is tcp.") - cmd.Flags().BoolVar(&options.FullDisable, "full-disable", false, "network on device full disable flag") return cmd } @@ -115,7 +114,6 @@ 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, "network on device full disable flag") return cmd } @@ -145,7 +143,7 @@ func NewNetworkCorruptCommand(dep fx.Option, options *core.NetworkCommand) *cobr 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, "network on device full disable flag") + return cmd } @@ -174,7 +172,7 @@ func NetworkDuplicateCommand(dep fx.Option, options *core.NetworkCommand) *cobra 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, "network on device full disable flag") + return cmd } diff --git a/pkg/core/network.go b/pkg/core/network.go index 7fc459a..eae0e6c 100644 --- a/pkg/core/network.go +++ b/pkg/core/network.go @@ -43,8 +43,7 @@ type NetworkCommand struct { IPProtocol string `json:"ip-protocol,omitempty"` Hostname string `json:"hostname,omitempty"` - Direction string `json:"direction,omitempty"` - FullDisable bool `json:"full-disable,omitempty"` + Direction string `json:"direction,omitempty"` // used for DNS attack DNSServer string `json:"dns-server,omitempty"` @@ -143,10 +142,6 @@ func (n *NetworkCommand) validNetworkDelay() error { return errors.Errorf("protocol should be 'tcp' when set accept-tcp-flags") } - if err := checkNetworkLimitParams(n.Hostname, n.IPAddress, n.FullDisable); err != nil { - return err - } - return checkProtocolAndPorts(n.IPProtocol, n.SourcePort, n.EgressPort) } @@ -155,9 +150,7 @@ func (n *NetworkCommand) validNetworkBandwidth() error { return errors.Errorf("rate, limit and buffer both are required when action is bandwidth") } - err := checkNetworkLimitParams(n.Hostname, n.IPAddress, n.FullDisable) - - return err + return nil } func (n *NetworkCommand) validNetworkCommon() error { @@ -181,10 +174,6 @@ func (n *NetworkCommand) validNetworkCommon() error { return errors.Errorf("ip addressed %s not valid", n.IPAddress) } - if err := checkNetworkLimitParams(n.Hostname, n.IPAddress, n.FullDisable); err != nil { - return err - } - return checkProtocolAndPorts(n.IPProtocol, n.SourcePort, n.EgressPort) } @@ -209,9 +198,7 @@ func (n *NetworkCommand) validNetworkPartition() error { return errors.Errorf("ip protocols %s not valid", n.IPProtocol) } - err := checkNetworkLimitParams(n.Hostname, n.IPAddress, n.FullDisable) - - return err + return nil } func (n *NetworkCommand) validNetworkDNS() error { @@ -346,20 +333,6 @@ func checkProtocolAndPorts(p string, sports string, dports string) error { return nil } -func checkNetworkLimitParams(hostname string, ipaddress string, fullDisable bool) error { // revive:disable-line:flag-parameter - if len(hostname) == 0 && len(ipaddress) == 0 && !fullDisable { - return errors.New("hostname or ip address is required") - } - - if fullDisable { - if len(hostname) > 0 || len(ipaddress) > 0 { - return errors.New("the host and address are set, but the flag full-disable is enabled") - } - } - - return nil -} - func (n NetworkCommand) RecoverData() string { data, _ := json.Marshal(n) diff --git a/test/integration_test/jvm/run.sh b/test/integration_test/jvm/run.sh index 19205ab..13b9bd0 100644 --- a/test/integration_test/jvm/run.sh +++ b/test/integration_test/jvm/run.sh @@ -84,7 +84,7 @@ export MYSQL_USER=root export MYSQL_CONNECTOR_VERSION=8 mvn exec:java -Dexec.mainClass="com.mysqldemo.App" > mysqldemo.log 2>&1 & # make sure it works -for (( i=0; i<=30; i++ )) +for (( i=0; i<=20; i++ )) do tail_log=`tail -1 mysqldemo.log` if [ "$tail_log" == "Server start!" ]; then