From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>, Florian Westphal <fw@strlen.de>
Subject: [PATCH nft v3 03/10] proto: add proto_desc_id enumeration
Date: Tue, 17 Dec 2019 12:27:06 +0100 [thread overview]
Message-ID: <20191217112713.6017-4-fw@strlen.de> (raw)
In-Reply-To: <20191217112713.6017-1-fw@strlen.de>
From: Pablo Neira Ayuso <pablo@netfilter.org>
This allows to uniquely identify the protocol description.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
include/proto.h | 27 +++++++++++++++++++++++++++
src/proto.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
diff --git a/include/proto.h b/include/proto.h
index fab48c1bb30c..1771ba8e8d8c 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -63,10 +63,34 @@ struct proto_hdr_template {
#define PROTO_UPPER_MAX 16
#define PROTO_HDRS_MAX 20
+enum proto_desc_id {
+ PROTO_DESC_UNKNOWN = 0,
+ PROTO_DESC_AH,
+ PROTO_DESC_ESP,
+ PROTO_DESC_COMP,
+ PROTO_DESC_ICMP,
+ PROTO_DESC_IGMP,
+ PROTO_DESC_UDP,
+ PROTO_DESC_UDPLITE,
+ PROTO_DESC_TCP,
+ PROTO_DESC_DCCP,
+ PROTO_DESC_SCTP,
+ PROTO_DESC_TH,
+ PROTO_DESC_IP,
+ PROTO_DESC_IP6,
+ PROTO_DESC_ICMPV6,
+ PROTO_DESC_ARP,
+ PROTO_DESC_VLAN,
+ PROTO_DESC_ETHER,
+ __PROTO_DESC_MAX
+};
+#define PROTO_DESC_MAX (__PROTO_DESC_MAX - 1)
+
/**
* struct proto_desc - protocol header description
*
* @name: protocol name
+ * @id: protocol identifier
* @base: header base
* @checksum_key: key of template containing checksum
* @protocol_key: key of template containing upper layer protocol description
@@ -77,6 +101,7 @@ struct proto_hdr_template {
*/
struct proto_desc {
const char *name;
+ enum proto_desc_id id;
enum proto_bases base;
unsigned int checksum_key;
unsigned int protocol_key;
@@ -160,6 +185,8 @@ extern const struct proto_desc *proto_find_upper(const struct proto_desc *base,
extern int proto_find_num(const struct proto_desc *base,
const struct proto_desc *desc);
+extern const struct proto_desc *proto_find_desc(enum proto_desc_id desc_id);
+
enum eth_hdr_fields {
ETHHDR_INVALID,
ETHHDR_DADDR,
diff --git a/src/proto.c b/src/proto.c
index 40ce590efd12..7d001501d7d2 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -227,6 +227,7 @@ void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
const struct proto_desc proto_ah = {
.name = "ah",
+ .id = PROTO_DESC_AH,
.base = PROTO_BASE_TRANSPORT_HDR,
.protocol_key = AHHDR_NEXTHDR,
.protocols = {
@@ -263,6 +264,7 @@ const struct proto_desc proto_ah = {
const struct proto_desc proto_esp = {
.name = "esp",
+ .id = PROTO_DESC_ESP,
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[ESPHDR_SPI] = ESPHDR_FIELD("spi", spi),
@@ -279,6 +281,7 @@ const struct proto_desc proto_esp = {
const struct proto_desc proto_comp = {
.name = "comp",
+ .id = PROTO_DESC_COMP,
.base = PROTO_BASE_TRANSPORT_HDR,
.protocol_key = COMPHDR_NEXTHDR,
.protocols = {
@@ -343,6 +346,7 @@ const struct datatype icmp_type_type = {
const struct proto_desc proto_icmp = {
.name = "icmp",
+ .id = PROTO_DESC_ICMP,
.base = PROTO_BASE_TRANSPORT_HDR,
.checksum_key = ICMPHDR_CHECKSUM,
.templates = {
@@ -395,6 +399,7 @@ const struct datatype igmp_type_type = {
const struct proto_desc proto_igmp = {
.name = "igmp",
+ .id = PROTO_DESC_IGMP,
.base = PROTO_BASE_TRANSPORT_HDR,
.checksum_key = IGMPHDR_CHECKSUM,
.templates = {
@@ -415,6 +420,7 @@ const struct proto_desc proto_igmp = {
const struct proto_desc proto_udp = {
.name = "udp",
+ .id = PROTO_DESC_UDP,
.base = PROTO_BASE_TRANSPORT_HDR,
.checksum_key = UDPHDR_CHECKSUM,
.templates = {
@@ -427,6 +433,7 @@ const struct proto_desc proto_udp = {
const struct proto_desc proto_udplite = {
.name = "udplite",
+ .id = PROTO_DESC_UDPLITE,
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[UDPHDR_SPORT] = INET_SERVICE("sport", struct udphdr, source),
@@ -472,6 +479,7 @@ const struct datatype tcp_flag_type = {
const struct proto_desc proto_tcp = {
.name = "tcp",
+ .id = PROTO_DESC_TCP,
.base = PROTO_BASE_TRANSPORT_HDR,
.checksum_key = TCPHDR_CHECKSUM,
.templates = {
@@ -534,6 +542,7 @@ const struct datatype dccp_pkttype_type = {
const struct proto_desc proto_dccp = {
.name = "dccp",
+ .id = PROTO_DESC_DCCP,
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[DCCPHDR_SPORT] = INET_SERVICE("sport", struct dccp_hdr, dccph_sport),
@@ -552,6 +561,7 @@ const struct proto_desc proto_dccp = {
const struct proto_desc proto_sctp = {
.name = "sctp",
+ .id = PROTO_DESC_SCTP,
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[SCTPHDR_SPORT] = INET_SERVICE("sport", struct sctphdr, source),
@@ -566,6 +576,7 @@ const struct proto_desc proto_sctp = {
*/
const struct proto_desc proto_th = {
.name = "th",
+ .id = PROTO_DESC_TH,
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[THDR_SPORT] = INET_SERVICE("sport", struct udphdr, source),
@@ -648,6 +659,7 @@ const struct datatype ecn_type = {
const struct proto_desc proto_ip = {
.name = "ip",
+ .id = PROTO_DESC_IP,
.base = PROTO_BASE_NETWORK_HDR,
.checksum_key = IPHDR_CHECKSUM,
.protocols = {
@@ -744,6 +756,7 @@ const struct datatype icmp6_type_type = {
const struct proto_desc proto_icmp6 = {
.name = "icmpv6",
+ .id = PROTO_DESC_ICMPV6,
.base = PROTO_BASE_TRANSPORT_HDR,
.checksum_key = ICMP6HDR_CHECKSUM,
.templates = {
@@ -771,6 +784,7 @@ const struct proto_desc proto_icmp6 = {
const struct proto_desc proto_ip6 = {
.name = "ip6",
+ .id = PROTO_DESC_IP6,
.base = PROTO_BASE_NETWORK_HDR,
.protocols = {
PROTO_LINK(IPPROTO_ESP, &proto_esp),
@@ -892,6 +906,7 @@ const struct datatype arpop_type = {
const struct proto_desc proto_arp = {
.name = "arp",
+ .id = PROTO_DESC_ARP,
.base = PROTO_BASE_NETWORK_HDR,
.templates = {
[ARPHDR_HRD] = ARPHDR_FIELD("htype", htype),
@@ -925,6 +940,7 @@ const struct proto_desc proto_arp = {
const struct proto_desc proto_vlan = {
.name = "vlan",
+ .id = PROTO_DESC_VLAN,
.base = PROTO_BASE_LL_HDR,
.protocol_key = VLANHDR_TYPE,
.length = sizeof(struct vlan_hdr) * BITS_PER_BYTE,
@@ -996,6 +1012,7 @@ const struct datatype ethertype_type = {
const struct proto_desc proto_eth = {
.name = "ether",
+ .id = PROTO_DESC_ETHER,
.base = PROTO_BASE_LL_HDR,
.protocol_key = ETHHDR_TYPE,
.length = sizeof(struct ether_header) * BITS_PER_BYTE,
@@ -1034,3 +1051,32 @@ const struct proto_desc proto_netdev = {
[0] = PROTO_META_TEMPLATE("protocol", ðertype_type, NFT_META_PROTOCOL, 16),
},
};
+
+static const struct proto_desc *proto_definitions[PROTO_DESC_MAX + 1] = {
+ [PROTO_DESC_AH] = &proto_ah,
+ [PROTO_DESC_ESP] = &proto_esp,
+ [PROTO_DESC_COMP] = &proto_comp,
+ [PROTO_DESC_ICMP] = &proto_icmp,
+ [PROTO_DESC_IGMP] = &proto_igmp,
+ [PROTO_DESC_UDP] = &proto_udp,
+ [PROTO_DESC_UDPLITE] = &proto_udplite,
+ [PROTO_DESC_TCP] = &proto_tcp,
+ [PROTO_DESC_DCCP] = &proto_dccp,
+ [PROTO_DESC_SCTP] = &proto_sctp,
+ [PROTO_DESC_TH] = &proto_th,
+ [PROTO_DESC_IP] = &proto_ip,
+ [PROTO_DESC_IP6] = &proto_ip6,
+ [PROTO_DESC_ICMPV6] = &proto_icmp6,
+ [PROTO_DESC_ARP] = &proto_arp,
+ [PROTO_DESC_VLAN] = &proto_vlan,
+ [PROTO_DESC_ETHER] = &proto_eth,
+};
+
+const struct proto_desc *proto_find_desc(enum proto_desc_id desc_id)
+{
+ if (desc_id >= PROTO_DESC_UNKNOWN &&
+ desc_id <= PROTO_DESC_MAX)
+ return proto_definitions[desc_id];
+
+ return NULL;
+}
--
2.24.1
next prev parent reply other threads:[~2019-12-17 11:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-17 11:27 [PATCH nft v3 00/10] add typeof keyword Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 01/10] parser: add a helper for concat expression handling Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 02/10] src: store expr, not dtype to track data in sets Florian Westphal
2019-12-17 11:27 ` Florian Westphal [this message]
2019-12-17 11:27 ` [PATCH nft v3 04/10] expr: add expr_ops_by_type() Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 05/10] parser: add typeof keyword for declarations Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 06/10] src: add "typeof" build/parse/print support Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 07/10] mnl: round up the map data size too Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 08/10] evaluate: print a hint about 'typeof' syntax on 0 keylen Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 09/10] doc: mention 'typeof' as alternative to 'type' keyword Florian Westphal
2019-12-17 11:27 ` [PATCH nft v3 10/10] tests: add typeof test cases Florian Westphal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191217112713.6017-4-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox