1. 19 1月, 2011 1 次提交
    • M
      Simplify "NWFilterPool" to "NWFilter" · 2c0db5b5
      Matthias Bolte 提交于
      The public object is called NWFilter but the corresponding private
      object is called NWFilterPool. I don't see compelling reasons for this
      Pool suffix. One might argue that an NWFilter is a "pool" of rules, etc.
      
      Remove the Pool suffix from NWFilterPool. No functional change included.
      2c0db5b5
  2. 22 10月, 2010 1 次提交
    • D
      Remove pointless nwIPAddress struct & void *casts · 7ab7d17b
      Daniel P. Berrange 提交于
      The nwIPAddress was simply a wrapper about virSocketAddr.
      Just use the latter directly, removing all the extra field
      de-references from code & helper APIs for parsing/formatting.
      
      Also remove all the redundant casts from strong types to
      void * and then immediately back to strong types.
      
      * src/conf/nwfilter_conf.h: Remove nwIPAddress
      * src/conf/nwfilter_conf.c, src/nwfilter/nwfilter_ebiptables_driver.c:
        Update to use virSocketAddr and remove void * casts.
      7ab7d17b
  3. 13 10月, 2010 1 次提交
    • S
      nwfilter: resolve deadlock between VM ops and filter update · 4435f3c4
      Stefan Berger 提交于
       This is from a bug report and conversation on IRC where Soren reported that while a filter update is occurring on one or more VMs (due to a rule having been edited for example), a deadlock can occur when a VM referencing a filter is started.
      
      The problem is caused by the two locking sequences of
      
      qemu driver, qemu domain, filter             # for the VM start operation
      filter, qemu_driver, qemu_domain            # for the filter update operation
      
      that obviously don't lock in the same order. The problem is the 2nd lock sequence. Here the qemu_driver lock is being grabbed in qemu_driver:qemudVMFilterRebuild()
      
      The following solution is based on the idea of trying to re-arrange the 2nd sequence of locks as follows:
      
      qemu_driver, filter, qemu_driver, qemu_domain
      
      and making the qemu driver recursively lockable so that a second lock can occur, this would then lead to the following net-locking sequence
      
      qemu_driver, filter, qemu_domain
      
      where the 2nd qemu_driver lock has been ( logically ) eliminated.
      
      The 2nd part of the idea is that the sequence of locks (filter, qemu_domain) and (qemu_domain, filter) becomes interchangeable if all code paths where filter AND qemu_domain are locked have a preceding qemu_domain lock that basically blocks their concurrent execution
      
      So, the following code paths exist towards qemu_driver:qemudVMFilterRebuild where we now want to put a qemu_driver lock in front of the filter lock.
      
      -> nwfilterUndefine()   [ locks the filter ]
          -> virNWFilterTestUnassignDef()
              -> virNWFilterTriggerVMFilterRebuild()
                  -> qemudVMFilterRebuild()
      
      -> nwfilterDefine()
          -> virNWFilterPoolAssignDef() [ locks the filter ]
              -> virNWFilterTriggerVMFilterRebuild()
                  -> qemudVMFilterRebuild()
      
      -> nwfilterDriverReload()
          -> virNWFilterPoolLoadAllConfigs()
              ->virNWFilterPoolObjLoad()
                  -> virNWFilterPoolAssignDef() [ locks the filter ]
                      -> virNWFilterTriggerVMFilterRebuild()
                          -> qemudVMFilterRebuild()
      
      -> nwfilterDriverStartup()
          -> virNWFilterPoolLoadAllConfigs()
              ->virNWFilterPoolObjLoad()
                  -> virNWFilterPoolAssignDef() [ locks the filter ]
                      -> virNWFilterTriggerVMFilterRebuild()
                          -> qemudVMFilterRebuild()
      
      Qemu is not the only driver using the nwfilter driver, but also the UML driver calls into it. Therefore qemuVMFilterRebuild() can be exchanged with umlVMFilterRebuild() along with the driver lock of qemu_driver that can now be a uml_driver. Further, since UML and Qemu domains can be running on the same machine, the triggering of a rebuild of the filter can touch both types of drivers and their domains.
      
      In the patch below I am now extending each nwfilter callback driver with functions for locking and unlocking the (VM) driver (UML, QEMU) and introduce new functions for locking all registered callback drivers and unlocking them. Then I am distributing the lock-all-cbdrivers/unlock-all-cbdrivers call into the above call paths. The last shown callpath starting with nwfilterDriverStart() is problematic since it is initialize before the Qemu and UML drives are and thus a lock in the path would result in a NULL pointer attempted to be locked -- the call to virNWFilterTriggerVMFilterRebuild() is never called, so we never lock either the qemu_driver or the uml_driver in that path. Therefore, only the first 3 paths now receive calls to lock and unlock all callback drivers. Now that the locks are distributed where it matters I can remove the qemu_driver and uml_driver lock from qemudVMFilterRebuild() and umlVMFilterRebuild() and not requiring the recursive locks.
      
      For now I want to put this out as an RFC patch. I have tested it by 'stretching' the critical section after the define/undefine functions each lock the filter so I can (easily) concurrently execute another VM operation (suspend,start). That code is in this patch and if you want you can de-activate it. It seems to work ok and operations are being blocked while the update is being done.
      I still also want to verify the other assumption above that locking filter and qemu_domain always has a preceding qemu_driver lock.
      4435f3c4
  4. 07 10月, 2010 1 次提交
  5. 01 10月, 2010 1 次提交
  6. 18 6月, 2010 1 次提交
    • S
      nwfilter: add XML attribute to control iptables state match · 51d3fb02
      Stefan Berger 提交于
      This patch adds an optional XML attribute to a nwfilter rule to give the user control over whether the rule is supposed to be using the iptables state match or not. A rule may now look like shown in the XML below with the statematch attribute either having value '0' or 'false' (case-insensitive).
      
      [...]
      <rule action='accept' direction='in' statematch='false'>
      <tcp srcmacaddr='1:2:3:4:5:6'
                 srcipaddr='10.1.2.3' srcipmask='32'
                 dscp='33'
                 srcportstart='20' srcportend='21'
                 dstportstart='100' dstportend='1111'/>
      </rule>
      [...]
      
      I am also extending the nwfilter schema and add this attribute to a test case.
      51d3fb02
  7. 04 5月, 2010 1 次提交
    • S
      nwfilter: skip some interfaces on filter update · 018fd697
      Stefan Berger 提交于
      When a filter is updated, only those interfaces must have their old
      rules cleared that either reference the filter directly or indirectly
      through another filter. Remember between the different steps of the
      instantiation of the filters which interfaces must be skipped. I am
      using a hash map to remember the names of the interfaces and store a
      bogus pointer to ~0 into it that need not be freed.
      018fd697
  8. 30 4月, 2010 1 次提交
    • S
      Clean all tables before applying 'basic' rules · 59fe163f
      Stefan Berger 提交于
      The functions invoked by the IP address learning thread
      that apply some basic filtering rules did not clean up
      any previous filtering rules that may still be there
      (due to a libvirt restart for example). With the
      patch below all the rules are cleaned up first.
      
      Also, I am introducing a function to drop all traffic
      in case the IP address learning thread could not apply
      the rules.
      59fe163f
  9. 27 4月, 2010 2 次提交
    • S
      nwfilter: add support for RAPR protocol · aea68ce9
      Stefan Berger 提交于
      This patch adds support for the RARP protocol. This may be needed due to
      qemu sending out a RARP packet (at least that's what it seems to want to
      do even though the protocol id is wrong) when migration finishes and
      we'd need a rule to let the packets pass.
      
      Unfortunately my installation of ebtables does not understand -p RARP
      and also seems to otherwise depend on strings in /etc/ethertype
      translated to protocol identifiers. Therefore I need to pass -p 0x8035
      for RARP. To generally get rid of the dependency of that file I switch
      all so far supported protocols to use their protocol identifier in the
      -p parameter rather than the string.
      
      I am also extending the schema and added a test case.
      
      changes from v1 to v2:
      - added test case into patch
      aea68ce9
    • S
      nwfilter: enable hex number inputs in filter XML · 5c7c755f
      Stefan Berger 提交于
      With this patch I want to enable hex number inputs in the filter XML. A
      number that was entered as hex is also printed as hex unless a string
      representing the meaning can be found.
      
      I am also extending the schema and adding a test case. A problem with
      the DSCP value is fixed on the way as well.
      
      Changes from V1 to V2:
      
      - using asHex boolean in all printf type of functions to select the
      output format in hex or decimal format
      5c7c755f
  10. 21 4月, 2010 2 次提交
    • S
      nwfilter: add support for connlimit match · abce152a
      Stefan Berger 提交于
      This patch adds support for the connlimit match in iptables that is used
      to limit the number of outgoing directions.
      abce152a
    • S
      Extend fwall-drv interface and call functions via interface · c8f4dcca
      Stefan Berger 提交于
      I am moving some of the eb/iptables related functions into the interface
      of the firewall driver and am making them only accessible via the driver's
      interface. Otherwise exsiting code is adapted where needed. I am adding one
      new function to the interface that checks whether the 'basic' rules can be
      applied,  which will then be used by a subsequent patch.
      c8f4dcca
  11. 14 4月, 2010 1 次提交
    • S
      nwfilter: use virFindFileInPath for needed CLI tools · 274f09cb
      Stefan Berger 提交于
      I am getting rid of determining the path to necessary CLI tools at
      compile time. Instead, now the firewall driver has an initialization
      function that uses virFindFileInPath() to determine the path to
      necessary CLI tools and a shutdown function to free allocated memory.
      The rest of the patch mostly deals with availability of the CLI tools
      and to not call certain code blocks if a tool is not available and that
      strings now have to be built slightly differently.
      274f09cb
  12. 08 4月, 2010 1 次提交
    • S
      nwfilter: Support for learning a VM's IP address · 3bf24abc
      Stefan Berger 提交于
      This patch implements support for learning a VM's IP address. It uses
      the pcap library to listen on the VM's backend network interface (tap)
      or the physical ethernet device (macvtap) and tries to capture packets
      with source or destination MAC address of the VM and learn from DHCP
      Offers, ARP traffic, or first-sent IPv4 packet what the IP address of
      the VM's interface is. This then allows to instantiate the network
      traffic filtering rules without the user having to provide the IP
      parameter somewhere in the filter description or in the interface
      description as a parameter. This only supports to detect the parameter
      IP, which is for the assumed single IPv4 address of a VM. There is not
      support for interfaces that may have multiple  IP addresses (IP
      aliasing) or IPv6 that may then require more than one valid IP address
      to be detected. A VM can have multiple independent interfaces that each
      uses a different IP address and in that case it will be attempted to
      detect each one of the address independently.
      
      So, when for example an interface description in the domain XML has
      looked like this up to now:
      
          <interface type='bridge'>
            <source bridge='mybridge'/>
            <model type='virtio'/>
            <filterref filter='clean-traffic'>
              <parameter name='IP' value='10.2.3.4'/>
            </filterref>
          </interface>
      
      you may omit the IP parameter:
      
          <interface type='bridge'>
            <source bridge='mybridge'/>
            <model type='virtio'/>
            <filterref filter='clean-traffic'/>
          </interface>
      
      Internally I am walking the 'tree' of a VM's referenced network filters
      and determine with the given variables which variables are missing. Now,
      the above IP parameter may be missing and this causes a libvirt-internal
      thread to be started that uses the pcap library's API to listen to the
      backend interface  (in case of macvtap to the physical interface) in an
      attempt to determine the missing IP parameter. If the backend interface
      disappears the thread terminates assuming the VM was brought down. In
      case of a macvtap device a timeout is being used to wait for packets
      from the given VM (filtering by VM's interface MAC address). If the VM's
      macvtap device disappeared the thread also terminates. In all other
      cases it tries to determine the IP address of the VM and will then apply
      the rules late on the given interface, which would have happened
      immediately if the IP parameter had been explicitly given. In case an
      error happens while the firewall rules are applied, the VM's backend
      interface is 'down'ed preventing it to communicate. Reasons for failure
      for applying the network firewall rules may that an ebtables/iptables
      command failes or OOM errors. Essentially the same failure reasons may
      occur as when the firewall rules are applied immediately on VM start,
      except that due to the late application of the filtering rules the VM
      now is already running and cannot be hindered anymore from starting.
      Bringing down the whole VM would probably be considered too drastic.
      While a VM's IP address is attempted to be determined only limited
      updates to network filters are allowed. In particular it is prevented
      that filters are modified in such a way that they would introduce new
      variables.
      
      A caveat: The algorithm does not know which one is the appropriate IP
      address of a VM. If the VM spoofs an IP address in its first ARP traffic
      or IPv4 packets its filtering rules will be instantiated for this IP
      address, thus 'locking' it to the found IP address. So, it's still
      'safer' to explicitly provide the IP address of a VM's interface in the
      filter description if it is known beforehand.
      
      * configure.ac: detect libpcap
      * libvirt.spec.in: require libpcap[-devel] if qemu is built
      * src/internal.h: add the new ATTRIBUTE_PACKED define
      * src/Makefile.am src/libvirt_private.syms: add the new modules and symbols
      * src/nwfilter/nwfilter_learnipaddr.[ch]: new module being added
      * src/nwfilter/nwfilter_driver.c src/conf/nwfilter_conf.[ch]
        src/nwfilter/nwfilter_ebiptables_driver.[ch]
        src/nwfilter/nwfilter_gentech_driver.[ch]: plu the new functionality in
      * tests/nwfilterxml2xmltest: extend testing
      3bf24abc
  13. 06 4月, 2010 1 次提交
  14. 04 4月, 2010 1 次提交
  15. 30 3月, 2010 5 次提交
    • S
      Use libvirt's existing ipv6/ipv4 parser/printer rather than self-written ones · 0e0f6021
      Stefan Berger 提交于
      This patch changes the network filtering code to use libvirt's existing
      IPv4 and IPv6 address parsers/printers rather than my self-written ones.
      
      I am introducing a new function in network.c that counts the number of
      bits in a netmask and ensures that the given address is indeed a netmask,
      return -1 on error or values of 0-32 for IPv4 addresses and 0-128 for
      IPv6 addresses. I then based the function checking for valid netmask
      on invoking this function.
      0e0f6021
    • S
      Add ip6tables support for IPv6 filtering · bc210210
      Stefan Berger 提交于
      This patch adds IPv6 filtering support for the following protocols:
      - tcp-ipv6
      - udp-ipv6
      - udplite-ipv6
      - esp-ipv6
      - ah-ipv6
      - sctp-ipv6
      - all-ipv6
      - icmpv6
      
      Many of the IPv4 data structure could be re-used for IPv6 support.
      Since ip6tables also supports pretty much the same command line parameters
      as iptables does, also much of the code could be re-used and now
      command lines are invoked with the ip(6)tables tool parameter passed
      through the functions as a parameter.
      bc210210
    • S
      Remove driver dependency from nwfilter_conf.c · 0af0ded0
      Stefan Berger 提交于
      This patch removes the driver dependency from nwfilter_conf.c and moves
      a callback function calling into the driver into
      nwfilter_gentech_driver.c and passes a pointer to that callback function
      upon initialization of nwfilter_conf.c.
      0af0ded0
    • S
      Add support for so-far missing protocols for iptables filtering · 285d3893
      Stefan Berger 提交于
      This patch adds filtering support for the so-far missing protocols 'ah',
      'esp' and 'udplite'.
      285d3893
    • S
      Fix "make check" run requesting authentication · ad8bf13f
      Stefan Berger 提交于
      This patch fixes the 'make check' runs for me which, under certain
      circumstances and login configurations, did invoke popups requesting
      authentication. I removed the parameter conn from being passed into the
      error reporting function.
      
      * src/conf/nwfilter_conf.h src/conf/nwfilter_conf.c: remove conn from
        error reporting parameters.
      ad8bf13f
  16. 27 3月, 2010 4 次提交