Until now, fields writable by actions defined in terms of NXM field
numbers were special cases, but commit b3e9b2eda9a "ofproto: Optimize
datapath actions" had the side effect of making it easy to modify
additional fields.  This commit takes advantage of that to make
modifiable all the fields that the kernel datapath supports modifying.
We could make other fields modifiable by adding more support to the kernel
datapath.
---
 include/openflow/nicira-ext.h |   12 ++++++++++++
 lib/nx-match.c                |   37 +++++++++++++++++++++++++++++--------
 lib/nx-match.def              |   18 +++++++++---------
 3 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/include/openflow/nicira-ext.h b/include/openflow/nicira-ext.h
index d73f3ba..ba85676 100644
--- a/include/openflow/nicira-ext.h
+++ b/include/openflow/nicira-ext.h
@@ -406,6 +406,18 @@ OFP_ASSERT(sizeof(struct nx_action_pop_queue) == 16);
  *
  * The following nxm_header values are potentially acceptable as 'dst':
  *
+ *   - NXM_OF_ETH_DST
+ *   - NXM_OF_ETH_SRC
+ *   - NXM_OF_IP_TOS
+ *   - NXM_OF_IP_SRC
+ *   - NXM_OF_IP_DST
+ *   - NXM_OF_TCP_SRC
+ *   - NXM_OF_TCP_DST
+ *   - NXM_OF_UDP_SRC
+ *   - NXM_OF_UDP_DST
+ *     Modifying any of the above fields changes the corresponding packet
+ *     header.
+ *
  *   - NXM_NX_REG(idx) for idx in the switch's accepted range.
  *
  *   - NXM_OF_VLAN_TCI.  Modifying this field's value has side effects on the
diff --git a/lib/nx-match.c b/lib/nx-match.c
index f66c655..f7f4e4a 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -1345,6 +1345,14 @@ 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;
@@ -1374,21 +1382,34 @@ nxm_write_field(const struct nxm_field *dst, struct 
flow *flow,
 #error
 #endif
 
-    case NFI_NXM_OF_IN_PORT:
-    case NFI_NXM_OF_ETH_DST:
-    case NFI_NXM_OF_ETH_SRC:
-    case NFI_NXM_OF_ETH_TYPE:
     case NFI_NXM_OF_IP_TOS:
-    case NFI_NXM_OF_IP_PROTO:
-    case NFI_NXM_OF_ARP_OP:
+        flow->nw_tos = new_value & IP_DSCP_MASK;
+        break;
+
     case NFI_NXM_OF_IP_SRC:
-    case NFI_NXM_OF_ARP_SPA:
+        flow->nw_src = htonl(new_value);
+        break;
+
     case NFI_NXM_OF_IP_DST:
-    case NFI_NXM_OF_ARP_TPA:
+        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:
diff --git a/lib/nx-match.def b/lib/nx-match.def
index 4a42aaa..215e71a 100644
--- a/lib/nx-match.def
+++ b/lib/nx-match.def
@@ -30,18 +30,18 @@
 /*             ------------    ------------  -----------    ------------- --- 
*/
 DEFINE_FIELD_M(NX_TUN_ID,      0,            NXM_DL_NONE,   0,            true)
 DEFINE_FIELD  (OF_IN_PORT,     FWW_IN_PORT,  NXM_DL_NONE,   0,            
false)
-DEFINE_FIELD_M(OF_ETH_DST,     0,            NXM_DL_NONE,   0,            
false)
-DEFINE_FIELD  (OF_ETH_SRC,     FWW_DL_SRC,   NXM_DL_NONE,   0,            
false)
+DEFINE_FIELD_M(OF_ETH_DST,     0,            NXM_DL_NONE,   0,            true)
+DEFINE_FIELD  (OF_ETH_SRC,     FWW_DL_SRC,   NXM_DL_NONE,   0,            true)
 DEFINE_FIELD  (OF_ETH_TYPE,    FWW_DL_TYPE,  NXM_DL_NONE,   0,            
false)
 DEFINE_FIELD_M(OF_VLAN_TCI,    0,            NXM_DL_NONE,   0,            true)
-DEFINE_FIELD  (OF_IP_TOS,      FWW_NW_TOS,   NXM_DL_IP_ANY, 0,            
false)
+DEFINE_FIELD  (OF_IP_TOS,      FWW_NW_TOS,   NXM_DL_IP_ANY, 0,            true)
 DEFINE_FIELD  (OF_IP_PROTO,    FWW_NW_PROTO, NXM_DL_IP_ANY, 0,            
false)
-DEFINE_FIELD_M(OF_IP_SRC,      0,            NXM_DL_IP,     0,            
false)
-DEFINE_FIELD_M(OF_IP_DST,      0,            NXM_DL_IP,     0,            
false)
-DEFINE_FIELD  (OF_TCP_SRC,     FWW_TP_SRC,   NXM_DL_IP_ANY, IPPROTO_TCP,  
false)
-DEFINE_FIELD  (OF_TCP_DST,     FWW_TP_DST,   NXM_DL_IP_ANY, IPPROTO_TCP,  
false)
-DEFINE_FIELD  (OF_UDP_SRC,     FWW_TP_SRC,   NXM_DL_IP_ANY, IPPROTO_UDP,  
false)
-DEFINE_FIELD  (OF_UDP_DST,     FWW_TP_DST,   NXM_DL_IP_ANY, IPPROTO_UDP,  
false)
+DEFINE_FIELD_M(OF_IP_SRC,      0,            NXM_DL_IP,     0,            true)
+DEFINE_FIELD_M(OF_IP_DST,      0,            NXM_DL_IP,     0,            true)
+DEFINE_FIELD  (OF_TCP_SRC,     FWW_TP_SRC,   NXM_DL_IP_ANY, IPPROTO_TCP,  true)
+DEFINE_FIELD  (OF_TCP_DST,     FWW_TP_DST,   NXM_DL_IP_ANY, IPPROTO_TCP,  true)
+DEFINE_FIELD  (OF_UDP_SRC,     FWW_TP_SRC,   NXM_DL_IP_ANY, IPPROTO_UDP,  true)
+DEFINE_FIELD  (OF_UDP_DST,     FWW_TP_DST,   NXM_DL_IP_ANY, IPPROTO_UDP,  true)
 DEFINE_FIELD  (OF_ICMP_TYPE,   FWW_TP_SRC,   NXM_DL_IP,     IPPROTO_ICMP, 
false)
 DEFINE_FIELD  (OF_ICMP_CODE,   FWW_TP_DST,   NXM_DL_IP,     IPPROTO_ICMP, 
false)
 DEFINE_FIELD  (OF_ARP_OP,      FWW_NW_PROTO, NXM_DL_ARP,    0,            
false)
-- 
1.7.4.4

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to