1. For a gateway that executes a datapath module for processing packets sent between a first network and a second network, a method comprising: receiving a packet from the first network; executing a plurality of pipeline stages for processing the packet and determining a next destination of the packet, wherein the plurality of pipeline stages comprises a set of logical forwarding element stages for performing packet forwarding and a set of service stages for performing transport layer services and application layer services, wherein each pipeline stage is a function called by the datapath module; and outputting the processed packet to a second network based on the next destination of the packet.