[systemd-commits] 3 commits - src/libsystemd-network src/network
Tom Gundersen
tomegun at kemper.freedesktop.org
Tue Mar 11 04:08:06 PDT 2014
src/libsystemd-network/dhcp-internal.h | 4 ++-
src/libsystemd-network/dhcp-packet.c | 12 ++++++-----
src/libsystemd-network/sd-dhcp-client.c | 33 +++++++++++++++++++-------------
src/network/networkd.c | 20 +++++++++----------
4 files changed, 40 insertions(+), 29 deletions(-)
New commits:
commit 93570bd7ed31aad336c1a0a88ba08159c9c8e4cc
Author: Tom Gundersen <teg at jklm.no>
Date: Tue Mar 11 10:57:00 2014 +0100
sd-dhcp-client: use close_nointr_nofail()
We are already assuming the close() will not fail, so make it explicit.
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index e0fce5b..f4a83fb 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -185,7 +185,7 @@ static int client_stop(sd_dhcp_client *client, int error) {
sd_event_source_unref(client->receive_message);
if (client->fd >= 0)
- close(client->fd);
+ close_nointr_nofail(client->fd);
client->fd = -1;
client->timeout_resend = sd_event_source_unref(client->timeout_resend);
@@ -546,7 +546,7 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
if (client->fd >= 0) {
client->receive_message =
sd_event_source_unref(client->receive_message);
- close(client->fd);
+ close_nointr_nofail(client->fd);
client->fd = -1;
}
@@ -848,7 +848,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
client->receive_message =
sd_event_source_unref(client->receive_message);
- close(client->fd);
+ close_nointr_nofail(client->fd);
client->fd = -1;
}
commit f0c4cd7a2c2835a392b5b1807d8c506ab0af44de
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Mar 10 23:40:34 2014 +0100
networkd: rework startup
Open all listenerns before loading configuration.
diff --git a/src/network/networkd.c b/src/network/networkd.c
index a80740b..2f6a12d 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -51,33 +51,33 @@ int main(int argc, char *argv[]) {
goto out;
}
- r = manager_load_config(m);
+ r = manager_udev_listen(m);
if (r < 0) {
- log_error("Could not load configuration files: %s", strerror(-r));
+ log_error("Could not connect to udev: %s", strerror(-r));
goto out;
}
- r = manager_udev_listen(m);
+ r = manager_rtnl_listen(m);
if (r < 0) {
- log_error("Could not connect to udev: %s", strerror(-r));
+ log_error("Could not connect to rtnl: %s", strerror(-r));
goto out;
}
- r = manager_udev_enumerate_links(m);
+ r = manager_bus_listen(m);
if (r < 0) {
- log_error("Could not enumerate links: %s", strerror(-r));
+ log_error("Could not connect to system bus: %s", strerror(-r));
goto out;
}
- r = manager_rtnl_listen(m);
+ r = manager_load_config(m);
if (r < 0) {
- log_error("Could not connect to rtnl: %s", strerror(-r));
+ log_error("Could not load configuration files: %s", strerror(-r));
goto out;
}
- r = manager_bus_listen(m);
+ r = manager_udev_enumerate_links(m);
if (r < 0) {
- log_error("Could not connect to system bus: %s", strerror(-r));
+ log_error("Could not enumerate links: %s", strerror(-r));
goto out;
}
commit 63edaa623bee43c934a0c357e8c6498992429391
Author: Tom Gundersen <teg at jklm.no>
Date: Sun Mar 9 22:51:07 2014 +0100
sd-dhcp: generalise ip header generation
This will be needed for sd-dhcp-server.
diff --git a/src/libsystemd-network/dhcp-internal.h b/src/libsystemd-network/dhcp-internal.h
index ce83b81..3c3e1f6 100644
--- a/src/libsystemd-network/dhcp-internal.h
+++ b/src/libsystemd-network/dhcp-internal.h
@@ -48,7 +48,9 @@ int dhcp_option_parse(DHCPMessage *message, size_t len,
int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, uint8_t type,
uint8_t **opt, size_t *optlen);
-void dhcp_packet_append_ip_headers(DHCPPacket *packet, uint16_t len);
+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);
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index 95c4277..418a977 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -92,17 +92,19 @@ static uint16_t dhcp_checksum(void *buf, int len) {
return ~sum;
}
-void dhcp_packet_append_ip_headers(DHCPPacket *packet, uint16_t len) {
+void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
+ uint16_t source_port, be32_t destination_addr,
+ uint16_t destination_port, uint16_t len) {
packet->ip.version = IPVERSION;
packet->ip.ihl = DHCP_IP_SIZE / 4;
packet->ip.tot_len = htobe16(len);
packet->ip.protocol = IPPROTO_UDP;
- packet->ip.saddr = INADDR_ANY;
- packet->ip.daddr = INADDR_BROADCAST;
+ packet->ip.saddr = source_addr;
+ packet->ip.daddr = destination_addr;
- packet->udp.source = htobe16(DHCP_PORT_CLIENT);
- packet->udp.dest = htobe16(DHCP_PORT_SERVER);
+ packet->udp.source = htobe16(source_port);
+ packet->udp.dest = htobe16(destination_port);
packet->udp.len = htobe16(len - DHCP_IP_SIZE);
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 07b27d5..e0fce5b 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -264,6 +264,15 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message,
return 0;
}
+static int dhcp_client_send_raw(sd_dhcp_client *client, DHCPPacket *packet,
+ size_t len) {
+ dhcp_packet_append_ip_headers(packet, INADDR_ANY, DHCP_PORT_CLIENT,
+ INADDR_BROADCAST, DHCP_PORT_SERVER, len);
+
+ return dhcp_network_send_raw_socket(client->fd, &client->link,
+ packet, len);
+}
+
static int client_send_discover(sd_dhcp_client *client, uint16_t secs) {
int err = 0;
_cleanup_free_ DHCPPacket *discover;
@@ -295,14 +304,13 @@ static int client_send_discover(sd_dhcp_client *client, uint16_t secs) {
if (err < 0)
return err;
- dhcp_packet_append_ip_headers(discover, len);
-
- err = dhcp_network_send_raw_socket(client->fd, &client->link,
- discover, len);
+ err = dhcp_client_send_raw(client, discover, len);
+ if (err < 0)
+ return err;
log_dhcp_client(client, "DISCOVER");
- return err;
+ return 0;
}
static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
@@ -348,15 +356,14 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
&request->dhcp,
len - DHCP_IP_UDP_SIZE);
} else {
- dhcp_packet_append_ip_headers(request, len);
-
- err = dhcp_network_send_raw_socket(client->fd, &client->link,
- request, len);
+ err = dhcp_client_send_raw(client, request, len);
}
+ if (err < 0)
+ return err;
log_dhcp_client(client, "REQUEST");
- return err;
+ return 0;
}
static uint16_t client_update_secs(sd_dhcp_client *client, usec_t time_now)
More information about the systemd-commits
mailing list