From 7d35d3b9658fb61220b8970b6fadd52558d0d878 Mon Sep 17 00:00:00 2001 From: Lionel Gauthier Date: Fri, 5 Dec 2014 11:11:59 +0000 Subject: [PATCH] git-svn-id: http://svn.eurecom.fr/openair4G/trunk@6177 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- openair-cn/UTILS/mme_config.c | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/openair-cn/UTILS/mme_config.c b/openair-cn/UTILS/mme_config.c index a07b76771d..4b37df2128 100644 --- a/openair-cn/UTILS/mme_config.c +++ b/openair-cn/UTILS/mme_config.c @@ -149,6 +149,23 @@ void mme_config_init(mme_config_t *mme_config_p) mme_config_p->s1ap_config.outcome_drop_timer_sec = S1AP_OUTCOME_TIMER_DEFAULT; } +int mme_system(char *command_pP, int abort_on_errorP) { + int ret = -1; + if (command_pP) { + fprintf(stdout, "system command: %s\n",command_pP); + ret = system(command_pP); + if (ret < 0) { + fprintf(stderr, "ERROR in system command %s: %d\n", + command_pP,ret); + if (abort_on_errorP) { + exit(-1); // may be not exit + } + } + } + return ret; +} + + static int config_parse_file(mme_config_t *mme_config_p) { config_t cfg; @@ -173,6 +190,9 @@ static int config_parse_file(mme_config_t *mme_config_p) char *mme_interface_name_for_S11 = NULL; char *mme_ip_address_for_S11 = NULL; char *sgw_ip_address_for_S11 = NULL; +#if defined (ENABLE_USE_GTPU_IN_KERNEL) + char system_cmd[256]; +#endif config_init(&cfg); @@ -369,6 +389,35 @@ static int config_parse_file(mme_config_t *mme_config_p) address = strtok(cidr, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.mme_ip_address_for_S11, "BAD IP ADDRESS FORMAT FOR MME S11 !\n" ) free(cidr); + + if (strncasecmp("tun",mme_config_p->ipv4.mme_interface_name_for_S1_MME, strlen("tun")) == 0) { + if (snprintf(system_cmd, 256, + "ip link set %s down ;openvpn --rmtun --dev %s", + mme_config_p->ipv4.mme_interface_name_for_S1_MME, + mme_config_p->ipv4.mme_interface_name_for_S1_MME + ) > 0) { + mme_system(system_cmd, 1); + } else { + fprintf(stderr, "Del %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME); + } + if (snprintf(system_cmd, 256, + "openvpn --mktun --dev %s;sync;ifconfig %s up;sync", + mme_config_p->ipv4.mme_interface_name_for_S1_MME, + mme_config_p->ipv4.mme_interface_name_for_S1_MME) > 0) { + mme_system(system_cmd, 1); + } else { + fprintf(stderr, "Create %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME); + } + if (snprintf(system_cmd, 256, + "ip -4 addr add %s dev %s", + mme_ip_address_for_S1_MME, + mme_config_p->ipv4.mme_interface_name_for_S1_MME) > 0) { + mme_system(system_cmd, 1); + } else { + fprintf(stderr, "Set IPv4 address on %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME); + } + } + } }