#include "rt_names.h"
#include "utils.h"
+extern struct rtnl_handle rth;
+
static void usage(void) __attribute__((noreturn));
static void usage(void)
static int iprule_list(int argc, char **argv)
{
- struct rtnl_handle rth;
int af = preferred_family;
if (af == AF_UNSPEC)
return -1;
}
- if (rtnl_open(&rth, 0) < 0)
- return 1;
-
if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
perror("Cannot send dump request");
return 1;
static int iprule_modify(int cmd, int argc, char **argv)
{
int table_ok = 0;
- struct rtnl_handle rth;
struct {
struct nlmsghdr n;
struct rtmsg r;
addattr32(&req.n, sizeof(req), RTA_FLOW, realm);
} else if (matches(*argv, "table") == 0 ||
strcmp(*argv, "lookup") == 0) {
- int tid;
+ __u32 tid;
NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv))
invarg("invalid table ID\n", *argv);
if (!table_ok && cmd == RTM_NEWRULE)
req.r.rtm_table = RT_TABLE_MAIN;
- if (rtnl_open(&rth, 0) < 0)
- return 1;
-
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
return 2;
static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
- struct rtnl_handle rth;
+ struct rtnl_handle rth2;
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr * tb[RTA_MAX+1];
n->nlmsg_type = RTM_DELRULE;
n->nlmsg_flags = NLM_F_REQUEST;
- if (rtnl_open(&rth, 0) < 0)
+ if (rtnl_open(&rth2, 0) < 0)
return -1;
- if (rtnl_talk(&rth, n, 0, 0, NULL, NULL, NULL) < 0)
+ if (rtnl_talk(&rth2, n, 0, 0, NULL, NULL, NULL) < 0)
return -2;
+
+ rtnl_close(&rth2);
}
return 0;
static int iprule_flush(int argc, char **argv)
{
- struct rtnl_handle rth;
int af = preferred_family;
if (af == AF_UNSPEC)
af = AF_INET;
if (argc > 0) {
- fprintf(stderr, "\"ip rule flush\" need not any arguments.\n");
+ fprintf(stderr, "\"ip rule flush\" does not allow arguments\n");
return -1;
}
- if (rtnl_open(&rth, 0) < 0)
- return 1;
-
if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
perror("Cannot send dump request");
return 1;