mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-31 14:11:54 +00:00
client does not work for yi sock
This commit is contained in:
parent
17b08668a1
commit
b0f148b86c
@ -38,11 +38,13 @@
|
||||
|
||||
#define SERVER_READ_BUF_LEN 4096
|
||||
|
||||
static char *opt_list = "s:vrl";
|
||||
|
||||
static char *opt_list = "s:vrlY";
|
||||
static int verbose, restricted, once;
|
||||
static char *init_cmd;
|
||||
|
||||
static char *server_path = PATH_CONTROL_SOCKET;
|
||||
static char *server_path_yi = "bird-yang.ctl";
|
||||
static int server_fd;
|
||||
static byte server_read_buf[SERVER_READ_BUF_LEN];
|
||||
static byte *server_read_pos = server_read_buf;
|
||||
@ -51,6 +53,7 @@ int init = 1; /* During intial sequence */
|
||||
int busy = 1; /* Executing BIRD command */
|
||||
int interactive; /* Whether stdin is terminal */
|
||||
int last_code; /* Last return code */
|
||||
int yi_mode; /* Convert to cbor and push to yi socket (and convert answer back) */
|
||||
|
||||
static int num_lines, skip_input;
|
||||
int term_lns, term_cls;
|
||||
@ -61,7 +64,7 @@ int term_lns, term_cls;
|
||||
static void
|
||||
usage(char *name)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-s <control-socket>] [-v] [-r] [-l]\n", name);
|
||||
fprintf(stderr, "Usage: %s [-s <control-socket>] [-v] [-r] [-l] [-Y]\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -70,6 +73,7 @@ parse_args(int argc, char **argv)
|
||||
{
|
||||
int server_changed = 0;
|
||||
int c;
|
||||
yi_mode = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, opt_list)) >= 0)
|
||||
switch (c)
|
||||
@ -88,9 +92,17 @@ parse_args(int argc, char **argv)
|
||||
if (!server_changed)
|
||||
server_path = xbasename(server_path);
|
||||
break;
|
||||
case 'Y':
|
||||
yi_mode = 1;
|
||||
if (!server_changed)
|
||||
server_path = xbasename(server_path_yi);
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
yi_mode = 1;
|
||||
server_path = server_path_yi; //TODO delete - only for testing purposes
|
||||
fprintf(stderr, "Socket: %s \n", server_path_yi);
|
||||
|
||||
/* If some arguments are not options, we take it as commands */
|
||||
if (optind < argc)
|
||||
@ -142,6 +154,8 @@ submit_server_command(char *cmd)
|
||||
{
|
||||
busy = 1;
|
||||
num_lines = 2;
|
||||
fprintf(stderr, "Socket: %s \n", server_path_yi);
|
||||
fprintf(stderr, "cmd: %s \n", cmd);
|
||||
server_send(cmd);
|
||||
}
|
||||
|
||||
@ -262,6 +276,7 @@ server_connect(void)
|
||||
DIE("Unable to connect to server control socket (%s)", server_path);
|
||||
if (fcntl(server_fd, F_SETFL, O_NONBLOCK) < 0)
|
||||
DIE("fcntl");
|
||||
fprintf(stdout, "Socket: %s connected ok\n", server_path_yi);
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,17 +151,14 @@ void write_item(struct cbor_writer *writer, int8_t major, u64 num)
|
||||
{
|
||||
major = major<<5;
|
||||
check_memory(writer, 10);
|
||||
log("writing %li %lx max for lower %lx ", num, num, ((u64)1<<(4*8))-1);
|
||||
if (num > ((u64)1<<(4*8))-1)
|
||||
{ // We need 8 bytes to encode the num
|
||||
log("loong num");
|
||||
major += 0x1b; // reserving those bytes
|
||||
writer->cbor[writer->pt] = major;
|
||||
writer->pt++;
|
||||
for (int i = 7; i>=0; i--)
|
||||
{ // write n-th byte of num
|
||||
uint8_t to_write = (num>>(i*8)) & 0xff;
|
||||
log("%x", to_write);
|
||||
writer->cbor[writer->pt] = to_write;
|
||||
writer->pt++;
|
||||
}
|
||||
@ -175,7 +172,6 @@ void write_item(struct cbor_writer *writer, int8_t major, u64 num)
|
||||
for (int i = 3; i>=0; i--)
|
||||
{ // write n-th byte of num
|
||||
uint8_t to_write = (num>>(i*8)) & 0xff;
|
||||
log("%x", to_write);
|
||||
writer->cbor[writer->pt] = to_write;
|
||||
writer->pt++;
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ void cbor_add_net(struct cbor_writer *writer, const net_addr *N) {
|
||||
switch (n->n.type)
|
||||
{
|
||||
case NET_IP4:
|
||||
cbor_add_ipv4_prefix(writer, n->ip4.prefix, n->ip4.pxlen);
|
||||
cbor_add_ipv4_prefix(writer, n->ip4.prefix.addr, n->ip4.pxlen);
|
||||
return;
|
||||
case NET_IP6:
|
||||
cbor_add_ipv6_prefix(writer, n->ip6.prefix, n->ip6.pxlen);
|
||||
return;
|
||||
case NET_VPN4:
|
||||
cbor_add_ipv4_prefix(writer, n->vpn4.prefix, n->vpn4.pxlen);
|
||||
cbor_add_ipv4_prefix(writer, n->vpn4.prefix.addr, n->vpn4.pxlen);
|
||||
return;
|
||||
case NET_VPN6:
|
||||
cbor_add_ipv6_prefix(writer, n->vpn6.prefix, n->vpn6.pxlen);
|
||||
|
@ -489,6 +489,7 @@ yi_rx(sock *s, uint size)
|
||||
{
|
||||
/* zpracuj data délky len začínající na s->rbuf */
|
||||
/* zapiš výsledek do s->tbuf */
|
||||
log("in yi rx!");
|
||||
log("size tbuf %ui", s->tbsize);
|
||||
uint tx_len = yi_process(size, s->rbuf, s->tbuf, s->tbsize);
|
||||
sk_send(s, tx_len);
|
||||
|
Loading…
Reference in New Issue
Block a user