dect
/
libnl
Archived
13
0
Fork 0

CLI - Command Line Interface Library

Moved common code in src/ used by CLI tools to src/lib/ for possible use
by other CLI tools. Just link to libnl-cli.{so|la}
This commit is contained in:
Thomas Graf 2009-12-16 16:20:46 +01:00
parent ff76549013
commit 8808743839
71 changed files with 1446 additions and 1401 deletions

View File

@ -30,6 +30,6 @@ AC_SUBST([pkgconfigdir])
AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required])) AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required]))
AC_CONFIG_FILES([Makefile doc/Doxyfile doc/Makefile lib/Makefile AC_CONFIG_FILES([Makefile doc/Doxyfile doc/Makefile lib/Makefile
include/Makefile src/Makefile libnl-2.0.pc \ include/Makefile src/Makefile src/lib/Makefile \
include/netlink/version.h]) libnl-2.0.pc include/netlink/version.h])
AC_OUTPUT AC_OUTPUT

View File

@ -463,6 +463,7 @@ WARN_LOGFILE =
# with spaces. # with spaces.
INPUT = ../lib \ INPUT = ../lib \
../src/lib \
../include/netlink ../include/netlink
# This tag can be used to specify the character encoding of the source files that # This tag can be used to specify the character encoding of the source files that

View File

@ -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

34
include/netlink/cli/ct.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -6,26 +6,30 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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_ #ifndef __NETLINK_CLI_UTILS_H_
#define __SRC_UTILS_H_ #define __NETLINK_CLI_UTILS_H_
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <inttypes.h> #include <inttypes.h>
#include <errno.h> #include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <ctype.h> #include <ctype.h>
#include <getopt.h> #include <getopt.h>
#include <dlfcn.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netlink/netlink.h> #include <netlink/netlink.h>
#include <netlink/utils.h> #include <netlink/utils.h>
#include <netlink/addr.h> #include <netlink/addr.h>
#include <netlink/list.h>
#include <netlink/route/rtnl.h> #include <netlink/route/rtnl.h>
#include <netlink/route/link.h> #include <netlink/route/link.h>
#include <netlink/route/addr.h> #include <netlink/route/addr.h>
@ -44,6 +48,10 @@
#include <netlink/genl/mngt.h> #include <netlink/genl/mngt.h>
#include <netlink/netfilter/ct.h> #include <netlink/netfilter/ct.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __init #ifndef __init
#define __init __attribute__((constructor)) #define __init __attribute__((constructor))
#endif #endif
@ -52,26 +60,21 @@
#define __exit __attribute__((destructor)) #define __exit __attribute__((destructor))
#endif #endif
extern uint32_t parse_u32(const char *); 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 void nlt_print_version(void); extern struct nl_cache *nl_cli_alloc_cache(struct nl_sock *, const char *,
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 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 *,
int (*ac)(struct nl_sock *, struct nl_cache **)); int (*ac)(struct nl_sock *, struct nl_cache **));
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,7 +1,9 @@
# -*- Makefile -*- # -*- Makefile -*-
SUBDIRS = lib
AM_CFLAGS = -Wall -I${top_srcdir}/include -D_GNU_SOURCE 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 = \ noinst_PROGRAMS = \
genl-ctrl-list \ genl-ctrl-list \
@ -20,83 +22,76 @@ noinst_PROGRAMS = \
nl-list-caches nl-list-sockets \ nl-list-caches nl-list-sockets \
nl-util-addr nl-util-addr
rtnl_utils_c = rtnl-utils.c utils.c genl_ctrl_list_SOURCES = genl-ctrl-list.c
genl_ctrl_list_LDADD = -lnl-genl -lnl-route
genl_ctrl_list_SOURCES = genl-ctrl-list.c ctrl-utils.c utils.c nf_ct_list_SOURCES = nf-ct-list.c
genl_ctrl_list_LDADD = -lnl-genl
nf_ct_list_SOURCES = nf-ct-list.c ct-utils.c utils.c
nf_ct_list_LDADD = -lnl-nf 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_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_queue_LDADD = -lnl-nf
nf_monitor_SOURCES = nf-monitor.c utils.c nf_monitor_SOURCES = nf-monitor.c
nf_monitor_LDADD = -lnl-nf nf_monitor_LDADD = -lnl-nf
addr_c = addr-utils.c ${rtnl_utils_c} nl_addr_add_SOURCES = nl-addr-add.c
nl_addr_add_SOURCES = nl-addr-add.c ${addr_c}
nl_addr_add_LDADD = -lnl-route 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_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 nl_addr_list_LDADD = -lnl-route
link_c = link-utils.c ${rtnl_utils_c} nl_link_list_SOURCES = nl-link-list.c
nl_link_list_SOURCES = nl-link-list.c ${link_c}
nl_link_list_LDADD = -lnl-route 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_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_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_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_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 nl_monitor_LDADD = -lnl-route
neigh_c = neigh-utils.c ${rtnl_utils_c} nl_neigh_add_SOURCES = nl-neigh-add.c
nl_neigh_add_SOURCES = nl-neigh-add.c ${neigh_c}
nl_neigh_add_LDADD = -lnl-route 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_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_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 nl_neightbl_list_LDADD = -lnl-route
qdisc_c = qdisc-utils.c ${rtnl_utils_c} nl_qdisc_delete_SOURCES = nl-qdisc-delete.c
nl_qdisc_delete_SOURCES = nl-qdisc-delete.c ${qdisc_c}
nl_qdisc_delete_LDADD = -lnl-route 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 nl_qdisc_list_LDADD = -lnl-route
route_c = route-utils.c ${rtnl_utils_c} nl_route_add_SOURCES = nl-route-add.c
nl_route_add_SOURCES = nl-route-add.c ${route_c}
nl_route_add_LDADD = -lnl-route 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_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_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_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_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_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_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_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_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 nl_util_addr_LDADD = -lnl-route

View File

@ -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));
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -6,10 +6,16 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -33,9 +39,9 @@ int main(int argc, char *argv[])
.dp_fd = stdout, .dp_fd = stdout,
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_GENERIC); nl_cli_connect(sock, NETLINK_GENERIC);
family_cache = nlt_alloc_genl_family_cache(sock); family_cache = alloc_genl_family_cache(sock);
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -51,9 +57,9 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
} }
} }

41
src/lib/Makefile.am Normal file
View File

@ -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

135
src/lib/addr.c Normal file
View File

@ -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));
}
/** @} */

162
src/lib/ct.c Normal file
View File

@ -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
/** @} */

73
src/lib/link.c Normal file
View File

@ -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);
}
/** @} */

88
src/lib/neigh.c Normal file
View File

