3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

netconfig: Handle l_netconfig events

Add netconfig_event_handler() that responds to events emitted by
the l_netconfig object by calling netconfig_commit, tracking whether
we're connected for either address family and emitting
NETCONFIG_EVENT_CONNECTED or NETCONFIG_EVENT_FAILED as necessary.

NETCONFIG_EVENT_FAILED is a new event as until now failures would cause
the netconfig state machine to stop but no event emitted so that
station.c could take action.  As before, these events are only
emitted based on the IPv4 configuration state, not IPv6.
This commit is contained in:
Andrew Zaborowski 2022-08-29 19:35:58 +02:00 committed by Denis Kenzior
parent b79c7d49cd
commit fbdd4471a1
3 changed files with 74 additions and 3 deletions

View File

@ -114,6 +114,32 @@ static void netconfig_commit_done(struct netconfig *netconfig, uint8_t family,
enum l_netconfig_event event,
bool success)
{
bool connected = netconfig->connected[INDEX_FOR_AF(family)];
if (!success) {
netconfig->connected[INDEX_FOR_AF(family)] = false;
if (netconfig->notify && family == AF_INET)
netconfig->notify(NETCONFIG_EVENT_FAILED,
netconfig->user_data);
return;
}
switch (event) {
case L_NETCONFIG_EVENT_CONFIGURE:
case L_NETCONFIG_EVENT_UPDATE:
netconfig->connected[INDEX_FOR_AF(family)] = true;
if (family == AF_INET && !connected && netconfig->notify)
netconfig->notify(NETCONFIG_EVENT_CONNECTED,
netconfig->user_data);
break;
case L_NETCONFIG_EVENT_UNCONFIGURE:
case L_NETCONFIG_EVENT_FAILED:
break;
}
}
static void netconfig_set_neighbor_entry_cb(int error,

View File

@ -414,9 +414,8 @@ bool netconfig_configure(struct netconfig *netconfig,
netconfig->notify = notify;
netconfig->user_data = user_data;
/* TODO */
resolve_set_mdns(netconfig->resolve, netconfig->mdns);
if (unlikely(!l_netconfig_start(netconfig->nc)))
return false;
return true;
}
@ -449,6 +448,9 @@ bool netconfig_reset(struct netconfig *netconfig)
l_netconfig_unconfigure(netconfig->nc);
l_netconfig_stop(netconfig->nc);
netconfig->connected[0] = false;
netconfig->connected[1] = false;
netconfig_free_settings(netconfig);
return true;
}
@ -499,6 +501,44 @@ void netconfig_handle_fils_ip_resp(struct netconfig *netconfig,
netconfig->fils_override = l_memdup(info, sizeof(*info));
}
static void netconfig_event_handler(struct l_netconfig *nc, uint8_t family,
enum l_netconfig_event event,
void *user_data)
{
struct netconfig *netconfig = user_data;
l_debug("l_netconfig event %d", event);
netconfig_commit(netconfig, family, event);
switch (event) {
case L_NETCONFIG_EVENT_CONFIGURE:
case L_NETCONFIG_EVENT_UPDATE:
break;
case L_NETCONFIG_EVENT_UNCONFIGURE:
break;
case L_NETCONFIG_EVENT_FAILED:
netconfig->connected[INDEX_FOR_AF(family)] = false;
/*
* l_netconfig might have emitted an UNCONFIGURE before this
* but now it tells us it's given up on (re)establishing the
* IP setup.
*/
if (family == AF_INET && netconfig->notify)
netconfig->notify(NETCONFIG_EVENT_FAILED,
netconfig->user_data);
break;
default:
l_error("netconfig: Received unsupported l_netconfig event: %d",
event);
}
}
struct netconfig *netconfig_new(uint32_t ifindex)
{
struct netdev *netdev = netdev_find(ifindex);
@ -530,6 +570,9 @@ struct netconfig *netconfig_new(uint32_t ifindex)
dhcp_priority = L_LOG_DEBUG;
}
l_netconfig_set_event_handler(netconfig->nc, netconfig_event_handler,
netconfig, NULL);
l_dhcp_client_set_debug(l_netconfig_get_dhcp_client(netconfig->nc),
do_debug, "[DHCPv4] ", NULL, dhcp_priority);

View File

@ -27,6 +27,7 @@ struct ie_fils_ip_addr_response_info;
enum netconfig_event {
NETCONFIG_EVENT_CONNECTED,
NETCONFIG_EVENT_FAILED,
};
typedef void (*netconfig_notify_func_t)(enum netconfig_event event,
@ -42,6 +43,7 @@ struct netconfig {
bool static_config[2];
bool gateway_overridden[2];
bool dns_overridden[2];
bool connected[2];
const struct l_settings *active_settings;