Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make packets fail #144

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
/* Define for Click memory allocation debugging. */
#undef CLICK_DMALLOC

/* Define for forcing expensive packet operations. */
#undef CLICK_FORCE_EXPENSIVE

/* Define for forcing expensive packet operations. */
#undef CLICK_FLAKY_PACKETS

/* Define to generate smaller object files. */
#undef CLICK_OPTIMIZE_SIZE

Expand Down
35 changes: 35 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ enable_stats
enable_stride
enable_task_heap
enable_dmalloc
enable_force_expensive
enable_flaky_packets
enable_valgrind
enable_schedule_debugging
enable_intel_cpu
Expand Down Expand Up @@ -1573,6 +1575,9 @@ Optional Features:
--disable-stride disable stride scheduler
--enable-task-heap use heap for task list
--enable-dmalloc enable debugging malloc
--enable-force-expensive
force expensive packet operations
--enable-flaky-packets flaky packets packet operations
--enable-valgrind extra support for debugging with valgrind
--enable-schedule-debugging[=WHAT] enable Click scheduler debugging
(no/yes/extra) [yes]
Expand Down Expand Up @@ -10686,6 +10691,36 @@ fi



# Check whether --enable-force-expensive was given.
if test "${enable_force_expensive+set}" = set; then :
enableval=$enable_force_expensive; :
else
enable_force_expensive=no
fi

if test $enable_force_expensive = yes; then

$as_echo "#define CLICK_FORCE_EXPENSIVE 1" >>confdefs.h

fi



# Check whether --enable-flaky-packets was given.
if test "${enable_flaky_packets+set}" = set; then :
enableval=$enable_flaky_packets; :
else
enable_flaky_packets=no
fi

if test $enable_flaky_packets = yes; then

$as_echo "#define CLICK_FLAKY_PACKETS 1" >>confdefs.h

fi



# Check whether --enable-valgrind was given.
if test "${enable_valgrind+set}" = set; then :
enableval=$enable_valgrind; :
Expand Down
16 changes: 16 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,22 @@ if test $enable_dmalloc = yes; then
fi


dnl debug by forcing expensive operations

AC_ARG_ENABLE([force-expensive], [AS_HELP_STRING([--enable-force-expensive], [force expensive packet operations])], :, enable_force_expensive=no)
if test $enable_force_expensive = yes; then
AC_DEFINE([CLICK_FORCE_EXPENSIVE], [1], [Define for forcing expensive packet operations])
fi


dnl debug by making packet allocations fail randomly

AC_ARG_ENABLE([flaky-packets], [AS_HELP_STRING([--enable-flaky-packets], [flaky packets packet operations])], :, enable_flaky_packets=no)
if test $enable_flaky_packets = yes; then
AC_DEFINE([CLICK_FLAKY_PACKETS], [1], [Define for making packet allocations fail randomly])
fi


dnl valgrind debugging support

AC_ARG_ENABLE([valgrind], [AS_HELP_STRING([--enable-valgrind], [extra support for debugging with valgrind])], :, enable_valgrind=no)
Expand Down
29 changes: 28 additions & 1 deletion include/click/packet.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ Packet::kill()
#elif CLICK_PACKET_USE_DPDK
//Dpdk takes care of indirect and related things
rte_pktmbuf_free(mb());
#elif HAVE_CLICK_PACKET_POOL
#elif HAVE_CLICK_PACKET_POOL && !defined(CLICK_FORCE_EXPENSIVE) && !defined(CLICK_FLAKY_PACKETS)
if (_use_count.dec_and_test()) {
WritablePacket::recycle(static_cast<WritablePacket *>(this));
}
Expand Down Expand Up @@ -1851,6 +1851,19 @@ Packet::shared_nonatomic() const
}


class PacketRef {
public:
PacketRef(Packet* p) : _p(p->clone()) { }
~PacketRef() { if (_p) _p->kill(); }
Packet* release() {
Packet* tmp = _p;
_p = NULL;
return tmp;
}
private:
Packet* _p;
};

/** @brief Return an unshared packet containing this packet's data.
* @return the unshared packet, which is writable
*
Expand All @@ -1877,15 +1890,23 @@ Packet::shared_nonatomic() const
inline WritablePacket *
Packet::uniqueify()
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
#ifndef CLICK_FLAKY_PACKETS
if (!shared())
return static_cast<WritablePacket *>(this);
else
#endif
return expensive_uniqueify(0, 0, true);
}

inline WritablePacket *
Packet::push(uint32_t len)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
if (headroom() >= len && !shared()) {
WritablePacket *q = (WritablePacket *)this;
#if CLICK_LINUXMODULE /* Linux kernel module */
Expand Down Expand Up @@ -1952,6 +1973,9 @@ Packet::pull(uint32_t len)
inline WritablePacket *
Packet::put(uint32_t len)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
if (tailroom() >= len && !shared()) {
WritablePacket *q = (WritablePacket *)this;
#if CLICK_LINUXMODULE /* Linux kernel module */
Expand Down Expand Up @@ -2189,6 +2213,9 @@ Packet::clear_mac_header()
inline WritablePacket *
Packet::push_mac_header(uint32_t len)
{
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
WritablePacket *q;
if (headroom() >= len && !shared()) {
q = (WritablePacket *)this;
Expand Down
15 changes: 15 additions & 0 deletions lib/packet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ Packet::copy(Packet* p, int headroom)
Packet *
Packet::clone(bool fast)
{
#ifdef CLICK_FLAKY_PACKETS
if (0 == click_random(0, 10)) { return NULL; }
#endif
#if CLICK_LINUXMODULE
struct sk_buff *nskb = skb_clone(skb(), GFP_ATOMIC);
return reinterpret_cast<Packet *>(nskb);
Expand Down Expand Up @@ -888,6 +891,9 @@ Packet::clone(bool fast)
p->_head = _head;
p->_data = _data;
p->_tail = _tail;
#ifdef CLICK_FORCE_EXPENSIVE
PacketRef r(this);
#endif
p->_end = _end;
#if HAVE_DPDK
if (DPDKDevice::is_dpdk_packet(this)) {
Expand All @@ -901,6 +907,9 @@ Packet::clone(bool fast)
} else
#endif
{
#ifdef CLICK_FLAKY_PACKETS
if (0 == click_random(0, 10)) { return NULL; }
#endif
p->_destructor = empty_destructor;
}
p->_data_packet = 0;
Expand Down Expand Up @@ -964,6 +973,9 @@ Packet::expensive_uniqueify(int32_t extra_headroom, int32_t extra_tailroom,
kill();
return 0;
}
#ifdef CLICK_FLAKY_PACKETS
if (0 == click_random(0, 10)) { return NULL; }
#endif
nmb->data_off = mb->data_off + extra_headroom;

rte_pktmbuf_data_len(nmb) = length();
Expand Down Expand Up @@ -1029,6 +1041,9 @@ Packet::expensive_uniqueify(int32_t extra_headroom, int32_t extra_tailroom,
memcpy(p->_head + (extra_headroom >= 0 ? extra_headroom : 0), start_copy, end_copy - start_copy);

// free old data
#ifdef CLICK_FLAKY_PACKETS
if (0 == click_random(0, 10)) { kill(); return NULL; }
#endif
if (_data_packet) {
_data_packet->kill();
}
Expand Down