00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
#include <asm/system.h>
00119
#include <linux/types.h>
00120
#include <linux/kernel.h>
00121
#include <linux/string.h>
00122
#include <linux/errno.h>
00123
#include <linux/config.h>
00124
00125
#include <linux/net.h>
00126
#include <linux/socket.h>
00127
#include <linux/sockios.h>
00128
#include <linux/in.h>
00129
#include <linux/inet.h>
00130
#include <linux/netdevice.h>
00131
#include <linux/etherdevice.h>
00132
00133
#include <net/snmp.h>
00134
#include <net/ip.h>
00135
#include <net/protocol.h>
00136
#include <net/route.h>
00137
#include <linux/skbuff.h>
00138
#include <net/sock.h>
00139
#include <net/arp.h>
00140
#include <net/icmp.h>
00141
#include <net/raw.h>
00142
#include <net/checksum.h>
00143
#include <linux/netfilter_ipv4.h>
00144
#include <linux/mroute.h>
00145
#include <linux/netlink.h>
00146
00147
00148
00149
00150
00151 struct ip_mib ip_statistics[NR_CPUS*2];
00152
00153
00154
00155
00156 int ip_call_ra_chain(
struct sk_buff *skb)
00157 {
00158
struct ip_ra_chain *ra;
00159 u8 protocol = skb->
nh.iph->protocol;
00160
struct sock *last = NULL;
00161
00162 read_lock(&
ip_ra_lock);
00163
for (ra =
ip_ra_chain; ra; ra = ra->next) {
00164
struct sock *sk = ra->sk;
00165
00166
00167
00168
00169
if (sk && sk->num == protocol
00170 && ((sk->bound_dev_if == 0)
00171 || (sk->bound_dev_if == skb->
dev->
ifindex))) {
00172
if (skb->
nh.iph->frag_off & htons(
IP_MF|
IP_OFFSET)) {
00173 skb =
ip_defrag(skb);
00174
if (skb == NULL) {
00175 read_unlock(&
ip_ra_lock);
00176
return 1;
00177 }
00178 }
00179
if (last) {
00180
struct sk_buff *skb2 =
skb_clone(skb, GFP_ATOMIC);
00181
if (skb2)
00182
raw_rcv(last, skb2);
00183 }
00184 last = sk;
00185 }
00186 }
00187
00188
if (last) {
00189
raw_rcv(last, skb);
00190 read_unlock(&
ip_ra_lock);
00191
return 1;
00192 }
00193 read_unlock(&
ip_ra_lock);
00194
return 0;
00195 }
00196
00197
00198 static int ip_run_ipprot(
struct sk_buff *skb,
struct iphdr *iph,
00199
struct inet_protocol *ipprot,
int force_copy)
00200 {
00201
int ret = 0;
00202
00203
do {
00204
if (ipprot->
protocol == iph->
protocol) {
00205
struct sk_buff *skb2 = skb;
00206
if (ipprot->
copy || force_copy)
00207 skb2 =
skb_clone(skb, GFP_ATOMIC);
00208
if(skb2 != NULL) {
00209 ret = 1;
00210 ipprot->
handler(skb2);
00211 }
00212 }
00213 ipprot = (
struct inet_protocol *) ipprot->
next;
00214 }
while(ipprot != NULL);
00215
00216
return ret;
00217 }
00218
00244 static inline int ip_local_deliver_finish(
struct sk_buff *skb)
00245 {
00246
int ihl = skb->
nh.iph->ihl*4;
00247
00248
#ifdef CONFIG_NETFILTER_DEBUG
00249
nf_debug_ip_local_deliver(skb);
00250
#endif
00251
00252
__skb_pull(skb, ihl);
00253
00254
#ifdef CONFIG_NETFILTER
00255
00256
00257 nf_conntrack_put(skb->nfct);
00258 skb->nfct = NULL;
00259
#endif
00260
00261
00262 skb->
h.raw = skb->
data;
00263
00264 {
00265
00266
int protocol = skb->
nh.iph->protocol;
00267
int hash = protocol & (
MAX_INET_PROTOS - 1);
00268
struct sock *raw_sk =
raw_v4_htable[hash];
00269
struct inet_protocol *ipprot;
00270
int flag;
00271
00272
00273
00274
00275
if(raw_sk != NULL)
00276 raw_sk =
raw_v4_input(skb, skb->
nh.iph, hash);
00277
00278 ipprot = (
struct inet_protocol *)
inet_protos[hash];
00279 flag = 0;
00280
if(ipprot != NULL) {
00281
if(raw_sk == NULL &&
00282 ipprot->next == NULL &&
00283 ipprot->protocol == protocol) {
00284
int ret;
00285
00286
00287 ret = ipprot->
handler(skb);
00288
00289
return ret;
00290 }
else {
00291 flag =
ip_run_ipprot(skb, skb->
nh.iph, ipprot, (raw_sk != NULL));
00292 }
00293 }
00294
00295
00296
00297
00298
00299
00300
if(raw_sk != NULL) {
00301
raw_rcv(raw_sk, skb);
00302
sock_put(raw_sk);
00303 }
else if (!flag) {
00304
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, 0);
00305
kfree_skb(skb);
00306 }
00307 }
00308
00309
return 0;
00310 }
00311
00312
00313
00314
00315 int ip_local_deliver(
struct sk_buff *skb)
00316 {
00317
00318
00319
00320
00321
if (skb->
nh.iph->frag_off & htons(
IP_MF|
IP_OFFSET)) {
00322 skb =
ip_defrag(skb);
00323
if (!skb)
00324
return 0;
00325 }
00326
00327
return NF_HOOK(PF_INET,
NF_IP_LOCAL_IN, skb, skb->
dev, NULL,
00328
ip_local_deliver_finish);
00329 }
00330
00341 static inline int ip_rcv_finish(
struct sk_buff *skb)
00342 {
00343
struct net_device *dev = skb->
dev;
00344
struct iphdr *iph = skb->
nh.iph;
00345
00346
00347
00348
00349
00350
if (skb->
dst == NULL) {
00351
if (
ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))
00352
goto drop;
00353 }
00354
00355
#ifdef CONFIG_NET_CLS_ROUTE
00356
if (skb->
dst->tclassid) {
00357
struct ip_rt_acct *st =
ip_rt_acct + 256*smp_processor_id();
00358 u32 idx = skb->
dst->tclassid;
00359 st[idx&0xFF].o_packets++;
00360 st[idx&0xFF].o_bytes+=skb->
len;
00361 st[(idx>>16)&0xFF].i_packets++;
00362 st[(idx>>16)&0xFF].i_bytes+=skb->
len;
00363 }
00364
#endif
00365
00366
if (iph->ihl > 5) {
00367
struct ip_options *opt;
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
if (
skb_cow(skb,
skb_headroom(skb)))
00378
goto drop;
00379 iph = skb->
nh.iph;
00380
00381
if (
ip_options_compile(NULL, skb))
00382
goto inhdr_error;
00383
00384 opt = &(
IPCB(skb)->opt);
00385
if (opt->srr) {
00386
struct in_device *in_dev =
in_dev_get(dev);
00387
if (in_dev) {
00388
if (!
IN_DEV_SOURCE_ROUTE(in_dev)) {
00389
if (
IN_DEV_LOG_MARTIANS(in_dev) &&
net_ratelimit())
00390 printk(KERN_INFO
"source route option %u.%u.%u.%u -> %u.%u.%u.%u\n",
00391 NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
00392
in_dev_put(in_dev);
00393
goto drop;
00394 }
00395
in_dev_put(in_dev);
00396 }
00397
if (
ip_options_rcv_srr(skb))
00398
goto drop;
00399 }
00400 }
00401
00402
return skb->
dst->
input(skb);
00403
00404 inhdr_error:
00405
IP_INC_STATS_BH(IpInHdrErrors);
00406 drop:
00407
kfree_skb(skb);
00408
return NET_RX_DROP;
00409 }
00410
00411
00412
00413
00421 int ip_rcv(
struct sk_buff *skb,
struct net_device *dev,
struct packet_type *pt)
00422 {
00423
struct iphdr *iph;
00424
00425
00426
00427
00428
if (skb->
pkt_type == PACKET_OTHERHOST)
00429
goto drop;
00430
00431
IP_INC_STATS_BH(IpInReceives);
00432
00433
if ((skb =
skb_share_check(skb, GFP_ATOMIC)) == NULL)
00434
goto out;
00435
00436
if (!
pskb_may_pull(skb,
sizeof(
struct iphdr)))
00437
goto inhdr_error;
00438
00439 iph = skb->
nh.iph;
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
if (iph->ihl < 5 || iph->version != 4)
00453
goto inhdr_error;
00454
00455
if (!
pskb_may_pull(skb, iph->ihl*4))
00456
goto inhdr_error;
00457
00458 iph = skb->
nh.iph;
00459
00460
if (
ip_fast_csum((u8 *)iph, iph->ihl) != 0)
00461
goto inhdr_error;
00462
00463 {
00464 __u32 len = ntohs(iph->tot_len);
00465
if (skb->
len < len || len < (iph->ihl<<2))
00466
goto inhdr_error;
00467
00468
00469
00470
00471
00472
if (skb->
len > len) {
00473
__pskb_trim(skb, len);
00474
if (skb->
ip_summed ==
CHECKSUM_HW)
00475 skb->
ip_summed =
CHECKSUM_NONE;
00476 }
00477 }
00478
00479
return NF_HOOK(PF_INET,
NF_IP_PRE_ROUTING, skb, dev, NULL,
00480
ip_rcv_finish);
00481
00482 inhdr_error:
00483
IP_INC_STATS_BH(IpInHdrErrors);
00484 drop:
00485
kfree_skb(skb);
00486 out:
00487
return NET_RX_DROP;
00488 }
00489