Local messages are malformed in Kamailio 4.4.X. For example after receiving an error response (603) to an INVITE message, the ACK is generated with header Max-Forwards concatenated to header CSeq and double CRLF, which is wrong.

Via: SIP/2.0/TLS 173.16.10.61:5061;branch=z9hG4bKc782.5b960c7c48a4363a0126963daa797eb0.0;i=7
From: "22861"<sip:22861@173.16.10.61;transport=tls>;tag=snl_OIPEOzJUNy
Call-ID: 61b500a71b510a1Pj61qq1k9dPW
To: <sip:551138174108@174.16.4.108:5061;transport=tls>;tag=435012226
CSeq: 2351 ACKMax-Forwards: 70

User-Agent:...


The fix for that seems to be just the order of append_str in function build_local() from tm\t_msgbuilder.c.

append_str( p, method, method_len );
+ append_str( p, CRLF, CRLF_LEN );
append_str( p, MAXFWD_HEADER, MAXFWD_HEADER_LEN );
- append_str( p, CRLF, CRLF_LEN );