[systemd-commits] 7 commits - Makefile.am TODO src/libsystemd src/machine src/nss-myhostname src/resolve
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Jul 10 11:40:13 PDT 2014
Makefile.am | 8 +
TODO | 4
src/libsystemd/sd-event/event-util.h | 1
src/machine/machine-dbus.c | 52 +++++++----
src/nss-myhostname/addresses.c | 149 ++++++++++++++++++++++++++++++++++
src/nss-myhostname/addresses.h | 43 +++++++++
src/nss-myhostname/ifconf.h | 68 ---------------
src/nss-myhostname/netlink.c | 141 --------------------------------
src/nss-myhostname/nss-myhostname.c | 118 +++++++++++++++-----------
src/nss-myhostname/nss-myhostname.sym | 19 ++++
src/resolve/resolved-manager.c | 2
11 files changed, 323 insertions(+), 282 deletions(-)
New commits:
commit 947127ff6230b44623afec3e6aacc85f54168db2
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 20:38:07 2014 +0200
nss-myhostname: only export the NSS entry point symbols, nothing else
diff --git a/Makefile.am b/Makefile.am
index 425a5e1..b28fa3f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4397,6 +4397,7 @@ endif
# ------------------------------------------------------------------------------
if HAVE_MYHOSTNAME
libnss_myhostname_la_SOURCES = \
+ src/nss-myhostname/nss-myhostname.sym \
src/nss-myhostname/nss-myhostname.c \
src/nss-myhostname/addresses.h \
src/nss-myhostname/addresses.c
@@ -4407,7 +4408,8 @@ libnss_myhostname_la_LDFLAGS = \
-export-dynamic \
-avoid-version \
-shared \
- -shrext .so.2
+ -shrext .so.2 \
+ -Wl,--version-script=$(top_srcdir)/src/nss-myhostname/nss-myhostname.sym
libnss_myhostname_la_LIBADD = \
libsystemd-shared.la \
diff --git a/src/nss-myhostname/nss-myhostname.sym b/src/nss-myhostname/nss-myhostname.sym
new file mode 100644
index 0000000..dcfc2e4
--- /dev/null
+++ b/src/nss-myhostname/nss-myhostname.sym
@@ -0,0 +1,19 @@
+/***
+ This file is part of systemd.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+***/
+
+{
+global:
+ _nss_myhostname_gethostbyaddr2_r;
+ _nss_myhostname_gethostbyaddr_r;
+ _nss_myhostname_gethostbyname2_r;
+ _nss_myhostname_gethostbyname3_r;
+ _nss_myhostname_gethostbyname4_r;
+ _nss_myhostname_gethostbyname_r;
+local: *;
+};
commit bb62fb68f61fac69fa7f2470db943da859844acf
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 20:21:20 2014 +0200
machined: various modernizations when enumerating container addresses
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 14dae0a..39db505 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -32,6 +32,7 @@
#include "bus-errors.h"
#include "copy.h"
#include "fileio.h"
+#include "socket-util.h"
#include "machine.h"
static int property_get_id(
@@ -190,22 +191,20 @@ int bus_machine_method_get_addresses(sd_bus *bus, sd_bus_message *message, void
if (r < 0)
_exit(EXIT_FAILURE);
- r = sd_rtnl_message_request_dump(req, true);
- if (r < 0)
- _exit(EXIT_FAILURE);
-
r = sd_rtnl_call(rtnl, req, 0, &resp);
if (r < 0)
_exit(EXIT_FAILURE);
for (addr = resp; addr; addr = sd_rtnl_message_next(addr)) {
uint16_t type;
- unsigned char family;
- union {
- struct in_addr in;
- struct in6_addr in6;
- } in_addr;
+ unsigned char family, scope;
+ union in_addr_union in_addr;
struct iovec iov[2];
+ unsigned char flags;
+
+ r = sd_rtnl_message_get_errno(addr);
+ if (r < 0)
+ _exit(EXIT_FAILURE);
r = sd_rtnl_message_get_type(addr, &type);
if (r < 0)
@@ -214,6 +213,20 @@ int bus_machine_method_get_addresses(sd_bus *bus, sd_bus_message *message, void
if (type != RTM_NEWADDR)
continue;
+ r = sd_rtnl_message_addr_get_flags(addr, &flags);
+ if (r < 0)
+ _exit(EXIT_FAILURE);
+
+ if (flags & IFA_F_DEPRECATED)
+ continue;
+
+ r = sd_rtnl_message_addr_get_scope(addr, &scope);
+ if (r < 0)
+ _exit(EXIT_FAILURE);
+
+ if (scope == RT_SCOPE_HOST || scope == RT_SCOPE_NOWHERE)
+ continue;
+
r = sd_rtnl_message_addr_get_family(addr, &family);
if (r < 0)
_exit(EXIT_FAILURE);
@@ -225,8 +238,11 @@ int bus_machine_method_get_addresses(sd_bus *bus, sd_bus_message *message, void
case AF_INET:
r = sd_rtnl_message_read_in_addr(addr, IFA_LOCAL, &in_addr.in);
- if (r < 0)
- _exit(EXIT_FAILURE);
+ if (r < 0) {
+ r = sd_rtnl_message_read_in_addr(addr, IFA_ADDRESS, &in_addr.in);
+ if (r < 0)
+ _exit(EXIT_FAILURE);
+ }
if (in_addr.in.s_addr == htobe32(INADDR_LOOPBACK))
continue;
@@ -236,9 +252,12 @@ int bus_machine_method_get_addresses(sd_bus *bus, sd_bus_message *message, void
case AF_INET6:
- r = sd_rtnl_message_read_in6_addr(addr, IFA_ADDRESS, &in_addr.in6);
- if (r < 0)
- _exit(EXIT_FAILURE);
+ r = sd_rtnl_message_read_in6_addr(addr, IFA_LOCAL, &in_addr.in6);
+ if (r < 0) {
+ r = sd_rtnl_message_read_in6_addr(addr, IFA_ADDRESS, &in_addr.in6);
+ if (r < 0)
+ _exit(EXIT_FAILURE);
+ }
if (IN6_IS_ADDR_LOOPBACK(&in_addr.in6))
continue;
@@ -271,10 +290,7 @@ int bus_machine_method_get_addresses(sd_bus *bus, sd_bus_message *message, void
for (;;) {
unsigned char family;
ssize_t n;
- union {
- struct in_addr in;
- struct in6_addr in6;
- } in_addr;
+ union in_addr_union in_addr;
struct iovec iov[2];
struct msghdr mh = {
.msg_iov = iov,
commit 47efffc22badb20124dca5ed8c3b52911d71fc31
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 20:12:07 2014 +0200
nss-myhostname: following the usual naming scheme for .c/.h files
diff --git a/Makefile.am b/Makefile.am
index 5050820..425a5e1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4398,8 +4398,8 @@ endif
if HAVE_MYHOSTNAME
libnss_myhostname_la_SOURCES = \
src/nss-myhostname/nss-myhostname.c \
- src/nss-myhostname/ifconf.h \
- src/nss-myhostname/netlink.c
+ src/nss-myhostname/addresses.h \
+ src/nss-myhostname/addresses.c
libnss_myhostname_la_LDFLAGS = \
$(AM_LDFLAGS) \
diff --git a/src/nss-myhostname/addresses.c b/src/nss-myhostname/addresses.c
new file mode 100644
index 0000000..d75e850
--- /dev/null
+++ b/src/nss-myhostname/addresses.c
@@ -0,0 +1,149 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2008-2011 Lennart Poettering
+ Copyright 2014 Tom Gundersen
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "sd-rtnl.h"
+#include "rtnl-util.h"
+#include "macro.h"
+#include "addresses.h"
+
+static int address_compare(const void *_a, const void *_b) {
+ const struct address *a = _a, *b = _b;
+
+ /* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
+
+ if (a->scope < b->scope)
+ return -1;
+ if (a->scope > b->scope)
+ return 1;
+
+ if (a->family == AF_INET && b->family == AF_INET6)
+ return -1;
+ if (a->family == AF_INET6 && b->family == AF_INET)
+ return 1;
+
+ if (a->ifindex < b->ifindex)
+ return -1;
+ if (a->ifindex > b->ifindex)
+ return 1;
+
+ return 0;
+}
+
+int acquire_addresses(struct address **_list, unsigned *_n_list) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
+ _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+ _cleanup_free_ struct address *list = NULL;
+ size_t n_list = 0, n_allocated = 0;
+ sd_rtnl_message *m;
+ int r;
+
+ r = sd_rtnl_open(&rtnl, 0);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_call(rtnl, req, 0, &reply);
+ if (r < 0)
+ return r;
+
+ for (m = reply; m; m = sd_rtnl_message_next(m)) {
+ struct address *a;
+ unsigned char flags;
+ uint16_t type;
+
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_message_get_type(m, &type);
+ if (r < 0)
+ return r;
+
+ if (type != RTM_NEWADDR)
+ continue;
+
+ r = sd_rtnl_message_addr_get_flags(m, &flags);
+ if (r < 0)
+ return r;
+
+ if (flags & IFA_F_DEPRECATED)
+ continue;
+
+ if (!GREEDY_REALLOC(list, n_allocated, n_list+1))
+ return -ENOMEM;
+
+ a = list + n_list;
+
+ r = sd_rtnl_message_addr_get_scope(m, &a->scope);
+ if (r < 0)
+ return r;
+
+ if (a->scope == RT_SCOPE_HOST || a->scope == RT_SCOPE_NOWHERE)
+ continue;
+
+ r = sd_rtnl_message_addr_get_family(m, &a->family);
+ if (r < 0)
+ return r;
+
+ switch (a->family) {
+
+ case AF_INET:
+ r = sd_rtnl_message_read_in_addr(m, IFA_LOCAL, &a->address.in);
+ if (r < 0) {
+ r = sd_rtnl_message_read_in_addr(m, IFA_ADDRESS, &a->address.in);
+ if (r < 0)
+ continue;
+ }
+ break;
+
+ case AF_INET6:
+ r = sd_rtnl_message_read_in6_addr(m, IFA_LOCAL, &a->address.in6);
+ if (r < 0) {
+ r = sd_rtnl_message_read_in6_addr(m, IFA_ADDRESS, &a->address.in6);
+ if (r < 0)
+ continue;
+ }
+ break;
+
+ default:
+ continue;
+ }
+
+ r = sd_rtnl_message_addr_get_ifindex(m, &a->ifindex);
+ if (r < 0)
+ return r;
+
+ n_list++;
+ };
+
+ if (n_list)
+ qsort(list, n_list, sizeof(struct address), address_compare);
+
+ *_list = list;
+ list = NULL;
+ *_n_list = n_list;
+
+ return 0;
+}
diff --git a/src/nss-myhostname/addresses.h b/src/nss-myhostname/addresses.h
new file mode 100644
index 0000000..1bfb357
--- /dev/null
+++ b/src/nss-myhostname/addresses.h
@@ -0,0 +1,43 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2008-2011 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <inttypes.h>
+#include <sys/types.h>
+#include <assert.h>
+#include <sys/socket.h>
+
+#include "socket-util.h"
+
+struct address {
+ unsigned char family, scope;
+ union in_addr_union address;
+ int ifindex;
+};
+
+static inline size_t PROTO_ADDRESS_SIZE(int proto) {
+ assert(proto == AF_INET || proto == AF_INET6);
+
+ return proto == AF_INET6 ? 16 : 4;
+}
+
+int acquire_addresses(struct address **_list, unsigned *_n_list);
diff --git a/src/nss-myhostname/ifconf.h b/src/nss-myhostname/ifconf.h
deleted file mode 100644
index 92f03b2..0000000
--- a/src/nss-myhostname/ifconf.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2008-2011 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <inttypes.h>
-#include <sys/types.h>
-#include <assert.h>
-#include <sys/socket.h>
-
-#include "socket-util.h"
-
-struct address {
- unsigned char family;
- union in_addr_union address;
- unsigned char scope;
- int ifindex;
-};
-
-static inline size_t PROTO_ADDRESS_SIZE(int proto) {
- assert(proto == AF_INET || proto == AF_INET6);
-
- return proto == AF_INET6 ? 16 : 4;
-}
-
-int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list);
diff --git a/src/nss-myhostname/netlink.c b/src/nss-myhostname/netlink.c
deleted file mode 100644
index e9518e3..0000000
--- a/src/nss-myhostname/netlink.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2008-2011 Lennart Poettering
- Copyright 2014 Tom Gundersen
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include "sd-rtnl.h"
-#include "rtnl-util.h"
-#include "macro.h"
-#include "ifconf.h"
-
-static int address_compare(const void *_a, const void *_b) {
- const struct address *a = _a, *b = _b;
-
- /* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
-
- if (a->scope < b->scope)
- return -1;
- if (a->scope > b->scope)
- return 1;
-
- if (a->family == AF_INET && b->family == AF_INET6)
- return -1;
- if (a->family == AF_INET6 && b->family == AF_INET)
- return 1;
-
- if (a->ifindex < b->ifindex)
- return -1;
- if (a->ifindex > b->ifindex)
- return 1;
-
- return 0;
-}
-
-int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
- _cleanup_free_ struct address *list = NULL;
- size_t n_list = 0, n_allocated = 0;
- sd_rtnl_message *m;
- int r;
-
- r = sd_rtnl_open(&rtnl, 0);
- if (r < 0)
- return r;
-
- r = sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC);
- if (r < 0)
- return r;
-
- r = sd_rtnl_call(rtnl, req, 0, &reply);
- if (r < 0)
- return r;
-
- for (m = reply; m; m = sd_rtnl_message_next(m)) {
- struct address *a;
- unsigned char flags;
- uint16_t type;
-
- r = sd_rtnl_message_get_errno(m);
- if (r < 0)
- return r;
-
- r = sd_rtnl_message_get_type(m, &type);
- if (r < 0)
- return r;
-
- if (type != RTM_NEWADDR)
- continue;
-
- r = sd_rtnl_message_addr_get_flags(m, &flags);
- if (r < 0)
- return r;
-
- if (flags & IFA_F_DEPRECATED)
- continue;
-
- if (!GREEDY_REALLOC(list, n_allocated, n_list+1))
- return -ENOMEM;
-
- a = list + n_list;
-
- r = sd_rtnl_message_addr_get_scope(m, &a->scope);
- if (r < 0)
- return r;
-
- if (a->scope == RT_SCOPE_HOST || a->scope == RT_SCOPE_NOWHERE)
- continue;
-
- r = sd_rtnl_message_addr_get_family(m, &a->family);
- if (r < 0)
- return r;
-
- switch (a->family) {
-
- case AF_INET:
- r = sd_rtnl_message_read_in_addr(m, IFA_LOCAL, &a->address.in);
- if (r < 0) {
- r = sd_rtnl_message_read_in_addr(m, IFA_ADDRESS, &a->address.in);
- if (r < 0)
- continue;
- }
- break;
-
- case AF_INET6:
- r = sd_rtnl_message_read_in6_addr(m, IFA_LOCAL, &a->address.in6);
- if (r < 0) {
- r = sd_rtnl_message_read_in6_addr(m, IFA_ADDRESS, &a->address.in6);
- if (r < 0)
- continue;
- }
- break;
-
- default:
- continue;
- }
-
- r = sd_rtnl_message_addr_get_ifindex(m, &a->ifindex);
- if (r < 0)
- return r;
-
- n_list++;
- };
-
- if (n_list)
- qsort(list, n_list, sizeof(struct address), address_compare);
-
- *_list = list;
- list = NULL;
- *_n_list = n_list;
-
- return 0;
-}
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 9320e69..6551ac9 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -30,7 +30,7 @@
#include <stdlib.h>
#include <arpa/inet.h>
-#include "ifconf.h"
+#include "addresses.h"
#include "macro.h"
/* Ensure that glibc's assert is used. We cannot use assert from macro.h, as
@@ -137,7 +137,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
}
/* If this fails, n_addresses is 0. Which is fine */
- ifconf_acquire_addresses(&addresses, &n_addresses);
+ acquire_addresses(&addresses, &n_addresses);
canonical = hn;
local_address_ipv4 = LOCALADDRESS_IPV4;
@@ -389,7 +389,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
return NSS_STATUS_NOTFOUND;
}
- ifconf_acquire_addresses(&addresses, &n_addresses);
+ acquire_addresses(&addresses, &n_addresses);
canonical = hn;
additional = n_addresses <= 0 && af == AF_INET6 ? "localhost" : NULL;
@@ -492,7 +492,7 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
return NSS_STATUS_UNAVAIL;
}
- ifconf_acquire_addresses(&addresses, &n_addresses);
+ acquire_addresses(&addresses, &n_addresses);
for (a = addresses, n = 0; n < n_addresses; n++, a++) {
if (af != a->family)
commit 5502f0d97185218b93f01f9fe979a71bae38e213
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 19:55:53 2014 +0200
nss-myhostname: various modernizations
diff --git a/src/nss-myhostname/ifconf.h b/src/nss-myhostname/ifconf.h
index cd598d2..92f03b2 100644
--- a/src/nss-myhostname/ifconf.h
+++ b/src/nss-myhostname/ifconf.h
@@ -26,43 +26,19 @@
#include <assert.h>
#include <sys/socket.h>
+#include "socket-util.h"
+
struct address {
unsigned char family;
- uint8_t address[16];
+ union in_addr_union address;
unsigned char scope;
int ifindex;
};
-#define _public_ __attribute__ ((visibility("default")))
-#define _hidden_ __attribute__ ((visibility("hidden")))
-
-int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) _hidden_;
-
static inline size_t PROTO_ADDRESS_SIZE(int proto) {
assert(proto == AF_INET || proto == AF_INET6);
return proto == AF_INET6 ? 16 : 4;
}
-static inline int address_compare(const void *_a, const void *_b) {
- const struct address *a = _a, *b = _b;
-
- /* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
-
- if (a->scope < b->scope)
- return -1;
- if (a->scope > b->scope)
- return 1;
-
- if (a->family == AF_INET && b->family == AF_INET6)
- return -1;
- if (a->family == AF_INET6 && b->family == AF_INET)
- return 1;
-
- if (a->ifindex < b->ifindex)
- return -1;
- if (a->ifindex > b->ifindex)
- return 1;
-
- return 0;
-}
+int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list);
diff --git a/src/nss-myhostname/netlink.c b/src/nss-myhostname/netlink.c
index b4a464c..e9518e3 100644
--- a/src/nss-myhostname/netlink.c
+++ b/src/nss-myhostname/netlink.c
@@ -23,16 +23,37 @@
#include "sd-rtnl.h"
#include "rtnl-util.h"
#include "macro.h"
-
#include "ifconf.h"
+static int address_compare(const void *_a, const void *_b) {
+ const struct address *a = _a, *b = _b;
+
+ /* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
+
+ if (a->scope < b->scope)
+ return -1;
+ if (a->scope > b->scope)
+ return 1;
+
+ if (a->family == AF_INET && b->family == AF_INET6)
+ return -1;
+ if (a->family == AF_INET6 && b->family == AF_INET)
+ return 1;
+
+ if (a->ifindex < b->ifindex)
+ return -1;
+ if (a->ifindex > b->ifindex)
+ return 1;
+
+ return 0;
+}
+
int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) {
- _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
- sd_rtnl_message *m;
+ _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
_cleanup_free_ struct address *list = NULL;
- struct address *new_list = NULL;
- unsigned n_list = 0;
+ size_t n_list = 0, n_allocated = 0;
+ sd_rtnl_message *m;
int r;
r = sd_rtnl_open(&rtnl, 0);
@@ -46,18 +67,11 @@ int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) {
r = sd_rtnl_call(rtnl, req, 0, &reply);
if (r < 0)
return r;
- m = reply;
- do {
- uint16_t type;
- unsigned char scope;
+ for (m = reply; m; m = sd_rtnl_message_next(m)) {
+ struct address *a;
unsigned char flags;
- unsigned char family;
- int ifindex;
- union {
- struct in_addr in;
- struct in6_addr in6;
- } address;
+ uint16_t type;
r = sd_rtnl_message_get_errno(m);
if (r < 0)
@@ -70,72 +84,66 @@ int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) {
if (type != RTM_NEWADDR)
continue;
- r = sd_rtnl_message_addr_get_scope(m, &scope);
+ r = sd_rtnl_message_addr_get_flags(m, &flags);
if (r < 0)
return r;
- if (scope == RT_SCOPE_HOST || scope == RT_SCOPE_NOWHERE)
+ if (flags & IFA_F_DEPRECATED)
continue;
- r = sd_rtnl_message_addr_get_flags(m, &flags);
+ if (!GREEDY_REALLOC(list, n_allocated, n_list+1))
+ return -ENOMEM;
+
+ a = list + n_list;
+
+ r = sd_rtnl_message_addr_get_scope(m, &a->scope);
if (r < 0)
return r;
- if (flags & IFA_F_DEPRECATED)
+ if (a->scope == RT_SCOPE_HOST || a->scope == RT_SCOPE_NOWHERE)
continue;
- r = sd_rtnl_message_addr_get_family(m, &family);
+ r = sd_rtnl_message_addr_get_family(m, &a->family);
if (r < 0)
return r;
- switch (family) {
+ switch (a->family) {
+
case AF_INET:
- r = sd_rtnl_message_read_in_addr(m, IFA_LOCAL, &address.in);
+ r = sd_rtnl_message_read_in_addr(m, IFA_LOCAL, &a->address.in);
if (r < 0) {
- r = sd_rtnl_message_read_in_addr(m, IFA_ADDRESS, &address.in);
+ r = sd_rtnl_message_read_in_addr(m, IFA_ADDRESS, &a->address.in);
if (r < 0)
continue;
}
break;
+
case AF_INET6:
- r = sd_rtnl_message_read_in6_addr(m, IFA_LOCAL, &address.in6);
+ r = sd_rtnl_message_read_in6_addr(m, IFA_LOCAL, &a->address.in6);
if (r < 0) {
- r = sd_rtnl_message_read_in6_addr(m, IFA_ADDRESS, &address.in6);
+ r = sd_rtnl_message_read_in6_addr(m, IFA_ADDRESS, &a->address.in6);
if (r < 0)
continue;
}
break;
+
default:
continue;
}
- r = sd_rtnl_message_addr_get_ifindex(m, &ifindex);
+ r = sd_rtnl_message_addr_get_ifindex(m, &a->ifindex);
if (r < 0)
return r;
- new_list = realloc(list, (n_list+1) * sizeof(struct address));
- if (!new_list)
- return -ENOMEM;
- else
- list = new_list;
-
- assert_cc(sizeof(address) <= 16);
-
- list[n_list].family = family;
- list[n_list].scope = scope;
- memcpy(list[n_list].address, &address, sizeof(address));
- list[n_list].ifindex = ifindex;
-
n_list++;
-
- } while ((m = sd_rtnl_message_next(m)));
+ };
if (n_list)
qsort(list, n_list, sizeof(struct address), address_compare);
- *_n_list = n_list;
*_list = list;
list = NULL;
+ *_n_list = n_list;
return 0;
}
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 60e256d..9320e69 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -98,32 +98,39 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
- unsigned lo_ifi;
- char hn[HOST_NAME_MAX+1] = {};
- const char *canonical = NULL;
- size_t l, idx, ms;
- char *r_name;
struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;
- struct address *addresses = NULL, *a;
+ _cleanup_free_ struct address *addresses = NULL;
+ _cleanup_free_ char *hn = NULL;
+ const char *canonical = NULL;
unsigned n_addresses = 0, n;
uint32_t local_address_ipv4;
+ struct address *a;
+ size_t l, idx, ms;
+ char *r_name;
+ int lo_ifi;
- if (strcasecmp(name, "localhost") == 0) {
+ assert(name);
+ assert(pat);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
+
+ if (is_localhost(name)) {
/* We respond to 'localhost', so that /etc/hosts
* is optional */
canonical = "localhost";
local_address_ipv4 = htonl(INADDR_LOOPBACK);
} else {
- /* We respond to our local host name */
-
- if (gethostname(hn, sizeof(hn)-1) < 0) {
- *errnop = errno;
+ hn = gethostname_malloc();
+ if (!hn) {
+ *errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
- return NSS_STATUS_UNAVAIL;
+ return NSS_STATUS_TRYAGAIN;
}
- if (strcasecmp(name, hn) != 0) {
+ /* We respond to our local host name, our our hostname suffixed with a single dot. */
+ if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND;
@@ -140,11 +147,10 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
lo_ifi = n_addresses <= 0 ? if_nametoindex(LOOPBACK_INTERFACE) : 0;
l = strlen(canonical);
- ms = ALIGN(l+1)+ALIGN(sizeof(struct gaih_addrtuple))*(n_addresses > 0 ? n_addresses : 2);
+ ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 2);
if (buflen < ms) {
*errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
- free(addresses);
return NSS_STATUS_TRYAGAIN;
}
@@ -184,7 +190,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
r_tuple->name = r_name;
r_tuple->family = a->family;
r_tuple->scopeid = a->ifindex;
- memcpy(r_tuple->addr, a->address, 16);
+ memcpy(r_tuple->addr, &a->address, 16);
idx += ALIGN(sizeof(struct gaih_addrtuple));
r_tuple_prev = r_tuple;
@@ -202,8 +208,6 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
if (ttlp)
*ttlp = 0;
- free(addresses);
-
return NSS_STATUS_SUCCESS;
}
@@ -224,6 +228,12 @@ static enum nss_status fill_in_hostent(
struct address *a;
unsigned n, c;
+ assert(canonical);
+ assert(result);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
+
alen = PROTO_ADDRESS_SIZE(af);
for (a = addresses, n = 0, c = 0; n < n_addresses; a++, n++)
@@ -234,15 +244,14 @@ static enum nss_status fill_in_hostent(
l_additional = additional ? strlen(additional) : 0;
ms = ALIGN(l_canonical+1)+
(additional ? ALIGN(l_additional+1) : 0) +
- sizeof(char*)+
+ sizeof(char*) +
(additional ? sizeof(char*) : 0) +
- (c > 0 ? c : 1)*ALIGN(alen)+
- (c > 0 ? c+1 : 2)*sizeof(char*);
+ (c > 0 ? c : 1) * ALIGN(alen)+
+ (c > 0 ? c+1 : 2) * sizeof(char*);
if (buflen < ms) {
*errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
- free(addresses);
return NSS_STATUS_TRYAGAIN;
}
@@ -277,7 +286,7 @@ static enum nss_status fill_in_hostent(
if (af != a->family)
continue;
- memcpy(r_addr + i*ALIGN(alen), a->address, alen);
+ memcpy(r_addr + i*ALIGN(alen), &a->address, alen);
i++;
}
@@ -330,8 +339,6 @@ static enum nss_status fill_in_hostent(
if (canonp)
*canonp = r_name;
- free(addresses);
-
return NSS_STATUS_SUCCESS;
}
@@ -344,11 +351,17 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
int32_t *ttlp,
char **canonp) {
- char hn[HOST_NAME_MAX+1] = {};
- struct address *addresses = NULL;
- unsigned n_addresses = 0;
+ _cleanup_free_ struct address *addresses = NULL;
const char *canonical, *additional = NULL;
+ _cleanup_free_ char *hn = NULL;
uint32_t local_address_ipv4;
+ unsigned n_addresses = 0;
+
+ assert(name);
+ assert(host);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
if (af == AF_UNSPEC)
af = AF_INET;
@@ -359,17 +372,18 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
return NSS_STATUS_UNAVAIL;
}
- if (strcasecmp(name, "localhost") == 0) {
+ if (is_localhost(name)) {
canonical = "localhost";
local_address_ipv4 = htonl(INADDR_LOOPBACK);
} else {
- if (gethostname(hn, sizeof(hn)-1) < 0) {
- *errnop = errno;
+ hn = gethostname_malloc();
+ if (!hn) {
+ *errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
- return NSS_STATUS_UNAVAIL;
+ return NSS_STATUS_TRYAGAIN;
}
- if (strcasecmp(name, hn) != 0) {
+ if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND;
@@ -435,12 +449,18 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
- char hn[HOST_NAME_MAX+1] = {};
- struct address *addresses = NULL;
- struct address *a;
- unsigned n_addresses = 0, n;
- uint32_t local_address_ipv4 = LOCALADDRESS_IPV4;
const char *canonical = NULL, *additional = NULL;
+ uint32_t local_address_ipv4 = LOCALADDRESS_IPV4;
+ _cleanup_free_ struct address *addresses = NULL;
+ _cleanup_free_ char *hn = NULL;
+ unsigned n_addresses = 0, n;
+ struct address *a;
+
+ assert(addr);
+ assert(host);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
if (len != PROTO_ADDRESS_SIZE(af)) {
*errnop = EINVAL;
@@ -478,26 +498,22 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
if (af != a->family)
continue;
- if (memcmp(addr, a->address, PROTO_ADDRESS_SIZE(af)) == 0)
+ if (memcmp(addr, &a->address, PROTO_ADDRESS_SIZE(af)) == 0)
goto found;
}
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
- free(addresses);
-
return NSS_STATUS_NOTFOUND;
found:
if (!canonical) {
- if (gethostname(hn, sizeof(hn)-1) < 0) {
- *errnop = errno;
+ hn = gethostname_malloc();
+ if (!hn) {
+ *errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
-
- free(addresses);
-
- return NSS_STATUS_UNAVAIL;
+ return NSS_STATUS_TRYAGAIN;
}
canonical = hn;
commit 096b6773886bd7a0c8c97aa684b0b67dfae58355
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 18:25:51 2014 +0200
resolved: properly free network monitor
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 9d073c7..b4f4d07 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -149,6 +149,8 @@ void manager_free(Manager *m) {
if (!m)
return;
+ sd_event_source_unref(m->network_event_source);
+ sd_network_monitor_unref(m->network_monitor);
sd_event_unref(m->event);
while ((address = m->fallback_dns)) {
commit 138992534878483de28417dfc61c546bba5cb8ad
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 18:25:08 2014 +0200
event: pull in sd-event.h from event-util.h
diff --git a/src/libsystemd/sd-event/event-util.h b/src/libsystemd/sd-event/event-util.h
index e58020d..e7cad9b 100644
--- a/src/libsystemd/sd-event/event-util.h
+++ b/src/libsystemd/sd-event/event-util.h
@@ -22,6 +22,7 @@
***/
#include "util.h"
+#include "sd-event.h"
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_event*, sd_event_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_event_source*, sd_event_source_unref);
commit 27f1e9ebf6f9e7ff8a898f894c1b38cbdecfa77c
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jul 10 18:24:55 2014 +0200
update TODO
diff --git a/TODO b/TODO
index 8d6c83e..65f756d 100644
--- a/TODO
+++ b/TODO
@@ -28,7 +28,9 @@ Features:
* the resolv.conf tmpfiles line should be covered by ENABLE_NETWORKD...
-* sysusers: also create entries in /etc/shadow, /etc/gshadow
+* sysusers:
+ - also create entries in /etc/shadow, /etc/gshadow
+ - allow setting the home directory of system users
* Add a new verb "systemctl top"
More information about the systemd-commits
mailing list