I need to build a system in which i am able to route packets based on a number of parameters, such as port/protocol etc, which are somehow "normal", but also on other aspects, such as queue length, and other external factors. My router is composed of 2 internal interfaces (802.11) and two external interfaces (one ADSL, one LTE). So I would like to examine each packet through an external program, and decide on what interface it should be routed.
I took a look at iproute2, but I didn't found any method to pass each packet to an external program, or somehow dynamically choose the route for each packet.
So the question: what is the best way to do this? Are there already tools that go in this direction, or should i rely on something made by myself, and passing the packet through linux standard tools?