Bug 1452441 - Libvirt doesn't bind to specified port when attach rng device of udp type without host attribute
Summary: Libvirt doesn't bind to specified port when attach rng device of udp type wit...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.4
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Ján Tomko
QA Contact: yanqzhan@redhat.com
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-05-19 03:07 UTC by Fangge Jin
Modified: 2018-04-10 10:46 UTC (History)
6 users (show)

Fixed In Version: libvirt-3.7.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 10:44:33 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0704 0 None None None 2018-04-10 10:46:10 UTC

Description Fangge Jin 2017-05-19 03:07:04 UTC
Description of problem:
Libvirt doesn't bind to specified port when attach rng device of udp type without host attribute


Version-Release number of selected component:
libvirt-3.2.0-5.virtcov.el7.x86_64


How reproducible:
100%


Steps to Reproduce:
0.Start a guest

1.Prepare a rng file with bind mode:
# cat egd-udp-bind.xml 
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' service='2234'/>  ====> No host attribute here
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>

2.Attach the rng device:
# virsh attach-device rhel7.4 egd-udp-bind.xml 
Device attached successfully

3.check bind port:
# netstat -tunap|grep 1234
udp        0      0 127.0.0.1:54377         127.0.0.1:1234          ESTABLISHED 10129/qemu-kvm     


Actual results:
In step 3,rng device binds to port 53477

Expected results:
In step 3,rng device binds to port 2234



Additional info:
1. Define a guest with same rng device, then start guest, it binds to correct port
# virsh dumpxml rhel7
...
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' service='2234'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      </backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
    </rng>

# virsh start rhel7

# netstat -tunap|grep 1234
udp        0      0 127.0.0.1:2234          127.0.0.1:1234          ESTABLISHED 9770/qemu-kvm   

2. Hotplug a rng device of udp mode with host attribute for bind mode like below, it also binds to correct port:
# cat rng.xml
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='localhost' service='2234'/> ===> with host attribute
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>

# virsh attach-device rhel7 rng.xml

# netstat -tunap |grep 1234
udp        0      0 127.0.0.1:2234          127.0.0.1:1234          ESTABLISHED 11326/qemu-kvm

Comment 1 Ján Tomko 2017-05-19 11:45:25 UTC
Upstream patch:
https://www.redhat.com/archives/libvir-list/2017-May/msg00694.html

Comment 2 Fangge Jin 2017-05-23 05:21:36 UTC
A similar problem that may have been fixed in the same upstream patch:

1. # cat rng.xml
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='127.0.0.1' /> 
   <source mode='connect' host='127.0.0.1'  service='1234'/>
  </backend>
 </rng>

Hot plug rng device:
# virsh attach-device V egd-udp-bind.xml 
error: Failed to attach device from egd-udp-bind.xml
error: internal error: argument key 'port' must not have null value

2. virsh edit a guest with same rng device:
# virsh edit rhel7.4
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='127.0.0.1' /> 
   <source mode='connect' host='127.0.0.1'  service='1234'/>
  </backend>
 </rng>

Start guest:
# virsh start rhel7.4

UDP binds to 127.0.0.1:34705
$ netstat -tunap|grep 1234
udp        0      0 127.0.0.1:34705         127.0.0.1:1234          ESTABLISHED -

Comment 3 Ján Tomko 2017-07-11 13:43:14 UTC
commit 2277edb964731b7b2f80c371148f01848a03eacf
Author:     Ján Tomko <jtomko@redhat.com>
CommitDate: 2017-07-11 15:18:31 +0200

    qemu: handle missing bind host/service on chardev hotplug
    
    On domain startup, bind host or bind service can be omitted
    and we will format a working command line.
    
    Extend this to hotplug as well and specify the service to QEMU
    even if the host is missing.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1452441

git describe: v3.5.0-64-g2277edb96

Comment 5 yanqzhan@redhat.com 2017-10-24 11:11:00 UTC
Scenario 1: Hotplug - missing host attribute:

Reproduce with libvirt-3.2.0-14.el7_4.2.x86_64.
Steps:
# cat egd-udp-bind.xml
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' service='2234'/>
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>

