From: Christophe Saout Subject: Re: [PATCH 1/4] IPSEC output hooks Date: Thu, 17 Feb 2005 20:10:36 +0100 Message-ID: <1108667437.21912.16.camel@leto.cs.pocnet.net> References: <1108667319.21912.14.camel@leto.cs.pocnet.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit To: netfilter-devel@lists.netfilter.org In-Reply-To: <1108667319.21912.14.camel@leto.cs.pocnet.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: netfilter-devel-bounces@lists.netfilter.org Errors-To: netfilter-devel-bounces@lists.netfilter.org List-Id: netfilter-devel.vger.kernel.org Updated ipsec-01-output-hooks.diff --- linux-2.6.11-rc4/net/ipv4/xfrm4_output.c 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/net/ipv4/xfrm4_output.c 2005-02-17 18:07:38.357656232 +0100 @@ -129,6 +129,7 @@ err = -EHOSTUNREACH; goto error_nolock; } + IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED; err = NET_XMIT_BYPASS; out_exit: --- linux-2.6.11-rc4/net/ipv4/raw.c 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/net/ipv4/raw.c 2005-02-17 18:07:21.314247224 +0100 @@ -310,7 +310,7 @@ } err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, - dst_output); + ip_dst_output); if (err > 0) err = inet->recverr ? net_xmit_errno(err) : 0; if (err) --- linux-2.6.11-rc4/net/ipv4/ipmr.c 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/net/ipv4/ipmr.c 2005-02-17 18:05:59.814637048 +0100 @@ -1119,7 +1119,7 @@ if (unlikely(opt->optlen)) ip_forward_options(skb); - return dst_output(skb); + return ip_dst_output(skb); } /* --- linux-2.6.11-rc4/net/ipv4/ip_output.c 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/net/ipv4/ip_output.c 2005-02-17 18:06:29.153176912 +0100 @@ -124,6 +124,15 @@ return ttl; } +#ifdef CONFIG_NETFILTER +/* out-of-line copy is only required with netfilter */ +int ip_dst_output(struct sk_buff *skb) +{ + return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, + skb->dst->dev, dst_output, skb->dst->xfrm != NULL); +} +#endif + /* * Add an ip header to a skbuff and send it out. * @@ -166,7 +175,7 @@ /* Send it out. */ return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, - dst_output); + ip_dst_output); } static inline int ip_finish_output2(struct sk_buff *skb) @@ -284,7 +293,7 @@ return ip_finish_output(skb); } -int ip_output(struct sk_buff *skb) +static inline int ip_output2(struct sk_buff *skb) { IP_INC_STATS(IPSTATS_MIB_OUTREQUESTS); @@ -294,6 +303,16 @@ return ip_finish_output(skb); } +int ip_output(struct sk_buff *skb) +{ + int transformed = IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED; + + if (transformed) + nf_reset(skb); + return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, + skb->dst->dev, ip_output2, transformed); +} + int ip_queue_xmit(struct sk_buff *skb, int ipfragok) { struct sock *sk = skb->sk; @@ -374,7 +393,7 @@ skb->priority = sk->sk_priority; return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, - dst_output); + ip_dst_output); no_route: IP_INC_STATS(IPSTATS_MIB_OUTNOROUTES); @@ -1189,7 +1208,7 @@ /* Netfilter gets whole the not fragmented skb. */ err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, - skb->dst->dev, dst_output); + skb->dst->dev, ip_dst_output); if (err) { if (err > 0) err = inet->recverr ? net_xmit_errno(err) : 0; --- linux-2.6.11-rc4/net/ipv4/ip_forward.c 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/net/ipv4/ip_forward.c 2005-02-17 18:05:39.617707448 +0100 @@ -51,7 +51,7 @@ if (unlikely(opt->optlen)) ip_forward_options(skb); - return dst_output(skb); + return ip_dst_output(skb); } int ip_forward(struct sk_buff *skb) --- linux-2.6.11-rc4/net/ipv4/igmp.c 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/net/ipv4/igmp.c 2005-02-17 18:05:38.713844856 +0100 @@ -343,7 +343,7 @@ pig->csum = ip_compute_csum((void *)skb->h.igmph, igmplen); return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev, - dst_output); + ip_dst_output); } static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel) @@ -674,7 +674,7 @@ ih->csum=ip_compute_csum((void *)ih, sizeof(struct igmphdr)); return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, - dst_output); + ip_dst_output); } static void igmp_gq_timer_expire(unsigned long data) --- linux-2.6.11-rc4/include/net/ip.h 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/include/net/ip.h 2005-02-17 18:04:59.112627968 +0100 @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -45,6 +47,7 @@ #define IPSKB_TRANSLATED 2 #define IPSKB_FORWARDED 4 #define IPSKB_XFRM_TUNNEL_SIZE 8 +#define IPSKB_XFRM_TRANSFORMED 16 }; struct ipcm_cookie @@ -212,6 +215,16 @@ __ip_select_ident(iph, dst, more); } +#ifdef CONFIG_NETFILTER +extern int ip_dst_output(struct sk_buff *skb); +#else +static inline int ip_dst_output(struct sk_buff *skb) +{ + return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, + skb->dst->dev, dst_output, skb->dst->xfrm != NULL); +} +#endif + /* * Map a multicast IP onto multicast MAC for type ethernet. */ --- linux-2.6.11-rc4/include/linux/netfilter.h 2005-02-16 00:59:44.000000000 +0100 +++ linux-2.6.11-rc4-cs1/include/linux/netfilter.h 2005-02-17 18:04:16.640084776 +0100 @@ -138,12 +138,14 @@ /* This is gross, but inline doesn't cut it for avoiding the function call in fast path: gcc doesn't inline (needs value tracking?). --RR */ #ifdef CONFIG_NETFILTER_DEBUG -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \ - nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN) +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \ +(!(cond) \ + ? (okfn)(skb) \ + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)) #define NF_HOOK_THRESH nf_hook_slow #else -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \ -(list_empty(&nf_hooks[(pf)][(hook)]) \ +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \ +(!(cond) || list_empty(&nf_hooks[(pf)][(hook)]) \ ? (okfn)(skb) \ : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)) #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \ @@ -151,6 +153,8 @@ ? (okfn)(skb) \ : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh))) #endif +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \ + NF_HOOK_COND((pf), (hook), (skb), (indev), (outdev), (okfn), 1) int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb, struct net_device *indev, struct net_device *outdev, @@ -180,6 +184,7 @@ #else /* !CONFIG_NETFILTER */ #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb) +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb) static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {} #endif /*CONFIG_NETFILTER*/