[OE-core] [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd
Randy Witt
randy.e.witt at linux.intel.com
Wed Dec 7 17:58:54 UTC 2016
> 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
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))
More information about the Openembedded-core
mailing list