const union odp_action *a, int n_actions,
gfp_t gfp)
{
- u16 tci, mask;
-
- if (a->type == ODPAT_SET_VLAN_VID) {
- tci = ntohs(a->vlan_vid.vlan_vid);
- mask = VLAN_VID_MASK;
- } else {
- tci = a->vlan_pcp.vlan_pcp << VLAN_PCP_SHIFT;
- mask = VLAN_PCP_MASK;
- }
+ __be16 mask = a->dl_tci.mask;
+ __be16 tci = a->dl_tci.tci;
skb = make_writable(skb, VLAN_HLEN, gfp);
if (!skb)
vh = vlan_eth_hdr(skb);
old_tci = vh->h_vlan_TCI;
- vh->h_vlan_TCI = htons((ntohs(vh->h_vlan_TCI) & ~mask) | tci);
+ vh->h_vlan_TCI = (vh->h_vlan_TCI & ~mask) | tci;
if (OVS_CB(skb)->ip_summed == OVS_CSUM_COMPLETE) {
__be16 diff[] = { ~old_tci, vh->h_vlan_TCI };
/* GSO can change the checksum type so update.*/
compute_ip_summed(segs, true);
- segs = __vlan_put_tag(segs, tci);
+ segs = __vlan_put_tag(segs, ntohs(tci));
err = -ENOMEM;
if (segs) {
err = execute_actions(dp, segs,
* e.g. vconfig(8)), so call the software-only version
* __vlan_put_tag() directly instead.
*/
- skb = __vlan_put_tag(skb, tci);
+ skb = __vlan_put_tag(skb, ntohs(tci));
if (!skb)
return ERR_PTR(-ENOMEM);
skb = make_writable(skb, 0, gfp);
if (skb)
vlan_pull_tag(skb);
-
return skb;
}
OVS_CB(skb)->tun_id = a->tunnel.tun_id;
break;
- case ODPAT_SET_VLAN_VID:
- case ODPAT_SET_VLAN_PCP:
+ case ODPAT_SET_DL_TCI:
skb = modify_vlan_tci(dp, skb, key, a, n_actions, gfp);
if (IS_ERR(skb))
return PTR_ERR(skb);
for (i = 0; i < actions->n_actions; i++) {
const union odp_action *a = &actions->actions[i];
+ __be16 mask;
+
switch (a->type) {
case ODPAT_CONTROLLER:
case ODPAT_STRIP_VLAN:
return -EINVAL;
break;
- case ODPAT_SET_VLAN_VID:
- if (a->vlan_vid.vlan_vid & htons(~VLAN_VID_MASK))
+ case ODPAT_SET_DL_TCI:
+ mask = a->dl_tci.mask;
+ if (mask != htons(VLAN_VID_MASK) &&
+ mask != htons(VLAN_PCP_MASK) &&
+ mask != htons(VLAN_VID_MASK | VLAN_PCP_MASK))
return -EINVAL;
- break;
-
- case ODPAT_SET_VLAN_PCP:
- if (a->vlan_pcp.vlan_pcp
- & ~(VLAN_PCP_MASK >> VLAN_PCP_SHIFT))
+ if (a->dl_tci.tci & ~mask)
return -EINVAL;
break;
return;
qp = (struct qtag_prefix *) skb->data;
- key->dl_vlan = qp->tci & htons(VLAN_VID_MASK);
- key->dl_vlan_pcp = (ntohs(qp->tci) & VLAN_PCP_MASK) >> VLAN_PCP_SHIFT;
+ key->dl_tci = qp->tci | htons(ODP_TCI_PRESENT);
__skb_pull(skb, sizeof(struct qtag_prefix));
}
* Ethernet header
* @in_port: port number on which @skb was received.
* @key: output flow key
+ * @is_frag: set to 1 if @skb contains an IPv4 fragment, or to 0 if @skb does
+ * not contain an IPv4 packet or if it is not a fragment.
*
* The caller must ensure that skb->len >= ETH_HLEN.
*
memset(key, 0, sizeof *key);
key->tun_id = OVS_CB(skb)->tun_id;
key->in_port = in_port;
- key->dl_vlan = htons(ODP_VLAN_NONE);
*is_frag = false;
/*
return skb;
}
+
+/* All of these were introduced in a single commit preceding 2.6.33, so
+ * presumably all of them or none of them are present. */
+#ifndef VLAN_PRIO_MASK
+#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
+#define VLAN_PRIO_SHIFT 13
+#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */
+#define VLAN_TAG_PRESENT VLAN_CFI_MASK
+#endif
+
#endif /* linux/if_vlan.h wrapper */
uint16_t error; /* Used by ODP_FLOW_GET. */
};
+/*
+ * The datapath protocol adopts the Linux convention for TCI fields: if an
+ * 802.1Q header is present then its TCI value is used verbatim except that the
+ * CFI bit (0x1000) is always set to 1, and all-bits-zero indicates no 802.1Q
+ * header.
+ */
+#define ODP_TCI_PRESENT 0x1000 /* CFI bit */
+
struct odp_flow_key {
ovs_be32 tun_id; /* Encapsulating tunnel ID. */
ovs_be32 nw_src; /* IP source address. */
ovs_be32 nw_dst; /* IP destination address. */
uint16_t in_port; /* Input switch port. */
- ovs_be16 dl_vlan; /* Input VLAN. */
+ ovs_be16 dl_tci; /* All zeros if 802.1Q header absent,
+ * ODP_TCI_PRESENT set if present. */
ovs_be16 dl_type; /* Ethernet frame type. */
ovs_be16 tp_src; /* TCP/UDP source port. */
ovs_be16 tp_dst; /* TCP/UDP destination port. */
uint8_t dl_dst[6]; /* Ethernet destination address. */
uint8_t nw_proto; /* IP protocol or lower 8 bits of
ARP opcode. */
- uint8_t dl_vlan_pcp; /* Input VLAN priority. */
uint8_t nw_tos; /* IP ToS (DSCP field, 6 bits). */
- uint8_t reserved[3]; /* Align to 32-bits...must be zeroed. */
+ uint32_t reserved[1]; /* Reserved for later use. */
};
/* Flags for ODP_FLOW. */
uint32_t n_flows;
};
-/* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
- * special conditions. All ones is used to match that no VLAN id was
- * set. */
-#define ODP_VLAN_NONE 0xffff
-
/* Action types. */
#define ODPAT_OUTPUT 0 /* Output to switch port. */
#define ODPAT_CONTROLLER 2 /* Send copy to controller. */
-#define ODPAT_SET_VLAN_VID 3 /* Set the 802.1q VLAN id. */
-#define ODPAT_SET_VLAN_PCP 4 /* Set the 802.1q priority. */
+#define ODPAT_SET_DL_TCI 3 /* Set the 802.1q VLAN VID and/or PCP. */
#define ODPAT_STRIP_VLAN 5 /* Strip the 802.1q header. */
#define ODPAT_SET_DL_SRC 6 /* Ethernet source address. */
#define ODPAT_SET_DL_DST 7 /* Ethernet destination address. */
ovs_be32 tun_id; /* Tunnel ID. */
};
-/* Action structure for ODPAT_SET_VLAN_VID. */
-struct odp_action_vlan_vid {
- uint16_t type; /* ODPAT_SET_VLAN_VID. */
- ovs_be16 vlan_vid; /* VLAN id. */
- uint16_t reserved1;
- uint16_t reserved2;
-};
-
-/* Action structure for ODPAT_SET_VLAN_PCP. */
-struct odp_action_vlan_pcp {
- uint16_t type; /* ODPAT_SET_VLAN_PCP. */
- uint8_t vlan_pcp; /* VLAN priority. */
- uint8_t reserved1;
- uint16_t reserved2;
- uint16_t reserved3;
+/* Action structure for ODPAT_SET_DL_TCI. */
+struct odp_action_dl_tci {
+ uint16_t type; /* ODPAT_SET_DL_TCI. */
+ ovs_be16 tci; /* New TCI. Bits not in mask must be zero. */
+ ovs_be16 mask; /* 0x0fff to set VID, 0xe000 to set PCP,
+ * or 0xefff to set both. */
+ uint16_t reserved;
};
/* Action structure for ODPAT_SET_DL_SRC/DST. */
struct odp_action_output output;
struct odp_action_controller controller;
struct odp_action_tunnel tunnel;
- struct odp_action_vlan_vid vlan_vid;
- struct odp_action_vlan_pcp vlan_pcp;
+ struct odp_action_dl_tci dl_tci;
struct odp_action_dl_addr dl_addr;
struct odp_action_nw_addr nw_addr;
struct odp_action_nw_tos nw_tos;
*/
#define ODP_DL_TYPE_NOT_ETH_TYPE 0x05ff
-/* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
- * special conditions. All ones indicates that no VLAN id was set.
- */
-#define ODP_VLAN_NONE 0xffff
-
#endif /* openvswitch/datapath-protocol.h */
case ODPAT_CONTROLLER:
break;
- case ODPAT_SET_VLAN_VID:
+ case ODPAT_SET_DL_TCI:
*mutates = true;
- if (a->vlan_vid.vlan_vid & htons(~VLAN_VID_MASK)) {
+ if (a->dl_tci.mask != htons(VLAN_VID_MASK)
+ && a->dl_tci.mask != htons(VLAN_PCP_MASK)
+ && a->dl_tci.mask != htons(VLAN_VID_MASK | VLAN_PCP_MASK)) {
return EINVAL;
}
- break;
-
- case ODPAT_SET_VLAN_PCP:
- *mutates = true;
- if (a->vlan_pcp.vlan_pcp & ~(VLAN_PCP_MASK >> VLAN_PCP_SHIFT)) {
+ if (a->dl_tci.tci & ~a->dl_tci.mask){
return EINVAL;
}
break;
}
-/* Modify the TCI field of 'packet'. If a VLAN tag is not present, one
- * is added with the TCI field set to 'tci'. If a VLAN tag is present,
- * then 'mask' bits are cleared before 'tci' is logically OR'd into the
- * TCI field.
+/* Modify the TCI field of 'packet'. If a VLAN tag is not present, one is
+ * added with the TCI field set to 'a->tci'. If a VLAN tag is present, then
+ * 'a->mask' bits are cleared before 'a->tci' is logically OR'd into the TCI
+ * field.
*
- * Note that the function does not ensure that 'tci' does not affect
- * bits outside of 'mask'.
+ * Note that the function does not ensure that 'a->tci' does not affect bits
+ * outside of 'a->mask'.
*/
static void
-dp_netdev_modify_vlan_tci(struct ofpbuf *packet, uint16_t tci, uint16_t mask)
+dp_netdev_set_dl_tci(struct ofpbuf *packet, const struct odp_action_dl_tci *a)
{
struct vlan_eth_header *veh;
struct eth_header *eh;
&& eh->eth_type == htons(ETH_TYPE_VLAN)) {
/* Clear 'mask' bits, but maintain other TCI bits. */
veh = packet->l2;
- veh->veth_tci &= ~htons(mask);
- veh->veth_tci |= htons(tci);
+ veh->veth_tci = (veh->veth_tci & ~a->mask) | a->tci;
} else {
/* Insert new 802.1Q header. */
struct vlan_eth_header tmp;
memcpy(tmp.veth_dst, eh->eth_dst, ETH_ADDR_LEN);
memcpy(tmp.veth_src, eh->eth_src, ETH_ADDR_LEN);
tmp.veth_type = htons(ETH_TYPE_VLAN);
- tmp.veth_tci = htons(tci);
+ tmp.veth_tci = htons(a->tci);
tmp.veth_next_type = eh->eth_type;
veh = ofpbuf_push_uninit(packet, VLAN_HEADER_LEN);
key->in_port, a->controller.arg);
break;
- case ODPAT_SET_VLAN_VID:
- dp_netdev_modify_vlan_tci(packet, ntohs(a->vlan_vid.vlan_vid),
- VLAN_VID_MASK);
- break;
-
- case ODPAT_SET_VLAN_PCP:
- dp_netdev_modify_vlan_tci(packet,
- a->vlan_pcp.vlan_pcp << VLAN_PCP_SHIFT,
- VLAN_PCP_MASK);
+ case ODPAT_SET_DL_TCI:
+ dp_netdev_set_dl_tci(packet, &a->dl_tci);
break;
case ODPAT_STRIP_VLAN:
void
format_odp_flow_key(struct ds *ds, const struct odp_flow_key *key)
{
- ds_put_format(ds, "in_port%04x:vlan%d:pcp%d mac"ETH_ADDR_FMT
- "->"ETH_ADDR_FMT" type%04x proto%"PRId8" tos%"PRIu8
- " ip"IP_FMT"->"IP_FMT" port%d->%d",
- key->in_port, ntohs(key->dl_vlan), key->dl_vlan_pcp,
+ ds_put_format(ds, "in_port%04x tci(", key->in_port);
+ if (key->dl_tci) {
+ ds_put_format(ds, "vlan%"PRIu16",pcp%d",
+ vlan_tci_to_vid(key->dl_tci),
+ vlan_tci_to_pcp(key->dl_tci));
+ } else {
+ ds_put_char(ds, '0');
+ }
+ ds_put_format(ds, ") mac"ETH_ADDR_FMT"->"ETH_ADDR_FMT" type%04x "
+ "proto%"PRId8" tos%"PRIu8" ip"IP_FMT"->"IP_FMT" port%d->%d",
ETH_ADDR_ARGS(key->dl_src), ETH_ADDR_ARGS(key->dl_dst),
ntohs(key->dl_type), key->nw_proto, key->nw_tos,
IP_ARGS(&key->nw_src), IP_ARGS(&key->nw_dst),
case ODPAT_SET_TUNNEL:
ds_put_format(ds, "set_tunnel(0x%08"PRIx32")", ntohl(a->tunnel.tun_id));
break;
- case ODPAT_SET_VLAN_VID:
- ds_put_format(ds, "set_vlan(%"PRIu16")", ntohs(a->vlan_vid.vlan_vid));
- break;
- case ODPAT_SET_VLAN_PCP:
- ds_put_format(ds, "set_vlan_pcp(%"PRIu8")", a->vlan_pcp.vlan_pcp);
+ case ODPAT_SET_DL_TCI: {
+ int vid = vlan_tci_to_vid(a->dl_tci.tci);
+ int pcp = vlan_tci_to_pcp(a->dl_tci.tci);
+
+ ds_put_cstr(ds, "set_tci(");
+ switch (ntohs(a->dl_tci.mask)) {
+ case VLAN_VID_MASK:
+ ds_put_format(ds, "set_tci(vlan=%d)", vid);
+ break;
+ case VLAN_PCP_MASK:
+ ds_put_format(ds, "set_tci(pcp=%d)", pcp);
+ break;
+ case VLAN_VID_MASK | VLAN_PCP_MASK:
+ ds_put_format(ds, "set_tci(vlan=%d,pcp=%d)", vid, pcp);
+ break;
+ default:
+ ds_put_format(ds, "set_tci(tci=%04"PRIx16",mask=%04"PRIx16")",
+ ntohs(a->dl_tci.tci), ntohs(a->dl_tci.mask));
+ break;
+ }
+ }
break;
case ODPAT_STRIP_VLAN:
ds_put_format(ds, "strip_vlan");
key->nw_src = flow->nw_src;
key->nw_dst = flow->nw_dst;
key->in_port = flow->in_port;
- key->dl_vlan = flow->dl_vlan;
+ if (flow->dl_vlan == htons(OFP_VLAN_NONE)) {
+ key->dl_tci = htons(0);
+ } else {
+ uint16_t vid = flow->dl_vlan & htons(VLAN_VID_MASK);
+ uint16_t pcp = htons((flow->dl_vlan_pcp << VLAN_PCP_SHIFT)
+ & VLAN_PCP_MASK);
+ key->dl_tci = vid | pcp | htons(ODP_TCI_PRESENT);
+ }
key->dl_type = flow->dl_type;
key->tp_src = flow->tp_src;
key->tp_dst = flow->tp_dst;
memcpy(key->dl_src, flow->dl_src, ETH_ADDR_LEN);
memcpy(key->dl_dst, flow->dl_dst, ETH_ADDR_LEN);
key->nw_proto = flow->nw_proto;
- key->dl_vlan_pcp = flow->dl_vlan_pcp;
key->nw_tos = flow->nw_tos;
memset(key->reserved, 0, sizeof key->reserved);
}
flow->nw_src = key->nw_src;
flow->nw_dst = key->nw_dst;
flow->in_port = key->in_port;
- flow->dl_vlan = key->dl_vlan;
+ if (key->dl_tci) {
+ flow->dl_vlan = htons(vlan_tci_to_vid(key->dl_tci));
+ flow->dl_vlan_pcp = vlan_tci_to_pcp(key->dl_tci);
+ } else {
+ flow->dl_vlan = htons(OFP_VLAN_NONE);
+ flow->dl_vlan_pcp = 0;
+ }
flow->dl_type = key->dl_type;
flow->tp_src = key->tp_src;
flow->tp_dst = key->tp_dst;
memcpy(flow->dl_src, key->dl_src, ETH_ADDR_LEN);
memcpy(flow->dl_dst, key->dl_dst, ETH_ADDR_LEN);
flow->nw_proto = key->nw_proto;
- flow->dl_vlan_pcp = key->dl_vlan_pcp;
flow->nw_tos = key->nw_tos;
}
#define PACKETS_H 1
#include <inttypes.h>
+#include <sys/types.h>
+#include <netinet/in.h>
#include <stdint.h>
#include <string.h>
#include "compiler.h"
#define VLAN_PCP_MASK 0xe000
#define VLAN_PCP_SHIFT 13
+#define VLAN_CFI 0x1000
+
+/* Given the vlan_tci field from an 802.1Q header, in network byte order,
+ * returns the VLAN ID in host byte order. */
+static inline uint16_t
+vlan_tci_to_vid(uint16_t vlan_tci)
+{
+ return (ntohs(vlan_tci) & VLAN_VID_MASK) >> VLAN_VID_SHIFT;
+}
+
+/* Given the vlan_tci field from an 802.1Q header, in network byte order,
+ * returns the priority code point (PCP) in host byte order. */
+static inline int
+vlan_tci_to_pcp(uint16_t vlan_tci)
+{
+ return (ntohs(vlan_tci) & VLAN_PCP_MASK) >> VLAN_PCP_SHIFT;
+}
+
#define VLAN_HEADER_LEN 4
struct vlan_header {
uint16_t vlan_tci; /* Lowest 12 bits are VLAN ID. */
#include "netdev.h"
#include "ofpbuf.h"
#include "ofproto.h"
+#include "packets.h"
#include "poll-loop.h"
#include "sflow_api.h"
#include "socket-util.h"
n_outputs++;
break;
- case ODPAT_SET_VLAN_VID:
- switchElem.flowType.sw.dst_vlan = ntohs(a->vlan_vid.vlan_vid);
- break;
-
- case ODPAT_SET_VLAN_PCP:
- switchElem.flowType.sw.dst_priority = a->vlan_pcp.vlan_pcp;
+ case ODPAT_SET_DL_TCI:
+ if (a->dl_tci.mask & htons(VLAN_VID_MASK)) {
+ switchElem.flowType.sw.dst_vlan = vlan_tci_to_vid(a->dl_tci.tci);
+ }
+ if (a->dl_tci.mask & htons(VLAN_PCP_MASK)) {
+ switchElem.flowType.sw.dst_priority = vlan_tci_to_pcp(a->dl_tci.tci);
+ }
break;
default:
break;
case OFPAT_SET_VLAN_VID:
- oa = odp_actions_add(ctx->out, ODPAT_SET_VLAN_VID);
- ctx->flow.dl_vlan = oa->vlan_vid.vlan_vid = ia->vlan_vid.vlan_vid;
+ oa = odp_actions_add(ctx->out, ODPAT_SET_DL_TCI);
+ oa->dl_tci.tci = ia->vlan_vid.vlan_vid & htons(VLAN_VID_MASK);
+ oa->dl_tci.mask = htons(VLAN_VID_MASK);
break;
case OFPAT_SET_VLAN_PCP:
- oa = odp_actions_add(ctx->out, ODPAT_SET_VLAN_PCP);
- ctx->flow.dl_vlan_pcp = oa->vlan_pcp.vlan_pcp = ia->vlan_pcp.vlan_pcp;
+ oa = odp_actions_add(ctx->out, ODPAT_SET_DL_TCI);
+ oa->dl_tci.tci = htons((ia->vlan_pcp.vlan_pcp << VLAN_PCP_SHIFT)
+ & VLAN_PCP_MASK);
+ oa->dl_tci.mask = htons(VLAN_PCP_MASK);
break;
case OFPAT_STRIP_VLAN:
if (p->vlan == OFP_VLAN_NONE) {
odp_actions_add(actions, ODPAT_STRIP_VLAN);
} else {
- a = odp_actions_add(actions, ODPAT_SET_VLAN_VID);
- a->vlan_vid.vlan_vid = htons(p->vlan);
+ a = odp_actions_add(actions, ODPAT_SET_DL_TCI);
+ a->dl_tci.tci = htons(p->vlan & VLAN_VID_MASK);
+ a->dl_tci.mask = htons(VLAN_VID_MASK);
}
cur_vlan = p->vlan;
}