From patchwork Sat Mar 5 00:58:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 85455 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 94F6C1007D7 for ; Sat, 5 Mar 2011 11:59:17 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760033Ab1CEA7F (ORCPT ); Fri, 4 Mar 2011 19:59:05 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:46571 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760039Ab1CEA7B (ORCPT ); Fri, 4 Mar 2011 19:59:01 -0500 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1Pvfpk-0002dk-Nk; Fri, 04 Mar 2011 17:59:00 -0700 Received: from c-98-207-153-68.hsd1.ca.comcast.net ([98.207.153.68] helo=fess.ebiederm.org) by in01.mta.xmission.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1Pvfpj-0000EC-ML; Fri, 04 Mar 2011 17:59:00 -0700 Received: from fess.ebiederm.org (localhost [127.0.0.1]) by fess.ebiederm.org (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id p250wuTn019244; Fri, 4 Mar 2011 16:58:56 -0800 Received: (from eric@localhost) by fess.ebiederm.org (8.14.3/8.14.3/Submit) id p250wt91019242; Fri, 4 Mar 2011 16:58:55 -0800 From: ebiederm@xmission.com (Eric W. Biederman) To: "H. Peter Anvin" , CC: Joel Sing , David Miller Date: Fri, 04 Mar 2011 16:58:55 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=; ; ; mid=; ; ; hst=in01.mta.xmission.com; ; ; ip=98.207.153.68; ; ; frm=ebiederm@xmission.com; ; ; spf=neutral X-XM-AID: U2FsdGVkX18tKEZaalSHnadtm/agpEpQZHTVy9/TPUM= X-SA-Exim-Connect-IP: 98.207.153.68 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sa07.xmission.com X-Spam-Level: X-Spam-Status: No, score=-3.6 required=8.0 tests=ALL_TRUSTED,BAYES_00, DCC_CHECK_NEGATIVE, T_TM2_M_HEADER_IN_MSG, T_XMDrugObfuBody_08, UNTRUSTED_Relay autolearn=disabled version=3.3.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 T_TM2_M_HEADER_IN_MSG BODY: T_TM2_M_HEADER_IN_MSG * -3.0 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_XMDrugObfuBody_08 obfuscated drug references * 0.4 UNTRUSTED_Relay Comes from a non-trusted relay X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;"H. Peter Anvin" , X-Spam-Relay-Country: Subject: FYI: tftp-hpa breaks when used on secondary ip addresses X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Fri, 06 Aug 2010 16:31:04 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org tftp-hpa has code to test to see if the address it received a connection on is a local address. I don't have a clue why tftp-hpa doesn't trust the kernel but the code looks like: static int address_is_local(const struct sockaddr_in *addr) { struct sokcaddr sa; int sockfd = -1; sockfd = socket(AF_INET, SOCK_DGRAM, 0); connect(sockfd, (struct sockaddr *)&addr, sizeof(*addr)); getsockname(sockfd, (struct sockaddr *)&sa, sizeof(sa)); return sa.sin_addr.s_addr == addr->sin_addr.s_addr; } Which if fails now if you happen to be running tftp-hpa on a secondary ip address on the same subnet as your first ip. Because pref_source in the routing table points at the first ip. The change in kernel behavior appears to be from the commit below to honor the preferred source address in local connections. This all seems very fuzzy to me and mostly this appears to be a bug in tftp-hpa but since I tracked it down I figured I would let everyone know what happened. Eric commit 9fc3bbb4a752f108cf096d96640f3b548bbbce6c Author: Joel Sing Date: Mon Jan 3 20:24:20 2011 +0000 ipv4/route.c: respect prefsrc for local routes 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 Signed-off-by: David S. Miller res.fi = NULL; --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;