I see two errors:
1) You said "inbound" in your description, but your example is for an outbound INVITE.
2) You are providing three parameters to the modifyHeader function, but it only takes two
Alos, keep in mind that if you need to modify the IP address because of NAT, then you'll likely need to modify it in every single type of message (requests and responses), not just the inbound INVITEs. Plus you'll need it in all headers (E.g., Via) which might contain the 10.9.5.8 address.
This is probably easier with a firewall which can do deep packet inspection and re-write the addresses for you automatically.
At any rate, to help you with your single INVITE request change on the To header, try this:
M = {}
function M.inbound_INVITE(msg)
local orig_to = msg:getHeader("To")
local new_to = orig_to:gsub("10.9.5.8", "10.1.1.1")
msg:modifyHeader("To", new_to)
end
return M