First, there is no dynamic ACL going on here, and stateful inspection is not a factor, either. (But, read the last paragraph for an explanation of how FTP is special.) The firewall will perform stateful inspection regardless of the
inspect commands you have configured. Thus, return traffic will always make it back through the firewall because of this stateful behavior, which you can see in the connection table by doing a
The purpose of an
inspect statement is to invoke higher-OSI-layer examination. An example would be that the ESMTP inspection will drop connections where the SMTP client attempts to negotiate TLS. As you can see, that would be layer-7 examination to see that some payload did or did not contain something. That's what
inspect statements do.
In contrast to the
inspect statement, stateful inspection is only letting return traffic of already-permitted flows to come back through the firewall on the exact same ports on which they were initiated. That's layer 4 only.
Now, getting to the misconfig like the one you posted, my memory is a bit foggy from way-back when I read the documentation on this type of thing. If I remember correctly, the ASA will only process one
inspect statement for any given flow of traffic. So, since the
class ftp occurs first in the
policy-map test, the traffic will be inspected by the FTP inspection and not the HTTP inspection.
Now, because of the way FTP was designed (multiple TCP streams, dynamic ports), the ASA's FTP inspection has an extra special behavior. It will dig into the payload of the packets on TCP port 21 to look for operations that will open the FTP data channel (which will use TCP port 20). When these operations occur, the FTP payload will contain the TCP destination port number (some random number above 1024) that shall be used, and the ASA will quickly respond by adding a temporary ACL for the SYN packet of the data channel to pass through the firewall. Once the SYN gets through the firewall, stateful inspection kicks in and grants the return traffic to be permitted automatically. To reiterate, letting the SYN packet through is the function of the
inspect statement, where letting the return traffic through is a function of stateful inspection.
One final comment: you can actually permit FTP through your ASA firewall without using the
inspect ftp statement (despite this port 20 behavior) by simply building an ACL that allows traffic between the client and the server on port 21, and between the client and server in both direction on TCP port 20. You would effectively be accomplishing what the
inspect statement is intended to do. But that would be horrendously frowned upon by security folks. In contrast to that, you can not run your firewall without stateful inspection because (1) there is no way to turn it off that I know of, and (2) you would be removing all the security from inside your firewall.