summaryrefslogtreecommitdiff
path: root/usr/src/lib/libscf
diff options
context:
space:
mode:
authorAntonello Cruz <Antonello.Cruz@Sun.COM>2010-05-24 14:14:47 -0700
committerAntonello Cruz <Antonello.Cruz@Sun.COM>2010-05-24 14:14:47 -0700
commitb56bf881a9655cb27b53cba1468312f7c6dfb0a2 (patch)
tree83afaaf2a38b5e61bff1c8702eff6b6166db2647 /usr/src/lib/libscf
parent72c9c96770c90a8042add81e56bb8a2f9e4a29dc (diff)
downloadillumos-joyent-b56bf881a9655cb27b53cba1468312f7c6dfb0a2.tar.gz
6934233 A generic net_address SMF property type would be useful.
6934227 SMF should validate net_address_v4 amd net_address_v6 property types 6954776 libnsl should not depend on libscf PSARC/2010/153 Remove libnsl dependency on libscf PSARC/2010/157 SMF networking type extensions
Diffstat (limited to 'usr/src/lib/libscf')
-rw-r--r--usr/src/lib/libscf/Makefile.com8
-rw-r--r--usr/src/lib/libscf/common/lowlevel.c5
-rw-r--r--usr/src/lib/libscf/common/mapfile-vers4
-rw-r--r--usr/src/lib/libscf/common/midlevel.c51
-rw-r--r--usr/src/lib/libscf/common/scf_type.c86
-rw-r--r--usr/src/lib/libscf/inc/libscf.h6
-rw-r--r--usr/src/lib/libscf/inc/libscf_priv.h10
7 files changed, 149 insertions, 21 deletions
diff --git a/usr/src/lib/libscf/Makefile.com b/usr/src/lib/libscf/Makefile.com
index b2f3589247..784d2ef265 100644
--- a/usr/src/lib/libscf/Makefile.com
+++ b/usr/src/lib/libscf/Makefile.com
@@ -19,8 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
#
LIBRARY = libscf.a
@@ -44,7 +43,7 @@ $(NATIVE_BUILD)VERS =
$(NATIVE_BUILD)LIBS = $(DYNLIB)
LDLIBS_i386 += -lsmbios
-LDLIBS += -luutil -lc -lgen
+LDLIBS += -luutil -lc -lgen -lnsl
LDLIBS += $(LDLIBS_$(MACH))
SRCDIR = ../common
@@ -64,7 +63,8 @@ LIBUUTIL = $(SRC)/lib/libuutil
MY_NATIVE_CPPFLAGS =\
-DNATIVE_BUILD $(DTEXTDOM) \
-I../inc -I$(COMDIR) -I$(LIBUUTIL)/common -I$(ROOTHDRDIR)
-MY_NATIVE_LDLIBS = -L$(LIBUUTIL)/native -R$(LIBUUTIL)/native -luutil -lc -lgen
+MY_NATIVE_LDLIBS = -L$(LIBUUTIL)/native -R$(LIBUUTIL)/native -luutil -lc -lgen \
+ -lnsl
MY_NATIVE_LDLIBS_i386 = -lsmbios
MY_NATIVE_LDLIBS += $(MY_NATIVE_LDLIBS_$(MACH))
diff --git a/usr/src/lib/libscf/common/lowlevel.c b/usr/src/lib/libscf/common/lowlevel.c
index 92028e610b..27136167a5 100644
--- a/usr/src/lib/libscf/common/lowlevel.c
+++ b/usr/src/lib/libscf/common/lowlevel.c
@@ -20,8 +20,7 @@
*/
/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -301,6 +300,7 @@ static const struct {
{SCF_TYPE_FMRI, REP_PROTOCOL_SUBTYPE_FMRI, "fmri"},
{SCF_TYPE_HOST, REP_PROTOCOL_SUBTYPE_HOST, "host"},
{SCF_TYPE_HOSTNAME, REP_PROTOCOL_SUBTYPE_HOSTNAME, "hostname"},
+ {SCF_TYPE_NET_ADDR, REP_PROTOCOL_SUBTYPE_NETADDR, "net_address"},
{SCF_TYPE_NET_ADDR_V4, REP_PROTOCOL_SUBTYPE_NETADDR_V4,
"net_address_v4"},
{SCF_TYPE_NET_ADDR_V6, REP_PROTOCOL_SUBTYPE_NETADDR_V6,
@@ -4845,6 +4845,7 @@ scf_value_set_from_string(scf_value_t *v, scf_type_t type, const char *str)
case SCF_TYPE_FMRI:
case SCF_TYPE_HOST:
case SCF_TYPE_HOSTNAME:
+ case SCF_TYPE_NET_ADDR:
case SCF_TYPE_NET_ADDR_V4:
case SCF_TYPE_NET_ADDR_V6:
ty = scf_type_to_protocol_type(type);
diff --git a/usr/src/lib/libscf/common/mapfile-vers b/usr/src/lib/libscf/common/mapfile-vers
index 50815efb73..b3ae93f4d1 100644
--- a/usr/src/lib/libscf/common/mapfile-vers
+++ b/usr/src/lib/libscf/common/mapfile-vers
@@ -19,8 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
@@ -318,6 +317,7 @@ SUNWprivate_1.1 {
scf_get_boot_config_ovr;
scf_is_fastboot_default;
scf_fastreboot_default_set_transient;
+ _check_services;
local:
*;
};
diff --git a/usr/src/lib/libscf/common/midlevel.c b/usr/src/lib/libscf/common/midlevel.c
index e9b8854adf..c466391761 100644
--- a/usr/src/lib/libscf/common/midlevel.c
+++ b/usr/src/lib/libscf/common/midlevel.c
@@ -256,6 +256,7 @@ fill_prop(scf_property_t *prop, const char *pgname, const char *propname,
case SCF_TYPE_USTRING:
case SCF_TYPE_HOST:
case SCF_TYPE_HOSTNAME:
+ case SCF_TYPE_NET_ADDR:
case SCF_TYPE_NET_ADDR_V4:
case SCF_TYPE_NET_ADDR_V6:
case SCF_TYPE_URI:
@@ -332,6 +333,7 @@ error1:
case SCF_TYPE_USTRING:
case SCF_TYPE_HOST:
case SCF_TYPE_HOSTNAME:
+ case SCF_TYPE_NET_ADDR:
case SCF_TYPE_NET_ADDR_V4:
case SCF_TYPE_NET_ADDR_V6:
case SCF_TYPE_URI:
@@ -1751,6 +1753,7 @@ scf_simple_prop_free(scf_simple_prop_t *prop)
case SCF_TYPE_USTRING:
case SCF_TYPE_HOST:
case SCF_TYPE_HOSTNAME:
+ case SCF_TYPE_NET_ADDR:
case SCF_TYPE_NET_ADDR_V4:
case SCF_TYPE_NET_ADDR_V6:
case SCF_TYPE_URI:
@@ -2317,6 +2320,7 @@ scf_next_val(scf_simple_prop_t *prop, scf_type_t type)
case SCF_TYPE_USTRING:
case SCF_TYPE_HOST:
case SCF_TYPE_HOSTNAME:
+ case SCF_TYPE_NET_ADDR:
case SCF_TYPE_NET_ADDR_V4:
case SCF_TYPE_NET_ADDR_V6:
case SCF_TYPE_URI:
@@ -3001,3 +3005,50 @@ out:
return (ret);
}
+
+/*
+ * Check the "application/auto_enable" property for the passed FMRI.
+ * scf_simple_prop_get() should find the property on an instance
+ * or on the service FMRI. The routine returns:
+ * -1: inconclusive (likely no such property or FMRI)
+ * 0: auto_enable is false
+ * 1: auto_enable is true
+ */
+static int
+is_auto_enabled(char *fmri)
+{
+ scf_simple_prop_t *prop;
+ int retval = -1;
+ uint8_t *ret;
+
+ prop = scf_simple_prop_get(NULL, fmri, SCF_GROUP_APPLICATION,
+ "auto_enable");
+ if (!prop)
+ return (retval);
+ ret = scf_simple_prop_next_boolean(prop);
+ retval = (*ret != 0);
+ scf_simple_prop_free(prop);
+ return (retval);
+}
+
+/*
+ * Check an array of services and enable any that don't have the
+ * "application/auto_enable" property set to "false", which is
+ * the interface to turn off this behaviour (see PSARC 2004/739).
+ */
+void
+_check_services(char **svcs)
+{
+ char *s;
+
+ for (; *svcs; svcs++) {
+ if (is_auto_enabled(*svcs) == 0)
+ continue;
+ if ((s = smf_get_state(*svcs)) != NULL) {
+ if (strcmp(SCF_STATE_STRING_DISABLED, s) == 0)
+ (void) smf_enable_instance(*svcs,
+ SMF_TEMPORARY);
+ free(s);
+ }
+ }
+}
diff --git a/usr/src/lib/libscf/common/scf_type.c b/usr/src/lib/libscf/common/scf_type.c
index 8bd83a5c44..2866c15ff0 100644
--- a/usr/src/lib/libscf/common/scf_type.c
+++ b/usr/src/lib/libscf/common/scf_type.c
@@ -20,10 +20,10 @@
*/
/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
*/
+#include <assert.h>
#include <repcache_protocol.h>
#include "scf_type.h"
#include <errno.h>
@@ -31,6 +31,10 @@
#include <libscf_priv.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#define UTF8_TOP_N(n) \
(0xff ^ (0xff >> (n))) /* top N bits set */
@@ -228,6 +232,67 @@ valid_fmri(const char *str)
return (ret);
}
+/*
+ * check_prefix()
+ * Return 1 if the prefix is a valid IPv4 or IPv6 network prefix, 0 otherwise
+ */
+static int
+check_net_prefix(const char *p, int max_len)
+{
+ char *end;
+ int len;
+
+ len = strtol(p, &end, 10);
+ if (p == end || len < 0 || len > max_len)
+ return (0);
+
+ return (1);
+}
+
+/*
+ * Return 1 if the supplied IP address is valid, 0 otherwise.
+ */
+static int
+valid_ip(int af, const char *str)
+{
+ void *unused[4];
+ const char *addr = str;
+ char buf[INET6_ADDRSTRLEN]; /* enough for both IPv4 and IPv6 */
+ char *net_prefix;
+ int buf_sz;
+ int plen;
+
+ switch (af) {
+ case AF_INET:
+ buf_sz = INET_ADDRSTRLEN;
+ plen = 32; /* bit size of an IPv4 */
+ break;
+
+ case AF_INET6:
+ buf_sz = INET6_ADDRSTRLEN;
+ plen = 128; /* bit size of an IPv6 */
+ break;
+
+ default:
+ assert(0);
+ abort();
+ }
+
+ /* check network prefix for the IP address */
+ if ((net_prefix = strchr(str, '/')) != NULL) {
+ if (check_net_prefix(++net_prefix, plen) == 0)
+ return (0);
+
+ (void) strlcpy(buf, str, buf_sz);
+ if ((net_prefix = strchr(buf, '/')) != NULL)
+ *net_prefix = '\0';
+
+ addr = buf;
+ }
+
+ return (inet_pton(af, addr, unused));
+}
+
rep_protocol_value_type_t
scf_proto_underlying_type(rep_protocol_value_type_t t)
{
@@ -252,10 +317,12 @@ scf_proto_underlying_type(rep_protocol_value_type_t t)
return (REP_PROTOCOL_SUBTYPE_USTRING);
case REP_PROTOCOL_SUBTYPE_HOSTNAME:
return (REP_PROTOCOL_SUBTYPE_HOST);
- case REP_PROTOCOL_SUBTYPE_NETADDR_V4:
+ case REP_PROTOCOL_SUBTYPE_NETADDR:
return (REP_PROTOCOL_SUBTYPE_HOST);
+ case REP_PROTOCOL_SUBTYPE_NETADDR_V4:
+ return (REP_PROTOCOL_SUBTYPE_NETADDR);
case REP_PROTOCOL_SUBTYPE_NETADDR_V6:
- return (REP_PROTOCOL_SUBTYPE_HOST);
+ return (REP_PROTOCOL_SUBTYPE_NETADDR);
case REP_PROTOCOL_TYPE_INVALID:
default:
@@ -347,17 +414,20 @@ valid_encoded_value(rep_protocol_value_type_t t, const char *v)
case REP_PROTOCOL_SUBTYPE_HOST:
return (valid_encoded_value(REP_PROTOCOL_SUBTYPE_HOSTNAME, v) ||
- valid_encoded_value(REP_PROTOCOL_SUBTYPE_NETADDR_V4, v) ||
- valid_encoded_value(REP_PROTOCOL_SUBTYPE_NETADDR_V6, v));
+ valid_encoded_value(REP_PROTOCOL_SUBTYPE_NETADDR, v));
case REP_PROTOCOL_SUBTYPE_HOSTNAME:
/* XXX check for valid hostname */
return (valid_utf8(v));
+ case REP_PROTOCOL_SUBTYPE_NETADDR:
+ return (valid_ip(AF_INET, v) || valid_ip(AF_INET6, v));
+
case REP_PROTOCOL_SUBTYPE_NETADDR_V4:
+ return (valid_ip(AF_INET, v));
+
case REP_PROTOCOL_SUBTYPE_NETADDR_V6:
- /* XXX check for valid netaddr */
- return (valid_utf8(v));
+ return (valid_ip(AF_INET6, v));
case REP_PROTOCOL_TYPE_INVALID:
default:
diff --git a/usr/src/lib/libscf/inc/libscf.h b/usr/src/lib/libscf/inc/libscf.h
index e1df3a09fa..b3ded758bd 100644
--- a/usr/src/lib/libscf/inc/libscf.h
+++ b/usr/src/lib/libscf/inc/libscf.h
@@ -20,8 +20,7 @@
*/
/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _LIBSCF_H
@@ -85,7 +84,8 @@ typedef enum {
SCF_TYPE_HOST = 300,
SCF_TYPE_HOSTNAME,
SCF_TYPE_NET_ADDR_V4,
- SCF_TYPE_NET_ADDR_V6
+ SCF_TYPE_NET_ADDR_V6,
+ SCF_TYPE_NET_ADDR
} scf_type_t;
typedef struct scf_time {
diff --git a/usr/src/lib/libscf/inc/libscf_priv.h b/usr/src/lib/libscf/inc/libscf_priv.h
index c26006370e..cd058c0f43 100644
--- a/usr/src/lib/libscf/inc/libscf_priv.h
+++ b/usr/src/lib/libscf/inc/libscf_priv.h
@@ -19,8 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _LIBSCF_PRIV_H
@@ -546,6 +545,13 @@ int scf_fastreboot_default_set_transient(boolean_t);
*/
int scf_is_compatible_type(scf_type_t, scf_type_t);
+/*
+ * Check an array of services and enable any that don't have the
+ * "application/auto_enable" property set to "false", which is
+ * the interface to turn off this behaviour (see PSARC 2004/739).
+ */
+void _check_services(char **);
+
#ifdef __cplusplus
}
#endif