[IPV6]: Misc endianness annotations.
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 15 Nov 2006 04:56:00 +0000 (20:56 -0800)
committerDavid S. Miller <davem@sunset.davemloft.net>
Sun, 3 Dec 2006 05:22:52 +0000 (21:22 -0800)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
22 files changed:
include/net/addrconf.h
include/net/ip6_route.h
include/net/ipv6.h
include/net/ndisc.h
net/ipv6/addrconf.c
net/ipv6/af_inet6.c
net/ipv6/datagram.c
net/ipv6/exthdrs.c
net/ipv6/exthdrs_core.c
net/ipv6/inet6_connection_sock.c
net/ipv6/ip6_fib.c
net/ipv6/ip6_tunnel.c
net/ipv6/mip6.c
net/ipv6/ndisc.c
net/ipv6/netfilter/ip6_tables.c
net/ipv6/netfilter/ip6t_LOG.c
net/ipv6/raw.c
net/ipv6/reassembly.c
net/ipv6/route.c
net/ipv6/sit.c
net/ipv6/tcp_ipv6.c
net/ipv6/udp.c

index 44f1b67..88df8fc 100644 (file)
@@ -35,9 +35,9 @@ struct prefix_info {
 #else
 #error "Please fix <asm/byteorder.h>"
 #endif
-       __u32                   valid;
-       __u32                   prefered;
-       __u32                   reserved2;
+       __be32                  valid;
+       __be32                  prefered;
+       __be32                  reserved2;
 
        struct in6_addr         prefix;
 };
@@ -183,7 +183,7 @@ static __inline__ u8 ipv6_addr_hash(const struct in6_addr *addr)
         * This will include the IEEE address token on links that support it.
         */
 
-       word = addr->s6_addr32[2] ^ addr->s6_addr32[3];
+       word = (__force u32)(addr->s6_addr32[2] ^ addr->s6_addr32[3]);
        word ^= (word >> 16);
        word ^= (word >> 8);
 
index c14b70e..4e927eb 100644 (file)
@@ -20,7 +20,7 @@ struct route_info {
                                route_pref:2,
                                reserved_h:3;
 #endif
-       __u32                   lifetime;
+       __be32                  lifetime;
        __u8                    prefix[0];      /* 0,8 or 16 */
 };
 
index 9390649..4ca9e93 100644 (file)
@@ -563,7 +563,7 @@ extern int                  ip6_datagram_connect(struct sock *sk,
                                                     struct sockaddr *addr, int addr_len);
 
 extern int                     ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len);
-extern void                    ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, u16 port,
+extern void                    ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
                                                u32 info, u8 *payload);
 extern void                    ipv6_local_error(struct sock *sk, int err, struct flowi *fl, u32 info);
 
index d3915da..475b10c 100644 (file)
@@ -66,8 +66,8 @@ struct rs_msg {
 
 struct ra_msg {
         struct icmp6hdr                icmph;
-       __u32                   reachable_time;
-       __u32                   retrans_timer;
+       __be32                  reachable_time;
+       __be32                  retrans_timer;
 };
 
 struct nd_opt_hdr {
index 052f99e..b41c5d8 100644 (file)
@@ -232,7 +232,7 @@ static inline unsigned ipv6_addr_scope2type(unsigned scope)
 
 int __ipv6_addr_type(const struct in6_addr *addr)
 {
-       u32 st;
+       __be32 st;
 
        st = addr->s6_addr32[0];
 
index 1eb1c7f..87c8f54 100644 (file)
@@ -222,7 +222,7 @@ lookup_protocol:
                 * the user to assign a number at socket
                 * creation time automatically shares.
                 */
-               inet->sport = ntohs(inet->num);
+               inet->sport = htons(inet->num);
                sk->sk_prot->hash(sk);
        }
        if (sk->sk_prot->init) {
@@ -342,7 +342,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
        if (snum)
                sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
-       inet->sport = ntohs(inet->num);
+       inet->sport = htons(inet->num);
        inet->dport = 0;
        inet->daddr = 0;
 out:
index a67434a..5c94fea 100644 (file)
@@ -207,7 +207,7 @@ out:
 }
 
 void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, 
-                    u16 port, u32 info, u8 *payload)
+                    __be16 port, u32 info, u8 *payload)
 {
        struct ipv6_pinfo *np  = inet6_sk(sk);
        struct icmp6hdr *icmph = (struct icmp6hdr *)skb->h.raw;
@@ -324,7 +324,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
                } else {
                        ipv6_addr_set(&sin->sin6_addr, 0, 0,
                                      htonl(0xffff),
-                                     *(u32*)(skb->nh.raw + serr->addr_offset));
+                                     *(__be32*)(skb->nh.raw + serr->addr_offset));
                }
        }
 
