Browse code

core: new raw_ipip flag, indicate to cut off the extra IP header in IPIP encapsulation.

Alexandr Dubovikov authored on 22/08/2011 11:11:01
Showing 2 changed files
... ...
@@ -84,6 +84,8 @@
84 84
 
85 85
 #endif /* __OS_* */
86 86
 
87
+int raw_ipip = 0; /* set if raw socket is in capture mode for IPIP */
88
+
87 89
 
88 90
 /** create and return a raw socket.
89 91
  * @param proto - protocol used (e.g. IPPROTO_UDP, IPPROTO_RAW)
... ...
@@ -319,10 +321,14 @@ int raw_udp4_recv(int rsock, char** buf, int len, union sockaddr_union* from,
319 319
 	if (unlikely(n<0)) goto error;
320 320
 	
321 321
 	end=*buf+n;
322
-	if (unlikely(n<(sizeof(struct ip)+sizeof(struct udphdr)))) {
322
+	if (unlikely(n<((sizeof(struct ip) * raw_ipip ? 2 : 1)+sizeof(struct udphdr)))) {
323 323
 		n=-3;
324 324
 		goto error;
325 325
 	}
326
+	
327
+	if(raw_ipip) 
328
+        	*buf = *buf + sizeof(struct ip);
329
+	
326 330
 	/* FIXME: if initial buffer is aligned, one could skip the memcpy
327 331
 	   and directly cast ip and udphdr pointer to the memory */
328 332
 	memcpy(&iph, *buf, sizeof(struct ip));
... ...
@@ -39,6 +39,7 @@ struct raw_filter{
39 39
 	char proto;
40 40
 };
41 41
 
42
+extern int raw_ipip;
42 43
 
43 44
 int raw_socket(int proto, struct ip_addr* ip, str* iface, int iphdr_incl);
44 45
 int raw_udp4_socket(struct ip_addr* ip, str* iface, int iphdr_incl);