12 #define pr_fmt(fmt) "IPv4: " fmt
14 #include <linux/capability.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <asm/uaccess.h>
19 #include <asm/unaligned.h>
22 #include <linux/icmp.h>
23 #include <linux/netdevice.h>
24 #include <linux/rtnetlink.h>
46 unsigned char *iph = skb_network_header(skb);
50 opt = &(
IPCB(skb)->opt);
65 memcpy(iph+opt->
ts+iph[opt->
ts+2]-5, &midtime, 4);
93 unsigned char *sptr, *dptr;
99 sopt = &(
IPCB(skb)->opt);
104 sptr = skb_network_header(skb);
108 optlen = sptr[sopt->
rr+1];
109 soffset = sptr[sopt->
rr+2];
111 memcpy(dptr, sptr+sopt->
rr, optlen);
113 if (soffset + 3 > optlen)
115 dptr[2] = soffset + 4;
122 optlen = sptr[sopt->
ts+1];
123 soffset = sptr[sopt->
ts+2];
125 memcpy(dptr, sptr+sopt->
ts, optlen);
126 if (soffset <= optlen) {
128 if (soffset + 3 > optlen)
134 if (soffset + 3 > optlen)
142 if (soffset + 7 <= optlen) {
145 memcpy(&addr, dptr+soffset-1, 4);
159 unsigned char *
start = sptr+sopt->
srr;
165 if (soffset > optlen)
166 soffset = optlen + 1;
169 memcpy(&faddr, &start[soffset-1], 4);
170 for (soffset-=4, doffset=4; soffset > 3; soffset-=4, doffset+=4)
171 memcpy(&dptr[doffset-1], &start[soffset-1], 4);
176 &start[soffset + 3], 4) == 0)
182 memcpy(&start[doffset-1], &daddr, 4);
189 dopt->
optlen += doffset+3;
194 optlen = sptr[sopt->
cipso+1];
200 while (dopt->
optlen & 3) {
215 unsigned char *optptr = skb_network_header(skb) +
sizeof(
struct iphdr);
230 if (optlen<2 || optlen>l)
263 unsigned char *pp_ptr =
NULL;
265 unsigned char *optptr;
270 rt = skb_rtable(skb);
271 optptr = (
unsigned char *)&(ip_hdr(skb)[1]);
274 iph = optptr -
sizeof(
struct iphdr);
276 for (l = opt->
optlen; l > 0; ) {
279 for (optptr++, l--; l>0; optptr++, l--) {
292 if (optlen<2 || optlen>l) {
313 if (optptr[2] != 4 || optlen < 7 || ((optlen-3) & 3)) {
319 memmove(&optptr[3], &optptr[7], optlen-7);
322 opt->
srr = optptr - iph;
337 if (optptr[2] <= optlen) {
338 if (optptr[2]+3 > optlen) {
343 spec_dst_fill(&spec_dst, skb);
344 memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
350 opt->
rr = optptr - iph;
365 if (optptr[2] <= optlen) {
366 unsigned char *timeptr =
NULL;
367 if (optptr[2]+3 > optptr[1]) {
371 switch (optptr[3]&0xF) {
373 opt->
ts = optptr - iph;
375 timeptr = &optptr[optptr[2]-1];
380 if (optptr[2]+7 > optptr[1]) {
384 opt->
ts = optptr - iph;
386 spec_dst_fill(&spec_dst, skb);
387 memcpy(&optptr[optptr[2]-1], &spec_dst, 4);
388 timeptr = &optptr[optptr[2]+3];
395 if (optptr[2]+7 > optptr[1]) {
399 opt->
ts = optptr - iph;
402 memcpy(&addr, &optptr[optptr[2]-1], 4);
406 timeptr = &optptr[optptr[2]+3];
427 unsigned int overflow = optptr[3]>>4;
428 if (overflow == 15) {
432 opt->
ts = optptr - iph;
434 optptr[3] = (optptr[3]&0xF)|((overflow+1)<<4);
444 if (optptr[2] == 0 && optptr[3] == 0)
452 opt->
cipso = optptr - iph;
490 unsigned char *optptr = opt->
__data+opt->
srr-
sizeof(
struct iphdr);
491 memmove(optptr+7, optptr+3, optptr[1]-7);
495 unsigned char *optptr = opt->
__data+opt->
rr-
sizeof(
struct iphdr);
497 memset(&optptr[optptr[2]-1], 0, 4);
500 unsigned char *optptr = opt->
__data+opt->
ts-
sizeof(
struct iphdr);
503 memset(&optptr[optptr[2]-1], 0, 4);
509 memset(&optptr[optptr[2]-1], 0, 4);
514 static struct ip_options_rcu *ip_options_get_alloc(
const int optlen)
516 return kzalloc(
sizeof(
struct ip_options_rcu) + ((optlen + 3) & ~3),
525 opt->
opt.optlen = optlen;
536 unsigned char __user *
data,
int optlen)
546 return ip_options_get_finish(net, optp, opt, optlen);
550 unsigned char *
data,
int optlen)
558 return ip_options_get_finish(net, optp, opt, optlen);
564 unsigned char *optptr;
565 struct rtable *rt = skb_rtable(skb);
566 unsigned char *
raw = skb_network_header(skb);
569 optptr = (
unsigned char *)raw + opt->
rr;
574 int srrptr, srrspace;
576 optptr = raw + opt->
srr;
578 for ( srrptr=optptr[2], srrspace = optptr[1];
582 if (srrptr + 3 > srrspace)
587 if (srrptr + 3 <= srrspace) {
589 ip_hdr(skb)->daddr = opt->
nexthop;
591 optptr[2] = srrptr+4;
597 optptr = raw + opt->
ts;
611 int srrspace, srrptr;
613 struct iphdr *iph = ip_hdr(skb);
614 unsigned char *optptr = skb_network_header(skb) + opt->
srr;
615 struct rtable *rt = skb_rtable(skb);
617 unsigned long orefdst;
634 for (srrptr=optptr[2], srrspace = optptr[1]; srrptr <= srrspace; srrptr += 4) {
635 if (srrptr + 3 > srrspace) {
639 memcpy(&nexthop, &optptr[srrptr-1], 4);
642 skb_dst_set(skb,
NULL);
643 err = ip_route_input(skb, nexthop, iph->
saddr, iph->
tos, skb->
dev);
644 rt2 = skb_rtable(skb);
650 refdst_drop(orefdst);
654 iph->
daddr = nexthop;
657 if (srrptr <= srrspace) {