Skip to content

Commit

Permalink
fix hostname params and add full-disable params (chaos-mesh#226)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Savchenko <nikisavchenko@ozon.ru>
  • Loading branch information
Nikita Savchenko committed Jan 30, 2023
1 parent eb305e2 commit afdffae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/attack/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/core/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit afdffae

Please sign in to comment.