New version of the vif linux hotplug scripts improvements
Hopefully I addressed all the comments on the previous version.
Passing of additional params to those hoteplug scripts (for ipv6_allow_ra and proxy_ndp) is still pending.
Cheers,
Sylvain Munaut
PATCH 1/5 hotplug/linux: Fix the vif script to handle_iptable for tap interfaces
The TAP interfaces need the same iptables rules as the VIF, without it, traffic will not be forwarded to/from them is the default FORWARD policy is DROP/REJECT
--- tools/hotplug/Linux/vif-bridge | 4 +--- tools/hotplug/Linux/vif-common.sh | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-)
tools/hotplug/Linux/vif-bridge +1 -3
@@ -97,9 +97,7 @@ case "$command" in ;; esac -if [ "$type_if" = vif ]; then - handle_iptable -fi +handle_iptable call_hooks vif post
tools/hotplug/Linux/vif-common.sh +2 -2
@@ -123,7 +123,7 @@ ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") frob_iptable() { - if [ "$command" == "online" ] + if [ "$command" == "online" -o "$command" == "add" ] then local c="-I" else
@@ -135,7 +135,7 @@ frob_iptable() iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-out "$dev" \ -j ACCEPT 2>/dev/null - if [ "$command" == "online" -a $? -ne 0 ] + if [ \( "$command" == "online" -o "$command" == "add" \) -a $? -ne 0 ] then log err "iptables setup failed. This may affect guest networking." fi
Signature · 1 line
1.7.10.4
Re: [PATCH 1/5] hotplug/linux: Fix the vif script to handle_iptable for tap interfaces
Quoted 5 lines · Sylvain Munaut
The TAP interfaces need the same iptables rules as the VIF, without it, traffic will not be forwarded to/from them is the default FORWARD policy is DROP/REJECT
Signed-off-by Sylvain Munaut <[email protected]>
and applied, thanks.
PATCH 2/5 hotplug/linux: Improve iptables logic
In reply to Sylvain MunautThe main goal of this is to pave the way for IPv6 support, but it also improves the rules by preventing duplicate incoming packets rules to be added.
frob_iptables now takes a list of address to handle as parameter and creates the rules as needed. Any 'common' rule is no longer repeated.
Here below is a comparaison of the rules before / after.
<*> For the case where 'ip' is empty or not given at all:
Previous:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif87.0 --physdev-is-bridged
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif87.0 --physdev-is-bridged
New:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif88.0 --physdev-is-bridged
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif88.0 --physdev-is-bridged
<*> For the case where 'ip' is set to "192.168.0.254 192.168.0.141" (as an example) :
Previous:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif86.0 --physdev-is-bridged
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif86.0 --physdev-is-bridged udp spt:68 dpt:67
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif86.0 --physdev-is-bridged
ACCEPT all 192.168.0.141 0.0.0.0/0 PHYSDEV match --physdev-in
vif86.0 --physdev-is-bridged
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif86.0 --physdev-is-bridged
ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in
vif86.0 --physdev-is-bridged
New:
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif89.0 --physdev-is-bridged udp spt:68 dpt:67
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif89.0 --physdev-is-bridged
ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in
vif89.0 --physdev-is-bridged
ACCEPT all 192.168.0.141 0.0.0.0/0 PHYSDEV match --physdev-in
vif89.0 --physdev-is-bridged
--- tools/hotplug/Linux/vif-common.sh | 64 ++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 15 deletions(-)
tools/hotplug/Linux/vif-common.sh +49 -15
@@ -123,6 +123,10 @@ ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") frob_iptable() { + local has_err="no" + local has_any="no" + + # Add or remove if [ "$command" == "online" -o "$command" == "add" ] then local c="-I"
@@ -130,16 +134,40 @@ frob_iptable() local c="-D" fi - iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ - "$@" -j ACCEPT 2>/dev/null && + # Add rules for each address + local addr + + for addr in $@; do + if [ "$addr" = "any" ]; then + addr="0.0.0.0/0" + has_any="yes" + fi + + iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -s "$addr" -j ACCEPT 2>/dev/null || has_err="yes" + done + + # Always Allow all packets _to_ the domain iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-out "$dev" \ - -j ACCEPT 2>/dev/null + -j ACCEPT 2>/dev/null || has_err="yes" - if [ \( "$command" == "online" -o "$command" == "add" \) -a $? -ne 0 ] + # If 'any' isn't allowed, we needs to allow a few more things + if [ "$has_any" != "yes" ] + then + + # Always allow the domain to talk to a DHCP server. + iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p udp --sport 68 --dport 67 -j ACCEPT 2>/dev/null || has_err="yes" + + fi + + # Error handling + if [ \( "$command" == "online" -o "$command" == "add" \) -a "$has_err" == "yes" ] then log err "iptables setup failed. This may affect guest networking." fi } +} ##
@@ -160,21 +188,27 @@ handle_iptable() return fi - claim_lock "iptables" + # Scan through the addresses + local ipv4_addrs if [ "$ip" != "" ] then - local addr - for addr in $ip - do - frob_iptable -s "$addr" - done - - # Always allow the domain to talk to a DHCP server. - frob_iptable -p udp --sport 68 --dport 67 + local addr + for addr in $ip + do + ipv4_addrs="$addr $ipv4_addrs" + done else - # No IP addresses have been specified, so allow anything. - frob_iptable + # No IP addresses have been specified, so allow anything. + ipv4_addrs="any" + fi + + # Actually add the rules + claim_lock "iptables" + + if [ "$ipv4_addrs" != "" ] + then + frob_iptable $ipv4_addrs fi release_lock "iptables"
Signature · 1 line
1.7.10.4
Re: [PATCH 2/5] hotplug/linux: Improve iptables logic
Quoted 9 lines · Sylvain Munaut
The main goal of this is to pave the way for IPv6 support, but it also improves the rules by preventing duplicate incoming packets rules to be added.
frob_iptablesnow takes a list of address to handle as parameter and creates the rules as needed. Any 'common' rule is no longer repeated.Here below is a comparaison of the rules before / after.
"comparison"
Quoted 9 lines
<*> For the case where 'ip' is empty or not given at all:
Previous:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif87.0 --physdev-is-bridged
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif87.0 --physdev-is-bridged
Quoted 7 lines
New:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif88.0 --physdev-is-bridged
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif88.0 --physdev-is-bridged
i.e. no change?
Quoted 29 lines
<*> For the case where 'ip' is set to "192.168.0.254 192.168.0.141" (as an example) :
Previous:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif86.0 --physdev-is-bridged
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif86.0 --physdev-is-bridged udp spt:68 dpt:67
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif86.0 --physdev-is-bridged
ACCEPT all 192.168.0.141 0.0.0.0/0 PHYSDEV match --physdev-in
vif86.0 --physdev-is-bridged
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif86.0 --physdev-is-bridged
ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in
vif86.0 --physdev-is-bridgedNew:
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in
vif89.0 --physdev-is-bridged udp spt:68 dpt:67
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out
vif89.0 --physdev-is-bridged
ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in
vif89.0 --physdev-is-bridged
ACCEPT all 192.168.0.141 0.0.0.0/0 PHYSDEV match --physdev-in
vif89.0 --physdev-is-bridged
Quoted 1 line
Signed-off-by Sylvain Munaut <[email protected]>
Looks good to me:
I'm going to give it a day or two for others to comment before I apply.
When I do apply I'll fix the typo, insert the answer to that question and unwrap the example lines as I go.
Thanks!
Quoted 103 lines
--- tools/hotplug/Linux/vif-common.sh | 64 ++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 15 deletions(-)tools/hotplug/Linux/vif-common.sh +49
-15@@ -123,6 +123,10 @@ ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") frob_iptable() { + local has_err="no" + local has_any="no" + + # Add or remove if [ "$command" == "online" -o "$command" == "add" ] then local c="-I"@@ -130,16 +134,40 @@ frob_iptable() local c="-D" fi - iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ - "$@" -j ACCEPT 2>/dev/null && + # Add rules for each address + local addr + + for addr in $@; do + if [ "$addr" = "any" ]; then + addr="0.0.0.0/0" + has_any="yes" + fi + + iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -s "$addr" -j ACCEPT 2>/dev/null || has_err="yes" + done + + # Always Allow all packets _to_ the domain iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-out "$dev" \ - -j ACCEPT 2>/dev/null + -j ACCEPT 2>/dev/null || has_err="yes" - if [ \( "$command" == "online" -o "$command" == "add" \) -a $? -ne 0 ] + # If 'any' isn't allowed, we needs to allow a few more things + if [ "$has_any" != "yes" ] + then + + # Always allow the domain to talk to a DHCP server. + iptables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p udp --sport 68 --dport 67 -j ACCEPT 2>/dev/null || has_err="yes" + + fi + + # Error handling + if [ \( "$command" == "online" -o "$command" == "add" \) -a "$has_err" == "yes" ] then log err "iptables setup failed. This may affect guest networking." fi } +} ##@@ -160,21 +188,27 @@ handle_iptable() return fi - claim_lock "iptables" + # Scan through the addresses + local ipv4_addrs if [ "$ip" != "" ] then - local addr - for addr in $ip - do - frob_iptable -s "$addr" - done - - # Always allow the domain to talk to a DHCP server. - frob_iptable -p udp --sport 68 --dport 67 + local addr + for addr in $ip + do + ipv4_addrs="$addr $ipv4_addrs" + done else - # No IP addresses have been specified, so allow anything. - frob_iptable + # No IP addresses have been specified, so allow anything. + ipv4_addrs="any" + fi + + # Actually add the rules + claim_lock "iptables" + + if [ "$ipv4_addrs" != "" ] + then + frob_iptable $ipv4_addrs fi release_lock "iptables"
PATCH 3/5 hotplug/linux: Add IPv6 support to the iptables logic
In reply to Sylvain MunautThis adds the same functions for ip6tables as the one for iptables. The 'ip' variable can now contain ipv6s for the domain and add appropriate rules
- If the 'ip' var is empty then both full IPv4 and IPv6 are allowed.
- If only IPv4 ips are present, then IPv6 will be completely disallowed.
- If only IPv6 ips are present, then IPv4 will be completely disallowed.
- You can use ::0/0 or 0.0.0.0/0 to allow v6 or v4 globally but filter the other one.
(see below for examples of rules generated after this patch)
This gracefully handles if the dom0 doesn't have IPv6. If the call to ip6tables doesn't succeed, it just ignores any IPv6 stuff.
By default, domains aren't allows to send Router Advertisement or DHCP responses, see the ipv6_allow_ra to enable them. This is to limit the risk of a rogue VM sending RA and DHCPv6 response to try and intercept traffic by taking advantage of unconfigured VMs (where IPv6 autoconfig is enabled by default but not used)
Examples of rules added :
* ip=""
iptables:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out vif91.0 --physdev-is-bridged
ip6tables:
DROP udp ::/0 ::/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged udp spt:547 dpt:546 DROP icmpv6 ::/0 ::/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged ipv6-icmptype 134 ACCEPT all ::/0 ::/0 PHYSDEV match --physdev-out vif91.0 --physdev-is-bridged ACCEPT all ::/0 ::/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged
* ip="192.168.0.254"
iptables:
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in vif92.0 --physdev-is-bridged udp spt:68 dpt:67 ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out vif92.0 --physdev-is-bridged ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in vif92.0 --physdev-is-bridged
ip6tables:
[nothing]
* ip="2001:aaaa:bbbb:cccc::1 eui64"
iptables:
[nothing]
ip6tables:
DROP udp ::/0 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged udp spt:547
dpt:546
DROP icmpv6 ::/0 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged ipv6-icmptype
134
ACCEPT udp ::/0 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged udp spt:546 dpt:547
ACCEPT all fe80::216:3eff:fed0:da2d/128 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged
ACCEPT all ::/0 ::/0
PHYSDEV match --physdev-out vif94.0 --physdev-is-bridged
ACCEPT all 2001:aaaa:bbbb:cccc::1/128 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged
ACCEPT all ::216:3eff:fed0:da2d/::ffff:ffff:ffff:ffff ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged
* ip="192.168.0.254 2001:aaaa:bbbb:cccc::1" (either ipv4 or ipv6 can be replaced by the 0.0.0.0/0 or ::0/0 address to allow any, the dhcp/nd rules might be redudant then).
iptables:
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged udp spt:68 dpt:67 ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out vif95.0 --physdev-is-bridged ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged
ip6tables:
DROP udp ::/0 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged udp spt:547 dpt:546 DROP icmpv6 ::/0 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged ipv6-icmptype 134 ACCEPT udp ::/0 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged udp spt:546 dpt:547 ACCEPT all fe80::216:3eff:fed0:da2d/128 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged ACCEPT all ::/0 ::/0 PHYSDEV match --physdev-out vif95.0 --physdev-is-bridged
WARNING: There is currently no way to set the ipv6_allow_ra option
Support for this will come in a later patch.
--- tools/hotplug/Linux/vif-common.sh | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
tools/hotplug/Linux/vif-common.sh +95 -0
@@ -121,6 +121,8 @@ fi ip=${ip:-} ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") +ipv6_allow_ra=$(xenstore_read_default "$XENBUS_PATH/ipv6_allow_ra" "false") + frob_iptable() { local has_err="no"
@@ -167,6 +169,79 @@ frob_iptable() log err "iptables setup failed. This may affect guest networking." fi } + +frob_ip6table() +{ + local has_err="no" + local has_any="no" + local mac=$(xenstore_read "$XENBUS_PATH/mac") + local eui64=$(echo $mac | awk '{split($1,i,":"); print xor(i[1],2) i[2] ":" i[3] "ff:fe" i[4] ":" i[5] i[6] }') + + # Add or remove + if [ "$command" == "online" -o "$command" == "add" ] + then + local c="-I" + else + local c="-D" + fi + + # Add rules for each address + local addr + + for addr in $@; do + if [ "$addr" = "any" ]; then + addr="::0/0" + has_any="yes" + elif [ "$addr" = "eui64" ]; then + addr="::$eui64/::ffff:ffff:ffff:ffff" + fi + + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -s "$addr" -j ACCEPT 2>/dev/null || has_err="yes" + done + + # Always Allow all packets _to_ the domain + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-out "$dev" \ + -j ACCEPT 2>/dev/null || has_err="yes" + + # If 'any' isn't allowed, we needs to allow a few more things + if [ "$has_any" != "yes" ] + then + + # Always allow ICMP messages from link-local addresses (for ND) + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -s "fe80::$eui64" -j ACCEPT 2>/dev/null || has_err="yes" + + # Always allow the domain to talk to a DHCP server + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p udp --sport 546 --dport 547 -j ACCEPT 2>/dev/null || has_err="yes" + + fi + + # Filter out RA and DHCP server responses if not explicitely allowed + if [ "$ipv6_allow_ra" != "true" ] + then + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p icmpv6 --icmpv6-type router-advertisement -j DROP 2>/dev/null || has_err="yes" + + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p udp --sport 547 --dport 546 -j DROP 2>/dev/null || has_err="yes" + fi + + # Error handling + if [ \( "$command" == "online" -o "$command" == "add" \) -a "$has_err" == "yes" ] + then + log err "ip6tables setup failed. This may affect guest networking." + fi +} + + +## +# Check if the given IP is IPv6 or not +# +is_ipv6() +{ + echo "$1" | awk '/:|eui64/ { print "yes" }' }
@@ -188,19 +263,34 @@ handle_iptable() return fi + # User has a working IPv4 iptables, but maybe no IPv6 support ... + local do_ipv6="yes" + + if ! ip6tables -L -n >&/dev/null + then + do_ipv6="no" + fi + # Scan through the addresses local ipv4_addrs + local ipv6_addrs if [ "$ip" != "" ] then local addr for addr in $ip do + result=$(is_ipv6 "$addr") + if [ -z "$result" ] ; then ipv4_addrs="$addr $ipv4_addrs" + else + ipv6_addrs="$addr $ipv6_addrs" + fi done else # No IP addresses have been specified, so allow anything. ipv4_addrs="any" + ipv6_addrs="any" fi # Actually add the rules
@@ -211,6 +301,11 @@ handle_iptable() frob_iptable $ipv4_addrs fi + if [ "$ipv6_addrs" != "" -a "$do_ipv6" = "yes" ] + then + frob_ip6table $ipv6_addrs + fi + release_lock "iptables" }
Signature · 1 line
1.7.10.4
Re: [PATCH 3/5] hotplug/linux: Add IPv6 support to the iptables logic
Quoted 7 lines · Sylvain Munaut
This adds the same functions for ip6tables as the one for iptables. The 'ip' variable can now contain ipv6s for the domain and add appropriate rules
- If the 'ip' var is empty then both full IPv4 and IPv6 are allowed.
- If only IPv4 ips are present, then IPv6 will be completely disallowed.
- If only IPv6 ips are present, then IPv4 will be completely disallowed.
The respective examples for these cases show "[nothing]" in the tables for the "wrong" one. I think that is correct, but I would describe it here as "will have no rules created" since "completely disallowed" would depend on the default rules being set to drop.
Quoted 9 lines
- You can use ::0/0 or 0.0.0.0/0 to allow v6 or v4 globally but filter the other one.
(see below for examples of rules generated after this patch)
This gracefully handles if the dom0 doesn't have IPv6. If the call to ip6tables doesn't succeed, it just ignores any IPv6 stuff.
Quoted 5 lines
By default, domains aren't allows to send Router Advertisement or DHCP responses, see the
ipv6_allow_rato enable them. This is to limit the risk of a rogue VM sending RA and DHCPv6 response to try and intercept traffic by taking advantage of unconfigured VMs (where IPv6 autoconfig is enabled by default but not used)
I'm still not entirely sure about differing from v4 in this way. Does anyone else have any thoughts, Ian? (See
http://bugs.xenproject.org/xen/mid/%[email protected]%3E
for my previous comments)
Other than that the proposed new rules sets look good to me.
Quoted 63 lines
Examples of rules added :
* ip=""
iptables:
ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out vif91.0 --physdev-is-bridgedip6tables:
DROP udp ::/0 ::/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged udp spt:547 dpt:546 DROP icmpv6 ::/0 ::/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged ipv6-icmptype 134 ACCEPT all ::/0 ::/0 PHYSDEV match --physdev-out vif91.0 --physdev-is-bridged ACCEPT all ::/0 ::/0 PHYSDEV match --physdev-in vif91.0 --physdev-is-bridged* ip="192.168.0.254"
iptables:
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in vif92.0 --physdev-is-bridged udp spt:68 dpt:67 ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out vif92.0 --physdev-is-bridged ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in vif92.0 --physdev-is-bridgedip6tables:
[nothing]
* ip="2001:aaaa:bbbb:cccc::1 eui64"
iptables:
[nothing]
ip6tables:
DROP udp ::/0 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged udp spt:547
dpt:546
DROP icmpv6 ::/0 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged ipv6-icmptype
134
ACCEPT udp ::/0 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged udp spt:546 dpt:547
ACCEPT all fe80::216:3eff:fed0:da2d/128 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged
ACCEPT all ::/0 ::/0
PHYSDEV match --physdev-out vif94.0 --physdev-is-bridged
ACCEPT all 2001:aaaa:bbbb:cccc::1/128 ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged
ACCEPT all ::216:3eff:fed0:da2d/::ffff:ffff:ffff:ffff ::/0
PHYSDEV match --physdev-in vif94.0 --physdev-is-bridged
Quoted 3 lines
* ip="192.168.0.254 2001:aaaa:bbbb:cccc::1" (either ipv4 or ipv6 can be replaced by the 0.0.0.0/0 or ::0/0 address to allow any, the dhcp/nd rules might be redudant then).
"redundant"
Quoted 23 lines
iptables:
ACCEPT udp 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged udp spt:68 dpt:67 ACCEPT all 0.0.0.0/0 0.0.0.0/0 PHYSDEV match --physdev-out vif95.0 --physdev-is-bridged ACCEPT all 192.168.0.254 0.0.0.0/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridgedip6tables:
DROP udp ::/0 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged udp spt:547 dpt:546 DROP icmpv6 ::/0 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged ipv6-icmptype 134 ACCEPT udp ::/0 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged udp spt:546 dpt:547 ACCEPT all fe80::216:3eff:fed0:da2d/128 ::/0 PHYSDEV match --physdev-in vif95.0 --physdev-is-bridged ACCEPT all ::/0 ::/0 PHYSDEV match --physdev-out vif95.0 --physdev-is-bridged
Quoted 2 lines
WARNING: There is currently no way to set the
ipv6_allow_raoption
Support for this will come in a later patch.
This is pending replies to
http://marc.info/?l=xen-devel&m=140058920523168
Quoted 20 lines
Signed-off-by Sylvain Munaut <[email protected]>--- tools/hotplug/Linux/vif-common.sh | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)tools/hotplug/Linux/vif-common.sh +2
-0@@ -121,6 +121,8 @@ fi ip=${ip:-} ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") +ipv6_allow_ra=$(xenstore_read_default "$XENBUS_PATH/ipv6_allow_ra" "false") + frob_iptable() { local has_err="no"
tools/hotplug/Linux/vif-common.sh frob_iptable() · line 178
Quoted 10 lines
tools/hotplug/Linux/vif-common.sh +7
-0@@ -167,6 +169,79 @@ frob_iptable() log err "iptables setup failed. This may affect guest networking." fi } + +frob_ip6table() +{ + local has_err="no" + local has_any="no" + local mac=$(xenstore_read "$XENBUS_PATH/mac") + local eui64=$(echo $mac | awk '{split($1,i,":"); print xor(i[1],2) i[2] ":" i[3] "ff:fe" i[4] ":" i[5] i[6] }')
Yowza! I think a comment with a link to
http://en.wikipedia.org/wiki/IPv6_address#Modified_EUI-64 might help here.
Quoted 33 lines
tools/hotplug/Linux/vif-common.sh +33
-0+ + # Add or remove + if [ "$command" == "online" -o "$command" == "add" ] + then + local c="-I" + else + local c="-D" + fi + + # Add rules for each address + local addr + + for addr in $@; do + if [ "$addr" = "any" ]; then + addr="::0/0" + has_any="yes" + elif [ "$addr" = "eui64" ]; then + addr="::$eui64/::ffff:ffff:ffff:ffff" + fi + + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -s "$addr" -j ACCEPT 2>/dev/null || has_err="yes" + done + + # Always Allow all packets _to_ the domain + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-out "$dev" \ + -j ACCEPT 2>/dev/null || has_err="yes" + + # If 'any' isn't allowed, we needs to allow a few more things + if [ "$has_any" != "yes" ] + then + + # Always allow ICMP messages from link-local addresses (for ND)
tools/hotplug/Linux/vif-common.sh frob_iptable() · line 221
Quoted 10 lines
tools/hotplug/Linux/vif-common.sh +10
-0+ ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -s "fe80::$eui64" -j ACCEPT 2>/dev/null || has_err="yes" + + # Always allow the domain to talk to a DHCP server + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p udp --sport 546 --dport 547 -j ACCEPT 2>/dev/null || has_err="yes" + + fi + + # Filter out RA and DHCP server responses if not explicitely allowed
"explicitly".
Quoted 62 lines
tools/hotplug/Linux/vif-common.sh +38
-0+ if [ "$ipv6_allow_ra" != "true" ] + then + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p icmpv6 --icmpv6-type router-advertisement -j DROP 2>/dev/null || has_err="yes" + + ip6tables "$c" FORWARD -m physdev --physdev-is-bridged --physdev-in "$dev" \ + -p udp --sport 547 --dport 546 -j DROP 2>/dev/null || has_err="yes" + fi + + # Error handling + if [ \( "$command" == "online" -o "$command" == "add" \) -a "$has_err" == "yes" ] + then + log err "ip6tables setup failed. This may affect guest networking." + fi +} + + +## +# Check if the given IP is IPv6 or not +# +is_ipv6() +{ + echo "$1" | awk '/:|eui64/ { print "yes" }' }@@ -188,19 +263,34 @@ handle_iptable() return fi + # User has a working IPv4 iptables, but maybe no IPv6 support ... + local do_ipv6="yes" + + if ! ip6tables -L -n >&/dev/null + then + do_ipv6="no" + fi + # Scan through the addresses local ipv4_addrs + local ipv6_addrs if [ "$ip" != "" ] then local addr for addr in $ip do + result=$(is_ipv6 "$addr") + if [ -z "$result" ] ; then ipv4_addrs="$addr $ipv4_addrs" + else + ipv6_addrs="$addr $ipv6_addrs" + fi done else # No IP addresses have been specified, so allow anything. ipv4_addrs="any" + ipv6_addrs="any" fi # Actually add the rules
tools/hotplug/Linux/vif-common.sh handle_iptable() · line 304
Quoted 4 lines
tools/hotplug/Linux/vif-common.sh +1
-0@@ -211,6 +301,11 @@ handle_iptable() frob_iptable $ipv4_addrs fi + if [ "$ipv6_addrs" != "" -a "$do_ipv6" = "yes" ]
I think if ipv6_addrs != "" or "any" (or $ip !+ "" if you prefer) and do_ipv6 == no then a warning would be appropriate, something similar to the "ip6tables setup failed. This may affect guest networking." one (although best make it different to be distinct. "ip6table not present. This may ..." ?)
Quoted 7 lines
tools/hotplug/Linux/vif-common.sh +4
-0+ then + frob_ip6table $ipv6_addrs + fi + release_lock "iptables" }
PATCH 4/5 hotplug/linux: Add IPv6 support to vif-route
In reply to Sylvain Munaut--- tools/hotplug/Linux/vif-common.sh | 33 +++++++++++++++++++++++++++++++++ tools/hotplug/Linux/vif-route | 20 +++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
tools/hotplug/Linux/vif-common.sh +33 -0
@@ -342,3 +342,36 @@ dom0_ip() fi echo "$result" } + + +## +# ip6_of interface +# +# Print the first IPv6 address currently in use at the given interface, or nothing if +# the interface is not up. +# +ip6_of() +{ + ip -6 -o addr show primary dev "$1" scope global | awk '$3 == "inet6" {split($4,i,"/"); print i[1]; exit}' +} + + +## +# dom0_ip6 +# +# Print the IPv6 address of the interface in dom0 through which we are routing. +# This is the IP address on the interface specified as "netdev" as a parameter +# to these scripts, or eth0 by default. This function will return nothing if no +# such interface could be found. +# +dom0_ip6() +{ + local nd=${netdev:-eth0} + local result=$(ip6_of "$nd") + if [ -z "$result" ] + then + "" + else + echo "$result" + fi +}
tools/hotplug/Linux/vif-route +19 -1
@@ -24,11 +24,21 @@ dir=$(dirname "$0") . "${dir}/vif-common.sh" main_ip=$(dom0_ip) +main_ip6=$(dom0_ip6) + +proxy_ndp=$(xenstore_read_default "$XENBUS_PATH/proxy_ndp" "off") + case "${command}" in online) ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp + if [ ! -z "${main_ip6}" ]; then + ip -6 addr add ${main_ip6} dev ${vif} + if [ "${proxy_ndp}" != "off" ]; then + echo 1 >/proc/sys/net/ipv6/conf/${vif}/proxy_ndp + fi + fi ipcmd='add' cmdprefix='' ;;
@@ -43,7 +53,15 @@ if [ "${ip}" ] ; then # If we've been given a list of IP addresses, then add routes from dom0 to # the guest using those addresses. for addr in ${ip} ; do - ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} + result=$(is_ipv6 "${addr}") + if [ -z "${result}" ] ; then + ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} + else + ${cmdprefix} ip -6 route ${ipcmd} ${addr} dev ${vif} src ${main_ip6} + if [ "${proxy_ndp}" != "off" ]; then + ${cmdprefix} ip -6 neighbor ${ipcmd} proxy ${addr} dev ${netdev:-eth0} + fi + fi done fi
Signature · 1 line
1.7.10.4
Re: [PATCH 4/5] hotplug/linux: Add IPv6 support to vif-route
Quoted 1 line · Sylvain Munaut
Signed-off-by Sylvain Munaut <[email protected]>
Seems reasonable: Acked-by: Ian Campbell <[email protected]>
Quoted 89 lines
--- tools/hotplug/Linux/vif-common.sh | 33 +++++++++++++++++++++++++++++++++ tools/hotplug/Linux/vif-route | 20 +++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)tools/hotplug/Linux/vif-common.sh +33
-0@@ -342,3 +342,36 @@ dom0_ip() fi echo "$result" } + + +## +# ip6_of interface +# +# Print the first IPv6 address currently in use at the given interface, or nothing if +# the interface is not up. +# +ip6_of() +{ + ip -6 -o addr show primary dev "$1" scope global | awk '$3 == "inet6" {split($4,i,"/"); print i[1]; exit}' +} + + +## +# dom0_ip6 +# +# Print the IPv6 address of the interface in dom0 through which we are routing. +# This is the IP address on the interface specified as "netdev" as a parameter +# to these scripts, or eth0 by default. This function will return nothing if no +# such interface could be found. +# +dom0_ip6() +{ + local nd=${netdev:-eth0} + local result=$(ip6_of "$nd") + if [ -z "$result" ] + then + "" + else + echo "$result" + fi +}tools/hotplug/Linux/vif-route +19
-1@@ -24,11 +24,21 @@ dir=$(dirname "$0") . "${dir}/vif-common.sh" main_ip=$(dom0_ip) +main_ip6=$(dom0_ip6) + +proxy_ndp=$(xenstore_read_default "$XENBUS_PATH/proxy_ndp" "off") + case "${command}" in online) ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp + if [ ! -z "${main_ip6}" ]; then + ip -6 addr add ${main_ip6} dev ${vif} + if [ "${proxy_ndp}" != "off" ]; then + echo 1 >/proc/sys/net/ipv6/conf/${vif}/proxy_ndp + fi + fi ipcmd='add' cmdprefix='' ;;@@ -43,7 +53,15 @@ if [ "${ip}" ] ; then # If we've been given a list of IP addresses, then add routes from dom0 to # the guest using those addresses. for addr in ${ip} ; do - ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} + result=$(is_ipv6 "${addr}") + if [ -z "${result}" ] ; then + ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} + else + ${cmdprefix} ip -6 route ${ipcmd} ${addr} dev ${vif} src ${main_ip6} + if [ "${proxy_ndp}" != "off" ]; then + ${cmdprefix} ip -6 neighbor ${ipcmd} proxy ${addr} dev ${netdev:-eth0} + fi + fi done fi
PATCH 5/5 docs: Update the xl network config documentation with IPv6 support
In reply to Sylvain Munaut--- docs/misc/xl-network-configuration.markdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
docs/misc/xl-network-configuration.markdown +15 -0
@@ -128,6 +128,21 @@ configured. A typically behaviour (exhibited by the example hotplug scripts) if set might be to configure firewall rules to allow only the specified IP address to be used by the guest (blocking all others). +The linux hotplug script supports both IPv4 and IPv6 in this field. When +the field is omitted or empty, both will be fully allowed. If only IPv4s +are listed, then IPv6 will be blocked completely. Symetrically, if only +IPv6s are listed, then IPv4 will be blocked. If you wish to filter one +but not the other, you can use the wildcard addresses 0.0.0.0/0 and +::0/0 for IPv4/6 respectively. + +As a special case, you can use 'eui64' token as an IPv6 address and this +will allow traffic all traffic from the VM where the lower 64 bits are +matched against the EUI64 generated from the mac address of the VIF. It +is up to the network administrator to filter the network part of the +address globally if necessary. This is of course only usable for the +vif-bridge script as the vif-route will require a fully defined address +in the 'ip' field. + ### backend Specifies the backend domain which this device should attach to. This
Signature · 1 line
1.7.10.4
Re: [PATCH 5/5] docs: Update the xl network config documentation with IPv6 support
Quoted 10 lines · Sylvain Munaut
Signed-off-by Sylvain Munaut <[email protected]>--- docs/misc/xl-network-configuration.markdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+)docs/misc/xl-network-configuration.markdown +0
-0
docs/misc/xl-network-configuration.markdown configured. A typically behaviour (exhibited by the example hotplug · line 133
Quoted 6 lines
docs/misc/xl-network-configuration.markdown +3
-0@@ -128,6 +128,21 @@ configured. A typically behaviour (exhibited by the example hotplug scripts) if set might be to configure firewall rules to allow only the specified IP address to be used by the guest (blocking all others). +The linux hotplug script supports both IPv4 and IPv6 in this field. When +the field is omitted or empty, both will be fully allowed. If only IPv4s +are listed, then IPv6 will be blocked completely. Symetrically, if only
"Symmetrically"
docs/misc/xl-network-configuration.markdown configured. A typically behaviour (exhibited by the example hotplug · line 140
Quoted 7 lines
docs/misc/xl-network-configuration.markdown +7
-0+IPv6s are listed, then IPv4 will be blocked. If you wish to filter one +but not the other, you can use the wildcard addresses 0.0.0.0/0 and +::0/0 for IPv4/6 respectively. + +As a special case, you can use 'eui64' token as an IPv6 address and this +will allow traffic all traffic from the VM where the lower 64 bits are +matched against the EUI64 generated from the mac address of the VIF. It
If you say [EUI64] then at the end you can say:
[EUI64]: http://en.wikipedia.org/wiki/IPv6_address#Modified_EUI-64
(assuming this is what was implemented and not "normal" EUI-64, whatever that is)
I think it would be reasonable to fold this into the patch which adds this functionality, but I'm happy with it remaining separate too.
Quoted 8 lines
docs/misc/xl-network-configuration.markdown +5
-0+is up to the network administrator to filter the network part of the +address globally if necessary. This is of course only usable for the +vif-bridge script as the vif-route will require a fully defined address +in the 'ip' field. + ### backend Specifies the backend domain which this device should attach to. This
Quoted 1 line · Sylvain Munaut
Hopefully I addressed all the comments on the previous version.
Just a silly procedural note but it is useful to include a version number in the $subject, e.g. [PATCH v2]. git send-email --reroll-count=2 will do that for you for the patches themselves. Otherwise v3 ends up as "Yet another new ..." or something ;-)
If you could CC the maintainers too then that would be great. pipe the patch to "./scripts/get_maintainer.pl" and it will tell you who.
I'm going to go check that
http://wiki.xen.org/wiki/Submitting_Xen_Patches reflects all this..
Ian.