- /* Check for a VLAN tag */
- if (flow->dl_type == htons(ETH_TYPE_VLAN)) {
- struct vlan_header *vh = pull_vlan(&b);
- if (vh) {
- flow->dl_type = vh->vlan_next_type;
- flow->dl_vlan = vh->vlan_tci & htons(VLAN_VID_MASK);
- }
- }
- memcpy(flow->dl_src, eth->eth_src, ETH_ADDR_LEN);
- memcpy(flow->dl_dst, eth->eth_dst, ETH_ADDR_LEN);
-
- packet->l3 = b.data;
- if (flow->dl_type == htons(ETH_TYPE_IP)) {
- const struct ip_header *nh = pull_ip(&b);
- if (nh) {
- flow->nw_src = nh->ip_src;
- flow->nw_dst = nh->ip_dst;
- flow->nw_proto = nh->ip_proto;
- packet->l4 = b.data;
- if (!IP_IS_FRAGMENT(nh->ip_frag_off)) {
- if (flow->nw_proto == IP_TYPE_TCP) {
- const struct tcp_header *tcp = pull_tcp(&b);
- if (tcp) {
- flow->tp_src = tcp->tcp_src;
- flow->tp_dst = tcp->tcp_dst;
- packet->l7 = b.data;
- } else {
- /* Avoid tricking other code into thinking that
- * this packet has an L4 header. */
- flow->nw_proto = 0;
- }
- } else if (flow->nw_proto == IP_TYPE_UDP) {
- const struct udp_header *udp = pull_udp(&b);
- if (udp) {
- flow->tp_src = udp->udp_src;
- flow->tp_dst = udp->udp_dst;
- packet->l7 = b.data;
- } else {
- /* Avoid tricking other code into thinking that
- * this packet has an L4 header. */
- flow->nw_proto = 0;
- }
- } else if (flow->nw_proto == IP_TYPE_ICMP) {
- const struct icmp_header *icmp = pull_icmp(&b);
- if (icmp) {
- flow->icmp_type = htons(icmp->icmp_type);
- flow->icmp_code = htons(icmp->icmp_code);
- packet->l7 = b.data;
- } else {
- /* Avoid tricking other code into thinking that
- * this packet has an L4 header. */
- flow->nw_proto = 0;
- }
+ /* Link layer. */
+ eth = b.data;
+ memcpy(flow->dl_src, eth->eth_src, ETH_ADDR_LEN);
+ memcpy(flow->dl_dst, eth->eth_dst, ETH_ADDR_LEN);
+
+ /* dl_type, vlan_tci. */
+ ofpbuf_pull(&b, ETH_ADDR_LEN * 2);
+ if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
+ parse_vlan(&b, flow);
+ }
+ flow->dl_type = parse_ethertype(&b);
+
+ /* Network layer. */
+ packet->l3 = b.data;
+ if (flow->dl_type == htons(ETH_TYPE_IP)) {
+ const struct ip_header *nh = pull_ip(&b);
+ if (nh) {
+ flow->nw_src = get_unaligned_be32(&nh->ip_src);
+ flow->nw_dst = get_unaligned_be32(&nh->ip_dst);
+ flow->nw_tos = nh->ip_tos & IP_DSCP_MASK;
+ flow->nw_proto = nh->ip_proto;
+ packet->l4 = b.data;
+ if (!IP_IS_FRAGMENT(nh->ip_frag_off)) {
+ if (flow->nw_proto == IP_TYPE_TCP) {
+ const struct tcp_header *tcp = pull_tcp(&b);
+ if (tcp) {
+ flow->tp_src = tcp->tcp_src;
+ flow->tp_dst = tcp->tcp_dst;
+ packet->l7 = b.data;
+ }
+ } else if (flow->nw_proto == IP_TYPE_UDP) {
+ const struct udp_header *udp = pull_udp(&b);
+ if (udp) {
+ flow->tp_src = udp->udp_src;
+ flow->tp_dst = udp->udp_dst;
+ packet->l7 = b.data;
+ }
+ } else if (flow->nw_proto == IP_TYPE_ICMP) {
+ const struct icmp_header *icmp = pull_icmp(&b);
+ if (icmp) {
+ flow->icmp_type = htons(icmp->icmp_type);
+ flow->icmp_code = htons(icmp->icmp_code);
+ packet->l7 = b.data;