summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile.am19
-rw-r--r--src/lib/exp.c165
-rw-r--r--src/lib/link.c2
-rw-r--r--src/lib/route.c16
-rw-r--r--src/lib/tc.c4
-rw-r--r--src/lib/utils.c3
6 files changed, 192 insertions, 17 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 3236dbe..6688e7c 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -1,7 +1,10 @@
# -*- Makefile -*-
AM_CPPFLAGS = -Wall -I${top_srcdir}/include -I${top_builddir}/include -D_GNU_SOURCE -DPKGLIBDIR=\"$(pkglibdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -rdynamic
-AM_LDFLAGS = -L${top_builddir}/lib -ldl -version-info 3:0:0
+AM_LDFLAGS = \
+ -L${top_builddir}/lib \
+ -ldl \
+ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
#nobase_pkglib_LTLIBRARIES = cls/basic.la cls/ematch/cmp.la
#cls_basic_la_LDFLAGS = -module -version-info 2:0:0
@@ -26,15 +29,15 @@ AM_LDFLAGS = -L${top_builddir}/lib -ldl -version-info 3:0:0
# cls/pktloc_syntax.c cls/pktloc_syntax.h
lib_LTLIBRARIES = \
- libnl-cli.la
+ libnl-cli-3.la
-libnl_cli_la_LIBADD = ${top_builddir}/lib/libnl.la \
- ${top_builddir}/lib/libnl-route.la \
- ${top_builddir}/lib/libnl-nf.la \
- ${top_builddir}/lib/libnl-genl.la
+libnl_cli_3_la_LIBADD = ${top_builddir}/lib/libnl-3.la \
+ ${top_builddir}/lib/libnl-route-3.la \
+ ${top_builddir}/lib/libnl-nf-3.la \
+ ${top_builddir}/lib/libnl-genl-3.la
-libnl_cli_la_SOURCES = \
+libnl_cli_3_la_SOURCES = \
utils.c addr.c ct.c link.c neigh.c rule.c route.c \
- tc.c qdisc.c class.c cls.c
+ tc.c qdisc.c class.c cls.c exp.c
# cls/ematch_syntax.c cls/ematch_grammar.c cls/ematch.c
# cls/pktloc_syntax.c cls/pktloc_grammar.c cls/utils.c
diff --git a/src/lib/exp.c b/src/lib/exp.c
new file mode 100644
index 0000000..a7a74f5
--- /dev/null
+++ b/src/lib/exp.c
@@ -0,0 +1,165 @@
+/*
+ * src/lib/exp.c CLI Expectation Helpers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2012 Rich Fought <rich.fought@watchguard.com>
+ */
+
+/**
+ * @ingroup cli
+ * @defgroup cli_exp Expectation Tracking
+ *
+ * @{
+ */
+
+#include <netlink/cli/utils.h>
+#include <netlink/cli/exp.h>
+
+struct nfnl_exp *nl_cli_exp_alloc(void)
+{
+ struct nfnl_exp *exp;
+
+ exp = nfnl_exp_alloc();
+ if (!exp)
+ nl_cli_fatal(ENOMEM, "Unable to allocate expectation object");
+
+ return exp;
+}
+
+struct nl_cache *nl_cli_exp_alloc_cache(struct nl_sock *sk)
+{
+ return nl_cli_alloc_cache(sk, "expectation", nfnl_exp_alloc_cache);
+}
+
+void nl_cli_exp_parse_family(struct nfnl_exp *exp, char *arg)
+{
+ int family;
+
+ if ((family = nl_str2af(arg)) == AF_UNSPEC)
+ nl_cli_fatal(EINVAL,
+ "Unable to nl_cli_exp_parse family \"%s\": %s",
+ arg, nl_geterror(NLE_INVAL));
+
+ nfnl_exp_set_family(exp, family);
+}
+
+void nl_cli_exp_parse_timeout(struct nfnl_exp *exp, char *arg)
+{
+ uint32_t timeout = nl_cli_parse_u32(arg);
+ nfnl_exp_set_timeout(exp, timeout);
+}
+
+void nl_cli_exp_parse_id(struct nfnl_exp *exp, char *arg)
+{
+ uint32_t id = nl_cli_parse_u32(arg);
+ nfnl_exp_set_id(exp, id);
+}
+
+void nl_cli_exp_parse_helper_name(struct nfnl_exp *exp, char *arg)
+{
+ nfnl_exp_set_helper_name(exp, arg);
+}
+
+void nl_cli_exp_parse_zone(struct nfnl_exp *exp, char *arg)
+{
+ uint32_t zone = nl_cli_parse_u32(arg);
+ nfnl_exp_set_zone(exp, zone);
+}
+
+void nl_cli_exp_parse_flags(struct nfnl_exp *exp, char *arg)
+{
+ uint32_t flags = nl_cli_parse_u32(arg);
+ nfnl_exp_set_flags(exp, flags);
+}
+
+void nl_cli_exp_parse_class(struct nfnl_exp *exp, char *arg)
+{
+ uint32_t class = nl_cli_parse_u32(arg);
+ nfnl_exp_set_class(exp, class);
+}
+
+void nl_cli_exp_parse_nat_dir(struct nfnl_exp *exp, char *arg)
+{
+ uint32_t nat_dir = nl_cli_parse_u32(arg);
+ nfnl_exp_set_nat_dir(exp, nat_dir);
+}
+
+void nl_cli_exp_parse_fn(struct nfnl_exp *exp, char *arg)
+{
+ nfnl_exp_set_fn(exp, arg);
+}
+
+void nl_cli_exp_parse_src(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ int err;
+ struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_exp_get_family(exp));
+ if ((err = nfnl_exp_set_src(exp, tuple, a)) < 0)
+ nl_cli_fatal(err, "Unable to set source address: %s",
+ nl_geterror(err));
+}
+
+void nl_cli_exp_parse_dst(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ int err;
+ struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_exp_get_family(exp));
+ if ((err = nfnl_exp_set_dst(exp, tuple, a)) < 0)
+ nl_cli_fatal(err, "Unable to set destination address: %s",
+ nl_geterror(err));
+}
+
+void nl_cli_exp_parse_l4protonum(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ int l4protonum;
+
+ if ((l4protonum = nl_str2ip_proto(arg)) < 0)
+ nl_cli_fatal(l4protonum,
+ "Unable to nl_cli_exp_parse protocol \"%s\": %s",
+ arg, nl_geterror(l4protonum));
+
+ nfnl_exp_set_l4protonum(exp, tuple, l4protonum);
+}
+
+void nl_cli_exp_parse_src_port(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ uint32_t sport = nl_cli_parse_u32(arg);
+ uint16_t dport = nfnl_exp_get_dst_port(exp, tuple);
+ nfnl_exp_set_ports(exp, tuple, sport, dport);
+}
+
+void nl_cli_exp_parse_dst_port(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ uint32_t dport = nl_cli_parse_u32(arg);
+ uint16_t sport = nfnl_exp_get_src_port(exp, tuple);
+ nfnl_exp_set_ports(exp, tuple, sport, dport);
+}
+
+void nl_cli_exp_parse_icmp_id(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ uint32_t id = nl_cli_parse_u32(arg);
+ uint8_t type = nfnl_exp_get_icmp_type(exp, tuple);
+ uint8_t code = nfnl_exp_get_icmp_code(exp, tuple);
+ nfnl_exp_set_icmp(exp, tuple, id, type, code);
+}
+
+void nl_cli_exp_parse_icmp_type(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ uint32_t type = nl_cli_parse_u32(arg);
+ uint16_t id = nfnl_exp_get_icmp_id(exp, tuple);
+ uint8_t code = nfnl_exp_get_icmp_code(exp, tuple);
+ nfnl_exp_set_icmp(exp, tuple, id, type, code);
+}
+
+void nl_cli_exp_parse_icmp_code(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ uint32_t code = nl_cli_parse_u32(arg);
+ uint16_t id = nfnl_exp_get_icmp_id(exp, tuple);
+ uint8_t type = nfnl_exp_get_icmp_type(exp, tuple);
+ nfnl_exp_set_icmp(exp, tuple, id, type, code);
+}
+
+/** @} */
diff --git a/src/lib/link.c b/src/lib/link.c
index db90558..5bce824 100644
--- a/src/lib/link.c
+++ b/src/lib/link.c
@@ -86,8 +86,6 @@ void nl_cli_link_parse_txqlen(struct rtnl_link *link, char *arg)
void nl_cli_link_parse_weight(struct rtnl_link *link, char *arg)
{
- uint32_t weight = nl_cli_parse_u32(arg);
- rtnl_link_set_weight(link, weight);
}
void nl_cli_link_parse_ifalias(struct rtnl_link *link, char *arg)
diff --git a/src/lib/route.c b/src/lib/route.c
index 05cb2ad..cd3e897 100644
--- a/src/lib/route.c
+++ b/src/lib/route.c
@@ -198,14 +198,18 @@ void nl_cli_route_parse_table(struct rtnl_route *route, char *arg)
{
unsigned long lval;
char *endptr;
+ int table;
lval = strtoul(arg, &endptr, 0);
if (endptr == arg) {
- if ((lval = rtnl_route_str2table(arg)) < 0)
+ if ((table = rtnl_route_str2table(arg)) < 0)
nl_cli_fatal(EINVAL, "Unknown table name \"%s\"", arg);
}
+ else {
+ table = lval;
+ }
- rtnl_route_set_table(route, lval);
+ rtnl_route_set_table(route, table);
}
void nl_cli_route_parse_prio(struct rtnl_route *route, char *arg)
@@ -233,16 +237,20 @@ void nl_cli_route_parse_protocol(struct rtnl_route *route, char *arg)
{
unsigned long lval;
char *endptr;
+ int proto;
lval = strtoul(arg, &endptr, 0);
if (endptr == arg) {
- if ((lval = rtnl_route_str2proto(arg)) < 0)
+ if ((proto = rtnl_route_str2proto(arg)) < 0)
nl_cli_fatal(EINVAL,
"Unknown routing protocol name \"%s\"",
arg);
}
+ else {
+ proto = lval;
+ }
- rtnl_route_set_protocol(route, lval);
+ rtnl_route_set_protocol(route, proto);
}
void nl_cli_route_parse_type(struct rtnl_route *route, char *arg)
diff --git a/src/lib/tc.c b/src/lib/tc.c
index 4cdd081..dde729f 100644
--- a/src/lib/tc.c
+++ b/src/lib/tc.c
@@ -11,7 +11,7 @@
#include <netlink/cli/utils.h>
#include <netlink/cli/tc.h>
-#include <netlink/route/tc-api.h>
+#include <netlink-private/route/tc-api.h>
/**
* @ingroup cli
@@ -94,7 +94,7 @@ void nl_cli_tc_parse_linktype(struct rtnl_tc *tc, char *arg)
static NL_LIST_HEAD(tc_modules);
-struct nl_cli_tc_module *__nl_cli_tc_lookup(struct rtnl_tc_ops *ops)
+static struct nl_cli_tc_module *__nl_cli_tc_lookup(struct rtnl_tc_ops *ops)
{
struct nl_cli_tc_module *tm;
diff --git a/src/lib/utils.c b/src/lib/utils.c
index 78ad260..e5eacde 100644
--- a/src/lib/utils.c
+++ b/src/lib/utils.c
@@ -70,6 +70,7 @@ void nl_cli_print_version(void)
void nl_cli_fatal(int err, const char *fmt, ...)
{
va_list ap;
+ char buf[256];
fprintf(stderr, "Error: ");
@@ -79,7 +80,7 @@ void nl_cli_fatal(int err, const char *fmt, ...)
va_end(ap);
fprintf(stderr, "\n");
} else
- fprintf(stderr, "%s\n", strerror(err));
+ fprintf(stderr, "%s\n", strerror_r(err, buf, sizeof(buf)));
exit(abs(err));
}