Skip to content

Commit ac8a481

Browse files
Li Weidavem330
authored andcommitted
ipv4: Save nexthop address of LSRR/SSRR option to IPCB.
We can not update iph->daddr in ip_options_rcv_srr(), It is too early. When some exception ocurred later (eg. in ip_forward() when goto sr_failed) we need the ip header be identical to the original one as ICMP need it. Add a field 'nexthop' in struct ip_options to save nexthop of LSRR or SSRR option. Signed-off-by: Li Wei <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 67c170a commit ac8a481

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

include/net/inet_sock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/** struct ip_options - IP Options
3232
*
3333
* @faddr - Saved first hop address
34+
* @nexthop - Saved nexthop address in LSRR and SSRR
3435
* @is_data - Options in __data, rather than skb
3536
* @is_strictroute - Strict source route
3637
* @srr_is_hit - Packet destination addr was our one
@@ -41,6 +42,7 @@
4142
*/
4243
struct ip_options {
4344
__be32 faddr;
45+
__be32 nexthop;
4446
unsigned char optlen;
4547
unsigned char srr;
4648
unsigned char rr;

net/ipv4/ip_forward.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int ip_forward(struct sk_buff *skb)
8484

8585
rt = skb_rtable(skb);
8686

87-
if (opt->is_strictroute && ip_hdr(skb)->daddr != rt->rt_gateway)
87+
if (opt->is_strictroute && opt->nexthop != rt->rt_gateway)
8888
goto sr_failed;
8989

9090
if (unlikely(skb->len > dst_mtu(&rt->dst) && !skb_is_gso(skb) &&

net/ipv4/ip_options.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,13 @@ void ip_forward_options(struct sk_buff *skb)
568568
) {
569569
if (srrptr + 3 > srrspace)
570570
break;
571-
if (memcmp(&ip_hdr(skb)->daddr, &optptr[srrptr-1], 4) == 0)
571+
if (memcmp(&opt->nexthop, &optptr[srrptr-1], 4) == 0)
572572
break;
573573
}
574574
if (srrptr + 3 <= srrspace) {
575575
opt->is_changed = 1;
576576
ip_rt_get_source(&optptr[srrptr-1], skb, rt);
577+
ip_hdr(skb)->daddr = opt->nexthop;
577578
optptr[2] = srrptr+4;
578579
} else if (net_ratelimit())
579580
printk(KERN_CRIT "ip_forward(): Argh! Destination lost!\n");
@@ -640,7 +641,7 @@ int ip_options_rcv_srr(struct sk_buff *skb)
640641
}
641642
if (srrptr <= srrspace) {
642643
opt->srr_is_hit = 1;
643-
iph->daddr = nexthop;
644+
opt->nexthop = nexthop;
644645
opt->is_changed = 1;
645646
}
646647
return 0;

0 commit comments

Comments
 (0)