revised extended autnum patch, was: Re: Bit of tweaking to IRRToolSet web site
S.P.Zeidler
spz at serpens.de
Sat Feb 14 18:03:42 UTC 2009
Thus wrote Nick Hilliard (nick at inex.ie):
> Your patch causes gcc to get upset. I'll post an update to it shortly.
> Looks like a header problem, but I'm not on my dev box at the moment.
It had a bit more problems than that (among these being unnecessarily
complicated). Attached a patch that compliles and works as far as I could
test it. Simple test case:
peval -asplain -no-as AS3.3
To invert the preference between asplain and asdot, initialize opt_asdot
as false and rename the option (-asplain) to -asdot.
regards,
spz
--
spz at serpens.de (S.P.Zeidler)
-------------- next part --------------
Index: src/prtraceroute/prtraceroute.cc
===================================================================
--- src/prtraceroute/prtraceroute.cc (revision 221)
+++ src/prtraceroute/prtraceroute.cc (working copy)
@@ -103,6 +103,7 @@
extern IRR * irr; // defined in irr.cc
int opt_rusage = 0;
+bool opt_asdot = true;
int policy_flag = 1;
int nflag = 0;
@@ -171,6 +172,7 @@
ICMPProbeReply reply; // wait for incoming icmp's
Timer t1, t2;
int ttl, got_there = 0, unreachable = 0;
+ char buf[64];
printf ("prtraceroute to %s (%s), %d hops max, %d byte packets\n",
dst, dstip->getIpaddr(), max_ttl, datalen);
@@ -192,7 +194,8 @@
ipAddr *ipaddr = new ipAddr (newaddr);
if (policy_flag) {
path.addHop(ipaddr, ttl);
- printf (" [AS%d]", path.getHopAS(ttl));
+ asnum_string(buf, path.getHopAS(ttl));
+ printf (" [%s]", buf);
}
if (!nflag) {
printf (" %s (%s)", ipaddr->getName(),
@@ -401,6 +404,9 @@
IRR_COMMAND_LINE_OPTIONS,
+ {"-asplain", ARGV_BOOL, (char *) NULL, (char *) &opt_asdot,
+ "print AS numbers in asplain format."},
+
// prtraceroute specific arguments
{"-g", ARGV_FUNC, (char *)gFlag, (char *)NULL,
"Gateway"},
@@ -690,6 +696,7 @@
const AutNum * autnum;
char test[80];
+ char buf[64];
actiondictionary = new ActionDictionary;
@@ -796,7 +803,8 @@
for (i = last_ttl; i >= 0; i--) {
if (hops[i] != NULL) {
//cout << i << " AS" << getHopAS(i) << " ";
- printf ("%3d AS%d", i, getHopAS(i));
+ asnum_string(buf, getHopAS(i));
+ printf ("%3d %s", i, buf);
if (nflag) // XXX, this is a global, and is bad!!!
//cout << hops[i]->ipaddr->getIpaddr();
printf (" %-35s", hops[i]->ipaddr->getIpaddr());
Index: src/rpsl/rpsl/rpsl_item.cc
===================================================================
--- src/rpsl/rpsl/rpsl_item.cc (revision 221)
+++ src/rpsl/rpsl/rpsl_item.cc (working copy)
@@ -67,14 +67,18 @@
}
ostream &ItemASNO::print(ostream &out) const {
- out << "AS" << asno;
+ char buffer[64];
+ asnum_string(buffer, asno);
+ out << buffer;
return out;
}
Buffer *ItemASNO::bufferize(Buffer *buf, bool lcase) const {
+ char buffer[64];
+ asnum_string(buffer, asno);
if (!buf)
buf = new Buffer;
- buf->appendf("as%d", asno);
+ buf->appendf(buffer);
return buf;
}
Index: src/rpsl/rpsl/symbols.hh
===================================================================
--- src/rpsl/rpsl/symbols.hh (revision 221)
+++ src/rpsl/rpsl/symbols.hh (working copy)
@@ -114,7 +115,7 @@
}
SymID resolvePeerAS(SymID sid, ASt peerAS) {
- char *buffer = (char *) malloc(strlen(sid) * 2);
+ char *buffer = (char *) malloc(strlen(sid) * 3);
char *head, *tail, *ptr;
int written;
ptr = buffer;
@@ -123,7 +124,7 @@
tail = head + 6, head++, head = strstr(head, "PEERAS")) {
strncpy(ptr, tail, head - tail);
ptr += (head - tail);
- sprintf(ptr, "AS%d", peerAS);
+ asnum_string(ptr, peerAS);
written = strlen(ptr);
ptr += written;
}
Index: src/rpsl/rpsl/rpsl.y
===================================================================
--- src/rpsl/rpsl/rpsl.y (revision 221)
+++ src/rpsl/rpsl/rpsl.y (working copy)
@@ -755,7 +755,7 @@
}
| TKN_ASNO {
char buffer[64];
- sprintf(buffer, "AS%d", $1);
+ asnum_string(buffer, $1);
$$ = strdup(buffer);
}
| TKN_ASNAME {
Index: src/rpsl/rpsl/rpsl_item.hh
===================================================================
--- src/rpsl/rpsl/rpsl_item.hh (revision 221)
+++ src/rpsl/rpsl/rpsl_item.hh (working copy)
@@ -127,6 +128,9 @@
&& asno <= ((ItemASNO&) b).asno;
}
virtual Buffer *bufferize(Buffer *buf = NULL, bool lcase = false) const;
+ virtual const char *sprint(char *buf) {
+ asnum_string(buf, asno);
+ }
#ifdef DEBUG
virtual const char *className(void) const {
return "ItemASNO";
Index: src/rpsl/rpsl/rptype.cc
===================================================================
--- src/rpsl/rpsl/rptype.cc (revision 221)
+++ src/rpsl/rpsl/rptype.cc (working copy)
@@ -254,7 +254,7 @@
return new ItemWORD(strdup("false"));
if (typeid(*item) == typeid(ItemASNO)) {
char buffer[64];
- sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
+ asnum_string(buffer, ((ItemASNO *) item)->asno);
return new ItemWORD(strdup(buffer));
}
@@ -285,7 +285,7 @@
return new ItemBLOB(strdup("false"));
if (typeid(*item) == typeid(ItemASNO)) {
char buffer[64];
- sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
+ asnum_string(buffer, ((ItemASNO *) item)->asno);
return new ItemWORD(strdup(buffer));
}
@@ -367,7 +367,7 @@
w = new ItemWORD(strdup("false"));
if (typeid(*item) == typeid(ItemASNO)) {
char buffer[64];
- sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
+ asnum_string(buffer, ((ItemASNO *) item)->asno);
w = new ItemWORD(strdup(buffer));
}
@@ -388,8 +388,7 @@
////////////////////////////// RPTypeASNumber ////////////////////
bool RPTypeASNumber::validate(const Item *item) const {
- return ((typeid(*item) == typeid(ItemASNO))
- && ((ItemASNO *) item)->asno <= 65535);
+ return ((typeid(*item) == typeid(ItemASNO)));
}
////////////////////////////// RPTypeIPv4Address ////////////////////
Index: src/rpsl/rpsl/rpsl.l
===================================================================
--- src/rpsl/rpsl/rpsl.l (revision 221)
+++ src/rpsl/rpsl/rpsl.l (working copy)
@@ -74,7 +74,7 @@
SINT [+-]?{INT}
REAL [+-]?{INT}?\.{INT}({WS}*E{WS}*[+-]?{INT})?
NAME [[:alpha:]]([[:alnum:]_-]*[[:alnum:]])?
-ASNO AS{INT}
+ASNO AS{INT}\.{INT}|AS{INT}
ASNAME AS-[[:alnum:]_-]*[[:alnum:]]
RSNAME RS-[[:alnum:]_-]*[[:alnum:]]
RTRSNAME RTRS-[[:alnum:]_-]*[[:alnum:]]
@@ -455,7 +455,11 @@
/* The order of these rules are important */
{ASNO} {
- yylval.i = atoi(yytext+2);
+ const char *dot = strchr(yytext,'.');
+ if (dot)
+ yylval.i = atoi(yytext+2)<<16 | atoi(dot+1);
+ else
+ yylval.i = atoi(yytext+2);
LEXER_RETURN(TKN_ASNO);
}
@@ -751,7 +755,7 @@
if (rpsl_buffer)
yy_delete_buffer(rpsl_buffer);
- rpsl_buffer = yy_scan_bytes(o->contents, o->size);
+ rpsl_buffer = yy_scan_bytes(o->contents, (yy_size_t)o->size);
BEGIN(INITIAL);
}
Index: src/roe/schedule.cc
===================================================================
--- src/roe/schedule.cc (revision 221)
+++ src/roe/schedule.cc (working copy)
@@ -177,7 +177,8 @@
for (char *s = strtok(selection, " \t"); s; s = strtok(NULL, " \t")) {
r = routelist(atoi(s));
- tcl_Eval("set AS AS%d", routelist.as);
+ asnum_string(buffer, routelist.as);
+ tcl_Eval("set AS %s", buffer);
tcl_Eval("set ROUTE %s", r->route.get_text(buffer));
tcl_Eval("set DATE %s", configure.date);
tcl_Eval("subst \"%s\"", configure.add_template);
@@ -190,6 +191,7 @@
RouteList::Route *r;
RouteList::Route::db_as *p;
Route *route = NULL;
+ char buffer[64];
for (char *s = strtok(selection, " \t"); s; s = strtok(NULL, " \t")) {
r = routelist(atoi(s));
@@ -213,7 +215,8 @@
// Modified by wlee at isi.edu
// if (code)
if (route) {
- tcl_Eval("set AS AS%d", routelist.as);
+ asnum_string(buffer, routelist.as);
+ tcl_Eval("set AS %s", buffer);
tcl_Eval("set ROUTE %s", r->route.get_text());
tcl_Eval("set DATE %s", configure.date);
tcl_Eval("subst \"%.*s%s\"",
@@ -231,6 +234,7 @@
RouteList::Route *r;
RouteList::Route::db_as *p;
Route *route = NULL;
+ char buffer[64];
for (char *s = strtok(selection, " \t"); s; s = strtok(NULL, " \t")) {
r = routelist(atoi(s));
@@ -254,7 +258,8 @@
// Modified by wlee at isi.edu
if (route) {
- tcl_Eval("set AS AS%d", routelist.as);
+ asnum_string(buffer, routelist.as);
+ tcl_Eval("set AS %s", buffer);
tcl_Eval("set ROUTE %s", r->route.get_text());
tcl_Eval("set DATE %s", configure.date);
tcl_Eval("subst \"%.*s%s\"",
Index: src/roe/object.cc
===================================================================
--- src/roe/object.cc (revision 221)
+++ src/roe/object.cc (working copy)
@@ -107,7 +107,8 @@
RouteList::Route *vr = routelist(index);
// Modified by wlee at isi.edu
- tcl_Eval("set AS AS%d", routelist.as);
+ asnum_string(buffer, routelist.as);
+ tcl_Eval("set AS %s", buffer);
// tcl_Eval("set AS %s", routelist.as);
tcl_Eval("set ROUTE %s", vr->route.get_text(buffer));
tcl_Eval("set DATE %s", configure.date);
@@ -123,7 +124,8 @@
RouteList::Route *vr = routelist(index);
// Modified by wlee at isi.edu
- tcl_Eval("set AS AS%d", routelist.as);
+ asnum_string(buffer, routelist.as);
+ tcl_Eval("set AS %s", buffer);
// tcl_Eval("set AS %s", routelist.as);
tcl_Eval("set ROUTE %s", vr->route.get_text(buffer));
tcl_Eval("set DATE %s", configure.date);
@@ -140,7 +142,8 @@
RouteList::Route *vr = routelist(index);
// Modified by wlee at isi.edu
- tcl_Eval("set AS AS%d", routelist.as);
+ asnum_string(buffer, routelist.as);
+ tcl_Eval("set AS %s", buffer);
// tcl_Eval("set AS %s", routelist.as);
tcl_Eval("set ROUTE %s", vr->route.get_text(buffer));
tcl_Eval("set DATE %s", configure.date);
Index: src/roe/route-list.cc
===================================================================
--- src/roe/route-list.cc (revision 221)
+++ src/roe/route-list.cc (working copy)
@@ -67,6 +67,7 @@
char *RouteList::format(RouteList::Route *vr) {
static char line[256];
+ char buf[64];
char *c;
for (c = line; c < line + vr->indentation; ++c)
@@ -108,8 +109,10 @@
strcat(line, " ");
RouteList::Route::db_as* p;
- for (p = vr->db_as_l.head(); p; p = vr->db_as_l.next(p))
- sprintf(line + strlen(line), " %s:AS%d", p->db, p->as);
+ for (p = vr->db_as_l.head(); p; p = vr->db_as_l.next(p)) {
+ asnum_string(buf, p->as);
+ sprintf(line + strlen(line), " %s:%s", p->db, buf);
+ }
return line;
}
@@ -497,13 +500,17 @@
const PrefixRanges *registered_routes = whois->expandAS(as);
if (!registered_routes) {
- tcl_Eval("showWarning { No object for AS%d}", as);
+ char buf[64];
+ asnum_string(buf, as);
+ tcl_Eval("showWarning { No object for %s}", buf);
return;
}
// Added by wlee
if (registered_routes->isEmpty()) {
- tcl_Eval("showWarning { No route for AS%d}", as);
+ char buf[64];
+ asnum_string(buf, as);
+ tcl_Eval("showWarning { No route for %s}", buf);
return;
}
Index: src/roe/roe.cc
===================================================================
--- src/roe/roe.cc (revision 221)
+++ src/roe/roe.cc (working copy)
@@ -99,6 +99,7 @@
char opt_default_rcfile[256] = "";
char *display = NULL;
char *geometry = NULL;
+bool opt_asdot = true;
ASt myAS;
@@ -138,6 +139,9 @@
IRR_COMMAND_LINE_OPTIONS,
+ {"-asplain", ARGV_BOOL, (char *) NULL, (char *) &opt_asdot,
+ "print AS numbers in asplain format."},
+
// roe specific arguments
{"-as", ARGV_STRING, (char *) NULL, (char *) &opt_my_as,
"AS number of the aut-num object to use."},
Index: src/irr/irr.cc
===================================================================
--- src/irr/irr.cc (revision 221)
+++ src/irr/irr.cc (working copy)
@@ -316,7 +316,7 @@
AutNum *result = NULL;
if (! AutNumCache.query(as, result)) {
- sprintf(buffer, "AS%d", as);
+ asnum_string(buffer, as);
if (getAutNum(buffer, text, len)) {
Buffer b(text, len);
result = new AutNum(b);
@@ -369,7 +369,7 @@
char *text;
int len;
- sprintf(buffer, "AS%d", as);
+ asnum_string(buffer, as);
if (getRoute(rt->get_text(), buffer, text, len)) {
Buffer b(text, len);
route = new Route(b);
@@ -383,7 +383,7 @@
char *text;
int len;
- sprintf(buffer, "AS%d", as);
+ asnum_string(buffer, as);
if (getRoute(rt, buffer, text, len)) {
Buffer b(text, len);
route = new Route(b);
@@ -423,7 +423,7 @@
// we insert the set to the cache before expanding
// this is needed to avoid recursion if sets are recursively defined
expandASCache.add(as, result);
- sprintf(buffer, "AS%d", as);
+ asnum_string(buffer, as);
if (!expandAS(buffer, result)) {
expandASCache.nullify(as);
delete result;
Index: src/irr/birdwhoisc.cc
===================================================================
--- src/irr/birdwhoisc.cc (revision 221)
+++ src/irr/birdwhoisc.cc (working copy)
@@ -429,7 +429,11 @@
AttrGenericIterator<ItemASNO> itrOrigin(itrObject, "origin");
AttrGenericIterator<ItemWORD> itrSource(itrObject, "source");
if (itrOrigin && itrSource)
- cBuffer.append("%s AS%d\n", itrSource()->word, itrOrigin()->asno);
+ {
+ char buf[64];
+ asnum_string(buf, itrOrigin()->asno);
+ cBuffer.append("%s %s\n", itrSource()->word, buf);
+ }
}
}
if (cBuffer.empty())
Index: src/aoe/aoe.cc
===================================================================
--- src/aoe/aoe.cc (revision 221)
+++ src/aoe/aoe.cc (working copy)
@@ -107,6 +107,7 @@
char *opt_rcfile = NULL;
char *display = NULL;
ASt myAS = 0;
+bool opt_asdot = true;
//**********************
@@ -153,6 +154,9 @@
IRR_COMMAND_LINE_OPTIONS,
+ {"-asplain", ARGV_BOOL, (char *) NULL, (char *) &opt_asdot,
+ "print AS numbers in asplain format."},
+
// aoe specific arguments
{"-as", ARGV_STRING, (char *)NULL, (char *) &opt_my_as,
"AS number of the aut-num object to use"},
@@ -275,7 +279,7 @@
pcASPeer;
pcASPeer = lh.next(pcASPeer))
{
- sprintf(pzcASPeerNo, "AS%d", pcASPeer->getNo());
+ asnum_string(pzcASPeerNo, pcASPeer->getNo());
switch (pcASPeer->getType())
{
case dASPeerFromIRR:
@@ -662,8 +666,8 @@
ASt tPeerAS = pcApp->getASPeerNo(iPeerASIndex);
char pzcMyAS[16], pzcPeerAS[16];
- sprintf(pzcMyAS, "AS%d", tMyAS);
- sprintf(pzcPeerAS, "AS%d", tPeerAS);
+ asnum_string(pzcMyAS, tMyAS);
+ asnum_string(pzcPeerAS, tPeerAS);
// Setup $PeerAS properly
if (!pcApp->evalf("set PeerAS %s", pzcPeerAS)) return TCL_ERROR;
@@ -1093,7 +1097,7 @@
pcPolicyShowButton(NULL),
pcStatusLine(NULL)
{
- sprintf(pzcASNo, "AS%d", tASNo);
+ asnum_string(pzcASNo, tASNo);
if (!(pcIrr = IRR::newClient()))
{
usage();
Index: src/aoe/bgp_aspath.cc
===================================================================
--- src/aoe/bgp_aspath.cc (revision 221)
+++ src/aoe/bgp_aspath.cc (working copy)
@@ -110,11 +110,16 @@
pcFirstAndLastAS;
pcFirstAndLastAS = cFirstAndLastASes.next(pcFirstAndLastAS))
{
- printf("AS%d --", pcFirstAndLastAS->getFirst());
+ char buf[64];
+ asnum_string(buf, pcFirstAndLastAS->getFirst());
+ printf("%s --", buf);
for (int i = pcFirstAndLastAS->getLast().first();
i >= 0;
i = pcFirstAndLastAS->getLast().next(i))
- printf(" AS%d", i);
+ {
+ asnum_string(buf, i);
+ printf(" %s", buf);
+ }
printf("\n");
}
}
Index: src/peval/peval.cc
===================================================================
--- src/peval/peval.cc (revision 221)
+++ src/peval/peval.cc (working copy)
@@ -98,6 +98,7 @@
char *opt_prompt = "peval> ";
int opt_expand = EXPAND_ALL;
int opt_symbolic = 0;
+bool opt_asdot = true;
const int SIZE = 8*1024;
char base[SIZE] = "peval: ";
@@ -228,6 +229,9 @@
IRR_COMMAND_LINE_OPTIONS,
+ {"-asplain", ARGV_BOOL, (char *) NULL, (char *) &opt_asdot,
+ "print AS numbers in asplain format."},
+
// peval specific arguments
{"-symbolic", ARGV_CONSTANT, (char *)1, (char *)&opt_symbolic,
"Symbolic"},
Index: src/RtConfig/RtConfig.cc
===================================================================
--- src/RtConfig/RtConfig.cc (revision 221)
+++ src/RtConfig/RtConfig.cc (working copy)
@@ -85,6 +85,7 @@
Rusage ru(clog, &opt_rusage);
char *opt_prompt = "RtConfig> ";
+bool opt_asdot = true;
bool RtConfig::supressMartians = false;
int RtConfig::preferenceCeiling = 1000;
@@ -182,6 +183,9 @@ void init_and_set_options (int argc, cha
IRR_COMMAND_LINE_OPTIONS,
+ {"-asplain", ARGV_BOOL, (char *) NULL, (char *) &opt_asdot,
+ "print AS numbers in asplain format."},
+
{"-config", ARGV_FUNC, (char *) &select_config_format, (char *) NULL,
"Configuration format (junos, cisco, bcc, gated or rsd)"},
{"-no_match_ip_inbound", ARGV_BOOL,
Index: src/normalform/SetOfSymbol.cc
===================================================================
--- src/normalform/SetOfSymbol.cc (revision 221)
+++ src/normalform/SetOfSymbol.cc (working copy)
@@ -271,7 +271,7 @@
void SetOfSymbol::add(ASt as) {
char buffer[64];
- sprintf(buffer, "AS%d", as);
+ asnum_string(buffer, as);
add(symbols.symID(buffer));
}
Index: src/rpslcheck/rpslcheck.cc
===================================================================
--- src/rpslcheck/rpslcheck.cc (revision 221)
+++ src/rpslcheck/rpslcheck.cc (working copy)
@@ -73,6 +73,7 @@
char *opt_prompt = "rpslcheck> ";
bool opt_echo = false;
char *opt_my_as = NULL;
+bool opt_asdot = true;
#ifdef DEBUG
bool opt_debug_rpsl = false;
#endif // DEBUG
Index: man/man1/aoe.1
===================================================================
--- man/man1/aoe.1 (revision 221)
+++ man/man1/aoe.1 (working copy)
@@ -137,6 +137,9 @@
.RS
.IP "\-as <as-no>"
Gets aut-num object for <as-no>.
+.IP \-asplain
+Print AS numbers as asplain, i.e. as unstructured number;
+default is to use the more human readable asdot format.
.IP "-rcfile <resource filename>"
.IP "\-display <X Windows Display Specification>"
.RE
Index: man/man1/roe.1
===================================================================
--- man/man1/roe.1 (revision 221)
+++ man/man1/roe.1 (working copy)
@@ -115,6 +115,9 @@
.RS
.IP "\-as <as-no>"
Lists routes of <as-no>.
+.IP \-asplain
+Print AS numbers as asplain, i.e. as unstructured number;
+default is to use the more human readable asdot format.
.IP "-rcfile <resource filename>"
.IP "\-display <X Windows Display Specification>"
.IP "\-geometry <X Windows Geometry Specification>"
Index: man/man1/peval.1
===================================================================
--- man/man1/peval.1 (revision 221)
+++ man/man1/peval.1 (working copy)
@@ -137,6 +137,9 @@
Do a prior symbolic evaluation, then do the expansions and then
re-evaluate.
This may be faster for some policies.
+.IP \-asplain
+Print AS numbers as asplain, i.e. as unstructured number;
+default is to use the more human readable asdot format.
.IP -compressed
Print prefix lists using the more specific operators.
Otherwise,
Index: man/man1/RtConfig.1
===================================================================
--- man/man1/RtConfig.1 (revision 221)
+++ man/man1/RtConfig.1 (working copy)
@@ -128,6 +128,9 @@
in-bound route maps did not support ip access-list matches.
Use of this option causes RtConfig to use distribute-lists to overcome
this limitation.
+.IP \-asplain
+Print AS numbers as asplain, i.e. as unstructured number;
+default is to use the more human readable asdot format.
.IP \-disable_access_list_cache
RtConfig caches the access-lists (and in the future ip as-path
access-lists and route-maps) that it generates so that the same
Index: man/man1/prtraceroute.1
===================================================================
--- man/man1/prtraceroute.1 (revision 221)
+++ man/man1/prtraceroute.1 (working copy)
@@ -133,6 +133,9 @@
If an object is defined in multiple sources in <source-list>,
pmatch uses the definition first encountered in <source-list>
from left to right.
+.IP \-asplain
+Print AS numbers as asplain, i.e. as unstructured number;
+default is to use the more human readable asdot format.
.RE
.SH ENVIRONMENT VARIABLES
.RS
More information about the irrtoolset
mailing list