/* Prototype for event manager. */
static void zclient_event (enum event, struct zclient *);
-char *zclient_serv_path = NULL;
+const char *zclient_serv_path = NULL;
/* This file local debug flag. */
int zclient_debug = 0;
#ifdef HAVE_TCP_ZEBRA
zclient->sock = zclient_socket ();
#else
- zclient->sock = zclient_socket_un (zclient_serv_path ? zclient_serv_path : ZEBRA_SERV_PATH);
+ zclient->sock = zclient_socket_un (zclient_serv_path_get());
#endif
return zclient->sock;
}
stream_putw (s, command);
}
+int
+zclient_read_header (struct stream *s, int sock, u_int16_t *size, u_char *marker,
+ u_char *version, vrf_id_t *vrf_id, u_int16_t *cmd)
+{
+ if (stream_read (s, sock, ZEBRA_HEADER_SIZE) != ZEBRA_HEADER_SIZE)
+ return -1;
+
+ *size = stream_getw (s) - ZEBRA_HEADER_SIZE;
+ *marker = stream_getc (s);
+ *version = stream_getc (s);
+ *vrf_id = stream_getw (s);
+ *cmd = stream_getw (s);
+
+ if (*version != ZSERV_VERSION || *marker != ZEBRA_HEADER_MARKER)
+ {
+ zlog_err("%s: socket %d version mismatch, marker %d, version %d",
+ __func__, sock, *marker, *version);
+ return -1;
+ }
+
+ if (*size && stream_read (s, sock, *size) != *size)
+ return -1;
+
+ return 0;
+}
+
/* Send simple Zebra message. */
static int
zebra_message_send (struct zclient *zclient, int command, vrf_id_t vrf_id)
*
* If ZAPI_MESSAGE_TAG is set, the tag value is written as a 2 byte value
*
+ * If ZAPI_MESSAGE_MTU is set, the mtu value is written as a 4 byte value
+ *
* XXX: No attention paid to alignment.
*/
int
stream_putl (s, api->metric);
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
stream_putw (s, api->tag);
+ if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU))
+ stream_putl (s, api->mtu);
/* Put length at the first point of the stream. */
stream_putw_at (s, 0, stream_get_endp (s));
stream_putl (s, api->metric);
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
stream_putw (s, api->tag);
+ if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU))
+ stream_putl (s, api->mtu);
/* Put length at the first point of the stream. */
stream_putw_at (s, 0, stream_get_endp (s));
stream_putl (s, api->metric);
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
stream_putw (s, api->tag);
+ if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU))
+ stream_putl (s, api->mtu);
/* Put length at the first point of the stream. */
stream_putw_at (s, 0, stream_get_endp (s));
*/
static void
-zclient_vrf_add (struct stream *s, vrf_id_t vrf_id)
+zclient_vrf_add (struct zclient *zclient, vrf_id_t vrf_id)
{
struct vrf *vrf;
char vrfname_tmp[VRF_NAMSIZ];
/* Read interface name. */
- stream_get (vrfname_tmp, s, VRF_NAMSIZ);
+ stream_get (vrfname_tmp, zclient->ibuf, VRF_NAMSIZ);
/* Lookup/create vrf by vrf_id. */
vrf = vrf_get (vrf_id, vrfname_tmp);
}
static void
-zclient_vrf_delete (struct stream *s, vrf_id_t vrf_id)
+zclient_vrf_delete (struct zclient *zclient, vrf_id_t vrf_id)
{
struct vrf *vrf;
/* Lookup vrf by vrf_id. */
vrf = vrf_lookup (vrf_id);
+ /*
+ * If a routing protocol doesn't know about a
+ * vrf that is about to be deleted. There is
+ * no point in attempting to delete it.
+ */
+ if (!vrf)
+ return;
+
vrf_delete (vrf);
}
struct connected *
zebra_interface_address_read (int type, struct stream *s, vrf_id_t vrf_id)
{
- unsigned int ifindex;
+ ifindex_t ifindex;
struct interface *ifp;
struct connected *ifc;
struct prefix p, d;
else if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER))
{
/* carp interfaces on OpenBSD with 0.0.0.0/0 as "peer" */
- char buf[PREFIX2STR_BUFFER];
- prefix2str (ifc->address, buf, sizeof(buf));
+ char buf[PREFIX_STRLEN];
zlog_warn("warning: interface %s address %s "
"with peer flag set, but no peer address!",
- ifp->name, buf);
+ ifp->name,
+ prefix2str (ifc->address, buf, sizeof buf));
UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
}
}
(*zclient->router_id_update) (command, zclient, length, vrf_id);
break;
case ZEBRA_VRF_ADD:
- zclient_vrf_add (zclient->ibuf, vrf_id);
+ zclient_vrf_add (zclient, vrf_id);
break;
case ZEBRA_VRF_DELETE:
- zclient_vrf_delete (zclient->ibuf, vrf_id);
+ zclient_vrf_delete (zclient, vrf_id);
break;
case ZEBRA_INTERFACE_ADD:
if (zclient->interface_add)
}
}
+const char *zclient_serv_path_get()
+{
+ return zclient_serv_path ? zclient_serv_path : ZEBRA_SERV_PATH;
+}
+
void
zclient_serv_path_set (char *path)
{