@ -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);
}
/** @} */

72
src/lib/qdisc.c Normal file
View File

@ -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);
}
/** @} */

View File

@ -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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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
*
* @{
*/
struct rtnl_route *nlt_alloc_route(void) #include <netlink/cli/utils.h>
#include <netlink/cli/route.h>
struct rtnl_route *nl_cli_route_alloc(void)
{ {
struct rtnl_route *route; struct rtnl_route *route;
route = rtnl_route_alloc(); route = rtnl_route_alloc();
if (!route) if (!route)
fatal(ENOMEM, "Unable to allocate route object"); nl_cli_fatal(ENOMEM, "Unable to allocate route object");
return route; 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; int family;
@ -30,46 +52,46 @@ void parse_family(struct rtnl_route *route, char *arg)
rtnl_route_set_family(route, family); 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; struct nl_addr *addr;
int err; 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) 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_geterror(err));
nl_addr_put(addr); 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; struct nl_addr *addr;
int err; 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) 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_geterror(err));
nl_addr_put(addr); 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; struct nl_addr *addr;
int err; 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) 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_geterror(err));
nl_addr_put(addr); 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_* */ /* strict equal order to RTAX_* */
static char *const tokens[] = { static char *const tokens[] = {
@ -94,25 +116,25 @@ void parse_metric(struct rtnl_route *route, char *subopts)
while (*subopts != '\0') { while (*subopts != '\0') {
int ret = getsubopt(&subopts, tokens, &arg); int ret = getsubopt(&subopts, tokens, &arg);
if (ret == -1) if (ret == -1)
fatal(EINVAL, "Unknown metric token \"%s\"", arg); nl_cli_fatal(EINVAL, "Unknown metric token \"%s\"", arg);
if (ret == 0) if (ret == 0)
fatal(EINVAL, "Invalid metric \"%s\"", tokens[ret]); nl_cli_fatal(EINVAL, "Invalid metric \"%s\"", tokens[ret]);
if (arg == NULL) 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); lval = strtoul(arg, &endptr, 0);
if (endptr == arg) 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) 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)); 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) struct nl_cache *link_cache)
{ {
enum { enum {
@ -133,27 +155,27 @@ void parse_nexthop(struct rtnl_route *route, char *subopts,
char *arg, *endptr; char *arg, *endptr;
if (!(nh = rtnl_route_nh_alloc())) if (!(nh = rtnl_route_nh_alloc()))
fatal(ENOMEM, "Out of memory"); nl_cli_fatal(ENOMEM, "Out of memory");
while (*subopts != '\0') { while (*subopts != '\0') {
int ret = getsubopt(&subopts, tokens, &arg); int ret = getsubopt(&subopts, tokens, &arg);
if (ret == -1) if (ret == -1)
fatal(EINVAL, "Unknown nexthop token \"%s\"", arg); nl_cli_fatal(EINVAL, "Unknown nexthop token \"%s\"", arg);
if (arg == NULL) if (arg == NULL)
fatal(EINVAL, "Missing argument to option \"%s\"\n", nl_cli_fatal(EINVAL, "Missing argument to option \"%s\"\n",
tokens[ret]); tokens[ret]);
switch (ret) { switch (ret) {
case NH_DEV: case NH_DEV:
if (!(ival = rtnl_link_name2i(link_cache, arg))) 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); rtnl_route_nh_set_ifindex(nh, ival);
break; break;
case NH_VIA: 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); rtnl_route_nh_set_gateway(nh, addr);
nl_addr_put(addr); nl_addr_put(addr);
break; break;
@ -161,7 +183,9 @@ void parse_nexthop(struct rtnl_route *route, char *subopts,
case NH_WEIGHT: case NH_WEIGHT:
lval = strtoul(arg, &endptr, 0); lval = strtoul(arg, &endptr, 0);
if (endptr == arg) 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); rtnl_route_nh_set_weight(nh, lval);
break; break;
} }
@ -170,7 +194,7 @@ void parse_nexthop(struct rtnl_route *route, char *subopts,
rtnl_route_add_nexthop(route, nh); 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; unsigned long lval;
char *endptr; char *endptr;
@ -178,34 +202,34 @@ void parse_table(struct rtnl_route *route, char *arg)
lval = strtoul(arg, &endptr, 0); lval = strtoul(arg, &endptr, 0);
if (endptr == arg) { if (endptr == arg) {
if ((lval = rtnl_route_str2table(arg)) < 0) 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); 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; unsigned long lval;
char *endptr; char *endptr;
lval = strtoul(arg, &endptr, 0); lval = strtoul(arg, &endptr, 0);
if (endptr == arg) 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); 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; int ival;
if ((ival = rtnl_str2scope(arg)) < 0) 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); 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; unsigned long lval;
char *endptr; char *endptr;
@ -213,31 +237,34 @@ void parse_protocol(struct rtnl_route *route, char *arg)
lval = strtoul(arg, &endptr, 0); lval = strtoul(arg, &endptr, 0);
if (endptr == arg) { if (endptr == arg) {
if ((lval = rtnl_route_str2proto(arg)) < 0) if ((lval = rtnl_route_str2proto(arg)) < 0)
fatal(EINVAL, "Unknown routing protocol name \"%s\"", nl_cli_fatal(EINVAL,
arg); "Unknown routing protocol name \"%s\"",
arg);
} }
rtnl_route_set_protocol(route, lval); 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; int ival;
if ((ival = nl_str2rtntype(arg)) < 0) 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) 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)); 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; int ival;
if (!(ival = rtnl_link_name2i(link_cache, arg))) 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); rtnl_route_set_iif(route, ival);
} }
/** @} */

55
src/lib/rule.c Normal file
View File

@ -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);
}
/** @} */

View File

