diff mbox series

[ovs-dev,v3,2/5] conntrack: Add function ct_print_conn_info().

Message ID 1506397906-120886-2-git-send-email-dlu998@gmail.com
State Accepted
Headers show
Series [ovs-dev,v3,1/5] conntrack: Create nat_conn_keys_insert(). | expand

Commit Message

Darrell Ball Sept. 26, 2017, 3:51 a.m. UTC
A new debug function is added and used in a
subsequent patch.

Acked-by: Antonio Fischetti <antonio.fischetti@intel.com>
Signed-off-by: Darrell Ball <dlu998@gmail.com>
---
 lib/conntrack.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

Comments

Darrell Ball Sept. 26, 2017, 3:56 a.m. UTC | #1
Note that this patch gave me a checkpatch error on this line
+        if (RL_ON) {                                                        \

which I ignored since I did not see a valid reason for the complaint.

Darrell



On 9/25/17, 8:53 PM, "ovs-dev-bounces@openvswitch.org on behalf of Darrell Ball" <ovs-dev-bounces@openvswitch.org on behalf of dlu998@gmail.com> wrote:

    A new debug function is added and used in a
    subsequent patch.
    
    Acked-by: Antonio Fischetti <antonio.fischetti@intel.com>
    Signed-off-by: Darrell Ball <dlu998@gmail.com>
    ---
     lib/conntrack.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     1 file changed, 58 insertions(+)
    
    diff --git a/lib/conntrack.c b/lib/conntrack.c
    index cccba10..6da42bb 100644
    --- a/lib/conntrack.c
    +++ b/lib/conntrack.c
    @@ -67,6 +67,9 @@ enum ct_alg_mode {
         CT_TFTP_MODE,
     };
     
    +void ct_print_conn_info(struct conn *c, char *log_msg, enum vlog_level vll,
    +                        bool force, bool rl_on);
    +
     static bool conn_key_extract(struct conntrack *, struct dp_packet *,
                                  ovs_be16 dl_type, struct conn_lookup_ctx *,
                                  uint16_t zone);
    @@ -223,6 +226,61 @@ conn_key_cmp(const struct conn_key *key1, const struct conn_key *key2)
         return 1;
     }
     
    +void
    +ct_print_conn_info(struct conn *c, char *log_msg, enum vlog_level vll,
    +                   bool force, bool rl_on)
    +{
    +#define CT_VLOG(RL_ON, LEVEL, ...)                                          \
    +    do {                                                                    \
    +        if (RL_ON) {                                                        \
    +            static struct vlog_rate_limit rl_ = VLOG_RATE_LIMIT_INIT(5, 5); \
    +            vlog_rate_limit(&this_module, LEVEL, &rl_, __VA_ARGS__);        \
    +        } else {                                                            \
    +            vlog(&this_module, LEVEL, __VA_ARGS__);                         \
    +        }                                                                   \
    +    } while (0)
    +
    +    if (OVS_UNLIKELY(force || vlog_is_enabled(&this_module, vll))) {
    +        if (c->key.dl_type == htons(ETH_TYPE_IP)) {
    +            CT_VLOG(rl_on, vll, "%s: src ip "IP_FMT" dst ip "IP_FMT" rev src "
    +                    "ip "IP_FMT" rev dst ip "IP_FMT" src/dst ports "
    +                    "%"PRIu16"/%"PRIu16" rev src/dst ports "
    +                    "%"PRIu16"/%"PRIu16" zone/rev zone "
    +                    "%"PRIu16"/%"PRIu16" nw_proto/rev nw_proto "
    +                    "%"PRIu8"/%"PRIu8, log_msg,
    +                    IP_ARGS(c->key.src.addr.ipv4_aligned),
    +                    IP_ARGS(c->key.dst.addr.ipv4_aligned),
    +                    IP_ARGS(c->rev_key.src.addr.ipv4_aligned),
    +                    IP_ARGS(c->rev_key.dst.addr.ipv4_aligned),
    +                    ntohs(c->key.src.port), ntohs(c->key.dst.port),
    +                    ntohs(c->rev_key.src.port), ntohs(c->rev_key.dst.port),
    +                    c->key.zone, c->rev_key.zone, c->key.nw_proto,
    +                    c->rev_key.nw_proto);
    +        } else {
    +            char ip6_s[INET6_ADDRSTRLEN];
    +            inet_ntop(AF_INET6, &c->key.src.addr.ipv6, ip6_s, sizeof ip6_s);
    +            char ip6_d[INET6_ADDRSTRLEN];
    +            inet_ntop(AF_INET6, &c->key.dst.addr.ipv6, ip6_d, sizeof ip6_d);
    +            char ip6_rs[INET6_ADDRSTRLEN];
    +            inet_ntop(AF_INET6, &c->rev_key.src.addr.ipv6, ip6_rs,
    +                      sizeof ip6_rs);
    +            char ip6_rd[INET6_ADDRSTRLEN];
    +            inet_ntop(AF_INET6, &c->rev_key.dst.addr.ipv6, ip6_rd,
    +                      sizeof ip6_rd);
    +
    +            CT_VLOG(rl_on, vll, "%s: src ip %s dst ip %s rev src ip %s"
    +                    " rev dst ip %s src/dst ports %"PRIu16"/%"PRIu16
    +                    " rev src/dst ports %"PRIu16"/%"PRIu16" zone/rev zone "
    +                    "%"PRIu16"/%"PRIu16" nw_proto/rev nw_proto "
    +                    "%"PRIu8"/%"PRIu8, log_msg, ip6_s, ip6_d, ip6_rs,
    +                    ip6_rd, ntohs(c->key.src.port), ntohs(c->key.dst.port),
    +                    ntohs(c->rev_key.src.port), ntohs(c->rev_key.dst.port),
    +                    c->key.zone, c->rev_key.zone, c->key.nw_proto,
    +                    c->rev_key.nw_proto);
    +        }
    +    }
    +}
    +
     /* Initializes the connection tracker 'ct'.  The caller is responsible for
      * calling 'conntrack_destroy()', when the instance is not needed anymore */
     void
    -- 
    1.9.1
    
    _______________________________________________
    dev mailing list
    dev@openvswitch.org
    https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openvswitch.org_mailman_listinfo_ovs-2Ddev&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=BVhFA09CGX7JQ5Ih-uZnsw&m=FtGc7ekw4Jj5RMIiyX1uN9tCiUFXlXHa2fT0_pi0Gn0&s=eVYai0adcvgdXIlnXtLVJPJJQwyhybqOsuBHkXHBze4&e=
