All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Leblond <eric@inl.fr>
To: netfilter-devel@vger.kernel.org
Cc: Pierre Chifflier <chifflier@inl.fr>, Eric leblond <eric@inl.fr>
Subject: [PATCH 34/34]  Modify insert functions to accept standard integers to avoid casts.
Date: Sat,  2 Feb 2008 22:24:29 +0100	[thread overview]
Message-ID: <1201987472938-git-send-email-eric@inl.fr> (raw)
In-Reply-To: <12019874721483-git-send-email-eric@inl.fr>

From: Pierre Chifflier <chifflier@inl.fr>

This patch fixes the type of some fields in the SQL schema to sync
with datatype of the corresponding ulogd2 keys.

Signed-off-by: Pierre Chifflier <chifflier@inl.fr>
Signed-off-by: Eric leblond <eric@inl.fr>
---
:100644 100644 a488c11... 740a7ef... M	doc/pgsql-ulogd2.sql
:100644 100644 0882357... 7ece626... M	output/pgsql/ulogd_output_PGSQL.c
 doc/pgsql-ulogd2.sql              |  150 +++++++++++++++++--------------------
 output/pgsql/ulogd_output_PGSQL.c |    6 +-
 2 files changed, 72 insertions(+), 84 deletions(-)

diff --git a/doc/pgsql-ulogd2.sql b/doc/pgsql-ulogd2.sql
index a488c11..740a7ef 100644
--- a/doc/pgsql-ulogd2.sql
+++ b/doc/pgsql-ulogd2.sql
@@ -52,8 +52,8 @@ CREATE TABLE ulog2 (
   ip_ttl smallint default NULL,
   ip_totlen smallint default NULL,
   ip_ihl smallint default NULL,
-  ip_csum smallint default NULL,
-  ip_id smallint default NULL,
+  ip_csum integer default NULL,
+  ip_id integer default NULL,
   ip_fragoff smallint default NULL,
   timestamp timestamp NOT NULL default 'now'
 ) WITH (OIDS=FALSE);
@@ -77,16 +77,16 @@ CREATE TABLE tcp (
   _tcp_id bigint PRIMARY KEY UNIQUE NOT NULL,
   tcp_sport integer default NULL,
   tcp_dport integer default NULL,
-  tcp_seq integer default NULL,
+  tcp_seq bigint default NULL,
   tcp_ackseq integer default NULL,
-  tcp_window smallint default NULL,
-  tcp_urg smallint default NULL,
-  tcp_urgp smallint  default NULL,
-  tcp_ack smallint default NULL,
-  tcp_psh smallint default NULL,
-  tcp_rst smallint default NULL,
-  tcp_syn smallint default NULL,
-  tcp_fin smallint default NULL
+  tcp_window integer default NULL,
+  tcp_urg boolean default NULL,
+  tcp_urgp integer  default NULL,
+  tcp_ack boolean default NULL,
+  tcp_psh boolean default NULL,
+  tcp_rst boolean default NULL,
+  tcp_syn boolean default NULL,
+  tcp_fin boolean default NULL
 ) WITH (OIDS=FALSE);
 
 CREATE INDEX tcp_sport ON tcp(tcp_sport);
@@ -172,8 +172,8 @@ CREATE OR REPLACE VIEW ulog AS
         icmp_echoseq,
         icmp_gateway,
         icmp_fragmtu
-        FROM ulog2 INNER JOIN tcp ON ulog2._id = tcp._tcp_id INNER JOIN udp ON ulog2._id = udp._udp_id
-                INNER JOIN icmp ON ulog2._id = icmp._icmp_id INNER JOIN mac ON ulog2._id = mac._mac_id;
+        FROM ulog2 LEFT JOIN tcp ON ulog2._id = tcp._tcp_id LEFT JOIN udp ON ulog2._id = udp._udp_id
+                LEFT JOIN icmp ON ulog2._id = icmp._icmp_id LEFT JOIN mac ON ulog2._id = mac._mac_id;
 
 -- shortcuts
 CREATE OR REPLACE VIEW view_tcp_quad AS
