Skip to content

Commit

Permalink
TruncateFCS: new element to truncate the FCS
Browse files Browse the repository at this point in the history
Removes FCS from ethernet frames.

In practice, just removes 4 bytes...
  • Loading branch information
tbarbette committed Oct 24, 2023
1 parent bd9824c commit a448c24
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
57 changes: 57 additions & 0 deletions elements/ethernet/truncatefcs.cc
Original file line number Diff line number Diff line change
@@ -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 <click/config.h>
#include "truncatefcs.hh"
#include <click/args.hh>
#include <click/error.hh>
#include <click/glue.hh>
#include <click/packet_anno.hh>
CLICK_DECLS

TruncateFCS::TruncateFCS()
{
}

int
TruncateFCS::configure(Vector<String> &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)
41 changes: 41 additions & 0 deletions elements/ethernet/truncatefcs.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// -*- mode: c++; c-basic-offset: 4 -*-
#ifndef CLICK_TRUNCATECS_HH
#define CLICK_TRUNCATEFCS_HH
#include <click/element.hh>
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<String> &, 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

0 comments on commit a448c24

Please sign in to comment.