Skip to content

Commit bcae2e7

Browse files
author
Derrick Pallas
committed
lib/packet: add force-expensive configure option
This option forces expensive Packet operations to reallocate by taking a clone prior to checking shared and then killing the clone later. This is controlled by --enable-force-expensive / CLICK_FORCE_EXPENSIVE and allows one to debug issues where a caller assumes that the returned SKB is the same as the original SKB. Signed-off-by: Derrick Pallas <[email protected]>
1 parent 924e560 commit bcae2e7

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
/* Define for Click memory allocation debugging. */
2121
#undef CLICK_DMALLOC
2222

23+
/* Define for forcing expensive packet operations. */
24+
#undef CLICK_FORCE_EXPENSIVE
25+
2326
/* Define to generate smaller object files. */
2427
#undef CLICK_OPTIMIZE_SIZE
2528

configure

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,8 @@ Optional Features:
15401540
--disable-stride disable stride scheduler
15411541
--enable-task-heap use heap for task list
15421542
--enable-dmalloc enable debugging malloc
1543+
--enable-force-expensive
1544+
force expensive packet operations
15431545
--enable-valgrind extra support for debugging with valgrind
15441546
--enable-schedule-debugging[=WHAT] enable Click scheduler debugging
15451547
(no/yes/extra) [yes]
@@ -10267,6 +10269,21 @@ fi
1026710269

1026810270

1026910271

10272+
# Check whether --enable-dmalloc was given.
10273+
if test "${enable_dmalloc+set}" = set; then :
10274+
enableval=$enable_dmalloc; :
10275+
else
10276+
enable_force_expensive=no
10277+
fi
10278+
10279+
if test $enable_force_expensive = yes; then
10280+
10281+
$as_echo "#define CLICK_FORCE_EXPENSIVE 1" >>confdefs.h
10282+
10283+
fi
10284+
10285+
10286+
1027010287
# Check whether --enable-valgrind was given.
1027110288
if test "${enable_valgrind+set}" = set; then :
1027210289
enableval=$enable_valgrind; :

configure.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ if test $enable_dmalloc = yes; then
10871087
fi
10881088

10891089

1090+
dnl debug by forcing expensive operations
1091+
1092+
AC_ARG_ENABLE([dmalloc], [AS_HELP_STRING([--enable-force-expensive], [force expensive packet operations])], :, enable_force_expensive=no)
1093+
if test $enable_force_expensive = yes; then
1094+
AC_DEFINE([CLICK_FORCE_EXPENSIVE], [1], [Define for forcing expensive packet operations])
1095+
fi
1096+
1097+
10901098
dnl valgrind debugging support
10911099

10921100
AC_ARG_ENABLE([valgrind], [AS_HELP_STRING([--enable-valgrind], [extra support for debugging with valgrind])], :, enable_valgrind=no)

include/click/packet.hh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ Packet::kill()
14321432
b->list = 0;
14331433
# endif
14341434
skbmgr_recycle_skbs(b);
1435-
#elif HAVE_CLICK_PACKET_POOL
1435+
#elif HAVE_CLICK_PACKET_POOL && !defined(CLICK_FORCE_EXPENSIVE)
14361436
if (_use_count.dec_and_test())
14371437
WritablePacket::recycle(static_cast<WritablePacket *>(this));
14381438
#else
@@ -1536,6 +1536,19 @@ Packet::shared() const
15361536
#endif
15371537
}
15381538

1539+
class PacketRef {
1540+
public:
1541+
PacketRef(Packet* p) : _p(p->clone()) { }
1542+
~PacketRef() { if (_p) _p->kill(); }
1543+
Packet* release() {
1544+
Packet* tmp = _p;
1545+
_p = NULL;
1546+
return tmp;
1547+
}
1548+
private:
1549+
Packet* _p;
1550+
};
1551+
15391552
/** @brief Return an unshared packet containing this packet's data.
15401553
* @return the unshared packet, which is writable
15411554
*
@@ -1562,6 +1575,9 @@ Packet::shared() const
15621575
inline WritablePacket *
15631576
Packet::uniqueify()
15641577
{
1578+
#ifdef CLICK_FORCE_EXPENSIVE
1579+
PacketRef r(this);
1580+
#endif
15651581
if (!shared())
15661582
return static_cast<WritablePacket *>(this);
15671583
else
@@ -1571,6 +1587,9 @@ Packet::uniqueify()
15711587
inline WritablePacket *
15721588
Packet::push(uint32_t len)
15731589
{
1590+
#ifdef CLICK_FORCE_EXPENSIVE
1591+
PacketRef r(this);
1592+
#endif
15741593
if (headroom() >= len && !shared()) {
15751594
WritablePacket *q = (WritablePacket *)this;
15761595
#if CLICK_LINUXMODULE /* Linux kernel module */
@@ -1629,6 +1648,9 @@ Packet::pull(uint32_t len)
16291648
inline WritablePacket *
16301649
Packet::put(uint32_t len)
16311650
{
1651+
#ifdef CLICK_FORCE_EXPENSIVE
1652+
PacketRef r(this);
1653+
#endif
16321654
if (tailroom() >= len && !shared()) {
16331655
WritablePacket *q = (WritablePacket *)this;
16341656
#if CLICK_LINUXMODULE /* Linux kernel module */
@@ -1830,6 +1852,9 @@ Packet::clear_mac_header()
18301852
inline WritablePacket *
18311853
Packet::push_mac_header(uint32_t len)
18321854
{
1855+
#ifdef CLICK_FORCE_EXPENSIVE
1856+
PacketRef r(this);
1857+
#endif
18331858
WritablePacket *q;
18341859
if (headroom() >= len && !shared()) {
18351860
q = (WritablePacket *)this;

lib/packet.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,9 @@ Packet::expensive_put(uint32_t nbytes)
888888
Packet *
889889
Packet::shift_data(int offset, bool free_on_failure)
890890
{
891+
#ifdef CLICK_FORCE_EXPENSIVE
892+
PacketRef r(this);
893+
#endif
891894
if (offset == 0)
892895
return this;
893896

0 commit comments

Comments
 (0)