Skip to content

Commit cf70596

Browse files
committed
parse forward hostToVm and vmToHost ports
1 parent 2ff5886 commit cf70596

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/parser.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Parser {
5858
// net
5959
if (hw.net) {
6060
const net = hw.net;
61-
this.net(net.macAddr, net.nic, net.mode, net.opts);
61+
this.net(net.macAddr, net.nic, net.mode, net);
6262
} // if
6363

6464
if (st.noShutdown) { this.noShutdown(); }
@@ -178,15 +178,29 @@ class Parser {
178178
* N E T
179179
*
180180
*/
181-
net(macAddr, card='rtl8139', mode='host', opts) {
181+
net(macAddr, card='rtl8139', mode='host', opts = {}) {
182182
if ('host' === mode || 'darwin' === osType) {
183183
let ext = 'user';
184-
if (opts) {
185-
ext = opts.fwds.reduce( (prev, fwd) => {
186-
return `${prev},hostfwd=tcp:${fwd.hostIp}:${fwd.hostPort}-${opts.guestIp}:${fwd.guestPort}`;
187-
}, `${ext},dhcpstart=${opts.guestIp}`);
184+
185+
if (opts.hostToVmPortFwd || opts.vmToHostPortFwd) {
186+
ext = `${ext},dhcpstart=${opts.guestIp}`;
187+
188+
if (opts.hostToVmPortFwd) {
189+
ext = opts.hostToVmPortFwd.reduce( (prev, fwd) => {
190+
return `${prev},hostfwd=tcp:${fwd.hostIp}:${fwd.hostPort}-${opts.guestIp}:${fwd.guestPort}`;
191+
}, ext);
192+
} // if
193+
194+
// guestfwd=tcp:10.0.2.100:1234-tcp:10.10.1.1:4321
195+
if (opts.vmToHostPortFwd) {
196+
ext = opts.vmToHostPortFwd.reduce( (prev, fwd) => {
197+
return `${prev},guestfwd=tcp:${opts.guestIp}:${fwd.guestPort}-${fwd.hostIp}:${fwd.hostPort}`;
198+
}, ext);
199+
} // if
188200
} // if
201+
189202
return this.pushArg('-net', `nic,model=${card},macaddr=${macAddr}`, '-net', ext);
203+
190204
} else if ('bridged' === mode || 'bridge' === mode) {
191205
return this.pushArg('-net', `nic,model=${card},macaddr=${macAddr}`, '-net', 'tap');
192206
} // else if

tests.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ const tests = [
4949

5050
// net
5151
,['net', ['myMacAddr', 'myCard', 'user'], ['-net', 'nic,model=myCard,macaddr=myMacAddr', '-net', 'user']]
52-
,['net', ['myMacAddr', 'myCard', 'user', {guestIp:'gIp',fwds:[{hostIp:'hIp',hostPort:'hPort', guestPort:'gPort'}]}], ['-net', 'nic,model=myCard,macaddr=myMacAddr', '-net', 'user,dhcpstart=gIp,hostfwd=tcp:hIp:hPort-gIp:gPort']]
52+
,['net', ['myMacAddr', 'myCard', 'user', {guestIp:'gIp',hostToVmPortFwd:[{hostIp:'hIp',hostPort:'hPort', guestPort:'gPort'}]}], ['-net', 'nic,model=myCard,macaddr=myMacAddr', '-net', 'user,dhcpstart=gIp,hostfwd=tcp:hIp:hPort-gIp:gPort']]
53+
,['net', ['myMacAddr', 'myCard', 'user', {guestIp:'gIp',vmToHostPortFwd:[{hostIp:'hIp',hostPort:'hPort', guestPort:'gPort'}]}], ['-net', 'nic,model=myCard,macaddr=myMacAddr', '-net', 'user,dhcpstart=gIp,guestfwd=tcp:gIp:gPort-hIp:hPort']]
54+
55+
,['net', ['myMacAddr', 'myCard', 'user', {guestIp:'gIp',hostToVmPortFwd:[{hostIp:'hIp',hostPort:'hPort', guestPort:'gPort'}],
56+
vmToHostPortFwd:[{hostIp:'hIp',hostPort:'hPort', guestPort:'gPort'}]}], ['-net', 'nic,model=myCard,macaddr=myMacAddr', '-net', 'user,dhcpstart=gIp,hostfwd=tcp:hIp:hPort-gIp:gPort,guestfwd=tcp:gIp:gPort-hIp:hPort']]
5357

5458

5559
// drives

0 commit comments

Comments
 (0)