changeset 2493:ec2af7c0334d draft

Add a compat syslog function if the libc syslog does not support LOG_PERROR. Add a non working if-sun.c stub. Define IN6_IFF_TENTATIVE and friends to zero so IPv6 at least compiles on Solaris. Warn that Solaris support presently does not work.
author Roy Marples <roy@marples.name>
date Sat, 24 May 2014 13:08:29 +0000
parents 12585d26b91a
children 9ee5781a9a80
files configure dhcpcd.c if-sun.c ipv6.c
diffstat 4 files changed, 237 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Wed May 21 23:07:52 2014 +0000
+++ b/configure	Sat May 24 13:08:29 2014 +0000
@@ -372,9 +372,16 @@
 	echo "COMPAT_SRCS+=	compat/linkaddr.c" >>$CONFIG_MK
 	;;
 sunos*)
-#	echo "CSTD=		gnu99" >>$CONFIG_MK
+	echo "WARNING!!! Solaris support is at early development stage!" >&2
+	echo "so don't expect it to work just yet, patches welcome" >&2
 	echo "CPPFLAGS+=	-D_XPG4_2 -D__EXTENSIONS__ -DBSD_COMP" \
 	    >>$CONFIG_MK
+	echo "DHCPCD_SRCS+=	if-sun.c" >>$CONFIG_MK
+
+	# IPv6 won't work, but it will at least compile.
+	echo "CPPFLAGS+=	-DIN6_IFF_DETACHED=0" >>$CONFIG_MK
+	echo "CPPFLAGS+=	-DIN6_IFF_TENTATIVE=0" >>$CONFIG_MK
+	echo "CPPFLAGS+=	-DIN6_IFF_DUPLICATED=0" >>$CONFIG_MK
 	;;
 *)
 	echo "DHCPCD_SRCS+=	if-bsd.c" >>$CONFIG_MK
@@ -719,6 +726,29 @@
 	;;
 esac
 
+if [ -z "$LOG_PERROR" ]; then
+	printf "Testing for LOG_PERROR ... "
+	cat <<EOF >_log_perror.c
+#include <syslog.h>
+int main(void) {
+	openlog("test", LOG_PERROR, LOG_DAEMON);
+	return 0;
+}
+EOF
+	if $XCC _log_perror.c -o _log_perror 2>/dev/null; then
+		LOG_PERROR=yes
+	else
+		LOG_PERROR=no
+	fi
+	echo "$LOG_PERROR"
+	rm -f _log_perror.c _log_perror
+fi
+if [ "$LOG_PERROR" = no ]; then
+	echo "COMPAT_SRCS+=	compat/psyslog.c" >>$CONFIG_MK
+	echo "#include		\"compat/psyslog.h\"" >>$CONFIG_H
+	echo "#define syslog	psyslog" >>$CONFIG_H
+fi
+
 if [ -z "$MD5" ]; then
 	MD5_LIB=
 	printf "Testing for MD5Init ... "
--- a/dhcpcd.c	Wed May 21 23:07:52 2014 +0000
+++ b/dhcpcd.c	Sat May 24 13:08:29 2014 +0000
@@ -1145,6 +1145,9 @@
 	openlog(PACKAGE, LOG_PID, LOG_DAEMON);
 #endif
 	setlogmask(LOG_UPTO(LOG_INFO));
+#ifndef LOG_PERROR
+	psyslog_prio = LOG_UPTO(LOG_INFO);
+#endif
 
 	/* Test for --help and --version */
 	if (argc > 1) {
@@ -1255,8 +1258,12 @@
 	ctx.options &= ~DHCPCD_DAEMONISE;
 #endif
 
-	if (ctx.options & DHCPCD_DEBUG)
+	if (ctx.options & DHCPCD_DEBUG) {
 		setlogmask(LOG_UPTO(LOG_DEBUG));
+#ifndef LOG_PERROR
+		psyslog_prio = LOG_UPTO(LOG_DEBUG);
+#endif
+	}
 	if (ctx.options & DHCPCD_QUIET) {
 		i = open(_PATH_DEVNULL, O_RDWR);
 		if (i == -1)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/if-sun.c	Sat May 24 13:08:29 2014 +0000
@@ -0,0 +1,191 @@
+/*
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/utsname.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "common.h"
+#include "dhcp.h"
+#include "if.h"
+#include "if-options.h"
+#include "ipv4.h"
+#include "ipv6.h"
+#include "ipv6nd.h"
+
+int
+if_init(__unused struct interface *iface)
+{
+
+	return 0;
+}
+
+int
+if_conf(__unused struct interface *iface)
+{
+
+	return 0;
+}
+
+int
+if_openlinksocket(void)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+int
+if_getssid(const char *ifname, char *ssid)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+int
+if_vimaster(const char *ifname)
+{
+
+	return 0;
+}
+
+#ifdef INET
+int
+if_openrawsocket(struct interface *ifp, int protocol)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+ssize_t
+if_sendrawpacket(const struct interface *ifp, int protocol,
+    const void *data, size_t len)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+ssize_t
+if_readrawpacket(struct interface *ifp, int protocol,
+    void *data, size_t len, int *flags)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+int
+if_address(const struct interface *iface, const struct in_addr *address,
+    const struct in_addr *netmask, const struct in_addr *broadcast,
+    int action)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+int
+if_route(const struct rt *rt, int action)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+#endif
+
+#ifdef INET6
+int
+if_address6(const struct ipv6_addr *a, int action)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+int
+if_route6(const struct rt6 *rt, int action)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+#endif
+
+#ifdef INET6
+int
+if_addrflags6(const char *ifname, const struct in6_addr *addr)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+#endif
+
+int
+if_managelink(struct dhcpcd_ctx *ctx)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+if_machinearch(char *str, size_t len)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+#ifdef INET6
+int
+if_nd6reachable(const char *ifname, struct in6_addr *addr)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+
+void
+if_rarestore(struct dhcpcd_ctx *ctx)
+{
+
+}
+
+int
+if_checkipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
+{
+
+	errno = ENOTSUP;
+	return -1;
+}
+#endif
--- a/ipv6.c	Wed May 21 23:07:52 2014 +0000
+++ b/ipv6.c	Sat May 24 13:08:29 2014 +0000
@@ -52,8 +52,10 @@
 #ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */
 #  include <net/if_var.h>
 #endif
+#ifndef __sun
 #  include <netinet6/in6_var.h>
 #endif
+#endif
 
 #include <errno.h>
 #include <ifaddrs.h>
@@ -81,7 +83,11 @@
 
 /* Hackery at it's finest. */
 #ifndef s6_addr32
-#  define s6_addr32 __u6_addr.__u6_addr32
+#  ifdef __sun
+#    define s6_addr32	_S6_un._S6_u32
+#  else
+#    define s6_addr32	__u6_addr.__u6_addr32
+#  endif
 #endif
 
 struct ipv6_ctx *