@ -6,32 +6,35 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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 <netlink/cli/utils.h>
#include <stdarg.h>
#include <limits.h>
uint32_t parse_u32(const char *arg) uint32_t nl_cli_parse_u32(const char *arg)
{ {
unsigned long lval; unsigned long lval;
char *endptr; char *endptr;
lval = strtoul(arg, &endptr, 0); lval = strtoul(arg, &endptr, 0);
if (endptr == arg || lval == ULONG_MAX) 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; return (uint32_t) lval;
} }
void nlt_print_version(void) void nl_cli_print_version(void)
{ {
printf("libnl tools version %s\n", LIBNL_VERSION); printf("libnl tools version %s\n", LIBNL_VERSION);
printf( printf(
"Copyright (C) 2003-2008 Thomas Graf\n" "Copyright (C) 2003-2009 Thomas Graf <tgraf@redhat.com>\n"
"\n" "\n"
"This program comes with ABSOLUTELY NO WARRANTY. This is free \n" "This program comes with ABSOLUTELY NO WARRANTY. This is free \n"
"software, and you are welcome to redistribute it under certain\n" "software, and you are welcome to redistribute it under certain\n"
@ -41,55 +44,57 @@ void nlt_print_version(void)
exit(0); exit(0);
} }
void fatal(int err, const char *fmt, ...) void nl_cli_fatal(int err, const char *fmt, ...)
{ {
va_list ap; va_list ap;
fprintf(stderr, "Error: "); fprintf(stderr, "Error: ");
va_start(ap, fmt); if (fmt) {
vfprintf(stderr, fmt, ap); va_start(ap, fmt);
va_end(ap); vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} else
fprintf(stderr, "%s\n", strerror(err));
exit(abs(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; int err;
if ((err = nl_connect(sk, protocol)) < 0) if ((err = nl_connect(sk, protocol)) < 0)
fatal(err, "Unable to connect netlink socket: %s", nl_cli_fatal(err, "Unable to connect netlink socket: %s",
nl_geterror(err)); nl_geterror(err));
return err; return err;
} }
struct nl_sock *nlt_alloc_socket(void) struct nl_sock *nl_cli_alloc_socket(void)
{ {
struct nl_sock *sock; struct nl_sock *sock;
if (!(sock = nl_socket_alloc())) if (!(sock = nl_socket_alloc()))
fatal(ENOBUFS, "Unable to allocate netlink socket"); nl_cli_fatal(ENOBUFS, "Unable to allocate netlink socket");
return sock; 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; struct nl_addr *addr;
int err; int err;
if ((err = nl_addr_parse(str, family, &addr)) < 0) if ((err = nl_addr_parse(str, family, &addr)) < 0)
fatal(err, "Unable to parse address \"%s\": %s", nl_cli_fatal(err, "Unable to parse address \"%s\": %s",
str, nl_geterror(err)); str, nl_geterror(err));
return addr; return addr;
} }
int nlt_parse_dumptype(const char *str) int nl_cli_parse_dumptype(const char *str)
{ {
if (!strcasecmp(str, "brief")) if (!strcasecmp(str, "brief"))
return NL_DUMP_LINE; return NL_DUMP_LINE;
@ -100,13 +105,13 @@ int nlt_parse_dumptype(const char *str)
else if (!strcasecmp(str, "env")) else if (!strcasecmp(str, "env"))
return NL_DUMP_ENV; return NL_DUMP_ENV;
else else
fatal(EINVAL, "Invalid dump type \"%s\".\n", str); nl_cli_fatal(EINVAL, "Invalid dump type \"%s\".\n", str);
return 0; return 0;
} }
int nlt_confirm(struct nl_object *obj, struct nl_dump_params *params, int nl_cli_confirm(struct nl_object *obj, struct nl_dump_params *params,
int default_yes) int default_yes)
{ {
int answer; int answer;
@ -124,18 +129,19 @@ int nlt_confirm(struct nl_object *obj, struct nl_dump_params *params,
return answer == 'y'; return answer == 'y';
} }
struct nl_cache *alloc_cache(struct nl_sock *sock, const char *name, struct nl_cache *nl_cli_alloc_cache(struct nl_sock *sock, const char *name,
int (*ac)(struct nl_sock *, struct nl_cache **)) int (*ac)(struct nl_sock *, struct nl_cache **))
{ {
struct nl_cache *cache; struct nl_cache *cache;
int err; int err;
if ((err = ac(sock, &cache)) < 0) if ((err = ac(sock, &cache)) < 0)
fatal(err, "Unable to allocate %s cache: %s", nl_cli_fatal(err, "Unable to allocate %s cache: %s",
name, nl_geterror(err)); name, nl_geterror(err));
nl_cache_mngt_provide(cache); nl_cache_mngt_provide(cache);
return cache; return cache;
} }
/** @} */

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -6,12 +6,13 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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 Philip Craig <philipc@snapgear.com>
* Copyright (c) 2007 Secure Computing Corporation * 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) static void print_usage(void)
{ {
@ -54,7 +55,7 @@ int main(int argc, char *argv[])
.dp_fd = stdout, .dp_fd = stdout,
}; };
ct = nlt_alloc_ct(); ct = nl_cli_ct_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -103,31 +104,31 @@ int main(int argc, char *argv[])
case '?': exit(NLE_INVAL); case '?': exit(NLE_INVAL);
case '4': nfnl_ct_set_family(ct, AF_INET); break; case '4': nfnl_ct_set_family(ct, AF_INET); break;
case '6': nfnl_ct_set_family(ct, AF_INET6); 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'i': parse_id(ct, optarg); break; case 'i': nl_cli_ct_parse_id(ct, optarg); break;
case 'p': parse_protocol(ct, optarg); break; case 'p': nl_cli_ct_parse_protocol(ct, optarg); break;
case ARG_TCP_STATE: parse_tcp_state(ct, optarg); break; case ARG_TCP_STATE: nl_cli_ct_parse_tcp_state(ct, optarg); break;
case ARG_ORIG_SRC: parse_src(ct, 0, optarg); break; case ARG_ORIG_SRC: nl_cli_ct_parse_src(ct, 0, optarg); break;
case ARG_ORIG_SPORT: parse_src_port(ct, 0, optarg); break; case ARG_ORIG_SPORT: nl_cli_ct_parse_src_port(ct, 0, optarg); break;
case ARG_ORIG_DST: parse_dst(ct, 0, optarg); break; case ARG_ORIG_DST: nl_cli_ct_parse_dst(ct, 0, optarg); break;
case ARG_ORIG_DPORT: parse_dst_port(ct, 0, optarg); break; case ARG_ORIG_DPORT: nl_cli_ct_parse_dst_port(ct, 0, optarg); break;
case ARG_REPLY_SRC: parse_src(ct, 1, optarg); break; case ARG_REPLY_SRC: nl_cli_ct_parse_src(ct, 1, optarg); break;
case ARG_REPLY_SPORT: parse_src_port(ct, 1, optarg); break; case ARG_REPLY_SPORT: nl_cli_ct_parse_src_port(ct, 1, optarg); break;
case ARG_REPLY_DST: parse_dst(ct, 1, optarg); break; case ARG_REPLY_DST: nl_cli_ct_parse_dst(ct, 1, optarg); break;
case ARG_REPLY_DPORT: parse_dst_port(ct, 1, optarg); break; case ARG_REPLY_DPORT: nl_cli_ct_parse_dst_port(ct, 1, optarg); break;
case 'F': parse_family(ct, optarg); break; case 'F': nl_cli_ct_parse_family(ct, optarg); break;
case ARG_MARK: parse_mark(ct, optarg); break; case ARG_MARK: nl_cli_ct_parse_mark(ct, optarg); break;
case ARG_TIMEOUT: parse_timeout(ct, optarg); break; case ARG_TIMEOUT: nl_cli_ct_parse_timeout(ct, optarg); break;
case ARG_REFCNT: parse_use(ct, optarg); break; case ARG_REFCNT: nl_cli_ct_parse_use(ct, optarg); break;
case ARG_FLAGS: parse_status(ct, optarg); break; case ARG_FLAGS: nl_cli_ct_parse_status(ct, optarg); break;
} }
} }
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_NETFILTER); nl_cli_connect(sock, NETLINK_NETFILTER);
ct_cache = nlt_alloc_ct_cache(sock); ct_cache = nl_cli_ct_alloc_cache(sock);
nl_cache_dump_filter(ct_cache, &params, OBJ_CAST(ct)); nl_cache_dump_filter(ct_cache, &params, OBJ_CAST(ct));

