From patchwork Mon Oct 12 21:05:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jamal X-Patchwork-Id: 35817 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.176.167]) by ozlabs.org (Postfix) with ESMTP id 81C93B7B74 for ; Tue, 13 Oct 2009 08:14:33 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758181AbZJLVJh (ORCPT ); Mon, 12 Oct 2009 17:09:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758161AbZJLVJh (ORCPT ); Mon, 12 Oct 2009 17:09:37 -0400 Received: from mail-qy0-f186.google.com ([209.85.221.186]:46622 "EHLO mail-qy0-f186.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757991AbZJLVJg (ORCPT ); Mon, 12 Oct 2009 17:09:36 -0400 Received: by qyk16 with SMTP id 16so2676713qyk.15 for ; Mon, 12 Oct 2009 14:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:subject:from:reply-to :to:cc:content-type:date:message-id:mime-version:x-mailer; bh=g2hD0nDkg+EAVGu/jpPLBaz4xpnIgV2dPV3Fw8NwKww=; b=I41ET8tc0k6NbQtdV5SFiXFCFgP8BLU+Ud48lgekZ8Qr6mKWLRDt+/tPBDBc7Frz6+ mKgJQNopCkW2HWJQ9d9MsrcWd3M3rB2VFCSV1V4vb8WYpBn9ctiWWl3DexL4Y7mR6M5I wQ2u0gDrYTtkFsNK6rN+SgLU7IjYeEBWysC5g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:from:reply-to:to:cc:content-type:date:message-id :mime-version:x-mailer; b=fj6Y9h4NEUCRwfSa6Dv6NMR5lscvFJjmW3+zhbhki46W1+nSsdgLNs+sthYQU9qBnh x9YJoXUzPeIXNj/sEN9bxFIMWaTOrl/g8faxUHVkKx2WI9hwWXJpKnvQ0aKntard9M5T 9sQE2LwFAKEm+zB3epul+UKvZ3kZv8gIJ56bw= Received: by 10.224.72.12 with SMTP id k12mr5164183qaj.62.1255381738875; Mon, 12 Oct 2009 14:08:58 -0700 (PDT) Received: from ?10.0.0.31? (CPE0030ab124d2f-CM001bd7a7f1a0.cpe.net.cable.rogers.com [99.240.75.67]) by mx.google.com with ESMTPS id 7sm1271590qwf.8.2009.10.12.14.08.57 (version=SSLv3 cipher=RC4-MD5); Mon, 12 Oct 2009 14:08:58 -0700 (PDT) Subject: [PATCH] iputils: ping by mark From: jamal Reply-To: hadi@cyberus.ca To: YOSHIFUJI Hideaki Cc: netdev@vger.kernel.org Date: Mon, 12 Oct 2009 17:05:58 -0400 Message-Id: <1255381558.5406.33.camel@dogo.mojatatu.com> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ping by mark, example to use firewall mark decimal 10 (which hopefully maps to something meaningful with policy routing): ping -m 10 10.0.0.1 cheers, jamal commit 7afb1e52ecc8bda3677f8b7db8433486936d473f Author: Jamal Hadi Salim Date: Mon Oct 12 16:59:27 2009 -0400 [PATCH] iputils: ping by mark This extends ping to send a packet out based on a given mark using -m option. Useful with policy routing to take different paths to same destination .. Signed-off-by: Jamal Hadi Salim diff --git a/ping.c b/ping.c index b67cff4..5c913e0 100644 --- a/ping.c +++ b/ping.c @@ -1216,7 +1216,7 @@ void usage(void) fprintf(stderr, "Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]\n" " [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]\n" -" [-M mtu discovery hint] [-S sndbuf]\n" +" [-M mtu discovery hint] [-m mark] [-S sndbuf]\n" " [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination\n"); exit(2); } diff --git a/ping_common.c b/ping_common.c index be36cbd..b1cc9fc 100644 --- a/ping_common.c +++ b/ping_common.c @@ -4,6 +4,7 @@ int options; +int mark; int sndbuf; int ttl; int rtt; @@ -141,6 +142,17 @@ void common_options(int ch) options |= F_INTERVAL; break; } + case 'm': + { + char *endp; + mark = (int)strtoul(optarg, &endp, 10); + if (mark < 0 || *endp != '\0') { + fprintf(stderr, "mark cannot be negative"); + exit(2); + } + options |= F_MARK; + break; + } case 'w': deadline = atoi(optarg); if (deadline < 0) { @@ -442,6 +454,15 @@ void setup(int icmp_sock) fprintf(stderr, "Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP\n"); } #endif + if (options & F_MARK) { + if (setsockopt(icmp_sock, SOL_SOCKET, SO_MARK, + &mark, sizeof(mark)) == -1) { + /* we probably dont wanna exit since old kernels + * dont support mark .. + */ + fprintf(stderr, "Warning: Failed to set mark %d\n", mark); + } + } /* Set some SNDTIMEO to prevent blocking forever * on sends, when device is too slow or stalls. Just put limit diff --git a/ping_common.h b/ping_common.h index 5b80118..466792e 100644 --- a/ping_common.h +++ b/ping_common.h @@ -60,6 +60,7 @@ extern int options; #define F_STRICTSOURCE 0x8000 #define F_NOLOOP 0x10000 #define F_TTL 0x20000 +#define F_MARK 0x40000 /* * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum @@ -118,9 +119,9 @@ case 'a': case 'U': case 'c': case 'd': \ case 'f': case 'i': case 'w': case 'l': \ case 'S': case 'n': case 'p': case 'q': \ case 'r': case 's': case 'v': case 'L': \ -case 't': case 'A': case 'W': case 'B': +case 't': case 'A': case 'W': case 'B': case 'm': -#define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:B" +#define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:Bm:" /*