diff options
71 files changed, 1446 insertions, 1401 deletions
diff --git a/configure.in b/configure.in index b00a759..02b5119 100644 --- a/configure.in +++ b/configure.in @@ -30,6 +30,6 @@ AC_SUBST([pkgconfigdir]) AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required])) AC_CONFIG_FILES([Makefile doc/Doxyfile doc/Makefile lib/Makefile - include/Makefile src/Makefile libnl-2.0.pc \ - include/netlink/version.h]) + include/Makefile src/Makefile src/lib/Makefile \ + libnl-2.0.pc include/netlink/version.h]) AC_OUTPUT diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 7e00f51..8e311e3 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -463,6 +463,7 @@ WARN_LOGFILE = # with spaces. INPUT = ../lib \ + ../src/lib \ ../include/netlink # This tag can be used to specify the character encoding of the source files that diff --git a/include/netlink/cli/addr.h b/include/netlink/cli/addr.h new file mode 100644 index 0000000..d0fd055 --- /dev/null +++ b/include/netlink/cli/addr.h @@ -0,0 +1,32 @@ +/* + * netlink/cli/addr.h CLI Address 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> + */ + +#ifndef __NETLINK_CLI_ADDR_H_ +#define __NETLINK_CLI_ADDR_H_ + +#include <netlink/route/addr.h> + +#define nl_cli_addr_alloc_cache(sk) \ + nl_cli_alloc_cache((sk), "address", rtnl_addr_alloc_cache) + +extern struct rtnl_addr *nl_cli_addr_alloc(void); + +extern void nl_cli_addr_parse_family(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_local(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_dev(struct rtnl_addr *, struct nl_cache *,char *); +extern void nl_cli_addr_parse_label(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_peer(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_scope(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_broadcast(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_preferred(struct rtnl_addr *, char *); +extern void nl_cli_addr_parse_valid(struct rtnl_addr *, char *); + +#endif diff --git a/include/netlink/cli/ct.h b/include/netlink/cli/ct.h new file mode 100644 index 0000000..bed776b --- /dev/null +++ b/include/netlink/cli/ct.h @@ -0,0 +1,34 @@ +/* + * netlink/cli/ct.h CLI Conntrack 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) 2008-2009 Thomas Graf <tgraf@suug.ch> + */ + +#ifndef __NETLINK_CLI_CT_H_ +#define __NETLINK_CLI_CT_H_ + +#include <netlink/netfilter/ct.h> +#include <linux/netfilter/nf_conntrack_common.h> + +extern struct nfnl_ct *nl_cli_ct_alloc(void); +extern struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *); + +extern void nl_cli_ct_parse_family(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_protocol(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_mark(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_timeout(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_id(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_use(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_src(struct nfnl_ct *, int, char *); +extern void nl_cli_ct_parse_dst(struct nfnl_ct *, int, char *); +extern void nl_cli_ct_parse_src_port(struct nfnl_ct *, int, char *); +extern void nl_cli_ct_parse_dst_port(struct nfnl_ct *, int, char *); +extern void nl_cli_ct_parse_tcp_state(struct nfnl_ct *, char *); +extern void nl_cli_ct_parse_status(struct nfnl_ct *, char *); + +#endif diff --git a/include/netlink/cli/link.h b/include/netlink/cli/link.h new file mode 100644 index 0000000..c404019 --- /dev/null +++ b/include/netlink/cli/link.h @@ -0,0 +1,30 @@ +/* + * netlink/cli/link.h CLI Link 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> + */ + +#ifndef __NETLINK_CLI_LINK_H_ +#define __NETLINK_CLI_LINK_H_ + +#include <netlink/route/link.h> +#include <netlink/cli/utils.h> + +#define nl_cli_link_alloc_cache(sk) \ + nl_cli_alloc_cache((sk), "link", rtnl_link_alloc_cache) + +extern struct rtnl_link *nl_cli_link_alloc(void); + +extern void nl_cli_link_parse_family(struct rtnl_link *, char *); +extern void nl_cli_link_parse_name(struct rtnl_link *, char *); +extern void nl_cli_link_parse_mtu(struct rtnl_link *, char *); +extern void nl_cli_link_parse_ifindex(struct rtnl_link *, char *); +extern void nl_cli_link_parse_txqlen(struct rtnl_link *, char *); +extern void nl_cli_link_parse_weight(struct rtnl_link *, char *); + +#endif diff --git a/include/netlink/cli/neigh.h b/include/netlink/cli/neigh.h new file mode 100644 index 0000000..5440012 --- /dev/null +++ b/include/netlink/cli/neigh.h @@ -0,0 +1,27 @@ +/* + * netlink/cli/neighbour.h CLI Neighbour 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> + */ + +#ifndef __NETLINK_CLI_NEIGH_H_ +#define __NETLINK_CLI_NEIGH_H_ + +#include <netlink/route/neighbour.h> + +#define nl_cli_neigh_alloc_cache(sk) \ + nl_cli_alloc_cache((sk), "neighbour", rtnl_neigh_alloc_cache) + +extern struct rtnl_neigh *nl_cli_neigh_alloc(void); +extern void nl_cli_neigh_parse_dst(struct rtnl_neigh *, char *); +extern void nl_cli_neigh_parse_lladdr(struct rtnl_neigh *, char *); +extern void nl_cli_neigh_parse_dev(struct rtnl_neigh *, struct nl_cache *, char *); +extern void nl_cli_neigh_parse_family(struct rtnl_neigh *, char *); +extern void nl_cli_neigh_parse_state(struct rtnl_neigh *, char *); + +#endif diff --git a/include/netlink/cli/qdisc.h b/include/netlink/cli/qdisc.h new file mode 100644 index 0000000..9fc4506 --- /dev/null +++ b/include/netlink/cli/qdisc.h @@ -0,0 +1,28 @@ +/* + * netlink/cli/qdisc.h CLI QDisc 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> + */ + +#ifndef __NETLINK_CLI_QDISC_H_ +#define __NETLINK_CLI_QDISC_H_ + +#include <netlink/route/qdisc.h> + +#define nl_cli_qdisc_alloc_cache(sk) \ + nl_cli_alloc_cache((sk), "queueing disciplines", \ + rtnl_qdisc_alloc_cache) + +extern struct rtnl_qdisc *nl_cli_qdisc_alloc(void); + +extern void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *, struct nl_cache *, char *); +extern void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *, char *); +extern void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *, char *); +extern void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *, char *); + +#endif diff --git a/include/netlink/cli/route.h b/include/netlink/cli/route.h new file mode 100644 index 0000000..089c658 --- /dev/null +++ b/include/netlink/cli/route.h @@ -0,0 +1,34 @@ +/* + * netlink/cli//route.h CLI Route 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> + */ + +#ifndef __NETLINK_CLI_ROUTE_H_ +#define __NETLINK_CLI_ROUTE_H_ + +#include <netlink/route/route.h> + +extern struct rtnl_route *nl_cli_route_alloc(void); + +extern struct nl_cache *nl_cli_route_alloc_cache(struct nl_sock *, int); + +extern void nl_cli_route_parse_family(struct rtnl_route *, char *); +extern void nl_cli_route_parse_dst(struct rtnl_route *, char *); +extern void nl_cli_route_parse_src(struct rtnl_route *, char *); +extern void nl_cli_route_parse_pref_src(struct rtnl_route *, char *); +extern void nl_cli_route_parse_metric(struct rtnl_route *, char *); +extern void nl_cli_route_parse_nexthop(struct rtnl_route *, char *, struct nl_cache *); +extern void nl_cli_route_parse_table(struct rtnl_route *, char *); +extern void nl_cli_route_parse_prio(struct rtnl_route *, char *); +extern void nl_cli_route_parse_scope(struct rtnl_route *, char *); +extern void nl_cli_route_parse_protocol(struct rtnl_route *, char *); +extern void nl_cli_route_parse_type(struct rtnl_route *, char *); +extern void nl_cli_route_parse_iif(struct rtnl_route *, char *, struct nl_cache *); + +#endif diff --git a/include/netlink/cli/rule.h b/include/netlink/cli/rule.h new file mode 100644 index 0000000..61cd63e --- /dev/null +++ b/include/netlink/cli/rule.h @@ -0,0 +1,21 @@ +/* + * netlink/cli/rule.h CLI Routing Rule 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> + */ + +#ifndef __NETLINK_CLI_RULE_H_ +#define __NETLINK_CLI_RULE_H_ + +#include <netlink/route/rule.h> + +extern struct rtnl_rule *nl_cli_rule_alloc(void); +extern struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *); +extern void nl_cli_rule_parse_family(struct rtnl_rule *, char *); + +#endif diff --git a/src/utils.h b/include/netlink/cli/utils.h index 69b6fdc..2a23208 100644 --- a/src/utils.h +++ b/include/netlink/cli/utils.h @@ -6,26 +6,30 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#ifndef __SRC_UTILS_H_ -#define __SRC_UTILS_H_ +#ifndef __NETLINK_CLI_UTILS_H_ +#define __NETLINK_CLI_UTILS_H_ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <stdarg.h> +#include <limits.h> #include <inttypes.h> #include <errno.h> #include <stdint.h> #include <ctype.h> #include <getopt.h> +#include <dlfcn.h> #include <sys/types.h> #include <sys/socket.h> #include <netlink/netlink.h> #include <netlink/utils.h> #include <netlink/addr.h> +#include <netlink/list.h> #include <netlink/route/rtnl.h> #include <netlink/route/link.h> #include <netlink/route/addr.h> @@ -44,6 +48,10 @@ #include <netlink/genl/mngt.h> #include <netlink/netfilter/ct.h> +#ifdef __cplusplus +extern "C" { +#endif + #ifndef __init #define __init __attribute__((constructor)) #endif @@ -52,26 +60,21 @@ #define __exit __attribute__((destructor)) #endif -extern uint32_t parse_u32(const char *); - -extern void nlt_print_version(void); -extern void fatal(int err, const char *fmt, ...); -extern struct nl_addr * nlt_addr_parse(const char *, int); - -extern int nlt_connect(struct nl_sock *, int); -extern struct nl_sock * nlt_alloc_socket(void); +extern uint32_t nl_cli_parse_u32(const char *); +extern void nl_cli_print_version(void); +extern void nl_cli_fatal(int, const char *, ...); +extern struct nl_addr * nl_cli_addr_parse(const char *, int); +extern int nl_cli_connect(struct nl_sock *, int); +extern struct nl_sock * nl_cli_alloc_socket(void); +extern int nl_cli_parse_dumptype(const char *); +extern int nl_cli_confirm(struct nl_object *, + struct nl_dump_params *, int); -extern int nlt_parse_dumptype(const char *str); -extern int nlt_confirm(struct nl_object *, struct nl_dump_params *, int); - -extern struct nl_cache *nlt_alloc_link_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_addr_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_neigh_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_neightbl_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_qdisc_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_route_cache(struct nl_sock *, int); -extern struct nl_cache *nlt_alloc_rule_cache(struct nl_sock *); -extern struct nl_cache *alloc_cache(struct nl_sock *, const char *, +extern struct nl_cache *nl_cli_alloc_cache(struct nl_sock *, const char *, int (*ac)(struct nl_sock *, struct nl_cache **)); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/Makefile.am b/src/Makefile.am index 1f2fe70..ca37843 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,9 @@ # -*- Makefile -*- +SUBDIRS = lib + AM_CFLAGS = -Wall -I${top_srcdir}/include -D_GNU_SOURCE -AM_LDFLAGS = -L${top_builddir}/lib +AM_LDFLAGS = -L${top_builddir}/lib -L${top_builddir}/src/lib -lnl-cli noinst_PROGRAMS = \ genl-ctrl-list \ @@ -20,83 +22,76 @@ noinst_PROGRAMS = \ nl-list-caches nl-list-sockets \ nl-util-addr -rtnl_utils_c = rtnl-utils.c utils.c - -genl_ctrl_list_SOURCES = genl-ctrl-list.c ctrl-utils.c utils.c -genl_ctrl_list_LDADD = -lnl-genl +genl_ctrl_list_SOURCES = genl-ctrl-list.c +genl_ctrl_list_LDADD = -lnl-genl -lnl-route -nf_ct_list_SOURCES = nf-ct-list.c ct-utils.c utils.c +nf_ct_list_SOURCES = nf-ct-list.c nf_ct_list_LDADD = -lnl-nf -nf_log_SOURCES = nf-log.c log-utils.c ${rtnl_utils_c} +nf_log_SOURCES = nf-log.c nf_log_LDADD = -lnl-nf -nf_queue_SOURCES = nf-queue.c queue-utils.c ${rtnl_utils_c} +nf_queue_SOURCES = nf-queue.c nf_queue_LDADD = -lnl-nf -nf_monitor_SOURCES = nf-monitor.c utils.c +nf_monitor_SOURCES = nf-monitor.c nf_monitor_LDADD = -lnl-nf -addr_c = addr-utils.c ${rtnl_utils_c} -nl_addr_add_SOURCES = nl-addr-add.c ${addr_c} +nl_addr_add_SOURCES = nl-addr-add.c nl_addr_add_LDADD = -lnl-route -nl_addr_delete_SOURCES = nl-addr-delete.c ${addr_c} +nl_addr_delete_SOURCES = nl-addr-delete.c nl_addr_delete_LDADD = -lnl-route -nl_addr_list_SOURCES = nl-addr-list.c ${addr_c} +nl_addr_list_SOURCES = nl-addr-list.c nl_addr_list_LDADD = -lnl-route -link_c = link-utils.c ${rtnl_utils_c} -nl_link_list_SOURCES = nl-link-list.c ${link_c} +nl_link_list_SOURCES = nl-link-list.c nl_link_list_LDADD = -lnl-route -nl_link_set_SOURCES = nl-link-set.c ${link_c} +nl_link_set_SOURCES = nl-link-set.c nl_link_set_LDADD = -lnl-route -nl_link_stats_SOURCES = nl-link-stats.c ${link_c} +nl_link_stats_SOURCES = nl-link-stats.c nl_link_stats_LDADD = -lnl-route -nl_link_ifindex2name_SOURCES = nl-link-ifindex2name.c ${rtnl_utils_c} +nl_link_ifindex2name_SOURCES = nl-link-ifindex2name.c nl_link_ifindex2name_LDADD = -lnl-route -nl_link_name2ifindex_SOURCES = nl-link-name2ifindex.c ${rtnl_utils_c} +nl_link_name2ifindex_SOURCES = nl-link-name2ifindex.c nl_link_name2ifindex_LDADD = -lnl-route -nl_monitor_SOURCES = nl-monitor.c ${rtnl_utils_c} +nl_monitor_SOURCES = nl-monitor.c nl_monitor_LDADD = -lnl-route -neigh_c = neigh-utils.c ${rtnl_utils_c} -nl_neigh_add_SOURCES = nl-neigh-add.c ${neigh_c} +nl_neigh_add_SOURCES = nl-neigh-add.c nl_neigh_add_LDADD = -lnl-route -nl_neigh_delete_SOURCES = nl-neigh-delete.c ${neigh_c} +nl_neigh_delete_SOURCES = nl-neigh-delete.c nl_neigh_delete_LDADD = -lnl-route -nl_neigh_list_SOURCES = nl-neigh-list.c ${neigh_c} +nl_neigh_list_SOURCES = nl-neigh-list.c nl_neigh_list_LDADD = -lnl-route -nl_neightbl_list_SOURCES = nl-neightbl-list.c ${rtnl_utils_c} +nl_neightbl_list_SOURCES = nl-neightbl-list.c nl_neightbl_list_LDADD = -lnl-route -qdisc_c = qdisc-utils.c ${rtnl_utils_c} -nl_qdisc_delete_SOURCES = nl-qdisc-delete.c ${qdisc_c} +nl_qdisc_delete_SOURCES = nl-qdisc-delete.c nl_qdisc_delete_LDADD = -lnl-route -nl_qdisc_list_SOURCES = nl-qdisc-list.c ${qdisc_c} +nl_qdisc_list_SOURCES = nl-qdisc-list.c nl_qdisc_list_LDADD = -lnl-route -route_c = route-utils.c ${rtnl_utils_c} -nl_route_add_SOURCES = nl-route-add.c ${route_c} +nl_route_add_SOURCES = nl-route-add.c nl_route_add_LDADD = -lnl-route -nl_route_delete_SOURCES = nl-route-delete.c ${route_c} +nl_route_delete_SOURCES = nl-route-delete.c nl_route_delete_LDADD = -lnl-route -nl_route_get_SOURCES = nl-route-get.c ${route_c} +nl_route_get_SOURCES = nl-route-get.c nl_route_get_LDADD = -lnl-route -nl_route_list_SOURCES = nl-route-list.c ${route_c} +nl_route_list_SOURCES = nl-route-list.c nl_route_list_LDADD = -lnl-route -nl_rule_list_SOURCES = nl-rule-list.c rule-utils.c ${rtnl_utils_c} +nl_rule_list_SOURCES = nl-rule-list.c nl_rule_list_LDADD = -lnl-route -nl_tctree_list_SOURCES = nl-tctree-list.c ${rtnl_utils_c} +nl_tctree_list_SOURCES = nl-tctree-list.c nl_tctree_list_LDADD = -lnl-route -nl_fib_lookup_SOURCES = nl-fib-lookup.c ${rtnl_utils_c} +nl_fib_lookup_SOURCES = nl-fib-lookup.c nl_fib_lookup_LDADD = -lnl-route -nl_list_caches_SOURCES = nl-list-caches.c ${rtnl_utils_c} +nl_list_caches_SOURCES = nl-list-caches.c nl_list_caches_LDADD = -lnl-route -nl_list_sockets_SOURCES = nl-list-sockets.c ${rtnl_utils_c} +nl_list_sockets_SOURCES = nl-list-sockets.c nl_list_sockets_LDADD = -lnl-route -nl_util_addr_SOURCES = nl-util-addr.c ${rtnl_utils_c} +nl_util_addr_SOURCES = nl-util-addr.c nl_util_addr_LDADD = -lnl-route diff --git a/src/addr-utils.c b/src/addr-utils.c deleted file mode 100644 index 3cbe4f4..0000000 --- a/src/addr-utils.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * src/addr-utils.c Address 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "addr-utils.h" - -struct rtnl_addr *nlt_alloc_addr(void) -{ - struct rtnl_addr *addr; - - addr = rtnl_addr_alloc(); - if (!addr) - fatal(ENOMEM, "Unable to allocate address object"); - - return addr; -} - -void parse_family(struct rtnl_addr *addr, char *arg) -{ - int family; - - if ((family = nl_str2af(arg)) != AF_UNSPEC) - rtnl_addr_set_family(addr, family); -} - -void parse_local(struct rtnl_addr *addr, char *arg) -{ - struct nl_addr *a; - int err; - - a = nlt_addr_parse(arg, rtnl_addr_get_family(addr)); - if ((err = rtnl_addr_set_local(addr, a)) < 0) - fatal(err, "Unable to set local address: %s", - nl_geterror(err)); - - nl_addr_put(a); -} - -void parse_dev(struct rtnl_addr *addr, struct nl_cache *link_cache, char *arg) -{ - int ival; - - if (!(ival = rtnl_link_name2i(link_cache, arg))) - fatal(ENOENT, "Link \"%s\" does not exist", arg); - - rtnl_addr_set_ifindex(addr, ival); -} - -void parse_label(struct rtnl_addr *addr, char *arg) -{ - int err; - - if ((err = rtnl_addr_set_label(addr, arg)) < 0) - fatal(err, "Unable to set address label: %s", nl_geterror(err)); -} - -void parse_peer(struct rtnl_addr *addr, char *arg) -{ - struct nl_addr *a; - int err; - - a = nlt_addr_parse(arg, rtnl_addr_get_family(addr)); - if ((err = rtnl_addr_set_peer(addr, a)) < 0) - fatal(err, "Unable to set peer address: %s", nl_geterror(err)); - - nl_addr_put(a); -} - -void parse_scope(struct rtnl_addr *addr, char *arg) -{ - int ival; - - if ((ival = rtnl_str2scope(arg)) < 0) - fatal(EINVAL, "Unknown address scope \"%s\"", arg); - - rtnl_addr_set_scope(addr, ival); -} - -void parse_broadcast(struct rtnl_addr *addr, char *arg) -{ - struct nl_addr *a; - int err; - - a = nlt_addr_parse(arg, rtnl_addr_get_family(addr)); - if ((err = rtnl_addr_set_broadcast(addr, a)) < 0) - fatal(err, "Unable to set broadcast address: %s", - nl_geterror(err)); - - nl_addr_put(a); -} - -static uint32_t parse_lifetime(const char *arg) -{ - uint64_t msecs; - int err; - - if (!strcasecmp(arg, "forever")) - return 0xFFFFFFFFU; - - if ((err = nl_str2msec(arg, &msecs)) < 0) - fatal(err, "Unable to parse time string \"%s\": %s", - arg, nl_geterror(err)); - - return (msecs / 1000); -} - -void parse_preferred(struct rtnl_addr *addr, char *arg) -{ - rtnl_addr_set_preferred_lifetime(addr, parse_lifetime(arg)); -} - -void parse_valid(struct rtnl_addr *addr, char *arg) -{ - rtnl_addr_set_valid_lifetime(addr, parse_lifetime(arg)); -} diff --git a/src/addr-utils.h b/src/addr-utils.h deleted file mode 100644 index 5efa07f..0000000 --- a/src/addr-utils.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * src/addr-utils.h Address 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __ADDR_UTILS_H_ -#define __ADDR_UTILS_H_ - -#include "utils.h" - -extern struct rtnl_addr *nlt_alloc_addr(void); -extern void parse_family(struct rtnl_addr *, char *); -extern void parse_local(struct rtnl_addr *, char *); -extern void parse_dev(struct rtnl_addr *, struct nl_cache *, char *); -extern void parse_label(struct rtnl_addr *, char *); -extern void parse_peer(struct rtnl_addr *, char *); -extern void parse_scope(struct rtnl_addr *, char *); -extern void parse_broadcast(struct rtnl_addr *, char *); -extern void parse_preferred(struct rtnl_addr *, char *); -extern void parse_valid(struct rtnl_addr *, char *); - -#endif diff --git a/src/ct-utils.c b/src/ct-utils.c deleted file mode 100644 index 7d116fa..0000000 --- a/src/ct-utils.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * src/ct-utils.c Conntrack 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "ct-utils.h" - -struct nfnl_ct *nlt_alloc_ct(void) -{ - struct nfnl_ct *ct; - - ct = nfnl_ct_alloc(); - if (!ct) - fatal(ENOMEM, "Unable to allocate conntrack object"); - - return ct; -} - -struct nl_cache *nlt_alloc_ct_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "conntrack", nfnl_ct_alloc_cache); -} - -void parse_family(struct nfnl_ct *ct, char *arg) -{ - int family; - - if ((family = nl_str2af(arg)) == AF_UNSPEC) - fatal(EINVAL, "Unable to parse family \"%s\": %s", - arg, nl_geterror(NLE_INVAL)); - - nfnl_ct_set_family(ct, family); -} - -void parse_protocol(struct nfnl_ct *ct, char *arg) -{ - int proto; - - if ((proto = nl_str2ip_proto(arg)) < 0) - fatal(proto, "Unable to parse protocol \"%s\": %s", - arg, nl_geterror(proto)); - - nfnl_ct_set_proto(ct, proto); -} - -void parse_mark(struct nfnl_ct *ct, char *arg) -{ - uint32_t mark = parse_u32(arg); - nfnl_ct_set_mark(ct, mark); -} - -void parse_timeout(struct nfnl_ct *ct, char *arg) -{ - uint32_t timeout = parse_u32(arg); - nfnl_ct_set_timeout(ct, timeout); -} - -void parse_id(struct nfnl_ct *ct, char *arg) -{ - uint32_t id = parse_u32(arg); - nfnl_ct_set_id(ct, id); -} - -void parse_use(struct nfnl_ct *ct, char *arg) -{ - uint32_t use = parse_u32(arg); - nfnl_ct_set_use(ct, use); -} - -void parse_src(struct nfnl_ct *ct, int reply, char *arg) -{ - int err; - struct nl_addr *a = nlt_addr_parse(arg, nfnl_ct_get_family(ct)); - if ((err = nfnl_ct_set_src(ct, reply, a)) < 0) - fatal(err, "Unable to set source address: %s", - nl_geterror(err)); -} - -void parse_dst(struct nfnl_ct *ct, int reply, char *arg) -{ - int err; - struct nl_addr *a = nlt_addr_parse(arg, nfnl_ct_get_family(ct)); - if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0) - fatal(err, "Unable to set destination address: %s", - nl_geterror(err)); -} - -void parse_src_port(struct nfnl_ct *ct, int reply, char *arg) -{ - uint32_t port = parse_u32(arg); - nfnl_ct_set_src_port(ct, reply, port); -} - -void parse_dst_port(struct nfnl_ct *ct, int reply, char *arg) -{ - uint32_t port = parse_u32(arg); - nfnl_ct_set_dst_port(ct, reply, port); -} - -void parse_tcp_state(struct nfnl_ct *ct, char *arg) -{ - int state; - - if ((state = nfnl_ct_str2tcp_state(arg)) < 0) - fatal(state, "Unable to parse tcp state \"%s\": %s", - arg, nl_geterror(state)); - - nfnl_ct_set_tcp_state(ct, state); -} - -void parse_status(struct nfnl_ct *ct, char *arg) -{ - int status; - - if ((status = nfnl_ct_str2status(arg)) < 0) - fatal(status, "Unable to parse flags \"%s\": %s", - arg, nl_geterror(status)); - - nfnl_ct_set_status(ct, status); -} - -#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 diff --git a/src/ct-utils.h b/src/ct-utils.h deleted file mode 100644 index fc20e49..0000000 --- a/src/ct-utils.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * src/ct-utils.h Conntrack 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) 2008 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __CT_UTILS_H_ -#define __CT_UTILS_H_ - -#include "utils.h" -#include <netlink/netfilter/ct.h> -#include <linux/netfilter/nf_conntrack_common.h> - -extern struct nfnl_ct *nlt_alloc_ct(void); -extern struct nl_cache *nlt_alloc_ct_cache(struct nl_sock *); -extern void parse_family(struct nfnl_ct *, char *); -extern void parse_protocol(struct nfnl_ct *, char *); -extern void parse_mark(struct nfnl_ct *, char *); -extern void parse_timeout(struct nfnl_ct *, char *); -extern void parse_id(struct nfnl_ct *, char *); -extern void parse_use(struct nfnl_ct *, char *); -extern void parse_src(struct nfnl_ct *, int, char *); -extern void parse_dst(struct nfnl_ct *, int, char *); -extern void parse_src_port(struct nfnl_ct *, int, char *); -extern void parse_dst_port(struct nfnl_ct *, int, char *); -extern void parse_tcp_state(struct nfnl_ct *, char *); -extern void parse_status(struct nfnl_ct *, char *); - -#endif diff --git a/src/ctrl-utils.c b/src/ctrl-utils.c deleted file mode 100644 index 5309c23..0000000 --- a/src/ctrl-utils.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * src/ctrl-utils.c Generic Ctrl Netlink 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "ctrl-utils.h" - -struct nl_cache *nlt_alloc_genl_family_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "generic netlink family", - genl_ctrl_alloc_cache); -} diff --git a/src/ctrl-utils.h b/src/ctrl-utils.h deleted file mode 100644 index 59e3cdc..0000000 --- a/src/ctrl-utils.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * src/ctrl-utils.h Generic Netlink Ctrl 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __SRC_CTRL_UTILS_H_ -#define __SRC_CTRL_UTILS_H_ - -#include "utils.h" - -extern struct nl_cache *nlt_alloc_genl_family_cache(struct nl_sock *); - -#endif diff --git a/src/genl-ctrl-list.c b/src/genl-ctrl-list.c index 5276779..e25eb2a 100644 --- a/src/genl-ctrl-list.c +++ b/src/genl-ctrl-list.c @@ -6,10 +6,16 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "ctrl-utils.h" +#include <netlink/cli/utils.h> + +static struct nl_cache *alloc_genl_family_cache(struct nl_sock *sk) +{ + return nl_cli_alloc_cache(sk, "generic netlink family", + genl_ctrl_alloc_cache); +} static void print_usage(void) { @@ -33,9 +39,9 @@ int main(int argc, char *argv[]) .dp_fd = stdout, }; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_GENERIC); - family_cache = nlt_alloc_genl_family_cache(sock); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_GENERIC); + family_cache = alloc_genl_family_cache(sock); for (;;) { int c, optidx = 0; @@ -51,9 +57,9 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; + case 'v': nl_cli_print_version(); break; } } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am new file mode 100644 index 0000000..068c3a6 --- /dev/null +++ b/src/lib/Makefile.am @@ -0,0 +1,41 @@ +# -*- Makefile -*- + +AM_CFLAGS = -Wall -I${top_srcdir}/include -D_GNU_SOURCE -DPKGLIBDIR=\"$(pkglibdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -rdynamic +AM_LDFLAGS = -L${top_builddir}/lib -ldl + +#nobase_pkglib_LTLIBRARIES = cls/basic.la cls/ematch/cmp.la +#cls_basic_la_LDFLAGS = -module -version-info 2:0:0 +#cls_ematch_cmp_la_LDFLAGS = -module -version-info 2:0:0 + +#cls/ematch_grammar.c: cls/ematch_grammar.l +# $(LEX) --header-file=cls/ematch_grammar.h $(LFLAGS) -o $@ $^ + +#cls/ematch_syntax.c: cls/ematch_syntax.y +# $(YACC) -d $(YFLAGS) -o $@ $^ + +#cls/pktloc_grammar.c: cls/pktloc_grammar.l +# $(LEX) --header-file=cls/pktloc_grammar.h $(LFLAGS) -o $@ $^ + +#cls/pktloc_syntax.c: cls/pktloc_syntax.y +# $(YACC) -d $(YFLAGS) -o $@ $^ + +#CLEANFILES = \ +# cls/ematch_grammar.c cls/ematch_grammar.h \ +# cls/ematch_syntax.c cls/ematch_syntax.h \ +# cls/pktloc_grammar.c cls/pktloc_grammar.h \ +# cls/pktloc_syntax.c cls/pktloc_syntax.h + +lib_LTLIBRARIES = \ + libnl-cli.la + +libnl_cli_la_LDFLAGS = -version-info 2:0:0 + +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_la_SOURCES = \ + utils.c addr.c ct.c link.c neigh.c qdisc.c rule.c route.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/addr.c b/src/lib/addr.c new file mode 100644 index 0000000..a9c137b --- /dev/null +++ b/src/lib/addr.c @@ -0,0 +1,135 @@ +/* + * src/lib/addr.c Address 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> + */ + +/** + * @ingroup cli + * @defgroup cli_addr Addresses + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/addr.h> + +struct rtnl_addr *nl_cli_addr_alloc(void) +{ + struct rtnl_addr *addr; + + addr = rtnl_addr_alloc(); + if (!addr) + nl_cli_fatal(ENOMEM, "Unable to allocate address object"); + + return addr; +} + +void nl_cli_addr_parse_family(struct rtnl_addr *addr, char *arg) +{ + int family; + + if ((family = nl_str2af(arg)) != AF_UNSPEC) + rtnl_addr_set_family(addr, family); +} + +void nl_cli_addr_parse_local(struct rtnl_addr *addr, char *arg) +{ + struct nl_addr *a; + int err; + + a = nl_cli_addr_parse(arg, rtnl_addr_get_family(addr)); + if ((err = rtnl_addr_set_local(addr, a)) < 0) + nl_cli_fatal(err, "Unable to set local address: %s", + nl_geterror(err)); + + nl_addr_put(a); +} + +void nl_cli_addr_parse_dev(struct rtnl_addr *addr, struct nl_cache *link_cache, + char *arg) +{ + int ival; + + if (!(ival = rtnl_link_name2i(link_cache, arg))) + nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg); + + rtnl_addr_set_ifindex(addr, ival); +} + +void nl_cli_addr_parse_label(struct rtnl_addr *addr, char *arg) +{ + int err; + + if ((err = rtnl_addr_set_label(addr, arg)) < 0) + nl_cli_fatal(err, "Unable to set address label: %s", + nl_geterror(err)); +} + +void nl_cli_addr_parse_peer(struct rtnl_addr *addr, char *arg) +{ + struct nl_addr *a; + int err; + + a = nl_cli_addr_parse(arg, rtnl_addr_get_family(addr)); + if ((err = rtnl_addr_set_peer(addr, a)) < 0) + nl_cli_fatal(err, "Unable to set peer address: %s", + nl_geterror(err)); + + nl_addr_put(a); +} + +void nl_cli_addr_parse_scope(struct rtnl_addr *addr, char *arg) +{ + int ival; + + if ((ival = rtnl_str2scope(arg)) < 0) + nl_cli_fatal(EINVAL, "Unknown address scope \"%s\"", arg); + + rtnl_addr_set_scope(addr, ival); +} + +void nl_cli_addr_parse_broadcast(struct rtnl_addr *addr, char *arg) +{ + struct nl_addr *a; + int err; + + a = nl_cli_addr_parse(arg, rtnl_addr_get_family(addr)); + if ((err = rtnl_addr_set_broadcast(addr, a)) < 0) + nl_cli_fatal(err, "Unable to set broadcast address: %s", + nl_geterror(err)); + + nl_addr_put(a); +} + +static uint32_t parse_lifetime(const char *arg) +{ + uint64_t msecs; + int err; + + if (!strcasecmp(arg, "forever")) + return 0xFFFFFFFFU; + + if ((err = nl_str2msec(arg, &msecs)) < 0) + nl_cli_fatal(err, "Unable to parse time string \"%s\": %s", + arg, nl_geterror(err)); + + return (msecs / 1000); +} + +void nl_cli_addr_parse_preferred(struct rtnl_addr *addr, char *arg) +{ + rtnl_addr_set_preferred_lifetime(addr, parse_lifetime(arg)); +} + +void nl_cli_addr_parse_valid(struct rtnl_addr *addr, char *arg) +{ + rtnl_addr_set_valid_lifetime(addr, parse_lifetime(arg)); +} + +/** @} */ diff --git a/src/lib/ct.c b/src/lib/ct.c new file mode 100644 index 0000000..5bab08f --- /dev/null +++ b/src/lib/ct.c @@ -0,0 +1,162 @@ +/* + * src/lib/ct.c CLI Conntrack 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> + */ + +/** + * @ingroup cli + * @defgroup cli_ct Connection Tracking + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/ct.h> + +struct nfnl_ct *nl_cli_ct_alloc(void) +{ + struct nfnl_ct *ct; + + ct = nfnl_ct_alloc(); + if (!ct) + nl_cli_fatal(ENOMEM, "Unable to allocate conntrack object"); + + return ct; +} + +struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *sk) +{ + return nl_cli_alloc_cache(sk, "conntrack", nfnl_ct_alloc_cache); +} + +void nl_cli_ct_parse_family(struct nfnl_ct *ct, char *arg) +{ + int family; + + if ((family = nl_str2af(arg)) == AF_UNSPEC) + nl_cli_fatal(EINVAL, + "Unable to nl_cli_ct_parse family \"%s\": %s", + arg, nl_geterror(NLE_INVAL)); + + nfnl_ct_set_family(ct, family); +} + +void nl_cli_ct_parse_protocol(struct nfnl_ct *ct, char *arg) +{ + int proto; + + if ((proto = nl_str2ip_proto(arg)) < 0) + nl_cli_fatal(proto, + "Unable to nl_cli_ct_parse protocol \"%s\": %s", + arg, nl_geterror(proto)); + + nfnl_ct_set_proto(ct, proto); +} + +void nl_cli_ct_parse_mark(struct nfnl_ct *ct, char *arg) +{ + uint32_t mark = nl_cli_parse_u32(arg); + nfnl_ct_set_mark(ct, mark); +} + +void nl_cli_ct_parse_timeout(struct nfnl_ct *ct, char *arg) +{ + uint32_t timeout = nl_cli_parse_u32(arg); + nfnl_ct_set_timeout(ct, timeout); +} + +void nl_cli_ct_parse_id(struct nfnl_ct *ct, char *arg) +{ + uint32_t id = nl_cli_parse_u32(arg); + nfnl_ct_set_id(ct, id); +} + +void nl_cli_ct_parse_use(struct nfnl_ct *ct, char *arg) +{ + uint32_t use = nl_cli_parse_u32(arg); + nfnl_ct_set_use(ct, use); +} + +void nl_cli_ct_parse_src(struct nfnl_ct *ct, int reply, char *arg) +{ + int err; + struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct)); + if ((err = nfnl_ct_set_src(ct, reply, a)) < 0) + nl_cli_fatal(err, "Unable to set source address: %s", + nl_geterror(err)); +} + +void nl_cli_ct_parse_dst(struct nfnl_ct *ct, int reply, char *arg) +{ + int err; + struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct)); + if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0) + nl_cli_fatal(err, "Unable to set destination address: %s", + nl_geterror(err)); +} + +void nl_cli_ct_parse_src_port(struct nfnl_ct *ct, int reply, char *arg) +{ + uint32_t port = nl_cli_parse_u32(arg); + nfnl_ct_set_src_port(ct, reply, port); +} + +void nl_cli_ct_parse_dst_port(struct nfnl_ct *ct, int reply, char *arg) +{ + uint32_t port = nl_cli_parse_u32(arg); + nfnl_ct_set_dst_port(ct, reply, port); +} + +void nl_cli_ct_parse_tcp_state(struct nfnl_ct *ct, char *arg) +{ + int state; + + if ((state = nfnl_ct_str2tcp_state(arg)) < 0) + nl_cli_fatal(state, + "Unable to nl_cli_ct_parse tcp state \"%s\": %s", + arg, nl_geterror(state)); + + nfnl_ct_set_tcp_state(ct, state); +} + +void nl_cli_ct_parse_status(struct nfnl_ct *ct, char *arg) +{ + int status; + + if ((status = nfnl_ct_str2status(arg)) < 0) + nl_cli_fatal(status, + "Unable to nl_cli_ct_parse flags \"%s\": %s", + arg, nl_geterror(status)); + + nfnl_ct_set_status(ct, status); +} + +#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 + +/** @} */ diff --git a/src/lib/link.c b/src/lib/link.c new file mode 100644 index 0000000..c192569 --- /dev/null +++ b/src/lib/link.c @@ -0,0 +1,73 @@ +/* + * src/lib/link.c CLI Link 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> + */ + +/** + * @ingroup cli + * @defgroup cli_link Links + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> + +struct rtnl_link *nl_cli_link_alloc(void) +{ + struct rtnl_link *link; + + link = rtnl_link_alloc(); + if (!link) + nl_cli_fatal(ENOMEM, "Unable to allocate link object"); + + return link; +} + +void nl_cli_link_parse_family(struct rtnl_link *link, char *arg) +{ + int family; + + if ((family = nl_str2af(arg)) == AF_UNSPEC) + nl_cli_fatal(EINVAL, + "Unable to translate address family \"%s\"", arg); + + rtnl_link_set_family(link, family); +} + +void nl_cli_link_parse_name(struct rtnl_link *link, char *arg) +{ + rtnl_link_set_name(link, arg); +} + +void nl_cli_link_parse_mtu(struct rtnl_link *link, char *arg) +{ + uint32_t mtu = nl_cli_parse_u32(arg); + rtnl_link_set_mtu(link, mtu); +} + +void nl_cli_link_parse_ifindex(struct rtnl_link *link, char *arg) +{ + uint32_t index = nl_cli_parse_u32(arg); + rtnl_link_set_ifindex(link, index); +} + +void nl_cli_link_parse_txqlen(struct rtnl_link *link, char *arg) +{ + uint32_t qlen = nl_cli_parse_u32(arg); + rtnl_link_set_txqlen(link, qlen); +} + +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); +} + +/** @} */ diff --git a/src/lib/neigh.c b/src/lib/neigh.c new file mode 100644 index 0000000..a814bd8 --- /dev/null +++ b/src/lib/neigh.c @@ -0,0 +1,88 @@ +/* + * src/lib/neigh.c CLI Neighbour 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> + */ + +/** + * @ingroup cli + * @defgroup cli_neigh Neighbour + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/neigh.h> + +struct rtnl_neigh *nl_cli_neigh_alloc(void) +{ + struct rtnl_neigh *neigh; + + neigh = rtnl_neigh_alloc(); + if (!neigh) + nl_cli_fatal(ENOMEM, "Unable to allocate neighbout object"); + + return neigh; +} + +void nl_cli_neigh_parse_dst(struct rtnl_neigh *neigh, char *arg) +{ + struct nl_addr *a; + int err; + + a = nl_cli_addr_parse(arg, rtnl_neigh_get_family(neigh)); + if ((err = rtnl_neigh_set_dst(neigh, a)) < 0) + nl_cli_fatal(err, "Unable to set local address: %s", + nl_geterror(err)); + + nl_addr_put(a); +} + +void nl_cli_neigh_parse_lladdr(struct rtnl_neigh *neigh, char *arg) +{ + struct nl_addr *a; + + a = nl_cli_addr_parse(arg, AF_UNSPEC); + rtnl_neigh_set_lladdr(neigh, a); + nl_addr_put(a); +} + +void nl_cli_neigh_parse_dev(struct rtnl_neigh *neigh, + struct nl_cache *link_cache, char *arg) +{ + int ival; + + if (!(ival = rtnl_link_name2i(link_cache, arg))) + nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg); + + rtnl_neigh_set_ifindex(neigh, ival); +} + +void nl_cli_neigh_parse_family(struct rtnl_neigh *neigh, char *arg) +{ + int family; + + if ((family = nl_str2af(arg)) == AF_UNSPEC) + nl_cli_fatal(EINVAL, + "Unable to translate address family \"%s\"", arg); + + rtnl_neigh_set_family(neigh, family); +} + +void nl_cli_neigh_parse_state(struct rtnl_neigh *neigh, char *arg) +{ + int state; + + if ((state = rtnl_neigh_str2state(arg)) < 0) + nl_cli_fatal(state, "Unable to translate state \"%s\": %s", + arg, state); + + rtnl_neigh_set_state(neigh, state); +} + +/** @} */ diff --git a/src/lib/qdisc.c b/src/lib/qdisc.c new file mode 100644 index 0000000..bc7ff92 --- /dev/null +++ b/src/lib/qdisc.c @@ -0,0 +1,72 @@ +/* + * src/lib/qdisc.c CLI QDisc 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> + */ + +/** + * @ingroup cli + * @defgroup cli_qdisc Queueing Disciplines + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/qdisc.h> + +struct rtnl_qdisc *nl_cli_qdisc_alloc(void) +{ + struct rtnl_qdisc *qdisc; + + qdisc = rtnl_qdisc_alloc(); + if (!qdisc) + nl_cli_fatal(ENOMEM, "Unable to allocate qdisc object"); + + return qdisc; +} + +void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *qdisc, struct nl_cache *link_cache, char *arg) +{ + int ival; + + if (!(ival = rtnl_link_name2i(link_cache, arg))) + nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg); + + rtnl_qdisc_set_ifindex(qdisc, ival); +} + +void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *qdisc, char *arg) +{ + uint32_t parent; + int err; + + if ((err = rtnl_tc_str2handle(arg, &parent)) < 0) + nl_cli_fatal(err, "Unable to parse handle \"%s\": %s", + arg, nl_geterror(err)); + + rtnl_qdisc_set_parent(qdisc, parent); +} + +void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *qdisc, char *arg) +{ + uint32_t handle; + int err; + + if ((err = rtnl_tc_str2handle(arg, &handle)) < 0) + nl_cli_fatal(err, "Unable to parse handle \"%s\": %s", + arg, nl_geterror(err)); + + rtnl_qdisc_set_handle(qdisc, handle); +} + +void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *qdisc, char *arg) +{ + rtnl_qdisc_set_kind(qdisc, arg); +} + +/** @} */ diff --git a/src/route-utils.c b/src/lib/route.c index 549e6ff..05cb2ad 100644 --- a/src/route-utils.c +++ b/src/lib/route.c @@ -1,28 +1,50 @@ /* - * src/route-utils.c Route Helpers + * src/lib/route.c CLI Route 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 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch> */ -#include "route-utils.h" +/** + * @ingroup cli + * @defgroup cli_route Routing + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/route.h> -struct rtnl_route *nlt_alloc_route(void) +struct rtnl_route *nl_cli_route_alloc(void) { struct rtnl_route *route; route = rtnl_route_alloc(); if (!route) - fatal(ENOMEM, "Unable to allocate route object"); + nl_cli_fatal(ENOMEM, "Unable to allocate route object"); return route; } -void parse_family(struct rtnl_route *route, char *arg) +struct nl_cache *nl_cli_route_alloc_cache(struct nl_sock *sk, int flags) +{ + struct nl_cache *cache; + int err; + + if ((err = rtnl_route_alloc_cache(sk, AF_UNSPEC, flags, &cache)) < 0) + nl_cli_fatal(err, "Unable to allocate route cache: %s\n", + nl_geterror(err)); + + nl_cache_mngt_provide(cache); + + return cache; +} + +void nl_cli_route_parse_family(struct rtnl_route *route, char *arg) { int family; @@ -30,46 +52,46 @@ void parse_family(struct rtnl_route *route, char *arg) rtnl_route_set_family(route, family); } -void parse_dst(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_dst(struct rtnl_route *route, char *arg) { struct nl_addr *addr; int err; - addr = nlt_addr_parse(arg, rtnl_route_get_family(route)); + addr = nl_cli_addr_parse(arg, rtnl_route_get_family(route)); if ((err = rtnl_route_set_dst(route, addr)) < 0) - fatal(err, "Unable to set destination address: %s", + nl_cli_fatal(err, "Unable to set destination address: %s", nl_geterror(err)); nl_addr_put(addr); } -void parse_src(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_src(struct rtnl_route *route, char *arg) { struct nl_addr *addr; int err; - addr = nlt_addr_parse(arg, rtnl_route_get_family(route)); + addr = nl_cli_addr_parse(arg, rtnl_route_get_family(route)); if ((err = rtnl_route_set_src(route, addr)) < 0) - fatal(err, "Unable to set source address: %s", + nl_cli_fatal(err, "Unable to set source address: %s", nl_geterror(err)); nl_addr_put(addr); } -void parse_pref_src(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_pref_src(struct rtnl_route *route, char *arg) { struct nl_addr *addr; int err; - addr = nlt_addr_parse(arg, rtnl_route_get_family(route)); + addr = nl_cli_addr_parse(arg, rtnl_route_get_family(route)); if ((err = rtnl_route_set_pref_src(route, addr)) < 0) - fatal(err, "Unable to set preferred source address: %s", + nl_cli_fatal(err, "Unable to set preferred source address: %s", nl_geterror(err)); nl_addr_put(addr); } -void parse_metric(struct rtnl_route *route, char *subopts) +void nl_cli_route_parse_metric(struct rtnl_route *route, char *subopts) { /* strict equal order to RTAX_* */ static char *const tokens[] = { @@ -94,25 +116,25 @@ void parse_metric(struct rtnl_route *route, char *subopts) while (*subopts != '\0') { int ret = getsubopt(&subopts, tokens, &arg); if (ret == -1) - fatal(EINVAL, "Unknown metric token \"%s\"", arg); + nl_cli_fatal(EINVAL, "Unknown metric token \"%s\"", arg); if (ret == 0) - fatal(EINVAL, "Invalid metric \"%s\"", tokens[ret]); + nl_cli_fatal(EINVAL, "Invalid metric \"%s\"", tokens[ret]); if (arg == NULL) - fatal(EINVAL, "Metric \"%s\", no value given", tokens[ret]); + nl_cli_fatal(EINVAL, "Metric \"%s\", no value given", tokens[ret]); lval = strtoul(arg, &endptr, 0); if (endptr == arg) - fatal(EINVAL, "Metric \"%s\", value not numeric", tokens[ret]); + nl_cli_fatal(EINVAL, "Metric \"%s\", value not numeric", tokens[ret]); if ((ret = rtnl_route_set_metric(route, ret, lval)) < 0) - fatal(ret, "Unable to set metric: %s", + nl_cli_fatal(ret, "Unable to set metric: %s", nl_geterror(ret)); } } -void parse_nexthop(struct rtnl_route *route, char *subopts, +void nl_cli_route_parse_nexthop(struct rtnl_route *route, char *subopts, struct nl_cache *link_cache) { enum { @@ -133,27 +155,27 @@ void parse_nexthop(struct rtnl_route *route, char *subopts, char *arg, *endptr; if (!(nh = rtnl_route_nh_alloc())) - fatal(ENOMEM, "Out of memory"); + nl_cli_fatal(ENOMEM, "Out of memory"); while (*subopts != '\0') { int ret = getsubopt(&subopts, tokens, &arg); if (ret == -1) - fatal(EINVAL, "Unknown nexthop token \"%s\"", arg); + nl_cli_fatal(EINVAL, "Unknown nexthop token \"%s\"", arg); if (arg == NULL) - fatal(EINVAL, "Missing argument to option \"%s\"\n", + nl_cli_fatal(EINVAL, "Missing argument to option \"%s\"\n", tokens[ret]); switch (ret) { case NH_DEV: if (!(ival = rtnl_link_name2i(link_cache, arg))) - fatal(ENOENT,"Link \"%s\" does not exist", arg); + nl_cli_fatal(ENOENT,"Link \"%s\" does not exist", arg); rtnl_route_nh_set_ifindex(nh, ival); break; case NH_VIA: - addr = nlt_addr_parse(arg,rtnl_route_get_family(route)); + addr = nl_cli_addr_parse(arg,rtnl_route_get_family(route)); rtnl_route_nh_set_gateway(nh, addr); nl_addr_put(addr); break; @@ -161,7 +183,9 @@ void parse_nexthop(struct rtnl_route *route, char *subopts, case NH_WEIGHT: lval = strtoul(arg, &endptr, 0); if (endptr == arg) - fatal(EINVAL, "Invalid weight \"%s\", not numeric", arg); + nl_cli_fatal(EINVAL, + "Invalid weight \"%s\", not numeric", + arg); rtnl_route_nh_set_weight(nh, lval); break; } @@ -170,7 +194,7 @@ void parse_nexthop(struct rtnl_route *route, char *subopts, rtnl_route_add_nexthop(route, nh); } -void parse_table(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_table(struct rtnl_route *route, char *arg) { unsigned long lval; char *endptr; @@ -178,34 +202,34 @@ void parse_table(struct rtnl_route *route, char *arg) lval = strtoul(arg, &endptr, 0); if (endptr == arg) { if ((lval = rtnl_route_str2table(arg)) < 0) - fatal(EINVAL, "Unknown table name \"%s\"", arg); + nl_cli_fatal(EINVAL, "Unknown table name \"%s\"", arg); } rtnl_route_set_table(route, lval); } -void parse_prio(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_prio(struct rtnl_route *route, char *arg) { unsigned long lval; char *endptr; lval = strtoul(arg, &endptr, 0); if (endptr == arg) - fatal(EINVAL, "Invalid priority value, not numeric"); + nl_cli_fatal(EINVAL, "Invalid priority value, not numeric"); rtnl_route_set_priority(route, lval); } -void parse_scope(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_scope(struct rtnl_route *route, char *arg) { int ival; if ((ival = rtnl_str2scope(arg)) < 0) - fatal(EINVAL, "Unknown routing scope \"%s\"", arg); + nl_cli_fatal(EINVAL, "Unknown routing scope \"%s\"", arg); rtnl_route_set_scope(route, ival); } -void parse_protocol(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_protocol(struct rtnl_route *route, char *arg) { unsigned long lval; char *endptr; @@ -213,31 +237,34 @@ void parse_protocol(struct rtnl_route *route, char *arg) lval = strtoul(arg, &endptr, 0); if (endptr == arg) { if ((lval = rtnl_route_str2proto(arg)) < 0) - fatal(EINVAL, "Unknown routing protocol name \"%s\"", - arg); + nl_cli_fatal(EINVAL, + "Unknown routing protocol name \"%s\"", + arg); } rtnl_route_set_protocol(route, lval); } -void parse_type(struct rtnl_route *route, char *arg) +void nl_cli_route_parse_type(struct rtnl_route *route, char *arg) { int ival; if ((ival = nl_str2rtntype(arg)) < 0) - fatal(EINVAL, "Unknown routing type \"%s\"", arg); + nl_cli_fatal(EINVAL, "Unknown routing type \"%s\"", arg); if ((ival = rtnl_route_set_type(route, ival)) < 0) - fatal(ival, "Unable to set routing type: %s", + nl_cli_fatal(ival, "Unable to set routing type: %s", nl_geterror(ival)); } -void parse_iif(struct rtnl_route *route, char *arg, struct nl_cache *link_cache) +void nl_cli_route_parse_iif(struct rtnl_route *route, char *arg, struct nl_cache *link_cache) { int ival; if (!(ival = rtnl_link_name2i(link_cache, arg))) - fatal(ENOENT, "Link \"%s\" does not exist", arg); + nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg); rtnl_route_set_iif(route, ival); } + +/** @} */ diff --git a/src/lib/rule.c b/src/lib/rule.c new file mode 100644 index 0000000..96f1d4c --- /dev/null +++ b/src/lib/rule.c @@ -0,0 +1,55 @@ +/* + * src/lib/rule.c CLI Routing Rule 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> + */ + +/** + * @ingroup cli + * @defgroup cli_rule Routing Rules + * + * @{ + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/rule.h> + +struct rtnl_rule *nl_cli_rule_alloc(void) +{ + struct rtnl_rule *rule; + + rule = rtnl_rule_alloc(); + if (!rule) + nl_cli_fatal(ENOMEM, "Unable to allocate rule object"); + + return rule; +} + +struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *sk) +{ + struct nl_cache *cache; + int err; + + if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0) + nl_cli_fatal(err, "Unable to allocate routing rule cache: %s\n", + nl_geterror(err)); + + nl_cache_mngt_provide(cache); + + return cache; +} + +void nl_cli_rule_parse_family(struct rtnl_rule *rule, char *arg) +{ + int family; + + if ((family = nl_str2af(arg)) != AF_UNSPEC) + rtnl_rule_set_family(rule, family); +} + +/** @} */ diff --git a/src/utils.c b/src/lib/utils.c index a7c11e4..02a7be1 100644 --- a/src/utils.c +++ b/src/lib/utils.c @@ -6,32 +6,35 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +/** + * @defgroup cli Command Line Interface API + * + * @{ + */ -#include <stdlib.h> -#include <stdarg.h> -#include <limits.h> +#include <netlink/cli/utils.h> -uint32_t parse_u32(const char *arg) +uint32_t nl_cli_parse_u32(const char *arg) { unsigned long lval; char *endptr; lval = strtoul(arg, &endptr, 0); if (endptr == arg || lval == ULONG_MAX) - fatal(EINVAL, "Unable to parse \"%s\", not a number.", arg); + nl_cli_fatal(EINVAL, "Unable to parse \"%s\", not a number.", + arg); return (uint32_t) lval; } -void nlt_print_version(void) +void nl_cli_print_version(void) { printf("libnl tools version %s\n", LIBNL_VERSION); printf( - "Copyright (C) 2003-2008 Thomas Graf\n" + "Copyright (C) 2003-2009 Thomas Graf <tgraf@redhat.com>\n" "\n" "This program comes with ABSOLUTELY NO WARRANTY. This is free \n" "software, and you are welcome to redistribute it under certain\n" @@ -41,55 +44,57 @@ void nlt_print_version(void) exit(0); } -void fatal(int err, const char *fmt, ...) +void nl_cli_fatal(int err, const char *fmt, ...) { va_list ap; fprintf(stderr, "Error: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - fprintf(stderr, "\n"); + if (fmt) { + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + } else + fprintf(stderr, "%s\n", strerror(err)); exit(abs(err)); } -int nlt_connect(struct nl_sock *sk, int protocol) +int nl_cli_connect(struct nl_sock *sk, int protocol) { int err; if ((err = nl_connect(sk, protocol)) < 0) - fatal(err, "Unable to connect netlink socket: %s", - nl_geterror(err)); + nl_cli_fatal(err, "Unable to connect netlink socket: %s", + nl_geterror(err)); return err; } -struct nl_sock *nlt_alloc_socket(void) +struct nl_sock *nl_cli_alloc_socket(void) { struct nl_sock *sock; if (!(sock = nl_socket_alloc())) - fatal(ENOBUFS, "Unable to allocate netlink socket"); + nl_cli_fatal(ENOBUFS, "Unable to allocate netlink socket"); return sock; } -struct nl_addr *nlt_addr_parse(const char *str, int family) +struct nl_addr *nl_cli_addr_parse(const char *str, int family) { struct nl_addr *addr; int err; if ((err = nl_addr_parse(str, family, &addr)) < 0) - fatal(err, "Unable to parse address \"%s\": %s", - str, nl_geterror(err)); + nl_cli_fatal(err, "Unable to parse address \"%s\": %s", + str, nl_geterror(err)); return addr; } -int nlt_parse_dumptype(const char *str) +int nl_cli_parse_dumptype(const char *str) { if (!strcasecmp(str, "brief")) return NL_DUMP_LINE; @@ -100,13 +105,13 @@ int nlt_parse_dumptype(const char *str) else if (!strcasecmp(str, "env")) return NL_DUMP_ENV; else - fatal(EINVAL, "Invalid dump type \"%s\".\n", str); + nl_cli_fatal(EINVAL, "Invalid dump type \"%s\".\n", str); return 0; } -int nlt_confirm(struct nl_object *obj, struct nl_dump_params *params, - int default_yes) +int nl_cli_confirm(struct nl_object *obj, struct nl_dump_params *params, + int default_yes) { int answer; @@ -124,18 +129,19 @@ int nlt_confirm(struct nl_object *obj, struct nl_dump_params *params, return answer == 'y'; } -struct nl_cache *alloc_cache(struct nl_sock *sock, const char *name, - int (*ac)(struct nl_sock *, struct nl_cache **)) +struct nl_cache *nl_cli_alloc_cache(struct nl_sock *sock, const char *name, + int (*ac)(struct nl_sock *, struct nl_cache **)) { struct nl_cache *cache; int err; if ((err = ac(sock, &cache)) < 0) - fatal(err, "Unable to allocate %s cache: %s", - name, nl_geterror(err)); + nl_cli_fatal(err, "Unable to allocate %s cache: %s", + name, nl_geterror(err)); nl_cache_mngt_provide(cache); return cache; } +/** @} */ diff --git a/src/link-utils.c b/src/link-utils.c deleted file mode 100644 index 93bb4c0..0000000 --- a/src/link-utils.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * src/link-utils.c Link 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "link-utils.h" - -struct rtnl_link *nlt_alloc_link(void) -{ - struct rtnl_link *link; - - link = rtnl_link_alloc(); - if (!link) - fatal(ENOMEM, "Unable to allocate link object"); - - return link; -} - -void parse_family(struct rtnl_link *link, char *arg) -{ - int family; - - if ((family = nl_str2af(arg)) == AF_UNSPEC) - fatal(EINVAL, "Unable to translate address family \"%s\"", arg); - - rtnl_link_set_family(link, family); -} - -void parse_name(struct rtnl_link *link, char *arg) -{ - rtnl_link_set_name(link, arg); -} - -void parse_mtu(struct rtnl_link *link, char *arg) -{ - uint32_t mtu = parse_u32(arg); - rtnl_link_set_mtu(link, mtu); -} - -void parse_ifindex(struct rtnl_link *link, char *arg) -{ - uint32_t index = parse_u32(arg); - rtnl_link_set_ifindex(link, index); -} - -void parse_txqlen(struct rtnl_link *link, char *arg) -{ - uint32_t qlen = parse_u32(arg); - rtnl_link_set_txqlen(link, qlen); -} - -void parse_weight(struct rtnl_link *link, char *arg) -{ - uint32_t weight = parse_u32(arg); - rtnl_link_set_weight(link, weight); -} diff --git a/src/link-utils.h b/src/link-utils.h deleted file mode 100644 index 1d5c6c0..0000000 --- a/src/link-utils.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * src/link-utils.h Link 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __LINK_UTILS_H_ -#define __LINK_UTILS_H_ - -#include "utils.h" - -extern struct rtnl_link *nlt_alloc_link(void); -extern void parse_family(struct rtnl_link *, char *); -extern void parse_name(struct rtnl_link *, char *); -extern void parse_mtu(struct rtnl_link *, char *); -extern void parse_ifindex(struct rtnl_link *, char *); -extern void parse_txqlen(struct rtnl_link *, char *); -extern void parse_weight(struct rtnl_link *, char *); - -#endif diff --git a/src/log-utils.c b/src/log-utils.c deleted file mode 100644 index e3cfe44..0000000 --- a/src/log-utils.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * src/ct-utils.c Conntrack 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "log-utils.h" - -struct nfnl_log *nlt_alloc_log(void) -{ - struct nfnl_log *log; - - log = nfnl_log_alloc(); - if (!log) - fatal(ENOMEM, "Unable to allocate log object"); - - return log; -} diff --git a/src/log-utils.h b/src/log-utils.h deleted file mode 100644 index fb5bf2a..0000000 --- a/src/log-utils.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * src/log-utils.h Log 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) 2008 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __LOG_UTILS_H_ -#define __LOG_UTILS_H_ - -#include "utils.h" -#include <linux/netfilter/nfnetlink_log.h> -#include <netlink/netfilter/nfnl.h> -#include <netlink/netfilter/log.h> - -extern struct nfnl_log *nlt_alloc_log(void); - -#endif diff --git a/src/neigh-utils.c b/src/neigh-utils.c deleted file mode 100644 index 3e2d699..0000000 --- a/src/neigh-utils.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * src/neigh-utils.c Neighbour 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "neigh-utils.h" - -struct rtnl_neigh *nlt_alloc_neigh(void) -{ - struct rtnl_neigh *neigh; - - neigh = rtnl_neigh_alloc(); - if (!neigh) - fatal(ENOMEM, "Unable to allocate neighbout object"); - - return neigh; -} - -void parse_dst(struct rtnl_neigh *neigh, char *arg) -{ - struct nl_addr *a; - int err; - - a = nlt_addr_parse(arg, rtnl_neigh_get_family(neigh)); - if ((err = rtnl_neigh_set_dst(neigh, a)) < 0) - fatal(err, "Unable to set local address: %s", - nl_geterror(err)); - - nl_addr_put(a); -} - -void parse_lladdr(struct rtnl_neigh *neigh, char *arg) -{ - struct nl_addr *a; - - a = nlt_addr_parse(arg, AF_UNSPEC); - rtnl_neigh_set_lladdr(neigh, a); - nl_addr_put(a); -} - -void parse_dev(struct rtnl_neigh *neigh, struct nl_cache *link_cache, char *arg) -{ - int ival; - - if (!(ival = rtnl_link_name2i(link_cache, arg))) - fatal(ENOENT, "Link \"%s\" does not exist", arg); - - rtnl_neigh_set_ifindex(neigh, ival); -} - -void parse_family(struct rtnl_neigh *neigh, char *arg) -{ - int family; - - if ((family = nl_str2af(arg)) == AF_UNSPEC) - fatal(EINVAL, "Unable to translate address family \"%s\"", arg); - - rtnl_neigh_set_family(neigh, family); -} - -void parse_state(struct rtnl_neigh *neigh, char *arg) -{ - int state; - - if ((state = rtnl_neigh_str2state(arg)) < 0) - fatal(state, "Unable to translate state \"%s\": %s", - arg, state); - - rtnl_neigh_set_state(neigh, state); -} diff --git a/src/neigh-utils.h b/src/neigh-utils.h deleted file mode 100644 index 3662546..0000000 --- a/src/neigh-utils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * src/neigh-utils.h Neighbour 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __NEIGH_UTILS_H_ -#define __NEIGH_UTILS_H_ - -#include "utils.h" - -extern struct rtnl_neigh *nlt_alloc_neigh(void); -extern void parse_dst(struct rtnl_neigh *, char *); -extern void parse_lladdr(struct rtnl_neigh *, char *); -extern void parse_dev(struct rtnl_neigh *, struct nl_cache *, char *); -extern void parse_family(struct rtnl_neigh *, char *); -extern void parse_state(struct rtnl_neigh *, char *); - -#endif diff --git a/src/nf-ct-list.c b/src/nf-ct-list.c index c751c11..5f72998 100644 --- a/src/nf-ct-list.c +++ b/src/nf-ct-list.c @@ -6,12 +6,13 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> * Copyright (c) 2007 Philip Craig <philipc@snapgear.com> * Copyright (c) 2007 Secure Computing Corporation */ -#include "ct-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/ct.h> static void print_usage(void) { @@ -54,7 +55,7 @@ int main(int argc, char *argv[]) .dp_fd = stdout, }; - ct = nlt_alloc_ct(); + ct = nl_cli_ct_alloc(); for (;;) { int c, optidx = 0; @@ -103,31 +104,31 @@ int main(int argc, char *argv[]) case '?': exit(NLE_INVAL); case '4': nfnl_ct_set_family(ct, AF_INET); break; case '6': nfnl_ct_set_family(ct, AF_INET6); break; - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'i': parse_id(ct, optarg); break; - case 'p': parse_protocol(ct, optarg); break; - case ARG_TCP_STATE: parse_tcp_state(ct, optarg); break; - case ARG_ORIG_SRC: parse_src(ct, 0, optarg); break; - case ARG_ORIG_SPORT: parse_src_port(ct, 0, optarg); break; - case ARG_ORIG_DST: parse_dst(ct, 0, optarg); break; - case ARG_ORIG_DPORT: parse_dst_port(ct, 0, optarg); break; - case ARG_REPLY_SRC: parse_src(ct, 1, optarg); break; - case ARG_REPLY_SPORT: parse_src_port(ct, 1, optarg); break; - case ARG_REPLY_DST: parse_dst(ct, 1, optarg); break; - case ARG_REPLY_DPORT: parse_dst_port(ct, 1, optarg); break; - case 'F': parse_family(ct, optarg); break; - case ARG_MARK: parse_mark(ct, optarg); break; - case ARG_TIMEOUT: parse_timeout(ct, optarg); break; - case ARG_REFCNT: parse_use(ct, optarg); break; - case ARG_FLAGS: parse_status(ct, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'i': nl_cli_ct_parse_id(ct, optarg); break; + case 'p': nl_cli_ct_parse_protocol(ct, optarg); break; + case ARG_TCP_STATE: nl_cli_ct_parse_tcp_state(ct, optarg); break; + case ARG_ORIG_SRC: nl_cli_ct_parse_src(ct, 0, optarg); break; + case ARG_ORIG_SPORT: nl_cli_ct_parse_src_port(ct, 0, optarg); break; + case ARG_ORIG_DST: nl_cli_ct_parse_dst(ct, 0, optarg); break; + case ARG_ORIG_DPORT: nl_cli_ct_parse_dst_port(ct, 0, optarg); break; + case ARG_REPLY_SRC: nl_cli_ct_parse_src(ct, 1, optarg); break; + case ARG_REPLY_SPORT: nl_cli_ct_parse_src_port(ct, 1, optarg); break; + case ARG_REPLY_DST: nl_cli_ct_parse_dst(ct, 1, optarg); break; + case ARG_REPLY_DPORT: nl_cli_ct_parse_dst_port(ct, 1, optarg); break; + case 'F': nl_cli_ct_parse_family(ct, optarg); break; + case ARG_MARK: nl_cli_ct_parse_mark(ct, optarg); break; + case ARG_TIMEOUT: nl_cli_ct_parse_timeout(ct, optarg); break; + case ARG_REFCNT: nl_cli_ct_parse_use(ct, optarg); break; + case ARG_FLAGS: nl_cli_ct_parse_status(ct, optarg); break; } } - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_NETFILTER); - ct_cache = nlt_alloc_ct_cache(sock); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_NETFILTER); + ct_cache = nl_cli_ct_alloc_cache(sock); nl_cache_dump_filter(ct_cache, ¶ms, OBJ_CAST(ct)); diff --git a/src/nf-log.c b/src/nf-log.c index 33a689b..26bae6d 100644 --- a/src/nf-log.c +++ b/src/nf-log.c @@ -11,7 +11,22 @@ * Copyright (c) 2007 Secure Computing Corporation */ -#include "log-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> +#include <linux/netfilter/nfnetlink_log.h> +#include <netlink/netfilter/nfnl.h> +#include <netlink/netfilter/log.h> + +static struct nfnl_log *alloc_log(void) +{ + struct nfnl_log *log; + + log = nfnl_log_alloc(); + if (!log) + nl_cli_fatal(ENOMEM, "Unable to allocate log object"); + + return log; +} static void obj_input(struct nl_object *obj, void *arg) { @@ -44,7 +59,7 @@ int main(int argc, char *argv[]) int err; int family; - nf_sock = nlt_alloc_socket(); + nf_sock = nl_cli_alloc_socket(); nl_socket_disable_seq_check(nf_sock); nl_socket_modify_cb(nf_sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); @@ -54,26 +69,28 @@ int main(int argc, char *argv[]) return 2; } - nlt_connect(nf_sock, NETLINK_NETFILTER); + nl_cli_connect(nf_sock, NETLINK_NETFILTER); family = nl_str2af(argv[1]); if (family == AF_UNSPEC) - fatal(NLE_INVAL, "Unknown family \"%s\": %s", - argv[1], nl_geterror(family)); + nl_cli_fatal(NLE_INVAL, "Unknown family \"%s\": %s", + argv[1], nl_geterror(family)); nfnl_log_pf_unbind(nf_sock, family); if ((err = nfnl_log_pf_bind(nf_sock, family)) < 0) - fatal(err, "Unable to bind logger: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to bind logger: %s", + nl_geterror(err)); - log = nlt_alloc_log(); + log = alloc_log(); nfnl_log_set_group(log, atoi(argv[2])); copy_mode = NFNL_LOG_COPY_META; if (argc > 3) { copy_mode = nfnl_log_str2copy_mode(argv[3]); if (copy_mode < 0) - fatal(copy_mode, "Unable to parse copy mode \"%s\": %s", - argv[3], nl_geterror(copy_mode)); + nl_cli_fatal(copy_mode, + "Unable to parse copy mode \"%s\": %s", + argv[3], nl_geterror(copy_mode)); } nfnl_log_set_copy_mode(log, copy_mode); @@ -83,7 +100,8 @@ int main(int argc, char *argv[]) nfnl_log_set_copy_range(log, copy_range); if ((err = nfnl_log_create(nf_sock, log)) < 0) - fatal(err, "Unable to bind instance: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to bind instance: %s", + nl_geterror(err)); { struct nl_dump_params dp = { @@ -96,9 +114,9 @@ int main(int argc, char *argv[]) nl_object_dump((struct nl_object *) log, &dp); } - rt_sock = nlt_alloc_socket(); - nlt_connect(rt_sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(rt_sock); + rt_sock = nl_cli_alloc_socket(); + nl_cli_connect(rt_sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(rt_sock); while (1) { fd_set rfds; diff --git a/src/nf-monitor.c b/src/nf-monitor.c index 619254a..fe99af4 100644 --- a/src/nf-monitor.c +++ b/src/nf-monitor.c @@ -11,7 +11,7 @@ * Copyright (c) 2007 Secure Computing Corporation */ -#include "utils.h" +#include <netlink/cli/utils.h> #include <netlink/netfilter/nfnl.h> static void obj_input(struct nl_object *obj, void *arg) @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) { NFNLGRP_NONE, NULL } }; - sock = nlt_alloc_socket(); + sock = nl_cli_alloc_socket(); nl_socket_disable_seq_check(sock); nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) return 2; } - nlt_connect(sock, NETLINK_NETFILTER); + nl_cli_connect(sock, NETLINK_NETFILTER); for (idx = 1; argc > idx; idx++) { for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++) { @@ -73,14 +73,15 @@ int main(int argc, char *argv[]) err = nl_socket_add_membership(sock, groups[i].gr_id); if (err < 0) - fatal(err, "Unable to add membership: %s", - nl_geterror(err)); + nl_cli_fatal(err, + "Unable to add membership: %s", + nl_geterror(err)); break; } if (groups[i].gr_id == NFNLGRP_NONE) - fatal(NLE_OBJ_NOTFOUND, "Unknown group: \"%s\"", - argv[idx]); + nl_cli_fatal(NLE_OBJ_NOTFOUND, "Unknown group: \"%s\"", + argv[idx]); } while (1) { diff --git a/src/nf-queue.c b/src/nf-queue.c index ac2f4ea..5874688 100644 --- a/src/nf-queue.c +++ b/src/nf-queue.c @@ -10,10 +10,28 @@ */ -#include "queue-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> +#include <linux/netfilter.h> +#include <linux/netfilter/nfnetlink_queue.h> +#include <netlink/netfilter/nfnl.h> +#include <netlink/netfilter/queue.h> +#include <netlink/netfilter/queue_msg.h> static struct nl_sock *nf_sock; +static struct nfnl_queue *alloc_queue(void) +{ + struct nfnl_queue *queue; + + queue = nfnl_queue_alloc(); + if (!queue) + nl_cli_fatal(ENOMEM, "Unable to allocate queue object"); + + return queue; +} + + static void obj_input(struct nl_object *obj, void *arg) { struct nfnl_queue_msg *msg = (struct nfnl_queue_msg *) obj; @@ -49,7 +67,7 @@ int main(int argc, char *argv[]) nf_sock = nfnl_queue_socket_alloc(); if (nf_sock == NULL) - fatal(ENOBUFS, "Unable to allocate netlink socket"); + nl_cli_fatal(ENOBUFS, "Unable to allocate netlink socket"); nl_socket_disable_seq_check(nf_sock); nl_socket_modify_cb(nf_sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); @@ -60,24 +78,26 @@ int main(int argc, char *argv[]) return 2; } - nlt_connect(nf_sock, NETLINK_NETFILTER); + nl_cli_connect(nf_sock, NETLINK_NETFILTER); if ((family = nl_str2af(argv[1])) == AF_UNSPEC) - fatal(NLE_INVAL, "Unknown family \"%s\"", argv[1]); + nl_cli_fatal(NLE_INVAL, "Unknown family \"%s\"", argv[1]); nfnl_queue_pf_unbind(nf_sock, family); if ((err = nfnl_queue_pf_bind(nf_sock, family)) < 0) - fatal(err, "Unable to bind logger: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to bind logger: %s", + nl_geterror(err)); - queue = nlt_alloc_queue(); + queue = alloc_queue(); nfnl_queue_set_group(queue, atoi(argv[2])); copy_mode = NFNL_QUEUE_COPY_PACKET; if (argc > 3) { copy_mode = nfnl_queue_str2copy_mode(argv[3]); if (copy_mode < 0) - fatal(copy_mode, "Unable to parse copy mode \"%s\": %s", - argv[3], nl_geterror(copy_mode)); + nl_cli_fatal(copy_mode, + "Unable to parse copy mode \"%s\": %s", + argv[3], nl_geterror(copy_mode)); } nfnl_queue_set_copy_mode(queue, copy_mode); @@ -87,11 +107,11 @@ int main(int argc, char *argv[]) nfnl_queue_set_copy_range(queue, copy_range); if ((err = nfnl_queue_create(nf_sock, queue)) < 0) - fatal(err, "Unable to bind queue: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to bind queue: %s", nl_geterror(err)); - rt_sock = nlt_alloc_socket(); - nlt_connect(rt_sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(rt_sock); + rt_sock = nl_cli_alloc_socket(); + nl_cli_connect(rt_sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(rt_sock); while (1) { fd_set rfds; diff --git a/src/nl-addr-add.c b/src/nl-addr-add.c index 74911a6..52995ec 100644 --- a/src/nl-addr-add.c +++ b/src/nl-addr-add.c @@ -5,10 +5,12 @@ * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation version 2 of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "addr-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/addr.h> +#include <netlink/cli/link.h> static int quiet = 0; @@ -49,10 +51,10 @@ int main(int argc, char *argv[]) }; int err, nlflags = NLM_F_CREATE; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - addr = nlt_alloc_addr(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + addr = nl_cli_addr_alloc(); for (;;) { int c, optidx = 0; @@ -92,21 +94,22 @@ int main(int argc, char *argv[]) case ARG_REPLACE: nlflags |= NLM_F_REPLACE; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'a': parse_local(addr, optarg); break; - case 'd': parse_dev(addr, link_cache, optarg); break; - case ARG_FAMILY: parse_family(addr, optarg); break; - case ARG_LABEL: parse_label(addr, optarg); break; - case ARG_PEER: parse_peer(addr, optarg); break; - case ARG_SCOPE: parse_scope(addr, optarg); break; - case ARG_BROADCAST: parse_broadcast(addr, optarg); break; - case ARG_PREFERRED: parse_preferred(addr, optarg); break; - case ARG_VALID: parse_valid(addr, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'a': nl_cli_addr_parse_local(addr, optarg); break; + case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break; + case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break; + case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break; + case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break; + case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break; + case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break; + case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break; + case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break; } } if ((err = rtnl_addr_add(sock, addr, nlflags)) < 0) - fatal(err, "Unable to add address: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to add address: %s", + nl_geterror(err)); if (!quiet) { printf("Added "); diff --git a/src/nl-addr-delete.c b/src/nl-addr-delete.c index f185563..2849c01 100644 --- a/src/nl-addr-delete.c +++ b/src/nl-addr-delete.c @@ -5,10 +5,12 @@ * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation version 2 of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "addr-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/addr.h> +#include <netlink/cli/link.h> static struct nl_sock *sock; static int interactive = 0, default_yes = 0, quiet = 0; @@ -51,11 +53,12 @@ static void delete_cb(struct nl_object *obj, void *arg) }; int err; - if (interactive && !nlt_confirm(obj, ¶ms, default_yes)) + if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes)) return; if ((err = rtnl_addr_delete(sock, addr, 0)) < 0) - fatal(err, "Unable to delete address: %s\n", nl_geterror(err)); + nl_cli_fatal(err, "Unable to delete address: %s\n", + nl_geterror(err)); if (!quiet) { printf("Deleted "); @@ -70,11 +73,11 @@ int main(int argc, char *argv[]) struct rtnl_addr *addr; struct nl_cache *link_cache, *addr_cache; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - addr_cache = nlt_alloc_addr_cache(sock); - addr = nlt_alloc_addr(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + addr_cache = nl_cli_addr_alloc_cache(sock); + addr = nl_cli_addr_alloc(); for (;;) { int c, optidx = 0; @@ -115,16 +118,16 @@ int main(int argc, char *argv[]) case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'a': parse_local(addr, optarg); break; - case 'd': parse_dev(addr, link_cache, optarg); break; - case ARG_FAMILY: parse_family(addr, optarg); break; - case ARG_LABEL: parse_label(addr, optarg); break; - case ARG_PEER: parse_peer(addr, optarg); break; - case ARG_SCOPE: parse_scope(addr, optarg); break; - case ARG_BROADCAST: parse_broadcast(addr, optarg); break; - case ARG_PREFERRED: parse_preferred(addr, optarg); break; - case ARG_VALID: parse_valid(addr, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'a': nl_cli_addr_parse_local(addr, optarg); break; + case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break; + case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break; + case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break; + case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break; + case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break; + case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break; + case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break; + case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break; } } diff --git a/src/nl-addr-list.c b/src/nl-addr-list.c index 1393f6e..9b045a5 100644 --- a/src/nl-addr-list.c +++ b/src/nl-addr-list.c @@ -5,10 +5,12 @@ * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation version 2 of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "addr-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/addr.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -118,11 +120,11 @@ int main(int argc, char *argv[]) }; int dump_env = 0; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - addr_cache = nlt_alloc_addr_cache(sock); - addr = nlt_alloc_addr(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + addr_cache = nl_cli_addr_alloc_cache(sock); + addr = nl_cli_addr_alloc(); for (;;) { int c, optidx = 0; @@ -168,16 +170,16 @@ int main(int argc, char *argv[]) case ARG_ENV: dump_env = 1; break; case ARG_PREFIX: prefix = strdup(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'a': parse_local(addr, optarg); break; - case 'd': parse_dev(addr, link_cache, optarg); break; - case ARG_FAMILY: parse_family(addr, optarg); break; - case ARG_LABEL: parse_label(addr, optarg); break; - case ARG_PEER: parse_peer(addr, optarg); break; - case ARG_SCOPE: parse_scope(addr, optarg); break; - case ARG_BROADCAST: parse_broadcast(addr, optarg); break; - case ARG_PREFERRED: parse_preferred(addr, optarg); break; - case ARG_VALID: parse_valid(addr, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'a': nl_cli_addr_parse_local(addr, optarg); break; + case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break; + case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break; + case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break; + case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break; + case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break; + case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break; + case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break; + case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break; } } diff --git a/src/nl-fib-lookup.c b/src/nl-fib-lookup.c index 328e60f..705cf32 100644 --- a/src/nl-fib-lookup.c +++ b/src/nl-fib-lookup.c @@ -6,10 +6,10 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> static void print_usage(void) { @@ -73,19 +73,19 @@ int main(int argc, char *argv[]) if (optind >= argc) print_usage(); - nlh = nlt_alloc_socket(); + nlh = nl_cli_alloc_socket(); if ((err = nl_addr_parse(argv[optind], AF_INET, &addr)) < 0) - fatal(err, "Unable to parse address \"%s\": %s\n", + nl_cli_fatal(err, "Unable to parse address \"%s\": %s\n", argv[optind], nl_geterror(err)); result = flnl_result_alloc_cache(); if (!result) - fatal(ENOMEM, "Unable to allocate cache"); + nl_cli_fatal(ENOMEM, "Unable to allocate cache"); request = flnl_request_alloc(); if (!request) - fatal(ENOMEM, "Unable to allocate request"); + nl_cli_fatal(ENOMEM, "Unable to allocate request"); flnl_request_set_table(request, table); flnl_request_set_fwmark(request, fwmark); @@ -95,13 +95,13 @@ int main(int argc, char *argv[]) err = flnl_request_set_addr(request, addr); nl_addr_put(addr); if (err < 0) - fatal(err, "Unable to send request: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to send request: %s", nl_geterror(err)); - nlt_connect(nlh, NETLINK_FIB_LOOKUP); + nl_cli_connect(nlh, NETLINK_FIB_LOOKUP); err = flnl_lookup(nlh, request, result); if (err < 0) - fatal(err, "Unable to lookup: %s\n", nl_geterror(err)); + nl_cli_fatal(err, "Unable to lookup: %s\n", nl_geterror(err)); nl_cache_dump(result, ¶ms); diff --git a/src/nl-link-ifindex2name.c b/src/nl-link-ifindex2name.c index 109ec46..68e5158 100644 --- a/src/nl-link-ifindex2name.c +++ b/src/nl-link-ifindex2name.c @@ -6,10 +6,11 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -27,14 +28,15 @@ int main(int argc, char *argv[]) if (argc < 2) print_usage(); - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); - ifindex = parse_u32(argv[1]); + ifindex = nl_cli_parse_u32(argv[1]); if (!rtnl_link_i2name(link_cache, ifindex, name, sizeof(name))) - fatal(ENOENT, "Interface index %d does not exist", ifindex); + nl_cli_fatal(ENOENT, "Interface index %d does not exist", + ifindex); printf("%s\n", name); diff --git a/src/nl-link-list.c b/src/nl-link-list.c index 99b1ad8..5e1e3f6 100644 --- a/src/nl-link-list.c +++ b/src/nl-link-list.c @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ #if 0 @@ -24,7 +24,8 @@ static void print_usage(void) } #endif -#include "link-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -56,10 +57,10 @@ int main(int argc, char *argv[]) .dp_fd = stdout, }; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - link = nlt_alloc_link(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + link = nl_cli_link_alloc(); for (;;) { int c, optidx = 0; @@ -87,15 +88,15 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'n': parse_name(link, optarg); break; - case 'i': parse_ifindex(link, optarg); break; - case ARG_FAMILY: parse_family(link, optarg); break; - case ARG_MTU: parse_mtu(link, optarg); break; - case ARG_TXQLEN: parse_txqlen(link, optarg); break; - case ARG_WEIGHT: parse_weight(link, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'n': nl_cli_link_parse_name(link, optarg); break; + case 'i': nl_cli_link_parse_ifindex(link, optarg); break; + case ARG_FAMILY: nl_cli_link_parse_family(link, optarg); break; + case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break; + case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break; + case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break; } } diff --git a/src/nl-link-name2ifindex.c b/src/nl-link-name2ifindex.c index 12a61c6..b04af04 100644 --- a/src/nl-link-name2ifindex.c +++ b/src/nl-link-name2ifindex.c @@ -9,7 +9,8 @@ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -26,12 +27,13 @@ int main(int argc, char *argv[]) if (argc < 2) print_usage(); - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); if (!(ifindex = rtnl_link_name2i(link_cache, argv[1]))) - fatal(ENOENT, "Interface \"%s\" does not exist", argv[1]); + nl_cli_fatal(ENOENT, "Interface \"%s\" does not exist", + argv[1]); printf("%u\n", ifindex); diff --git a/src/nl-link-set.c b/src/nl-link-set.c index 6dbf99e..94c94e7 100644 --- a/src/nl-link-set.c +++ b/src/nl-link-set.c @@ -6,10 +6,11 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "link-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static struct nl_sock *sock; static int quiet = 0; @@ -55,7 +56,8 @@ static void set_cb(struct nl_object *obj, void *arg) int err; if ((err = rtnl_link_change(sock, link, change, 0) < 0)) - fatal(err, "Unable to change link: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to change link: %s", + nl_geterror(err)); if (!quiet) { printf("Changed "); @@ -69,11 +71,11 @@ int main(int argc, char *argv[]) struct rtnl_link *link, *change; int ok = 0; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - link = nlt_alloc_link(); - change = nlt_alloc_link(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + link = nl_cli_link_alloc(); + change = nl_cli_link_alloc(); for (;;) { int c, optidx = 0; @@ -103,13 +105,13 @@ int main(int argc, char *argv[]) switch (c) { case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'n': ok++; parse_name(link, optarg); break; - case 'i': ok++; parse_ifindex(link, optarg); break; - case ARG_RENAME: parse_name(change, optarg); break; - case ARG_MTU: parse_mtu(link, optarg); break; - case ARG_TXQLEN: parse_txqlen(link, optarg); break; - case ARG_WEIGHT: parse_weight(link, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'n': ok++; nl_cli_link_parse_name(link, optarg); break; + case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg); break; + case ARG_RENAME: nl_cli_link_parse_name(change, optarg); break; + case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break; + case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break; + case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break; } } diff --git a/src/nl-link-stats.c b/src/nl-link-stats.c index 9203e08..4dfca86 100644 --- a/src/nl-link-stats.c +++ b/src/nl-link-stats.c @@ -6,10 +6,11 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "link-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -81,10 +82,10 @@ int main(int argc, char *argv[]) struct nl_cache *link_cache; struct rtnl_link *link; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - link = nlt_alloc_link(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + link = nl_cli_link_alloc(); for (;;) { int c, optidx = 0; @@ -104,9 +105,9 @@ int main(int argc, char *argv[]) switch (c) { case 'l': list_stat_names(); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'n': parse_name(link, optarg); break; - case 'i': parse_ifindex(link, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'n': nl_cli_link_parse_name(link, optarg); break; + case 'i': nl_cli_link_parse_ifindex(link, optarg); break; } } diff --git a/src/nl-list-caches.c b/src/nl-list-caches.c index abd5ff3..7e4ffc1 100644 --- a/src/nl-list-caches.c +++ b/src/nl-list-caches.c @@ -6,11 +6,11 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ #include <netlink-local.h> -#include "utils.h" +#include <netlink/cli/utils.h> static void print_usage(void) { diff --git a/src/nl-list-sockets.c b/src/nl-list-sockets.c index f769adc..868006e 100644 --- a/src/nl-list-sockets.c +++ b/src/nl-list-sockets.c @@ -6,10 +6,10 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> #define PROC_NETLINK "/proc/net/netlink" diff --git a/src/nl-monitor.c b/src/nl-monitor.c index 19117a2..fdf6497 100644 --- a/src/nl-monitor.c +++ b/src/nl-monitor.c @@ -6,12 +6,11 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" -#include <netlink/route/link.h> -#include <netlink/route/addr.h> +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static void obj_input(struct nl_object *obj, void *arg) { @@ -61,7 +60,7 @@ int main(int argc, char *argv[]) { RTNLGRP_NONE, NULL } }; - sock = nlt_alloc_socket(); + sock = nl_cli_alloc_socket(); nl_socket_disable_seq_check(sock); nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); @@ -75,14 +74,15 @@ int main(int argc, char *argv[]) return 2; } - nlt_connect(sock, NETLINK_ROUTE); + nl_cli_connect(sock, NETLINK_ROUTE); for (idx = 1; argc > idx; idx++) { for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++) { if (!strcmp(argv[idx], known_groups[i].gr_name)) { if ((err = nl_socket_add_membership(sock, known_groups[i].gr_id)) < 0) { - fatal(err, "%s: %s\n", argv[idx], nl_geterror(err)); + nl_cli_fatal(err, "%s: %s\n", argv[idx], + nl_geterror(err)); } break; @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Warning: Unknown group: %s\n", argv[idx]); } - link_cache = nlt_alloc_link_cache(sock); + link_cache = nl_cli_link_alloc_cache(sock); while (1) { fd_set rfds; diff --git a/src/nl-neigh-add.c b/src/nl-neigh-add.c index 1c73e24..4cddabe 100644 --- a/src/nl-neigh-add.c +++ b/src/nl-neigh-add.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "neigh-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/neigh.h> +#include <netlink/cli/link.h> static int quiet = 0; @@ -50,10 +52,10 @@ int main(int argc, char *argv[]) }; int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - neigh = nlt_alloc_neigh(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + neigh = nl_cli_neigh_alloc(); for (;;) { int c, optidx = 0; @@ -84,11 +86,11 @@ int main(int argc, char *argv[]) case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'a': ok++; parse_dst(neigh, optarg); break; - case 'l': parse_lladdr(neigh, optarg); break; - case 'd': parse_dev(neigh, link_cache, optarg); break; - case ARG_STATE: parse_state(neigh, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg); break; + case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break; + case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break; + case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break; } } @@ -96,7 +98,8 @@ int main(int argc, char *argv[]) print_usage(); if ((err = rtnl_neigh_add(sock, neigh, nlflags)) < 0) - fatal(err, "Unable to add neighbour: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to add neighbour: %s", + nl_geterror(err)); if (!quiet) { printf("Added "); diff --git a/src/nl-neigh-delete.c b/src/nl-neigh-delete.c index 474d5f0..887bd84 100644 --- a/src/nl-neigh-delete.c +++ b/src/nl-neigh-delete.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "neigh-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/neigh.h> +#include <netlink/cli/link.h> static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0; struct nl_sock *sock; @@ -46,11 +48,12 @@ static void delete_cb(struct nl_object *obj, void *arg) }; int err; - if (interactive && !nlt_confirm(obj, ¶ms, default_yes)) + if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes)) return; if ((err = rtnl_neigh_delete(sock, neigh, 0)) < 0) - fatal(err, "Unable to delete neighbour: %s\n", nl_geterror(err)); + nl_cli_fatal(err, "Unable to delete neighbour: %s\n", + nl_geterror(err)); if (!quiet) { printf("Deleted "); @@ -65,11 +68,11 @@ int main(int argc, char *argv[]) struct rtnl_neigh *neigh; struct nl_cache *link_cache, *neigh_cache; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - neigh_cache = nlt_alloc_neigh_cache(sock); - neigh = nlt_alloc_neigh(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + neigh_cache = nl_cli_neigh_alloc_cache(sock); + neigh = nl_cli_neigh_alloc(); for (;;) { int c, optidx = 0; @@ -101,12 +104,12 @@ int main(int argc, char *argv[]) case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'a': parse_dst(neigh, optarg); break; - case 'l': parse_lladdr(neigh, optarg); break; - case 'd': parse_dev(neigh, link_cache, optarg); break; - case ARG_FAMILY: parse_family(neigh, optarg); break; - case ARG_STATE: parse_state(neigh, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break; + case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break; + case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break; + case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break; + case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break; } } diff --git a/src/nl-neigh-list.c b/src/nl-neigh-list.c index 4a74e27..ebf5486 100644 --- a/src/nl-neigh-list.c +++ b/src/nl-neigh-list.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "neigh-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/neigh.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -41,11 +43,11 @@ int main(int argc, char *argv[]) .dp_fd = stdout, }; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - neigh_cache = nlt_alloc_neigh_cache(sock); - neigh = nlt_alloc_neigh(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + neigh_cache = nl_cli_neigh_alloc_cache(sock); + neigh = nl_cli_neigh_alloc(); for (;;) { int c, optidx = 0; @@ -70,14 +72,14 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'a': parse_dst(neigh, optarg); break; - case 'l': parse_lladdr(neigh, optarg); break; - case 'd': parse_dev(neigh, link_cache, optarg); break; - case ARG_FAMILY: parse_family(neigh, optarg); break; - case ARG_STATE: parse_state(neigh, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break; + case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break; + case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break; + case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break; + case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break; } } diff --git a/src/nl-neightbl-list.c b/src/nl-neightbl-list.c index 8a7a83f..5010b92 100644 --- a/src/nl-neightbl-list.c +++ b/src/nl-neightbl-list.c @@ -6,10 +6,11 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -33,10 +34,11 @@ int main(int argc, char *argv[]) .dp_fd = stdout, }; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - neightbl_cache = nlt_alloc_neightbl_cache(sock); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table", + rtnl_neightbl_alloc_cache); for (;;) { int c, optidx = 0; @@ -52,9 +54,9 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; + case 'v': nl_cli_print_version(); break; } } diff --git a/src/nl-qdisc-delete.c b/src/nl-qdisc-delete.c index e0c82a2..5cb7aa3 100644 --- a/src/nl-qdisc-delete.c +++ b/src/nl-qdisc-delete.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "qdisc-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/qdisc.h> +#include <netlink/cli/link.h> static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0; struct nl_sock *sock; @@ -45,11 +47,11 @@ static void delete_cb(struct nl_object *obj, void *arg) }; int err; - if (interactive && !nlt_confirm(obj, ¶ms, default_yes)) + if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes)) return; if ((err = rtnl_qdisc_delete(sock, qdisc)) < 0) - fatal(err, "Unable to delete qdisc: %s\n", nl_geterror(err)); + nl_cli_fatal(err, "Unable to delete qdisc: %s\n", nl_geterror(err)); if (!quiet) { printf("Deleted "); @@ -64,11 +66,11 @@ int main(int argc, char *argv[]) struct rtnl_qdisc *qdisc; struct nl_cache *link_cache, *qdisc_cache; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - qdisc_cache = nlt_alloc_qdisc_cache(sock); - qdisc = nlt_alloc_qdisc(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + qdisc_cache = nl_cli_qdisc_alloc_cache(sock); + qdisc = nl_cli_qdisc_alloc(); for (;;) { int c, optidx = 0; @@ -97,11 +99,11 @@ int main(int argc, char *argv[]) case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'd': parse_dev(qdisc, link_cache, optarg); break; - case 'p': parse_parent(qdisc, optarg); break; - case 'H': parse_handle(qdisc, optarg); break; - case 'k': parse_kind(qdisc, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break; + case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break; + case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break; + case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break; } } diff --git a/src/nl-qdisc-list.c b/src/nl-qdisc-list.c index b4e7116..ec6e25f 100644 --- a/src/nl-qdisc-list.c +++ b/src/nl-qdisc-list.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "qdisc-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/qdisc.h> +#include <netlink/cli/link.h> static int quiet = 0; @@ -42,11 +44,11 @@ int main(int argc, char *argv[]) .dp_fd = stdout, }; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - qdisc_cache = nlt_alloc_qdisc_cache(sock); - qdisc = nlt_alloc_qdisc(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + qdisc_cache = nl_cli_qdisc_alloc_cache(sock); + qdisc = nl_cli_qdisc_alloc(); for (;;) { int c, optidx = 0; @@ -71,14 +73,14 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'd': parse_dev(qdisc, link_cache, optarg); break; - case 'p': parse_parent(qdisc, optarg); break; - case 'H': parse_handle(qdisc, optarg); break; - case 'k': parse_kind(qdisc, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break; + case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break; + case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break; + case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break; } } diff --git a/src/nl-route-add.c b/src/nl-route-add.c index a1ab7f3..2f187df 100644 --- a/src/nl-route-add.c +++ b/src/nl-route-add.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "route-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/route.h> +#include <netlink/cli/link.h> static int quiet = 0; static struct nl_cache *link_cache, *route_cache; @@ -57,11 +59,11 @@ int main(int argc, char *argv[]) }; int err = 1; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - route_cache = nlt_alloc_route_cache(sock, 0); - route = nlt_alloc_route(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + route_cache = nl_cli_route_alloc_cache(sock, 0); + route = nl_cli_route_alloc(); for (;;) { int c, optidx = 0; @@ -102,24 +104,24 @@ int main(int argc, char *argv[]) switch (c) { case 'q': quiet = 1; break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'd': parse_dst(route, optarg); break; - case 'n': parse_nexthop(route, optarg, link_cache); break; - case 't': parse_table(route, optarg); break; - case ARG_FAMILY: parse_family(route, optarg); break; - case ARG_SRC: parse_src(route, optarg); break; - case ARG_IIF: parse_iif(route, optarg, link_cache); break; - case ARG_PREF_SRC: parse_pref_src(route, optarg); break; - case ARG_METRICS: parse_metric(route, optarg); break; - case ARG_PRIORITY: parse_prio(route, optarg); break; - case ARG_SCOPE: parse_scope(route, optarg); break; - case ARG_PROTOCOL: parse_protocol(route, optarg); break; - case ARG_TYPE: parse_type(route, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'd': nl_cli_route_parse_dst(route, optarg); break; + case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break; + case 't': nl_cli_route_parse_table(route, optarg); break; + case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break; + case ARG_SRC: nl_cli_route_parse_src(route, optarg); break; + case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break; + case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break; + case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break; + case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break; + case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break; + case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break; + case ARG_TYPE: nl_cli_route_parse_type(route, optarg); break; } } if ((err = rtnl_route_add(sock, route, 0)) < 0) - fatal(err, "Unable to add route: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to add route: %s", nl_geterror(err)); if (!quiet) { printf("Added "); diff --git a/src/nl-route-delete.c b/src/nl-route-delete.c index aca3a39..884fd7f 100644 --- a/src/nl-route-delete.c +++ b/src/nl-route-delete.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "route-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/route.h> +#include <netlink/cli/link.h> static int interactive = 0, default_yes = 0, quiet = 0; static int deleted = 0; @@ -65,11 +67,11 @@ static void delete_cb(struct nl_object *obj, void *arg) }; int err; - if (interactive && !nlt_confirm(obj, ¶ms, default_yes)) + if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes)) return; if ((err = rtnl_route_delete(sock, route, 0)) < 0) - fatal(err, "Unable to delete route: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to delete route: %s", nl_geterror(err)); if (!quiet) { printf("Deleted "); @@ -85,11 +87,11 @@ int main(int argc, char *argv[]) struct rtnl_route *route; int nf = 0; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - route_cache = nlt_alloc_route_cache(sock, 0); - route = nlt_alloc_route(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + route_cache = nl_cli_route_alloc_cache(sock, 0); + route = nl_cli_route_alloc(); for (;;) { int c, optidx = 0; @@ -136,18 +138,18 @@ int main(int argc, char *argv[]) case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': print_version(); break; - case 'd': nf++; parse_dst(route, optarg); break; - case 'n': nf++; parse_nexthop(route, optarg, link_cache); break; - case 't': nf++; parse_table(route, optarg); break; - case ARG_FAMILY: nf++; parse_family(route, optarg); break; - case ARG_SRC: nf++; parse_src(route, optarg); break; - case ARG_IIF: nf++; parse_iif(route, optarg, link_cache); break; - case ARG_PREF_SRC: nf++; parse_pref_src(route, optarg); break; - case ARG_METRICS: nf++; parse_metric(route, optarg); break; - case ARG_PRIORITY: nf++; parse_prio(route, optarg); break; - case ARG_SCOPE: nf++; parse_scope(route, optarg); break; - case ARG_PROTOCOL: nf++; parse_protocol(route, optarg); break; - case ARG_TYPE: nf++; parse_type(route, optarg); break; + case 'd': nf++; nl_cli_route_parse_dst(route, optarg); break; + case 'n': nf++; nl_cli_route_parse_nexthop(route, optarg, link_cache); break; + case 't': nf++; nl_cli_route_parse_table(route, optarg); break; + case ARG_FAMILY: nf++; nl_cli_route_parse_family(route, optarg); break; + case ARG_SRC: nf++; nl_cli_route_parse_src(route, optarg); break; + case ARG_IIF: nf++; nl_cli_route_parse_iif(route, optarg, link_cache); break; + case ARG_PREF_SRC: nf++; nl_cli_route_parse_pref_src(route, optarg); break; + case ARG_METRICS: nf++; nl_cli_route_parse_metric(route, optarg); break; + case ARG_PRIORITY: nf++; nl_cli_route_parse_prio(route, optarg); break; + case ARG_SCOPE: nf++; nl_cli_route_parse_scope(route, optarg); break; + case ARG_PROTOCOL: nf++; nl_cli_route_parse_protocol(route, optarg); break; + case ARG_TYPE: nf++; nl_cli_route_parse_type(route, optarg); break; } } diff --git a/src/nl-route-get.c b/src/nl-route-get.c index ce267ec..c2f07d4 100644 --- a/src/nl-route-get.c +++ b/src/nl-route-get.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/route.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -33,7 +35,7 @@ static int cb(struct nl_msg *msg, void *arg) int err; if ((err = nl_msg_parse(msg, &parse_cb, NULL)) < 0) - fatal(err, "Unable to parse object: %s", nl_geterror(err)); + nl_cli_fatal(err, "Unable to parse object: %s", nl_geterror(err)); return 0; } @@ -48,12 +50,12 @@ int main(int argc, char *argv[]) if (argc < 2 || !strcmp(argv[1], "-h")) print_usage(); - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - route_cache = nlt_alloc_route_cache(sock, 0); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + route_cache = nl_cli_route_alloc_cache(sock, 0); - dst = nlt_addr_parse(argv[1], AF_INET); + dst = nl_cli_addr_parse(argv[1], AF_INET); { struct nl_msg *m; @@ -69,12 +71,12 @@ int main(int argc, char *argv[]) err = nl_send_auto_complete(sock, m); nlmsg_free(m); if (err < 0) - fatal(err, "%s", nl_geterror(err)); + nl_cli_fatal(err, "%s", nl_geterror(err)); nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, cb, NULL); if (nl_recvmsgs_default(sock) < 0) - fatal(err, "%s", nl_geterror(err)); + nl_cli_fatal(err, "%s", nl_geterror(err)); } //nl_cache_dump(route_cache, ¶ms); diff --git a/src/nl-route-list.c b/src/nl-route-list.c index f9f8813..e0e57be 100644 --- a/src/nl-route-list.c +++ b/src/nl-route-list.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "route-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/route.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -56,10 +58,10 @@ int main(int argc, char *argv[]) }; int print_cache = 0; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - route = nlt_alloc_route(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + route = nl_cli_route_alloc(); for (;;) { int c, optidx = 0; @@ -100,25 +102,25 @@ int main(int argc, char *argv[]) switch (c) { case 'c': print_cache = 1; break; - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case 'd': parse_dst(route, optarg); break; - case 'n': parse_nexthop(route, optarg, link_cache); break; - case 't': parse_table(route, optarg); break; - case ARG_FAMILY: parse_family(route, optarg); break; - case ARG_SRC: parse_src(route, optarg); break; - case ARG_IIF: parse_iif(route, optarg, link_cache); break; - case ARG_PREF_SRC: parse_pref_src(route, optarg); break; - case ARG_METRICS: parse_metric(route, optarg); break; - case ARG_PRIORITY: parse_prio(route, optarg); break; - case ARG_SCOPE: parse_scope(route, optarg); break; - case ARG_PROTOCOL: parse_protocol(route, optarg); break; - case ARG_TYPE: parse_type(route, optarg); break; + case 'v': nl_cli_print_version(); break; + case 'd': nl_cli_route_parse_dst(route, optarg); break; + case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break; + case 't': nl_cli_route_parse_table(route, optarg); break; + case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break; + case ARG_SRC: nl_cli_route_parse_src(route, optarg); break; + case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break; + case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break; + case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break; + case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break; + case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break; + case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break; + case ARG_TYPE: nl_cli_route_parse_type(route, optarg); break; } } - route_cache = nlt_alloc_route_cache(sock, + route_cache = nl_cli_route_alloc_cache(sock, print_cache ? ROUTE_CACHE_CONTENT : 0); nl_cache_dump_filter(route_cache, ¶ms, OBJ_CAST(route)); diff --git a/src/nl-rule-list.c b/src/nl-rule-list.c index 12fc84b..8b474fa 100644 --- a/src/nl-rule-list.c +++ b/src/nl-rule-list.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "rule-utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/rule.h> +#include <netlink/cli/link.h> static void print_usage(void) { @@ -38,11 +40,11 @@ int main(int argc, char *argv[]) .dp_type = NL_DUMP_LINE, }; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - rule_cache = nlt_alloc_rule_cache(sock); - rule = nlt_alloc_rule(); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + rule_cache = nl_cli_rule_alloc_cache(sock); + rule = nl_cli_rule_alloc(); for (;;) { int c, optidx = 0; @@ -62,10 +64,10 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; - case ARG_FAMILY: parse_family(rule, optarg); break; + case 'v': nl_cli_print_version(); break; + case ARG_FAMILY: nl_cli_rule_parse_family(rule, optarg); break; } } diff --git a/src/nl-tctree-list.c b/src/nl-tctree-list.c index 6f6bf56..a074a51 100644 --- a/src/nl-tctree-list.c +++ b/src/nl-tctree-list.c @@ -6,10 +6,12 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> +#include <netlink/cli/link.h> +#include <netlink/cli/qdisc.h> #include <linux/pkt_sched.h> static struct nl_sock *sock; @@ -114,10 +116,10 @@ int main(int argc, char *argv[]) { struct nl_cache *link_cache; - sock = nlt_alloc_socket(); - nlt_connect(sock, NETLINK_ROUTE); - link_cache = nlt_alloc_link_cache(sock); - qdisc_cache = nlt_alloc_qdisc_cache(sock); + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_ROUTE); + link_cache = nl_cli_link_alloc_cache(sock); + qdisc_cache = nl_cli_qdisc_alloc_cache(sock); params.dp_fd = stdout; @@ -135,9 +137,9 @@ int main(int argc, char *argv[]) break; switch (c) { - case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; - case 'v': nlt_print_version(); break; + case 'v': nl_cli_print_version(); break; } } diff --git a/src/nl-util-addr.c b/src/nl-util-addr.c index 93779ea..5f0738d 100644 --- a/src/nl-util-addr.c +++ b/src/nl-util-addr.c @@ -6,10 +6,10 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> */ -#include "utils.h" +#include <netlink/cli/utils.h> int main(int argc, char *argv[]) { @@ -22,10 +22,10 @@ int main(int argc, char *argv[]) return -1; } - a = nlt_addr_parse(argv[1], AF_UNSPEC); + a = nl_cli_addr_parse(argv[1], AF_UNSPEC); err = nl_addr_resolve(a, host, sizeof(host)); if (err != 0) - fatal(err, "Unable to resolve address \"%s\": %s", + nl_cli_fatal(err, "Unable to resolve address \"%s\": %s", argv[1], nl_geterror(err)); printf("%s\n", host); diff --git a/src/qdisc-utils.c b/src/qdisc-utils.c deleted file mode 100644 index 57b5066..0000000 --- a/src/qdisc-utils.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * src/qdisc-utils.c QDisc 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "qdisc-utils.h" - -struct rtnl_qdisc *nlt_alloc_qdisc(void) -{ - struct rtnl_qdisc *qdisc; - - qdisc = rtnl_qdisc_alloc(); - if (!qdisc) - fatal(ENOMEM, "Unable to allocate qdisc object"); - - return qdisc; -} - -void parse_dev(struct rtnl_qdisc *qdisc, struct nl_cache *link_cache, char *arg) -{ - int ival; - - if (!(ival = rtnl_link_name2i(link_cache, arg))) - fatal(ENOENT, "Link \"%s\" does not exist", arg); - - rtnl_qdisc_set_ifindex(qdisc, ival); -} - -void parse_parent(struct rtnl_qdisc *qdisc, char *arg) -{ - uint32_t parent; - int err; - - if ((err = rtnl_tc_str2handle(arg, &parent)) < 0) - fatal(err, "Unable to parse handle \"%s\": %s", - arg, nl_geterror(err)); - - rtnl_qdisc_set_parent(qdisc, parent); -} - -void parse_handle(struct rtnl_qdisc *qdisc, char *arg) -{ - uint32_t handle; - int err; - - if ((err = rtnl_tc_str2handle(arg, &handle)) < 0) - fatal(err, "Unable to parse handle \"%s\": %s", - arg, nl_geterror(err)); - - rtnl_qdisc_set_handle(qdisc, handle); -} - -void parse_kind(struct rtnl_qdisc *qdisc, char *arg) -{ - rtnl_qdisc_set_kind(qdisc, arg); -} diff --git a/src/qdisc-utils.h b/src/qdisc-utils.h deleted file mode 100644 index f6ce3ef..0000000 --- a/src/qdisc-utils.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * src/qdisc-utils.h QDisc 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __QDISC_UTILS_H_ -#define __QDISC_UTILS_H_ - -#include "utils.h" - -extern struct rtnl_qdisc *nlt_alloc_qdisc(void); -extern void parse_dev(struct rtnl_qdisc *, struct nl_cache *, char *); -extern void parse_parent(struct rtnl_qdisc *, char *); -extern void parse_handle(struct rtnl_qdisc *, char *); -extern void parse_kind(struct rtnl_qdisc *, char *); - -#endif diff --git a/src/queue-utils.c b/src/queue-utils.c deleted file mode 100644 index 77038aa..0000000 --- a/src/queue-utils.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * src/queue-utils.c Queue 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "queue-utils.h" - -struct nfnl_queue *nlt_alloc_queue(void) -{ - struct nfnl_queue *queue; - - queue = nfnl_queue_alloc(); - if (!queue) - fatal(ENOMEM, "Unable to allocate queue object"); - - return queue; -} - diff --git a/src/queue-utils.h b/src/queue-utils.h deleted file mode 100644 index 5a628fe..0000000 --- a/src/queue-utils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * src/queue-utils.h Queue 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) 2008 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __QUEUE_UTILS_H_ -#define __QUEUE_UTILS_H_ - -#include "utils.h" -#include <linux/netfilter.h> -#include <linux/netfilter/nfnetlink_queue.h> -#include <netlink/netfilter/nfnl.h> -#include <netlink/netfilter/queue.h> -#include <netlink/netfilter/queue_msg.h> - -extern struct nfnl_queue *nlt_alloc_queue(void); - -#endif diff --git a/src/route-utils.h b/src/route-utils.h deleted file mode 100644 index b410557..0000000 --- a/src/route-utils.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * src/route-utils.h Route 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __ROUTE_UTILS_H_ -#define __ROUTE_UTILS_H_ - -#include "utils.h" - -extern struct rtnl_route *nlt_alloc_route(void); -extern void parse_family(struct rtnl_route *, char *); -extern void parse_dst(struct rtnl_route *, char *); -extern void parse_src(struct rtnl_route *, char *); -extern void parse_pref_src(struct rtnl_route *, char *); -extern void parse_metric(struct rtnl_route *, char *); -extern void parse_nexthop(struct rtnl_route *, char *, struct nl_cache *); -extern void parse_table(struct rtnl_route *, char *); -extern void parse_prio(struct rtnl_route *, char *); -extern void parse_scope(struct rtnl_route *, char *); -extern void parse_protocol(struct rtnl_route *, char *); -extern void parse_type(struct rtnl_route *, char *); -extern void parse_iif(struct rtnl_route *, char *, struct nl_cache *); - -#endif diff --git a/src/rtnl-utils.c b/src/rtnl-utils.c deleted file mode 100644 index 5c4228b..0000000 --- a/src/rtnl-utils.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * src/rtnl-utils.c rtnetlink 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "rtnl-utils.h" - -struct nl_cache *nlt_alloc_link_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "link", rtnl_link_alloc_cache); -} - -struct nl_cache *nlt_alloc_addr_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "address", rtnl_addr_alloc_cache); -} - -struct nl_cache *nlt_alloc_neigh_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "neighbour", rtnl_neigh_alloc_cache); -} - -struct nl_cache *nlt_alloc_neightbl_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "neighbour table", rtnl_neightbl_alloc_cache); -} - -struct nl_cache *nlt_alloc_route_cache(struct nl_sock *sk, int flags) -{ - struct nl_cache *cache; - int err; - - if ((err = rtnl_route_alloc_cache(sk, AF_UNSPEC, flags, &cache)) < 0) - fatal(err, "Unable to allocate route cache: %s\n", - nl_geterror(err)); - - nl_cache_mngt_provide(cache); - - return cache; -} - -struct nl_cache *nlt_alloc_rule_cache(struct nl_sock *sk) -{ - struct nl_cache *cache; - int err; - - if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0) - fatal(err, "Unable to allocate routing rule cache: %s\n", - nl_geterror(err)); - - nl_cache_mngt_provide(cache); - - return cache; -} - -struct nl_cache *nlt_alloc_qdisc_cache(struct nl_sock *sk) -{ - return alloc_cache(sk, "queueing disciplines", rtnl_qdisc_alloc_cache); -} - diff --git a/src/rtnl-utils.h b/src/rtnl-utils.h deleted file mode 100644 index 5f2bbe3..0000000 --- a/src/rtnl-utils.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * src/rtnl-utils.h rtnetlink 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __SRC_RTNL_UTILS_H_ -#define __SRC_RTNL_UTILS_H_ - -#include "utils.h" - -extern struct nl_cache *nlt_alloc_link_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_addr_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_neigh_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_neightbl_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_qdisc_cache(struct nl_sock *); -extern struct nl_cache *nlt_alloc_route_cache(struct nl_sock *, int); -extern struct nl_cache *nlt_alloc_rule_cache(struct nl_sock *); - -#endif diff --git a/src/rule-utils.c b/src/rule-utils.c deleted file mode 100644 index e8f3ba7..0000000 --- a/src/rule-utils.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * src/rule-utils.c Routing Rule 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 Thomas Graf <tgraf@suug.ch> - */ - -#include "rule-utils.h" - -struct rtnl_rule *nlt_alloc_rule(void) -{ - struct rtnl_rule *rule; - - rule = rtnl_rule_alloc(); - if (!rule) - fatal(ENOMEM, "Unable to allocate rule object"); - - return rule; -} - -void parse_family(struct rtnl_rule *rule, char *arg) -{ - int family; - - if ((family = nl_str2af(arg)) != AF_UNSPEC) - rtnl_rule_set_family(rule, family); -} diff --git a/src/rule-utils.h b/src/rule-utils.h deleted file mode 100644 index fcbf9a7..0000000 --- a/src/rule-utils.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * src/rule-utils.h Routing Rule 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 Thomas Graf <tgraf@suug.ch> - */ - -#ifndef __RULE_UTILS_H_ -#define __RULE_UTILS_H_ - -#include "utils.h" - -extern struct rtnl_rule *nlt_alloc_rule(void); -extern void parse_family(struct rtnl_rule *, char *); - -#endif |