Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IPv6 support in globalzone #503

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions overlay/generic/lib/svc/method/identity-node
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,33 @@ fi
# Reloading sysinfo here serves two purposes:
# - getting the IP info (which should exist now)
# - updating the host info (which we just set)
# - ndp needs some time to stabilize to get addrconf
[ -n "$CONFIG_admin_ip6" ] && sleep 3
eval $(/usr/bin/sysinfo -f -p | sed -e "s/^/SYSINFO_/")

# Try to add the /etc/hosts entry if we can find an IP
if [[ -n ${SYSINFO_NIC_admin} ]]; then
eval "ipaddr=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_IPv4_Address}"
eval "ip4addr=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_IPv4_Address}"
eval "ip6addr=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_IPv6_Address}"
fi
if [[ -z ${ipaddr} ]]; then
ipaddr=$(set | grep "^SYSINFO_Network_Interface_.*_IPv4_Address" | head -n1 | cut -d'=' -f2)
if [[ -z ${ip4addr} ]]; then
ip4addr=$(set | grep "^SYSINFO_Network_Interface_.*_IPv4_Address" | head -n1 | cut -d'=' -f2)
# empty values end up as '' sometimes, so we clear them
[[ "${ip4addr}" == "''" ]] && unset ip4addr
fi
if [[ -n ${ipaddr} ]]; then
if [[ -z ${ip6addr} ]]; then
ip6addr=$(set | grep "^SYSINFO_Network_Interface_.*_IPv6_Address" | head -n1 | cut -d'=' -f2)
# empty values end up as '' sometimes, so we clear them
[[ "${ip6addr}" == "''" ]] && unset ip6addr
fi
if [[ -n ${ip4addr} ]] || [[ -n ${ip6addr} ]]; then
fullname=""

if [ -n "$CONFIG_dns_domain" ]; then
fullname=" ${hostname}.${CONFIG_dns_domain}"
fi

printf "${ipaddr}\t${hostname}${fullname}\n" >> /etc/hosts
[[ -n ${ip4addr} ]] && printf "${ip4addr}\t${hostname}${fullname}\n" >> /etc/hosts
[[ -n ${ip6addr} ]] && printf "${ip6addr}\t${hostname}${fullname}\n" >> /etc/hosts
fi

# Reset the library path now that we are past the critical stage
Expand Down
74 changes: 74 additions & 0 deletions overlay/generic/lib/svc/method/svc-ndp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"

. /lib/svc/share/smf_include.sh
. /lib/svc/share/routing_include.sh

smf_configure_ip || exit $SMF_EXIT_OK

daemon_args=`get_daemon_args $SMF_FMRI`
options="adtf:"

#
# Handle upgrade - routing/daemon-args property must be mapped to properties
# in routeadm property group. Note that the SMF-incompatible -t option is not
# supported, since it requires that in.ndpd run in the foreground.
#
if [ -n "$daemon_args" ]; then
set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
"$options" "a" stateless_addr_conf false true
set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
"$options" "d" debug true false
set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
"$options" "f" config_file
clear_daemon_args $SMF_FMRI
fi

#
# Assemble arguments to daemon from properties
#
args="`get_daemon_option_from_boolean_property $SMF_FMRI stateless_addr_conf \
a false`"
args="$args`get_daemon_option_from_boolean_property $SMF_FMRI debug d true`"
if [ -n "$args" ]; then
args="-${args}"
fi
args="$args `get_daemon_option_from_property $SMF_FMRI config_file f`"


/usr/lib/inet/in.ndpd $args

# update the sysinfo cache, ndp potentially has made some network changes
# - wait for ndp to stabilize, 3 seconds seems to be the sweet spot
if smf_is_globalzone; then
sleep 3
/usr/bin/sysinfo -u
fi

[ "$?" = 0 ] || exit $SMF_EXIT_ERR_FATAL

