Skip to content

Add support for subdomain checking in aliases and socket aliases#3458

Merged
liviuchircu merged 5 commits into
OpenSIPS:masterfrom
purecloudlabs:subdomain_alias
May 20, 2025
Merged

Add support for subdomain checking in aliases and socket aliases#3458
liviuchircu merged 5 commits into
OpenSIPS:masterfrom
purecloudlabs:subdomain_alias

Conversation

@davidtrihy-genesys
Copy link
Copy Markdown
Contributor

Summary
Adds support for subdomains in aliases and socket aliases

Details
New feature related to this issue #1466

When defining sockets or aliases we can mark them with subdomain so that when check_self is called it will match when there the host to check is subdomain of the alias, definition of the socket and alias as so

socket = udp:127.0.0.1:5060 as my.subdomain.com subdomain

or

alias = udp:my.subdomain.com:5060 subdomain

If either are set up this way then when check_self is called for example in the TM topology_hiding then if the request domain is something like resource.my.subdomain.com or different.resource.my.subdomain.com it will match the alias but also a deliberate design decision to allow my.subdomain.com to match too.

Solution
A flag is added, when the subdomain|SUBDOMAIN flag is on the socket or alias this allows it to match addresses that match that alias subdomain while preserving strict matching when the flag is not set

Compatibility
The flag is a new flag so existing config where the subdomain flag is not on the alias or socket will behave like it already does without this change, it's backwards compatible

Closing issues
closes #1466

@bogdan-iancu bogdan-iancu self-assigned this Sep 13, 2024
Copy link
Copy Markdown
Member

@bogdan-iancu bogdan-iancu left a comment

Choose a reason for hiding this comment

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

The overall approach of the patch is good, great idea here! With a bit of changes, we could merge it, please see my comments.
What needs to be taken into consideration is the extension of the domain module (when aliases are provisioned via DB), to also support sub-domains - maybe something like an extra flag column. This will do a 100% coverage of the SIP-domains support in OpenSIPS

Comment thread cfg.lex Outdated
Comment thread cfg.y Outdated
Comment thread cfg.y Outdated
Comment thread name_alias.c Outdated
Comment thread name_alias.h Outdated
@davidtrihy-genesys
Copy link
Copy Markdown
Contributor Author

Hi Bogdan, thanks for the feedback I'll work on integrating the changes you requested in the coming week

@bogdan-iancu
Copy link
Copy Markdown
Member

just a gentle ping here :)

@bogdan-iancu
Copy link
Copy Markdown
Member

and one more gentle ping here :)

@davidtrihy-genesys
Copy link
Copy Markdown
Contributor Author

@bogdan-iancu sorry I've been quite busy, the grammar changes and the fix suggested for ensuring we strictly match subdomains works.

I also believe I have the domain changes working when you load the hash table into memory, the check for that is a lot easier as it can utilise the name_alias changes and provide the domain to check and the accept_subdomain parameter from the db instead of the socket aliases, still need to verify my changes work there but I think they should, just need to setup my env to add the new column.

The main reason why I haven't pushed these changes yet is I'm having trouble with the domain module when you do not load the table into memory (ie. db mode == 0) the query for this is a strict SELECT * from domain where domain == 'super.mario.com' via this piece of code domain_dbf.query(db_handle, keys, 0, vals, cols, 1, 2, 0, &res) my understanding here is that it does just do that strict select so there would need to be some refactor done to achieve this lookup.

One area would be to tokenise the domain so that we could potentially do multiple queries so domain four.sub.domain.com would be able to query for any subdomain of sub.domain.com or domain.com because the logic dictates that you should be able to match it against either if the accept_subdomain flag is set, this should be relatively easily achieved by doing a SELECT * from domain where domain LIKE '%domain.com' then just looping through the results and matching if the accept_subdomain is true.

Do you have any good example you can point me to achieve this LIKE query otherwise when db mode is 0 the lookup will be very difficult to achieve or non performant, one thing we could do is to do multiple db queries of domain == 'four.sub.domain.com' then domain == 'sub.domain.com' etc... but that is not an approach I particularly like.

If I could your thoughts I could have this finished quickly enough as I have the bulk of the changes just that scenario described and I need to test it

@davidtrihy-genesys
Copy link
Copy Markdown
Contributor Author

@bogdan-iancu I got the feature added to the domain module, I don't think there's anyway around needing to iterate through the domain to check each one against the host and accepting the subdomain.

I have tested it with both db mode on and off and with accept subdomain on and off and it works, also the new grammar you suggested is there too along with the fixes you mentioned.

There was a failure checking the rtpio I'm not sure if what I did affected that, let me know your thoughts on the PR

@davidtrihy-genesys
Copy link
Copy Markdown
Contributor Author

Just added in some comments to explain the algorithm @bogdan-iancu I understand this feature you have tagged for 3.6-dev which I presume means you would like it in before the conference on the 26th so let me know if you want to have a chat and we can try and fix any residual issues you may have with my PR or if you need clarification

Comment thread modules/domain/domain.c
* Check if domain is local and store attributes in a pvar
*/
int is_domain_local_pvar(struct sip_msg *msg, str* _host, pv_spec_t *pv)
int db_table_lookup(struct sip_msg *msg, str *lookup_domain, str *host, pv_spec_t *pv)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is mostly just the existing is_domain_local_pvar refactored into a specific db lookup function with one minor change where it first gets the accept_subdomain column and does the match subdomain based on the supplied host rather than implictly trusting it matches based on getting a result back

Comment thread name_alias.h

extern struct alias_function* alias_fcts;

static inline int match_domain(char* alias, int alias_len, char* host, int host_len, int accept_subdomain) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Broke this functionality out into a separate function so it could be exposed to the domain module for use there, this file is part of the core OpenSIPs so the domain module will always have access to this file regardless of the Makefile definitions

Copy link
Copy Markdown
Member

@bogdan-iancu bogdan-iancu left a comment

Choose a reason for hiding this comment

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

Thank you @davidtrihy-genesys , it looks good - what is missing is the increment on the table version for "domain" (as the schema changed), but as we are in a hurry for 3.6 release, I will take care of that after merging ;)

@davidtrihy-genesys
Copy link
Copy Markdown
Contributor Author

@bogdan-iancu thanks for reviewing and I'll see you in Amsterdam next Monday!

@liviuchircu liviuchircu merged commit 96f2fa6 into OpenSIPS:master May 20, 2025
86 checks passed
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.

3 participants