|
| 1 | +/* |
| 2 | + * EtherRewrite.{cc,hh} -- encapsulates packet in Ethernet header |
| 3 | + * Tom Barbette |
| 4 | + * |
| 5 | + * Copyright (c) 2015 University of Liege |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | + * copy of this software and associated documentation files (the "Software"), |
| 9 | + * to deal in the Software without restriction, subject to the conditions |
| 10 | + * listed in the Click LICENSE file. These conditions include: you must |
| 11 | + * preserve this copyright notice, and you cannot mention the copyright |
| 12 | + * holders in advertising related to the Software without their permission. |
| 13 | + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This |
| 14 | + * notice is a summary of the Click LICENSE file; the license in that file is |
| 15 | + * legally binding. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <click/config.h> |
| 19 | +#include "etherrewrite.hh" |
| 20 | +#include <click/etheraddress.hh> |
| 21 | +#include <click/args.hh> |
| 22 | +#include <click/error.hh> |
| 23 | +#include <click/glue.hh> |
| 24 | +CLICK_DECLS |
| 25 | + |
| 26 | +EtherRewrite::EtherRewrite() |
| 27 | +{ |
| 28 | +} |
| 29 | + |
| 30 | +EtherRewrite::~EtherRewrite() |
| 31 | +{ |
| 32 | +} |
| 33 | + |
| 34 | +int |
| 35 | +EtherRewrite::configure(Vector<String> &conf, ErrorHandler *errh) |
| 36 | +{ |
| 37 | + if (Args(conf, this, errh) |
| 38 | + .read_mp("SRC", EtherAddressArg(), _ethh.ether_shost) |
| 39 | + .read_mp("DST", EtherAddressArg(), _ethh.ether_dhost) |
| 40 | + .complete() < 0) |
| 41 | + return -1; |
| 42 | + return 0; |
| 43 | +} |
| 44 | + |
| 45 | +inline Packet * |
| 46 | +EtherRewrite::smaction(Packet *p) |
| 47 | +{ |
| 48 | + WritablePacket* q = p->uniqueify(); |
| 49 | + if (q) { |
| 50 | + memcpy(q->mac_header(), &_ethh, 12); |
| 51 | + } |
| 52 | + return q; |
| 53 | +} |
| 54 | + |
| 55 | +void |
| 56 | +EtherRewrite::push(int, Packet *p) |
| 57 | +{ |
| 58 | + if (Packet *q = smaction(p)) |
| 59 | + output(0).push(q); |
| 60 | +} |
| 61 | + |
| 62 | +Packet * |
| 63 | +EtherRewrite::pull(int) |
| 64 | +{ |
| 65 | + if (Packet *p = input(0).pull()) |
| 66 | + return smaction(p); |
| 67 | + else |
| 68 | + return 0; |
| 69 | +} |
| 70 | + |
| 71 | +void |
| 72 | +EtherRewrite::add_handlers() |
| 73 | +{ |
| 74 | + add_data_handlers("src", Handler::h_read, reinterpret_cast<EtherAddress *>(&_ethh.ether_shost)); |
| 75 | + add_write_handler("src", reconfigure_keyword_handler, "1 SRC"); |
| 76 | + add_data_handlers("dst", Handler::h_read, reinterpret_cast<EtherAddress *>(&_ethh.ether_dhost)); |
| 77 | + add_write_handler("dst", reconfigure_keyword_handler, "2 DST"); |
| 78 | +} |
| 79 | + |
| 80 | +CLICK_ENDDECLS |
| 81 | +EXPORT_ELEMENT(EtherRewrite) |
0 commit comments