[ovs-dev] [VLAN splinters 10/16] packets: New function eth_pop_vlan(), formerly dp_netdev_pop_vlan().
Ben Pfaff
blp at nicira.com
Wed Nov 16 01:17:08 UTC 2011
An upcoming commit will add a new user.
---
lib/dpif-netdev.c | 20 +-------------------
lib/packets.c | 21 +++++++++++++++++++++
lib/packets.h | 1 +
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index bc93a10..afec1a2 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1034,24 +1034,6 @@ dpif_netdev_wait(struct dpif *dpif)
}
static void
-dp_netdev_pop_vlan(struct ofpbuf *packet)
-{
- struct vlan_eth_header *veh = packet->l2;
- if (packet->size >= sizeof *veh
- && veh->veth_type == htons(ETH_TYPE_VLAN)) {
- struct eth_header tmp;
-
- memcpy(tmp.eth_dst, veh->veth_dst, ETH_ADDR_LEN);
- memcpy(tmp.eth_src, veh->veth_src, ETH_ADDR_LEN);
- tmp.eth_type = veh->veth_next_type;
-
- ofpbuf_pull(packet, VLAN_HEADER_LEN);
- packet->l2 = (char*)packet->l2 + VLAN_HEADER_LEN;
- memcpy(packet->data, &tmp, sizeof tmp);
- }
-}
-
-static void
dp_netdev_set_dl(struct ofpbuf *packet, const struct ovs_key_ethernet *eth_key)
{
struct eth_header *eh = packet->l2;
@@ -1317,7 +1299,7 @@ dp_netdev_execute_actions(struct dp_netdev *dp,
break;
case OVS_ACTION_ATTR_POP_VLAN:
- dp_netdev_pop_vlan(packet);
+ eth_pop_vlan(packet);
break;
case OVS_ACTION_ATTR_SET:
diff --git a/lib/packets.c b/lib/packets.c
index 03f92e3..46a44bd 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -100,6 +100,27 @@ eth_push_vlan(struct ofpbuf *packet, ovs_be16 tci)
packet->l2 = packet->data;
}
+/* Removes outermost VLAN header (if any is present) from 'packet'.
+ *
+ * 'packet->l2' must initially point to 'packet''s Ethernet header. */
+void
+eth_pop_vlan(struct ofpbuf *packet)
+{
+ struct vlan_eth_header *veh = packet->l2;
+ if (packet->size >= sizeof *veh
+ && veh->veth_type == htons(ETH_TYPE_VLAN)) {
+ struct eth_header tmp;
+
+ memcpy(tmp.eth_dst, veh->veth_dst, ETH_ADDR_LEN);
+ memcpy(tmp.eth_src, veh->veth_src, ETH_ADDR_LEN);
+ tmp.eth_type = veh->veth_next_type;
+
+ ofpbuf_pull(packet, VLAN_HEADER_LEN);
+ packet->l2 = (char*)packet->l2 + VLAN_HEADER_LEN;
+ memcpy(packet->data, &tmp, sizeof tmp);
+ }
+}
+
/* Given the IP netmask 'netmask', returns the number of bits of the IP address
* that it specifies, that is, the number of 1-bits in 'netmask'. 'netmask'
* must be a CIDR netmask (see ip_is_cidr()). */
diff --git a/lib/packets.h b/lib/packets.h
index d924492..439a7dd 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -132,6 +132,7 @@ void compose_benign_packet(struct ofpbuf *, const char *tag,
const uint8_t eth_src[ETH_ADDR_LEN]);
void eth_push_vlan(struct ofpbuf *, ovs_be16 tci);
+void eth_pop_vlan(struct ofpbuf *);
/* Example:
*
--
1.7.4.4
More information about the dev
mailing list