[systemd-devel] [PATCH 08/17] sd-dhcp-server: add support for setting the server address
Tom Gundersen
teg at jklm.no
Tue May 27 08:33:34 PDT 2014
On Tue, May 27, 2014 at 5:29 PM, Zbigniew Jędrzejewski-Szmek
<zbyszek at in.waw.pl> wrote:
> On Mon, May 26, 2014 at 09:39:37PM +0200, Tom Gundersen wrote:
>> ---
>> src/libsystemd-network/dhcp-server-internal.h | 1 +
>> src/libsystemd-network/sd-dhcp-server.c | 13 +++++++++++++
>> src/libsystemd-network/test-dhcp-server.c | 17 +++++++++++++++++
>> src/systemd/sd-dhcp-server.h | 1 +
>> 4 files changed, 32 insertions(+)
>>
>> diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h
>> index 6c2f2b4..58a9877 100644
>> --- a/src/libsystemd-network/dhcp-server-internal.h
>> +++ b/src/libsystemd-network/dhcp-server-internal.h
>> @@ -39,6 +39,7 @@ struct sd_dhcp_server {
>> int fd_raw;
>>
>> int index;
>> + be32_t address;
>> };
>>
>> typedef struct DHCPClientId {
>> diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
>> index ecdc15d..7d6170c 100644
>> --- a/src/libsystemd-network/sd-dhcp-server.c
>> +++ b/src/libsystemd-network/sd-dhcp-server.c
>> @@ -27,6 +27,17 @@
>> #include "dhcp-server-internal.h"
>> #include "dhcp-internal.h"
>>
>> +int sd_dhcp_server_set_address(sd_dhcp_server *server, struct in_addr *address) {
>> + assert_return(server, -EINVAL);
>> + assert_return(address, -EINVAL);
>> + assert_return(address->s_addr, -EINVAL);
>> + assert_return(server->address == htobe32(INADDR_ANY), -EBUSY);
>> +
>> + server->address = address->s_addr;
>> +
>> + return 0;
>> +}
>> +
>> sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server) {
>> if (server)
>> assert_se(REFCNT_INC(server->n_ref) >= 2);
>> @@ -60,6 +71,7 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
>> server->n_ref = REFCNT_INIT;
>> server->fd_raw = -1;
>> server->fd = -1;
>> + server->address = htobe32(INADDR_ANY);
>> server->index = ifindex;
>>
>> *ret = server;
>> @@ -281,6 +293,7 @@ int sd_dhcp_server_start(sd_dhcp_server *server) {
>> assert_return(!server->receive_message, -EBUSY);
>> assert_return(server->fd_raw == -1, -EBUSY);
>> assert_return(server->fd == -1, -EBUSY);
>> + assert_return(server->address != htobe32(INADDR_ANY), -EBUSY);
>
> EBUSY seems rather confusing here, since actually the opposite is
> true, for this newly added check as well for the preexisting ones:
> the structure has not been initialized to be usable yet. Maybe a
> different error code like EUNATCH or EBADRQC, ENODATA, EDESTADDRREQ or
> EUCLEAN ?
Ah, that's a fair point. I expect this issue to appear throughout the
patches, I'll fix them all up.
Cheers,
Tom
More information about the systemd-devel
mailing list