#endif
#if 1
-# define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? 0 : \
- (X)==vcNET_IPV6 ? 1 : \
- (X)==vcNET_IPV4R ? 2 : \
- (X)==vcNET_IPV6R ? 3 : \
+# define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? NXA_TYPE_IPV4 : \
+ (X)==vcNET_IPV6 ? NXA_TYPE_IPV6 : \
+ (X)==vcNET_IPV4B ? (NXA_TYPE_IPV4 | NXA_MOD_BCAST) : \
+ (X)==vcNET_ANY ? NXA_TYPE_ANY : \
+ (X))
+# define NETTYPE_KERNEL2USER(X) ((X)==NXA_TYPE_IPV4 ? vcNET_IPV4 : \
+ (X)==NXA_TYPE_IPV6 ? vcNET_IPV6 : \
+ (X)==(NXA_TYPE_IPV4|NXA_MOD_BCAST) ? vcNET_IPV4B : \
+ (X)==NXA_TYPE_ANY ? vcNET_ANY : \
(X))
-# define NETTYPE_KERNEL2USER(X) ((X)==0 ? vcNET_IPV4 ? : \
- (X)==1 ? vcNET_IPV6 ? : \
- (X)==2 ? vcNET_IPV4R ? : \
- (X)==3 ? vcNET_IPV6R ? : \
- (vc_net_nx_type)(X))
#else
# define NETTYPE_USER2KERNEL(X) (X)
# define NETTYPE_KERNEL2USER(X) (X)
#include "vserver.h"
#include "util.h"
+#include <lib/internal.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ENSC_WRAPPERS_PREFIX "chbind: "
#define ENSC_WRAPPERS_IO 1
#define ENSC_WRAPPERS_UNISTD 1
+#define ENSC_WRAPPERS_VSERVER 1
#include "wrappers.h"
#define CMD_HELP 0x1000
#define CMD_SILENT 0x2000
#define CMD_IP 0x2001
#define CMD_BCAST 0x2002
+#define CMD_NID 0x2003
int wrapper_exit_code = 255;
{ "silent", no_argument, 0, CMD_SILENT },
{ "ip", required_argument, 0, CMD_IP },
{ "bcast", required_argument, 0, CMD_BCAST },
+ { "nid", required_argument, 0, CMD_NID },
{ 0,0,0,0 }
};
WRITE_MSG(fd, "Usage:\n ");
WRITE_STR(fd, cmd);
WRITE_MSG(fd,
- " [--silent] [--ip <ip_num>[/<mask>]] [--bcast <broadcast>] [--] <commands> <args>*\n\n"
+ " [--silent] [--nid <nid>] [--ip <ip_num>[/<mask>]] [--bcast <broadcast>] [--] <commands> <args>*\n\n"
"Please report bugs to " PACKAGE_BUGREPORT "\n");
exit(res);
}
}
+#if defined(VC_ENABLE_API_NET)
+static void
+make_nx(nid_t nid, uint32_t bcast, size_t nbaddrs, struct vc_ip_mask_pair *ips)
+{
+ size_t i;
+ struct vc_net_nx addr;
+
+ if (nid == VC_DYNAMIC_NID) {
+ nid = vc_net_create(VC_DYNAMIC_NID);
+ if (nid == (nid_t) -1) {
+ perror("chbind: vc_net_create()");
+ exit(wrapper_exit_code);
+ }
+ }
+ else {
+ if (vc_net_create(nid) == (nid_t) -1) {
+ if (errno == EEXIST) {
+ if (vc_net_migrate(nid) != 0) {
+ perror("chbind: vc_net_migrate()");
+ exit(wrapper_exit_code);
+ }
+ else
+ return;
+ }
+ else {
+ perror("chbind: vc_net_create()");
+ exit(wrapper_exit_code);
+ }
+ }
+ }
+
+ addr.type = vcNET_IPV4B;
+ addr.count = 1;
+ addr.ip[0] = bcast;
+ addr.mask[0] = 0;
+
+ if (vc_net_add(nid, &addr) != 1) {
+ perror("chbind: vc_net_add()");
+ exit(wrapper_exit_code);
+ }
+
+ for (i = 0; i < nbaddrs; i++) {
+ addr.type = vcNET_IPV4;
+ addr.count = 1;
+ addr.ip[0] = ips[i].ip;
+ addr.mask[0] = ips[i].mask;
+
+ if (vc_net_add(nid, &addr) != 1) {
+ perror("chbind: vc_net_add()");
+ exit(wrapper_exit_code);
+ }
+ }
+}
+#endif
+
int main (int argc, char *argv[])
{
size_t const nb_ipv4root = vc_get_nb_ipv4root();
struct vc_ip_mask_pair ips[nb_ipv4root];
size_t nbaddrs = 0;
uint32_t bcast = 0xffffffff;
+ nid_t nid = VC_DYNAMIC_NID;
while (1) {
int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
case CMD_VERSION : showVersion();
case CMD_SILENT : is_silent = true; break;
case CMD_BCAST : readBcast(optarg, &bcast); break;
+#if defined(VC_ENABLE_API_NET)
+ case CMD_NID : nid = Evc_xidopt2xid(optarg,true); break;
+#else
+ case CMD_NID : WRITE_MSG(2, "WARNING: --nid is not supported by this version\n"); break;
+#endif
case CMD_IP :
if (nbaddrs>=nb_ipv4root) {
WRITE_MSG(2, "Too many IP numbers, max 16\n");
}
+#if defined(VC_ENABLE_API_NET)
+ if (vc_isSupported(vcFEATURE_VNET)) {
+ make_nx(nid, bcast, nbaddrs, ips);
+ }
+ else
+#endif
if (vc_set_ipv4root(bcast,nbaddrs,ips)!=0) {
perror("chbind: vc_set_ipv4root()");
exit(wrapper_exit_code);