<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [x] Commit message has the format required by CONTRIBUTING guide - [x] Commits are split per component (core, individual modules, libs, utils, ...) - [x] Each component has a single commit (if not, squash them into one commit) - [x] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [] Small bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [x] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail -->
This PR aims to add support for PRT queries in ipops module.
Some functions were modified to accommodate and reuse the structures already defined for DNS.
Any feedback is appreciated! You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/3802
-- Commit Summary --
* ipops: Move structures to header * ipops: Add PTR query support
-- File Changes --
M src/modules/ipops/ipops_mod.c (30) M src/modules/ipops/ipops_pv.c (162) M src/modules/ipops/ipops_pv.h (33)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/3802.patch https://github.com/kamailio/kamailio/pull/3802.diff
The topic contains a spelling error - you mean PTR and not PRT :-)
Please add documentation as well
Oh good catch!
Yep, will do!
@oej commented on this pull request.
@@ -1292,6 +1297,31 @@ static int ki_dns_query(sip_msg_t *msg, str *naptrname, str *pvid)
return dns_update_pv(naptrname, pvid); }
+/** + *
There is room for a description of the function here - that's why we have comments before functions.
@oej commented on this pull request.
+/**
+ * + */ +static int w_ptr_query(sip_msg_t *msg, char *ip, char *pv_name) +{ + str ip_address; + str name; + + if(msg == NULL) { + LM_ERR("received null msg\n"); + return -1; + } + + if(fixup_get_svalue(msg, (gparam_t *)ip, &ip_address) < 0) { + LM_ERR("cannot get the IP address\n"); + return -1;
Just thinking loud - any reason you want different returns in different situations in your scripts? All errors return exactly the same value here.
@xkaraman pushed 1 commit.
be6447a94e0e8871da2a813f638f36afea786250 ipops: Add ptr_query docs
@xkaraman commented on this pull request.
@@ -1292,6 +1297,31 @@ static int ki_dns_query(sip_msg_t *msg, str *naptrname, str *pvid)
return dns_update_pv(naptrname, pvid); }
+/** + *
I'll be glad to add some comments! i was just following the style in the file that was just above! Should have noticed all the others do have some brief comments. Will add some.
@xkaraman commented on this pull request.
+/**
+ * + */ +static int w_ptr_query(sip_msg_t *msg, char *ip, char *pv_name) +{ + str ip_address; + str name; + + if(msg == NULL) { + LM_ERR("received null msg\n"); + return -1; + } + + if(fixup_get_svalue(msg, (gparam_t *)ip, &ip_address) < 0) { + LM_ERR("cannot get the IP address\n"); + return -1;
I followed the `w_dns_query` as a base and assumed this is how error reporting is done. How would you like me to change them?
Docs added regarding `ptr_query`.
@xkaraman pushed 1 commit.
06e86a429dec156951d938e9e4b6590f61ac2a86 ipops: Add brief comment for ptr_query
@xkaraman commented on this pull request.
@@ -1292,6 +1297,31 @@ static int ki_dns_query(sip_msg_t *msg, str *naptrname, str *pvid)
return dns_update_pv(naptrname, pvid); }
+/** + *
Fixed
@oej commented on this pull request.
You're doing good. Just a few small nits after reading it again.
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip
s/ip/an IP address/
Also document if you support both IPv4 and IPv6 clearly. Thanks!
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname).
You mean a "pseudo variable" not a config variable.
<title>
+ <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname). + </para> + + <para>Parameters:</para> + + <itemizedlist> + <listitem> + <para> + <emphasis>ip</emphasis> - string or pseudo-variable containing the ip. + The resulting IP addresses from DNS query are compared with ipaddr.
In line 901 you just say "ip" and here "ipaddr". I suggest you write clear text on both cases. Like "containing the IP address" and "compared with the IP address"
Store the hostname that correspond to ip
+ in a config variable $ptrquery(pvid=>hostname). + </para> + + <para>Parameters:</para> + + <itemizedlist> + <listitem> + <para> + <emphasis>ip</emphasis> - string or pseudo-variable containing the ip. + The resulting IP addresses from DNS query are compared with ipaddr. + </para> + </listitem> + <listitem> + <para> + <emphasis>pvid</emphasis> - container id for script variable.
I don't think we call a pseudo variable a "container" anywhere. If so, I consider it a bug :-)
@@ -418,6 +413,91 @@ int dns_update_pv(str *hostname, str *name)
return 1; }
+/* +*
Add a comment here
@@ -24,13 +24,46 @@
#define _IPOPS_PV_H_
#include "../../core/pvar.h" +#define PV_DNS_ADDR 64 +#define PV_DNS_RECS 32 +#define SR_DNS_PVIDX 1 + +typedef struct _sr_dns_record +{ + int type; + char addr[PV_DNS_ADDR]; +} sr_dns_record_t; +typedef struct _sr_dns_item
Empty line missing
+/**
+ * + */ +static int w_ptr_query(sip_msg_t *msg, char *ip, char *pv_name) +{ + str ip_address; + str name; + + if(msg == NULL) { + LM_ERR("received null msg\n"); + return -1; + } + + if(fixup_get_svalue(msg, (gparam_t *)ip, &ip_address) < 0) { + LM_ERR("cannot get the IP address\n"); + return -1;
Depends if you think there's any point of separating the various errors from each other in the script of if it doesn't matter - the coder just want to know that it failed, not caring about how. There are several functions in other modules, like TM, that has multiple return values. It's really up to you, just a suggestion that you consider this.
@henningw commented on this pull request.
Store the hostname that correspond to ip
+ in a config variable $ptrquery(pvid=>hostname). + </para> + + <para>Parameters:</para> + + <itemizedlist> + <listitem> + <para> + <emphasis>ip</emphasis> - string or pseudo-variable containing the ip. + The resulting IP addresses from DNS query are compared with ipaddr. + </para> + </listitem> + <listitem> + <para> + <emphasis>pvid</emphasis> - container id for script variable.
Actually the module uses already the term "container" in 3 places. So its probably fine in this regards.
@henningw commented on this pull request.
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname).
The term "config variable" is also already used in the module, but I agree its probably more clear to spell it explictly.
@xkaraman commented on this pull request.
Store the hostname that correspond to ip
+ in a config variable $ptrquery(pvid=>hostname). + </para> + + <para>Parameters:</para> + + <itemizedlist> + <listitem> + <para> + <emphasis>ip</emphasis> - string or pseudo-variable containing the ip. + The resulting IP addresses from DNS query are compared with ipaddr. + </para> + </listitem> + <listitem> + <para> + <emphasis>pvid</emphasis> - container id for script variable.
These were mostly taken from dns_query docs and just altered it where it made sense.
@oej commented on this pull request.
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname).
You are right. But it doesn't make it more correct... :-)
xkaraman - you decide if you want to improve the docs or keep it at the current state.
@xkaraman commented on this pull request.
Store the hostname that correspond to ip
+ in a config variable $ptrquery(pvid=>hostname). + </para> + + <para>Parameters:</para> + + <itemizedlist> + <listitem> + <para> + <emphasis>ip</emphasis> - string or pseudo-variable containing the ip. + The resulting IP addresses from DNS query are compared with ipaddr. + </para> + </listitem> + <listitem> + <para> + <emphasis>pvid</emphasis> - container id for script variable.
What is the correct term for the `member/container` inside a pv that has multiple keys to get info from?
@xkaraman pushed 4 commits.
348b95f86226b38ece4706684145caeab40272b9 ipops/docs: Add docs 893df07908c758863f814303b3689f172b9d7a2a ipops: Fix ip_type 60a70eebfc57c2103029b1afab60473441dad3cc ipops: Add new line 3027862b16052a8f08275fcc1f929c05c08aa98c ipops/doc: Update docs
@xkaraman commented on this pull request.
<emphasis>ipv4</emphasis> - 1 if IPv4 address
+ </para> + </listitem> + <listitem> + <para> + <emphasis>ipv6</emphasis> - 1 if IPv6 address + </para> + </listitem>
For these i am not exactly sure their purpose. They were accesible before these commits. Are they for counting IPv4/6 in dns_query or just to check if at least one IPv4/6 is associated with hostname?
@xkaraman commented on this pull request.
@@ -418,6 +413,91 @@ int dns_update_pv(str *hostname, str *name)
return 1; }
+/* +*
Fixed
@xkaraman commented on this pull request.
<title>
+ <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname). + </para> + + <para>Parameters:</para> + + <itemizedlist> + <listitem> + <para> + <emphasis>ip</emphasis> - string or pseudo-variable containing the ip. + The resulting IP addresses from DNS query are compared with ipaddr.
Removed altogether. there is no comparison done at all. It must be a leftover from DNS query.
@xkaraman commented on this pull request.
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname).
Fixed
@xkaraman commented on this pull request.
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip
Fixed
@xkaraman commented on this pull request.
+/**
+ * + */ +static int w_ptr_query(sip_msg_t *msg, char *ip, char *pv_name) +{ + str ip_address; + str name; + + if(msg == NULL) { + LM_ERR("received null msg\n"); + return -1; + } + + if(fixup_get_svalue(msg, (gparam_t *)ip, &ip_address) < 0) { + LM_ERR("cannot get the IP address\n"); + return -1;
Main reason i see for separating errors is for debugging purposes.
Another thing, that might be good, would be to separate the failure over bad input and successful call with no hostname associated ([getnameinfo](https://man7.org/linux/man-pages/man3/getnameinfo.3.html)). Do you think this makes sense to separate and document it?
Other than that, as you have said the code just want to know it had failed and not how.
@miconda commented on this pull request.
@@ -883,6 +883,57 @@ if(dns_query("test.com", "xyz"))
</section>
+ <section id="ipops.f.ptr_query"> + <title> + <function moreinfo="none">ptr_query(ip, pvid)</function> + </title> + + <para> + Store the hostname that correspond to ip + in a config variable $ptrquery(pvid=>hostname).
I use both terms config variables and pseudo variables, and I am referring to the same concept. Historically the term pseudo-variables was used from developer's perspective, trying to differentiate them from C-style variables. Over the time, I noticed that config-variables are easier to "understand" what one refers to, specially by those coming new to use Kamailio.
In other words, pseudo-variables tries to define them from technical point of view (i.e., no declaration, no explicit type association, automatically available by loading various modules, some read-only, other read-write). The config-variables indicates where these variables are available/can be used.
@oej commented on this pull request.
+/**
+ * + */ +static int w_ptr_query(sip_msg_t *msg, char *ip, char *pv_name) +{ + str ip_address; + str name; + + if(msg == NULL) { + LM_ERR("received null msg\n"); + return -1; + } + + if(fixup_get_svalue(msg, (gparam_t *)ip, &ip_address) < 0) { + LM_ERR("cannot get the IP address\n"); + return -1;
Seems like you have reasons for multiple return values, so go ahead.
@xkaraman pushed 5 commits.
8fa52eaa74ddb2a1fecb0fbc6cebf0cb7adb8ea3 ipops: Move structures to header c830d0ddd9bcf053f5ed570d7ce92a5eabf68310 ipops: Add PTR query support e987f151ad87c0a611b8a3320cecbb7379b09767 ipops: Add ptr_query docs 624b3c4f2dff29d038d929197690d6c223e9c531 ipops: Add brief comment for ptr_query 45f84873d03f87bff0c8d0cfe8385c5c6c2520d0 ipops: Add KEMI wrapper for ptr_query function
So i've rebased to master and squashed some commits to make it more manageable. I have also add some more in-code comments/doc.
If there are no other suggestions/review, I will merge it soon.
I'm good. Good work!
Merged #3802 into master.
Thanks! Merged!