sctp: simplify addr copy
authorMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Wed, 28 Dec 2016 11:26:33 +0000 (09:26 -0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 28 Dec 2016 19:06:31 +0000 (14:06 -0500)
Make it a bit easier to read.

Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sctp/ipv6.c
net/sctp/protocol.c

index 5ed8e79bf102e1c2a9ef1955aee6dba01869545e..6619367bb6ca30f1421c91248263e5ae6e5edc86 100644 (file)
@@ -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,
                             int is_saddr)
 {
-       __be16 *port;
-       struct sctphdr *sh;
+       /* Always called on head skb, so this is safe */
+       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_flowinfo = 0; /* FIXME */
        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) {
-               *port  = sh->source;
-               addr->v6.sin6_addr = ipv6_hdr(skb)->saddr;
+               sa->sin6_port = sh->source;
+               sa->sin6_addr = ipv6_hdr(skb)->saddr;
        } else {
-               *port = sh->dest;
-               addr->v6.sin6_addr = ipv6_hdr(skb)->daddr;
+               sa->sin6_port = sh->dest;
+               sa->sin6_addr = ipv6_hdr(skb)->daddr;
        }
 }
 
index 616a9428e0c4f3ba2b2cf910f339074f79488e62..f9c3c37c9ae0780e6181745aa679c7e86ed4b5e4 100644 (file)
@@ -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,
                             int is_saddr)
 {
-       void *from;
-       __be16 *port;
-       struct sctphdr *sh;
+       /* Always called on head skb, so this is safe */
+       struct sctphdr *sh = sctp_hdr(skb);
+       struct sockaddr_in *sa = &addr->v4;
 
-       port = &addr->v4.sin_port;
        addr->v4.sin_family = AF_INET;
 
-       /* Always called on head skb, so this is safe */
-       sh = sctp_hdr(skb);
        if (is_saddr) {
-               *port  = sh->source;
-               from = &ip_hdr(skb)->saddr;
+               sa->sin_port = sh->source;
+               sa->sin_addr.s_addr = ip_hdr(skb)->saddr;
        } else {
-               *port = sh->dest;
-               from = &ip_hdr(skb)->daddr;
+               sa->sin_port = sh->dest;
+               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. */