[Olsr-cvs] olsrd-current/lib/quagga/src olsrd_plugin.c, 1.4, 1.5 quagga.c, 1.3, 1.4 quagga.h, 1.2, 1.3
Bernd Petrovitsch
(spam-protected)
Thu Aug 16 21:07:31 CEST 2007
Update of /cvsroot/olsrd/olsrd-current/lib/quagga/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11265/lib/quagga/src
Modified Files:
olsrd_plugin.c quagga.c quagga.h
Log Message:
* sync'ed current svn (rev 33) upon Immo 'FaUl' Wehrenberg's hint
Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/quagga/src/olsrd_plugin.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** olsrd_plugin.c 15 Jul 2007 17:41:33 -0000 1.4
--- olsrd_plugin.c 16 Aug 2007 19:07:28 -0000 1.5
***************
*** 32,36 ****
#define PLUGIN_INTERFACE_VERSION 4
-
static void __attribute__ ((constructor)) my_init(void);
static void __attribute__ ((destructor)) my_fini(void);
--- 32,35 ----
***************
*** 64,67 ****
--- 63,67 ----
olsr_addroute_add_function(&zebra_add_olsr_v4_route, AF_INET);
olsr_delroute_add_function(&zebra_del_olsr_v4_route, AF_INET);
+ zebra_export_routes(1);
return 1;
}
***************
*** 69,74 ****
--- 69,76 ----
olsr_addroute_add_function(&zebra_add_olsr_v4_route, AF_INET);
olsr_delroute_add_function(&zebra_del_olsr_v4_route, AF_INET);
+ zebra_export_routes(1);
return 1;
}
+ else zebra_export_routes(0);
}
else if (!strcmp(key, "Distance")) {
***************
*** 92,96 ****
int olsrd_plugin_init() {
if(olsr_cnf->ip_version != AF_INET) {
! fputs("see the source - ipv6 so far not supportet\n" ,stderr);
return 1;
}
--- 94,98 ----
int olsrd_plugin_init() {
if(olsr_cnf->ip_version != AF_INET) {
! fputs("see the source - ipv6 so far not supported\n" ,stderr);
return 1;
}
***************
*** 106,109 ****
--- 108,112 ----
static void my_fini(void) {
+ zebra_cleanup();
}
Index: quagga.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/quagga/src/quagga.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** quagga.h 11 Mar 2007 23:26:06 -0000 1.2
--- quagga.h 16 Aug 2007 19:07:28 -0000 1.3
***************
*** 52,61 ****
};
! int init_zebra (void);
char zebra_send_command (unsigned char, char *, int );
int zebra_add_v4_route (struct ipv4_route r);
int zebra_delete_v4_route (struct ipv4_route r);
void zebra_check (void*);
! int zebra_parse_packet (char*, ssize_t);
int zebra_redistribute (unsigned char);
int zebra_disable_redistribute (unsigned char);
--- 52,62 ----
};
! void init_zebra (void);
! void zebra_cleanup (void);
char zebra_send_command (unsigned char, char *, int );
int zebra_add_v4_route (struct ipv4_route r);
int zebra_delete_v4_route (struct ipv4_route r);
void zebra_check (void*);
! int zebra_parse_packet (unsigned char*, ssize_t);
int zebra_redistribute (unsigned char);
int zebra_disable_redistribute (unsigned char);
***************
*** 65,68 ****
int zebra_add_olsr_v4_route (struct rt_entry*);
int zebra_del_olsr_v4_route (struct rt_entry*);
! void zebra_olsr_localpref(void);
! void zebra_olsr_distance(char);
--- 66,70 ----
int zebra_add_olsr_v4_route (struct rt_entry*);
int zebra_del_olsr_v4_route (struct rt_entry*);
! void zebra_olsr_localpref (void);
! void zebra_olsr_distance (char);
! void zebra_export_routes (unsigned char);
Index: quagga.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/quagga/src/quagga.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** quagga.c 11 Mar 2007 23:26:06 -0000 1.3
--- quagga.c 16 Aug 2007 19:07:28 -0000 1.4
***************
*** 47,53 ****
#define STATUS_CONNECTED 1
static struct {
! char status; // TODO: internal status
int sock; // Socket to zebra...
char redistribute[ZEBRA_ROUTE_MAX];
--- 47,55 ----
#define STATUS_CONNECTED 1
+ #define OPTION_EXPORT 1
static struct {
! char status; // internal status
! char options; // internal options
int sock; // Socket to zebra...
char redistribute[ZEBRA_ROUTE_MAX];
***************
*** 61,78 ****
static char *try_read (ssize_t *);
static char* zebra_route_packet (struct ipv4_route r, ssize_t *);
! static int parse_interface_add (char *, size_t);
! static int parse_interface_delete (char *, size_t);
! static int parse_interface_up (char *, size_t);
! static int parse_interface_down (char *, size_t);
! static int parse_interface_address_add (char *, size_t);
! static int parse_interface_address_delete (char *, size_t);
! static int parse_ipv4_route (char *, size_t, struct ipv4_route *);
! static int ipv4_route_add (char *, size_t);
! static int ipv4_route_delete (char *, size_t);
! static int parse_ipv6_route_add (char*, size_t);
! static int zebra_reconnect (void);
! static int zebra_connect (void);
! static int add_v4_route_status (struct ipv4_route r);
! static int del_v4_route_status (struct ipv4_route r);
static uint32_t prefixlentomask (uint8_t);
static void free_ipv4_route (struct ipv4_route);
--- 63,79 ----
static char *try_read (ssize_t *);
static char* zebra_route_packet (struct ipv4_route r, ssize_t *);
! static int parse_interface_add (unsigned char *, size_t);
! static int parse_interface_delete (unsigned char *, size_t);
! static int parse_interface_up (unsigned char *, size_t);
! static int parse_interface_down (unsigned char *, size_t);
! static int parse_interface_address_add (unsigned char *, size_t);
! static int parse_interface_address_delete (unsigned char *, size_t);
! static int parse_ipv4_route (unsigned char *, size_t, struct ipv4_route *);
! static int ipv4_route_add (unsigned char *, size_t);
! static int ipv4_route_delete (unsigned char *, size_t);
! static int parse_ipv6_route_add (unsigned char*, size_t);
! static void zebra_reconnect (void);
! static void zebra_connect (void);
!
static uint32_t prefixlentomask (uint8_t);
static void free_ipv4_route (struct ipv4_route);
***************
*** 86,90 ****
-
#ifdef MY_DEBUG
static void dump_ipv4_route (struct ipv4_route r, char *c) {
--- 87,90 ----
***************
*** 148,152 ****
buf = realloc (buf, s);
if (!buf) {
! OLSR_PRINTF (1, "OUT OF MEMORY: %s\n", strerror(errno));
olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
olsr_exit(c, EXIT_FAILURE);
--- 148,152 ----
buf = realloc (buf, s);
if (!buf) {
! OLSR_PRINTF (1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
olsr_exit(c, EXIT_FAILURE);
***************
*** 155,259 ****
}
! int init_zebra () {
! if (zebra_connect() < 0 || !(zebra.status&STATUS_CONNECTED)) {
! olsr_exit ("AIIIII, could not connect to zebra! is zebra running?",
EXIT_FAILURE);
- }
}
!
! static int zebra_reconnect (void) {
! struct ipv4_route *tmp;
int i;
- if (zebra_connect() < 0 || !(zebra.status&STATUS_CONNECTED))
- // log: zebra-reconnect failed
- ;
for (i = 0; ZEBRA_ROUTE_MAX - 1; i++)
! if (zebra.redistribute[i]) zebra_redistribute(i + 1);
!
! for (tmp = zebra.v4_rt; tmp; tmp = tmp->next)
! zebra_add_v4_route(*tmp);
! }
!
!
! static int add_v4_route_status (struct ipv4_route r) {
!
! struct ipv4_route *tmp = olsr_malloc (sizeof r, "quagga_v4_route_status");
! memcpy (tmp, &r, sizeof r);
!
! if (r.message & ZAPI_MESSAGE_NEXTHOP) {
! tmp->nexthops = olsr_malloc (r.nh_count * sizeof tmp->nexthops,
! "quagga_v4_route_status");
! memcpy (tmp->nexthops, &r.nexthops, sizeof *r.nexthops);
! }
!
! if (r.message & ZAPI_MESSAGE_IFINDEX) {
! tmp->index = olsr_malloc (r.ind_num * sizeof *tmp->index,
! "quagga_v4_route_status");
! memcpy (tmp->index, &r.index, r.ind_num * sizeof *tmp->index);
! }
!
! tmp->next = zebra.v4_rt;
! zebra.v4_rt = tmp;
!
! return 0;
!
! }
!
!
! static int cmp_v4_route (struct ipv4_route a, struct ipv4_route b) {
! if (a.type != b.type) return 1;
! if (a.flags != b.flags) return 1;
! if (a.message != b.message) return 1;
! if (a.prefixlen != b.prefixlen) return 1;
! if (a.message & ZAPI_MESSAGE_NEXTHOP) {
! if (a.nh_count != b.nh_count) return 1;
! if (memcmp (a.nexthops, b.nexthops, a.nh_count * sizeof *b.nexthops))
! return 1;
! }
! if (a.message & ZAPI_MESSAGE_IFINDEX) {
! if (a.ind_num != b.ind_num) return 1;
! if (memcpy (a.index, b.index, a.ind_num * sizeof *a.index)) return 1;
! }
! if (a.message & ZAPI_MESSAGE_DISTANCE)
! if (a.distance != b.distance) return 1;
! if (a.message & ZAPI_MESSAGE_METRIC)
! if (a.metric != b.metric) return 1;
! return 0;
}
- static int del_v4_route_status (struct ipv4_route r) {
! struct ipv4_route *tmp, *prv = 0;
!
! for (tmp = zebra.v4_rt; tmp; tmp = tmp->next) {
! if (!cmp_v4_route(*tmp, r)) {
! if (prv) prv->next = tmp->next;
!
! free_ipv4_route(*tmp);
! free (tmp);
! return 0;
}
! prv = tmp;
! }
! return 1;
}
/* Connect to the zebra-daemon, returns a socket */
! static int zebra_connect (void) {
#ifndef USE_UNIX_DOMAIN_SOCKET
struct sockaddr_in i;
! close (zebra.sock);
zebra.sock = socket (AF_INET,SOCK_STREAM, 0);
#else
struct sockaddr_un i;
! close (zebra.sock);
zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0);
--- 155,217 ----
}
! void init_zebra (void) {
! zebra_connect();
! if (!zebra.status&STATUS_CONNECTED)
! olsr_exit ("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?",
EXIT_FAILURE);
}
! void zebra_cleanup (void) {
int i;
+ struct rt_entry *tmp;
+ if (zebra.options & OPTION_EXPORT) {
+ for (i = 0; i < HASHSIZE; i++) {
+ for (tmp = routingtable[i].next; tmp != &routingtable[i]; tmp = tmp->next)
+ zebra_del_olsr_v4_route (tmp);
+ for (tmp = hna_routes[i].next; tmp != &hna_routes[i]; tmp = tmp->next)
+ zebra_del_olsr_v4_route (tmp) ; }
+ }
for (i = 0; ZEBRA_ROUTE_MAX - 1; i++)
! if (zebra.redistribute[i]) zebra_disable_redistribute(i + 1);
}
! static void zebra_reconnect (void) {
! struct rt_entry *tmp;
! int i;
! zebra_connect();
! if (!zebra.status & STATUS_CONNECTED) return; // try again next time
+ if (zebra.options & OPTION_EXPORT) {
+ for (i = 0; i < HASHSIZE; i++) {
+ for (tmp = routingtable[i].next; tmp != &routingtable[i]; tmp = tmp->next)
+ zebra_add_olsr_v4_route (tmp);
+ for (tmp = hna_routes[i].next; tmp != &hna_routes[i]; tmp = tmp->next)
+ zebra_add_olsr_v4_route (tmp);
}
! }
! for (i = 0; ZEBRA_ROUTE_MAX - 1; i++)
! if (zebra.redistribute[i]) zebra_redistribute(i + 1);
! /* Zebra sends us all routes of type it knows after
! zebra_redistribute(type) */
}
+
/* Connect to the zebra-daemon, returns a socket */
! static void zebra_connect (void) {
#ifndef USE_UNIX_DOMAIN_SOCKET
struct sockaddr_in i;
! if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
!
zebra.sock = socket (AF_INET,SOCK_STREAM, 0);
#else
struct sockaddr_un i;
! if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0);
***************
*** 263,267 ****
if (zebra.sock <0 )
! olsr_exit("could not create socket!", EXIT_FAILURE);
memset (&i, 0, sizeof i);
--- 221,225 ----
if (zebra.sock <0 )
! olsr_exit("(QUAGGA) Could not create socket!", EXIT_FAILURE);
memset (&i, 0, sizeof i);
***************
*** 276,284 ****
ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i);
! if (ret < 0) {
! close (zebra.sock);
! }
else zebra.status |= STATUS_CONNECTED;
- return zebra.sock;
}
--- 234,239 ----
ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i);
! if (ret < 0) zebra.status &= ~STATUS_CONNECTED;
else zebra.status |= STATUS_CONNECTED;
}
***************
*** 298,305 ****
uint16_t length = optlen + 3; // length of option + command + packet_length
#endif
!
int ret;
uint16_t len = htons(length);
memcpy (p, &len, 2);
--- 253,261 ----
uint16_t length = optlen + 3; // length of option + command + packet_length
#endif
! char *pnt = p;
int ret;
uint16_t len = htons(length);
+
memcpy (p, &len, 2);
***************
*** 325,329 ****
--- 281,287 ----
}
else {
+ olsr_printf (1, "(QUAGGA) Disconnected from zebra\n");
zebra.status &= ~STATUS_CONNECTED;
+ free (pnt);
return -1;
}
***************
*** 331,335 ****
p = p+ret;
} while ((length -= ret));
!
return 0;
}
--- 289,293 ----
p = p+ret;
} while ((length -= ret));
! free (pnt);
return 0;
}
***************
*** 441,445 ****
if (!(zebra.status & STATUS_CONNECTED)) {
! if (!zebra_reconnect()) return;
}
data = try_read (&len);
--- 399,404 ----
if (!(zebra.status & STATUS_CONNECTED)) {
! zebra_reconnect();
! return;
}
data = try_read (&len);
***************
*** 448,454 ****
do {
ret = zebra_parse_packet (f, len);
! if (!ret) {//something wired happened
! puts ("DEBUG: IIIIIIIIIIRGS");
! exit (EXIT_FAILURE);
}
f += ret;
--- 407,412 ----
do {
ret = zebra_parse_packet (f, len);
! if (!ret) { // something wired happened
! olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
}
f += ret;
***************
*** 462,466 ****
// if there is something to read - make sure to read whole packages
static char *try_read (ssize_t *len) {
! char *buf = NULL;
ssize_t ret = 0, bsize = 0;
uint16_t length = 0, l = 0;
--- 420,424 ----
// if there is something to read - make sure to read whole packages
static char *try_read (ssize_t *len) {
! unsigned char *buf = NULL;
ssize_t ret = 0, bsize = 0;
uint16_t length = 0, l = 0;
***************
*** 478,497 ****
}
ret = read (zebra.sock, buf + l, bsize - l);
! if (ret <= 0) {
! if (errno == EAGAIN) {
! errno = 0;
! }
! else {
! olsr_printf(1, "OOPS, something realy wired happened:"
! "read returned %s\n", strerror(errno));
! errno = 0;
! zebra.status &= ~STATUS_CONNECTED;
! return 0;
! }
free (buf);
return NULL;
}
! *len += ret;
while ((*len - l) > length) {
l += length;
--- 436,449 ----
}
ret = read (zebra.sock, buf + l, bsize - l);
! if (!ret) { // nothing more to read, packet is broken, discard!
free (buf);
return NULL;
}
! if (ret < 0 && errno != EAGAIN) { // oops - we got disconnected
! olsr_printf (1, "(QUAGGA) Disconnected from zebra\n");
! zebra.status &= ~STATUS_CONNECTED;
! }
+ *len += ret;
while ((*len - l) > length) {
l += length;
***************
*** 512,519 ****
/* Parse a packet recived from zebra */
! int zebra_parse_packet (char *packet, ssize_t maxlen) {
/* Array of functions */
! int (*foo[ZEBRA_MESSAGE_MAX]) (char *, size_t) = {
parse_interface_add,
parse_interface_delete,
--- 464,474 ----
/* Parse a packet recived from zebra */
! int zebra_parse_packet (unsigned char *packet, ssize_t maxlen) {
!
! uint16_t command;
! int skip;
/* Array of functions */
! int (*foo[ZEBRA_MESSAGE_MAX]) (unsigned char *, size_t) = {
parse_interface_add,
parse_interface_delete,
***************
*** 527,554 ****
};
#ifdef MY_DEBUG
puts ("DEBUG: zebra_parse_packet");
#endif
! uint16_t length;
!
! int ret;
memcpy (&length, packet, 2);
length = ntohs (length);
if (maxlen < length) {
! puts("Error: programmer is an idiot");
! printf ("DEBUG: maxlen = %d, packet_length = %d\n", maxlen, length);
! return maxlen;
}
! if (packet[2] - 1 < ZEBRA_MESSAGE_MAX && foo[packet[2] - 1]) {
! if (!(ret = foo[packet[2] - 1] (packet + 3, length - 3)))
return length;
! else printf ("DEBUG: Parse error: %d\n", ret);
}
else
! printf ("Unknown packet type: %d\n", packet[2]);
! puts ("Quagga: RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
return length;
--- 482,521 ----
};
+ uint16_t length;
+ int ret;
+
#ifdef MY_DEBUG
puts ("DEBUG: zebra_parse_packet");
#endif
!
memcpy (&length, packet, 2);
length = ntohs (length);
if (maxlen < length) {
! olsr_printf (1, "(QUAGGA) maxlen = %d, packet_length = %d\n", maxlen, length);
! olsr_exit ("(QUAGGA) programmer is an idiot", EXIT_FAILURE);
}
! #ifdef ZEBRA_HEADER_MARKER
! if (packet[2] == 255) { // found header marker!!
! //packet[3] == ZSERV_VERSION: FIXME: HANDLE THIS!
! memcpy (command, packet + 4, sizeof command); // two bytes command now!
! command-- = ntohs (command);
! skip = 6;
! }
! #else
! command = packet[2] - 1;
! skip = 3;
! #endif
!
! if (command < ZEBRA_MESSAGE_MAX && foo[command]) {
! if (!(ret = foo[command] (packet + skip, length - skip)))
return length;
! else olsr_printf (1, "(QUAGGA) Parse error: %d\n", ret);
}
else
! olsr_printf (1, "(QUAGGA) Unknown packet type: %d\n", packet[2]);
! olsr_printf (1, "(Quagga) RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
return length;
***************
*** 556,560 ****
! static int parse_interface_add (char *opt, size_t len) {
//todo
return 0;
--- 523,527 ----
! static int parse_interface_add (unsigned char *opt, size_t len) {
//todo
return 0;
***************
*** 562,566 ****
! static int parse_interface_delete (char *opt, size_t len) {
//todo
return 0;
--- 529,533 ----
! static int parse_interface_delete (unsigned char *opt, size_t len) {
//todo
return 0;
***************
*** 568,572 ****
! static int parse_interface_address_add (char *opt, size_t len) {
//todo
--- 535,539 ----
! static int parse_interface_address_add (unsigned char *opt, size_t len) {
//todo
***************
*** 574,578 ****
}
! static int parse_interface_up (char *opt, size_t len) {
//todo
--- 541,545 ----
}
! static int parse_interface_up (unsigned char *opt, size_t len) {
//todo
***************
*** 580,584 ****
}
! static int parse_interface_down (char *opt, size_t len) {
//todo
--- 547,551 ----
}
! static int parse_interface_down (unsigned char *opt, size_t len) {
//todo
***************
*** 587,591 ****
! static int parse_interface_address_delete (char *opt, size_t len) {
//todo
return 0;
--- 554,558 ----
! static int parse_interface_address_delete (unsigned char *opt, size_t len) {
//todo
return 0;
***************
*** 595,599 ****
/* Parse an ipv4-route-packet recived from zebra
*/
! static int parse_ipv4_route (char *opt, size_t len, struct ipv4_route *r) {
int c;
--- 562,566 ----
/* Parse an ipv4-route-packet recived from zebra
*/
! static int parse_ipv4_route (unsigned char *opt, size_t len, struct ipv4_route *r) {
int c;
***************
*** 654,658 ****
! static int ipv4_route_add (char *opt, size_t len) {
struct ipv4_route r;
--- 621,625 ----
! static int ipv4_route_add (unsigned char *opt, size_t len) {
struct ipv4_route r;
***************
*** 660,673 ****
f = parse_ipv4_route (opt, len, &r);
! if (f < 0) {
! printf ("parse-error: %d\n",f);
! return f;
! }
!
! add_hna4_route (r);
! return 0;
}
! static int ipv4_route_delete (char *opt, size_t len) {
struct ipv4_route r;
int f;
--- 627,636 ----
f = parse_ipv4_route (opt, len, &r);
! if (f < 0) return f;
!
! return add_hna4_route (r);
}
! static int ipv4_route_delete (unsigned char *opt, size_t len) {
struct ipv4_route r;
int f;
***************
*** 680,684 ****
}
! static int parse_ipv6_route_add (char *opt, size_t len) {
//todo
return 0;
--- 643,647 ----
}
! static int parse_ipv6_route_add (unsigned char *opt, size_t len) {
//todo
return 0;
***************
*** 811,815 ****
}
- add_v4_route_status (route);
retval = zebra_add_v4_route(route);
free_ipv4_route (route);
--- 774,777 ----
***************
*** 856,860 ****
}
- retval = zebra_delete_v4_route(route);
del_v4_route_status(route);
free_ipv4_route (route);
--- 818,821 ----
***************
*** 869,870 ****
--- 830,838 ----
zebra.flags &= ZEBRA_FLAG_SELECTED;
}
+
+ void zebra_export (char t) {
+ if (t)
+ zebra.options |= OPTION_EXPORT;
+ else
+ zebra.options &= ~OPTION_EXPORT;
+ }
More information about the Olsr-cvs
mailing list