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

netfilter: nft_osf: Add version option support

Add version 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
22c7652c 6978cdb1

+46 -15
+6
include/uapi/linux/netfilter/nf_tables.h
··· 1522 1522 * 1523 1523 * @NFTA_OSF_DREG: destination register (NLA_U32: nft_registers) 1524 1524 * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8) 1525 + * @NFTA_OSF_FLAGS: flags (NLA_U32) 1525 1526 */ 1526 1527 enum nft_osf_attributes { 1527 1528 NFTA_OSF_UNSPEC, 1528 1529 NFTA_OSF_DREG, 1529 1530 NFTA_OSF_TTL, 1531 + NFTA_OSF_FLAGS, 1530 1532 __NFTA_OSF_MAX, 1531 1533 }; 1532 1534 #define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1) 1535 + 1536 + enum nft_osf_flags { 1537 + NFT_OSF_F_VERSION = (1 << 0), 1538 + }; 1533 1539 1534 1540 /** 1535 1541 * enum nft_device_attributes - nf_tables device netlink attributes
+25 -5
net/netfilter/nft_osf.c
··· 7 7 struct nft_osf { 8 8 enum nft_registers dreg:8; 9 9 u8 ttl; 10 + u32 flags; 10 11 }; 11 12 12 13 static const struct nla_policy nft_osf_policy[NFTA_OSF_MAX + 1] = { 13 14 [NFTA_OSF_DREG] = { .type = NLA_U32 }, 14 15 [NFTA_OSF_TTL] = { .type = NLA_U8 }, 16 + [NFTA_OSF_FLAGS] = { .type = NLA_U32 }, 15 17 }; 16 18 17 19 static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, ··· 22 20 struct nft_osf *priv = nft_expr_priv(expr); 23 21 u32 *dest = &regs->data[priv->dreg]; 24 22 struct sk_buff *skb = pkt->skb; 23 + char os_match[NFT_OSF_MAXGENRELEN + 1]; 25 24 const struct tcphdr *tcp; 25 + struct nf_osf_data data; 26 26 struct tcphdr _tcph; 27 - const char *os_name; 28 27 29 28 tcp = skb_header_pointer(skb, ip_hdrlen(skb), 30 29 sizeof(struct tcphdr), &_tcph); ··· 38 35 return; 39 36 } 40 37 41 - os_name = nf_osf_find(skb, nf_osf_fingers, priv->ttl); 42 - if (!os_name) 38 + if (!nf_osf_find(skb, nf_osf_fingers, priv->ttl, &data)) { 43 39 strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN); 44 - else 45 - strncpy((char *)dest, os_name, NFT_OSF_MAXGENRELEN); 40 + } else { 41 + if (priv->flags & NFT_OSF_F_VERSION) 42 + snprintf(os_match, NFT_OSF_MAXGENRELEN, "%s:%s", 43 + data.genre, data.version); 44 + else 45 + strlcpy(os_match, data.genre, NFT_OSF_MAXGENRELEN); 46 + 47 + strncpy((char *)dest, os_match, NFT_OSF_MAXGENRELEN); 48 + } 46 49 } 47 50 48 51 static int nft_osf_init(const struct nft_ctx *ctx, ··· 56 47 const struct nlattr * const tb[]) 57 48 { 58 49 struct nft_osf *priv = nft_expr_priv(expr); 50 + u32 flags; 59 51 int err; 60 52 u8 ttl; 61 53 ··· 65 55 if (ttl > 2) 66 56 return -EINVAL; 67 57 priv->ttl = ttl; 58 + } 59 + 60 + if (tb[NFTA_OSF_FLAGS]) { 61 + flags = ntohl(nla_get_be32(tb[NFTA_OSF_FLAGS])); 62 + if (flags != NFT_OSF_F_VERSION) 63 + return -EINVAL; 64 + priv->flags = flags; 68 65 } 69 66 70 67 priv->dreg = nft_parse_register(tb[NFTA_OSF_DREG]); ··· 88 71 const struct nft_osf *priv = nft_expr_priv(expr); 89 72 90 73 if (nla_put_u8(skb, NFTA_OSF_TTL, priv->ttl)) 74 + goto nla_put_failure; 75 + 76 + if (nla_put_be32(skb, NFTA_OSF_FLAGS, ntohl(priv->flags))) 91 77 goto nla_put_failure; 92 78 93 79 if (nft_dump_register(skb, NFTA_OSF_DREG, priv->dreg))