22 #include <sys/socket.h>
23 #include <arpa/inet.h>
27 #include <sys/types.h>
29 #include "routeSrvMgr.h"
30 #include "NetworkMgrMain.h"
31 #include "NetworkMedium.h"
34 #ifdef ENABLE_NLMONITOR
35 #include "netlinkifc.h"
36 #endif //ENABLE_NLMONITOR
40 #define ROUTE_PRIORITY 50
41 #define GW_SETUP_FILE "/lib/rdk/gwSetup.sh"
42 #define MAX_CJSON_EMPTY_LENGTH 40
44 #define DHCP_LEASE_FLAG "/tmp/usingdhcp"
45 #define PREFERRED_GATEWAY_FILE "/opt/prefered-gateway"
49 #include "secure_wrapper.h"
53 #include "safec_lib.h"
55 #define MEMCPY_S(dest,dsize,source,ssize) \
56 memcpy(dest,source,ssize);
61 GList* gwRouteInfo = NULL;
62 bool lastRouteSetV4=FALSE;
64 bool signalUpnpDataReady=
true;
67 bool RouteNetworkMgr::instanceIsReady =
false;
69 static bool gwSelected =
false;
70 static bool xb3Selected =
false;
71 static bool upnpGwyLost =
true;
73 pthread_cond_t condRoute = PTHREAD_COND_INITIALIZER;
74 pthread_mutex_t mutexRoute = PTHREAD_MUTEX_INITIALIZER;
76 RouteNetworkMgr::RouteNetworkMgr() {}
77 RouteNetworkMgr::~RouteNetworkMgr() { }
84 instanceIsReady =
true;
90 int RouteNetworkMgr::Start()
97 std::ifstream cfgFile(PREFERRED_GATEWAY_FILE);
99 if (cfgFile.is_open())
105 LOG_INFO(
"[%s] Preferred Gateway is XB", MODULE_NAME);
131 static void _evtHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
139 pthread_mutex_lock(&mutexRoute);
140 signalUpnpDataReady=
true;
141 if(0 == pthread_cond_signal(&condRoute))
143 messageLength = eventData->data.xupnpData.deviceInfoLength;
144 LOG_INFO(
"[%s] Signal to fetch the data from upnp %ld", MODULE_NAME, eventData->data.xupnpData.deviceInfoLength );
146 pthread_mutex_unlock(&mutexRoute);
168 IARM_Result_t ret = IARM_RESULT_SUCCESS;
169 bool returnStatus = FALSE;
173 if(ret == IARM_RESULT_SUCCESS)
175 param->bufLength = messageLength;
180 if(ret == IARM_RESULT_SUCCESS)
183 gatewayResults[param->bufLength] =
'\0';
188 LOG_ERR(
"[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo IARM failed in the fetch", MODULE_NAME);
190 LOG_TRACE(
"[%s] gatewayResults %s", MODULE_NAME, gatewayResults);
191 IARM_Free(IARM_MEMTYPE_PROCESSLOCAL, param);
196 LOG_ERR(
"[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo , IARM_Malloc Failed", MODULE_NAME);
203 pthread_t getGatewayRouteDataThread;
208 pthread_attr_init(&attr);
209 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
212 LOG_ERR(
"ERROR; getGatewayRouteData return code from pthread_create() is %d", rc);
228 char upnpResults[messageLength+1];
229 gboolean retVal=FALSE;
231 memset(&upnpResults,0,
sizeof(upnpResults));
234 if(parse_store_gateway_data(&upnpResults[0]))
239 LOG_ERR(
"Failure in getting gateway results.");
250 pthread_mutex_lock(&mutexRoute);
251 while(signalUpnpDataReady ==
false) {
252 pthread_cond_wait(&condRoute, &mutexRoute);
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);
263 if(RouteNetworkMgr::checkExistingRouteValid())
265 if(RouteNetworkMgr::setRoute())
266 RouteNetworkMgr::sendCurrentRouteData();
272 RouteNetworkMgr::delRouteList();
274 gwRouteInfo = g_list_first(gwRouteInfo);
275 if((g_list_length(gwRouteInfo) == 0) && ( access( DHCP_LEASE_FLAG, F_OK ) == -1 ))
281 LOG_INFO(
"[%s] Triggering dhcp lease since no XG gateway", MODULE_NAME);
282 netSrvMgrUtiles::triggerDhcpRenew();
286 #ifdef ENABLE_NLMONITOR
289 ofs.open(
"/tmp/resolv.dnsmasq.upnp", std::ofstream::out | std::ofstream::trunc);
294 list<std::string> ifcList;
296 if ((interface = getenv(
"WIFI_INTERFACE")) != NULL)
297 ifcList.push_back(interface);
298 if ((interface = getenv(
"MOCA_INTERFACE")) != NULL)
299 ifcList.push_back(interface);
301 for (
auto const& i : ifcList)
303 std::string ifcStr = i;
305 NetLinkIfc::get_instance()->deleteinterfaceip(ifcStr,AF_INET6);
306 NetLinkIfc::get_instance()->deleteinterfaceroutes(ifcStr,AF_INET6);
309 v_secure_system(
"/lib/rdk/enableIpv6Autoconf.sh %s", ifcStr.c_str());
311 std::string cmd =
"/lib/rdk/enableIpv6Autoconf.sh ";
316 LOG_INFO(
"[%s] No Gateway Detected, SLAAC Support is enabled", MODULE_NAME);
318 #endif//ENABLE_NLMONITOR
339 struct in_addr addr4;
340 struct in6_addr addr6;
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 )
346 LOG_ERR(
"[%s] ipaddress are empty %s", MODULE_NAME, ipAddress);
349 if ((validip4 == 1 ) || (validip6 == 1 ))
355 LOG_ERR(
"[%s] Not a valid ip address %s", MODULE_NAME, ipAddress);
370 if (g_strrstr(g_strstrip(hostname),
"null") || ! *hostname )
372 LOG_ERR(
"[%s] hostname values are empty %s", MODULE_NAME, hostname);
375 gchar **tokens = g_strsplit_set(hostname,
" ;\n\0", -1);
376 guint toklength = g_strv_length(tokens);
378 for (loopvar=0; loopvar<toklength; loopvar++)
385 LOG_ERR(
"[%s] no valid ip so rejecting the dns values %s", MODULE_NAME, hostname);
391 gboolean RouteNetworkMgr::init_gwydata(
GwyDeviceData* gwydata)
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);
405 gboolean RouteNetworkMgr::free_gwydata(
GwyDeviceData* gwydata)
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);
420 gboolean RouteNetworkMgr::readDevFile(
char *deviceFile,
char *mocaIface,
char *wifiIface)
423 gboolean result = FALSE;
424 gchar* devfilebuffer = NULL;
427 if (deviceFile == NULL)
429 LOG_ERR(
"[%s] device properties file not found", MODULE_NAME);
432 result = g_file_get_contents (deviceFile, &devfilebuffer, NULL, &error);
435 LOG_ERR(
"[%s] No contents in device properties", MODULE_NAME);
441 gchar **tokens = g_strsplit_set(devfilebuffer,
",='\n'", -1);
442 guint toklength = g_strv_length(tokens);
444 for (loopvar=0; loopvar<toklength; loopvar++)
446 if (g_strrstr(g_strstrip(tokens[loopvar]),
"MOCA_INTERFACE"))
448 if ((loopvar+1) < toklength )
451 g_stpcpy(mocaIface, g_strstrip(tokens[loopvar+1]));
458 if (g_strrstr(g_strstrip(tokens[loopvar]),
"WIFI_INTERFACE"))
460 if ((loopvar+1) < toklength )
463 g_stpcpy(wifiIface, g_strstrip(tokens[loopvar+1]));
472 g_free(devfilebuffer);
474 if((!mocaIface) && (!wifiIface))
476 LOG_ERR(
"[%s] MOCA_INTERFACE and WIFI_INTERFACE not found in %s", MODULE_NAME, deviceFile);
483 g_clear_error(&error);
488 gboolean RouteNetworkMgr::delGatewayList()
490 guint gwListLength=0;
492 gwList = g_list_first(gwList);
493 gwListLength = g_list_length(gwList);
494 if (gwListLength > 0)
497 while (gwList && (gwListLength > 0))
500 gwList = g_list_next(gwList);
503 gwList = g_list_remove(gwList, gwdata);
510 LOG_INFO(
"[%s] NO gateway data available", MODULE_NAME);
516 gboolean RouteNetworkMgr::delRouteList()
518 guint gwRouteLength=0;
520 gwRouteInfo = g_list_first(gwRouteInfo);
521 gwRouteLength = g_list_length(gwRouteInfo);
522 if (gwRouteLength > 0)
525 while (gwRouteInfo && (gwRouteLength > 0))
528 checkRemoveRouteInfo(gwdata->ipStr->str,gwdata->isIPv4);
529 gwRouteInfo = g_list_next(gwRouteInfo);
534 g_list_free(gwRouteInfo);
540 LOG_INFO(
"[%s] NO gateway data available", MODULE_NAME);
546 gboolean RouteNetworkMgr::parse_store_gateway_data(
char *array)
551 gboolean retVal=
TRUE;
555 cJSON *rootJson=cJSON_Parse(array);
558 cJSON *gwFullData = cJSON_GetObjectItem(rootJson,
"xmediagateways");
561 guint gwCount = cJSON_GetArraySize(gwFullData);
562 LOG_INFO(
"gateway count in json %d", gwCount);
563 char *isgateway,*dnsConfig,*gatewayIp,*gatewayIpV6,*serialNum,*ipv6Prefix,*devType;
565 for (counter = 0; counter < gwCount; counter++)
567 cJSON *gwData = cJSON_GetArrayItem(gwFullData, counter);
568 isgateway = dnsConfig = gatewayIp = gatewayIpV6 = serialNum = ipv6Prefix = devType = NULL;
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;
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));
600 LOG_ERR(
"[%s] not a valid gateway %s", MODULE_NAME, serialNum);
603 LOG_ERR(
"[%s] Failed to get gateway details,Array item is Null", MODULE_NAME);
606 gwList = g_list_first(gwList);
607 if( g_list_length(gwList) == 0)
615 checkExistingRouteValid();
617 LOG_INFO(
"[%s] No gwdata to parse gwcount ", MODULE_NAME);
619 cJSON_Delete(rootJson);
630 LOG_ERR(
"[%s] gateway list is empty", MODULE_NAME);
637 gboolean RouteNetworkMgr::getRouteInterface(
char * routeIf)
639 char devFile[] =
"//etc//device.properties";
640 char mocaIf[10]= {0};
641 char wifiIf[10]= {0};
642 char ipAddressBuffer[46];
646 int result =
getipaddress(mocaIf,ipAddressBuffer,FALSE);
649 LOG_INFO(
"[%s] Could not locate the ipaddress of the broadcast interface %s", MODULE_NAME,mocaIf );
653 LOG_INFO(
"[%s] Could not locate the ipaddress of the broadcast interface %s", MODULE_NAME, wifiIf );
658 g_stpcpy(routeIf,wifiIf);
663 g_stpcpy(routeIf,mocaIf);
668 LOG_ERR(
"[%s] No route interface available", MODULE_NAME);
675 gboolean RouteNetworkMgr::setRoute() {
677 gboolean firstXG1GwData=
TRUE;
678 gboolean firstXG2GwData=
TRUE;
679 gboolean setRoute=FALSE;
680 GList *element = NULL;
681 gboolean retVal=FALSE;
684 element = g_list_first(gwList);
685 LOG_TRACE(
"[%s] gw list count %d", MODULE_NAME, g_list_length(gwList));
689 LOG_ERR(
"[%s] No Interface available to add route", MODULE_NAME);
695 element = g_list_next(element);
698 LOG_TRACE(
"[%s] gwdata NULL", MODULE_NAME);
701 if(g_strcmp0(gwdata->devicetype->str,
"XG2") == 0)
703 if(firstXG2GwData ==
TRUE)
705 firstXG2GwData=FALSE;
711 if(firstXG1GwData ==
TRUE)
713 firstXG1GwData = FALSE;
720 #ifdef ENABLE_NLMONITOR
721 if ((!gwSelected) && (!xb3Selected))
723 list<std::string> ifcList;
725 if ((interface = getenv(
"WIFI_INTERFACE")) != NULL)
726 ifcList.push_back(interface);
727 if ((interface = getenv(
"MOCA_INTERFACE")) != NULL)
728 ifcList.push_back(interface);
731 for (
auto const& i : ifcList)
734 std::string ifcStr = i;
736 v_secure_system(
"/lib/rdk/disableIpv6Autoconf.sh %s", ifcStr.c_str());
738 std::string cmd =
"/lib/rdk/disableIpv6Autoconf.sh ";
744 NetLinkIfc::get_instance()->deleteinterfaceip(ifcStr,AF_INET6);
745 NetLinkIfc::get_instance()->deleteinterfaceroutes(ifcStr,AF_INET6);
747 LOG_INFO(
"[%s] Gateway Detecetd, SLAAC Support is disabled.", MODULE_NAME);
749 #endif //ENABLE_NLMONITOR
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);
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)
774 retType = WEXITSTATUS(retType);
778 if(retType == SYSTEM_COMMAND_ERROR)
780 LOG_ERR(
"[%s] Error has occured in shell command", MODULE_NAME);
782 else if (retType == SYSTEM_COMMAND_SHELL_NOT_FOUND)
784 LOG_ERR(
"[%s] That shell command is not found", MODULE_NAME);
786 else if (retType == SYSTEM_COMMAND_SHELL_SUCESS)
788 LOG_INFO(
"[%s] system call route set successfully %d", MODULE_NAME, retType);
789 gwdata->isRouteSet=
TRUE;
792 checkAddRouteInfo(gwdata->gwyipv6->str,FALSE,gwdata->ipv6prefix->str);
796 checkAddRouteInfo(gwdata->gwyip->str,
TRUE,gwdata->ipv6prefix->str);
802 LOG_INFO(
"[%s] no change in routing information %d", MODULE_NAME, retType);
821 struct ifaddrs * ifAddrStruct=NULL;
822 struct ifaddrs * ifa=NULL;
823 void * tmpAddrPtr=NULL;
825 getifaddrs(&ifAddrStruct);
828 for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
829 if (ifa->ifa_addr == NULL)
continue;
830 if (ipv6Enabled ==
TRUE)
833 if ((strcmp(ifa->ifa_name,ifname)==0) && (ifa ->ifa_addr->sa_family==AF_INET6))
835 tmpAddrPtr=&((
struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
836 inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
838 if (IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr))
846 if (ifa ->ifa_addr->sa_family==AF_INET) {
848 tmpAddrPtr=&((
struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
849 inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
851 if (strcmp(ifa->ifa_name,ifname)==0)
859 if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
864 gboolean RouteNetworkMgr::checkAddRouteInfo(
char *ipAddr,
bool isIPv4,
char *ipv6Pfix)
868 gwRouteInfo=g_list_first(gwRouteInfo);
869 GList* tmpGWRouteInfo=g_list_find_custom(gwRouteInfo,ipAddr,(GCompareFunc)g_list_find_ip);
871 gwdata = (
routeInfo*)tmpGWRouteInfo->data;
874 lastRouteSetV4=isIPv4;
875 addRouteToList(ipAddr,isIPv4,ipv6Pfix);
877 else if ( (!isIPv4) && (gwdata) && (g_strcmp0(g_strstrip(gwdata->ipv6Pfix->str),ipv6Pfix) != 0))
879 LOG_INFO(
"Adding route since prefix changed from %s to %s ", gwdata->ipv6Pfix->str, ipv6Pfix);
880 lastRouteSetV4=isIPv4;
881 addRouteToList(ipAddr,isIPv4,ipv6Pfix);
885 LOG_INFO(
"[%s] Route %s is already in the list", MODULE_NAME, ipAddr);
891 gboolean RouteNetworkMgr::addRouteToList(
char *ipAddr,
bool isIPv4,
char *ipv6Pfix)
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));
906 gboolean RouteNetworkMgr::checkRemoveRouteInfo(
char *ipAddr,
bool isIPv4)
908 guint gwRouteLength=0;
912 gboolean retVal=FALSE;
914 gwRouteInfo=g_list_first(gwRouteInfo);
915 gwRouteLength = g_list_length(gwRouteInfo);
916 if (gwRouteLength > 0)
918 gwRouteInfo=g_list_find_custom(gwRouteInfo,ipAddr,(GCompareFunc)g_list_find_ip);
919 if( gwRouteInfo != NULL)
922 GString* command=g_string_new(NULL);
924 LOG_INFO(
"[%s] Route to be removed ******* %s ******* ", MODULE_NAME, ipAddr);
928 retType=v_secure_system(
"route del default gw %s", ipAddr);
930 LOG_INFO(
"[%s] Remove Route ******* route del default gw %s ******* ", MODULE_NAME, ipAddr);
932 g_string_printf(command,
"route del default gw %s", ipAddr);
938 retType=v_secure_system(
"ip -6 route del default via %s", ipAddr);
940 LOG_INFO(
"[%s] Remove Route ******* ip -6 route del default via %s *******", MODULE_NAME,ipAddr);
942 g_string_printf(command,
"ip -6 route del default via %s", ipAddr);
947 retType=system(command->str);
948 if(retType != SYSTEM_COMMAND_ERROR)
950 retType = WEXITSTATUS(retType);
952 LOG_INFO(
"[%s] Remove Route ******* %s *******", MODULE_NAME, command->str);
954 if(retType == SYSTEM_COMMAND_ERROR)
956 LOG_ERR(
"[%s] Error has occured in shell command", MODULE_NAME);
958 else if (retType == SYSTEM_COMMAND_SHELL_NOT_FOUND)
960 LOG_ERR(
"[%s] That shell command is not found", MODULE_NAME);
964 LOG_INFO(
"[%s] system call route set successfully %d", MODULE_NAME, retType);
967 sendCurrentRouteData();
968 routeInfoData=(
routeInfo *)gwRouteInfo->data;
969 removeRouteFromList(routeInfoData);
971 g_string_free(command,
TRUE);
976 LOG_INFO(
"[%s] Existing route exist in the new list", MODULE_NAME);
981 LOG_INFO(
"[%s] Saved gw list is empty ", MODULE_NAME);
986 gboolean RouteNetworkMgr::removeRouteFromList(
routeInfo *routeInfoData)
989 if((routeInfoData) && (gwRouteInfo))
991 gwRouteInfo = g_list_first(gwRouteInfo);
992 gwRouteInfo = g_list_remove(gwRouteInfo, routeInfoData);
995 g_string_free(routeInfoData->ipStr,
TRUE);
996 g_string_free(routeInfoData->ipv6Pfix,
TRUE);
997 g_free(routeInfoData);
1002 LOG_INFO(
"[%s] route info data is NULL ", MODULE_NAME);
1013 if (g_strrstr(g_strstrip(v6Prefix),
"null") || ! *(v6Prefix))
1019 gboolean RouteNetworkMgr::checkExistingRouteValid()
1021 guint gwRouteLength=0;
1022 guint tempGwRouteLength=0;
1028 gwRouteInfo=g_list_first(gwRouteInfo);
1029 gwRouteLength = g_list_length(gwRouteInfo);
1030 tempGwRouteLength = gwRouteLength;
1031 if (gwRouteLength > 0)
1033 GList *element = g_list_first(gwRouteInfo);
1034 while (element && (gwRouteLength > 0))
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);
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);
1049 else if((!routeInfoData->isIPv4) && (gwdata) && (g_strcmp0(g_strstrip(routeInfoData->ipv6Pfix->str),g_strstrip(gwdata->ipv6prefix->str)) != 0))
1051 LOG_INFO(
"prefix changed from %s to %s ", routeInfoData->ipv6Pfix->str, gwdata->ipv6prefix->str);
1052 checkRemoveRouteInfo(routeInfoData->ipStr->str,routeInfoData->isIPv4);
1056 LOG_INFO(
"[%s] route is there in new list", MODULE_NAME);
1061 if((g_list_length(gwRouteInfo) != 0 ) && (g_list_length(gwRouteInfo) != tempGwRouteLength))
1063 LOG_INFO(
"existing route are fine");
1068 gboolean RouteNetworkMgr::printExistingRouteValid()
1070 guint gwRouteLength=0;
1073 gwRouteLength = g_list_length(gwRouteInfo);
1074 if (gwRouteLength > 0)
1076 GList *element = g_list_first(gwRouteInfo);
1077 while (element && (gwRouteLength > 0))
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);
1086 LOG_INFO(
"[%s] local route list is empty ", MODULE_NAME);
1095 gboolean RouteNetworkMgr::printGatewayList()
1097 guint gwListLength=0;
1099 gwListLength = g_list_length(gwList);
1100 LOG_INFO(
"[%s] gateway count %d ", MODULE_NAME, gwListLength);
1101 if (gwListLength > 0)
1104 GList *element = g_list_first(gwList);
1105 while (element && (gwListLength > 0))
1108 element = g_list_next(element);
1109 LOG_INFO(
"[%s] gateway list %s", MODULE_NAME, gwdata->serial_num->str);
1114 LOG_INFO(
"[%s] local gateway list is empty", MODULE_NAME);
1120 guint RouteNetworkMgr::g_list_find_ip(
routeInfo* gwData, gconstpointer* ip )
1123 if (g_strcmp0(g_strstrip(gwData->ipStr->str),g_strstrip((gchar *)ip)) == 0)
1128 guint RouteNetworkMgr::g_list_find_gw(
GwyDeviceData* gwData, gconstpointer* ip )
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))
1138 gboolean RouteNetworkMgr::getCurrentRoute(
char * routeIp,gboolean* isIpv4)
1141 char data[100] = {0};
1143 GString* command=g_string_new(NULL);
1144 *isIpv4=lastRouteSetV4;
1147 g_string_printf(command,
"route -n | grep 'UG[ \t]' | grep %s | awk '{print $2}' | grep 169.254 | sed -n '1p'", routeIf);
1151 g_string_printf(command,
" ip -6 route | grep %s | awk '/default/ { print $3 }' ", routeIf);
1153 pf=popen(command->str,
"r");
1156 LOG_ERR(
"[%s] pipe to open route failed %s", MODULE_NAME, command->str );
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);
1166 LOG_ERR(
"[%s] pipe command stream not closed properly", MODULE_NAME);
1174 pthread_t sendDefaultGatewayRouteThread;
1175 pthread_attr_t attr;
1178 pthread_attr_init(&attr);
1179 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1182 LOG_ERR(
"ERROR; sendDefaultGatewayRoute return code from pthread_create() is %d", rc);
1190 RouteNetworkMgr::sendCurrentRouteData();
1195 gboolean RouteNetworkMgr::sendCurrentRouteData()
1198 char routeIp[100]= {0};
1199 gboolean retVal=FALSE;
1202 memset(&data,0,
sizeof(data));
1205 if(getCurrentRoute(routeIp,&isIpv4))
1207 LOG_INFO(
"[%s] route data to be sent is %s and isIpv4 %d", MODULE_NAME, routeIp, isIpv4);
1209 strncpy(data.routeIp,routeIp,
sizeof(data.routeIp));
1212 strncpy(data.routeIf,routeIf,
sizeof(data.routeIf));
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)
1216 LOG_INFO(
"[%s] Successfully send IARM_BUS_NETSRVMGR_Route_Event event", MODULE_NAME);
1221 LOG_ERR(
"[%s] IARM_BUS_NETSRVMGR_Route_Event IARM failed ", MODULE_NAME);
1227 IARM_Result_t RouteNetworkMgr::getCurrentRouteData(
void *arg)
1229 IARM_Result_t ret = IARM_RESULT_SUCCESS;
1232 if(getCurrentRoute(param->route.routeIp,¶m->route.ipv4))
1234 param->status =
true;
1235 strncpy(param->route.routeIf,routeIf,
sizeof(param->route.routeIf));
1239 LOG_INFO(
"[%s] no current route available", MODULE_NAME);
1240 param->status =
false;
1241 ret=IARM_RESULT_IPCCORE_FAIL;