--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2007-2008 Daniel Hokka Zakrisson
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef _ATTRIBUTE_UTIL_H
+#define _ATTRIBUTE_UTIL_H
+
+static inline int
+ffsull(unsigned long long word)
+{
+ int bit;
+ for (bit = 0; bit < 64; bit++) {
+ if (word & (1ULL << bit))
+ break;
+ }
+ if (bit == 64)
+ bit = 0;
+ return bit;
+}
+
+#define print_bitfield(fd, type, name, var) \
+ do { \
+ int first; \
+ WRITE_MSG(fd, name ":\n"); \
+ first = 1; \
+ while (1) { \
+ char const *i; \
+ i = vc_lo ## type ## 2text(var); \
+ if (!i) \
+ break; \
+ if (!first) \
+ WRITE_MSG(fd, ","); \
+ else \
+ first = 0; \
+ WRITE_STR(fd, i); \
+ } \
+ while (*(var)) { \
+ int bit = ffsull(*(var)); \
+ if (!bit) \
+ break; \
+ if (!first) \
+ WRITE_MSG(fd, ","); \
+ else \
+ first = 0; \
+ WRITE_MSG(fd, "^"); \
+ WRITE_INT(fd, bit); \
+ *(var) &= ~(1ULL << bit); \
+ } \
+ WRITE_MSG(fd, "\n"); \
+ } while (0)
+
+#endif
#endif
#include "util.h"
+#include "attribute-util.h"
#include <lib/vserver.h>
#include <getopt.h>
#define CMD_CAP 0x2002
#define CMD_FLAG 0x2003
#define CMD_SECURE 0x2004
+#define CMD_GET 0x2005
int wrapper_exit_code = 1;
{ "ncap", required_argument, 0, CMD_CAP },
{ "flag", required_argument, 0, CMD_FLAG },
{ "secure", no_argument, 0, CMD_SECURE },
+ { "get", no_argument, 0, CMD_GET },
{0,0,0,0}
};
struct Arguments {
+ int mode;
nid_t nid;
- struct vc_net_flags flags;
- struct vc_net_caps caps;
+ struct vc_net_flags flags;
+ struct vc_net_caps caps;
};
static void
WRITE_MSG(fd, "Usage:\n ");
WRITE_STR(fd, cmd);
WRITE_MSG(fd,
- " --set [--nid <nid>] [--ncap [~!]<ncap>] [--flag [~!]<flag>] [--secure] -- [<program> <args>*]\n"
+ " {--set|--get} [--nid <nid>] [--ncap [~!]<ncap>] [--flag [~!]<flag>] [--secure] --\n"
+ " [<program> <args>*]\n"
"\n"
" --ncap <cap> ... network capability to be added\n"
" --flag <flag> ... network flag to be added\n"
showVersion()
{
WRITE_MSG(1,
- "nattribute " VERSION " -- sets attributes of network contexts\n"
+ "nattribute " VERSION " -- sets/gets attributes of network contexts\n"
"This program is part of " PACKAGE_STRING "\n\n"
"Copyright (C) 2004 Enrico Scholz\n"
"Copyright (C) 2006 Daniel Hokka Zakrisson\n"
flags->mask = VC_NXF_HIDE_NETIF;
}
+static int
+printAttrs(struct Arguments *args)
+{
+ struct vc_net_flags flags;
+ struct vc_net_caps caps;
+
+ Evc_get_nflags(args->nid, &flags);
+ Evc_get_ncaps(args->nid, &caps);
+
+ print_bitfield(1, ncap, "ncapabilities", &caps.ncaps);
+ print_bitfield(1, nflag, "nflags", &flags.flagword);
+
+ return 0;
+}
+
int main(int argc, char *argv[])
{
struct Arguments args = {
+ .mode = CMD_SET,
.nid = VC_NOCTX,
.flags = { .flagword = 0, .mask = 0 },
.caps = { .ncaps = 0, .cmask = 0 },
switch (c) {
case CMD_HELP : showHelp(1, argv[0], 0);
case CMD_VERSION : showVersion();
- case CMD_SET : break; // default op currently
+ case CMD_SET : args.mode = CMD_SET; break;
+ case CMD_GET : args.mode = CMD_GET; break;
case CMD_NID : args.nid = Evc_nidopt2nid(optarg,true); break;
case CMD_FLAG : parseFlags(optarg, &args.flags); break;
case CMD_CAP : parseNCaps(optarg, &args.caps); break;
if (args.nid==VC_NOCTX) args.nid = Evc_get_task_nid(0);
- if (args.caps.cmask &&
- vc_set_ncaps(args.nid, &args.caps)==-1)
- perror(ENSC_WRAPPERS_PREFIX "vc_set_ncaps()");
- else if (args.flags.mask &&
- vc_set_nflags(args.nid, &args.flags)==-1)
- perror(ENSC_WRAPPERS_PREFIX "vc_set_nflags()");
- else if (optind<argc)
- EexecvpD(argv[optind], argv+optind);
- else
- return EXIT_SUCCESS;
+ if (args.mode == CMD_SET) {
+ if (args.caps.cmask &&
+ vc_set_ncaps(args.nid, &args.caps)==-1)
+ perror(ENSC_WRAPPERS_PREFIX "vc_set_ncaps()");
+ else if (args.flags.mask &&
+ vc_set_nflags(args.nid, &args.flags)==-1)
+ perror(ENSC_WRAPPERS_PREFIX "vc_set_nflags()");
+ else if (optind<argc)
+ EexecvpD(argv[optind], argv+optind);
+ else
+ return EXIT_SUCCESS;
+ }
+ else if (args.mode == CMD_GET) {
+ printAttrs(&args);
+ if (optind<argc)
+ EexecvpD(argv[optind], argv+optind);
+ else
+ return EXIT_SUCCESS;
+ }
return EXIT_FAILURE;
}
#endif
#include "util.h"
+#include "attribute-util.h"
#include <lib/vserver.h>
#include <getopt.h>
flags->mask = VC_VXF_HIDE_NETIF;
}
-static inline int
-ffsull(unsigned long long word)
-{
- int bit;
- for (bit = 0; bit < 64; bit++) {
- if (word & (1ULL << bit))
- break;
- }
- if (bit == 64)
- bit = 0;
- return bit;
-}
-
static int
printAttrs(struct Arguments *args)
{
Evc_get_cflags(args->xid, &flags);
Evc_get_ccaps(args->xid, &caps);
-#define PRINT_VALUES(type, name, var) \
- WRITE_MSG(1, name ":\n"); \
- first = 1; \
- while (1) { \
- char const *i; \
- i = vc_lo ## type ## 2text(var); \
- if (!i) \
- break; \
- if (!first) \
- WRITE_MSG(1, ","); \
- else \
- first = 0; \
- WRITE_STR(1, i); \
- } \
- while (*(var)) { \
- int bit = ffsull(*(var)); \
- if (!bit) \
- break; \
- if (!first) \
- WRITE_MSG(1, ","); \
- else \
- first = 0; \
- WRITE_MSG(1, "^"); \
- WRITE_INT(1, bit); \
- *(var) &= ~(1ULL << bit); \
- } \
- WRITE_MSG(1, "\n");
-
- PRINT_VALUES(bcap, "bcapabilities", &caps.bcaps);
- PRINT_VALUES(ccap, "ccapabilities", &caps.ccaps);
- PRINT_VALUES(cflag, "flags", &flags.flagword);
+ print_bitfield(1, bcap, "bcapabilities", &caps.bcaps);
+ print_bitfield(1, ccap, "ccapabilities", &caps.ccaps);
+ print_bitfield(1, cflag, "flags", &flags.flagword);
return 0;
}