2008-05-18 20:24:13 +00:00
|
|
|
Index: linux-2.6.22.19/include/linux/rtnetlink.h
|
|
|
|
===================================================================
|
|
|
|
--- linux-2.6.22.19.orig/include/linux/rtnetlink.h
|
|
|
|
+++ linux-2.6.22.19/include/linux/rtnetlink.h
|
|
|
|
@@ -293,6 +293,8 @@ struct rtnexthop
|
2007-06-16 01:56:04 +00:00
|
|
|
#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
|
|
|
|
#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
|
|
|
|
#define RTNH_F_ONLINK 4 /* Gateway is forced on link */
|
|
|
|
+#define RTNH_F_SUSPECT 8 /* We don't know the real state */
|
|
|
|
+#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
|
|
|
|
|
|
|
|
/* Macros to handle hexthops */
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
Index: linux-2.6.22.19/include/net/flow.h
|
|
|
|
===================================================================
|
|
|
|
--- linux-2.6.22.19.orig/include/net/flow.h
|
|
|
|
+++ linux-2.6.22.19/include/net/flow.h
|
|
|
|
@@ -19,6 +19,8 @@ struct flowi {
|
2007-06-16 01:56:04 +00:00
|
|
|
struct {
|
|
|
|
__be32 daddr;
|
|
|
|
__be32 saddr;
|
|
|
|
+ __u32 lsrc;
|
|
|
|
+ __u32 gw;
|
|
|
|
__u8 tos;
|
|
|
|
__u8 scope;
|
|
|
|
} ip4_u;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -43,6 +45,8 @@ struct flowi {
|
2007-06-16 01:56:04 +00:00
|
|
|
#define fl6_flowlabel nl_u.ip6_u.flowlabel
|
|
|
|
#define fl4_dst nl_u.ip4_u.daddr
|
|
|
|
#define fl4_src nl_u.ip4_u.saddr
|
|
|
|
+#define fl4_lsrc nl_u.ip4_u.lsrc
|
|
|
|
+#define fl4_gw nl_u.ip4_u.gw
|
|
|
|
#define fl4_tos nl_u.ip4_u.tos
|
|
|
|
#define fl4_scope nl_u.ip4_u.scope
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
Index: linux-2.6.22.19/net/ipv4/route.c
|
|
|
|
===================================================================
|
|
|
|
--- linux-2.6.22.19.orig/net/ipv4/route.c
|
|
|
|
+++ linux-2.6.22.19/net/ipv4/route.c
|
|
|
|
@@ -1208,6 +1208,7 @@ void ip_rt_redirect(__be32 old_gw, __be3
|
2007-06-16 01:56:04 +00:00
|
|
|
|
|
|
|
/* Gateway is different ... */
|
|
|
|
rt->rt_gateway = new_gw;
|
|
|
|
+ if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
|
|
|
|
|
|
|
|
/* Redirect received -> path was valid */
|
|
|
|
dst_confirm(&rth->u.dst);
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1643,6 +1644,7 @@ static int ip_route_input_mc(struct sk_b
|
2007-06-16 01:56:04 +00:00
|
|
|
rth->fl.fl4_tos = tos;
|
|
|
|
rth->fl.mark = skb->mark;
|
|
|
|
rth->fl.fl4_src = saddr;
|
|
|
|
+ rth->fl.fl4_lsrc = 0;
|
|
|
|
rth->rt_src = saddr;
|
|
|
|
#ifdef CONFIG_NET_CLS_ROUTE
|
|
|
|
rth->u.dst.tclassid = itag;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1653,6 +1655,7 @@ static int ip_route_input_mc(struct sk_b
|
2007-06-16 01:56:04 +00:00
|
|
|
dev_hold(rth->u.dst.dev);
|
|
|
|
rth->idev = in_dev_get(rth->u.dst.dev);
|
|
|
|
rth->fl.oif = 0;
|
|
|
|
+ rth->fl.fl4_gw = 0;
|
|
|
|
rth->rt_gateway = daddr;
|
|
|
|
rth->rt_spec_dst= spec_dst;
|
|
|
|
rth->rt_type = RTN_MULTICAST;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1716,7 +1719,7 @@ static void ip_handle_martian_source(str
|
2007-06-16 01:56:04 +00:00
|
|
|
static inline int __mkroute_input(struct sk_buff *skb,
|
|
|
|
struct fib_result* res,
|
|
|
|
struct in_device *in_dev,
|
|
|
|
- __be32 daddr, __be32 saddr, u32 tos,
|
|
|
|
+ __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
|
|
|
|
struct rtable **result)
|
|
|
|
{
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1751,6 +1754,7 @@ static inline int __mkroute_input(struct
|
2007-06-16 01:56:04 +00:00
|
|
|
flags |= RTCF_DIRECTSRC;
|
|
|
|
|
|
|
|
if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
|
|
|
|
+ !lsrc &&
|
|
|
|
(IN_DEV_SHARED_MEDIA(out_dev) ||
|
|
|
|
inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
|
|
|
|
flags |= RTCF_DOREDIRECT;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1788,6 +1792,7 @@ static inline int __mkroute_input(struct
|
2007-06-16 01:56:04 +00:00
|
|
|
rth->fl.mark = skb->mark;
|
|
|
|
rth->fl.fl4_src = saddr;
|
|
|
|
rth->rt_src = saddr;
|
|
|
|
+ rth->fl.fl4_lsrc = lsrc;
|
|
|
|
rth->rt_gateway = daddr;
|
|
|
|
rth->rt_iif =
|
|
|
|
rth->fl.iif = in_dev->dev->ifindex;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1795,6 +1800,7 @@ static inline int __mkroute_input(struct
|
2007-06-16 01:56:04 +00:00
|
|
|
dev_hold(rth->u.dst.dev);
|
|
|
|
rth->idev = in_dev_get(rth->u.dst.dev);
|
|
|
|
rth->fl.oif = 0;
|
|
|
|
+ rth->fl.fl4_gw = 0;
|
|
|
|
rth->rt_spec_dst= spec_dst;
|
|
|
|
|
|
|
|
rth->u.dst.input = ip_forward;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1816,19 +1822,21 @@ static inline int ip_mkroute_input_def(s
|
2007-06-16 01:56:04 +00:00
|
|
|
struct fib_result* res,
|
|
|
|
const struct flowi *fl,
|
|
|
|
struct in_device *in_dev,
|
|
|
|
- __be32 daddr, __be32 saddr, u32 tos)
|
|
|
|
+ __be32 daddr, __be32 saddr, u32 tos,
|
|
|
|
+ u32 lsrc)
|
|
|
|
{
|
|
|
|
struct rtable* rth = NULL;
|
|
|
|
int err;
|
|
|
|
unsigned hash;
|
|
|
|
|
|
|
|
+ fib_select_default(fl, res);
|
|
|
|
#ifdef CONFIG_IP_ROUTE_MULTIPATH
|
|
|
|
- if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
|
|
|
|
+ if (res->fi && res->fi->fib_nhs > 1)
|
|
|
|
fib_select_multipath(fl, res);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* create a routing cache entry */
|
|
|
|
- err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
|
|
|
|
+ err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1841,7 +1849,8 @@ static inline int ip_mkroute_input(struc
|
2007-06-16 01:56:04 +00:00
|
|
|
struct fib_result* res,
|
|
|
|
const struct flowi *fl,
|
|
|
|
struct in_device *in_dev,
|
|
|
|
- __be32 daddr, __be32 saddr, u32 tos)
|
|
|
|
+ __be32 daddr, __be32 saddr, u32 tos,
|
|
|
|
+ u32 lsrc)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
|
|
|
|
struct rtable* rth = NULL, *rtres;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1857,7 +1866,7 @@ static inline int ip_mkroute_input(struc
|
2007-06-16 01:56:04 +00:00
|
|
|
/* distinguish between multipath and singlepath */
|
|
|
|
if (hopcount < 2)
|
|
|
|
return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
|
|
|
|
- saddr, tos);
|
|
|
|
+ saddr, tos, 0);
|
|
|
|
|
|
|
|
/* add all alternatives to the routing cache */
|
|
|
|
for (hop = 0; hop < hopcount; hop++) {
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1869,7 +1878,7 @@ static inline int ip_mkroute_input(struc
|
2007-06-16 01:56:04 +00:00
|
|
|
|
|
|
|
/* create a routing cache entry */
|
|
|
|
err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
|
|
|
|
- &rth);
|
|
|
|
+ 0, &rth);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1889,7 +1898,7 @@ static inline int ip_mkroute_input(struc
|
2007-06-16 01:56:04 +00:00
|
|
|
skb->dst = &rtres->u.dst;
|
|
|
|
return err;
|
|
|
|
#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
|
|
|
|
- return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
|
|
|
|
+ return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
|
|
|
|
#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
|
|
|
|
}
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1905,18 +1914,18 @@ static inline int ip_mkroute_input(struc
|
2007-06-16 01:56:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
|
|
|
|
- u8 tos, struct net_device *dev)
|
|
|
|
+ u8 tos, struct net_device *dev, u32 lsrc)
|
|
|
|
{
|
|
|
|
struct fib_result res;
|
|
|
|
struct in_device *in_dev = in_dev_get(dev);
|
|
|
|
struct flowi fl = { .nl_u = { .ip4_u =
|
|
|
|
{ .daddr = daddr,
|
|
|
|
- .saddr = saddr,
|
|
|
|
+ .saddr = lsrc ? : saddr,
|
|
|
|
.tos = tos,
|
|
|
|
.scope = RT_SCOPE_UNIVERSE,
|
|
|
|
} },
|
|
|
|
.mark = skb->mark,
|
|
|
|
- .iif = dev->ifindex };
|
|
|
|
+ .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
|
|
|
|
unsigned flags = 0;
|
|
|
|
u32 itag = 0;
|
|
|
|
struct rtable * rth;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1949,6 +1958,12 @@ static int ip_route_input_slow(struct sk
|
2007-06-16 01:56:04 +00:00
|
|
|
if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
|
|
|
|
goto martian_destination;
|
|
|
|
|
|
|
|
+ if (lsrc) {
|
|
|
|
+ if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
|
|
|
|
+ ZERONET(lsrc) || LOOPBACK(lsrc))
|
|
|
|
+ goto e_inval;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Now we are ready to route packet.
|
|
|
|
*/
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1958,6 +1973,10 @@ static int ip_route_input_slow(struct sk
|
2007-06-16 01:56:04 +00:00
|
|
|
goto no_route;
|
|
|
|
}
|
|
|
|
free_res = 1;
|
|
|
|
+ if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
|
|
|
|
+ goto e_inval;
|
|
|
|
+ fl.iif = dev->ifindex;
|
|
|
|
+ fl.fl4_src = saddr;
|
|
|
|
|
|
|
|
RT_CACHE_STAT_INC(in_slow_tot);
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1982,7 +2001,7 @@ static int ip_route_input_slow(struct sk
|
2007-06-16 01:56:04 +00:00
|
|
|
if (res.type != RTN_UNICAST)
|
|
|
|
goto martian_destination;
|
|
|
|
|
|
|
|
- err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
|
|
|
|
+ err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
|
|
|
|
if (err == -ENOBUFS)
|
|
|
|
goto e_nobufs;
|
|
|
|
if (err == -EINVAL)
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -1997,6 +2016,8 @@ out: return err;
|
2007-06-16 01:56:04 +00:00
|
|
|
brd_input:
|
|
|
|
if (skb->protocol != htons(ETH_P_IP))
|
|
|
|
goto e_inval;
|
|
|
|
+ if (lsrc)
|
|
|
|
+ goto e_inval;
|
|
|
|
|
|
|
|
if (ZERONET(saddr))
|
|
|
|
spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2037,6 +2058,7 @@ local_input:
|
2007-06-16 01:56:04 +00:00
|
|
|
rth->u.dst.dev = &loopback_dev;
|
|
|
|
dev_hold(rth->u.dst.dev);
|
|
|
|
rth->idev = in_dev_get(rth->u.dst.dev);
|
|
|
|
+ rth->fl.fl4_gw = 0;
|
|
|
|
rth->rt_gateway = daddr;
|
|
|
|
rth->rt_spec_dst= spec_dst;
|
|
|
|
rth->u.dst.input= ip_local_deliver;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2086,8 +2108,9 @@ martian_source:
|
2007-06-16 01:56:04 +00:00
|
|
|
goto e_inval;
|
|
|
|
}
|
|
|
|
|
|
|
|
-int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
|
|
|
|
- u8 tos, struct net_device *dev)
|
|
|
|
+static inline int
|
|
|
|
+ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
|
|
|
|
+ u8 tos, struct net_device *dev, u32 lsrc)
|
|
|
|
{
|
|
|
|
struct rtable * rth;
|
|
|
|
unsigned hash;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2102,6 +2125,7 @@ int ip_route_input(struct sk_buff *skb,
|
2007-06-16 01:56:04 +00:00
|
|
|
if (rth->fl.fl4_dst == daddr &&
|
|
|
|
rth->fl.fl4_src == saddr &&
|
|
|
|
rth->fl.iif == iif &&
|
|
|
|
+ rth->fl.fl4_lsrc == lsrc &&
|
|
|
|
rth->fl.oif == 0 &&
|
|
|
|
rth->fl.mark == skb->mark &&
|
|
|
|
rth->fl.fl4_tos == tos) {
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2148,7 +2172,19 @@ int ip_route_input(struct sk_buff *skb,
|
2007-06-16 01:56:04 +00:00
|
|
|
rcu_read_unlock();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
- return ip_route_input_slow(skb, daddr, saddr, tos, dev);
|
|
|
|
+ return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
|
|
|
|
+ u8 tos, struct net_device *dev)
|
|
|
|
+{
|
|
|
|
+ return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
|
|
|
|
+ u8 tos, struct net_device *dev, u32 lsrc)
|
|
|
|
+{
|
|
|
|
+ return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __mkroute_output(struct rtable **result,
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2227,6 +2263,7 @@ static inline int __mkroute_output(struc
|
2007-06-16 01:56:04 +00:00
|
|
|
rth->fl.fl4_tos = tos;
|
|
|
|
rth->fl.fl4_src = oldflp->fl4_src;
|
|
|
|
rth->fl.oif = oldflp->oif;
|
|
|
|
+ rth->fl.fl4_gw = oldflp->fl4_gw;
|
|
|
|
rth->fl.mark = oldflp->mark;
|
|
|
|
rth->rt_dst = fl->fl4_dst;
|
|
|
|
rth->rt_src = fl->fl4_src;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2367,6 +2404,7 @@ static int ip_route_output_slow(struct r
|
2007-06-16 01:56:04 +00:00
|
|
|
struct flowi fl = { .nl_u = { .ip4_u =
|
|
|
|
{ .daddr = oldflp->fl4_dst,
|
|
|
|
.saddr = oldflp->fl4_src,
|
|
|
|
+ .gw = oldflp->fl4_gw,
|
|
|
|
.tos = tos & IPTOS_RT_MASK,
|
|
|
|
.scope = ((tos & RTO_ONLINK) ?
|
|
|
|
RT_SCOPE_LINK :
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2470,6 +2508,7 @@ static int ip_route_output_slow(struct r
|
2007-06-16 01:56:04 +00:00
|
|
|
dev_out = &loopback_dev;
|
|
|
|
dev_hold(dev_out);
|
|
|
|
fl.oif = loopback_dev.ifindex;
|
|
|
|
+ fl.fl4_gw = 0;
|
|
|
|
res.type = RTN_LOCAL;
|
|
|
|
flags |= RTCF_LOCAL;
|
|
|
|
goto make_route;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2477,7 +2516,7 @@ static int ip_route_output_slow(struct r
|
2007-06-16 01:56:04 +00:00
|
|
|
|
|
|
|
if (fib_lookup(&fl, &res)) {
|
|
|
|
res.fi = NULL;
|
|
|
|
- if (oldflp->oif) {
|
|
|
|
+ if (oldflp->oif && dev_out->flags & IFF_UP) {
|
|
|
|
/* Apparently, routing tables are wrong. Assume,
|
|
|
|
that the destination is on link.
|
|
|
|
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2517,6 +2556,7 @@ static int ip_route_output_slow(struct r
|
2007-06-16 01:56:04 +00:00
|
|
|
dev_out = &loopback_dev;
|
|
|
|
dev_hold(dev_out);
|
|
|
|
fl.oif = dev_out->ifindex;
|
|
|
|
+ fl.fl4_gw = 0;
|
|
|
|
if (res.fi)
|
|
|
|
fib_info_put(res.fi);
|
|
|
|
res.fi = NULL;
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2524,13 +2564,12 @@ static int ip_route_output_slow(struct r
|
2007-06-16 01:56:04 +00:00
|
|
|
goto make_route;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (res.type == RTN_UNICAST)
|
|
|
|
+ fib_select_default(&fl, &res);
|
|
|
|
#ifdef CONFIG_IP_ROUTE_MULTIPATH
|
|
|
|
- if (res.fi->fib_nhs > 1 && fl.oif == 0)
|
|
|
|
+ if (res.fi->fib_nhs > 1)
|
|
|
|
fib_select_multipath(&fl, &res);
|
|
|
|
- else
|
|
|
|
#endif
|
|
|
|
- if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
|
|
|
|
- fib_select_default(&fl, &res);
|
|
|
|
|
|
|
|
if (!fl.fl4_src)
|
|
|
|
fl.fl4_src = FIB_RES_PREFSRC(res);
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -2567,6 +2606,7 @@ int __ip_route_output_key(struct rtable
|
2007-06-16 01:56:04 +00:00
|
|
|
rth->fl.fl4_src == flp->fl4_src &&
|
|
|
|
rth->fl.iif == 0 &&
|
|
|
|
rth->fl.oif == flp->oif &&
|
|
|
|
+ rth->fl.fl4_gw == flp->fl4_gw &&
|
|
|
|
rth->fl.mark == flp->mark &&
|
|
|
|
!((rth->fl.fl4_tos ^ flp->fl4_tos) &
|
|
|
|
(IPTOS_RT_MASK | RTO_ONLINK))) {
|
2008-05-18 20:24:13 +00:00
|
|
|
@@ -3267,3 +3307,4 @@ int __init ip_rt_init(void)
|
2007-06-16 01:56:04 +00:00
|
|
|
EXPORT_SYMBOL(__ip_select_ident);
|
|
|
|
EXPORT_SYMBOL(ip_route_input);
|
|
|
|
EXPORT_SYMBOL(ip_route_output_key);
|
|
|
|
+EXPORT_SYMBOL(ip_route_input_lookup);
|