Blame view
net/ipv6/netfilter.c
4.36 KB
020b4c12d
|
1 |
#include <linux/kernel.h> |
bb94aa169
|
2 |
#include <linux/init.h> |
020b4c12d
|
3 |
#include <linux/ipv6.h> |
2cc7d5730
|
4 5 |
#include <linux/netfilter.h> #include <linux/netfilter_ipv6.h> |
020b4c12d
|
6 7 8 |
#include <net/dst.h> #include <net/ipv6.h> #include <net/ip6_route.h> |
3e3850e98
|
9 |
#include <net/xfrm.h> |
503e4faad
|
10 |
#include <net/ip6_checksum.h> |
c01cd429f
|
11 |
#include <net/netfilter/nf_queue.h> |
020b4c12d
|
12 13 14 |
int ip6_route_me_harder(struct sk_buff *skb) { |
adf30907d
|
15 |
struct net *net = dev_net(skb_dst(skb)->dev); |
0660e03f6
|
16 |
struct ipv6hdr *iph = ipv6_hdr(skb); |
020b4c12d
|
17 18 19 |
struct dst_entry *dst; struct flowi fl = { .oif = skb->sk ? skb->sk->sk_bound_dev_if : 0, |
bc5f77434
|
20 |
.mark = skb->mark, |
5811662b1
|
21 22 |
.fl6_dst = iph->daddr, .fl6_src = iph->saddr, |
020b4c12d
|
23 |
}; |
eef9d90dc
|
24 |
dst = ip6_route_output(net, skb->sk, &fl); |
020b4c12d
|
25 |
if (dst->error) { |
eef9d90dc
|
26 |
IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES); |
64ce20730
|
27 28 |
LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route. "); |
020b4c12d
|
29 30 31 32 33 |
dst_release(dst); return -EINVAL; } /* Drop old route. */ |
adf30907d
|
34 |
skb_dst_drop(skb); |
020b4c12d
|
35 |
|
adf30907d
|
36 |
skb_dst_set(skb, dst); |
90348e0ed
|
37 38 39 40 41 42 43 44 45 46 |
#ifdef CONFIG_XFRM if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && xfrm_decode_session(skb, &fl, AF_INET6) == 0) { skb_dst_set(skb, NULL); if (xfrm_lookup(net, &dst, &fl, skb->sk, 0)) return -1; skb_dst_set(skb, dst); } #endif |
020b4c12d
|
47 48 49 |
return 0; } EXPORT_SYMBOL(ip6_route_me_harder); |
2cc7d5730
|
50 51 52 53 54 55 56 57 |
/* * Extra routing may needed on local out, as the QUEUE target never * returns control to the table. */ struct ip6_rt_info { struct in6_addr daddr; struct in6_addr saddr; |
9f40ac713
|
58 |
u_int32_t mark; |
2cc7d5730
|
59 |
}; |
02f014d88
|
60 61 |
static void nf_ip6_saveroute(const struct sk_buff *skb, struct nf_queue_entry *entry) |
2cc7d5730
|
62 |
{ |
02f014d88
|
63 |
struct ip6_rt_info *rt_info = nf_queue_entry_reroute(entry); |
2cc7d5730
|
64 |
|
02f014d88
|
65 |
if (entry->hook == NF_INET_LOCAL_OUT) { |
0660e03f6
|
66 |
struct ipv6hdr *iph = ipv6_hdr(skb); |
2cc7d5730
|
67 68 69 |
rt_info->daddr = iph->daddr; rt_info->saddr = iph->saddr; |
9f40ac713
|
70 |
rt_info->mark = skb->mark; |
2cc7d5730
|
71 72 |
} } |
02f014d88
|
73 74 |
static int nf_ip6_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry) |
2cc7d5730
|
75 |
{ |
02f014d88
|
76 |
struct ip6_rt_info *rt_info = nf_queue_entry_reroute(entry); |
2cc7d5730
|
77 |
|
02f014d88
|
78 |
if (entry->hook == NF_INET_LOCAL_OUT) { |
3db05fea5
|
79 |
struct ipv6hdr *iph = ipv6_hdr(skb); |
2cc7d5730
|
80 |
if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) || |
9f40ac713
|
81 82 |
!ipv6_addr_equal(&iph->saddr, &rt_info->saddr) || skb->mark != rt_info->mark) |
3db05fea5
|
83 |
return ip6_route_me_harder(skb); |
2cc7d5730
|
84 85 86 |
} return 0; } |
1841a4c7a
|
87 88 |
static int nf_ip6_route(struct dst_entry **dst, struct flowi *fl) { |
4591db4f3
|
89 |
*dst = ip6_route_output(&init_net, NULL, fl); |
1841a4c7a
|
90 91 |
return (*dst)->error; } |
b51655b95
|
92 |
__sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook, |
422c346fa
|
93 94 |
unsigned int dataoff, u_int8_t protocol) { |
0660e03f6
|
95 |
struct ipv6hdr *ip6h = ipv6_hdr(skb); |
b51655b95
|
96 |
__sum16 csum = 0; |
422c346fa
|
97 98 |
switch (skb->ip_summed) { |
84fa7933a
|
99 |
case CHECKSUM_COMPLETE: |
6e23ae2a4
|
100 |
if (hook != NF_INET_PRE_ROUTING && hook != NF_INET_LOCAL_IN) |
422c346fa
|
101 102 |
break; if (!csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
1ab1457c4
|
103 |
skb->len - dataoff, protocol, |
422c346fa
|
104 105 106 107 108 109 110 111 |
csum_sub(skb->csum, skb_checksum(skb, 0, dataoff, 0)))) { skb->ip_summed = CHECKSUM_UNNECESSARY; break; } /* fall through */ case CHECKSUM_NONE: |
868c86bcb
|
112 113 |
skb->csum = ~csum_unfold( csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
422c346fa
|
114 115 116 117 |
skb->len - dataoff, protocol, csum_sub(0, skb_checksum(skb, 0, |
1ab1457c4
|
118 |
dataoff, 0)))); |
422c346fa
|
119 120 121 122 |
csum = __skb_checksum_complete(skb); } return csum; } |
422c346fa
|
123 |
EXPORT_SYMBOL(nf_ip6_checksum); |
d63a65073
|
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
static __sum16 nf_ip6_checksum_partial(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, unsigned int len, u_int8_t protocol) { struct ipv6hdr *ip6h = ipv6_hdr(skb); __wsum hsum; __sum16 csum = 0; switch (skb->ip_summed) { case CHECKSUM_COMPLETE: if (len == skb->len - dataoff) return nf_ip6_checksum(skb, hook, dataoff, protocol); /* fall through */ case CHECKSUM_NONE: hsum = skb_checksum(skb, 0, dataoff, 0); skb->csum = ~csum_unfold(csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, skb->len - dataoff, protocol, csum_sub(0, hsum))); skb->ip_summed = CHECKSUM_NONE; |
c86ee67c7
|
145 |
return __skb_checksum_complete_head(skb, dataoff + len); |
d63a65073
|
146 147 148 |
} return csum; }; |
1e796fda0
|
149 |
static const struct nf_afinfo nf_ip6_afinfo = { |
d63a65073
|
150 151 152 153 154 155 156 |
.family = AF_INET6, .checksum = nf_ip6_checksum, .checksum_partial = nf_ip6_checksum_partial, .route = nf_ip6_route, .saveroute = nf_ip6_saveroute, .reroute = nf_ip6_reroute, .route_key_size = sizeof(struct ip6_rt_info), |
2cc7d5730
|
157 158 159 160 |
}; int __init ipv6_netfilter_init(void) { |
bce8032ef
|
161 |
return nf_register_afinfo(&nf_ip6_afinfo); |
2cc7d5730
|
162 |
} |
5bf887f2f
|
163 164 165 166 |
/* This can be called from inet6_init() on errors, so it cannot * be marked __exit. -DaveM */ void ipv6_netfilter_fini(void) |
2cc7d5730
|
167 |
{ |
bce8032ef
|
168 |
nf_unregister_afinfo(&nf_ip6_afinfo); |
2cc7d5730
|
169 |
} |