[systemd-commits] 6 commits - src/core src/libsystemd src/libsystemd-dhcp src/network src/nspawn src/systemd TODO
Tom Gundersen
tomegun at kemper.freedesktop.org
Sat Feb 15 12:16:41 CET 2014
TODO | 1
src/core/loopback-setup.c | 1
src/libsystemd-dhcp/dhcp-internal.h | 4
src/libsystemd-dhcp/dhcp-network.c | 12 -
src/libsystemd-dhcp/dhcp-protocol.h | 1
src/libsystemd-dhcp/sd-dhcp-client.c | 208 ++++++++++++++++++---------------
src/libsystemd-dhcp/test-dhcp-client.c | 4
src/libsystemd/sd-rtnl/rtnl-message.c | 21 +--
src/libsystemd/sd-rtnl/rtnl-util.c | 1
src/libsystemd/sd-rtnl/test-rtnl.c | 9 -
src/network/networkd-netdev.c | 4
src/network/networkd.h | 1
src/nspawn/nspawn.c | 7 -
src/systemd/sd-rtnl.h | 10 -
14 files changed, 151 insertions(+), 133 deletions(-)
New commits:
commit 080ab27621e979e75f6bb1a055616f3d419f7ac3
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Feb 14 17:23:58 2014 +0100
sd-dhcp: network - don't hardcode ports
We want to reuse these functions for the server library too.
diff --git a/src/libsystemd-dhcp/dhcp-internal.h b/src/libsystemd-dhcp/dhcp-internal.h
index 3f1e000..7639069 100644
--- a/src/libsystemd-dhcp/dhcp-internal.h
+++ b/src/libsystemd-dhcp/dhcp-internal.h
@@ -30,10 +30,10 @@
#include "dhcp-protocol.h"
int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link);
-int dhcp_network_bind_udp_socket(int index, be32_t client_address);
+int dhcp_network_bind_udp_socket(int index, 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);
-int dhcp_network_send_udp_socket(int s, be32_t server_address,
+int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
const void *packet, size_t len);
int dhcp_option_append(uint8_t **buf, size_t *buflen, uint8_t code,
diff --git a/src/libsystemd-dhcp/dhcp-network.c b/src/libsystemd-dhcp/dhcp-network.c
index b2de67e..6c9d4ef 100644
--- a/src/libsystemd-dhcp/dhcp-network.c
+++ b/src/libsystemd-dhcp/dhcp-network.c
@@ -56,13 +56,13 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
return s;
}
-int dhcp_network_bind_udp_socket(int index, be32_t client_address)
+int dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port)
{
int s;
union sockaddr_union src = {
.in.sin_family = AF_INET,
- .in.sin_port = htobe16(DHCP_PORT_CLIENT),
- .in.sin_addr.s_addr = client_address,
+ .in.sin_port = htobe16(port),
+ .in.sin_addr.s_addr = address,
};
s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
@@ -90,13 +90,13 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
return 0;
}
-int dhcp_network_send_udp_socket(int s, be32_t server_address,
+int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
const void *packet, size_t len)
{
union sockaddr_union dest = {
.in.sin_family = AF_INET,
- .in.sin_port = htobe16(DHCP_PORT_SERVER),
- .in.sin_addr.s_addr = server_address,
+ .in.sin_port = htobe16(port),
+ .in.sin_addr.s_addr = address,
};
if (sendto(s, packet, len, 0, &dest.sa, sizeof(dest.in)) < 0)
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index bff3588..83d56a2 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -324,6 +324,7 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
if (client->state == DHCP_STATE_RENEWING) {
err = dhcp_network_send_udp_socket(client->fd,
client->lease->server_address,
+ DHCP_PORT_SERVER,
&request->dhcp,
len - DHCP_IP_UDP_SIZE);
} else {
@@ -535,7 +536,8 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
client->attempt = 1;
r = dhcp_network_bind_udp_socket(client->index,
- client->lease->address);
+ client->lease->address,
+ DHCP_PORT_CLIENT);
if (r < 0) {
client_stop(client, r);
return 0;
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c
index 56a10b3..f341b3c 100644
--- a/src/libsystemd-dhcp/test-dhcp-client.c
+++ b/src/libsystemd-dhcp/test-dhcp-client.c
@@ -191,12 +191,12 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
return test_fd[0];
}
-int dhcp_network_bind_udp_socket(int index, be32_t client_address)
+int dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port)
{
return 0;
}
-int dhcp_network_send_udp_socket(int s, be32_t server_address,
+int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
const void *packet, size_t len)
{
return 0;
commit 818dc5e72af8a3eb772997188e2bd8ea616de844
Author: Tom Gundersen <teg at jklm.no>
Date: Sat Feb 15 00:06:09 2014 +0100
sd-rtnl: always include linux/rtnetlink.h
diff --git a/src/core/loopback-setup.c b/src/core/loopback-setup.c
index a53855f..8a5b812 100644
--- a/src/core/loopback-setup.c
+++ b/src/core/loopback-setup.c
@@ -24,7 +24,6 @@
#include <net/if.h>
#include <asm/types.h>
#include <netinet/in.h>
-#include <linux/rtnetlink.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index 096a322..15e3247 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -19,7 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <linux/rtnetlink.h>
#include <netinet/in.h>
#include <netinet/ether.h>
#include <stdbool.h>
@@ -232,6 +231,8 @@ int sd_rtnl_message_new_addr(uint16_t nlmsg_type, int index, unsigned char famil
(*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
(*ret)->hdr->nlmsg_type = nlmsg_type;
+ if (nlmsg_type == RTM_GETADDR && family == AF_INET)
+ (*ret)->hdr->nlmsg_flags |= NLM_F_DUMP;
ifa = NLMSG_DATA((*ret)->hdr);
diff --git a/src/libsystemd/sd-rtnl/rtnl-util.c b/src/libsystemd/sd-rtnl/rtnl-util.c
index caa21d6..6545ad0 100644
--- a/src/libsystemd/sd-rtnl/rtnl-util.c
+++ b/src/libsystemd/sd-rtnl/rtnl-util.c
@@ -19,7 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <linux/rtnetlink.h>
#include <netinet/ether.h>
#include "sd-rtnl.h"
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index 53efed5..21e12f6 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -19,7 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <linux/rtnetlink.h>
#include <netinet/ether.h>
#include "util.h"
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 726cd83..51d7757 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -22,7 +22,6 @@
#pragma once
#include <arpa/inet.h>
-#include <linux/rtnetlink.h>
#include "sd-event.h"
#include "sd-rtnl.h"
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index fcc0f17..a81bb8e 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -40,7 +40,6 @@
#include <sys/un.h>
#include <sys/socket.h>
#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
#include <sys/eventfd.h>
#include <net/if.h>
#include <linux/veth.h>
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index 5506bfa..321f42a 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -25,6 +25,7 @@
#include <inttypes.h>
#include <netinet/in.h>
#include <netinet/ether.h>
+#include <linux/rtnetlink.h>
#include "sd-event.h"
#include "_sd-common.h"
@@ -71,12 +72,7 @@ int sd_rtnl_message_new_addr(uint16_t msg_type, int index, unsigned char family,
sd_rtnl_message **ret);
int sd_rtnl_message_new_route(uint16_t nlmsg_type, unsigned char rtm_family,
sd_rtnl_message **ret);
-/*
- unsigned char rtm_dst_len, unsigned char rtm_src_len,
- unsigned char rtm_tos, unsigned char rtm_table,
- unsigned char rtm_scope, unsigned char rtm_protocol,
- unsigned char rtm_type, unsigned flags, sd_rtnl_message **ret);
-*/
+
sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
commit 0bfedf143c72005cb540ddcaf9a8630844e381f8
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Feb 14 11:58:41 2014 +0100
sd-dhcp: minimum options size is part of the protocol
diff --git a/src/libsystemd-dhcp/dhcp-protocol.h b/src/libsystemd-dhcp/dhcp-protocol.h
index abdfe8d..81d36ce 100644
--- a/src/libsystemd-dhcp/dhcp-protocol.h
+++ b/src/libsystemd-dhcp/dhcp-protocol.h
@@ -58,6 +58,7 @@ typedef struct DHCPPacket DHCPPacket;
#define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
#define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
#define DHCP_MESSAGE_SIZE (int32_t)(sizeof(DHCPMessage))
+#define DHCP_MIN_OPTIONS_SIZE 312
enum {
DHCP_PORT_SERVER = 67,
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 39c2eeb..bff3588 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -32,8 +32,6 @@
#include "dhcp-internal.h"
#include "sd-dhcp-client.h"
-#define DHCP_CLIENT_MIN_OPTIONS_SIZE 312
-
struct sd_dhcp_client {
DHCPState state;
sd_event *event;
@@ -237,7 +235,7 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message,
defined default size unless the Maximum Messge Size option
is explicitely set */
max_size = htobe16(DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE +
- DHCP_CLIENT_MIN_OPTIONS_SIZE);
+ DHCP_MIN_OPTIONS_SIZE);
r = dhcp_option_append(opt, optlen,
DHCP_OPTION_MAXIMUM_MESSAGE_SIZE,
2, &max_size);
@@ -254,7 +252,7 @@ static int client_send_discover(sd_dhcp_client *client, uint16_t secs) {
size_t optlen, len;
uint8_t *opt;
- optlen = DHCP_CLIENT_MIN_OPTIONS_SIZE;
+ optlen = DHCP_MIN_OPTIONS_SIZE;
len = sizeof(DHCPPacket) + optlen;
discover = malloc0(len);
@@ -293,7 +291,7 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
int err;
uint8_t *opt;
- optlen = DHCP_CLIENT_MIN_OPTIONS_SIZE;
+ optlen = DHCP_MIN_OPTIONS_SIZE;
len = DHCP_MESSAGE_SIZE + optlen;
request = malloc0(len);
@@ -801,7 +799,7 @@ error:
static int client_receive_message_raw(sd_event_source *s, int fd,
uint32_t revents, void *userdata) {
sd_dhcp_client *client = userdata;
- uint8_t buf[sizeof(DHCPMessage) + DHCP_CLIENT_MIN_OPTIONS_SIZE];
+ uint8_t buf[sizeof(DHCPMessage) + DHCP_MIN_OPTIONS_SIZE];
int buflen = sizeof(buf);
int len, r = 0;
usec_t time_now;
@@ -825,7 +823,7 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
static int client_receive_message_udp(sd_event_source *s, int fd,
uint32_t revents, void *userdata) {
sd_dhcp_client *client = userdata;
- uint8_t buf[sizeof(DHCPPacket) + DHCP_CLIENT_MIN_OPTIONS_SIZE];
+ uint8_t buf[sizeof(DHCPPacket) + DHCP_MIN_OPTIONS_SIZE];
int buflen = sizeof(buf);
int len, r = 0;
DHCPPacket *packet;
commit e5002702716b047c3d5515aaeecc5b829db02aa4
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Feb 13 20:56:16 2014 +0100
sd-dhcp-client: explicitly handle raw and udp messages
Split the recevie_message callback into _raw and _udp parts and a generic
DHCPMessage handler.
Also always verify the xid/MAC, rather than only for udp messages.
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 3b4db1d..39c2eeb 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -70,8 +70,10 @@ static const uint8_t default_req_opts[] = {
DHCP_OPTION_NTP_SERVER,
};
-static int client_receive_message(sd_event_source *s, int fd,
- uint32_t revents, void *userdata);
+static int client_receive_message_raw(sd_event_source *s, int fd,
+ uint32_t revents, void *userdata);
+static int client_receive_message_udp(sd_event_source *s, int fd,
+ uint32_t revents, void *userdata);
int sd_dhcp_client_set_callback(sd_dhcp_client *client, sd_dhcp_client_cb_t cb,
void *userdata) {
@@ -357,7 +359,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
switch (client->state) {
case DHCP_STATE_RENEWING:
- time_left = (client->lease->t2 - client->lease->t1)/2;
+ time_left = (client->lease->t2 - client->lease->t1) / 2;
if (time_left < 60)
time_left = 60;
@@ -367,7 +369,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
case DHCP_STATE_REBINDING:
- time_left = (client->lease->lifetime - client->lease->t2)/2;
+ time_left = (client->lease->lifetime - client->lease->t2) / 2;
if (time_left < 60)
time_left = 60;
@@ -398,7 +400,8 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
if (r < 0)
goto error;
- r = sd_event_source_set_priority(client->timeout_resend, client->event_priority);
+ r = sd_event_source_set_priority(client->timeout_resend,
+ client->event_priority);
if (r < 0)
goto error;
@@ -455,19 +458,21 @@ error:
return 0;
}
-static int client_initialize_events(sd_dhcp_client *client, usec_t usec) {
+static int client_initialize_events(sd_dhcp_client *client,
+ sd_event_io_handler_t io_callback,
+ usec_t usec) {
int r;
assert(client);
assert(client->event);
- r = sd_event_add_io(client->event, client->fd, EPOLLIN,
- client_receive_message, client,
- &client->receive_message);
+ r = sd_event_add_io(client->event, client->fd, EPOLLIN, io_callback,
+ client, &client->receive_message);
if (r < 0)
goto error;
- r = sd_event_source_set_priority(client->receive_message, client->event_priority);
+ r = sd_event_source_set_priority(client->receive_message,
+ client->event_priority);
if (r < 0)
goto error;
@@ -477,7 +482,8 @@ static int client_initialize_events(sd_dhcp_client *client, usec_t usec) {
if (r < 0)
goto error;
- r = sd_event_source_set_priority(client->timeout_resend, client->event_priority);
+ r = sd_event_source_set_priority(client->timeout_resend,
+ client->event_priority);
error:
if (r < 0)
@@ -518,10 +524,12 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
client->fd = r;
- return client_initialize_events(client, usec);
+ return client_initialize_events(client, client_receive_message_raw,
+ usec);
}
-static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata) {
+static int client_timeout_t1(sd_event_source *s, uint64_t usec,
+ void *userdata) {
sd_dhcp_client *client = userdata;
int r;
@@ -537,47 +545,23 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata)
client->fd = r;
- return client_initialize_events(client, usec);
+ return client_initialize_events(client, client_receive_message_udp, usec);
}
-static int client_verify_headers(sd_dhcp_client *client, DHCPPacket *message,
- size_t len) {
- int r;
-
- r = dhcp_packet_verify_headers(message, BOOTREPLY, len);
- if (r < 0)
- return r;
-
- if (be32toh(message->dhcp.xid) != client->xid)
- return -EINVAL;
-
- if (memcmp(&message->dhcp.chaddr[0], &client->mac_addr.ether_addr_octet,
- ETHER_ADDR_LEN))
- return -EINVAL;
-
- return 0;
-}
-
-static int client_receive_offer(sd_dhcp_client *client, DHCPPacket *offer,
- size_t len) {
+static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
+ size_t len) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
int r;
- r = client_verify_headers(client, offer, len);
- if (r < 0)
- return r;
-
r = dhcp_lease_new(&lease);
if (r < 0)
return r;
- len = len - DHCP_IP_UDP_SIZE;
- r = dhcp_option_parse(&offer->dhcp, len, dhcp_lease_parse_options,
- lease);
+ r = dhcp_option_parse(offer, len, dhcp_lease_parse_options, lease);
if (r != DHCP_OFFER)
return -ENOMSG;
- lease->address = offer->dhcp.yiaddr;
+ lease->address = offer->yiaddr;
if (lease->address == INADDR_ANY ||
lease->server_address == INADDR_ANY ||
@@ -591,38 +575,23 @@ static int client_receive_offer(sd_dhcp_client *client, DHCPPacket *offer,
return 0;
}
-static int client_receive_ack(sd_dhcp_client *client, const uint8_t *buf,
- size_t len) {
- DHCPPacket *ack;
- DHCPMessage *dhcp;
+static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
+ size_t len) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
int r;
- if (client->state == DHCP_STATE_RENEWING) {
- dhcp = (DHCPMessage *)buf;
- } else {
- ack = (DHCPPacket *)buf;
-
- r = client_verify_headers(client, ack, len);
- if (r < 0)
- return r;
-
- dhcp = &ack->dhcp;
- len -= DHCP_IP_UDP_SIZE;
- }
-
r = dhcp_lease_new(&lease);
if (r < 0)
return r;
- r = dhcp_option_parse(dhcp, len, dhcp_lease_parse_options, lease);
+ r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease);
if (r == DHCP_NAK)
return DHCP_EVENT_NO_LEASE;
if (r != DHCP_ACK)
return -ENOMSG;
- lease->address = dhcp->yiaddr;
+ lease->address = ack->yiaddr;
if (lease->address == INADDR_ANY ||
lease->server_address == INADDR_ANY ||
@@ -681,7 +650,8 @@ static int client_set_lease_timeouts(sd_dhcp_client *client, uint64_t usec) {
if (r < 0)
return r;
- r = sd_event_source_set_priority(client->timeout_t1, client->event_priority);
+ r = sd_event_source_set_priority(client->timeout_t1,
+ client->event_priority);
if (r < 0)
return r;
@@ -706,7 +676,8 @@ static int client_set_lease_timeouts(sd_dhcp_client *client, uint64_t usec) {
if (r < 0)
return r;
- r = sd_event_source_set_priority(client->timeout_t2, client->event_priority);
+ r = sd_event_source_set_priority(client->timeout_t2,
+ client->event_priority);
if (r < 0)
return r;
@@ -722,40 +693,34 @@ static int client_set_lease_timeouts(sd_dhcp_client *client, uint64_t usec) {
if (r < 0)
return r;
- r = sd_event_source_set_priority(client->timeout_expire, client->event_priority);
+ r = sd_event_source_set_priority(client->timeout_expire,
+ client->event_priority);
if (r < 0)
return r;
return 0;
}
-static int client_receive_message(sd_event_source *s, int fd,
- uint32_t revents, void *userdata) {
- sd_dhcp_client *client = userdata;
- uint8_t buf[sizeof(DHCPPacket) + DHCP_CLIENT_MIN_OPTIONS_SIZE];
- int buflen = sizeof(buf);
- int len, r = 0, notify_event = 0;
- DHCPPacket *message;
- usec_t time_now;
+static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
+ int len, usec_t time_now) {
+ int r = 0, notify_event = 0;
- assert(s);
assert(client);
assert(client->event);
+ assert(message);
- len = read(fd, &buf, buflen);
- if (len < 0)
- return 0;
+ if (be32toh(message->xid) != client->xid)
+ return -EINVAL;
- r = sd_event_get_now_monotonic(client->event, &time_now);
- if (r < 0)
- goto error;
+ if (memcmp(&message->chaddr[0], &client->mac_addr.ether_addr_octet,
+ ETHER_ADDR_LEN))
+ return -EINVAL;
switch (client->state) {
case DHCP_STATE_SELECTING:
- message = (DHCPPacket *)&buf;
-
- if (client_receive_offer(client, message, len) >= 0) {
+ r = client_handle_offer(client, message, len);
+ if (r >= 0) {
client->timeout_resend =
sd_event_source_unref(client->timeout_resend);
@@ -770,7 +735,8 @@ static int client_receive_message(sd_event_source *s, int fd,
if (r < 0)
goto error;
- r = sd_event_source_set_priority(client->timeout_resend, client->event_priority);
+ r = sd_event_source_set_priority(client->timeout_resend,
+ client->event_priority);
if (r < 0)
goto error;
}
@@ -781,7 +747,7 @@ static int client_receive_message(sd_event_source *s, int fd,
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
- r = client_receive_ack(client, buf, len);
+ r = client_handle_ack(client, message, len);
if (r == DHCP_EVENT_NO_LEASE)
goto error;
@@ -832,6 +798,62 @@ error:
return 0;
}
+static int client_receive_message_raw(sd_event_source *s, int fd,
+ uint32_t revents, void *userdata) {
+ sd_dhcp_client *client = userdata;
+ uint8_t buf[sizeof(DHCPMessage) + DHCP_CLIENT_MIN_OPTIONS_SIZE];
+ int buflen = sizeof(buf);
+ int len, r = 0;
+ usec_t time_now;
+
+ assert(s);
+ assert(client);
+ assert(client->event);
+
+ len = read(fd, &buf, buflen);
+ if (len < 0)
+ return 0;
+
+ r = sd_event_get_now_monotonic(client->event, &time_now);
+ if (r < 0)
+ return client_stop(client, r);
+
+ return client_handle_message(client, (DHCPMessage *) buf, len,
+ time_now);
+}
+
+static int client_receive_message_udp(sd_event_source *s, int fd,
+ uint32_t revents, void *userdata) {
+ sd_dhcp_client *client = userdata;
+ uint8_t buf[sizeof(DHCPPacket) + DHCP_CLIENT_MIN_OPTIONS_SIZE];
+ int buflen = sizeof(buf);
+ int len, r = 0;
+ DHCPPacket *packet;
+ usec_t time_now;
+
+ assert(s);
+ assert(client);
+ assert(client->event);
+
+ len = read(fd, &buf, buflen);
+ if (len < 0)
+ return 0;
+
+ packet = (DHCPPacket *) buf;
+
+ r = dhcp_packet_verify_headers(packet, BOOTREPLY, len);
+ if (r < 0)
+ return r;
+
+ len -= DHCP_IP_UDP_SIZE;
+
+ r = sd_event_get_now_monotonic(client->event, &time_now);
+ if (r < 0)
+ return client_stop(client, r);
+
+ return client_handle_message(client, &packet->dhcp, len, time_now);
+}
+
int sd_dhcp_client_start(sd_dhcp_client *client) {
int r;
@@ -854,14 +876,16 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
client->start_time = now(CLOCK_MONOTONIC);
client->secs = 0;
- return client_initialize_events(client, client->start_time);
+ return client_initialize_events(client, client_receive_message_udp,
+ client->start_time);
}
int sd_dhcp_client_stop(sd_dhcp_client *client) {
return client_stop(client, DHCP_EVENT_STOP);
}
-int sd_dhcp_client_attach_event(sd_dhcp_client *client, sd_event *event, int priority) {
+int sd_dhcp_client_attach_event(sd_dhcp_client *client, sd_event *event,
+ int priority) {
int r;
assert_return(client, -EINVAL);
commit ee3a6a51e5b098aa0c9641ed71d275c459ad2f5a
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Feb 14 22:39:48 2014 +0100
sd-rtnl: message_open_container - don't take a 'size' argument
We can always know the size based on the type, so let's do this inside the library.
diff --git a/TODO b/TODO
index db2c623..299f450 100644
--- a/TODO
+++ b/TODO
@@ -648,7 +648,6 @@ Features:
* networkd:
- add more keys to [Route] and [Address] sections
- add support for more DHCPv4 options (and, longer term, other kinds of dynamic config)
- - allow opting out of receiving DNS servers over DHCPv4
- add proper initrd support (in particular generate .network/.link files based on /proc/cmdline)
External:
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index 226329f..096a322 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -699,7 +699,7 @@ int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, c
return 0;
}
-int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type, size_t extra) {
+int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
uint16_t rtm_type;
assert_return(m, -EINVAL);
@@ -710,9 +710,13 @@ int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type, size
if (rtnl_message_type_is_link(rtm_type)) {
if ((type == IFLA_LINKINFO && m->n_containers == 0) ||
- (type == IFLA_INFO_DATA && m->n_containers == 1 && GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO) ||
- (type == VETH_INFO_PEER && m->n_containers == 2 && GET_CONTAINER(m, 1)->rta_type == IFLA_INFO_DATA))
- return add_rtattr(m, type, NULL, extra);
+ (type == IFLA_INFO_DATA && m->n_containers == 1 &&
+ GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO))
+ return add_rtattr(m, type, NULL, 0);
+ else if (type == VETH_INFO_PEER && m->n_containers == 2 &&
+ GET_CONTAINER(m, 1)->rta_type == IFLA_INFO_DATA &&
+ GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO)
+ return add_rtattr(m, type, NULL, sizeof(struct ifinfomsg));
}
return -ENOTSUP;
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index 9de3806..53efed5 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -287,11 +287,11 @@ static void test_container(void) {
assert(sd_rtnl_message_new_link(RTM_NEWLINK, 0, &m) >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO, 0) >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO, 0) == -ENOTSUP);
+ assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
+ assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA, 0) >= 0);
- assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA, 0) == -ENOTSUP);
+ assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
+ assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
assert(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
assert(sd_rtnl_message_close_container(m) >= 0);
assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index a452e0d..30eb77d 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -194,7 +194,7 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
return r;
}
- r = sd_rtnl_message_open_container(req, IFLA_LINKINFO, 0);
+ r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
if (r < 0) {
log_error_netdev(netdev,
"Could not open IFLA_LINKINFO container: %s",
@@ -217,7 +217,7 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
}
if (netdev->vlanid <= VLANID_MAX) {
- r = sd_rtnl_message_open_container(req, IFLA_INFO_DATA, 0);
+ r = sd_rtnl_message_open_container(req, IFLA_INFO_DATA);
if (r < 0) {
log_error_netdev(netdev,
"Could not open IFLA_INFO_DATA container: %s",
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 51a1a66..fcc0f17 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1303,7 +1303,7 @@ static int setup_veth(int netns_fd) {
return r;
}
- r = sd_rtnl_message_open_container(m, IFLA_LINKINFO, 0);
+ r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
if (r < 0) {
log_error("Failed to open netlink container: %s", strerror(-r));
return r;
@@ -1315,13 +1315,13 @@ static int setup_veth(int netns_fd) {
return r;
}
- r = sd_rtnl_message_open_container(m, IFLA_INFO_DATA, 0);
+ r = sd_rtnl_message_open_container(m, IFLA_INFO_DATA);
if (r < 0) {
log_error("Failed to open netlink container: %s", strerror(-r));
return r;
}
- r = sd_rtnl_message_open_container(m, VETH_INFO_PEER, sizeof(struct ifinfomsg));
+ r = sd_rtnl_message_open_container(m, VETH_INFO_PEER);
if (r < 0) {
log_error("z Failed to open netlink container: %s", strerror(-r));
return r;
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index 93edbcb..5506bfa 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -102,7 +102,7 @@ int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, cons
int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, const struct in6_addr *data);
int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, const struct ether_addr *data);
-int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type, size_t extra);
+int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type);
int sd_rtnl_message_close_container(sd_rtnl_message *m);
int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data);
commit a7b74db6e72f4f19f74eabc81c1ebb4cb8670f06
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Feb 14 12:15:26 2014 +0100
sd-rtnl: link flags - don't allow change = 0
The kernel will happily treat 0x0 as 0xffffffff, but it is for backwards
compatibility only, so let's not perpetuate this.
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index c780f71..226329f 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -119,14 +119,12 @@ int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned
assert_return(m, -EINVAL);
assert_return(m->hdr, -EINVAL);
assert_return(rtnl_message_type_is_link(m->hdr->nlmsg_type), -EINVAL);
+ assert_return(change, -EINVAL);
ifi = NLMSG_DATA(m->hdr);
ifi->ifi_flags = flags;
- if (change)
- ifi->ifi_change = change;
- else
- ifi->ifi_change = 0xffffffff;
+ ifi->ifi_change = change;
return 0;
}
More information about the systemd-commits
mailing list