Commit 0630c56e authored by Marcelo Ricardo Leitner's avatar Marcelo Ricardo Leitner Committed by David S. Miller

sctp: simplify addr copy

Make it a bit easier to read.
Signed-off-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1ff01561
...@@ -412,22 +412,20 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist, ...@@ -412,22 +412,20 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist,
static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb, static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb,
int is_saddr) int is_saddr)
{ {
__be16 *port; /* Always called on head skb, so this is safe */
struct sctphdr *sh; struct sctphdr *sh = sctp_hdr(skb);
struct sockaddr_in6 *sa = &addr->v6;
port = &addr->v6.sin6_port;
addr->v6.sin6_family = AF_INET6; addr->v6.sin6_family = AF_INET6;
addr->v6.sin6_flowinfo = 0; /* FIXME */ addr->v6.sin6_flowinfo = 0; /* FIXME */
addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif; addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif;
/* Always called on head skb, so this is safe */
sh = sctp_hdr(skb);
if (is_saddr) { if (is_saddr) {
*port = sh->source; sa->sin6_port = sh->source;
addr->v6.sin6_addr = ipv6_hdr(skb)->saddr; sa->sin6_addr = ipv6_hdr(skb)->saddr;
} else { } else {
*port = sh->dest; sa->sin6_port = sh->dest;
addr->v6.sin6_addr = ipv6_hdr(skb)->daddr; sa->sin6_addr = ipv6_hdr(skb)->daddr;
} }
} }
......
...@@ -237,23 +237,19 @@ int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *bp, ...@@ -237,23 +237,19 @@ int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *bp,
static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb, static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb,
int is_saddr) int is_saddr)
{ {
void *from; /* Always called on head skb, so this is safe */
__be16 *port; struct sctphdr *sh = sctp_hdr(skb);
struct sctphdr *sh; struct sockaddr_in *sa = &addr->v4;
port = &addr->v4.sin_port;
addr->v4.sin_family = AF_INET; addr->v4.sin_family = AF_INET;
/* Always called on head skb, so this is safe */
sh = sctp_hdr(skb);
if (is_saddr) { if (is_saddr) {
*port = sh->source; sa->sin_port = sh->source;
from = &ip_hdr(skb)->saddr; sa->sin_addr.s_addr = ip_hdr(skb)->saddr;
} else { } else {
*port = sh->dest; sa->sin_port = sh->dest;
from = &ip_hdr(skb)->daddr; sa->sin_addr.s_addr = ip_hdr(skb)->daddr;
} }
memcpy(&addr->v4.sin_addr.s_addr, from, sizeof(struct in_addr));
} }
/* Initialize an sctp_addr from a socket. */ /* Initialize an sctp_addr from a socket. */
......
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