0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

print_cbor: ospf show topology somehow works

This commit is contained in:
Katerina Kubecova 2023-12-22 16:42:14 +01:00
parent 0d74089e9a
commit b7bc3d195a
6 changed files with 705 additions and 22 deletions

View File

@ -123,6 +123,8 @@ parse_args(int argc, char **argv)
/*** Input ***/
static void server_send(char *cmd);
static void
server_send_byte(byte *cmd, int l);
static int
handle_internal_command(char *cmd)
@ -152,70 +154,105 @@ uint compare_string(byte *str1, uint length, const char *str2) {
return 1;
}
void write_args_cbor(char *cmd_buffer, struct cbor_writer *w)
{
size_t l = strlen(cmd_buffer);
size_t pt = 0;
while (cmd_buffer[pt] == ' ')
pt++;
if (pt+1 >= l)
{
return;
}
cbor_add_string(w, "args");
cbor_open_list(w);
while (l>pt)
{
size_t next_space = 0;
while (next_space + pt < l && cmd_buffer[next_space + pt] != ' ')
next_space++;
cbor_open_block_with_length(w, 1);
cbor_add_string(w, "arg");
cbor_nonterminated_string(w, &cmd_buffer[pt], next_space);
pt += next_space;
while (cmd_buffer[pt] == ' ')
pt++;
}
cbor_close_block_or_list(w);
}
void
make_cmd_cbor(char *cmd_buffer)
{
printf("input got line yi\n%s\n", cmd_buffer);
size_t l = strlen(cmd_buffer);
char cbor_buf[l*10];
struct linpool *lp = lp_new(&root_pool);
struct cbor_writer *w = cbor_init(cbor_buf, l*10, lp);
cbor_open_block_with_length(w, 1);
printf("main block opened");
cbor_add_string(w, "command:do");
cbor_open_block(w);
char *show = "show ";
int buf_pt = 0;
if (compare_string(cmd_buffer, l, show))
{
printf("show recognised\n");
cbor_open_block(w);
buf_pt += strlen(show);
l -= strlen(show);
if (compare_string(&cmd_buffer[buf_pt], l, "memory"))
{
printf("show memory...\n");
cbor_string_int(w, "command", SHOW_MEMORY);
cbor_close_block_or_list(w);
server_send_byte(cbor_buf, w->pt);
lp_flush(lp);
server_send(cbor_buf);
return;
}
else if (compare_string(&cmd_buffer[buf_pt], l, "status"))
{
cbor_string_int(w, "command", SHOW_STATUS);
cbor_close_block_or_list(w);
cbor_write_to_file(w, "status_command.cbor");
server_send_byte(cbor_buf, w->pt);
lp_flush(lp);
server_send(cbor_buf);
return;
}
else if (compare_string(&cmd_buffer[buf_pt], l, "symbols"))
{
cbor_string_int(w, "command", SHOW_SYMBOLS);
write_args_cbor(&cmd_buffer[buf_pt + strlen("symbols ")], w);
cbor_close_block_or_list(w);
server_send_byte(cbor_buf, w->pt);
lp_flush(lp);
server_send(cbor_buf);
return;
}
else if (compare_string(&cmd_buffer[buf_pt], l, "ospf"))
{
cbor_string_int(w, "command", SHOW_OSPF);
write_args_cbor(&cmd_buffer[buf_pt + strlen("ospf")], w);
cbor_close_block_or_list(w);
server_send_byte(cbor_buf, w->pt);
lp_flush(lp);
return;
}
else
{
printf("this command is not implemented yet");
printf("this command is not implemented yet\n");
}
}
else if (compare_string(cmd_buffer, l, "down"))
{
cbor_add_string(w, "down");
server_send_byte(cbor_buf, w->pt);
return;
}
lp_flush(lp);
printf("this command is not implemented yet");
printf("this command is not implemented yet\n");
}
static void
submit_server_command(char *cmd)
{
printf("command %s\n", cmd);
if (cbor_mode)
{
make_cmd_cbor(cmd);
@ -418,7 +455,6 @@ server_got_binary(int c)
static void
server_read(void)
{
printf("server read\n");
int c;
byte *start, *p;
@ -555,6 +591,33 @@ server_send(char *cmd)
}
}
static void
server_send_byte(byte *cmd, int l)
{
byte *z = alloca(l);
memcpy(z, cmd, l);
while (l)
{
int cnt = write(server_fd, z, l);
if (cnt < 0)
{
if (errno == EAGAIN)
wait_for_write(server_fd);
else if (errno == EINTR)
continue;
else
DIE("Server write error");
}
else
{
l -= cnt;
z += cnt;
}
}
}
int
main(int argc, char **argv)
{

View File

@ -1,4 +1,4 @@
#include <time.h>
#include "nest/cbor_parse.c"
void print_with_size(byte *string, int len)
@ -12,6 +12,462 @@ void print_with_size(byte *string, int len)
}
}
void print_with_size_(byte *string, int len)
{
for (int i = 0; i < len; i++)
{
putc(string[i], stdout);
}
}
void print_ip_addr(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read); // tag
val = get_value(buf_read); // bytestring
for (int i = 0; i < val.val-1; i++)
{
printf("%i.", buf_read->buff[buf_read->pt + i]);
}
printf("%i", buf_read->buff[buf_read->pt + val.val]);
buf_read->pt+=val.val;
}
void print_ip_prefix(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read); // tag
val = get_value(buf_read); // block
val = get_value(buf_read);
long prefix = val.val;
val = get_value(buf_read); // bytestring
for (int i = 0; i < val.val-1; i++)
{
printf("%i.", buf_read->buff[buf_read->pt + i]);
}
printf("%i/%li", buf_read->buff[buf_read->pt + val.val], prefix);
buf_read->pt+=val.val;
}
void print_distance(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(compare_buff_str(buf_read, val.val, "distance"));
buf_read->pt+=val.val;
val = get_value(buf_read);
if (val.major == UINT)
{
printf("\t\tdistance %li\n", val.val);
return;
}
else if (val.major == TEXT)
{
printf("\t\tdistance ");
print_with_size_(&buf_read->buff[buf_read->pt], val.val);
buf_read->pt+=val.val;
printf("\n");
return;
}
bug("print distance on incorrect type %i\n", val.major);
}
void discard_key(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
if(!(val.major == TEXT))
{
bug("key is not text but %i", val.major);
}
buf_read->pt+=val.val;
}
void print_time(int64_t time)
{
struct tm tm = *localtime(&time);
printf("%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}
void print_lsa_router(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
discard_key(buf_read);
printf("\trouter ");
print_ip_addr(buf_read);
printf("\n");
print_distance(buf_read);
discard_key(buf_read); // vlink
val = get_value(buf_read);
ASSERT(val.major == ARRAY);
val = get_value(buf_read);
while (!val_is_break(val))
{
discard_key(buf_read);
printf("\t\tvlink ");
print_ip_addr(buf_read);
discard_key(buf_read);
val = get_value(buf_read);
printf(" metric %li\n", val.val);
val = get_value(buf_read);
}
discard_key(buf_read); // router metric
val = get_value(buf_read);
ASSERT(val.major == ARRAY);
val = get_value(buf_read);
while (!val_is_break(val))
{
discard_key(buf_read);
printf("\t\trouter ");
print_ip_addr(buf_read);
val = get_value(buf_read);
buf_read->pt+=val.val;
val = get_value(buf_read);
printf(" metric %li\n", val.val);
val = get_value(buf_read);
}
discard_key(buf_read); // network
val = get_value(buf_read);
ASSERT(val.major == ARRAY);
val = get_value(buf_read);
while (!val_is_break(val))
{
ASSERT(val.major == BLOCK);
int block_len = val.val;
discard_key(buf_read); // dummy id
val = get_value(buf_read); //id num
discard_key(buf_read); // network
int bracket = !(block_len == 4 && buf_read->buff[buf_read->pt + 8] == 'l');
printf("\t\tnetwork ");
if (bracket)
printf("[");
print_ip_addr(buf_read);
val = get_value(buf_read);
if (compare_buff_str(buf_read, val.val, "nif"))
{
printf("-");
buf_read->pt+=val.val;
val = get_value(buf_read);
printf("%li", val.val);
}
else if (compare_buff_str(buf_read, val.val, "len"))
{
printf("/");
buf_read->pt+=val.val;
val = get_value(buf_read);
printf("%li", val.val);
}
if (bracket)
printf("]");
discard_key(buf_read);
val = get_value(buf_read);
printf(" metric %li\n", val.val);
val = get_value(buf_read);
}
val = get_value(buf_read);
if (!val_is_break(val))
{
val = get_value(buf_read); // open list
while (!val_is_break(val))
{
buf_read->pt+=val.val; // stubnet
val = get_value(buf_read); // open block
discard_key(buf_read); // stubnet
printf("\t\tstubnet ");
val = get_value(buf_read);
print_ip_addr(buf_read);
discard_key(buf_read); // len
val = get_value(buf_read);
printf("/%li", val.val);
discard_key(buf_read); // metric
val = get_value(buf_read);
printf(" metric %li\n", val.val);
}
val = get_value(buf_read);
}
}
void print_lsa_network(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
val = get_value(buf_read);
ASSERT(val.major == TEXT);
if (compare_buff_str(buf_read, val.val, "ospf2"))
{
buf_read->pt+=val.val;
val = get_value(buf_read);
ASSERT(val.major == BLOCK);
discard_key(buf_read); // network
printf("\tnetwork ");
print_ip_addr(buf_read);
printf("/");
discard_key(buf_read); // optx
val = get_value(buf_read);
printf("%li\n", val.val);
discard_key(buf_read); // dr
printf("\t\tdr ");
print_ip_addr(buf_read);
printf("\n");
}
else if (compare_buff_str(buf_read, val.val, "ospf"))
{
buf_read->pt+=val.val;
val = get_value(buf_read);
ASSERT(val.major == BLOCK);
discard_key(buf_read); // network
printf("\tnetwork ");
print_ip_addr(buf_read);
discard_key(buf_read); // lsa id
val = get_value(buf_read);
printf("-%li\n", val.val);
}
print_distance(buf_read);
discard_key(buf_read); // routers
val = get_value(buf_read);
ASSERT(val.major == ARRAY);
val = get_value(buf_read);
while (!val_is_break(val))
{
discard_key(buf_read);
printf("\t\trouter ");
print_ip_addr(buf_read);
printf("\n");
val = get_value(buf_read);
}
}
void print_lsa_sum_net(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
discard_key(buf_read);
printf("\t\txnetwork ");
print_ip_prefix(buf_read);
discard_key(buf_read);
val = get_value(buf_read);
printf("metric %li\n", val.val);
}
void print_lsa_sum_rt(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
discard_key(buf_read);
printf("\t\txrouter ");
print_ip_addr(buf_read);
discard_key(buf_read);
val = get_value(buf_read);
printf("metric %li\n", val.val);
}
void print_lsa_external(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
val = get_value(buf_read);
int via = 0;
if (compare_buff_str(buf_read, val.val, "via"))
{
buf_read->pt+=val.val;
via = buf_read->pt;
val = get_value(buf_read); // tag
val = get_value(buf_read); // bytestring
buf_read->pt+=val.val;
val = get_value(buf_read);
}
long tag = -1;
if (compare_buff_str(buf_read, val.val, "tag"))
{
buf_read->pt+=val.val;
val = get_value(buf_read);
tag = val.val;
val = get_value(buf_read);
}
discard_key(buf_read); // lsa type
printf("\t\t");
val = get_value(buf_read);
print_with_size_(&buf_read->buff[buf_read->pt], val.val);
printf(" ");
discard_key(buf_read);
print_ip_addr(buf_read);
discard_key(buf_read);
printf(" metric");
val = get_value(buf_read);
if (compare_buff_str(buf_read, val.val, "lsa_type_num"))
{
buf_read->pt+=val.val;
val = get_value(buf_read);
printf("%li", val.val);
val = get_value(buf_read);
}
buf_read->pt+=val.val;
val = get_value(buf_read);
printf(" %li", val.val);
if (via)
{
printf(" via ");
int pt = buf_read->pt;
buf_read->pt = via;
print_ip_addr(buf_read);
buf_read->pt = pt;
}
if (tag >- 1)
{
printf(" tag %08lx", tag);
}
val = get_value(buf_read); // end of block
}
void print_lsa_prefix(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
val = get_value(buf_read);
if (val_is_break(val))
return;
discard_key(buf_read);
val = get_value(buf_read); // open block or break
while (!val_is_break(val))
{
val = get_value(buf_read);
if (compare_buff_str(buf_read, val.val, "stubnet"))
{
buf_read->pt+=val.val;
printf("\t\tstubnet ");
print_ip_prefix(buf_read);
discard_key(buf_read);
val = get_value(buf_read);
printf(" metric %li", val.val);
}
else
{
buf_read->pt+=val.val;
printf("\t\taddress ");
print_ip_prefix(buf_read);
}
printf("\n");
val = get_value(buf_read);
val = get_value(buf_read); // open block or break
}
val = get_value(buf_read);
print_ip_addr(buf_read);
}
void print_show_ospf(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
val = get_value(buf_read);
printf("\n");
if (compare_buff_str(buf_read, val.val, "error"))
{
buf_read->pt+=val.val;
val = get_value(buf_read);
printf("error: ");
print_with_size(&buf_read->buff[buf_read->pt], val.val);
printf("\n");
return;
}
if (compare_buff_str(buf_read, val.val, "not_implemented"))
{
buf_read->pt+=val.val;
val = get_value(buf_read);
printf("not implemented: ");
print_with_size(&buf_read->buff[buf_read->pt], val.val);
printf("\n");
return;
}
buf_read->pt+=val.val;
val = get_value(buf_read); // list
ASSERT(val.major == ARRAY);
int j = val.val;
for (int i = 0; i < j; i++)
{
val = get_value(buf_read); // open block
ASSERT(val.major == BLOCK);
discard_key(buf_read); // dummy id
val = get_value(buf_read);
ASSERT(val.major == UINT);
val = get_value(buf_read);
if (compare_buff_str(buf_read, val.val, "area"))
{
buf_read->pt+=val.val;
printf("area ");
print_ip_addr(buf_read);
printf("\n");
val = get_value(buf_read);
}
if (compare_buff_str(buf_read, val.val, "lsa_router"))
{
buf_read->pt+=val.val;
print_lsa_router(buf_read);
}
else if (compare_buff_str(buf_read, val.val, "lsa_network"))
{
buf_read->pt+=val.val;
print_lsa_network(buf_read);
}
else if (compare_buff_str(buf_read, val.val, "lsa_sum_net"))
{
buf_read->pt+=val.val;
print_lsa_sum_net(buf_read);
}
else if (compare_buff_str(buf_read, val.val, "lsa_sum_rt"))
{
buf_read->pt+=val.val;
print_lsa_sum_rt(buf_read);
}
else if (compare_buff_str(buf_read, val.val, "lsa_prefix"))
{
buf_read->pt+=val.val;
print_lsa_prefix(buf_read);
}
else if (compare_buff_str(buf_read, val.val, "lsa_external"))
{
buf_read->pt+=val.val;
print_lsa_external(buf_read);
}
val = get_value(buf_read);
}
discard_key(buf_read);
val = get_value(buf_read);
while (!val_is_break(val))
{
val = get_value(buf_read);
if (val_is_break(val))
return;
if (compare_buff_str(buf_read, val.val, "other_ABSRs"))
{
buf_read->pt+=val.val;
printf("other ABSRs\n");
val = get_value(buf_read); // null list
val = get_value(buf_read);
}
if (compare_buff_str(buf_read, val.val, "router"))
{
buf_read->pt+=val.val;
printf("router ");
print_ip_addr(buf_read);
val = get_value(buf_read);
}
buf_read->pt+=val.val;
print_lsa_external(buf_read);
val = get_value(buf_read);
val = get_value(buf_read);
}
}
void print_show_memory(struct buff_reader *buf_read)
{
printf("BIRD memory usage\n");
@ -56,6 +512,120 @@ void print_show_memory(struct buff_reader *buf_read)
}
}
void print_show_status(struct buff_reader *buf_read)
{
/*
print("BIRD", answer["show_status:message"]["version"])
for key in answer["show_status:message"]["body"].keys():
name = key.replace("_", " ")
if key == "router_id":
print(name, self.addr_to_str( answer["show_status:message"]["body"][key]))
elif key in "server_time last_reboot last_reconfiguration":
print(name, datetime.datetime.fromtimestamp(answer["show_status:message"]["body"][key]))
else:
print(name, answer["show_status:message"]["body"][key])
print(answer["show_status:message"]["state"])
*/
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
val = get_value(buf_read);
ASSERT(val.major == TEXT);
buf_read->pt+=val.val;
val = get_value(buf_read);
ASSERT(val.major == TEXT);
printf("BIRD ");
print_with_size(&buf_read->buff[buf_read->pt], val.val);
printf("\n");
buf_read->pt+=val.val;
val = get_value(buf_read);
ASSERT(val.major == TEXT); // body
buf_read->pt+=val.val;
val = get_value(buf_read);
ASSERT(val.major == BLOCK);
val = get_value(buf_read);
ASSERT(val.major == TEXT); // router id
buf_read->pt+=val.val;
printf("router id: ");
print_ip_addr(buf_read);
printf("\n");
val = get_value(buf_read);
ASSERT(val.major == TEXT); // hostname
buf_read->pt+=val.val;
printf("hostname: ");
val = get_value(buf_read);
ASSERT(val.major == TEXT);
print_with_size(&buf_read->buff[buf_read->pt], val.val);
printf("\n");
buf_read->pt+=val.val;
for (int i =0; i<3; i++)
{
val = get_value(buf_read);
ASSERT(val.major == TEXT); // server time, last rebooot, last reconfiguration
print_with_size(&buf_read->buff[buf_read->pt], val.val);
buf_read->pt+=val.val;
printf(": ");
val = get_value(buf_read);
ASSERT(val.major == UINT);
print_time(val.val);
printf("\n");
}
val = get_value(buf_read);
if (val.major != TEXT)
val = get_value(buf_read);
ASSERT(val.major == TEXT); // state
printf("state: ");
buf_read->pt+=val.val;
val = get_value(buf_read);
ASSERT(val.major == TEXT);
print_with_size(&buf_read->buff[buf_read->pt], val.val);
printf("\n");
buf_read->pt+=val.val;
}
void print_show_symbols(struct buff_reader *buf_read)
{
struct value val = get_value(buf_read);
ASSERT(val.major == BLOCK);
discard_key(buf_read);
val = get_value(buf_read);
int one_item = 0;
if (val.val == 1)
one_item = 1;
if (val.val == 0)
return;
val = get_value(buf_read);
if (val_is_break(val))
{
printf("no names found\n");
return;
}
val = get_value(buf_read);
while (val.major == TEXT)
{
buf_read->pt+=val.val; //name
val = get_value(buf_read);
print_with_size_(&buf_read->buff[buf_read->pt], val.val);
for (int i = val.val; i < 15; i++)
{
printf(" ");
}
buf_read->pt+=val.val;
val = get_value(buf_read); //type
buf_read->pt+=val.val;
val = get_value(buf_read);
print_with_size_(&buf_read->buff[buf_read->pt], val.val);
printf("\n");
buf_read->pt+=val.val;
if (one_item)
return;
val = get_value(buf_read);
if (val_is_break(val))
return;
val = get_value(buf_read);
}
}
void print_cbor_response(byte *cbor, int len)
{
@ -64,15 +634,37 @@ void print_cbor_response(byte *cbor, int len)
buf_read.size = len;
buf_read.pt = 0;
struct value val = get_value(&buf_read);
printf("%i %li\n", val.major, val.val);
ASSERT(val.major == BLOCK);
ASSERT(val.val <=1);
val = get_value(&buf_read);
ASSERT(val.major == TEXT);
printf("\n");
if (compare_buff_str(&buf_read, val.val, "show_memory:message"))
{
buf_read.pt += val.val;
print_show_memory(&buf_read);
}
else if (compare_buff_str(&buf_read, val.val, "show_status:message"))
{
buf_read.pt += val.val;
print_show_status(&buf_read);
}
else if (compare_buff_str(&buf_read, val.val, "show_symbols:message"))
{
buf_read.pt += val.val;
print_show_symbols(&buf_read);
}
else if (compare_buff_str(&buf_read, val.val, "show_ospf:message"))
{
buf_read.pt += val.val;
print_show_ospf(&buf_read);
}
printf("\nbird>");
fflush(stdout);
}

View File

@ -119,6 +119,7 @@ void skip_optional_args(struct buff_reader *rbuf_read, int items_in_block)
{
log("items in block %i", items_in_block);
ASSERT(items_in_block == -1); // assert the block was not open to exact num of items, because it cant be just for command (we would returned) and we did not find more items.
ASSERT(val_is_break(val));
rbuf_read->pt--; // we read one byte from future, we need to shift pointer back. The val should be break, but we are not going to close the block, because it was not opened here.
}
}
@ -210,15 +211,18 @@ struct arg_list *parse_arguments(struct buff_reader *rbuf_read, int items_in_blo
uint
do_command(struct buff_reader *rbuf_read, struct buff_reader *tbuf_read, int items_in_block, struct linpool *lp)
{
log("val from %i", rbuf_read->buff[rbuf_read->pt]);
struct value val = get_value(rbuf_read);
ASSERT(val.major == UINT);
struct arg_list * args;
log("command %li, major %i", val.val, val.major);
switch (val.val)
{
case SHOW_MEMORY:
skip_optional_args(rbuf_read, items_in_block);
return cmd_show_memory_cbor(tbuf_read->buff, tbuf_read->size, lp);
case SHOW_STATUS:
log("show status");
skip_optional_args(rbuf_read, items_in_block);
return cmd_show_status_cbor(tbuf_read->buff, tbuf_read->size, lp);
case SHOW_SYMBOLS:
@ -228,17 +232,32 @@ do_command(struct buff_reader *rbuf_read, struct buff_reader *tbuf_read, int ite
args = parse_arguments(rbuf_read, items_in_block, lp);
log("args %i, pt %i", args, args->pt);
return cmd_show_ospf_cbor(tbuf_read->buff, tbuf_read->size, args, lp);
return 0;
default:
bug("command %li not found", val.val);
return 0;
}
}
uint
detect_down(uint size, byte *rbuf)
{
struct buff_reader rbuf_read;
rbuf_read.buff = rbuf;
rbuf_read.size = size;
rbuf_read.pt = 0;
struct value val = get_value(&rbuf_read);
ASSERT(val.major == BLOCK);
val = get_value(&rbuf_read);
ASSERT(compare_buff_str(&rbuf_read, val.val, "command:do"));
rbuf_read.pt+=val.val;
val = get_value(&rbuf_read);
return (val.major = TEXT && compare_buff_str(&rbuf_read, val.val, "down"));
}
uint
parse_cbor(uint size, byte *rbuf, byte *tbuf, uint tbsize, struct linpool* lp)
{
log("cbor parse, tb size %i tb %i", tbsize, tbuf);
struct buff_reader rbuf_read;
struct buff_reader tbuf_read;
rbuf_read.buff = rbuf;
@ -281,6 +300,7 @@ parse_cbor(uint size, byte *rbuf, byte *tbuf, uint tbsize, struct linpool* lp)
if (items_in_block == -1)
{
val = get_value(&rbuf_read);
log("val before fall %i %li", val.major, val.val);
ASSERT(val.major == FLOAT && val.val == -1);
}
}

View File

@ -73,6 +73,7 @@
pool *cli_pool;
pool *yi_pool;
struct linpool *yi_lnpool;
static byte *
cli_alloc_out(cli *c, int size)
@ -398,7 +399,12 @@ cli_kick(cli *c)
uint
yi_process(uint size, byte *rbuf, byte *tbuf, uint tbsize) {
log("capacity %i buffer %i", tbsize, tbuf);
return parse_cbor(size, rbuf, tbuf, tbsize, lp_new(yi_pool));
if (detect_down(size, rbuf))
{
order_shutdown(0);
return 0;
}
return parse_cbor(size, rbuf, tbuf, tbsize, yi_lnpool);
}
static list cli_log_hooks;
@ -506,6 +512,7 @@ void
yi_init(void)
{
yi_pool = rp_new(&root_pool, "YI");
yi_lnpool = lp_new(yi_pool);
init_list(&yi_log_hooks); /*we may be do not need this*/
yi_log_inited = 1;
}

View File

@ -275,7 +275,7 @@ show_lsa_prefix_cbor(struct cbor_writer *w, struct top_hash_entry *he, struct to
cbor_string_int(w, "metric", metric);
}
else{
cbor_add_string(w, "stubnet");
cbor_add_string(w, "address");
cbor_add_net(w, &net);
}
cbor_close_block_or_list(w);

View File

@ -123,14 +123,16 @@ class Ospf(Command):
for prefix in area['prefixes']:
if 'metric' in prefix.keys():
print(f"\t\tstubnet {self.prefix_to_str(prefix['stubnet'])} metric {prefix['metric']}")
else:
print(f"\t\taddress {self.prefix_to_str(prefix['address'])}")
def print_answer(self, answer):
print()
if ("error" in answer["show_ospf:message"].keys()):
print("error: ", answer["show_ospf:message"]["error"])
return
if ("not implemented" in answer["show_ospf:message"].keys()):
print("not implemented: ", answer["show_ospf:message"]["not implemented"])
if ("not_implemented" in answer["show_ospf:message"].keys()):
print("not implemented: ", answer["show_ospf:message"]["not_implemented"])
return
for area in answer["show_ospf:message"]["areas"]:
if 'area' in area.keys():
@ -152,7 +154,6 @@ class Ospf(Command):
for asbr in area['asbrs']:
if('other_ABSRs' in asbr.keys()):
print("other ASBRs")
print("other ASBRs")
print(f"\trouter {self.addr_to_str(asbr['router'])}")
command_dictionary = {"status":0, "memory":1, "symbols":2, "ospf":3}