From bbf77c173d5a8a49d867875351f887b05cf190a6 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Sun, 3 Feb 2008 11:24:07 +0000 Subject: From: Eric leblond This patch clarifies code which will be modified in next patch. --- util/db.c | 2 +- util/printflow.c | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'util') diff --git a/util/db.c b/util/db.c index 1702acc..f72ce79 100644 --- a/util/db.c +++ b/util/db.c @@ -90,7 +90,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi) return -ENOMEM; } - sprintf(mi->stmt, "CALL %s(", procedure); + sprintf(mi->stmt, "SELECT %s(", procedure); mi->stmt_val = mi->stmt + strlen(mi->stmt); diff --git a/util/printflow.c b/util/printflow.c index aa354d4..1d0b9e9 100644 --- a/util/printflow.c +++ b/util/printflow.c @@ -28,6 +28,19 @@ #include #include +enum printflow_fields { + PRINTFLOW_IP_SADDR = 0, + PRINTFLOW_IP_DADDR, + PRINTFLOW_IP_PROTOCOL, + PRINTFLOW_L4_SPORT, + PRINTFLOW_L4_DPORT, + PRINTFLOW_RAW_PKTLEN, + PRINTFLOW_RAW_PKTCOUNT, + PRINTFLOW_ICMP_CODE, + PRINTFLOW_ICMP_TYPE, + PRINTFLOW_DIR, +}; + struct ulogd_key printflow_keys[] = { { .type = ULOGD_RET_IPADDR, @@ -94,38 +107,38 @@ int printflow_print(struct ulogd_key *res, char *buf) { char *buf_cur = buf; - if (pp_is_valid(res, 9)) + if (pp_is_valid(res, PRINTFLOW_DIR)) buf_cur += sprintf(buf_cur, "DIR=%s ", - GET_VALUE(res, 9).b ? "REPLY" : "ORIG "); + GET_VALUE(res, PRINTFLOW_DIR).b ? "REPLY" : "ORIG "); - if (pp_is_valid(res, 0)) + if (pp_is_valid(res, PRINTFLOW_IP_SADDR)) buf_cur += sprintf(buf_cur, "SRC=%s ", inet_ntoa( (struct in_addr) {htonl(GET_VALUE(res, 0).ui32)})); - if (pp_is_valid(res, 1)) + if (pp_is_valid(res, PRINTFLOW_IP_DADDR)) buf_cur += sprintf(buf_cur, "DST=%s ", inet_ntoa( (struct in_addr) {htonl(GET_VALUE(res, 1).ui32)})); - if (!pp_is_valid(res, 2)) + if (!pp_is_valid(res, PRINTFLOW_IP_PROTOCOL)) goto out; - switch (GET_VALUE(res, 2).ui8) { + switch (GET_VALUE(res, PRINTFLOW_IP_PROTOCOL).ui8) { case IPPROTO_TCP: buf_cur += sprintf(buf_cur, "PROTO=TCP "); - pp_print(buf_cur, "SPT", res, 3, ui16); - pp_print(buf_cur, "DPT", res, 4, ui16); + pp_print(buf_cur, "SPT", res, PRINTFLOW_L4_SPORT, ui16); + pp_print(buf_cur, "DPT", res, PRINTFLOW_L4_DPORT, ui16); break; case IPPROTO_UDP: buf_cur += sprintf(buf_cur, "PROTO=UDP "); - pp_print(buf_cur, "SPT", res, 3, ui16); - pp_print(buf_cur, "DPT", res, 4, ui16); + pp_print(buf_cur, "SPT", res, PRINTFLOW_L4_SPORT, ui16); + pp_print(buf_cur, "DPT", res, PRINTFLOW_L4_DPORT, ui16); break; case IPPROTO_ICMP: buf_cur += sprintf(buf_cur, "PROTO=ICMP "); - pp_print(buf_cur, "TYPE", res, 7, ui8); - pp_print(buf_cur, "CODE", res, 8, ui8); + pp_print(buf_cur, "TYPE", res, PRINTFLOW_ICMP_CODE, ui8); + pp_print(buf_cur, "CODE", res, PRINTFLOW_ICMP_TYPE, ui8); break; case IPPROTO_ESP: @@ -137,13 +150,13 @@ int printflow_print(struct ulogd_key *res, char *buf) break; default: - pp_print(buf_cur, "PROTO", res, 2, ui8); + pp_print(buf_cur, "PROTO", res, PRINTFLOW_IP_PROTOCOL, ui8); break; } out: - pp_print(buf_cur, "PKTS", res, 6, ui32); - pp_print(buf_cur, "BYTES", res, 5, ui32); + pp_print(buf_cur, "PKTS", res, PRINTFLOW_RAW_PKTCOUNT, ui32); + pp_print(buf_cur, "BYTES", res, PRINTFLOW_RAW_PKTLEN, ui32); strcat(buf_cur, "\n"); return 0; -- cgit v1.2.3