On 12/08/2016 01:58 AM, Randy Witt wrote:

     def setup_slirp(self):
         """Setup user networking"""

         if self.fstype == 'nfs':
             self.setup_nfs()
         self.kernel_cmdline_script += ' ip=dhcp'
-        self.set('NETWORK_CMD', self.get('QB_SLIRP_OPT'))
+        # Port mapping
+        hostfwd = ",hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23"
+        qb_slirp_opt_default = "-netdev user,id=net0%s" % hostfwd
+        qb_slirp_opt = self.get('QB_SLIRP_OPT') or qb_slirp_opt_default
+        # Figure out the port
+        ports = re.findall('hostfwd=[^-]*:([0-9]+)-[^,-]*', qb_slirp_opt)
+        ports = [int(i) for i in ports]
+        mac = 2
+        # Find a free port to avoid conflicts
+        for p in ports[:]:
+            p_new = p
+            while not check_free_port('localhost', p_new):
+                p_new += 1
+                mac += 1
+                while p_new in ports:
+                        p_new += 1
+                        mac += 1
+            if p != p_new:
+                ports.append(p_new)
+                qb_slirp_opt = re.sub(':%s-' % p, ':%s-' % p_new, qb_slirp_opt)
+                logger.info("Port forward changed: %s -> %s" % (p, p_new))
Regardless if the port is changed or not, so that things like tests have an
easier time of figuring out the port mappings, would it be good add a flag that
prints out the entire list of ports used, or always do it? i.e. "Port forwarding
2222:22 2333:23.... It's not necessary of course, you can  always look at the

Thansk, make sense, I added the following lines:

+        # Print out port foward
+        hostfwd = re.findall('(hostfwd=[^,]*)', qb_slirp_opt)
+        if hostfwd:
+            logger.info('Port forward: %s' % ' '.join(hostfwd))

Now print:
runqemu - INFO - Port forward: hostfwd=tcp::2222-:22 hostfwd=tcp::2323-:23


Updated in the repo:
  git://git.openembedded.org/openembedded-core-contrib rbt/runqemu

http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu

Robert Yang (6):
  scripts/runqemu: fix checking for <file>.cpio.gz
  qemuboot.bbclass: use IMGDEPLOYDIR
  runqemu-export-rootfs: fix inconsistent var names
  runqemu: support mutiple qemus running when nfs
  runqemu: fixes for slirp, network device and hostfwd
  qemuboot.bbclass: add blank lines in comments


// Robert

command line and then check to see if anything is remapped. But that's a bit
more work.

+        mac = "%s%02x" % (self.mac_slirp, mac)
+        self.set('NETWORK_CMD', '%s %s' %
(self.network_device.replace('@MAC@', mac), qb_slirp_opt))


--
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Reply via email to