Makes olsrd-quagga compatible with quagga >=0.99 Signed-off by: Christian Franke diff --git a/src/quagga.c b/src/quagga.c index a953b56..eda7fb1 100644 --- a/src/quagga.c +++ b/src/quagga.c @@ -203,13 +203,17 @@ static unsigned char* zebra_route_packet (uint16_t cmd, struct zebra_route *r) { uint8_t len; uint16_t size; uint32_t ind, metric; - + uint16_t netcmd; unsigned char *cmdopt, *t; cmdopt = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra add_v4_route"); t = &cmdopt[2]; - *t++ = cmd; + *t++ = ZEBRA_HEADER_MARKER; + *t++ = ZSERV_VERSION; + netcmd = htons(cmd); + memcpy(t, &netcmd, 2); + t += 2; *t++ = r->type; *t++ = r->flags; *t++ = r->message; @@ -254,7 +258,7 @@ static unsigned char* zebra_route_packet (uint16_t cmd, struct zebra_route *r) { /* Check wether there is data from zebra aviable */ void zebra_parse (void* foo __attribute__((unused))) { unsigned char *data, *f; - unsigned char command; + uint16_t command; uint16_t length; ssize_t len; struct zebra_route *route; @@ -271,7 +275,10 @@ void zebra_parse (void* foo __attribute__((unused))) { length = ntohs (length); if (!length) // something wired happened olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE); - command = f[2]; + if (f[2] != ZEBRA_HEADER_MARKER || f[3] != ZSERV_VERSION) + olsr_exit ("(QUAGGA) This version of the plugin works only with quagga >= 0.99!", EXIT_FAILURE); + memcpy(&command, f + 4, sizeof command); + command = ntohs(command); switch (command) { case ZEBRA_IPV4_ROUTE_ADD: route = zebra_parse_route(f); @@ -286,6 +293,7 @@ void zebra_parse (void* foo __attribute__((unused))) { free (route); break; default: + olsr_printf(1, "(QUAGGA) Packet from zebra contains unknown cmd %d\n", command); break; } f += length; @@ -375,7 +383,7 @@ static struct zebra_route *zebra_parse_route (unsigned char *opt) { length = ntohs (length); r = olsr_malloc (sizeof *r , "zebra_parse_route"); - pnt = &opt[3]; + pnt = &opt[6]; r->type = *pnt++; r->flags = *pnt++; r->message = *pnt++; @@ -429,11 +437,16 @@ static struct zebra_route *zebra_parse_route (unsigned char *opt) { static unsigned char *zebra_redistribute_packet (unsigned char cmd, unsigned char type) { unsigned char *data, *pnt; uint16_t size; + uint16_t netcmd; data = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra_redistribute_packet"); pnt = &data[2]; - *pnt++ = cmd; + *pnt++ = ZEBRA_HEADER_MARKER; + *pnt++ = ZSERV_VERSION; + netcmd = htons(cmd); + memcpy(pnt, &netcmd, 2); + pnt += 2; *pnt++ = type; size = htons (pnt - data); memcpy (data, &size, 2); diff --git a/src/quagga.h b/src/quagga.h index d3fbdd5..f99a871 100644 --- a/src/quagga.h +++ b/src/quagga.h @@ -32,6 +32,7 @@ #endif /* Zebra version */ +#define ZEBRA_HEADER_MARKER 255 #ifdef ZEBRA_HEADER_MARKER #ifndef ZSERV_VERSION #define ZSERV_VERSION 1 @@ -75,7 +76,6 @@ #define STATUS_CONNECTED 1 #define OPTION_EXPORT 1 - struct zebra_route { unsigned char type; unsigned char flags;