@@ -402,42 +402,43 @@ public boolean addFirewallRules(Network network, List<NetrisNetworkRule> firewal
402402 String trafficType = baseNetworkRule .getTrafficType ().toUpperCase (Locale .ROOT );
403403 String sourcePrefix ;
404404 String destinationPrefix ;
405- if ("INGRESS" .equals (trafficType )) {
406- sourcePrefix = baseNetworkRule .getSourceCidrList ().get (0 );
407- if (NetUtils .isValidIp4Cidr (sourcePrefix )) {
408- destinationPrefix = network .getCidr ();
405+ boolean result = true ;
406+ List <String > sourceCidrs = baseNetworkRule .getSourceCidrList ();
407+ int index = 1 ;
408+ for (String sourceCidr : sourceCidrs ) {
409+ if ("INGRESS" .equals (trafficType )) {
410+ sourcePrefix = sourceCidr ;
411+ destinationPrefix = NetUtils .isValidIp4Cidr (sourcePrefix ) ? network .getCidr () : network .getIp6Cidr ();
409412 } else {
410- destinationPrefix = network .getIp6Cidr ();
413+ destinationPrefix = sourceCidr ;
414+ sourcePrefix = NetUtils .isValidIp4Cidr (destinationPrefix ) ? network .getCidr () : network .getIp6Cidr ();
411415 }
412- } else {
413- destinationPrefix = baseNetworkRule .getSourceCidrList ().get (0 );
414- if (NetUtils .isValidIp4Cidr (destinationPrefix )) {
415- sourcePrefix = network .getCidr ();
416+ String srcPort ;
417+ String dstPort ;
418+ if (baseNetworkRule .getPrivatePort ().contains ("-" )) {
419+ srcPort = baseNetworkRule .getPrivatePort ().split ("-" )[0 ];
420+ dstPort = baseNetworkRule .getPrivatePort ().split ("-" )[1 ];
416421 } else {
417- sourcePrefix = network . getIp6Cidr ();
422+ srcPort = dstPort = baseNetworkRule . getPrivatePort ();
418423 }
424+ CreateOrUpdateNetrisACLCommand cmd = new CreateOrUpdateNetrisACLCommand (zoneId , accountId , domainId , networkName , networkId ,
425+ vpcName , vpcId , Objects .nonNull (vpcId ), rule .getAclAction ().name ().toLowerCase (Locale .ROOT ), getPrefix (sourcePrefix ), getPrefix (destinationPrefix ),
426+ "null" .equals (srcPort ) ? 1 : Integer .parseInt (srcPort ),
427+ "null" .equals (dstPort ) ? 65535 : Integer .parseInt (dstPort ), baseNetworkRule .getProtocol ());
428+ String aclName = String .format ("V%s-N%s-ACL%s" , vpcId , networkId , rule .getBaseRule ().getRuleId ());
429+ if (sourceCidrs .size () > 1 ) {
430+ aclName = aclName + "-" + index ++;
431+ }
432+ String netrisAclName = NetrisResourceObjectUtils .retrieveNetrisResourceObjectName (cmd , NetrisResourceObjectUtils .NetrisObjectType .ACL , aclName );
433+ cmd .setNetrisAclName (netrisAclName );
434+ cmd .setReason (rule .getReason ());
435+ if ("ICMP" .equals (baseNetworkRule .getProtocol ())) {
436+ cmd .setIcmpType (baseNetworkRule .getIcmpType ());
437+ }
438+ NetrisAnswer answer = sendNetrisCommand (cmd , zoneId );
439+ result = result && answer .getResult ();
419440 }
420- String srcPort ;
421- String dstPort ;
422- if (baseNetworkRule .getPrivatePort ().contains ("-" )) {
423- srcPort = baseNetworkRule .getPrivatePort ().split ("-" )[0 ];
424- dstPort = baseNetworkRule .getPrivatePort ().split ("-" )[1 ];
425- } else {
426- srcPort = dstPort = baseNetworkRule .getPrivatePort ();
427- }
428- CreateOrUpdateNetrisACLCommand cmd = new CreateOrUpdateNetrisACLCommand (zoneId , accountId , domainId , networkName , networkId ,
429- vpcName , vpcId , Objects .nonNull (vpcId ), rule .getAclAction ().name ().toLowerCase (Locale .ROOT ), getPrefix (sourcePrefix ), getPrefix (destinationPrefix ),
430- "null" .equals (srcPort ) ? 1 : Integer .parseInt (srcPort ),
431- "null" .equals (dstPort ) ? 65535 : Integer .parseInt (dstPort ), baseNetworkRule .getProtocol ());
432- String aclName = String .format ("V%s-N%s-ACL%s" , vpcId , networkId , rule .getBaseRule ().getRuleId ());
433- String netrisAclName = NetrisResourceObjectUtils .retrieveNetrisResourceObjectName (cmd , NetrisResourceObjectUtils .NetrisObjectType .ACL , aclName );
434- cmd .setNetrisAclName (netrisAclName );
435- cmd .setReason (rule .getReason ());
436- if ("ICMP" .equals (baseNetworkRule .getProtocol ())) {
437- cmd .setIcmpType (baseNetworkRule .getIcmpType ());
438- }
439- NetrisAnswer answer = sendNetrisCommand (cmd , zoneId );
440- return answer .getResult ();
441+ return result ;
441442 }
442443
443444 public static String getPrefix (String prefix ) {
0 commit comments