1. 04 5月, 2018 4 次提交
  2. 28 4月, 2018 1 次提交
    • L
      nwfilter: increase pcap buffer size to be compatible with TPACKET_V3 · ce5aebea
      Laine Stump 提交于
      When an nwfilter rule sets the parameter CTRL_IP_LEARNING to "dhcp",
      this turns on the "dhcpsnoop" thread, which uses libpcap to monitor
      traffic on the domain's tap device and extract the IP address from the
      DHCP response.
      
      If libpcap on the host is built with HAVE_TPACKET3 defined (to enable
      support for TPACKET_V3), the dhcpsnoop code's initialization of the
      libpcap socket would fail with the following error:
      
        virNWFilterSnoopDHCPOpen:1134 : internal error: pcap_setfilter: can't remove kernel filter: Bad file descriptor
      
      It turns out that this was because TPACKET_V3 requires a larger buffer
      size than libvirt was setting (we were setting it to 128k). Changing
      the buffer size to 256k eliminates the error, and the dhcpsnoop thread
      once again works properly.
      
      A fuller explanation of why TPACKET_V3 requires such a large buffer,
      for future git spelunkers:
      
      libpcap calls setsockopt(... SOL_PACKET, PACKET_RX_RING...) to setup a
      ring buffer for receiving packets; two of the attributes sent to this
      API are called tp_frame_size, and tp_frame_nr. If libpcap was built
      with HAVE_TPACKET3 defined, tp_trame_size is set to MAXIMUM_SNAPLEN
      (defined in libpcap sources as 262144) and tp_frame_nr is set to:
      
       [the buffer size we set, i.e. PCAP_BUFFERSIZE i.e. 262144] / tp_frame_size.
      
      So if PCAP_BUFFERSIZE < MAXIMUM_SNAPLEN, then tp_frame_nr (the number
      of frames in the ring buffer) is 0, which is nonsensical. This same
      value is later used as a multiplier to determine the size for a call
      to malloc() (which would also fail).
      
      (NB: if HAVE_TPACKET3 is *not* defined, then tp_frame_size is set to
      the snaplen set by the user (in our case 576) plus a small amount to
      account for ethernet headers, so 256k is far more than adequate)
      
      Since the TPACKET_V3 code in libpcap actually reads multiple packets
      into each frame, it's not a problem to have only a single frame
      (especially when we are monitoring such infrequent traffic), so it's
      okay to set this relatively small buffer size (in comparison to the
      default, which is 2MB), which is important since every guest using
      dhcp snooping in a nwfilter rule will hold 2 of these buffers for the
      entire life of the guest.
      
      Thanks to Christian Ehrhardt for discovering that buffer size was the
      problem (this was not at all obvious from the error that was logged!)
      
      Resolves: https://bugzilla.redhat.com/1547237
      Fixes: https://bugs.launchpad.net/libvirt/+bug/1758037Signed-off-by: NLaine Stump <laine@laine.org>
      Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com> (V1)
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Tested-by: NChristian Ehrhardt <christian.ehrhardt@canonical.com>
      ce5aebea
  3. 12 4月, 2018 3 次提交
  4. 01 4月, 2018 1 次提交
  5. 08 3月, 2018 1 次提交
  6. 06 3月, 2018 1 次提交
  7. 28 2月, 2018 1 次提交
    • L
      nwfilter: save error from DHCP snoop thread to report in main thread · 1297db74
      Laine Stump 提交于
      A problem encountered due to a bug in libpcap was reported to the
      caller as:
      
         An error occurred, but the cause is unknown
      
      This was because the error had been logged in the DHCPSnoop
      thread. The worker thread handling the API call to start a domain
      spins up the DHCPSnoop thread which watches for dhcp packets with
      libpcap, then uses virCondSignal() to notify the worker thread (which
      has been waiting with virCondWait()). The worker thread knows that
      there was an error (because threadStatus != THREAD_STATUS_OK), but the
      error info had been stored in thread-specific storage for the other
      thread, so the worker thread can only report that there was a failure,
      but it doesn't know why.
      
      The solution is to save the error that was logged (with
      virErrorPreserveLast() into the object the is used to share info
      between the threads, then we can set the error in the worker thread
      using virErrorRestore().
      
      In the case of the error I was looking at, this changed the "unknown"
      message into:
      
          internal error: pcap_setfilter: can't remove kernel filter:
          Bad file descriptor
      Signed-off-by: NLaine Stump <laine@laine.org>
      1297db74
  8. 22 2月, 2018 1 次提交
  9. 21 2月, 2018 1 次提交
  10. 01 2月, 2018 1 次提交
  11. 06 12月, 2017 1 次提交
  12. 03 11月, 2017 1 次提交
    • A
      Remove backslash alignment attempts · 3e7db8d3
      Andrea Bolognani 提交于
      Right-aligning backslashes when defining macros or using complex
      commands in Makefiles looks cute, but as soon as any changes is
      required to the code you end up with either distractingly broken
      alignment or unnecessarily big diffs where most of the changes
      are just pushing all backslashes a few characters to one side.
      
      Generated using
      
        $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
          grep -E '*\.([chx]|am|mk)$$' | \
          while read f; do \
            sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
          done
      Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
      3e7db8d3
  13. 04 10月, 2017 2 次提交
    • J
      nwfilter: Fix memory leak and error path · f2fb783b
      John Ferlan 提交于
      Found by Coverity. If virNWFilterHashTablePut, then the 3rd arg @val
      must be free'd since it would be leaked.
      
      This also fixes potential problem on the error path where the caller
      could assume the virNWFilterHashTablePut was successful when in fact
      it failed leading to other issues.
      f2fb783b
    • J
      nwfilter: Clean up virNWFilterDetermineMissingVarsRec returns · ca3bef4c
      John Ferlan 提交于
      Rather than using loop break;'s in order to force a return
      of rc = -1, let's just return -1 immediately on the various
      error paths and then return 0 on the success path.
      ca3bef4c
  14. 02 10月, 2017 1 次提交
    • J
      nwfilter: Don't have virNWFilterIPAddrMapAddIPAddr consume input · a55eaced
      John Ferlan 提交于
      On pure success paths, virNWFilterIPAddrMapAddIPAddr was validly
      consuming the input @addr; however, on failure paths it was possible
      that virNWFilterVarValueCreateSimple succeed, but virNWFilterHashTablePut
      failed resulting in virNWFilterVarValueFree being called to clean
      up @val which also cleaned up the input @addr. Thus the caller had
      no way to determine on failure whether it too should clean up the
      passed parameter.
      
      Instead, let's create a copy of the input @addr, then handle that
      properly in the API allowing/forcing the caller to free it's own
      copy of the input parameter.
      a55eaced
  15. 27 9月, 2017 1 次提交
  16. 16 7月, 2017 6 次提交
  17. 11 7月, 2017 1 次提交
  18. 27 4月, 2017 8 次提交
  19. 13 4月, 2017 3 次提交
  20. 08 3月, 2017 1 次提交