Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / net / netfilter / utils.c
blob0b660c568156e60978c129efd78cf836c99af2c9
1 #include <linux/kernel.h>
2 #include <linux/netfilter.h>
3 #include <linux/netfilter_ipv4.h>
4 #include <linux/netfilter_ipv6.h>
5 #include <net/netfilter/nf_queue.h>
7 __sum16 nf_checksum(struct sk_buff *skb, unsigned int hook,
8 unsigned int dataoff, u_int8_t protocol,
9 unsigned short family)
11 const struct nf_ipv6_ops *v6ops;
12 __sum16 csum = 0;
14 switch (family) {
15 case AF_INET:
16 csum = nf_ip_checksum(skb, hook, dataoff, protocol);
17 break;
18 case AF_INET6:
19 v6ops = rcu_dereference(nf_ipv6_ops);
20 if (v6ops)
21 csum = v6ops->checksum(skb, hook, dataoff, protocol);
22 break;
25 return csum;
27 EXPORT_SYMBOL_GPL(nf_checksum);
29 __sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
30 unsigned int dataoff, unsigned int len,
31 u_int8_t protocol, unsigned short family)
33 const struct nf_ipv6_ops *v6ops;
34 __sum16 csum = 0;
36 switch (family) {
37 case AF_INET:
38 csum = nf_ip_checksum_partial(skb, hook, dataoff, len,
39 protocol);
40 break;
41 case AF_INET6:
42 v6ops = rcu_dereference(nf_ipv6_ops);
43 if (v6ops)
44 csum = v6ops->checksum_partial(skb, hook, dataoff, len,
45 protocol);
46 break;
49 return csum;
51 EXPORT_SYMBOL_GPL(nf_checksum_partial);
53 int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
54 bool strict, unsigned short family)
56 const struct nf_ipv6_ops *v6ops;
57 int ret = 0;
59 switch (family) {
60 case AF_INET:
61 ret = nf_ip_route(net, dst, fl, strict);
62 break;
63 case AF_INET6:
64 v6ops = rcu_dereference(nf_ipv6_ops);
65 if (v6ops)
66 ret = v6ops->route(net, dst, fl, strict);
67 break;
70 return ret;
72 EXPORT_SYMBOL_GPL(nf_route);
74 int nf_reroute(struct sk_buff *skb, struct nf_queue_entry *entry)
76 const struct nf_ipv6_ops *v6ops;
77 int ret = 0;
79 switch (entry->state.pf) {
80 case AF_INET:
81 ret = nf_ip_reroute(skb, entry);
82 break;
83 case AF_INET6:
84 v6ops = rcu_dereference(nf_ipv6_ops);
85 if (v6ops)
86 ret = v6ops->reroute(skb, entry);
87 break;
89 return ret;