[ovs-dev] [PATCH 17/17] packets, ofproto-dpif: factor out packet update logic
Isaku Yamahata
yamahata at valinux.co.jp
Wed Jul 18 11:41:31 UTC 2012
The split out function will be used for goto-table instruction.
Signed-off-by: Isaku Yamahata <yamahata at valinux.co.jp>
---
lib/packets.c | 42 ++++++++++++++++++++++++++++++++++++++++++
lib/packets.h | 2 ++
ofproto/ofproto-dpif.c | 39 ++-------------------------------------
3 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/lib/packets.c b/lib/packets.c
index 5729167..d99de4e 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -589,3 +589,45 @@ packet_format_tcp_flags(struct ds *s, uint8_t tcp_flags)
ds_put_cstr(s, "[80]");
}
}
+
+void
+packet_update(struct ofpbuf *packet, const struct flow *flow)
+{
+ struct eth_header *eh;
+ if (packet->l2 == NULL || packet->l3 == NULL) {
+ return;
+ }
+
+ eth_pop_vlan(packet);
+ eh = packet->l2;
+
+ /* If the Ethernet type is less than ETH_TYPE_MIN, it's likely an 802.2
+ * LLC frame. Calculating the Ethernet type of these frames is more
+ * trouble than seems appropriate for a simple assertion. */
+ assert(ntohs(eh->eth_type) < ETH_TYPE_MIN
+ || eh->eth_type == flow->dl_type);
+
+ memcpy(eh->eth_src, flow->dl_src, sizeof eh->eth_src);
+ memcpy(eh->eth_dst, flow->dl_dst, sizeof eh->eth_dst);
+
+ if (flow->vlan_tci & htons(VLAN_CFI)) {
+ eth_push_vlan(packet, flow->vlan_tci);
+ }
+
+ if (packet->l4) {
+ if (flow->dl_type == htons(ETH_TYPE_IP)) {
+ packet_set_ipv4(packet, flow->nw_src, flow->nw_dst,
+ flow->nw_tos, flow->nw_ttl);
+ }
+
+ if (packet->l7) {
+ if (flow->nw_proto == IPPROTO_TCP) {
+ packet_set_tcp_port(packet, flow->tp_src,
+ flow->tp_dst);
+ } else if (flow->nw_proto == IPPROTO_UDP) {
+ packet_set_udp_port(packet, flow->tp_src,
+ flow->tp_dst);
+ }
+ }
+ }
+}
diff --git a/lib/packets.h b/lib/packets.h
index ad5631d..b49c75a 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -508,4 +508,6 @@ 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);
+void packet_update(struct ofpbuf *packet, const struct flow *flow);
+
#endif /* packets.h */
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index d272cc0..95abb74 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -47,6 +47,7 @@
#include "ofp-print.h"
#include "ofproto-dpif-governor.h"
#include "ofproto-dpif-sflow.h"
+#include "packets.h"
#include "poll-loop.h"
#include "simap.h"
#include "timer.h"
@@ -5099,43 +5100,7 @@ execute_controller_action(struct action_xlate_ctx *ctx, int len,
}
packet = ofpbuf_clone(ctx->packet);
-
- if (packet->l2 && packet->l3) {
- struct eth_header *eh;
-
- eth_pop_vlan(packet);
- eh = packet->l2;
-
- /* If the Ethernet type is less than ETH_TYPE_MIN, it's likely an 802.2
- * LLC frame. Calculating the Ethernet type of these frames is more
- * trouble than seems appropriate for a simple assertion. */
- assert(ntohs(eh->eth_type) < ETH_TYPE_MIN
- || eh->eth_type == ctx->flow.dl_type);
-
- memcpy(eh->eth_src, ctx->flow.dl_src, sizeof eh->eth_src);
- memcpy(eh->eth_dst, ctx->flow.dl_dst, sizeof eh->eth_dst);
-
- if (ctx->flow.vlan_tci & htons(VLAN_CFI)) {
- eth_push_vlan(packet, ctx->flow.vlan_tci);
- }
-
- if (packet->l4) {
- if (ctx->flow.dl_type == htons(ETH_TYPE_IP)) {
- packet_set_ipv4(packet, ctx->flow.nw_src, ctx->flow.nw_dst,
- ctx->flow.nw_tos, ctx->flow.nw_ttl);
- }
-
- if (packet->l7) {
- if (ctx->flow.nw_proto == IPPROTO_TCP) {
- packet_set_tcp_port(packet, ctx->flow.tp_src,
- ctx->flow.tp_dst);
- } else if (ctx->flow.nw_proto == IPPROTO_UDP) {
- packet_set_udp_port(packet, ctx->flow.tp_src,
- ctx->flow.tp_dst);
- }
- }
- }
- }
+ packet_update(packet, &ctx->flow);
pin.packet = packet->data;
pin.packet_len = packet->size;
--
1.7.1.1
More information about the dev
mailing list