Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please comment: fix updating dialog nexthop #183

Merged
merged 9 commits into from
Apr 26, 2022

Conversation

AlexAT
Copy link
Contributor

@AlexAT AlexAT commented Apr 25, 2022

This one PR is request for comments because the way it proposes to fix the described issue maybe is a bit overkill.

Issue description:
When i.e. first reply in the sequence with pre-defined next hop (like with SBC module) is received, SEMS updates dialog next hop to be used. If some 181/182 reply needing PRACK but not setting remote_tag (so not flagging connection being beyond first request) is received, PRACK is being sent with the pre-defined (and thus updated) next hop.

This should work normally, but there is one exception: the next hop is updated with unframed remote IP. This works for IPv4 but totally fails for IPv6 because IPv6 address needs to be [] framed in SIP. Thus, SEMS tries to resolve first IPv6 address portion before first : as domain then, and the port part is decoded totally wrong.

Of course it works wrong on any other similar dialog update (both request/reply based), just is not noticeable under most conditions except specific ones where this dialog next hop update is crucial.

Amendment:
The PR amends that by also storing SIP variant of remote IP (and local IP for complementary reasons) in the AmSipMsg object, and utilizes SIP variant to update dialogs next hop.

Doubts:
This fix is a bit overkill because it increases memory consumption for storing remote/local IP twice and does double work on each address to string conversion.

An alternative way of doing this may be storing some 'remote_ip_is_ipv6' flag and reusing it in the places remote_ip needs to be injected in SIP escaped way. But this would not be semantically correct as get_addr_str_sip() may potentially begin to do something beyond just escaping IPv6 addresses with [], and so the flag will not be enough.

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

Sample of the issue manifesting and logged:

sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/AmB2BSession.cpp:186] DEBUG: B2BSipRequest: PRACK (fwd=true)
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/AmB2BSession.cpp:795] DEBUG: relaying SIP request PRACK sip:1.2.3.4:5060;transport=udp
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/resolver.cpp:1080] DEBUG: sip_destination: 2a02:18308/udp
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/resolver.cpp:1005] DEBUG: checking whether '2a02' is IP address...
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/resolver.cpp:863] DEBUG: Querying '2a02' (A)...
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/resolver.cpp:417] DEBUG: Unknown domain: 2a02
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/resolver.cpp:1049] ERROR: Unresolvable Request URI domain
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/resolver.cpp:1083] ERROR: Unresolvable destination
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/sip/trans_layer.cpp:1248] DEBUG: resolve_targets failed
sems[68975]: [85715/rpmbuild/BUILD/sems-1.6.0/core/AmBasicSipDialog.cpp:737] ERROR: Could not send request: method=PRACK; call-id=7198BA98-62627D75000D0AC1-6EC2F700; cseq=11

@AlexAT AlexAT changed the title RFC: fix updating dialog nexthop Please comment: fix updating dialog nexthop Apr 25, 2022
@dmitry-sinina
Copy link

dmitry-sinina commented Apr 25, 2022

@AlexAT looks like you are active SEMS user/developer. Could you look thread #181
looks like problems related to routeset and to-tag applying related to some previous problematic patch.

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

@dmitry-sinina Sorry, I'm just a very minor contributor actually :) Not part of the base team.

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

I'm closing this PR then, will try building with the #181 reverted and post there.

@AlexAT AlexAT closed this Apr 25, 2022
@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

Actually...
Sorry for messing it up, a busy work day.

I'm reopening this as actually the dialog update code is still broken, be #181 reverted or not.

@AlexAT AlexAT reopened this Apr 25, 2022
@juha-h
Copy link
Contributor

juha-h commented Apr 25, 2022

In order to avoid storing both, is it not possible to convert local/remote_ip to local/remote_ip_sip when the latter is needed?

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

No, as msg->local_ip / msg->remote_ip connection information related is lost and not stored in AmSipMsg.

As said, we can store addr->ss_family as additional field instead and replicate am_inet_ntop_sip() encapsulation where it's needed, but that will semantically go against am_inet_ntop_sip() / get_addr_str_sip() abstraction, meaning we make part of their behavior cloned and fixed to the place it's cloned to.

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

If such loss of abstraction / introduction of hardcoded dependency is okay for the place, I'll rewrite the fix storing and reusing addr->ss_family instead though

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

Another option is naming remote_ip_sip (and local_ip_sip) something like remote_ip_sip_opt, and storing it ONLY if it differs from remote_ip_sip, storing empty string otherwise. But this looks too hacky, and requires a comparison.

@juha-h
Copy link
Contributor

juha-h commented Apr 25, 2022 via email

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

Technically yes. It's simply escaping with '[' and ']'.
Semantically doubtful, it requires us to know address class and thus breaks the get_addr_str_sip() abstraction we use.

@juha-h
Copy link
Contributor

juha-h commented Apr 25, 2022 via email

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

I suggest storing local_ip_is_ipv6 and remote_ip_is_ipv6 booleans then.
Yes, it will introduce a bit of hardcoded dependency instead of full address abstraction, but is the less CPU/memory consuming.

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

I will rewrite this PR adjustments using such flags in a little while.

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 25, 2022

A trivial rewrite, please review.
I'm going to test it in practice on today-tomorrow interval.

@juha-h
Copy link
Contributor

juha-h commented Apr 26, 2022

Latest version looks fine. It clearly is backwards compatible when addresses are IPv4.

Do you still want to make changes or should I merge the request?

@AlexAT
Copy link
Contributor Author

AlexAT commented Apr 26, 2022

Tested in practice and found working fine, can be merged.
Thanks!

@juha-h juha-h merged commit e4383ac into sems-server:master Apr 26, 2022
@AlexAT AlexAT deleted the update_dialog_nexthop branch April 26, 2022 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants