systemd: merge branch 'systemd' into master

This commit is contained in:
Thomas Haller
2016-01-04 15:22:51 +01:00
75 changed files with 1086 additions and 547 deletions

View File

@@ -60,7 +60,6 @@ noinst_LTLIBRARIES = \
SYSTEMD_NM_CFLAGS_PATHS = \
-I$(top_srcdir)/src/systemd/src/systemd \
-I$(top_srcdir)/src/systemd/src/libsystemd-network \
-I$(top_srcdir)/src/systemd/src/libsystemd/sd-event \
-I$(top_srcdir)/src/systemd/src/basic \
-I$(top_srcdir)/src/systemd
@@ -143,7 +142,6 @@ libsystemd_nm_la_SOURCES = \
systemd/src/libsystemd-network/lldp-tlv.h \
systemd/src/libsystemd-network/lldp-port.c \
systemd/src/libsystemd-network/lldp-port.h \
systemd/src/libsystemd-network/lldp-util.h \
systemd/src/libsystemd-network/lldp-internal.h \
systemd/src/libsystemd-network/lldp-internal.c \
systemd/src/libsystemd-network/network-internal.c \
@@ -156,7 +154,6 @@ libsystemd_nm_la_SOURCES = \
systemd/src/libsystemd-network/sd-ipv4ll.c \
systemd/src/libsystemd-network/sd-lldp.c \
systemd/src/libsystemd/sd-id128/sd-id128.c \
systemd/src/libsystemd/sd-event/event-util.h \
systemd/src/shared/dns-domain.c \
systemd/src/shared/dns-domain.h \
systemd/src/systemd/_sd-common.h \
@@ -166,7 +163,6 @@ libsystemd_nm_la_SOURCES = \
systemd/src/systemd/sd-dhcp6-lease.h \
systemd/src/systemd/sd-lldp.h \
systemd/src/systemd/sd-event.h \
systemd/src/systemd/sd-icmp6-nd.h \
systemd/src/systemd/sd-id128.h \
systemd/src/systemd/sd-ipv4acd.h \
systemd/src/systemd/sd-ipv4ll.h \

View File

