Skip to content
Permalink
Browse files

net: dns: Send net-mgmt event for DNS server add and del

If DNS server(s) are added or removed e.g., as part of DHCP
processing, send newly defined net-mgmt events so that
a user application may get this information.

Fixes #16924

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Jun 21, 2019
1 parent 4b06ae3 commit 8f92dc4634de2a4c7b4411781867ac37e0e68a45
Showing with 36 additions and 0 deletions.
  1. +8 −0 include/net/net_event.h
  2. +28 −0 subsys/net/lib/dns/resolve.c
@@ -157,6 +157,8 @@ enum net_event_ipv4_cmd {
enum net_event_l4_cmd {
NET_EVENT_L4_CMD_CONNECTED = 1,
NET_EVENT_L4_CMD_DISCONNECTED,
NET_EVENT_L4_CMD_DNS_SERVER_ADD,
NET_EVENT_L4_CMD_DNS_SERVER_DEL,
};

#define NET_EVENT_L4_CONNECTED \
@@ -165,6 +167,12 @@ enum net_event_l4_cmd {
#define NET_EVENT_L4_DISCONNECTED \
(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DISCONNECTED)

#define NET_EVENT_DNS_SERVER_ADD \
(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_ADD)

#define NET_EVENT_DNS_SERVER_DEL \
(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_DEL)

/** @endcond */

#ifdef CONFIG_NET_MGMT_EVENT_INFO
@@ -20,6 +20,7 @@ LOG_MODULE_REGISTER(net_dns_resolve, CONFIG_DNS_RESOLVER_LOG_LEVEL);

#include <net/net_ip.h>
#include <net/net_pkt.h>
#include <net/net_mgmt.h>
#include <net/dns_resolve.h>
#include "dns_pack.h"

@@ -196,6 +197,7 @@ int dns_resolve_init(struct dns_resolve_context *ctx, const char *servers[],
struct sockaddr *local_addr = NULL;
socklen_t addr_len = 0;
int i = 0, idx = 0;
struct net_if *iface;
int ret, count;

if (!ctx) {
@@ -278,6 +280,17 @@ int dns_resolve_init(struct dns_resolve_context *ctx, const char *servers[],
return ret;
}

iface = net_context_get_iface(ctx->servers[i].net_ctx);

if (IS_ENABLED(CONFIG_NET_MGMT_EVENT_INFO)) {
net_mgmt_event_notify_with_info(
NET_EVENT_DNS_SERVER_ADD,
iface, (void *)&ctx->servers[i].dns_server,
sizeof(struct sockaddr));
} else {
net_mgmt_event_notify(NET_EVENT_DNS_SERVER_ADD, iface);
}

count++;
}

@@ -914,6 +927,21 @@ int dns_resolve_close(struct dns_resolve_context *ctx)

for (i = 0; i < SERVER_COUNT; i++) {
if (ctx->servers[i].net_ctx) {
struct net_if *iface;

iface = net_context_get_iface(ctx->servers[i].net_ctx);

if (IS_ENABLED(CONFIG_NET_MGMT_EVENT_INFO)) {
net_mgmt_event_notify_with_info(
NET_EVENT_DNS_SERVER_DEL,
iface,
(void *)&ctx->servers[i].dns_server,
sizeof(struct sockaddr));
} else {
net_mgmt_event_notify(NET_EVENT_DNS_SERVER_DEL,
iface);
}

net_context_put(ctx->servers[i].net_ctx);
}
}

0 comments on commit 8f92dc4

Please sign in to comment.
You can’t perform that action at this time.