From patchwork Sat Sep 29 10:16:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fernando F. Mancera" X-Patchwork-Id: 976568 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=riseup.net Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=riseup.net header.i=@riseup.net header.b="NTlujyIL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Mkwx6pvmz9s7T for ; Sat, 29 Sep 2018 20:16:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727756AbeI2Qok (ORCPT ); Sat, 29 Sep 2018 12:44:40 -0400 Received: from mx1.riseup.net ([198.252.153.129]:33588 "EHLO mx1.riseup.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727540AbeI2Qok (ORCPT ); Sat, 29 Sep 2018 12:44:40 -0400 Received: from piha.riseup.net (piha-pn.riseup.net [10.0.1.163]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 061981A0404 for ; Sat, 29 Sep 2018 03:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1538216208; bh=uTU1IqbU8cTTBUB/MD1v10ffGEmO69E459KbhNqOPrw=; h=From:To:Cc:Subject:Date:From; b=NTlujyILv42igV23wMcLfAJwjtra3mZqZC5GLwP9Nmgi5uW8LioXkJY1vkL8cwyVd JN4LuEVi07ONdG2+JUp0qtURbINlTM+f72XCUdDVU9m22G+D3f/3UmzOTrLtHEMkqF bUjGlDRNigwEg2tbYXTurN8AmAFkouDQ79pgWv6M= X-Riseup-User-ID: F581DEAE76B04A86927AAAA4C84D9B221ECB9B00973DC77EB905E9045788B27C Received: from [127.0.0.1] (localhost [127.0.0.1]) by piha.riseup.net with ESMTPSA id D4A13445B8; Sat, 29 Sep 2018 03:16:46 -0700 (PDT) From: Fernando Fernandez Mancera To: netfilter-devel@vger.kernel.org Cc: Fernando Fernandez Mancera Subject: [PATCH libnftnl] expr: osf: add ttl option support Date: Sat, 29 Sep 2018 12:16:37 +0200 Message-Id: <20180929101637.1019-1-ffmancera@riseup.net> MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Signed-off-by: Fernando Fernandez Mancera --- include/libnftnl/expr.h | 1 + include/linux/netfilter/nf_tables.h | 4 +++- src/expr/osf.c | 26 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/libnftnl/expr.h b/include/libnftnl/expr.h index 6285c6f..6988c62 100644 --- a/include/libnftnl/expr.h +++ b/include/libnftnl/expr.h @@ -281,6 +281,7 @@ enum { enum { NFTNL_EXPR_OSF_DREG = NFTNL_EXPR_BASE, + NFTNL_EXPR_OSF_TTL, }; enum { diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h index da2c291..936687d 100644 --- a/include/linux/netfilter/nf_tables.h +++ b/include/linux/netfilter/nf_tables.h @@ -936,11 +936,13 @@ enum nft_socket_keys { /** * enum nft_osf_attributes - nf_tables osf expression netlink attributes * - * @NFTA_OSF_DREG: OS to match + * @NFTA_OSF_DREG: destination register (NLA_U32) + * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8) */ enum nft_osf_attributes { NFTA_OSF_UNSPEC, NFTA_OSF_DREG, + NFTA_OSF_TTL, __NFTA_OSF_MAX, }; #define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1) diff --git a/src/expr/osf.c b/src/expr/osf.c index 6fd62e5..39d7e0c 100644 --- a/src/expr/osf.c +++ b/src/expr/osf.c @@ -14,6 +14,7 @@ struct nftnl_expr_osf { enum nft_registers dreg; + uint8_t ttl; }; static int nftnl_expr_osf_set(struct nftnl_expr *e, uint16_t type, @@ -25,6 +26,9 @@ static int nftnl_expr_osf_set(struct nftnl_expr *e, uint16_t type, case NFTNL_EXPR_OSF_DREG: osf->dreg = *((uint32_t *)data); break; + case NFTNL_EXPR_OSF_TTL: + osf->ttl = *((uint8_t *)data); + break; } return 0; } @@ -39,6 +43,9 @@ nftnl_expr_osf_get(const struct nftnl_expr *e, uint16_t type, case NFTNL_EXPR_OSF_DREG: *data_len = sizeof(osf->dreg); return &osf->dreg; + case NFTNL_EXPR_OSF_TTL: + *data_len = sizeof(osf->ttl); + return &osf->ttl; } return NULL; } @@ -56,6 +63,11 @@ static int nftnl_expr_osf_cb(const struct nlattr *attr, void *data) if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) abi_breakage(); break; + + case NFTNL_EXPR_OSF_TTL: + if (mnl_attr_validate(attr, MNL_TYPE_U8) < 0) + abi_breakage(); + break; } tb[type] = attr; @@ -69,6 +81,8 @@ nftnl_expr_osf_build(struct nlmsghdr *nlh, const struct nftnl_expr *e) if (e->flags & (1 << NFTNL_EXPR_OSF_DREG)) mnl_attr_put_u32(nlh, NFTNL_EXPR_OSF_DREG, htonl(osf->dreg)); + if (e->flags & (1 << NFTNL_EXPR_OSF_TTL)) + mnl_attr_put_u8(nlh, NFTNL_EXPR_OSF_TTL, osf->ttl); } static int @@ -85,6 +99,11 @@ nftnl_expr_osf_parse(struct nftnl_expr *e, struct nlattr *attr) e->flags |= (1 << NFTNL_EXPR_OSF_DREG); } + if (tb[NFTA_OSF_TTL]) { + osf->ttl = mnl_attr_get_u8(tb[NFTA_OSF_TTL]); + e->flags |= (1 << NFTNL_EXPR_OSF_TTL); + } + return 0; } @@ -95,7 +114,7 @@ static int nftnl_expr_osf_snprintf_default(char *buf, size_t size, int ret, offset = 0, len = size; if (e->flags & (1 << NFTNL_EXPR_OSF_DREG)) { - ret = snprintf(buf, len, "dreg %u ", osf->dreg); + ret = snprintf(buf, len, "dreg %u ttl %u", osf->dreg, osf->ttl); SNPRINTF_BUFFER_SIZE(ret, len, offset); } @@ -110,6 +129,8 @@ static int nftnl_expr_osf_export(char *buf, size_t size, if (e->flags & (1 << NFTNL_EXPR_OSF_DREG)) nftnl_buf_u32(&b, type, osf->dreg, "dreg"); + if (e->flags & (1 << NFTNL_EXPR_OSF_TTL)) + nftnl_buf_u32(&b, type, osf->ttl, "ttl"); return nftnl_buf_done(&b); } @@ -140,6 +161,9 @@ static bool nftnl_expr_osf_cmp(const struct nftnl_expr *e1, if (e1->flags & (1 << NFTNL_EXPR_OSF_DREG)) eq &= (l1->dreg == l2->dreg); + if (e1->flags & (1 << NFTNL_EXPR_OSF_TTL)) + eq &= (l1->ttl == l2->ttl); + return eq; }