Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ make test

- /crud-config-file -Config json file to store objects during create, retrieve, update and delete (CRUD) operations -optional argument

- /webpa-interface-label - can be configured with "Fixed" or "Mobile" values for representing primary or backup WAN respectively

- /wan-ipv4-address - represent the ipv4 address of the current active interface being used to connect to the cloud


# if ENABLE_SESHAT is enabled
- /seshat-url - The seshat server url
Expand Down Expand Up @@ -94,17 +98,17 @@ make test
```
# Seshat & FEATURE_DNS_QUERY Enabled

./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json --webpa-interface-label=Fixed --wan-ipv4-address=10.10.0.189


# Seshat is not enabled

./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json --webpa-interface-label=Fixed --wan-ipv4-address=10.10.0.189


# When both Seshat & FEATURE_DNS_QUERY not Enabled

./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json --webpa-interface-label=Fixed --wan-ipv4-address=10.10.0.189

```

17 changes: 17 additions & 0 deletions src/ParodusInternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ char* getWebpaConveyHeader()
{
cJSON_AddNumberToObject(response, BOOT_RETRY_WAIT, get_parodus_cfg()->boot_retry_wait);
}

if(strlen(get_parodus_cfg()->webpa_interface_label)!=0)
{
cJSON_AddStringToObject(response, WEBPA_INTERFACE_LABEL, get_parodus_cfg()->webpa_interface_label);
}
else
{
ParodusError("Failed to GET WebPA Interface label value\n");
}
if (strlen(get_parodus_cfg()->wan_ipv4_address) != 0)
{
cJSON_AddStringToObject(response, WAN_IPV4_ADDRESS, get_parodus_cfg()->wan_ipv4_address);
}
else
{
ParodusError("Failed to GET WAN IPv4 address value\n");
}
buffer = cJSON_PrintUnformatted(response);
ParodusInfo("X-WebPA-Convey Header: [%zd]%s\n", strlen(buffer), buffer);

Expand Down
30 changes: 29 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
{"close-reason-file", required_argument, 0, 'R'},
{"mtls-client-key-path", required_argument, 0, 'K'},
{"mtls-client-cert-path", required_argument, 0,'M'},
{"webpa-interface-label", required_argument, 0, 'L'},
{"wan-ipv4-address", required_argument, 0, 'I'},
#ifdef FEATURE_DNS_QUERY
{"record-jwt-payload", required_argument, 0,'W'},
#endif
Expand Down Expand Up @@ -497,7 +499,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv,
"m:s:f:d:r:n:b:u:t:o:i:l:q:p:e:D:j:a:k:c:E:T:N:w:J:46:C:S:R:K:M",
"m:s:f:d:r:n:b:u:t:o:i:l:q:p:e:D:j:a:k:c:E:T:N:w:J:46:C:S:R:K:M:L:I",
long_options, &option_index);

/* Detect the end of the options. */
Expand Down Expand Up @@ -696,6 +698,16 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
ParodusInfo("mtls_client_cert_path is %s\n", cfg->mtls_client_cert_path);
break;

case 'L':
parStrncpy(cfg->webpa_interface_label, optarg, sizeof(cfg->webpa_interface_label));
ParodusInfo("webpa_interface_label is %s\n", cfg->webpa_interface_label);
break;

case 'I':
parStrncpy(cfg->wan_ipv4_address, optarg, sizeof(cfg->wan_ipv4_address));
ParodusInfo("wan_ipv4_address is %s\n", cfg->wan_ipv4_address);
break;

