From: Andy Lee Subject: [PATCH] MAC Matching vif-route & tip Date: Wed, 07 Sep 2005 10:20:04 -0700 Message-ID: <6.1.2.0.2.20050907095502.07acf8b0@secure.hitx.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_1638516093==_" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --=====================_1638516093==_ Content-Type: text/plain; charset="us-ascii"; format=flowed This patch will setup iptable rules for vif's that does MAC matching, as PHYSDEV matching only works for bridged devices. (Patch generated from Xen-2.0-testing.) On a separate but still networking issue, I noticed that my XenU's outbound traffic is sporadic (between 800KB/sec and 2MB/sec). The problem is the default qdisc being inadequate. So I fix it with: XenU# tc qdisc add dev eth0 root tbf rate 50mbit latency 20ms burst 50k TBF requires kernel option CONFIG_NET_SCH_TBF, but other qdisc should work too if the buffer is large enough to handle the bandwidth. To make this permanent, add it as a 'up' line to iface eth0 in XenU's /etc/network/interfaces. --=====================_1638516093==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="vif-route.patch" diff -r 7fa00b26a995 tools/examples/network-route --- a/tools/examples/network-route Fri Aug 12 13:48:47 2005 +++ b/tools/examples/network-route Wed Sep 7 09:51:51 2005 @@ -17,3 +17,4 @@ #============================================================================ echo 1 >/proc/sys/net/ipv4/ip_forward +echo 1 >/proc/sys/net/ipv4/conf/eth0/proxy_arp diff -r 7fa00b26a995 tools/examples/vif-route --- a/tools/examples/vif-route Fri Aug 12 13:48:47 2005 +++ b/tools/examples/vif-route Wed Sep 7 09:51:51 2005 @@ -19,12 +19,31 @@ # vif vif interface name (required). # mac vif MAC address (required). # ip list of IP networks for the vif, space-separated (optional). +# +# Dom0 kernel options: +# +# CONFIG_IP_ADVANCED_ROUTER=y +# CONFIG_IP_MULTIPLE_TABLES=y +# CONFIG_IP_NF_IPTABLES=y +# CONFIG_IP_NF_MATCH_IPRANGE=y +# CONFIG_IP_NF_MATCH_MAC=y +# CONFIG_IP_NF_FILTER=y +# +# DomU config examples: +# +# vif = [ 'ip=192.168.0.16, vif=vif1.0' ] +# vif = [ 'ip=192.168.0.16 192.168.0.17' ] # multiple IP's +# vif = [ 'ip=192.168.0.16/31' ] # using netmask +# #============================================================================ # Exit if anything goes wrong set -e echo "vif-route $*" + +# Network device connected to the Internet +wan='eth0' # Operation name. OP=$1 @@ -41,12 +60,12 @@ # Optional parameters. Set defaults. ip=${ip:-''} # default to null (do nothing) -main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'` +main_ip=`ifconfig ${wan} | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'` # Are we going up or down? case $OP in up) - ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up + ifconfig ${vif} 10.255.255.1 netmask 255.255.255.255 up echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp iptcmd='-A' ipcmd='a' @@ -63,14 +82,16 @@ ;; esac -if [ ${ip} ] ; then +# Packet filtering +match_mac="-m mac --mac-source ${mac}" +if [ "${ip}" ] ; then - # If we've been given a list of IP networks, allow pkts with these src addrs. - for addr in ${ip} ; do - ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip} -# iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT - done + # Forward only packets with source IP's matching domain's IP's + for addr in `echo ${ip}` ; do + ( ip r ${ipcmd} ${addr} dev ${vif} &>/dev/null ) + iptables ${iptcmd} FORWARD ${match_mac} -s ${addr} -j ACCEPT + done - # Always allow us to talk to a DHCP server anyhow. -# iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT + # Drop other packets + iptables ${iptcmd} FORWARD ${match_mac} -j DROP fi --=====================_1638516093==_ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=====================_1638516093==_--