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

Update IP version choosing logic in media transport creation for generating SDP offer. #4067

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

nanangizz
Copy link
Member

@nanangizz nanangizz commented Sep 6, 2024

This will update the behavior of account config's ipv6_media_use:

  • PJSUA_IPV6_DISABLED, media will always use IPv4 regardless (may use loopback/local-link IP address).
  • PJSUA_IPV6_ENABLED_USE_IPV6_ONLY, media will always use IPv6 regardless (may use loopback/local-link IP address).
  • PJSUA_IPV6_ENABLED_PREFER_IPV4, media will use IPv4 if usable, otherwise it may fallback to IPv6 (if it is usable). If none is usable, it will prioritize IPv4 (if available).
  • PJSUA_IPV6_ENABLED_PREFER_IPV6, media will use IPv6 if usable, otherwise it may fallback to IPv4 (if it is usable). If none is usable, it will prioritize IPv6 (if available).
  • PJSUA_IPV6_ENABLED or PJSUA_IPV6_ENABLED_NO_PREFERENCE, media will find any usable IP version, and prioritizing IPv4 (e.g: if both are usable/available).

By useable, it means that the host has an IP address that is not loopback, local-link, nor disabled/invalid.
By available, it means that the host has an IP address for the specified IP version, including loopback or local-link address.

Copy link
Member

@sauwming sauwming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great improvement!

@andreas-wehrmann
Copy link
Contributor

  • PJSUA_IPV6_ENABLED_PREFER_IPV4, media will use IPv4 if usable, otherwise it may fallback to IPv6 (if it is usable). If none is usable, it will prioritize IPv4 (if available).

  • PJSUA_IPV6_ENABLED_PREFER_IPV6, media will use IPv6 if usable, otherwise it may fallback to IPv4 (if it is usable). If none is usable, it will prioritize IPv4 (if available)

Is this true?
My expectation would be that for PJSUA_IPV6_ENABLED_PREFER_IPV6 it will prioritize IPv6 if none is available.

@nanangizz
Copy link
Member Author

  • PJSUA_IPV6_ENABLED_PREFER_IPV4, media will use IPv4 if usable, otherwise it may fallback to IPv6 (if it is usable). If none is usable, it will prioritize IPv4 (if available).
  • PJSUA_IPV6_ENABLED_PREFER_IPV6, media will use IPv6 if usable, otherwise it may fallback to IPv4 (if it is usable). If none is usable, it will prioritize IPv4 (if available)

Is this true? My expectation would be that for PJSUA_IPV6_ENABLED_PREFER_IPV6 it will prioritize IPv6 if none is available.

IMO the "preference" is originally for good scenario (i.e: both usable). But when there is a problem such as "both are not usable" (we expect media won't work), I assume that IPv4 may have a little bit better chance to work than IPv6 (e.g: because we used to deal with IPv4 more than IPv6)? I am open to this, let's hear what others may say.

Btw, as described in the definitions, "none is available" is different to "none is usable". But yes, even when both is not available, it will prioritize IPv4 for the same reason above.

@sauwming
Copy link
Member

sauwming commented Sep 9, 2024

Since the user has explicitly specified its IPv6 preference, IMO following the user would be more reasonable.

@andreas-wehrmann
Copy link
Contributor

Since the user has explicitly specified its IPv6 preference, IMO following the user would be more reasonable.

Right, that was my expectation when I read PREFER_IPV6.
But a fallback to IPv4 might still make sense, when an IPv4 is usable but IPv6 is only available.
The reverse is true for IPv4 to IPv6 fallback.

I'd like to hear what others think about this.

@nanangizz
Copy link
Member Author

Since the user has explicitly specified its IPv6 preference, IMO following the user would be more reasonable.

Right, that was my expectation when I read PREFER_IPV6. But a fallback to IPv4 might still make sense, when an IPv4 is usable but IPv6 is only available. The reverse is true for IPv4 to IPv6 fallback.

I'd like to hear what others think about this.

I've updated the behavior based on your comments in 76496f0. Thanks for the feedback :)

@wosrediinanatour
Copy link
Contributor

Maybe it may sense to split the enum/flags up in two or three. Could be more expressive.

@nanangizz
Copy link
Member Author

Maybe it may sense to split the enum/flags up in two or three. Could be more expressive.

For example?

@wosrediinanatour
Copy link
Contributor

For example?

enum {
PJSUA_IPV4 = 1,
PJSUA_IPV6 = 1 << 1
};
enum {
PJSUA_NO_PREFERENCE = 0,
PJSUA_PREFER_IPV4 = 1,
PJSUA_PREFER_ IPV6 = 2
};

For me, having 2 enums make it more expressive and it easier to reason about the cases.

@andreas-wehrmann
Copy link
Contributor

Having two enums adds a further conditional and in fact makes it somewhat unclear (at least to me); I prefer just one enum and am fine with the suggestion made by @nanangizz above.

What if neither PJSUA_IPV4 or PJSUA_IPV6 are set?
Having IPV4 to be the default seems to make sense because it has been the last couple of decades.

The suggested enum also reminded me of what you can set as socket option on dual-use sockets (IPV6_V6ONLY);
which made it look and feel familiar (at least to me).

Furthermore, how would you make it configurable in the app? Would you have two separate parameters? This seems unergonomic and not very user friendly (also remember, we're talking about the PJSUA layer here, which is pretty high level); and if you were to merge them together so that there's only one parameter? You'd probably end up with the suggestion above anyway.

@nanangizz
Copy link
Member Author

Looks like what you want is to separate settings of IP versions & fallback methods. Actually that is out of this PR scope.

Note that changing the enum names (and as mentioned by @andreas-wehrmann, perhaps also changing the setting into two separate params) may cause a backward compatibility issue, thing we try to avoid. Also note that the enum is shared by media & SIP signaling.

@wosrediinanatour
Copy link
Contributor

I am convinced :-)

@nanangizz nanangizz merged commit 7249136 into master Oct 1, 2024
36 checks passed
@nanangizz nanangizz deleted the update-ipv6-media-preference branch October 1, 2024 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants