<br><tt><font size=2>One note: the attached patches must be compiled with
--without-lxc support due to a linking problem. Will fix this for the next
post.</font></tt>
<br>
<br><tt><font size=2>Regards,</font></tt>
<br><tt><font size=2>   Stefan</font></tt>
<br>
<br>
<br><tt><font size=2>> <br>
> Hi!<br>
> <br>
> The following set of patches add network filtering (ACL) extensions
to<br>
> libvirt and enable network traffic filtering for VMs using ebtables
and,<br>
> depending on the networking technology being used (tap, but not<br>
> macvtap), also iptables. Usage of either is optional and controlled<br>
> through filters that a VM is referencing.<br>
> <br>
> The ebtables-level filtering is based on the XML derived from the
CIM<br>
> network slide 10 (filtering) from the DMTF website<br>
> (</font></tt><a href=http://www.dmtf.org/standards/cim/cim_schema_v2230/CIM_Network.pdf><tt><font size=2>http://www.dmtf.org/standards/cim/cim_schema_v2230/CIM_Network.pdf</font></tt></a><tt><font size=2>).<br>
> The XML we derived from this was discussed on the list before. On
the<br>
> ebtables level we currently handle filtering of IPv4 and ARP traffic.
<br>
> <br>
>   The iptables-level filtering is based on similar XML where
XML nodes<br>
> described the particular protocol to filter for. Its extensions enable<br>
> the filtering of traffic using iptables for tcp, udp, icmp, igmp,
sctp<br>
> and 'all' types of traffic. This list of protocols maps to the features<br>
> supported by iptables and only excludes protocols like 'esp' and 'ah'.<br>
> Currently only bridging mode is supported and based on availability
of<br>
> the physdev match. <br>
> <br>
> The filtering framework adds new libvirt virsh commands for managing<br>
> the filters. The 5 new commands are:<br>
>   - virsh nwfilter-list<br>
>   - virsh nwfilter-dumpxml <name of filter><br>
>   - virsh nwfilter-define <name of file containing filter
desc.><br>
>   - virsh nwfilter-undefine <name of filter><br>
>   - virsh nwfilter-edit <name of filter><br>
> <br>
> Above commands are similar to commands for already existing pools
and as<br>
> such much of the code directly related to the above commands could
be<br>
> borrowed from other drivers.<br>
> <br>
> The network filters can either contain rules using the above mentioned<br>
> XML or contain references to other filters in order to build more<br>
> complex filters that form some sort of filter tree or can contain
both.<br>
> An example for a filter referencing other filters would be this one<br>
> here: <br>
> <br>
> <filter name='demofilter4' chain='root'><br>
>   <uuid>66f62d1d-34c1-1421-824f-c62d5ee5e8b6</uuid><br>
>   <filterref filter='no-mac-spoofing'/><br>
>   <filterref filter='no-mac-broadcast'/><br>
>   <filterref filter='no-arp-spoofing'/><br>
>   <filterref filter='allow-dhcp'><br>
>     <parameter name='DHCPSERVER' value='10.0.0.1'/><br>
>   </filterref><br>
>   <filterref filter='no-other-l2-traffic'/><br>
>   <filterref filter='recv-only-vm-ipaddress'/><br>
>   <filterref filter='recv-only-vm-macaddress'/><br>
>   <filterref filter='l3-test'/><br>
> </filter><br>
> <br>
> A filter containing actual rules would look like this:<br>
> <br>
> <filter name='no-mac-broadcast' chain='ipv4'><br>
>   <uuid>ffe2ccd6-edec-7360-1852-6b5ccb553234</uuid><br>
>   <rule action='drop' direction='out' priority='500'><br>
>     <mac dstmacaddr='ff:ff:ff:ff:ff:ff'/><br>
>   </rule><br>
> </filter><br>
> <br>
> The filter XML now also holds a priority attribute in the rule. This<br>
> provides control over the ordering of the applied ebtables/iptables<br>
> rules beyond their appearance in the XML.<br>
> <br>
> The domain XML has been extended to reference a top level filter from<br>
> within each <interface> XML node. A valid reference to such
a top level<br>
> filter looks like this: <br>
> <br>
> <interface type='bridge'><br>
>   <source bridge='static'/><br>
>   <filterref filter='demofilter4'><br>
>     <parameter name='IP' value='9.59.241.151'/><br>
>   </filterref><br>
> </interface><br>
> <br>
> In this XML a parameter IP is passed for instantiation of the referenced<br>
> filters, that may require the availability of this parameter. In the<br>
> above case the IP parameter's value describes the value of the IP<br>
> address of the VM and allows to enable those filters to be instantiated<br>
> that require this 'IP' variable. If a filter requires a parameter
that<br>
> is not provided, the VM will not start or the interface will not attach<br>
> to a running VM. Any names of parameters can be provided for<br>
> instantiation of filters and their names and values only need to pass
a<br>
> regular expression test. Currently only MAC and IP addresses and port<br>
> numbers can be replaced with variables inside the filter XML. In a<br>
> subsequent patch we will be adding capability to allow users to omit
the<br>
> IP parameter (only) and enable libvirt to learn the IP address of
the VM<br>
> and have it instantiate the filter once it knows it.<br>
> <br>
> While virtual machines are running, it is possible to update their<br>
> filters. For that all running VMs' filter 'trees' are traversed to<br>
> detect whether the updated filter is referenced by the VM. If so,
its<br>
> ebtables/iptable rules are applied. If one of the VMs' update fails<br>
> allupdates are rolled back and the filter XML update is rejected.<br>
> <br>
> One comment about the instantiation of the rules: Since the XML allows<br>
> to create nearly any possible combination of parameters to ebtables
or<br>
> iptables commands, I haven't used the ebtables or iptables wrappers.<br>
> Instead, I am writing ebtables/iptables command into a buffer, add<br>
> command line options to each one of them as described in the rule's
XML,<br>
> write the buffer into a file and run it as a script. For those commands<br>
> that are not allowed to fail I am using the following format to run<br>
> them:<br>
> <br>
> cmd="ebtables <some options>"<br>
> r=`${cmd}`<br>
> if [ $? -ne 0 ]; then<br>
> echo "Failure in command ${cmd}."<br>
> exit 1<br>
> fi<br>
> <br>
> cmd="..."<br>
> [...]<br>
> <br>
> If one of the command fails in such a batch, the libvirt code is going<br>
> pick up the error code '1', tear down anything previously established<br>
> and report an error back. The actual error message shown above is<br>
> currently not reported back, but can be later on with some changes
to<br>
> the commands running external programs that need to read the script's<br>
> stdout.<br>
> <br>
> One comment to patch 13: It currently #include's a .c file into a
.c<br>
> file only for the reason so I don't have to change too much code once
I<br>
> change code in the underlying patch. So this has to be changed. The<br>
> patch series works without patch 13, but then only supports ebtables.<br>
> <br>
> The patches apply to the current tip. They pass 'make syntax-check'
and<br>
> have been frequently run in valgrind for memory leak checks. The order<br>
> in which I apply the patches is as follows:<br>
> <br>
> add_recursive_locks.diff<br>
> add_build_support.diff<br>
> add_public_api.diff<br>
> add_internal_api.diff<br>
> impl_pub_api.diff<br>
> def_wire_protocol_format.diff<br>
> impl_rpc_client.c<br>
> impl_srv_dispatch.diff<br>
> add_virsh_support.diff<br>
> add_xml_parsing.diff<br>
> add_qemu_support.diff<br>
> impl_driver.diff<br>
> add_iptables_support.diff<br>
> <br>
> Looking forward to your feedback on the patches. <br>
> <br>
> Thanks and regards,<br>
>     Stefan and Gerhard<br>
> <br>
> <br>
> --<br>
> libvir-list mailing list<br>
> libvir-list@redhat.com<br>
> </font></tt><a href="https://www.redhat.com/mailman/listinfo/libvir-list"><tt><font size=2>https://www.redhat.com/mailman/listinfo/libvir-list</font></tt></a><tt><font size=2><br>
</font></tt>