aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/route.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-04-01 20:27:33 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-02 04:33:43 -0400
commitc78679e8f31b86c7a46e77a3096011f911854187 (patch)
tree511b7a8e07c89a6ca7936c1ed3cb26300d8fe6a5 /net/ipv6/route.c
parent86ebb02dc793058ea17ad647c802b507dafff7cb (diff)
ipv6: Stop using NLA_PUT*().
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/route.c')
-rw-r--r--net/ipv6/route.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 3992e26a6039..4d70c06f0436 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2413,7 +2413,8 @@ static int rt6_fill_node(struct net *net,
2413 else 2413 else
2414 table = RT6_TABLE_UNSPEC; 2414 table = RT6_TABLE_UNSPEC;
2415 rtm->rtm_table = table; 2415 rtm->rtm_table = table;
2416 NLA_PUT_U32(skb, RTA_TABLE, table); 2416 if (nla_put_u32(skb, RTA_TABLE, table))
2417 goto nla_put_failure;
2417 if (rt->rt6i_flags & RTF_REJECT) 2418 if (rt->rt6i_flags & RTF_REJECT)
2418 rtm->rtm_type = RTN_UNREACHABLE; 2419 rtm->rtm_type = RTN_UNREACHABLE;
2419 else if (rt->rt6i_flags & RTF_LOCAL) 2420 else if (rt->rt6i_flags & RTF_LOCAL)
@@ -2436,16 +2437,20 @@ static int rt6_fill_node(struct net *net,
2436 rtm->rtm_flags |= RTM_F_CLONED; 2437 rtm->rtm_flags |= RTM_F_CLONED;
2437 2438
2438 if (dst) { 2439 if (dst) {
2439 NLA_PUT(skb, RTA_DST, 16, dst); 2440 if (nla_put(skb, RTA_DST, 16, dst))
2441 goto nla_put_failure;
2440 rtm->rtm_dst_len = 128; 2442 rtm->rtm_dst_len = 128;
2441 } else if (rtm->rtm_dst_len) 2443 } else if (rtm->rtm_dst_len)
2442 NLA_PUT(skb, RTA_DST, 16, &rt->rt6i_dst.addr); 2444 if (nla_put(skb, RTA_DST, 16, &rt->rt6i_dst.addr))
2445 goto nla_put_failure;
2443#ifdef CONFIG_IPV6_SUBTREES 2446#ifdef CONFIG_IPV6_SUBTREES
2444 if (src) { 2447 if (src) {
2445 NLA_PUT(skb, RTA_SRC, 16, src); 2448 if (nla_put(skb, RTA_SRC, 16, src))
2449 goto nla_put_failure;
2446 rtm->rtm_src_len = 128; 2450 rtm->rtm_src_len = 128;
2447 } else if (rtm->rtm_src_len) 2451 } else if (rtm->rtm_src_len &&
2448 NLA_PUT(skb, RTA_SRC, 16, &rt->rt6i_src.addr); 2452 nla_put(skb, RTA_SRC, 16, &rt->rt6i_src.addr))
2453 goto nla_put_failure;
2449#endif 2454#endif
2450 if (iif) { 2455 if (iif) {
2451#ifdef CONFIG_IPV6_MROUTE 2456#ifdef CONFIG_IPV6_MROUTE
@@ -2463,17 +2468,20 @@ static int rt6_fill_node(struct net *net,
2463 } 2468 }
2464 } else 2469 } else
2465#endif 2470#endif
2466 NLA_PUT_U32(skb, RTA_IIF, iif); 2471 if (nla_put_u32(skb, RTA_IIF, iif))
2472 goto nla_put_failure;
2467 } else if (dst) { 2473 } else if (dst) {
2468 struct in6_addr saddr_buf; 2474 struct in6_addr saddr_buf;
2469 if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0) 2475 if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
2470 NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf); 2476 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
2477 goto nla_put_failure;
2471 } 2478 }
2472 2479
2473 if (rt->rt6i_prefsrc.plen) { 2480 if (rt->rt6i_prefsrc.plen) {
2474 struct in6_addr saddr_buf; 2481 struct in6_addr saddr_buf;
2475 saddr_buf = rt->rt6i_prefsrc.addr; 2482 saddr_buf = rt->rt6i_prefsrc.addr;
2476 NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf); 2483 if (nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
2484 goto nla_put_failure;
2477 } 2485 }
2478 2486
2479 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0) 2487 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
@@ -2489,11 +2497,11 @@ static int rt6_fill_node(struct net *net,
2489 } 2497 }
2490 rcu_read_unlock(); 2498 rcu_read_unlock();
2491 2499
2492 if (rt->dst.dev) 2500 if (rt->dst.dev &&
2493 NLA_PUT_U32(skb, RTA_OIF, rt->dst.dev->ifindex); 2501 nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex))
2494 2502 goto nla_put_failure;
2495 NLA_PUT_U32(skb, RTA_PRIORITY, rt->rt6i_metric); 2503 if (nla_put_u32(skb, RTA_PRIORITY, rt->rt6i_metric))
2496 2504 goto nla_put_failure;
2497 if (!(rt->rt6i_flags & RTF_EXPIRES)) 2505 if (!(rt->rt6i_flags & RTF_EXPIRES))
2498 expires = 0; 2506 expires = 0;
2499 else if (rt->dst.expires - jiffies < INT_MAX) 2507 else if (rt->dst.expires - jiffies < INT_MAX)