Skip to contentSkip to conversation

RFC: quote control and 8bit characters in the data portion

PATCH In review Max Kellermann 2 participants 4 messages Feb 11, 2005 – Feb 12, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: quote control and 8bit characters in the data portion

Hi,

I had difficulties when I wrote tests for H.323, because it is a binary protocol. With the current nfsim, I have to insert non-printable characters into the test source code. This is because print_data() only escapes only very few special characters.

My patch escapes all characters below 0x20 and above 0x7f. This way, I can write tests for binary protocols in 7bit ASCII.

This is not a viable solution, it is only my first idea to fix this problem. With my patch, I am still forced to write 'A' instead of '\x41', even if the hex value is more clear than the letter 'A'.

Any more ideas? What else can be done to improve nfsim's support for binary protocols? Maybe unescape everything before checking expectations?

(ah, btw my patch breaks existing nfsim tests which happen to expect characters that are now escaped. AFAIK none in nfsim-testsuite affected.)

Max

core/ipv4/ipv4.c +6 -0
diff -urN nfsim-orig/core/ipv4/ipv4.c nfsim-new/core/ipv4/ipv4.c
@@ -740,6 +740,7 @@
 
 static char *print_data(char *ptr, const char *data, int len)
 {
+	static const char hexbuf[]= "0123456789abcdef";
 	int i;
 
 	ptr += sprintf(ptr, "DATA ");
@@ -759,6 +760,11 @@
 		} else if (data[i] == '\\') {
 			*ptr++ = '\\';
 			*ptr++ = '\\';
+		} else if (data[i] & 0x80 || (data[i] & 0xe0) == 0) {
+			*ptr++ = '\\';
+			*ptr++ = 'x';
+			*ptr++ = hexbuf[(data[i] >> 4) & 0xf];
+			*ptr++ = hexbuf[data[i] & 0xf];
 		} else
 			*ptr++ = data[i];
 	}
#1 lore raw

Hi Max,

On Fri, Feb 11, 2005 at 11:56:28PM +0100, Max Kellermann told us:

Quoted 3 lines

Any more ideas? What else can be done to improve nfsim's support for binary protocols? Maybe unescape everything before checking expectations?

one thing I could think about and what would be quite handy IMHO would be to give packet input to nfsim from tcpdump files. So one could make some captures of packets on the wire and then feed them to nfsim for testing. Unfortunately, I didn't have time to think a little bit more about this...

Sven

Quoted 3 lines

Max

Signature · 2 lines
Linux zion 2.6.11-rc2-mm1 #1 Fri Jan 28 18:13:44 CET 2005 i686 athlon i386 GNU/Linux
 01:25:16 up 14 days,  7:06,  1 user,  load average: 0.08, 0.02, 0.01
#2 lore raw
Quoted 5 lines · Sven Schuster

one thing I could think about and what would be quite handy IMHO would be to give packet input to nfsim from tcpdump files. So one could make some captures of packets on the wire and then feed them to nfsim for testing. Unfortunately, I didn't have time to think a little bit more about this...

Your idea tries to solve another problem, not mine. It tries to make it easier to inject binary packages, but my problem is writing the expectation string, which requires me to write the test case (=text file) with a hex editor.

I believe it is good that test cases are self contained, and no external dump file has to be loaded, although that may make a useful additional feature.

Max

#3 lore raw
Quoted 1 line · Max Kellermann

it easier to inject binary packages, but my problem is writing the

packages. I guess I'm building too many binary Debian packages.

packets! packets! ;)

Max