Skip to content

Commit

Permalink
netfilter: nft_byteorder: provide 64bit le/be conversion
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Florian Westphal authored and Pablo Neira Ayuso committed Jan 8, 2016
1 parent e6d8eca commit ce1e798
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions net/netfilter/nft_byteorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/

#include <asm/unaligned.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
Expand Down Expand Up @@ -39,6 +40,27 @@ static void nft_byteorder_eval(const struct nft_expr *expr,
d = (void *)dst;

switch (priv->size) {
case 8: {
u64 src64;

switch (priv->op) {
case NFT_BYTEORDER_NTOH:
for (i = 0; i < priv->len / 8; i++) {
src64 = get_unaligned_be64(&src[i]);
src64 = be64_to_cpu((__force __be64)src64);
put_unaligned_be64(src64, &dst[i]);
}
break;
case NFT_BYTEORDER_HTON:
for (i = 0; i < priv->len / 8; i++) {
src64 = get_unaligned_be64(&src[i]);
src64 = (__force u64)cpu_to_be64(src64);
put_unaligned_be64(src64, &dst[i]);
}
break;
}
break;
}
case 4:
switch (priv->op) {
case NFT_BYTEORDER_NTOH:
Expand Down Expand Up @@ -101,6 +123,7 @@ static int nft_byteorder_init(const struct nft_ctx *ctx,
switch (priv->size) {
case 2:
case 4:
case 8:
break;
default:
return -EINVAL;
Expand Down

0 comments on commit ce1e798

Please sign in to comment.