#ifdef FEATURE_DNS_QUERY
case 'W':
cfg->record_jwt_file = strdup(optarg);
Expand Down Expand Up @@ -993,6 +1005,22 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
parStrncpy(cfg->cert_path, "\0", sizeof(cfg->cert_path));
ParodusPrint("cert_path is NULL. set to empty\n");
}
if(strlen(config->webpa_interface_label )!=0)
{
parStrncpy(cfg->webpa_interface_label, config->webpa_interface_label,sizeof(cfg->webpa_interface_label));
}
else
{
ParodusPrint("webpa_interface_label is NULL. read from tmp file\n");
}
if(strlen(config->wan_ipv4_address) !=0)
{
parStrncpy(cfg->wan_ipv4_address, config->wan_ipv4_address,sizeof(cfg->wan_ipv4_address));
}
else
{
ParodusPrint("wan_ipv4_address is NULL. read from tmp file\n");
}
#ifdef ENABLE_WEBCFGBIN
cfg->max_queue_size = config->max_queue_size;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ extern "C" {
#define CLOUD_STATUS_OFFLINE "offline"
#define CLOUD_DISCONNECT_REASON "disconnection-reason"
#define BOOT_RETRY_WAIT "boot-time-retry-wait"
#define WEBPA_INTERFACE_LABEL "webpa-interface-label"
#define WAN_IPV4_ADDRESS "wan-ipv4-address"

#define PROTOCOL_VALUE "PARODUS-2.0"
#define WEBPA_PATH_URL "/api/v2/device"
Expand Down Expand Up @@ -116,6 +118,8 @@ typedef struct
char *cloud_status;
char *cloud_disconnect;
unsigned int boot_retry_wait;
char webpa_interface_label[64];
char wan_ipv4_address[64];
#ifdef FEATURE_DNS_QUERY
char *record_jwt_file;
#endif
Expand Down
22 changes: 21 additions & 1 deletion src/crud_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,34 @@ int retrieveFromMemory(char *keyName, cJSON **jsonresponse)
}
else if(strcmp(WEBPA_INTERFACE, keyName)==0)
{
if((getWebpaInterface() !=NULL)&& (strlen(get_parodus_cfg()->fw_name)==0))
if((getWebpaInterface() !=NULL)&& (strlen(get_parodus_cfg()->webpa_interface_used)==0))
{
ParodusError("retrieveFromMemory: webpa_interface_used value is NULL\n");
return -1;
}
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,getWebpaInterface());
cJSON_AddItemToObject( *jsonresponse, WEBPA_INTERFACE , cJSON_CreateString(getWebpaInterface()));
}
else if(strcmp(WEBPA_INTERFACE_LABEL, keyName)==0)
{
if((get_parodus_cfg()->webpa_interface_label !=NULL)&& (strlen(get_parodus_cfg()->webpa_interface_label)==0))
{
ParodusError("retrieveFromMemory: webpa_interface_label value is NULL\n");
return -1;
}
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,get_parodus_cfg()->webpa_interface_label);
cJSON_AddItemToObject( *jsonresponse, WEBPA_INTERFACE_LABEL , cJSON_CreateString(get_parodus_cfg()->webpa_interface_label));
}
else if(strcmp(WAN_IPV4_ADDRESS, keyName)==0)
{
if((get_parodus_cfg()->wan_ipv4_address !=NULL) && (strlen(get_parodus_cfg()->wan_ipv4_address)==0))
{
ParodusError("retrieveFromMemory: wan_ipv4_address value is NULL\n");
return -1;
}
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,get_parodus_cfg()->wan_ipv4_address);
cJSON_AddItemToObject( *jsonresponse, WAN_IPV4_ADDRESS , cJSON_CreateString(get_parodus_cfg()->wan_ipv4_address));
}
else if(strcmp(WEBPA_URL, keyName)==0)
{
if((get_parodus_cfg()->webpa_url !=NULL) && (strlen(get_parodus_cfg()->webpa_url)==0))
Expand Down
10 changes: 10 additions & 0 deletions tests/test_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ void test_setParodusConfig()
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid));
parStrncpy(cfg.partner_id , "mycom", sizeof(cfg.partner_id));
parStrncpy(cfg.webpa_interface_label , "Fixed", sizeof(cfg.webpa_interface_label));
parStrncpy(cfg.wan_ipv4_address , "10.10.0.189", sizeof(cfg.wan_ipv4_address));
#ifdef ENABLE_SESHAT
parStrncpy(cfg.seshat_url, "ipc://tmp/seshat_service.url", sizeof(cfg.seshat_url));
#endif
Expand Down Expand Up @@ -108,6 +110,8 @@ void test_setParodusConfig()
assert_string_equal(cfg.webpa_protocol, temp->webpa_protocol);
assert_string_equal(cfg.webpa_uuid, temp->webpa_uuid);
assert_string_equal(cfg.partner_id, temp->partner_id);
assert_string_equal(cfg.webpa_interface_label, temp->webpa_interface_label);
assert_string_equal(cfg.wan_ipv4_address, temp->wan_ipv4_address);
#ifdef ENABLE_SESHAT
assert_string_equal(cfg.seshat_url, temp->seshat_url);
#endif
Expand Down Expand Up @@ -187,6 +191,8 @@ void test_parseCommandLine()
"--boot-time=1234",
"--parodus-local-url=tcp://127.0.0.1:6666",
"--partner-id=cox",
"--webpa-interface-label=Fixed",
"--wan-ipv4-address=10.10.0.189",
#ifdef ENABLE_SESHAT
"--seshat-url=ipc://127.0.0.1:7777",
#endif
Expand Down Expand Up @@ -231,6 +237,8 @@ void test_parseCommandLine()
assert_int_equal( (int) parodusCfg.boot_time,1234);
assert_string_equal( parodusCfg.local_url,"tcp://127.0.0.1:6666");
assert_string_equal( parodusCfg.partner_id,"cox");
assert_string_equal( parodusCfg.webpa_interface_label,"Fixed");
assert_string_equal( parodusCfg.wan_ipv4_address,"10.10.0.189");
#ifdef ENABLE_SESHAT
assert_string_equal( parodusCfg.seshat_url, "ipc://127.0.0.1:7777");
#endif
Expand Down Expand Up @@ -328,6 +336,8 @@ void test_loadParodusCfg()
parStrncpy(Cfg->webpa_protocol , protocol, sizeof(Cfg->webpa_protocol));
parStrncpy(Cfg->local_url , "tcp://10.0.0.1:6000", sizeof(Cfg->local_url));
parStrncpy(Cfg->partner_id , "shaw", sizeof(Cfg->partner_id));
parStrncpy(Cfg->webpa_interface_label , "Fixed", sizeof(Cfg->webpa_interface_label));
parStrncpy(Cfg->wan_ipv4_address , "10.10.0.189", sizeof(Cfg->wan_ipv4_address));
#ifdef FEATURE_DNS_QUERY
Cfg->acquire_jwt = 1;
parStrncpy(Cfg->dns_txt_url, "mydns",sizeof(Cfg->dns_txt_url));
Expand Down
10 changes: 10 additions & 0 deletions tests/test_crud_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void test_retrieveFromMemory()
parStrncpy(cfg->webpa_url, "http://127.0.0.1", sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_uuid, "1234567-345456546", sizeof(cfg->webpa_uuid));
parStrncpy(cfg->webpa_protocol , "PARODUS-2.0", sizeof(cfg->webpa_protocol));
parStrncpy(cfg->webpa_interface_label, "Fixed", sizeof(cfg->webpa_interface_label));
parStrncpy(cfg->wan_ipv4_address , "10.10.0.189", sizeof(cfg->wan_ipv4_address));
cfg->webpa_backoff_max=0;
cfg->boot_time=1234;
set_parodus_cfg(cfg);
Expand Down Expand Up @@ -171,6 +173,10 @@ void test_retrieveFromMemory()
assert_int_equal (ret, 0);
ret = retrieveFromMemory("webpa-backoff-max", &jsonresponse );
assert_int_equal (ret, 0);
ret = retrieveFromMemory("webpa-interface-label", &jsonresponse );
assert_int_equal (ret, 0);
ret = retrieveFromMemory("wan-ipv4-address", &jsonresponse );
assert_int_equal (ret, 0);
free(cfg);
}

Expand Down Expand Up @@ -208,6 +214,10 @@ void test_retrieveFromMemoryFailure()
assert_int_equal (ret, 0);
ret = retrieveFromMemory("webpa-invalid", &jsonresponse );
assert_int_equal (ret, -1);
ret = retrieveFromMemory("webpa-interface-label", &jsonresponse );
assert_int_equal (ret, -1);
ret = retrieveFromMemory("wan-ipv4-address", &jsonresponse );
assert_int_equal (ret, -1);
}

void test_createObjectInvalidReq()
Expand Down
Loading