diff mbox

[nftables-kernel] netfilter: nftables: Fix sparse endianness issue on nft_nat.c

Message ID 1382086853-14251-1-git-send-email-tomasz.bursztyka@linux.intel.com
State Superseded
Headers show

Commit Message

Tomasz Bursztyka Oct. 18, 2013, 9 a.m. UTC
Fixes this:

CHECK   net/netfilter/nft_nat.c
net/netfilter/nft_nat.c:50:43: warning: incorrect type in assignment (different base types)
net/netfilter/nft_nat.c:50:43:    expected restricted __be32 [addressable] [usertype] ip
net/netfilter/nft_nat.c:50:43:    got unsigned int [unsigned] [usertype] <noident>
net/netfilter/nft_nat.c:51:43: warning: incorrect type in assignment (different base types)
net/netfilter/nft_nat.c:51:43:    expected restricted __be32 [addressable] [usertype] ip
net/netfilter/nft_nat.c:51:43:    got unsigned int [unsigned] [usertype] <noident>
net/netfilter/nft_nat.c:65:37: warning: incorrect type in assignment (different base types)
net/netfilter/nft_nat.c:65:37:    expected restricted __be16 [addressable] [assigned] [usertype] all
net/netfilter/nft_nat.c:65:37:    got unsigned int [unsigned] <noident>
net/netfilter/nft_nat.c:66:37: warning: incorrect type in assignment (different base types)
net/netfilter/nft_nat.c:66:37:    expected restricted __be16 [addressable] [assigned] [usertype] all
net/netfilter/nft_nat.c:66:37:    got unsigned int [unsigned] <noident>

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
---

Hi,

looks a bit ugly, would there be another way to fix this?

Tomasz

 net/netfilter/nft_nat.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Tomasz Bursztyka Oct. 28, 2013, 7:18 a.m. UTC | #1
Hi,

Any thoughts on that one?
Is there another (and proper) way of fixing this?

Tomasz
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Patrick McHardy Oct. 28, 2013, 9:41 a.m. UTC | #2
On Fri, Oct 18, 2013 at 12:00:53PM +0300, Tomasz Bursztyka wrote:
> Fixes this:
> 
> CHECK   net/netfilter/nft_nat.c
> net/netfilter/nft_nat.c:50:43: warning: incorrect type in assignment (different base types)
> net/netfilter/nft_nat.c:50:43:    expected restricted __be32 [addressable] [usertype] ip
> net/netfilter/nft_nat.c:50:43:    got unsigned int [unsigned] [usertype] <noident>
> net/netfilter/nft_nat.c:51:43: warning: incorrect type in assignment (different base types)
> net/netfilter/nft_nat.c:51:43:    expected restricted __be32 [addressable] [usertype] ip
> net/netfilter/nft_nat.c:51:43:    got unsigned int [unsigned] [usertype] <noident>
> net/netfilter/nft_nat.c:65:37: warning: incorrect type in assignment (different base types)
> net/netfilter/nft_nat.c:65:37:    expected restricted __be16 [addressable] [assigned] [usertype] all
> net/netfilter/nft_nat.c:65:37:    got unsigned int [unsigned] <noident>
> net/netfilter/nft_nat.c:66:37: warning: incorrect type in assignment (different base types)
> net/netfilter/nft_nat.c:66:37:    expected restricted __be16 [addressable] [assigned] [usertype] all
> net/netfilter/nft_nat.c:66:37:    got unsigned int [unsigned] <noident>
> 
> Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
> ---
> 
> Hi,
> 
> looks a bit ugly, would there be another way to fix this?
> 
> Tomasz
> 
>  net/netfilter/nft_nat.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c
> index b0b87b2..f9d488f 100644
> --- a/net/netfilter/nft_nat.c
> +++ b/net/netfilter/nft_nat.c
> @@ -47,8 +47,12 @@ static void nft_nat_eval(const struct nft_expr *expr,
>  	memset(&range, 0, sizeof(range));
>  	if (priv->sreg_addr_min) {
>  		if (priv->family == AF_INET) {
> -			range.min_addr.ip = data[priv->sreg_addr_min].data[0];
> -			range.max_addr.ip = data[priv->sreg_addr_max].data[0];
> +			range.min_addr.ip =
> +				be32_to_cpup((__be32 *)
> +					data[priv->sreg_addr_min].data);
> +			range.max_addr.ip =
> +				be32_to_cpup((__be32 *)
> +					data[priv->sreg_addr_max].data);

That doesn't seem correct, we don't want to actually switch the byteorder of
the data. I'd suggest to simply use (__force __be32).
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tomasz Bursztyka Oct. 28, 2013, 10:13 a.m. UTC | #3
Hi Patrick,

> On Fri, Oct 18, 2013 at 12:00:53PM +0300, Tomasz Bursztyka wrote:
>> +			range.max_addr.ip =
>> +				be32_to_cpup((__be32 *)
>> +					data[priv->sreg_addr_max].data);
> That doesn't seem correct, we don't want to actually switch the byteorder of
> the data. I'd suggest to simply use (__force __be32).

Was sure I messed up with that. Thanks

Tomasz
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c
index b0b87b2..f9d488f 100644
--- a/net/netfilter/nft_nat.c
+++ b/net/netfilter/nft_nat.c
@@ -47,8 +47,12 @@  static void nft_nat_eval(const struct nft_expr *expr,
 	memset(&range, 0, sizeof(range));
 	if (priv->sreg_addr_min) {
 		if (priv->family == AF_INET) {
-			range.min_addr.ip = data[priv->sreg_addr_min].data[0];
-			range.max_addr.ip = data[priv->sreg_addr_max].data[0];
+			range.min_addr.ip =
+				be32_to_cpup((__be32 *)
+					data[priv->sreg_addr_min].data);
+			range.max_addr.ip =
+				be32_to_cpup((__be32 *)
+					data[priv->sreg_addr_max].data);
 
 		} else {
 			memcpy(range.min_addr.ip6,
@@ -62,8 +66,12 @@  static void nft_nat_eval(const struct nft_expr *expr,
 	}
 
 	if (priv->sreg_proto_min) {
-		range.min_proto.all = data[priv->sreg_proto_min].data[0];
-		range.max_proto.all = data[priv->sreg_proto_max].data[0];
+		range.min_proto.all =
+			be16_to_cpup((__be16 *)
+					data[priv->sreg_proto_min].data);
+		range.max_proto.all =
+			be16_to_cpup((__be16 *)
+					data[priv->sreg_proto_max].data);
 		range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
 	}