+int _connection_libnet_add_route_entry(connection_address_family_e address_family,
+ const char *interface_name, const char *host_address, const char *gateway)
+{
+ int rv;
+ char *endstr = NULL;
+ int address_family_type = 0;
+
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
+ address_family_type = AF_INET;
+ else
+ address_family_type = AF_INET6;
+
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
+
+ endstr = strrchr(host_address, '.');
+ if (endstr == NULL ||
+ strcmp(endstr, ".0") == 0 ||
+ strncmp(host_address, "0.", 2) == 0 ||
+ strstr(host_address, "255") != NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ rv = net_add_route_entry(host_address, interface_name, address_family_type, gateway);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+
+ } else {
+
+ if (strncmp(host_address, "fe80:", 5) == 0 ||
+ strncmp(host_address, "ff00:", 5) == 0 ||
+ strncmp(host_address, "::", 2) == 0) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ rv = net_add_route_ipv6(host_address, interface_name, address_family_type, gateway);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+ }
+
+ return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_remove_route_entry(connection_address_family_e address_family,
+ const char *interface_name, const char *host_address, const char *gateway)
+{
+ int rv;
+ char *endstr = strrchr(host_address, '.');
+ int address_family_type = 0;
+
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
+ address_family_type = AF_INET;
+ else
+ address_family_type = AF_INET6;
+
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
+ endstr = strrchr(host_address, '.');
+ if (endstr == NULL ||
+ strcmp(endstr, ".0") == 0 ||
+ strncmp(host_address, "0.", 2) == 0 ||
+ strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ rv = net_remove_route_entry(host_address, interface_name, address_family_type, gateway);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+
+ } else {
+
+ if (strncmp(host_address, "fe80:", 5) == 0 ||
+ strncmp(host_address, "ff00:", 5) == 0 ||
+ strncmp(host_address, "::", 2) == 0) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ rv = net_remove_route_ipv6(host_address, interface_name, address_family_type, gateway);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+ }
+
+ return CONNECTION_ERROR_NONE;
+}
+