[ovs-dev] [patch v3 1/4] packets: Handle line continuations for packets.

Darrell Ball dlu998 at gmail.com
Thu Jun 28 22:39:28 UTC 2018


Line continuations are useful for specifying big packets in
hex form in tests.  Allow the hex packet to include '\'s to
specify continuations.  Also line length is limited to 998
in patches because of SMTP limits. Creating patches with
longer lines lines leads to corrupted patches.

Signed-off-by: Darrell Ball <dlu998 at gmail.com>
---
 lib/packets.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/packets.c b/lib/packets.c
index 38bfb60..13186f9 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -490,21 +490,32 @@ eth_from_hex(const char *hex, struct dp_packet **packetp)
 {
     struct dp_packet *packet;
 
+    char *hex2 = xstrdup(hex);
+    /* Handle '\' in input to allow for long line continuations. */
+    for (int i = 0; i < strlen(hex2); i++) {
+        if (hex2[i] == '\\') {
+            memmove(&hex2[i], &hex2[i + 1], strlen(hex2) - i);
+        }
+    }
+
     /* Use 2 bytes of headroom to 32-bit align the L3 header. */
-    packet = *packetp = dp_packet_new_with_headroom(strlen(hex) / 2, 2);
+    packet = *packetp = dp_packet_new_with_headroom(strlen(hex2) / 2, 2);
 
-    if (dp_packet_put_hex(packet, hex, NULL)[0] != '\0') {
+    if (dp_packet_put_hex(packet, hex2, NULL)[0] != '\0') {
         dp_packet_delete(packet);
         *packetp = NULL;
+        free(hex2);
         return "Trailing garbage in packet data";
     }
 
     if (dp_packet_size(packet) < ETH_HEADER_LEN) {
         dp_packet_delete(packet);
         *packetp = NULL;
+        free(hex2);
         return "Packet data too short for Ethernet";
     }
 
+    free(hex2);
     return NULL;
 }
 
-- 
1.9.1



More information about the dev mailing list