From: Evgeniy Polyakov <johnpol@2ka•mipt.ru>
To: David Miller <davem@davemloft•net>
Cc: kaber@trash•net, herbert@gondor•apana.org.au,
netdev@vger•kernel.org, kuznet@ms2•inr.ac.ru, hadi@cyberus•ca
Subject: Re: [PKT_SCHED]: Add stateless NAT
Date: Fri, 28 Sep 2007 13:16:43 +0400 [thread overview]
Message-ID: <20070928091643.GA16484@2ka.mipt.ru> (raw)
In-Reply-To: <20070928081918.GB2304@2ka.mipt.ru>
On Fri, Sep 28, 2007 at 12:19:19PM +0400, Evgeniy Polyakov (johnpol@2ka•mipt.ru) wrote:
> > I still think the nf_*() prefixes should all go and the extern
> > prototypes should go into an independant header file.
> >
> > These are not netfilter routines, they are "INET" helpers.
> >
> > And we should make similar treatment for all of the ipv6
> > packet parser helper functions that ipv6 netfilter needs.
>
> Should netfilter still have own nf_ prefixed functions which will just
> call the same ones without prefix from inet header?
Kind of.
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 1dd075e..befdb82 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -291,9 +291,7 @@ extern int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len);
static inline void nf_csum_replace4(__sum16 *sum, __be32 from, __be32 to)
{
- __be32 diff[] = { ~from, to };
-
- *sum = csum_fold(csum_partial((char *)diff, sizeof(diff), ~csum_unfold(*sum)));
+ csum_replace(sum, from, to);
}
static inline void nf_csum_replace2(__sum16 *sum, __be16 from, __be16 to)
@@ -301,13 +299,17 @@ static inline void nf_csum_replace2(__sum16 *sum, __be16 from, __be16 to)
nf_csum_replace4(sum, (__force __be32)from, (__force __be32)to);
}
-extern void nf_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
- __be32 from, __be32 to, int pseudohdr);
+static inline void nf_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
+ __be32 from, __be32 to, int pseudohdr)
+{
+ proto_csum_replace(sum, skb, (__force __be32)from,
+ (__force __be32)to, pseudohdr);
+}
static inline void nf_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
__be16 from, __be16 to, int pseudohdr)
{
- nf_proto_csum_replace4(sum, skb, (__force __be32)from,
+ proto_csum_replace(sum, skb, (__force __be32)from,
(__force __be32)to, pseudohdr);
}
diff --git a/include/linux/netfilter_ipv6.h b/include/linux/netfilter_ipv6.h
index 66ca8e3..e0561ea 100644
--- a/include/linux/netfilter_ipv6.h
+++ b/include/linux/netfilter_ipv6.h
@@ -72,8 +72,11 @@ enum nf_ip6_hook_priorities {
#ifdef CONFIG_NETFILTER
extern int ip6_route_me_harder(struct sk_buff *skb);
-extern __sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
- unsigned int dataoff, u_int8_t protocol);
+static inline __sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
+ unsigned int dataoff, u_int8_t protocol)
+{
+ return ip6_checksum(skb, hook, dataoff, protocol);
+}
extern int ipv6_netfilter_init(void);
extern void ipv6_netfilter_fini(void);
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index a656cec..95ad5af 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1788,5 +1788,11 @@ static inline void skb_forward_csum(struct sk_buff *skb)
skb->ip_summed = CHECKSUM_NONE;
}
+extern void proto_csum_replace(__sum16 *sum, struct sk_buff *skb,
+ __be32 from, __be32 to, int pseudohdr);
+
+extern __sum16 ip6_checksum(struct sk_buff *skb, unsigned int hook,
+ unsigned int dataoff, u_int8_t protocol);
+
#endif /* __KERNEL__ */
#endif /* _LINUX_SKBUFF_H */
diff --git a/include/net/checksum.h b/include/net/checksum.h
index 1242461..8602189 100644
--- a/include/net/checksum.h
+++ b/include/net/checksum.h
@@ -93,4 +93,12 @@ static inline __wsum csum_unfold(__sum16 n)
}
#define CSUM_MANGLED_0 ((__force __sum16)0xffff)
+
+static inline void csum_replace(__sum16 *sum, __be32 from, __be32 to)
+{
+ __be32 diff[] = { ~from, to };
+
+ *sum = csum_fold(csum_partial((char *)diff, sizeof(diff), ~csum_unfold(*sum)));
+}
+
#endif
diff --git a/net/core/utils.c b/net/core/utils.c
index 0bf17da..17576c8 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -293,3 +293,54 @@ out:
}
EXPORT_SYMBOL(in6_pton);
+
+void proto_csum_replace(__sum16 *sum, struct sk_buff *skb,
+ __be32 from, __be32 to, int pseudohdr)
+{
+ __be32 diff[] = { ~from, to };
+ if (skb->ip_summed != CHECKSUM_PARTIAL) {
+ *sum = csum_fold(csum_partial(diff, sizeof(diff),
+ ~csum_unfold(*sum)));
+ if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
+ skb->csum = ~csum_partial(diff, sizeof(diff),
+ ~skb->csum);
+ } else if (pseudohdr)
+ *sum = ~csum_fold(csum_partial(diff, sizeof(diff),
+ csum_unfold(*sum)));
+}
+EXPORT_SYMBOL(proto_csum_replace);
+
+__sum16 ip6_checksum(struct sk_buff *skb, unsigned int hook,
+ unsigned int dataoff, u_int8_t protocol)
+{
+ struct ipv6hdr *ip6h = ipv6_hdr(skb);
+ __sum16 csum = 0;
+
+ switch (skb->ip_summed) {
+ case CHECKSUM_COMPLETE:
+ if (hook != NF_IP6_PRE_ROUTING && hook != NF_IP6_LOCAL_IN)
+ break;
+ if (!csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
+ skb->len - dataoff, protocol,
+ csum_sub(skb->csum,
+ skb_checksum(skb, 0,
+ dataoff, 0)))) {
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ break;
+ }
+ /* fall through */
+ case CHECKSUM_NONE:
+ skb->csum = ~csum_unfold(
+ csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
+ skb->len - dataoff,
+ protocol,
+ csum_sub(0,
+ skb_checksum(skb, 0,
+ dataoff, 0))));
+ csum = __skb_checksum_complete(skb);
+ }
+ return csum;
+}
+
+EXPORT_SYMBOL(ip6_checksum);
+
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c
index 38b1496..be43559 100644
--- a/net/ipv6/netfilter.c
+++ b/net/ipv6/netfilter.c
@@ -81,40 +81,6 @@ static int nf_ip6_reroute(struct sk_buff **pskb, const struct nf_info *info)
return 0;
}
-__sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
- unsigned int dataoff, u_int8_t protocol)
-{
- struct ipv6hdr *ip6h = ipv6_hdr(skb);
- __sum16 csum = 0;
-
- switch (skb->ip_summed) {
- case CHECKSUM_COMPLETE:
- if (hook != NF_IP6_PRE_ROUTING && hook != NF_IP6_LOCAL_IN)
- break;
- if (!csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
- skb->len - dataoff, protocol,
- csum_sub(skb->csum,
- skb_checksum(skb, 0,
- dataoff, 0)))) {
- skb->ip_summed = CHECKSUM_UNNECESSARY;
- break;
- }
- /* fall through */
- case CHECKSUM_NONE:
- skb->csum = ~csum_unfold(
- csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
- skb->len - dataoff,
- protocol,
- csum_sub(0,
- skb_checksum(skb, 0,
- dataoff, 0))));
- csum = __skb_checksum_complete(skb);
- }
- return csum;
-}
-
-EXPORT_SYMBOL(nf_ip6_checksum);
-
static struct nf_afinfo nf_ip6_afinfo = {
.family = AF_INET6,
.checksum = nf_ip6_checksum,
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 381a77c..9ffbbe2 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -226,22 +226,6 @@ copy_skb:
}
EXPORT_SYMBOL(skb_make_writable);
-void nf_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
- __be32 from, __be32 to, int pseudohdr)
-{
- __be32 diff[] = { ~from, to };
- if (skb->ip_summed != CHECKSUM_PARTIAL) {
- *sum = csum_fold(csum_partial(diff, sizeof(diff),
- ~csum_unfold(*sum)));
- if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
- skb->csum = ~csum_partial(diff, sizeof(diff),
- ~skb->csum);
- } else if (pseudohdr)
- *sum = ~csum_fold(csum_partial(diff, sizeof(diff),
- csum_unfold(*sum)));
-}
-EXPORT_SYMBOL(nf_proto_csum_replace4);
-
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
/* This does not belong here, but locally generated errors need it if connection
tracking in use: without this, connection may not be in hash table, and hence
--
Evgeniy Polyakov
next prev parent reply other threads:[~2007-09-28 9:17 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-27 7:34 [PKT_SCHED]: Add stateless NAT Herbert Xu
2007-09-27 9:25 ` Evgeniy Polyakov
2007-09-27 9:33 ` Herbert Xu
2007-09-27 10:07 ` Evgeniy Polyakov
2007-09-27 10:29 ` Herbert Xu
2007-09-27 12:41 ` Evgeniy Polyakov
2007-09-27 12:45 ` Herbert Xu
2007-09-27 13:10 ` Evgeniy Polyakov
2007-09-27 13:16 ` Patrick McHardy
2007-09-27 13:25 ` Evgeniy Polyakov
2007-09-27 13:30 ` Patrick McHardy
2007-09-27 13:33 ` Evgeniy Polyakov
2007-09-27 13:34 ` jamal
2007-09-27 13:20 ` Herbert Xu
2007-09-27 13:29 ` Evgeniy Polyakov
2007-09-27 13:39 ` Patrick McHardy
2007-09-27 19:52 ` David Miller
2007-09-28 8:19 ` Evgeniy Polyakov
2007-09-28 9:16 ` Evgeniy Polyakov [this message]
2007-09-28 16:31 ` Patrick McHardy
2007-09-27 12:52 ` jamal
2007-09-27 13:06 ` Evgeniy Polyakov
2007-09-27 12:27 ` Herbert Xu
2007-09-27 12:46 ` jamal
2007-09-27 12:39 ` jamal
2007-09-27 12:58 ` Herbert Xu
2007-09-27 19:48 ` David Miller
2007-09-27 13:01 ` Herbert Xu
2007-09-27 13:16 ` jamal
2007-09-27 19:08 ` David Miller
2007-09-28 16:55 ` Patrick McHardy
2007-09-29 0:51 ` Herbert Xu
2007-09-29 3:37 ` Herbert Xu
2007-09-29 15:21 ` Patrick McHardy
2007-09-29 23:36 ` Herbert Xu
2007-09-30 0:13 ` David Miller
2007-09-30 0:26 ` Herbert Xu
2007-09-30 0:43 ` Herbert Xu
2007-09-30 15:38 ` Patrick McHardy
2007-10-14 4:26 ` [0/10] Remove sk_buff ** from netfilter API Herbert Xu
2007-10-14 4:27 ` [PATCH 1/10] [SKBUFF]: Merge common code between copy_skb_header and skb_clone Herbert Xu
2007-10-14 10:36 ` jamal
2007-10-14 4:27 ` [PATCH 2/10] [SKBUFF]: Add skb_morph Herbert Xu
2007-11-26 6:50 ` Yasuyuki KOZAKAI
[not found] ` <200711260650.lAQ6oOL9006774@toshiba.co.jp>
2007-11-26 15:10 ` Herbert Xu
2007-11-27 6:50 ` Yasuyuki KOZAKAI
2007-10-14 4:27 ` [PATCH 3/10] [IPV4]: Make ip_defrag return the same packet Herbert Xu
2007-10-14 4:27 ` [PATCH 4/10] [IPV4]: Change ip_defrag to return an integer Herbert Xu
2007-10-14 4:27 ` [PATCH 5/10] [NET]: Avoid unnecessary cloning for ingress filtering Herbert Xu
2007-10-14 10:49 ` jamal
2007-10-15 13:57 ` jamal
2007-10-15 14:28 ` Patrick McHardy
2007-10-15 14:55 ` Alexey Kuznetsov
2007-10-16 10:28 ` jamal
2007-10-14 4:27 ` [PATCH 6/10] [BRIDGE]: Unshare skb upon entry Herbert Xu
2007-10-15 7:20 ` Patrick McHardy
2007-10-15 8:04 ` Herbert Xu
2007-10-15 8:50 ` David Miller
2007-10-14 4:27 ` [PATCH 7/10] [NETFILTER]: Do not copy skb in skb_make_writable Herbert Xu
2007-10-14 4:27 ` [PATCH 8/10] [IPVS]: Replace local version of skb_make_writable Herbert Xu
2007-10-14 4:27 ` [PATCH 9/10] [NETFILTER]: Avoid skb_copy/pskb_copy/skb_realloc_headroom Herbert Xu
2007-10-14 4:27 ` [PATCH 10/10] [NETFILTER]: Replace sk_buff ** with sk_buff * Herbert Xu
2007-10-14 9:55 ` Herbert Xu
2007-10-14 14:46 ` [0/3] [IPV6]: Kill sk_buff ** usage on input path Herbert Xu
2007-10-14 14:49 ` [PATCH 1/3] [IPV6]: Make ipv6_frag_rcv return the same packet Herbert Xu
2007-10-15 8:28 ` David Miller
2007-10-14 14:49 ` [PATCH 2/3] [IPV6]: Avoid skb_copy/pskb_copy/skb_realloc_headroom on input Herbert Xu
2007-10-15 8:29 ` David Miller
2007-10-14 14:49 ` [PATCH 3/3] [IPV6]: Replace sk_buff ** with sk_buff * in input handlers Herbert Xu
2007-10-14 15:43 ` YOSHIFUJI Hideaki / 吉藤英明
2007-10-15 8:30 ` David Miller
2007-10-15 8:29 ` David Miller
2007-10-15 14:21 ` Herbert Xu
2007-10-15 8:27 ` [PATCH 10/10] [NETFILTER]: Replace sk_buff ** with sk_buff * David Miller
2007-10-15 6:25 ` [0/10] Remove sk_buff ** from netfilter API Patrick McHardy
2007-10-15 7:57 ` [IPV4]: Uninline netfilter okfns Patrick McHardy
2007-10-15 8:05 ` Herbert Xu
2007-10-15 8:30 ` [IPV6]: " Patrick McHardy
2007-10-15 8:51 ` David Miller
2007-10-15 8:49 ` [IPV4]: " David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070928091643.GA16484@2ka.mipt.ru \
--to=johnpol@2ka$(echo .)mipt.ru \
--cc=davem@davemloft$(echo .)net \
--cc=hadi@cyberus$(echo .)ca \
--cc=herbert@gondor$(echo .)apana.org.au \
--cc=kaber@trash$(echo .)net \
--cc=kuznet@ms2$(echo .)inr.ac.ru \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox