sergey-safarov created an issue (kamailio/kamailio#4290)
### Description According to [RFC3261](https://www.ietf.org/rfc/rfc3261.html#section-18.3) Section 18.3 ``` In the case of message-oriented transports (such as UDP), if the message has a Content-Length header field, the message body is assumed to contain that many bytes. If there are additional bytes in the transport packet beyond the end of the body, they MUST be discarded. ``` In the current Kamailio implementation, extra bytes are analyzed, and this triggers a failed sanity check.
### Troubleshooting
#### Reproduction
To reproduce required prepare config file ``` listen=udp:127.0.0.1:5060
loadmodule "xlog.so" loadmodule "sl.so" loadmodule "sanity.so"
modparam("sanity", "autodrop", 0) modparam("sanity", "noreply", 1)
route{ if(sanity_check()) { sl_send_reply("200", "OK"); exit; }
xerr("sanity checks failed\n"); sanity_reply(); drop; } ``` And start using a command like ``` kamailio -DD -E -f kamailio.cfg ``` Then need to send options using a command like ``` cat options-extra.txt | nc -u 127.0.0.1 5060 ``` Where `options-extra.txt` is a file from the attached archive
[options.tar.gz](https://github.com/user-attachments/files/20838024/options.tar.gz)
If you remove extra bytes after the OPTIONS message, then Kamailio does not generate an error. This can be tested using the command ``` cat options-normal.txt | nc -u 127.0.0.1 5060 ```
frideo left a comment (kamailio/kamailio#4290)
It's not an issue. That function, by default, includes checking the content-length, so it's doing what it's supposed to do. The module documentation explains this.
If you pass an argument that excludes 128, then this won't happen.
sergey-safarov left a comment (kamailio/kamailio#4290)
In the sanity module documentation, I can see
content length - (128) - checks if the size of the body matches the value from the Content-Length header.
Technically, the SIP message body is equal `Content-Length` header value. Here is the present trailer, which is not specified in the `sanity` module description.
When SDP is smaller or bigger than it is specified in the `Content-Length` header sanity check will properly drop the message because in this case it breaks the RFC. But in this case SIP message is RFC compliant.
miconda left a comment (kamailio/kamailio#4290)
The sanity module does not drop the message unless is configured so. Furthermore, all the tests of sanity module are configurable, it is config writer choice to do one or another.
You can set the body as you wish with the functions from the textops/x modules. There is a transformation that can be used to extract how many characters you want from a string. You can do conditions on `$cl` and `$bs` and decide what you want to do.
This is one of most powerful/appreciated features of Kamailio over the years: ability to be flexible in receiving SIP traffic so the config writer can fix messages sent by broken UAs. It offer tools/components that enables it to be compliant as much as possible, but it is the matter of the config writer to make it so, when needed/wanted.
sergey-safarov left a comment (kamailio/kamailio#4290)
Let me rephrase the issue description. Please start Kamailio with the config file ``` route{ forward(); } ``` And send an OPTIONS message using the command ``` cat options-extra.txt | nc -u 192.168.1.1 5060 ``` Where a private IP address needs to be replaced with the IP address of Kamailio on the network interface.
In this case, Kamailio will forward the OPTIONS message towards `158.51.225.1`. If you check the forwarded message, you will see the `trailer` bytes in the UDP frame.
If I understand the RFC requirements, `trailer` should be `discarded`.
In the case of message-oriented transports (such as UDP), if the
message has a Content-Length header field, the message body is assumed to contain that many bytes. If there are additional bytes in the transport packet beyond the end of the body, they MUST be discarded.
As I understand it, Kamailio does not meet these requirements.
Closed #4290 as completed.
miconda left a comment (kamailio/kamailio#4290)
Why you only put `forward()` in kamailio.cfg? Why just not empty? Or why not the conditions and actions I described in previous comment that allows you to set the body as you want, to shorter size or whatever else you want?
As a matter of fact, the body is not the business of the SIP proxy, it is the end point that has to understand and process it. Actually, by changing the body (e.g., for nat traversal, to replace connection IP and port in SDP), a proxy infringes the specs, but it is still done to make things (e.g., calls) work.
If you want to discuss further, use the sr-users mailing list, it is the place for discussing how to use kamailio and/or implement different features with kamailio, required or not by the specs. This is not about a bug in the source code.