summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Fought <Rich.Fought@watchguard.com>2012-10-08 17:31:42 -0700
committerRich Fought <Rich.Fought@watchguard.com>2012-10-08 17:31:42 -0700
commit4a702e6b728f0ecfe7994c650403b6e7c8ffc88f (patch)
tree6f11d4c030b7622f233a065565334c002d32ba30
parentf111efd894560a3f5d4393ff9aa59d1d87b78f6e (diff)
downloadlibnl-4a702e6b728f0ecfe7994c650403b6e7c8ffc88f.tar.gz
Starting CLI work
-rw-r--r--include/netlink/cli/exp.h30
-rw-r--r--src/lib/exp.c127
2 files changed, 157 insertions, 0 deletions
diff --git a/include/netlink/cli/exp.h b/include/netlink/cli/exp.h
new file mode 100644
index 0000000..94609d7
--- /dev/null
+++ b/include/netlink/cli/exp.h
@@ -0,0 +1,30 @@
+/*
+ * netlink/cli/exp.h CLI Expectation Helper
+ *
+ * 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) 2012 Rich Fought <Rich.Fought@watchguard.com>
+ */
+
+#ifndef __NETLINK_CLI_EXP_H_
+#define __NETLINK_CLI_EXP_H_
+
+#include <netlink/netfilter/exp.h>
+#include <linux/netfilter/nf_conntrack_common.h>
+
+extern struct nfnl_exp *nl_cli_exp_alloc(void);
+extern struct nl_cache *nl_cli_exp_alloc_cache(struct nl_sock *);
+
+extern void nl_cli_exp_parse_family(struct nfnl_exp *, char *);
+extern void nl_cli_exp_parse_timeout(struct nfnl_exp *, char *);
+extern void nl_cli_exp_parse_id(struct nfnl_exp *, char *);
+extern void nl_cli_exp_parse_src(struct nfnl_exp *, int, char *);
+extern void nl_cli_exp_parse_dst(struct nfnl_exp *, int, char *);
+extern void nl_cli_exp_parse_l4protonum(struct nfnl_exp *, int, char *);
+extern void nl_cli_exp_parse_src_port(struct nfnl_exp *, int, char *);
+extern void nl_cli_exp_parse_dst_port(struct nfnl_exp *, int, char *);
+
+#endif
diff --git a/src/lib/exp.c b/src/lib/exp.c
new file mode 100644
index 0000000..7e10803
--- /dev/null
+++ b/src/lib/exp.c
@@ -0,0 +1,127 @@
+/*
+ * 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) 20012 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_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);
+ nfnl_exp_set_ports(exp, tuple, sport, 0);
+}
+
+void nl_cli_exp_parse_dst_port(struct nfnl_exp *exp, int tuple, char *arg)
+{
+ uint32_t dport = nl_cli_parse_u32(arg);
+ uint32_t sport = nfnl_exp_get_src_port(exp, tuple);
+ nfnl_exp_set_ports(exp, tuple, sport, dport);
+}
+
+#if 0
+ } else if (arg_match("origicmpid")) {
+ if (argc > ++idx)
+ nfnl_ct_set_icmp_id(ct, 0, strtoul(argv[idx++], NULL, 0));
+ } else if (arg_match("origicmptype")) {
+ if (argc > ++idx)
+ nfnl_ct_set_icmp_type(ct, 0, strtoul(argv[idx++], NULL, 0));
+ } else if (arg_match("origicmpcode")) {
+ if (argc > ++idx)
+ nfnl_ct_set_icmp_code(ct, 0, strtoul(argv[idx++], NULL, 0));
+ } else if (arg_match("replyicmpid")) {
+ if (argc > ++idx)
+ nfnl_ct_set_icmp_id(ct, 1, strtoul(argv[idx++], NULL, 0));
+ } else if (arg_match("replyicmptype")) {
+ if (argc > ++idx)
+ nfnl_ct_set_icmp_type(ct, 1, strtoul(argv[idx++], NULL, 0));
+ } else if (arg_match("replyicmpcode")) {
+ if (argc > ++idx)
+ nfnl_ct_set_icmp_code(ct, 1, strtoul(argv[idx++], NULL, 0));
+ }
+#endif
+
+/** @} */