[ovs-dev] [PATCH 5/6] Generic encap and decap support for NSH

Jan Scheurich jan.scheurich at ericsson.com
Sun Jul 16 18:49:00 UTC 2017


Hi Yi,

The following incremental patch drops a packet in the datapath at decap_nsh() rather
than aborting if the NSH next protocol field does not match any of the supported values. 

Normally this should not happen if the next proto field is checked in the ofproto
translation, but it feels safer to gracefully handle this case.

It also adds support for NSN in NSH encapsulation in in the encap_nsh and decap_nsh
Action in the datapath to match the translation logic in ofproto.

BR, Jan


diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index 12f517e..14978a7 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -828,11 +828,18 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal,
             }
             break;
         }
-        case OVS_ACTION_ATTR_DECAP_NSH:
-            DP_PACKET_BATCH_FOR_EACH (packet, batch) {
-                decap_nsh(packet);
+        case OVS_ACTION_ATTR_DECAP_NSH: {
+            size_t i, num = batch->count;
+
+            DP_PACKET_BATCH_REFILL_FOR_EACH (i, num, packet, batch) {
+                if (decap_nsh(packet)) {
+                    dp_packet_batch_refill(batch, packet, i);
+                } else {
+                    dp_packet_delete(packet);
+                }
             }
             break;
+        }

         case OVS_ACTION_ATTR_OUTPUT:
         case OVS_ACTION_ATTR_TUNNEL_PUSH:
diff --git a/lib/packets.c b/lib/packets.c
index f0ba027..45ddfee 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -419,6 +419,9 @@ encap_nsh(struct dp_packet *packet, const struct ovs_action_encap_nsh *encap)
         case PT_IPV6:
             next_proto = NSH_P_IPV6;
             break;
+        case PT_NSH:
+            next_proto = NSH_P_NSH;
+            break;
         default:
             OVS_NOT_REACHED();
     }
@@ -444,7 +447,7 @@ encap_nsh(struct dp_packet *packet, const struct ovs_action_encap_nsh *encap)
     packet->l3_ofs = 0;
 }

-void
+bool
 decap_nsh(struct dp_packet *packet)
 {
     struct nsh_hdr *nsh = (struct nsh_hdr *) dp_packet_l3(packet);
@@ -462,8 +465,12 @@ decap_nsh(struct dp_packet *packet)
             case NSH_P_IPV6:
                 next_pt = PT_IPV6;
                 break;
+            case NSH_P_NSH:
+                next_pt = PT_NSH;
+                break;
             default:
-                OVS_NOT_REACHED();
+                /* Unknown inner packet type. Drop packet. */
+                return false;
         }

         length = nsh_hdr_len(nsh);
@@ -471,6 +478,7 @@ decap_nsh(struct dp_packet *packet)
         packet->packet_type = htonl(next_pt);
         /* Packet must be recirculated for further processing. */
     }
+    return true;
 }

 /* Converts hex digits in 'hex' to an Ethernet packet in '*packetp'.  The
diff --git a/lib/packets.h b/lib/packets.h
index 19571b1..ff0c4cc 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -409,7 +409,7 @@ void pop_eth(struct dp_packet *packet);

 void encap_nsh(struct dp_packet *packet,
                const struct ovs_action_encap_nsh *encap_nsh);
-void decap_nsh(struct dp_packet *packet);
+bool decap_nsh(struct dp_packet *packet);

 #define LLC_DSAP_SNAP 0xaa
 #define LLC_SSAP_SNAP 0xaa


More information about the dev mailing list