aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/route.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-04-01 20:39:02 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-02 04:33:43 -0400
commitf3756b79e8f76cb92830383c215deba146fe0a26 (patch)
tree107c0e99681a0b26b2e750b3fc7a0b01ba1404aa /net/ipv4/route.c
parente549a6b3a5acff66f0427091e44f814943a26a86 (diff)
ipv4: 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/ipv4/route.c')
-rw-r--r--net/ipv4/route.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 3b110a46362c..e5647b4e51c6 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2973,7 +2973,8 @@ static int rt_fill_info(struct net *net,
2973 r->rtm_src_len = 0; 2973 r->rtm_src_len = 0;
2974 r->rtm_tos = rt->rt_key_tos; 2974 r->rtm_tos = rt->rt_key_tos;
2975 r->rtm_table = RT_TABLE_MAIN; 2975 r->rtm_table = RT_TABLE_MAIN;
2976 NLA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN); 2976 if (nla_put_u32(skb, RTA_TABLE, RT_TABLE_MAIN))
2977 goto nla_put_failure;
2977 r->rtm_type = rt->rt_type; 2978 r->rtm_type = rt->rt_type;
2978 r->rtm_scope = RT_SCOPE_UNIVERSE; 2979 r->rtm_scope = RT_SCOPE_UNIVERSE;
2979 r->rtm_protocol = RTPROT_UNSPEC; 2980 r->rtm_protocol = RTPROT_UNSPEC;
@@ -2981,31 +2982,38 @@ static int rt_fill_info(struct net *net,
2981 if (rt->rt_flags & RTCF_NOTIFY) 2982 if (rt->rt_flags & RTCF_NOTIFY)
2982 r->rtm_flags |= RTM_F_NOTIFY; 2983 r->rtm_flags |= RTM_F_NOTIFY;
2983 2984
2984 NLA_PUT_BE32(skb, RTA_DST, rt->rt_dst); 2985 if (nla_put_be32(skb, RTA_DST, rt->rt_dst))
2985 2986 goto nla_put_failure;
2986 if (rt->rt_key_src) { 2987 if (rt->rt_key_src) {
2987 r->rtm_src_len = 32; 2988 r->rtm_src_len = 32;
2988 NLA_PUT_BE32(skb, RTA_SRC, rt->rt_key_src); 2989 if (nla_put_be32(skb, RTA_SRC, rt->rt_key_src))
2990 goto nla_put_failure;
2989 } 2991 }
2990 if (rt->dst.dev) 2992 if (rt->dst.dev &&
2991 NLA_PUT_U32(skb, RTA_OIF, rt->dst.dev->ifindex); 2993 nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex))
2994 goto nla_put_failure;
2992#ifdef CONFIG_IP_ROUTE_CLASSID 2995#ifdef CONFIG_IP_ROUTE_CLASSID
2993 if (rt->dst.tclassid) 2996 if (rt->dst.tclassid &&
2994 NLA_PUT_U32(skb, RTA_FLOW, rt->dst.tclassid); 2997 nla_put_u32(skb, RTA_FLOW, rt->dst.tclassid))
2998 goto nla_put_failure;
2995#endif 2999#endif
2996 if (rt_is_input_route(rt)) 3000 if (rt_is_input_route(rt)) {
2997 NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_spec_dst); 3001 if (nla_put_be32(skb, RTA_PREFSRC, rt->rt_spec_dst))
2998 else if (rt->rt_src != rt->rt_key_src) 3002 goto nla_put_failure;
2999 NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_src); 3003 } else if (rt->rt_src != rt->rt_key_src) {
3000 3004 if (nla_put_be32(skb, RTA_PREFSRC, rt->rt_src))
3001 if (rt->rt_dst != rt->rt_gateway) 3005 goto nla_put_failure;
3002 NLA_PUT_BE32(skb, RTA_GATEWAY, rt->rt_gateway); 3006 }
3007 if (rt->rt_dst != rt->rt_gateway &&
3008 nla_put_be32(skb, RTA_GATEWAY, rt->rt_gateway))
3009 goto nla_put_failure;
3003 3010
3004 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0) 3011 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
3005 goto nla_put_failure; 3012 goto nla_put_failure;
3006 3013
3007 if (rt->rt_mark) 3014 if (rt->rt_mark &&
3008 NLA_PUT_BE32(skb, RTA_MARK, rt->rt_mark); 3015 nla_put_be32(skb, RTA_MARK, rt->rt_mark))
3016 goto nla_put_failure;
3009 3017
3010 error = rt->dst.error; 3018 error = rt->dst.error;
3011 if (peer) { 3019 if (peer) {
@@ -3046,7 +3054,8 @@ static int rt_fill_info(struct net *net,
3046 } 3054 }
3047 } else 3055 } else
3048#endif 3056#endif
3049 NLA_PUT_U32(skb, RTA_IIF, rt->rt_iif); 3057 if (nla_put_u32(skb, RTA_IIF, rt->rt_iif))
3058 goto nla_put_failure;
3050 } 3059 }
3051 3060
3052 if (rtnl_put_cacheinfo(skb, &rt->dst, id, ts, tsage, 3061 if (rtnl_put_cacheinfo(skb, &rt->dst, id, ts, tsage,