diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2008-04-27 11:50:45 -0400 |
---|---|---|
committer | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2008-06-11 13:38:15 -0400 |
commit | 9e8b4ed8bb7d2f0f91dccf0abf648771d76e7a01 (patch) | |
tree | 44be0ec32b667eb5d4dbf3448a4b44cdfac5b9f1 /net/key | |
parent | 3de232554a91adc74e80dc15c304be806bd7e1f9 (diff) |
key: Introduce pfkey_sockaddr_len() for raw sockaddr{} length.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'net/key')
-rw-r--r-- | net/key/af_key.c | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/net/key/af_key.c b/net/key/af_key.c index 9bba7ac5fee0..02c8aba4239e 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c | |||
@@ -579,6 +579,19 @@ static uint8_t pfkey_proto_from_xfrm(uint8_t proto) | |||
579 | return (proto ? proto : IPSEC_PROTO_ANY); | 579 | return (proto ? proto : IPSEC_PROTO_ANY); |
580 | } | 580 | } |
581 | 581 | ||
582 | static inline int pfkey_sockaddr_len(sa_family_t family) | ||
583 | { | ||
584 | switch (family) { | ||
585 | case AF_INET: | ||
586 | return sizeof(struct sockaddr_in); | ||
587 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
588 | case AF_INET6: | ||
589 | return sizeof(struct sockaddr_in6); | ||
590 | #endif | ||
591 | } | ||
592 | return 0; | ||
593 | } | ||
594 | |||
582 | static int pfkey_sadb_addr2xfrm_addr(struct sadb_address *addr, | 595 | static int pfkey_sadb_addr2xfrm_addr(struct sadb_address *addr, |
583 | xfrm_address_t *xaddr) | 596 | xfrm_address_t *xaddr) |
584 | { | 597 | { |
@@ -642,20 +655,11 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct sadb_msg *hdr, void ** | |||
642 | } | 655 | } |
643 | 656 | ||
644 | #define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1))) | 657 | #define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1))) |
658 | |||
645 | static int | 659 | static int |
646 | pfkey_sockaddr_size(sa_family_t family) | 660 | pfkey_sockaddr_size(sa_family_t family) |
647 | { | 661 | { |
648 | switch (family) { | 662 | return PFKEY_ALIGN8(pfkey_sockaddr_len(family)); |
649 | case AF_INET: | ||
650 | return PFKEY_ALIGN8(sizeof(struct sockaddr_in)); | ||
651 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
652 | case AF_INET6: | ||
653 | return PFKEY_ALIGN8(sizeof(struct sockaddr_in6)); | ||
654 | #endif | ||
655 | default: | ||
656 | return 0; | ||
657 | } | ||
658 | /* NOTREACHED */ | ||
659 | } | 663 | } |
660 | 664 | ||
661 | static inline int pfkey_mode_from_xfrm(int mode) | 665 | static inline int pfkey_mode_from_xfrm(int mode) |
@@ -1952,9 +1956,7 @@ static int pfkey_xfrm_policy2msg_size(struct xfrm_policy *xp) | |||
1952 | 1956 | ||
1953 | for (i=0; i<xp->xfrm_nr; i++) { | 1957 | for (i=0; i<xp->xfrm_nr; i++) { |
1954 | t = xp->xfrm_vec + i; | 1958 | t = xp->xfrm_vec + i; |
1955 | socklen += (t->encap_family == AF_INET ? | 1959 | socklen += pfkey_sockaddr_len(t->encap_family); |
1956 | sizeof(struct sockaddr_in) : | ||
1957 | sizeof(struct sockaddr_in6)); | ||
1958 | } | 1960 | } |
1959 | 1961 | ||
1960 | return sizeof(struct sadb_msg) + | 1962 | return sizeof(struct sadb_msg) + |
@@ -1996,9 +1998,7 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in | |||
1996 | int i; | 1998 | int i; |
1997 | int size; | 1999 | int size; |
1998 | int sockaddr_size = pfkey_sockaddr_size(xp->family); | 2000 | int sockaddr_size = pfkey_sockaddr_size(xp->family); |
1999 | int socklen = (xp->family == AF_INET ? | 2001 | int socklen = pfkey_sockaddr_len(xp->family); |
2000 | sizeof(struct sockaddr_in) : | ||
2001 | sizeof(struct sockaddr_in6)); | ||
2002 | 2002 | ||
2003 | size = pfkey_xfrm_policy2msg_size(xp); | 2003 | size = pfkey_xfrm_policy2msg_size(xp); |
2004 | 2004 | ||
@@ -2122,9 +2122,7 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in | |||
2122 | 2122 | ||
2123 | req_size = sizeof(struct sadb_x_ipsecrequest); | 2123 | req_size = sizeof(struct sadb_x_ipsecrequest); |
2124 | if (t->mode == XFRM_MODE_TUNNEL) | 2124 | if (t->mode == XFRM_MODE_TUNNEL) |
2125 | req_size += ((t->encap_family == AF_INET ? | 2125 | req_size += pfkey_sockaddr_len(t->encap_family) * 2; |
2126 | sizeof(struct sockaddr_in) : | ||
2127 | sizeof(struct sockaddr_in6)) * 2); | ||
2128 | else | 2126 | else |
2129 | size -= 2*socklen; | 2127 | size -= 2*socklen; |
2130 | rq = (void*)skb_put(skb, req_size); | 2128 | rq = (void*)skb_put(skb, req_size); |
@@ -2459,17 +2457,7 @@ out: | |||
2459 | #ifdef CONFIG_NET_KEY_MIGRATE | 2457 | #ifdef CONFIG_NET_KEY_MIGRATE |
2460 | static int pfkey_sockaddr_pair_size(sa_family_t family) | 2458 | static int pfkey_sockaddr_pair_size(sa_family_t family) |
2461 | { | 2459 | { |
2462 | switch (family) { | 2460 | return PFKEY_ALIGN8(pfkey_sockaddr_len(family) * 2); |
2463 | case AF_INET: | ||
2464 | return PFKEY_ALIGN8(sizeof(struct sockaddr_in) * 2); | ||
2465 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
2466 | case AF_INET6: | ||
2467 | return PFKEY_ALIGN8(sizeof(struct sockaddr_in6) * 2); | ||
2468 | #endif | ||
2469 | default: | ||
2470 | return 0; | ||
2471 | } | ||
2472 | /* NOTREACHED */ | ||
2473 | } | 2461 | } |
2474 | 2462 | ||
2475 | static int parse_sockaddr_pair(struct sadb_x_ipsecrequest *rq, | 2463 | static int parse_sockaddr_pair(struct sadb_x_ipsecrequest *rq, |