[PATCH] osmo-ggsn[master]: sgsnemu: created "pinghost" and "createif" modes for mutual ...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Viktor Tsymbalyuk gerrit-no-reply at lists.osmocom.org
Tue Jan 30 13:47:51 UTC 2018


Review at  https://gerrit.osmocom.org/6196

sgsnemu: created "pinghost" and "createif" modes for mutual exclusion

No warnings when used options from "pinghost" and "createif" groups
in a same time. sgsnemu created tun0 interface and send pings inside
G-PDU, but didn't calculate replys. Added options modes to avoid
mutual exclusion options.

Change-Id: I196df7838212dcddecd64a64a6cba613b6cfced0
---
M sgsnemu/cmdline.c
M sgsnemu/cmdline.ggo
M sgsnemu/cmdline.h
3 files changed, 97 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/96/6196/1

diff --git a/sgsnemu/cmdline.c b/sgsnemu/cmdline.c
index 1c02baa..412e484 100644
--- a/sgsnemu/cmdline.c
+++ b/sgsnemu/cmdline.c
@@ -65,12 +65,14 @@
 	"      --charging=INT            Charging characteristics  (default=`0x0800')",
 	"  -u, --uid=STRING              Login user ID  (default=`mig')",
 	"  -p, --pwd=STRING              Login password  (default=`hemmelig')",
+	"\n Mode: createif\n  any option of this mode is related to tun interface, all payload going in and\n  out  via tunN interface",
 	"      --createif                Create local network interface  (default=off)",
 	"  -n, --net=STRING              Network address for local interface",
 	"      --defaultroute            Create default route  (default=off)",
 	"      --ipup=STRING             Script to run after link-up",
 	"      --ipdown=STRING           Script to run after link-down",
 	"      --tun-device=STRING       Name of the local network interface",
+	"\n Mode: pinghost\n  generate ICMP payload inside G-PDU without setting up tun interface",
 	"      --pinghost=STRING         Ping remote host",
 	"      --pingrate=INT            Number of ping req per second  (default=`1')",
 	"      --pingsize=INT            Number of ping data bytes  (default=`56')",
@@ -168,6 +170,8 @@
 	args_info->pingquiet_given = 0;
 	args_info->no_tx_gpdu_seq_given = 0;
 	args_info->pdp_type_given = 0;
+	args_info->createif_mode_counter = 0;
+	args_info->pinghost_mode_counter = 0;
 }
 
 static
@@ -290,19 +294,19 @@
 	args_info->charging_help = gengetopt_args_info_help[28];
 	args_info->uid_help = gengetopt_args_info_help[29];
 	args_info->pwd_help = gengetopt_args_info_help[30];
-	args_info->createif_help = gengetopt_args_info_help[31];
-	args_info->net_help = gengetopt_args_info_help[32];
-	args_info->defaultroute_help = gengetopt_args_info_help[33];
-	args_info->ipup_help = gengetopt_args_info_help[34];
-	args_info->ipdown_help = gengetopt_args_info_help[35];
-	args_info->tun_device_help = gengetopt_args_info_help[36];
-	args_info->pinghost_help = gengetopt_args_info_help[37];
-	args_info->pingrate_help = gengetopt_args_info_help[38];
-	args_info->pingsize_help = gengetopt_args_info_help[39];
-	args_info->pingcount_help = gengetopt_args_info_help[40];
-	args_info->pingquiet_help = gengetopt_args_info_help[41];
-	args_info->no_tx_gpdu_seq_help = gengetopt_args_info_help[42];
-	args_info->pdp_type_help = gengetopt_args_info_help[43];
+	args_info->createif_help = gengetopt_args_info_help[32];
+	args_info->net_help = gengetopt_args_info_help[33];
+	args_info->defaultroute_help = gengetopt_args_info_help[34];
+	args_info->ipup_help = gengetopt_args_info_help[35];
+	args_info->ipdown_help = gengetopt_args_info_help[36];
+	args_info->tun_device_help = gengetopt_args_info_help[37];
+	args_info->pinghost_help = gengetopt_args_info_help[39];
+	args_info->pingrate_help = gengetopt_args_info_help[40];
+	args_info->pingsize_help = gengetopt_args_info_help[41];
+	args_info->pingcount_help = gengetopt_args_info_help[42];
+	args_info->pingquiet_help = gengetopt_args_info_help[43];
+	args_info->no_tx_gpdu_seq_help = gengetopt_args_info_help[44];
+	args_info->pdp_type_help = gengetopt_args_info_help[45];
 
 }
 
