aboutsummaryrefslogtreecommitdiffstats
path: root/ggsn/cmdline.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2014-03-24 18:06:53 +0100
committerPablo Neira Ayuso <pablo@gnumonks.org>2014-03-24 19:20:26 +0100
commit3f58223436f1b91591e9faff0dbc8b20ad2f2eb6 (patch)
tree136f658b089b7399974cc516ad3cccfaf376b2d1 /ggsn/cmdline.c
parent746b944ad6835c38e94a591bf5363b1797429337 (diff)
ggsn: add support for GTP kernel data encapsulationosmo-ggsn
This patch adds the -g, --gtpnl=device option that allows you to enable the GTP kernel tunneling mode in openggsn. You have to specify the real downlink device that will be used to tunnel traffic, eg. -g=eth0 This means that the gtp0 device will be created and it will use eth0 as the real device to encapsulate packet coming from the Internet that are addressed to the MS (so the tunnel devuce encapsulates these IP packets in GTP packets when traveling to the SGSN). Alternatively, you can also add this to the ggsn.conf configuration file: gtpnl eth0 The device has to be the real device that can route packets to the SGSN, if you select the wrong device, the kernel routing code may not find a way to reach the SSGN, you've been warned. Therefore, if this option is set, the operational becomes the following: 1) A gtp0 device is created via rtnetlink and configure the socket encapsulation infrastructure in the kernel. 2) Whenever a PDP context is created, this adds the necessary tunnel configuration via genetlink GTP interface. 3) Whenever a PDP context is destroyed, this deletes the tunnel via genetlink GTP interface. 4) Destroy the gtp0 device if ggsn is stopped, including all of the existing tunnels. You require the osmo-ggsn.git tree, which contains the kernel module gtp.ko and the libgtpnl library that you have to compile and install. Make sure you have loaded the gtp.ko kernel module before launching the ggsn daemon using the kernel driver mode, otherwise you will get a nice "operation not supported" error message ;-). This patch also adds supports for "ipup" configuration option to invoke an external script after the gtp0 device has been brought up. Typical command to add the route to reach the MS behind the GGSN is required, eg. ip route add 10.0.0.0/8 dev gtp0. The (horrible) ggsn parser has been manually extended to support the new configuration option. That code doesn't look nice, but it just mimics what we already have there for consistency, please don't blame me for that. If you want to run in debugging mode, I suggest you to use: sudo ggsn -c ggsn.conf -f -d Note that you do have to run openggsn as root to bring up the gtp0 device. You have to see this message that announce that the GTP kernel mode is enabled. openggsn[1106]: ggsn.c: 656: Using the GTP kernel mode (genl ID is 25) This patch also automagically sets up route to reach MS from Internet just like tun mode does. This is fundamental to get this working, better don't leave to the admin, he may forget to add this route. In this patch, I tried to encapsulate this new feature as much as possible as Harald initially suggested. To compile this feature, you have to pass --enable-gtp-kernel, ie. ./configire --enable-gtp-kernel Otherwise, the code to interact with the gtp kernel part is not compiled.
Diffstat (limited to 'ggsn/cmdline.c')
-rw-r--r--ggsn/cmdline.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/ggsn/cmdline.c b/ggsn/cmdline.c
index 3fcfbd5..6c7f143 100644
--- a/ggsn/cmdline.c
+++ b/ggsn/cmdline.c
@@ -1,5 +1,5 @@
/*
- File autogenerated by gengetopt version 2.22.6
+ File autogenerated by gengetopt version 2.22.5
generated with the following command:
gengetopt --conf-parser
@@ -29,8 +29,6 @@ const char *gengetopt_args_info_purpose = "";
const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]...";
-const char *gengetopt_args_info_versiontext = "";
-
const char *gengetopt_args_info_description = "";
const char *gengetopt_args_info_help[] = {
@@ -39,8 +37,8 @@ const char *gengetopt_args_info_help[] = {
" -f, --fg Run in foreground (default=off)",
" -d, --debug Run in debug mode (default=off)",
" -c, --conf=STRING Read configuration file (default=`/etc/ggsn.conf')",
- " --pidfile=STRING Filename of process id file\n (default=`/var/run/ggsn.pid')",
- " --statedir=STRING Directory of nonvolatile data\n (default=`/var/lib/ggsn/')",
+ " --pidfile=STRING Filename of process id file \n (default=`/var/run/ggsn.pid')",
+ " --statedir=STRING Directory of nonvolatile data \n (default=`/var/lib/ggsn/')",
" -l, --listen=STRING Local interface",
" -n, --net=STRING Network (default=`192.168.0.0/24')",
" --ipup=STRING Script to run after link-up",
@@ -53,6 +51,7 @@ const char *gengetopt_args_info_help[] = {
" -a, --apn=STRING Access point name (default=`internet')",
" -q, --qos=INT Requested quality of service (default=`0x0b921f')",
" --logfile=STRING Logfile for errors",
+ " -g, --gtpnl=STRING GTP kernel support (default=`eth0')",
0
};
@@ -121,6 +120,7 @@ void clear_given (struct gengetopt_args_info *args_info)
args_info->apn_given = 0 ;
args_info->qos_given = 0 ;
args_info->logfile_given = 0 ;
+ args_info->gtpnl_given = 0 ;
}
static
@@ -159,6 +159,8 @@ void clear_args (struct gengetopt_args_info *args_info)
args_info->qos_orig = NULL;
args_info->logfile_arg = NULL;
args_info->logfile_orig = NULL;
+ args_info->gtpnl_arg = gengetopt_strdup ("eth0");
+ args_info->gtpnl_orig = NULL;
}
@@ -186,6 +188,7 @@ void init_args_info(struct gengetopt_args_info *args_info)
args_info->apn_help = gengetopt_args_info_help[16] ;
args_info->qos_help = gengetopt_args_info_help[17] ;
args_info->logfile_help = gengetopt_args_info_help[18] ;
+ args_info->gtpnl_help = gengetopt_args_info_help[19] ;
}
@@ -195,9 +198,6 @@ cmdline_parser_print_version (void)
printf ("%s %s\n",
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
CMDLINE_PARSER_VERSION);
-
- if (strlen(gengetopt_args_info_versiontext) > 0)
- printf("\n%s\n", gengetopt_args_info_versiontext);
}
static void print_help_common(void) {
@@ -297,6 +297,8 @@ cmdline_parser_release (struct gengetopt_args_info *args_info)
free_string_field (&(args_info->qos_orig));
free_string_field (&(args_info->logfile_arg));
free_string_field (&(args_info->logfile_orig));
+ free_string_field (&(args_info->gtpnl_arg));
+ free_string_field (&(args_info->gtpnl_orig));
@@ -365,6 +367,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
write_into_file(outfile, "qos", args_info->qos_orig, 0);
if (args_info->logfile_given)
write_into_file(outfile, "logfile", args_info->logfile_orig, 0);
+ if (args_info->gtpnl_given)
+ write_into_file(outfile, "gtpnl", args_info->gtpnl_orig, 0);
i = EXIT_SUCCESS;
@@ -589,17 +593,19 @@ cmdline_parser_internal (
{
int c; /* Character of the parsed option. */
- int error_occurred = 0;
+ int error = 0;
struct gengetopt_args_info local_args_info;
int override;
int initialize;
+ int check_required;
int check_ambiguity;
package_name = argv[0];
override = params->override;
initialize = params->initialize;
+ check_required = params->check_required;
check_ambiguity = params->check_ambiguity;
if (initialize)
@@ -636,10 +642,11 @@ cmdline_parser_internal (
{ "apn", 1, NULL, 'a' },
{ "qos", 1, NULL, 'q' },
{ "logfile", 1, NULL, 0 },
+ { "gtpnl", 1, NULL, 'g' },
{ 0, 0, 0, 0 }
};
- c = getopt_long (argc, argv, "hVfdc:l:n:a:q:", long_options, &option_index);
+ c = getopt_long (argc, argv, "hVfdc:l:n:a:q:g:", long_options, &option_index);
if (c == -1) break; /* Exit from `while (1)' loop. */
@@ -735,6 +742,18 @@ cmdline_parser_internal (
goto failure;
break;
+ case 'g': /* GTP kernel support. */
+
+
+ if (update_arg( (void *)&(args_info->gtpnl_arg),
+ &(args_info->gtpnl_orig), &(args_info->gtpnl_given),
+ &(local_args_info.gtpnl_given), optarg, 0, "eth0", ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "gtpnl", 'g',
+ additional_error))
+ goto failure;
+
+ break;
case 0: /* Long option with no short option */
/* Filename of process id file. */
@@ -894,7 +913,7 @@ cmdline_parser_internal (
cmdline_parser_release (&local_args_info);
- if ( error_occurred )
+ if ( error )
return (EXIT_FAILURE);
return 0;