# virsh attach-device V egd-udp-bind.xml
Device attached successfully

# virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' service='2234'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      </backend>
      <alias name='rng0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </rng>

# netstat -tunap|grep 1234
udp        0      0 127.0.0.1:60524         127.0.0.1:1234          ESTABLISHED 24080/qemu-kvm      <==Binds to 60524, not the specified 2234.



Verify with libvirt-3.8.0-1.el7.x86_64.
Steps:
# cat egd-udp-bind.xml
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' service='2234'/>
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>

# virsh attach-device V egd-udp-bind.xml
Device attached successfully

# virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' service='2234'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      </backend>
      <alias name='rng0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </rng>
# netstat -tunap|grep 1234
udp        0      0 127.0.0.1:2234          127.0.0.1:1234          ESTABLISHED 19616/qemu-kvm      <==Successfully binds to the specified 2234.

Comment 6 yanqzhan@redhat.com 2017-10-24 11:14:50 UTC
Scenario 1: Hotplug - missing service attribute:

Reproduce with libvirt-3.2.0-14.el7_4.2.x86_64.
Steps:
# cat rng.xml
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='127.0.0.1'/>
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>

# virsh attach-device V rng.xml
error: Failed to attach device from rng.xml
error: internal error: argument key 'port' must not have null value



Verify with libvirt-3.8.0-1.el7.x86_64.
Steps:
# cat rng.xml
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='127.0.0.1'/>
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>

#  virsh attach-device V rng.xml
Device attached successfully

# virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' host='127.0.0.1'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      </backend>
      <alias name='rng0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </rng>
# netstat -tunap|grep 1234
udp        0      0 127.0.0.1:53291         127.0.0.1:1234          ESTABLISHED 20107/qemu-kvm      <==Can successfully bind to a port

Comment 7 yanqzhan@redhat.com 2017-10-24 11:24:34 UTC
Scenario 3: Edit - missing service attribute:
Reproduce with libvirt-3.2.0-14.el7_4.2.x86_64.
Steps:
# virsh edit V     (same as rng.xml)
...
 <rng model='virtio'>
  <backend model='egd' type='udp'>
   <source mode='bind' host='127.0.0.1'/>
   <source mode='connect' host='127.0.0.1' service='1234'/>
  </backend>
 </rng>
...

#  virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind'/>           <=='host' disappears
        <source mode='connect' host='127.0.0.1' service='1234'/>
      ...

# virsh start V
Domain V started

#  virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind'/>           <== No 'host'
        <source mode='connect' host='127.0.0.1' service='1234'/>
      ...

#  netstat -tunap|grep 1234
udp        0      0 127.0.0.1:56327         127.0.0.1:1234          ESTABLISHED 27931/qemu-kvm   
   
# virsh destroy V
Domain V destroyed

#  virsh dumpxml V|grep '/rng' -B7
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='egd' type='udp'>
                                      <==No "bind" any more
        <source mode='connect' host='127.0.0.1' service='1234'/>
      ...


Verify with libvirt-3.8.0-1.el7.x86_64.
Steps:
# virsh edit V
Domain V XML configuration edited.

# virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' host='127.0.0.1'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      ...

# virsh start V
Domain V started

# virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' host='127.0.0.1'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      ...

# netstat -tunap|grep 1234
udp        0      0 127.0.0.1:42293         127.0.0.1:1234          ESTABLISHED 20353/qemu-kvm    
  
# virsh destroy V
Domain V destroyed

# virsh dumpxml V|grep '/rng' -B7
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='bind' host='127.0.0.1'/>
        <source mode='connect' host='127.0.0.1' service='1234'/>
      ...

The 'host' attribute for "bind" mode never disappears.

Comment 8 yanqzhan@redhat.com 2017-10-24 11:27:51 UTC
Since all the results are expected with libvirt-3.8.0-1.el7.x86_64, mark this bug as verified according to comment 5, comment 6 and comment 7.

Comment 12 errata-xmlrpc 2018-04-10 10:44:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:0704


Note You need to log in before you can comment on or make changes to this bug.