From patchwork Mon Feb 22 21:32:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jamal X-Patchwork-Id: 46008 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 B6969B7CEE for ; Tue, 23 Feb 2010 08:33:32 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754757Ab0BVVda (ORCPT ); Mon, 22 Feb 2010 16:33:30 -0500 Received: from mail-bw0-f209.google.com ([209.85.218.209]:48471 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754668Ab0BVVd1 (ORCPT ); Mon, 22 Feb 2010 16:33:27 -0500 Received: by mail-bw0-f209.google.com with SMTP id 1so465337bwz.21 for ; Mon, 22 Feb 2010 13:33:27 -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=GWnCWGbRH/p6fcHJj9ZydtwFtwwqvO+oqHPccPby0ug=; b=xcKCRuil50VZ8JNrEtYoHsUWF9ZcTkaMhhRzpN/NTslBIU4GO8jxkVTpC6f/Trg0P/ FKuW2ycRAg9FtbU5O50e5Cki8mEMeki9hwh2OtSu2QKL06kTCy8Ft/FpB7BtbzH/tNMC o2WIlk5SwNUFEsf4xGugNoYhkKdOyOo81/Dwk= 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=xL4Vrqci6Lb5uGvkmhKVLxCzh9Ysc6EyAAiMvv+oS4Tk3KAjZGmVcvvo9qFFOM5z9j d1Yrxc4oAFDgfacHKlAxiVvsIseCFfhLp0sTsSkFDlALRTKymjH1g1epqdO5ZdZ4RY2b +3Nun4a+GGelHzRjrZDoE/8S/7Xbe7D4yjit8= Received: by 10.204.38.65 with SMTP id a1mr4660045bke.168.1266874406619; Mon, 22 Feb 2010 13:33:26 -0800 (PST) Received: from localhost.localdomain ([207.236.146.86]) by mx.google.com with ESMTPS id 16sm1377025bwz.5.2010.02.22.13.33.23 (version=SSLv3 cipher=RC4-MD5); Mon, 22 Feb 2010 13:33:25 -0800 (PST) From: jamal To: davem@davemloft.net Cc: timo.teras@iki.fi, kaber@trash.net, herbert@gondor.apana.org.au, netdev@vger.kernel.org, Jamal Hadi Salim Subject: [net-next-2.6 PATCH 5/7] xfrm: SP lookups with mark Date: Mon, 22 Feb 2010 16:32:58 -0500 Message-Id: <1266874380-29593-6-git-send-email-hadi@cyberus.ca> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <1266874380-29593-5-git-send-email-hadi@cyberus.ca> References: <1266874380-29593-1-git-send-email-hadi@cyberus.ca> <1266874380-29593-2-git-send-email-hadi@cyberus.ca> <1266874380-29593-3-git-send-email-hadi@cyberus.ca> <1266874380-29593-4-git-send-email-hadi@cyberus.ca> <1266874380-29593-5-git-send-email-hadi@cyberus.ca> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim Allow mark to be used when doing SP lookup Signed-off-by: Jamal Hadi Salim --- net/xfrm/xfrm_policy.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index e67d3ca..2a6e646 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -556,6 +556,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) struct hlist_head *chain; struct hlist_node *entry, *newpos; struct dst_entry *gc_list; + u32 mark = policy->mark.v & policy->mark.m; write_lock_bh(&xfrm_policy_lock); chain = policy_hash_bysel(net, &policy->selector, policy->family, dir); @@ -564,6 +565,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) hlist_for_each_entry(pol, entry, chain, bydst) { if (pol->type == policy->type && !selector_cmp(&pol->selector, &policy->selector) && + (mark & pol->mark.m) == pol->mark.v && xfrm_sec_ctx_match(pol->security, policy->security) && !WARN_ON(delpol)) { if (excl) { @@ -650,6 +652,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type, ret = NULL; hlist_for_each_entry(pol, entry, chain, bydst) { if (pol->type == type && + (mark & pol->mark.m) == pol->mark.v && !selector_cmp(sel, &pol->selector) && xfrm_sec_ctx_match(ctx, pol->security)) { xfrm_pol_hold(pol); @@ -692,7 +695,8 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type, chain = net->xfrm.policy_byidx + idx_hash(net, id); ret = NULL; hlist_for_each_entry(pol, entry, chain, byidx) { - if (pol->type == type && pol->index == id) { + if (pol->type == type && pol->index == id && + (mark & pol->mark.m) == pol->mark.v) { xfrm_pol_hold(pol); if (delete) { *err = security_xfrm_policy_delete( @@ -916,6 +920,7 @@ static int xfrm_policy_match(struct xfrm_policy *pol, struct flowi *fl, int match, ret = -ESRCH; if (pol->family != family || + (fl->mark & pol->mark.m) != pol->mark.v || pol->type != type) return ret; @@ -1040,6 +1045,10 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, struc int err = 0; if (match) { + if ((sk->sk_mark & pol->mark.m) != pol->mark.v) { + pol = NULL; + goto out; + } err = security_xfrm_policy_lookup(pol->security, fl->secid, policy_to_flow_dir(dir)); @@ -1052,6 +1061,7 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, struc } else pol = NULL; } +out: read_unlock_bh(&xfrm_policy_lock); return pol; }