boettner created an issue (kamailio/kamailio#4718)

### Description                                                                 
                                                                          

`sdp_get_address_family()` from the `sdpops` module does not return the address 
family when the SDP body has no session-level `c=` line and the connection 
information is only present per media description (`c=` below an `m=` line).    
              

What I expected: with an SDP body that contains exactly one `c=IN IP4 …` line 
at media level, `sdp_get_address_family()` returns `4`, but it does ont.

Replacing the call with `sdp_get_line_startswith("$avp(x)", "c=IN IP4")` 
correctly detects the IPv4 connection line, which confirms the address family 
is parseable and only the `sdp_get_address_family()` lookup misses it.

The [module documentation for 
`sdp_get_address_family()`](https://www.kamailio.org/docs/modules/stable/modules/sdpops.html#sdpops.f.sdp_get_address_family)
 does not mention this limitation, so it is unclear whether this is a bug or 
intended behaviour. Either way, please consider documenting the lookup scope 
(session-level only) and/or extending the implementation to fall back to the 
first media-level `c=` line when no session-level `c=` is present. WebRTC 
offers from Firefox/Mozilla routinely have only media-level `c=`, so the 
current behaviour is a foot-gun for anyone routing WebRTC traffic.

  ### Troubleshooting                                                           
                                                                              
   
  #### Reproduction                                                             
                                                                              
                                         
  Configuration snippet (simplified):

  if (has_body() && sdp_with_ice()) {                                           
                                                                              
      $avp(af) = sdp_get_address_family();
      xlog("L_INFO", "sdp_get_address_family => $avp(af)\n");                   
                                                                              
  }                                                                             
                                                                              
                                                                                
                                                                              
  Send an INVITE whose SDP body contains no session-level `c=` line, only a 
media-level `c=IN IP4 …`:                                                       
  
```                                                                             
                                                                            
  v=0
  o=user1 53655765 2353687637 IN IP6 2001:db8::1                                
                                                                              
  s=-                                                                           
                                                                              
  t=0 0
  a=group:BUNDLE 0                                                              
                                                                              
  m=audio 9 UDP/TLS/RTP/SAVPF 111 0 8                                           
                                                                              
  c=IN IP4 198.51.100.9                                                         
                                                                              
  a=rtcp:9 IN IP4 0.0.0.0                                                       
                                                                              
  a=ice-ufrag:69ew                                                              
                                                                              
  a=ice-pwd:0dPg1o51hP5rXPExjrUfCU8r                                            
                                                                              
  a=fingerprint:sha-256 
83:BF:7A:75:29:C4:ED:94:67:ED:22:CC:A9:5F:18:96:A6:78:0F:0D:2E:23:81:A6:89:CF:D7:DB:9E:EE:61:7E
                                       
  a=setup:actpass                                                               
                                                                              
  a=mid:0                                                                       
                                                                              
  a=sendrecv                                                                    
                                                                              
  a=rtcp-mux                                                                    
                                                                              
  a=rtpmap:111 opus/48000/2
  a=rtpmap:0 PCMU/8000                                                          
                                                                              
  a=rtpmap:8 PCMA/8000                   
```
The xlog line does not show `=> 4`. Adding a session-level `c=IN IP4 
198.51.100.9` above the `m=` line makes the same call return `4`.

### Possible Solutions                                                          
                                                                            

- **Documentation:** add a note to `sdp_get_address_family()` stating that only 
the session-level `c=` line is inspected, and recommend 
`sdp_get_line_startswith()` (or a future per-media variant) for SDP bodies 
without a session-level `c=`.
- **Code:** if no session-level `c=` line is found, fall back to the first 
media-level `c=` line.

A workaround we are using:

```
if (sdp_get_line_startswith("$avp(c_line)", "c=IN IP4")) { ... }                
                                                                            
```

### Additional Information                                                      
                                                                            
 
* **Kamailio Version** `kamailio 5.8.7`

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4718
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/[email protected]>
_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to