📄 recpfilter.cc
字号:
/* * ackfilter.{cc,hh} -- Picks up ack header for encoded packets * Wenjun Hu * * Copyright (c) 2005 University of Cambridge * Copyright (c) 2005 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 <click/error.hh>#include <click/glue.hh>#include <click/etheraddress.hh>#include <clicknet/ether.h>#include <click/straccum.hh>#include <click/timestamp.hh>#include <click/string.hh>#include "recpheader.hh"#include "recpfilter.hh"CLICK_DECLSRecpFilter::RecpFilter() : Element(1, 2), _et(0), _et_nothing(0){}RecpFilter::~RecpFilter(){}intRecpFilter::configure(Vector<String> &conf, ErrorHandler *errh){ int ret = cp_va_parse(conf, this, errh, cpKeywords, "ETHTYPE", cpUnsigned, "Ethernet Recp encapsulation type", &_et, "NOTHINGETHTYPE", cpUnsigned, "Nothing Ethernet Encapsulation type", &_et_nothing, cpEnd); if (!_et) return errh->error("ETHTYPE not specified"); if (!_et_nothing) return errh->error("NOTHINGETHTYPE not specified"); return ret;}voidRecpFilter::push(int, Packet *p){ click_ether *eh = (click_ether *) p->data(); EtherAddress src = EtherAddress(eh->ether_shost); EtherAddress dst = EtherAddress(eh->ether_dhost); uint16_t ethtype = eh->ether_type; if (ethtype != htons(_et)) { output(0).push(p); return; } click_chatter("recpfilter received a packet with recpheader and ethtype %04x at %u", ntohs(ethtype), Timestamp::now().msec1()); // has an recp header, try to separate that into another precpet struct click_enc_recp *recph = (struct click_enc_recp *)(eh + 1); uint8_t hlen = recph->get_hlen(recph->nentries()); recph = (struct click_enc_recp*) malloc(hlen); memcpy(recph, (struct click_enc_recp*)(eh+1), hlen); int recplen = sizeof(click_ether) + hlen; WritablePacket *recppkt = Packet::make(recplen); if (!recppkt) return; StringAccum sa; sa << "push() separating recp packet from ea " << EtherAddress(src); click_chatter("%s %s", id().cc(), sa.c_str()); memcpy(recppkt->data(), p->data(), recplen); output(1).push(recppkt); if (recph->_et_next == htons(_et_nothing)) return; // a pure recp packet click_chatter("%s : pushing the data packet", id().cc()); // sort out the original precpet too WritablePacket *wp = p->uniqueify(); wp->pull(recplen); // not sure about this offset...*** wp = wp->push(sizeof(click_ether)); click_ether *oeth = (click_ether *)wp->data(); memcpy(oeth->ether_dhost, dst.data(), 6); memcpy(oeth->ether_shost, src.data(), 6); oeth->ether_type = recph->_et_next; sa.clear(); sa << "Source EA " << src << " Dst EA " << dst; click_chatter("%s data packet %s %#x", id().cc(), sa.c_str(), ntohs(recph->_et_next)); output(0).push(wp);}CLICK_ENDDECLSEXPORT_ELEMENT(RecpFilter)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -