- /* Get the final value. */
- uint64_t new_data = dst_data | ((src_data >> src_ofs) << dst_ofs);
-
- /* Store the result. */
- if (NXM_IS_NX_REG(dst->header)) {
- flow->regs[NXM_NX_REG_IDX(dst->header)] = new_data;
- } else if (dst->header == NXM_OF_VLAN_TCI) {
- flow->vlan_tci = htons(new_data);
- } else if (dst->header == NXM_NX_TUN_ID) {
- flow->tun_id = htonll(new_data);
- } else {
+static void
+nxm_write_field(const struct nxm_field *dst, struct flow *flow,
+ uint64_t new_value)
+{
+ switch (dst->index) {
+ case NFI_NXM_OF_ETH_DST:
+ eth_addr_from_uint64(new_value, flow->dl_dst);
+ break;
+
+ case NFI_NXM_OF_ETH_SRC:
+ eth_addr_from_uint64(new_value, flow->dl_src);
+ break;
+
+ case NFI_NXM_OF_VLAN_TCI:
+ flow->vlan_tci = htons(new_value);
+ break;
+
+ case NFI_NXM_NX_TUN_ID:
+ flow->tun_id = htonll(new_value);
+ break;
+
+#define NXM_WRITE_REGISTER(IDX) \
+ case NFI_NXM_NX_REG##IDX: \
+ flow->regs[IDX] = new_value; \
+ break; \
+ case NFI_NXM_NX_REG##IDX##_W: \
+ NOT_REACHED();
+
+ NXM_WRITE_REGISTER(0);
+#if FLOW_N_REGS >= 2
+ NXM_WRITE_REGISTER(1);
+#endif
+#if FLOW_N_REGS >= 3
+ NXM_WRITE_REGISTER(2);
+#endif
+#if FLOW_N_REGS >= 4
+ NXM_WRITE_REGISTER(3);
+#endif
+#if FLOW_N_REGS > 4
+#error
+#endif
+
+ case NFI_NXM_OF_IP_TOS:
+ flow->nw_tos = new_value & IP_DSCP_MASK;
+ break;
+
+ case NFI_NXM_OF_IP_SRC:
+ flow->nw_src = htonl(new_value);
+ break;
+
+ case NFI_NXM_OF_IP_DST:
+ flow->nw_dst = htonl(new_value);
+ break;
+
+ case NFI_NXM_OF_TCP_SRC:
+ case NFI_NXM_OF_UDP_SRC:
+ flow->tp_src = htons(new_value);
+ break;
+
+ case NFI_NXM_OF_TCP_DST:
+ case NFI_NXM_OF_UDP_DST:
+ flow->tp_dst = htons(new_value);
+ break;
+
+ case NFI_NXM_OF_IN_PORT:
+ case NFI_NXM_OF_ETH_TYPE:
+ case NFI_NXM_OF_IP_PROTO:
+ case NFI_NXM_OF_ARP_OP:
+ case NFI_NXM_OF_ARP_SPA:
+ case NFI_NXM_OF_ARP_TPA:
+ case NFI_NXM_OF_ICMP_TYPE:
+ case NFI_NXM_OF_ICMP_CODE:
+ case NFI_NXM_NX_TUN_ID_W:
+ case NFI_NXM_OF_ETH_DST_W:
+ case NFI_NXM_OF_VLAN_TCI_W:
+ case NFI_NXM_OF_IP_SRC_W:
+ case NFI_NXM_OF_IP_DST_W:
+ case NFI_NXM_OF_ARP_SPA_W:
+ case NFI_NXM_OF_ARP_TPA_W:
+ case NFI_NXM_NX_ARP_SHA:
+ case NFI_NXM_NX_ARP_THA:
+ case NFI_NXM_NX_IPV6_SRC:
+ case NFI_NXM_NX_IPV6_SRC_W:
+ case NFI_NXM_NX_IPV6_DST:
+ case NFI_NXM_NX_IPV6_DST_W:
+ case NFI_NXM_NX_ICMPV6_TYPE:
+ case NFI_NXM_NX_ICMPV6_CODE:
+ case NFI_NXM_NX_ND_TARGET:
+ case NFI_NXM_NX_ND_SLL:
+ case NFI_NXM_NX_ND_TLL:
+ case N_NXM_FIELDS: