diff options
author | Florian Westphal <fw@strlen.de> | 2016-01-08 04:29:12 -0500 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2016-01-08 07:32:11 -0500 |
commit | ce1e7989d989e36ee3b032d46aab28b7d5e30428 (patch) | |
tree | 925691995a6208ecf9d937453df68c42b9153440 /net/netfilter | |
parent | e6d8ecac9e68265aee9be711c5bd29406129666f (diff) |
netfilter: nft_byteorder: provide 64bit le/be conversion
Needed to convert the (64bit) conntrack counters to BE ordering.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/nft_byteorder.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/net/netfilter/nft_byteorder.c b/net/netfilter/nft_byteorder.c index fde5145f2e36..383c17138399 100644 --- a/net/netfilter/nft_byteorder.c +++ b/net/netfilter/nft_byteorder.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * Development of this code funded by Astaro AG (http://www.astaro.com/) | 8 | * Development of this code funded by Astaro AG (http://www.astaro.com/) |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <asm/unaligned.h> | ||
11 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
12 | #include <linux/init.h> | 13 | #include <linux/init.h> |
13 | #include <linux/module.h> | 14 | #include <linux/module.h> |
@@ -39,6 +40,27 @@ static void nft_byteorder_eval(const struct nft_expr *expr, | |||
39 | d = (void *)dst; | 40 | d = (void *)dst; |
40 | 41 | ||
41 | switch (priv->size) { | 42 | switch (priv->size) { |
43 | case 8: { | ||
44 | u64 src64; | ||
45 | |||
46 | switch (priv->op) { | ||
47 | case NFT_BYTEORDER_NTOH: | ||
48 | for (i = 0; i < priv->len / 8; i++) { | ||
49 | src64 = get_unaligned_be64(&src[i]); | ||
50 | src64 = be64_to_cpu((__force __be64)src64); | ||
51 | put_unaligned_be64(src64, &dst[i]); | ||
52 | } | ||
53 | break; | ||
54 | case NFT_BYTEORDER_HTON: | ||
55 | for (i = 0; i < priv->len / 8; i++) { | ||
56 | src64 = get_unaligned_be64(&src[i]); | ||
57 | src64 = (__force u64)cpu_to_be64(src64); | ||
58 | put_unaligned_be64(src64, &dst[i]); | ||
59 | } | ||
60 | break; | ||
61 | } | ||
62 | break; | ||
63 | } | ||
42 | case 4: | 64 | case 4: |
43 | switch (priv->op) { | 65 | switch (priv->op) { |
44 | case NFT_BYTEORDER_NTOH: | 66 | case NFT_BYTEORDER_NTOH: |
@@ -101,6 +123,7 @@ static int nft_byteorder_init(const struct nft_ctx *ctx, | |||
101 | switch (priv->size) { | 123 | switch (priv->size) { |
102 | case 2: | 124 | case 2: |
103 | case 4: | 125 | case 4: |
126 | case 8: | ||
104 | break; | 127 | break; |
105 | default: | 128 | default: |
106 | return -EINVAL; | 129 | return -EINVAL; |