From patchwork Thu Dec 13 11:21:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: duanjiong X-Patchwork-Id: 205806 X-Patchwork-Delegate: davem@davemloft.net 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 676AD2C008E for ; Thu, 13 Dec 2012 22:21:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754660Ab2LMLVn (ORCPT ); Thu, 13 Dec 2012 06:21:43 -0500 Received: from mail-da0-f46.google.com ([209.85.210.46]:49497 "EHLO mail-da0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753854Ab2LMLVm (ORCPT ); Thu, 13 Dec 2012 06:21:42 -0500 Received: by mail-da0-f46.google.com with SMTP id p5so779015dak.19 for ; Thu, 13 Dec 2012 03:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=UKRXDyNZwBziA+NqISQypsPDPX9wgbrNty7LMkiX0/E=; b=sqTQA0sWTbqwDeSFkwWcyh5lPs6/mmyXABw0nXyilMlcnmvkHduSFgn5Zp31NL8csw 1NmXrYPT/yceMQhPS6AgAWPWodFI+SzqV9aq8S4gW7a2CTB6lpnqEXsSnKXeTshOl59n arFwkbvEPprDq4qpF5NYMwnwDMRF8CVnPO86gj3qJgpgK33ACtkXT7aOueTEvMfLL3YO M5BmBAU1zaTB/FkmmwKs6/np7EzxeBF7g+qK2Uzfi+z9SeFJW19xGMxgYSB/coCuXIW3 C6bSfq7ChVMgmeDDRHlLkSwR6LE8g9TMrO1Qspz8GGMwJ9MBaTqG5nMgxk9lJfZmWYg/ DFtw== Received: by 10.66.78.100 with SMTP id a4mr5532780pax.4.1355397701650; Thu, 13 Dec 2012 03:21:41 -0800 (PST) Received: from [192.168.1.100] ([223.65.143.4]) by mx.google.com with ESMTPS id j8sm1100404paz.30.2012.12.13.03.21.38 (version=SSLv3 cipher=OTHER); Thu, 13 Dec 2012 03:21:40 -0800 (PST) Message-ID: <50C9BA41.1010507@gmail.com> Date: Thu, 13 Dec 2012 19:21:37 +0800 From: Duan Jiong User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: davem@davemloft.net CC: Steffen Klassert , netdev@vger.kernel.org Subject: [PATCH v2] ipv6: Change skb->data before using icmpv6_notify() to propagate redirect Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In function ndisc_redirect_rcv(), the skb->data points to the transport header, but function icmpv6_notify() need the skb->data points to the inner IP packet. So before using icmpv6_notify() to propagate redirect, change skb->data to point the inner IP packet that triggered the sending of the Redirect, and introduce struct rd_msg to make it easy. Many thanks to Steffen Klassert. Signed-off-by: Duan Jiong --- include/net/ndisc.h | 7 +++++++ net/ipv6/ndisc.c | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/include/net/ndisc.h b/include/net/ndisc.h index 980d263..6b305d7 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -78,6 +78,13 @@ struct ra_msg { __be32 retrans_timer; }; +struct rd_msg { + struct icmp6hdr icmph; + struct in6_addr target; + struct in6_addr dest; + __u8 opt[0]; +}; + struct nd_opt_hdr { __u8 nd_opt_type; __u8 nd_opt_len; diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 2edce30..03deabc 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1333,6 +1333,12 @@ out: static void ndisc_redirect_rcv(struct sk_buff *skb) { + u8 *hdr; + struct ndisc_options ndopts; + struct rd_msg *msg = (struct rd_msg *)skb_transport_header(skb); + u32 ndoptlen = skb->tail - (skb->transport_header + + offsetof(struct rd_msg, opt)); + #ifdef CONFIG_IPV6_NDISC_NODETYPE switch (skb->ndisc_nodetype) { case NDISC_NODETYPE_HOST: @@ -1349,6 +1355,22 @@ static void ndisc_redirect_rcv(struct sk_buff *skb) return; } + if (!ndisc_parse_options(msg->opt, ndoptlen, &ndopts)) { + ND_PRINTK(2, warn, + "Redirect: invalid ND options\n"); + return; + } + + if (!ndopts.nd_opts_rh) { + return; + } + + hdr = (u8 *)ndopts.nd_opts_rh; + hdr += 8; + if(!pskb_pull(skb, hdr - skb_transport_header(skb))) { + return; + } + icmpv6_notify(skb, NDISC_REDIRECT, 0, 0); }