summaryrefslogtreecommitdiff
path: root/usr/src/cmd/svc/shell
diff options
context:
space:
mode:
authorAnurag S. Maskey <Anurag.Maskey@Sun.COM>2010-02-25 22:05:58 -0500
committerAnurag S. Maskey <Anurag.Maskey@Sun.COM>2010-02-25 22:05:58 -0500
commit6ba597c56d749c61b4f783157f63196d7b2445f0 (patch)
treef723e502e6a07690117ebc91df6130954ea29fb3 /usr/src/cmd/svc/shell
parent07377e5e51e2e8f6251029c3b5808547d9d1c54d (diff)
downloadillumos-joyent-6ba597c56d749c61b4f783157f63196d7b2445f0.tar.gz
PSARC/2008/532 NWAM Phase 1
PSARC/2009/577 Network Auto-Magic (NWAM) Phase 1 Updates PSARC/2010/049 Network Auto-Magic (NWAM) Phase 1 Updates part 2 4087814 User friendly utility wanted for network config, able to add network interfaces. 6509720 support configuration using DHCP "inform" and static IP address 6553627 network/physical:default and network/physical:nwam should be mutually-exclusive (perhaps a property) 6609581 nwam does not start the dns/client service after configuring the network 6664072 nwam profiles should include name service configuration properties 6723947 setting static MAC address should be possible 6794043 NWAM needs more complete profile support 6914190 Support for unmanaged network interfaces in NWAM - hands off 6921971 nwamd fails to run teardown/net-svc after suspend/resume --HG-- rename : usr/src/cmd/cmd-inet/lib/nwamd/interface.c => usr/src/cmd/cmd-inet/lib/nwamd/ncu_ip.c rename : usr/src/cmd/cmd-inet/lib/nwamd/wireless.c => usr/src/cmd/cmd-inet/lib/nwamd/ncu_phys.c rename : usr/src/cmd/cmd-inet/lib/nwamd/events.c => usr/src/cmd/cmd-inet/lib/nwamd/routing_events.c rename : usr/src/cmd/cmd-inet/lib/nwamd/functions.h => usr/src/cmd/cmd-inet/lib/nwamd/util.h
Diffstat (limited to 'usr/src/cmd/svc/shell')
-rw-r--r--usr/src/cmd/svc/shell/ipf_include.sh21
-rw-r--r--usr/src/cmd/svc/shell/net_include.sh112
2 files changed, 128 insertions, 5 deletions
diff --git a/usr/src/cmd/svc/shell/ipf_include.sh b/usr/src/cmd/svc/shell/ipf_include.sh
index b55cd6385e..3f2e53cfc5 100644
--- a/usr/src/cmd/svc/shell/ipf_include.sh
+++ b/usr/src/cmd/svc/shell/ipf_include.sh
@@ -20,14 +20,27 @@
# CDDL HEADER END
#
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+IPFILTER_FMRI="svc:/network/ipfilter:default"
ETC_IPF_DIR=/etc/ipf
-IP6FILCONF=$ETC_IPF_DIR/ipf6.conf
-IPNATCONF=$ETC_IPF_DIR/ipnat.conf
-IPPOOLCONF=$ETC_IPF_DIR/ippool.conf
+IP6FILCONF=`/usr/bin/svcprop -p config/ipf6_config_file $IPFILTER_FMRI \
+ 2>/dev/null`
+if [ $? -eq 1 ]; then
+ IP6FILCONF=$ETC_IPF_DIR/ipf6.conf
+fi
+IPNATCONF=`/usr/bin/svcprop -p config/ipnat_config_file $IPFILTER_FMRI \
+ 2>/dev/null`
+if [ $? -eq 1 ]; then
+ IPNATCONF=$ETC_IPF_DIR/ipnat.conf
+fi
+IPPOOLCONF=`/usr/bin/svcprop -p config/ippool_config_file $IPFILTER_FMRI \
+ 2>/dev/null`
+if [ $? -eq 1 ]; then
+ IPPOOLCONF=$ETC_IPF_DIR/ippool.conf
+fi
VAR_IPF_DIR=/var/run/ipf
IPFILCONF=$VAR_IPF_DIR/ipf.conf
IPFILOVRCONF=$VAR_IPF_DIR/ipf_ovr.conf
diff --git a/usr/src/cmd/svc/shell/net_include.sh b/usr/src/cmd/svc/shell/net_include.sh
index 84376a981b..cbc5b051b5 100644
--- a/usr/src/cmd/svc/shell/net_include.sh
+++ b/usr/src/cmd/svc/shell/net_include.sh
@@ -20,7 +20,7 @@
# CDDL HEADER END
#
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
@@ -710,3 +710,113 @@ update_pvid()
}
}'
}
+
+#
+# service_exists fmri
+#
+# returns success (0) if the service exists, 1 otherwise.
+#
+service_exists()
+{
+ /usr/sbin/svccfg -s $1 listpg > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ return 0;
+ fi
+ return 1;
+}
+
+#
+# service_is_enabled fmri
+#
+# returns success (0) if the service is enabled (permanently or
+# temporarily), 1 otherwise.
+#
+service_is_enabled()
+{
+ #
+ # The -c option must be specified to use the composed view
+ # because the general/enabled property takes immediate effect.
+ # See Example 2 in svcprop(1).
+ #
+ # Look at the general_ovr/enabled (if it is present) first to
+ # determine the temporarily enabled state.
+ #
+ tstate=`/usr/bin/svcprop -c -p general_ovr/enabled $1 2>/dev/null`
+ if [ $? -eq 0 ]; then
+ [ "$tstate" = "true" ] && return 0
+ return 1
+ fi
+
+ state=`/usr/bin/svcprop -c -p general/enabled $1 2>/dev/null`
+ [ "$state" = "true" ] && return 0
+ return 1
+}
+
+#
+# is_valid_v4addr addr
+#
+# Returns 0 if a valid IPv4 address is given, 1 otherwise.
+#
+is_valid_v4addr()
+{
+ echo $1 | /usr/xpg4/bin/awk 'NF != 1 { exit 1 } \
+ $1 !~ /^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}\
+ (25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$/ \
+ { exit 1 }'
+ return $?
+}
+
+#
+# is_valid_v6addr addr
+#
+# Returns 0 if a valid IPv6 address is given, 1 otherwise.
+#
+is_valid_v6addr()
+{
+ echo $1 | /usr/xpg4/bin/awk 'NF != 1 { exit 1 } \
+ # 1:2:3:4:5:6:7:8
+ $1 !~ /^([a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/ &&
+ # 1:2:3::6:7:8
+ $1 !~ /^([a-fA-F0-9]{1,4}:){0,6}:([a-fA-F0-9]{1,4}:){0,6}\
+ [a-fA-F0-9]{1,4}$/ &&
+ # 1:2:3::
+ $1 !~ /^([a-fA-F0-9]{1,4}:){0,7}:$/ &&
+ # ::7:8
+ $1 !~ /^:(:[a-fA-F0-9]{1,4}){0,6}:[a-fA-F0-9]{1,4}$/ &&
+ # ::f:1.2.3.4
+ $1 !~ /^:(:[a-fA-F0-9]{1,4}){0,5}:\
+ ((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}\
+ (25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$/ &&
+ # a:b:c:d:e:f:1.2.3.4
+ $1 !~ /^([a-fA-F0-9]{1,4}:){6}\
+ ((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}\
+ (25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$/ \
+ { exit 1 }'
+ return $?
+}
+
+#
+# is_valid_addr addr
+#
+# Returns 0 if a valid IPv4 or IPv6 address is given, 1 otherwise.
+#
+is_valid_addr()
+{
+ is_valid_v4addr $1 || is_valid_v6addr $1
+}
+
+#
+# nwam_get_loc_prop location property
+#
+# echoes the value of the property for the given location
+# return:
+# 0 => property is set
+# 1 => property is not set
+#
+nwam_get_loc_prop()
+{
+ value=`/usr/sbin/nwamcfg "select loc $1; get -V $2" 2>/dev/null`
+ rtn=$?
+ echo $value
+ return $rtn
+}