Skip to content
Extraits de code Groupes Projets
Valider a80fb23f rédigé par eddietwo's avatar eddietwo
Parcourir les fichiers

fixed bugs caused by bad assumption. Code assumed that after cp_ip_prefix(str,...

fixed bugs caused by bad assumption. Code assumed that after cp_ip_prefix(str, &ip, &mask), you must have (ip & ~mask) == 0. This was NOT in fact true. So added some explicit maskings (basically, ip &= mask).
parent 6e9d4949
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -29,6 +29,7 @@
#include <click/confparse.hh>
#include <click/error.hh>
#include <click/glue.hh>
#include <click/straccum.hh>
ARPResponder::ARPResponder()
: Element(1, 1)
......@@ -51,7 +52,7 @@ void
ARPResponder::add_map(IPAddress ipa, IPAddress mask, EtherAddress ena)
{
struct Entry e;
e._dst = ipa;
e._dst = ipa & mask;
e._mask = mask;
e._ena = ena;
_v.push_back(e);
......@@ -73,10 +74,10 @@ ARPResponder::configure(const Vector<String> &conf, ErrorHandler *errh)
cp_spacevec(conf[i], words);
for (int j = 0; j < words.size(); j++)
if (cp_ip_prefix(words[j], &ipa, &mask, this))
add_map(ipa, mask, EtherAddress());
else if (cp_ip_address(words[j], &ipa, this))
if (cp_ip_address(words[j], &ipa, this))
add_map(ipa, IPAddress(0xFFFFFFFFU), EtherAddress());
else if (cp_ip_prefix(words[j], &ipa, &mask, this))
add_map(ipa, mask, EtherAddress());
else if (cp_ethernet_address(words[j], &ena, this)) {
if (have_ena)
errh->error("argument %d has more than one Ethernet address", i);
......@@ -186,6 +187,31 @@ ARPResponder::simple_action(Packet *p)
return(q);
}
String
ARPResponder::read_handler(Element *e, void *thunk)
{
ARPResponder *ar = static_cast<ARPResponder *>(e);
switch ((int)thunk) {
case 0: { // table
StringAccum sa;
for (int i = 0; i < ar->_v.size(); i++)
sa << ar->_v[i]._dst << '/' << ar->_v[i]._mask << ' ' << ar->_v[i]._ena << '\n';
return sa.take_string();
}
default:
return "<error>\n";
}
}
void
ARPResponder::add_handlers()
{
add_read_handler("table", read_handler, (void *)0);
}
EXPORT_ELEMENT(ARPResponder)
// generate Vector template instance
......
......@@ -20,10 +20,13 @@
* (`C<18.26.7.0/24>').
*
* =n
*
* AddressInfo elements can simplify the arguments to ARPResponder. In
* particular, if C<NAME> is shorthand for both an IP network address (or IP
* address) C<IP> and an Ethernet address C<ETH>, then C<ARPResponder(NAME)>
* is equivalent to C<ARPResponder(IP ETH)>.
* address) C<IP> and an Ethernet address C<ETH>, then C<ARPResponder(NAME)> is
* 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.)
*
* =e
* Produce ARP replies for the local machine (18.26.4.24)
......@@ -51,7 +54,9 @@ class ARPResponder : public Element { public:
const char *class_name() const { return "ARPResponder"; }
const char *processing() const { return AGNOSTIC; }
ARPResponder *clone() const;
int configure(const Vector<String> &, ErrorHandler *);
void add_handlers();
Packet *simple_action(Packet *);
......@@ -70,6 +75,8 @@ private:
Vector<Entry> _v;
void add_map(IPAddress dst, IPAddress mask, EtherAddress);
static String read_handler(Element *, void *);
};
......
......@@ -55,8 +55,9 @@ IPTable::lookup(unsigned dst, unsigned &gw, int &index)
void
IPTable::add(unsigned dst, unsigned mask, unsigned gw, int index)
{
struct Entry e;
dst &= mask;
struct Entry e;
e._dst = dst;
e._mask = mask;
e._gw = gw;
......
......@@ -41,6 +41,8 @@ IPTable2::~IPTable2()
void
IPTable2::add(unsigned dst, unsigned mask, unsigned gw)
{
dst &= mask;
for(int i = 0; i < _v.size(); i++)
if(_v[i]._valid && (_v[i]._dst == dst) && (_v[i]._mask == mask))
return;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter