mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
systemd: merge branch systemd into master
This commit is contained in:
commit
a791a9aa4b
|
@ -984,7 +984,7 @@ src_libsystemd_nm_la_SOURCES = \
|
|||
src/systemd/sd-adapt/conf-parser.h \
|
||||
src/systemd/sd-adapt/def.h \
|
||||
src/systemd/sd-adapt/dirent-util.h \
|
||||
src/systemd/sd-adapt/formats-util.h \
|
||||
src/systemd/sd-adapt/format-util.h \
|
||||
src/systemd/sd-adapt/gunicode.h \
|
||||
src/systemd/sd-adapt/libudev.h \
|
||||
src/systemd/sd-adapt/missing.h \
|
||||
|
|
|
@ -50,7 +50,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
|
|||
|
||||
/* Bail early if called after last value or with no input */
|
||||
if (!*p)
|
||||
goto finish_force_terminate;
|
||||
goto finish;
|
||||
c = **p;
|
||||
|
||||
if (!separators)
|
||||
|
|
|
@ -678,7 +678,7 @@ static int load_env_file_push(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
p = strjoin(key, "=", strempty(value), NULL);
|
||||
p = strjoin(key, "=", strempty(value));
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -966,9 +966,9 @@ static int search_and_fopen_internal(const char *path, const char *mode, const c
|
|||
FILE *f;
|
||||
|
||||
if (root)
|
||||
p = strjoin(root, *i, "/", path, NULL);
|
||||
p = strjoin(root, *i, "/", path);
|
||||
else
|
||||
p = strjoin(*i, "/", path, NULL);
|
||||
p = strjoin(*i, "/", path);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
@ -749,7 +749,7 @@ int chase_symlinks(const char *path, const char *_root, char **ret) {
|
|||
/* A relative destination. If so, this is what we'll prefix what's left to do with what
|
||||
* we just read, and start the loop again, but remain in the current directory. */
|
||||
|
||||
joined = strjoin("/", destination, todo, NULL);
|
||||
joined = strjoin("/", destination, todo);
|
||||
if (!joined)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ char *path_make_absolute(const char *p, const char *prefix) {
|
|||
if (path_is_absolute(p) || !prefix)
|
||||
return strdup(p);
|
||||
|
||||
return strjoin(prefix, "/", p, NULL);
|
||||
return strjoin(prefix, "/", p);
|
||||
}
|
||||
|
||||
int path_make_absolute_cwd(const char *p, char **ret) {
|
||||
|
@ -107,7 +107,7 @@ int path_make_absolute_cwd(const char *p, char **ret) {
|
|||
if (!cwd)
|
||||
return negative_errno();
|
||||
|
||||
c = strjoin(cwd, "/", p, NULL);
|
||||
c = strjoin(cwd, "/", p);
|
||||
}
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
@ -359,6 +359,16 @@ char* path_startswith(const char *path, const char *prefix) {
|
|||
assert(path);
|
||||
assert(prefix);
|
||||
|
||||
/* Returns a pointer to the start of the first component after the parts matched by
|
||||
* the prefix, iff
|
||||
* - both paths are absolute or both paths are relative,
|
||||
* and
|
||||
* - each component in prefix in turn matches a component in path at the same position.
|
||||
* An empty string will be returned when the prefix and path are equivalent.
|
||||
*
|
||||
* Returns NULL otherwise.
|
||||
*/
|
||||
|
||||
if ((path[0] == '/') != (prefix[0] == '/'))
|
||||
return NULL;
|
||||
|
||||
|
@ -449,13 +459,11 @@ char* path_join(const char *root, const char *path, const char *rest) {
|
|||
return strjoin(root, endswith(root, "/") ? "" : "/",
|
||||
path[0] == '/' ? path+1 : path,
|
||||
rest ? (endswith(path, "/") ? "" : "/") : NULL,
|
||||
rest && rest[0] == '/' ? rest+1 : rest,
|
||||
NULL);
|
||||
rest && rest[0] == '/' ? rest+1 : rest);
|
||||
else
|
||||
return strjoin(path,
|
||||
rest ? (endswith(path, "/") ? "" : "/") : NULL,
|
||||
rest && rest[0] == '/' ? rest+1 : rest,
|
||||
NULL);
|
||||
rest && rest[0] == '/' ? rest+1 : rest);
|
||||
}
|
||||
|
||||
int find_binary(const char *name, char **ret) {
|
||||
|
@ -499,7 +507,7 @@ int find_binary(const char *name, char **ret) {
|
|||
if (!path_is_absolute(element))
|
||||
continue;
|
||||
|
||||
j = strjoin(element, "/", name, NULL);
|
||||
j = strjoin(element, "/", name);
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "alloc-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
|
|
|
@ -220,7 +220,7 @@ char *strappend(const char *s, const char *suffix) {
|
|||
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
|
||||
}
|
||||
|
||||
char *strjoin(const char *x, ...) {
|
||||
char *strjoin_real(const char *x, ...) {
|
||||
va_list ap;
|
||||
size_t l;
|
||||
char *r, *p;
|
||||
|
|
|
@ -107,16 +107,14 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
|
|||
#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
|
||||
_FOREACH_WORD(word, length, s, separator, false, state)
|
||||
|
||||
#define FOREACH_WORD_QUOTED(word, length, s, state) \
|
||||
_FOREACH_WORD(word, length, s, WHITESPACE, true, state)
|
||||
|
||||
#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
|
||||
for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
|
||||
|
||||
char *strappend(const char *s, const char *suffix);
|
||||
char *strnappend(const char *s, const char *suffix, size_t length);
|
||||
|
||||
char *strjoin(const char *x, ...) _sentinel_;
|
||||
char *strjoin_real(const char *x, ...) _sentinel_;
|
||||
#define strjoin(a, ...) strjoin_real((a), __VA_ARGS__, NULL)
|
||||
|
||||
#define strjoina(a, ...) \
|
||||
({ \
|
||||
|
|
|
@ -312,7 +312,7 @@ static char *format_timestamp_internal(
|
|||
if (n + 8 > l)
|
||||
return NULL; /* Microseconds part doesn't fit. */
|
||||
|
||||
sprintf(buf + n, ".%06llu", (unsigned long long) (t % USEC_PER_SEC));
|
||||
sprintf(buf + n, ".%06"PRI_USEC, t % USEC_PER_SEC);
|
||||
}
|
||||
|
||||
/* Append the timezone */
|
||||
|
@ -503,11 +503,11 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
|
|||
|
||||
if (j > 0) {
|
||||
k = snprintf(p, l,
|
||||
"%s"USEC_FMT".%0*llu%s",
|
||||
"%s"USEC_FMT".%0*"PRI_USEC"%s",
|
||||
p > buf ? " " : "",
|
||||
a,
|
||||
j,
|
||||
(unsigned long long) b,
|
||||
b,
|
||||
table[i].suffix);
|
||||
|
||||
t = 0;
|
||||
|
@ -1327,7 +1327,7 @@ unsigned long usec_to_jiffies(usec_t u) {
|
|||
r = sysconf(_SC_CLK_TCK);
|
||||
|
||||
assert(r > 0);
|
||||
hz = (unsigned long) r;
|
||||
hz = r;
|
||||
}
|
||||
|
||||
return DIV_ROUND_UP(u , USEC_PER_SEC / hz);
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
typedef uint64_t usec_t;
|
||||
typedef uint64_t nsec_t;
|
||||
|
||||
#define NSEC_FMT "%" PRIu64
|
||||
#define USEC_FMT "%" PRIu64
|
||||
#define PRI_NSEC PRIu64
|
||||
#define PRI_USEC PRIu64
|
||||
#define NSEC_FMT "%" PRI_NSEC
|
||||
#define USEC_FMT "%" PRI_USEC
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "dirent-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "formats-util.h"
|
||||
#include "format-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "hostname-util.h"
|
||||
#include "log.h"
|
||||
|
@ -136,7 +136,7 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) {
|
|||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
path = strjoin(*directory, "/", de->d_name, NULL);
|
||||
path = strjoin(*directory, "/", de->d_name);
|
||||
if (!path)
|
||||
return log_oom();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "formats-util.h"
|
||||
#include "format-util.h"
|
||||
#include "macro.h"
|
||||
#include "missing.h"
|
||||
#include "time-util.h"
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
|
||||
int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link,
|
||||
uint32_t xid, const uint8_t *mac_addr,
|
||||
size_t mac_addr_len, uint16_t arp_type);
|
||||
size_t mac_addr_len, uint16_t arp_type,
|
||||
uint16_t port);
|
||||
int dhcp_network_bind_udp_socket(be32_t address, uint16_t port);
|
||||
int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
|
||||
const void *packet, size_t len);
|
||||
|
@ -57,7 +58,7 @@ void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
|
|||
uint16_t source, be32_t destination_addr,
|
||||
uint16_t destination, uint16_t len);
|
||||
|
||||
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum);
|
||||
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, uint16_t port);
|
||||
|
||||
/* If we are invoking callbacks of a dhcp-client, ensure unreffing the
|
||||
* client from the callback doesn't destroy the object we are working
|
||||
|
|
|
@ -38,7 +38,8 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link,
|
|||
size_t mac_addr_len,
|
||||
const uint8_t *bcast_addr,
|
||||
const struct ether_addr *eth_mac,
|
||||
uint16_t arp_type, uint8_t dhcp_hlen) {
|
||||
uint16_t arp_type, uint8_t dhcp_hlen,
|
||||
uint16_t port) {
|
||||
struct sock_filter filter[] = {
|
||||
BPF_STMT(BPF_LD + BPF_W + BPF_LEN, 0), /* A <- packet length */
|
||||
BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, sizeof(DHCPPacket), 1, 0), /* packet >= DHCPPacket ? */
|
||||
|
@ -55,7 +56,7 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link,
|
|||
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 1, 0), /* A == 0 ? */
|
||||
BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */
|
||||
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, offsetof(DHCPPacket, udp.dest)), /* A <- UDP destination port */
|
||||
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DHCP_PORT_CLIENT, 1, 0), /* UDP destination port == DHCP client port ? */
|
||||
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, port, 1, 0), /* UDP destination port == DHCP client port ? */
|
||||
BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */
|
||||
BPF_STMT(BPF_LD + BPF_B + BPF_ABS, offsetof(DHCPPacket, dhcp.op)), /* A <- DHCP op */
|
||||
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTREPLY, 1, 0), /* op == BOOTREPLY ? */
|
||||
|
@ -127,7 +128,8 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link,
|
|||
|
||||
int dhcp_network_bind_raw_socket(int ifindex, union sockaddr_union *link,
|
||||
uint32_t xid, const uint8_t *mac_addr,
|
||||
size_t mac_addr_len, uint16_t arp_type) {
|
||||
size_t mac_addr_len, uint16_t arp_type,
|
||||
uint16_t port) {
|
||||
static const uint8_t eth_bcast[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
/* Default broadcast address for IPoIB */
|
||||
static const uint8_t ib_bcast[] = {
|
||||
|
@ -153,7 +155,7 @@ int dhcp_network_bind_raw_socket(int ifindex, union sockaddr_union *link,
|
|||
return -EINVAL;
|
||||
|
||||
return _bind_raw_socket(ifindex, link, xid, mac_addr, mac_addr_len,
|
||||
bcast_addr, ð_mac, arp_type, dhcp_hlen);
|
||||
bcast_addr, ð_mac, arp_type, dhcp_hlen, port);
|
||||
}
|
||||
|
||||
int dhcp_network_bind_udp_socket(be32_t address, uint16_t port) {
|
||||
|
|
|
@ -116,7 +116,7 @@ void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
|
|||
packet->ip.check = dhcp_packet_checksum((uint8_t*)&packet->ip, DHCP_IP_SIZE);
|
||||
}
|
||||
|
||||
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
|
||||
int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, uint16_t port) {
|
||||
size_t hdrlen;
|
||||
|
||||
assert(packet);
|
||||
|
@ -162,10 +162,10 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
|
||||
if (be16toh(packet->udp.dest) != port) {
|
||||
log_debug("ignoring packet: to port %u, which "
|
||||
"is not the DHCP client port (%u)",
|
||||
be16toh(packet->udp.dest), DHCP_PORT_CLIENT);
|
||||
be16toh(packet->udp.dest), port);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ struct sd_dhcp_client {
|
|||
sd_event_source *timeout_resend;
|
||||
int ifindex;
|
||||
int fd;
|
||||
uint16_t port;
|
||||
union sockaddr_union link;
|
||||
sd_event_source *receive_message;
|
||||
bool request_broadcast;
|
||||
|
@ -430,6 +431,17 @@ int sd_dhcp_client_set_vendor_class_identifier(
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sd_dhcp_client_set_client_port(
|
||||
sd_dhcp_client *client,
|
||||
uint16_t port) {
|
||||
|
||||
assert_return(client, -EINVAL);
|
||||
|
||||
client->port = port;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_dhcp_client_set_mtu(sd_dhcp_client *client, uint32_t mtu) {
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(mtu >= DHCP_DEFAULT_MIN_SIZE, -ERANGE);
|
||||
|
@ -672,7 +684,7 @@ static int dhcp_client_send_raw(
|
|||
DHCPPacket *packet,
|
||||
size_t len) {
|
||||
|
||||
dhcp_packet_append_ip_headers(packet, INADDR_ANY, DHCP_PORT_CLIENT,
|
||||
dhcp_packet_append_ip_headers(packet, INADDR_ANY, client->port,
|
||||
INADDR_BROADCAST, DHCP_PORT_SERVER, len);
|
||||
|
||||
return dhcp_network_send_raw_socket(client->fd, &client->link,
|
||||
|
@ -1124,7 +1136,7 @@ static int client_start_delayed(sd_dhcp_client *client) {
|
|||
|
||||
r = dhcp_network_bind_raw_socket(client->ifindex, &client->link,
|
||||
client->xid, client->mac_addr,
|
||||
client->mac_addr_len, client->arp_type);
|
||||
client->mac_addr_len, client->arp_type, client->port);
|
||||
if (r < 0) {
|
||||
client_stop(client, r);
|
||||
return r;
|
||||
|
@ -1174,7 +1186,8 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
|
|||
|
||||
r = dhcp_network_bind_raw_socket(client->ifindex, &client->link,
|
||||
client->xid, client->mac_addr,
|
||||
client->mac_addr_len, client->arp_type);
|
||||
client->mac_addr_len, client->arp_type,
|
||||
client->port);
|
||||
if (r < 0) {
|
||||
client_stop(client, r);
|
||||
return 0;
|
||||
|
@ -1559,8 +1572,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
|
|||
goto error;
|
||||
}
|
||||
|
||||
r = dhcp_network_bind_udp_socket(client->lease->address,
|
||||
DHCP_PORT_CLIENT);
|
||||
r = dhcp_network_bind_udp_socket(client->lease->address, client->port);
|
||||
if (r < 0) {
|
||||
log_dhcp_client(client, "could not bind UDP socket");
|
||||
goto error;
|
||||
|
@ -1770,7 +1782,7 @@ static int client_receive_message_raw(
|
|||
}
|
||||
}
|
||||
|
||||
r = dhcp_packet_verify_headers(packet, len, checksum);
|
||||
r = dhcp_packet_verify_headers(packet, len, checksum, client->port);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
|
@ -1895,6 +1907,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret) {
|
|||
client->fd = -1;
|
||||
client->attempt = 1;
|
||||
client->mtu = DHCP_DEFAULT_MIN_SIZE;
|
||||
client->port = DHCP_PORT_CLIENT;
|
||||
|
||||
client->req_opts_size = ELEMENTSOF(default_req_opts);
|
||||
client->req_opts = memdup(default_req_opts, client->req_opts_size);
|
||||
|
|
|
@ -1081,7 +1081,7 @@ int dns_service_split(const char *joined, char **_name, char **_type, char **_do
|
|||
if (!name)
|
||||
return -ENOMEM;
|
||||
|
||||
type = strjoin(b, ".", c, NULL);
|
||||
type = strjoin(b, ".", c);
|
||||
if (!type)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -1095,7 +1095,7 @@ int dns_service_split(const char *joined, char **_name, char **_type, char **_do
|
|||
|
||||
name = NULL;
|
||||
|
||||
type = strjoin(a, ".", b, NULL);
|
||||
type = strjoin(a, ".", b);
|
||||
if (!type)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
@ -126,6 +126,9 @@ int sd_dhcp_client_get_client_id(
|
|||
int sd_dhcp_client_set_mtu(
|
||||
sd_dhcp_client *client,
|
||||
uint32_t mtu);
|
||||
int sd_dhcp_client_set_client_port(
|
||||
sd_dhcp_client *client,
|
||||
uint16_t port);
|
||||
int sd_dhcp_client_set_hostname(
|
||||
sd_dhcp_client *client,
|
||||
const char *hostname);
|
||||
|
|
Loading…
Reference in a new issue