package com.yahoo.vespa.hosted.node.admin.util;

/**
 * Utility class for creating iptables commands
 *
 * @author mpolden
 */
public class IpTables {

    private static final String COMMAND = "ip6tables";

    public static String[] allowFromAddress(String ipAddress) {
        return new String[]{COMMAND, "-A", "INPUT", "-s", ipAddress, "-j", "ACCEPT"};
    }

    public static String[] chainPolicy(Policy policy) {
        return new String[]{COMMAND, "-P", "INPUT", policy.target};
    }

    public static String[] flushChain() {
        return new String[]{COMMAND, "-F", "INPUT"};
    }

    public enum Policy {
        DROP("DROP"),
        ACCEPT("ACCEPT");

        private final String target;

        Policy(String target) {
            this.target = target;
        }
    }
}

@@ -308,23 +308,32 @@
 , %22-A%22, 
-%22INPUT%22
+Chain.INPUT.name
 , %22-s%22, 
@@ -349,24 +349,36 @@
 , %22-j%22, 
-%22ACCEPT%22
+Action.ACCEPT.target
 %7D;%0A    %7D
@@ -422,21 +422,21 @@
 icy(
-Policy policy
+Action action
 ) %7B%0A
@@ -482,23 +482,32 @@
 P%22, 
-%22INPUT%22, policy
+Chain.INPUT.name, action
 .tar
@@ -608,15 +608,24 @@
 F%22, 
-%22INPUT%22
+Chain.INPUT.name
 %7D;%0A 
@@ -646,22 +646,22 @@
 ic enum 
-Policy
+Action
  %7B%0A     
@@ -750,22 +750,22 @@
         
-Policy
+Action
 (String 
@@ -823,11 +823,172 @@
  %7D%0A    %7D
+%0A%0A    public enum Chain %7B%0A        INPUT(%22INPUT%22);%0A%0A        private final String name;%0A%0A        Chain(String name) %7B%0A            this.name = name;%0A        %7D%0A    %7D
 %0A%7D%0A

Add enum for chain names