Printing of AS paths and community sets.

This commit is contained in:
Martin Mares 2000-04-17 10:18:55 +00:00
parent afc54517db
commit c6add07fa6
5 changed files with 100 additions and 10 deletions

View file

@ -9,8 +9,10 @@
#include "nest/bird.h" #include "nest/bird.h"
#include "nest/route.h" #include "nest/route.h"
#include "nest/attrs.h"
#include "lib/resource.h" #include "lib/resource.h"
#include "lib/unaligned.h" #include "lib/unaligned.h"
#include "lib/string.h"
struct adata * struct adata *
as_path_prepend(struct linpool *pool, struct adata *olda, int as) as_path_prepend(struct linpool *pool, struct adata *olda, int as)
@ -36,3 +38,46 @@ as_path_prepend(struct linpool *pool, struct adata *olda, int as)
put_u16(newa->data+2, as); put_u16(newa->data+2, as);
return newa; return newa;
} }
void
as_path_format(struct adata *path, byte *buf, unsigned int size)
{
byte *p = path->data;
byte *e = p + path->length - 8;
byte *end = buf + size;
int sp = 1;
int l, type, isset, as;
while (p < e)
{
if (buf > end)
{
strcpy(buf, " ...");
return;
}
isset = (*p++ == AS_PATH_SET);
l = *p++;
if (isset)
{
if (!sp)
*buf++ = ' ';
*buf++ = '{';
sp = 0;
}
while (l-- && buf <= end)
{
if (!sp)
*buf++ = ' ';
buf += bsprintf(buf, "%d", get_u16(p));
p += 2;
sp = 0;
}
if (isset)
{
*buf++ = ' ';
*buf++ = '}';
sp = 0;
}
}
*buf = 0;
}

View file

@ -9,4 +9,32 @@
#include "nest/bird.h" #include "nest/bird.h"
#include "nest/route.h" #include "nest/route.h"
#include "nest/attrs.h"
#include "lib/resource.h" #include "lib/resource.h"
#include "lib/string.h"
void
int_set_format(struct adata *set, byte *buf, unsigned int size)
{
u32 *z = (u32 *) set->data;
int l = set->length / 4;
int sp = 1;
byte *end = buf + size - 16;
while (l--)
{
if (sp)
{
sp = 0;
*buf++ = ' ';
}
if (buf > end)
{
strcpy(buf, "...");
return;
}
buf += bsprintf(buf, "%d:%d", *z/65536, *z & 0xffff);
z++;
}
*buf = 0;
}

View file

@ -12,5 +12,13 @@
/* a-path.c */ /* a-path.c */
struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as); struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as);
void as_path_format(struct adata *path, byte *buf, unsigned int size);
#define AS_PATH_SET 1 /* Types of path segments */
#define AS_PATH_SEQUENCE 2
/* a-set.c */
void int_set_format(struct adata *set, byte *buf, unsigned int size);
#endif #endif

View file

@ -325,6 +325,7 @@ void ea_merge(ea_list *from, ea_list *to); /* Merge sub-lists to allocated buffe
int ea_same(ea_list *x, ea_list *y); /* Test whether two ea_lists are identical */ int ea_same(ea_list *x, ea_list *y); /* Test whether two ea_lists are identical */
unsigned int ea_hash(ea_list *e); /* Calculate 16-bit hash value */ unsigned int ea_hash(ea_list *e); /* Calculate 16-bit hash value */
void ea_format(eattr *e, byte *buf); void ea_format(eattr *e, byte *buf);
#define EA_FORMAT_BUF_SIZE 256
void rta_init(void); void rta_init(void);
rta *rta_lookup(rta *); /* Get rta equivalent to this one, uc++ */ rta *rta_lookup(rta *); /* Get rta equivalent to this one, uc++ */

View file

@ -13,6 +13,7 @@
#include "nest/protocol.h" #include "nest/protocol.h"
#include "nest/iface.h" #include "nest/iface.h"
#include "nest/cli.h" #include "nest/cli.h"
#include "nest/attrs.h"
#include "lib/resource.h" #include "lib/resource.h"
#include "lib/string.h" #include "lib/string.h"
@ -240,8 +241,9 @@ ea_format(eattr *e, byte *buf)
{ {
struct protocol *p; struct protocol *p;
int status = GA_UNKNOWN; int status = GA_UNKNOWN;
unsigned int i, l; unsigned int i;
struct adata *ad = (e->type & EAF_EMBEDDED) ? NULL : e->u.ptr; struct adata *ad = (e->type & EAF_EMBEDDED) ? NULL : e->u.ptr;
byte *end = buf + EA_FORMAT_BUF_SIZE - 1;
if (p = attr_class_to_protocol[EA_PROTO(e->id)]) if (p = attr_class_to_protocol[EA_PROTO(e->id)])
{ {
@ -264,15 +266,17 @@ ea_format(eattr *e, byte *buf)
bsprintf(buf, "%d", e->u.data); bsprintf(buf, "%d", e->u.data);
break; break;
case EAF_TYPE_OPAQUE: case EAF_TYPE_OPAQUE:
l = (ad->length < 16) ? ad->length : 16; for(i=0; i<ad->length; i++)
for(i=0; i<l; i++)
{ {
buf += bsprintf(buf, "%02x", ad->data[i]); if (buf > end - 8)
if (i < l) {
strcpy(buf, " ...");
break;
}
if (i)
*buf++ = ' '; *buf++ = ' ';
buf += bsprintf(buf, "%02x", ad->data[i]);
} }
if (l < ad->length)
strcpy(buf, "...");
break; break;
case EAF_TYPE_IP_ADDRESS: case EAF_TYPE_IP_ADDRESS:
bsprintf(buf, "%I", *(ip_addr *) ad->data); bsprintf(buf, "%I", *(ip_addr *) ad->data);
@ -280,8 +284,12 @@ ea_format(eattr *e, byte *buf)
case EAF_TYPE_ROUTER_ID: case EAF_TYPE_ROUTER_ID:
bsprintf(buf, "%08x", e->u.data); /* FIXME: Better printing of router ID's */ bsprintf(buf, "%08x", e->u.data); /* FIXME: Better printing of router ID's */
break; break;
case EAF_TYPE_AS_PATH: /* FIXME */ case EAF_TYPE_AS_PATH:
case EAF_TYPE_INT_SET: /* FIXME */ as_path_format(ad, buf, end - buf);
break;
case EAF_TYPE_INT_SET:
int_set_format(ad, buf, end - buf);
break;
case EAF_TYPE_UNDEF: case EAF_TYPE_UNDEF:
default: default:
bsprintf(buf, "<type %02x>", e->type); bsprintf(buf, "<type %02x>", e->type);
@ -542,7 +550,7 @@ rta_show(struct cli *c, rta *a)
static char *cast_names[] = { "unicast", "broadcast", "multicast", "anycast" }; static char *cast_names[] = { "unicast", "broadcast", "multicast", "anycast" };
ea_list *eal; ea_list *eal;
int i; int i;
byte buf[256]; byte buf[EA_FORMAT_BUF_SIZE];
cli_printf(c, -1008, "\tType: %s %s %s", src_names[a->source], cast_names[a->cast], ip_scope_text(a->scope)); cli_printf(c, -1008, "\tType: %s %s %s", src_names[a->source], cast_names[a->cast], ip_scope_text(a->scope));
for(eal=a->eattrs; eal; eal=eal->next) for(eal=a->eattrs; eal; eal=eal->next)