summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-07-22 12:55:23 -0500
committerDan Williams <dcbw@redhat.com>2014-11-06 21:58:32 -0600
commit1b1222ffdf4d022e482c70af6d745cb8fb6c5fdf (patch)
tree416d0969b9a7abc520c32a1cf7faa55c031b3beb
parent78539e5ad62fc0bc1c16fcaa777c6b58fd090832 (diff)
dhcp: make systemd DHCP code into a library
The systemd code was modified to add "#if 0 /* NM_IGNORED */" around lines that cause problems for compilation or code that is not actually used in the library. An adaptation layer (nm-sd-adapt) was added for glue between systemd functions and NetworkManager, but changes to the actual systemd code have been kept to a minimum. The sd_event/sd_event_source functions of systemd have been re-implemented on top of the GLib main loop.
-rw-r--r--src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c208
-rw-r--r--src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h104
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c10
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h4
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c4
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c12
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/macro.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/strv.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/time-util.c9
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/time-util.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/utf8.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/util.c45
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/util.h10
23 files changed, 434 insertions, 0 deletions
diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c
new file mode 100644
index 0000000000..dbc922e9eb
--- /dev/null
+++ b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "sd-event.h"
+#include "time-util.h"
+
+struct sd_event_source {
+ guint refcount;
+ guint id;
+ gpointer user_data;
+
+ GIOChannel *channel;
+ sd_event_io_handler_t io_cb;
+
+ uint64_t usec;
+ sd_event_time_handler_t time_cb;
+};
+
+int
+sd_event_source_set_priority (sd_event_source *s, int64_t priority)
+{
+ return 0;
+}
+
+sd_event_source*
+sd_event_source_unref (sd_event_source *s)
+{
+
+ if (!s)
+ return NULL;
+
+ g_return_val_if_fail (s->refcount, NULL);
+
+ s->refcount--;
+ if (s->refcount == 0) {
+ if (s->id)
+ g_source_remove (s->id);
+ if (s->channel) {
+ /* Don't shut down the channel since systemd will soon close
+ * the file descriptor itself, which would cause -EBADF.
+ */
+ g_io_channel_unref (s->channel);
+ }
+ g_free (s);
+ }
+ return NULL;
+}
+
+int
+sd_event_source_set_name(sd_event_source *s, const char *name)
+{
+ if (!s)
+ return -EINVAL;
+
+ g_source_set_name_by_id (s->id, name);
+ return 0;
+}
+
+static gboolean
+io_ready (GIOChannel *channel, GIOCondition condition, struct sd_event_source *source)
+{
+ int r, revents = 0;
+
+ if (condition & G_IO_IN)
+ revents |= EPOLLIN;
+ if (condition & G_IO_OUT)
+ revents |= EPOLLOUT;
+ if (condition & G_IO_PRI)
+ revents |= EPOLLPRI;
+ if (condition & G_IO_ERR)
+ revents |= EPOLLERR;
+ if (condition & G_IO_HUP)
+ revents |= EPOLLHUP;
+
+ r = source->io_cb (source, g_io_channel_unix_get_fd (channel), revents, source->user_data);
+ if (r < 0) {
+ source->id = 0;
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+int
+sd_event_add_io (sd_event *e, sd_event_source **s, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata)
+{
+ struct sd_event_source *source;
+ GIOChannel *channel;
+ GIOCondition condition = 0;
+
+ channel = g_io_channel_unix_new (fd);
+ if (!channel)
+ return -EINVAL;
+
+ source = g_new0 (struct sd_event_source, 1);
+ source->refcount = 1;
+ source->io_cb = callback;
+ source->user_data = userdata;
+ source->channel = channel;
+
+ if (events & EPOLLIN)
+ condition |= G_IO_IN;
+ if (events & EPOLLOUT)
+ condition |= G_IO_OUT;
+ if (events & EPOLLPRI)
+ condition |= G_IO_PRI;
+ if (events & EPOLLERR)
+ condition |= G_IO_ERR;
+ if (events & EPOLLHUP)
+ condition |= G_IO_HUP;
+
+ g_io_channel_set_encoding (source->channel, NULL, NULL);
+ g_io_channel_set_buffered (source->channel, FALSE);
+ source->id = g_io_add_watch (source->channel, condition, (GIOFunc) io_ready, source);
+
+ *s = source;
+ return 0;
+}
+
+static gboolean
+time_ready (struct sd_event_source *source)
+{
+ int r;
+
+ r = source->time_cb (source, source->usec, source->user_data);
+ if (r < 0) {
+ source->id = 0;
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+int
+sd_event_add_time(sd_event *e, sd_event_source **s, clockid_t clock, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata)
+{
+ struct sd_event_source *source;
+ uint64_t n = now (clock);
+
+ source = g_new0 (struct sd_event_source, 1);
+ source->refcount = 1;
+ source->time_cb = callback;
+ source->user_data = userdata;
+ source->usec = usec;
+
+ if (usec > 1000)
+ usec = n < usec - 1000 ? usec - n : 1000;
+ source->id = g_timeout_add (usec / 1000, (GSourceFunc) time_ready, source);
+
+ *s = source;
+ return 0;
+}
+
+/* sd_event is basically a GMainContext; but since we only
+ * ever use the default context, nothing to do here.
+ */
+
+int
+sd_event_default (sd_event **e)
+{
+ *e = GUINT_TO_POINTER (1);
+ return 0;
+}
+
+sd_event*
+sd_event_ref (sd_event *e)
+{
+ return e;
+}
+
+sd_event*
+sd_event_unref (sd_event *e)
+{
+ return NULL;
+}
+
+int
+sd_event_now (sd_event *e, clockid_t clock, uint64_t *usec)
+{
+ *usec = now (clock);
+ return 0;
+}
+
+int asynchronous_close(int fd) {
+ safe_close(fd);
+ return -1;
+}
+
diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
new file mode 100644
index 0000000000..9282aaaf94
--- /dev/null
+++ b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#ifndef NM_SD_ADAPT_H
+#define NM_SD_ADAPT_H
+
+#include <config.h>
+
+#include <glib.h>
+
+#include <netinet/in.h>
+#include <stdbool.h>
+#include <syslog.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <elf.h>
+#include <sys/auxv.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "nm-logging.h"
+
+static inline guint32
+_slog_level_to_nm (int slevel)
+{
+ switch (slevel) {
+ case LOG_DEBUG: return LOGL_DEBUG;
+ case LOG_WARNING: return LOGL_WARN;
+ case LOG_ERR: return LOGL_ERR;
+ case LOG_INFO:
+ case LOG_NOTICE:
+ default: return LOGL_INFO;
+ }
+}
+
+#define log_meta(level, file, line, func, format, ...) \
+G_STMT_START { \
+ guint32 _l = _slog_level_to_nm ((level)); \
+ if (nm_logging_enabled (_l, LOGD_DHCP)) \
+ _nm_log (#file ":" #line, func, LOGD_DHCP, _l, format, ## __VA_ARGS__); \
+} G_STMT_END
+
+#define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__)
+#define log_error(...) log_full(LOG_ERR, __VA_ARGS__)
+#define log_full(level, ...) log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__);
+
+#define log_dhcp_client(client, fmt, ...) \
+ log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, "DHCP CLIENT (0x%x): " fmt, client->xid, ##__VA_ARGS__)
+
+#define log_assert_failed(e, file, line, func) \
+G_STMT_START { \
+ nm_log_err (LOGD_DHCP, #file ":" #line "(" #func "): assertion failed: " # e); \
+ g_assert (FALSE); \
+} G_STMT_END
+
+#define log_assert_failed_unreachable(t, file, line, func) \
+G_STMT_START { \
+ nm_log_err (LOGD_DHCP, #file ":" #line "(" #func "): assert unreachable: " # t); \
+ g_assert_not_reached (); \
+} G_STMT_END
+
+#define log_assert_failed_return(e, file, line, func) \
+ nm_log_err (LOGD_DHCP, #file ":" #line "(" #func "): assert return: " # e); \
+
+#define log_oom nm_log_err(LOGD_CORE, "%s:%s/%s: OOM", __FILE__, __LINE__, __func__)
+
+/* Can't include both net/if.h and linux/if.h; so have to define this here */
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
+#ifndef MAX_HANDLE_SZ
+#define MAX_HANDLE_SZ 128
+#endif
+
+#define noreturn G_GNUC_NORETURN
+
+#include "sd-id128.h"
+#include "sparse-endian.h"
+#include "async.h"
+#include "util.h"
+
+static inline pid_t gettid(void) {
+ return (pid_t) syscall(SYS_gettid);
+}
+
+#endif /* NM_SD_ADAPT_H */
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h
index d358a49307..28c0e63454 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h
@@ -22,6 +22,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdint.h>
#include <linux/if_packet.h>
#include <net/if_arp.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c
index 29e9993f66..26e6e9f3df 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c
@@ -17,6 +17,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c
index b6110c5f16..50ecf87383 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdint.h>
#include <string.h>
#include <errno.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
index 7581daeeeb..e6ebf86ae1 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h
index 6cc0aa8a8d..e29e2f0ee0 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h
@@ -21,6 +21,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <net/ethernet.h>
#include <netinet/in.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h
index 109e0f4f21..9f7826c466 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h
@@ -22,6 +22,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdint.h>
#include "refcnt.h"
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c
index fe56c10273..626a4d6a7f 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c
@@ -17,6 +17,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c
index e6a31778f4..c18fb2a660 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
index 372f3ed371..f870e3bb42 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
@@ -19,22 +19,31 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <netinet/ether.h>
#include <linux/if.h>
#include <arpa/inet.h>
#include <fnmatch.h>
+#if 0 /* NM_IGNORED */
#include "strv.h"
#include "siphash24.h"
#include "libudev-private.h"
+#endif
#include "dhcp-lease-internal.h"
+#if 0 /* NM_IGNORED */
#include "log.h"
#include "utf8.h"
+#endif
#include "util.h"
+#if 0 /* NM_IGNORED */
#include "conf-parser.h"
#include "condition.h"
+#endif
#include "network-internal.h"
+#if 0 /* NM_IGNORED */
const char *net_get_name(struct udev_device *device) {
const char *name, *field;
@@ -295,6 +304,7 @@ int config_parse_hwaddr(const char *unit,
return 0;
}
+#endif
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) {
unsigned i;
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
index 49387d03cf..f4ff1dd4e8 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
@@ -21,10 +21,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <netinet/ether.h>
#include <netinet/in.h>
#include <stdbool.h>
+#if 0 /* NM_IGNORED */
#include "udev.h"
#include "condition-util.h"
@@ -62,6 +65,7 @@ int config_parse_ifalias(const char *unit, const char *filename, unsigned line,
int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]);
const char *net_get_name(struct udev_device *device);
+#endif
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size);
int deserialize_in_addrs(struct in_addr **addresses, const char *string);
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
index 1a54d3abee..df8abdf3a3 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
@@ -17,6 +17,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
index ebd031bb03..4d078b4c8a 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
@@ -28,7 +30,9 @@
#include "util.h"
#include "list.h"
+#if 0 /* NM_IGNORED */
#include "mkdir.h"
+#endif
#include "fileio.h"
#include "in-addr-util.h"
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
index dbec1a2a8b..faf490e141 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
@@ -19,14 +19,18 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/if_infiniband.h>
+#if 0 /* NM_IGNORED */
#include "udev.h"
#include "udev-util.h"
#include "virt.h"
+#endif
#include "siphash24.h"
#include "util.h"
#include "refcnt.h"
@@ -630,6 +634,7 @@ error:
static int client_ensure_iaid(sd_dhcp6_client *client) {
/* name is a pointer to memory in the udev_device struct, so must
have the same scope */
+#if 0 /* NM_IGNORED */
_cleanup_udev_device_unref_ struct udev_device *device = NULL;
const char *name = NULL;
uint64_t id;
@@ -671,6 +676,9 @@ static int client_ensure_iaid(sd_dhcp6_client *client) {
client->ia_na.id = (id & 0xffffffff) ^ (id >> 32);
return 0;
+#else
+ return -1;
+#endif
}
static int client_parse_message(sd_dhcp6_client *client,
@@ -1199,8 +1207,10 @@ sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
int sd_dhcp6_client_new(sd_dhcp6_client **ret)
{
_cleanup_dhcp6_client_unref_ sd_dhcp6_client *client = NULL;
+#if 0 /* NM_IGNORED */
sd_id128_t machine_id;
int r;
+#endif
size_t t;
assert_return(ret, -EINVAL);
@@ -1217,6 +1227,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
client->fd = -1;
+#if 0 /* NM_IGNORED */
/* initialize DUID */
client->duid.en.type = htobe16(DHCP6_DUID_EN);
client->duid.en.pen = htobe32(SYSTEMD_PEN);
@@ -1229,6 +1240,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
/* a bit of snake-oil perhaps, but no need to expose the machine-id
directly */
siphash24(client->duid.en.id, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
+#endif
client->req_opts_len = ELEMENTSOF(default_req_opts);
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c
index e2715ea659..6a1cb22daa 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include "util.h"
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/macro.h b/src/dhcp-manager/systemd-dhcp/src/shared/macro.h
index ceef491268..e6cf6eecd7 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/macro.h
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/macro.h
@@ -384,6 +384,7 @@ do { \
_found; \
})
+#if 0 /* NM_IGNORED */
/* Define C11 thread_local attribute even on older gcc compiler
* version */
#ifndef thread_local
@@ -409,3 +410,4 @@ do { \
#endif
#include "log.h"
+#endif
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/strv.c b/src/dhcp-manager/systemd-dhcp/src/shared/strv.c
index 00857e40a7..9d1e6b22ea 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/strv.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/strv.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c
index d3404afd55..efc18bc319 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <time.h>
#include <string.h>
#include <sys/timex.h>
@@ -26,7 +28,9 @@
#include "util.h"
#include "time-util.h"
+#if 0 /* NM_IGNORED */
#include "strv.h"
+#endif
usec_t now(clockid_t clock_id) {
struct timespec ts;
@@ -118,6 +122,7 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u) {
return ts;
}
+#if 0 /* NM_IGNORED */
usec_t timeval_load(const struct timeval *tv) {
assert(tv);
@@ -272,6 +277,7 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
buf[l-1] = 0;
return buf;
}
+#endif
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
static const struct {
@@ -383,6 +389,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
return buf;
}
+#if 0 /* NM_IGNORED */
void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
assert(f);
@@ -974,6 +981,7 @@ bool timezone_is_valid(const char *name) {
return true;
}
+#endif
clockid_t clock_boottime_or_monotonic(void) {
static clockid_t clock = -1;
@@ -992,3 +1000,4 @@ clockid_t clock_boottime_or_monotonic(void) {
return clock;
}
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h
index b55a660bb0..578a0c1ca4 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h
@@ -27,6 +27,8 @@
typedef uint64_t usec_t;
typedef uint64_t nsec_t;
+#include "nm-sd-adapt.h"
+
#define NSEC_FMT "%" PRIu64
#define USEC_FMT "%" PRIu64
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c b/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c
index 9353559b76..dd3adf0add 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c
@@ -43,6 +43,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <stdlib.h>
#include <inttypes.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/util.c b/src/dhcp-manager/systemd-dhcp/src/shared/util.c
index 4143f6d643..af607386ec 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/util.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/util.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <assert.h>
#include <string.h>
#include <unistd.h>
@@ -69,6 +71,7 @@
#include "macro.h"
#include "util.h"
+#if 0 /* NM_IGNORED */
#include "ioprio.h"
#include "missing.h"
#include "log.h"
@@ -85,7 +88,9 @@
#include "gunicode.h"
#include "virt.h"
#include "def.h"
+#endif
+#if 0 /* NM_IGNORED */
int saved_argc = 0;
char **saved_argv = NULL;
@@ -105,6 +110,7 @@ size_t page_size(void) {
pgsz = (size_t) r;
return pgsz;
}
+#endif
bool streq_ptr(const char *a, const char *b) {
@@ -219,6 +225,7 @@ int safe_close(int fd) {
return -1;
}
+#if 0 /* NM_IGNORED */
void close_many(const int fds[], unsigned n_fd) {
unsigned i;
@@ -302,6 +309,7 @@ int parse_uid(const char *s, uid_t* ret_uid) {
*ret_uid = uid;
return 0;
}
+#endif
int safe_atou(const char *s, unsigned *ret_u) {
char *x = NULL;
@@ -323,6 +331,7 @@ int safe_atou(const char *s, unsigned *ret_u) {
return 0;
}
+#if 0 /* NM_IGNORED */
int safe_atoi(const char *s, int *ret_i) {
char *x = NULL;
long l;
@@ -415,6 +424,7 @@ int safe_atod(const char *s, double *ret_d) {
*ret_d = (double) d;
return 0;
}
+#endif
static size_t strcspn_escaped(const char *s, const char *reject) {
bool escaped = false;
@@ -472,6 +482,7 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
return current;
}
+#if 0 /* NM_IGNORED */
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
int r;
_cleanup_free_ char *line = NULL;
@@ -564,6 +575,7 @@ int get_starttime_of_pid(pid_t pid, unsigned long long *st) {
return 0;
}
+#endif
int fchmod_umask(int fd, mode_t m) {
mode_t u;
@@ -583,6 +595,7 @@ char *truncate_nl(char *s) {
return s;
}
+#if 0 /* NM_IGNORED */
int get_process_state(pid_t pid) {
const char *p;
char state;
@@ -820,6 +833,7 @@ int get_process_gid(pid_t pid, gid_t *gid) {
assert_cc(sizeof(uid_t) == sizeof(gid_t));
return get_process_id(pid, "Gid:", gid);
}
+#endif
char *strnappend(const char *s, const char *suffix, size_t b) {
size_t a;
@@ -856,6 +870,7 @@ char *strappend(const char *s, const char *suffix) {
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
}
+#if 0 /* NM_IGNORED */
int readlinkat_malloc(int fd, const char *p, char **ret) {
size_t l = 100;
int r;
@@ -970,6 +985,7 @@ int reset_signal_mask(void) {
return 0;
}
+#endif
char *strstrip(char *s) {
char *e;
@@ -988,6 +1004,7 @@ char *strstrip(char *s) {
return s;
}
+#if 0 /* NM_IGNORED */
char *delete_chars(char *s, const char *bad) {
char *f, *t;
@@ -1077,6 +1094,7 @@ int rmdir_parents(const char *path, const char *stop) {
return 0;
}
+#endif
char hexchar(int x) {
static const char table[16] = "0123456789abcdef";
@@ -1374,6 +1392,7 @@ char *cunescape_length(const char *s, size_t length) {
return cunescape_length_with_prefix(s, length, NULL);
}
+#if 0 /* NM_IGNORED */
char *cunescape(const char *s) {
assert(s);
@@ -1563,6 +1582,7 @@ int close_all_fds(const int except[], unsigned n_except) {
return r;
}
+#endif
bool chars_intersect(const char *a, const char *b) {
const char *p;
@@ -1575,6 +1595,7 @@ bool chars_intersect(const char *a, const char *b) {
return false;
}
+#if 0 /* NM_IGNORED */
bool fstype_is_network(const char *fstype) {
static const char table[] =
"cifs\0"
@@ -2184,6 +2205,7 @@ void safe_close_pair(int p[]) {
p[0] = safe_close(p[0]);
p[1] = safe_close(p[1]);
}
+#endif
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
uint8_t *p = buf;
@@ -2220,6 +2242,7 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
return n;
}
+#if 0 /* NM_IGNORED */
ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
const uint8_t *p = buf;
ssize_t n = 0;
@@ -2464,6 +2487,7 @@ char* dirname_malloc(const char *path) {
return dir;
}
+#endif
int dev_urandom(void *p, size_t n) {
_cleanup_close_ int fd;
@@ -2521,6 +2545,7 @@ void random_bytes(void *p, size_t n) {
*q = rand();
}
+#if 0 /* NM_IGNORED */
void rename_process(const char name[8]) {
assert(name);
@@ -4021,6 +4046,7 @@ char* strshorten(char *s, size_t l) {
return s;
}
+#endif
static bool hostname_valid_char(char c) {
return
@@ -4062,6 +4088,7 @@ bool hostname_is_valid(const char *s) {
return true;
}
+#if 0 /* NM_IGNORED */
char* hostname_cleanup(char *s, bool lowercase) {
char *p, *d;
bool dot;
@@ -4122,6 +4149,7 @@ int pipe_eof(int fd) {
return pollfd.revents & POLLHUP;
}
+#endif
int fd_wait_for_event(int fd, int event, usec_t t) {
@@ -4175,6 +4203,7 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
return 0;
}
+#if 0 /* NM_IGNORED */
int terminal_vhangup_fd(int fd) {
assert(fd >= 0);
@@ -4653,6 +4682,7 @@ int get_files_in_directory(const char *path, char ***list) {
return n;
}
+#endif
char *strjoin(const char *x, ...) {
va_list ap;
@@ -4711,6 +4741,7 @@ char *strjoin(const char *x, ...) {
return r;
}
+#if 0 /* NM_IGNORED */
bool is_main_thread(void) {
static thread_local int cached = 0;
@@ -5031,6 +5062,7 @@ finish:
return buf;
}
+#endif
void* memdup(const void *p, size_t l) {
void *r;
@@ -5045,6 +5077,7 @@ void* memdup(const void *p, size_t l) {
return r;
}
+#if 0 /* NM_IGNORED */
int fd_inc_sndbuf(int fd, size_t n) {
int r, value;
socklen_t l = sizeof(value);
@@ -5476,6 +5509,7 @@ bool string_is_safe(const char *p) {
return true;
}
+#endif
/**
* Check if a string contains control characters. If 'ok' is non-NULL
@@ -5500,6 +5534,7 @@ bool string_has_cc(const char *p, const char *ok) {
return false;
}
+#if 0 /* NM_IGNORED */
bool path_is_safe(const char *p) {
if (isempty(p))
@@ -5977,6 +6012,7 @@ char *strrep(const char *s, unsigned n) {
*p = 0;
return r;
}
+#endif
void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
size_t a, newalloc;
@@ -6004,6 +6040,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
return q;
}
+#if 0 /* NM_IGNORED */
void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size) {
size_t prev;
uint8_t *q;
@@ -6406,6 +6443,7 @@ int getpeersec(int fd, char **ret) {
*ret = s;
return 0;
}
+#endif
/* This is much like like mkostemp() but is subject to umask(). */
int mkostemp_safe(char *pattern, int flags) {
@@ -6423,6 +6461,7 @@ int mkostemp_safe(char *pattern, int flags) {
return fd;
}
+#if 0 /* NM_IGNORED */
int open_tmpfile(const char *path, int flags) {
char *p;
int fd;
@@ -6809,6 +6848,7 @@ int bind_remount_recursive(const char *prefix, bool ro) {
}
}
}
+#endif
int fflush_and_check(FILE *f) {
assert(f);
@@ -6841,6 +6881,7 @@ char *tempfn_xxxxxx(const char *p) {
return t;
}
+#if 0 /* NM_IGNORED */
char *tempfn_random(const char *p) {
const char *fn;
char *t, *x;
@@ -6869,6 +6910,7 @@ char *tempfn_random(const char *p) {
return t;
}
+#endif
/* make sure the hostname is not "localhost" */
bool is_localhost(const char *hostname) {
@@ -6887,6 +6929,7 @@ bool is_localhost(const char *hostname) {
endswith(hostname, ".localdomain.");
}
+#if 0 /* NM_IGNORED */
int take_password_lock(const char *root) {
struct flock flock = {
@@ -7195,3 +7238,5 @@ int sethostname_idempotent(const char *s) {
return 1;
}
+#endif
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/util.h b/src/dhcp-manager/systemd-dhcp/src/shared/util.h
index 35584467c1..f6ff8ea40f 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/util.h
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/util.h
@@ -21,6 +21,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <alloca.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -43,6 +45,7 @@
#include <mntent.h>
#include <sys/socket.h>
+#if 0 /* NM_IGNORED */
#if SIZEOF_PID_T == 4
# define PID_FMT "%" PRIu32
#elif SIZEOF_PID_T == 2
@@ -82,9 +85,12 @@
#else
# error Unknown rlim_t size
#endif
+#endif
#include "macro.h"
+#if 0 /* NM_IGNORED */
#include "missing.h"
+#endif
#include "time-util.h"
/* What is interpreted as whitespace? */
@@ -951,8 +957,10 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int root_fd);
bool pid_is_alive(pid_t pid);
bool pid_is_unwaited(pid_t pid);
+#if 0 /* NM_IGNORED */
int getpeercred(int fd, struct ucred *ucred);
int getpeersec(int fd, char **ret);
+#endif
int writev_safe(int fd, const struct iovec *w, int j);
@@ -970,10 +978,12 @@ char* mount_test_option(const char *haystack, const char *needle);
void hexdump(FILE *f, const void *p, size_t s);
+#if 0 /* NM_IGNORED */
union file_handle_union {
struct file_handle handle;
char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
};
+#endif
int update_reboot_param_file(const char *param);