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

PDB module prefixes #433

Closed
igorPot opened this issue Dec 8, 2015 · 9 comments
Closed

PDB module prefixes #433

igorPot opened this issue Dec 8, 2015 · 9 comments

Comments

@igorPot
Copy link

igorPot commented Dec 8, 2015

Hi all,

I had configured my pdb module to accept 5 number prefixes by modifying:

In pdbt.c:

 bufsize = slen + 1 + 1 + 4 + 1 + 1; // line buffer (telephone number + colon + white space + carrier ID + newline + \0)

 ...

  ret = snprintf(p, 7, "%d\n", node->carrier);
           if (ret < 1 || ret > 6) {

And in common.h:

 #define MAX_PDB_CARRIERID 99999

And i hadn't had any problem until now. I had rows in my .csv like:

0645052050;10122

And it worked. The problem I have now is with prefixes bigger than 40000. I get segmentation fault when doiong a query with pdbt, however the pdbt build works good without any error.

At first i thought of a buffer problem but eventhough testing with a .csv of 2 rows with 50000 prefixes will not work. Another curious effect is that for a prefix like 84238 the server changes the answer to 18754. I dont know why...

Could anyone help me please?

Thanks.

@smititelu
Copy link
Contributor

Hi Igor,

Looking at the kamailio pdb module code I can see that it should work well for prefixes smaller than the MAX_SHORT_INT= 32767 = 2^15-1 because:

typedef int16_t carrier_t;
...
struct dt_node_t {
    struct dt_node_t *child[10];
    carrier_t carrier;
};

Also I think you should try:

bufsize = slen + 1 + 1 + *5* + 1 + 1; // instead of your "+ 4"

Also the utils/pdbt/pdb_server.c is using the same int16_t for carrierid.

This can be an idea of enhancing the kamailio pdb module to be able to set the number of prefix digits via modparam (and use uint32_t for carrierid).

@igorPot
Copy link
Author

igorPot commented Dec 8, 2015

Hi,

Yes sorry, I had:

 bufsize = slen + 1 + 1 + 5 + 1 + 1; // instead of your "+ 4"

Good point, I think you are right about the int16 limitation, I will try and let you know hank you very much.

@igorPot
Copy link
Author

igorPot commented Dec 8, 2015

Where did you find :

typedef int16_t carrier_t;
 ...
 struct dt_node_t {
struct dt_node_t *child[10];
carrier_t carrier;
 };

In dt.h I only see:

 struct dt_node_t {
    struct dt_node_t *child[10];
    carrier_t carrier;
 };

@igorPot
Copy link
Author

igorPot commented Dec 8, 2015

I have now made the following changes:

pdbt.c:

 bufsize = slen + 1 + 1 + 5 + 1 + 1; // line buffer (telephone number + colon + white space + carrier ID + newline + \0)
 ret = snprintf(p, 7, "%d\n", node->carrier);
           if (ret < 1 || ret > 6) {

common.h:

 #define MAX_PDB_CARRIERID 99999
 #define MAX_CARRIERID 99999
 …
 typedef int32_t carrier_t;

I still get no answer for prefixes bigger than 32767. I have a server with only this two lines :

 0778667682;32768
 0781541867;32767

The results of 2 querys are:

 processing command line parameters...
 got an answer in 0.180000 ms
 0778667682: not_found: comment=''

 processing command line parameters...
 got an answer in 0.155000 ms
 0781541867:32767:unknown carrier

@smititelu
Copy link
Contributor

The changes are not trivial.

You have to change to uint_32 in all the places where int_16 is used (or short int) for the carrierid, in order to avoid conversion. This implies changes to both pdb client (kamailio pdb module) and pdb server(see utils/pdbt folder).

Also have a look on the comunication protocol between pdb server<->client (see utils/pdbt/docs/network_protocol.txt)

@igorPot
Copy link
Author

igorPot commented Dec 8, 2015

I have made some progress, I can reach now 65535.

I have no pdb client module running now, it's just the server and I am testing with pdbt:

 pdbt -r XX.XX.XX.XX:10001 query 0778667682

Now I have changed the int16_t to uint32_t and the short int to uint32_t also but I get the same result eventhough is unsigned:

pdbt.c:

  bufsize = slen + 1 + 1 + 5 + 1 + 1; // line buffer (telephone number + colon + white space + carrier ID + newline + \0)
  ret = snprintf(p, 7, "%d\n", node->carrier);
       if (ret < 1 || ret > 6) {
 …

    uint32_t carrierid;

 …

 carrierid=ntohs(*((uint32_t *)&(buf[reqlen]))); /* convert to host byte order */

common.h:

  #define MAX_PDB_CARRIERID 99999
  #define MAX_CARRIERID 99999
  …
  typedef uint32_t carrier_t;

My server has only this two lines :

  0778667682;65535
  0781541867;65536

The results of 2 querys are:

  processing command line parameters...
  got an answer in 0.180000 ms
  0778667682: 65535: comment=''

  processing command line parameters...
  got an answer in 0.155000 ms
  0781541867:not_found:unknown carrier

Should I change all the int to uint32_t?

@smititelu
Copy link
Contributor

You should try have a look in pdbt.c, query_udp():

short int carrierid;
...
short int * idptr;

You should try have a look in pdb_server.c, udp_server():

case PDB_VERSION_1:
...
                short int *_id

Try to change all the short int related to the carrier id to uint32_t (or unsigned int).
For both of them, you should try to replace ntohs/htons with ntohl/htonl (see [1]).

[1] http://linux.die.net/man/3/ntohs

@igorPot
Copy link
Author

igorPot commented Dec 9, 2015

Thank you very much!!!

That solved my issue :)

@igorPot igorPot closed this as completed Dec 9, 2015
@smititelu
Copy link
Contributor

I'm glad I could help.

If you consider extending the kamailio pdb module to make the length of the prefix configurable(e.g. via modparam) just make a pull request for it.

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

No branches or pull requests

2 participants