Skip to content

Commit 409b15c

Browse files
kderdacarlescufi
authored andcommitted
net: event: provide complete information about the prefix in events
At the moment, NET_EVENT_IPV6_PREFIX_ADD and NET_EVENT_IPV6_PREFIX_DEL events provide provide information about an address without its length and lifetime. Signed-off-by: Konrad Derda <[email protected]>
1 parent 1622210 commit 409b15c

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

include/zephyr/net/net_event.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ enum net_event_l4_cmd {
214214

215215
/** @endcond */
216216

217-
#ifdef CONFIG_NET_MGMT_EVENT_INFO
218217
/**
219218
* @brief Network Management event information structure
220219
* Used to pass information on network events like
@@ -236,7 +235,7 @@ struct net_event_ipv6_addr {
236235
* NET_EVENT_IPV6_NBR_DEL
237236
* when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
238237
* information.
239-
* @Note: idx will be '-1' in case of NET_EVENT_IPV6_NBR_DEL event.
238+
* @note: idx will be '-1' in case of NET_EVENT_IPV6_NBR_DEL event.
240239
*/
241240
struct net_event_ipv6_nbr {
242241
struct in6_addr addr;
@@ -257,7 +256,19 @@ struct net_event_ipv6_route {
257256
uint8_t prefix_len;
258257
};
259258

260-
#endif /* CONFIG_NET_MGMT_EVENT_INFO */
259+
/**
260+
* @brief Network Management event information structure
261+
* Used to pass information on network events like
262+
* NET_EVENT_IPV6_PREFIX_ADD and
263+
* NET_EVENT_IPV6_PREFIX_DEL
264+
* when CONFIG_NET_MGMT_EVENT_INFO is enabled and event generator pass the
265+
* information.
266+
*/
267+
struct net_event_ipv6_prefix {
268+
struct in6_addr addr; /* prefix */
269+
uint8_t len;
270+
uint32_t lifetime;
271+
};
261272

262273
#ifdef __cplusplus
263274
}

subsys/net/ip/net_if.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ LOG_MODULE_REGISTER(net_if, CONFIG_NET_IF_LOG_LEVEL);
1616
#include <string.h>
1717
#include <zephyr/net/igmp.h>
1818
#include <zephyr/net/net_core.h>
19+
#include <zephyr/net/net_event.h>
1920
#include <zephyr/net/net_pkt.h>
2021
#include <zephyr/net/net_if.h>
2122
#include <zephyr/net/net_mgmt.h>
@@ -2220,9 +2221,20 @@ static void prefix_lifetime_expired(struct net_if_ipv6_prefix *ifprefix)
22202221
remove_prefix_addresses(ifprefix->iface, ipv6, &ifprefix->prefix,
22212222
ifprefix->len);
22222223

2223-
net_mgmt_event_notify_with_info(
2224-
NET_EVENT_IPV6_PREFIX_DEL, ifprefix->iface,
2225-
&ifprefix->prefix, sizeof(struct in6_addr));
2224+
if (IS_ENABLED(CONFIG_NET_MGMT_EVENT_INFO)) {
2225+
struct net_event_ipv6_prefix info;
2226+
2227+
net_ipaddr_copy(&info.addr, &ifprefix->prefix);
2228+
info.len = ifprefix->len;
2229+
info.lifetime = 0;
2230+
2231+
net_mgmt_event_notify_with_info(NET_EVENT_IPV6_PREFIX_DEL,
2232+
ifprefix->iface,
2233+
(const void *) &info,
2234+
sizeof(struct net_event_ipv6_prefix));
2235+
} else {
2236+
net_mgmt_event_notify(NET_EVENT_IPV6_PREFIX_DEL, ifprefix->iface);
2237+
}
22262238

22272239
net_if_unlock(ifprefix->iface);
22282240
}
@@ -2384,9 +2396,19 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
23842396
NET_DBG("[%d] interface %p prefix %s/%d added", i, iface,
23852397
net_sprint_ipv6_addr(prefix), len);
23862398

2387-
net_mgmt_event_notify_with_info(
2388-
NET_EVENT_IPV6_PREFIX_ADD, iface,
2389-
&ipv6->prefix[i].prefix, sizeof(struct in6_addr));
2399+
if (IS_ENABLED(CONFIG_NET_MGMT_EVENT_INFO)) {
2400+
struct net_event_ipv6_prefix info;
2401+
2402+
net_ipaddr_copy(&info.addr, prefix);
2403+
info.len = len;
2404+
info.lifetime = lifetime;
2405+
2406+
net_mgmt_event_notify_with_info(NET_EVENT_IPV6_PREFIX_ADD,
2407+
iface, (const void *) &info,
2408+
sizeof(struct net_event_ipv6_prefix));
2409+
} else {
2410+
net_mgmt_event_notify(NET_EVENT_IPV6_PREFIX_ADD, iface);
2411+
}
23902412

23912413
ifprefix = &ipv6->prefix[i];
23922414
goto out;
@@ -2431,9 +2453,19 @@ bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr,
24312453
*/
24322454
remove_prefix_addresses(iface, ipv6, addr, len);
24332455

2434-
net_mgmt_event_notify_with_info(
2435-
NET_EVENT_IPV6_PREFIX_DEL, iface,
2436-
&ipv6->prefix[i].prefix, sizeof(struct in6_addr));
2456+
if (IS_ENABLED(CONFIG_NET_MGMT_EVENT_INFO)) {
2457+
struct net_event_ipv6_prefix info;
2458+
2459+
net_ipaddr_copy(&info.addr, addr);
2460+
info.len = len;
2461+
info.lifetime = 0;
2462+
2463+
net_mgmt_event_notify_with_info(NET_EVENT_IPV6_PREFIX_DEL,
2464+
iface, (const void *) &info,
2465+
sizeof(struct net_event_ipv6_prefix));
2466+
} else {
2467+
net_mgmt_event_notify(NET_EVENT_IPV6_PREFIX_DEL, iface);
2468+
}
24372469

24382470
ret = true;
24392471
goto out;

subsys/net/ip/net_private.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ union net_mgmt_events {
3434
struct wifi_raw_scan_result raw_scan_result;
3535
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
3636
#endif /* CONFIG_NET_L2_WIFI_MGMT */
37-
#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV6_MLD)
37+
#if defined(CONFIG_NET_IPV6)
38+
struct net_event_ipv6_prefix ipv6_prefix;
39+
#if defined(CONFIG_NET_IPV6_MLD)
3840
struct net_event_ipv6_route ipv6_route;
39-
#endif /* CONFIG_NET_IPV6 && CONFIG_NET_IPV6_MLD */
41+
#endif /* CONFIG_NET_IPV6_MLD */
42+
#endif /* CONFIG_NET_IPV6 */
4043
char default_event[DEFAULT_NET_EVENT_INFO_SIZE];
4144
};
4245

0 commit comments

Comments
 (0)