From c8396bdc040f4b16e6f6e3f8b81b9fb67a499d9c Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Thu, 20 Jan 2011 14:48:23 +0100 Subject: Use annotated types and fix sparse warnings Annotated types are introduced and sparse warnings fixed. Two warnings remained in ip_set_core.c but those are false ones. (Patrick McHardy's review) --- kernel/include/linux/netfilter/ipset/ip_set.h | 42 +++++++++------------- .../include/linux/netfilter/ipset/ip_set_getport.h | 12 +++---- kernel/include/linux/netfilter/ipset/pfxlen.h | 4 +-- 3 files changed, 25 insertions(+), 33 deletions(-) (limited to 'kernel/include') diff --git a/kernel/include/linux/netfilter/ipset/ip_set.h b/kernel/include/linux/netfilter/ipset/ip_set.h index b35c5d9..7679b33 100644 --- a/kernel/include/linux/netfilter/ipset/ip_set.h +++ b/kernel/include/linux/netfilter/ipset/ip_set.h @@ -320,10 +320,22 @@ extern int ip_set_test(ip_set_id_t id, const struct sk_buff *skb, /* Utility functions */ extern void * ip_set_alloc(size_t size, gfp_t gfp_mask); extern void ip_set_free(void *members); -extern int ip_set_get_ipaddr4(struct nlattr *attr[], int type, u32 *ipaddr); +extern int ip_set_get_ipaddr4(struct nlattr *attr[], int type, __be32 *ipaddr); extern int ip_set_get_ipaddr6(struct nlattr *attr[], int type, union nf_inet_addr *ipaddr); +static inline int +ip_set_get_hostipaddr4(struct nlattr *attr[], int type, u32 *ipaddr) +{ + __be32 ip; + int ret = ip_set_get_ipaddr4(attr, type, &ip); + + if (ret) + return ret; + *ipaddr = ntohl(ip); + return 0; +} + /* Ignore IPSET_ERR_EXIST errors if asked to do so? */ static inline bool ip_set_eexist(int ret, u32 flags) @@ -335,33 +347,13 @@ ip_set_eexist(int ret, u32 flags) static inline u32 ip_set_get_h32(const struct nlattr *attr) { - u32 value = nla_get_u32(attr); - - return attr->nla_type & NLA_F_NET_BYTEORDER ? ntohl(value) : value; + return ntohl(nla_get_be32(attr)); } static inline u16 ip_set_get_h16(const struct nlattr *attr) { - u16 value = nla_get_u16(attr); - - return attr->nla_type & NLA_F_NET_BYTEORDER ? ntohs(value) : value; -} - -static inline u32 -ip_set_get_n32(const struct nlattr *attr) -{ - u32 value = nla_get_u32(attr); - - return attr->nla_type & NLA_F_NET_BYTEORDER ? value : htonl(value); -} - -static inline u16 -ip_set_get_n16(const struct nlattr *attr) -{ - u16 value = nla_get_u16(attr); - - return attr->nla_type & NLA_F_NET_BYTEORDER ? value : htons(value); + return ntohs(nla_get_be16(attr)); } #define ipset_nest_start(skb, attr) nla_nest_start(skb, attr | NLA_F_NESTED) @@ -389,14 +381,14 @@ do { \ } while (0) /* Get address from skbuff */ -static inline u32 +static inline __be32 ip4addr(const struct sk_buff *skb, bool src) { return src ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr; } static inline void -ip4addrptr(const struct sk_buff *skb, bool src, u32 *addr) +ip4addrptr(const struct sk_buff *skb, bool src, __be32 *addr) { *addr = src ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr; } diff --git a/kernel/include/linux/netfilter/ipset/ip_set_getport.h b/kernel/include/linux/netfilter/ipset/ip_set_getport.h index 8be8ecf..a5d243c 100644 --- a/kernel/include/linux/netfilter/ipset/ip_set_getport.h +++ b/kernel/include/linux/netfilter/ipset/ip_set_getport.h @@ -12,7 +12,7 @@ /* We must handle non-linear skbs */ static inline bool get_port(const struct sk_buff *skb, int protocol, unsigned int protooff, - bool src, u16 *port, u8 *proto) + bool src, __be16 *port, u8 *proto) { switch (protocol) { case IPPROTO_TCP: { @@ -47,7 +47,7 @@ get_port(const struct sk_buff *skb, int protocol, unsigned int protooff, if (ic == NULL) return false; - *port = (ic->type << 8) & ic->code; + *port = (__force __be16)((ic->type << 8) & ic->code); break; } case IPPROTO_ICMPV6: { @@ -58,7 +58,7 @@ get_port(const struct sk_buff *skb, int protocol, unsigned int protooff, if (ic == NULL) return false; - *port = (ic->icmp6_type << 8) & ic->icmp6_code; + *port = (__force __be16)((ic->icmp6_type << 8) & ic->icmp6_code); break; } default: @@ -70,7 +70,7 @@ get_port(const struct sk_buff *skb, int protocol, unsigned int protooff, } static inline bool -get_ip4_port(const struct sk_buff *skb, bool src, u16 *port, u8 *proto) +get_ip4_port(const struct sk_buff *skb, bool src, __be16 *port, u8 *proto) { const struct iphdr *iph = ip_hdr(skb); unsigned int protooff = ip_hdrlen(skb); @@ -84,7 +84,7 @@ get_ip4_port(const struct sk_buff *skb, bool src, u16 *port, u8 *proto) } static inline bool -get_ip6_port(const struct sk_buff *skb, bool src, u16 *port, u8 *proto) +get_ip6_port(const struct sk_buff *skb, bool src, __be16 *port, u8 *proto) { unsigned int protooff = 0; int protocol; @@ -98,7 +98,7 @@ get_ip6_port(const struct sk_buff *skb, bool src, u16 *port, u8 *proto) } static inline bool -get_ip_port(const struct sk_buff *skb, u8 pf, bool src, u16 *port) +get_ip_port(const struct sk_buff *skb, u8 pf, bool src, __be16 *port) { bool ret; u8 proto; diff --git a/kernel/include/linux/netfilter/ipset/pfxlen.h b/kernel/include/linux/netfilter/ipset/pfxlen.h index 08e6059..0e1fb50 100644 --- a/kernel/include/linux/netfilter/ipset/pfxlen.h +++ b/kernel/include/linux/netfilter/ipset/pfxlen.h @@ -20,10 +20,10 @@ ip_set_netmask6(u8 pfxlen) return &ip_set_netmask_map[pfxlen].ip6[0]; } -static inline __be32 +static inline u32 ip_set_hostmask(u8 pfxlen) { - return ip_set_hostmask_map[pfxlen].ip; + return (__force u32) ip_set_hostmask_map[pfxlen].ip; } static inline const __be32 * -- cgit v1.2.3