View File

@ -11,7 +11,22 @@
* Copyright (c) 2007 Secure Computing Corporation * 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) static void obj_input(struct nl_object *obj, void *arg)
{ {
@ -44,7 +59,7 @@ int main(int argc, char *argv[])
int err; int err;
int family; int family;
nf_sock = nlt_alloc_socket(); nf_sock = nl_cli_alloc_socket();
nl_socket_disable_seq_check(nf_sock); nl_socket_disable_seq_check(nf_sock);
nl_socket_modify_cb(nf_sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); 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; return 2;
} }
nlt_connect(nf_sock, NETLINK_NETFILTER); nl_cli_connect(nf_sock, NETLINK_NETFILTER);
family = nl_str2af(argv[1]); family = nl_str2af(argv[1]);
if (family == AF_UNSPEC) if (family == AF_UNSPEC)
fatal(NLE_INVAL, "Unknown family \"%s\": %s", nl_cli_fatal(NLE_INVAL, "Unknown family \"%s\": %s",
argv[1], nl_geterror(family)); argv[1], nl_geterror(family));
nfnl_log_pf_unbind(nf_sock, family); nfnl_log_pf_unbind(nf_sock, family);
if ((err = nfnl_log_pf_bind(nf_sock, family)) < 0) 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])); nfnl_log_set_group(log, atoi(argv[2]));
copy_mode = NFNL_LOG_COPY_META; copy_mode = NFNL_LOG_COPY_META;
if (argc > 3) { if (argc > 3) {
copy_mode = nfnl_log_str2copy_mode(argv[3]); copy_mode = nfnl_log_str2copy_mode(argv[3]);
if (copy_mode < 0) if (copy_mode < 0)
fatal(copy_mode, "Unable to parse copy mode \"%s\": %s", nl_cli_fatal(copy_mode,
argv[3], nl_geterror(copy_mode)); "Unable to parse copy mode \"%s\": %s",
argv[3], nl_geterror(copy_mode));
} }
nfnl_log_set_copy_mode(log, 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); nfnl_log_set_copy_range(log, copy_range);
if ((err = nfnl_log_create(nf_sock, log)) < 0) 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 = { struct nl_dump_params dp = {
@ -96,9 +114,9 @@ int main(int argc, char *argv[])
nl_object_dump((struct nl_object *) log, &dp); nl_object_dump((struct nl_object *) log, &dp);
} }
rt_sock = nlt_alloc_socket(); rt_sock = nl_cli_alloc_socket();
nlt_connect(rt_sock, NETLINK_ROUTE); nl_cli_connect(rt_sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(rt_sock); link_cache = nl_cli_link_alloc_cache(rt_sock);
while (1) { while (1) {
fd_set rfds; fd_set rfds;

View File

@ -11,7 +11,7 @@
* Copyright (c) 2007 Secure Computing Corporation * Copyright (c) 2007 Secure Computing Corporation
*/ */
#include "utils.h" #include <netlink/cli/utils.h>
#include <netlink/netfilter/nfnl.h> #include <netlink/netfilter/nfnl.h>
static void obj_input(struct nl_object *obj, void *arg) static void obj_input(struct nl_object *obj, void *arg)
@ -50,7 +50,7 @@ int main(int argc, char *argv[])
{ NFNLGRP_NONE, NULL } { NFNLGRP_NONE, NULL }
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nl_socket_disable_seq_check(sock); nl_socket_disable_seq_check(sock);
nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); 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; return 2;
} }
nlt_connect(sock, NETLINK_NETFILTER); nl_cli_connect(sock, NETLINK_NETFILTER);
for (idx = 1; argc > idx; idx++) { for (idx = 1; argc > idx; idx++) {
for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++) { 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); err = nl_socket_add_membership(sock, groups[i].gr_id);
if (err < 0) if (err < 0)
fatal(err, "Unable to add membership: %s", nl_cli_fatal(err,
nl_geterror(err)); "Unable to add membership: %s",
nl_geterror(err));
break; break;
} }
if (groups[i].gr_id == NFNLGRP_NONE) if (groups[i].gr_id == NFNLGRP_NONE)
fatal(NLE_OBJ_NOTFOUND, "Unknown group: \"%s\"", nl_cli_fatal(NLE_OBJ_NOTFOUND, "Unknown group: \"%s\"",
argv[idx]); argv[idx]);
} }
while (1) { while (1) {

View File

@ -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 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) static void obj_input(struct nl_object *obj, void *arg)
{ {
struct nfnl_queue_msg *msg = (struct nfnl_queue_msg *) obj; 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(); nf_sock = nfnl_queue_socket_alloc();
if (nf_sock == NULL) 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_disable_seq_check(nf_sock);
nl_socket_modify_cb(nf_sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); 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; return 2;
} }
nlt_connect(nf_sock, NETLINK_NETFILTER); nl_cli_connect(nf_sock, NETLINK_NETFILTER);
if ((family = nl_str2af(argv[1])) == AF_UNSPEC) 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); nfnl_queue_pf_unbind(nf_sock, family);
if ((err = nfnl_queue_pf_bind(nf_sock, family)) < 0) 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])); nfnl_queue_set_group(queue, atoi(argv[2]));
copy_mode = NFNL_QUEUE_COPY_PACKET; copy_mode = NFNL_QUEUE_COPY_PACKET;
if (argc > 3) { if (argc > 3) {
copy_mode = nfnl_queue_str2copy_mode(argv[3]); copy_mode = nfnl_queue_str2copy_mode(argv[3]);
if (copy_mode < 0) if (copy_mode < 0)
fatal(copy_mode, "Unable to parse copy mode \"%s\": %s", nl_cli_fatal(copy_mode,
argv[3], nl_geterror(copy_mode)); "Unable to parse copy mode \"%s\": %s",
argv[3], nl_geterror(copy_mode));
} }
nfnl_queue_set_copy_mode(queue, 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); nfnl_queue_set_copy_range(queue, copy_range);
if ((err = nfnl_queue_create(nf_sock, queue)) < 0) 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(); rt_sock = nl_cli_alloc_socket();
nlt_connect(rt_sock, NETLINK_ROUTE); nl_cli_connect(rt_sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(rt_sock); link_cache = nl_cli_link_alloc_cache(rt_sock);
while (1) { while (1) {
fd_set rfds; fd_set rfds;

View File

@ -5,10 +5,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2 of the License. * 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; static int quiet = 0;
@ -49,10 +51,10 @@ int main(int argc, char *argv[])
}; };
int err, nlflags = NLM_F_CREATE; int err, nlflags = NLM_F_CREATE;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
addr = nlt_alloc_addr(); addr = nl_cli_addr_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -92,21 +94,22 @@ int main(int argc, char *argv[])
case ARG_REPLACE: nlflags |= NLM_F_REPLACE; break; case ARG_REPLACE: nlflags |= NLM_F_REPLACE; break;
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'a': parse_local(addr, optarg); break; case 'a': nl_cli_addr_parse_local(addr, optarg); break;
case 'd': parse_dev(addr, link_cache, optarg); break; case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break;
case ARG_FAMILY: parse_family(addr, optarg); break; case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break;
case ARG_LABEL: parse_label(addr, optarg); break; case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break;
case ARG_PEER: parse_peer(addr, optarg); break; case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break;
case ARG_SCOPE: parse_scope(addr, optarg); break; case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break;
case ARG_BROADCAST: parse_broadcast(addr, optarg); break; case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break;
case ARG_PREFERRED: parse_preferred(addr, optarg); break; case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break;
case ARG_VALID: parse_valid(addr, optarg); break; case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break;
} }
} }
if ((err = rtnl_addr_add(sock, addr, nlflags)) < 0) 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) { if (!quiet) {
printf("Added "); printf("Added ");

View File

@ -5,10 +5,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2 of the License. * 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 struct nl_sock *sock;
static int interactive = 0, default_yes = 0, quiet = 0; 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; int err;
if (interactive && !nlt_confirm(obj, &params, default_yes)) if (interactive && !nl_cli_confirm(obj, &params, default_yes))
return; return;
if ((err = rtnl_addr_delete(sock, addr, 0)) < 0) 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) { if (!quiet) {
printf("Deleted "); printf("Deleted ");
@ -70,11 +73,11 @@ int main(int argc, char *argv[])
struct rtnl_addr *addr; struct rtnl_addr *addr;
struct nl_cache *link_cache, *addr_cache; struct nl_cache *link_cache, *addr_cache;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
addr_cache = nlt_alloc_addr_cache(sock); addr_cache = nl_cli_addr_alloc_cache(sock);
addr = nlt_alloc_addr(); addr = nl_cli_addr_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -115,16 +118,16 @@ int main(int argc, char *argv[])
case ARG_YES: default_yes = 1; break; case ARG_YES: default_yes = 1; break;
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'a': parse_local(addr, optarg); break; case 'a': nl_cli_addr_parse_local(addr, optarg); break;
case 'd': parse_dev(addr, link_cache, optarg); break; case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break;
case ARG_FAMILY: parse_family(addr, optarg); break; case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break;
case ARG_LABEL: parse_label(addr, optarg); break; case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break;
case ARG_PEER: parse_peer(addr, optarg); break; case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break;
case ARG_SCOPE: parse_scope(addr, optarg); break; case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break;
case ARG_BROADCAST: parse_broadcast(addr, optarg); break; case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break;
case ARG_PREFERRED: parse_preferred(addr, optarg); break; case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break;
case ARG_VALID: parse_valid(addr, optarg); break; case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break;
} }
} }

