Need help with kvstore commands and weird error

Since freepbx is not NAT friendly when it comes to link failovers, I’m writing a way of checking IP freepbx has and comparing it to real_current IP and automatically updating, reloading and restart core, if its changed by way of failing over to 5G.

Now the getting IP works, and basically everything else works too, except one niggly problem, the variable now_ip only submits the first two octets-

relevant code bit:
char command[256];
snprintf(command, sizeof(command), “fwconsole kvstore --action set --key externip --value %s Sipsettings”, now_ip);
execute_command(command);

This runs fine, debug shows it is running with and submitting the full 4 octets of the IP, but either when saving or some other point in the database transaction, it only saves the first two octets, ie: send “1.2.3.4” it saves only “1.2”

I have tried as-is, single and double quotes, it makes no difference, even hard coded a full IP, still only first two octets.

Using describe kvstore_Sipsettings, the field is exponentially bigger than it needs so length is not the problem.

Any current/previous Sangoma dev have any insights into why this is happening?

As suspected kvstore is doing weirdness.

Octets 2,3,4 have been changed to protect the guilty :slight_smile:

Program Submission: kvstore does not see what is sent to it or does not pass to mariadb what it should

1360 Query SELECT * FROM modules WHERE modulename = ‘sipsettings’
1360 Query SELECT data FROM module_xml WHERE id = ‘track’
1360 Query SELECT * FROM kvstore_Sipsettings LIMIT 1
1360 Query SELECT * FROM kvstore WHERE module=‘Sipsettings’ LIMIT 1
1360 Query SELECT val, type FROM kvstore_Sipsettings WHERE key = ‘externip’ AND id = ‘noid’
1360 Query INSERT INTO kvstore_Sipsettings ( key, val, type, id )
VALUES ( ‘externip’, ‘110.500’, NULL, ‘noid’ ) ON DUPLICATE KEY UPDATE val = ‘110.500’, type = NULL
1360 Quit

Freepbx sip settings page sets it correctly however

1381 Query INSERT INTO kvstore_Sipsettings ( key, val, type, id )
VALUES ( ‘externip’, ‘110.500.501.502’, NULL, ‘noid’ ) ON DUPLICATE KEY UPDATE val = ‘110.500.501.502’,
type = NULL

OK new question what does kvstore do? It’s clear kvstore just wont work on this machine for some reason when used in my program, is there anything more than a database insert? I can manipulate the database directly, fwconsole reload and restart asterisk core, my understanding is this will re-write any asterisk flat files of changes, so I’ll have my program insert directly and see if it works, but wondering if those familiar with kvstore knows if it does anything else?
TIA

I know nothing about kvstore, but wrote a script to track public IP address changes and update Asterisk, with a goal of having it running with the new IP within a minute of the change. See

Unfortunately, this is 4+ years old and depends on chan_sip. You’ll have to tweak it if you don’t have that driver.

Also, see

for a recently updated list of STUN servers (though it’s not a significant issue if some aren’t working).

Courtesy of @billsimon

That script is exactly the same thing, my C program is doing, but there is a reason its in C, so wont make any difference.

I kind of have this working now, the double NAT can be got around for one of the trunks, but not the other, so i’m thinking that trunk provider isnt nat traversal friendly, bit of a bugger since the one that doesnt work is the least cost route :frowning:
but hopefully it wont have too much impact as primary is pretty stable, and if it goes out for prolonged, just have to wear the extra cost, some clients only use one trunk so it should now work for them at least.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.