📄 checkgridheader.cc
字号:
/* * checkgridheader.{cc,hh} -- element checks Grid header for correctness * (checksums, lengths) * Douglas S. J. De Couto * from checkipheader.{cc,hh} by Robert Morris * * Copyright (c) 1999-2000 Massachusetts Institute of Technology * * 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 <click/confparse.hh>#include "checkgridheader.hh"#include <click/glue.hh>#include "grid.hh"#include <clicknet/ether.h>#include <clicknet/ip.h>CLICK_DECLSCheckGridHeader::CheckGridHeader() : _drops(0){ add_input(); add_output();}CheckGridHeader::~CheckGridHeader(){}voidCheckGridHeader::notify_noutputs(int n){ set_noutputs(n < 2 ? 1 : 2);}voidCheckGridHeader::drop_it(Packet *p){ if (_drops == 0) click_chatter("CheckGridHeader %s: Grid checksum failed", id().cc()); _drops++; if (noutputs() == 2) output(1).push(p); else p->kill();}Packet *CheckGridHeader::simple_action(Packet *p){ grid_hdr *gh = (grid_hdr *) (p->data() + sizeof(click_ether)); if(p->length() < sizeof(click_ether) + sizeof(grid_hdr)) { #if 1 click_chatter("%s: packet truncated", id().cc());#endif goto bad; } unsigned int hlen, tlen; hlen = gh->hdr_len; tlen = ntohs(gh->total_len); /* grid header size keeps changing if(hlen < sizeof(grid_hdr)) goto bad; */ if (ntohl(gh->version) != grid_hdr::GRID_VERSION) { click_chatter ("%s: unknown grid version %x", id().cc(), ntohl(gh->version)); p->kill(); return 0; } if (tlen + sizeof(click_ether) > p->length()) { /* can only check inequality, as short packets are padded to a minimum frame size for wavelan and ethernet */#if 1 click_chatter("%s: bad packet size, wanted %d, only got %d", id().cc(), tlen + sizeof(click_ether), p->length());#endif goto bad; } if (click_in_cksum((unsigned char *) gh, tlen) != 0) {#if 1 click_chatter("%s: bad Grid checksum", id().cc()); click_chatter("%s: length: %d, cksum: 0x%.4x", id().cc(), p->length(), (unsigned long) ntohs(gh->cksum));#endif goto bad; } return(p); bad: drop_it(p); return 0;}static StringCheckGridHeader_read_drops(Element *xf, void *){ CheckGridHeader *f = (CheckGridHeader *)xf; return String(f->drops()) + "\n";}voidCheckGridHeader::add_handlers(){ add_read_handler("drops", CheckGridHeader_read_drops, 0);}CLICK_ENDDECLSEXPORT_ELEMENT(CheckGridHeader)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -