xhyve-ruby 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubygems_plugin.rb +7 -0
- data/lib/xhyve.rb +0 -1
- data/lib/xhyve/guest.rb +29 -11
- data/lib/xhyve/vendor/xhyve +0 -0
- data/lib/xhyve/version.rb +1 -1
- metadata +3 -21
- data/ext/vmnet/extconf.rb +0 -9
- data/ext/vmnet/uuid.h +0 -153
- data/ext/vmnet/vmnet.c +0 -146
- data/lib/xhyve/vmnet/vmnet.bundle +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39b350054bcc76d6bb4069ece51fb1754af1ca15
|
4
|
+
data.tar.gz: da559becc2b5ea86ffef4144d930e8c627df8380
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccf4a15f9a25a23ba835a352f59b709695684d401e67485a86cd25d373f0ce4b6d576315b1727e1c7c44cbf6b49af70563e8e7eb60a6590ea1e283be73f25b4a
|
7
|
+
data.tar.gz: 0cb1070d717ce4792252ba65eece64a63deb53124efa52de3daf3d144c742e2fd9ca8d80767ec8ef0cc634edd11cb084dce917569d74d3202455566e65f250df
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Gem.post_install do
|
2
|
+
if Gem::Platform.local.os =~ /darwin/
|
3
|
+
# Required until https://github.com/mist64/xhyve/issues/60 is resolved
|
4
|
+
bin = File.expand_path('../xhyve/vendor/xhyve', __FILE__)
|
5
|
+
`/usr/bin/osascript -e 'do shell script "chown root #{bin} && chmod +s #{bin}" with administrator privileges'`
|
6
|
+
end
|
7
|
+
end
|
data/lib/xhyve.rb
CHANGED
data/lib/xhyve/guest.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require '
|
2
|
+
require 'io/console'
|
3
3
|
|
4
4
|
require 'xhyve/dhcp'
|
5
5
|
|
@@ -11,6 +11,7 @@ module Xhyve
|
|
11
11
|
# object oriented interface to a hypervisor guest
|
12
12
|
class Guest
|
13
13
|
PCI_BASE = 3
|
14
|
+
NULLDEV = '/dev/null'
|
14
15
|
|
15
16
|
attr_reader :pid, :uuid, :mac
|
16
17
|
|
@@ -24,13 +25,21 @@ module Xhyve
|
|
24
25
|
@uuid = opts[:uuid] || SecureRandom.uuid
|
25
26
|
@serial = opts[:serial] || 'com1'
|
26
27
|
@acpi = opts[:acpi] || true
|
27
|
-
@
|
28
|
+
@networking = opts[:networking] || true
|
29
|
+
@foreground = opts[:foreground] || false
|
28
30
|
@command = build_command
|
29
|
-
@mac =
|
31
|
+
@mac = find_mac
|
30
32
|
end
|
31
33
|
|
32
34
|
def start
|
33
|
-
|
35
|
+
outfile, infile = redirection
|
36
|
+
@pid = spawn(@command, [:out, :err] => outfile, in: infile)
|
37
|
+
if @foreground
|
38
|
+
Process.wait(@pid)
|
39
|
+
outfile.cooked!
|
40
|
+
infile.cooked!
|
41
|
+
end
|
42
|
+
@pid
|
34
43
|
end
|
35
44
|
|
36
45
|
def stop
|
@@ -38,7 +47,7 @@ module Xhyve
|
|
38
47
|
end
|
39
48
|
|
40
49
|
def running?
|
41
|
-
|
50
|
+
(true if Process.kill(0, @pid) rescue false)
|
42
51
|
end
|
43
52
|
|
44
53
|
def ip
|
@@ -47,23 +56,32 @@ module Xhyve
|
|
47
56
|
|
48
57
|
private
|
49
58
|
|
59
|
+
def redirection
|
60
|
+
if @foreground
|
61
|
+
[$stdout.raw!, $stdin.raw! ]
|
62
|
+
else
|
63
|
+
[NULLDEV, NULLDEV]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_mac
|
68
|
+
`#{@command} -M`.gsub(/MAC:\s+/,'')
|
69
|
+
end
|
70
|
+
|
50
71
|
def build_command
|
51
72
|
[
|
52
|
-
"#{'sudo' if @sudo}",
|
53
73
|
"#{BINARY_PATH}",
|
54
74
|
"#{'-A' if @acpi}",
|
55
75
|
'-U', @uuid,
|
56
76
|
'-m', @memory,
|
57
77
|
'-c', @processors,
|
58
78
|
'-s', '0:0,hostbridge',
|
79
|
+
"#{"-s #{PCI_BASE - 1}:0,virtio-net" if @networking }" ,
|
80
|
+
"#{"#{@blockdevs.each_with_index.map { |p, i| "-s #{PCI_BASE + i},virtio-blk,#{p}" }.join(' ')}" unless @blockdevs.empty? }",
|
59
81
|
'-s', '31,lpc',
|
60
82
|
'-l', "#{@serial},stdio",
|
61
|
-
'-s', "#{PCI_BASE - 1}:0,virtio-net",
|
62
|
-
"#{"#{@blockdevs.each_with_index.map { |p, i| "-s #{PCI_BASE + i},virtio-blk,#{p}" }.join(' ')}" unless @blockdevs.empty? }",
|
63
83
|
'-f' "kexec,#{@kernel},#{@initrd},'#{@cmdline}'"
|
64
|
-
].
|
84
|
+
].join(' ')
|
65
85
|
end
|
66
86
|
end
|
67
|
-
|
68
|
-
# ./build/xhyve -U $UUID -m ${MEM}G -c ${PROCS} -s 2:0,virtio-net -s 0:0,hostbridge -s 31,lpc -l com2,stdio -A -f kexec,/Volumes/CDROM\ 1/BOOT/VMLINUZ,/Volumes/CDROM\ 1/BOOT/INITRD,"boot=live root=/dev/ram0 live-media=initramfs earlyprintk=serial console=ttyS1,115200 net.ifnames=0 biosdevname=0"
|
69
87
|
end
|
data/lib/xhyve/vendor/xhyve
CHANGED
Binary file
|
data/lib/xhyve/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xhyve-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Hamel
|
@@ -94,36 +94,18 @@ dependencies:
|
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.9.5
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: childprocess
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.5.8
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.5.8
|
111
97
|
description: Provides a means of interacting with xhyve from ruby
|
112
98
|
email: dale.hamel@srvthe.net
|
113
99
|
executables: []
|
114
|
-
extensions:
|
115
|
-
- ext/vmnet/extconf.rb
|
100
|
+
extensions: []
|
116
101
|
extra_rdoc_files: []
|
117
102
|
files:
|
118
|
-
-
|
119
|
-
- ext/vmnet/uuid.h
|
120
|
-
- ext/vmnet/vmnet.c
|
103
|
+
- lib/rubygems_plugin.rb
|
121
104
|
- lib/xhyve.rb
|
122
105
|
- lib/xhyve/dhcp.rb
|
123
106
|
- lib/xhyve/guest.rb
|
124
107
|
- lib/xhyve/vendor/xhyve
|
125
108
|
- lib/xhyve/version.rb
|
126
|
-
- lib/xhyve/vmnet/vmnet.bundle
|
127
109
|
homepage: http://rubygems.org/gems/ruby-xhyve
|
128
110
|
licenses:
|
129
111
|
- MIT
|
data/ext/vmnet/extconf.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'mkmf'
|
2
|
-
require 'rbconfig'
|
3
|
-
|
4
|
-
abort 'Only works on OS X' unless RbConfig::CONFIG['host_os'].downcase.include?('darwin')
|
5
|
-
abort 'missing vmnet.h' unless have_header 'uuid.h'
|
6
|
-
abort 'missing vmnet.h' unless have_header 'vmnet/vmnet.h'
|
7
|
-
abort 'missing vmnet' unless have_framework 'vmnet'
|
8
|
-
|
9
|
-
create_makefile 'vmnet/vmnet'
|
data/ext/vmnet/uuid.h
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
/*-
|
2
|
-
* Copyright (c) 2002,2005 Marcel Moolenaar
|
3
|
-
* Copyright (c) 2002 Hiten Mahesh Pandya
|
4
|
-
* All rights reserved.
|
5
|
-
*
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
7
|
-
* modification, are permitted provided that the following conditions
|
8
|
-
* are met:
|
9
|
-
* 1. Redistributions of source code must retain the above copyright
|
10
|
-
* notice, this list of conditions and the following disclaimer.
|
11
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in the
|
13
|
-
* documentation and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
16
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
19
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
21
|
-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
22
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
23
|
-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
24
|
-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
25
|
-
* SUCH DAMAGE.
|
26
|
-
*
|
27
|
-
* $FreeBSD$
|
28
|
-
*/
|
29
|
-
|
30
|
-
#pragma once
|
31
|
-
|
32
|
-
#include <stdint.h>
|
33
|
-
#include <stdio.h>
|
34
|
-
#include <string.h>
|
35
|
-
|
36
|
-
#define _UUID_NODE_LEN 6
|
37
|
-
|
38
|
-
#pragma clang diagnostic push
|
39
|
-
#pragma clang diagnostic ignored "-Wpadded"
|
40
|
-
struct uuid {
|
41
|
-
uint32_t time_low;
|
42
|
-
uint16_t time_mid;
|
43
|
-
uint16_t time_hi_and_version;
|
44
|
-
uint8_t clock_seq_hi_and_reserved;
|
45
|
-
uint8_t clock_seq_low;
|
46
|
-
uint8_t node[_UUID_NODE_LEN];
|
47
|
-
};
|
48
|
-
#pragma clang diagnostic pop
|
49
|
-
|
50
|
-
typedef struct uuid uuid_internal_t;
|
51
|
-
|
52
|
-
/*
|
53
|
-
* This implementation mostly conforms to the DCE 1.1 specification.
|
54
|
-
* See Also:
|
55
|
-
* uuidgen(1), uuidgen(2), uuid(3)
|
56
|
-
*/
|
57
|
-
|
58
|
-
/* Status codes returned by the functions. */
|
59
|
-
#define uuid_s_ok 0
|
60
|
-
#define uuid_s_bad_version 1
|
61
|
-
#define uuid_s_invalid_string_uuid 2
|
62
|
-
#define uuid_s_no_memory 3
|
63
|
-
|
64
|
-
/*
|
65
|
-
* uuid_create_nil() - create a nil UUID.
|
66
|
-
* See also:
|
67
|
-
* http://www.opengroup.org/onlinepubs/009629399/uuid_create_nil.htm
|
68
|
-
*/
|
69
|
-
static inline void
|
70
|
-
uuid_create_nil(uuid_t *u, uint32_t *status)
|
71
|
-
{
|
72
|
-
if (status)
|
73
|
-
*status = uuid_s_ok;
|
74
|
-
|
75
|
-
bzero(u, sizeof(*u));
|
76
|
-
}
|
77
|
-
|
78
|
-
static inline void
|
79
|
-
uuid_enc_le(void *buf, uuid_t *uuid)
|
80
|
-
{
|
81
|
-
uuid_internal_t *u = (uuid_internal_t *) ((void *) uuid);
|
82
|
-
uint8_t *p = buf;
|
83
|
-
int i;
|
84
|
-
|
85
|
-
memcpy(p, &u->time_low, 4);
|
86
|
-
memcpy(p, &u->time_mid, 2);
|
87
|
-
memcpy(p, &u->time_hi_and_version, 2);
|
88
|
-
p[8] = u->clock_seq_hi_and_reserved;
|
89
|
-
p[9] = u->clock_seq_low;
|
90
|
-
for (i = 0; i < _UUID_NODE_LEN; i++)
|
91
|
-
p[10 + i] = u->node[i];
|
92
|
-
}
|
93
|
-
|
94
|
-
/*
|
95
|
-
* uuid_from_string() - convert a string representation of an UUID into
|
96
|
-
* a binary representation.
|
97
|
-
* See also:
|
98
|
-
* http://www.opengroup.org/onlinepubs/009629399/uuid_from_string.htm
|
99
|
-
*
|
100
|
-
* NOTE: The sequence field is in big-endian, while the time fields are in
|
101
|
-
* native byte order.
|
102
|
-
*/
|
103
|
-
static inline void
|
104
|
-
uuid_from_string(const char *s, uuid_t *uuid, uint32_t *status)
|
105
|
-
{
|
106
|
-
uuid_internal_t *u = (uuid_internal_t *) ((void *) uuid);
|
107
|
-
int n;
|
108
|
-
|
109
|
-
/* Short-circuit 2 special cases: NULL pointer and empty string. */
|
110
|
-
if (s == NULL || *s == '\0') {
|
111
|
-
uuid_create_nil(((uuid_t *) u), status);
|
112
|
-
return;
|
113
|
-
}
|
114
|
-
|
115
|
-
/* Assume the worst. */
|
116
|
-
if (status != NULL)
|
117
|
-
*status = uuid_s_invalid_string_uuid;
|
118
|
-
|
119
|
-
/* The UUID string representation has a fixed length. */
|
120
|
-
if (strlen(s) != 36)
|
121
|
-
return;
|
122
|
-
|
123
|
-
/*
|
124
|
-
* We only work with "new" UUIDs. New UUIDs have the form:
|
125
|
-
* 01234567-89ab-cdef-0123-456789abcdef
|
126
|
-
* The so called "old" UUIDs, which we don't support, have the form:
|
127
|
-
* 0123456789ab.cd.ef.01.23.45.67.89.ab
|
128
|
-
*/
|
129
|
-
if (s[8] != '-')
|
130
|
-
return;
|
131
|
-
|
132
|
-
n = sscanf(s,
|
133
|
-
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
134
|
-
&u->time_low, &u->time_mid, &u->time_hi_and_version,
|
135
|
-
&u->clock_seq_hi_and_reserved, &u->clock_seq_low, &u->node[0],
|
136
|
-
&u->node[1], &u->node[2], &u->node[3], &u->node[4], &u->node[5]);
|
137
|
-
|
138
|
-
/* Make sure we have all conversions. */
|
139
|
-
if (n != 11)
|
140
|
-
return;
|
141
|
-
|
142
|
-
/* We have a successful scan. Check semantics... */
|
143
|
-
n = u->clock_seq_hi_and_reserved;
|
144
|
-
if ((n & 0x80) != 0x00 && /* variant 0? */
|
145
|
-
(n & 0xc0) != 0x80 && /* variant 1? */
|
146
|
-
(n & 0xe0) != 0xc0) { /* variant 2? */
|
147
|
-
if (status != NULL)
|
148
|
-
*status = uuid_s_bad_version;
|
149
|
-
} else {
|
150
|
-
if (status != NULL)
|
151
|
-
*status = uuid_s_ok;
|
152
|
-
}
|
153
|
-
}
|
data/ext/vmnet/vmnet.c
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
/*-
|
2
|
-
* Copyright (c) 2011 NetApp, Inc.
|
3
|
-
* Copyright (c) 2015 xhyve developers
|
4
|
-
* All rights reserved.
|
5
|
-
*
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
7
|
-
* modification, are permitted provided that the following conditions
|
8
|
-
* are met:
|
9
|
-
* 1. Redistributions of source code must retain the above copyright
|
10
|
-
* notice, this list of conditions and the following disclaimer.
|
11
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in the
|
13
|
-
* documentation and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
|
16
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
|
19
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
21
|
-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
22
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
23
|
-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
24
|
-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
25
|
-
* SUCH DAMAGE.
|
26
|
-
*
|
27
|
-
* $FreeBSD$
|
28
|
-
*/
|
29
|
-
|
30
|
-
/*
|
31
|
-
* https://github.com/mirage/ocaml-vmnet/blob/master/lib/vmnet_stubs.c
|
32
|
-
*
|
33
|
-
* Copyright (C) 2014 Anil Madhavapeddy <anil@recoil.org>
|
34
|
-
*
|
35
|
-
* Permission to use, copy, modify, and distribute this software for any
|
36
|
-
* purpose with or without fee is hereby granted, provided that the above
|
37
|
-
* copyright notice and this permission notice appear in all copies.
|
38
|
-
*
|
39
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
40
|
-
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
41
|
-
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
42
|
-
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
43
|
-
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
44
|
-
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
45
|
-
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
46
|
-
*/
|
47
|
-
|
48
|
-
#include <ruby.h>
|
49
|
-
|
50
|
-
#include <stdio.h>
|
51
|
-
|
52
|
-
#include <vmnet/vmnet.h>
|
53
|
-
|
54
|
-
#include "uuid.h"
|
55
|
-
|
56
|
-
static VALUE
|
57
|
-
vmnet_get_mac_address_from_uuid(VALUE self, VALUE guest_uuid_str_ruby) {
|
58
|
-
/*
|
59
|
-
* from vmn_create() in https://github.com/mist64/xhyve/blob/master/src/pci_virtio_vmnet.c
|
60
|
-
*/
|
61
|
-
char* guest_uuid_str;
|
62
|
-
xpc_object_t interface_desc;
|
63
|
-
uuid_t uuid;
|
64
|
-
__block interface_ref iface;
|
65
|
-
__block vmnet_return_t iface_status;
|
66
|
-
__block char* mac = malloc(18);
|
67
|
-
dispatch_semaphore_t iface_created, iface_stopped;
|
68
|
-
dispatch_queue_t if_create_q, if_stop_q;
|
69
|
-
uint32_t uuid_status;
|
70
|
-
|
71
|
-
guest_uuid_str = RSTRING_PTR(guest_uuid_str_ruby);
|
72
|
-
interface_desc = xpc_dictionary_create(NULL, NULL, 0);
|
73
|
-
xpc_dictionary_set_uint64(interface_desc, vmnet_operation_mode_key, VMNET_SHARED_MODE);
|
74
|
-
|
75
|
-
uuid_from_string(guest_uuid_str, &uuid, &uuid_status);
|
76
|
-
if (uuid_status != uuid_s_ok) {
|
77
|
-
fprintf(stderr, "Invalid UUID %s\n", guest_uuid_str);
|
78
|
-
return rb_str_new2("");
|
79
|
-
}
|
80
|
-
|
81
|
-
xpc_dictionary_set_uuid(interface_desc, vmnet_interface_id_key, uuid);
|
82
|
-
iface = NULL;
|
83
|
-
iface_status = 0;
|
84
|
-
|
85
|
-
if_create_q = dispatch_queue_create("org.xhyve.vmnet.create", DISPATCH_QUEUE_SERIAL);
|
86
|
-
|
87
|
-
iface_created = dispatch_semaphore_create(0);
|
88
|
-
|
89
|
-
iface = vmnet_start_interface(interface_desc, if_create_q,
|
90
|
-
^(vmnet_return_t status, xpc_object_t interface_param)
|
91
|
-
{
|
92
|
-
iface_status = status;
|
93
|
-
if (status != VMNET_SUCCESS || !interface_param) {
|
94
|
-
dispatch_semaphore_signal(iface_created);
|
95
|
-
return;
|
96
|
-
}
|
97
|
-
|
98
|
-
//printf("%s\n", xpc_dictionary_get_string(interface_param, vmnet_mac_address_key));
|
99
|
-
const char *macStr = xpc_dictionary_get_string(interface_param, vmnet_mac_address_key);
|
100
|
-
strcpy(mac, macStr);
|
101
|
-
|
102
|
-
dispatch_semaphore_signal(iface_created);
|
103
|
-
});
|
104
|
-
|
105
|
-
dispatch_semaphore_wait(iface_created, DISPATCH_TIME_FOREVER);
|
106
|
-
dispatch_release(if_create_q);
|
107
|
-
|
108
|
-
if (iface == NULL || iface_status != VMNET_SUCCESS) {
|
109
|
-
fprintf(stderr, "virtio_net: Could not create vmnet interface, "
|
110
|
-
"permission denied or no entitlement?\n");
|
111
|
-
return rb_str_new2("");
|
112
|
-
}
|
113
|
-
|
114
|
-
iface_status = 0;
|
115
|
-
|
116
|
-
if_stop_q = dispatch_queue_create("org.xhyve.vmnet.stop", DISPATCH_QUEUE_SERIAL);
|
117
|
-
|
118
|
-
iface_stopped = dispatch_semaphore_create(0);
|
119
|
-
|
120
|
-
iface_status = vmnet_stop_interface(iface, if_stop_q,
|
121
|
-
^(vmnet_return_t status)
|
122
|
-
{
|
123
|
-
iface_status = status;
|
124
|
-
dispatch_semaphore_signal(iface_stopped);
|
125
|
-
});
|
126
|
-
|
127
|
-
dispatch_semaphore_wait(iface_stopped, DISPATCH_TIME_FOREVER);
|
128
|
-
dispatch_release(if_stop_q);
|
129
|
-
|
130
|
-
if (iface_status != VMNET_SUCCESS) {
|
131
|
-
fprintf(stderr, "virtio_net: Could not stop vmnet interface, "
|
132
|
-
"permission denied or no entitlement?\n");
|
133
|
-
return rb_str_new2("");
|
134
|
-
}
|
135
|
-
|
136
|
-
return rb_str_new2(mac);
|
137
|
-
}
|
138
|
-
|
139
|
-
void
|
140
|
-
Init_vmnet(void){
|
141
|
-
VALUE cVmnet;
|
142
|
-
|
143
|
-
cVmnet = rb_define_module("VMNet");
|
144
|
-
|
145
|
-
rb_define_singleton_method(cVmnet, "uuid_to_mac", vmnet_get_mac_address_from_uuid, 1);
|
146
|
-
}
|
Binary file
|