* [PATCH 16/17] examples: Update netconfig method calls
@ 2022-05-13 14:55 Andrew Zaborowski
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Zaborowski @ 2022-05-13 14:55 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 4076 bytes --]
---
examples/netconfig-test.c | 49 ++++++++++++++++-----------------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/examples/netconfig-test.c b/examples/netconfig-test.c
index c9d02ab..77ad74c 100644
--- a/examples/netconfig-test.c
+++ b/examples/netconfig-test.c
@@ -40,7 +40,6 @@
#include <ell/ell.h>
static bool apply;
-static struct l_netlink *rtnl;
static void do_debug(const char *str, void *user_data)
{
@@ -61,16 +60,14 @@ static void signal_handler(uint32_t signo, void *user_data)
}
static void log_addresses(const char *af_str, const char *action,
- struct l_queue *list)
+ const struct l_queue_entry *entry)
{
- const struct l_queue_entry *entry;
-
- if (l_queue_isempty(list))
+ if (!entry)
return;
l_info("[netconfig%s] Addresses %s:", af_str, action);
- for (entry = l_queue_get_entries(list); entry; entry = entry->next) {
+ for (; entry; entry = entry->next) {
struct l_rtnl_address *addr = entry->data;
char ip_str[INET6_ADDRSTRLEN];
@@ -83,25 +80,26 @@ static void log_addresses(const char *af_str, const char *action,
}
static void log_routes(const char *af_str, const char *action,
- struct l_queue *list)
+ const struct l_queue_entry *entry)
{
- const struct l_queue_entry *entry;
-
- if (l_queue_isempty(list))
+ if (!entry)
return;
l_info("[netconfig%s] Routes %s:", af_str, action);
- for (entry = l_queue_get_entries(list); entry; entry = entry->next) {
+ for (; entry; entry = entry->next) {
struct l_rtnl_route *rt = entry->data;
- char subnet_str[INET6_ADDRSTRLEN];
+ char subnet_str[INET6_ADDRSTRLEN] = "unknown";
char gateway_str[INET6_ADDRSTRLEN];
uint8_t prefix_len;
+ bool onlink;
l_rtnl_route_get_dst(rt, subnet_str, &prefix_len);
- l_rtnl_route_get_gateway(rt, gateway_str);
- l_info("[netconfig%s] \t%s/%i, gateway %s, orig lifetime %i s",
- af_str, subnet_str, prefix_len, gateway_str,
+ onlink = !l_rtnl_route_get_gateway(rt, gateway_str);
+ l_info("[netconfig%s] \t%s/%i, %s%s, orig lifetime %i s",
+ af_str, subnet_str, prefix_len,
+ onlink ? "onlink" : "next-hop ",
+ onlink ? "" : gateway_str,
l_rtnl_route_get_lifetime(rt));
}
}
@@ -110,7 +108,7 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
enum l_netconfig_event event, void *user_data)
{
const char *af_str = family == AF_INET ? "v4" : "v6";
- struct l_queue *added, *updated, *removed;
+ const struct l_queue_entry *added, *updated, *removed, *expired;
switch (event) {
case L_NETCONFIG_EVENT_CONFIGURE:
@@ -128,18 +126,21 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
return;
}
- l_netconfig_get_addresses(netconfig, &added, &updated, &removed);
+ l_netconfig_get_addresses(netconfig, &added, &updated,
+ &removed, &expired);
log_addresses(af_str, "added", added);
log_addresses(af_str, "updated", updated);
log_addresses(af_str, "removed", removed);
+ log_addresses(af_str, "expired", expired);
- l_netconfig_get_routes(netconfig, &added, &updated, &removed);
+ l_netconfig_get_routes(netconfig, &added, &updated, &removed, &expired);
log_routes(af_str, "added", added);
log_routes(af_str, "updated", updated);
log_routes(af_str, "removed", removed);
+ log_routes(af_str, "expired", expired);
if (apply)
- l_netconfig_apply_rtnl(netconfig, rtnl);
+ l_netconfig_apply_rtnl(netconfig);
}
static const struct option main_options[] = {
@@ -181,14 +182,6 @@ int main(int argc, char *argv[])
if (!l_main_init())
return EXIT_FAILURE;
- if (apply) {
- rtnl = l_netlink_new(NETLINK_ROUTE);
- if (!rtnl) {
- fprintf(stderr, "l_netlink_new(NETLINK_ROUTE) error\n");
- return EXIT_FAILURE;
- }
- }
-
l_log_set_stderr();
l_debug_enable("*");
@@ -203,7 +196,5 @@ int main(int argc, char *argv[])
l_netconfig_destroy(netconfig);
l_main_exit();
- l_netlink_destroy(rtnl);
-
return EXIT_SUCCESS;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 16/17] examples: Update netconfig method calls
@ 2022-05-13 22:47 Andrew Zaborowski
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Zaborowski @ 2022-05-13 22:47 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 4076 bytes --]
---
examples/netconfig-test.c | 49 ++++++++++++++++-----------------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/examples/netconfig-test.c b/examples/netconfig-test.c
index c9d02ab..77ad74c 100644
--- a/examples/netconfig-test.c
+++ b/examples/netconfig-test.c
@@ -40,7 +40,6 @@
#include <ell/ell.h>
static bool apply;
-static struct l_netlink *rtnl;
static void do_debug(const char *str, void *user_data)
{
@@ -61,16 +60,14 @@ static void signal_handler(uint32_t signo, void *user_data)
}
static void log_addresses(const char *af_str, const char *action,
- struct l_queue *list)
+ const struct l_queue_entry *entry)
{
- const struct l_queue_entry *entry;
-
- if (l_queue_isempty(list))
+ if (!entry)
return;
l_info("[netconfig%s] Addresses %s:", af_str, action);
- for (entry = l_queue_get_entries(list); entry; entry = entry->next) {
+ for (; entry; entry = entry->next) {
struct l_rtnl_address *addr = entry->data;
char ip_str[INET6_ADDRSTRLEN];
@@ -83,25 +80,26 @@ static void log_addresses(const char *af_str, const char *action,
}
static void log_routes(const char *af_str, const char *action,
- struct l_queue *list)
+ const struct l_queue_entry *entry)
{
- const struct l_queue_entry *entry;
-
- if (l_queue_isempty(list))
+ if (!entry)
return;
l_info("[netconfig%s] Routes %s:", af_str, action);
- for (entry = l_queue_get_entries(list); entry; entry = entry->next) {
+ for (; entry; entry = entry->next) {
struct l_rtnl_route *rt = entry->data;
- char subnet_str[INET6_ADDRSTRLEN];
+ char subnet_str[INET6_ADDRSTRLEN] = "unknown";
char gateway_str[INET6_ADDRSTRLEN];
uint8_t prefix_len;
+ bool onlink;
l_rtnl_route_get_dst(rt, subnet_str, &prefix_len);
- l_rtnl_route_get_gateway(rt, gateway_str);
- l_info("[netconfig%s] \t%s/%i, gateway %s, orig lifetime %i s",
- af_str, subnet_str, prefix_len, gateway_str,
+ onlink = !l_rtnl_route_get_gateway(rt, gateway_str);
+ l_info("[netconfig%s] \t%s/%i, %s%s, orig lifetime %i s",
+ af_str, subnet_str, prefix_len,
+ onlink ? "onlink" : "next-hop ",
+ onlink ? "" : gateway_str,
l_rtnl_route_get_lifetime(rt));
}
}
@@ -110,7 +108,7 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
enum l_netconfig_event event, void *user_data)
{
const char *af_str = family == AF_INET ? "v4" : "v6";
- struct l_queue *added, *updated, *removed;
+ const struct l_queue_entry *added, *updated, *removed, *expired;
switch (event) {
case L_NETCONFIG_EVENT_CONFIGURE:
@@ -128,18 +126,21 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
return;
}
- l_netconfig_get_addresses(netconfig, &added, &updated, &removed);
+ l_netconfig_get_addresses(netconfig, &added, &updated,
+ &removed, &expired);
log_addresses(af_str, "added", added);
log_addresses(af_str, "updated", updated);
log_addresses(af_str, "removed", removed);
+ log_addresses(af_str, "expired", expired);
- l_netconfig_get_routes(netconfig, &added, &updated, &removed);
+ l_netconfig_get_routes(netconfig, &added, &updated, &removed, &expired);
log_routes(af_str, "added", added);
log_routes(af_str, "updated", updated);
log_routes(af_str, "removed", removed);
+ log_routes(af_str, "expired", expired);
if (apply)
- l_netconfig_apply_rtnl(netconfig, rtnl);
+ l_netconfig_apply_rtnl(netconfig);
}
static const struct option main_options[] = {
@@ -181,14 +182,6 @@ int main(int argc, char *argv[])
if (!l_main_init())
return EXIT_FAILURE;
- if (apply) {
- rtnl = l_netlink_new(NETLINK_ROUTE);
- if (!rtnl) {
- fprintf(stderr, "l_netlink_new(NETLINK_ROUTE) error\n");
- return EXIT_FAILURE;
- }
- }
-
l_log_set_stderr();
l_debug_enable("*");
@@ -203,7 +196,5 @@ int main(int argc, char *argv[])
l_netconfig_destroy(netconfig);
l_main_exit();
- l_netlink_destroy(rtnl);
-
return EXIT_SUCCESS;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-13 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 14:55 [PATCH 16/17] examples: Update netconfig method calls Andrew Zaborowski
2022-05-13 22:47 Andrew Zaborowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).