summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2016-03-01 15:31:28 -0300
committerDonald Sharp <sharpd@cumulusnetworks.com>2016-09-23 09:31:09 -0400
commiteac6e3f027356c25a8c8fddf921f769b79945fcc (patch)
tree69d5a17fb3f95934bafa22f8a3aee28c92780d62 /lib
parente30090a678e45aee2755c492212c5a478b9dcfcc (diff)
ldpd: adapt the code for Quagga
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am5
-rw-r--r--lib/command.c35
-rw-r--r--lib/command.h7
-rw-r--r--lib/imsg-buffer.c14
-rw-r--r--lib/imsg.c50
-rw-r--r--lib/log.c3
-rw-r--r--lib/log.h2
-rw-r--r--lib/mpls.h9
-rw-r--r--lib/privs.c9
-rw-r--r--lib/route_types.txt2
-rw-r--r--lib/vty.c40
-rw-r--r--lib/vty.h11
12 files changed, 158 insertions, 29 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index dbb80076c5..17be655a17 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -14,7 +14,8 @@ libzebra_la_SOURCES = \
filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
zclient.c sockopt.c smux.c agentx.c snmp.c md5.c if_rmap.c keychain.c privs.c \
sigevent.c pqueue.c jhash.c workqueue.c nexthop.c json.c \
- ptm_lib.c csv.c bfd.c vrf.c systemd.c ns.c memory.c memory_vty.c
+ ptm_lib.c csv.c bfd.c vrf.c systemd.c ns.c memory.c memory_vty.c \
+ imsg-buffer.c imsg.c
BUILT_SOURCES = route_types.h gitversion.h
@@ -31,7 +32,7 @@ pkginclude_HEADERS = \
privs.h sigevent.h pqueue.h jhash.h zassert.h \
workqueue.h route_types.h libospf.h nexthop.h json.h \
ptm_lib.h csv.h bfd.h vrf.h ns.h systemd.h bitfield.h \
- fifo.h memory_vty.h
+ fifo.h memory_vty.h mpls.h imsg.h openbsd-queue.h openbsd-tree.h
noinst_HEADERS = \
plist_int.h
diff --git a/lib/command.c b/lib/command.c
index cfdb91a5b9..bf8b1b1d33 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -2550,6 +2550,19 @@ node_parent ( enum node_type node )
case LINK_PARAMS_NODE:
ret = INTERFACE_NODE;
break;
+ case LDP_IPV4_NODE:
+ case LDP_IPV6_NODE:
+ ret = LDP_NODE;
+ break;
+ case LDP_IPV4_IFACE_NODE:
+ ret = LDP_IPV4_NODE;
+ break;
+ case LDP_IPV6_IFACE_NODE:
+ ret = LDP_IPV6_NODE;
+ break;
+ case LDP_PSEUDOWIRE_NODE:
+ ret = LDP_L2VPN_NODE;
+ break;
default:
ret = CONFIG_NODE;
break;
@@ -2920,6 +2933,8 @@ DEFUN (config_exit,
case RIPNG_NODE:
case OSPF_NODE:
case OSPF6_NODE:
+ case LDP_NODE:
+ case LDP_L2VPN_NODE:
case ISIS_NODE:
case KEYCHAIN_NODE:
case MASC_NODE:
@@ -2938,6 +2953,19 @@ DEFUN (config_exit,
case BGP_IPV6M_NODE:
vty->node = BGP_NODE;
break;
+ case LDP_IPV4_NODE:
+ case LDP_IPV6_NODE:
+ vty->node = LDP_NODE;
+ break;
+ case LDP_IPV4_IFACE_NODE:
+ vty->node = LDP_IPV4_NODE;
+ break;
+ case LDP_IPV6_IFACE_NODE:
+ vty->node = LDP_IPV6_NODE;
+ break;
+ case LDP_PSEUDOWIRE_NODE:
+ vty->node = LDP_L2VPN_NODE;
+ break;
case KEYCHAIN_KEY_NODE:
vty->node = KEYCHAIN_NODE;
break;
@@ -2988,6 +3016,13 @@ DEFUN (config_end,
case RMAP_NODE:
case OSPF_NODE:
case OSPF6_NODE:
+ case LDP_NODE:
+ case LDP_IPV4_NODE:
+ case LDP_IPV6_NODE:
+ case LDP_IPV4_IFACE_NODE:
+ case LDP_IPV6_IFACE_NODE:
+ case LDP_L2VPN_NODE:
+ case LDP_PSEUDOWIRE_NODE:
case ISIS_NODE:
case KEYCHAIN_NODE:
case KEYCHAIN_KEY_NODE:
diff --git a/lib/command.h b/lib/command.h
index 808e742059..7a4c53a616 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -98,6 +98,13 @@ enum node_type
BGP_ENCAPV6_NODE, /* BGP ENCAP SAFI */
OSPF_NODE, /* OSPF protocol mode */
OSPF6_NODE, /* OSPF protocol for IPv6 mode */
+ LDP_NODE, /* LDP protocol mode */
+ LDP_IPV4_NODE, /* LDP IPv4 address family */
+ LDP_IPV6_NODE, /* LDP IPv6 address family */
+ LDP_IPV4_IFACE_NODE, /* LDP IPv4 Interface */
+ LDP_IPV6_IFACE_NODE, /* LDP IPv6 Interface */
+ LDP_L2VPN_NODE, /* LDP L2VPN node */
+ LDP_PSEUDOWIRE_NODE, /* LDP Pseudowire node */
ISIS_NODE, /* ISIS protocol mode */
PIM_NODE, /* PIM protocol mode */
MASC_NODE, /* MASC for multicast. */
diff --git a/lib/imsg-buffer.c b/lib/imsg-buffer.c
index 61b2c095ae..a486fc17c1 100644
--- a/lib/imsg-buffer.c
+++ b/lib/imsg-buffer.c
@@ -16,17 +16,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include <zebra.h>
+#include "openbsd-queue.h"
#include "imsg.h"
int ibuf_realloc(struct ibuf *, size_t);
@@ -258,7 +250,7 @@ msgbuf_write(struct msgbuf *msgbuf)
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(cmsg) = buf->fd;
+ memcpy(CMSG_DATA(cmsg), &buf->fd, sizeof(int));
}
again:
diff --git a/lib/imsg.c b/lib/imsg.c
index 0c1cb8220c..246430cdd5 100644
--- a/lib/imsg.c
+++ b/lib/imsg.c
@@ -16,22 +16,49 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include <zebra.h>
+#include "openbsd-queue.h"
#include "imsg.h"
int imsg_fd_overhead = 0;
int imsg_get_fd(struct imsgbuf *);
+#ifndef __OpenBSD__
+/*
+ * The original code calls getdtablecount() which is OpenBSD specific. Use
+ * available_fds() from OpenSMTPD instead.
+ */
+static int
+available_fds(unsigned int n)
+{
+ unsigned int i;
+ int ret, fds[256];
+
+ if (n > (sizeof(fds)/sizeof(fds[0])))
+ return (1);
+
+ ret = 0;
+ for (i = 0; i < n; i++) {
+ fds[i] = -1;
+ if ((fds[i] = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)
+ fds[i] = socket(AF_INET6, SOCK_DGRAM, 0);
+ if (fds[i] < 0) {
+ ret = 1;
+ break;
+ }
+ }
+ }
+
+ for (i = 0; i < n && fds[i] >= 0; i++)
+ close(fds[i]);
+
+ return (ret);
+}
+#endif
+
void
imsg_init(struct imsgbuf *ibuf, int fd)
{
@@ -71,9 +98,14 @@ imsg_read(struct imsgbuf *ibuf)
return (-1);
again:
+#ifdef __OpenBSD__
if (getdtablecount() + imsg_fd_overhead +
(int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))
>= getdtablesize()) {
+#else
+ if (available_fds(imsg_fd_overhead +
+ (CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))) {
+#endif
errno = EAGAIN;
free(ifd);
return (-1);
diff --git a/lib/log.c b/lib/log.c
index b9edb12fbd..14fa81a9d7 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -51,6 +51,7 @@ const char *zlog_proto_names[] =
"OSPF",
"RIPNG",
"OSPF6",
+ "LDP",
"ISIS",
"PIM",
"MASC",
@@ -177,7 +178,7 @@ time_print(FILE *fp, struct timestamp_control *ctl)
/* va_list version of zlog. */
-static void
+void
vzlog (struct zlog *zl, int priority, const char *format, va_list args)
{
char proto_str[32];
diff --git a/lib/log.h b/lib/log.h
index 951fa124c8..31bf2b67cf 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -51,6 +51,7 @@ typedef enum
ZLOG_OSPF,
ZLOG_RIPNG,
ZLOG_OSPF6,
+ ZLOG_LDP,
ZLOG_ISIS,
ZLOG_PIM,
ZLOG_MASC
@@ -115,6 +116,7 @@ extern void zlog (struct zlog *zl, int priority, const char *format, ...)
PRINTF_ATTRIBUTE(3, 4);
/* Handy zlog functions. */
+extern void vzlog (struct zlog *zl, int priority, const char *format, va_list args);
extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
diff --git a/lib/mpls.h b/lib/mpls.h
index 8889868970..5a67b915d1 100644
--- a/lib/mpls.h
+++ b/lib/mpls.h
@@ -169,4 +169,13 @@ label2str (mpls_label_t label, char *buf, int len)
return(buf);
}
+/* constants used by ldpd */
+#define MPLS_LABEL_IPV4NULL 0 /* IPv4 Explicit NULL Label */
+#define MPLS_LABEL_RTALERT 1 /* Router Alert Label */
+#define MPLS_LABEL_IPV6NULL 2 /* IPv6 Explicit NULL Label */
+#define MPLS_LABEL_IMPLNULL 3 /* Implicit NULL Label */
+/* MPLS_LABEL_RESERVED 4-15 */ /* Values 4-15 are reserved */
+#define MPLS_LABEL_RESERVED_MAX 15
+#define MPLS_LABEL_MAX ((1 << 20) - 1)
+
#endif
diff --git a/lib/privs.c b/lib/privs.c
index 9228a56d35..6cf87c18d4 100644
--- a/lib/privs.c
+++ b/lib/privs.c
@@ -250,12 +250,6 @@ zprivs_caps_init (struct zebra_privs_t *zprivs)
exit(1);
}
- if ( !zprivs_state.syscaps_p )
- {
- fprintf (stderr, "privs_init: capabilities enabled, "
- "but no capabilities supplied\n");
- }
-
/* we have caps, we have no need to ever change back the original user */
if (zprivs_state.zuid)
{
@@ -266,6 +260,9 @@ zprivs_caps_init (struct zebra_privs_t *zprivs)
exit (1);
}
}
+
+ if ( !zprivs_state.syscaps_p )
+ return;
if ( !(zprivs_state.caps = cap_init()) )
{
diff --git a/lib/route_types.txt b/lib/route_types.txt
index 8fc3092cac..0ac442d85d 100644
--- a/lib/route_types.txt
+++ b/lib/route_types.txt
@@ -60,6 +60,7 @@ ZEBRA_ROUTE_PIM, pim, pimd, 'P', 1, 0, "PIM"
ZEBRA_ROUTE_HSLS, hsls, hslsd, 'H', 0, 0, "HSLS"
ZEBRA_ROUTE_OLSR, olsr, olsrd, 'o', 0, 0, "OLSR"
ZEBRA_ROUTE_TABLE, table, zebra, 'T', 1, 1, "Table"
+ZEBRA_ROUTE_LDP, ldp, ldpd, 'L', 0, 0, "LDP"
## help strings
ZEBRA_ROUTE_SYSTEM, "Reserved route type, for internal use only"
@@ -76,3 +77,4 @@ ZEBRA_ROUTE_PIM, "Protocol Independent Multicast (PIM)"
ZEBRA_ROUTE_HSLS, "Hazy-Sighted Link State Protocol (HSLS)"
ZEBRA_ROUTE_OLSR, "Optimised Link State Routing (OLSR)"
ZEBRA_ROUTE_TABLE, "Non-main Kernel Routing Table"
+ZEBRA_ROUTE_LDP, "Label Distribution Protocol (LDP)"
diff --git a/lib/vty.c b/lib/vty.c
index 48b64a95c4..3f13500449 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -754,6 +754,13 @@ vty_end_config (struct vty *vty)
case RMAP_NODE:
case OSPF_NODE:
case OSPF6_NODE:
+ case LDP_NODE:
+ case LDP_IPV4_NODE:
+ case LDP_IPV6_NODE:
+ case LDP_IPV4_IFACE_NODE:
+ case LDP_IPV6_IFACE_NODE:
+ case LDP_L2VPN_NODE:
+ case LDP_PSEUDOWIRE_NODE:
case ISIS_NODE:
case KEYCHAIN_NODE:
case KEYCHAIN_KEY_NODE:
@@ -1158,6 +1165,13 @@ vty_stop_input (struct vty *vty)
case RMAP_NODE:
case OSPF_NODE:
case OSPF6_NODE:
+ case LDP_NODE:
+ case LDP_IPV4_NODE:
+ case LDP_IPV6_NODE:
+ case LDP_IPV4_IFACE_NODE:
+ case LDP_IPV6_IFACE_NODE:
+ case LDP_L2VPN_NODE:
+ case LDP_PSEUDOWIRE_NODE:
case ISIS_NODE:
case KEYCHAIN_NODE:
case KEYCHAIN_KEY_NODE:
@@ -3180,3 +3194,29 @@ vty_terminate (void)
vector_free (Vvty_serv_thread);
}
}
+
+/* Utility functions to get arguments from commands generated
+ by the xml2cli.pl script. */
+const char *
+vty_get_arg_value (struct vty_arg *args[], const char *arg)
+{
+ while (*args)
+ {
+ if (strcmp ((*args)->name, arg) == 0)
+ return (*args)->value;
+ args++;
+ }
+ return NULL;
+}
+
+struct vty_arg *
+vty_get_arg (struct vty_arg *args[], const char *arg)
+{
+ while (*args)
+ {
+ if (strcmp ((*args)->name, arg) == 0)
+ return *args;
+ args++;
+ }
+ return NULL;
+}
diff --git a/lib/vty.h b/lib/vty.h
index 599882a382..4f1dbe653e 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -127,6 +127,14 @@ struct vty
char address[SU_ADDRSTRLEN];
};
+struct vty_arg
+{
+ const char *name;
+ const char *value;
+ const char **argv;
+ int argc;
+};
+
/* Integrated configuration file. */
#define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
@@ -292,4 +300,7 @@ extern void vty_hello (struct vty *);
an async-signal-safe function. */
extern void vty_log_fixed (char *buf, size_t len);
+extern const char *vty_get_arg_value (struct vty_arg **, const char *);
+extern struct vty_arg *vty_get_arg (struct vty_arg **, const char *);
+
#endif /* _ZEBRA_VTY_H */