diff mbox series

Patch

diff --git a/lib/conntrack.c b/lib/conntrack.c
index cccba10..6da42bb 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -67,6 +67,9 @@  enum ct_alg_mode {
     CT_TFTP_MODE,
 };
 
+void ct_print_conn_info(struct conn *c, char *log_msg, enum vlog_level vll,
+                        bool force, bool rl_on);
+
 static bool conn_key_extract(struct conntrack *, struct dp_packet *,
                              ovs_be16 dl_type, struct conn_lookup_ctx *,
                              uint16_t zone);
@@ -223,6 +226,61 @@  conn_key_cmp(const struct conn_key *key1, const struct conn_key *key2)
     return 1;
 }
 
+void
+ct_print_conn_info(struct conn *c, char *log_msg, enum vlog_level vll,
+                   bool force, bool rl_on)
+{
+#define CT_VLOG(RL_ON, LEVEL, ...)                                          \
+    do {                                                                    \
+        if (RL_ON) {                                                        \
+            static struct vlog_rate_limit rl_ = VLOG_RATE_LIMIT_INIT(5, 5); \
+            vlog_rate_limit(&this_module, LEVEL, &rl_, __VA_ARGS__);        \
+        } else {                                                            \
+            vlog(&this_module, LEVEL, __VA_ARGS__);                         \
+        }                                                                   \
+    } while (0)
+
+    if (OVS_UNLIKELY(force || vlog_is_enabled(&this_module, vll))) {
+        if (c->key.dl_type == htons(ETH_TYPE_IP)) {
+            CT_VLOG(rl_on, vll, "%s: src ip "IP_FMT" dst ip "IP_FMT" rev src "
+                    "ip "IP_FMT" rev dst ip "IP_FMT" src/dst ports "
+                    "%"PRIu16"/%"PRIu16" rev src/dst ports "
+                    "%"PRIu16"/%"PRIu16" zone/rev zone "
+                    "%"PRIu16"/%"PRIu16" nw_proto/rev nw_proto "
+                    "%"PRIu8"/%"PRIu8, log_msg,
+                    IP_ARGS(c->key.src.addr.ipv4_aligned),
+                    IP_ARGS(c->key.dst.addr.ipv4_aligned),
+                    IP_ARGS(c->rev_key.src.addr.ipv4_aligned),
+                    IP_ARGS(c->rev_key.dst.addr.ipv4_aligned),
+                    ntohs(c->key.src.port), ntohs(c->key.dst.port),
+                    ntohs(c->rev_key.src.port), ntohs(c->rev_key.dst.port),
+                    c->key.zone, c->rev_key.zone, c->key.nw_proto,
+                    c->rev_key.nw_proto);
+        } else {
+            char ip6_s[INET6_ADDRSTRLEN];
+            inet_ntop(AF_INET6, &c->key.src.addr.ipv6, ip6_s, sizeof ip6_s);
+            char ip6_d[INET6_ADDRSTRLEN];
+            inet_ntop(AF_INET6, &c->key.dst.addr.ipv6, ip6_d, sizeof ip6_d);
+            char ip6_rs[INET6_ADDRSTRLEN];
+            inet_ntop(AF_INET6, &c->rev_key.src.addr.ipv6, ip6_rs,
+                      sizeof ip6_rs);
+            char ip6_rd[INET6_ADDRSTRLEN];
+            inet_ntop(AF_INET6, &c->rev_key.dst.addr.ipv6, ip6_rd,
+                      sizeof ip6_rd);
+
+            CT_VLOG(rl_on, vll, "%s: src ip %s dst ip %s rev src ip %s"
+                    " rev dst ip %s src/dst ports %"PRIu16"/%"PRIu16
+                    " rev src/dst ports %"PRIu16"/%"PRIu16" zone/rev zone "
+                    "%"PRIu16"/%"PRIu16" nw_proto/rev nw_proto "
+                    "%"PRIu8"/%"PRIu8, log_msg, ip6_s, ip6_d, ip6_rs,
+                    ip6_rd, ntohs(c->key.src.port), ntohs(c->key.dst.port),
+                    ntohs(c->rev_key.src.port), ntohs(c->rev_key.dst.port),
+                    c->key.zone, c->rev_key.zone, c->key.nw_proto,
+                    c->rev_key.nw_proto);
+        }
+    }
+}
+
 /* Initializes the connection tracker 'ct'.  The caller is responsible for
  * calling 'conntrack_destroy()', when the instance is not needed anymore */
 void