exit $SMF_EXIT_OK
1 change: 1 addition & 0 deletions overlay/generic/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ f lib/svc/method/manifest-import 0555 root bin
f lib/svc/method/mdata-execute 0555 root bin
f lib/svc/method/mdata-fetch 0555 root bin
f lib/svc/method/net-physical 0555 root sys
f lib/svc/method/svc-ndp 0555 root sys
f lib/svc/method/smartdc-config 0555 root bin
f lib/svc/method/smartdc-init 0555 root sys
f lib/svc/method/smartdc-ur 0555 root bin
Expand Down
24 changes: 24 additions & 0 deletions src/sysinfo
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ function get_smartos_network_interfaces()
mac=${normalized}
ip4addr=$(ifconfig ${iface} 2>/dev/null \
| grep "inet " | awk '{ print $2 }')
ip6addr=$(ifconfig ${iface}:1 inet6 2> /dev/null \
| grep "inet6 " | awk '{ print $2 }' \
| awk -F/ '{ print $1 }')

nic_tag_count=0
while [[ ${nic_tag_count} -lt ${NicTagCount} ]]; do
Expand All @@ -372,6 +375,7 @@ function get_smartos_network_interfaces()
NetworkInterfaces[${count}]=${iface}
eval "Network_Interface_${iface}_MAC_Address=${mac}"
eval "Network_Interface_${iface}_IPv4_Address=${ip4addr}"
eval "Network_Interface_${iface}_IPv6_Address=${ip6addr}"
if [[ -n ${nicnames} ]]; then
eval "Network_Interface_${iface}_NIC_Names=${nicnames}"
fi
Expand Down Expand Up @@ -437,6 +441,9 @@ function get_smartos_network_interfaces()

ip4addr=$(ifconfig ${iface} 2>/dev/null \
| grep "inet " | awk '{ print $2 }')
ip6addr=$(ifconfig ${iface}:1 inet6 2> /dev/null \
| grep "inet6 " | awk '{ print $2 }' \
| awk -F/ '{ print $1 }')

nic_tag_count=0
while [[ ${nic_tag_count} -lt ${NicTagCount} ]]; do
Expand All @@ -457,6 +464,7 @@ function get_smartos_network_interfaces()
normalize_mac $(echo ${mac} | sed 's/\|/:/g')
eval "Network_Interface_${iface}_MAC_Address=${normalized}"
eval "Network_Interface_${iface}_IPv4_Address=${ip4addr}"
eval "Network_Interface_${iface}_IPv6_Address=${ip6addr}"
if [[ -n ${nicnames} ]]; then
eval "Network_Interface_${iface}_NIC_Names=${nicnames}"
fi
Expand Down Expand Up @@ -492,9 +500,13 @@ function get_smartos_vnics()
link_status=$(pfexec /sbin/dladm show-link -p -o state ${iface})
ip4addr=$(ifconfig ${iface} 2>/dev/null \
| grep "inet " | awk '{ print $2 }')
ip6addr=$(ifconfig ${iface}:1 inet6 2> /dev/null \
| grep "inet6 " | awk '{ print $2 }' \
| awk -F/ '{ print $1 }')
VirtualNetworkInterfaces[${count}]=${iface}
eval "Virtual_Network_Interface_${iface}_MAC_Address=${mac}"
eval "Virtual_Network_Interface_${iface}_IPv4_Address=${ip4addr}"
eval "Virtual_Network_Interface_${iface}_IPv6_Address=${ip6addr}"
eval "Virtual_Network_Interface_${iface}_Link_Status=${link_status}"
eval "Virtual_Network_Interface_${iface}_VLAN=${vlan}"
eval "Virtual_Network_Interface_${iface}_Host_Interface=${over}"
Expand Down Expand Up @@ -687,19 +699,22 @@ END
for iface in "${NetworkInterfaces[@]}"; do
mac_var="Network_Interface_${iface}_MAC_Address"
ipv4_var="Network_Interface_${iface}_IPv4_Address"
ipv6_var="Network_Interface_${iface}_IPv6_Address"
nicnames_var="Network_Interface_${iface}_NIC_Names"
link_status_var="Network_Interface_${iface}_Link_Status"
detected_tag_var="Network_Interface_${iface}_Detected_Nic_Tag"

eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "ipv6=\${${ipv6_var}}"
eval "nicnames=\${${nicnames_var}}"
link_status="unknown"
eval "link_status=\${${link_status_var}}"
eval "detected_tag=\${${detected_tag_var}}"

echo "${mac_var}='${mac}'"
echo "${ipv4_var}='${ipv4}'"
echo "${ipv6_var}='${ipv6}'"
echo "${nicnames_var}='${nicnames}'"
echo "${link_status_var}='${link_status}'"
if [[ -n "${detected_tag}" ]] ; then
Expand All @@ -710,18 +725,21 @@ END
for iface in "${VirtualNetworkInterfaces[@]}"; do
mac_var="Virtual_Network_Interface_${iface}_MAC_Address"
ipv4_var="Virtual_Network_Interface_${iface}_IPv4_Address"
ipv6_var="Virtual_Network_Interface_${iface}_IPv6_Address"
link_status_var="Virtual_Network_Interface_${iface}_Link_Status"
vlan_var="Virtual_Network_Interface_${iface}_VLAN"
host_var="Virtual_Network_Interface_${iface}_Host_Interface"

eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "ipv6=\${${ipv6_var}}"
eval "link_status=\${${link_status_var}}"
eval "vlan=\${${vlan_var}}"
eval "host=\${${host_var}}"

echo "${mac_var}='${mac}'"
echo "${ipv4_var}='${ipv4}'"
echo "${ipv6_var}='${ipv6}'"
echo "${link_status_var}='${link_status}'"
echo "${vlan_var}='${vlan}'"
if [[ ${ZONENAME} == "global" ]]; then
Expand Down Expand Up @@ -862,6 +880,7 @@ END
for iface in "${NetworkInterfaces[@]}"; do
mac_var="Network_Interface_${iface}_MAC_Address"
ipv4_var="Network_Interface_${iface}_IPv4_Address"
ipv6_var="Network_Interface_${iface}_IPv6_Address"
nicnames_var="Network_Interface_${iface}_NIC_Names"
link_status_var="Network_Interface_${iface}_Link_Status"
detected_tag_var="Network_Interface_${iface}_Detected_Nic_Tag"
Expand All @@ -870,6 +889,7 @@ END

eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "ipv6=\${${ipv6_var}}"
eval "nicnames=\${${nicnames_var}}"
eval "link_status=\${${link_status_var}}"
eval "detected_tag=\${${detected_tag_var}}"
Expand All @@ -889,6 +909,7 @@ END
echo -n " \"${iface}\": {"
echo -n "\"MAC Address\": \"${mac}\", "
echo -n "\"ip4addr\": \"${ipv4}\", "
echo -n "\"ip6addr\": \"${ipv6}\", "
echo -n "\"Link Status\": \"${link_status}\", "
echo -n "${detected_fmt}"
echo -n "\"NIC Names\": [${nic_names_fmt}]}"
Expand All @@ -905,12 +926,14 @@ END
for iface in "${VirtualNetworkInterfaces[@]}"; do
mac_var="Virtual_Network_Interface_${iface}_MAC_Address"
ipv4_var="Virtual_Network_Interface_${iface}_IPv4_Address"
ipv6_var="Virtual_Network_Interface_${iface}_IPv6_Address"
link_status_var="Virtual_Network_Interface_${iface}_Link_Status"
vlan_var="Virtual_Network_Interface_${iface}_VLAN"
parent_var="Virtual_Network_Interface_${iface}_Host_Interface"

eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "ipv6=\${${ipv6_var}}"
eval "link_status=\${${link_status_var}}"
eval "vlan=\${${vlan_var}}"
eval "host=\${${host_var}}"
Expand All @@ -922,6 +945,7 @@ END
echo -n " \"${iface}\": {"
echo -n "\"MAC Address\": \"${mac}\", "
echo -n "\"ip4addr\": \"${ipv4}\", "
echo -n "\"ip6addr\": \"${ipv6}\", "
echo -n "\"Link Status\": \"${link_status}\", "
if [[ ${ZONENAME} == "global" ]]; then
echo -n "\"Host Interface\": \"${host}\", "
Expand Down