@@ -451,7 +451,7 @@ nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface,
err:
sd_lldp_detach_event (priv->lldp_handle);
err_free:
sd_lldp_free (priv->lldp_handle);
sd_lldp_unref (priv->lldp_handle);
priv->lldp_handle = NULL;
return FALSE;
}
@@ -468,7 +468,7 @@ nm_lldp_listener_stop (NMLldpListener *self)
if (priv->lldp_handle) {
sd_lldp_stop (priv->lldp_handle);
sd_lldp_detach_event (priv->lldp_handle);
sd_lldp_free (priv->lldp_handle);
sd_lldp_unref (priv->lldp_handle);
g_clear_pointer (&priv->iface, g_free);
priv->lldp_handle = NULL;

View File

@@ -150,7 +150,7 @@ test_ip6_address_general (void)
/* Remove address again */
nmtstp_ip6_address_del (EX, ifindex, addr, IP6_PLEN);
/* ensure no pending signal. */
/* ensure not pending signal. */
accept_signals (address_changed, 0, 1);
free_signal (address_added);

View File

@@ -21,7 +21,11 @@
#include "nm-sd-adapt.h"
#include <stdint.h>
#include <string.h>
#include "alloc-util.h"
#include "macro.h"
#include "util.h"
void* memdup(const void *p, size_t l) {

View File

@@ -24,6 +24,7 @@
#include "nm-sd-adapt.h"
#include <alloca.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

View File

@@ -21,12 +21,15 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "alloc-util.h"
#include "escape.h"
#include "hexdecoct.h"
#include "string-util.h"
#include "macro.h"
#include "utf8.h"
#include "util.h"
size_t cescape_char(char c, char *buf) {
char * buf_old = buf;
@@ -91,20 +94,20 @@ size_t cescape_char(char c, char *buf) {
return buf - buf_old;
}
char *cescape(const char *s) {
char *r, *t;
char *cescape_length(const char *s, size_t n) {
const char *f;
char *r, *t;
assert(s);
assert(s || n == 0);
/* Does C style string escaping. May be reversed with
* cunescape(). */
r = new(char, strlen(s)*4 + 1);
r = new(char, n*4 + 1);
if (!r)
return NULL;
for (f = s, t = r; *f; f++)
for (f = s, t = r; f < s + n; f++)
t += cescape_char(*f, t);
*t = 0;
@@ -112,6 +115,12 @@ char *cescape(const char *s) {
return r;
}
char *cescape(const char *s) {
assert(s);
return cescape_length(s, strlen(s));
}
int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_unicode) {
int r = 1;

View File

@@ -24,8 +24,12 @@
#include "nm-sd-adapt.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include "string-util.h"
/* What characters are special in the shell? */
/* must be escaped outside and inside double-quotes */
#define SHELL_NEED_ESCAPE "\"\\`$"
@@ -37,6 +41,7 @@ typedef enum UnescapeFlags {
} UnescapeFlags;
char *cescape(const char *s);
char *cescape_length(const char *s, size_t n);
size_t cescape_char(char c, char *buf);
int cunescape(const char *s, UnescapeFlags flags, char **ret);

View File

@@ -21,13 +21,20 @@
#include "nm-sd-adapt.h"
#if 0 /* NM_IGNORED */
#include "dirent-util.h"
#endif /* NM_IGNORED */
#include <errno.h>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include "fd-util.h"
#include "macro.h"
#if 0 /* NM_IGNORED */
#include "parse-util.h"
#include "missing.h"
#endif /* NM_IGNORED */
#include "parse-util.h"
#include "path-util.h"
#include "socket-util.h"
#include "util.h"

View File

@@ -21,6 +21,15 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "alloc-util.h"
@@ -30,6 +39,8 @@
#include "fileio.h"
#include "fs-util.h"
#include "hexdecoct.h"
#include "log.h"
#include "macro.h"
#include "parse-util.h"
#include "path-util.h"
#include "random-util.h"
@@ -38,9 +49,9 @@
#endif /* NM_IGNORED */
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#include "umask-util.h"
#include "utf8.h"
#include "util.h"
int write_string_stream(FILE *f, const char *line, bool enforce_newline) {

View File

@@ -21,6 +21,16 @@
#include "nm-sd-adapt.h"
#include <dirent.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include "alloc-util.h"
#if 0 /* NM_IGNORED */
#include "dirent-util.h"
@@ -28,13 +38,17 @@
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "log.h"
#include "macro.h"
#if 0 /* NM_IGNORED */
#include "missing.h"
#include "mkdir.h"
#endif /* NM_IGNORED */
#include "parse-util.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#if 0 /* NM_IGNORED */
#include "user-util.h"
#endif /* NM_IGNORED */

View File

@@ -25,6 +25,8 @@
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/inotify.h>
#include <sys/types.h>
#include <unistd.h>

View File

@@ -23,8 +23,9 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "alloc-util.h"
#include "hashmap.h"
@@ -40,6 +41,7 @@
#include "util.h"
#ifdef ENABLE_DEBUG_HASHMAP
#include <pthread.h>
#include "list.h"
#endif

View File

@@ -24,7 +24,9 @@
#include "nm-sd-adapt.h"
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include "macro.h"
#include "siphash24.h"

View File

@@ -22,11 +22,13 @@
#include "nm-sd-adapt.h"
#include <ctype.h>
#include <inttypes.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include "alloc-util.h"
#include "hexdecoct.h"
#include "util.h"
#include "macro.h"
char octchar(int x) {
return '0' + (x & 7);

View File

@@ -24,6 +24,7 @@
#include "nm-sd-adapt.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>

View File

@@ -21,14 +21,19 @@
#include "nm-sd-adapt.h"
#include <ctype.h>
#include <bits/local_lim.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "fd-util.h"
#include "fileio.h"
#include "hostname-util.h"
#include "macro.h"
#include "string-util.h"
#include "util.h"
bool hostname_is_set(void) {
struct utsname u;

View File

@@ -22,9 +22,15 @@
#include "nm-sd-adapt.h"
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include "alloc-util.h"
#include "in-addr-util.h"
#include "macro.h"
#include "util.h"
int in_addr_is_null(int family, const union in_addr_union *u) {
assert(u);
@@ -46,7 +52,7 @@ int in_addr_is_link_local(int family, const union in_addr_union *u) {
assert(u);
if (family == AF_INET)
return (be32toh(u->in.s_addr) & 0xFFFF0000) == (169U << 24 | 254U << 16);
return (be32toh(u->in.s_addr) & UINT32_C(0xFFFF0000)) == (UINT32_C(169) << 24 | UINT32_C(254) << 16);
if (family == AF_INET6)
return IN6_IS_ADDR_LINKLOCAL(&u->in6);
@@ -54,6 +60,19 @@ int in_addr_is_link_local(int family, const union in_addr_union *u) {
return -EAFNOSUPPORT;
}
int in_addr_is_localhost(int family, const union in_addr_union *u) {
assert(u);
if (family == AF_INET)
/* All of 127.x.x.x is localhost. */
return (be32toh(u->in.s_addr) & UINT32_C(0xFF000000)) == UINT32_C(127) << 24;
if (family == AF_INET6)
return IN6_IS_ADDR_LOOPBACK(&u->in6);
return -EAFNOSUPPORT;
}
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) {
assert(a);
assert(b);

View File

@@ -24,6 +24,8 @@
#include "nm-sd-adapt.h"
#include <netinet/in.h>
#include <stddef.h>
#include <sys/socket.h>
#include "macro.h"
#include "util.h"
@@ -35,6 +37,7 @@ union in_addr_union {
int in_addr_is_null(int family, const union in_addr_union *u);
int in_addr_is_link_local(int family, const union in_addr_union *u);
int in_addr_is_localhost(int family, const union in_addr_union *u);
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b);
int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen);
int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);

View File

@@ -21,10 +21,15 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <limits.h>
#include <poll.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "io-util.h"
#include "time-util.h"
int flush_fd(int fd) {
struct pollfd pollfd = {

View File

@@ -24,9 +24,12 @@
#include "nm-sd-adapt.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/uio.h>
#include "macro.h"
#include "time-util.h"
int flush_fd(int fd);

View File

@@ -359,17 +359,15 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
#endif
#endif
#if 0 /* NM_IGNORED */
/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
* compiler versions */
#ifndef noreturn
#if __STDC_VERSION__ >= 201112L
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define noreturn _Noreturn
#else
#define noreturn __attribute__((noreturn))
#endif
#endif
#endif /* NM_IGNORED */
#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
static inline void func##p(type *p) { \

View File

@@ -22,6 +22,9 @@
#include "nm-sd-adapt.h"
#include <stdint.h>
#include <stdlib.h>
#include "macro.h"
#include "mempool.h"
#include "util.h"

View File

@@ -21,13 +21,21 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <inttypes.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xlocale.h>
#include "alloc-util.h"
#if 0 /* NM_IGNORED */
#include "extract-word.h"
#endif /* NM_IGNORED */
#include "macro.h"
#include "parse-util.h"
#include "string-util.h"
#include "util.h"
int parse_boolean(const char *v) {
assert(v);

View File

@@ -24,6 +24,9 @@
#include "nm-sd-adapt.h"
#include <inttypes.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include "macro.h"

View File

@@ -22,11 +22,11 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/statvfs.h>
#include <sys/stat.h>
#include <unistd.h>
/* When we include libgen.h because we need dirname() we immediately
@@ -37,23 +37,21 @@
#include "alloc-util.h"
#if 0 /* NM_IGNORED */
#include "fd-util.h"
#include "fileio.h"
#include "extract-word.h"
#endif /* NM_IGNORED */
#include "fs-util.h"
#include "log.h"
#include "macro.h"
#if 0 /* NM_IGNORED */
#include "missing.h"
#include "parse-util.h"
#endif /* NM_IGNORED */
#include "path-util.h"
#if 0 /* NM_IGNORED */
#include "stat-util.h"
#endif /* NM_IGNORED */
#include "string-util.h"
#if 0 /* NM_IGNORED */
#include "strv.h"
#endif /* NM_IGNORED */
#include "util.h"
#include "time-util.h"
#if 0 /* NM_IGNORED */
bool path_is_absolute(const char *p) {

View File

@@ -23,7 +23,9 @@
#include "nm-sd-adapt.h"
#include <alloca.h>
#include <stdbool.h>
#include <stddef.h>
#include "macro.h"
#include "time-util.h"

View File

@@ -31,9 +31,12 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <stdlib.h>
#include "alloc-util.h"
#include "hashmap.h"
#include "prioq.h"
#include "util.h"
struct prioq_item {
void *data;

View File

@@ -23,7 +23,10 @@
#include "nm-sd-adapt.h"
#include <stdbool.h>
#include "hashmap.h"
#include "macro.h"
typedef struct Prioq Prioq;

View File

@@ -19,16 +19,18 @@
#include "nm-sd-adapt.h"
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/time.h>
#include <linux/random.h>
#include <stdint.h>
#ifdef HAVE_SYS_AUXV_H
#include <sys/auxv.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include "fd-util.h"
#include "io-util.h"
@@ -37,7 +39,6 @@
#endif
#include "random-util.h"
#include "time-util.h"
#include "util.h"
int dev_urandom(void *p, size_t n) {
#if 0 /* NM_IGNORED */

View File

@@ -21,6 +21,7 @@
#include "nm-sd-adapt.h"
#include <stddef.h>
#include <stdint.h>
int dev_urandom(void *p, size_t n);

View File

@@ -29,7 +29,6 @@
Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
static inline Set *set_free(Set *s) {
internal_hashmap_free(HASHMAP_BASE(s));
return NULL;

View File

@@ -19,10 +19,9 @@
#include "nm-sd-adapt.h"
#include "macro.h"
#include "siphash24.h"
#include "sparse-endian.h"
#include "unaligned.h"
#include "util.h"
static inline uint64_t rotate_left(uint64_t x, uint8_t b) {
assert(b < 64);

View File

@@ -3,6 +3,8 @@
#include "nm-sd-adapt.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
struct siphash {

View File

@@ -25,7 +25,10 @@
#include <netinet/ether.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <linux/netlink.h>
#include <linux/if_packet.h>
@@ -127,7 +130,11 @@ int ip_tos_from_string(const char *s);
int getpeercred(int fd, struct ucred *ucred);
int getpeersec(int fd, char **ret);
int send_one_fd(int transport_fd, int fd, int flags);
int send_one_fd_sa(int transport_fd,
int fd,
const struct sockaddr *sa, socklen_t len,
int flags);
#define send_one_fd(transport_fd, fd, flags) send_one_fd_sa(transport_fd, fd, NULL, 0, flags)
int receive_one_fd(int transport_fd, int flags);
#define CMSG_FOREACH(cmsg, mh) \

View File

@@ -22,6 +22,7 @@
#include "nm-sd-adapt.h"
#include "string-table.h"
#include "string-util.h"
ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) {
size_t i;

View File

@@ -24,6 +24,7 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

View File

@@ -21,10 +21,17 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "alloc-util.h"
#if 0 /* NM_IGNORED */
#include "gunicode.h"
#endif /* NM_IGNORED */
#include "macro.h"
#include "string-util.h"
#include "utf8.h"
#include "util.h"

View File

@@ -23,7 +23,9 @@
#include "nm-sd-adapt.h"
#include <alloca.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "macro.h"

View File

@@ -22,12 +22,17 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <fnmatch.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "alloc-util.h"
#include "escape.h"
#if 0 /* NM_IGNORED */
#include "extract-word.h"
#endif /* NM_IGNORED */
#include "string-util.h"
#include "strv.h"
#include "util.h"

View File

@@ -26,10 +26,13 @@
#include <fnmatch.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include "alloc-util.h"
#if 0 /* NM_IGNORED */
#include "extract-word.h"
#endif /* NM_IGNORED */
#include "macro.h"
#include "util.h"
char *strv_find(char **l, const char *name) _pure_;

View File

@@ -21,22 +21,28 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timerfd.h>
#include <sys/timex.h>
#include <sys/types.h>
#include <unistd.h>
#include "alloc-util.h"
#include "fd-util.h"
#include "fileio.h"
#if 0 /* NM_IGNORED */
#include "fs-util.h"
#include "log.h"
#include "macro.h"
#include "parse-util.h"
#endif /* NM_IGNORED */
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#include "util.h"
usec_t now(clockid_t clock_id) {
struct timespec ts;

View File

@@ -24,6 +24,9 @@
#include "nm-sd-adapt.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>

View File

@@ -46,15 +46,14 @@
#include "nm-sd-adapt.h"
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "alloc-util.h"
#include "hexdecoct.h"
#include "macro.h"
#include "utf8.h"
#include "util.h"
bool unichar_is_valid(uint32_t ch) {

View File

@@ -24,6 +24,8 @@
#include "nm-sd-adapt.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "macro.h"

View File

@@ -21,99 +21,58 @@
#include "nm-sd-adapt.h"
#include <ctype.h>
#include <alloca.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <langinfo.h>
#include <libintl.h>
#include <limits.h>
#include <linux/magic.h>
#include <linux/oom.h>
#include <linux/sched.h>
#include <locale.h>
#include <poll.h>
#include <pwd.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/personality.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <sys/statfs.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/vfs.h>
#include <sys/wait.h>
#include <syslog.h>
#include <unistd.h>
/* When we include libgen.h because we need dirname() we immediately
* undefine basename() since libgen.h defines it as a macro to the
* POSIX version which is really broken. We prefer GNU basename(). */
#include <libgen.h>
#undef basename
#ifdef HAVE_SYS_AUXV_H
#include <sys/auxv.h>
#endif
/* We include linux/fs.h as last of the system headers, as it
* otherwise conflicts with sys/mount.h. Yay, Linux is great! */
#include <linux/fs.h>
#if 0 /* NM_IGNORED */
#include "alloc-util.h"
#if 0 /* NM_IGNORED */
#include "build.h"
#include "def.h"
#include "device-nodes.h"
#include "dirent-util.h"
#include "env-util.h"
#include "escape.h"
#include "exit-status.h"
#endif /* NM_IGNORED */
#include "fd-util.h"
#include "fileio.h"
#if 0 /* NM_IGNORED */
#include "formats-util.h"
#include "gunicode.h"
#include "hashmap.h"
#include "hexdecoct.h"
#include "hostname-util.h"
#include "ioprio.h"
#include "log.h"
#endif /* NM_IGNORED */
#include "hashmap.h"
#include "hostname-util.h"
#include "log.h"
#include "macro.h"
#if 0 /* NM_IGNORED */
#include "missing.h"
#include "mkdir.h"
#include "parse-util.h"
#endif /* NM_IGNORED */
#include "parse-util.h"
#include "path-util.h"
#if 0 /* NM_IGNORED */
#include "process-util.h"
#include "random-util.h"
#endif /* NM_IGNORED */
#include "set.h"
#if 0 /* NM_IGNORED */
#include "signal-util.h"
#include "sparse-endian.h"
#include "stat-util.h"
#include "string-table.h"
#endif /* NM_IGNORED */
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "time-util.h"
#if 0 /* NM_IGNORED */
#include "user-util.h"
#endif /* NM_IGNORED */
#include "utf8.h"
#include "util.h"
#if 0 /* NM_IGNORED */
#include "virt.h"
#endif /* NM_IGNORED */
/* Put this test here for a lack of better place */
assert_cc(EAGAIN == EWOULDBLOCK);

View File

@@ -24,6 +24,7 @@
#include "nm-sd-adapt.h"
#include <alloca.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
@@ -31,8 +32,10 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/inotify.h>
#include <sys/socket.h>
#include <sys/stat.h>

View File

@@ -49,8 +49,7 @@ int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset, uint8_
typedef int (*dhcp_option_cb_t)(uint8_t code, uint8_t len,
const void *option, void *userdata);
int dhcp_option_parse(DHCPMessage *message, size_t len,
dhcp_option_cb_t cb, void *userdata);
int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_cb_t cb, void *userdata, char **error_message);
int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
uint8_t type, uint16_t arp_type, size_t optlen,
@@ -64,13 +63,10 @@ void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_client*, sd_dhcp_client_unref);
#define _cleanup_dhcp_client_unref_ _cleanup_(sd_dhcp_client_unrefp)
/* If we are invoking callbacks of a dhcp-client, ensure unreffing the
* client from the callback doesn't destroy the object we are working
* on */
#define DHCP_CLIENT_DONT_DESTROY(client) \
_cleanup_dhcp_client_unref_ _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
_cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
#define log_dhcp_client(client, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP CLIENT (0x%x): " fmt, client->xid, ##__VA_ARGS__)

View File

@@ -104,6 +104,3 @@ int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id, size_t
int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file);
int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_lease*, sd_dhcp_lease_unref);
#define _cleanup_dhcp_lease_unref_ _cleanup_(sd_dhcp_lease_unrefp)

View File

@@ -26,6 +26,9 @@
#include <stdio.h>
#include <string.h>
#include "alloc-util.h"
#include "utf8.h"
#include "dhcp-internal.h"
static int option_append(uint8_t options[], size_t size, size_t *offset,
@@ -141,72 +144,84 @@ int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset,
}
static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overload,
uint8_t *message_type, dhcp_option_cb_t cb,
uint8_t *message_type, char **error_message, dhcp_option_cb_t cb,
void *userdata) {
uint8_t code, len;
const uint8_t *option;
size_t offset = 0;
while (offset < buflen) {
switch (options[offset]) {
case DHCP_OPTION_PAD:
offset++;
code = options[offset ++];
break;
switch (code) {
case DHCP_OPTION_PAD:
continue;
case DHCP_OPTION_END:
return 0;
}
case DHCP_OPTION_MESSAGE_TYPE:
if (buflen < offset + 3)
if (buflen < offset + 1)
return -ENOBUFS;
len = options[++offset];
len = options[offset ++];
if (buflen < offset + len)
return -EINVAL;
option = &options[offset];
switch (code) {
case DHCP_OPTION_MESSAGE_TYPE:
if (len != 1)
return -EINVAL;
if (message_type)
*message_type = options[++offset];
else
offset++;
offset++;
*message_type = *option;
break;
case DHCP_OPTION_OVERLOAD:
if (buflen < offset + 3)
return -ENOBUFS;
case DHCP_OPTION_ERROR_MESSAGE:
if (len == 0)
return -EINVAL;
len = options[++offset];
if (error_message) {
_cleanup_free_ char *string = NULL;
/* Accept a trailing NUL byte */
if (memchr(option, 0, len - 1))
return -EINVAL;
string = strndup((const char *) option, len);
if (!string)
return -ENOMEM;
if (!ascii_is_valid(string))
return -EINVAL;
free(*error_message);
*error_message = string;
string = NULL;
}
break;
case DHCP_OPTION_OVERLOAD:
if (len != 1)
return -EINVAL;
if (overload)
*overload = options[++offset];
else
offset++;
offset++;
*overload = *option;
break;
default:
if (buflen < offset + 3)
return -ENOBUFS;
code = options[offset];
len = options[++offset];
if (buflen < ++offset + len)
return -EINVAL;
if (cb)
cb(code, len, &options[offset], userdata);
offset += len;
cb(code, len, option, userdata);
break;
}
offset += len;
}
if (offset < buflen)
@@ -215,8 +230,8 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
return 0;
}
int dhcp_option_parse(DHCPMessage *message, size_t len,
dhcp_option_cb_t cb, void *userdata) {
int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_cb_t cb, void *userdata, char **_error_message) {
_cleanup_free_ char *error_message = NULL;
uint8_t overload = 0;
uint8_t message_type = 0;
int r;
@@ -229,27 +244,29 @@ int dhcp_option_parse(DHCPMessage *message, size_t len,
len -= sizeof(DHCPMessage);
r = parse_options(message->options, len, &overload, &message_type,
cb, userdata);
r = parse_options(message->options, len, &overload, &message_type, &error_message, cb, userdata);
if (r < 0)
return r;
if (overload & DHCP_OVERLOAD_FILE) {
r = parse_options(message->file, sizeof(message->file),
NULL, &message_type, cb, userdata);
r = parse_options(message->file, sizeof(message->file), NULL, &message_type, &error_message, cb, userdata);
if (r < 0)
return r;
}
if (overload & DHCP_OVERLOAD_SNAME) {
r = parse_options(message->sname, sizeof(message->sname),
NULL, &message_type, cb, userdata);
r = parse_options(message->sname, sizeof(message->sname), NULL, &message_type, &error_message, cb, userdata);
if (r < 0)
return r;
}
if (message_type)
return message_type;
if (message_type == 0)
return -ENOMSG;
if (_error_message && IN_SET(message_type, DHCP_NAK, DHCP_DECLINE)) {
*_error_message = error_message;
error_message = NULL;
}
return message_type;
}

View File

@@ -134,6 +134,7 @@ enum {
DHCP_OPTION_MESSAGE_TYPE = 53,
DHCP_OPTION_SERVER_IDENTIFIER = 54,
DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
DHCP_OPTION_ERROR_MESSAGE = 56,
DHCP_OPTION_MAXIMUM_MESSAGE_SIZE = 57,
DHCP_OPTION_RENEWAL_T1_TIME = 58,
DHCP_OPTION_REBINDING_T2_TIME = 59,

View File

@@ -76,6 +76,3 @@ int dhcp6_lease_set_sntp(sd_dhcp6_lease *lease, uint8_t *optval,
size_t optlen) ;
int dhcp6_lease_new(sd_dhcp6_lease **ret);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp6_lease*, sd_dhcp6_lease_unref);
#define _cleanup_dhcp6_lease_free_ _cleanup_(sd_dhcp6_lease_unrefp)

View File

@@ -362,7 +362,6 @@ int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char *
/* End of name */
break;
else if (c <= 63) {
_cleanup_free_ char *t = NULL;
const char *label;
/* Literal label */
@@ -371,21 +370,20 @@ int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char *
if (pos > optlen)
return -EMSGSIZE;
r = dns_label_escape(label, c, &t);
if (r < 0)
goto fail;
if (!GREEDY_REALLOC0(ret, allocated, n + !first + strlen(t) + 1)) {
if (!GREEDY_REALLOC(ret, allocated, n + !first + DNS_LABEL_ESCAPED_MAX)) {
r = -ENOMEM;
goto fail;
}
if (!first)
ret[n++] = '.';
else
if (first)
first = false;
else
ret[n++] = '.';
r = dns_label_escape(label, c, ret + n, DNS_LABEL_ESCAPED_MAX);
if (r < 0)
goto fail;
memcpy(ret + n, t, r);
n += r;
continue;
} else {

View File

@@ -337,7 +337,7 @@ int lldp_chassis_new(tlv_packet *tlv,
}
int lldp_receive_packet(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
_cleanup_lldp_packet_unref_ tlv_packet *packet = NULL;
_cleanup_(sd_lldp_packet_unrefp) tlv_packet *packet = NULL;
tlv_packet *p;
uint16_t length;
int r;

View File

@@ -76,9 +76,6 @@ struct sd_lldp_packet {
int tlv_packet_new(tlv_packet **ret);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_lldp_packet*, sd_lldp_packet_unref);
#define _cleanup_lldp_packet_unref_ _cleanup_(sd_lldp_packet_unrefp)
int lldp_tlv_packet_open_container(tlv_packet *m, uint16_t type);
int lldp_tlv_packet_close_container(tlv_packet *m);

View File

@@ -1,28 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2014 Tom Gundersen
Copyright (C) 2014 Susant Sahani
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/>.
***/
#pragma once
#include "nm-sd-adapt.h"
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_lldp *, sd_lldp_free);
#define _cleanup_lldp_free_ _cleanup_(sd_lldp_freep)

View File

@@ -556,7 +556,7 @@ static int client_append_fqdn_option(DHCPMessage *message, size_t optlen, size_t
buffer[1] = 0; /* RCODE1 (deprecated) */
buffer[2] = 0; /* RCODE2 (deprecated) */
r = dns_name_to_wire_format(fqdn, buffer + 3, sizeof(buffer) - 3);
r = dns_name_to_wire_format(fqdn, buffer + 3, sizeof(buffer) - 3, false);
if (r > 0)
r = dhcp_option_append(message, optlen, optoffset, 0,
DHCP_OPTION_FQDN, 3 + r, buffer);
@@ -606,7 +606,7 @@ static int client_send_discover(sd_dhcp_client *client) {
their messages MUST NOT also send the Host Name option". Just send
one of the two depending on the hostname type.
*/
if (dns_name_single_label(client->hostname)) {
if (dns_name_is_single_label(client->hostname)) {
/* it is unclear from RFC 2131 if client should send hostname in
DHCPDISCOVER but dhclient does and so we do as well
*/
@@ -721,7 +721,7 @@ static int client_send_request(sd_dhcp_client *client) {
}
if (client->hostname) {
if (dns_name_single_label(client->hostname))
if (dns_name_is_single_label(client->hostname))
r = dhcp_option_append(&request->dhcp, optlen, &optoffset, 0,
DHCP_OPTION_HOST_NAME,
strlen(client->hostname), client->hostname);
@@ -1069,7 +1069,7 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
size_t len) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
_cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
int r;
r = dhcp_lease_new(&lease);
@@ -1084,7 +1084,7 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
return r;
}
r = dhcp_option_parse(offer, len, dhcp_lease_parse_options, lease);
r = dhcp_option_parse(offer, len, dhcp_lease_parse_options, lease, NULL);
if (r != DHCP_OFFER) {
log_dhcp_client(client, "received message was not an OFFER, ignoring");
return -ENOMSG;
@@ -1123,7 +1123,7 @@ static int client_handle_forcerenew(sd_dhcp_client *client, DHCPMessage *force,
size_t len) {
int r;
r = dhcp_option_parse(force, len, NULL, NULL);
r = dhcp_option_parse(force, len, NULL, NULL, NULL);
if (r != DHCP_FORCERENEW)
return -ENOMSG;
@@ -1134,7 +1134,8 @@ static int client_handle_forcerenew(sd_dhcp_client *client, DHCPMessage *force,
static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
size_t len) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
_cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
_cleanup_free_ char *error_message = NULL;
int r;
r = dhcp_lease_new(&lease);
@@ -1149,9 +1150,9 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
return r;
}
r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease);
r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease, &error_message);
if (r == DHCP_NAK) {
log_dhcp_client(client, "NAK");
log_dhcp_client(client, "NAK: %s", strna(error_message));
return -EADDRNOTAVAIL;
}
@@ -1515,9 +1516,8 @@ static int client_receive_message_udp(sd_event_source *s, int fd,
r = ioctl(fd, FIONREAD, &buflen);
if (r < 0)
return r;
if (buflen < 0)
return -errno;
else if (buflen < 0)
/* this can't be right */
return -EIO;
@@ -1527,26 +1527,28 @@ static int client_receive_message_udp(sd_event_source *s, int fd,
len = read(fd, message, buflen);
if (len < 0) {
log_dhcp_client(client, "could not receive message from UDP "
"socket: %m");
if (errno == EAGAIN || errno == EINTR)
return 0;
log_dhcp_client(client, "Could not receive message from UDP socket: %m");
return -errno;
} else if ((size_t)len < sizeof(DHCPMessage)) {
log_dhcp_client(client, "too small to be a DHCP message: ignoring");
log_dhcp_client(client, "Too small to be a DHCP message: ignoring");
return 0;
}
if (be32toh(message->magic) != DHCP_MAGIC_COOKIE) {
log_dhcp_client(client, "not a DHCP message: ignoring");
log_dhcp_client(client, "Not a DHCP message: ignoring");
return 0;
}
if (message->op != BOOTREPLY) {
log_dhcp_client(client, "not a BOOTREPLY message: ignoring");
log_dhcp_client(client, "Not a BOOTREPLY message: ignoring");
return 0;
}
if (message->htype != client->arp_type) {
log_dhcp_client(client, "packet type does not match client type");
log_dhcp_client(client, "Packet type does not match client type");
return 0;
}
@@ -1560,13 +1562,12 @@ static int client_receive_message_udp(sd_event_source *s, int fd,
}
if (message->hlen != expected_hlen) {
log_dhcp_client(client, "unexpected packet hlen %d", message->hlen);
log_dhcp_client(client, "Unexpected packet hlen %d", message->hlen);
return 0;
}
if (memcmp(&message->chaddr[0], expected_chaddr, ETH_ALEN)) {
log_dhcp_client(client, "received chaddr does not match "
"expected: ignoring");
log_dhcp_client(client, "Received chaddr does not match expected: ignoring");
return 0;
}
@@ -1574,8 +1575,7 @@ static int client_receive_message_udp(sd_event_source *s, int fd,
be32toh(message->xid) != client->xid) {
/* in BOUND state, we may receive FORCERENEW with xid set by server,
so ignore the xid in this case */
log_dhcp_client(client, "received xid (%u) does not match "
"expected (%u): ignoring",
log_dhcp_client(client, "Received xid (%u) does not match expected (%u): ignoring",
be32toh(message->xid), client->xid);
return 0;
}
@@ -1604,9 +1604,8 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
r = ioctl(fd, FIONREAD, &buflen);
if (r < 0)
return r;
if (buflen < 0)
return -errno;
else if (buflen < 0)
/* this can't be right */
return -EIO;
@@ -1619,9 +1618,12 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
len = recvmsg(fd, &msg, 0);
if (len < 0) {
log_dhcp_client(client, "could not receive message from raw "
"socket: %m");
if (errno == EAGAIN || errno == EINTR)
return 0;
log_dhcp_client(client, "Could not receive message from raw socket: %m");
return -errno;
} else if ((size_t)len < sizeof(DHCPPacket))
return 0;
@@ -1751,7 +1753,7 @@ sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client) {
}
int sd_dhcp_client_new(sd_dhcp_client **ret) {
_cleanup_dhcp_client_unref_ sd_dhcp_client *client = NULL;
_cleanup_(sd_dhcp_client_unrefp) sd_dhcp_client *client = NULL;
assert_return(ret, -EINVAL);

View File

@@ -663,7 +663,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void
break;
default:
log_debug("Ignoring option DHCP option %i while parsing.", code);
log_debug("Ignoring option DHCP option %"PRIu8" while parsing.", code);
break;
}
@@ -867,7 +867,7 @@ fail:
int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
_cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
_cleanup_free_ char
*address = NULL,
*router = NULL,

View File

@@ -109,11 +109,8 @@ const char * dhcp6_message_status_table[_DHCP6_STATUS_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(dhcp6_message_status, int);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp6_client*, sd_dhcp6_client_unref);
#define _cleanup_dhcp6_client_unref_ _cleanup_(sd_dhcp6_client_unrefp)
#define DHCP6_CLIENT_DONT_DESTROY(client) \
_cleanup_dhcp6_client_unref_ _unused_ sd_dhcp6_client *_dont_destroy_##client = sd_dhcp6_client_ref(client)
_cleanup_(sd_dhcp6_client_unrefp) _unused_ sd_dhcp6_client *_dont_destroy_##client = sd_dhcp6_client_ref(client)
static int client_start(sd_dhcp6_client *client, enum DHCP6State state);
@@ -831,7 +828,7 @@ static int client_parse_message(sd_dhcp6_client *client,
static int client_receive_reply(sd_dhcp6_client *client, DHCP6Message *reply, size_t len) {
int r;
_cleanup_dhcp6_lease_free_ sd_dhcp6_lease *lease = NULL;
_cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL;
bool rapid_commit;
if (reply->type != DHCP6_REPLY)
@@ -862,7 +859,7 @@ static int client_receive_reply(sd_dhcp6_client *client, DHCP6Message *reply, si
static int client_receive_advertise(sd_dhcp6_client *client, DHCP6Message *advertise, size_t len) {
int r;
_cleanup_dhcp6_lease_free_ sd_dhcp6_lease *lease = NULL;
_cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL;
uint8_t pref_advertise = 0, pref_lease = 0;
if (advertise->type != DHCP6_ADVERTISE)
@@ -905,18 +902,26 @@ static int client_receive_message(sd_event_source *s, int fd, uint32_t revents,
assert(client->event);
r = ioctl(fd, FIONREAD, &buflen);
if (r < 0 || buflen <= 0)
buflen = DHCP6_MIN_OPTIONS_SIZE;
if (r < 0)
return -errno;
else if (buflen < 0)
/* This really should not happen */
return -EIO;
message = malloc0(buflen);
message = malloc(buflen);
if (!message)
return -ENOMEM;
len = read(fd, message, buflen);
if ((size_t)len < sizeof(DHCP6Message)) {
log_dhcp6_client(client, "could not receive message from UDP socket: %m");
if (len < 0) {
if (errno == EAGAIN || errno == EINTR)
return 0;
log_dhcp6_client(client, "Could not receive message from UDP socket: %m");
return -errno;
} else if ((size_t)len < sizeof(DHCP6Message))
return 0;
}
switch(message->type) {
case DHCP6_SOLICIT:
@@ -1271,7 +1276,7 @@ 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;
_cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL;
size_t t;
assert_return(ret, -EINVAL);

View File

@@ -30,7 +30,6 @@
#include "alloc-util.h"
#include "arp-util.h"
#include "event-util.h"
#include "fd-util.h"
#include "in-addr-util.h"
#include "list.h"
@@ -122,11 +121,8 @@ sd_ipv4acd *sd_ipv4acd_unref(sd_ipv4acd *ll) {
return NULL;
}
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_ipv4acd*, sd_ipv4acd_unref);
#define _cleanup_ipv4acd_unref_ _cleanup_(sd_ipv4acd_unrefp)
int sd_ipv4acd_new(sd_ipv4acd **ret) {
_cleanup_ipv4acd_unref_ sd_ipv4acd *ll = NULL;
_cleanup_(sd_ipv4acd_unrefp) sd_ipv4acd *ll = NULL;
assert_return(ret, -EINVAL);
@@ -191,7 +187,7 @@ int sd_ipv4acd_stop(sd_ipv4acd *ll) {
static int ipv4acd_on_timeout(sd_event_source *s, uint64_t usec, void *userdata);
static int ipv4acd_set_next_wakeup(sd_ipv4acd *ll, int sec, int random_sec) {
_cleanup_event_source_unref_ sd_event_source *timer = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *timer = NULL;
usec_t next_timeout;
usec_t time_now;
int r;

View File

@@ -30,7 +30,6 @@
#include "sd-ipv4ll.h"
#include "alloc-util.h"
#include "event-util.h"
#include "in-addr-util.h"
#include "list.h"
#include "random-util.h"
@@ -43,7 +42,7 @@
#define IPV4LL_NETMASK 0xFFFF0000L
#define IPV4LL_DONT_DESTROY(ll) \
_cleanup_ipv4ll_unref_ _unused_ sd_ipv4ll *_dont_destroy_##ll = sd_ipv4ll_ref(ll)
_cleanup_(sd_ipv4ll_unrefp) _unused_ sd_ipv4ll *_dont_destroy_##ll = sd_ipv4ll_ref(ll)
struct sd_ipv4ll {
unsigned n_ref;
@@ -88,13 +87,10 @@ sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll) {
return NULL;
}
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_ipv4ll*, sd_ipv4ll_unref);
#define _cleanup_ipv4ll_unref_ _cleanup_(sd_ipv4ll_unrefp)
static void ipv4ll_on_acd(sd_ipv4acd *ll, int event, void *userdata);
int sd_ipv4ll_new(sd_ipv4ll **ret) {
_cleanup_ipv4ll_unref_ sd_ipv4ll *ll = NULL;
_cleanup_(sd_ipv4ll_unrefp) sd_ipv4ll *ll = NULL;
int r;
assert_return(ret, -EINVAL);

View File

@@ -33,7 +33,6 @@
#include "lldp-internal.h"
#include "lldp-port.h"
#include "lldp-tlv.h"
#include "lldp-util.h"
#include "prioq.h"
#include "siphash24.h"
#include "string-util.h"
@@ -148,12 +147,9 @@ static int lldp_receive_frame(sd_lldp *lldp, tlv_packet *tlv) {
/* 10.3.2 LLDPDU validation: rxProcessFrame() */
int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
bool system_description = false, system_name = false, chassis_id = false;
bool malformed = false, port_id = false, ttl = false, end = false;
uint16_t type, len, i, l, t;
bool chassis_id = false;
bool malformed = false;
bool port_id = false;
bool ttl = false;
bool end = false;
lldp_port *port;
uint8_t *p, *q;
sd_lldp *lldp;
@@ -166,8 +162,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
lldp = (sd_lldp *) port->userdata;
if (lldp->port->status == LLDP_PORT_STATUS_DISABLED) {
log_lldp("Port is disabled : %s . Dropping ...",
lldp->port->ifname);
log_lldp("Port: %s is disabled. Dropping.", lldp->port->ifname);
goto out;
}
@@ -185,8 +180,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
if (type == LLDP_TYPE_END) {
if (len != 0) {
log_lldp("TLV type end is not length 0. Length:%d received . Dropping ...",
len);
log_lldp("TLV type end must be length 0 (not %d). Dropping.", len);
malformed = true;
goto out;
@@ -196,8 +190,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
break;
} else if (type >=_LLDP_TYPE_MAX) {
log_lldp("TLV type not recognized %d . Dropping ...",
type);
log_lldp("TLV type: %d not recognized. Dropping.", type);
malformed = true;
goto out;
@@ -212,7 +205,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
if (i <= 3) {
if (i != type) {
log_lldp("TLV missing or out of order. Dropping ...");
log_lldp("TLV missing or out of order. Dropping.");
malformed = true;
goto out;
@@ -223,25 +216,22 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
case LLDP_TYPE_CHASSIS_ID:
if (len < 2) {
log_lldp("Received malformed Chassis ID TLV len = %d. Dropping",
len);
log_lldp("Received malformed Chassis ID TLV length: %d. Dropping.", len);
malformed = true;
goto out;
}
if (chassis_id) {
log_lldp("Duplicate Chassis ID TLV found. Dropping ...");
log_lldp("Duplicate Chassis ID TLV found. Dropping.");
malformed = true;
goto out;
}
/* Look what subtype it has */
if (*q == LLDP_CHASSIS_SUBTYPE_RESERVED ||
*q > LLDP_CHASSIS_SUBTYPE_LOCALLY_ASSIGNED) {
log_lldp("Unknown subtype: %d found in Chassis ID TLV . Dropping ...",
*q);
if (*q == LLDP_CHASSIS_SUBTYPE_RESERVED || *q > LLDP_CHASSIS_SUBTYPE_LOCALLY_ASSIGNED) {
log_lldp("Unknown subtype: %d found in Chassis ID TLV. Dropping.", *q);
malformed = true;
goto out;
@@ -254,25 +244,22 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
case LLDP_TYPE_PORT_ID:
if (len < 2) {
log_lldp("Received malformed Port ID TLV len = %d. Dropping",
len);
log_lldp("Received malformed Port ID TLV length: %d. Dropping.", len);
malformed = true;
goto out;
}
if (port_id) {
log_lldp("Duplicate Port ID TLV found. Dropping ...");
log_lldp("Duplicate Port ID TLV found. Dropping.");
malformed = true;
goto out;
}
/* Look what subtype it has */
if (*q == LLDP_PORT_SUBTYPE_RESERVED ||
*q > LLDP_PORT_SUBTYPE_LOCALLY_ASSIGNED) {
log_lldp("Unknown subtype: %d found in Port ID TLV . Dropping ...",
*q);
if (*q == LLDP_PORT_SUBTYPE_RESERVED || *q > LLDP_PORT_SUBTYPE_LOCALLY_ASSIGNED) {
log_lldp("Unknown subtype: %d found in Port ID TLV. Dropping.", *q);
malformed = true;
goto out;
@@ -285,16 +272,14 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
case LLDP_TYPE_TTL:
if(len != 2) {
log_lldp(
"Received invalid lenth: %d TTL TLV. Dropping ...",
len);
log_lldp("Received invalid TTL TLV lenth: %d. Dropping.", len);
malformed = true;
goto out;
}
if (ttl) {
log_lldp("Duplicate TTL TLV found. Dropping ...");
log_lldp("Duplicate TTL TLV found. Dropping.");
malformed = true;
goto out;
@@ -302,12 +287,46 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
ttl = true;
break;
case LLDP_TYPE_SYSTEM_NAME:
/* According to RFC 1035 the length of a FQDN is limited to 255 characters */
if (len > 255) {
log_lldp("Received invalid system name length: %d. Dropping.", len);
malformed = true;
goto out;
}
if (system_name) {
log_lldp("Duplicate system name found. Dropping.");
malformed = true;
goto out;
}
system_name = true;
break;
case LLDP_TYPE_SYSTEM_DESCRIPTION:
/* 0 <= n <= 255 octets */
if (len > 255) {
log_lldp("Received invalid system description length: %d. Dropping.", len);
malformed = true;
goto out;
}
if (system_description) {
log_lldp("Duplicate system description found. Dropping.");
malformed = true;
goto out;
}
system_description = true;
break;
default:
if (len == 0) {
log_lldp("TLV type = %d's, length 0 received . Dropping ...",
type);
log_lldp("TLV type: %d length 0 received. Dropping.", type);
malformed = true;
goto out;
@@ -317,7 +336,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
}
if(!chassis_id || !port_id || !ttl || !end) {
log_lldp( "One or more mandotory TLV missing . Dropping ...");
log_lldp("One or more mandatory TLV missing. Dropping.");
malformed = true;
goto out;
@@ -326,7 +345,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
r = tlv_packet_parse_pdu(tlv, length);
if (r < 0) {
log_lldp( "Failed to parse the TLV. Dropping ...");
log_lldp("Failed to parse the TLV. Dropping.");
malformed = true;
goto out;
@@ -654,10 +673,10 @@ int sd_lldp_set_callback(sd_lldp *lldp, sd_lldp_cb_t cb, void *userdata) {
return 0;
}
void sd_lldp_free(sd_lldp *lldp) {
sd_lldp* sd_lldp_unref(sd_lldp *lldp) {
if (!lldp)
return;
return NULL;
/* Drop all packets */
lldp_mib_objects_flush(lldp);
@@ -668,13 +687,14 @@ void sd_lldp_free(sd_lldp *lldp) {
prioq_free(lldp->by_expiry);
free(lldp);
return NULL;
}
int sd_lldp_new(int ifindex,
const char *ifname,
const struct ether_addr *mac,
sd_lldp **ret) {
_cleanup_lldp_free_ sd_lldp *lldp = NULL;
_cleanup_(sd_lldp_unrefp) sd_lldp *lldp = NULL;
int r;
assert_return(ret, -EINVAL);

View File

@@ -1,34 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#pragma once
/***
This file is part of systemd.
Copyright 2013 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 "nm-sd-adapt.h"
#include "sd-event.h"
#include "util.h"
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_event*, sd_event_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_event_source*, sd_event_source_unref);
#define _cleanup_event_unref_ _cleanup_(sd_event_unrefp)
#define _cleanup_event_source_unref_ _cleanup_(sd_event_source_unrefp)

View File

@@ -26,11 +26,22 @@
#include <stringprep.h>
#endif
#include <endian.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "alloc-util.h"
#include "dns-domain.h"
#include "hashmap.h"
#include "hexdecoct.h"
#include "in-addr-util.h"
#include "macro.h"
#include "parse-util.h"
#include "string-util.h"
#include "strv.h"
#include "utf8.h"
int dns_label_unescape(const char **name, char *dest, size_t sz) {
const char *n;
@@ -39,7 +50,6 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
assert(name);
assert(*name);
assert(dest);
n = *name;
d = dest;
@@ -53,12 +63,12 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
if (*n == 0)
break;
if (sz <= 0)
return -ENOSPC;
if (r >= DNS_LABEL_MAX)
return -EINVAL;
if (sz <= 0)
return -ENOBUFS;
if (*n == '\\') {
/* Escaped character */
@@ -70,9 +80,12 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
else if (*n == '\\' || *n == '.') {
/* Escaped backslash or dot */
*(d++) = *(n++);
if (d)
*(d++) = *n;
sz--;
r++;
n++;
} else if (n[0] >= '0' && n[0] <= '9') {
unsigned k;
@@ -87,10 +100,16 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
((unsigned) (n[1] - '0') * 10) +
((unsigned) (n[2] - '0'));
/* Don't allow CC characters or anything that doesn't fit in 8bit */
if (k < ' ' || k > 255 || k == 127)
/* Don't allow anything that doesn't
* fit in 8bit. Note that we do allow
* control characters, as some servers
* (e.g. cloudflare) are happy to
* generate labels with them
* inside. */
if (k > 255)
return -EINVAL;
if (d)
*(d++) = (char) k;
sz--;
r++;
@@ -102,9 +121,12 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
} else if ((uint8_t) *n >= (uint8_t) ' ' && *n != 127) {
/* Normal character */
*(d++) = *(n++);
if (d)
*(d++) = *n;
sz--;
r++;
n++;
} else
return -EINVAL;
}
@@ -113,7 +135,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
if (r == 0 && *n)
return -EINVAL;
if (sz >= 1)
if (sz >= 1 && d)
*d = 0;
*name = n;
@@ -139,20 +161,24 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
return 0;
}
assert(**label_terminal == '.' || **label_terminal == 0);
terminal = *label_terminal;
assert(*terminal == '.' || *terminal == 0);
/* skip current terminal character */
terminal = *label_terminal - 1;
/* Skip current terminal character (and accept domain names ending it ".") */
if (*terminal == 0)
terminal--;
if (terminal >= name && *terminal == '.')
terminal--;
/* point name to the last label, and terminal to the preceding terminal symbol (or make it a NULL pointer) */
/* Point name to the last label, and terminal to the preceding terminal symbol (or make it a NULL pointer) */
for (;;) {
if (terminal < name) {
/* reached the first label, so indicate that there are no more */
/* Reached the first label, so indicate that there are no more */
terminal = NULL;
break;
}
/* find the start of the last label */
/* Find the start of the last label */
if (*terminal == '.') {
const char *y;
unsigned slashes = 0;
@@ -161,7 +187,7 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
slashes ++;
if (slashes % 2 == 0) {
/* the '.' was not escaped */
/* The '.' was not escaped */
name = terminal + 1;
break;
} else {
@@ -182,30 +208,36 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
return r;
}
int dns_label_escape(const char *p, size_t l, char **ret) {
_cleanup_free_ char *s = NULL;
int dns_label_escape(const char *p, size_t l, char *dest, size_t sz) {
char *q;
int r;
/* DNS labels must be between 1 and 63 characters long. A
* zero-length label does not exist. See RFC 2182, Section
* 11. */
if (l <= 0 || l > DNS_LABEL_MAX)
return -EINVAL;
if (sz < 1)
return -ENOBUFS;
assert(p);
assert(ret);
assert(dest);
if (l > DNS_LABEL_MAX)
return -EINVAL;
s = malloc(l * 4 + 1);
if (!s)
return -ENOMEM;
q = s;
q = dest;
while (l > 0) {
if (*p == '.' || *p == '\\') {
/* Dot or backslash */
if (sz < 3)
return -ENOBUFS;
*(q++) = '\\';
*(q++) = *p;
sz -= 2;
} else if (*p == '_' ||
*p == '-' ||
(*p >= '0' && *p <= '9') ||
@@ -213,25 +245,56 @@ int dns_label_escape(const char *p, size_t l, char **ret) {
(*p >= 'A' && *p <= 'Z')) {
/* Proper character */
if (sz < 2)
return -ENOBUFS;
*(q++) = *p;
} else if ((uint8_t) *p >= (uint8_t) ' ' && *p != 127) {
sz -= 1;
} else {
/* Everything else */
if (sz < 5)
return -ENOBUFS;
*(q++) = '\\';
*(q++) = '0' + (char) ((uint8_t) *p / 100);
*(q++) = '0' + (char) (((uint8_t) *p / 10) % 10);
*(q++) = '0' + (char) ((uint8_t) *p % 10);
} else
return -EINVAL;
sz -= 4;
}
p++;
l--;
}
*q = 0;
return (int) (q - dest);
}
int dns_label_escape_new(const char *p, size_t l, char **ret) {
_cleanup_free_ char *s = NULL;
int r;
assert(p);
assert(ret);
if (l <= 0 || l > DNS_LABEL_MAX)
return -EINVAL;
s = new(char, DNS_LABEL_ESCAPED_MAX);
if (!s)
return -ENOMEM;
r = dns_label_escape(p, l, s, DNS_LABEL_ESCAPED_MAX);
if (r < 0)
return r;
*ret = s;
r = q - s;
s = NULL;
return r;
@@ -240,32 +303,52 @@ int dns_label_escape(const char *p, size_t l, char **ret) {
int dns_label_apply_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max) {
#ifdef HAVE_LIBIDN
_cleanup_free_ uint32_t *input = NULL;
size_t input_size;
size_t input_size, l;
const char *p;
bool contains_8bit = false;
char buffer[DNS_LABEL_MAX+1];
assert(encoded);
assert(decoded);
assert(decoded_max >= DNS_LABEL_MAX);
/* Converts an U-label into an A-label */
if (encoded_size <= 0)
return 0;
return -EINVAL;
for (p = encoded; p < encoded + encoded_size; p++)
if ((uint8_t) *p > 127)
contains_8bit = true;
if (!contains_8bit)
if (!contains_8bit) {
if (encoded_size > DNS_LABEL_MAX)
return -EINVAL;
return 0;
}
input = stringprep_utf8_to_ucs4(encoded, encoded_size, &input_size);
if (!input)
return -ENOMEM;
if (idna_to_ascii_4i(input, input_size, decoded, 0) != 0)
if (idna_to_ascii_4i(input, input_size, buffer, 0) != 0)
return -EINVAL;
return strlen(decoded);
l = strlen(buffer);
/* Verify that the the result is not longer than one DNS label. */
if (l <= 0 || l > DNS_LABEL_MAX)
return -EINVAL;
if (l > decoded_max)
return -ENOBUFS;
memcpy(decoded, buffer, l);
/* If there's room, append a trailing NUL byte, but only then */
if (decoded_max > l)
decoded[l] = 0;
return (int) l;
#else
return 0;
#endif
@@ -279,11 +362,14 @@ int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded,
uint32_t *output = NULL;
size_t w;
/* To be invoked after unescaping */
/* To be invoked after unescaping. Converts an A-label into an U-label. */
assert(encoded);
assert(decoded);
if (encoded_size <= 0 || encoded_size > DNS_LABEL_MAX)
return -EINVAL;
if (encoded_size < sizeof(IDNA_ACE_PREFIX)-1)
return 0;
@@ -303,11 +389,16 @@ int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded,
if (!result)
return -ENOMEM;
if (w <= 0)
return 0;
if (w+1 > decoded_max)
return -EINVAL;
if (w > decoded_max)
return -ENOBUFS;
memcpy(decoded, result, w);
/* Append trailing NUL byte if there's space, but only then. */
if (decoded_max > w)
decoded[w] = 0;
memcpy(decoded, result, w+1);
return w;
#else
return 0;
@@ -324,7 +415,6 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
assert(a);
for (;;) {
_cleanup_free_ char *t = NULL;
char label[DNS_LABEL_MAX];
int k;
@@ -351,26 +441,33 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
if (k > 0)
r = k;
r = dns_label_escape(label, r, &t);
if (_ret) {
if (!GREEDY_REALLOC(ret, allocated, n + !first + DNS_LABEL_ESCAPED_MAX))
return -ENOMEM;
r = dns_label_escape(label, r, ret + n + !first, DNS_LABEL_ESCAPED_MAX);
if (r < 0)
return r;
if (_ret) {
if (!GREEDY_REALLOC(ret, allocated, n + !first + strlen(t) + 1))
return -ENOMEM;
if (!first)
ret[n] = '.';
} else {
char escaped[DNS_LABEL_ESCAPED_MAX];
r = dns_label_escape(label, r, escaped, sizeof(escaped));
if (r < 0)
return r;
}
if (!first)
ret[n++] = '.';
n++;
else
first = false;
memcpy(ret + n, t, r);
}
n += r;
}
if (n > DNS_NAME_MAX)
if (n > DNS_HOSTNAME_MAX)
return -EINVAL;
if (_ret) {
@@ -447,7 +544,7 @@ int dns_name_compare_func(const void *a, const void *b) {
if (k > 0)
r = k;
if (w > 0)
r = w;
q = w;
la[r] = lb[q] = 0;
r = strcasecmp(la, lb);
@@ -476,24 +573,32 @@ int dns_name_equal(const char *x, const char *y) {
r = dns_label_unescape(&x, la, sizeof(la));
if (r < 0)
return r;
if (r > 0) {
k = dns_label_undo_idna(la, r, la, sizeof(la));
if (k < 0)
return k;
if (k > 0)
r = k;
}
q = dns_label_unescape(&y, lb, sizeof(lb));
if (q < 0)
return q;
if (q > 0) {
w = dns_label_undo_idna(lb, q, lb, sizeof(lb));
if (w < 0)
return w;
if (w > 0)
q = w;
}
/* If one name had fewer labels than the other, this
* will show up as empty label here, which the
* strcasecmp() below will properly consider different
* from a non-empty label. */
la[r] = lb[q] = 0;
if (strcasecmp(la, lb))
if (strcasecmp(la, lb) != 0)
return false;
}
}
@@ -514,11 +619,13 @@ int dns_name_endswith(const char *name, const char *suffix) {
r = dns_label_unescape(&n, ln, sizeof(ln));
if (r < 0)
return r;
if (r > 0) {
k = dns_label_undo_idna(ln, r, ln, sizeof(ln));
if (k < 0)
return k;
if (k > 0)
r = k;
}
if (!saved_n)
saved_n = n;
@@ -526,11 +633,13 @@ int dns_name_endswith(const char *name, const char *suffix) {
q = dns_label_unescape(&s, ls, sizeof(ls));
if (q < 0)
return q;
if (q > 0) {
w = dns_label_undo_idna(ls, q, ls, sizeof(ls));
if (w < 0)
return w;
if (w > 0)
q = w;
}
if (r == 0 && q == 0)
return true;
@@ -549,6 +658,77 @@ int dns_name_endswith(const char *name, const char *suffix) {
}
}
int dns_name_change_suffix(const char *name, const char *old_suffix, const char *new_suffix, char **ret) {
const char *n, *s, *saved_before = NULL, *saved_after = NULL, *prefix;
int r, q, k, w;
assert(name);
assert(old_suffix);
assert(new_suffix);
assert(ret);
n = name;
s = old_suffix;
for (;;) {
char ln[DNS_LABEL_MAX+1], ls[DNS_LABEL_MAX+1];
if (!saved_before)
saved_before = n;
r = dns_label_unescape(&n, ln, sizeof(ln));
if (r < 0)
return r;
if (r > 0) {
k = dns_label_undo_idna(ln, r, ln, sizeof(ln));
if (k < 0)
return k;
if (k > 0)
r = k;
}
if (!saved_after)
saved_after = n;
q = dns_label_unescape(&s, ls, sizeof(ls));
if (q < 0)
return q;
if (q > 0) {
w = dns_label_undo_idna(ls, q, ls, sizeof(ls));
if (w < 0)
return w;
if (w > 0)
q = w;
}
if (r == 0 && q == 0)
break;
if (r == 0 && saved_after == n) {
*ret = NULL; /* doesn't match */
return 0;
}
ln[r] = ls[q] = 0;
if (r != q || strcasecmp(ln, ls)) {
/* Not the same, let's jump back, and try with the next label again */
s = old_suffix;
n = saved_after;
saved_after = saved_before = NULL;
}
}
/* Found it! Now generate the new name */
prefix = strndupa(name, saved_before - name);
r = dns_name_concat(prefix, new_suffix, ret);
if (r < 0)
return r;
return 1;
}
int dns_name_between(const char *a, const char *b, const char *c) {
int n;
@@ -686,70 +866,384 @@ int dns_name_address(const char *p, int *family, union in_addr_union *address) {
return 0;
}
int dns_name_root(const char *name) {
char label[DNS_LABEL_MAX+1];
int r;
assert(name);
r = dns_label_unescape(&name, label, sizeof(label));
if (r < 0)
return r;
return r == 0 && *name == 0;
}
#endif /* NM_IGNORED */
int dns_name_single_label(const char *name) {
bool dns_name_is_root(const char *name) {
assert(name);
/* There are exactly two ways to encode the root domain name:
* as empty string, or with a single dot. */
return STR_IN_SET(name, "", ".");
}
bool dns_name_is_single_label(const char *name) {
char label[DNS_LABEL_MAX+1];
int r;
assert(name);
r = dns_label_unescape(&name, label, sizeof(label));
if (r < 0)
return r;
if (r == 0)
return 0;
if (r <= 0)
return false;
r = dns_label_unescape(&name, label, sizeof(label));
if (r < 0)
return r;
return r == 0 && *name == 0;
return dns_name_is_root(name);
}
/* Encode a domain name according to RFC 1035 Section 3.1 */
int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len) {
uint8_t *label_length;
uint8_t *out;
/* Encode a domain name according to RFC 1035 Section 3.1, without compression */
int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len, bool canonical) {
uint8_t *label_length, *out;
int r;
assert_return(buffer, -EINVAL);
assert_return(domain, -EINVAL);
assert_return(domain[0], -EINVAL);
assert(domain);
assert(buffer);
out = buffer;
do {
/* reserve a byte for label length */
if (len == 0)
/* Reserve a byte for label length */
if (len <= 0)
return -ENOBUFS;
len--;
label_length = out;
out++;
/* convert and copy a single label */
/* Convert and copy a single label. Note that
* dns_label_unescape() returns 0 when it hits the end
* of the domain name, which we rely on here to encode
* the trailing NUL byte. */
r = dns_label_unescape(&domain, (char *) out, len);
if (r < 0)
return r;
/* fill label length, move forward */
if (canonical) {
size_t i;
/* Optionally, output the name in DNSSEC
* canonical format, as described in RFC 4034,
* section 6.2. Or in other words: in
* lower-case. */
for (i = 0; i < (size_t) r; i++) {
if (out[i] >= 'A' && out[i] <= 'Z')
out[i] = out[i] - 'A' + 'a';
}
}
/* Fill label length, move forward */
*label_length = r;
out += r;
len -= r;
} while (r != 0);
/* Verify the maximum size of the encoded name. The trailing
* dot + NUL byte account are included this time, hence
* compare against DNS_HOSTNAME_MAX + 2 (which is 255) this
* time. */
if (out - buffer > DNS_HOSTNAME_MAX + 2)
return -EINVAL;
return out - buffer;
}
#if 0 /* NM_IGNORED */
static bool srv_type_label_is_valid(const char *label, size_t n) {
size_t k;
assert(label);
if (n < 2) /* Label needs to be at least 2 chars long */
return false;
if (label[0] != '_') /* First label char needs to be underscore */
return false;
/* Second char must be a letter */
if (!(label[1] >= 'A' && label[1] <= 'Z') &&
!(label[1] >= 'a' && label[1] <= 'z'))
return false;
/* Third and further chars must be alphanumeric or a hyphen */
for (k = 2; k < n; k++) {
if (!(label[k] >= 'A' && label[k] <= 'Z') &&
!(label[k] >= 'a' && label[k] <= 'z') &&
!(label[k] >= '0' && label[k] <= '9') &&
label[k] != '-')
return false;
}
return true;
}
bool dns_srv_type_is_valid(const char *name) {
unsigned c = 0;
int r;
if (!name)
return false;
for (;;) {
char label[DNS_LABEL_MAX];
/* This more or less implements RFC 6335, Section 5.1 */
r = dns_label_unescape(&name, label, sizeof(label));
if (r < 0)
return false;
if (r == 0)
break;
if (c >= 2)
return false;
if (!srv_type_label_is_valid(label, r))
return false;
c++;
}
return c == 2; /* exactly two labels */
}
bool dns_service_name_is_valid(const char *name) {
size_t l;
/* This more or less implements RFC 6763, Section 4.1.1 */
if (!name)
return false;
if (!utf8_is_valid(name))
return false;
if (string_has_cc(name, NULL))
return false;
l = strlen(name);
if (l <= 0)
return false;
if (l > 63)
return false;
return true;
}
int dns_service_join(const char *name, const char *type, const char *domain, char **ret) {
char escaped[DNS_LABEL_ESCAPED_MAX];
_cleanup_free_ char *n = NULL;
int r;
assert(type);
assert(domain);
assert(ret);
if (!dns_srv_type_is_valid(type))
return -EINVAL;
if (!name)
return dns_name_concat(type, domain, ret);
if (!dns_service_name_is_valid(name))
return -EINVAL;
r = dns_label_escape(name, strlen(name), escaped, sizeof(escaped));
if (r < 0)
return r;
r = dns_name_concat(type, domain, &n);
if (r < 0)
return r;
return dns_name_concat(escaped, n, ret);
}
static bool dns_service_name_label_is_valid(const char *label, size_t n) {
char *s;
assert(label);
if (memchr(label, 0, n))
return false;
s = strndupa(label, n);
return dns_service_name_is_valid(s);
}
int dns_service_split(const char *joined, char **_name, char **_type, char **_domain) {
_cleanup_free_ char *name = NULL, *type = NULL, *domain = NULL;
const char *p = joined, *q = NULL, *d = NULL;
char a[DNS_LABEL_MAX], b[DNS_LABEL_MAX], c[DNS_LABEL_MAX];
int an, bn, cn, r;
unsigned x = 0;
assert(joined);
/* Get first label from the full name */
an = dns_label_unescape(&p, a, sizeof(a));
if (an < 0)
return an;
if (an > 0) {
x++;
/* If there was a first label, try to get the second one */
bn = dns_label_unescape(&p, b, sizeof(b));
if (bn < 0)
return bn;
if (bn > 0) {
x++;
/* If there was a second label, try to get the third one */
q = p;
cn = dns_label_unescape(&p, c, sizeof(c));
if (cn < 0)
return cn;
if (cn > 0)
x++;
} else
cn = 0;
} else
an = 0;
if (x >= 2 && srv_type_label_is_valid(b, bn)) {
if (x >= 3 && srv_type_label_is_valid(c, cn)) {
if (dns_service_name_label_is_valid(a, an)) {
/* OK, got <name> . <type> . <type2> . <domain> */
name = strndup(a, an);
if (!name)
return -ENOMEM;
type = new(char, bn+1+cn+1);
if (!type)
return -ENOMEM;
strcpy(stpcpy(stpcpy(type, b), "."), c);
d = p;
goto finish;
}
} else if (srv_type_label_is_valid(a, an)) {
/* OK, got <type> . <type2> . <domain> */
name = NULL;
type = new(char, an+1+bn+1);
if (!type)
return -ENOMEM;
strcpy(stpcpy(stpcpy(type, a), "."), b);
d = q;
goto finish;
}
}
name = NULL;
type = NULL;
d = joined;
finish:
r = dns_name_normalize(d, &domain);
if (r < 0)
return r;
if (_domain) {
*_domain = domain;
domain = NULL;
}
if (_type) {
*_type = type;
type = NULL;
}
if (_name) {
*_name = name;
name = NULL;
}
return 0;
}
int dns_name_suffix(const char *name, unsigned n_labels, const char **ret) {
const char* labels[DNS_N_LABELS_MAX+1];
unsigned n = 0;
const char *p;
int r;
assert(name);
assert(ret);
p = name;
for (;;) {
if (n > DNS_N_LABELS_MAX)
return -EINVAL;
labels[n] = p;
r = dns_name_parent(&p);
if (r < 0)
return r;
if (r == 0)
break;
n++;
}
if (n < n_labels)
return -EINVAL;
*ret = labels[n - n_labels];
return (int) (n - n_labels);
}
int dns_name_count_labels(const char *name) {
unsigned n = 0;
const char *p;
int r;
assert(name);
p = name;
for (;;) {
r = dns_name_parent(&p);
if (r < 0)
return r;
if (r == 0)
break;
if (n >= DNS_N_LABELS_MAX)
return -EINVAL;
n++;
}
return (int) n;
}
int dns_name_equal_skip(const char *a, unsigned n_labels, const char *b) {
int r;
assert(a);
assert(b);
while (n_labels > 0) {
r = dns_name_parent(&a);
if (r <= 0)
return r;
n_labels --;
}
return dns_name_equal(a, b);
}
#endif /* NM_IGNORED */

View File

@@ -23,17 +23,37 @@
#include "nm-sd-adapt.h"
#if 0 /* NM_IGNORED */
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "hashmap.h"
#include "in-addr-util.h"
#endif /* NM_IGNORED */
/* Length of a single label, with all escaping removed, excluding any trailing dot or NUL byte */
#define DNS_LABEL_MAX 63
#define DNS_NAME_MAX 255
/* Worst case length of a single label, with all escaping applied and room for a trailing NUL byte. */
#define DNS_LABEL_ESCAPED_MAX (DNS_LABEL_MAX*4+1)
/* Maximum length of a full hostname, consisting of a series of unescaped labels, and no trailing dot or NUL byte */
#define DNS_HOSTNAME_MAX 253
/* Maximum length of a full hostname, on the wire, including the final NUL byte */
#define DNS_WIRE_FOMAT_HOSTNAME_MAX 255
/* Maximum number of labels per valid hostname */
#define DNS_N_LABELS_MAX 127
int dns_label_unescape(const char **name, char *dest, size_t sz);
int dns_label_unescape_suffix(const char *name, const char **label_end, char *dest, size_t sz);
int dns_label_escape(const char *p, size_t l, char **ret);
int dns_label_escape(const char *p, size_t l, char *dest, size_t sz);
int dns_label_escape_new(const char *p, size_t l, char **ret);
static inline int dns_name_parent(const char **name) {
return dns_label_unescape(name, NULL, DNS_LABEL_MAX);
}
int dns_label_apply_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max);
int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max);
@@ -57,7 +77,6 @@ static inline int dns_name_is_valid(const char *s) {
return 1;
}
#if 0 /* NM_IGNORED */
void dns_name_hash_func(const void *s, struct siphash *state);
int dns_name_compare_func(const void *a, const void *b);
extern const struct hash_ops dns_name_hash_ops;
@@ -66,12 +85,23 @@ int dns_name_between(const char *a, const char *b, const char *c);
int dns_name_equal(const char *x, const char *y);
int dns_name_endswith(const char *name, const char *suffix);
int dns_name_change_suffix(const char *name, const char *old_suffix, const char *new_suffix, char **ret);
int dns_name_reverse(int family, const union in_addr_union *a, char **ret);
int dns_name_address(const char *p, int *family, union in_addr_union *a);
int dns_name_root(const char *name);
#endif /* NM_IGNORED */
bool dns_name_is_root(const char *name);
bool dns_name_is_single_label(const char *name);
int dns_name_single_label(const char *name);
int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len, bool canonical);
int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len);
bool dns_srv_type_is_valid(const char *name);
bool dns_service_name_is_valid(const char *name);
int dns_service_join(const char *name, const char *type, const char *domain, char **ret);
int dns_service_split(const char *joined, char **name, char **type, char **domain);
int dns_name_suffix(const char *name, unsigned n_labels, const char **ret);
int dns_name_count_labels(const char *name);
int dns_name_equal_skip(const char *a, unsigned n_labels, const char *b);

View File

@@ -59,10 +59,10 @@
# ifdef __cplusplus
# define _SD_BEGIN_DECLARATIONS \
extern "C" { \
struct __useless_struct_to_allow_trailing_semicolon__
struct _sd_useless_struct_to_allow_trailing_semicolon_
# else
# define _SD_BEGIN_DECLARATIONS \
struct __useless_struct_to_allow_trailing_semicolon__
struct _sd_useless_struct_to_allow_trailing_semicolon_
# endif
#endif
@@ -70,11 +70,18 @@
# ifdef __cplusplus
# define _SD_END_DECLARATIONS \
} \
struct __useless_struct_to_allow_trailing_semicolon__
struct _sd_useless_cpp_struct_to_allow_trailing_semicolon_
# else
# define _SD_END_DECLARATIONS \
struct __useless_struct_to_allow_trailing_semicolon__
struct _sd_useless_struct_to_allow_trailing_semicolon_
# endif
#endif
#define _SD_DEFINE_POINTER_CLEANUP_FUNC(type, func) \
static inline void func##p(type **p) { \
if (*p) \
func(*p); \
} \
struct _sd_useless_struct_to_allow_trailing_semicolon_
#endif

View File

@@ -51,7 +51,6 @@ typedef void (*sd_dhcp_client_cb_t)(sd_dhcp_client *client, int event,
int sd_dhcp_client_set_callback(sd_dhcp_client *client, sd_dhcp_client_cb_t cb,
void *userdata);
int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option);
int sd_dhcp_client_set_request_address(sd_dhcp_client *client,
const struct in_addr *last_address);
@@ -80,6 +79,8 @@ int sd_dhcp_client_attach_event(sd_dhcp_client *client, sd_event *event, int pri
int sd_dhcp_client_detach_event(sd_dhcp_client *client);
sd_event *sd_dhcp_client_get_event(sd_dhcp_client *client);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_client, sd_dhcp_client_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -60,6 +60,8 @@ int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const void **data, s
int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const void **client_id, size_t *client_id_len);
int sd_dhcp_lease_get_timezone(sd_dhcp_lease *lease, const char **timezone);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_lease, sd_dhcp_lease_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -74,6 +74,8 @@ sd_dhcp6_client *sd_dhcp6_client_ref(sd_dhcp6_client *client);
sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client);
int sd_dhcp6_client_new(sd_dhcp6_client **ret);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp6_client, sd_dhcp6_client_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -49,6 +49,8 @@ int sd_dhcp6_lease_get_ntp_fqdn(sd_dhcp6_lease *lease, char ***ntp_fqdn);
sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease);
sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp6_lease, sd_dhcp6_lease_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -133,6 +133,10 @@ int sd_event_source_get_time_clock(sd_event_source *s, clockid_t *clock);
int sd_event_source_get_signal(sd_event_source *s);
int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid);
/* Define helpers so that __attribute__((cleanup(sd_event_unrefp))) and similar may be used. */
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event, sd_event_unref);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event_source, sd_event_source_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -1,81 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#ifndef foosdicmp6ndfoo
#define foosdicmp6ndfoo
/***
This file is part of systemd.
Copyright (C) 2014 Intel Corporation. All rights reserved.
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 "nm-sd-adapt.h"
#include <net/ethernet.h>
#include "sd-event.h"
enum {
SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_NONE = 0,
SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_TIMEOUT = 1,
SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_OTHER = 2,
SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_MANAGED = 3,
SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_PREFIX_EXPIRED = 4,
};
typedef struct sd_icmp6_nd sd_icmp6_nd;
typedef void(*sd_icmp6_nd_callback_t)(sd_icmp6_nd *nd, int event,
void *userdata);
int sd_icmp6_nd_set_callback(sd_icmp6_nd *nd, sd_icmp6_nd_callback_t cb,
void *userdata);
int sd_icmp6_nd_set_index(sd_icmp6_nd *nd, int interface_index);
int sd_icmp6_nd_set_mac(sd_icmp6_nd *nd, const struct ether_addr *mac_addr);
int sd_icmp6_nd_attach_event(sd_icmp6_nd *nd, sd_event *event, int priority);
int sd_icmp6_nd_detach_event(sd_icmp6_nd *nd);
sd_event *sd_icmp6_nd_get_event(sd_icmp6_nd *nd);
sd_icmp6_nd *sd_icmp6_nd_ref(sd_icmp6_nd *nd);
sd_icmp6_nd *sd_icmp6_nd_unref(sd_icmp6_nd *nd);
int sd_icmp6_nd_new(sd_icmp6_nd **ret);
int sd_icmp6_prefix_match(struct in6_addr *prefix, uint8_t prefixlen,
struct in6_addr *addr);
int sd_icmp6_ra_get_mtu(sd_icmp6_nd *nd, uint32_t *mtu);
int sd_icmp6_ra_get_prefixlen(sd_icmp6_nd *nd, const struct in6_addr *addr,
uint8_t *prefixlen);
int sd_icmp6_ra_get_expired_prefix(sd_icmp6_nd *nd, struct in6_addr **addr,
uint8_t *prefixlen);
int sd_icmp6_nd_stop(sd_icmp6_nd *nd);
int sd_icmp6_router_solicitation_start(sd_icmp6_nd *nd);
#define SD_ICMP6_ND_ADDRESS_FORMAT_STR "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
#define SD_ICMP6_ND_ADDRESS_FORMAT_VAL(address) \
be16toh((address).s6_addr16[0]), \
be16toh((address).s6_addr16[1]), \
be16toh((address).s6_addr16[2]), \
be16toh((address).s6_addr16[3]), \
be16toh((address).s6_addr16[4]), \
be16toh((address).s6_addr16[5]), \
be16toh((address).s6_addr16[6]), \
be16toh((address).s6_addr16[7])
#endif

View File

@@ -55,7 +55,9 @@ int sd_ipv4acd_start(sd_ipv4acd *ll);
int sd_ipv4acd_stop(sd_ipv4acd *ll);
sd_ipv4acd *sd_ipv4acd_ref(sd_ipv4acd *ll);
sd_ipv4acd *sd_ipv4acd_unref(sd_ipv4acd *ll);
int sd_ipv4acd_new (sd_ipv4acd **ret);
int sd_ipv4acd_new(sd_ipv4acd **ret);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ipv4acd, sd_ipv4acd_unref);
_SD_END_DECLARATIONS;

View File

@@ -57,6 +57,8 @@ sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll);
sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll);
int sd_ipv4ll_new (sd_ipv4ll **ret);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ipv4ll, sd_ipv4ll_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -50,7 +50,7 @@ typedef struct sd_lldp_packet sd_lldp_packet;
typedef void (*sd_lldp_cb_t)(sd_lldp *lldp, int event, void *userdata);
int sd_lldp_new(int ifindex, const char *ifname, const struct ether_addr *mac, sd_lldp **ret);
void sd_lldp_free(sd_lldp *lldp);
sd_lldp* sd_lldp_unref(sd_lldp *lldp);
int sd_lldp_start(sd_lldp *lldp);
int sd_lldp_stop(sd_lldp *lldp);
@@ -83,6 +83,9 @@ int sd_lldp_packet_get_destination_type(sd_lldp_packet *tlv, int *dest);
int sd_lldp_get_packets(sd_lldp *lldp, sd_lldp_packet ***tlvs);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_lldp, sd_lldp_unref);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_lldp_packet, sd_lldp_packet_unref);
_SD_END_DECLARATIONS;
#endif

View File

@@ -81,6 +81,8 @@ int sd_ndisc_router_discovery_start(sd_ndisc *nd);
be16toh((address).s6_addr16[6]), \
be16toh((address).s6_addr16[7])
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc, sd_ndisc_unref);
_SD_END_DECLARATIONS;
#endif