@@ -397,7 +397,7 @@ int datagram_recv_ctl(struct sock *sk, struct msghdr *msg, struct sk_buff *skb)
        }
 
        if (np->rxopt.bits.rxtclass) {
-               int tclass = (ntohl(*(u32 *)skb->nh.ipv6h) >> 20) & 0xff;
+               int tclass = (ntohl(*(__be32 *)skb->nh.ipv6h) >> 20) & 0xff;
                put_cmsg(msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass);
        }
 
index 27829cc..0711f92 100644 (file)
@@ -655,7 +655,7 @@ static int ipv6_hop_jumbo(struct sk_buff **skbp, int optoff)
                goto drop;
        }
 
-       pkt_len = ntohl(*(u32*)(skb->nh.raw+optoff+2));
+       pkt_len = ntohl(*(__be32*)(skb->nh.raw+optoff+2));
        if (pkt_len <= IPV6_MAXPLEN) {
                IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
                icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2);
index 315bc1f..21cbbbd 100644 (file)
@@ -77,7 +77,7 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp)
                if (hp == NULL)
                        return -1;
                if (nexthdr == NEXTHDR_FRAGMENT) {
-                       unsigned short _frag_off, *fp;
+                       __be16 _frag_off, *fp;
                        fp = skb_header_pointer(skb,
                                                start+offsetof(struct frag_hdr,
                                                               frag_off),
index c598962..c700302 100644 (file)
@@ -55,16 +55,16 @@ EXPORT_SYMBOL_GPL(inet6_csk_bind_conflict);
 static u32 inet6_synq_hash(const struct in6_addr *raddr, const __be16 rport,
                           const u32 rnd, const u16 synq_hsize)
 {
-       u32 a = raddr->s6_addr32[0];
-       u32 b = raddr->s6_addr32[1];
-       u32 c = raddr->s6_addr32[2];
+       u32 a = (__force u32)raddr->s6_addr32[0];
+       u32 b = (__force u32)raddr->s6_addr32[1];
+       u32 c = (__force u32)raddr->s6_addr32[2];
 
        a += JHASH_GOLDEN_RATIO;
        b += JHASH_GOLDEN_RATIO;
        c += rnd;
        __jhash_mix(a, b, c);
 
-       a += raddr->s6_addr32[3];
+       a += (__force u32)raddr->s6_addr32[3];
        b += (__force u32)rport;
        __jhash_mix(a, b, c);
 
index f98ca30..bf52611 100644 (file)
@@ -139,9 +139,9 @@ static __inline__ u32 fib6_new_sernum(void)
  *     test bit
  */
 
-static __inline__ int addr_bit_set(void *token, int fn_bit)
+static __inline__ __be32 addr_bit_set(void *token, int fn_bit)
 {
-       __u32 *addr = token;
+       __be32 *addr = token;
 
        return htonl(1 << ((~fn_bit)&0x1F)) & addr[fn_bit>>5];
 }
@@ -434,7 +434,7 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
        struct fib6_node *pn = NULL;
        struct rt6key *key;
        int     bit;
-               int     dir = 0;
+               __be32  dir = 0;
        __u32   sernum = fib6_new_sernum();
 
        RT6_TRACE("fib6_add_1\n");
@@ -829,7 +829,7 @@ static struct fib6_node * fib6_lookup_1(struct fib6_node *root,
                                        struct lookup_args *args)
 {
        struct fib6_node *fn;
-       int dir;
+       __be32 dir;
 
        if (unlikely(args->offset == 0))
                return NULL;
index 80a1190..25bc5ed 100644 (file)
@@ -66,7 +66,7 @@ MODULE_LICENSE("GPL");
 
 #define HASH_SIZE  32
 
-#define HASH(addr) (((addr)->s6_addr32[0] ^ (addr)->s6_addr32[1] ^ \
+#define HASH(addr) ((__force u32)((addr)->s6_addr32[0] ^ (addr)->s6_addr32[1] ^ \
                     (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \
                     (HASH_SIZE - 1))
 
index 7ccdc8f..be7dd7d 100644 (file)
@@ -262,10 +262,10 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, struct
        sel.proto = fl->proto;
        sel.dport = xfrm_flowi_dport(fl);
        if (sel.dport)
-               sel.dport_mask = ~((__u16)0);
+               sel.dport_mask = htons(~0);
        sel.sport = xfrm_flowi_sport(fl);
        if (sel.sport)
-               sel.sport_mask = ~((__u16)0);
+               sel.sport_mask = htons(~0);
        sel.ifindex = fl->oif;
 
        err = km_report(IPPROTO_DSTOPTS, &sel,
index 1342be8..56ea928 100644 (file)
@@ -1267,10 +1267,11 @@ skip_defrtr:
        }
 
        if (ndopts.nd_opts_mtu) {
+               __be32 n;
                u32 mtu;
 
-               memcpy(&mtu, ((u8*)(ndopts.nd_opts_mtu+1))+2, sizeof(mtu));
-               mtu = ntohl(mtu);
+               memcpy(&n, ((u8*)(ndopts.nd_opts_mtu+1))+2, sizeof(mtu));
+               mtu = ntohl(n);
 
                if (mtu < IPV6_MIN_MTU || mtu > skb->dev->mtu) {
                        ND_PRINTK2(KERN_WARNING
index 204e021..f63fb86 100644 (file)
@@ -1481,7 +1481,8 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
                if (hp == NULL)
                        return -EBADMSG;
                if (nexthdr == NEXTHDR_FRAGMENT) {
-                       unsigned short _frag_off, *fp;
+                       unsigned short _frag_off;
+                       __be16 *fp;
                        fp = skb_header_pointer(skb,
                                                start+offsetof(struct frag_hdr,
                                                               frag_off),
index 3cb6bb7..f4857cf 100644 (file)
@@ -69,9 +69,9 @@ static void dump_packet(const struct nf_loginfo *info,
        /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
        printk("LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
               ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
-              (ntohl(*(u_int32_t *)ih) & 0x0ff00000) >> 20,
+              (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
               ih->hop_limit,
-              (ntohl(*(u_int32_t *)ih) & 0x000fffff));
+              (ntohl(*(__be32 *)ih) & 0x000fffff));
 
        fragment = 0;
        ptr = ip6hoff + sizeof(struct ipv6hdr);
index 813fa1d..b03040a 100644 (file)
@@ -220,7 +220,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        struct inet_sock *inet = inet_sk(sk);
        struct ipv6_pinfo *np = inet6_sk(sk);
        struct sockaddr_in6 *addr = (struct sockaddr_in6 *) uaddr;
-       __u32 v4addr = 0;
+       __be32 v4addr = 0;
        int addr_type;
        int err;
 
index 3af0d5a..6f9a904 100644 (file)
@@ -77,7 +77,7 @@ struct frag_queue
        struct hlist_node       list;
        struct list_head lru_list;              /* lru list member      */
 
-       __u32                   id;             /* fragment id          */
+       __be32                  id;             /* fragment id          */
        struct in6_addr         saddr;
        struct in6_addr         daddr;
 
@@ -125,28 +125,28 @@ static __inline__ void fq_unlink(struct frag_queue *fq)
  * callers should be careful not to use the hash value outside the ipfrag_lock
  * as doing so could race with ipfrag_hash_rnd being recalculated.
  */
-static unsigned int ip6qhashfn(u32 id, struct in6_addr *saddr,
+static unsigned int ip6qhashfn(__be32 id, struct in6_addr *saddr,
                               struct in6_addr *daddr)
 {
        u32 a, b, c;
 
-       a = saddr->s6_addr32[0];
-       b = saddr->s6_addr32[1];
-       c = saddr->s6_addr32[2];
+       a = (__force u32)saddr->s6_addr32[0];
+       b = (__force u32)saddr->s6_addr32[1];
+       c = (__force u32)saddr->s6_addr32[2];
 
        a += JHASH_GOLDEN_RATIO;
        b += JHASH_GOLDEN_RATIO;
        c += ip6_frag_hash_rnd;
        __jhash_mix(a, b, c);
 
-       a += saddr->s6_addr32[3];
-       b += daddr->s6_addr32[0];
-       c += daddr->s6_addr32[1];
+       a += (__force u32)saddr->s6_addr32[3];
+       b += (__force u32)daddr->s6_addr32[0];
+       c += (__force u32)daddr->s6_addr32[1];
        __jhash_mix(a, b, c);
 
-       a += daddr->s6_addr32[2];
-       b += daddr->s6_addr32[3];
-       c += id;
+       a += (__force u32)daddr->s6_addr32[2];
+       b += (__force u32)daddr->s6_addr32[3];
+       c += (__force u32)id;
        __jhash_mix(a, b, c);
 
        return c & (IP6Q_HASHSZ - 1);
@@ -370,7 +370,7 @@ static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in)
 
 
 static struct frag_queue *
-ip6_frag_create(u32 id, struct in6_addr *src, struct in6_addr *dst,
+ip6_frag_create(__be32 id, struct in6_addr *src, struct in6_addr *dst,
                struct inet6_dev *idev)
 {
        struct frag_queue *fq;
@@ -396,7 +396,7 @@ oom:
 }
 
 static __inline__ struct frag_queue *
-fq_find(u32 id, struct in6_addr *src, struct in6_addr *dst,
+fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst,
        struct inet6_dev *idev)
 {
        struct frag_queue *fq;
index a6472cb..0bf17a3 100644 (file)
@@ -440,7 +440,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
        if (pref == ICMPV6_ROUTER_PREF_INVALID)
                pref = ICMPV6_ROUTER_PREF_MEDIUM;
 
-       lifetime = htonl(rinfo->lifetime);
+       lifetime = ntohl(rinfo->lifetime);
        if (lifetime == 0xffffffff) {
                /* infinity */
        } else if (lifetime > 0x7fffffff/HZ) {
index be699f8..85ff3dc 100644 (file)
@@ -60,7 +60,7 @@
  */
 
 #define HASH_SIZE  16
-#define HASH(addr) ((addr^(addr>>4))&0xF)
+#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
 
 static int ipip6_fb_tunnel_init(struct net_device *dev);
 static int ipip6_tunnel_init(struct net_device *dev);
@@ -76,7 +76,7 @@ static struct ip_tunnel **tunnels[4] = { tunnels_wc, tunnels_l, tunnels_r, tunne
 
 static DEFINE_RWLOCK(ipip6_lock);
 
-static struct ip_tunnel * ipip6_tunnel_lookup(u32 remote, u32 local)
+static struct ip_tunnel * ipip6_tunnel_lookup(__be32 remote, __be32 local)
 {
        unsigned h0 = HASH(remote);
        unsigned h1 = HASH(local);
@@ -102,8 +102,8 @@ static struct ip_tunnel * ipip6_tunnel_lookup(u32 remote, u32 local)
 
 static struct ip_tunnel ** ipip6_bucket(struct ip_tunnel *t)
 {
-       u32 remote = t->parms.iph.daddr;
-       u32 local = t->parms.iph.saddr;
+       __be32 remote = t->parms.iph.daddr;
+       __be32 local = t->parms.iph.saddr;
        unsigned h = 0;
        int prio = 0;
 
@@ -144,8 +144,8 @@ static void ipip6_tunnel_link(struct ip_tunnel *t)
 
 static struct ip_tunnel * ipip6_tunnel_locate(struct ip_tunnel_parm *parms, int create)
 {
-       u32 remote = parms->iph.daddr;
-       u32 local = parms->iph.saddr;
+       __be32 remote = parms->iph.daddr;
+       __be32 local = parms->iph.saddr;
        struct ip_tunnel *t, **tp, *nt;
        struct net_device *dev;
        unsigned h = 0;
@@ -405,9 +405,9 @@ out:
 /* Returns the embedded IPv4 address if the IPv6 address
    comes from 6to4 (RFC 3056) addr space */
 
-static inline u32 try_6to4(struct in6_addr *v6dst)
+static inline __be32 try_6to4(struct in6_addr *v6dst)
 {
-       u32 dst = 0;
+       __be32 dst = 0;
 
        if (v6dst->s6_addr16[0] == htons(0x2002)) {
                /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */
@@ -432,7 +432,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
        struct net_device *tdev;                        /* Device to other host */
        struct iphdr  *iph;                     /* Our new IP header */
        int    max_headroom;                    /* The extra header space needed */
-       u32    dst = tiph->daddr;
+       __be32 dst = tiph->daddr;
        int    mtu;
        struct in6_addr *addr6; 
        int addr_type;
index edef7ee..53f2709 100644 (file)
@@ -1084,7 +1084,7 @@ static void tcp_v6_send_ack(struct tcp_timewait_sock *tw,
        struct sk_buff *buff;
        struct flowi fl;
        int tot_len = sizeof(struct tcphdr);
-       u32 *topt;
+       __be32 *topt;
 #ifdef CONFIG_TCP_MD5SIG
        struct tcp_md5sig_key *key;
        struct tcp_md5sig_key tw_key;
@@ -1128,7 +1128,7 @@ static void tcp_v6_send_ack(struct tcp_timewait_sock *tw,
        t1->ack = 1;
        t1->window = htons(win);
 
-       topt = (u32*)(t1 + 1);
+       topt = (__be32 *)(t1 + 1);
        
        if (ts) {
                *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
index 5a64027..e6e1f85 100644 (file)
@@ -298,8 +298,8 @@ drop:
 }
 
 static struct sock *udp_v6_mcast_next(struct sock *sk,
-                                     u16 loc_port, struct in6_addr *loc_addr,
-                                     u16 rmt_port, struct in6_addr *rmt_addr,
+                                     __be16 loc_port, struct in6_addr *loc_addr,
+                                     __be16 rmt_port, struct in6_addr *rmt_addr,
                                      int dif)
 {
        struct hlist_node *node;