View File

@ -5,10 +5,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2 of the License. * 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) static void print_usage(void)
{ {
@ -118,11 +120,11 @@ int main(int argc, char *argv[])
}; };
int dump_env = 0; int dump_env = 0;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
addr_cache = nlt_alloc_addr_cache(sock); addr_cache = nl_cli_addr_alloc_cache(sock);
addr = nlt_alloc_addr(); addr = nl_cli_addr_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -168,16 +170,16 @@ int main(int argc, char *argv[])
case ARG_ENV: dump_env = 1; break; case ARG_ENV: dump_env = 1; break;
case ARG_PREFIX: prefix = strdup(optarg); break; case ARG_PREFIX: prefix = strdup(optarg); break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'a': parse_local(addr, optarg); break; case 'a': nl_cli_addr_parse_local(addr, optarg); break;
case 'd': parse_dev(addr, link_cache, optarg); break; case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break;
case ARG_FAMILY: parse_family(addr, optarg); break; case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break;
case ARG_LABEL: parse_label(addr, optarg); break; case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break;
case ARG_PEER: parse_peer(addr, optarg); break; case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break;
case ARG_SCOPE: parse_scope(addr, optarg); break; case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break;
case ARG_BROADCAST: parse_broadcast(addr, optarg); break; case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break;
case ARG_PREFERRED: parse_preferred(addr, optarg); break; case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break;
case ARG_VALID: parse_valid(addr, optarg); break; case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break;
} }
} }

View File

@ -6,10 +6,10 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -73,19 +73,19 @@ int main(int argc, char *argv[])
if (optind >= argc) if (optind >= argc)
print_usage(); print_usage();
nlh = nlt_alloc_socket(); nlh = nl_cli_alloc_socket();
if ((err = nl_addr_parse(argv[optind], AF_INET, &addr)) < 0) 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)); argv[optind], nl_geterror(err));
result = flnl_result_alloc_cache(); result = flnl_result_alloc_cache();
if (!result) if (!result)
fatal(ENOMEM, "Unable to allocate cache"); nl_cli_fatal(ENOMEM, "Unable to allocate cache");
request = flnl_request_alloc(); request = flnl_request_alloc();
if (!request) 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_table(request, table);
flnl_request_set_fwmark(request, fwmark); flnl_request_set_fwmark(request, fwmark);
@ -95,13 +95,13 @@ int main(int argc, char *argv[])
err = flnl_request_set_addr(request, addr); err = flnl_request_set_addr(request, addr);
nl_addr_put(addr); nl_addr_put(addr);
if (err < 0) 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); err = flnl_lookup(nlh, request, result);
if (err < 0) 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, &params); nl_cache_dump(result, &params);

View File

