From a448c24b251d1c3eb57ff4516a6e078e6423740f Mon Sep 17 00:00:00 2001 From: Tom Barbette Date: Tue, 24 Oct 2023 14:25:41 +0000 Subject: [PATCH] TruncateFCS: new element to truncate the FCS Removes FCS from ethernet frames. In practice, just removes 4 bytes... --- elements/ethernet/truncatefcs.cc | 57 ++++++++++++++++++++++++++++++++ elements/ethernet/truncatefcs.hh | 41 +++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 elements/ethernet/truncatefcs.cc create mode 100644 elements/ethernet/truncatefcs.hh diff --git a/elements/ethernet/truncatefcs.cc b/elements/ethernet/truncatefcs.cc new file mode 100644 index 0000000000..060ea0a2cb --- /dev/null +++ b/elements/ethernet/truncatefcs.cc @@ -0,0 +1,57 @@ +// -*- mode: c++; c-basic-offset: 4 -*- +/* + * truncate.{cc,hh} -- limits packet length + * Eddie Kohler + * + * Copyright (c) 2004 Regents of the University of California + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "truncatefcs.hh" +#include +#include +#include +#include +CLICK_DECLS + +TruncateFCS::TruncateFCS() +{ +} + +int +TruncateFCS::configure(Vector &conf, ErrorHandler *errh) +{ + _extra_anno = true; + return Args(conf, this, errh) + .read("EXTRA_LENGTH", _extra_anno) + .complete(); +} + +Packet * +TruncateFCS::simple_action(Packet *p) +{ + if (_extra_anno && EXTRA_LENGTH_ANNO(p) > 4) + SET_EXTRA_LENGTH_ANNO(p, EXTRA_LENGTH_ANNO(p) - 4); + else + p->take(4); + return p; +} + +void +TruncateFCS::add_handlers() +{ +} + +CLICK_ENDDECLS +EXPORT_ELEMENT(TruncateFCS) +ELEMENT_MT_SAFE(TruncateFCS) diff --git a/elements/ethernet/truncatefcs.hh b/elements/ethernet/truncatefcs.hh new file mode 100644 index 0000000000..6d72f66c19 --- /dev/null +++ b/elements/ethernet/truncatefcs.hh @@ -0,0 +1,41 @@ +// -*- mode: c++; c-basic-offset: 4 -*- +#ifndef CLICK_TRUNCATECS_HH +#define CLICK_TRUNCATEFCS_HH +#include +CLICK_DECLS + +/* + * =c + * TruncateFCS() + * =s ethernet + * remove the FCS from packet + * =d + * Does not check if the FCS is present, therefore the packets is always shortened by 4 bytes. + * + * The EXTRA_LENGTH keyword argument determines whether packets' extra length + * annotations are updated to account for any dropped bytes. Default is true. + * =a Strip, Pad, Truncate + */ + +class TruncateFCS : public Element { public: + + TruncateFCS() CLICK_COLD; + + const char *class_name() const override { return "TruncateFCS"; } + const char *port_count() const override { return PORTS_1_1; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + bool can_live_reconfigure() const { return true; } + + Packet *simple_action(Packet *); + + void add_handlers() CLICK_COLD; + + private: + + bool _extra_anno; + +}; + +CLICK_ENDDECLS +#endif