35 #include <sys/sysinfo.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
38 #include <sys/types.h>
39 #include <arpa/inet.h>
45 #include "hostIf_utils.h"
47 #include "safec_lib.h"
55 struct in6_addr ifr6_addr;
57 unsigned int ifr6_ifindex;
60 GMutex* hostIf_IPv6Address::m_mutex = NULL;
61 GHashTable *hostIf_IPv6Address::ifHash = NULL;
63 const char* hostIf_IPv6Address::PREFERRED =
"Preferred";
64 const char* hostIf_IPv6Address::DEPRECATED =
"Deprecated";
65 const char* hostIf_IPv6Address::INVALID =
"Invalid";
66 const char* hostIf_IPv6Address::INACCESSIBLE =
"Inaccessible";
67 const char* hostIf_IPv6Address::UNKNOWN =
"Unknown";
68 const char* hostIf_IPv6Address::TENTATIVE =
"Tentative";
69 const char* hostIf_IPv6Address::DUPLICATE =
"Duplicate";
70 const char* hostIf_IPv6Address::OPTIMISTIC =
"Optimistic";
72 const char* hostIf_IPv6Address::AUTOCONFIGURED =
"AutoConfigured";
73 const char* hostIf_IPv6Address::DHCPv6 =
"DHCPv6";
74 const char* hostIf_IPv6Address::WELLKNOWN =
"WellKnown";
75 const char* hostIf_IPv6Address::STATIC =
"Static";
76 const char* hostIf_IPv6Address::PREFIXDELEGATION =
"PrefixDelegation";
77 const char* hostIf_IPv6Address::ROUTERADVERTISEMENT =
"RouterAdvertisement";
78 const char* hostIf_IPv6Address::CHILD =
"Child";
79 const char* hostIf_IPv6Address::INAPPLICABLE =
"Inapplicable";
81 hostIf_IPv6Address::hostIf_IPv6Address(
int dev_id):
87 backupIPv6AddressEnable (false),
88 backupIPv6PrefixEnable (false)
91 rc=strcpy_s (backupIPv6AddressStatus,
sizeof(backupIPv6AddressStatus),
"Disabled");
96 backupIPv6AddressIPAddress[0]=
'\0';
97 rc=strcpy_s (backupIPv6AddressOrigin,
sizeof(backupIPv6AddressOrigin), STATIC);
102 rc=strcpy_s (backupIPv6PrefixStatus,
sizeof(backupIPv6PrefixStatus),
"Disabled");
107 backupIPv6PrefixPrefix[0]=
'\0';
108 rc=strcpy_s (backupIPv6PrefixOrigin,
sizeof(backupIPv6PrefixOrigin), STATIC);
115 hostIf_IPv6Address::~hostIf_IPv6Address()
119 void hostIf_IPv6Address::refreshInterfaceName ()
121 nameOfInterface[0] = 0;
123 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: error getting interface name for Device.IP.Interface.%d\n", __FUNCTION__, dev_id);
138 ifHash = g_hash_table_new(NULL,NULL);
145 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
148 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create MoCA Interface instance..\n");
154 pRet->refreshInterfaceName ();
159 GList* hostIf_IPv6Address::getAllInstances()
164 return g_hash_table_get_keys(ifHash);
174 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
179 void hostIf_IPv6Address::closeAllInstances()
185 GList* tmp_list = g_hash_table_get_values (ifHash);
190 tmp_list = tmp_list->next;
196 int hostIf_IPv6Address::handleGetMsg (
const char* pSubSetting,
int subInstanceNumber,
HOSTIF_MsgData_t* stMsgData,
bool isAddress)
200 int ret = NOT_HANDLED;
204 if (!strcasecmp (pSubSetting,
"Enable"))
208 else if (!strcasecmp (pSubSetting,
"Status"))
212 else if (!strcasecmp (pSubSetting,
"IPAddressStatus"))
214 ret = get_IPv6Address_IPAddressStatus (stMsgData, subInstanceNumber);
216 else if (!strcasecmp (pSubSetting,
"Alias"))
220 else if (!strcasecmp (pSubSetting,
"IPAddress"))
224 else if (!strcasecmp (pSubSetting,
"Origin"))
228 else if (!strcasecmp (pSubSetting,
"Prefix"))
230 ret = get_IPv6Address_Prefix (stMsgData, subInstanceNumber);
232 else if (!strcasecmp (pSubSetting,
"PreferredLifetime"))
234 ret = get_IPv6Address_PreferredLifetime (stMsgData, subInstanceNumber);
236 else if (!strcasecmp (pSubSetting,
"ValidLifetime"))
238 ret = get_IPv6Address_ValidLifetime (stMsgData, subInstanceNumber);
240 else if (!strcasecmp (pSubSetting,
"Anycast"))
242 ret = get_IPv6Address_Anycast (stMsgData, subInstanceNumber);
246 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%d]Device.IPv6: Parameter \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->
paramName);
247 stMsgData->
faultCode = fcInvalidParameterName;
253 if (!strcasecmp (pSubSetting,
"Enable"))
255 ret = get_IPv6Prefix_Enable (stMsgData, subInstanceNumber);
257 else if (!strcasecmp (pSubSetting,
"Status"))
259 ret = get_IPv6Prefix_Status (stMsgData, subInstanceNumber);
261 else if (!strcasecmp (pSubSetting,
"PrefixStatus"))
263 ret = get_IPv6Prefix_PrefixStatus (stMsgData, subInstanceNumber);
265 else if (!strcasecmp (pSubSetting,
"Alias"))
267 ret = get_IPv6Prefix_Alias (stMsgData, subInstanceNumber);
269 else if (!strcasecmp (pSubSetting,
"Prefix"))
271 ret = get_IPv6Prefix_Prefix (stMsgData, subInstanceNumber);
273 else if (!strcasecmp (pSubSetting,
"Origin"))
275 ret = get_IPv6Prefix_Origin (stMsgData, subInstanceNumber);
277 else if (!strcasecmp (pSubSetting,
"StaticType"))
279 ret = get_IPv6Prefix_StaticType (stMsgData, subInstanceNumber);
281 else if (!strcasecmp (pSubSetting,
"ParentPrefix"))
283 ret = get_IPv6Prefix_ParentPrefix (stMsgData, subInstanceNumber);
285 else if (!strcasecmp (pSubSetting,
"ChildPrefixBits"))
287 ret = get_IPv6Prefix_ChildPrefixBits (stMsgData, subInstanceNumber);
289 else if (!strcasecmp (pSubSetting,
"OnLink"))
291 ret = get_IPv6Prefix_OnLink (stMsgData, subInstanceNumber);
293 else if (!strcasecmp (pSubSetting,
"Autonomous"))
295 ret = get_IPv6Prefix_Autonomous (stMsgData, subInstanceNumber);
297 else if (!strcasecmp (pSubSetting,
"PreferredLifetime"))
299 ret = get_IPv6Prefix_PreferredLifetime (stMsgData, subInstanceNumber);
301 else if (!strcasecmp (pSubSetting,
"ValidLifetime"))
303 ret = get_IPv6Prefix_ValidLifetime (stMsgData, subInstanceNumber);
307 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%d]xBlueTooth: Parameter \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->
paramName);
308 stMsgData->
faultCode = fcInvalidParameterName;
316 int hostIf_IPv6Address::handleSetMsg (
const char* pSubSetting,
int subInstanceNumber,
HOSTIF_MsgData_t* stMsgData,
bool isAddress)
320 int ret = NOT_HANDLED;
324 if (!strcasecmp (pSubSetting,
"Enable"))
328 else if (!strcasecmp (pSubSetting,
"Alias"))
332 else if (!strcasecmp (pSubSetting,
"IPAddress"))
336 else if (!strcasecmp (pSubSetting,
"Prefix"))
338 ret = set_IPv6Address_Prefix (stMsgData, subInstanceNumber);
340 else if (!strcasecmp (pSubSetting,
"PreferredLifetime"))
342 ret = set_IPv6Address_PreferredLifetime (stMsgData, subInstanceNumber);
344 else if (!strcasecmp (pSubSetting,
"ValidLifetime"))
346 ret = set_IPv6Address_ValidLifetime (stMsgData, subInstanceNumber);
348 else if (!strcasecmp (pSubSetting,
"Anycast"))
350 ret = set_IPv6Address_Anycast (stMsgData, subInstanceNumber);
354 stMsgData->
faultCode = fcInvalidParameterName;
360 if (!strcasecmp (pSubSetting,
"Enable"))
362 ret = set_IPv6Prefix_Enable (stMsgData, subInstanceNumber);
364 else if (!strcasecmp (pSubSetting,
"Alias"))
366 ret = set_IPv6Prefix_Alias (stMsgData, subInstanceNumber);
368 else if (!strcasecmp (pSubSetting,
"Prefix"))
370 ret = set_IPv6Prefix_Prefix (stMsgData, subInstanceNumber);
372 else if (!strcasecmp (pSubSetting,
"StaticType"))
374 ret = set_IPv6Prefix_StaticType (stMsgData, subInstanceNumber);
376 else if (!strcasecmp (pSubSetting,
"ParentPrefix"))
378 ret = set_IPv6Prefix_ParentPrefix (stMsgData, subInstanceNumber);
380 else if (!strcasecmp (pSubSetting,
"ChildPrefixBits"))
382 ret = set_IPv6Prefix_ChildPrefixBits (stMsgData, subInstanceNumber);
384 else if (!strcasecmp (pSubSetting,
"OnLink"))
386 ret = set_IPv6Prefix_OnLink (stMsgData, subInstanceNumber);
388 else if (!strcasecmp (pSubSetting,
"Autonomous"))
390 ret = set_IPv6Prefix_Autonomous (stMsgData, subInstanceNumber);
392 else if (!strcasecmp (pSubSetting,
"PreferredLifetime"))
394 ret = set_IPv6Prefix_PreferredLifetime (stMsgData, subInstanceNumber);
396 else if (!strcasecmp (pSubSetting,
"ValidLifetime"))
398 ret = set_IPv6Prefix_ValidLifetime (stMsgData, subInstanceNumber);
402 stMsgData->
faultCode = fcInvalidParameterName;
411 int hostIf_IPv6Address::getIPv6AddressAndMask (
int instance,
struct in6_addr& in6_address,
struct in6_addr& in6_mask)
417 if (getifaddrs (&ifa))
420 int current_instance = 0;
421 for (
struct ifaddrs *ifa_node = ifa; ifa_node; ifa_node = ifa_node->ifa_next)
423 if (ifa_node->ifa_addr->sa_family == AF_INET6 && !strcmp (ifa_node->ifa_name, nameOfInterface) && (++current_instance == instance))
425 in6_address = ((
struct sockaddr_in6 *) ifa_node->ifa_addr)->sin6_addr;
426 in6_mask = ((
struct sockaddr_in6 *) ifa_node->ifa_netmask)->sin6_addr;
434 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s]: rc=%d, if=%s, instance=%d\n", __FUNCTION__, rc, nameOfInterface, instance);
442 int hostIf_IPv6Address::getIPv6Prefix (
int instance,
struct in6_addr& in6_prefix_address,
unsigned int& prefix_length)
446 struct in6_addr in6_address;
447 struct in6_addr in6_mask;
448 if (OK != getIPv6AddressAndMask (instance, in6_address, in6_mask))
452 for (
int i = 3 ; i >= 0 ; i--)
454 in6_prefix_address.s6_addr32[i] = in6_address.s6_addr32[i] & in6_mask.s6_addr32[i];
461 for (uint8_t i = 0, number_of_1bits = 8, bitPattern = 0xFF; i < 16 && number_of_1bits == 8; i++)
464 while (in6_mask.s6_addr[i] != bitPattern && number_of_1bits != 0)
466 bitPattern = bitPattern << 1;
469 prefix_length += number_of_1bits;
472 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s]: prefix_length =%u\n", __FUNCTION__, prefix_length);
491 RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF,
"[%s]: ntohs(in6_address.s6_addr16[0]) = %x, (ntohs(in6_address.s6_addr16[0]) & 0xffc0) = %x\n",
492 __FUNCTION__, ntohs(in6_address.s6_addr16[0]), (ntohs(in6_address.s6_addr16[0]) & 0xffc0));
493 return (ntohs(in6_address.s6_addr16[0]) & 0xffc0) == 0xfe80;
497 int hostIf_IPv6Address::removeIp(
int interfaceNo,
char *value)
500 errno_t safec_rc = -1;
503 struct sockaddr_in6 sai6;
507 if(0 == strcasecmp(backupIPv6AddressOrigin, STATIC))
512 sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
519 memset(&sai6, 0,
sizeof(sockaddr_in6));
520 sai6.sin6_family = AF_INET6;
523 if(inet_pton(AF_INET6, value, (
void *)&sai6.sin6_addr) <= 0)
525 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"Error Formatting IP Address");
535 ifr6.ifr6_ifindex = interfaceNo;
536 safec_rc=memcpy_s( (
char *) &ifr6.ifr6_addr,
sizeof(
struct in6_addr), (
char *) &sai6.sin6_addr,
sizeof(
struct in6_addr));
541 ifr6.ifr6_prefixlen = 64;
543 if (ioctl(sockfd, SIOCDIFADDR, &ifr6) < 0)
545 perror(
"SIOCDIFADDR: Error Deleting Existing IPAddress");
553 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"Error Creating Socket; Not Removing IP Address");
560 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"The interface is not static; Cannot Remove IP Address\n");
567 int hostIf_IPv6Address::setIp(
int interfaceNo,
char *value)
570 errno_t safec_rc = -1;
573 struct sockaddr_in6 sai6;
577 if(0 == strcasecmp(backupIPv6AddressOrigin, STATIC))
582 sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
589 memset(&sai6, 0,
sizeof(sockaddr_in6));
590 sai6.sin6_family = AF_INET6;
593 if(inet_pton(AF_INET6, value, (
void *)&sai6.sin6_addr) <= 0)
595 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"Error Formatting IP Address");
605 ifr6.ifr6_ifindex = interfaceNo;
606 safec_rc=memcpy_s( (
char *) &ifr6.ifr6_addr,
sizeof(
struct in6_addr), (
char *) &sai6.sin6_addr,
sizeof(
struct in6_addr));
611 ifr6.ifr6_prefixlen = 64;
613 if (ioctl(sockfd, SIOCSIFADDR, &ifr6) < 0)
615 perror(
"SIOCDIFADDR: Error Assigning IPAddress");
623 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"Error Creating Socket; Not Assigning IP Address");
629 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"The interface is not static; Cannot Assign IP Address\n");
657 struct in6_addr in6_address;
658 struct in6_addr in6_mask;
659 bool enable = (OK == getIPv6AddressAndMask (subInstanceNo, in6_address, in6_mask));
661 if(bCalledEnable && pChanged && (backupIPv6AddressEnable != enable))
665 bCalledEnable =
true;
666 backupIPv6AddressEnable = enable;
668 stMsgData->
paramtype = hostIf_BooleanType;
699 char status[BUFF_LENGTH_16];
700 struct in6_addr in6_address;
701 struct in6_addr in6_mask;
703 if(OK == getIPv6AddressAndMask (subInstanceNo, in6_address, in6_mask))
705 rc=strcpy_s (status,
sizeof(status),
"Enabled");
709 rc=strcpy_s (status,
sizeof(status),
"Disabled");
715 if (bCalledStatus && pChanged && strncmp (status, backupIPv6AddressStatus, BUFF_LENGTH_16))
719 bCalledStatus =
true;
720 strncpy (backupIPv6AddressStatus, status,
sizeof(backupIPv6AddressStatus) -1);
721 backupIPv6AddressStatus[
sizeof(backupIPv6AddressStatus) -1] =
'\0';
722 strncpy (stMsgData->
paramValue, status, BUFF_LENGTH_16);
723 stMsgData->
paramtype = hostIf_StringType;
724 stMsgData->
paramLen = strlen (status);
729 int hostIf_IPv6Address::get_IPv6Address_IPAddressStatus (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
763 long int preferred_lft;
767 char interfaceOperationalState[BUFF_LENGTH_16];
768 hostIf_IPInterface::getInstance (dev_id)->getInterfaceOperationalState (interfaceOperationalState);
770 char ipaddressStatus[BUFF_LENGTH_16];
773 rc=strcpy_s (ipaddressStatus,BUFF_LENGTH_16, INVALID);
779 else if (strcasecmp (interfaceOperationalState, STATE_DOWN) == 0)
781 rc=strcpy_s (ipaddressStatus,BUFF_LENGTH_16, INACCESSIBLE);
787 else if (preferred_lft == 0)
789 rc=strcpy_s (ipaddressStatus,BUFF_LENGTH_16, DEPRECATED);
798 rc=strcpy_s (ipaddressStatus,BUFF_LENGTH_16, PREFERRED);
807 strncpy (stMsgData->
paramValue, ipaddressStatus, BUFF_LENGTH_16);
808 stMsgData->
paramtype = hostIf_StringType;
809 stMsgData->
paramLen = strlen (ipaddressStatus);
843 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
867 struct in6_addr in6_address;
868 struct in6_addr in6_mask;
869 if (OK != getIPv6AddressAndMask (subInstanceNo, in6_address, in6_mask))
872 char ipv6Address[BUFF_LENGTH_64];
873 inet_ntop (AF_INET6, &in6_address, ipv6Address, BUFF_LENGTH_64);
874 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s,%d]: if = %s, instance = %d, ipv6address = %s\n",
875 __FUNCTION__, __LINE__, nameOfInterface, subInstanceNo, ipv6Address);
877 if (bCalledIPAddress && pChanged && strncmp (ipv6Address, backupIPv6AddressIPAddress, BUFF_LENGTH_64))
881 bCalledIPAddress =
true;
882 strncpy (backupIPv6AddressIPAddress, ipv6Address,
sizeof(backupIPv6AddressIPAddress) -1);
883 backupIPv6AddressIPAddress[
sizeof(backupIPv6AddressIPAddress) -1] =
'\0';
884 strncpy (stMsgData->
paramValue, ipv6Address, BUFF_LENGTH_64);
885 stMsgData->
paramtype = hostIf_StringType;
886 stMsgData->
paramLen = strlen (ipv6Address);
939 struct in6_addr in6_address;
940 struct in6_addr in6_mask;
941 if (OK != getIPv6AddressAndMask (subInstanceNo, in6_address, in6_mask))
944 char origin[BUFF_LENGTH_32];
945 if (hostIf_IPInterface::isLoopback (nameOfInterface))
947 rc=strcpy_s (origin,BUFF_LENGTH_32, WELLKNOWN);
955 rc=strcpy_s (origin,BUFF_LENGTH_32, AUTOCONFIGURED);
963 rc=strcpy_s (origin,BUFF_LENGTH_32, AUTOCONFIGURED);
970 if (bCalledOrigin && pChanged && strncmp (origin, backupIPv6AddressOrigin, BUFF_LENGTH_32))
974 bCalledOrigin =
true;
975 strncpy (backupIPv6AddressOrigin, origin,
sizeof(backupIPv6AddressOrigin) -1);
976 backupIPv6AddressOrigin[
sizeof(backupIPv6AddressOrigin) -1] =
'\0';
977 strncpy (stMsgData->
paramValue, origin, BUFF_LENGTH_32);
978 stMsgData->
paramtype = hostIf_StringType;
979 stMsgData->
paramLen = strlen (origin);
984 int hostIf_IPv6Address::get_IPv6Address_Prefix (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1004 struct in6_addr in6_address;
1005 struct in6_addr in6_mask;
1007 if (OK != getIPv6AddressAndMask (subInstanceNo, in6_address, in6_mask))
1015 char pathnameOfRowInIPv6PrefixTable[TR69HOSTIFMGR_MAX_PARAM_LEN];
1016 rc=strcpy_s (pathnameOfRowInIPv6PrefixTable,TR69HOSTIFMGR_MAX_PARAM_LEN, stMsgData->
paramName);
1021 const char *positionAfterInstanceNumber = 0;
1022 int instanceNumber = 0;
1023 if(!matchComponent (pathnameOfRowInIPv6PrefixTable,
"Device.IP.Interface", &positionAfterInstanceNumber, instanceNumber))
1025 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"hostIf_IPv6Address : matchComponent error \n");
1027 sprintf ((
char*) positionAfterInstanceNumber,
"%s%d.",
"IPv6Prefix.", subInstanceNo);
1029 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s,%d] pathnameOfRowInIPv6PrefixTable = %s",
1030 __FUNCTION__, __LINE__, pathnameOfRowInIPv6PrefixTable);
1032 strncpy (stMsgData->
paramValue, pathnameOfRowInIPv6PrefixTable,
sizeof(stMsgData->
paramValue) -1);
1034 stMsgData->
paramtype = hostIf_StringType;
1035 stMsgData->
paramLen = strlen (pathnameOfRowInIPv6PrefixTable);
1040 int hostIf_IPv6Address::get_IPv6Address_PreferredLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1048 char preferredLifetime[BUFF_LENGTH_32];
1049 convert_lifetime_to_string (lifetime, preferredLifetime);
1052 strncpy (stMsgData->
paramValue, preferredLifetime, BUFF_LENGTH_32);
1053 stMsgData->
paramtype = hostIf_StringType;
1054 stMsgData->
paramLen = strlen (preferredLifetime);
1059 int hostIf_IPv6Address::get_IPv6Address_ValidLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1067 char validLifetime[BUFF_LENGTH_32];
1068 convert_lifetime_to_string (lifetime, validLifetime);
1071 strncpy (stMsgData->
paramValue, validLifetime, BUFF_LENGTH_32);
1072 stMsgData->
paramtype = hostIf_StringType;
1073 stMsgData->
paramLen = strlen (validLifetime);
1078 int hostIf_IPv6Address::get_IPv6Address_Anycast (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1089 stMsgData->
paramtype = hostIf_BooleanType;
1090 stMsgData->
paramLen =
sizeof(bool);
1121 char cmd[BUFF_LENGTH_64] = { 0 };
1122 char resultBuff[BUFF_LENGTH_128] = { 0 };
1123 snprintf (cmd, BUFF_LENGTH_64,
"ip -6 -o addr show %s | awk '{i++;if(i==%d){print}}'", nameOfInterface, instance);
1124 if (read_command_output (cmd, resultBuff, BUFF_LENGTH_128) != OK)
1126 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s,%d] resultBuff = %s", __FUNCTION__, __LINE__, resultBuff);
1128 char *str = strstr (resultBuff, search_string);
1135 str += strlen (search_string);
1136 while (isspace (*str))
1139 char strLifetime[BUFF_LENGTH_64];
1140 int count = sscanf (str,
"%s", strLifetime);
1142 if (strcmp (strLifetime,
"forever") == 0)
1149 long int time_remaining = strtol (strLifetime, &time_units, 10);
1150 long int seconds_remaining = (strncasecmp (time_units,
"s", 1) == 0) ? time_remaining :
1151 (strncasecmp (time_units,
"m", 1) == 0) ? time_remaining * 60 : -1;
1152 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s,%d] time_remaining = %ld, time_units = %s, seconds_remaining = %ld\n",
1153 __FUNCTION__, __LINE__, time_remaining, time_units, seconds_remaining);
1155 if (seconds_remaining == -1)
1162 lifetime = time (0) + seconds_remaining;
1196 void hostIf_IPv6Address::convert_lifetime_to_string (
long int t,
char* lifetime)
1205 rc=strcpy_s (lifetime,BUFF_LENGTH_32, TIME_UNKNOWN);
1213 rc=strcpy_s (lifetime,BUFF_LENGTH_32, TIME_INFINITY);
1222 gmtime_r (&t, &tmp);
1223 strftime (lifetime, BUFF_LENGTH_128,
"%Y-%m-%dT%H:%M:%SZ", &tmp);
1228 int hostIf_IPv6Address::get_IPv6Prefix_Enable(
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1232 struct in6_addr in6_prefix_address;
1233 unsigned int prefix_length;
1234 bool enable = (OK == getIPv6Prefix (subInstanceNo, in6_prefix_address, prefix_length));
1237 if (bCalledEnable && pChanged && (backupIPv6PrefixEnable != enable))
1241 bCalledEnable =
true;
1242 backupIPv6PrefixEnable = enable;
1244 stMsgData->
paramtype = hostIf_BooleanType;
1245 stMsgData->
paramLen =
sizeof(bool);
1250 int hostIf_IPv6Address::get_IPv6Prefix_Status(
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1255 char status[BUFF_LENGTH_16];
1256 struct in6_addr in6_prefix_address;
1257 unsigned int prefix_length;
1259 if(OK == getIPv6Prefix (subInstanceNo, in6_prefix_address, prefix_length))
1261 rc=strcpy_s (status,
sizeof(status),
"Enabled");
1269 rc=strcpy_s (status,
sizeof(status),
"Disabled");
1276 if (bCalledStatus && pChanged && strncmp (status, backupIPv6PrefixStatus, BUFF_LENGTH_16))
1280 bCalledStatus =
true;
1281 strncpy (backupIPv6PrefixStatus, status,
sizeof(backupIPv6PrefixStatus) -1);
1282 backupIPv6PrefixStatus[
sizeof(backupIPv6PrefixStatus) -1] =
'\0';
1283 strncpy (stMsgData->
paramValue, status, BUFF_LENGTH_16);
1284 stMsgData->
paramtype = hostIf_StringType;
1285 stMsgData->
paramLen = strlen (status);
1290 int hostIf_IPv6Address::get_IPv6Prefix_PrefixStatus (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1323 long int preferred_lft;
1327 char interfaceOperationalState[BUFF_LENGTH_16];
1328 hostIf_IPInterface::getInstance (dev_id)->getInterfaceOperationalState (interfaceOperationalState);
1330 char prefixStatus[BUFF_LENGTH_16];
1333 rc=strcpy_s (prefixStatus,BUFF_LENGTH_16, INVALID);
1339 else if (strcasecmp (interfaceOperationalState, STATE_DOWN) == 0)
1341 rc=strcpy_s (prefixStatus,BUFF_LENGTH_16, INACCESSIBLE);
1347 else if (preferred_lft == 0)
1349 rc=strcpy_s (prefixStatus,BUFF_LENGTH_16, DEPRECATED);
1357 rc=strcpy_s (prefixStatus,BUFF_LENGTH_16, PREFERRED);
1366 strncpy (stMsgData->
paramValue, prefixStatus, BUFF_LENGTH_16);
1367 stMsgData->
paramtype = hostIf_StringType;
1368 stMsgData->
paramLen = strlen (prefixStatus);
1373 int hostIf_IPv6Address::get_IPv6Prefix_Alias(
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1376 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1380 int hostIf_IPv6Address::get_IPv6Prefix_Prefix(
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1384 struct in6_addr in6_prefix_address;
1385 unsigned int prefix_length;
1386 if (OK != getIPv6Prefix (subInstanceNo, in6_prefix_address, prefix_length))
1389 char prefix_address[BUFF_LENGTH_64];
1390 inet_ntop (AF_INET6, &in6_prefix_address, prefix_address, 64);
1392 char prefix[BUFF_LENGTH_64];
1393 sprintf (prefix,
"%s/%u", prefix_address, prefix_length);
1394 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s]: if=%s, instance=%d, prefix=%s\n",
1395 __FUNCTION__, nameOfInterface, subInstanceNo, prefix);
1398 if (bCalledIPAddress && pChanged && strncmp (prefix, backupIPv6PrefixPrefix, BUFF_LENGTH_64))
1402 bCalledIPAddress =
true;
1403 strncpy (backupIPv6PrefixPrefix, prefix,
sizeof(backupIPv6PrefixPrefix) -1);
1404 backupIPv6PrefixPrefix[
sizeof(backupIPv6PrefixPrefix) -1] =
'\0';
1405 strncpy (stMsgData->
paramValue, prefix, BUFF_LENGTH_64);
1406 stMsgData->
paramtype = hostIf_StringType;
1407 stMsgData->
paramLen = strlen (prefix);
1412 int hostIf_IPv6Address::get_IPv6Prefix_Origin (
int instance,
char* origin)
1453 struct in6_addr in6_address;
1454 struct in6_addr in6_mask;
1456 if (OK != getIPv6AddressAndMask (instance, in6_address, in6_mask))
1459 if (hostIf_IPInterface::isLoopback (nameOfInterface) ||
isLinkLocalAddress (in6_address))
1461 rc=strcpy_s (origin,BUFF_LENGTH_32, WELLKNOWN);
1469 rc=strcpy_s (origin,BUFF_LENGTH_32, AUTOCONFIGURED);
1479 int hostIf_IPv6Address::get_IPv6Prefix_Origin(
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1483 char origin[BUFF_LENGTH_32];
1484 if (OK != get_IPv6Prefix_Origin (subInstanceNo, origin))
1488 if (bCalledOrigin && pChanged && strncmp (origin, backupIPv6PrefixOrigin, BUFF_LENGTH_32))
1492 bCalledOrigin =
true;
1493 strncpy (backupIPv6PrefixOrigin, origin,
sizeof(backupIPv6PrefixOrigin) -1);
1494 backupIPv6PrefixOrigin[
sizeof(backupIPv6PrefixOrigin) -1] =
'\0';
1495 strncpy (stMsgData->
paramValue, origin, BUFF_LENGTH_32);
1496 stMsgData->
paramtype = hostIf_StringType;
1497 stMsgData->
paramLen = strlen (origin);
1502 int hostIf_IPv6Address::get_IPv6Prefix_StaticType (
int instance,
char* staticType)
1542 char origin[BUFF_LENGTH_32];
1544 if (OK != get_IPv6Prefix_Origin (instance, origin))
1546 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Error retrieving IPv6Prefix Origin\n", __FUNCTION__);
1551 if (strcasecmp (origin, STATIC) != 0)
1553 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"%s: StaticType = Inapplicable (IPv6Prefix origin not Static)\n", __FUNCTION__);
1554 rc=strcpy_s (staticType,BUFF_LENGTH_32, INAPPLICABLE);
1563 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1564 rc=strcpy_s (staticType,BUFF_LENGTH_32, NOT_IMPLEMENTED);
1572 int hostIf_IPv6Address::get_IPv6Prefix_StaticType (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1577 char staticType[BUFF_LENGTH_32];
1578 if (OK != get_IPv6Prefix_StaticType (subInstanceNo, staticType))
1580 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Error retrieving IPv6Prefix StaticType\n", __FUNCTION__);
1589 stMsgData->
paramtype = hostIf_StringType;
1590 stMsgData->
paramLen = strlen (staticType);
1595 int hostIf_IPv6Address::get_IPv6Prefix_ParentPrefix (
int instance,
char* parentPrefix)
1612 char origin[BUFF_LENGTH_32];
1613 if (OK != get_IPv6Prefix_Origin (instance, origin))
1616 bool relevant =
false;
1617 if (strcasecmp (origin, CHILD) == 0)
1623 char staticType[BUFF_LENGTH_32];
1624 if (OK != get_IPv6Prefix_StaticType (instance, staticType))
1626 if (strcasecmp (staticType, CHILD) == 0)
1632 parentPrefix[0]=
'\0';
1637 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1638 rc=strcpy_s (parentPrefix,BUFF_LENGTH_64, NOT_IMPLEMENTED);
1648 int hostIf_IPv6Address::get_IPv6Prefix_ParentPrefix (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1653 char parentPrefix[BUFF_LENGTH_64];
1654 if (OK != get_IPv6Prefix_ParentPrefix (subInstanceNo, parentPrefix))
1662 stMsgData->
paramtype = hostIf_StringType;
1663 stMsgData->
paramLen = strlen (parentPrefix);
1668 int hostIf_IPv6Address::get_IPv6Prefix_ChildPrefixBits (
int instance,
char* childPrefixBits)
1685 char staticType[BUFF_LENGTH_32];
1686 if (OK != get_IPv6Prefix_StaticType (instance, staticType))
1689 if (strcasecmp (staticType, CHILD) != 0)
1691 childPrefixBits[0]=
'\0';
1696 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1697 rc=strcpy_s (childPrefixBits,BUFF_LENGTH_64, NOT_IMPLEMENTED);
1705 int hostIf_IPv6Address::get_IPv6Prefix_ChildPrefixBits (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1710 char childPrefixBits[BUFF_LENGTH_64];
1711 if (OK != get_IPv6Prefix_ChildPrefixBits (subInstanceNo, childPrefixBits))
1719 stMsgData->
paramtype = hostIf_StringType;
1720 stMsgData->
paramLen = strlen (childPrefixBits);
1725 int hostIf_IPv6Address::get_IPv6Prefix_OnLink (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1739 stMsgData->
paramtype = hostIf_BooleanType;
1740 stMsgData->
paramLen =
sizeof(bool);
1745 int hostIf_IPv6Address::get_IPv6Prefix_Autonomous (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1759 stMsgData->
paramtype = hostIf_BooleanType;
1760 stMsgData->
paramLen =
sizeof(bool);
1765 int hostIf_IPv6Address::get_IPv6Prefix_PreferredLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1777 return get_IPv6Address_PreferredLifetime (stMsgData, subInstanceNo, pChanged);
1780 int hostIf_IPv6Address::get_IPv6Prefix_ValidLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo,
bool *pChanged)
1791 return get_IPv6Address_ValidLifetime (stMsgData, subInstanceNo, pChanged);
1816 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1847 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1873 struct in6_addr in6_address;
1874 struct in6_addr in6_mask;
1875 int rc = getIPv6AddressAndMask (subInstanceNo, in6_address, in6_mask);
1877 char ipAddress[BUFF_LENGTH_64];
1878 inet_ntop (AF_INET6, &in6_address, ipAddress, BUFF_LENGTH_64);
1883 if (OK == rc && (strcmp (ipAddress,
"") != 0))
1885 rc = removeIp (dev_id, ipAddress);
1904 int hostIf_IPv6Address::set_IPv6Address_Prefix (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1907 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1911 int hostIf_IPv6Address::set_IPv6Address_PreferredLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1914 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1918 int hostIf_IPv6Address::set_IPv6Address_ValidLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1921 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1925 int hostIf_IPv6Address::set_IPv6Address_Anycast (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1928 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1932 int hostIf_IPv6Address::set_IPv6Prefix_Enable (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1935 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1939 int hostIf_IPv6Address::set_IPv6Prefix_Alias (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1942 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1946 int hostIf_IPv6Address::set_IPv6Prefix_Prefix (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1949 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1953 int hostIf_IPv6Address::set_IPv6Prefix_StaticType (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1956 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1960 int hostIf_IPv6Address::set_IPv6Prefix_ParentPrefix (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1963 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1967 int hostIf_IPv6Address::set_IPv6Prefix_ChildPrefixBits (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1970 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1974 int hostIf_IPv6Address::set_IPv6Prefix_OnLink (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1977 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1981 int hostIf_IPv6Address::set_IPv6Prefix_Autonomous (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1984 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1988 int hostIf_IPv6Address::set_IPv6Prefix_PreferredLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1991 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);
1995 int hostIf_IPv6Address::set_IPv6Prefix_ValidLifetime (
HOSTIF_MsgData_t *stMsgData,
int subInstanceNo)
1998 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Not Implemented\n", __FUNCTION__);