From patchwork Tue Jan 4 06:24:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Sing X-Patchwork-Id: 77390 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 393F6B710A for ; Tue, 4 Jan 2011 17:27:48 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751174Ab1ADGYt (ORCPT ); Tue, 4 Jan 2011 01:24:49 -0500 Received: from smtp-out.google.com ([216.239.44.51]:50973 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750886Ab1ADGYs (ORCPT ); Tue, 4 Jan 2011 01:24:48 -0500 Received: from hpaq1.eem.corp.google.com (hpaq1.eem.corp.google.com [172.25.149.1]) by smtp-out.google.com with ESMTP id p046Olrc015007 for ; Mon, 3 Jan 2011 22:24:47 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1294122288; bh=YH7XtOKrNsZHEf3nVeRSR16K4OE=; h=From:To:Cc:Subject:Date:Message-Id; b=NUkROgp9IuEJVg6BoWbdq9w8DlWBjFCBm3eehUE5UxW7nSIeiJDnD1lhpJ33EuizE PlxABGtbx8ciNFKzPBY2w== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=from:to:cc:subject:date:message-id:x-mailer; b=jW81Ej+RuLNYIBLwzq90lRJZS1RVLx02fSMPc2sqPIaDKAvqmHoSEVjEdI7O2mxYk e2mtjOxxKX7VPFrtDeswA== Received: from jsing-t3500-linux.syd.corp.google.com (jsing-t3500-linux.syd.corp.google.com [172.23.124.32]) by hpaq1.eem.corp.google.com with ESMTP id p046OhId013986; Mon, 3 Jan 2011 22:24:44 -0800 From: Joel Sing To: netdev@vger.kernel.org Cc: Joel Sing Subject: [PATCH] ipv4/route.c: respect prefsrc for local routes Date: Tue, 4 Jan 2011 17:24:20 +1100 Message-Id: <1294122260-13245-1-git-send-email-jsing@google.com> X-Mailer: git-send-email 1.7.3.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The preferred source address is currently ignored for local routes, which results in all local connections having a src address that is the same as the local dst address. Fix this by respecting the preferred source address when it is provided for local routes. This bug can be demonstrated as follows: # ifconfig dummy0 192.168.0.1 # ip route show table local | grep local.*dummy0 local 192.168.0.1 dev dummy0 proto kernel scope host src 192.168.0.1 # ip route change table local local 192.168.0.1 dev dummy0 \ proto kernel scope host src 127.0.0.1 # ip route show table local | grep local.*dummy0 local 192.168.0.1 dev dummy0 proto kernel scope host src 127.0.0.1 We now establish a local connection and verify the source IP address selection: # nc -l 192.168.0.1 3128 & # nc 192.168.0.1 3128 & # netstat -ant | grep 192.168.0.1:3128.*EST tcp 0 0 192.168.0.1:3128 192.168.0.1:33228 ESTABLISHED tcp 0 0 192.168.0.1:33228 192.168.0.1:3128 ESTABLISHED Signed-off-by: Joel Sing --- net/ipv4/route.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index df948b0..93bfd95 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2649,8 +2649,12 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp, } if (res.type == RTN_LOCAL) { - if (!fl.fl4_src) - fl.fl4_src = fl.fl4_dst; + if (!fl.fl4_src) { + if (res.fi->fib_prefsrc) + fl.fl4_src = res.fi->fib_prefsrc; + else + fl.fl4_src = fl.fl4_dst; + } dev_out = net->loopback_dev; fl.oif = dev_out->ifindex; res.fi = NULL;