From patchwork Wed Apr 15 12:00:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 461499 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 29C0D14009B for ; Wed, 15 Apr 2015 22:01:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756126AbbDOMA7 (ORCPT ); Wed, 15 Apr 2015 08:00:59 -0400 Received: from 33.106-14-84.ripe.coltfrance.com ([84.14.106.33]:44958 "EHLO proxy.6wind.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753981AbbDOMA5 (ORCPT ); Wed, 15 Apr 2015 08:00:57 -0400 Received: from schnaps.dev.6wind.com (unknown [10.16.0.249]) by proxy.6wind.com (Postfix) with ESMTPS id 57232281DC; Wed, 15 Apr 2015 14:00:55 +0200 (CEST) Received: from root by schnaps.dev.6wind.com with local (Exim 4.80) (envelope-from ) id 1YiM00-0006S8-9e; Wed, 15 Apr 2015 14:00:56 +0200 From: Nicolas Dichtel To: shemminger@vyatta.com Cc: netdev@vger.kernel.org, gregory.hoggarth@alliedtelesis.co.nz, Nicolas Dichtel Subject: [PATCH iproute2] ipxfrm: wrong nl msg sent on deleteall cmd Date: Wed, 15 Apr 2015 14:00:53 +0200 Message-Id: <1429099253-24739-1-git-send-email-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.2.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org XFRM netlink family is independent from the route netlink family. It's wrong to call rtnl_wilddump_request(), because it will add a 'struct ifinfomsg' into the header and the kernel will complain (at least for xfrm state): netlink: 24 bytes leftover after parsing attributes in process `ip'. Reported-by: Gregory Hoggarth Signed-off-by: Nicolas Dichtel --- ip/xfrm_policy.c | 24 ++++++++++++++++++++++-- ip/xfrm_state.c | 12 +++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c index 2337d35246fa..fd6d4890fa4e 100644 --- a/ip/xfrm_policy.c +++ b/ip/xfrm_policy.c @@ -847,13 +847,23 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) xb.rth = &rth; for (i = 0; ; i++) { + struct { + struct nlmsghdr n; + char buf[NLMSG_BUF_SIZE]; + } req = { + .n.nlmsg_len = NLMSG_HDRLEN, + .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .n.nlmsg_type = XFRM_MSG_GETPOLICY, + .n.nlmsg_seq = rth.dump = ++rth.seq, + }; + xb.offset = 0; xb.nlmsg_count = 0; if (show_stats > 1) fprintf(stderr, "Delete-all round = %d\n", i); - if (rtnl_wilddump_request(&rth, preferred_family, XFRM_MSG_GETPOLICY) < 0) { + if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); } @@ -879,7 +889,17 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) xb.nlmsg_count = 0; } } else { - if (rtnl_wilddump_request(&rth, preferred_family, XFRM_MSG_GETPOLICY) < 0) { + struct { + struct nlmsghdr n; + char buf[NLMSG_BUF_SIZE]; + } req = { + .n.nlmsg_len = NLMSG_HDRLEN, + .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .n.nlmsg_type = XFRM_MSG_GETPOLICY, + .n.nlmsg_seq = rth.dump = ++rth.seq, + }; + + if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c index 2ad3d8d37fbe..04af50b348e6 100644 --- a/ip/xfrm_state.c +++ b/ip/xfrm_state.c @@ -1148,13 +1148,23 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) xb.rth = &rth; for (i = 0; ; i++) { + struct { + struct nlmsghdr n; + char buf[NLMSG_BUF_SIZE]; + } req = { + .n.nlmsg_len = NLMSG_HDRLEN, + .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .n.nlmsg_type = XFRM_MSG_GETSA, + .n.nlmsg_seq = rth.dump = ++rth.seq, + }; + xb.offset = 0; xb.nlmsg_count = 0; if (show_stats > 1) fprintf(stderr, "Delete-all round = %d\n", i); - if (rtnl_wilddump_request(&rth, preferred_family, XFRM_MSG_GETSA) < 0) { + if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); }