3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 23:09:34 +01:00

ap: Save AP address as l_rtnl_address

Change the char *addr_str and uint8_t prefix_len pair to an
l_rtnl_address object and use ell/rtnl.h utilities that use that
directly.  Extend broadcast_from_ip to handle prefix_len.
This commit is contained in:
Andrew Zaborowski 2021-05-28 02:47:35 +02:00 committed by Denis Kenzior
parent a6002562ef
commit 7163a9d9d7

View File

@ -90,8 +90,7 @@ struct ap_state {
struct l_queue *sta_states; struct l_queue *sta_states;
struct l_dhcp_server *netconfig_dhcp; struct l_dhcp_server *netconfig_dhcp;
char *netconfig_addr4_str; struct l_rtnl_address *netconfig_addr4;
uint8_t netconfig_prefix_len4;
uint32_t rtnl_add_cmd; uint32_t rtnl_add_cmd;
bool started : 1; bool started : 1;
@ -132,20 +131,15 @@ static char **global_addr4_strs;
static uint32_t netdev_watch; static uint32_t netdev_watch;
static struct l_netlink *rtnl; static struct l_netlink *rtnl;
static const char *broadcast_from_ip(const char *ip) static const char *broadcast_from_ip(const char *ip, uint8_t prefix_len)
{ {
struct in_addr ia; struct in_addr ia;
uint32_t bcast; uint32_t netmask = util_netmask_from_prefix(prefix_len);
if (inet_aton(ip, &ia) != 1) if (inet_aton(ip, &ia) != 1)
return NULL; return NULL;
bcast = ntohl(ia.s_addr); ia.s_addr |= htonl(~netmask);
bcast &= 0xffffff00;
bcast |= 0x000000ff;
ia.s_addr = htonl(bcast);
return inet_ntoa(ia); return inet_ntoa(ia);
} }
@ -234,16 +228,12 @@ static void ap_reset(struct ap_state *ap)
/* Delete IP if one was set by IWD */ /* Delete IP if one was set by IWD */
if (ap->netconfig_set_addr4) { if (ap->netconfig_set_addr4) {
l_rtnl_ifaddr4_delete(rtnl, netdev_get_ifindex(netdev), l_rtnl_ifaddr_delete(rtnl, netdev_get_ifindex(netdev),
ap->netconfig_prefix_len4, ap->netconfig_addr4, NULL, NULL, NULL);
ap->netconfig_addr4_str,
broadcast_from_ip(ap->netconfig_addr4_str),
NULL, NULL, NULL);
ap->netconfig_set_addr4 = false; ap->netconfig_set_addr4 = false;
} }
l_free(ap->netconfig_addr4_str); l_rtnl_address_free(l_steal_ptr(ap->netconfig_addr4));
ap->netconfig_addr4_str = NULL;
if (ap->netconfig_dhcp) { if (ap->netconfig_dhcp) {
l_dhcp_server_destroy(ap->netconfig_dhcp); l_dhcp_server_destroy(ap->netconfig_dhcp);
@ -2454,6 +2444,13 @@ static int ap_setup_netconfig4(struct ap_state *ap, const char **addr_str_list,
} }
new_addr = l_rtnl_address_new(addr_str_buf, prefix_len); new_addr = l_rtnl_address_new(addr_str_buf, prefix_len);
if (!l_rtnl_address_set_broadcast(new_addr,
broadcast_from_ip(addr_str_buf, prefix_len))) {
ret = -EIO;
goto cleanup;
}
ret = 0; ret = 0;
} else { } else {
if (!prefix_len) if (!prefix_len)
@ -2516,9 +2513,8 @@ static int ap_setup_netconfig4(struct ap_state *ap, const char **addr_str_list,
goto cleanup; goto cleanup;
} }
ap->netconfig_addr4_str = l_strdup(addr_str_buf);
ap->netconfig_prefix_len4 = prefix_len;
ap->netconfig_set_addr4 = true; ap->netconfig_set_addr4 = true;
ap->netconfig_addr4 = l_steal_ptr(new_addr);
ap->netconfig_dhcp = l_steal_ptr(dhcp); ap->netconfig_dhcp = l_steal_ptr(dhcp);
ret = 0; ret = 0;
@ -2952,14 +2948,9 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
l_error("Registering for MLME notification failed"); l_error("Registering for MLME notification failed");
if (ap->netconfig_set_addr4) { if (ap->netconfig_set_addr4) {
const char *broadcast_str = ap->rtnl_add_cmd = l_rtnl_ifaddr_add(rtnl,
broadcast_from_ip(ap->netconfig_addr4_str);
ap->rtnl_add_cmd = l_rtnl_ifaddr4_add(rtnl,
netdev_get_ifindex(netdev), netdev_get_ifindex(netdev),
ap->netconfig_prefix_len4, ap->netconfig_addr4,
ap->netconfig_addr4_str,
broadcast_str,
ap_ifaddr4_added_cb, ap, NULL); ap_ifaddr4_added_cb, ap, NULL);
if (!ap->rtnl_add_cmd) { if (!ap->rtnl_add_cmd) {
l_error("Failed to add the IPv4 address"); l_error("Failed to add the IPv4 address");