int fd_raw;
int ifindex;
+ char *ifname;
be32_t address;
be32_t netmask;
be32_t subnet;
unsigned n_ref;
int ifindex;
+ char *ifname;
int fd;
sd_event *event;
sd-ipv4acd.c
arp-util.h
arp-util.c
+ network-common.c
+ network-common.h
network-internal.c
network-internal.h
sd-ndisc.c
Copyright © 2014 Intel Corporation. All rights reserved.
***/
+#include "sd-ndisc.h"
+
#include "log.h"
#include "time-util.h"
-#include "sd-ndisc.h"
-
#define NDISC_ROUTER_SOLICITATION_INTERVAL (4U * USEC_PER_SEC)
#define NDISC_MAX_ROUTER_SOLICITATION_INTERVAL (3600U * USEC_PER_SEC)
#define NDISC_MAX_ROUTER_SOLICITATIONS 3U
unsigned n_ref;
int ifindex;
+ char *ifname;
int fd;
sd_event *event;
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "format-util.h"
+#include "network-common.h"
+#include "string-util.h"
+
+const char *get_ifname(int ifindex, char **ifname) {
+ char buf[IF_NAMESIZE + 1];
+
+ assert(ifname);
+
+ /* This sets ifname only when it is not set yet. */
+
+ if (*ifname)
+ return *ifname;
+
+ if (ifindex <= 0)
+ return NULL;
+
+ if (!format_ifname(ifindex, buf))
+ return NULL;
+
+ return *ifname = strdup(buf);
+}
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+const char *get_ifname(int ifindex, char **ifname);
RAdvState state;
int ifindex;
+ char *ifname;
sd_event *event;
int event_priority;
#include "hostname-util.h"
#include "io-util.h"
#include "memory-util.h"
+#include "network-common.h"
#include "random-util.h"
#include "set.h"
#include "sort-util.h"
int event_priority;
sd_event_source *timeout_resend;
int ifindex;
+ char *ifname;
int fd;
uint16_t port;
union sockaddr_union link;
return 0;
}
+int sd_dhcp_client_set_ifname(sd_dhcp_client *client, const char *ifname) {
+ assert_return(client, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&client->ifname, ifname);
+}
+
+const char *sd_dhcp_client_get_ifname(sd_dhcp_client *client) {
+ if (!client)
+ return NULL;
+
+ return get_ifname(client->ifindex, &client->ifname);
+}
+
int sd_dhcp_client_set_mac(
sd_dhcp_client *client,
const uint8_t *addr,
client->user_class = strv_free(client->user_class);
ordered_hashmap_free(client->extra_options);
ordered_hashmap_free(client->vendor_options);
+ free(client->ifname);
return mfree(client);
}
#include "fd-util.h"
#include "in-addr-util.h"
#include "io-util.h"
+#include "network-common.h"
#include "ordered-set.h"
#include "siphash24.h"
#include "string-util.h"
ordered_set_free(server->vendor_options);
free(server->bound_leases);
+
+ free(server->ifname);
return mfree(server);
}
assert_return(ret, -EINVAL);
assert_return(ifindex > 0, -EINVAL);
- server = new0(sd_dhcp_server, 1);
+ server = new(sd_dhcp_server, 1);
if (!server)
return -ENOMEM;
- server->n_ref = 1;
- server->fd_raw = -1;
- server->fd = -1;
- server->address = htobe32(INADDR_ANY);
- server->netmask = htobe32(INADDR_ANY);
- server->ifindex = ifindex;
+ *server = (sd_dhcp_server) {
+ .n_ref = 1,
+ .fd_raw = -1,
+ .fd = -1,
+ .address = htobe32(INADDR_ANY),
+ .netmask = htobe32(INADDR_ANY),
+ .ifindex = ifindex,
+ .default_lease_time = DIV_ROUND_UP(DHCP_DEFAULT_LEASE_TIME_USEC, USEC_PER_SEC),
+ .max_lease_time = DIV_ROUND_UP(DHCP_MAX_LEASE_TIME_USEC, USEC_PER_SEC),
+ };
server->leases_by_client_id = hashmap_new(&dhcp_lease_hash_ops);
if (!server->leases_by_client_id)
return -ENOMEM;
- server->default_lease_time = DIV_ROUND_UP(DHCP_DEFAULT_LEASE_TIME_USEC, USEC_PER_SEC);
- server->max_lease_time = DIV_ROUND_UP(DHCP_MAX_LEASE_TIME_USEC, USEC_PER_SEC);
-
*ret = TAKE_PTR(server);
return 0;
}
+int sd_dhcp_server_set_ifname(sd_dhcp_server *server, const char *ifname) {
+ assert_return(server, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&server->ifname, ifname);
+}
+
+const char *sd_dhcp_server_get_ifname(sd_dhcp_server *server) {
+ if (!server)
+ return NULL;
+
+ return get_ifname(server->ifindex, &server->ifname);
+}
+
int sd_dhcp_server_attach_event(sd_dhcp_server *server, sd_event *event, int64_t priority) {
int r;
#include "hexdecoct.h"
#include "hostname-util.h"
#include "in-addr-util.h"
+#include "network-common.h"
#include "random-util.h"
#include "socket-util.h"
#include "string-table.h"
sd_event *event;
int event_priority;
int ifindex;
+ char *ifname;
DHCP6Address hint_pd_prefix;
struct in6_addr local_address;
uint8_t mac_addr[MAX_MAC_ADDR_LEN];
return 0;
}
+int sd_dhcp6_client_set_ifname(sd_dhcp6_client *client, const char *ifname) {
+ assert_return(client, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&client->ifname, ifname);
+}
+
+const char *sd_dhcp6_client_get_ifname(sd_dhcp6_client *client) {
+ if (!client)
+ return NULL;
+
+ return get_ifname(client->ifindex, &client->ifname);
+}
+
int sd_dhcp6_client_set_local_address(
sd_dhcp6_client *client,
const struct in6_addr *local_address) {
ordered_hashmap_free(client->extra_options);
strv_free(client->user_class);
strv_free(client->vendor_class);
+ free(client->ifname);
return mfree(client);
}
#include "ether-addr-util.h"
#include "event-util.h"
#include "fd-util.h"
-#include "format-util.h"
#include "in-addr-util.h"
#include "log-link.h"
+#include "network-common.h"
#include "random-util.h"
#include "siphash24.h"
#include "string-table.h"
int ifindex;
int fd;
- char ifname[IF_NAMESIZE + 1];
+ char *ifname;
unsigned n_iteration;
unsigned n_conflict;
ipv4acd_reset(acd);
sd_ipv4acd_detach_event(acd);
-
+ free(acd->ifname);
return mfree(acd);
}
}
int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int ifindex) {
- char ifname[IF_NAMESIZE + 1];
-
assert_return(acd, -EINVAL);
assert_return(ifindex > 0, -EINVAL);
assert_return(acd->state == IPV4ACD_STATE_INIT, -EBUSY);
- if (!format_ifname(ifindex, ifname))
- return -ENODEV;
-
- strcpy(acd->ifname, ifname);
acd->ifindex = ifindex;
return 0;
return acd->ifindex;
}
+int sd_ipv4acd_set_ifname(sd_ipv4acd *acd, const char *ifname) {
+ assert_return(acd, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&acd->ifname, ifname);
+}
+
const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd) {
if (!acd)
return NULL;
- return empty_to_null(acd->ifname);
+ return get_ifname(acd->ifindex, &acd->ifname);
}
int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr) {
return sd_ipv4acd_get_ifindex(ll->acd);
}
+int sd_ipv4ll_set_ifname(sd_ipv4ll *ll, const char *ifname) {
+ assert_return(ll, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ return sd_ipv4acd_set_ifname(ll->acd, ifname);
+}
+
const char *sd_ipv4ll_get_ifname(sd_ipv4ll *ll) {
if (!ll)
return NULL;
#include "lldp-neighbor.h"
#include "lldp-network.h"
#include "memory-util.h"
+#include "network-common.h"
#include "socket-util.h"
#include "sort-util.h"
#include "string-table.h"
return 0;
}
+int sd_lldp_set_ifname(sd_lldp *lldp, const char *ifname) {
+ assert_return(lldp, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&lldp->ifname, ifname);
+}
+
+const char *sd_lldp_get_ifname(sd_lldp *lldp) {
+ if (!lldp)
+ return NULL;
+
+ return get_ifname(lldp->ifindex, &lldp->ifname);
+}
+
static sd_lldp* lldp_free(sd_lldp *lldp) {
assert(lldp);
hashmap_free(lldp->neighbor_by_id);
prioq_free(lldp->neighbor_by_expiry);
+ free(lldp->ifname);
return mfree(lldp);
}
#include "memory-util.h"
#include "ndisc-internal.h"
#include "ndisc-router.h"
+#include "network-common.h"
#include "random-util.h"
#include "socket-util.h"
#include "string-table.h"
return 0;
}
+int sd_ndisc_set_ifname(sd_ndisc *nd, const char *ifname) {
+ assert_return(nd, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&nd->ifname, ifname);
+}
+
+const char *sd_ndisc_get_ifname(sd_ndisc *nd) {
+ if (!nd)
+ return NULL;
+
+ return get_ifname(nd->ifindex, &nd->ifname);
+}
+
_public_ int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr) {
assert_return(nd, -EINVAL);
ndisc_reset(nd);
sd_ndisc_detach_event(nd);
+ free(nd->ifname);
return mfree(nd);
}
#include "io-util.h"
#include "macro.h"
#include "memory-util.h"
+#include "network-common.h"
#include "radv-internal.h"
#include "random-util.h"
#include "socket-util.h"
sd_radv_detach_event(ra);
ra->fd = safe_close(ra->fd);
+ free(ra->ifname);
return mfree(ra);
}
return 0;
}
+int sd_radv_set_ifname(sd_radv *ra, const char *ifname) {
+ assert_return(ra, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&ra->ifname, ifname);
+}
+
+const char *sd_radv_get_ifname(sd_radv *ra) {
+ if (!ra)
+ return NULL;
+
+ return get_ifname(ra->ifindex, &ra->ifname);
+}
+
_public_ int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr) {
assert_return(ra, -EINVAL);
int sd_dhcp_client_set_ifindex(
sd_dhcp_client *client,
int interface_index);
+int sd_dhcp_client_set_ifname(
+ sd_dhcp_client *client,
+ const char *interface_name);
+const char *sd_dhcp_client_get_ifname(sd_dhcp_client *client);
int sd_dhcp_client_set_mac(
sd_dhcp_client *client,
const uint8_t *addr,
int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex);
+int sd_dhcp_server_set_ifname(sd_dhcp_server *server, const char *ifname);
+const char *sd_dhcp_server_get_ifname(sd_dhcp_server *server);
+
sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server);
sd_dhcp_server *sd_dhcp_server_unref(sd_dhcp_server *server);
int sd_dhcp6_client_set_ifindex(
sd_dhcp6_client *client,
int interface_index);
+int sd_dhcp6_client_set_ifname(
+ sd_dhcp6_client *client,
+ const char *interface_name);
+const char * sd_dhcp6_client_get_ifname(sd_dhcp6_client *client);
int sd_dhcp6_client_set_local_address(
sd_dhcp6_client *client,
const struct in6_addr *local_address);
int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr);
int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int interface_index);
int sd_ipv4acd_get_ifindex(sd_ipv4acd *acd);
+int sd_ipv4acd_set_ifname(sd_ipv4acd *acd, const char *interface_name);
const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd);
int sd_ipv4acd_set_address(sd_ipv4acd *acd, const struct in_addr *address);
int sd_ipv4acd_is_running(sd_ipv4acd *acd);
int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr);
int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int interface_index);
int sd_ipv4ll_get_ifindex(sd_ipv4ll *ll);
+int sd_ipv4ll_set_ifname(sd_ipv4ll *ll, const char *interface_name);
const char *sd_ipv4ll_get_ifname(sd_ipv4ll *ll);
int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address);
int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed);
int sd_lldp_set_callback(sd_lldp *lldp, sd_lldp_callback_t cb, void *userdata);
int sd_lldp_set_ifindex(sd_lldp *lldp, int ifindex);
+int sd_lldp_set_ifname(sd_lldp *lldp, const char *ifname);
+const char *sd_lldp_get_ifname(sd_lldp *lldp);
/* Controls how much and what to store in the neighbors database */
int sd_lldp_set_neighbors_max(sd_lldp *lldp, uint64_t n);
int sd_ndisc_set_callback(sd_ndisc *nd, sd_ndisc_callback_t cb, void *userdata);
int sd_ndisc_set_ifindex(sd_ndisc *nd, int interface_index);
+int sd_ndisc_set_ifname(sd_ndisc *nd, const char *interface_name);
+const char *sd_ndisc_get_ifname(sd_ndisc *nd);
int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr);
int sd_ndisc_get_mtu(sd_ndisc *nd, uint32_t *ret);
int sd_radv_is_running(sd_radv *ra);
int sd_radv_set_ifindex(sd_radv *ra, int interface_index);
+int sd_radv_set_ifname(sd_radv *ra, const char *interface_name);
+const char *sd_radv_get_ifname(sd_radv *ra);
int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr);
int sd_radv_set_mtu(sd_radv *ra, uint32_t mtu);
int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit);