Compare commits
15 Commits
7b6c92e6bb
...
58f848148f
Author | SHA1 | Date |
---|---|---|
Zbigniew Jędrzejewski-Szmek | 58f848148f | |
Zbigniew Jędrzejewski-Szmek | e61f999755 | |
Zbigniew Jędrzejewski-Szmek | ae7e5d2037 | |
Hans de Goede | ac6a1b9017 | |
Zbigniew Jędrzejewski-Szmek | c062cd9dde | |
Zbigniew Jędrzejewski-Szmek | 448e7440c2 | |
Zbigniew Jędrzejewski-Szmek | 59a711c2cd | |
Zbigniew Jędrzejewski-Szmek | 4368277c74 | |
Timo Rothenpieler | f1f1714411 | |
Timo Rothenpieler | 14b66dbc92 | |
Timo Rothenpieler | b8162cd200 | |
Timo Rothenpieler | 4fc8a29a7e | |
Lennart Poettering | b370adb593 | |
Lennart Poettering | 8facd1ce4f | |
Lennart Poettering | 1ed314087f |
|
@ -650,6 +650,14 @@ sensor:modalias:acpi:KIOX000A*:dmi:*:rvnPOV:rnI102A:*
|
|||
sensor:modalias:i2c:bmc150_accel:dmi:bvnINSYDECorp.:*:svnInsyde:pnBayTrail:*:rvn105B:rn0E57:*
|
||||
ACCEL_MOUNT_MATRIX=1, 0, 0; 0, -1, 0; 0, 0, 1
|
||||
|
||||
#########################################
|
||||
# Predia
|
||||
#########################################
|
||||
|
||||
# Predia Basic tablet, most DMI strings are generic, match on BIOS version
|
||||
sensor:modalias:acpi:BOSC0200*:dmi:bvnINSYDECorp.:bvrMx.WT107.KUBNGEA*svnInsyde:pnCherryTrail:*
|
||||
ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1
|
||||
|
||||
#########################################
|
||||
# Prowise
|
||||
#########################################
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LicenseRef-murmurhash2-public-domain */
|
||||
//-----------------------------------------------------------------------------
|
||||
// MurmurHash2 was written by Austin Appleby, and is placed in the public
|
||||
// domain. The author hereby disclaims copyright to this source code.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LicenseRef-murmurhash2-public-domain */
|
||||
//-----------------------------------------------------------------------------
|
||||
// MurmurHash2 was written by Austin Appleby, and is placed in the public
|
||||
// domain. The author hereby disclaims copyright to this source code.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -9,6 +10,20 @@
|
|||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
|
||||
char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]) {
|
||||
assert(addr);
|
||||
assert(buffer);
|
||||
assert(addr->length <= HW_ADDR_MAX_SIZE);
|
||||
|
||||
for (size_t i = 0; i < addr->length; i++) {
|
||||
sprintf(&buffer[3*i], "%02"PRIx8, addr->addr.bytes[i]);
|
||||
if (i < addr->length - 1)
|
||||
buffer[3*i + 2] = ':';
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) {
|
||||
assert(addr);
|
||||
assert(buffer);
|
||||
|
|
|
@ -1,11 +1,35 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include <linux/if_infiniband.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "hash-funcs.h"
|
||||
|
||||
/* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h
|
||||
* defines a macro of the same name with a much lower size. */
|
||||
#define HW_ADDR_MAX_SIZE 32
|
||||
|
||||
union hw_addr_union {
|
||||
struct ether_addr ether;
|
||||
uint8_t infiniband[INFINIBAND_ALEN];
|
||||
uint8_t bytes[HW_ADDR_MAX_SIZE];
|
||||
};
|
||||
|
||||
typedef struct hw_addr_data {
|
||||
union hw_addr_union addr;
|
||||
size_t length;
|
||||
} hw_addr_data;
|
||||
|
||||
#define HW_ADDR_TO_STRING_MAX (3*HW_ADDR_MAX_SIZE)
|
||||
char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]);
|
||||
|
||||
/* Use only as function argument, never stand-alone! */
|
||||
#define HW_ADDR_TO_STR(hw_addr) hw_addr_to_string((hw_addr), (char[HW_ADDR_TO_STRING_MAX]){})
|
||||
|
||||
#define HW_ADDR_NULL ((const hw_addr_data){})
|
||||
|
||||
#define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X"
|
||||
#define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5]
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/* gunicode.c - Unicode manipulation functions
|
||||
*
|
||||
* Copyright (C) 1999, 2000 Tom Tromey
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/* gunicode.h - Unicode manipulation functions
|
||||
*
|
||||
* Copyright (C) 1999, 2000 Tom Tromey
|
||||
* Copyright © 2000, 2005 Red Hat, Inc.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "memory-util.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: CC0-1.0 */
|
||||
|
||||
/*
|
||||
SipHash reference C implementation
|
||||
|
||||
|
@ -10,7 +12,7 @@
|
|||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
this software. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
(Minimal changes made by Lennart Poettering, to make clean for inclusion in systemd)
|
||||
(Refactored by Tom Gundersen to split up in several functions and follow systemd
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: CC0-1.0 */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "sort-util.h"
|
||||
#include "alloc-util.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc-util.h"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LicenseRef-crc32-no-restriction */
|
||||
/* This is copied from util-linux, which in turn copied in the version from Gary S. Brown */
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/* SPDX-License-Identifier: LicenseRef-crc32-no-restriction */
|
||||
#pragma once
|
||||
|
||||
#include <efi.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
/* Stolen from glibc and converted to UEFI style. In glibc it comes with the following copyright blurb: */
|
||||
|
||||
/* Functions to compute SHA256 message digest of files or memory blocks.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <openssl/pem.h>
|
||||
|
||||
#include "fd-util.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LicenseRef-lookup3-public-domain */
|
||||
/* Slightly modified by Lennart Poettering, to avoid name clashes, and
|
||||
* unexport a few functions. */
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LicenseRef-lookup3-public-domain */
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -29,10 +29,10 @@ typedef struct DHCPServerData {
|
|||
|
||||
extern const struct hash_ops dhcp_option_hash_ops;
|
||||
|
||||
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,
|
||||
uint16_t port);
|
||||
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,
|
||||
const uint8_t *bcast_addr, size_t bcast_addr_len,
|
||||
uint16_t arp_type, uint16_t port);
|
||||
int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int ip_service_type);
|
||||
int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
|
||||
const void *packet, size_t len);
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
#include "unaligned.h"
|
||||
|
||||
static int _bind_raw_socket(int ifindex, union sockaddr_union *link,
|
||||
uint32_t xid, const uint8_t *mac_addr,
|
||||
size_t mac_addr_len,
|
||||
uint32_t xid,
|
||||
const uint8_t *bcast_addr,
|
||||
size_t bcast_addr_len,
|
||||
const struct ether_addr *eth_mac,
|
||||
uint16_t arp_type, uint8_t dhcp_hlen,
|
||||
uint16_t port) {
|
||||
|
@ -104,9 +104,9 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link,
|
|||
.sll_protocol = htobe16(ETH_P_IP),
|
||||
.sll_ifindex = ifindex,
|
||||
.sll_hatype = htobe16(arp_type),
|
||||
.sll_halen = mac_addr_len,
|
||||
.sll_halen = bcast_addr_len,
|
||||
};
|
||||
memcpy(link->ll.sll_addr, bcast_addr, mac_addr_len);
|
||||
memcpy(link->ll.sll_addr, bcast_addr, bcast_addr_len);
|
||||
|
||||
r = bind(s, &link->sa, SOCKADDR_LL_LEN(link->ll));
|
||||
if (r < 0)
|
||||
|
@ -115,34 +115,44 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link,
|
|||
return TAKE_FD(s);
|
||||
}
|
||||
|
||||
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,
|
||||
uint16_t port) {
|
||||
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,
|
||||
const uint8_t *bcast_addr, size_t bcast_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[] = {
|
||||
0x00, 0xff, 0xff, 0xff, 0xff, 0x12, 0x40, 0x1b,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
};
|
||||
struct ether_addr eth_mac = { { 0, 0, 0, 0, 0, 0 } };
|
||||
const uint8_t *bcast_addr = NULL;
|
||||
const uint8_t *default_bcast_addr;
|
||||
size_t expected_bcast_addr_len;
|
||||
uint8_t dhcp_hlen = 0;
|
||||
|
||||
if (arp_type == ARPHRD_ETHER) {
|
||||
assert_return(mac_addr_len == ETH_ALEN, -EINVAL);
|
||||
memcpy(ð_mac, mac_addr, ETH_ALEN);
|
||||
bcast_addr = eth_bcast;
|
||||
dhcp_hlen = ETH_ALEN;
|
||||
|
||||
default_bcast_addr = eth_bcast;
|
||||
expected_bcast_addr_len = ETH_ALEN;
|
||||
} else if (arp_type == ARPHRD_INFINIBAND) {
|
||||
assert_return(mac_addr_len == INFINIBAND_ALEN, -EINVAL);
|
||||
bcast_addr = ib_bcast;
|
||||
default_bcast_addr = ib_bcast;
|
||||
expected_bcast_addr_len = INFINIBAND_ALEN;
|
||||
} else
|
||||
return -EINVAL;
|
||||
|
||||
return _bind_raw_socket(ifindex, link, xid, mac_addr, mac_addr_len,
|
||||
bcast_addr, ð_mac, arp_type, dhcp_hlen, port);
|
||||
if (bcast_addr && bcast_addr_len > 0)
|
||||
assert_return(bcast_addr_len == expected_bcast_addr_len, -EINVAL);
|
||||
else {
|
||||
bcast_addr = default_bcast_addr;
|
||||
bcast_addr_len = expected_bcast_addr_len;
|
||||
}
|
||||
|
||||
return _bind_raw_socket(ifindex, link, xid, bcast_addr, bcast_addr_len,
|
||||
ð_mac, arp_type, dhcp_hlen, port);
|
||||
}
|
||||
|
||||
int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int ip_service_type) {
|
||||
|
|
|
@ -82,6 +82,8 @@ struct sd_dhcp_client {
|
|||
be32_t last_addr;
|
||||
uint8_t mac_addr[MAX_MAC_ADDR_LEN];
|
||||
size_t mac_addr_len;
|
||||
uint8_t bcast_addr[MAX_MAC_ADDR_LEN];
|
||||
size_t bcast_addr_len;
|
||||
uint16_t arp_type;
|
||||
sd_dhcp_client_id client_id;
|
||||
size_t client_id_len;
|
||||
|
@ -277,6 +279,7 @@ int sd_dhcp_client_set_ifindex(sd_dhcp_client *client, int ifindex) {
|
|||
int sd_dhcp_client_set_mac(
|
||||
sd_dhcp_client *client,
|
||||
const uint8_t *addr,
|
||||
const uint8_t *bcast_addr,
|
||||
size_t addr_len,
|
||||
uint16_t arp_type) {
|
||||
|
||||
|
@ -297,7 +300,9 @@ int sd_dhcp_client_set_mac(
|
|||
return -EINVAL;
|
||||
|
||||
if (client->mac_addr_len == addr_len &&
|
||||
memcmp(&client->mac_addr, addr, addr_len) == 0)
|
||||
memcmp(&client->mac_addr, addr, addr_len) == 0 &&
|
||||
(client->bcast_addr_len > 0) == !!bcast_addr &&
|
||||
(!bcast_addr || memcmp(&client->bcast_addr, bcast_addr, addr_len) == 0))
|
||||
return 0;
|
||||
|
||||
if (!IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_STOPPED)) {
|
||||
|
@ -309,6 +314,12 @@ int sd_dhcp_client_set_mac(
|
|||
memcpy(&client->mac_addr, addr, addr_len);
|
||||
client->mac_addr_len = addr_len;
|
||||
client->arp_type = arp_type;
|
||||
client->bcast_addr_len = 0;
|
||||
|
||||
if (bcast_addr) {
|
||||
memcpy(&client->bcast_addr, bcast_addr, addr_len);
|
||||
client->bcast_addr_len = addr_len;
|
||||
}
|
||||
|
||||
if (need_restart && client->state != DHCP_STATE_STOPPED) {
|
||||
r = sd_dhcp_client_start(client);
|
||||
|
@ -1381,9 +1392,10 @@ static int client_start_delayed(sd_dhcp_client *client) {
|
|||
|
||||
client->xid = random_u32();
|
||||
|
||||
r = dhcp_network_bind_raw_socket(client->ifindex, &client->link,
|
||||
client->xid, client->mac_addr,
|
||||
client->mac_addr_len, client->arp_type, client->port);
|
||||
r = dhcp_network_bind_raw_socket(client->ifindex, &client->link, client->xid,
|
||||
client->mac_addr, client->mac_addr_len,
|
||||
client->bcast_addr, client->bcast_addr_len,
|
||||
client->arp_type, client->port);
|
||||
if (r < 0) {
|
||||
client_stop(client, r);
|
||||
return r;
|
||||
|
@ -1431,10 +1443,10 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
|
|||
client->state = DHCP_STATE_REBINDING;
|
||||
client->attempt = 0;
|
||||
|
||||
r = dhcp_network_bind_raw_socket(client->ifindex, &client->link,
|
||||
client->xid, client->mac_addr,
|
||||
client->mac_addr_len, client->arp_type,
|
||||
client->port);
|
||||
r = dhcp_network_bind_raw_socket(client->ifindex, &client->link, client->xid,
|
||||
client->mac_addr, client->mac_addr_len,
|
||||
client->bcast_addr, client->bcast_addr_len,
|
||||
client->arp_type, client->port);
|
||||
if (r < 0) {
|
||||
client_stop(client, r);
|
||||
return 0;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "util.h"
|
||||
|
||||
static uint8_t mac_addr[] = {'A', 'B', 'C', '1', '2', '3'};
|
||||
static uint8_t bcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
typedef int (*test_callback_recv_t)(size_t size, DHCPMessage *dhcp);
|
||||
|
||||
|
@ -247,6 +248,7 @@ int dhcp_network_bind_raw_socket(
|
|||
union sockaddr_union *link,
|
||||
uint32_t id,
|
||||
const uint8_t *addr, size_t addr_len,
|
||||
const uint8_t *bcaddr, size_t bcaddr_len,
|
||||
uint16_t arp_type, uint16_t port) {
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
|
||||
|
@ -296,7 +298,7 @@ static void test_discover_message(sd_event *e) {
|
|||
assert_se(r >= 0);
|
||||
|
||||
assert_se(sd_dhcp_client_set_ifindex(client, 42) >= 0);
|
||||
assert_se(sd_dhcp_client_set_mac(client, mac_addr, ETH_ALEN, ARPHRD_ETHER) >= 0);
|
||||
assert_se(sd_dhcp_client_set_mac(client, mac_addr, bcast_addr, ETH_ALEN, ARPHRD_ETHER) >= 0);
|
||||
|
||||
assert_se(sd_dhcp_client_set_request_option(client, 248) >= 0);
|
||||
|
||||
|
@ -513,7 +515,7 @@ static void test_addr_acq(sd_event *e) {
|
|||
assert_se(r >= 0);
|
||||
|
||||
assert_se(sd_dhcp_client_set_ifindex(client, 42) >= 0);
|
||||
assert_se(sd_dhcp_client_set_mac(client, mac_addr, ETH_ALEN, ARPHRD_ETHER) >= 0);
|
||||
assert_se(sd_dhcp_client_set_mac(client, mac_addr, bcast_addr, ETH_ALEN, ARPHRD_ETHER) >= 0);
|
||||
|
||||
assert_se(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e) >= 0);
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "dhcp-lease-internal.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "bus-internal.h"
|
||||
|
|
|
@ -495,6 +495,25 @@ int sd_netlink_message_append_ether_addr(sd_netlink_message *m, unsigned short t
|
|||
return 0;
|
||||
}
|
||||
|
||||
int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, const hw_addr_data *data) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(!m->sealed, -EPERM);
|
||||
assert_return(data, -EINVAL);
|
||||
assert_return(data->length > 0, -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_ETHER_ADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = add_rtattr(m, type, data->addr.bytes, data->length);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_message_append_cache_info(sd_netlink_message *m, unsigned short type, const struct ifa_cacheinfo *info) {
|
||||
int r;
|
||||
|
||||
|
@ -864,6 +883,30 @@ int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short typ
|
|||
return 0;
|
||||
}
|
||||
|
||||
int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, hw_addr_data *data) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_ETHER_ADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r > sizeof(union hw_addr_union))
|
||||
return -EIO;
|
||||
|
||||
if (data) {
|
||||
memcpy(data->addr.bytes, attr_data, r);
|
||||
data->length = r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short type, struct ifa_cacheinfo *info) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "ether-addr-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "ordered-set.h"
|
||||
#include "socket-util.h"
|
||||
|
@ -100,9 +101,11 @@ int rtnl_log_create_error(int r);
|
|||
userdata, description); \
|
||||
})
|
||||
|
||||
int netlink_message_append_hw_addr(sd_netlink_message *m, unsigned short type, const hw_addr_data *data);
|
||||
int netlink_message_append_in_addr_union(sd_netlink_message *m, unsigned short type, int family, const union in_addr_union *data);
|
||||
int netlink_message_append_sockaddr_union(sd_netlink_message *m, unsigned short type, const union sockaddr_union *data);
|
||||
|
||||
int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, hw_addr_data *data);
|
||||
int netlink_message_read_in_addr_union(sd_netlink_message *m, unsigned short type, int family, union in_addr_union *data);
|
||||
|
||||
void rtattr_append_attribute_internal(struct rtattr *rta, unsigned short type, const void *data, size_t data_length);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct Wireguard Wireguard;
|
||||
|
|
|
@ -135,7 +135,7 @@ typedef struct LinkInfo {
|
|||
sd_device *sd_device;
|
||||
int ifindex;
|
||||
unsigned short iftype;
|
||||
struct ether_addr mac_address;
|
||||
hw_addr_data hw_address;
|
||||
struct ether_addr permanent_mac_address;
|
||||
uint32_t master;
|
||||
uint32_t mtu;
|
||||
|
@ -416,13 +416,14 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns, b
|
|||
info->alternative_names = TAKE_PTR(altnames);
|
||||
|
||||
info->has_mac_address =
|
||||
sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 &&
|
||||
memcmp(&info->mac_address, ÐER_ADDR_NULL, sizeof(struct ether_addr)) != 0;
|
||||
netlink_message_read_hw_addr(m, IFLA_ADDRESS, &info->hw_address) >= 0 &&
|
||||
memcmp(&info->hw_address, &HW_ADDR_NULL, sizeof(hw_addr_data)) != 0;
|
||||
|
||||
info->has_permanent_mac_address =
|
||||
ethtool_get_permanent_macaddr(NULL, info->name, &info->permanent_mac_address) >= 0 &&
|
||||
memcmp(&info->permanent_mac_address, ÐER_ADDR_NULL, sizeof(struct ether_addr)) != 0 &&
|
||||
memcmp(&info->permanent_mac_address, &info->mac_address, sizeof(struct ether_addr)) != 0;
|
||||
(info->hw_address.length != sizeof(struct ether_addr) ||
|
||||
memcmp(&info->permanent_mac_address, info->hw_address.addr.bytes, sizeof(struct ether_addr)) != 0);
|
||||
|
||||
(void) sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu);
|
||||
(void) sd_netlink_message_read_u32(m, IFLA_MIN_MTU, &info->min_mtu);
|
||||
|
@ -1526,9 +1527,9 @@ static int link_status_one(
|
|||
|
||||
if (info->has_mac_address) {
|
||||
_cleanup_free_ char *description = NULL;
|
||||
char ea[ETHER_ADDR_TO_STRING_MAX];
|
||||
|
||||
(void) ieee_oui(hwdb, &info->mac_address, &description);
|
||||
if (info->hw_address.length == ETH_ALEN)
|
||||
(void) ieee_oui(hwdb, &info->hw_address.addr.ether, &description);
|
||||
|
||||
r = table_add_many(table,
|
||||
TABLE_EMPTY,
|
||||
|
@ -1536,7 +1537,7 @@ static int link_status_one(
|
|||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
|
||||
ether_addr_to_string(&info->mac_address, ea),
|
||||
HW_ADDR_TO_STR(&info->hw_address),
|
||||
description ? " (" : "",
|
||||
strempty(description),
|
||||
description ? ")" : "");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "firewall-util.h"
|
||||
|
@ -21,16 +22,24 @@ int generate_ipv6_eui_64_address(const Link *link, struct in6_addr *ret) {
|
|||
assert(link);
|
||||
assert(ret);
|
||||
|
||||
if (link->iftype == ARPHRD_INFINIBAND) {
|
||||
/* see RFC4391 section 8 */
|
||||
memcpy(&ret->s6_addr[8], &link->hw_addr.addr.infiniband[12], 8);
|
||||
ret->s6_addr[8] ^= 1 << 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* see RFC4291 section 2.5.1 */
|
||||
ret->s6_addr[8] = link->mac.ether_addr_octet[0];
|
||||
ret->s6_addr[8] = link->hw_addr.addr.ether.ether_addr_octet[0];
|
||||
ret->s6_addr[8] ^= 1 << 1;
|
||||
ret->s6_addr[9] = link->mac.ether_addr_octet[1];
|
||||
ret->s6_addr[10] = link->mac.ether_addr_octet[2];
|
||||
ret->s6_addr[9] = link->hw_addr.addr.ether.ether_addr_octet[1];
|
||||
ret->s6_addr[10] = link->hw_addr.addr.ether.ether_addr_octet[2];
|
||||
ret->s6_addr[11] = 0xff;
|
||||
ret->s6_addr[12] = 0xfe;
|
||||
ret->s6_addr[13] = link->mac.ether_addr_octet[3];
|
||||
ret->s6_addr[14] = link->mac.ether_addr_octet[4];
|
||||
ret->s6_addr[15] = link->mac.ether_addr_octet[5];
|
||||
ret->s6_addr[13] = link->hw_addr.addr.ether.ether_addr_octet[3];
|
||||
ret->s6_addr[14] = link->hw_addr.addr.ether.ether_addr_octet[4];
|
||||
ret->s6_addr[15] = link->hw_addr.addr.ether.ether_addr_octet[5];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1373,7 +1382,7 @@ static int ipv4_dad_configure(Address *address) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_ipv4acd_set_mac(address->acd, &address->link->mac);
|
||||
r = sd_ipv4acd_set_mac(address->acd, &address->link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -1403,7 +1412,7 @@ static int ipv4_dad_update_mac_one(Address *address) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_ipv4acd_set_mac(address->acd, &address->link->mac);
|
||||
r = sd_ipv4acd_set_mac(address->acd, &address->link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -650,7 +650,7 @@ static int dhcp4_configure_dad(Link *link) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->mac);
|
||||
r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -672,7 +672,7 @@ static int dhcp4_dad_update_mac(Link *link) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->mac);
|
||||
r = sd_ipv4acd_set_mac(link->dhcp_acd, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -1271,14 +1271,24 @@ static int dhcp4_set_client_identifier(Link *link) {
|
|||
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set DUID: %m");
|
||||
break;
|
||||
}
|
||||
case DHCP_CLIENT_ID_MAC:
|
||||
case DHCP_CLIENT_ID_MAC: {
|
||||
const uint8_t *hw_addr = link->hw_addr.addr.bytes;
|
||||
size_t hw_addr_len = link->hw_addr.length;
|
||||
|
||||
if (link->iftype == ARPHRD_INFINIBAND && hw_addr_len == INFINIBAND_ALEN) {
|
||||
/* set_client_id expects only last 8 bytes of an IB address */
|
||||
hw_addr += INFINIBAND_ALEN - 8;
|
||||
hw_addr_len -= INFINIBAND_ALEN - 8;
|
||||
}
|
||||
|
||||
r = sd_dhcp_client_set_client_id(link->dhcp_client,
|
||||
ARPHRD_ETHER,
|
||||
(const uint8_t *) &link->mac,
|
||||
sizeof(link->mac));
|
||||
link->iftype,
|
||||
hw_addr,
|
||||
hw_addr_len);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set client ID: %m");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert_not_reached("Unknown client identifier type.");
|
||||
}
|
||||
|
@ -1325,8 +1335,9 @@ int dhcp4_configure(Link *link) {
|
|||
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to initialize DHCP4 client: %m");
|
||||
|
||||
r = sd_dhcp_client_set_mac(link->dhcp_client,
|
||||
(const uint8_t *) &link->mac,
|
||||
sizeof (link->mac), ARPHRD_ETHER);
|
||||
link->hw_addr.addr.bytes,
|
||||
link->bcast_addr.length > 0 ? link->bcast_addr.addr.bytes : NULL,
|
||||
link->hw_addr.length, link->iftype);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set MAC address: %m");
|
||||
|
||||
|
@ -1484,7 +1495,9 @@ int dhcp4_update_mac(Link *link) {
|
|||
if (!link->dhcp_client)
|
||||
return 0;
|
||||
|
||||
r = sd_dhcp_client_set_mac(link->dhcp_client, (const uint8_t *) &link->mac, sizeof (link->mac), ARPHRD_ETHER);
|
||||
r = sd_dhcp_client_set_mac(link->dhcp_client, link->hw_addr.addr.bytes,
|
||||
link->bcast_addr.length > 0 ? link->bcast_addr.addr.bytes : NULL,
|
||||
link->hw_addr.length, link->iftype);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -1357,7 +1357,7 @@ static int dhcp6_set_identifier(Link *link, sd_dhcp6_client *client) {
|
|||
assert(link->network);
|
||||
assert(client);
|
||||
|
||||
r = sd_dhcp6_client_set_mac(client, (const uint8_t *) &link->mac, sizeof (link->mac), ARPHRD_ETHER);
|
||||
r = sd_dhcp6_client_set_mac(client, link->hw_addr.addr.bytes, link->hw_addr.length, link->iftype);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ int ipv4ll_configure(Link *link) {
|
|||
return r;
|
||||
}
|
||||
|
||||
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac);
|
||||
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -211,7 +211,7 @@ int ipv4ll_update_mac(Link *link) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac);
|
||||
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -421,9 +421,13 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
|||
if (r < 0)
|
||||
log_link_debug_errno(link, r, "New device has no master, continuing without");
|
||||
|
||||
r = sd_netlink_message_read_ether_addr(message, IFLA_ADDRESS, &link->mac);
|
||||
r = netlink_message_read_hw_addr(message, IFLA_ADDRESS, &link->hw_addr);
|
||||
if (r < 0)
|
||||
log_link_debug_errno(link, r, "MAC address not found for new device, continuing without");
|
||||
log_link_debug_errno(link, r, "Hardware address not found for new device, continuing without");
|
||||
|
||||
r = netlink_message_read_hw_addr(message, IFLA_BROADCAST, &link->bcast_addr);
|
||||
if (r < 0)
|
||||
log_link_debug_errno(link, r, "Broadcast address not found for new device, continuing without");
|
||||
|
||||
r = ethtool_get_permanent_macaddr(&manager->ethtool_fd, link->ifname, &link->permanent_mac);
|
||||
if (r < 0)
|
||||
|
@ -2167,7 +2171,7 @@ static int link_reconfigure_internal(Link *link, sd_netlink_message *m, bool for
|
|||
|
||||
r = network_get(link->manager, link->iftype, link->sd_device,
|
||||
link->ifname, link->alternative_names, link->driver,
|
||||
&link->mac, &link->permanent_mac,
|
||||
&link->hw_addr.addr.ether, &link->permanent_mac,
|
||||
link->wlan_iftype, link->ssid, &link->bssid, &network);
|
||||
if (r == -ENOENT) {
|
||||
link_enter_unmanaged(link);
|
||||
|
@ -2302,7 +2306,7 @@ static int link_initialized_and_synced(Link *link) {
|
|||
|
||||
r = network_get(link->manager, link->iftype, link->sd_device,
|
||||
link->ifname, link->alternative_names, link->driver,
|
||||
&link->mac, &link->permanent_mac,
|
||||
&link->hw_addr.addr.ether, &link->permanent_mac,
|
||||
link->wlan_iftype, link->ssid, &link->bssid, &network);
|
||||
if (r == -ENOENT) {
|
||||
link_enter_unmanaged(link);
|
||||
|
@ -2697,7 +2701,7 @@ static int link_admin_state_up(Link *link) {
|
|||
|
||||
int link_update(Link *link, sd_netlink_message *m) {
|
||||
_cleanup_strv_free_ char **s = NULL;
|
||||
struct ether_addr mac;
|
||||
hw_addr_data hw_addr;
|
||||
const char *ifname;
|
||||
uint32_t mtu;
|
||||
bool had_carrier, carrier_gained, carrier_lost, link_was_admin_up;
|
||||
|
@ -2756,19 +2760,13 @@ int link_update(Link *link, sd_netlink_message *m) {
|
|||
|
||||
/* The kernel may broadcast NEWLINK messages without the MAC address
|
||||
set, simply ignore them. */
|
||||
r = sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &mac);
|
||||
if (r >= 0 && memcmp(link->mac.ether_addr_octet, mac.ether_addr_octet, ETH_ALEN) != 0) {
|
||||
r = netlink_message_read_hw_addr(m, IFLA_ADDRESS, &hw_addr);
|
||||
if (r >= 0 && (link->hw_addr.length != hw_addr.length ||
|
||||
memcmp(link->hw_addr.addr.bytes, hw_addr.addr.bytes, hw_addr.length) != 0)) {
|
||||
|
||||
memcpy(link->mac.ether_addr_octet, mac.ether_addr_octet, ETH_ALEN);
|
||||
memcpy(link->hw_addr.addr.bytes, hw_addr.addr.bytes, hw_addr.length);
|
||||
|
||||
log_link_debug(link, "Gained new MAC address: "
|
||||
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
|
||||
mac.ether_addr_octet[0],
|
||||
mac.ether_addr_octet[1],
|
||||
mac.ether_addr_octet[2],
|
||||
mac.ether_addr_octet[3],
|
||||
mac.ether_addr_octet[4],
|
||||
mac.ether_addr_octet[5]);
|
||||
log_link_debug(link, "Gained new hardware address: %s", HW_ADDR_TO_STR(&hw_addr));
|
||||
|
||||
r = ipv4ll_update_mac(link);
|
||||
if (r < 0)
|
||||
|
@ -2787,7 +2785,7 @@ int link_update(Link *link, sd_netlink_message *m) {
|
|||
return log_link_warning_errno(link, r, "Could not update MAC address for Router Advertisement: %m");
|
||||
|
||||
if (link->ndisc) {
|
||||
r = sd_ndisc_set_mac(link->ndisc, &link->mac);
|
||||
r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not update MAC for NDisc: %m");
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "sd-radv.h"
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "ether-addr-util.h"
|
||||
#include "log-link.h"
|
||||
#include "network-util.h"
|
||||
#include "networkd-util.h"
|
||||
|
@ -52,7 +53,8 @@ typedef struct Link {
|
|||
char *kind;
|
||||
unsigned short iftype;
|
||||
char *state_file;
|
||||
struct ether_addr mac;
|
||||
hw_addr_data hw_addr;
|
||||
hw_addr_data bcast_addr;
|
||||
struct ether_addr permanent_mac;
|
||||
struct in6_addr ipv6ll_address;
|
||||
uint32_t mtu;
|
||||
|
|
|
@ -93,7 +93,7 @@ int link_lldp_rx_configure(Link *link) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_lldp_set_filter_address(link->lldp, &link->mac);
|
||||
r = sd_lldp_set_filter_address(link->lldp, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -313,7 +313,7 @@ static int link_send_lldp(Link *link) {
|
|||
SD_LLDP_SYSTEM_CAPABILITIES_STATION;
|
||||
|
||||
r = lldp_make_packet(link->network->lldp_emit,
|
||||
&link->mac,
|
||||
&link->hw_addr.addr.ether,
|
||||
sd_id128_to_string(machine_id, machine_id_string),
|
||||
link->ifname,
|
||||
(uint16_t) ttl,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <linux/if.h>
|
||||
|
||||
#include "sd-ndisc.h"
|
||||
|
@ -593,7 +594,11 @@ static int make_stableprivate_address(Link *link, const struct in6_addr *prefix,
|
|||
l = MAX(DIV_ROUND_UP(prefix_len, 8), 8);
|
||||
siphash24_compress(prefix, l, &state);
|
||||
siphash24_compress_string(link->ifname, &state);
|
||||
siphash24_compress(&link->mac, sizeof(struct ether_addr), &state);
|
||||
/* Only last 8 bytes of IB MAC are stable */
|
||||
if (link->iftype == ARPHRD_INFINIBAND)
|
||||
siphash24_compress(&link->hw_addr.addr.infiniband[12], 8, &state);
|
||||
else
|
||||
siphash24_compress(link->hw_addr.addr.bytes, link->hw_addr.length, &state);
|
||||
siphash24_compress(&dad_counter, sizeof(uint8_t), &state);
|
||||
|
||||
rid = htole64(siphash24_finalize(&state));
|
||||
|
@ -1257,7 +1262,7 @@ int ndisc_configure(Link *link) {
|
|||
return r;
|
||||
}
|
||||
|
||||
r = sd_ndisc_set_mac(link->ndisc, &link->mac);
|
||||
r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -659,7 +659,7 @@ int radv_configure(Link *link) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_radv_set_mac(link->radv, &link->mac);
|
||||
r = sd_radv_set_mac(link->radv, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -727,7 +727,7 @@ int radv_update_mac(Link *link) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_radv_set_mac(link->radv, &link->mac);
|
||||
r = sd_radv_set_mac(link->radv, &link->hw_addr.addr.ether);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "bond.h"
|
||||
#include "dhcp6-internal.h"
|
||||
#include "dhcp6-protocol.h"
|
||||
|
|
|
@ -436,20 +436,22 @@ static int dns_cache_put_positive(
|
|||
|
||||
dns_cache_make_space(c, 1);
|
||||
|
||||
i = new0(DnsCacheItem, 1);
|
||||
i = new(DnsCacheItem, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
i->type = DNS_CACHE_POSITIVE;
|
||||
i->key = dns_resource_key_ref(rr->key);
|
||||
i->rr = dns_resource_record_ref(rr);
|
||||
i->until = calculate_until(rr, (uint32_t) -1, timestamp, false);
|
||||
i->authenticated = authenticated;
|
||||
i->shared_owner = shared_owner;
|
||||
i->ifindex = ifindex;
|
||||
i->owner_family = owner_family;
|
||||
i->owner_address = *owner_address;
|
||||
i->prioq_idx = PRIOQ_IDX_NULL;
|
||||
*i = (DnsCacheItem) {
|
||||
.type = DNS_CACHE_POSITIVE,
|
||||
.key = dns_resource_key_ref(rr->key),
|
||||
.rr = dns_resource_record_ref(rr),
|
||||
.until = calculate_until(rr, (uint32_t) -1, timestamp, false),
|
||||
.authenticated = authenticated,
|
||||
.shared_owner = shared_owner,
|
||||
.ifindex = ifindex,
|
||||
.owner_family = owner_family,
|
||||
.owner_address = *owner_address,
|
||||
.prioq_idx = PRIOQ_IDX_NULL,
|
||||
};
|
||||
|
||||
r = dns_cache_link_item(c, i);
|
||||
if (r < 0)
|
||||
|
@ -521,21 +523,23 @@ static int dns_cache_put_negative(
|
|||
|
||||
dns_cache_make_space(c, 1);
|
||||
|
||||
i = new0(DnsCacheItem, 1);
|
||||
i = new(DnsCacheItem, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
i->type =
|
||||
rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA :
|
||||
rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE;
|
||||
i->until =
|
||||
i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC :
|
||||
calculate_until(soa, nsec_ttl, timestamp, true);
|
||||
i->authenticated = authenticated;
|
||||
i->owner_family = owner_family;
|
||||
i->owner_address = *owner_address;
|
||||
i->prioq_idx = PRIOQ_IDX_NULL;
|
||||
i->rcode = rcode;
|
||||
*i = (DnsCacheItem) {
|
||||
.type =
|
||||
rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA :
|
||||
rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE,
|
||||
.until =
|
||||
i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC :
|
||||
calculate_until(soa, nsec_ttl, timestamp, true),
|
||||
.authenticated = authenticated,
|
||||
.owner_family = owner_family,
|
||||
.owner_address = *owner_address,
|
||||
.prioq_idx = PRIOQ_IDX_NULL,
|
||||
.rcode = rcode,
|
||||
};
|
||||
|
||||
if (i->type == DNS_CACHE_NXDOMAIN) {
|
||||
/* NXDOMAIN entries should apply equally to all types, so we use ANY as
|
||||
|
|
|
@ -75,12 +75,16 @@ int dns_packet_new(
|
|||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
p->size = p->rindex = DNS_PACKET_HEADER_SIZE;
|
||||
p->allocated = a;
|
||||
p->max_size = max_size;
|
||||
p->protocol = protocol;
|
||||
p->opt_start = p->opt_size = (size_t) -1;
|
||||
p->n_ref = 1;
|
||||
*p = (DnsPacket) {
|
||||
.n_ref = 1,
|
||||
.protocol = protocol,
|
||||
.size = DNS_PACKET_HEADER_SIZE,
|
||||
.rindex = DNS_PACKET_HEADER_SIZE,
|
||||
.allocated = a,
|
||||
.max_size = max_size,
|
||||
.opt_start = (size_t) -1,
|
||||
.opt_size = (size_t) -1,
|
||||
};
|
||||
|
||||
*ret = p;
|
||||
|
||||
|
|
|
@ -21,12 +21,14 @@ static int dns_query_candidate_new(DnsQueryCandidate **ret, DnsQuery *q, DnsScop
|
|||
assert(q);
|
||||
assert(s);
|
||||
|
||||
c = new0(DnsQueryCandidate, 1);
|
||||
c = new(DnsQueryCandidate, 1);
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
c->query = q;
|
||||
c->scope = s;
|
||||
*c = (DnsQueryCandidate) {
|
||||
.query = q,
|
||||
.scope = s,
|
||||
};
|
||||
|
||||
LIST_PREPEND(candidates_by_query, q->candidates, c);
|
||||
LIST_PREPEND(candidates_by_scope, s->query_candidates, c);
|
||||
|
@ -413,17 +415,19 @@ int dns_query_new(
|
|||
if (m->n_dns_queries >= QUERIES_MAX)
|
||||
return -EBUSY;
|
||||
|
||||
q = new0(DnsQuery, 1);
|
||||
q = new(DnsQuery, 1);
|
||||
if (!q)
|
||||
return -ENOMEM;
|
||||
|
||||
q->question_utf8 = dns_question_ref(question_utf8);
|
||||
q->question_idna = dns_question_ref(question_idna);
|
||||
q->ifindex = ifindex;
|
||||
q->flags = flags;
|
||||
q->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
|
||||
q->answer_protocol = _DNS_PROTOCOL_INVALID;
|
||||
q->answer_family = AF_UNSPEC;
|
||||
*q = (DnsQuery) {
|
||||
.question_utf8 = dns_question_ref(question_utf8),
|
||||
.question_idna = dns_question_ref(question_idna),
|
||||
.ifindex = ifindex,
|
||||
.flags = flags,
|
||||
.answer_dnssec_result = _DNSSEC_RESULT_INVALID,
|
||||
.answer_protocol = _DNS_PROTOCOL_INVALID,
|
||||
.answer_family = AF_UNSPEC,
|
||||
};
|
||||
|
||||
/* First dump UTF8 question */
|
||||
DNS_QUESTION_FOREACH(key, question_utf8)
|
||||
|
|
|
@ -97,14 +97,16 @@ DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char
|
|||
|
||||
assert(name);
|
||||
|
||||
k = new0(DnsResourceKey, 1);
|
||||
k = new(DnsResourceKey, 1);
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
k->n_ref = 1;
|
||||
k->class = class;
|
||||
k->type = type;
|
||||
k->_name = name;
|
||||
*k = (DnsResourceKey) {
|
||||
.n_ref = 1,
|
||||
.class = class,
|
||||
.type = type,
|
||||
._name = name,
|
||||
};
|
||||
|
||||
return k;
|
||||
}
|
||||
|
@ -372,14 +374,17 @@ bool dns_resource_key_reduce(DnsResourceKey **a, DnsResourceKey **b) {
|
|||
DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
|
||||
DnsResourceRecord *rr;
|
||||
|
||||
rr = new0(DnsResourceRecord, 1);
|
||||
rr = new(DnsResourceRecord, 1);
|
||||
if (!rr)
|
||||
return NULL;
|
||||
|
||||
rr->n_ref = 1;
|
||||
rr->key = dns_resource_key_ref(key);
|
||||
rr->expiry = USEC_INFINITY;
|
||||
rr->n_skip_labels_signer = rr->n_skip_labels_source = (unsigned) -1;
|
||||
*rr = (DnsResourceRecord) {
|
||||
.n_ref = 1,
|
||||
.key = dns_resource_key_ref(key),
|
||||
.expiry = USEC_INFINITY,
|
||||
.n_skip_labels_signer = (unsigned) -1,
|
||||
.n_skip_labels_source = (unsigned) -1,
|
||||
};
|
||||
|
||||
return rr;
|
||||
}
|
||||
|
|
|
@ -33,14 +33,16 @@ int dns_search_domain_new(
|
|||
return -E2BIG;
|
||||
}
|
||||
|
||||
d = new0(DnsSearchDomain, 1);
|
||||
d = new(DnsSearchDomain, 1);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
d->n_ref = 1;
|
||||
d->manager = m;
|
||||
d->type = type;
|
||||
d->name = TAKE_PTR(normalized);
|
||||
*d = (DnsSearchDomain) {
|
||||
.n_ref = 1,
|
||||
.manager = m,
|
||||
.type = type,
|
||||
.name = TAKE_PTR(normalized),
|
||||
};
|
||||
|
||||
switch (type) {
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
* IP and UDP header sizes */
|
||||
#define ADVERTISE_DATAGRAM_SIZE_MAX (65536U-14U-20U-8U)
|
||||
|
||||
/* On the extra stubs, use a more conservative choice */
|
||||
#define ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX DNS_PACKET_UNICAST_SIZE_LARGE_MAX
|
||||
|
||||
static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int type);
|
||||
|
||||
static void dns_stub_listener_extra_hash_func(const DnsStubListenerExtra *a, struct siphash *state) {
|
||||
|
@ -155,14 +158,15 @@ static int dns_stub_finish_reply_packet(
|
|||
bool tc, /* set the Truncated bit? */
|
||||
bool add_opt, /* add an OPT RR to this packet? */
|
||||
bool edns0_do, /* set the EDNS0 DNSSEC OK bit? */
|
||||
bool ad) { /* set the DNSSEC authenticated data bit? */
|
||||
bool ad, /* set the DNSSEC authenticated data bit? */
|
||||
uint16_t max_udp_size) { /* The maximum UDP datagram size to advertise to clients */
|
||||
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (add_opt) {
|
||||
r = dns_packet_append_opt(p, ADVERTISE_DATAGRAM_SIZE_MAX, edns0_do, /* include_rfc6975 = */ false, rcode, NULL);
|
||||
r = dns_packet_append_opt(p, max_udp_size, edns0_do, /* include_rfc6975 = */ false, rcode, NULL);
|
||||
if (r == -EMSGSIZE) /* Hit the size limit? then indicate truncation */
|
||||
tc = true;
|
||||
else if (r < 0)
|
||||
|
@ -245,7 +249,15 @@ static int dns_stub_send_failure(
|
|||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to make failure packet: %m");
|
||||
|
||||
r = dns_stub_finish_reply_packet(reply, DNS_PACKET_ID(p), rcode, false, !!p->opt, DNS_PACKET_DO(p), authenticated);
|
||||
r = dns_stub_finish_reply_packet(
|
||||
reply,
|
||||
DNS_PACKET_ID(p),
|
||||
rcode,
|
||||
/* truncated = */ false,
|
||||
!!p->opt,
|
||||
DNS_PACKET_DO(p),
|
||||
authenticated,
|
||||
l ? ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX : ADVERTISE_DATAGRAM_SIZE_MAX);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to build failure packet: %m");
|
||||
|
||||
|
@ -290,7 +302,8 @@ static void dns_stub_query_complete(DnsQuery *q) {
|
|||
truncated,
|
||||
!!q->request_dns_packet->opt,
|
||||
DNS_PACKET_DO(q->request_dns_packet),
|
||||
dns_query_fully_authenticated(q));
|
||||
dns_query_fully_authenticated(q),
|
||||
q->stub_listener_extra ? ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX : ADVERTISE_DATAGRAM_SIZE_MAX);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to finish reply packet: %m");
|
||||
break;
|
||||
|
|
|
@ -194,19 +194,20 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key)
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
t = new0(DnsTransaction, 1);
|
||||
t = new(DnsTransaction, 1);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
t->dns_udp_fd = -1;
|
||||
t->answer_source = _DNS_TRANSACTION_SOURCE_INVALID;
|
||||
t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
|
||||
t->answer_nsec_ttl = (uint32_t) -1;
|
||||
t->key = dns_resource_key_ref(key);
|
||||
t->current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
|
||||
t->clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
|
||||
|
||||
t->id = pick_new_id(s->manager);
|
||||
*t = (DnsTransaction) {
|
||||
.dns_udp_fd = -1,
|
||||
.answer_source = _DNS_TRANSACTION_SOURCE_INVALID,
|
||||
.answer_dnssec_result = _DNSSEC_RESULT_INVALID,
|
||||
.answer_nsec_ttl = (uint32_t) -1,
|
||||
.key = dns_resource_key_ref(key),
|
||||
.current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID,
|
||||
.clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID,
|
||||
.id = pick_new_id(s->manager),
|
||||
};
|
||||
|
||||
r = hashmap_put(s->manager->dns_transactions, UINT_TO_PTR(t->id), t);
|
||||
if (r < 0) {
|
||||
|
@ -1112,60 +1113,54 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) {
|
|||
if (r > 0) /* Transaction got restarted... */
|
||||
return;
|
||||
|
||||
if (IN_SET(t->scope->protocol, DNS_PROTOCOL_DNS, DNS_PROTOCOL_LLMNR, DNS_PROTOCOL_MDNS)) {
|
||||
|
||||
/* When dealing with protocols other than mDNS only consider responses with
|
||||
* equivalent query section to the request. For mDNS this check doesn't make
|
||||
* sense, because the section 6 of RFC6762 states that "Multicast DNS responses MUST NOT
|
||||
* contain any questions in the Question Section". */
|
||||
if (t->scope->protocol != DNS_PROTOCOL_MDNS) {
|
||||
r = dns_packet_is_reply_for(p, t->key);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0) {
|
||||
dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Install the answer as answer to the transaction */
|
||||
dns_answer_unref(t->answer);
|
||||
t->answer = dns_answer_ref(p->answer);
|
||||
t->answer_rcode = DNS_PACKET_RCODE(p);
|
||||
t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
|
||||
t->answer_authenticated = false;
|
||||
|
||||
r = dns_transaction_fix_rcode(t);
|
||||
/* When dealing with protocols other than mDNS only consider responses with equivalent query section
|
||||
* to the request. For mDNS this check doesn't make sense, because the section 6 of RFC6762 states
|
||||
* that "Multicast DNS responses MUST NOT contain any questions in the Question Section". */
|
||||
if (t->scope->protocol != DNS_PROTOCOL_MDNS) {
|
||||
r = dns_packet_is_reply_for(p, t->key);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
/* Block GC while starting requests for additional DNSSEC RRs */
|
||||
t->block_gc++;
|
||||
r = dns_transaction_request_dnssec_keys(t);
|
||||
t->block_gc--;
|
||||
|
||||
/* Maybe the transaction is ready for GC'ing now? If so, free it and return. */
|
||||
if (!dns_transaction_gc(t))
|
||||
return;
|
||||
|
||||
/* Requesting additional keys might have resulted in
|
||||
* this transaction to fail, since the auxiliary
|
||||
* request failed for some reason. If so, we are not
|
||||
* in pending state anymore, and we should exit
|
||||
* quickly. */
|
||||
if (t->state != DNS_TRANSACTION_PENDING)
|
||||
return;
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r > 0) {
|
||||
/* There are DNSSEC transactions pending now. Update the state accordingly. */
|
||||
t->state = DNS_TRANSACTION_VALIDATING;
|
||||
dns_transaction_close_connection(t);
|
||||
dns_transaction_stop_timeout(t);
|
||||
if (r == 0) {
|
||||
dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Install the answer as answer to the transaction */
|
||||
dns_answer_unref(t->answer);
|
||||
t->answer = dns_answer_ref(p->answer);
|
||||
t->answer_rcode = DNS_PACKET_RCODE(p);
|
||||
t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
|
||||
t->answer_authenticated = false;
|
||||
|
||||
r = dns_transaction_fix_rcode(t);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
/* Block GC while starting requests for additional DNSSEC RRs */
|
||||
t->block_gc++;
|
||||
r = dns_transaction_request_dnssec_keys(t);
|
||||
t->block_gc--;
|
||||
|
||||
/* Maybe the transaction is ready for GC'ing now? If so, free it and return. */
|
||||
if (!dns_transaction_gc(t))
|
||||
return;
|
||||
|
||||
/* Requesting additional keys might have resulted in this transaction to fail, since the auxiliary
|
||||
* request failed for some reason. If so, we are not in pending state anymore, and we should exit
|
||||
* quickly. */
|
||||
if (t->state != DNS_TRANSACTION_PENDING)
|
||||
return;
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r > 0) {
|
||||
/* There are DNSSEC transactions pending now. Update the state accordingly. */
|
||||
t->state = DNS_TRANSACTION_VALIDATING;
|
||||
dns_transaction_close_connection(t);
|
||||
dns_transaction_stop_timeout(t);
|
||||
return;
|
||||
}
|
||||
|
||||
dns_transaction_process_dnssec(t);
|
||||
return;
|
||||
|
||||
|
|
|
@ -231,13 +231,15 @@ int dns_zone_put(DnsZone *z, DnsScope *s, DnsResourceRecord *rr, bool probe) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
i = new0(DnsZoneItem, 1);
|
||||
i = new(DnsZoneItem, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
i->scope = s;
|
||||
i->rr = dns_resource_record_ref(rr);
|
||||
i->probing_enabled = probe;
|
||||
*i = (DnsZoneItem) {
|
||||
.scope = s,
|
||||
.rr = dns_resource_record_ref(rr),
|
||||
.probing_enabled = probe,
|
||||
};
|
||||
|
||||
r = dns_zone_link_item(z, i);
|
||||
if (r < 0)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sd-bus.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "list.h"
|
||||
|
|
|
@ -80,11 +80,13 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
|
|||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
item = new0(EtcHostsItem, 1);
|
||||
item = new(EtcHostsItem, 1);
|
||||
if (!item)
|
||||
return log_oom();
|
||||
|
||||
item->address = address;
|
||||
*item = (EtcHostsItem) {
|
||||
.address = address,
|
||||
};
|
||||
|
||||
r = hashmap_put(hosts->by_address, &item->address, item);
|
||||
if (r < 0) {
|
||||
|
|
|
@ -818,14 +818,16 @@ int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr
|
|||
assert(l);
|
||||
assert(in_addr);
|
||||
|
||||
a = new0(LinkAddress, 1);
|
||||
a = new(LinkAddress, 1);
|
||||
if (!a)
|
||||
return -ENOMEM;
|
||||
|
||||
a->family = family;
|
||||
a->in_addr = *in_addr;
|
||||
*a = (LinkAddress) {
|
||||
.family = family,
|
||||
.in_addr = *in_addr,
|
||||
.link = l,
|
||||
};
|
||||
|
||||
a->link = l;
|
||||
LIST_PREPEND(addresses, l->addresses, a);
|
||||
l->n_addresses++;
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/vfs.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/dm-ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: LGPL-2+ */
|
||||
/*
|
||||
* initreq.h Interface to talk to init through /dev/initctl.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#ifndef __LINUX_NL80211_H
|
||||
#define __LINUX_NL80211_H
|
||||
/*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <security/pam_ext.h>
|
||||
#include <syslog.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "qrcode-util.h"
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
|
|
|
@ -126,6 +126,7 @@ int sd_dhcp_client_set_ifindex(
|
|||
int sd_dhcp_client_set_mac(
|
||||
sd_dhcp_client *client,
|
||||
const uint8_t *addr,
|
||||
const uint8_t *bcast_addr,
|
||||
size_t addr_len,
|
||||
uint16_t arp_type);
|
||||
int sd_dhcp_client_set_client_id(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "sd-hwdb.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
/*
|
||||
* systemd service to wait until kernel realtime clock is synchronized
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
/* systemd service to wait until kernel realtime clock is synchronized */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
|
Loading…
Reference in New Issue