Re: no reassembly for outgoing packets on RAW socket

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jiri Olsa
Date: Thursday, June 10, 2010 - 2:53 am

On Thu, Jun 10, 2010 at 11:14:04AM +0200, Patrick McHardy wrote:

one last thought before the socket option.. :)

there's IP_HDRINCL option which is enabled for RAW sockets
(can be disabled later by setsockopt)

The 'man 7 ip' says:
	"the user supplies an IP header in front of the user data"

but does not mention the outgoing defragmentation.

It kind of looks to me more appropriate to preserve the user suplied
IP header.. moreover if there's a way to switch this off and have
netfilter defragmentation + connection tracking for RAW socket.

please check the following patch..
(there's no special need for the IPSKB_NODEFRAG, it could check the
socket->hdrincl flag directly..)

thoughts?

thanks,
jirka

---
diff --git a/include/net/ip.h b/include/net/ip.h
index 452f229..201a17e 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -42,6 +42,7 @@ struct inet_skb_parm {
 #define IPSKB_XFRM_TRANSFORMED	4
 #define IPSKB_FRAG_COMPLETE	8
 #define IPSKB_REROUTED		16
+#define IPSKB_NODEFRAG		32
 };
 
 static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
diff --git a/net/ipv4/netfilter/nf_defrag_ipv4.c b/net/ipv4/netfilter/nf_defrag_ipv4.c
index cb763ae..0355bea 100644
--- a/net/ipv4/netfilter/nf_defrag_ipv4.c
+++ b/net/ipv4/netfilter/nf_defrag_ipv4.c
@@ -74,6 +74,9 @@ static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,
 		return NF_ACCEPT;
 #endif
 #endif
+	if (IPCB(skb)->flags & IPSKB_NODEFRAG)
+		return NF_ACCEPT;
+
 	/* Gather fragments. */
 	if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) {
 		enum ip_defrag_users user = nf_ct_defrag_user(hooknum, skb);
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 2c7a163..978e813 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -354,6 +354,13 @@ static int raw_send_hdrinc(struct sock *sk, void *from, size_t length,
 	if (memcpy_fromiovecend((void *)iph, from, 0, length))
 		goto error_free;
 
+	/*
+	 * The header is created by user, preserve the fragments
+	 * settings throught the defragmentation unit.
+	 */
+	if (iph->frag_off & htons(IP_MF|IP_OFFSET))
+		IPCB(skb)->flags |= IPSKB_NODEFRAG;
+
 	iphlen = iph->ihl * 4;
 
 	/*
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
no reassembly for outgoing packets on RAW socket, Jiri Olsa, (Fri Jun 4, 4:27 am)
Re: no reassembly for outgoing packets on RAW socket, Patrick McHardy, (Fri Jun 4, 5:03 am)
Re: no reassembly for outgoing packets on RAW socket, Patrick McHardy, (Wed Jun 9, 7:16 am)
Re: no reassembly for outgoing packets on RAW socket, Jan Engelhardt, (Wed Jun 9, 8:15 am)
Re: no reassembly for outgoing packets on RAW socket, Patrick McHardy, (Wed Jun 9, 8:16 am)
Re: no reassembly for outgoing packets on RAW socket, Jan Engelhardt, (Wed Jun 9, 8:20 am)
Re: no reassembly for outgoing packets on RAW socket, Patrick McHardy, (Thu Jun 10, 2:14 am)
Re: no reassembly for outgoing packets on RAW socket, Jiri Olsa, (Thu Jun 10, 2:53 am)
Re: no reassembly for outgoing packets on RAW socket, Patrick McHardy, (Thu Jun 10, 3:04 am)
Re: no reassembly for outgoing packets on RAW socket, Jan Engelhardt, (Fri Jun 11, 2:53 am)
[PATCH] net: IP_NODEFRAG option for IPv4 socket, Jiri Olsa, (Mon Jun 14, 11:53 pm)
Re: [PATCH] net: IP_NODEFRAG option for IPv4 socket, Eric Dumazet, (Tue Jun 15, 12:13 am)
Re: [PATCH] net: IP_NODEFRAG option for IPv4 socket, Jiri Olsa, (Tue Jun 15, 2:18 am)
Re: [PATCH] net: IP_NODEFRAG option for IPv4 socket, Eric Dumazet, (Tue Jun 15, 2:49 am)