@@ -137,6 +137,10 @@ func (n *NetworkCommand) validNetworkDelay() error {
137
137
return errors .Errorf ("ip addressed %s not valid" , n .IPAddress )
138
138
}
139
139
140
+ if len (n .AcceptTCPFlags ) > 0 && n .IPProtocol != "tcp" {
141
+ return errors .Errorf ("protocol should be 'tcp' when set accept-tcp-flags" )
142
+ }
143
+
140
144
return checkProtocolAndPorts (n .IPProtocol , n .SourcePort , n .EgressPort )
141
145
}
142
146
@@ -519,24 +523,20 @@ func (n *NetworkCommand) NeedApplyTC() bool {
519
523
}
520
524
}
521
525
522
- func (n * NetworkCommand ) PartitionChain (ipset string ) ([]* pb.Chain , error ) {
523
- if n .Action != NetworkPartitionAction {
524
- return nil , nil
525
- }
526
-
526
+ func (n * NetworkCommand ) AdditionalChain (ipset string ) ([]* pb.Chain , error ) {
527
527
chains := make ([]* pb.Chain , 0 , 2 )
528
528
var toChains , fromChains []* pb.Chain
529
529
var err error
530
530
531
531
if n .Direction == "to" || n .Direction == "both" {
532
- toChains , err = n .getPartitionChain (ipset , "to" )
532
+ toChains , err = n .getAdditionalChain (ipset , "to" )
533
533
if err != nil {
534
534
return nil , err
535
535
}
536
536
}
537
537
538
538
if n .Direction == "from" || n .Direction == "both" {
539
- fromChains , err = n .getPartitionChain (ipset , "from" )
539
+ fromChains , err = n .getAdditionalChain (ipset , "from" )
540
540
if err != nil {
541
541
return nil , err
542
542
}
@@ -548,7 +548,7 @@ func (n *NetworkCommand) PartitionChain(ipset string) ([]*pb.Chain, error) {
548
548
return chains , nil
549
549
}
550
550
551
- func (n * NetworkCommand ) getPartitionChain (ipset , direction string ) ([]* pb.Chain , error ) {
551
+ func (n * NetworkCommand ) getAdditionalChain (ipset , direction string ) ([]* pb.Chain , error ) {
552
552
var directionStr string
553
553
var directionChain pb.Chain_Direction
554
554
if direction == "to" {
@@ -573,14 +573,15 @@ func (n *NetworkCommand) getPartitionChain(ipset, direction string) ([]*pb.Chain
573
573
})
574
574
}
575
575
576
- chains = append (chains , & pb.Chain {
577
- Name : fmt .Sprintf ("%s/1" , directionStr ),
578
- Ipsets : []string {ipset },
579
- Direction : directionChain ,
580
- Protocol : n .IPProtocol ,
581
- Target : "DROP" ,
582
- })
583
-
576
+ if n .Action == NetworkPartitionAction {
577
+ chains = append (chains , & pb.Chain {
578
+ Name : fmt .Sprintf ("%s/1" , directionStr ),
579
+ Ipsets : []string {ipset },
580
+ Direction : directionChain ,
581
+ Protocol : n .IPProtocol ,
582
+ Target : "DROP" ,
583
+ })
584
+ }
584
585
return chains , nil
585
586
}
586
587
@@ -596,6 +597,13 @@ func (n *NetworkCommand) NeedApplyDNSServer() bool {
596
597
return len (n .DNSServer ) > 0
597
598
}
598
599
600
+ func (n * NetworkCommand ) NeedAdditionalChains () bool {
601
+ if n .Action != NetworkPartitionAction || (n .Action == NetworkDelayAction && len (n .AcceptTCPFlags ) != 0 ) {
602
+ return true
603
+ }
604
+ return false
605
+ }
606
+
599
607
func NewNetworkCommand () * NetworkCommand {
600
608
return & NetworkCommand {
601
609
CommonAttackConfig : CommonAttackConfig {
0 commit comments