From patchwork Mon Jan 29 21:11:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harsha Sharma X-Patchwork-Id: 867305 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HUG6zjqM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zVhz0115zz9s7s for ; Tue, 30 Jan 2018 08:11:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751434AbeA2VLy (ORCPT ); Mon, 29 Jan 2018 16:11:54 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:45064 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751590AbeA2VLY (ORCPT ); Mon, 29 Jan 2018 16:11:24 -0500 Received: by mail-pg0-f67.google.com with SMTP id m136so5433817pga.12 for ; Mon, 29 Jan 2018 13:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VBSCmf/nmoLSWxACWMSu1sei9GG+x3nkkJ0qmQGPDr0=; b=HUG6zjqMJySTCeguY4fjnVlU1cYwZcPy/8DuYziDzTbzJwDEO2qrxa6bWvgZqF+c0Y Ayu7+K46vQxyYRKq5C9M+GiUaWlBtFqHyZToFvtUOUKQp35BB91h8fTT+ZeYiubW+IfQ Cn+rl3GzqcBfAhJT1cj6Qto7/UnSeAWk69DmeaydokwgzLZzYp8i3bBCTeYW9YcE3e64 MnTwVaIiicO5O7cWbZF/Csfn0roQx33eSSkaPR03A2swljmG4F/bKnNkROWHXICaEWGq sA0HJBFLXfRybSsVUaInMZeCs0XmgWAGR+WrZevjxcdRj6O268o7OCK6TVxdRaLyyaMe /iXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VBSCmf/nmoLSWxACWMSu1sei9GG+x3nkkJ0qmQGPDr0=; b=maO0dHDo1XCvx5/p0XhirTdWEcWldEBICqopLk2od5KKyEL013EoCJ4Y9rO88f8jZu BwUGmMXo2u+d4lVJpdpUyDnzKdH0wRmFIuAlSNoHvpG6z77LugyLBsxymKePC2WAXM7G f+rVXJwVQciFlst0y050PWeFTS1WuLpx0kcb3iUK2ot6y1b2d0uYYFypRJMZbb42tDab VrNJnkscSu6BxiKiHMdhoz+B8MX7kzcoPHNPtIBlmdkk+4jk8uy7pEMCRYVXmWT+qwDM ruiA6P3hOgS1xunCB1rK54mMEyTYVNBW/scUwkd1UZ6bT4PeHhEYmkQF8mCUFsJXPd8K emag== X-Gm-Message-State: AKwxyteNMbd+zHZGD6J6k/l5ZF24l53qqY7wzTBW33Lxl7vdkuI5A4ZX esr3GDDa33e8VO3aGRX4jy8= X-Google-Smtp-Source: AH8x225yfLvE85doQdJ0TV6sOE9Mbli0KwYOe6AvSmRHBol/4zo4YgXcKdFxkiUFwAcshhuhEZgVZw== X-Received: by 2002:a17:902:678b:: with SMTP id g11-v6mr21349566plk.13.1517260283774; Mon, 29 Jan 2018 13:11:23 -0800 (PST) Received: from XDDDDD.iitr.ernet.in ([103.37.201.122]) by smtp.gmail.com with ESMTPSA id y131sm32572448pfg.69.2018.01.29.13.11.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2018 13:11:23 -0800 (PST) From: Harsha Sharma To: pablo@netfilter.org, harshasharmaiitr@gmail.com Cc: netfilter-devel@vger.kernel.org Subject: [PATCH v2] src: parse new handle attribute for tables Date: Tue, 30 Jan 2018 02:41:02 +0530 Message-Id: <20180129211102.12335-1-harshasharmaiitr@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org This patch adds code to parse new handle attribute for tables. Signed-off-by: Harsha Sharma --- Changes in v2: - Remove code for tracing table handle. include/libnftnl/table.h | 3 +++ include/linux/netfilter/nf_tables.h | 2 ++ src/libnftnl.map | 2 ++ src/table.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/include/libnftnl/table.h b/include/libnftnl/table.h index 2e76c45..44017c6 100644 --- a/include/libnftnl/table.h +++ b/include/libnftnl/table.h @@ -22,6 +22,7 @@ enum nftnl_table_attr { NFTNL_TABLE_FAMILY, NFTNL_TABLE_FLAGS, NFTNL_TABLE_USE, + NFTNL_TABLE_HANDLE, __NFTNL_TABLE_MAX }; #define NFTNL_TABLE_MAX (__NFTNL_TABLE_MAX - 1) @@ -37,9 +38,11 @@ const void *nftnl_table_get_data(const struct nftnl_table *t, uint16_t attr, void nftnl_table_set_u8(struct nftnl_table *t, uint16_t attr, uint8_t data); void nftnl_table_set_u32(struct nftnl_table *t, uint16_t attr, uint32_t data); +void nftnl_table_set_u64(struct nftnl_table *t, uint16_t attr, uint64_t data); int nftnl_table_set_str(struct nftnl_table *t, uint16_t attr, const char *str); uint8_t nftnl_table_get_u8(const struct nftnl_table *t, uint16_t attr); uint32_t nftnl_table_get_u32(const struct nftnl_table *t, uint16_t attr); +uint64_t nftnl_table_get_u64(const struct nftnl_table *t, uint16_t attr); const char *nftnl_table_get_str(const struct nftnl_table *t, uint16_t attr); struct nlmsghdr; diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h index 874fa3f..b057d67 100644 --- a/include/linux/netfilter/nf_tables.h +++ b/include/linux/netfilter/nf_tables.h @@ -160,12 +160,14 @@ enum nft_table_flags { * @NFTA_TABLE_NAME: name of the table (NLA_STRING) * @NFTA_TABLE_FLAGS: bitmask of enum nft_table_flags (NLA_U32) * @NFTA_TABLE_USE: number of chains in this table (NLA_U32) + * @NFTA_TABLE_HANDLE: numeric handle of the table (NLA_U64) */ enum nft_table_attributes { NFTA_TABLE_UNSPEC, NFTA_TABLE_NAME, NFTA_TABLE_FLAGS, NFTA_TABLE_USE, + NFTA_TABLE_HANDLE, __NFTA_TABLE_MAX }; #define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1) diff --git a/src/libnftnl.map b/src/libnftnl.map index d59e802..e641824 100644 --- a/src/libnftnl.map +++ b/src/libnftnl.map @@ -8,9 +8,11 @@ global: nftnl_table_get; nftnl_table_set_u8; nftnl_table_set_u32; + nftnl_table_set_u64; nftnl_table_set_str; nftnl_table_get_u8; nftnl_table_get_u32; + nftnl_table_get_u64; nftnl_table_get_str; nftnl_table_parse; nftnl_table_parse_file; diff --git a/src/table.c b/src/table.c index cf61dda..5196db0 100644 --- a/src/table.c +++ b/src/table.c @@ -34,6 +34,7 @@ struct nftnl_table { uint32_t table_flags; uint32_t use; uint32_t flags; + uint64_t handle; }; struct nftnl_table *nftnl_table_alloc(void) @@ -67,6 +68,7 @@ void nftnl_table_unset(struct nftnl_table *t, uint16_t attr) xfree(t->name); break; case NFTNL_TABLE_FLAGS: + case NFTNL_TABLE_HANDLE: case NFTNL_TABLE_FAMILY: break; case NFTNL_TABLE_USE: @@ -79,6 +81,7 @@ EXPORT_SYMBOL(nftnl_table_unset); static uint32_t nftnl_table_validate[NFTNL_TABLE_MAX + 1] = { [NFTNL_TABLE_FLAGS] = sizeof(uint32_t), [NFTNL_TABLE_FAMILY] = sizeof(uint32_t), + [NFTNL_TABLE_HANDLE] = sizeof(uint64_t), }; int nftnl_table_set_data(struct nftnl_table *t, uint16_t attr, @@ -96,6 +99,9 @@ int nftnl_table_set_data(struct nftnl_table *t, uint16_t attr, if (!t->name) return -1; break; + case NFTNL_TABLE_HANDLE: + t->handle = *((uint64_t *)data); + break; case NFTNL_TABLE_FLAGS: t->table_flags = *((uint32_t *)data); break; @@ -123,6 +129,12 @@ void nftnl_table_set_u32(struct nftnl_table *t, uint16_t attr, uint32_t val) } EXPORT_SYMBOL(nftnl_table_set_u32); +void nftnl_table_set_u64(struct nftnl_table *t, uint16_t attr, uint64_t val) +{ + nftnl_table_set_data(t, attr, &val, sizeof(uint64_t)); +} +EXPORT_SYMBOL(nftnl_table_set_u64); + void nftnl_table_set_u8(struct nftnl_table *t, uint16_t attr, uint8_t val) { nftnl_table_set_data(t, attr, &val, sizeof(uint8_t)); @@ -145,6 +157,9 @@ const void *nftnl_table_get_data(const struct nftnl_table *t, uint16_t attr, case NFTNL_TABLE_NAME: *data_len = strlen(t->name) + 1; return t->name; + case NFTNL_TABLE_HANDLE: + *data_len = sizeof(uint64_t); + return &t->handle; case NFTNL_TABLE_FLAGS: *data_len = sizeof(uint32_t); return &t->table_flags; @@ -173,6 +188,13 @@ uint32_t nftnl_table_get_u32(const struct nftnl_table *t, uint16_t attr) } EXPORT_SYMBOL(nftnl_table_get_u32); +uint64_t nftnl_table_get_u64(const struct nftnl_table *t, uint16_t attr) +{ + const void *ret = nftnl_table_get(t, attr); + return ret == NULL ? 0 : *((uint64_t *)ret); +} +EXPORT_SYMBOL(nftnl_table_get_u64); + uint8_t nftnl_table_get_u8(const struct nftnl_table *t, uint16_t attr) { const void *ret = nftnl_table_get(t, attr); @@ -190,6 +212,8 @@ void nftnl_table_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nftnl_ta { if (t->flags & (1 << NFTNL_TABLE_NAME)) mnl_attr_put_strz(nlh, NFTA_TABLE_NAME, t->name); + if (t->flags & (1 << NFTNL_TABLE_HANDLE)) + mnl_attr_put_u64(nlh, NFTA_TABLE_HANDLE, htobe64(t->handle)); if (t->flags & (1 << NFTNL_TABLE_FLAGS)) mnl_attr_put_u32(nlh, NFTA_TABLE_FLAGS, htonl(t->table_flags)); } @@ -208,6 +232,10 @@ static int nftnl_table_parse_attr_cb(const struct nlattr *attr, void *data) if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) abi_breakage(); break; + case NFTA_TABLE_HANDLE: + if (mnl_attr_validate(attr, MNL_TYPE_U64) < 0) + abi_breakage(); + break; case NFTA_TABLE_FLAGS: case NFTA_TABLE_USE: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) @@ -243,6 +271,10 @@ int nftnl_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_table *t) t->use = ntohl(mnl_attr_get_u32(tb[NFTA_TABLE_USE])); t->flags |= (1 << NFTNL_TABLE_USE); } + if (tb[NFTA_TABLE_HANDLE]) { + t->handle = be64toh(mnl_attr_get_u64(tb[NFTA_TABLE_HANDLE])); + t->flags |= (1 << NFTNL_TABLE_HANDLE); + } t->family = nfg->nfgen_family; t->flags |= (1 << NFTNL_TABLE_FAMILY); @@ -358,6 +390,8 @@ static int nftnl_table_export(char *buf, size_t size, nftnl_buf_u32(&b, type, t->table_flags, FLAGS); if (t->flags & (1 << NFTNL_TABLE_USE)) nftnl_buf_u32(&b, type, t->use, USE); + if (t->flags & (1 << NFTNL_TABLE_HANDLE)) + nftnl_buf_u64(&b, type, t->handle, HANDLE); nftnl_buf_close(&b, type, TABLE);