Commit ee3f1aaf authored by David S. Miller's avatar David S. Miller

ipv4: Lookup multicast routes by rtable using helper.

Create a common helper for this operation, since we do
it identically in three spots.

Suggested by Eric Dumazet.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bd33acc3
...@@ -1793,6 +1793,24 @@ static int ip_mr_forward(struct net *net, struct mr_table *mrt, ...@@ -1793,6 +1793,24 @@ static int ip_mr_forward(struct net *net, struct mr_table *mrt,
return 0; return 0;
} }
static struct mr_table *ipmr_rt_fib_lookup(struct net *net, struct rtable *rt)
{
struct flowi fl = {
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
struct mr_table *mrt;
int err;
err = ipmr_fib_lookup(net, &fl, &mrt);
if (err)
return ERR_PTR(err);
return mrt;
}
/* /*
* Multicast packets for forwarding arrive here * Multicast packets for forwarding arrive here
...@@ -1805,7 +1823,6 @@ int ip_mr_input(struct sk_buff *skb) ...@@ -1805,7 +1823,6 @@ int ip_mr_input(struct sk_buff *skb)
struct net *net = dev_net(skb->dev); struct net *net = dev_net(skb->dev);
int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL;
struct mr_table *mrt; struct mr_table *mrt;
int err;
/* Packet is looped back after forward, it should not be /* Packet is looped back after forward, it should not be
* forwarded second time, but still can be delivered locally. * forwarded second time, but still can be delivered locally.
...@@ -1813,21 +1830,10 @@ int ip_mr_input(struct sk_buff *skb) ...@@ -1813,21 +1830,10 @@ int ip_mr_input(struct sk_buff *skb)
if (IPCB(skb)->flags & IPSKB_FORWARDED) if (IPCB(skb)->flags & IPSKB_FORWARDED)
goto dont_forward; goto dont_forward;
{ mrt = ipmr_rt_fib_lookup(net, skb_rtable(skb));
struct rtable *rt = skb_rtable(skb); if (IS_ERR(mrt)) {
struct flowi fl = { kfree_skb(skb);
.fl4_dst = rt->rt_key_dst, return PTR_ERR(mrt);
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
err = ipmr_fib_lookup(net, &fl, &mrt);
if (err < 0) {
kfree_skb(skb);
return err;
}
} }
if (!local) { if (!local) {
if (IPCB(skb)->opt.router_alert) { if (IPCB(skb)->opt.router_alert) {
...@@ -1956,19 +1962,9 @@ int pim_rcv_v1(struct sk_buff *skb) ...@@ -1956,19 +1962,9 @@ int pim_rcv_v1(struct sk_buff *skb)
pim = igmp_hdr(skb); pim = igmp_hdr(skb);
{ mrt = ipmr_rt_fib_lookup(net, skb_rtable(skb));
struct rtable *rt = skb_rtable(skb); if (IS_ERR(mrt))
struct flowi fl = { goto drop;
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
goto drop;
}
if (!mrt->mroute_do_pim || if (!mrt->mroute_do_pim ||
pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
goto drop; goto drop;
...@@ -1998,19 +1994,9 @@ static int pim_rcv(struct sk_buff *skb) ...@@ -1998,19 +1994,9 @@ static int pim_rcv(struct sk_buff *skb)
csum_fold(skb_checksum(skb, 0, skb->len, 0)))) csum_fold(skb_checksum(skb, 0, skb->len, 0))))
goto drop; goto drop;
{ mrt = ipmr_rt_fib_lookup(net, skb_rtable(skb));
struct rtable *rt = skb_rtable(skb); if (IS_ERR(mrt))
struct flowi fl = { goto drop;
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.oif = rt->rt_oif,
.iif = rt->rt_iif,
.mark = rt->rt_mark,
};
if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
goto drop;
}
if (__pim_rcv(mrt, skb, sizeof(*pim))) { if (__pim_rcv(mrt, skb, sizeof(*pim))) {
drop: drop:
kfree_skb(skb); kfree_skb(skb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment