RDK Documentation (Open Sourced RDK Components)
routeSrvMgr.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #include <iostream>
21 #include <stdint.h>
22 #include <sys/socket.h>
23 #include <arpa/inet.h>
24 #include <stdio.h>
25 #include <glib.h>
26 #include <cJSON.h>
27 #include <sys/types.h>
28 #include <ifaddrs.h>
29 #include "routeSrvMgr.h"
30 #include "NetworkMgrMain.h"
31 #include "NetworkMedium.h"
32 #include "netsrvmgrUtiles.h"
33 #include <fstream>
34 #ifdef ENABLE_NLMONITOR
35 #include "netlinkifc.h"
36 #endif //ENABLE_NLMONITOR
37 
38 
39 
40 #define ROUTE_PRIORITY 50
41 #define GW_SETUP_FILE "/lib/rdk/gwSetup.sh"
42 #define MAX_CJSON_EMPTY_LENGTH 40
43 #define IP_SIZE 46
44 #define DHCP_LEASE_FLAG "/tmp/usingdhcp"
45 #define PREFERRED_GATEWAY_FILE "/opt/prefered-gateway"
46 
47 #ifdef YOCTO_BUILD
48 extern "C" {
49 #include "secure_wrapper.h"
50 }
51 #endif
52 #ifdef SAFEC_RDKV
53 #include "safec_lib.h"
54 #else
55 #define MEMCPY_S(dest,dsize,source,ssize) \
56  memcpy(dest,source,ssize);
57 #endif
58 
59 int messageLength;
60 GList* gwList = NULL;
61 GList* gwRouteInfo = NULL;
62 bool lastRouteSetV4=FALSE;
63 char routeIf[15];
64 bool signalUpnpDataReady=true;
65 
66 RouteNetworkMgr* RouteNetworkMgr::instance = NULL;
67 bool RouteNetworkMgr::instanceIsReady = false;
68 
69 static bool gwSelected = false;
70 static bool xb3Selected = false;
71 static bool upnpGwyLost = true;
72 
73 pthread_cond_t condRoute = PTHREAD_COND_INITIALIZER;
74 pthread_mutex_t mutexRoute = PTHREAD_MUTEX_INITIALIZER;
75 
76 RouteNetworkMgr::RouteNetworkMgr() {}
77 RouteNetworkMgr::~RouteNetworkMgr() { }
78 
79 RouteNetworkMgr* RouteNetworkMgr::getInstance()
80 {
81  if (instance == NULL)
82  {
83  instance = new RouteNetworkMgr();
84  instanceIsReady = true;
85  }
86  return instance;
87 }
88 
89 
90 int RouteNetworkMgr::Start()
91 {
93  IARM_Bus_RegisterCall(IARM_BUS_ROUTE_MGR_API_getCurrentRouteData, getCurrentRouteData);
94 
95 
96  //Check to see the preferred Gateway contents.
97  std::ifstream cfgFile(PREFERRED_GATEWAY_FILE);
98  std::string prefgw;
99  if (cfgFile.is_open())
100  {
101  cfgFile>>prefgw;
102  if (prefgw == "XB3")
103  {
104  xb3Selected = true;
105  LOG_INFO("[%s] Preferred Gateway is XB", MODULE_NAME);
106  }
107  cfgFile.close();
108  }
109 
110 
111  LOG_TRACE("[%s] Enter", MODULE_NAME);
112 
114  return 0;
115 }
116 
117 
118 
119 /**
120  * @fn void RouteNetworkMgr::_evtHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
121  * @brief This function is a common event handler for IARM Manager events. It receives events
122  * from Power Manager, SYS Manager, IR Manager etc.
123  *
124  * @param[in] owner Name of the Manager application in string format.
125  * @param[in] eventId Variable of IARM_EventId_t type representing event identifier.
126  * @param[in] data Event data as void pointer.
127  * @param[in] len Length of the data buffer.
128  *
129  * @return None.
130  */
131 static void _evtHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
132 {
133  LOG_TRACE("[%s] Enter", MODULE_NAME);
134  if (strcmp(owner, IARM_BUS_SYSMGR_NAME) == 0) {
135  switch(eventId) {
137  {
139  pthread_mutex_lock(&mutexRoute);
140  signalUpnpDataReady=true;
141  if(0 == pthread_cond_signal(&condRoute))
142  {
143  messageLength = eventData->data.xupnpData.deviceInfoLength;
144  LOG_INFO("[%s] Signal to fetch the data from upnp %ld", MODULE_NAME, eventData->data.xupnpData.deviceInfoLength );
145  }
146  pthread_mutex_unlock(&mutexRoute);
147  break;
148  }
149  }
150  LOG_TRACE("[%s] Exit", MODULE_NAME);
151  }
152 }
153 
154 /**
155  * @fn bool RouteNetworkMgr::getGatewayResults(char* gatewayResults, unsigned int messageLength)
156  * @brief This function used IARM Bus call to get XUPNP device information and returns
157  * the result as a string.
158  *
159  * @param[out] gatewayResults String to store discovery results.
160  * @param[in] messageLength Unsigned integer variable representing buffer length.
161  *
162  * @return None.
163  */
164 
165 bool RouteNetworkMgr::getGatewayResults(char* gatewayResults, unsigned int messageLength)
166 {
168  IARM_Result_t ret = IARM_RESULT_SUCCESS;
169  bool returnStatus = FALSE;
170  LOG_TRACE("[%s] Enter", MODULE_NAME);
171 
172  ret = IARM_Malloc(IARM_MEMTYPE_PROCESSLOCAL, sizeof(IARM_Bus_SYSMGR_GetXUPNPDeviceInfo_Param_t) + messageLength + 1, (void**)&param);
173  if(ret == IARM_RESULT_SUCCESS)
174  {
175  param->bufLength = messageLength;
176 
178  (void *)param, sizeof(IARM_Bus_SYSMGR_GetXUPNPDeviceInfo_Param_t) + messageLength + 1);
179 
180  if(ret == IARM_RESULT_SUCCESS)
181  {
182  MEMCPY_S(gatewayResults,messageLength+1, ((char *)param + sizeof(IARM_Bus_SYSMGR_GetXUPNPDeviceInfo_Param_t)), param->bufLength);
183  gatewayResults[param->bufLength] = '\0';
184  returnStatus = TRUE;
185  }
186  else
187  {
188  LOG_ERR("[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo IARM failed in the fetch", MODULE_NAME);
189  }
190  LOG_TRACE("[%s] gatewayResults %s", MODULE_NAME, gatewayResults);
191  IARM_Free(IARM_MEMTYPE_PROCESSLOCAL, param);
192  LOG_TRACE("[%s] Exit", MODULE_NAME);
193  }
194  else
195  {
196  LOG_ERR("[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo , IARM_Malloc Failed", MODULE_NAME);
197  }
198  return returnStatus;
199 }
200 
202 {
203  pthread_t getGatewayRouteDataThread;
204  pthread_attr_t attr;
205  int rc;
206 
207  LOG_TRACE("[%s] Enter", MODULE_NAME);
208  pthread_attr_init(&attr);
209  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
210  rc = pthread_create(&getGatewayRouteDataThread, &attr, &getGatewayRouteDataThrd, NULL);
211  if (rc) {
212  LOG_ERR("ERROR; getGatewayRouteData return code from pthread_create() is %d", rc);
213  }
214  LOG_TRACE("[%s] Exit", MODULE_NAME);
215 }
216 
217 /**
218  * @fn void RouteNetworkMgr::storeRouteDetails(unsigned int messageLength)
219  * @brief This is invoked when there is a new gateway data
220  *
221  * @param[in] messageLength Length of buffer.
222  *
223  * @return None.
224  */
225 
226 gboolean RouteNetworkMgr::storeRouteDetails(unsigned int messageLength)
227 {
228  char upnpResults[messageLength+1];
229  gboolean retVal=FALSE;
230  LOG_TRACE("[%s] Enter", MODULE_NAME);
231  memset(&upnpResults,0,sizeof(upnpResults));
232  if(getGatewayResults(&upnpResults[0], messageLength))
233  {
234  if(parse_store_gateway_data(&upnpResults[0]))
235  retVal=TRUE;
236  }
237  else
238  {
239  LOG_ERR("Failure in getting gateway results.");
240  }
241  LOG_TRACE("[%s] Exit", MODULE_NAME);
242  return retVal;
243 }
244 
245 void* getGatewayRouteDataThrd(void* arg)
246 {
247  int msgLength;
248  LOG_TRACE("[%s] Enter", MODULE_NAME);
249  while (true ) {
250  pthread_mutex_lock(&mutexRoute);
251  while(signalUpnpDataReady == false) {
252  pthread_cond_wait(&condRoute, &mutexRoute);
253  }
254  LOG_DBG("[%s] ***** Started fetching gateway data from upnp msg len = %d *****", MODULE_NAME,messageLength );
255  msgLength = messageLength;
256  signalUpnpDataReady=false;
257  pthread_mutex_unlock(&mutexRoute);
258 // RouteNetworkMgr::delGatewayList();
259 // if(msgLength > MAX_CJSON_EMPTY_LENGTH)
260 // {
262  {
263  if(RouteNetworkMgr::checkExistingRouteValid())
264  {
265  if(RouteNetworkMgr::setRoute())
266  RouteNetworkMgr::sendCurrentRouteData();
267  }
268 // sendDefaultGatewayRoute();
269  }
270  else
271  {
272  RouteNetworkMgr::delRouteList();
273  }
274  gwRouteInfo = g_list_first(gwRouteInfo);
275  if((g_list_length(gwRouteInfo) == 0) && ( access( DHCP_LEASE_FLAG, F_OK ) == -1 ))
276  {
277  if (!upnpGwyLost)
278  {
279  if (!xb3Selected)
280  {
281  LOG_INFO("[%s] Triggering dhcp lease since no XG gateway", MODULE_NAME);
282  netSrvMgrUtiles::triggerDhcpRenew();
283  upnpGwyLost=true;
284  }
285  }
286 #ifdef ENABLE_NLMONITOR
287  //Clear out /tmp/resolv.dnsmasq.upnp
288  std::ofstream ofs;
289  ofs.open("/tmp/resolv.dnsmasq.upnp", std::ofstream::out | std::ofstream::trunc);
290  ofs.close();
291 
292  if (gwSelected)
293  {
294  list<std::string> ifcList;
295  char* interface;
296  if ((interface = getenv("WIFI_INTERFACE")) != NULL)
297  ifcList.push_back(interface);
298  if ((interface = getenv("MOCA_INTERFACE")) != NULL)
299  ifcList.push_back(interface);
300  gwSelected = false;
301  for (auto const& i : ifcList)
302  {
303  std::string ifcStr = i;
304  //Invoke API to cleanup Global IPs assigned.
305  NetLinkIfc::get_instance()->deleteinterfaceip(ifcStr,AF_INET6);
306  NetLinkIfc::get_instance()->deleteinterfaceroutes(ifcStr,AF_INET6);
307  //Call script to enable SLAAC ra support.
308 #ifdef YOCTO_BUILD
309  v_secure_system("/lib/rdk/enableIpv6Autoconf.sh %s", ifcStr.c_str());
310 #else
311  std::string cmd = "/lib/rdk/enableIpv6Autoconf.sh ";
312  cmd += ifcStr;
313  system(cmd.c_str());
314 #endif
315  }
316  LOG_INFO("[%s] No Gateway Detected, SLAAC Support is enabled", MODULE_NAME);
317  }
318 #endif//ENABLE_NLMONITOR
319  }
320 // }
321 // else
322 // {
323 // LOG_DBG("[%s] No Gateway in UPNP list msgLength = %d msglenlocal = %d ***** ", MODULE_NAME, messageLength, msgLength );
324 // }
325  }
326  LOG_TRACE("[%s] Exit", MODULE_NAME);
327 }
328 
329 /**
330  * @brief This will check whether the input IP Address is a valid IPv4 or IPv6 address.
331  *
332  * @param[in] ipAddress IP Address in string format.
333  *
334  * @return Returns TRUE if IP address is valid else returns FALSE.
335  * @ingroup
336  */
337 gboolean checkvalidip( char* ipAddress)
338 {
339  struct in_addr addr4;
340  struct in6_addr addr6;
341  LOG_TRACE("[%s] Enter", MODULE_NAME);
342  int validip4 = inet_pton(AF_INET, ipAddress, &addr4);
343  int validip6 = inet_pton(AF_INET6, ipAddress, &addr6);
344  if (g_strrstr(g_strstrip(ipAddress),"null") || ! *ipAddress )
345  {
346  LOG_ERR("[%s] ipaddress are empty %s", MODULE_NAME, ipAddress);
347  return TRUE;
348  }
349  if ((validip4 == 1 ) || (validip6 == 1 ))
350  {
351  return TRUE;
352  }
353  else
354  {
355  LOG_ERR("[%s] Not a valid ip address %s", MODULE_NAME, ipAddress);
356  return FALSE;
357  }
358 }
359 /**
360  * @brief This function will check whether a Host name is valid by validating all the associated IP addresses.
361  *
362  * @param[in] hostname Host name represented as a string.
363  *
364  * @return Returns TRUE if host name is valid else returns FALSE.
365  * @ingroup
366  */
367 gboolean checkvalidhostname( char* hostname)
368 {
369  LOG_TRACE("[%s] Enter", MODULE_NAME);
370  if (g_strrstr(g_strstrip(hostname),"null") || ! *hostname )
371  {
372  LOG_ERR("[%s] hostname values are empty %s", MODULE_NAME, hostname);
373  return TRUE;
374  }
375  gchar **tokens = g_strsplit_set(hostname," ;\n\0", -1);
376  guint toklength = g_strv_length(tokens);
377  guint loopvar=0;
378  for (loopvar=0; loopvar<toklength; loopvar++)
379  {
380  if (checkvalidip(tokens[loopvar]))
381  {
382  return TRUE;
383  }
384  }
385  LOG_ERR("[%s] no valid ip so rejecting the dns values %s", MODULE_NAME, hostname);
386  if(tokens)
387  g_strfreev(tokens); /*CID-24000*/
388  return FALSE;
389 }
390 
391 gboolean RouteNetworkMgr::init_gwydata(GwyDeviceData* gwydata)
392 {
393  LOG_TRACE("[%s] Enter", MODULE_NAME);
394  gwydata->serial_num = g_string_new(NULL);
395  gwydata->gwyip = g_string_new(NULL);
396  gwydata->gwyipv6 = g_string_new(NULL);
397  gwydata->ipv6prefix = g_string_new(NULL);
398  gwydata->isRouteSet=FALSE;
399  gwydata->dnsconfig = g_string_new(NULL);
400  gwydata->devicetype = g_string_new(NULL);
401  LOG_TRACE("[%s] Exit", MODULE_NAME);
402  return TRUE;
403 }
404 
405 gboolean RouteNetworkMgr::free_gwydata(GwyDeviceData* gwydata)
406 {
407  LOG_TRACE("[%s] Enter", MODULE_NAME);
408  if(gwydata)
409  {
410  g_string_free(gwydata->serial_num, TRUE);
411  g_string_free(gwydata->gwyip, TRUE);
412  g_string_free(gwydata->gwyipv6, TRUE);
413  g_string_free(gwydata->dnsconfig, TRUE);
414  g_string_free(gwydata->ipv6prefix, TRUE);
415  g_string_free(gwydata->devicetype, TRUE);
416  }
417  LOG_TRACE("[%s] Exit", MODULE_NAME);
418  return TRUE;
419 }
420 gboolean RouteNetworkMgr::readDevFile(char *deviceFile,char *mocaIface,char *wifiIface)
421 {
422  GError *error=NULL;
423  gboolean result = FALSE;
424  gchar* devfilebuffer = NULL;
425  gchar counter=0;
426  LOG_TRACE("[%s] Enter", MODULE_NAME);
427  if (deviceFile == NULL)
428  {
429  LOG_ERR("[%s] device properties file not found", MODULE_NAME);
430  return result;
431  }
432  result = g_file_get_contents (deviceFile, &devfilebuffer, NULL, &error);
433  if (result == FALSE)
434  {
435  LOG_ERR("[%s] No contents in device properties", MODULE_NAME);
436  }
437  else
438  {
439  /* reset result = FALSE to identify device properties from devicefile contents */
440  result = FALSE;
441  gchar **tokens = g_strsplit_set(devfilebuffer,",='\n'", -1);
442  guint toklength = g_strv_length(tokens);
443  guint loopvar=0;
444  for (loopvar=0; loopvar<toklength; loopvar++)
445  {
446  if (g_strrstr(g_strstrip(tokens[loopvar]), "MOCA_INTERFACE"))
447  {
448  if ((loopvar+1) < toklength )
449  {
450  counter++;
451  g_stpcpy(mocaIface, g_strstrip(tokens[loopvar+1]));
452  }
453  if (counter == 2)
454  {
455  break;
456  }
457  }
458  if (g_strrstr(g_strstrip(tokens[loopvar]), "WIFI_INTERFACE"))
459  {
460  if ((loopvar+1) < toklength )
461  {
462  counter++;
463  g_stpcpy(wifiIface, g_strstrip(tokens[loopvar+1]));
464  }
465  if (counter == 2)
466  {
467  break;
468  }
469  }
470  }
471  g_strfreev(tokens);
472  g_free(devfilebuffer);
473  }
474  if((!mocaIface) && (!wifiIface))
475  {
476  LOG_ERR("[%s] MOCA_INTERFACE and WIFI_INTERFACE not found in %s", MODULE_NAME, deviceFile);
477  }
478  else
479  result = TRUE;
480  if(error)
481  {
482  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
483  g_clear_error(&error);
484  }
485  LOG_TRACE("[%s] Exit", MODULE_NAME);
486  return result;
487 }
488 gboolean RouteNetworkMgr::delGatewayList()
489 {
490  guint gwListLength=0;
491  LOG_TRACE("[%s] Enter", MODULE_NAME);
492  gwList = g_list_first(gwList);
493  gwListLength = g_list_length(gwList);
494  if (gwListLength > 0)
495  {
496  GwyDeviceData *gwdata = NULL;
497  while (gwList && (gwListLength > 0))
498  {
499  gwdata = (GwyDeviceData*)gwList->data;
500  gwList = g_list_next(gwList);
501  free_gwydata(gwdata);
502  g_free(gwdata);
503  gwList = g_list_remove(gwList, gwdata);
504  gwListLength--;
505  }
506  g_list_free(gwList);
507  }
508  else
509  {
510  LOG_INFO("[%s] NO gateway data available", MODULE_NAME);
511  }
512  LOG_TRACE("[%s] Exit", MODULE_NAME);
513  return TRUE;
514 }
515 
516 gboolean RouteNetworkMgr::delRouteList()
517 {
518  guint gwRouteLength=0;
519  LOG_TRACE("[%s] Enter", MODULE_NAME);
520  gwRouteInfo = g_list_first(gwRouteInfo);
521  gwRouteLength = g_list_length(gwRouteInfo);
522  if (gwRouteLength > 0)
523  {
524  routeInfo *gwdata = NULL;
525  while (gwRouteInfo && (gwRouteLength > 0))
526  {
527  gwdata = (routeInfo*)gwRouteInfo->data;
528  checkRemoveRouteInfo(gwdata->ipStr->str,gwdata->isIPv4);
529  gwRouteInfo = g_list_next(gwRouteInfo);
530  gwRouteLength--;
531  }
532  if(gwRouteInfo)
533  {
534  g_list_free(gwRouteInfo);
535  gwRouteInfo=NULL;
536  }
537  }
538  else
539  {
540  LOG_INFO("[%s] NO gateway data available", MODULE_NAME);
541  }
542  LOG_TRACE("[%s] Exit", MODULE_NAME);
543  return TRUE;
544 }
545 
546 gboolean RouteNetworkMgr::parse_store_gateway_data(char *array)
547 {
548  LOG_TRACE("[%s] Enter", MODULE_NAME);
549  GList *tempGwList;
550  guint counter;
551  gboolean retVal=TRUE;
552  if(array)
553  {
554  delGatewayList();
555  cJSON *rootJson=cJSON_Parse(array);
556  if(rootJson)
557  {
558  cJSON *gwFullData = cJSON_GetObjectItem(rootJson,"xmediagateways");
559  if(gwFullData)
560  {
561  guint gwCount = cJSON_GetArraySize(gwFullData);
562  LOG_INFO("gateway count in json %d", gwCount);
563  char *isgateway,*dnsConfig,*gatewayIp,*gatewayIpV6,*serialNum,*ipv6Prefix,*devType;
564 
565  for (counter = 0; counter < gwCount; counter++)
566  {
567  cJSON *gwData = cJSON_GetArrayItem(gwFullData, counter);
568  isgateway = dnsConfig = gatewayIp = gatewayIpV6 = serialNum = ipv6Prefix = devType = NULL;
569  if(gwData) {
570  if (cJSON_GetObjectItem(gwData, "isgateway"))
571  isgateway = cJSON_GetObjectItem(gwData, "isgateway")->valuestring;
572  if(cJSON_GetObjectItem(gwData, "dnsconfig"))
573  dnsConfig = cJSON_GetObjectItem(gwData, "dnsconfig")->valuestring;
574  if(cJSON_GetObjectItem(gwData, "gatewayip"))
575  gatewayIp = cJSON_GetObjectItem(gwData, "gatewayip")->valuestring;
576  if(cJSON_GetObjectItem(gwData, "gatewayipv6"))
577  gatewayIpV6 = cJSON_GetObjectItem(gwData, "gatewayipv6")->valuestring;
578  if(cJSON_GetObjectItem(gwData, "sno"))
579  serialNum = cJSON_GetObjectItem(gwData, "sno")->valuestring;
580  if(cJSON_GetObjectItem(gwData, "ipv6Prefix"))
581  ipv6Prefix = cJSON_GetObjectItem(gwData, "ipv6Prefix")->valuestring;
582  if(cJSON_GetObjectItem(gwData, "DevType"))
583  devType = cJSON_GetObjectItem(gwData, "DevType")->valuestring;
584 
585  if((isgateway) && (g_strrstr(g_strstrip(isgateway),"yes")) && (dnsConfig) && (checkvalidhostname(dnsConfig) == TRUE ) && (gatewayIp) && (checkvalidip(gatewayIp) == TRUE) && (gatewayIpV6) &&(checkvalidip(gatewayIpV6) == TRUE))
586  {
587  GwyDeviceData *gwydata = g_new(GwyDeviceData,1);
588  init_gwydata(gwydata);
589  g_string_assign(gwydata->serial_num,serialNum);
590  g_string_assign(gwydata->gwyip,gatewayIp);
591  g_string_assign(gwydata->gwyipv6,gatewayIpV6);
592  g_string_assign(gwydata->dnsconfig,dnsConfig);
593  g_string_assign(gwydata->ipv6prefix,ipv6Prefix);
594  g_string_assign(gwydata->devicetype,devType);
595  gwList=g_list_append(gwList,gwydata);
596  LOG_TRACE("[%s] serial_num %s gwcount %d", MODULE_NAME,gwydata->serial_num->str,g_list_length(gwList));
597  }
598  else
599  {
600  LOG_ERR("[%s] not a valid gateway %s", MODULE_NAME, serialNum);
601  }
602  } else {
603  LOG_ERR("[%s] Failed to get gateway details,Array item is Null", MODULE_NAME);
604  }
605  }
606  gwList = g_list_first(gwList);
607  if( g_list_length(gwList) == 0)
608  {
609  retVal=FALSE;
610  delRouteList();
611  }
612  }
613  else
614  {
615  checkExistingRouteValid();
616  retVal=FALSE;
617  LOG_INFO("[%s] No gwdata to parse gwcount ", MODULE_NAME);
618  }
619  cJSON_Delete(rootJson);
620  }
621  else
622  {
623  retVal=FALSE;
624  LOG_INFO("JSON is empty");
625 
626  }
627  }
628  else
629  {
630  LOG_ERR("[%s] gateway list is empty", MODULE_NAME);
631  retVal=FALSE;
632  }
633  LOG_TRACE("[%s] Exit", MODULE_NAME);
634  return retVal;
635 }
636 
637 gboolean RouteNetworkMgr::getRouteInterface(char * routeIf)
638 {
639  char devFile[] = "//etc//device.properties";
640  char mocaIf[10]= {0};
641  char wifiIf[10]= {0};
642  char ipAddressBuffer[46];
643  LOG_TRACE("[%s] Enter", MODULE_NAME);
644  if(readDevFile(devFile,mocaIf,wifiIf))
645  {
646  int result = getipaddress(mocaIf,ipAddressBuffer,FALSE);
647  if (!result)
648  {
649  LOG_INFO("[%s] Could not locate the ipaddress of the broadcast interface %s", MODULE_NAME,mocaIf );
650  result = getipaddress(wifiIf,ipAddressBuffer,FALSE);
651  if (!result)
652  {
653  LOG_INFO("[%s] Could not locate the ipaddress of the broadcast interface %s", MODULE_NAME, wifiIf );
654  return FALSE;
655  }
656  else
657  {
658  g_stpcpy(routeIf,wifiIf);
659  }
660  }
661  else
662  {
663  g_stpcpy(routeIf,mocaIf);
664  }
665  }
666  else
667  {
668  LOG_ERR("[%s] No route interface available", MODULE_NAME);
669  }
670 
671  LOG_TRACE("[%s] Exit", MODULE_NAME);
672  return TRUE;
673 }
674 
675 gboolean RouteNetworkMgr::setRoute() {
676  gint retType;
677  gboolean firstXG1GwData=TRUE;
678  gboolean firstXG2GwData=TRUE;
679  gboolean setRoute=FALSE;
680  GList *element = NULL;
681  gboolean retVal=FALSE;
682  GwyDeviceData *gwdata;
683  LOG_TRACE("[%s] Enter", MODULE_NAME);
684  element = g_list_first(gwList);
685  LOG_TRACE("[%s] gw list count %d", MODULE_NAME, g_list_length(gwList));
686  getRouteInterface(routeIf);
687  if(!routeIf)
688  {
689  LOG_ERR("[%s] No Interface available to add route", MODULE_NAME);
690  return retVal;
691  }
692  while(element)
693  {
694  gwdata=((GwyDeviceData *)element->data);
695  element = g_list_next(element);
696  if(!gwdata)
697  {
698  LOG_TRACE("[%s] gwdata NULL", MODULE_NAME);
699  return FALSE;
700  }
701  if(g_strcmp0(gwdata->devicetype->str,"XG2") == 0)
702  {
703  if(firstXG2GwData == TRUE)
704  {
705  firstXG2GwData=FALSE;
706  setRoute=TRUE;
707  }
708  }
709  else
710  {
711  if(firstXG1GwData == TRUE)
712  {
713  firstXG1GwData = FALSE;
714  setRoute=TRUE;
715  }
716  }
717  if(setRoute)
718  {
719  upnpGwyLost=false;
720 #ifdef ENABLE_NLMONITOR
721  if ((!gwSelected) && (!xb3Selected))
722  {
723  list<std::string> ifcList;
724  char* interface;
725  if ((interface = getenv("WIFI_INTERFACE")) != NULL)
726  ifcList.push_back(interface);
727  if ((interface = getenv("MOCA_INTERFACE")) != NULL)
728  ifcList.push_back(interface);
729  gwSelected = true;
730 
731  for (auto const& i : ifcList)
732  {
733  //Call script to disable SLAAC ra support.
734  std::string ifcStr = i;
735 #ifdef YOCTO_BUILD
736  v_secure_system("/lib/rdk/disableIpv6Autoconf.sh %s", ifcStr.c_str());
737 #else
738  std::string cmd = "/lib/rdk/disableIpv6Autoconf.sh ";
739  cmd += ifcStr;
740  system(cmd.c_str());
741 #endif
742 
743  //Invoke API to cleanup Global IPs assigned.
744  NetLinkIfc::get_instance()->deleteinterfaceip(ifcStr,AF_INET6);
745  NetLinkIfc::get_instance()->deleteinterfaceroutes(ifcStr,AF_INET6);
746  }
747  LOG_INFO("[%s] Gateway Detecetd, SLAAC Support is disabled.", MODULE_NAME);
748  }
749 #endif //ENABLE_NLMONITOR
750 
751 #ifdef YOCTO_BUILD
752  LOG_INFO("[%s] Calling gateway script with arguments %s %s %s %s %d %s %s %s ", MODULE_NAME,
753  GW_SETUP_FILE, gwdata->gwyip->str, gwdata->dnsconfig->str, routeIf, ROUTE_PRIORITY,
754  gwdata->ipv6prefix->str, gwdata->gwyipv6->str, gwdata->devicetype->str);
755  retType=v_secure_system(GW_SETUP_FILE " %s %s %s %d %s %s %s ",
756  gwdata->gwyip->str, gwdata->dnsconfig->str, routeIf, ROUTE_PRIORITY,
757  gwdata->ipv6prefix->str, gwdata->gwyipv6->str, gwdata->devicetype->str);
758  //Ignoring WEXITSTATUS(retType) in v_secure_system() as it is already taken care in secure_wrapper.c
759 #else
760  GString *GwRouteParam=g_string_new(NULL);
761  g_string_printf(GwRouteParam,"%s" ,GW_SETUP_FILE);
762  g_string_append_printf(GwRouteParam," \"%s\"" ,gwdata->gwyip->str);
763  g_string_append_printf(GwRouteParam," \"%s\"" ,gwdata->dnsconfig->str);
764  g_string_append_printf(GwRouteParam," \"%s\"" ,routeIf);
765  g_string_append_printf(GwRouteParam," \"%d\"" ,ROUTE_PRIORITY);
766  g_string_append_printf(GwRouteParam," \"%s\"" ,gwdata->ipv6prefix->str);
767  g_string_append_printf(GwRouteParam," \"%s\"" ,gwdata->gwyipv6->str);
768  g_string_append_printf(GwRouteParam," \"%s\"" ,gwdata->devicetype->str);
769  LOG_INFO("[%s] Calling gateway script %s", MODULE_NAME,GwRouteParam->str);
770  retType=system(GwRouteParam->str);
771  g_string_free(GwRouteParam,TRUE);
772  if(retType != SYSTEM_COMMAND_ERROR)
773  {
774  retType = WEXITSTATUS(retType);
775  }
776 #endif
777  }
778  if(retType == SYSTEM_COMMAND_ERROR)
779  {
780  LOG_ERR("[%s] Error has occured in shell command", MODULE_NAME);
781  }
782  else if (retType == SYSTEM_COMMAND_SHELL_NOT_FOUND)
783  {
784  LOG_ERR("[%s] That shell command is not found", MODULE_NAME);
785  }
786  else if (retType == SYSTEM_COMMAND_SHELL_SUCESS)
787  {
788  LOG_INFO("[%s] system call route set successfully %d", MODULE_NAME, retType);
789  gwdata->isRouteSet=TRUE;
790  if(checkIpMode(gwdata->ipv6prefix->str))
791  {
792  checkAddRouteInfo(gwdata->gwyipv6->str,FALSE,gwdata->ipv6prefix->str);
793  }
794  else
795  {
796  checkAddRouteInfo(gwdata->gwyip->str,TRUE,gwdata->ipv6prefix->str);
797  }
798  retVal=TRUE;
799  }
800  else
801  {
802  LOG_INFO("[%s] no change in routing information %d", MODULE_NAME, retType);
803  }
804  }
805  LOG_TRACE("[%s] Exit", MODULE_NAME);
806  return retVal;
807 }
808 
809 /**
810  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
811  *
812  * @param[in] ifname Name of the network interface.
813  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
814  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
815  *
816  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
817  * @ingroup
818  */
819 int RouteNetworkMgr::getipaddress(char* ifname, char* ipAddressBuffer, gboolean ipv6Enabled)
820 {
821  struct ifaddrs * ifAddrStruct=NULL;
822  struct ifaddrs * ifa=NULL;
823  void * tmpAddrPtr=NULL;
824  LOG_TRACE("[%s] Enter", MODULE_NAME);
825  getifaddrs(&ifAddrStruct);
826  //char addressBuffer[INET_ADDRSTRLEN] = NULL;
827  int found=0;
828  for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
829  if (ifa->ifa_addr == NULL) continue;
830  if (ipv6Enabled == TRUE)
831  { // check it is IP6
832  // is a valid IP6 Address
833  if ((strcmp(ifa->ifa_name,ifname)==0) && (ifa ->ifa_addr->sa_family==AF_INET6))
834  {
835  tmpAddrPtr=&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
836  inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
837  //if (strcmp(ifa->ifa_name,"eth0")==0trcmp0(g_strstrip(devConf->mocaMacIf),ifname) == 0)
838  if (IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr))
839  {
840  found = 1;
841  break;
842  }
843  }
844  }
845  else {
846  if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
847  // is a valid IP4 Address
848  tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
849  inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
850  //if (strcmp(ifa->ifa_name,"eth0")==0)
851  if (strcmp(ifa->ifa_name,ifname)==0)
852  {
853  found = 1;
854  break;
855  }
856  }
857  }
858  }
859  if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
860  LOG_TRACE("[%s] Exit", MODULE_NAME);
861  return found;
862 }
863 
864 gboolean RouteNetworkMgr::checkAddRouteInfo(char *ipAddr,bool isIPv4,char *ipv6Pfix)
865 {
866  LOG_TRACE("[%s] Enter", MODULE_NAME);
867  routeInfo *gwdata=NULL;
868  gwRouteInfo=g_list_first(gwRouteInfo);
869  GList* tmpGWRouteInfo=g_list_find_custom(gwRouteInfo,ipAddr,(GCompareFunc)g_list_find_ip);
870  if(tmpGWRouteInfo)
871  gwdata = (routeInfo*)tmpGWRouteInfo->data;
872  if(!tmpGWRouteInfo)
873  {
874  lastRouteSetV4=isIPv4;
875  addRouteToList(ipAddr,isIPv4,ipv6Pfix);
876  }
877  else if ( (!isIPv4) && (gwdata) && (g_strcmp0(g_strstrip(gwdata->ipv6Pfix->str),ipv6Pfix) != 0))
878  {
879  LOG_INFO("Adding route since prefix changed from %s to %s ", gwdata->ipv6Pfix->str, ipv6Pfix);
880  lastRouteSetV4=isIPv4;
881  addRouteToList(ipAddr,isIPv4,ipv6Pfix);
882  }
883  else
884  {
885  LOG_INFO("[%s] Route %s is already in the list", MODULE_NAME, ipAddr);
886  }
887  LOG_TRACE("[%s] Exit", MODULE_NAME);
888  return TRUE;
889 }
890 
891 gboolean RouteNetworkMgr::addRouteToList(char *ipAddr,bool isIPv4,char *ipv6Pfix)
892 {
893  LOG_TRACE("[%s] Enter", MODULE_NAME);
894  routeInfo *routeInfoData = g_new(routeInfo,1);
895  routeInfoData->isIPv4 = isIPv4;
896  routeInfoData->ipStr = g_string_new(NULL);
897  routeInfoData->ipv6Pfix = g_string_new(NULL);
898  g_string_assign(routeInfoData->ipStr,ipAddr);
899  g_string_assign(routeInfoData->ipv6Pfix,ipv6Pfix);
900  gwRouteInfo=g_list_prepend(gwRouteInfo,routeInfoData);
901  LOG_INFO("[%s] length of route list is %d",MODULE_NAME,g_list_length(gwRouteInfo));
902  LOG_TRACE("[%s] Exit", MODULE_NAME);
903  return TRUE;
904 
905 }
906 gboolean RouteNetworkMgr::checkRemoveRouteInfo(char *ipAddr,bool isIPv4)
907 {
908  guint gwRouteLength=0;
909 // GList* routeList;
910  routeInfo *routeInfoData;
911  gint retType;
912  gboolean retVal=FALSE;
913  LOG_TRACE("[%s] Enter", MODULE_NAME);
914  gwRouteInfo=g_list_first(gwRouteInfo);
915  gwRouteLength = g_list_length(gwRouteInfo);
916  if (gwRouteLength > 0)
917  {
918  gwRouteInfo=g_list_find_custom(gwRouteInfo,ipAddr,(GCompareFunc)g_list_find_ip);
919  if( gwRouteInfo != NULL)
920  {
921 #ifndef YOCTO_BUILD
922  GString* command=g_string_new(NULL);
923 #endif
924  LOG_INFO("[%s] Route to be removed ******* %s ******* ", MODULE_NAME, ipAddr);
925  if (isIPv4)
926  {
927 #ifdef YOCTO_BUILD
928  retType=v_secure_system("route del default gw %s", ipAddr);
929  //Ignoring WEXITSTATUS(retType) in v_secure_system() as it is already taken care in secure_wrapper.c
930  LOG_INFO("[%s] Remove Route ******* route del default gw %s ******* ", MODULE_NAME, ipAddr);
931 #else
932  g_string_printf(command, "route del default gw %s", ipAddr);
933 #endif
934  }
935  else
936  {
937 #ifdef YOCTO_BUILD
938  retType=v_secure_system("ip -6 route del default via %s", ipAddr);
939  //Ignoring WEXITSTATUS(retType) in v_secure_system() as it is already taken care in secure_wrapper.c
940  LOG_INFO("[%s] Remove Route ******* ip -6 route del default via %s *******", MODULE_NAME,ipAddr);
941 #else
942  g_string_printf(command, "ip -6 route del default via %s", ipAddr);
943 #endif
944  }
945 
946 #ifndef YOCTO_BUILD
947  retType=system(command->str);
948  if(retType != SYSTEM_COMMAND_ERROR)
949  {
950  retType = WEXITSTATUS(retType);
951  }
952  LOG_INFO( "[%s] Remove Route ******* %s *******", MODULE_NAME, command->str);
953 #endif
954  if(retType == SYSTEM_COMMAND_ERROR)
955  {
956  LOG_ERR("[%s] Error has occured in shell command", MODULE_NAME);
957  }
958  else if (retType == SYSTEM_COMMAND_SHELL_NOT_FOUND)
959  {
960  LOG_ERR("[%s] That shell command is not found", MODULE_NAME);
961  }
962  else
963  {
964  LOG_INFO("[%s] system call route set successfully %d", MODULE_NAME, retType);
965  retVal=TRUE;
966  }
967  sendCurrentRouteData();
968  routeInfoData=(routeInfo *)gwRouteInfo->data;
969  removeRouteFromList(routeInfoData);
970 #ifndef YOCTO_BUILD
971  g_string_free(command,TRUE);
972 #endif
973  }
974  else
975  {
976  LOG_INFO("[%s] Existing route exist in the new list", MODULE_NAME);
977  }
978  }
979  else
980  {
981  LOG_INFO("[%s] Saved gw list is empty ", MODULE_NAME);
982  }
983  LOG_TRACE("[%s] Exit", MODULE_NAME);
984  return retVal;
985 }
986 gboolean RouteNetworkMgr::removeRouteFromList(routeInfo *routeInfoData)
987 {
988  LOG_TRACE("[%s] Enter", MODULE_NAME);
989  if((routeInfoData) && (gwRouteInfo))
990  {
991  gwRouteInfo = g_list_first(gwRouteInfo);
992  gwRouteInfo = g_list_remove(gwRouteInfo, routeInfoData);
993  if(routeInfoData)
994  {
995  g_string_free(routeInfoData->ipStr,TRUE);
996  g_string_free(routeInfoData->ipv6Pfix,TRUE);
997  g_free(routeInfoData);
998  }
999  }
1000  else
1001  {
1002  LOG_INFO("[%s] route info data is NULL ", MODULE_NAME);
1003  }
1004  LOG_TRACE("[%s] Exit", MODULE_NAME);
1005  return TRUE;
1006 
1007 }
1008 
1009 bool checkIpMode(char *v6Prefix)
1010 {
1011  bool retVal=TRUE;
1012  LOG_TRACE("[%s] Enter", MODULE_NAME);
1013  if (g_strrstr(g_strstrip(v6Prefix),"null") || ! *(v6Prefix))
1014  retVal=FALSE;
1015  LOG_TRACE("[%s] Exit", MODULE_NAME);
1016  return retVal;
1017 }
1018 
1019 gboolean RouteNetworkMgr::checkExistingRouteValid()
1020 {
1021  guint gwRouteLength=0;
1022  guint tempGwRouteLength=0;
1023  GwyDeviceData *gwdata = NULL;
1024  routeInfo *routeInfoData=NULL;
1025  GList* tmpGWList;
1026  char tempIP[46];
1027  LOG_TRACE("[%s] Enter", MODULE_NAME);
1028  gwRouteInfo=g_list_first(gwRouteInfo);
1029  gwRouteLength = g_list_length(gwRouteInfo);
1030  tempGwRouteLength = gwRouteLength;
1031  if (gwRouteLength > 0)
1032  {
1033  GList *element = g_list_first(gwRouteInfo);
1034  while (element && (gwRouteLength > 0))
1035  {
1036  routeInfoData = (routeInfo*)element->data;
1037  element = g_list_next(element);
1038  gwList=g_list_first(gwList);
1039  g_stpcpy(tempIP,routeInfoData->ipStr->str);
1040  tmpGWList=g_list_find_custom(gwList,tempIP,(GCompareFunc)g_list_find_gw);
1041  if(tmpGWList)
1042  gwdata = (GwyDeviceData*)tmpGWList->data;
1043  if(!tmpGWList)
1044 // if((g_list_find(gwList,tempIP) == NULL))
1045  {
1046  LOG_INFO("[%s] route %s is not there in new list proceed to remove it", MODULE_NAME, routeInfoData->ipStr->str);
1047  checkRemoveRouteInfo(routeInfoData->ipStr->str,routeInfoData->isIPv4);
1048  }
1049  else if((!routeInfoData->isIPv4) && (gwdata) && (g_strcmp0(g_strstrip(routeInfoData->ipv6Pfix->str),g_strstrip(gwdata->ipv6prefix->str)) != 0))
1050  {
1051  LOG_INFO("prefix changed from %s to %s ", routeInfoData->ipv6Pfix->str, gwdata->ipv6prefix->str);
1052  checkRemoveRouteInfo(routeInfoData->ipStr->str,routeInfoData->isIPv4);
1053  }
1054  else
1055  {
1056  LOG_INFO("[%s] route is there in new list", MODULE_NAME);
1057  }
1058  }
1059  }
1060  LOG_TRACE("[%s] Exit", MODULE_NAME);
1061  if((g_list_length(gwRouteInfo) != 0 ) && (g_list_length(gwRouteInfo) != tempGwRouteLength))
1062  {
1063  LOG_INFO("existing route are fine");
1064  return FALSE;
1065  }
1066  return TRUE;
1067 }
1068 gboolean RouteNetworkMgr::printExistingRouteValid()
1069 {
1070  guint gwRouteLength=0;
1071  routeInfo *routeInfoData=NULL;
1072  LOG_TRACE("[%s] Enter", MODULE_NAME);
1073  gwRouteLength = g_list_length(gwRouteInfo);
1074  if (gwRouteLength > 0)
1075  {
1076  GList *element = g_list_first(gwRouteInfo);
1077  while (element && (gwRouteLength > 0))
1078  {
1079  routeInfoData = (routeInfo*)element->data;
1080  element = g_list_next(element);
1081  LOG_TRACE("[%s] ipstring %s isipv4 %d gwRouteLength %d", MODULE_NAME,routeInfoData->ipStr->str,routeInfoData->isIPv4,gwRouteLength);
1082  }
1083  }
1084  else
1085  {
1086  LOG_INFO("[%s] local route list is empty ", MODULE_NAME);
1087  }
1088  LOG_TRACE("[%s] Exit", MODULE_NAME);
1089  return TRUE;
1090 }
1091 
1092 
1093 
1094 
1095 gboolean RouteNetworkMgr::printGatewayList()
1096 {
1097  guint gwListLength=0;
1098  LOG_TRACE("[%s] Enter", MODULE_NAME);
1099  gwListLength = g_list_length(gwList);
1100  LOG_INFO("[%s] gateway count %d ", MODULE_NAME, gwListLength);
1101  if (gwListLength > 0)
1102  {
1103  GwyDeviceData *gwdata = NULL;
1104  GList *element = g_list_first(gwList);
1105  while (element && (gwListLength > 0))
1106  {
1107  gwdata = (GwyDeviceData*)element->data;
1108  element = g_list_next(element);
1109  LOG_INFO("[%s] gateway list %s", MODULE_NAME, gwdata->serial_num->str);
1110  }
1111  }
1112  else
1113  {
1114  LOG_INFO("[%s] local gateway list is empty", MODULE_NAME);
1115  }
1116  LOG_TRACE("[%s] Exit", MODULE_NAME);
1117  return TRUE;
1118 }
1119 
1120 guint RouteNetworkMgr::g_list_find_ip(routeInfo* gwData, gconstpointer* ip )
1121 {
1122  LOG_TRACE("[%s] Enter", MODULE_NAME);
1123  if (g_strcmp0(g_strstrip(gwData->ipStr->str),g_strstrip((gchar *)ip)) == 0)
1124  return 0;
1125  else
1126  return 1;
1127 }
1128 guint RouteNetworkMgr::g_list_find_gw(GwyDeviceData* gwData, gconstpointer* ip )
1129 {
1130  LOG_TRACE("[%s] Enter", MODULE_NAME);
1131  if ((g_strcmp0(g_strstrip(gwData->gwyip->str),g_strstrip((gchar *)ip)) == 0) || (g_strcmp0(g_strstrip(gwData->gwyipv6->str),g_strstrip((gchar *)ip)) == 0))
1132 // if ((g_strcmp0(g_strstrip(gwData->gwyip->str),g_strstrip((gchar *)ip)) == 0) )
1133  return 0;
1134  else
1135  return 1;
1136 }
1137 
1138 gboolean RouteNetworkMgr::getCurrentRoute(char * routeIp,gboolean* isIpv4)
1139 {
1140  FILE *pf;
1141  char data[100] = {0};
1142  LOG_TRACE("[%s] Enter", MODULE_NAME);
1143  GString* command=g_string_new(NULL);
1144  *isIpv4=lastRouteSetV4;
1145  if(lastRouteSetV4)
1146  {
1147  g_string_printf(command, "route -n | grep 'UG[ \t]' | grep %s | awk '{print $2}' | grep 169.254 | sed -n '1p'", routeIf);
1148  }
1149  else
1150  {
1151  g_string_printf(command, " ip -6 route | grep %s | awk '/default/ { print $3 }' ", routeIf);
1152  }
1153  pf=popen(command->str,"r");
1154  if(!pf)
1155  {
1156  LOG_ERR("[%s] pipe to open route failed %s", MODULE_NAME, command->str );
1157  return FALSE;
1158  }
1159 
1160  fgets(data, sizeof (data), pf);
1161  LOG_INFO("[%s] Current Route set is %s", MODULE_NAME, data );
1162  g_stpcpy(routeIp,g_strstrip(data));
1163  g_string_free(command,TRUE);
1164  if(pclose(pf))
1165  {
1166  LOG_ERR("[%s] pipe command stream not closed properly", MODULE_NAME);
1167  }
1168  LOG_TRACE("[%s] Exit", MODULE_NAME);
1169  return TRUE;
1170 }
1171 
1173 {
1174  pthread_t sendDefaultGatewayRouteThread;
1175  pthread_attr_t attr;
1176  int rc;
1177  LOG_TRACE("[%s] Enter", MODULE_NAME);
1178  pthread_attr_init(&attr);
1179  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1180  rc = pthread_create(&sendDefaultGatewayRouteThread, &attr, &sendDefaultGatewayRouteThrd, NULL);
1181  if (rc) {
1182  LOG_ERR("ERROR; sendDefaultGatewayRoute return code from pthread_create() is %d", rc);
1183  }
1184  LOG_TRACE("[%s] Exit", MODULE_NAME);
1185 }
1186 
1188 {
1189  LOG_TRACE("[%s] Enter", MODULE_NAME);
1190  RouteNetworkMgr::sendCurrentRouteData();
1191  LOG_TRACE("[%s] Exit", MODULE_NAME);
1192  return NULL;
1193 }
1194 
1195 gboolean RouteNetworkMgr::sendCurrentRouteData()
1196 {
1197  routeEventData_t data;
1198  char routeIp[100]= {0};
1199  gboolean retVal=FALSE;
1200  gboolean isIpv4;
1201 
1202  memset(&data,0,sizeof(data));
1203 
1204  LOG_TRACE("[%s] Enter", MODULE_NAME);
1205  if(getCurrentRoute(routeIp,&isIpv4))
1206  {
1207  LOG_INFO("[%s] route data to be sent is %s and isIpv4 %d", MODULE_NAME, routeIp, isIpv4);
1208  if(data.routeIp)
1209  strncpy(data.routeIp,routeIp,sizeof(data.routeIp));
1210  data.ipv4=isIpv4;
1211  if(NULL != routeIf)
1212  strncpy(data.routeIf,routeIf,sizeof(data.routeIf));
1213  }
1214  if (IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA, (void *)&data, sizeof(data)) == IARM_RESULT_SUCCESS)
1215  {
1216  LOG_INFO("[%s] Successfully send IARM_BUS_NETSRVMGR_Route_Event event", MODULE_NAME);
1217  retVal=TRUE;
1218  }
1219  else
1220  {
1221  LOG_ERR("[%s] IARM_BUS_NETSRVMGR_Route_Event IARM failed ", MODULE_NAME);
1222  }
1223  LOG_TRACE("[%s] Exit", MODULE_NAME);
1224  return retVal;
1225 }
1226 
1227 IARM_Result_t RouteNetworkMgr::getCurrentRouteData(void *arg)
1228 {
1229  IARM_Result_t ret = IARM_RESULT_SUCCESS;
1230  LOG_TRACE("[%s] Enter", MODULE_NAME);
1232  if(getCurrentRoute(param->route.routeIp,&param->route.ipv4))
1233  {
1234  param->status = true;
1235  strncpy(param->route.routeIf,routeIf,sizeof(param->route.routeIf));
1236  }
1237  else
1238  {
1239  LOG_INFO("[%s] no current route available", MODULE_NAME);
1240  param->status = false;
1241  ret=IARM_RESULT_IPCCORE_FAIL;
1242  }
1243 
1244  LOG_TRACE("[%s] Exit", MODULE_NAME);
1245  return ret;
1246 }
getGatewayRouteData
void getGatewayRouteData()
This function is used to init thread attributes and create thread to get route data.
Definition: routeSrvMgr.cpp:201
RouteNetworkMgr::getGatewayResults
static bool getGatewayResults(char *gatewayResults, unsigned int messageLength)
This function used IARM Bus call to get XUPNP device information and returns the result as a string.
Definition: routeSrvMgr.cpp:165
checkIpMode
bool checkIpMode(char *v6Prefix)
This function is used to check whether the input IP Address belongs to IPv4 or IPv6 address.
Definition: routeSrvMgr.cpp:1009
IARM_BUS_SYSMGR_NAME
#define IARM_BUS_SYSMGR_NAME
Definition: sysMgr.h:110
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_UPDATE
@ IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_UPDATE
Definition: sysMgr.h:131
RouteNetworkMgr
Definition: routeSrvMgr.h:48
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
_IARM_XUPNP_NAME
#define _IARM_XUPNP_NAME
Definition: xdiscovery.h:125
readDevFile
gboolean readDevFile(const char *deviceFile)
This function is used to get partner ID.
Definition: xcal-device-library.c:385
IARM_Bus_RegisterCall
IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler)
This API is used to register an RPC method that can be invoked by other applications.
netsrvmgrUtiles.h
The header file provides components netSrvMgrUtiles information APIs.
checkvalidip
gboolean checkvalidip(char *ipAddress)
This will check whether the input IP Address is a valid IPv4 or IPv6 address.
Definition: routeSrvMgr.cpp:337
checkvalidhostname
gboolean checkvalidhostname(char *hostname)
This function will check whether a Host name is valid by validating all the associated IP addresses.
Definition: routeSrvMgr.cpp:367
sendDefaultGatewayRouteThrd
void * sendDefaultGatewayRouteThrd(void *arg)
Thread function handles the current route data by identifying appropriate IP mode to send route data ...
Definition: routeSrvMgr.cpp:1187
_IARM_BUS_SYSMgr_EventData_t
Definition: sysMgr.h:229
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
_IARM_Bus_RouteSrvMgr_RouteData_Param_t
Definition: xdevice-library.h:127
_IARM_BUS_SYSMGR_GetXUPNPDeviceInfo_Param_t
Definition: sysMgr.h:113
sendDefaultGatewayRoute
void sendDefaultGatewayRoute()
This function is used to init thread attributes and create thread to send route data event.
Definition: routeSrvMgr.cpp:1172
RouteNetworkMgr::storeRouteDetails
static gboolean storeRouteDetails(unsigned int messageLength)
This is invoked when there is a new gateway data.
Definition: routeSrvMgr.cpp:226
_gwyDeviceData
Definition: xdiscovery_private.h:96
getGatewayRouteDataThrd
void * getGatewayRouteDataThrd(void *arg)
When there is a new gateway data, this thread function used IARM Bus call to get XUPNP device informa...
Definition: routeSrvMgr.cpp:245
RouteNetworkMgr::getipaddress
static int getipaddress(char *ifname, char *ipAddressBuffer, gboolean ipv6Enabled)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: routeSrvMgr.cpp:819
free_gwydata
gboolean free_gwydata(GwyDeviceData *gwydata)
Uninitialize gateway data attributes by resetting them to default value.
Definition: xdiscovery.c:2803
LOG_INFO
#define LOG_INFO(AAMP_JS_OBJECT, FORMAT,...)
Definition: jsutils.h:39
_routeInfo
Definition: routeSrvMgr.h:40
IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo
#define IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo
Definition: xdiscovery.h:126
netSrvMgrUtiles::getRouteInterface
bool getRouteInterface(char *devname)
This function retrieves information about the active routing interface.
Definition: netsrvmgrUtiles.cpp:263
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
LOG_TRACE
#define LOG_TRACE
Definition: rdk_debug_priv.c:83
init_gwydata
gboolean init_gwydata(GwyDeviceData *gwydata)
Initializes gateway attributes such as serial number, IP details , MAC details, URL details etc.
Definition: idm_client.c:267
_routeEventData_t
Definition: xdevice-library.h:121