From 803d2bb8ef2ab969c772bcdfe5127558ae98336e Mon Sep 17 00:00:00 2001 From: Lionel Gauthier Date: Thu, 20 Nov 2014 15:39:09 +0000 Subject: [PATCH] git-svn-id: http://svn.eurecom.fr/openair4G/trunk@6058 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- openair-cn/SGW-LITE/spgw_config.c | 77 ++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/openair-cn/SGW-LITE/spgw_config.c b/openair-cn/SGW-LITE/spgw_config.c index 3ab51ece63..d68fa344d4 100755 --- a/openair-cn/SGW-LITE/spgw_config.c +++ b/openair-cn/SGW-LITE/spgw_config.c @@ -180,6 +180,8 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { char *pgw_ipv4_address_for_S5_S8 = NULL; char *pgw_interface_name_for_SGI = NULL; char *pgw_ipv4_address_for_SGI = NULL; + char *pgw_default_dns_ipv4_address = NULL; + char *pgw_default_dns_sec_ipv4_address = NULL; char *delimiters=NULL; char *saveptr1 = NULL; @@ -202,7 +204,9 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { struct in_addr addr_mask; pgw_lite_conf_ipv4_list_elm_t *ip4_ref = NULL; pgw_lite_conf_ipv6_list_elm_t *ip6_ref = NULL; - +#if defined (ENABLE_USE_GTPU_IN_KERNEL) + char system_cmd[256]; +#endif memset((char*)config_pP, 0 , sizeof(spgw_config_t)); STAILQ_INIT(&config_pP->pgw_config.pgw_lite_ipv4_pool_list); @@ -249,6 +253,17 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { config_pP->sgw_config.ipv4.sgw_ip_netmask_for_S1u_S12_S4_up = atoi(mask); free(cidr); +#if defined (ENABLE_USE_GTPU_IN_KERNEL) + if (snprintf(system_cmd, 128, + "echo 0 > /proc/sys/net/ipv4/conf/%s/send_redirects", + config_pP->sgw_config.ipv4.sgw_interface_name_for_S1u_S12_S4_up) > 0) { + SPGW_APP_INFO("Disable send ICMP redirect: %s\n",system_cmd); + system(system_cmd); + } else { + SPGW_APP_ERROR("Disable send ICMP redirect for %s\n", + config_pP->sgw_config.ipv4.sgw_interface_name_for_S1u_S12_S4_up); + } +#endif in_addr_var.s_addr = config_pP->sgw_config.ipv4.sgw_ipv4_address_for_S1u_S12_S4_up; SPGW_APP_INFO("Parsing configuration file found sgw_ipv4_address_for_S1u_S12_S4_up: %s/%d on %s\n", inet_ntoa(in_addr_var), @@ -330,6 +345,33 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { inet_ntoa(in_addr_var), config_pP->pgw_config.ipv4.pgw_ip_netmask_for_SGI, config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI); + +#if defined (ENABLE_USE_GTPU_IN_KERNEL) + if (snprintf(system_cmd, 128, + "iptables -I POSTROUTING -t mangle -o %s -m state --state NEW -m mark ! --mark 0 ! --protocol sctp -j CONNMARK --save-mark", + config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI) > 0) { + SPGW_APP_INFO("Save mark: %s\n",system_cmd); + system(system_cmd); + } else { + SPGW_APP_ERROR("Save mark\n"); + } + if (snprintf(system_cmd, 128, + "iptables -I PREROUTING -t mangle -i %s ! --protocol sctp -j CONNMARK --restore-mark", + config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI) > 0) { + SPGW_APP_INFO("Restore mark: %s\n",system_cmd); + system(system_cmd); + } else { + SPGW_APP_ERROR("Restore mark\n"); + } + if (snprintf(system_cmd, 128, + "iptables -t nat -A POSTROUTING -o %s ! --protocol sctp -j MASQUERADE", + config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI) > 0) { + SPGW_APP_INFO("Masquerade SGI: %s\n",system_cmd); + system(system_cmd); + } else { + SPGW_APP_ERROR("Masquerade SGI\n"); + } +#endif } else { SPGW_APP_WARN("CONFIG P-GW / NETWORK INTERFACES parsing failed\n"); } @@ -352,6 +394,17 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { memcpy (&addr_start, buf_in_addr, sizeof(struct in_addr)); // valid address atoken2 = strtok(NULL, PGW_CONFIG_STRING_IPV4_PREFIX_DELIMITER); +#if defined (ENABLE_USE_GTPU_IN_KERNEL) + if (snprintf(system_cmd, 128, "ip route add %s/%s dev %s", + astring, + atoken2, + config_pP->sgw_config.ipv4.sgw_interface_name_for_S1u_S12_S4_up) > 0) { + SPGW_APP_INFO("Add route: %s\n",system_cmd); + system(system_cmd); + } else { + SPGW_APP_ERROR("Add route: for %s\n", astring); + } +#endif prefix_mask = atoi(atoken2); if ((prefix_mask >= 2)&&(prefix_mask < 32)) { memcpy (&addr_start, buf_in_addr, sizeof(struct in_addr)); @@ -385,6 +438,16 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { ip4_ref = calloc(1, sizeof(pgw_lite_conf_ipv4_list_elm_t)); ip4_ref->addr = addr_start; STAILQ_INSERT_TAIL(&config_pP->pgw_config.pgw_lite_ipv4_pool_list, ip4_ref, ipv4_entries); +#if defined (ENABLE_USE_GTPU_IN_KERNEL) + if (snprintf(system_cmd, 128, "ip route add %s dev %s", + buf_in_addr, + config_pP->sgw_config.ipv4.sgw_interface_name_for_S1u_S12_S4_up) > 0) { + SPGW_APP_INFO("Add route: %s\n",system_cmd); + system(system_cmd); + } else { + SPGW_APP_ERROR("Add route: for %s\n", buf_in_addr); + } +#endif } } } @@ -428,7 +491,19 @@ int spgw_config_init(char* lib_config_file_name_pP, spgw_config_t* config_pP) { } } } + if( + config_setting_lookup_string(subsetting, + PGW_CONFIG_STRING_DEFAULT_DNS_IPV4_ADDRESS, + (const char **)&pgw_default_dns_ipv4_address) + && config_setting_lookup_string(subsetting, + PGW_CONFIG_STRING_DEFAULT_DNS_SEC_IPV4_ADDRESS, + (const char **)&pgw_default_dns_sec_ipv4_address)) { + config_pP->pgw_config.ipv4.pgw_interface_name_for_S5_S8 = strdup(pgw_interface_name_for_S5_S8); + IPV4_STR_ADDR_TO_INT_NWBO ( pgw_default_dns_ipv4_address, config_pP->pgw_config.ipv4.default_dns_v4, "BAD IPv4 ADDRESS FORMAT FOR DEFAULT DNS !\n" ) + IPV4_STR_ADDR_TO_INT_NWBO ( pgw_default_dns_sec_ipv4_address, config_pP->pgw_config.ipv4.default_dns_sec_v4, "BAD IPv4 ADDRESS FORMAT FOR DEFAULT DNS SEC!\n" ) + } } + } else { SPGW_APP_WARN("CONFIG P-GW not found\n"); }