3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #define ENSC_WRAPPERS_PREFIX "vcontext: "
32 #define CMD_HELP 0x1000
33 #define CMD_VERSION 0x1001
34 #define CMD_NID 0x4000
35 #define CMD_CREATE 0x4001
36 #define CMD_MIGRATE 0x4003
37 #define CMD_SILENT 0x4007
38 #define CMD_SILENTEXIST 0x400c
42 { "help", no_argument, 0, CMD_HELP },
43 { "version", no_argument, 0, CMD_VERSION },
44 { "nid", required_argument, 0, CMD_NID },
45 { "create", no_argument, 0, CMD_CREATE },
46 { "migrate", required_argument, 0, CMD_MIGRATE },
47 { "silent", no_argument, 0, CMD_SILENT },
48 { "silentexist", no_argument, 0, CMD_SILENTEXIST },
60 int wrapper_exit_code = 255;
63 showHelp(char const *cmd)
65 WRITE_MSG(1, "Usage:\n ");
68 " --create <opts>* [--] <program> <args>*\n ");
71 " --migrate <opts>* [--] <program> <args>*\n");
74 " --add|--del <ip>/[<prefix>|<mask>] <opts>* [--] <program> <args>*\n");
77 " (--flag <flags>*)|(--caps <caps>*) <opts>* [--] <program> <args>*\n"
80 " --nid <nid> ... operate on network context <nid>; in combination\n"
81 " with '--create' the network context <nid> instead of\n"
82 " a dynamic one will be created, and with '--migrate\n"
83 " the context <nid> instead of the current one will\n"
85 " --silent ... be silent\n"
86 " --silentexist ... be silent when context exists already; usefully\n"
87 " for '--create' only\n"
89 "'vnet --create' exits with code 254 iff the context exists already.\n"
91 "Please report bugs to " PACKAGE_BUGREPORT "\n");
101 "vnet " VERSION " -- manages the creation of network contexts\n"
102 "This program is part of " PACKAGE_STRING "\n\n"
103 "Copyright (C) 2004 Enrico Scholz\n"
104 VERSION_COPYRIGHT_DISCLAIMER);
108 static inline ALWAYSINLINE int
109 doit(struct Arguments const *args, char *argv[])
113 if (args->do_create) {
114 nid = vc_net_create_context(args->nid);
118 if (!args->is_silentexist)
119 perror(ENSC_WRAPPERS_PREFIX "vc_net_create_context()");
122 perror(ENSC_WRAPPERS_PREFIX "vc_net_create_context()");
123 return wrapper_exit_code;
126 tellContext(nid, args->verbosity>=1);
135 int main (int argc, char *argv[])
137 struct Arguments args = {
140 .is_silentexist = false,
142 .nid = VC_DYNAMIC_NID,
146 int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
150 case CMD_HELP : showHelp(1, argv[0], 0);
151 case CMD_VERSION : showVersion();
152 case CMD_NID : args.nid = optarg(nid); break;
153 case CMD_CREATE : args.do_create = true; break;
154 case CMD_MIGRATE : args.do_migrate = true; break;
155 case CMD_SILENTEXIST : args.is_silentexist = true; break;
156 case CMD_SILENT : --args.verbosity; break;
159 WRITE_MSG(2, "Try '");
160 WRITE_STR(2, argv[0]);
161 WRITE_MSG(2, " --help\" for more information.\n");
167 if (args.nid==VC_DYNAMIC_NID && args.do_migrate)
168 args.nid = Evc_get_task_nid(0);
170 if (!args.do_create && !args.do_migrate)
171 WRITE_MSG(2, "Neither '--create' nor '--migrate specified; try '--help' for more information\n");
172 else if (args.do_create && args.do_migrate)
173 WRITE_MSG(2, "Can not specify '--create' and '--migrate' at the same time; try '--help' for more information\n");
174 else if (!args.do_create && args.nid==VC_DYNAMIC_NID)
175 WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "Can not migrate to an unknown context\n");
176 else if (optind>=argc)
177 WRITE_MSG(2, "No command given; use '--help' for more information.\n");
179 return doit(&args, argv);