Commit 9e8b4ed8 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki

key: Introduce pfkey_sockaddr_len() for raw sockaddr{} length.

Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
parent 3de23255
...@@ -579,6 +579,19 @@ static uint8_t pfkey_proto_from_xfrm(uint8_t proto) ...@@ -579,6 +579,19 @@ static uint8_t pfkey_proto_from_xfrm(uint8_t proto)
return (proto ? proto : IPSEC_PROTO_ANY); return (proto ? proto : IPSEC_PROTO_ANY);
} }
static inline int pfkey_sockaddr_len(sa_family_t family)
{
switch (family) {
case AF_INET:
return sizeof(struct sockaddr_in);
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case AF_INET6:
return sizeof(struct sockaddr_in6);
#endif
}
return 0;
}
static int pfkey_sadb_addr2xfrm_addr(struct sadb_address *addr, static int pfkey_sadb_addr2xfrm_addr(struct sadb_address *addr,
xfrm_address_t *xaddr) xfrm_address_t *xaddr)
{ {
...@@ -642,20 +655,11 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct sadb_msg *hdr, void ** ...@@ -642,20 +655,11 @@ static struct xfrm_state *pfkey_xfrm_state_lookup(struct sadb_msg *hdr, void **
} }
#define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1))) #define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1)))
static int static int
pfkey_sockaddr_size(sa_family_t family) pfkey_sockaddr_size(sa_family_t family)
{ {
switch (family) { return PFKEY_ALIGN8(pfkey_sockaddr_len(family));
case AF_INET:
return PFKEY_ALIGN8(sizeof(struct sockaddr_in));
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case AF_INET6:
return PFKEY_ALIGN8(sizeof(struct sockaddr_in6));
#endif
default:
return 0;
}
/* NOTREACHED */
} }
static inline int pfkey_mode_from_xfrm(int mode) static inline int pfkey_mode_from_xfrm(int mode)
...@@ -1952,9 +1956,7 @@ static int pfkey_xfrm_policy2msg_size(struct xfrm_policy *xp) ...@@ -1952,9 +1956,7 @@ static int pfkey_xfrm_policy2msg_size(struct xfrm_policy *xp)
for (i=0; i<xp->xfrm_nr; i++) { for (i=0; i<xp->xfrm_nr; i++) {
t = xp->xfrm_vec + i; t = xp->xfrm_vec + i;
socklen += (t->encap_family == AF_INET ? socklen += pfkey_sockaddr_len(t->encap_family);
sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6));
} }
return sizeof(struct sadb_msg) + return sizeof(struct sadb_msg) +
...@@ -1996,9 +1998,7 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in ...@@ -1996,9 +1998,7 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in
int i; int i;
int size; int size;
int sockaddr_size = pfkey_sockaddr_size(xp->family); int sockaddr_size = pfkey_sockaddr_size(xp->family);
int socklen = (xp->family == AF_INET ? int socklen = pfkey_sockaddr_len(xp->family);
sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6));
size = pfkey_xfrm_policy2msg_size(xp); size = pfkey_xfrm_policy2msg_size(xp);
...@@ -2122,9 +2122,7 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in ...@@ -2122,9 +2122,7 @@ static int pfkey_xfrm_policy2msg(struct sk_buff *skb, struct xfrm_policy *xp, in
req_size = sizeof(struct sadb_x_ipsecrequest); req_size = sizeof(struct sadb_x_ipsecrequest);
if (t->mode == XFRM_MODE_TUNNEL) if (t->mode == XFRM_MODE_TUNNEL)
req_size += ((t->encap_family == AF_INET ? req_size += pfkey_sockaddr_len(t->encap_family) * 2;
sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6)) * 2);
else else
size -= 2*socklen; size -= 2*socklen;
rq = (void*)skb_put(skb, req_size); rq = (void*)skb_put(skb, req_size);
...@@ -2459,17 +2457,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, struct sadb ...@@ -2459,17 +2457,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, struct sadb
#ifdef CONFIG_NET_KEY_MIGRATE #ifdef CONFIG_NET_KEY_MIGRATE
static int pfkey_sockaddr_pair_size(sa_family_t family) static int pfkey_sockaddr_pair_size(sa_family_t family)
{ {
switch (family) { return PFKEY_ALIGN8(pfkey_sockaddr_len(family) * 2);
case AF_INET:
return PFKEY_ALIGN8(sizeof(struct sockaddr_in) * 2);
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case AF_INET6:
return PFKEY_ALIGN8(sizeof(struct sockaddr_in6) * 2);
#endif
default:
return 0;
}
/* NOTREACHED */
} }
static int parse_sockaddr_pair(struct sadb_x_ipsecrequest *rq, static int parse_sockaddr_pair(struct sadb_x_ipsecrequest *rq,
......
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