Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nft_osf: Add ttl option support

Add ttl option support to the nftables "osf" expression.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Fernando Fernandez Mancera and committed by
Pablo Neira Ayuso
a218dc82 ea9cf2a5

+42 -25
+7
include/uapi/linux/netfilter/nf_tables.h
··· 1511 1511 }; 1512 1512 #define NFTA_FLOWTABLE_HOOK_MAX (__NFTA_FLOWTABLE_HOOK_MAX - 1) 1513 1513 1514 + /** 1515 + * enum nft_osf_attributes - nftables osf expression netlink attributes 1516 + * 1517 + * @NFTA_OSF_DREG: destination register (NLA_U32: nft_registers) 1518 + * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8) 1519 + */ 1514 1520 enum nft_osf_attributes { 1515 1521 NFTA_OSF_UNSPEC, 1516 1522 NFTA_OSF_DREG, 1523 + NFTA_OSF_TTL, 1517 1524 __NFTA_OSF_MAX, 1518 1525 }; 1519 1526 #define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1)
+14 -1
net/netfilter/nft_osf.c
··· 6 6 7 7 struct nft_osf { 8 8 enum nft_registers dreg:8; 9 + u8 ttl; 9 10 }; 10 11 11 12 static const struct nla_policy nft_osf_policy[NFTA_OSF_MAX + 1] = { 12 13 [NFTA_OSF_DREG] = { .type = NLA_U32 }, 14 + [NFTA_OSF_TTL] = { .type = NLA_U8 }, 13 15 }; 14 16 15 17 static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, ··· 35 33 return; 36 34 } 37 35 38 - os_name = nf_osf_find(skb, nf_osf_fingers); 36 + os_name = nf_osf_find(skb, nf_osf_fingers, priv->ttl); 39 37 if (!os_name) 40 38 strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN); 41 39 else ··· 48 46 { 49 47 struct nft_osf *priv = nft_expr_priv(expr); 50 48 int err; 49 + u8 ttl; 50 + 51 + if (nla_get_u8(tb[NFTA_OSF_TTL])) { 52 + ttl = nla_get_u8(tb[NFTA_OSF_TTL]); 53 + if (ttl > 2) 54 + return -EINVAL; 55 + priv->ttl = ttl; 56 + } 51 57 52 58 priv->dreg = nft_parse_register(tb[NFTA_OSF_DREG]); 53 59 err = nft_validate_register_store(ctx, priv->dreg, NULL, ··· 69 59 static int nft_osf_dump(struct sk_buff *skb, const struct nft_expr *expr) 70 60 { 71 61 const struct nft_osf *priv = nft_expr_priv(expr); 62 + 63 + if (nla_put_u8(skb, NFTA_OSF_TTL, priv->ttl)) 64 + goto nla_put_failure; 72 65 73 66 if (nft_dump_register(skb, NFTA_OSF_DREG, priv->dreg)) 74 67 goto nla_put_failure;