diff options
| author | Mathias Krause <mathias.krause@secunet.com> | 2013-10-18 06:09:05 -0400 |
|---|---|---|
| committer | Steffen Klassert <steffen.klassert@secunet.com> | 2013-10-29 01:39:42 -0400 |
| commit | 1c5ad13f7c2b2afe30e43858d04fff979dc9d243 (patch) | |
| tree | fc68ea62c7d59c08b464ad47daea13db0adf1484 | |
| parent | 123b0d1ba0a98ef12550d82b79ccb8d89090f871 (diff) | |
net: esp{4,6}: get rid of struct esp_data
struct esp_data consists of a single pointer, vanishing the need for it
to be a structure. Fold the pointer into 'data' direcly, removing one
level of pointer indirection.
Signed-off-by: Mathias Krause <mathias.krause@secunet.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
| -rw-r--r-- | include/net/esp.h | 7 | ||||
| -rw-r--r-- | net/ipv4/esp4.c | 40 | ||||
| -rw-r--r-- | net/ipv6/esp6.c | 39 |
3 files changed, 28 insertions, 58 deletions
diff --git a/include/net/esp.h b/include/net/esp.h index 706b740d7057..c92213c38312 100644 --- a/include/net/esp.h +++ b/include/net/esp.h | |||
| @@ -3,13 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | #include <linux/skbuff.h> | 4 | #include <linux/skbuff.h> |
| 5 | 5 | ||
| 6 | struct crypto_aead; | ||
| 7 | |||
| 8 | struct esp_data { | ||
| 9 | /* Confidentiality & Integrity */ | ||
| 10 | struct crypto_aead *aead; | ||
| 11 | }; | ||
| 12 | |||
| 13 | void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len); | 6 | void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len); |
| 14 | 7 | ||
| 15 | struct ip_esp_hdr; | 8 | struct ip_esp_hdr; |
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 8b5386a6cb88..7785b28061ac 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c | |||
| @@ -121,7 +121,6 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) | |||
| 121 | struct aead_givcrypt_request *req; | 121 | struct aead_givcrypt_request *req; |
| 122 | struct scatterlist *sg; | 122 | struct scatterlist *sg; |
| 123 | struct scatterlist *asg; | 123 | struct scatterlist *asg; |
| 124 | struct esp_data *esp; | ||
| 125 | struct sk_buff *trailer; | 124 | struct sk_buff *trailer; |
| 126 | void *tmp; | 125 | void *tmp; |
| 127 | u8 *iv; | 126 | u8 *iv; |
| @@ -139,8 +138,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) | |||
| 139 | 138 | ||
| 140 | /* skb is pure payload to encrypt */ | 139 | /* skb is pure payload to encrypt */ |
| 141 | 140 | ||
| 142 | esp = x->data; | 141 | aead = x->data; |
| 143 | aead = esp->aead; | ||
| 144 | alen = crypto_aead_authsize(aead); | 142 | alen = crypto_aead_authsize(aead); |
| 145 | 143 | ||
| 146 | tfclen = 0; | 144 | tfclen = 0; |
| @@ -278,8 +276,7 @@ static int esp_input_done2(struct sk_buff *skb, int err) | |||
| 278 | { | 276 | { |
| 279 | const struct iphdr *iph; | 277 | const struct iphdr *iph; |
| 280 | struct xfrm_state *x = xfrm_input_state(skb); | 278 | struct xfrm_state *x = xfrm_input_state(skb); |
| 281 | struct esp_data *esp = x->data; | 279 | struct crypto_aead *aead = x->data; |
| 282 | struct crypto_aead *aead = esp->aead; | ||
| 283 | int alen = crypto_aead_authsize(aead); | 280 | int alen = crypto_aead_authsize(aead); |
| 284 | int hlen = sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead); | 281 | int hlen = sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead); |
| 285 | int elen = skb->len - hlen; | 282 | int elen = skb->len - hlen; |
| @@ -374,8 +371,7 @@ static void esp_input_done(struct crypto_async_request *base, int err) | |||
| 374 | static int esp_input(struct xfrm_state *x, struct sk_buff *skb) | 371 | static int esp_input(struct xfrm_state *x, struct sk_buff *skb) |
| 375 | { | 372 | { |
| 376 | struct ip_esp_hdr *esph; | 373 | struct ip_esp_hdr *esph; |
| 377 | struct esp_data *esp = x->data; | 374 | struct crypto_aead *aead = x->data; |
| 378 | struct crypto_aead *aead = esp->aead; | ||
| 379 | struct aead_request *req; | 375 | struct aead_request *req; |
| 380 | struct sk_buff *trailer; | 376 | struct sk_buff *trailer; |
| 381 | int elen = skb->len - sizeof(*esph) - crypto_aead_ivsize(aead); | 377 | int elen = skb->len - sizeof(*esph) - crypto_aead_ivsize(aead); |
| @@ -457,8 +453,8 @@ out: | |||
| 457 | 453 | ||
| 458 | static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) | 454 | static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) |
| 459 | { | 455 | { |
| 460 | struct esp_data *esp = x->data; | 456 | struct crypto_aead *aead = x->data; |
| 461 | u32 blksize = ALIGN(crypto_aead_blocksize(esp->aead), 4); | 457 | u32 blksize = ALIGN(crypto_aead_blocksize(aead), 4); |
| 462 | unsigned int net_adj; | 458 | unsigned int net_adj; |
| 463 | 459 | ||
| 464 | switch (x->props.mode) { | 460 | switch (x->props.mode) { |
| @@ -473,7 +469,7 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) | |||
| 473 | BUG(); | 469 | BUG(); |
| 474 | } | 470 | } |
| 475 | 471 | ||
| 476 | return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - | 472 | return ((mtu - x->props.header_len - crypto_aead_authsize(aead) - |
| 477 | net_adj) & ~(blksize - 1)) + net_adj - 2; | 473 | net_adj) & ~(blksize - 1)) + net_adj - 2; |
| 478 | } | 474 | } |
| 479 | 475 | ||
| @@ -508,18 +504,16 @@ static void esp4_err(struct sk_buff *skb, u32 info) | |||
| 508 | 504 | ||
| 509 | static void esp_destroy(struct xfrm_state *x) | 505 | static void esp_destroy(struct xfrm_state *x) |
| 510 | { | 506 | { |
| 511 | struct esp_data *esp = x->data; | 507 | struct crypto_aead *aead = x->data; |
| 512 | 508 | ||
| 513 | if (!esp) | 509 | if (!aead) |
| 514 | return; | 510 | return; |
| 515 | 511 | ||
| 516 | crypto_free_aead(esp->aead); | 512 | crypto_free_aead(aead); |
| 517 | kfree(esp); | ||
| 518 | } | 513 | } |
| 519 | 514 | ||
| 520 | static int esp_init_aead(struct xfrm_state *x) | 515 | static int esp_init_aead(struct xfrm_state *x) |
| 521 | { | 516 | { |
| 522 | struct esp_data *esp = x->data; | ||
| 523 | struct crypto_aead *aead; | 517 | struct crypto_aead *aead; |
| 524 | int err; | 518 | int err; |
| 525 | 519 | ||
| @@ -528,7 +522,7 @@ static int esp_init_aead(struct xfrm_state *x) | |||
| 528 | if (IS_ERR(aead)) | 522 | if (IS_ERR(aead)) |
| 529 | goto error; | 523 | goto error; |
| 530 | 524 | ||
| 531 | esp->aead = aead; | 525 | x->data = aead; |
| 532 | 526 | ||
| 533 | err = crypto_aead_setkey(aead, x->aead->alg_key, | 527 | err = crypto_aead_setkey(aead, x->aead->alg_key, |
| 534 | (x->aead->alg_key_len + 7) / 8); | 528 | (x->aead->alg_key_len + 7) / 8); |
| @@ -545,7 +539,6 @@ error: | |||
| 545 | 539 | ||
| 546 | static int esp_init_authenc(struct xfrm_state *x) | 540 | static int esp_init_authenc(struct xfrm_state *x) |
| 547 | { | 541 | { |
| 548 | struct esp_data *esp = x->data; | ||
| 549 | struct crypto_aead *aead; | 542 | struct crypto_aead *aead; |
| 550 | struct crypto_authenc_key_param *param; | 543 | struct crypto_authenc_key_param *param; |
| 551 | struct rtattr *rta; | 544 | struct rtattr *rta; |
| @@ -580,7 +573,7 @@ static int esp_init_authenc(struct xfrm_state *x) | |||
| 580 | if (IS_ERR(aead)) | 573 | if (IS_ERR(aead)) |
| 581 | goto error; | 574 | goto error; |
| 582 | 575 | ||
| 583 | esp->aead = aead; | 576 | x->data = aead; |
| 584 | 577 | ||
| 585 | keylen = (x->aalg ? (x->aalg->alg_key_len + 7) / 8 : 0) + | 578 | keylen = (x->aalg ? (x->aalg->alg_key_len + 7) / 8 : 0) + |
| 586 | (x->ealg->alg_key_len + 7) / 8 + RTA_SPACE(sizeof(*param)); | 579 | (x->ealg->alg_key_len + 7) / 8 + RTA_SPACE(sizeof(*param)); |
| @@ -635,16 +628,11 @@ error: | |||
| 635 | 628 | ||
| 636 | static int esp_init_state(struct xfrm_state *x) | 629 | static int esp_init_state(struct xfrm_state *x) |
| 637 | { | 630 | { |
| 638 | struct esp_data *esp; | ||
| 639 | struct crypto_aead *aead; | 631 | struct crypto_aead *aead; |
| 640 | u32 align; | 632 | u32 align; |
| 641 | int err; | 633 | int err; |
| 642 | 634 | ||
| 643 | esp = kzalloc(sizeof(*esp), GFP_KERNEL); | 635 | x->data = NULL; |
| 644 | if (esp == NULL) | ||
| 645 | return -ENOMEM; | ||
| 646 | |||
| 647 | x->data = esp; | ||
| 648 | 636 | ||
| 649 | if (x->aead) | 637 | if (x->aead) |
| 650 | err = esp_init_aead(x); | 638 | err = esp_init_aead(x); |
| @@ -654,7 +642,7 @@ static int esp_init_state(struct xfrm_state *x) | |||
| 654 | if (err) | 642 | if (err) |
| 655 | goto error; | 643 | goto error; |
| 656 | 644 | ||
| 657 | aead = esp->aead; | 645 | aead = x->data; |
| 658 | 646 | ||
| 659 | x->props.header_len = sizeof(struct ip_esp_hdr) + | 647 | x->props.header_len = sizeof(struct ip_esp_hdr) + |
| 660 | crypto_aead_ivsize(aead); | 648 | crypto_aead_ivsize(aead); |
| @@ -678,7 +666,7 @@ static int esp_init_state(struct xfrm_state *x) | |||
| 678 | } | 666 | } |
| 679 | 667 | ||
| 680 | align = ALIGN(crypto_aead_blocksize(aead), 4); | 668 | align = ALIGN(crypto_aead_blocksize(aead), 4); |
| 681 | x->props.trailer_len = align + 1 + crypto_aead_authsize(esp->aead); | 669 | x->props.trailer_len = align + 1 + crypto_aead_authsize(aead); |
| 682 | 670 | ||
| 683 | error: | 671 | error: |
| 684 | return err; | 672 | return err; |
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 0073cd096984..87eb79e65e49 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c | |||
| @@ -164,10 +164,9 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) | |||
| 164 | u8 *iv; | 164 | u8 *iv; |
| 165 | u8 *tail; | 165 | u8 *tail; |
| 166 | __be32 *seqhi; | 166 | __be32 |
