netfilter: nft_meta: move time handling to helper

reduce size of the (large) meta evaluation function.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
Florian Westphal 2019-12-18 12:05:13 +01:00 committed by Pablo Neira Ayuso
parent 13d74c0a97
commit db8f6f5c8d

View File

@ -33,8 +33,9 @@
static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state);
static u8 nft_meta_weekday(time64_t secs)
static u8 nft_meta_weekday(void)
{
time64_t secs = ktime_get_real_seconds();
unsigned int dse;
u8 wday;
@ -56,6 +57,25 @@ static u32 nft_meta_hour(time64_t secs)
+ tm.tm_sec;
}
static noinline_for_stack void
nft_meta_get_eval_time(enum nft_meta_keys key,
u32 *dest)
{
switch (key) {
case NFT_META_TIME_NS:
nft_reg_store64(dest, ktime_get_real_ns());
break;
case NFT_META_TIME_DAY:
nft_reg_store8(dest, nft_meta_weekday());
break;
case NFT_META_TIME_HOUR:
*dest = nft_meta_hour(ktime_get_real_seconds());
break;
default:
break;
}
}
void nft_meta_get_eval(const struct nft_expr *expr,
struct nft_regs *regs,
const struct nft_pktinfo *pkt)
@ -247,13 +267,9 @@ void nft_meta_get_eval(const struct nft_expr *expr,
strncpy((char *)dest, out->rtnl_link_ops->kind, IFNAMSIZ);
break;
case NFT_META_TIME_NS:
nft_reg_store64(dest, ktime_get_real_ns());
break;
case NFT_META_TIME_DAY:
nft_reg_store8(dest, nft_meta_weekday(ktime_get_real_seconds()));
break;
case NFT_META_TIME_HOUR:
*dest = nft_meta_hour(ktime_get_real_seconds());
nft_meta_get_eval_time(priv->key, dest);
break;
default:
WARN_ON(1);