Election time is upon us, and lots of our customers are getting hit with unwanted dialer traffic (some people refer to this as robocalls). To combat this, here is a simple albeit far from fool-proof way to limit the amount of calls being sent from particular users.
The advantages of using Redis for this are as follows:
- It is a very light-weight solution
- It's configured with a time to live (TTL) so that blocks will fall off over time
- This solution is highly configurable
- It's very easy to troubleshoot
The following is the base configuration that belongs in your opensips.cfg. It rejects all calls from a unique From URI after that From URI exceeds 50 calls per minute. Simple modifications will allow you to adjust based upon your business rules. For example, limiting by Request URI would easy with a few simple changes this.
First we load the redis module and connect to the Redis server.
Create the rate limiter route. $fu, ttl and max values can easily be changed to something more appropriate for your setup.
Finally call the route, check the return value, then take action. In this case, send a 480 reply.