1. 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
  2. 17 4月, 2010 1 次提交
  3. 16 4月, 2010 2 次提交
  4. 15 4月, 2010 3 次提交
    • S
      nwfilter: fix tear down order and consolidate functions · 41b08719
      Stefan Berger 提交于
      To avoid race-conditions, the tear down of a filter has to happen before
      the tap interface disappears and another tap interface with the same
      name can re-appear. This patch tries to fix this. In one place, where
      communication with the qemu monitor may fail, I am only tearing the
      filters down after knowing that the function did not fail.
      
      I am also moving the tear down functions into an include file for other
      drivers to reuse.
      41b08719
    • S
      Trivial fix: Add braces to for statement to avoid crashes · c41873f4
      Stefan Berger 提交于
      I am adding braces around the for statement that are now needed to due the
      new sa_assert immediately following the for statement.
      c41873f4
    • J
      nwfilter_ebiptables_driver.c: avoid NULL dereference · b6719eab
      Jim Meyering 提交于
      * src/nwfilter/nwfilter_ebiptables_driver.c (ebiptablesApplyNewRules):
      Don't dereference a NULL or uninitialized pointer when given
      an empty list of rules.  Add an sa_assert(inst) in each loop to
      tell clang that the uses of "inst[i]" are valid.
      b6719eab
  5. 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
  6. 13 4月, 2010 1 次提交
    • S
      Consolidate interface related functions in interface.c · 5174b02f
      Stefan Berger 提交于
      Changes from v1 to v2:
      - changed function name prefixes to 'iface' from previous 'Iface'
      
      - Further to make make syntax-check pass:
       - indentation fix in interface.h
       - added entry to POTFILES.in
      
      I am consolidating network interface related functions used in nwfilter
      and macvtap code in utils/interface.c. All function names are prefixed
      with 'Iface'. The following functions are now available through
      interface.h:
      
      int ifaceCtrl(const char *name, bool up);
      int ifaceUp(const char *name);
      int ifaceDown(const char *name);
      
      int ifaceCheck(bool reportError, const char *ifname,
                     const unsigned char *macaddr, int ifindex);
      
      int ifaceGetIndex(bool reportError, const char *ifname, int *ifindex);
      
      I added 'int ifindex' as parameter to ifaceCheck to the original
      function and modified the code accordingly.
      5174b02f
  7. 12 4月, 2010 1 次提交
  8. 10 4月, 2010 1 次提交
    • S
      nwfilter: Process DHCP option to determine whether packet is a DHCP_OFFER · 55d444cc
      Stefan Berger 提交于
      I mistakenly took the op field in the DHCP message as the DHCP_OFFER
      type. Rather than basing the decision to read the VM's IP address on
      that field, process the appended DHCP options where option 53 indicates
      the actual type of the packet. I am also reading the broadcast address
      of the VM, but don't use it so far.
      55d444cc
  9. 08 4月, 2010 2 次提交
    • S
      nwfilter: fix for directionality of ICMP traffic · 9fd54a78
      Stefan Berger 提交于
      Changes from V1 to V2 of this patch
      - I had reversed the logic thinking that icmp type 0 is a echo
      request,but it's reply -- needed to reverse the logic
      - Found that ebtables takes the --ip-tos argument only as a hex number
      
      This patch enables the skipping of some of the ICMP traffic rules on the
      iptables level under certain circumstances so that the following filter
      properly enables unidirectional pings:
      
      <filter name='testcase'>
          <uuid>d6b1a2af-def6-2898-9f8d-4a74e3c39558</uuid>
          <!-- allow incoming ICMP Echo Request -->
          <rule action='accept' direction='in' priority='500'>
              <icmp type='8'/>
          </rule>
          <!-- allow outgoing ICMP Echo Reply -->
          <rule action='accept' direction='out' priority='500'>
              <icmp type='0'/>
          </rule>
          <!-- drop all other ICMP traffic -->
          <rule action='drop' direction='inout' priority='600'>
              <icmp/>
          </rule>
      </filter>
      9fd54a78
    • 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
  10. 07 4月, 2010 1 次提交
    • S
      nwfiler: fix due to non-symmetric src mac address match in iptables · f8352e22
      Stefan Berger 提交于
      The attached patch fixes a problem due to the mac match in iptables only
      supporting --mac-source and no --mac-destination, thus it not being
      symmetric. Therefore a rule like this one
      
      <rule action='drop' direction='out'>
        <all match='no' srcmacaddr='$MAC'/>
      </rule>
      
      should only have the MAC match on traffic leaving the VM and not test
      for the same source MAC address on traffic that the VM receives.
      f8352e22
  11. 06 4月, 2010 3 次提交
    • S
      nwfilter: Fix instantiated layer 2 rules for 'inout' direction · 552bdb9b
      Stefan Berger 提交于
      With Eric Blake's suggestions applied.
      
      The following rule for direction 'in'
      
      <rule direction='in' action='drop'>
        <mac srcmacaddr='1:2:3:4:5:6'/>
      </rule>
      
      drops all traffic from the given mac address.
      The following rule for direction 'out'
      
      <rule direction='out' action='drop'>
        <mac dstmacaddr='1:2:3:4:5:6'/>
      </rule>
      
      drops all traffic to the given mac address.
      The following rule in direction 'inout'
      
      <rule direction='inout' action='drop'>
        <mac srcmacaddr='1:2:3:4:5:6'/>
      </rule>
      
      now drops all traffic from and to the given MAC address.
      So far it would have dropped traffic from the given MAC address
      and outgoing traffic with the given source MAC address, which is not useful
      since the packets will always have the VM's MAC address as source
      MAC address. The attached patch fixes this.
      
      This is the last bug I currently know of and want to fix.
      552bdb9b
    • M
      Remove unnecessary trailing \n in log messages · 49411f02
      Matthias Bolte 提交于
      49411f02
    • S
      This patch removes the virConnectPtr parameter from all functions where it's... · 45274d41
      Stefan Berger 提交于
      This patch removes the virConnectPtr parameter from all functions where it's not necessary starting out with removing it as a parameter to the error reporting function.
      45274d41
  12. 05 4月, 2010 1 次提交
  13. 03 4月, 2010 1 次提交
    • S
      The following issues are fixed in the patch below: · b3e8f9f4
      Stefan Berger 提交于
      - ebtables requires that some of the command line parameters are passed as hex numbers; so have those attributes call a function that prints 16 and 8 bit integers as hex nunbers.
      
      - ip6tables requires '--icmpv6-type' rather than '--icmp-type'
      
      - ebtables complains about protocol identifiers lower than 0x600, so already discard anything lower than 0x600 in the parser
      
      - make the protocol entry types more readable using a #define for its entries
      
      - continue parsing a filtering rule even if a faulty entry is encountered; return an error value at the end and let the caller decide what to do with the rule's object
      
      - fix an error message
      b3e8f9f4
  14. 02 4月, 2010 1 次提交
  15. 01 4月, 2010 1 次提交
    • S
      While writing a couple of test cases for the nwfilter's XML parser I · e8132007
      Stefan Berger 提交于
      found some cases where the output ended up not looking as expected. So
      the following changes are in the patch below:
      
      - if the protocol ID in the MAC header is an integer, just write it into
      the datastructure without trying to find a corresponding string for it
      and if none is found failing
      - when writing the protocol ID as string, simply write it as integer if
      no corresponding string can be found
      - same changes for arpOpcode parsing and printing
      - same changes for protocol ID in an IP packet
      - DSCP value needs to be written into the data structure
      - IP protocol version number is redundant at this level, so remove it
      - parse the protocol ID found inside an IP packet not only as string but
      also as uint8
      - arrange the display of the src and destination masks to be shown after
      the src and destination ip address respectively in the XML
      - the existing libvirt IP address parser accepts for example '25' as an
      IP address. I want this to be parsed as a CIDR type netmask. So try to
      parse it as an integer first (CIDR netmask) and if that doesn't work as
      a dotted IP address style netmask.
      - instantiation of rules with MAC masks didn't work because they weren't
      printed into a buffer, yet.
      e8132007
  16. 30 3月, 2010 4 次提交
    • 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
  17. 27 3月, 2010 4 次提交
    • J
      filter new files through cppi, so syntax-check passes once again · 19a863c4
      Jim Meyering 提交于
      * src/conf/nwfilter_conf.h: Indent cpp directives.
      * src/conf/nwfilter_params.h: Likewise.
      * src/datatypes.h: Likewise.
      * src/nwfilter/nwfilter_driver.h: Likewise.
      * src/nwfilter/nwfilter_ebiptables_driver.h: Likewise.
      * src/nwfilter/nwfilter_gentech_driver.h: Likewise.
      19a863c4
    • S
      Extensions for iptables rules · 1130085c
      Stefan Berger 提交于
      This patch adds support for L3/L4 filtering using iptables. This adds
      support for 'tcp', 'udp', 'icmp', 'igmp', 'sctp' etc. filtering.
      
      As mentioned in the introduction, a .c file provided by this patch
      is #include'd into a .c file. This will need work, but should be alright
      for review.
      Signed-off-by: NStefan Berger <stefanb@us.ibm.com>
      1130085c
    • S
      Add IPv6 support for the ebtables layer · f85208ee
      Stefan Berger 提交于
      This patch adds IPv6 support for the ebtables layer. Since the parser
      etc. are all parameterized, it was fairly easy to add this...
      Signed-off-by: NStefan Berger <stefanb@us.ibm.com>
      f85208ee
    • S
      Core driver implementation with ebtables support · 065b6571
      Stefan Berger 提交于
      This patch implements the core driver and provides
      - management functionality for managing the filter XMLs
      - compiling the internal filter representation into ebtables rules
      - applying ebtables rules on a network (tap,macvtap) interface
      - tearing down ebtables rules that were applied on behalf of an
      interface
      - updating of filters while VMs are running and causing the firewalls to
      be rebuilt
      - other bits and pieces
      Signed-off-by: NStefan Berger <stefanb@us.ibm.com>
      065b6571