Search in sources :

Example 21 with IpAccessListLine

use of org.batfish.datamodel.IpAccessListLine in project batfish by batfish.

the class Region method applySecurityGroupsAcls.

private void applySecurityGroupsAcls(Map<String, Configuration> cfgNodes) {
    for (Entry<String, Set<SecurityGroup>> entry : _configurationSecurityGroups.entrySet()) {
        Configuration cfgNode = cfgNodes.get(entry.getKey());
        List<IpAccessListLine> inboundRules = new LinkedList<>();
        List<IpAccessListLine> outboundRules = new LinkedList<>();
        entry.getValue().forEach(securityGroup -> securityGroup.addInOutAccessLines(inboundRules, outboundRules, this));
        // create ACLs from inboundRules and outboundRules
        IpAccessList inAcl = new IpAccessList(SG_INGRESS_ACL_NAME, inboundRules);
        IpAccessList outAcl = new IpAccessList(SG_EGRESS_ACL_NAME, outboundRules);
        cfgNode.getIpAccessLists().put(SG_INGRESS_ACL_NAME, inAcl);
        cfgNode.getIpAccessLists().put(SG_EGRESS_ACL_NAME, outAcl);
        // applying the filters to all interfaces in the node
        cfgNode.getInterfaces().values().forEach(iface -> {
            iface.setIncomingFilter(inAcl);
            iface.setOutgoingFilter(outAcl);
        });
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Configuration(org.batfish.datamodel.Configuration) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) IpAccessList(org.batfish.datamodel.IpAccessList) LinkedList(java.util.LinkedList)

Example 22 with IpAccessListLine

use of org.batfish.datamodel.IpAccessListLine in project batfish by batfish.

the class IpPermissions method toIpAccessListLine.

private IpAccessListLine toIpAccessListLine() {
    IpAccessListLine line = new IpAccessListLine();
    line.setAction(LineAction.ACCEPT);
    IpProtocol protocol = toIpProtocol(_ipProtocol);
    if (protocol != null) {
        line.setIpProtocols(Collections.singleton(protocol));
    }
    // if the range isn't all ports, set it in ACL
    if (_fromPort != 0 || _toPort != 65535) {
        line.setDstPorts(Collections.singleton(new SubRange(_fromPort, _toPort)));
    }
    return line;
}
Also used : IpProtocol(org.batfish.datamodel.IpProtocol) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) SubRange(org.batfish.datamodel.SubRange)

Example 23 with IpAccessListLine

use of org.batfish.datamodel.IpAccessListLine in project batfish by batfish.

the class IpPermissions method toIngressIpAccessListLine.

public IpAccessListLine toIngressIpAccessListLine(Region region) {
    IpAccessListLine line = toIpAccessListLine();
    line.setSrcIps(collectIpWildCards(region));
    return line;
}
Also used : IpAccessListLine(org.batfish.datamodel.IpAccessListLine)

Example 24 with IpAccessListLine

use of org.batfish.datamodel.IpAccessListLine in project batfish by batfish.

the class IptablesVendorConfiguration method applyAsOverlay.

public void applyAsOverlay(Configuration configuration, Warnings warnings) {
    IpAccessList prerouting = configuration.getIpAccessLists().remove("mangle::PREROUTING");
    IpAccessList postrouting = configuration.getIpAccessLists().remove("mangle::POSTROUTING");
    if (!configuration.getIpAccessLists().isEmpty()) {
        throw new BatfishException("Merging iptables rules for " + configuration.getName() + ": only mangle tables are supported");
    }
    if (prerouting != null) {
        for (Interface i : configuration.getInterfaces().values()) {
            String dbgName = configuration.getHostname() + ":" + i.getName();
            List<IpAccessListLine> newRules = prerouting.getLines().stream().filter(l -> {
                String iface = _lineInInterfaces.get(l);
                return iface == null || i.getName().equals(iface);
            }).collect(Collectors.toList());
            if (i.getIncomingFilter() != null) {
                throw new BatfishException(dbgName + " already has a filter," + " cannot combine with iptables rules!");
            }
            String aclName = "iptables_" + i.getName() + "_ingress";
            IpAccessList acl = new IpAccessList(aclName, newRules);
            if (configuration.getIpAccessLists().putIfAbsent(aclName, acl) != null) {
                throw new BatfishException(dbgName + " acl " + aclName + " already exists");
            }
            i.setIncomingFilter(acl);
        }
    }
    if (postrouting != null) {
        for (Interface i : configuration.getInterfaces().values()) {
            String dbgName = configuration.getHostname() + ":" + i.getName();
            List<IpAccessListLine> newRules = postrouting.getLines().stream().filter(l -> {
                String iface = _lineOutInterfaces.get(l);
                return iface == null || i.getName().equals(iface);
            }).collect(Collectors.toList());
            if (i.getOutgoingFilter() != null) {
                throw new BatfishException(dbgName + " already has a filter," + " cannot combine with iptables rules!");
            }
            String aclName = "iptables_" + i.getName() + "_egress";
            IpAccessList acl = new IpAccessList(aclName, newRules);
            if (configuration.getIpAccessLists().putIfAbsent(aclName, acl) != null) {
                throw new BatfishException(dbgName + " acl " + aclName + " already exists");
            }
            i.setOutgoingFilter(acl);
        }
    }
}
Also used : ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) Iterables(com.google.common.collect.Iterables) IdentityHashMap(java.util.IdentityHashMap) SortedSet(java.util.SortedSet) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Set(java.util.Set) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) Collectors(java.util.stream.Collectors) Interface(org.batfish.datamodel.Interface) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) Warnings(org.batfish.common.Warnings) Map(java.util.Map) Entry(java.util.Map.Entry) Configuration(org.batfish.datamodel.Configuration) LineAction(org.batfish.datamodel.LineAction) Collections(java.util.Collections) VendorConversionException(org.batfish.common.VendorConversionException) BatfishException(org.batfish.common.BatfishException) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) IpAccessList(org.batfish.datamodel.IpAccessList) Interface(org.batfish.datamodel.Interface)

Example 25 with IpAccessListLine

use of org.batfish.datamodel.IpAccessListLine in project batfish by batfish.

the class BdpDataPlanePluginTest method makeAclLine.

@SuppressWarnings("unused")
private static IpAccessListLine makeAclLine(LineAction action) {
    IpAccessListLine aclLine = new IpAccessListLine();
    aclLine.setAction(action);
    return aclLine;
}
Also used : IpAccessListLine(org.batfish.datamodel.IpAccessListLine)

Aggregations

IpAccessListLine (org.batfish.datamodel.IpAccessListLine)35 IpWildcard (org.batfish.datamodel.IpWildcard)17 Test (org.junit.Test)17 IpAccessList (org.batfish.datamodel.IpAccessList)15 LinkedList (java.util.LinkedList)13 SubRange (org.batfish.datamodel.SubRange)12 Configuration (org.batfish.datamodel.Configuration)8 ImmutableList (com.google.common.collect.ImmutableList)6 ArrayList (java.util.ArrayList)6 Interface (org.batfish.datamodel.Interface)6 Set (java.util.Set)5 BatfishException (org.batfish.common.BatfishException)5 Ip (org.batfish.datamodel.Ip)5 LineAction (org.batfish.datamodel.LineAction)5 IpProtocol (org.batfish.datamodel.IpProtocol)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Prefix (org.batfish.datamodel.Prefix)3