Skip to content

Commit

Permalink
make static packet config the default one
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed May 8, 2022
1 parent b3fd2b5 commit d856e84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/job/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
type httpJobConfig struct {
BasicJobConfig

Static bool
Dynamic bool
Request map[string]any
Client map[string]any // See HTTPClientConfig
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func fastHTTPJob(ctx context.Context, args config.Args, globalConfig *GlobalConf
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)

if jobConfig.Static {
if !jobConfig.Dynamic {
if err := buildHTTPRequest(ctx, logger, requestTpl, req); err != nil {
return nil, fmt.Errorf("error executing request template: %w", err)
}
Expand All @@ -158,7 +158,7 @@ func fastHTTPJob(ctx context.Context, args config.Args, globalConfig *GlobalConf
logger.Info("attacking", zap.Any("target", jobConfig.Request["path"]))

for jobConfig.Next(ctx) {
if !jobConfig.Static {
if jobConfig.Dynamic {
if err := buildHTTPRequest(ctx, logger, requestTpl, req); err != nil {
return nil, fmt.Errorf("error executing request template: %w", err)
}
Expand Down
37 changes: 18 additions & 19 deletions src/job/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

type packetgenJobConfig struct {
BasicJobConfig
Static bool
Dynamic bool
Packets []*templates.MapStruct
Connection packetgen.ConnectionConfig
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func sendPacket(ctx context.Context, logger *zap.Logger, jobConfig *packetgenJob
}
defer conn.Close()

packetSrc, err := makePacketSource(ctx, logger, jobConfig.Packets, jobConfig.Static)
packetSrc, err := makePacketSource(ctx, logger, jobConfig.Packets, jobConfig.Dynamic)
if err != nil {
return err
}
Expand Down Expand Up @@ -112,24 +112,24 @@ func sendPacket(ctx context.Context, logger *zap.Logger, jobConfig *packetgenJob

type packetSource func(ctx context.Context, logger *zap.Logger) (packetgen.Packet, error)

func makePacketSource(ctx context.Context, logger *zap.Logger, packetTpls []*templates.MapStruct, static bool) (packetSource, error) {
if static {
packets, err := staticPackets(ctx, logger, packetTpls)
if err != nil {
return nil, err
}

packetsChan := utils.InfiniteRange(ctx, packets)
func makePacketSource(ctx context.Context, logger *zap.Logger, packetTpls []*templates.MapStruct, dynamic bool) (packetSource, error) {
if dynamic {
packetsChan := utils.InfiniteRange(ctx, packetTpls)

return func(ctx context.Context, logger *zap.Logger) (packetgen.Packet, error) {
return getNextStaticPacket(ctx, logger, packetsChan)
return getNextDynamicPacket(ctx, logger, packetsChan)
}, nil
}

packetsChan := utils.InfiniteRange(ctx, packetTpls)
packets, err := staticPackets(ctx, logger, packetTpls)
if err != nil {
return nil, err
}

packetsChan := utils.InfiniteRange(ctx, packets)

return func(ctx context.Context, logger *zap.Logger) (packetgen.Packet, error) {
return getNextDynamicPacket(ctx, logger, packetsChan)
return getNextStaticPacket(ctx, logger, packetsChan)
}, nil
}

Expand Down Expand Up @@ -228,11 +228,10 @@ func parsePacketgenArgs(ctx context.Context, args config.Args, globalConfig *Glo
) {
var jobConfig struct {
BasicJobConfig
StaticPacket bool
Static bool
Packet map[string]any
Packets []packetDescriptor
Connection packetgen.ConnectionConfig
Dynamic bool
Packet map[string]any
Packets []packetDescriptor
Connection packetgen.ConnectionConfig
}

if err = ParseConfig(&jobConfig, args, *globalConfig); err != nil {
Expand All @@ -249,7 +248,7 @@ func parsePacketgenArgs(ctx context.Context, args config.Args, globalConfig *Glo

return &packetgenJobConfig{
BasicJobConfig: jobConfig.BasicJobConfig,
Static: jobConfig.StaticPacket || jobConfig.Static,
Dynamic: jobConfig.Dynamic,
Packets: packetTpls,
Connection: jobConfig.Connection,
}, nil
Expand Down

0 comments on commit d856e84

Please sign in to comment.