@ -6,10 +6,11 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -27,14 +28,15 @@ int main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
print_usage(); print_usage();
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); 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))) 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); printf("%s\n", name);

View File

@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * of the License.
* *
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
*/ */
#if 0 #if 0
@ -24,7 +24,8 @@ static void print_usage(void)
} }
#endif #endif
#include "link-utils.h" #include <netlink/cli/utils.h>
#include <netlink/cli/link.h>
static void print_usage(void) static void print_usage(void)
{ {
@ -56,10 +57,10 @@ int main(int argc, char *argv[])
.dp_fd = stdout, .dp_fd = stdout,
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
link = nlt_alloc_link(); link = nl_cli_link_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -87,15 +88,15 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'n': parse_name(link, optarg); break; case 'n': nl_cli_link_parse_name(link, optarg); break;
case 'i': parse_ifindex(link, optarg); break; case 'i': nl_cli_link_parse_ifindex(link, optarg); break;
case ARG_FAMILY: parse_family(link, optarg); break; case ARG_FAMILY: nl_cli_link_parse_family(link, optarg); break;
case ARG_MTU: parse_mtu(link, optarg); break; case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break;
case ARG_TXQLEN: parse_txqlen(link, optarg); break; case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break;
case ARG_WEIGHT: parse_weight(link, optarg); break; case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break;
} }
} }

View File

@ -9,7 +9,8 @@
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> * 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) static void print_usage(void)
{ {
@ -26,12 +27,13 @@ int main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
print_usage(); print_usage();
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
if (!(ifindex = rtnl_link_name2i(link_cache, argv[1]))) 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); printf("%u\n", ifindex);

View File

@ -6,10 +6,11 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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 struct nl_sock *sock;
static int quiet = 0; static int quiet = 0;
@ -55,7 +56,8 @@ static void set_cb(struct nl_object *obj, void *arg)
int err; int err;
if ((err = rtnl_link_change(sock, link, change, 0) < 0)) 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) { if (!quiet) {
printf("Changed "); printf("Changed ");
@ -69,11 +71,11 @@ int main(int argc, char *argv[])
struct rtnl_link *link, *change; struct rtnl_link *link, *change;
int ok = 0; int ok = 0;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
link = nlt_alloc_link(); link = nl_cli_link_alloc();
change = nlt_alloc_link(); change = nl_cli_link_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -103,13 +105,13 @@ int main(int argc, char *argv[])
switch (c) { switch (c) {
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'n': ok++; parse_name(link, optarg); break; case 'n': ok++; nl_cli_link_parse_name(link, optarg); break;
case 'i': ok++; parse_ifindex(link, optarg); break; case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg); break;
case ARG_RENAME: parse_name(change, optarg); break; case ARG_RENAME: nl_cli_link_parse_name(change, optarg); break;
case ARG_MTU: parse_mtu(link, optarg); break; case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break;
case ARG_TXQLEN: parse_txqlen(link, optarg); break; case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break;
case ARG_WEIGHT: parse_weight(link, optarg); break; case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break;
} }
} }

View File

@ -6,10 +6,11 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -81,10 +82,10 @@ int main(int argc, char *argv[])
struct nl_cache *link_cache; struct nl_cache *link_cache;
struct rtnl_link *link; struct rtnl_link *link;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
link = nlt_alloc_link(); link = nl_cli_link_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -104,9 +105,9 @@ int main(int argc, char *argv[])
switch (c) { switch (c) {
case 'l': list_stat_names(); break; case 'l': list_stat_names(); break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'n': parse_name(link, optarg); break; case 'n': nl_cli_link_parse_name(link, optarg); break;
case 'i': parse_ifindex(link, optarg); break; case 'i': nl_cli_link_parse_ifindex(link, optarg); break;
} }
} }

View File

@ -6,11 +6,11 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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 <netlink-local.h>
#include "utils.h" #include <netlink/cli/utils.h>
static void print_usage(void) static void print_usage(void)
{ {

View File

@ -6,10 +6,10 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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" #define PROC_NETLINK "/proc/net/netlink"

View File

@ -6,12 +6,11 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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/route/link.h> #include <netlink/cli/link.h>
#include <netlink/route/addr.h>
static void obj_input(struct nl_object *obj, void *arg) static void obj_input(struct nl_object *obj, void *arg)
{ {
@ -61,7 +60,7 @@ int main(int argc, char *argv[])
{ RTNLGRP_NONE, NULL } { RTNLGRP_NONE, NULL }
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nl_socket_disable_seq_check(sock); nl_socket_disable_seq_check(sock);
nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); 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; return 2;
} }
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
for (idx = 1; argc > idx; idx++) { for (idx = 1; argc > idx; idx++) {
for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++) { for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++) {
if (!strcmp(argv[idx], known_groups[i].gr_name)) { if (!strcmp(argv[idx], known_groups[i].gr_name)) {
if ((err = nl_socket_add_membership(sock, known_groups[i].gr_id)) < 0) { 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; break;
@ -92,7 +92,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Warning: Unknown group: %s\n", argv[idx]); 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) { while (1) {
fd_set rfds; fd_set rfds;

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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; 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; int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
neigh = nlt_alloc_neigh(); neigh = nl_cli_neigh_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -84,11 +86,11 @@ int main(int argc, char *argv[])
case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL; break; case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL; break;
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'a': ok++; parse_dst(neigh, optarg); break; case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg); break;
case 'l': parse_lladdr(neigh, optarg); break; case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break;
case 'd': parse_dev(neigh, link_cache, optarg); break; case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break;
case ARG_STATE: parse_state(neigh, 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(); print_usage();
if ((err = rtnl_neigh_add(sock, neigh, nlflags)) < 0) 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) { if (!quiet) {
printf("Added "); printf("Added ");

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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; static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
struct nl_sock *sock; struct nl_sock *sock;
@ -46,11 +48,12 @@ static void delete_cb(struct nl_object *obj, void *arg)
}; };
int err; int err;
if (interactive && !nlt_confirm(obj, &params, default_yes)) if (interactive && !nl_cli_confirm(obj, &params, default_yes))
return; return;
if ((err = rtnl_neigh_delete(sock, neigh, 0)) < 0) 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) { if (!quiet) {
printf("Deleted "); printf("Deleted ");
@ -65,11 +68,11 @@ int main(int argc, char *argv[])
struct rtnl_neigh *neigh; struct rtnl_neigh *neigh;
struct nl_cache *link_cache, *neigh_cache; struct nl_cache *link_cache, *neigh_cache;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
neigh_cache = nlt_alloc_neigh_cache(sock); neigh_cache = nl_cli_neigh_alloc_cache(sock);
neigh = nlt_alloc_neigh(); neigh = nl_cli_neigh_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -101,12 +104,12 @@ int main(int argc, char *argv[])
case ARG_YES: default_yes = 1; break; case ARG_YES: default_yes = 1; break;
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'a': parse_dst(neigh, optarg); break; case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break;
case 'l': parse_lladdr(neigh, optarg); break; case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break;
case 'd': parse_dev(neigh, link_cache, optarg); break; case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break;
case ARG_FAMILY: parse_family(neigh, optarg); break; case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break;
case ARG_STATE: parse_state(neigh, optarg); break; case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break;
} }
} }

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -41,11 +43,11 @@ int main(int argc, char *argv[])
.dp_fd = stdout, .dp_fd = stdout,
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
neigh_cache = nlt_alloc_neigh_cache(sock); neigh_cache = nl_cli_neigh_alloc_cache(sock);
neigh = nlt_alloc_neigh(); neigh = nl_cli_neigh_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -70,14 +72,14 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'a': parse_dst(neigh, optarg); break; case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break;
case 'l': parse_lladdr(neigh, optarg); break; case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break;
case 'd': parse_dev(neigh, link_cache, optarg); break; case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break;
case ARG_FAMILY: parse_family(neigh, optarg); break; case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break;
case ARG_STATE: parse_state(neigh, optarg); break; case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break;
} }
} }

