Skip to contentSkip to conversation

datatype: Replace getnameinfo() by internal lookup table

PATCH Superseded Elise Lennion 2 participants 2 messages Nov 23, 2016 – Nov 24, 2016 netfilter

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 datatype: Replace getnameinfo() by internal lookup table

To avoid exceeding the inputs number limit of the flex scanner used.

Using port number as index, to map service names in the table, results in a very sparse table, so a new struct is needed to associate ports with names.

---

The services list are all well-known and registered ports of my local /etc/services file.

 include/datatype.h |  11 ++++
 src/datatype.c     | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 162 insertions(+), 8 deletions(-)
include/datatype.h +11 -0
index 9f3f711..9c34c50 100644
@@ -172,6 +172,17 @@ struct symbolic_constant {
 	uint64_t			value;
 };
 
+/**
+ * struct port_servname - port <-> service name mapping
+ *
+ * @port: port number
+ * @name: service name
+ */
+struct port_servname {
+	uint16_t			port;
+	char				*name;
+};
+
 #define SYMBOL(id, v)	{ .identifier = (id), .value = (v) }
 #define SYMBOL_LIST_END	(struct symbolic_constant) { }
 
src/datatype.c +151 -8

173 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

Hi Elise,

Quoted 5 lines · Elise Lennion

To avoid exceeding the inputs number limit of the flex scanner used.

Using port number as index, to map service names in the table, results in a very sparse table, so a new struct is needed to associate ports with names.

Please, indicate what /etc/services you have used, ie. your linux distro version, so that info remains here for the record.

More comments below.

Quoted 37 lines

---

The services list are all well-known and registered ports of my local /etc/services file.

 include/datatype.h |  11 ++++
 src/datatype.c     | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 162 insertions(+), 8 deletions(-)
include/datatype.h +11 -0
index 9f3f711..9c34c50 100644
@@ -172,6 +172,17 @@ struct symbolic_constant {
 	uint64_t			value;
 };
 
+/**
+ * struct port_servname - port <-> service name mapping
+ *
+ * @port: port number
+ * @name: service name
+ */
+struct port_servname {
+	uint16_t			port;
+	char				*name;
+};
+
 #define SYMBOL(id, v)	{ .identifier = (id), .value = (v) }
 #define SYMBOL_LIST_END	(struct symbolic_constant) { }
 
src/datatype.c +0 -0
index 1e40287..85b261d 100644

src/datatype.c line 31

Quoted 4 lines
src/datatype.c +1 -0
@@ -28,6 +28,156 @@
 
 #include <netinet/ip_icmp.h>
 
+static const struct port_servname services[] = {

Given that this is long, please, place this and nft_service_lookup() under a new file, src/services.c.

src/datatype.c line 32

Quoted 1 line
src/datatype.c +1 -0
+	{1, "tcpmux"}, {7, "echo"}, {9, "discard"},

We use symbol_table for these definitions instead, eg.

        static const struct symbol_table icmp_code_tbl = {
                ...
                .sym_tbl        = &icmp_code_tbl,

If you attach the symbol table that defines the services to the inet_service_type definition, then "nft describe tcp dport" will also display the available service names.

BTW, on a different front, the binary search in this patch is useful, you can probably integrate this into the core, I mean symbolic_constant_print(). Only problem is that we would need an explicit size in struct symbol_table, but that shouldn't be a problem. And update many spots in the code, but that should be fine. You can follow up with a patch that applies on top of this to add this binary search approach.

Thanks.