Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F103893963
D35525.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
9 KB
Referenced Files
None
Subscribers
None
D35525.diff
View Options
diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c
--- a/sys/net/route/nhgrp.c
+++ b/sys/net/route/nhgrp.c
@@ -60,6 +60,11 @@
#include <net/route/nhop_var.h>
#include <net/route/nhgrp_var.h>
+#define DEBUG_MOD_NAME nhgrp
+#define DEBUG_MAX_LEVEL LOG_DEBUG
+#include <net/route/route_debug.h>
+_DECLARE_DEBUG(LOG_INFO);
+
/*
* This file contains data structures management logic for the nexthop
* groups ("nhgrp") route subsystem.
@@ -163,7 +168,7 @@
if (bitmask_alloc_idx(&ctl->nh_idx_head, &idx) != 0) {
NHOPS_WUNLOCK(ctl);
- DPRINTF("Unable to allocate mpath index");
+ FIB_RH_LOG(LOG_INFO, ctl->ctl_rh, "Unable to allocate nhg index");
consider_resize(ctl, new_num_buckets, new_num_items);
return (0);
}
@@ -190,7 +195,7 @@
CHT_SLIST_REMOVE(&ctl->gr_head, mpath, key, nhg_priv_ret);
if (nhg_priv_ret == NULL) {
- DPRINTF("Unable to find nhop group!");
+ FIB_RH_LOG(LOG_DEBUG, ctl->ctl_rh, "Unable to find nhg");
NHOPS_WUNLOCK(ctl);
return (NULL);
}
@@ -233,7 +238,8 @@
return;
}
- DPRINTF("mp: going to resize: gr:[ptr:%p sz:%u] idx:[ptr:%p sz:%u]",
+ FIB_RH_LOG(LOG_DEBUG, ctl->ctl_rh,
+ "going to resize nhg hash: [ptr:%p sz:%u] idx:[ptr:%p sz:%u]",
gr_ptr, new_gr_bucket, gr_idx_ptr, new_idx_items);
old_idx_ptr = NULL;
@@ -271,7 +277,7 @@
cht_ptr = malloc(alloc_size, M_NHOP, malloc_flags);
if (cht_ptr == NULL) {
- DPRINTF("mpath init failed");
+ FIB_RH_LOG(LOG_WARNING, ctl->ctl_rh, "multipath init failed");
return (false);
}
@@ -287,8 +293,7 @@
free(cht_ptr, M_NHOP);
}
- DPRINTF("mpath init done for fib/af %d/%d", ctl->rh->rib_fibnum,
- ctl->rh->rib_family);
+ FIB_RH_LOG(LOG_DEBUG, ctl->ctl_rh, "multipath init done");
return (true);
}
@@ -320,7 +325,11 @@
NHOPS_WLOCK_ASSERT(ctl);
CHT_SLIST_FOREACH(&ctl->gr_head, mpath, nhg_priv) {
- DPRINTF("Marking nhgrp %u unlinked", nhg_priv->nhg_idx);
+#if DEBUG_MAX_LEVEL >= LOG_DEBUG
+ char nhgbuf[NHOP_PRINT_BUFSIZE];
+ FIB_RH_LOG(LOG_DEBUG, ctl->ctl_rh, "marking %s unlinked",
+ nhgrp_print_buf(nhg_priv->nhg, nhgbuf, sizeof(nhgbuf)));
+#endif
refcount_release(&nhg_priv->nhg_linked);
} CHT_SLIST_FOREACH_END;
}
diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -58,6 +58,11 @@
#include <net/route/nhop_var.h>
#include <net/route/nhgrp_var.h>
+#define DEBUG_MOD_NAME nhgrp_ctl
+#define DEBUG_MAX_LEVEL LOG_DEBUG
+#include <net/route/route_debug.h>
+_DECLARE_DEBUG(LOG_INFO);
+
/*
* This file contains the supporting functions for creating multipath groups
* and compiling their dataplane parts.
@@ -222,7 +227,8 @@
for (i = 0; i < dst_priv->nhg_nh_count; i++)
remaining_sum += x[i].weight;
remaining_slots = num_slots;
- DPRINTF("O: %u/%u", (uint32_t)remaining_sum, remaining_slots);
+ FIB_NH_LOG(LOG_DEBUG3, x[0].nh, "sum: %lu, slots: %d",
+ remaining_sum, remaining_slots);
for (i = 0; i < dst_priv->nhg_nh_count; i++) {
/* Calculate number of slots for the current nexthop */
if (remaining_sum > 0) {
@@ -234,9 +240,9 @@
remaining_sum -= x[i].weight;
remaining_slots -= nh_slots;
- DPRINTF(" OO[%d]: %u/%u curr=%d slot_idx=%d", i,
- (uint32_t)remaining_sum, remaining_slots,
- (int)nh_slots, slot_idx);
+ FIB_NH_LOG(LOG_DEBUG3, x[0].nh,
+ " rem_sum: %lu, rem_slots: %d nh_slots: %d, slot_idx: %d",
+ remaining_sum, remaining_slots, (int)nh_slots, slot_idx);
KASSERT((slot_idx + nh_slots <= num_slots),
("index overflow during nhg compilation"));
@@ -267,12 +273,14 @@
size_t sz = get_nhgrp_alloc_size(nhgrp_size, num_nhops);
nhg = malloc(sz, M_NHOP, M_NOWAIT | M_ZERO);
if (nhg == NULL) {
+ FIB_NH_LOG(LOG_INFO, wn[0].nh,
+ "unable to allocate group with num_nhops %d (compiled %u)",
+ num_nhops, nhgrp_size);
return (NULL);
}
/* Has to be the first to make NHGRP_PRIV() work */
nhg->nhg_size = nhgrp_size;
- DPRINTF("new mpath group: num_nhops: %u", (uint32_t)nhgrp_size);
nhg->nhg_flags = MPF_MULTIPATH;
nhg_priv = NHGRP_PRIV(nhg);
@@ -286,6 +294,9 @@
memcpy(&nhg_priv->nhg_nh_weights[0], wn,
num_nhops * sizeof(struct weightened_nhop));
+ FIB_NH_LOG(LOG_DEBUG, wn[0].nh, "num_nhops: %d, compiled_nhop: %u",
+ num_nhops, nhgrp_size);
+
compile_nhgrp(nhg_priv, wn, nhg->nhg_size);
return (nhg_priv);
@@ -345,7 +356,8 @@
ctl = nhg_priv->nh_control;
if (unlink_nhgrp(ctl, nhg_priv) == NULL) {
/* Do not try to reclaim */
- DPRINTF("Failed to unlink nexhop group %p", nhg_priv);
+ RT_LOG(LOG_INFO, "Failed to unlink nexhop group %p",
+ nhg_priv);
NET_EPOCH_EXIT(et);
return;
}
@@ -371,13 +383,16 @@
{
KASSERT((nhg_priv->nhg_refcount == 0), ("nhg_refcount != 0"));
-
- DPRINTF("DEL MPATH %p", nhg_priv);
-
KASSERT((nhg_priv->nhg_idx == 0), ("gr_idx != 0"));
- free_nhgrp_nhops(nhg_priv);
+#if DEBUG_MAX_LEVEL >= LOG_DEBUG
+ char nhgbuf[NHOP_PRINT_BUFSIZE];
+ FIB_NH_LOG(LOG_DEBUG, nhg_priv->nhg_nh_weights[0].nh,
+ "destroying %s", nhgrp_print_buf(nhg_priv->nhg,
+ nhgbuf, sizeof(nhgbuf)));
+#endif
+ free_nhgrp_nhops(nhg_priv);
destroy_nhgrp_int(nhg_priv);
}
@@ -695,6 +710,37 @@
return (nhg_priv->nhg_nh_weights);
}
+/*
+ * Prints nexhop group @nhg data in the provided @buf.
+ * Example: nhg#33/sz=3:[#1:100,#2:100,#3:100]
+ * Example: nhg#33/sz=5:[#1:100,#2:100,..]
+ */
+char *
+nhgrp_print_buf(const struct nhgrp_object *nhg, char *buf, size_t bufsize)
+{
+ const struct nhgrp_priv *nhg_priv = NHGRP_PRIV_CONST(nhg);
+
+ int off = snprintf(buf, bufsize, "nhg#%u/sz=%u:[", nhg_priv->nhg_idx,
+ nhg_priv->nhg_nh_count);
+
+ for (int i = 0; i < nhg_priv->nhg_nh_count; i++) {
+ const struct weightened_nhop *wn = &nhg_priv->nhg_nh_weights[i];
+ int len = snprintf(&buf[off], bufsize - off, "#%u:%u,",
+ wn->nh->nh_priv->nh_idx, wn->weight);
+ if (len + off + 3 >= bufsize) {
+ int len = snprintf(&buf[off], bufsize - off, "...");
+ off += len;
+ break;
+ }
+ off += len;
+ }
+ if (off > 0)
+ off--; // remove last ","
+ if (off + 1 < bufsize)
+ snprintf(&buf[off], bufsize - off, "]");
+ return buf;
+}
+
__noinline static int
dump_nhgrp_entry(struct rib_head *rh, const struct nhgrp_priv *nhg_priv,
char *buffer, size_t buffer_size, struct sysctl_req *w)
diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c
--- a/sys/net/route/nhop_ctl.c
+++ b/sys/net/route/nhop_ctl.c
@@ -584,7 +584,7 @@
* the epoch end, as nexthop is not used
* and return.
*/
- char nhbuf[48];
+ char nhbuf[NHOP_PRINT_BUFSIZE];
FIB_NH_LOG(LOG_WARNING, nh, "failed to link %s",
nhop_print_buf(nh, nhbuf, sizeof(nhbuf)));
destroy_nhop(nh_priv);
@@ -593,7 +593,7 @@
}
#if DEBUG_MAX_LEVEL >= LOG_DEBUG
- char nhbuf[48];
+ char nhbuf[NHOP_PRINT_BUFSIZE];
FIB_NH_LOG(LOG_DEBUG, nh, "finalized: %s", nhop_print_buf(nh, nhbuf, sizeof(nhbuf)));
#endif
@@ -655,7 +655,7 @@
return;
#if DEBUG_MAX_LEVEL >= LOG_DEBUG
- char nhbuf[48];
+ char nhbuf[NHOP_PRINT_BUFSIZE];
FIB_NH_LOG(LOG_DEBUG, nh, "deleting %s", nhop_print_buf(nh, nhbuf, sizeof(nhbuf)));
#endif
@@ -683,7 +683,7 @@
ctl = nh_priv->nh_control;
if (unlink_nhop(ctl, nh_priv) == NULL) {
/* Do not try to reclaim */
- char nhbuf[48];
+ char nhbuf[NHOP_PRINT_BUFSIZE];
FIB_NH_LOG(LOG_WARNING, nh, "failed to unlink %s",
nhop_print_buf(nh, nhbuf, sizeof(nhbuf)));
NET_EPOCH_EXIT(et);
@@ -864,6 +864,17 @@
return (buf);
}
+char *
+nhop_print_buf_any(const struct nhop_object *nh, char *buf, size_t bufsize)
+{
+#ifdef ROUTE_MPATH
+ if (NH_IS_NHGRP(nh))
+ return (nhgrp_print_buf((const struct nhgrp_object *)nh, buf, bufsize));
+ else
+#endif
+ return (nhop_print_buf(nh, buf, bufsize));
+}
+
/*
* Dumps a single entry to sysctl buffer.
*
diff --git a/sys/net/route/route_debug.h b/sys/net/route/route_debug.h
--- a/sys/net/route/route_debug.h
+++ b/sys/net/route/route_debug.h
@@ -76,6 +76,8 @@
/* Same as FIB_LOG, but uses nhop to get fib and family */
#define FIB_NH_LOG(_l, _nh, _fmt, ...) FIB_LOG_##_l(_l, nhop_get_fibnum(_nh), nhop_get_upper_family(_nh), _fmt, ## __VA_ARGS__)
+/* Same as FIB_LOG, but uses rib_head to get fib and family */
+#define FIB_RH_LOG(_l, _rh, _fmt, ...) FIB_LOG_##_l(_l, (_rh)->rib_fibnum, (_rh)->rib_family, _fmt, ## __VA_ARGS__)
/*
* Generic logging for routing subsystem
@@ -90,7 +92,7 @@
/*
* Wrapper logic to avoid compiling high levels of debugging messages for production systems.
*/
-#if DEBUG_MAX_LEVEL>=LOG_DEBUG2
+#if DEBUG_MAX_LEVEL>=LOG_DEBUG3
#define FIB_LOG_LOG_DEBUG3 _FIB_LOG
#define RT_LOG_LOG_DEBUG3 _RT_LOG
#else
@@ -129,10 +131,14 @@
/* Helpers for fancy-printing various objects */
struct nhop_object;
+struct nhgrp_object;
struct llentry;
struct nhop_neigh;
+#define NHOP_PRINT_BUFSIZE 48
char *nhop_print_buf(const struct nhop_object *nh, char *buf, size_t bufsize);
+char *nhop_print_buf_any(const struct nhop_object *nh, char *buf, size_t bufsize);
+char *nhgrp_print_buf(const struct nhgrp_object *nhg, char *buf, size_t bufsize);
char *llentry_print_buf(const struct llentry *lle, struct ifnet *ifp, int family, char *buf,
size_t bufsize);
char *llentry_print_buf_lltable(const struct llentry *lle, char *buf, size_t bufsize);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 8:36 PM (18 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14970870
Default Alt Text
D35525.diff (9 KB)
Attached To
Mode
D35525: routing: improve debug logging
Attached
Detach File
Event Timeline
Log In to Comment