@@ -306,10 +306,10 @@ CREATE OR REPLACE FUNCTION INSERT_IP_PACKET(
                 IN oob_mark integer,
                 IN oob_in varchar(32),
                 IN oob_out varchar(32),
-                IN oob_family smallint,
+                IN oob_family integer,
                 IN ip_saddr_str inet,
                 IN ip_daddr_str inet,
-                IN ip_protocol smallint
+                IN ip_protocol integer
         )
 RETURNS bigint AS $$
         INSERT INTO ulog2 (oob_time_sec,oob_time_usec,oob_prefix,oob_mark,
@@ -326,17 +326,17 @@ CREATE OR REPLACE FUNCTION INSERT_IP_PACKET_FULL(
                 IN oob_mark integer,
                 IN oob_in varchar(32),
                 IN oob_out varchar(32),
-                IN oob_family smallint,
+                IN oob_family integer,
                 IN ip_saddr_str inet,
                 IN ip_daddr_str inet,
-                IN ip_protocol smallint,
-                IN ip_tos smallint,
-                IN ip_ttl smallint,
-                IN ip_totlen smallint,
-                IN ip_ihl smallint,
-                IN ip_csum smallint,
-                IN ip_id smallint,
-                IN ip_fragoff smallint
+                IN ip_protocol integer,
+                IN ip_tos integer,
+                IN ip_ttl integer,
+                IN ip_totlen integer,
+                IN ip_ihl integer,
+                IN ip_csum integer,
+                IN ip_id integer,
+                IN ip_fragoff integer
         )
 RETURNS bigint AS $$
         INSERT INTO ulog2 (oob_time_sec,oob_time_usec,oob_prefix,oob_mark,
@@ -350,16 +350,16 @@ CREATE OR REPLACE FUNCTION INSERT_TCP_FULL(
                 IN tcp_id bigint,
                 IN tcp_sport integer,
                 IN tcp_dport integer,
-                IN tcp_seq integer,
+                IN tcp_seq bigint,
                 IN tcp_ackseq integer,
-                IN tcp_window smallint,
-                IN tcp_urg smallint,
-                IN tcp_urgp smallint ,
-                IN tcp_ack smallint,
-                IN tcp_psh smallint,
-                IN tcp_rst smallint,
-                IN tcp_syn smallint,
-                IN tcp_fin smallint
+                IN tcp_window integer,
+                IN tcp_urg boolean,
+                IN tcp_urgp integer ,
+                IN tcp_ack boolean,
+                IN tcp_psh boolean,
+                IN tcp_rst boolean,
+                IN tcp_syn boolean,
+                IN tcp_fin boolean
         )
 RETURNS bigint AS $$
         INSERT INTO tcp (_tcp_id,tcp_sport,tcp_dport,tcp_seq,tcp_ackseq,tcp_window,tcp_urg,
@@ -369,10 +369,10 @@ RETURNS bigint AS $$
 $$ LANGUAGE SQL SECURITY INVOKER;
 
 CREATE OR REPLACE FUNCTION INSERT_UDP(
-                IN tcp_id bigint,
-                IN tcp_sport integer,
-                IN tcp_dport integer,
-                IN tcp_len smallint
+                IN udp_id bigint,
+                IN udp_sport integer,
+                IN udp_dport integer,
+                IN udp_len integer
         )
 RETURNS bigint AS $$
         INSERT INTO udp (_udp_id,udp_sport,udp_dport,udp_len)
@@ -382,12 +382,12 @@ $$ LANGUAGE SQL SECURITY INVOKER;
 
 CREATE OR REPLACE FUNCTION INSERT_ICMP(
                 IN icmp_id bigint,
-                IN icmp_type smallint,
-                IN icmp_code smallint,
-                IN icmp_echoid smallint,
-                IN icmp_echoseq smallint,
+                IN icmp_type integer,
+                IN icmp_code integer,
+                IN icmp_echoid integer,
+                IN icmp_echoseq integer,
                 IN icmp_gateway integer,
-                IN icmp_fragmtu smallint 
+                IN icmp_fragmtu integer 
         )
 RETURNS bigint AS $$
         INSERT INTO icmp (_icmp_id,icmp_type,icmp_code,icmp_echoid,icmp_echoseq,icmp_gateway,icmp_fragmtu)
@@ -395,18 +395,6 @@ RETURNS bigint AS $$
         SELECT currval('ulog2__id_seq');
 $$ LANGUAGE SQL SECURITY INVOKER;
 
-CREATE OR REPLACE FUNCTION INSERT_MAC(
-                IN tcp_id bigint,
-                IN udp_sport integer,
-                IN udp_dport integer,
-                IN udp_len smallint
-        )
-RETURNS bigint AS $$
-        INSERT INTO udp (_udp_id,udp_sport,udp_dport,udp_len)
-                VALUES ($1,$2,$3,$4);
-        SELECT currval('ulog2__id_seq');
-$$ LANGUAGE SQL SECURITY INVOKER;
-
 -- this function requires plpgsql
 -- su -c "createlang plpgsql ulog2" postgres
 CREATE OR REPLACE FUNCTION INSERT_PACKET_FULL(
@@ -416,38 +404,38 @@ CREATE OR REPLACE FUNCTION INSERT_PACKET_FULL(
                 IN oob_mark integer,
                 IN oob_in varchar(32),
                 IN oob_out varchar(32),
-                IN oob_family smallint,
+                IN oob_family integer,
                 IN ip_saddr_str inet,
                 IN ip_daddr_str inet,
-                IN ip_protocol smallint,
-                IN ip_tos smallint,
-                IN ip_ttl smallint,
-                IN ip_totlen smallint,
-                IN ip_ihl smallint,
-                IN ip_csum smallint,
-                IN ip_id smallint,
-                IN ip_fragoff smallint,
+                IN ip_protocol integer,
+                IN ip_tos integer,
+                IN ip_ttl integer,
+                IN ip_totlen integer,
+                IN ip_ihl integer,
+                IN ip_csum integer,
+                IN ip_id integer,
+                IN ip_fragoff integer,
                 IN tcp_sport integer,
                 IN tcp_dport integer,
-                IN tcp_seq integer,
+                IN tcp_seq bigint,
                 IN tcp_ackseq integer,
-                IN tcp_window smallint,
-                IN tcp_urg smallint,
-                IN tcp_urgp smallint ,
-                IN tcp_ack smallint,
-                IN tcp_psh smallint,
-                IN tcp_rst smallint,
-                IN tcp_syn smallint,
-                IN tcp_fin smallint,
+                IN tcp_window integer,
+                IN tcp_urg boolean,
+                IN tcp_urgp integer ,
+                IN tcp_ack boolean,
+                IN tcp_psh boolean,
+                IN tcp_rst boolean,
+                IN tcp_syn boolean,
+                IN tcp_fin boolean,
                 IN udp_sport integer,
                 IN udp_dport integer,
-                IN udp_len smallint,
-                IN icmp_type smallint,
-                IN icmp_code smallint,
-                IN icmp_echoid smallint,
-                IN icmp_echoseq smallint,
+                IN udp_len integer,
+                IN icmp_type integer,
+                IN icmp_code integer,
+                IN icmp_echoid integer,
+                IN icmp_echoseq integer,
                 IN icmp_gateway integer,
-                IN icmp_fragmtu smallint 
+                IN icmp_fragmtu integer 
         )
 RETURNS bigint AS $$
 DECLARE
@@ -455,11 +443,11 @@ DECLARE
 BEGIN
         _id := INSERT_IP_PACKET_FULL($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17) ;
         IF (ip_protocol = 6) THEN
-                SELECT INSERT_TCP_FULL(_id,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29);
+                PERFORM INSERT_TCP_FULL(_id,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29);
         ELSIF (ip_protocol = 17) THEN
-                SELECT INSERT_UDP(_id,$30,$31,$32,$33);
+                PERFORM INSERT_UDP(_id,$30,$31,$32,$33);
         ELSIF (ip_protocol = 1) THEN
-                SELECT INSERT_ICMP(_id,$34,$35,$36,$37,$38,$39);
+                PERFORM INSERT_ICMP(_id,$34,$35,$36,$37,$38,$39);
         END IF;
         RETURN _id;
 END
diff --git a/output/pgsql/ulogd_output_PGSQL.c b/output/pgsql/ulogd_output_PGSQL.c
index 0882357..7ece626 100644
--- a/output/pgsql/ulogd_output_PGSQL.c
+++ b/output/pgsql/ulogd_output_PGSQL.c
@@ -280,8 +280,7 @@ static int open_db_pgsql(struct ulogd_pluginstance *upi)
 static int escape_string_pgsql(struct ulogd_pluginstance *upi,
 			       char *dst, const char *src, unsigned int len)
 {
-	PQescapeString(dst, src, strlen(src)); 
-	return 0;
+	return PQescapeString(dst, src, strlen(src)); 
 }
 
 static int execute_pgsql(struct ulogd_pluginstance *upi,
@@ -290,7 +289,8 @@ static int execute_pgsql(struct ulogd_pluginstance *upi,
 	struct pgsql_instance *pi = (struct pgsql_instance *) upi->private;
 
 	pi->pgres = PQexec(pi->dbh, stmt);
-	if (!pi->pgres || PQresultStatus(pi->pgres) != PGRES_COMMAND_OK) {
+	if (!(pi->pgres && (PQresultStatus(pi->pgres) == PGRES_COMMAND_OK)
+		|| (PQresultStatus(pi->pgres) == PGRES_TUPLES_OK))) {
 		ulogd_log(ULOGD_ERROR, "execute failed (%s)\n",
 			  PQerrorMessage(pi->dbh));
 		return -1;
-- 
1.5.2.5


  reply	other threads:[~2008-02-02 22:16 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-02 21:23 [ULOGD RFC PATCH 0/34] Eric Leblond
2008-02-02 21:23 ` [PATCH 01/34] Introduce new SQL schema Eric Leblond
2008-02-02 21:23   ` [PATCH 02/34] [Resend] Do not propagate one conntrack event via 2 messages Eric Leblond
2008-02-02 21:23     ` [PATCH 03/34] Use an enum to clarify code Eric Leblond
2008-02-02 21:23       ` [PATCH 04/34] Adapt printflow for one conntrack entry per line format Eric Leblond
2008-02-02 21:24         ` [PATCH 05/34] Add --info option which displays information about plugin Eric Leblond
2008-02-02 21:24           ` [PATCH 06/34] New version of SQL schema Eric Leblond
2008-02-02 21:24             ` [PATCH 07/34] Changed sighup_handler_print to fallback to continue using old descriptor on new file opening failure Eric Leblond
2008-02-02 21:24               ` [PATCH 08/34] Added explicit null termination of the hostname buffer Eric Leblond
2008-02-02 21:24                 ` [PATCH 09/34] For OPRINT, changed sighup_handler_print to fallback to continue using old descriptor on new file opening failure Eric Leblond
2008-02-02 21:24                   ` [PATCH 10/34] Add some missing line break Eric Leblond
2008-02-02 21:24                     ` [PATCH 11/34] Put O at the real end of the string Eric Leblond
2008-02-02 21:24                       ` [PATCH 12/34] Changed to show pcap file name when open failed Eric Leblond
2008-02-02 21:24                         ` [PATCH 13/34] Display filename in the other error case Eric Leblond
2008-02-02 21:24                           ` [PATCH 14/34] Request at least autoconf 2.50 (needed for large file support macro) Eric Leblond
2008-02-02 21:24                             ` [PATCH 15/34] MySQL client library does not reconnect automatically since 5.0 Eric Leblond
2008-02-02 21:24                               ` [PATCH 16/34] Introduce IP2STR module which convert IP to string Eric Leblond
2008-02-02 21:24                                 ` [PATCH 17/34] Suppress key relative to IPv6 address Eric Leblond
2008-02-02 21:24                                   ` [PATCH 18/34] Update schema for PostgreSQL Eric Leblond
2008-02-02 21:24                                     ` [PATCH 19/34] Fix options for pgsql module Eric Leblond
2008-02-02 21:24                                       ` [PATCH 20/34] Mark ID as inactive (sequence in pg schema) Eric Leblond
2008-02-02 21:24                                         ` [PATCH 21/34] Add IP2BIN module: convert IP address to binary string Eric Leblond
2008-02-02 21:24                                           ` [PATCH 22/34] Fix description and indenting Eric Leblond
2008-02-02 21:24                                             ` [PATCH 23/34] Print RAW as raw string Eric Leblond
2008-02-02 21:24                                               ` [PATCH 24/34] Fix IPv4 output Eric Leblond
2008-02-02 21:24                                                 ` [PATCH 25/34] Set oob.family as VALID key Eric Leblond
2008-02-02 21:24                                                   ` [PATCH 26/34] Modify IPv6 parser to fill oob_family Eric Leblond
2008-02-02 21:24                                                     ` [PATCH 27/34] Free insertion function result (mysql) Eric Leblond
2008-02-02 21:24                                                       ` [PATCH 28/34] Update SQL schema Eric Leblond
2008-02-02 21:24                                                         ` [PATCH 29/34] Fix some place were oob_family was used instead of _oob_family Eric Leblond
2008-02-02 21:24                                                           ` [PATCH 30/34] Convert SQL procedure to function call Eric Leblond
2008-02-02 21:24                                                             ` [PATCH 31/34] Switch from INNER JOIN to LEFT JOIN in ulog view Eric Leblond
2008-02-02 21:24                                                               ` [PATCH 32/34] Add state extension Eric Leblond
2008-02-02 21:24                                                                 ` [PATCH 33/34] ULOGD_RET_IPADDR is for IPv4 or IPv6 address: fix description Eric Leblond
2008-02-02 21:24                                                                   ` Eric Leblond [this message]
2008-02-03 12:28                                                                     ` [PATCH 34/34] Modify insert functions to accept standard integers to avoid casts Pablo Neira Ayuso
2008-02-03 12:29                                                                   ` [PATCH 33/34] ULOGD_RET_IPADDR is for IPv4 or IPv6 address: fix description Pablo Neira Ayuso
2008-02-03 12:27                                                                 ` [PATCH 32/34] Add state extension Pablo Neira Ayuso
2008-02-03 12:26                                                               ` [PATCH 31/34] Switch from INNER JOIN to LEFT JOIN in ulog view Pablo Neira Ayuso
2008-02-03 12:26                                                             ` [PATCH 30/34] Convert SQL procedure to function call Pablo Neira Ayuso
2008-02-03 12:24                                                           ` [PATCH 29/34] Fix some place were oob_family was used instead of _oob_family Pablo Neira Ayuso
2008-02-03 12:23                                                         ` [PATCH 28/34] Update SQL schema Pablo Neira Ayuso
2008-02-03 12:22                                                       ` [PATCH 27/34] Free insertion function result (mysql) Pablo Neira Ayuso
2008-02-03 12:21                                                     ` [PATCH 26/34] Modify IPv6 parser to fill oob_family Pablo Neira Ayuso
2008-02-03 12:17                                                   ` [PATCH 25/34] Set oob.family as VALID key Pablo Neira Ayuso
2008-02-03 12:10                                                 ` [PATCH 24/34] Fix IPv4 output Pablo Neira Ayuso
2008-02-03 17:36                                                   ` Eric Leblond
2008-02-03 12:09                                               ` [PATCH 23/34] Print RAW as raw string Pablo Neira Ayuso
2008-02-03 12:07                                             ` [PATCH 22/34] Fix description and indenting Pablo Neira Ayuso
2008-02-03 12:04                                           ` [PATCH 21/34] Add IP2BIN module: convert IP address to binary string Pablo Neira Ayuso
2008-02-03 12:02                                         ` [PATCH 20/34] Mark ID as inactive (sequence in pg schema) Pablo Neira Ayuso
2008-02-03 12:01                                       ` [PATCH 19/34] Fix options for pgsql module Pablo Neira Ayuso
2008-02-03 11:59                                     ` [PATCH 18/34] Update schema for PostgreSQL Pablo Neira Ayuso
2008-02-03 11:59                                   ` [PATCH 17/34] Suppress key relative to IPv6 address Pablo Neira Ayuso
2008-02-03 11:55                                 ` [PATCH 16/34] Introduce IP2STR module which convert IP to string Pablo Neira Ayuso
2008-02-03 11:45                               ` [PATCH 15/34] MySQL client library does not reconnect automatically since 5.0 Pablo Neira Ayuso
2008-02-03 11:44                             ` [PATCH 14/34] Request at least autoconf 2.50 (needed for large file support macro) Pablo Neira Ayuso
2008-02-03 11:43                           ` [PATCH 13/34] Display filename in the other error case Pablo Neira Ayuso
2008-02-03 11:42                         ` [PATCH 12/34] Changed to show pcap file name when open failed Pablo Neira Ayuso
2008-02-03 11:41                       ` [PATCH 11/34] Put O at the real end of the string Pablo Neira Ayuso
2008-02-03 11:40                     ` [PATCH 10/34] Add some missing line break Pablo Neira Ayuso
2008-02-03 11:38                   ` [PATCH 09/34] For OPRINT, changed sighup_handler_print to fallback to continue using old descriptor on new file opening failure Pablo Neira Ayuso
2008-02-03 11:36                 ` [PATCH 08/34] Added explicit null termination of the hostname buffer Pablo Neira Ayuso
2008-02-03 11:35               ` [PATCH 07/34] Changed sighup_handler_print to fallback to continue using old descriptor on new file opening failure Pablo Neira Ayuso
2008-02-03 11:34             ` [PATCH 06/34] New version of SQL schema Pablo Neira Ayuso
2008-02-03 11:30           ` [PATCH 05/34] Add --info option which displays information about plugin Pablo Neira Ayuso
2008-02-03 11:25         ` [PATCH 04/34] Adapt printflow for one conntrack entry per line format Pablo Neira Ayuso
2008-02-03 11:23       ` [PATCH 03/34] Use an enum to clarify code Pablo Neira Ayuso
2008-02-03  9:27     ` [PATCH 02/34] [Resend] Do not propagate one conntrack event via 2 messages Holger Eitzenberger
2008-02-03 11:53       ` Eric Leblond
2008-02-19 14:05         ` Eric Leblond
2008-02-19 15:31           ` Pablo Neira Ayuso
2008-02-19 15:49             ` [ULOGD2 PATCH] Sends one message for each connection event instead of two Eric Leblond
2008-02-19 16:01               ` Pablo Neira Ayuso
2008-02-03 11:22   ` [PATCH 01/34] Introduce new SQL schema Pablo Neira Ayuso
2008-02-03 11:50     ` Eric Leblond
2008-02-03 11:57       ` Eric Leblond
2008-02-03 12:17         ` Pablo Neira Ayuso
2008-02-06 10:04           ` [PATCH] Use index2name capabilities of libnfnetlink in IFINDEX filter Eric Leblond
2008-02-07  6:45             ` Pablo Neira Ayuso
2008-02-03 12:14       ` [PATCH 01/34] Introduce new SQL schema Pablo Neira Ayuso
2008-02-03 12:37       ` Holger Eitzenberger
2008-02-03 17:34         ` Pierre Chifflier
2008-02-03 23:54           ` Pablo Neira Ayuso
2008-02-03  0:32 ` [ULOGD RFC PATCH 0/34] Pablo Neira Ayuso

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=1201987472938-git-send-email-eric@inl.fr \
    --to=eric@inl.fr \
    --cc=chifflier@inl.fr \
    --cc=netfilter-devel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.