]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/zclient.c
lib: Remove unused ZEBRA_NEXTHOP_IPV4_ONLINK type
[mirror_frr.git] / lib / zclient.c
index 35a5b9e857877319df81962822b98d2cfc69db55..0259af597106bf4a1730abd8cd1da75a306ae4c1 100644 (file)
@@ -39,7 +39,7 @@ enum event {ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT};
 /* 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;
@@ -260,7 +260,7 @@ zclient_socket_connect (struct zclient *zclient)
 #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;
 }
@@ -334,6 +334,32 @@ zclient_create_header (struct stream *s, uint16_t command, vrf_id_t vrf_id)
   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)
@@ -683,6 +709,8 @@ zclient_connect (struct thread *t)
   *
   * 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
@@ -743,6 +771,8 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p,
     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));
@@ -808,6 +838,8 @@ zapi_ipv4_route_ipv6_nexthop (u_char cmd, struct zclient *zclient,
     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));
@@ -872,6 +904,8 @@ zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p,
     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));
@@ -952,13 +986,13 @@ zebra_router_id_update_read (struct stream *s, struct prefix *rid)
  */
 
 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);
@@ -967,13 +1001,21 @@ zclient_vrf_add (struct stream *s, vrf_id_t vrf_id)
 }
 
 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);
 }
 
@@ -1099,7 +1141,7 @@ memconstant(const void *s, int c, size_t n)
 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;
@@ -1154,11 +1196,11 @@ zebra_interface_address_read (int type, struct stream *s, vrf_id_t vrf_id)
           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);
             }
         }
@@ -1377,10 +1419,10 @@ zclient_read (struct thread *thread)
        (*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)
@@ -1574,6 +1616,11 @@ zclient_event (enum event event, struct zclient *zclient)
     }
 }
 
+const char *zclient_serv_path_get()
+{
+  return zclient_serv_path ? zclient_serv_path : ZEBRA_SERV_PATH;
+}
+
 void
 zclient_serv_path_set (char *path)
 {