diff mbox

[PATCHv3,net-next,6/7] {pktgen, xfrm} Introduce xfrm_state_lookup_byspi for pktgen

Message ID 1387094284-2901-7-git-send-email-fan.du@windriver.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

fan.du Dec. 15, 2013, 7:58 a.m. UTC
Introduce xfrm_state_lookup_byspi to find user specified by custom
from "pgset spi xxx". Using this scheme, any flow regardless its
saddr/daddr could be transform by SA specified with configurable
spi.

Signed-off-by: Fan Du <fan.du@windriver.com>
---
 include/net/xfrm.h    |    2 ++
 net/core/pktgen.c     |   22 +++++++++++++++-------
 net/xfrm/xfrm_state.c |   22 ++++++++++++++++++++++
 3 files changed, 39 insertions(+), 7 deletions(-)

Comments

Sergei Shtylyov Dec. 15, 2013, 8:42 p.m. UTC | #1
Hello.

On 12/15/2013 10:58 AM, Fan Du wrote:

> Introduce xfrm_state_lookup_byspi to find user specified by custom
> from "pgset spi xxx". Using this scheme, any flow regardless its
> saddr/daddr could be transform by SA specified with configurable
> spi.

> Signed-off-by: Fan Du <fan.du@windriver.com>
[...]

> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index eb70c23..ae268ff 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -2247,13 +2247,21 @@ static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
>   	struct xfrm_state *x = pkt_dev->flows[flow].x;
>   	struct pktgen_net *pn = net_generic(dev_net(pkt_dev->odev), pg_net_id);
>   	if (!x) {
> -		/*slow path: we dont already have xfrm_state*/
> -		x = xfrm_stateonly_find(pn->net, DUMMY_MARK,
> -					(xfrm_address_t *)&pkt_dev->cur_daddr,
> -					(xfrm_address_t *)&pkt_dev->cur_saddr,
> -					AF_INET,
> -					pkt_dev->ipsmode,
> -					pkt_dev->ipsproto, 0);
> +
> +		if (pkt_dev->spi) {
> +			/* We need as quick as possible to find the right SA
> +		 	 * Searching with minimum criteria to archieve this.
> +		 	 */
> +			x = xfrm_state_lookup_byspi(pn->net, htonl(pkt_dev->spi), AF_INET);
> +		} else {
> +			/*slow path: we dont already have xfrm_state*/

    Could you insert spaces after /* and before */, while at it?

WBR, Sergei

--
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
fan.du Dec. 16, 2013, 11:38 a.m. UTC | #2
On 2013年12月16日 04:42, Sergei Shtylyov wrote:
> Hello.
>
> On 12/15/2013 10:58 AM, Fan Du wrote:
>
>> Introduce xfrm_state_lookup_byspi to find user specified by custom
>> from "pgset spi xxx". Using this scheme, any flow regardless its
>> saddr/daddr could be transform by SA specified with configurable
>> spi.
>
>> Signed-off-by: Fan Du <fan.du@windriver.com>
> [...]
>
>> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
>> index eb70c23..ae268ff 100644
>> --- a/net/core/pktgen.c
>> +++ b/net/core/pktgen.c
>> @@ -2247,13 +2247,21 @@ static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
>> struct xfrm_state *x = pkt_dev->flows[flow].x;
>> struct pktgen_net *pn = net_generic(dev_net(pkt_dev->odev), pg_net_id);
>> if (!x) {
>> - /*slow path: we dont already have xfrm_state*/
>> - x = xfrm_stateonly_find(pn->net, DUMMY_MARK,
>> - (xfrm_address_t *)&pkt_dev->cur_daddr,
>> - (xfrm_address_t *)&pkt_dev->cur_saddr,
>> - AF_INET,
>> - pkt_dev->ipsmode,
>> - pkt_dev->ipsproto, 0);
>> +
>> + if (pkt_dev->spi) {
>> + /* We need as quick as possible to find the right SA
>> + * Searching with minimum criteria to archieve this.
>> + */
>> + x = xfrm_state_lookup_byspi(pn->net, htonl(pkt_dev->spi), AF_INET);
>> + } else {
>> + /*slow path: we dont already have xfrm_state*/
>
> Could you insert spaces after /* and before */, while at it?

Sure, I will incorporate this in v4.

Thanks for your attention.
diff mbox

Patch

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 6b82fdf..dfdfead 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1422,6 +1422,8 @@  struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark,
 				       xfrm_address_t *saddr,
 				       unsigned short family,
 				       u8 mode, u8 proto, u32 reqid);
+struct xfrm_state *xfrm_state_lookup_byspi(struct net *net, __be32 spi,
+					      unsigned short family);
 int xfrm_state_check_expire(struct xfrm_state *x);
 void xfrm_state_insert(struct xfrm_state *x);
 int xfrm_state_add(struct xfrm_state *x);
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index eb70c23..ae268ff 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2247,13 +2247,21 @@  static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
 	struct xfrm_state *x = pkt_dev->flows[flow].x;
 	struct pktgen_net *pn = net_generic(dev_net(pkt_dev->odev), pg_net_id);
 	if (!x) {
-		/*slow path: we dont already have xfrm_state*/
-		x = xfrm_stateonly_find(pn->net, DUMMY_MARK,
-					(xfrm_address_t *)&pkt_dev->cur_daddr,
-					(xfrm_address_t *)&pkt_dev->cur_saddr,
-					AF_INET,
-					pkt_dev->ipsmode,
-					pkt_dev->ipsproto, 0);
+
+		if (pkt_dev->spi) {
+			/* We need as quick as possible to find the right SA
+		 	 * Searching with minimum criteria to archieve this.
+		 	 */
+			x = xfrm_state_lookup_byspi(pn->net, htonl(pkt_dev->spi), AF_INET);
+		} else {
+			/*slow path: we dont already have xfrm_state*/
+			x = xfrm_stateonly_find(pn->net, DUMMY_MARK,
+						(xfrm_address_t *)&pkt_dev->cur_daddr,
+						(xfrm_address_t *)&pkt_dev->cur_saddr,
+						AF_INET,
+						pkt_dev->ipsmode,
+						pkt_dev->ipsproto, 0);
+		}
 		if (x) {
 			pkt_dev->flows[flow].x = x;
 			set_pkt_overhead(pkt_dev);
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index f7cb4a3..4a7800e 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -925,6 +925,28 @@  xfrm_stateonly_find(struct net *net, u32 mark,
 }
 EXPORT_SYMBOL(xfrm_stateonly_find);
 
+struct xfrm_state *xfrm_state_lookup_byspi(struct net *net, __be32 spi,
+					      unsigned short family)
+{
+	struct xfrm_state *x;
+	struct xfrm_state_walk *w;
+
+	spin_lock_bh(&xfrm_state_lock);
+	list_for_each_entry(w, &net->xfrm.state_all, all) {
+		x = container_of(w, struct xfrm_state, km);
+		if (x->props.family != family ||
+			x->id.spi != spi)
+			continue;
+ 
+		spin_unlock_bh(&xfrm_state_lock);
+		xfrm_state_hold(x);
+		return x;
+	}
+	spin_unlock_bh(&xfrm_state_lock);
+	return NULL;
+}
+EXPORT_SYMBOL(xfrm_state_lookup_byspi);
+
 static void __xfrm_state_insert(struct xfrm_state *x)
 {
 	struct net *net = xs_net(x);