-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This patch allows to add or del entries from the ARPResponder Element
- --
Harald Schiöberg
Technische Universität Berlin | T-Laboratories | FG INET
www: http://www.net.t-labs.tu-berlin.de
Phone: +49-(0)30-8353-58476 | Fax: +49-(0)391 534 783 47
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFKfFAFy8wrZ9OvkU0RAp1CAKCCLHAYb3MpQe+JnRkFAp0isr+wVQCgmWrF
yAYaG8cKe+vy97MOfNtEM8E=
=0Xvi
-----END PGP SIGNATURE-----
diff --git a/elements/ethernet/arpresponder.cc b/elements/ethernet/arpresponder.cc
index 87f3c30..160553d 100644
--- a/elements/ethernet/arpresponder.cc
+++ b/elements/ethernet/arpresponder.cc
@@ -207,10 +207,74 @@ ARPResponder::read_handler(Element *e, void *thunk)
}
}
+int
+ARPResponder::add_handler(const String &s, Element *e, void *, ErrorHandler *errh)
+{
+ ARPResponder *ar = static_cast<ARPResponder *>(e);
+ IPAddress ipa, mask;
+ EtherAddress ena;
+ bool have_ena = false;
+ int first = ar->_v.size();
+
+ Vector<String> words;
+ cp_spacevec(s, words);
+ for (int j = 0; j < words.size(); j++)
+ if (cp_ip_address(words[j], &ipa, ar))
+ ar->add_map(ipa, IPAddress(0xFFFFFFFFU), EtherAddress());
+ else if (cp_ip_prefix(words[j], &ipa, &mask, ar))
+ ar->add_map(ipa, mask, EtherAddress());
+ else if (cp_ethernet_address(words[j], &ena, ar)) {
+ if (have_ena)
+ errh->error("argument has more than one Ethernet address");
+ have_ena = true;
+ } else {
+ errh->error("argument should be 'IP/MASK ETHADDR'");
+ j = words.size();
+ }
+ // check for an argument that is both IP address and Ethernet address
+ for (int j = 0; !have_ena && j < words.size(); j++)
+ if (cp_ethernet_address(words[j], &ena, ar))
+ have_ena = true;
+
+ if (!have_ena)
+ errh->error("argument had no Ethernet addresses");
+ for (int j = first; j < ar->_v.size(); j++)
+ ar->_v[j].ena = ena;
+
+ return 200;
+}
+
+int
+ARPResponder::del_handler(const String &s, Element *e, void *, ErrorHandler *errh)
+{
+
+ ARPResponder *ar = static_cast<ARPResponder *>(e);
+ IPAddress ipa, mask;
+ if (cp_ip_address(s, &ipa, ar))
+ mask = IPAddress(0xFFFFFFFFU);
+ else if (! cp_ip_prefix(s, &ipa, &mask, ar))
+ errh->error("Argument is not an IP address or prefix");
+ ipa &= mask;
+
+ int found = 0;
+ for (int j = 0; j < ar->_v.size(); j++) {
+ if ( ar->_v[j].dst == ipa ) {
+ ar->_v.erase(ar->_v.begin() + j);
+ found++;
+ }
+ }
+ if (! found)
+ errh->error("%s not found", ipa.s().c_str());
+ return 200;
+}
+
+
void
ARPResponder::add_handlers()
{
add_read_handler("table", read_handler, (void *)0);
+ add_write_handler("add", add_handler, (void *)0);
+ add_write_handler("del", del_handler, (void *)0);
}
EXPORT_ELEMENT(ARPResponder)
diff --git a/elements/ethernet/arpresponder.hh b/elements/ethernet/arpresponder.hh
index 48740a9..7716830 100644
--- a/elements/ethernet/arpresponder.hh
+++ b/elements/ethernet/arpresponder.hh
@@ -39,7 +39,18 @@ CLICK_DECLS
* equivalent to C<ARPResponder(IP ETH)>. If C<NAME> is short for both an IP
* address and an IP network address, then ARPResponder will prefer the IP
* address. (You can say C<NAME:ipnet> to use the IP network address.)
- *
+ *
+ * =h add write
+ *
+ * Add a new configuration entry
+ * takes the same format as one configuration item
+ *
+ * =h del write
+ *
+ * Delete a configuration entry
+ * takes an IPAddress with or without mask
+ *
+ *
* =e
*
* Produce ARP replies for the local machine (18.26.4.24)
@@ -92,6 +103,9 @@ private:
void add_map(IPAddress dst, IPAddress mask, EtherAddress);
static String read_handler(Element *, void *);
+
+ static int add_handler(const String &s, Element *e, void *, ErrorHandler *errh);
+ static int del_handler(const String &s, Element *e, void *, ErrorHandler *errh);
};
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click