2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-02-28 16:10:20 +01:00
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright (C) 2014 Axis Communications AB. All rights reserved.
|
2015-08-20 11:26:57 +02:00
|
|
|
Copyright (C) 2015 Tom Gundersen
|
2014-02-28 16:10:20 +01:00
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <arpa/inet.h>
|
2014-02-28 16:10:20 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-01-11 00:39:12 +01:00
|
|
|
#include "sd-id128.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "sd-ipv4acd.h"
|
|
|
|
#include "sd-ipv4ll.h"
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2016-05-23 19:24:21 +02:00
|
|
|
#include "ether-addr-util.h"
|
2015-10-01 21:51:49 +02:00
|
|
|
#include "in-addr-util.h"
|
2014-02-28 16:10:20 +01:00
|
|
|
#include "list.h"
|
2015-04-10 22:27:10 +02:00
|
|
|
#include "random-util.h"
|
2015-08-21 12:50:31 +02:00
|
|
|
#include "siphash24.h"
|
|
|
|
#include "sparse-endian.h"
|
2016-05-23 19:35:54 +02:00
|
|
|
#include "string-util.h"
|
2015-08-21 12:50:31 +02:00
|
|
|
#include "util.h"
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
#define IPV4LL_NETWORK UINT32_C(0xA9FE0000)
|
|
|
|
#define IPV4LL_NETMASK UINT32_C(0xFFFF0000)
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2015-08-20 11:40:10 +02:00
|
|
|
#define IPV4LL_DONT_DESTROY(ll) \
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_ipv4ll_unrefp) _unused_ sd_ipv4ll *_dont_destroy_##ll = sd_ipv4ll_ref(ll)
|
2015-08-20 11:40:10 +02:00
|
|
|
|
2014-02-28 16:10:20 +01:00
|
|
|
struct sd_ipv4ll {
|
2015-08-27 19:56:52 +02:00
|
|
|
unsigned n_ref;
|
2014-04-09 12:12:09 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
sd_ipv4acd *acd;
|
2016-05-23 19:24:21 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
be32_t address; /* the address pushed to ACD */
|
2016-05-23 19:24:21 +02:00
|
|
|
struct ether_addr mac;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
le64_t value;
|
|
|
|
le64_t generation;
|
|
|
|
} seed;
|
|
|
|
bool seed_set;
|
2015-08-21 12:50:31 +02:00
|
|
|
|
2014-02-28 16:10:20 +01:00
|
|
|
/* External */
|
|
|
|
be32_t claimed_address;
|
2016-05-23 19:24:21 +02:00
|
|
|
|
2016-05-23 16:48:56 +02:00
|
|
|
sd_ipv4ll_callback_t callback;
|
2014-02-28 16:10:20 +01:00
|
|
|
void* userdata;
|
|
|
|
};
|
|
|
|
|
2016-05-23 19:35:54 +02:00
|
|
|
#define log_ipv4ll_errno(ll, error, fmt, ...) log_internal(LOG_DEBUG, error, __FILE__, __LINE__, __func__, "IPV4LL: " fmt, ##__VA_ARGS__)
|
|
|
|
#define log_ipv4ll(ll, fmt, ...) log_ipv4ll_errno(ll, 0, fmt, ##__VA_ARGS__)
|
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
static void ipv4ll_on_acd(sd_ipv4acd *ll, int event, void *userdata);
|
|
|
|
|
2015-08-20 11:40:10 +02:00
|
|
|
sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll) {
|
|
|
|
if (!ll)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
assert(ll->n_ref >= 1);
|
|
|
|
ll->n_ref++;
|
|
|
|
|
|
|
|
return ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll) {
|
|
|
|
if (!ll)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
assert(ll->n_ref >= 1);
|
|
|
|
ll->n_ref--;
|
|
|
|
|
|
|
|
if (ll->n_ref > 0)
|
|
|
|
return NULL;
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
sd_ipv4acd_unref(ll->acd);
|
2016-10-17 00:28:30 +02:00
|
|
|
return mfree(ll);
|
2015-08-20 11:40:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int sd_ipv4ll_new(sd_ipv4ll **ret) {
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_ipv4ll_unrefp) sd_ipv4ll *ll = NULL;
|
2015-08-21 12:50:31 +02:00
|
|
|
int r;
|
2015-08-20 11:40:10 +02:00
|
|
|
|
|
|
|
assert_return(ret, -EINVAL);
|
|
|
|
|
|
|
|
ll = new0(sd_ipv4ll, 1);
|
|
|
|
if (!ll)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-11-17 00:16:21 +01:00
|
|
|
ll->n_ref = 1;
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
r = sd_ipv4acd_new(&ll->acd);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_ipv4acd_set_callback(ll->acd, ipv4ll_on_acd, ll);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2018-04-05 07:26:26 +02:00
|
|
|
*ret = TAKE_PTR(ll);
|
2015-08-20 11:40:10 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sd_ipv4ll_stop(sd_ipv4ll *ll) {
|
2015-08-21 12:50:31 +02:00
|
|
|
assert_return(ll, -EINVAL);
|
2015-08-20 00:09:08 +02:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
return sd_ipv4acd_stop(ll->acd);
|
2014-02-28 16:10:20 +01:00
|
|
|
}
|
|
|
|
|
2016-05-23 16:13:18 +02:00
|
|
|
int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int ifindex) {
|
2015-08-21 12:50:31 +02:00
|
|
|
assert_return(ll, -EINVAL);
|
2016-05-23 16:13:18 +02:00
|
|
|
assert_return(ifindex > 0, -EINVAL);
|
2016-05-23 19:24:21 +02:00
|
|
|
assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY);
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2016-05-23 16:13:18 +02:00
|
|
|
return sd_ipv4acd_set_ifindex(ll->acd, ifindex);
|
2014-02-28 16:10:20 +01:00
|
|
|
}
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) {
|
2015-08-18 23:58:58 +02:00
|
|
|
int r;
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
assert_return(ll, -EINVAL);
|
2016-05-23 19:24:21 +02:00
|
|
|
assert_return(addr, -EINVAL);
|
|
|
|
assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY);
|
2015-08-18 23:58:58 +02:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
r = sd_ipv4acd_set_mac(ll->acd, addr);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
ll->mac = *addr;
|
|
|
|
return 0;
|
2014-02-28 16:10:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int sd_ipv4ll_detach_event(sd_ipv4ll *ll) {
|
|
|
|
assert_return(ll, -EINVAL);
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
return sd_ipv4acd_detach_event(ll->acd);
|
2014-02-28 16:10:20 +01:00
|
|
|
}
|
|
|
|
|
2016-02-16 19:33:36 +01:00
|
|
|
int sd_ipv4ll_attach_event(sd_ipv4ll *ll, sd_event *event, int64_t priority) {
|
2014-02-28 16:10:20 +01:00
|
|
|
assert_return(ll, -EINVAL);
|
|
|
|
|
2016-05-23 17:19:35 +02:00
|
|
|
return sd_ipv4acd_attach_event(ll->acd, event, priority);
|
2014-02-28 16:10:20 +01:00
|
|
|
}
|
|
|
|
|
2016-02-16 18:58:51 +01:00
|
|
|
int sd_ipv4ll_set_callback(sd_ipv4ll *ll, sd_ipv4ll_callback_t cb, void *userdata) {
|
2014-02-28 16:10:20 +01:00
|
|
|
assert_return(ll, -EINVAL);
|
|
|
|
|
2016-05-23 16:48:56 +02:00
|
|
|
ll->callback = cb;
|
2014-02-28 16:10:20 +01:00
|
|
|
ll->userdata = userdata;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 18:52:52 +01:00
|
|
|
int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address) {
|
2014-02-28 16:10:20 +01:00
|
|
|
assert_return(ll, -EINVAL);
|
|
|
|
assert_return(address, -EINVAL);
|
|
|
|
|
2015-09-08 23:03:38 +02:00
|
|
|
if (ll->claimed_address == 0)
|
2014-02-28 16:10:20 +01:00
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
address->s_addr = ll->claimed_address;
|
2015-08-21 12:50:31 +02:00
|
|
|
|
2014-02-28 16:10:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-23 18:33:17 +02:00
|
|
|
int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed) {
|
2014-03-21 19:23:35 +01:00
|
|
|
assert_return(ll, -EINVAL);
|
2016-05-23 19:24:21 +02:00
|
|
|
assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY);
|
2014-04-27 21:58:26 +02:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
ll->seed.value = htole64(seed);
|
|
|
|
ll->seed_set = true;
|
2014-03-21 19:23:35 +01:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
return 0;
|
2014-03-21 19:23:35 +01:00
|
|
|
}
|
|
|
|
|
2015-10-24 23:42:56 +02:00
|
|
|
int sd_ipv4ll_is_running(sd_ipv4ll *ll) {
|
2015-08-06 00:32:25 +02:00
|
|
|
assert_return(ll, false);
|
2014-04-02 21:31:12 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
return sd_ipv4acd_is_running(ll->acd);
|
2014-04-02 21:31:12 +02:00
|
|
|
}
|
|
|
|
|
2015-10-01 21:51:49 +02:00
|
|
|
static bool ipv4ll_address_is_valid(const struct in_addr *address) {
|
|
|
|
assert(address);
|
|
|
|
|
|
|
|
if (!in_addr_is_link_local(AF_INET, (const union in_addr_union *) address))
|
|
|
|
return false;
|
|
|
|
|
2016-05-26 15:32:23 +02:00
|
|
|
return !IN_SET(be32toh(address->s_addr) & 0x0000FF00U, 0x0000U, 0xFF00U);
|
2015-10-01 21:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(ll, -EINVAL);
|
|
|
|
assert_return(address, -EINVAL);
|
|
|
|
assert_return(ipv4ll_address_is_valid(address), -EINVAL);
|
|
|
|
|
|
|
|
r = sd_ipv4acd_set_address(ll->acd, address);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
ll->address = address->s_addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
#define PICK_HASH_KEY SD_ID128_MAKE(15,ac,82,a6,d6,3f,49,78,98,77,5d,0c,69,02,94,0b)
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
static int ipv4ll_pick_address(sd_ipv4ll *ll) {
|
2016-05-23 19:35:54 +02:00
|
|
|
_cleanup_free_ char *address = NULL;
|
2015-08-21 12:50:31 +02:00
|
|
|
be32_t addr;
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
assert(ll);
|
2014-04-09 12:12:10 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
do {
|
2016-05-23 19:24:21 +02:00
|
|
|
uint64_t h;
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
h = siphash24(&ll->seed, sizeof(ll->seed), PICK_HASH_KEY.bytes);
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
/* Increase the generation counter by one */
|
|
|
|
ll->seed.generation = htole64(le64toh(ll->seed.generation) + 1);
|
2014-03-21 19:23:35 +01:00
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
addr = htobe32((h & UINT32_C(0x0000FFFF)) | IPV4LL_NETWORK);
|
|
|
|
} while (addr == ll->address ||
|
2016-05-26 15:32:23 +02:00
|
|
|
IN_SET(be32toh(addr) & 0x0000FF00U, 0x0000U, 0xFF00U));
|
2016-05-23 19:24:21 +02:00
|
|
|
|
2016-05-23 19:35:54 +02:00
|
|
|
(void) in_addr_to_string(AF_INET, &(union in_addr_union) { .in.s_addr = addr }, &address);
|
|
|
|
log_ipv4ll(ll, "Picked new IP address %s.", strna(address));
|
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
return sd_ipv4ll_set_address(ll, &(struct in_addr) { addr });
|
2015-08-21 12:50:31 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 21:23:10 +02:00
|
|
|
int sd_ipv4ll_restart(sd_ipv4ll *ll) {
|
|
|
|
ll->address = 0;
|
|
|
|
|
|
|
|
return sd_ipv4ll_start(ll);
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:24:21 +02:00
|
|
|
#define MAC_HASH_KEY SD_ID128_MAKE(df,04,22,98,3f,ad,14,52,f9,87,2e,d1,9c,70,e2,f2)
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
int sd_ipv4ll_start(sd_ipv4ll *ll) {
|
|
|
|
int r;
|
2016-05-23 19:24:21 +02:00
|
|
|
bool picked_address = false;
|
2015-08-21 12:50:31 +02:00
|
|
|
|
|
|
|
assert_return(ll, -EINVAL);
|
2016-05-23 19:24:21 +02:00
|
|
|
assert_return(!ether_addr_is_null(&ll->mac), -EINVAL);
|
|
|
|
assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY);
|
|
|
|
|
|
|
|
/* If no random seed is set, generate some from the MAC address */
|
|
|
|
if (!ll->seed_set)
|
|
|
|
ll->seed.value = htole64(siphash24(ll->mac.ether_addr_octet, ETH_ALEN, MAC_HASH_KEY.bytes));
|
|
|
|
|
|
|
|
/* Restart the generation counter. */
|
|
|
|
ll->seed.generation = 0;
|
2014-03-21 19:23:35 +01:00
|
|
|
|
|
|
|
if (ll->address == 0) {
|
2015-08-21 12:50:31 +02:00
|
|
|
r = ipv4ll_pick_address(ll);
|
2014-03-21 19:23:35 +01:00
|
|
|
if (r < 0)
|
2015-08-21 12:50:31 +02:00
|
|
|
return r;
|
2016-05-23 19:24:21 +02:00
|
|
|
|
|
|
|
picked_address = true;
|
2014-03-21 19:23:35 +01:00
|
|
|
}
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
r = sd_ipv4acd_start(ll->acd);
|
2016-05-23 19:24:21 +02:00
|
|
|
if (r < 0) {
|
|
|
|
|
|
|
|
/* We couldn't start? If so, let's forget the picked address again, the user might make a change and
|
|
|
|
* retry, and we want the new data to take effect when picking an address. */
|
|
|
|
if (picked_address)
|
|
|
|
ll->address = 0;
|
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
return r;
|
2016-05-23 19:24:21 +02:00
|
|
|
}
|
2015-08-18 15:37:43 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-18 15:37:43 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
static void ipv4ll_client_notify(sd_ipv4ll *ll, int event) {
|
|
|
|
assert(ll);
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2016-05-23 16:48:56 +02:00
|
|
|
if (ll->callback)
|
|
|
|
ll->callback(ll, event, ll->userdata);
|
2015-08-21 12:50:31 +02:00
|
|
|
}
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
void ipv4ll_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
|
|
|
|
sd_ipv4ll *ll = userdata;
|
|
|
|
IPV4LL_DONT_DESTROY(ll);
|
|
|
|
int r;
|
2014-02-28 16:10:20 +01:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
assert(acd);
|
|
|
|
assert(ll);
|
2014-08-28 15:46:29 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
switch (event) {
|
2016-05-23 17:19:35 +02:00
|
|
|
|
2015-09-22 15:05:35 +02:00
|
|
|
case SD_IPV4ACD_EVENT_STOP:
|
2015-09-22 15:08:28 +02:00
|
|
|
ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_STOP);
|
2015-08-21 12:50:31 +02:00
|
|
|
ll->claimed_address = 0;
|
|
|
|
break;
|
2016-05-23 17:19:35 +02:00
|
|
|
|
2015-09-22 15:05:35 +02:00
|
|
|
case SD_IPV4ACD_EVENT_BIND:
|
2015-08-21 12:50:31 +02:00
|
|
|
ll->claimed_address = ll->address;
|
2015-09-22 15:08:28 +02:00
|
|
|
ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_BIND);
|
2015-08-21 12:50:31 +02:00
|
|
|
break;
|
2016-05-23 17:19:35 +02:00
|
|
|
|
2015-09-22 15:05:35 +02:00
|
|
|
case SD_IPV4ACD_EVENT_CONFLICT:
|
2015-08-21 12:50:31 +02:00
|
|
|
/* if an address was already bound we must call up to the
|
|
|
|
user to handle this, otherwise we just try again */
|
|
|
|
if (ll->claimed_address != 0) {
|
2015-09-22 15:08:28 +02:00
|
|
|
ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_CONFLICT);
|
2015-08-21 12:50:31 +02:00
|
|
|
|
|
|
|
ll->claimed_address = 0;
|
|
|
|
} else {
|
|
|
|
r = ipv4ll_pick_address(ll);
|
|
|
|
if (r < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
r = sd_ipv4acd_start(ll->acd);
|
|
|
|
if (r < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2016-05-23 19:24:21 +02:00
|
|
|
|
2015-08-21 12:50:31 +02:00
|
|
|
default:
|
|
|
|
assert_not_reached("Invalid IPv4ACD event.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2015-09-22 15:08:28 +02:00
|
|
|
ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_STOP);
|
2014-02-28 16:10:20 +01:00
|
|
|
}
|