@@ -361,8 +365,7 @@
 
 struct cmdline_parser_params *cmdline_parser_params_create(void)
 {
-	struct cmdline_parser_params *params =
-	    (struct cmdline_parser_params *)
+	struct cmdline_parser_params *params = (struct cmdline_parser_params *)
 	    malloc(sizeof(struct cmdline_parser_params));
 	cmdline_parser_params_init(params);
 	return params;
@@ -853,6 +856,30 @@
 	return 0;		/* OK */
 }
 
+static int check_modes(int given1[], const char *options1[],
+		       int given2[], const char *options2[])
+{
+	int i = 0, j = 0, errors = 0;
+
+	while (given1[i] >= 0) {
+		if (given1[i]) {
+			while (given2[j] >= 0) {
+				if (given2[j]) {
+					++errors;
+					fprintf(stderr,
+						"%s: option %s conflicts with option %s\n",
+						package_name, options1[i],
+						options2[j]);
+				}
+				++j;
+			}
+		}
+		++i;
+	}
+
+	return errors;
+}
+
 int
 cmdline_parser_internal(int argc, char **argv,
 			struct gengetopt_args_info *args_info,
@@ -1073,6 +1100,7 @@
 
 			break;
 		case 'n':	/* Network address for local interface.  */
+			args_info->createif_mode_counter += 1;
 
 			if (update_arg((void *)&(args_info->net_arg),
 				       &(args_info->net_orig),
@@ -1391,6 +1419,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "createif") == 0) {
+				args_info->createif_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->createif_flag), 0,
@@ -1405,6 +1434,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "defaultroute") == 0) {
+				args_info->createif_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->defaultroute_flag), 0,
@@ -1419,6 +1449,7 @@
 			/* Script to run after link-up.  */
 			else if (strcmp(long_options[option_index].name, "ipup")
 				 == 0) {
+				args_info->createif_mode_counter += 1;
 
 				if (update_arg((void *)&(args_info->ipup_arg),
 					       &(args_info->ipup_orig),
@@ -1434,6 +1465,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "ipdown") == 0) {
+				args_info->createif_mode_counter += 1;
 
 				if (update_arg((void *)&(args_info->ipdown_arg),
 					       &(args_info->ipdown_orig),
@@ -1449,6 +1481,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "tun-device") == 0) {
+				args_info->createif_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->tun_device_arg),
@@ -1465,6 +1498,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "pinghost") == 0) {
+				args_info->pinghost_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->pinghost_arg),
@@ -1481,6 +1515,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "pingrate") == 0) {
+				args_info->pinghost_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->pingrate_arg),
@@ -1496,6 +1531,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "pingsize") == 0) {
+				args_info->pinghost_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->pingsize_arg),
@@ -1512,6 +1548,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "pingcount") == 0) {
+				args_info->pinghost_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->pingcount_arg),
@@ -1527,6 +1564,7 @@
 			else if (strcmp
 				 (long_options[option_index].name,
 				  "pingquiet") == 0) {
+				args_info->pinghost_mode_counter += 1;
 
 				if (update_arg
 				    ((void *)&(args_info->pingquiet_flag), 0,
@@ -1566,6 +1604,31 @@
 		}		/* switch */
 	}			/* while */
 
+	if (args_info->createif_mode_counter
+	    && args_info->pinghost_mode_counter) {
+		int createif_given[] =
+		    { args_info->createif_given, args_info->net_given,
+			args_info->defaultroute_given, args_info->ipup_given,
+			args_info->ipdown_given, args_info->tun_device_given, -1
+		};
+		const char *createif_desc[] =
+		    { "--createif", "--net", "--defaultroute", "--ipup",
+			"--ipdown", "--tun-device", 0
+		};
+		int pinghost_given[] =
+		    { args_info->pinghost_given, args_info->pingrate_given,
+			args_info->pingsize_given, args_info->pingcount_given,
+			args_info->pingquiet_given, -1
+		};
+		const char *pinghost_desc[] =
+		    { "--pinghost", "--pingrate", "--pingsize", "--pingcount",
+			"--pingquiet", 0
+		};
+		error_occurred +=
+		    check_modes(createif_given, createif_desc, pinghost_given,
+				pinghost_desc);
+	}
+
 	if (check_required) {
 		error_occurred +=
 		    cmdline_parser_required2(args_info, argv[0],
diff --git a/sgsnemu/cmdline.ggo b/sgsnemu/cmdline.ggo
index 8136d3a..dec19cd 100644
--- a/sgsnemu/cmdline.ggo
+++ b/sgsnemu/cmdline.ggo
@@ -15,6 +15,10 @@
 
 package "sgsnemu"
 
+defmode "createif"  modedesc="any option of this mode is related to tun interface, \
+all payload going in and out  via tunN interface"
+defmode "pinghost"  modedesc="generate ICMP payload inside G-PDU without setting up tun interface"
+
 option  "debug"        d "Run in debug mode"              flag   off
 
 option  "conf"         c "Read configuration file"        string no
@@ -49,18 +53,18 @@
 option  "uid"          u "Login user ID"                  string default="mig" no
 option  "pwd"          p "Login password"                 string default="hemmelig" no
 
-option  "createif"     - "Create local network interface" flag   off
-option  "net"          n "Network address for local interface" string dependon="createif" no
-option  "defaultroute" - "Create default route"           flag   dependon="createif" off
-option  "ipup"         - "Script to run after link-up"    string dependon="createif" no
-option  "ipdown"       - "Script to run after link-down"  string dependon="createif" no
-option  "tun-device"   - "Name of the local network interface" string dependon="createif" no
+modeoption   "createif"     - "Create local network interface" flag   off                           mode="createif"
+modeoption   "net"          n "Network address for local interface" string dependon="createif" no   mode="createif"
+modeoption   "defaultroute" - "Create default route"           flag   dependon="createif" off       mode="createif"
+modeoption   "ipup"         - "Script to run after link-up"    string dependon="createif" no        mode="createif"
+modeoption   "ipdown"       - "Script to run after link-down"  string dependon="createif" no        mode="createif"
+modeoption   "tun-device"   - "Name of the local network interface" string dependon="createif" no   mode="createif"
 
-option  "pinghost"     - "Ping remote host"               string no
-option  "pingrate"     - "Number of ping req per second"  int default="1" dependon="pinghost" no
-option  "pingsize"     - "Number of ping data bytes"      int default="56" dependon="pinghost" no
-option  "pingcount"    - "Number of ping req to send"     int default="0" dependon="pinghost" no
-option  "pingquiet"    - "Do not print ping packet info"  flag dependon="pinghost" off
+modeoption   "pinghost"     - "Ping remote host"               string no                                mode="pinghost"
+modeoption   "pingrate"     - "Number of ping req per second"  int default="1" dependon="pinghost" no   mode="pinghost"
+modeoption   "pingsize"     - "Number of ping data bytes"      int default="56" dependon="pinghost" no  mode="pinghost"
+modeoption   "pingcount"    - "Number of ping req to send"     int default="0" dependon="pinghost" no   mode="pinghost"
+modeoption   "pingquiet"    - "Do not print ping packet info"  flag dependon="pinghost" off             mode="pinghost"
 
 option  "no-tx-gpdu-seq" - "Don't transmit G-PDU sequence nums"   flag    off
 option  "pdp-type"     t "PDP Type"                       string default="v4" no typestr="(v4|v6)"
diff --git a/sgsnemu/cmdline.h b/sgsnemu/cmdline.h
index 9dc210e..31a2085 100644
--- a/sgsnemu/cmdline.h
+++ b/sgsnemu/cmdline.h
@@ -370,6 +370,10 @@
 		unsigned int pdp_type_given;
 				/**< @brief Whether pdp-type was given.  */
 
+		int createif_mode_counter;
+			     /**< @brief Counter for mode createif */
+		int pinghost_mode_counter;
+			     /**< @brief Counter for mode pinghost */
 	};
 
 /** @brief The additional parameters to pass to parser functions */

-- 
To view, visit https://gerrit.osmocom.org/6196
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I196df7838212dcddecd64a64a6cba613b6cfced0
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Viktor Tsymbalyuk <viktor.tsymbalyuk at gmail.com>



More information about the gerrit-log mailing list