View File

@ -6,10 +6,11 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -33,10 +34,11 @@ int main(int argc, char *argv[])
.dp_fd = stdout, .dp_fd = stdout,
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
neightbl_cache = nlt_alloc_neightbl_cache(sock); neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table",
rtnl_neightbl_alloc_cache);
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -52,9 +54,9 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
} }
} }

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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; static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
struct nl_sock *sock; struct nl_sock *sock;
@ -45,11 +47,11 @@ static void delete_cb(struct nl_object *obj, void *arg)
}; };
int err; int err;
if (interactive && !nlt_confirm(obj, &params, default_yes)) if (interactive && !nl_cli_confirm(obj, &params, default_yes))
return; return;
if ((err = rtnl_qdisc_delete(sock, qdisc)) < 0) 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) { if (!quiet) {
printf("Deleted "); printf("Deleted ");
@ -64,11 +66,11 @@ int main(int argc, char *argv[])
struct rtnl_qdisc *qdisc; struct rtnl_qdisc *qdisc;
struct nl_cache *link_cache, *qdisc_cache; struct nl_cache *link_cache, *qdisc_cache;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
qdisc_cache = nlt_alloc_qdisc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
qdisc = nlt_alloc_qdisc(); qdisc = nl_cli_qdisc_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -97,11 +99,11 @@ int main(int argc, char *argv[])
case ARG_YES: default_yes = 1; break; case ARG_YES: default_yes = 1; break;
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'd': parse_dev(qdisc, link_cache, optarg); break; case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break;
case 'p': parse_parent(qdisc, optarg); break; case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break;
case 'H': parse_handle(qdisc, optarg); break; case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break;
case 'k': parse_kind(qdisc, optarg); break; case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break;
} }
} }

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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; static int quiet = 0;
@ -42,11 +44,11 @@ int main(int argc, char *argv[])
.dp_fd = stdout, .dp_fd = stdout,
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
qdisc_cache = nlt_alloc_qdisc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
qdisc = nlt_alloc_qdisc(); qdisc = nl_cli_qdisc_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -71,14 +73,14 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'd': parse_dev(qdisc, link_cache, optarg); break; case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break;
case 'p': parse_parent(qdisc, optarg); break; case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break;
case 'H': parse_handle(qdisc, optarg); break; case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break;
case 'k': parse_kind(qdisc, optarg); break; case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break;
} }
} }

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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 int quiet = 0;
static struct nl_cache *link_cache, *route_cache; static struct nl_cache *link_cache, *route_cache;
@ -57,11 +59,11 @@ int main(int argc, char *argv[])
}; };
int err = 1; int err = 1;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
route_cache = nlt_alloc_route_cache(sock, 0); route_cache = nl_cli_route_alloc_cache(sock, 0);
route = nlt_alloc_route(); route = nl_cli_route_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -102,24 +104,24 @@ int main(int argc, char *argv[])
switch (c) { switch (c) {
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'd': parse_dst(route, optarg); break; case 'd': nl_cli_route_parse_dst(route, optarg); break;
case 'n': parse_nexthop(route, optarg, link_cache); break; case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break;
case 't': parse_table(route, optarg); break; case 't': nl_cli_route_parse_table(route, optarg); break;
case ARG_FAMILY: parse_family(route, optarg); break; case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break;
case ARG_SRC: parse_src(route, optarg); break; case ARG_SRC: nl_cli_route_parse_src(route, optarg); break;
case ARG_IIF: parse_iif(route, optarg, link_cache); break; case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break;
case ARG_PREF_SRC: parse_pref_src(route, optarg); break; case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break;
case ARG_METRICS: parse_metric(route, optarg); break; case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break;
case ARG_PRIORITY: parse_prio(route, optarg); break; case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break;
case ARG_SCOPE: parse_scope(route, optarg); break; case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break;
case ARG_PROTOCOL: parse_protocol(route, optarg); break; case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break;
case ARG_TYPE: parse_type(route, optarg); break; case ARG_TYPE: nl_cli_route_parse_type(route, optarg); break;
} }
} }
if ((err = rtnl_route_add(sock, route, 0)) < 0) 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) { if (!quiet) {
printf("Added "); printf("Added ");

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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 interactive = 0, default_yes = 0, quiet = 0;
static int deleted = 0; static int deleted = 0;
@ -65,11 +67,11 @@ static void delete_cb(struct nl_object *obj, void *arg)
}; };
int err; int err;
if (interactive && !nlt_confirm(obj, &params, default_yes)) if (interactive && !nl_cli_confirm(obj, &params, default_yes))
return; return;
if ((err = rtnl_route_delete(sock, route, 0)) < 0) 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) { if (!quiet) {
printf("Deleted "); printf("Deleted ");
@ -85,11 +87,11 @@ int main(int argc, char *argv[])
struct rtnl_route *route; struct rtnl_route *route;
int nf = 0; int nf = 0;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
route_cache = nlt_alloc_route_cache(sock, 0); route_cache = nl_cli_route_alloc_cache(sock, 0);
route = nlt_alloc_route(); route = nl_cli_route_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -136,18 +138,18 @@ int main(int argc, char *argv[])
case 'q': quiet = 1; break; case 'q': quiet = 1; break;
case 'h': print_usage(); break; case 'h': print_usage(); break;
case 'v': print_version(); break; case 'v': print_version(); break;
case 'd': nf++; parse_dst(route, optarg); break; case 'd': nf++; nl_cli_route_parse_dst(route, optarg); break;
case 'n': nf++; parse_nexthop(route, optarg, link_cache); break; case 'n': nf++; nl_cli_route_parse_nexthop(route, optarg, link_cache); break;
case 't': nf++; parse_table(route, optarg); break; case 't': nf++; nl_cli_route_parse_table(route, optarg); break;
case ARG_FAMILY: nf++; parse_family(route, optarg); break; case ARG_FAMILY: nf++; nl_cli_route_parse_family(route, optarg); break;
case ARG_SRC: nf++; parse_src(route, optarg); break; case ARG_SRC: nf++; nl_cli_route_parse_src(route, optarg); break;
case ARG_IIF: nf++; parse_iif(route, optarg, link_cache); break; case ARG_IIF: nf++; nl_cli_route_parse_iif(route, optarg, link_cache); break;
case ARG_PREF_SRC: nf++; parse_pref_src(route, optarg); break; case ARG_PREF_SRC: nf++; nl_cli_route_parse_pref_src(route, optarg); break;
case ARG_METRICS: nf++; parse_metric(route, optarg); break; case ARG_METRICS: nf++; nl_cli_route_parse_metric(route, optarg); break;
case ARG_PRIORITY: nf++; parse_prio(route, optarg); break; case ARG_PRIORITY: nf++; nl_cli_route_parse_prio(route, optarg); break;
case ARG_SCOPE: nf++; parse_scope(route, optarg); break; case ARG_SCOPE: nf++; nl_cli_route_parse_scope(route, optarg); break;
case ARG_PROTOCOL: nf++; parse_protocol(route, optarg); break; case ARG_PROTOCOL: nf++; nl_cli_route_parse_protocol(route, optarg); break;
case ARG_TYPE: nf++; parse_type(route, optarg); break; case ARG_TYPE: nf++; nl_cli_route_parse_type(route, optarg); break;
} }
} }

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -33,7 +35,7 @@ static int cb(struct nl_msg *msg, void *arg)
int err; int err;
if ((err = nl_msg_parse(msg, &parse_cb, NULL)) < 0) 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; return 0;
} }
@ -48,12 +50,12 @@ int main(int argc, char *argv[])
if (argc < 2 || !strcmp(argv[1], "-h")) if (argc < 2 || !strcmp(argv[1], "-h"))
print_usage(); print_usage();
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
route_cache = nlt_alloc_route_cache(sock, 0); 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; struct nl_msg *m;
@ -69,12 +71,12 @@ int main(int argc, char *argv[])
err = nl_send_auto_complete(sock, m); err = nl_send_auto_complete(sock, m);
nlmsg_free(m); nlmsg_free(m);
if (err < 0) 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); nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, cb, NULL);
if (nl_recvmsgs_default(sock) < 0) 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, &params); //nl_cache_dump(route_cache, &params);

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -56,10 +58,10 @@ int main(int argc, char *argv[])
}; };
int print_cache = 0; int print_cache = 0;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
route = nlt_alloc_route(); route = nl_cli_route_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -100,25 +102,25 @@ int main(int argc, char *argv[])
switch (c) { switch (c) {
case 'c': print_cache = 1; break; 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case 'd': parse_dst(route, optarg); break; case 'd': nl_cli_route_parse_dst(route, optarg); break;
case 'n': parse_nexthop(route, optarg, link_cache); break; case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break;
case 't': parse_table(route, optarg); break; case 't': nl_cli_route_parse_table(route, optarg); break;
case ARG_FAMILY: parse_family(route, optarg); break; case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break;
case ARG_SRC: parse_src(route, optarg); break; case ARG_SRC: nl_cli_route_parse_src(route, optarg); break;
case ARG_IIF: parse_iif(route, optarg, link_cache); break; case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break;
case ARG_PREF_SRC: parse_pref_src(route, optarg); break; case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break;
case ARG_METRICS: parse_metric(route, optarg); break; case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break;
case ARG_PRIORITY: parse_prio(route, optarg); break; case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break;
case ARG_SCOPE: parse_scope(route, optarg); break; case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break;
case ARG_PROTOCOL: parse_protocol(route, optarg); break; case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break;
case ARG_TYPE: parse_type(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); print_cache ? ROUTE_CACHE_CONTENT : 0);
nl_cache_dump_filter(route_cache, &params, OBJ_CAST(route)); nl_cache_dump_filter(route_cache, &params, OBJ_CAST(route));

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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) static void print_usage(void)
{ {
@ -38,11 +40,11 @@ int main(int argc, char *argv[])
.dp_type = NL_DUMP_LINE, .dp_type = NL_DUMP_LINE,
}; };
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
rule_cache = nlt_alloc_rule_cache(sock); rule_cache = nl_cli_rule_alloc_cache(sock);
rule = nlt_alloc_rule(); rule = nl_cli_rule_alloc();
for (;;) { for (;;) {
int c, optidx = 0; int c, optidx = 0;
@ -62,10 +64,10 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
case ARG_FAMILY: parse_family(rule, optarg); break; case ARG_FAMILY: nl_cli_rule_parse_family(rule, optarg); break;
} }
} }

