From: Ben Pfaff Date: Thu, 5 Apr 2012 17:24:56 +0000 (-0700) Subject: dpif: Include TCP flags in "ovs-dpctl dump-flows" output. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7393104d1a31b5b256e491ec689cc7358f101280;p=openvswitch dpif: Include TCP flags in "ovs-dpctl dump-flows" output. Signed-off-by: Ben Pfaff --- diff --git a/NEWS b/NEWS index ac00335b..9c733520 100644 --- a/NEWS +++ b/NEWS @@ -11,7 +11,7 @@ post-v1.6.0 - ovs-test: - Added support for spawning ovs-test server from the client. - Now ovs-test is able to automatically create test bridges and ports. - + - "ovs-dpctl dump-flows" now prints observed TCP flags in TCP flows. v1.6.0 - xx xxx xxxx diff --git a/lib/dpif.c b/lib/dpif.c index 35df1e5d..e000e13d 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -697,7 +697,10 @@ dpif_flow_stats_format(const struct dpif_flow_stats *stats, struct ds *s) } else { ds_put_format(s, "never"); } - /* XXX tcp_flags? */ + if (stats->tcp_flags) { + ds_put_cstr(s, ", flags:"); + packet_format_tcp_flags(s, stats->tcp_flags); + } } /* Deletes all flows from 'dpif'. Returns 0 if successful, otherwise a diff --git a/lib/packets.c b/lib/packets.c index 8fb7f6b0..cd9227b3 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -496,3 +496,40 @@ packet_get_tcp_flags(const struct ofpbuf *packet, const struct flow *flow) return 0; } } + +/* Appends a string representation of the TCP flags value 'tcp_flags' + * (e.g. obtained via packet_get_tcp_flags() or TCP_FLAGS) to 's', in the + * format used by tcpdump. */ +void +packet_format_tcp_flags(struct ds *s, uint8_t tcp_flags) +{ + if (!tcp_flags) { + ds_put_cstr(s, "none"); + return; + } + + if (tcp_flags & TCP_SYN) { + ds_put_char(s, 'S'); + } + if (tcp_flags & TCP_FIN) { + ds_put_char(s, 'F'); + } + if (tcp_flags & TCP_PSH) { + ds_put_char(s, 'P'); + } + if (tcp_flags & TCP_RST) { + ds_put_char(s, 'R'); + } + if (tcp_flags & TCP_URG) { + ds_put_char(s, 'U'); + } + if (tcp_flags & TCP_ACK) { + ds_put_char(s, '.'); + } + if (tcp_flags & 0x40) { + ds_put_cstr(s, "[40]"); + } + if (tcp_flags & 0x80) { + ds_put_cstr(s, "[80]"); + } +} diff --git a/lib/packets.h b/lib/packets.h index 34a8b4ea..dc71b053 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -470,5 +470,6 @@ void packet_set_tcp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst); void packet_set_udp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst); uint8_t packet_get_tcp_flags(const struct ofpbuf *, const struct flow *); +void packet_format_tcp_flags(struct ds *, uint8_t); #endif /* packets.h */ diff --git a/tests/test-netflow.c b/tests/test-netflow.c index 7d028874..5f30c636 100644 --- a/tests/test-netflow.c +++ b/tests/test-netflow.c @@ -24,6 +24,7 @@ #include "command-line.h" #include "daemon.h" +#include "dynamic-string.h" #include "netflow.h" #include "ofpbuf.h" #include "packets.h" @@ -87,31 +88,10 @@ print_netflow(struct ofpbuf *buf) printf(", TCP %"PRIu16" > %"PRIu16, ntohs(rec->src_port), ntohs(rec->dst_port)); if (rec->tcp_flags) { - putchar(' '); - if (rec->tcp_flags & TCP_SYN) { - putchar('S'); - } - if (rec->tcp_flags & TCP_FIN) { - putchar('F'); - } - if (rec->tcp_flags & TCP_PSH) { - putchar('P'); - } - if (rec->tcp_flags & TCP_RST) { - putchar('R'); - } - if (rec->tcp_flags & TCP_URG) { - putchar('U'); - } - if (rec->tcp_flags & TCP_ACK) { - putchar('.'); - } - if (rec->tcp_flags & 0x40) { - printf("[40]"); - } - if (rec->tcp_flags & 0x80) { - printf("[80]"); - } + struct ds s = DS_EMPTY_INITIALIZER; + packet_format_tcp_flags(&s, rec->tcp_flags); + printf(" %s", ds_cstr(&s)); + ds_destroy(&s); } break;