58
58
#include <net/route/nhop_var.h>
59
59
#include <net/route/nhgrp_var.h>
60
60
61
+ #define DEBUG_MOD_NAME nhgrp_ctl
62
+ #define DEBUG_MAX_LEVEL LOG_DEBUG
63
+ #include <net/route/route_debug.h>
64
+ _DECLARE_DEBUG (LOG_INFO );
65
+
61
66
/*
62
67
* This file contains the supporting functions for creating multipath groups
63
68
* and compiling their dataplane parts.
@@ -222,7 +227,8 @@ compile_nhgrp(struct nhgrp_priv *dst_priv, const struct weightened_nhop *x,
222
227
for (i = 0 ; i < dst_priv -> nhg_nh_count ; i ++ )
223
228
remaining_sum += x [i ].weight ;
224
229
remaining_slots = num_slots ;
225
- DPRINTF ("O: %u/%u" , (uint32_t )remaining_sum , remaining_slots );
230
+ FIB_NH_LOG (LOG_DEBUG3 , x [0 ].nh , "sum: %lu, slots: %d" ,
231
+ remaining_sum , remaining_slots );
226
232
for (i = 0 ; i < dst_priv -> nhg_nh_count ; i ++ ) {
227
233
/* Calculate number of slots for the current nexthop */
228
234
if (remaining_sum > 0 ) {
@@ -234,9 +240,9 @@ compile_nhgrp(struct nhgrp_priv *dst_priv, const struct weightened_nhop *x,
234
240
remaining_sum -= x [i ].weight ;
235
241
remaining_slots -= nh_slots ;
236
242
237
- DPRINTF ( " OO[%d]: %u/%u curr=%d slot_idx=%d" , i ,
238
- ( uint32_t ) remaining_sum , remaining_slots ,
239
- (int )nh_slots , slot_idx );
243
+ FIB_NH_LOG ( LOG_DEBUG3 , x [ 0 ]. nh ,
244
+ " rem_sum: %lu, rem_slots: %d nh_slots: %d, slot_idx: %d" ,
245
+ remaining_sum , remaining_slots , (int )nh_slots , slot_idx );
240
246
241
247
KASSERT ((slot_idx + nh_slots <= num_slots ),
242
248
("index overflow during nhg compilation" ));
@@ -267,12 +273,14 @@ alloc_nhgrp(struct weightened_nhop *wn, int num_nhops)
267
273
size_t sz = get_nhgrp_alloc_size (nhgrp_size , num_nhops );
268
274
nhg = malloc (sz , M_NHOP , M_NOWAIT | M_ZERO );
269
275
if (nhg == NULL ) {
276
+ FIB_NH_LOG (LOG_INFO , wn [0 ].nh ,
277
+ "unable to allocate group with num_nhops %d (compiled %u)" ,
278
+ num_nhops , nhgrp_size );
270
279
return (NULL );
271
280
}
272
281
273
282
/* Has to be the first to make NHGRP_PRIV() work */
274
283
nhg -> nhg_size = nhgrp_size ;
275
- DPRINTF ("new mpath group: num_nhops: %u" , (uint32_t )nhgrp_size );
276
284
nhg -> nhg_flags = MPF_MULTIPATH ;
277
285
278
286
nhg_priv = NHGRP_PRIV (nhg );
@@ -286,6 +294,9 @@ alloc_nhgrp(struct weightened_nhop *wn, int num_nhops)
286
294
memcpy (& nhg_priv -> nhg_nh_weights [0 ], wn ,
287
295
num_nhops * sizeof (struct weightened_nhop ));
288
296
297
+ FIB_NH_LOG (LOG_DEBUG , wn [0 ].nh , "num_nhops: %d, compiled_nhop: %u" ,
298
+ num_nhops , nhgrp_size );
299
+
289
300
compile_nhgrp (nhg_priv , wn , nhg -> nhg_size );
290
301
291
302
return (nhg_priv );
@@ -345,7 +356,8 @@ nhgrp_free(struct nhgrp_object *nhg)
345
356
ctl = nhg_priv -> nh_control ;
346
357
if (unlink_nhgrp (ctl , nhg_priv ) == NULL ) {
347
358
/* Do not try to reclaim */
348
- DPRINTF ("Failed to unlink nexhop group %p" , nhg_priv );
359
+ RT_LOG (LOG_INFO , "Failed to unlink nexhop group %p" ,
360
+ nhg_priv );
349
361
NET_EPOCH_EXIT (et );
350
362
return ;
351
363
}
@@ -371,13 +383,16 @@ destroy_nhgrp(struct nhgrp_priv *nhg_priv)
371
383
{
372
384
373
385
KASSERT ((nhg_priv -> nhg_refcount == 0 ), ("nhg_refcount != 0" ));
374
-
375
- DPRINTF ("DEL MPATH %p" , nhg_priv );
376
-
377
386
KASSERT ((nhg_priv -> nhg_idx == 0 ), ("gr_idx != 0" ));
378
387
379
- free_nhgrp_nhops (nhg_priv );
388
+ #if DEBUG_MAX_LEVEL >= LOG_DEBUG
389
+ char nhgbuf [NHOP_PRINT_BUFSIZE ];
390
+ FIB_NH_LOG (LOG_DEBUG , nhg_priv -> nhg_nh_weights [0 ].nh ,
391
+ "destroying %s" , nhgrp_print_buf (nhg_priv -> nhg ,
392
+ nhgbuf , sizeof (nhgbuf )));
393
+ #endif
380
394
395
+ free_nhgrp_nhops (nhg_priv );
381
396
destroy_nhgrp_int (nhg_priv );
382
397
}
383
398
@@ -695,6 +710,37 @@ nhgrp_get_nhops(struct nhgrp_object *nhg, uint32_t *pnum_nhops)
695
710
return (nhg_priv -> nhg_nh_weights );
696
711
}
697
712
713
+ /*
714
+ * Prints nexhop group @nhg data in the provided @buf.
715
+ * Example: nhg#33/sz=3:[#1:100,#2:100,#3:100]
716
+ * Example: nhg#33/sz=5:[#1:100,#2:100,..]
717
+ */
718
+ char *
719
+ nhgrp_print_buf (const struct nhgrp_object * nhg , char * buf , size_t bufsize )
720
+ {
721
+ const struct nhgrp_priv * nhg_priv = NHGRP_PRIV_CONST (nhg );
722
+
723
+ int off = snprintf (buf , bufsize , "nhg#%u/sz=%u:[" , nhg_priv -> nhg_idx ,
724
+ nhg_priv -> nhg_nh_count );
725
+
726
+ for (int i = 0 ; i < nhg_priv -> nhg_nh_count ; i ++ ) {
727
+ const struct weightened_nhop * wn = & nhg_priv -> nhg_nh_weights [i ];
728
+ int len = snprintf (& buf [off ], bufsize - off , "#%u:%u," ,
729
+ wn -> nh -> nh_priv -> nh_idx , wn -> weight );
730
+ if (len + off + 3 >= bufsize ) {
731
+ int len = snprintf (& buf [off ], bufsize - off , "..." );
732
+ off += len ;
733
+ break ;
734
+ }
735
+ off += len ;
736
+ }
737
+ if (off > 0 )
738
+ off -- ; // remove last ","
739
+ if (off + 1 < bufsize )
740
+ snprintf (& buf [off ], bufsize - off , "]" );
741
+ return buf ;
742
+ }
743
+
698
744
__noinline static int
699
745
dump_nhgrp_entry (struct rib_head * rh , const struct nhgrp_priv * nhg_priv ,
700
746
char * buffer , size_t buffer_size , struct sysctl_req * w )
0 commit comments