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
This commit is contained in:
parent
dddbbaaee1
commit
ab4db10750
|
@ -65,12 +65,14 @@ const char *gengetopt_args_info_help[] = {
|
|||
" --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 @@ void clear_given(struct gengetopt_args_info *args_info)
|
|||
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 @@ void init_args_info(struct gengetopt_args_info *args_info)
|
|||
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 @@ void cmdline_parser_params_init(struct cmdline_parser_params *params)
|
|||
|
||||
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 @@ int update_arg(void *field, char **orig_field,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
|
||||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
/* 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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
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 @@ cmdline_parser_internal(int argc, char **argv,
|
|||
} /* 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],
|
||||
|
|
|
@ -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 "charging" - "Charging characteristics" int default="0x0800
|
|||
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)"
|
||||
|
|
|
@ -370,6 +370,10 @@ extern "C" {
|
|||
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 */
|
||||
|
|
Loading…
Reference in New Issue