summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-06 08:28:06 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-06 08:29:57 +0100
commit7a3fe8ef43993f7b598bacc07cf801a6265b11af (patch)
treebfa69eabc123b82ded1054151fa700d2b20552f8
parentHOSTNAME(1): Import from FreeBSD (diff)
downloadrtems-libbsd-7a3fe8ef43993f7b598bacc07cf801a6265b11af.tar.bz2
Add rtems_mdns_sethostname()
Use it to set the multi-cast hostname of the default mDNS resolver instance via sethostname().
-rw-r--r--Makefile1
-rwxr-xr-xfreebsd-to-rtems.py1
-rw-r--r--freebsd/sys/kern/kern_mib.c7
-rw-r--r--rtemsbsd/include/rtems/mdns.h17
-rw-r--r--rtemsbsd/mdns/mdns-sethostname-default.c41
-rw-r--r--rtemsbsd/mdns/mdns.c41
6 files changed, 104 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 9b955a3b..63a31782 100644
--- a/Makefile
+++ b/Makefile
@@ -102,6 +102,7 @@ LIB_C_FILES += rtemsbsd/rtems/rtems-syslog-initialize.c
LIB_C_FILES += rtemsbsd/rtems/syslog.c
LIB_C_FILES += rtemsbsd/ftpd/ftpd.c
LIB_C_FILES += rtemsbsd/mdns/mdns.c
+LIB_C_FILES += rtemsbsd/mdns/mdns-sethostname-default.c
LIB_C_FILES += rtemsbsd/pppd/auth.c
LIB_C_FILES += rtemsbsd/pppd/ccp.c
LIB_C_FILES += rtemsbsd/pppd/chap.c
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py
index 1e385fc8..6c3450e4 100755
--- a/freebsd-to-rtems.py
+++ b/freebsd-to-rtems.py
@@ -700,6 +700,7 @@ rtems.addRTEMSSourceFiles(
'rtems/syslog.c',
'ftpd/ftpd.c',
'mdns/mdns.c',
+ 'mdns/mdns-sethostname-default.c',
'pppd/auth.c',
'pppd/ccp.c',
'pppd/chap.c',
diff --git a/freebsd/sys/kern/kern_mib.c b/freebsd/sys/kern/kern_mib.c
index 8d19a3b7..a1430f91 100644
--- a/freebsd/sys/kern/kern_mib.c
+++ b/freebsd/sys/kern/kern_mib.c
@@ -56,6 +56,9 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h>
#include <sys/sx.h>
#include <rtems/bsd/sys/unistd.h>
+#ifdef __rtems__
+#include <rtems/mdns.h>
+#endif /* __rtems__ */
SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
"Sysctl internal magic");
@@ -326,6 +329,10 @@ sysctl_hostname(SYSCTL_HANDLER_ARGS)
#else /* __rtems__ */
(void) cpr;
(void) descend;
+
+ if (pr_offset == offsetof(struct prison, pr_hostname)) {
+ rtems_mdns_sethostname(tmpname);
+ }
#endif /* __rtems__ */
mtx_unlock(&pr->pr_mtx);
#ifndef __rtems__
diff --git a/rtemsbsd/include/rtems/mdns.h b/rtemsbsd/include/rtems/mdns.h
index ecf9242b..4abfbfe5 100644
--- a/rtemsbsd/include/rtems/mdns.h
+++ b/rtemsbsd/include/rtems/mdns.h
@@ -40,6 +40,9 @@
extern "C" {
#endif /* __cplusplus */
+/* Private variable, do not touch. Use rtems_mdns_sethostname() instead. */
+extern void (*rtems_mdns_sethostname_handler)(const char *hostname);
+
/**
* @brief Initializes an mDNS resolver instance.
*
@@ -67,6 +70,20 @@ rtems_status_code rtems_mdns_initialize(rtems_task_priority daemon_priority,
*/
mDNS *rtems_mdns_get_instance(void);
+/**
+ * @brief Sets the multi-cast hostname of the mDNS resolver instance.
+ *
+ * In case the mDNS resolver instance is not initialized, then this function
+ * has no effect.
+ *
+ * @param[in] hostname The new multi-cast hostname.
+ */
+static inline void
+rtems_mdns_sethostname(const char *hostname)
+{
+ (*rtems_mdns_sethostname_handler)(hostname);
+}
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/rtemsbsd/mdns/mdns-sethostname-default.c b/rtemsbsd/mdns/mdns-sethostname-default.c
new file mode 100644
index 00000000..4db2c96a
--- /dev/null
+++ b/rtemsbsd/mdns/mdns-sethostname-default.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * 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 <rtems/mdns.h>
+
+static void
+mdns_sethostname_default(const char *hostname)
+{
+ /* Do nothing */
+}
+
+void (*rtems_mdns_sethostname_handler)(const char *hostname) =
+ mdns_sethostname_default;
diff --git a/rtemsbsd/mdns/mdns.c b/rtemsbsd/mdns/mdns.c
index 3cdcfe61..425c1276 100644
--- a/rtemsbsd/mdns/mdns.c
+++ b/rtemsbsd/mdns/mdns.c
@@ -31,6 +31,7 @@
#include <mDNSEmbeddedAPI.h>
#include <mDNSPosix.h>
+#include <DNSCommon.h>
#include <sys/select.h>
#include <sys/socket.h>
@@ -54,7 +55,7 @@
#include <rtems/bsd/util.h>
#include <rtems/mdns.h>
-static rtems_id daemon_id;
+static rtems_id mdns_daemon_id;
static mDNS mDNSStorage;
@@ -223,7 +224,7 @@ mdns_gethostbyname(void *rval, void *cb_data, va_list ap)
ctx.task_id = rtems_task_self();
mDNS_StartQuery(&mDNSStorage, &q);
- rtems_bsd_force_select_timeout(daemon_id);
+ rtems_bsd_force_select_timeout(mdns_daemon_id);
sc = rtems_event_transient_receive(RTEMS_WAIT,
10 * rtems_clock_get_ticks_per_second());
@@ -261,6 +262,36 @@ mdns_daemon(rtems_task_argument arg)
}
}
+static void
+truncate_at_first_dot(domainlabel *name)
+{
+ int c = name->c[0];
+ int n = 0;
+
+ while (n < c && name->c[n + 1] != '.') {
+ ++n;
+ }
+
+ name->c[0] = n;
+}
+
+static void
+mdns_sethostname(const char *hostname)
+{
+ mDNS *m = &mDNSStorage;
+
+ mDNS_Lock(m);
+
+ MakeDomainLabelFromLiteralString(&m->hostlabel, hostname);
+ truncate_at_first_dot(&m->hostlabel);
+
+ mDNS_Unlock(m);
+
+ mDNS_SetFQDN(m);
+
+ rtems_bsd_force_select_timeout(mdns_daemon_id);
+}
+
rtems_status_code
rtems_mdns_initialize(rtems_task_priority daemon_priority,
CacheEntity *rrcachestorage, mDNSu32 rrcachesize)
@@ -279,12 +310,12 @@ rtems_mdns_initialize(rtems_task_priority daemon_priority,
sc = rtems_task_create(rtems_build_name('m', 'D', 'N', 'S'),
daemon_priority, 16 * 1024, RTEMS_DEFAULT_MODES,
- RTEMS_DEFAULT_ATTRIBUTES, &daemon_id);
+ RTEMS_DEFAULT_ATTRIBUTES, &mdns_daemon_id);
if (sc != RTEMS_SUCCESSFUL) {
return (RTEMS_UNSATISFIED);
}
- sc = rtems_task_start(daemon_id, mdns_daemon, 0);
+ sc = rtems_task_start(mdns_daemon_id, mdns_daemon, 0);
if (sc != RTEMS_SUCCESSFUL) {
return (RTEMS_UNSATISFIED);
}
@@ -311,6 +342,8 @@ rtems_mdns_initialize(rtems_task_priority daemon_priority,
}
}
+ rtems_mdns_sethostname_handler = mdns_sethostname;
+
return (RTEMS_SUCCESSFUL);
}