@@ -1438,12 +1438,33 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
1438
1438
}
1439
1439
1440
1440
static struct rtable * rt_dst_alloc (struct net_device * dev ,
1441
+ unsigned int flags , u16 type ,
1441
1442
bool nopolicy , bool noxfrm , bool will_cache )
1442
1443
{
1443
- return dst_alloc (& ipv4_dst_ops , dev , 1 , DST_OBSOLETE_FORCE_CHK ,
1444
- (will_cache ? 0 : (DST_HOST | DST_NOCACHE )) |
1445
- (nopolicy ? DST_NOPOLICY : 0 ) |
1446
- (noxfrm ? DST_NOXFRM : 0 ));
1444
+ struct rtable * rt ;
1445
+
1446
+ rt = dst_alloc (& ipv4_dst_ops , dev , 1 , DST_OBSOLETE_FORCE_CHK ,
1447
+ (will_cache ? 0 : (DST_HOST | DST_NOCACHE )) |
1448
+ (nopolicy ? DST_NOPOLICY : 0 ) |
1449
+ (noxfrm ? DST_NOXFRM : 0 ));
1450
+
1451
+ if (rt ) {
1452
+ rt -> rt_genid = rt_genid_ipv4 (dev_net (dev ));
1453
+ rt -> rt_flags = flags ;
1454
+ rt -> rt_type = type ;
1455
+ rt -> rt_is_input = 0 ;
1456
+ rt -> rt_iif = 0 ;
1457
+ rt -> rt_pmtu = 0 ;
1458
+ rt -> rt_gateway = 0 ;
1459
+ rt -> rt_uses_gateway = 0 ;
1460
+ INIT_LIST_HEAD (& rt -> rt_uncached );
1461
+
1462
+ rt -> dst .output = ip_output ;
1463
+ if (flags & RTCF_LOCAL )
1464
+ rt -> dst .input = ip_local_deliver ;
1465
+ }
1466
+
1467
+ return rt ;
1447
1468
}
1448
1469
1449
1470
/* called in rcu_read_lock() section */
@@ -1452,6 +1473,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1452
1473
{
1453
1474
struct rtable * rth ;
1454
1475
struct in_device * in_dev = __in_dev_get_rcu (dev );
1476
+ unsigned int flags = RTCF_MULTICAST ;
1455
1477
u32 itag = 0 ;
1456
1478
int err ;
1457
1479
@@ -1477,7 +1499,10 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1477
1499
if (err < 0 )
1478
1500
goto e_err ;
1479
1501
}
1480
- rth = rt_dst_alloc (dev_net (dev )-> loopback_dev ,
1502
+ if (our )
1503
+ flags |= RTCF_LOCAL ;
1504
+
1505
+ rth = rt_dst_alloc (dev_net (dev )-> loopback_dev , flags , RTN_MULTICAST ,
1481
1506
IN_DEV_CONF_GET (in_dev , NOPOLICY ), false, false);
1482
1507
if (!rth )
1483
1508
goto e_nobufs ;
@@ -1486,20 +1511,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1486
1511
rth -> dst .tclassid = itag ;
1487
1512
#endif
1488
1513
rth -> dst .output = ip_rt_bug ;
1489
-
1490
- rth -> rt_genid = rt_genid_ipv4 (dev_net (dev ));
1491
- rth -> rt_flags = RTCF_MULTICAST ;
1492
- rth -> rt_type = RTN_MULTICAST ;
1493
1514
rth -> rt_is_input = 1 ;
1494
- rth -> rt_iif = 0 ;
1495
- rth -> rt_pmtu = 0 ;
1496
- rth -> rt_gateway = 0 ;
1497
- rth -> rt_uses_gateway = 0 ;
1498
- INIT_LIST_HEAD (& rth -> rt_uncached );
1499
- if (our ) {
1500
- rth -> dst .input = ip_local_deliver ;
1501
- rth -> rt_flags |= RTCF_LOCAL ;
1502
- }
1503
1515
1504
1516
#ifdef CONFIG_IP_MROUTE
1505
1517
if (!ipv4_is_local_multicast (daddr ) && IN_DEV_MFORWARD (in_dev ))
@@ -1608,27 +1620,18 @@ static int __mkroute_input(struct sk_buff *skb,
1608
1620
}
1609
1621
}
1610
1622
1611
- rth = rt_dst_alloc (out_dev -> dev ,
1623
+ rth = rt_dst_alloc (out_dev -> dev , 0 , res -> type ,
1612
1624
IN_DEV_CONF_GET (in_dev , NOPOLICY ),
1613
1625
IN_DEV_CONF_GET (out_dev , NOXFRM ), do_cache );
1614
1626
if (!rth ) {
1615
1627
err = - ENOBUFS ;
1616
1628
goto cleanup ;
1617
1629
}
1618
1630
1619
- rth -> rt_genid = rt_genid_ipv4 (dev_net (rth -> dst .dev ));
1620
- rth -> rt_flags = 0 ;
1621
- rth -> rt_type = res -> type ;
1622
1631
rth -> rt_is_input = 1 ;
1623
- rth -> rt_iif = 0 ;
1624
- rth -> rt_pmtu = 0 ;
1625
- rth -> rt_gateway = 0 ;
1626
- rth -> rt_uses_gateway = 0 ;
1627
- INIT_LIST_HEAD (& rth -> rt_uncached );
1628
1632
RT_CACHE_STAT_INC (in_slow_tot );
1629
1633
1630
1634
rth -> dst .input = ip_forward ;
1631
- rth -> dst .output = ip_output ;
1632
1635
1633
1636
rt_set_nexthop (rth , daddr , res , fnhe , res -> fi , res -> type , itag );
1634
1637
if (lwtunnel_output_redirect (rth -> dst .lwtstate )) {
@@ -1795,26 +1798,16 @@ out: return err;
1795
1798
}
1796
1799
}
1797
1800
1798
- rth = rt_dst_alloc (net -> loopback_dev ,
1801
+ rth = rt_dst_alloc (net -> loopback_dev , flags | RTCF_LOCAL , res . type ,
1799
1802
IN_DEV_CONF_GET (in_dev , NOPOLICY ), false, do_cache );
1800
1803
if (!rth )
1801
1804
goto e_nobufs ;
1802
1805
1803
- rth -> dst .input = ip_local_deliver ;
1804
1806
rth -> dst .output = ip_rt_bug ;
1805
1807
#ifdef CONFIG_IP_ROUTE_CLASSID
1806
1808
rth -> dst .tclassid = itag ;
1807
1809
#endif
1808
-
1809
- rth -> rt_genid = rt_genid_ipv4 (net );
1810
- rth -> rt_flags = flags |RTCF_LOCAL ;
1811
- rth -> rt_type = res .type ;
1812
1810
rth -> rt_is_input = 1 ;
1813
- rth -> rt_iif = 0 ;
1814
- rth -> rt_pmtu = 0 ;
1815
- rth -> rt_gateway = 0 ;
1816
- rth -> rt_uses_gateway = 0 ;
1817
- INIT_LIST_HEAD (& rth -> rt_uncached );
1818
1811
1819
1812
RT_CACHE_STAT_INC (in_slow_tot );
1820
1813
if (res .type == RTN_UNREACHABLE ) {
@@ -1987,28 +1980,16 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
1987
1980
}
1988
1981
1989
1982
add :
1990
- rth = rt_dst_alloc (dev_out ,
1983
+ rth = rt_dst_alloc (dev_out , flags , type ,
1991
1984
IN_DEV_CONF_GET (in_dev , NOPOLICY ),
1992
1985
IN_DEV_CONF_GET (in_dev , NOXFRM ),
1993
1986
do_cache );
1994
1987
if (!rth )
1995
1988
return ERR_PTR (- ENOBUFS );
1996
1989
1997
- rth -> dst .output = ip_output ;
1998
-
1999
- rth -> rt_genid = rt_genid_ipv4 (dev_net (dev_out ));
2000
- rth -> rt_flags = flags ;
2001
- rth -> rt_type = type ;
2002
- rth -> rt_is_input = 0 ;
2003
1990
rth -> rt_iif = orig_oif ? : 0 ;
2004
- rth -> rt_pmtu = 0 ;
2005
- rth -> rt_gateway = 0 ;
2006
- rth -> rt_uses_gateway = 0 ;
2007
- INIT_LIST_HEAD (& rth -> rt_uncached );
2008
1991
RT_CACHE_STAT_INC (out_slow_tot );
2009
1992
2010
- if (flags & RTCF_LOCAL )
2011
- rth -> dst .input = ip_local_deliver ;
2012
1993
if (flags & (RTCF_BROADCAST | RTCF_MULTICAST )) {
2013
1994
if (flags & RTCF_LOCAL &&
2014
1995
!(dev_out -> flags & IFF_LOOPBACK )) {
0 commit comments