View File

@ -6,10 +6,12 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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> #include <linux/pkt_sched.h>
static struct nl_sock *sock; static struct nl_sock *sock;
@ -114,10 +116,10 @@ int main(int argc, char *argv[])
{ {
struct nl_cache *link_cache; struct nl_cache *link_cache;
sock = nlt_alloc_socket(); sock = nl_cli_alloc_socket();
nlt_connect(sock, NETLINK_ROUTE); nl_cli_connect(sock, NETLINK_ROUTE);
link_cache = nlt_alloc_link_cache(sock); link_cache = nl_cli_link_alloc_cache(sock);
qdisc_cache = nlt_alloc_qdisc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
params.dp_fd = stdout; params.dp_fd = stdout;
@ -135,9 +137,9 @@ int main(int argc, char *argv[])
break; break;
switch (c) { 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 'h': print_usage(); break;
case 'v': nlt_print_version(); break; case 'v': nl_cli_print_version(); break;
} }
} }

View File

@ -6,10 +6,10 @@
* License as published by the Free Software Foundation version 2.1 * License as published by the Free Software Foundation version 2.1
* of the License. * 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[]) int main(int argc, char *argv[])
{ {
@ -22,10 +22,10 @@ int main(int argc, char *argv[])
return -1; 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)); err = nl_addr_resolve(a, host, sizeof(host));
if (err != 0) 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)); argv[1], nl_geterror(err));
printf("%s\n", host); printf("%s\n", host);

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}

View File

@ -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