From patchwork Tue Feb 23 13:15:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jamal X-Patchwork-Id: 46060 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 D0C00B7D0C for ; Wed, 24 Feb 2010 00:15:27 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752407Ab0BWNPW (ORCPT ); Tue, 23 Feb 2010 08:15:22 -0500 Received: from mail-pw0-f46.google.com ([209.85.160.46]:61657 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751959Ab0BWNPV (ORCPT ); Tue, 23 Feb 2010 08:15:21 -0500 Received: by pwj8 with SMTP id 8so3774506pwj.19 for ; Tue, 23 Feb 2010 05:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=HSGd6G5MuIJgofJH0+f/VWam3Wu0vpXmKmwZDItKaOc=; b=JBT83dnbIY8d7g2N1V6wAQ017t3tkhsrygZGWG8WyVAdyv+4fG6Y7Qw1v1s3uyzt0J Zvv/VybqcjPmcg5PRslBp8EIQPo87PV9ieAqM5hoLBZTy7fDHW6ZE1HMdAqN4olLQqfX jwRUTrL9g2v4AVvZFzZoLNCMZiAmy8a8MQ8QU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=juxJpoK7vTUPXStHGxbRulVUlt0n5Apv6KEyfFOheuxoGERUEzRjBWDPnepG52Riyt VqYGEEs0kf+xj0AKM4KlrEkD0XCbqI7Sfa19RjL1QIY2wODVWuRY/hXAog65f14qJ2Cx 1YyxewmceUOLZAqZoEeFJByZKYDEtZ9uHODnA= Received: by 10.114.6.7 with SMTP id 7mr2477021waf.90.1266930920759; Tue, 23 Feb 2010 05:15:20 -0800 (PST) Received: from localhost.localdomain (CPE0030ab124d2f-CM001bd7a7f1a0.cpe.net.cable.rogers.com [99.240.66.42]) by mx.google.com with ESMTPS id 21sm783039pwi.1.2010.02.23.05.15.18 (version=SSLv3 cipher=RC4-MD5); Tue, 23 Feb 2010 05:15:20 -0800 (PST) From: jamal To: shemminger@vyatta.com Cc: netdev@vger.kernel.org, Jamal Hadi Salim Subject: [iproute2 PATCH 1/3] xfrm: Introduce xfrm by mark Date: Tue, 23 Feb 2010 08:15:10 -0500 Message-Id: <1266930912-14640-1-git-send-email-hadi@cyberus.ca> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim This patch carries basic infrastructure. You need to make sure that the proper include/linux/xfrm.h is included for it to compile. Example: --- output: src 192.168.2.100 dst 192.168.1.10 proto esp spi 0x00000301 reqid 0 mode tunnel replay-window 0 mark 7/0xffffffff auth hmac(md5) 0x96358c90783bbfa3d7b196ceabe0536b enc cbc(des3_ede) 0xf6ddb555acfd9d77b03ea3843f2653255afe8eb5573965df sel src 0.0.0.0/0 dst 0.0.0.0/0 dir fwd ptype main \ tmpl src 192.168.2.100 dst 192.168.1.100 \ proto esp mode tunnel mark 7 mask 0xffffffff output: src 172.16.2.0/24 dst 172.16.1.0/24 dir fwd priority 0 ptype main mark 7/0xffffffff tmpl src 192.168.2.100 dst 192.168.1.100 proto esp reqid 0 mode tunnel ----- A mark-configured SAD/SPD entry will use the mark as part of the lookup key (both in data and control path). Example: --- output: RTNETLINK answers: No such file or directory output: src 172.16.2.0/24 dst 172.16.1.0/24 dir fwd priority 0 ptype main mark 7/0xffffffff tmpl src 192.168.2.100 dst 192.168.1.100 proto esp reqid 0 mode tunnel --- Signed-off-by: Jamal Hadi Salim --- ip/ipxfrm.c | 40 ++++++++++++++++++++++++++++++++++++++++ ip/xfrm.h | 1 + 2 files changed, 41 insertions(+), 0 deletions(-) diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c index 7dc36f3..78e1926 100644 --- a/ip/ipxfrm.c +++ b/ip/ipxfrm.c @@ -629,9 +629,48 @@ static void xfrm_tmpl_print(struct xfrm_user_tmpl *tmpls, int len, } } +int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp) +{ + int argc = *argcp; + char **argv = *argvp; + + NEXT_ARG(); + if (get_u32(&mark->v, *argv, 0)) { + invarg("Illegal \"mark\" value\n", *argv); + } + if (argc > 1) + NEXT_ARG(); + else { /* last entry on parse line */ + mark->m = 0xffffffff; + goto done; + } + + if (strcmp(*argv, "mask") == 0) { + NEXT_ARG(); + if (get_u32(&mark->m, *argv, 0)) { + invarg("Illegal \"mark\" mask\n", *argv); + } + } else { + mark->m = 0xffffffff; + PREV_ARG(); + } + +done: + *argcp = argc; + *argvp = argv; + + return 0; +} + void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, FILE *fp, const char *prefix) { + if (tb[XFRMA_MARK]) { + struct rtattr *rta = tb[XFRMA_MARK]; + struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta); + fprintf(fp, "\tmark %d/0x%x\n", m->v, m->m); + } + if (tb[XFRMA_ALG_AUTH]) { struct rtattr *rta = tb[XFRMA_ALG_AUTH]; xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta), @@ -740,6 +779,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, fprintf(fp, "%s", strxf_time(lastused)); fprintf(fp, "%s", _SL_); } + } static int xfrm_selector_iszero(struct xfrm_selector *s) diff --git a/ip/xfrm.h b/ip/xfrm.h index 104fb20..d3ca5c5 100644 --- a/ip/xfrm.h +++ b/ip/xfrm.h @@ -121,6 +121,7 @@ int xfrm_xfrmproto_is_ipsec(__u8 proto); int xfrm_xfrmproto_is_ro(__u8 proto); int xfrm_xfrmproto_getbyname(char *name); int xfrm_algotype_getbyname(char *name); +int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp); const char *strxf_xfrmproto(__u8 proto); const char *strxf_algotype(int type); const char *strxf_mask8(__u8 mask);