#include "privs.h"
#include "zebra/zserv.h"
+#include "zebra/router-id.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/ipforward.h"
extern struct zebra_privs_t zserv_privs;
\f
/* For logging of zebra meesages. */
-static char *zebra_command_str [] =
+static const char *zebra_command_str [] =
{
"NULL",
"ZEBRA_INTERFACE_ADD",
"ZEBRA_IPV4_NEXTHOP_LOOKUP",
"ZEBRA_IPV6_NEXTHOP_LOOKUP",
"ZEBRA_IPV4_IMPORT_LOOKUP",
- "ZEBRA_IPV6_IMPORT_LOOKUP"
+ "ZEBRA_IPV6_IMPORT_LOOKUP",
+ "ZEBRA_ROUTER_ID_ADD",
+ "ZEBRA_ROUTER_ID_DELETE",
+ "ZEBRA_ROUTER_ID_UPDATE"
};
\f
struct zebra_message_queue
else
return -1;
}
- else if (nbytes != length)
+ /* It's clear that nbytes is positive at this point. */
+ else if ((unsigned) nbytes != length)
zebra_server_enqueue (sock, buf, length, nbytes);
return 0;
|| cmd == ZEBRA_IPV4_ROUTE_DELETE)
{
struct in_addr empty;
- memset (&empty, 0, sizeof (struct in6_addr));
+ memset (&empty, 0, sizeof (struct in_addr));
stream_write (s, (u_char *) &empty, IPV4_MAX_BYTELEN);
}
else
/* Write next-hop number */
if (nhnummark)
- stream_putw_at (s, nhnummark, nhnum);
+ stream_putc_at (s, nhnummark, nhnum);
/* Write packet size. */
stream_putw_at (s, 0, stream_get_endp (s));
return 0;
}
\f
+/* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
+int
+zsend_router_id_update (struct zserv *client, struct prefix *p)
+{
+ struct stream *s;
+ int blen;
+
+ /* Check this client need interface information. */
+ if (!client->ridinfo)
+ return -1;
+
+ s = client->obuf;
+ stream_reset (s);
+
+ /* Place holder for size. */
+ stream_putw (s, 0);
+
+ /* Message type. */
+ stream_putc (s, ZEBRA_ROUTER_ID_UPDATE);
+
+ /* Prefix information. */
+ stream_putc (s, p->family);
+ blen = prefix_blen (p);
+ stream_put (s, &p->u.prefix, blen);
+ stream_putc (s, p->prefixlen);
+
+ /* Write packet size. */
+ stream_putw_at (s, 0, stream_get_endp (s));
+
+ return writen (client->sock, s->data, stream_get_endp (s));
+}
+\f
/* Register zebra server interface information. Send current all
interface and address information. */
static void
zread_interface_add (struct zserv *client, u_short length)
{
- listnode ifnode;
- listnode cnode;
+ struct listnode *ifnode;
+ struct listnode *cnode;
struct interface *ifp;
struct connected *c;
}
#endif /* HAVE_IPV6 */
+/* Register zebra server router-id information. Send current router-id */
+void
+zread_router_id_add (struct zserv *client, u_short length)
+{
+ struct prefix p;
+
+ /* Router-id information is needed. */
+ client->ridinfo = 1;
+
+ router_id_get (&p);
+
+ zsend_router_id_update (client,&p);
+}
+
+/* Unregister zebra server router-id information. */
+void
+zread_router_id_delete (struct zserv *client, u_short length)
+{
+ client->ridinfo = 0;
+}
+
/* Close zebra client. */
static void
zebra_client_close (struct zserv *client)
switch (command)
{
+ case ZEBRA_ROUTER_ID_ADD:
+ zread_router_id_add (client, length);
+ break;
+ case ZEBRA_ROUTER_ID_DELETE:
+ zread_router_id_delete (client, length);
+ break;
case ZEBRA_INTERFACE_ADD:
zread_interface_add (client, length);
break;
if (client_sock < 0)
{
- zlog_warn ("Can't accept zebra socket: %s", strerror (errno));
+ zlog_warn ("Can't accept zebra socket: %s", safe_strerror (errno));
return -1;
}
if (accept_sock < 0)
{
- zlog_warn ("Can't bind to socket: %s", strerror (errno));
+ zlog_warn ("Can't bind to socket: %s", safe_strerror (errno));
zlog_warn ("zebra can't provice full functionality due to above error");
return;
}
sizeof (struct sockaddr_in));
if (ret < 0)
{
- zlog_warn ("Can't bind to socket: %s", strerror (errno));
+ zlog_warn ("Can't bind to socket: %s", safe_strerror (errno));
zlog_warn ("zebra can't provice full functionality due to above error");
close (accept_sock); /* Avoid sd leak. */
return;
ret = listen (accept_sock, 1);
if (ret < 0)
{
- zlog_warn ("Can't listen to socket: %s", strerror (errno));
+ zlog_warn ("Can't listen to socket: %s", safe_strerror (errno));
zlog_warn ("zebra can't provice full functionality due to above error");
close (accept_sock); /* Avoid sd leak. */
return;
/* zebra server UNIX domain socket. */
static void
-zebra_serv_un (char *path)
+zebra_serv_un (const char *path)
{
int ret;
int sock, len;
int ret;
ret = ipforward ();
+ if (ret == 0)
+ ret = ipforward_on ();
- if (ret != 0)
- {
- vty_out (vty, "IP forwarding is already on%s", VTY_NEWLINE);
- return CMD_ERR_NOTHING_TODO;
- }
-
- ret = ipforward_on ();
if (ret == 0)
{
vty_out (vty, "Can't turn on IP forwarding%s", VTY_NEWLINE);
int ret;
ret = ipforward ();
+ if (ret != 0)
+ ret = ipforward_off ();
- if (ret == 0)
- {
- vty_out (vty, "IP forwarding is already off%s", VTY_NEWLINE);
- return CMD_ERR_NOTHING_TODO;
- }
-
- ret = ipforward_off ();
if (ret != 0)
{
vty_out (vty, "Can't turn off IP forwarding%s", VTY_NEWLINE);
"Zebra information"
"Client information")
{
- listnode node;
+ struct listnode *node;
struct zserv *client;
for (node = listhead (zebrad.client_list); node; nextnode (node))
int ret;
ret = ipforward_ipv6 ();
- if (ret != 0)
- {
- vty_out (vty, "IPv6 forwarding is already on%s", VTY_NEWLINE);
- return CMD_ERR_NOTHING_TODO;
- }
+ if (ret == 0)
+ ret = ipforward_ipv6_on ();
- ret = ipforward_ipv6_on ();
if (ret == 0)
{
vty_out (vty, "Can't turn on IPv6 forwarding%s", VTY_NEWLINE);
int ret;
ret = ipforward_ipv6 ();
- if (ret == 0)
- {
- vty_out (vty, "IP forwarding is already off%s", VTY_NEWLINE);
- return CMD_ERR_NOTHING_TODO;
- }
+ if (ret != 0)
+ ret = ipforward_ipv6_off ();
- ret = ipforward_ipv6_off ();
if (ret != 0)
{
vty_out (vty, "Can't turn off IPv6 forwarding%s", VTY_NEWLINE);
int
config_write_forwarding (struct vty *vty)
{
- if (! ipforward ())
- vty_out (vty, "no ip forwarding%s", VTY_NEWLINE);
+ /* FIXME: Find better place for that. */
+ router_id_write (vty);
+
+ if (ipforward ())
+ vty_out (vty, "ip forwarding%s", VTY_NEWLINE);
#ifdef HAVE_IPV6
- if (! ipforward_ipv6 ())
- vty_out (vty, "no ipv6 forwarding%s", VTY_NEWLINE);
+ if (ipforward_ipv6 ())
+ vty_out (vty, "ipv6 forwarding%s", VTY_NEWLINE);
#endif /* HAVE_IPV6 */
vty_out (vty, "!%s", VTY_NEWLINE);
return 0;
/* Client list init. */
zebrad.client_list = list_new ();
- /* Forwarding is on by default. */
- ipforward_on ();
-#ifdef HAVE_IPV6
- ipforward_ipv6_on ();
-#endif /* HAVE_IPV6 */
-
/* Make zebra server socket. */
#ifdef HAVE_TCP_ZEBRA
zebra_serv ();