aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/fib_semantics.c
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2019-04-02 17:11:57 -0400
committerDavid S. Miller <davem@davemloft.net>2019-04-04 00:50:20 -0400
commitc236419981224d37a5d0a6e7781f73479d4a030e (patch)
treea6d42c3229296dd4ae8096892d174b7416f55d01 /net/ipv4/fib_semantics.c
parentb0f60193632e4eab4c9663101bb435dd7bc27ae8 (diff)
ipv4: Change fib_nexthop_info and fib_add_nexthop to take fib_nh_common
With the exception of the nexthop weight, the nexthop attributes used by fib_nexthop_info and fib_add_nexthop come from the fib_nh_common struct. Update both to use it and change fib_nexthop_info to check the family as needed. nexthop weight comes from the common struct for existing use cases, but for nexthop groups the weight is outside of the fib_nh_common to allow the same nexthop definition to be used in multiple groups with different weights. Signed-off-by: David Ahern <dsahern@gmail.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/fib_semantics.c')
-rw-r--r--net/ipv4/fib_semantics.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 32fb0123d881..33a43965a232 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1317,35 +1317,44 @@ failure:
1317 return ERR_PTR(err); 1317 return ERR_PTR(err);
1318} 1318}
1319 1319
1320static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh *nh, 1320static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
1321 unsigned int *flags, bool skip_oif) 1321 unsigned int *flags, bool skip_oif)
1322{ 1322{
1323 if (nh->fib_nh_flags & RTNH_F_DEAD) 1323 if (nhc->nhc_flags & RTNH_F_DEAD)
1324 *flags |= RTNH_F_DEAD; 1324 *flags |= RTNH_F_DEAD;
1325 1325
1326 if (nh->fib_nh_flags & RTNH_F_LINKDOWN) { 1326 if (nhc->nhc_flags & RTNH_F_LINKDOWN) {
1327 *flags |= RTNH_F_LINKDOWN; 1327 *flags |= RTNH_F_LINKDOWN;
1328 1328
1329 rcu_read_lock(); 1329 rcu_read_lock();
1330 if (ip_ignore_linkdown(nh->fib_nh_dev)) 1330 switch (nhc->nhc_family) {
1331 *flags |= RTNH_F_DEAD; 1331 case AF_INET:
1332 if (ip_ignore_linkdown(nhc->nhc_dev))
1333 *flags |= RTNH_F_DEAD;
1334 break;
1335 }
1332 rcu_read_unlock(); 1336 rcu_read_unlock();
1333 } 1337 }
1334 1338
1335 if (nh->fib_nh_gw4 && 1339 if (nhc->nhc_has_gw) {
1336 nla_put_in_addr(skb, RTA_GATEWAY, nh->fib_nh_gw4)) 1340 switch (nhc->nhc_family) {
1337 goto nla_put_failure; 1341 case AF_INET:
1342 if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
1343 goto nla_put_failure;
1344 break;
1345 }
1346 }
1338 1347
1339 *flags |= (nh->fib_nh_flags & RTNH_F_ONLINK); 1348 *flags |= (nhc->nhc_flags & RTNH_F_ONLINK);
1340 if (nh->fib_nh_flags & RTNH_F_OFFLOAD) 1349 if (nhc->nhc_flags & RTNH_F_OFFLOAD)
1341 *flags |= RTNH_F_OFFLOAD; 1350 *flags |= RTNH_F_OFFLOAD;
1342 1351
1343 if (!skip_oif && nh->fib_nh_dev && 1352 if (!skip_oif && nhc->nhc_dev &&
1344 nla_put_u32(skb, RTA_OIF, nh->fib_nh_dev->ifindex)) 1353 nla_put_u32(skb, RTA_OIF, nhc->nhc_dev->ifindex))
1345 goto nla_put_failure; 1354 goto nla_put_failure;
1346 1355
1347 if (nh->fib_nh_lws && 1356 if (nhc->nhc_lwtstate &&
1348 lwtunnel_fill_encap(skb, nh->fib_nh_lws) < 0) 1357 lwtunnel_fill_encap(skb, nhc->nhc_lwtstate) < 0)
1349 goto nla_put_failure; 1358 goto nla_put_failure;
1350 1359
1351 return 0; 1360 return 0;
@@ -1355,9 +1364,10 @@ nla_put_failure:
1355} 1364}
1356 1365
1357#ifdef CONFIG_IP_ROUTE_MULTIPATH 1366#ifdef CONFIG_IP_ROUTE_MULTIPATH
1358static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh) 1367static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
1368 int nh_weight)
1359{ 1369{
1360 const struct net_device *dev = nh->fib_nh_dev; 1370 const struct net_device *dev = nhc->nhc_dev;
1361 struct rtnexthop *rtnh; 1371 struct rtnexthop *rtnh;
1362 unsigned int flags = 0; 1372 unsigned int flags = 0;
1363 1373
@@ -1365,10 +1375,10 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh)
1365 if (!rtnh) 1375 if (!rtnh)
1366 goto nla_put_failure; 1376 goto nla_put_failure;
1367 1377
1368 rtnh->rtnh_hops = nh->fib_nh_weight - 1; 1378 rtnh->rtnh_hops = nh_weight - 1;
1369 rtnh->rtnh_ifindex = dev ? dev->ifindex : 0; 1379 rtnh->rtnh_ifindex = dev ? dev->ifindex : 0;
1370 1380
1371 if (fib_nexthop_info(skb, nh, &flags, true) < 0) 1381 if (fib_nexthop_info(skb, nhc, &flags, true) < 0)
1372 goto nla_put_failure; 1382 goto nla_put_failure;
1373 1383
1374 rtnh->rtnh_flags = flags; 1384 rtnh->rtnh_flags = flags;
@@ -1381,7 +1391,9 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh)
1381nla_put_failure: 1391nla_put_failure:
1382 return -EMSGSIZE; 1392 return -EMSGSIZE;
1383} 1393}
1394#endif
1384 1395
1396#ifdef CONFIG_IP_ROUTE_MULTIPATH
1385static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) 1397static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
1386{ 1398{
1387 struct nlattr *mp; 1399 struct nlattr *mp;
@@ -1391,7 +1403,7 @@ static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
1391 goto nla_put_failure; 1403 goto nla_put_failure;
1392 1404
1393 for_nexthops(fi) { 1405 for_nexthops(fi) {
1394 if (fib_add_nexthop(skb, nh) < 0) 1406 if (fib_add_nexthop(skb, &nh->nh_common, nh->fib_nh_weight) < 0)
1395 goto nla_put_failure; 1407 goto nla_put_failure;
1396#ifdef CONFIG_IP_ROUTE_CLASSID 1408#ifdef CONFIG_IP_ROUTE_CLASSID
1397 if (nh->nh_tclassid && 1409 if (nh->nh_tclassid &&
@@ -1457,7 +1469,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
1457 struct fib_nh *nh = &fi->fib_nh[0]; 1469 struct fib_nh *nh = &fi->fib_nh[0];
1458 unsigned int flags = 0; 1470 unsigned int flags = 0;
1459 1471
1460 if (fib_nexthop_info(skb, nh, &flags, false) < 0) 1472 if (fib_nexthop_info(skb, &nh->nh_common, &flags, false) < 0)
1461 goto nla_put_failure; 1473 goto nla_put_failure;
1462 1474
1463 rtm->rtm_flags = flags; 1475 rtm->rtm_flags = flags;