[ovs-dev] [fin_timeout 2/3] packets: New function packet_get_tcp_flags(), factored out of dpif.

Ben Pfaff blp at nicira.com
Fri Jan 20 01:03:14 UTC 2012


This will acquire a new user in an upcoming commit.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/dpif.c    |    9 +--------
 lib/packets.c |   20 +++++++++++++++++++-
 lib/packets.h |    5 ++++-
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/lib/dpif.c b/lib/dpif.c
index 37c0012..e1698ba 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -679,14 +679,7 @@ dpif_flow_stats_extract(const struct flow *flow, struct ofpbuf *packet,
                         struct dpif_flow_stats *stats)
 {
     memset(stats, 0, sizeof(*stats));
-
-    if ((flow->dl_type == htons(ETH_TYPE_IP)) && packet->l4) {
-        if ((flow->nw_proto == IPPROTO_TCP) && packet->l7) {
-            struct tcp_header *tcp = packet->l4;
-            stats->tcp_flags = TCP_FLAGS(tcp->tcp_ctl);
-        }
-    }
-
+    stats->tcp_flags = packet_get_tcp_flags(packet, flow);
     stats->n_bytes = packet->size;
     stats->n_packets = 1;
 }
diff --git a/lib/packets.c b/lib/packets.c
index eaf3e43..738eb6f 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include "byte-order.h"
 #include "csum.h"
+#include "flow.h"
 #include "dynamic-string.h"
 #include "ofpbuf.h"
 
@@ -478,3 +479,20 @@ packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
         uh->udp_dst = dst;
     }
 }
+
+/* If 'packet' is a TCP packet, returns the TCP flags.  Otherwise, returns 0.
+ *
+ * 'flow' must be the flow corresponding to 'packet' and 'packet''s header
+ * pointers must be properly initialized (e.g. with flow_extract()). */
+uint8_t
+packet_get_tcp_flags(struct ofpbuf *packet, const struct flow *flow)
+{
+    /* XXX IPv6? */
+    if (flow->dl_type == htons(ETH_TYPE_IP) && packet->l4
+        && flow->nw_proto == IPPROTO_TCP && packet->l7) {
+        const struct tcp_header *tcp = packet->l4;
+        return TCP_FLAGS(tcp->tcp_ctl);
+    } else {
+        return 0;
+    }
+}
diff --git a/lib/packets.h b/lib/packets.h
index 78ccfe9..736f58e 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
 
 struct ofpbuf;
 struct ds;
+struct flow;
 
 bool dpid_from_string(const char *s, uint64_t *dpidp);
 
@@ -468,4 +469,6 @@ void packet_set_ipv4(struct ofpbuf *, ovs_be32 src, ovs_be32 dst, uint8_t tos,
 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(struct ofpbuf *, const struct flow *);
+
 #endif /* packets.h */
-- 
1.7.2.5




More information about the dev mailing list