📄 enchostetherfilter.cc
字号:
/* * enchostetherfilter.{cc,hh} -- Discard packets not for this host. * Wenjun Hu * * adapted from hostetherfilter by Robert Morris * * 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 "xorheader_general.hh"#include "enchostetherfilter.hh"CLICK_DECLSEncHostEtherFilter::EncHostEtherFilter() : HostEtherFilter(), _myea(), _aliases(0), _myalias(0) //_arp_table(0){}EncHostEtherFilter::~EncHostEtherFilter(){}/*voidHostEtherFilter::notify_noutputs(int n){ set_noutputs(n < 2 ? 1 : 2);}*/intEncHostEtherFilter::configure(Vector<String> &conf, ErrorHandler *errh){ bool drop_own = false, drop_other = true; int ret = cp_va_parse(conf, this, errh, cpKeywords, "ETH", cpEthernetAddress, "Ethernet address", &_myea, "ALIASTABLE", cpElement, "Alias Table", &_aliases, cpOptional, cpKeywords, "DROP_OWN", cpBool, "Drop packets from us?", &drop_own, "DROP_OTHER", cpBool, "Drop packets to others?", &drop_other, cpEnd); if (!_myea) return errh->error("ETH not specified"); if (!_aliases) return errh->error("ALIASTABLE not specified"); if (_aliases->cast("AliasTable") == 0) return errh->error("ALIASTABLE element is not an AliasTable"); _drop_own = drop_own; _drop_other = drop_other; _myalias = _aliases->lookup(_myea); click_chatter("enchostfilter lookup"); return ret;}Packet *EncHostEtherFilter::drop(Packet *p){ if (noutputs() == 2) output(1).push(p); else p->kill(); return 0;}Packet *EncHostEtherFilter::simple_action(Packet *p){ click_ether *e = (click_ether *) p->data(); unsigned short *daddr = (unsigned short *)e->ether_dhost; struct click_xorn_header *xorh = (struct click_xorn_header *)(e + 1); click_chatter("%s packet length %d", id().cc(), p->length()); if (_drop_own && memcmp(e->ether_shost, _myea.data(), 6) == 0) return drop(p); else if (memcmp(e->ether_dhost, _myea.data(), 6) == 0) { p->set_packet_type_anno(Packet::HOST); click_chatter("%s packet meant for me", id().cc()); return p; } else if (daddr[0] == 0xFFFF && daddr[1] == 0xFFFF && daddr[2] == 0xFFFF) { p->set_packet_type_anno(Packet::BROADCAST); return p; } else if (e->ether_dhost[0] & 0x80) { p->set_packet_type_anno(Packet::MULTICAST); return p; } else { // update the header with the 'right' ether address and decide further... // see scramblequeue.cc for how dest etheraddress of encoded packet is assigned // the current etheraddress should correspond to prev_hop[0] // so the alternative should be the other // this might change in future... // brute force for now, could put into a loop later int nentries = xorh->nentries(); click_chatter("%s coded packet", id().cc()); for (int i = 0; i < nentries; i++) { if (xorh->get_entry_alias(i) == _myalias) { click_chatter("%s encoded packet meant for me", id().cc()); p->set_packet_type_anno(Packet::HOST); memcpy(e->ether_dhost, _myea.data(), 6); return p; } }// if ((xorh->_alias[0] == _myalias) || (xorh->_alias[1] == _myalias)) {// p->set_packet_type_anno(Packet::HOST);// memcpy(e->ether_dhost, _myea.data(), 6);// return p;// } else { p->set_packet_type_anno(Packet::OTHERHOST); return (_drop_other ? drop(p) : p); /* EtherAddress dst = _arp_table->lookup(ip); EtherAddress alt_dst = _arp_table->lookup(alt_ip); // debugging click_chatter("%{element}: IP %s, MAC %s, IP %s, MAC %s", this, ip.s().cc(), dst.s().cc(), alt_ip.s().cc(), alt_dst.s().cc()); // brute force... if (memcmp(_addr, dst.data(), 6) == 0) { p->set_packet_type_anno(Packet::HOST); memcpy(e->ether_dhost, dst.data(), 6); return p; } else if (memcmp(_addr, alt_dst.data(), 6) == 0) { p->set_packet_type_anno(Packet::HOST); memcpy(e->ether_dhost, alt_dst.data(), 6); return p; } else if (dst == _arp_table->_bcast) { click_chatter("%{element}::%s arp lookup failed for %s", this, __func__, ip.s().cc()); p->set_packet_type_anno(Packet::BROADCAST); return p; } else if (alt_dst == _arp_table->_bcast) { click_chatter("%{element}::%s arp lookup failed for %s", this, __func__, alt_ip.s().cc()); p->set_packet_type_anno(Packet::BROADCAST); return p; } else { p->set_packet_type_anno(Packet::OTHERHOST); return (_drop_other ? drop(p) : p); } memcpy(e->ether_dhost, alt_dst.data(), 6); if (alt_dst == _arp_table->_bcast) { click_chatter("%{element}::%s arp lookup failed for %s", this, __func__, alt_ip.s().cc()); p->set_packet_type_anno(Packet::BROADCAST); return p; } else if (memcmp(e->ether_dhost, _addr, 6) == 0){ p->set_packet_type_anno(Packet::HOST); return p; } else { p->set_packet_type_anno(Packet::OTHERHOST); return (_drop_other ? drop(p) : p); } */ }}CLICK_ENDDECLSEXPORT_ELEMENT(EncHostEtherFilter)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -