summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2017-01-13 14:48:16 -0500
committerGitHub <noreply@github.com>2017-01-13 14:48:16 -0500
commit9aa7f43f7e7310c285f39a38ff36e1546c00058c (patch)
treecdcfdc0f188027cd77937c790895fc5926bb85dd /lib
parent386ea4d526de953f3648dfa286f77e5b0a8eef12 (diff)
parentb6f1faf04596242329d8ecd95b732f1d396e7823 (diff)
Merge branch 'master' into cleanup
Diffstat (limited to 'lib')
-rw-r--r--lib/vrf.c8
-rw-r--r--lib/vty.c98
-rw-r--r--lib/vty.h2
-rw-r--r--lib/zebra.h67
4 files changed, 121 insertions, 54 deletions
diff --git a/lib/vrf.c b/lib/vrf.c
index 14501c5265..ce8ffe75d5 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -381,7 +381,7 @@ vrf_bitmap_set (vrf_bitmap_t bmap, vrf_id_t vrf_id)
u_char group = VRF_BITMAP_GROUP (vrf_id);
u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id);
- if (bmap == VRF_BITMAP_NULL)
+ if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN)
return;
if (bm->groups[group] == NULL)
@@ -399,7 +399,8 @@ vrf_bitmap_unset (vrf_bitmap_t bmap, vrf_id_t vrf_id)
u_char group = VRF_BITMAP_GROUP (vrf_id);
u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id);
- if (bmap == VRF_BITMAP_NULL || bm->groups[group] == NULL)
+ if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN ||
+ bm->groups[group] == NULL)
return;
UNSET_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)],
@@ -413,7 +414,8 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id)
u_char group = VRF_BITMAP_GROUP (vrf_id);
u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id);
- if (bmap == VRF_BITMAP_NULL || bm->groups[group] == NULL)
+ if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN ||
+ bm->groups[group] == NULL)
return 0;
return CHECK_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)],
diff --git a/lib/vty.c b/lib/vty.c
index a0bcf130ef..e47ad1e59a 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -508,18 +508,6 @@ vty_write (struct vty *vty, const char *buf, size_t nbytes)
buffer_put (vty->obuf, buf, nbytes);
}
-/* Ensure length of input buffer. Is buffer is short, double it. */
-static void
-vty_ensure (struct vty *vty, int length)
-{
- if (vty->max <= length)
- {
- vty->max *= 2;
- vty->buf = XREALLOC (MTYPE_VTY, vty->buf, vty->max);
- vty->error_buf = XREALLOC (MTYPE_VTY, vty->error_buf, vty->max);
- }
-}
-
/* Basic function to insert character into vty. */
static void
vty_self_insert (struct vty *vty, char c)
@@ -527,7 +515,9 @@ vty_self_insert (struct vty *vty, char c)
int i;
int length;
- vty_ensure (vty, vty->length + 1);
+ if (vty->length + 1 > VTY_BUFSIZ)
+ return;
+
length = vty->length - vty->cp;
memmove (&vty->buf[vty->cp + 1], &vty->buf[vty->cp], length);
vty->buf[vty->cp] = c;
@@ -544,26 +534,29 @@ vty_self_insert (struct vty *vty, char c)
static void
vty_self_insert_overwrite (struct vty *vty, char c)
{
- vty_ensure (vty, vty->length + 1);
- vty->buf[vty->cp++] = c;
-
- if (vty->cp > vty->length)
- vty->length++;
-
- if ((vty->node == AUTH_NODE) || (vty->node == AUTH_ENABLE_NODE))
- return;
+ if (vty->cp == vty->length)
+ {
+ vty_self_insert (vty, c);
+ return;
+ }
+ vty->buf[vty->cp++] = c;
vty_write (vty, &c, 1);
}
-/* Insert a word into vty interface with overwrite mode. */
+/**
+ * Insert a string into vty->buf at the current cursor position.
+ *
+ * If the resultant string would be larger than VTY_BUFSIZ it is
+ * truncated to fit.
+ */
static void
vty_insert_word_overwrite (struct vty *vty, char *str)
{
- int len = strlen (str);
- vty_write (vty, str, len);
- strcpy (&vty->buf[vty->cp], str);
- vty->cp += len;
+ size_t nwrite = MIN ((int) strlen (str), VTY_BUFSIZ - vty->cp);
+ vty_write (vty, str, nwrite);
+ strncpy (&vty->buf[vty->cp], str, nwrite);
+ vty->cp += nwrite;
vty->length = vty->cp;
}
@@ -2148,36 +2141,45 @@ vtysh_read (struct thread *thread)
printf ("line: %.*s\n", nbytes, buf);
#endif /* VTYSH_DEBUG */
- for (p = buf; p < buf+nbytes; p++)
+ if (vty->length + nbytes > VTY_BUFSIZ)
+ {
+ /* Clear command line buffer. */
+ vty->cp = vty->length = 0;
+ vty_clear_buf (vty);
+ vty_out (vty, "%% Command is too long.%s", VTY_NEWLINE);
+ }
+ else
{
- vty_ensure(vty, vty->length+1);
- vty->buf[vty->length++] = *p;
- if (*p == '\0')
+ for (p = buf; p < buf+nbytes; p++)
{
- /* Pass this line to parser. */
- ret = vty_execute (vty);
- /* Note that vty_execute clears the command buffer and resets
- vty->length to 0. */
+ vty->buf[vty->length++] = *p;
+ if (*p == '\0')
+ {
+ /* Pass this line to parser. */
+ ret = vty_execute (vty);
+ /* Note that vty_execute clears the command buffer and resets
+ vty->length to 0. */
- /* Return result. */
+ /* Return result. */
#ifdef VTYSH_DEBUG
- printf ("result: %d\n", ret);
- printf ("vtysh node: %d\n", vty->node);
+ printf ("result: %d\n", ret);
+ printf ("vtysh node: %d\n", vty->node);
#endif /* VTYSH_DEBUG */
- /* hack for asynchronous "write integrated"
- * - other commands in "buf" will be ditched
- * - input during pending config-write is "unsupported" */
- if (ret == CMD_SUSPEND)
- break;
+ /* hack for asynchronous "write integrated"
+ * - other commands in "buf" will be ditched
+ * - input during pending config-write is "unsupported" */
+ if (ret == CMD_SUSPEND)
+ break;
- /* warning: watchfrr hardcodes this result write */
- header[3] = ret;
- buffer_put(vty->obuf, header, 4);
+ /* warning: watchquagga hardcodes this result write */
+ header[3] = ret;
+ buffer_put(vty->obuf, header, 4);
- if (!vty->t_write && (vtysh_flush(vty) < 0))
- /* Try to flush results; exit if a write error occurs. */
- return 0;
+ if (!vty->t_write && (vtysh_flush(vty) < 0))
+ /* Try to flush results; exit if a write error occurs. */
+ return 0;
+ }
}
}
diff --git a/lib/vty.h b/lib/vty.h
index 24bdcd1817..f0b833d4d8 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -26,7 +26,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "sockunion.h"
#include "qobj.h"
-#define VTY_BUFSIZ 512
+#define VTY_BUFSIZ 4096
#define VTY_MAXHIST 20
/* VTY struct. */
diff --git a/lib/zebra.h b/lib/zebra.h
index 3a9ad15bf4..5a58cf8e6e 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -473,9 +473,28 @@ typedef enum {
#define SAFI_MULTICAST 2
#define SAFI_MPLS_VPN 3
#define SAFI_RESERVED_4 4
-#define SAFI_ENCAP 7 /* per IANA */
+#define SAFI_ENCAP 5
#define SAFI_RESERVED_5 5
-#define SAFI_MAX 8
+#define SAFI_MAX 6
+
+/*
+ * The above AFI and SAFI definitions are for internal use. The protocol
+ * definitions (IANA values) as for example used in BGP protocol packets
+ * are defined below and these will get mapped to/from the internal values
+ * in the appropriate places.
+ * The rationale is that the protocol (IANA) values may be sparse and are
+ * not optimal for use in data-structure sizing.
+ * Note: Only useful (i.e., supported) values are defined below.
+ */
+#define IANA_AFI_RESERVED 0
+#define IANA_AFI_IPV4 1
+#define IANA_AFI_IPV6 2
+
+#define IANA_SAFI_RESERVED 0
+#define IANA_SAFI_UNICAST 1
+#define IANA_SAFI_MULTICAST 2
+#define IANA_SAFI_ENCAP 7
+#define IANA_SAFI_MPLS_VPN 128
/* Default Administrative Distance of each protocol. */
#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
@@ -509,4 +528,48 @@ typedef uint32_t route_tag_t;
#define ROUTE_TAG_MAX UINT32_MAX
#define ROUTE_TAG_PRI PRIu32
+static inline afi_t afi_iana2int (afi_t afi)
+{
+ if (afi == IANA_AFI_IPV4)
+ return AFI_IP;
+ if (afi == IANA_AFI_IPV6)
+ return AFI_IP6;
+ return AFI_MAX;
+}
+
+static inline afi_t afi_int2iana (afi_t afi)
+{
+ if (afi == AFI_IP)
+ return IANA_AFI_IPV4;
+ if (afi == AFI_IP6)
+ return IANA_AFI_IPV6;
+ return IANA_AFI_RESERVED;
+}
+
+static inline safi_t safi_iana2int (safi_t safi)
+{
+ if (safi == IANA_SAFI_UNICAST)
+ return SAFI_UNICAST;
+ if (safi == IANA_SAFI_MULTICAST)
+ return SAFI_MULTICAST;
+ if (safi == IANA_SAFI_MPLS_VPN)
+ return SAFI_MPLS_VPN;
+ if (safi == IANA_SAFI_ENCAP)
+ return SAFI_ENCAP;
+ return SAFI_MAX;
+}
+
+static inline safi_t safi_int2iana (safi_t safi)
+{
+ if (safi == SAFI_UNICAST)
+ return IANA_SAFI_UNICAST;
+ if (safi == SAFI_MULTICAST)
+ return IANA_SAFI_MULTICAST;
+ if (safi == SAFI_MPLS_VPN)
+ return IANA_SAFI_MPLS_VPN;
+ if (safi == SAFI_ENCAP)
+ return IANA_SAFI_ENCAP;
+ return IANA_SAFI_RESERVED;
+}
+
#endif /* _ZEBRA_H */