Skip to content

Commit

Permalink
More exception removal code.
Browse files Browse the repository at this point in the history
Gah, this is taking forever!
  • Loading branch information
greearb committed Sep 13, 2017
1 parent d2ee0d7 commit 55e1ba9
Show file tree
Hide file tree
Showing 50 changed files with 1,065 additions and 1,034 deletions.
53 changes: 23 additions & 30 deletions xorp/bgp/peer.cc
Expand Up @@ -1272,33 +1272,27 @@ BGPPeer::event_open(const XorpFd sock)
}

void
BGPPeer::check_open_packet(const OpenPacket *p) throw(CorruptMessage)
BGPPeer::check_open_packet(const OpenPacket *p, CorruptMessage& m)
{
if (p->Version() != BGPVERSION) {
static uint8_t data[2];
embed_16(data, BGPVERSION);
xorp_throw(CorruptMessage,
c_format("Unsupported BGPVERSION %d", p->Version()),
OPENMSGERROR, UNSUPVERNUM, &data[0], sizeof(data));
INVALID_BGP(OPENMSGERR, UNSUPVERNUM, "Unsupported BGPVERSION %d", p->Version());
}

if (p->as() != _peerdata->as()) {
debug_msg("**** Peer has %s, should have %s ****\n",
p->as().str().c_str(),
_peerdata->as().str().c_str());
xorp_throw(CorruptMessage,
c_format("Wrong AS %s expecting %s",
p->as().str().c_str(),
_peerdata->as().str().c_str()),
OPENMSGERROR, BADASPEER);
INVALID_BGP(OPENMSGERROR, BADASPEER, "Wrong AS %s expecting %s",
p->as().str().c_str(),
_peerdata->as().str().c_str());
}

// Must be a valid unicast IP host address.
if (!p->id().is_unicast() || p->id().is_zero()) {
xorp_throw(CorruptMessage,
c_format("Not a valid unicast IP host address %s",
p->id().str().c_str()),
OPENMSGERROR, BADBGPIDENT);
INVALID_BGP(OPENMSGERROR, BADBGPIDENT, "Not a valid unicast IP host address %s",
p->id().str().c_str());
}

// This has to be a valid IPv4 address.
Expand All @@ -1309,9 +1303,8 @@ BGPPeer::check_open_packet(const OpenPacket *p) throw(CorruptMessage)
// check the received parameters
#if 0
if (_peerdata->unsupported_parameters() == true)
xorp_throw(CorruptMessage,
c_format("Unsupported parameters"),
OPENMSGERROR, UNSUPOPTPAR);
INVALID_BGP(OPENMSGERROR, UNSUPOPTPAR,
c_format("Unsupported parameters"));
#endif
/*
* Set the holdtime and keepalive times.
Expand All @@ -1327,9 +1320,7 @@ BGPPeer::check_open_packet(const OpenPacket *p) throw(CorruptMessage)
*/
uint16_t hold_secs = p->HoldTime();
if (hold_secs == 1 || hold_secs == 2)
xorp_throw(CorruptMessage,
c_format("Illegal holdtime value %d secs", hold_secs),
OPENMSGERROR, UNACCEPTHOLDTIME);
INVALID_BGP(OPENMSGERROR, UNACCEPTHOLDTIME, "Illegal holdtime value %d secs", hold_secs);

if (_peerdata->get_configured_hold_time() < hold_secs)
hold_secs = _peerdata->get_configured_hold_time();
Expand Down Expand Up @@ -2608,16 +2599,19 @@ AcceptSession::get_message_accept(BGPPacket::Status status,

const uint8_t* marker = buf + BGPPacket::MARKER_OFFSET;
uint8_t type = extract_8(buf + BGPPacket::TYPE_OFFSET);
try {
/*
** Check the Marker, total waste of time as it never contains
** anything of interest.
*/
if (0 != memcmp(const_cast<uint8_t *>(&BGPPacket::Marker[0]),
marker, BGPPacket::MARKER_SIZE)) {
xorp_throw(CorruptMessage,"Bad Marker", MSGHEADERERR, CONNNOTSYNC);
}


CorruptMessage m;

/*
** Check the Marker, total waste of time as it never contains
** anything of interest.
*/
if (0 != memcmp(const_cast<uint8_t *>(&BGPPacket::Marker[0]),
marker, BGPPacket::MARKER_SIZE)) {
INVALID_BGP(MSGHEADERERR, CANNOTSYNC, "Bad Marker");
}

TODO
switch (type) {
case MESSAGETYPEOPEN: {
debug_msg("OPEN Packet RECEIVED\n");
Expand All @@ -2627,7 +2621,6 @@ AcceptSession::get_message_accept(BGPPacket::Status status,
peerdata()->iptuple().str().c_str(),
cstring(pac)));

// All decode errors should throw a CorruptMessage.
debug_msg("%s", pac.str().c_str());
// want unified decode call. now need to get peerdata out.
// _peerdata->dump_peer_data();
Expand Down
14 changes: 7 additions & 7 deletions xorp/libproto/config_node_id.hh
Expand Up @@ -63,8 +63,8 @@ public:
*
* @param s the initialization string.
*/
explicit ConfigNodeId(const string& s) {
copy_in(s);
explicit ConfigNodeId(const string& s, string& err) {
copy_in(s, err);
}

#ifdef XORP_USE_USTL
Expand All @@ -91,7 +91,7 @@ public:
* @param from_string the string to copy the node ID from.
* @return the number of copied octets.
*/
size_t copy_in(const string& from_string);
size_t copy_in(const string& from_string, string& err);

/**
* Equality Operator
Expand Down Expand Up @@ -365,7 +365,7 @@ private:
};

inline size_t
ConfigNodeId::copy_in(const string& from_string)
ConfigNodeId::copy_in(const string& from_string, string& err)
{
string::size_type space, ix;
string s = from_string;
Expand All @@ -380,7 +380,7 @@ ConfigNodeId::copy_in(const string& from_string)

space = s.find(' ');
if ((space == string::npos) || (space == 0) || (space >= s.size() - 1)) {
XLOG_WARNING("Bad ConfigNodeId \"%s\"", s.c_str());
err += c_format("Bad ConfigNodeId \"%s\"", s.c_str());
set_invalid(true);
return 0;
}
Expand All @@ -391,14 +391,14 @@ ConfigNodeId::copy_in(const string& from_string)
//
for (ix = 0; ix < space; ix++) {
if (! xorp_isdigit(s[ix])) {
XLOG_WARNING("Bad ConfigNodeId \"%s\"", s.c_str());
err = c_format("Bad ConfigNodeId \"%s\"", s.c_str());
set_invalid(true);
return 0;
}
}
for (ix = space + 1; ix < s.size(); ix++) {
if (! xorp_isdigit(s[ix])) {
XLOG_WARNING("Bad ConfigNodeId \"%s\"", s.c_str());
err = c_format("Bad ConfigNodeId \"%s\"", s.c_str());
set_invalid(true);
return 0;
}
Expand Down
7 changes: 6 additions & 1 deletion xorp/libxorp/profile.hh
Expand Up @@ -19,7 +19,6 @@
// XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

// $XORP: xorp/libxorp/profile.hh,v 1.18 2008/10/02 21:57:32 bms Exp $

#ifndef __LIBXORP_PROFILE_HH__
#define __LIBXORP_PROFILE_HH__
Expand Down Expand Up @@ -126,6 +125,12 @@ class Profile {
return i->second->enabled();
}

/* Ignore any error messages */
bool log_ne(const string& pname, string comment) {
string e;
return log(pname, comment, e);
}

/**
* Add an entry to the profile log.
*/
Expand Down
16 changes: 7 additions & 9 deletions xorp/libxorp/range.hh
Expand Up @@ -36,35 +36,33 @@ class IPv6;
* (_low <= _high) always holds!
*/
template <class T>
class Range {
class Range : public Invalid {
public:
/**
* Default constructor
*/
Range() { _invalid = false; }
Range() { }
virtual ~Range() { }

/**
* Constructor from a single value.
*/
explicit Range(T value) { _low = _high = value; _invalid = false; }
explicit Range(T value) { _low = _high = value; }

/**
* Constructor from two values.
*/
explicit Range(T low, T high) {
_low = low;
_high = high;
_invalid = false;
}

const T& low() const { return _low; }
const T& high() const { return _high; }
virtual bool invalid() const { return _invalid; }

protected:
T _low;
T _high;
bool _invalid;
};

/**
Expand Down Expand Up @@ -102,7 +100,7 @@ public:
_low = strtoul(from_string.substr(0, delim).c_str(), NULL, 10);
_high = strtoul(from_string.substr(delim + 2, from_string.length()).c_str(), NULL, 10);
} else {
_invalid = true;
set_invalid(true);
XLOG_WARNING("Syntax error: %s", from_cstr);
}
}
Expand Down Expand Up @@ -163,7 +161,7 @@ public:
_low = strtoul(from_string.substr(0, delim).c_str(), NULL, 10);
_high = strtoul(from_string.substr(delim + 2, from_string.length()).c_str(), NULL, 10);
} else {
_invalid = true;
set_invalid(true);
XLOG_WARNING("Syntax error: %s", from_cstr);
}
}
Expand Down Expand Up @@ -375,7 +373,7 @@ public:
from_string.length())
.c_str());
} else {
Range<T>::_invalid = true;
Invalid::set_invalid(true);
XLOG_WARNING("Syntax error: %s", from_cstr);
}
}
Expand Down
9 changes: 5 additions & 4 deletions xorp/policy/configuration.cc
Expand Up @@ -93,21 +93,22 @@ Configuration::update_term_block(const string& policy,
}
}

void
bool
Configuration::create_term(const string& policy, const ConfigNodeId& order,
const string& term)
const string& term, string& err)
{
PolicyStatement& ps = _policies.find(policy);

if (ps.term_exists(term)) {
xorp_throw(ConfError,
"Term " + term + " exists already in policy " + policy);
err += "Term " + term + " exists already in policy " + policy;
return false;
}

Term* t = new Term(term);

ps.add_term(order, t);
policy_modified(policy);
return true;
}

void
Expand Down
5 changes: 2 additions & 3 deletions xorp/policy/configuration.hh
Expand Up @@ -18,7 +18,6 @@
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

// $XORP: xorp/policy/configuration.hh,v 1.20 2008/10/02 21:57:58 bms Exp $

#ifndef __POLICY_CONFIGURATION_HH__
#define __POLICY_CONFIGURATION_HH__
Expand Down Expand Up @@ -147,8 +146,8 @@ public:
* @param order node ID with position of term.
* @param term term name which should be created.
*/
void create_term(const string& policy, const ConfigNodeId& order,
const string& term);
bool create_term(const string& policy, const ConfigNodeId& order,
const string& term, string& err);

/**
* Throws an exception on failure.
Expand Down
6 changes: 3 additions & 3 deletions xorp/policy/policy_target.cc
Expand Up @@ -60,11 +60,11 @@ PolicyTarget::shutdown()
}


void
bool
PolicyTarget::create_term(const string& policy, const ConfigNodeId& order,
const string& term)
const string& term, string& err)
{
_conf.create_term(policy, order, term);
return _conf.create_term(policy, order, term, err);
}

void
Expand Down
5 changes: 2 additions & 3 deletions xorp/policy/policy_target.hh
Expand Up @@ -18,7 +18,6 @@
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

// $XORP: xorp/policy/policy_target.hh,v 1.19 2008/10/02 21:57:59 bms Exp $

#ifndef __POLICY_POLICY_TARGET_HH__
#define __POLICY_POLICY_TARGET_HH__
Expand Down Expand Up @@ -67,8 +66,8 @@ public:
* @param order node ID with position of term.
* @param term name of term to create.
*/
void create_term(const string& policy, const ConfigNodeId& order,
const string& term);
bool create_term(const string& policy, const ConfigNodeId& order,
const string& term, string& err);

/**
* Attempts to delete a term.
Expand Down
18 changes: 9 additions & 9 deletions xorp/policy/xrl_target.cc
Expand Up @@ -89,20 +89,19 @@ XrlPolicyTarget::policy_0_1_create_term(const string& policy,
const string& term)
{
ConfigNodeId config_node_id(ConfigNodeId::ZERO());
string err;

config_node_id.copy_in(order);
config_node_id.copy_in(order, err);
if (config_node_id.invalid()) {
return XrlCmdError::COMMAND_FAILED("Create of policy " + policy
+ " term " + term + " failed "
+ "because of invalid node ID "
+ "\"" + order + "\" : ");
+ "\"" + order + "\" : " + err);
}

try {
_policy_target.create_term(policy, config_node_id, term);
} catch(const PolicyException& e) {
return XrlCmdError::COMMAND_FAILED("create_term failed: " + e.str());
}
if (!_policy_target.create_term(policy, config_node_id, term, err))
return XrlCmdError::COMMAND_FAILED("create_term failed: " + err);

return XrlCmdError::OKAY();
}

Expand All @@ -128,13 +127,14 @@ XrlPolicyTarget::policy_0_1_update_term_block(const string& policy,
const string& statement)
{
ConfigNodeId config_node_id(ConfigNodeId::ZERO());
string err;

config_node_id.copy_in(order);
config_node_id.copy_in(order, err);
if (config_node_id.invalid()) {
return XrlCmdError::COMMAND_FAILED("Update of policy " + policy
+ " term " + term + " failed "
+ "because of invalid node ID "
+ "\"" + order + "\" : ");
+ "\"" + order + "\" : " + err);
}
try {
_policy_target.update_term_block(policy, term, block, config_node_id,
Expand Down
3 changes: 2 additions & 1 deletion xorp/rib/profile_vars.cc
Expand Up @@ -40,7 +40,8 @@ struct profile_vars {
void
initialize_profiling_variables(Profile& p)
{
string e;
for (size_t i = 0; i < sizeof(profile_vars) / sizeof(struct profile_vars);
i++)
p.create(profile_vars[i].var, profile_vars[i].comment);
p.create(profile_vars[i].var, profile_vars[i].comment, e);
}

0 comments on commit 55e1ba9

Please sign in to comment.