Skip to content

Commit 8e36360

Browse files
committed
ipv4: Remove route key identity dependencies in ip_rt_get_source().
Pass in the sk_buff so that we can fetch the necessary keys from the packet header when working with input routes. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 22f728f commit 8e36360

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

include/net/route.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ extern unsigned inet_addr_type(struct net *net, __be32 addr);
189189
extern unsigned inet_dev_addr_type(struct net *net, const struct net_device *dev, __be32 addr);
190190
extern void ip_rt_multicast_event(struct in_device *);
191191
extern int ip_rt_ioctl(struct net *, unsigned int cmd, void __user *arg);
192-
extern void ip_rt_get_source(u8 *src, struct rtable *rt);
192+
extern void ip_rt_get_source(u8 *src, struct sk_buff *skb, struct rtable *rt);
193193
extern int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb);
194194

195195
struct in_ifaddr;

net/ipv4/ip_options.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838

3939
void ip_options_build(struct sk_buff *skb, struct ip_options *opt,
40-
__be32 daddr, struct rtable *rt, int is_frag)
40+
__be32 daddr, struct rtable *rt, int is_frag)
4141
{
4242
unsigned char *iph = skb_network_header(skb);
4343

@@ -50,9 +50,9 @@ void ip_options_build(struct sk_buff *skb, struct ip_options *opt,
5050

5151
if (!is_frag) {
5252
if (opt->rr_needaddr)
53-
ip_rt_get_source(iph+opt->rr+iph[opt->rr+2]-5, rt);
53+
ip_rt_get_source(iph+opt->rr+iph[opt->rr+2]-5, skb, rt);
5454
if (opt->ts_needaddr)
55-
ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, rt);
55+
ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, skb, rt);
5656
if (opt->ts_needtime) {
5757
struct timespec tv;
5858
__be32 midtime;
@@ -553,7 +553,7 @@ void ip_forward_options(struct sk_buff *skb)
553553

554554
if (opt->rr_needaddr) {
555555
optptr = (unsigned char *)raw + opt->rr;
556-
ip_rt_get_source(&optptr[optptr[2]-5], rt);
556+
ip_rt_get_source(&optptr[optptr[2]-5], skb, rt);
557557
opt->is_changed = 1;
558558
}
559559
if (opt->srr_is_hit) {
@@ -572,13 +572,13 @@ void ip_forward_options(struct sk_buff *skb)
572572
}
573573
if (srrptr + 3 <= srrspace) {
574574
opt->is_changed = 1;
575-
ip_rt_get_source(&optptr[srrptr-1], rt);
575+
ip_rt_get_source(&optptr[srrptr-1], skb, rt);
576576
optptr[2] = srrptr+4;
577577
} else if (net_ratelimit())
578578
printk(KERN_CRIT "ip_forward(): Argh! Destination lost!\n");
579579
if (opt->ts_needaddr) {
580580
optptr = raw + opt->ts;
581-
ip_rt_get_source(&optptr[optptr[2]-9], rt);
581+
ip_rt_get_source(&optptr[optptr[2]-9], skb, rt);
582582
opt->is_changed = 1;
583583
}
584584
}

net/ipv4/route.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,22 +1699,26 @@ static int ip_rt_bug(struct sk_buff *skb)
16991699
in IP options!
17001700
*/
17011701

1702-
void ip_rt_get_source(u8 *addr, struct rtable *rt)
1702+
void ip_rt_get_source(u8 *addr, struct sk_buff *skb, struct rtable *rt)
17031703
{
17041704
__be32 src;
1705-
struct fib_result res;
17061705

17071706
if (rt_is_output_route(rt))
17081707
src = rt->rt_src;
17091708
else {
1710-
struct flowi4 fl4 = {
1711-
.daddr = rt->rt_key_dst,
1712-
.saddr = rt->rt_key_src,
1713-
.flowi4_tos = rt->rt_key_tos,
1714-
.flowi4_oif = rt->rt_oif,
1715-
.flowi4_iif = rt->rt_iif,
1716-
.flowi4_mark = rt->rt_mark,
1717-
};
1709+
struct fib_result res;
1710+
struct flowi4 fl4;
1711+
struct iphdr *iph;
1712+
1713+
iph = ip_hdr(skb);
1714+
1715+
memset(&fl4, 0, sizeof(fl4));
1716+
fl4.daddr = iph->daddr;
1717+
fl4.saddr = iph->saddr;
1718+
fl4.flowi4_tos = iph->tos;
1719+
fl4.flowi4_oif = rt->dst.dev->ifindex;
1720+
fl4.flowi4_iif = skb->dev->ifindex;
1721+
fl4.flowi4_mark = skb->mark;
17181722

17191723
rcu_read_lock();
17201724
if (fib_lookup(dev_net(rt->dst.dev), &fl4, &res) == 0)

0 commit comments

Comments
 (0)