Commit 3b6cdf94 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki

[XFRM] IPV6: Use distribution counting sort for xfrm_state/xfrm_tmpl chain.

Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
parent 92f1fecb
...@@ -49,125 +49,102 @@ __xfrm6_init_tempsel(struct xfrm_state *x, struct flowi *fl, ...@@ -49,125 +49,102 @@ __xfrm6_init_tempsel(struct xfrm_state *x, struct flowi *fl,
x->props.family = AF_INET6; x->props.family = AF_INET6;
} }
/* distribution counting sort function for xfrm_state and xfrm_tmpl */
static int static int
__xfrm6_state_sort(struct xfrm_state **dst, struct xfrm_state **src, int n) __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass)
{ {
int i; int i;
int j = 0; int class[XFRM_MAX_DEPTH];
int count[maxclass];
/* Rule 1: select IPsec transport except AH */ memset(count, 0, sizeof(count));
for (i = 0; i < n; i++) {
if (src[i]->props.mode == XFRM_MODE_TRANSPORT &&
src[i]->id.proto != IPPROTO_AH) {
dst[j++] = src[i];
src[i] = NULL;
}
}
if (j == n)
goto end;
/* Rule 2: select MIPv6 RO or inbound trigger */
#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (src[i] && int c;
(src[i]->props.mode == XFRM_MODE_ROUTEOPTIMIZATION || class[i] = c = cmp(src[i]);
src[i]->props.mode == XFRM_MODE_IN_TRIGGER)) { count[c]++;
dst[j++] = src[i];
src[i] = NULL;
}
} }
if (j == n)
goto end;
#endif
/* Rule 3: select IPsec transport AH */ for (i = 2; i < maxclass; i++)
for (i = 0; i < n; i++) { count[i] += count[i - 1];
if (src[i] &&
src[i]->props.mode == XFRM_MODE_TRANSPORT &&
src[i]->id.proto == IPPROTO_AH) {
dst[j++] = src[i];
src[i] = NULL;
}
}
if (j == n)
goto end;
/* Rule 4: select IPsec tunnel */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (src[i] && dst[count[class[i] - 1]++] = src[i];
(src[i]->props.mode == XFRM_MODE_TUNNEL || src[i] = 0;
src[i]->props.mode == XFRM_MODE_BEET)) {
dst[j++] = src[i];
src[i] = NULL;
}
} }
if (likely(j == n))
goto end;
/* Final rule */
for (i = 0; i < n; i++) {
if (src[i]) {
dst[j++] = src[i];
src[i] = NULL;
}
}
end:
return 0; return 0;
} }
static int /*
__xfrm6_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n) * Rule for xfrm_state:
*
* rule 1: select IPsec transport except AH
* rule 2: select MIPv6 RO or inbound trigger
* rule 3: select IPsec transport AH
* rule 4: select IPsec tunnel
* rule 5: others
*/
static int __xfrm6_state_sort_cmp(void *p)
{ {
int i; struct xfrm_state *v = p;
int j = 0;
switch (v->props.mode) {
/* Rule 1: select IPsec transport */ case XFRM_MODE_TRANSPORT:
for (i = 0; i < n; i++) { if (v->id.proto != IPPROTO_AH)
if (src[i]->mode == XFRM_MODE_TRANSPORT) { return 1;
dst[j++] = src[i]; else
src[i] = NULL; return 3;
}
}
if (j == n)
goto end;
/* Rule 2: select MIPv6 RO or inbound trigger */
#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
for (i = 0; i < n; i++) { case XFRM_MODE_ROUTEOPTIMIZATION:
if (src[i] && case XFRM_MODE_IN_TRIGGER:
(src[i]->mode == XFRM_MODE_ROUTEOPTIMIZATION || return 2;
src[i]->mode == XFRM_MODE_IN_TRIGGER)) {
dst[j++] = src[i];
src[i] = NULL;
}
}
if (j == n)
goto end;
#endif #endif
case XFRM_MODE_TUNNEL:
/* Rule 3: select IPsec tunnel */ case XFRM_MODE_BEET:
for (i = 0; i < n; i++) { return 4;
if (src[i] &&
(src[i]->mode == XFRM_MODE_TUNNEL ||
src[i]->mode == XFRM_MODE_BEET)) {
dst[j++] = src[i];
src[i] = NULL;
}
} }
if (likely(j == n)) return 5;
goto end; }
/* Final rule */ static int
for (i = 0; i < n; i++) { __xfrm6_state_sort(struct xfrm_state **dst, struct xfrm_state **src, int n)
if (src[i]) { {
dst[j++] = src[i]; return __xfrm6_sort((void **)dst, (void **)src, n,
src[i] = NULL; __xfrm6_state_sort_cmp, 6);
} }
/*
* Rule for xfrm_tmpl:
*
* rule 1: select IPsec transport
* rule 2: select MIPv6 RO or inbound trigger
* rule 3: select IPsec tunnel
* rule 4: others
*/
static int __xfrm6_tmpl_sort_cmp(void *p)
{
struct xfrm_tmpl *v = p;
switch (v->mode) {
case XFRM_MODE_TRANSPORT:
return 1;
#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
case XFRM_MODE_ROUTEOPTIMIZATION:
case XFRM_MODE_IN_TRIGGER:
return 2;
#endif
case XFRM_MODE_TUNNEL:
case XFRM_MODE_BEET:
return 3;
} }
return 4;
}
end: static int
return 0; __xfrm6_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n)
{
return __xfrm6_sort((void **)dst, (void **)src, n,
__xfrm6_tmpl_sort_cmp, 5);
} }
int xfrm6_extract_header(struct sk_buff *skb) int xfrm6_extract_header(struct sk_buff *skb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment