Most of network routing is based on the destination. But sometimes you may need to forward packets to different gateways depending on the source.
In Linux you can do this using the iproute2 package. It uses netlink socket interface in order to handle addressment, routing, queuing and scheduling of Linux network subsystem. Follow an example:
Define a lable for a table to be used:
echo "10 foo" >> /etc/iproute2/rt_tables
Insert a route into foo table:
ip route add default via 10.10.10.1 dev eth1 table foo
Insert a rule with low priority in order to a host consult the new table foo:
ip rule add prio 10 from 192.168.16.7 lookup foo
You can check the rules with:
ip rule show list
Use the man for more information.