return true;
}
-int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
+int print_rule(struct nlmsghdr *n, void *arg)
{
FILE *fp = arg;
struct fib_rule_hdr *frh = NLMSG_DATA(n);
print_string(PRINT_FP, NULL, "to ", NULL);
print_color_string(PRINT_ANY, ifa_family_color(frh->family),
- "dst", "%s ", dst);
+ "dst", "%s", dst);
if (frh->dst_len != host_len)
print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len);
else
return 0;
}
-static int save_rule(const struct sockaddr_nl *who,
- struct nlmsghdr *n, void *arg)
+static int save_rule(struct nlmsghdr *n, void *arg)
{
int ret;
return ret == n->nlmsg_len ? 0 : ret;
}
-static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n,
- void *arg)
+static int flush_rule(struct nlmsghdr *n, void *arg)
{
struct rtnl_handle rth2;
struct fib_rule_hdr *frh = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[FRA_MAX+1];
+ int host_len = -1;
len -= NLMSG_LENGTH(sizeof(*frh));
if (len < 0)
parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len);
+ host_len = af_bit_len(frh->family);
+ if (!filter_nlmsg(n, tb, host_len))
+ return 0;
+
if (tb[FRA_PROTOCOL]) {
__u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]);
argc--; argv++;
}
- if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) {
+ if (rtnl_ruledump_req(&rth, af) < 0) {
perror("Cannot send dump request");
return 1;
}
return 0;
}
-static int restore_handler(const struct sockaddr_nl *nl,
- struct rtnl_ctrl_data *ctrl,
+static int restore_handler(struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg)
{
int ret;
};
if (cmd == RTM_NEWRULE) {
+ if (argc == 0) {
+ fprintf(stderr,
+ "\"ip rule add\" requires arguments.\n");
+ return -1;
+ }
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
req.frh.action = FR_ACT_TO_TBL;
}