diff options
author | David S. Miller <davem@davemloft.net> | 2012-03-29 23:20:48 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-01 18:11:37 -0400 |
commit | 028d6a6767456d6c84a72d3451f19fe7ca7b47db (patch) | |
tree | ee49f2a07439ffcaa2ffd34891faf2f30c7cdfef /net/openvswitch | |
parent | 569a8fc38367dfafd87454f27ac646c8e6b54bca (diff) |
openvswitch: 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/openvswitch')
-rw-r--r-- | net/openvswitch/datapath.c | 34 | ||||
-rw-r--r-- | net/openvswitch/flow.c | 18 |
2 files changed, 31 insertions, 21 deletions
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 2c030505b335..f5ca1257debf 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c | |||
@@ -779,15 +779,18 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp, | |||
779 | tcp_flags = flow->tcp_flags; | 779 | tcp_flags = flow->tcp_flags; |
780 | spin_unlock_bh(&flow->lock); | 780 | spin_unlock_bh(&flow->lock); |
781 | 781 | ||
782 | if (used) | 782 | if (used && |
783 | NLA_PUT_U64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used)); | 783 | nla_put_u64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used))) |
784 | goto nla_put_failure; | ||
784 | 785 | ||
785 | if (stats.n_packets) | 786 | if (stats.n_packets && |
786 | NLA_PUT(skb, OVS_FLOW_ATTR_STATS, | 787 | nla_put(skb, OVS_FLOW_ATTR_STATS, |
787 | sizeof(struct ovs_flow_stats), &stats); | 788 | sizeof(struct ovs_flow_stats), &stats)) |
789 | goto nla_put_failure; | ||
788 | 790 | ||
789 | if (tcp_flags) | 791 | if (tcp_flags && |
790 | NLA_PUT_U8(skb, OVS_FLOW_ATTR_TCP_FLAGS, tcp_flags); | 792 | nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, tcp_flags)) |
793 | goto nla_put_failure; | ||
791 | 794 | ||
792 | /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if | 795 | /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if |
793 | * this is the first flow to be dumped into 'skb'. This is unusual for | 796 | * this is the first flow to be dumped into 'skb'. This is unusual for |
@@ -1169,7 +1172,8 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, | |||
1169 | goto nla_put_failure; | 1172 | goto nla_put_failure; |
1170 | 1173 | ||
1171 | get_dp_stats(dp, &dp_stats); | 1174 | get_dp_stats(dp, &dp_stats); |
1172 | NLA_PUT(skb, OVS_DP_ATTR_STATS, sizeof(struct ovs_dp_stats), &dp_stats); | 1175 | if (nla_put(skb, OVS_DP_ATTR_STATS, sizeof(struct ovs_dp_stats), &dp_stats)) |
1176 | goto nla_put_failure; | ||
1173 | 1177 | ||
1174 | return genlmsg_end(skb, ovs_header); | 1178 | return genlmsg_end(skb, ovs_header); |
1175 | 1179 | ||
@@ -1469,14 +1473,16 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, | |||
1469 | 1473 | ||
1470 | ovs_header->dp_ifindex = get_dpifindex(vport->dp); | 1474 | ovs_header->dp_ifindex = get_dpifindex(vport->dp); |
1471 | 1475 | ||
1472 | NLA_PUT_U32(skb, OVS_VPORT_ATTR_PORT_NO, vport->port_no); | 1476 | if (nla_put_u32(skb, OVS_VPORT_ATTR_PORT_NO, vport->port_no) || |
1473 | NLA_PUT_U32(skb, OVS_VPORT_ATTR_TYPE, vport->ops->type); | 1477 | nla_put_u32(skb, OVS_VPORT_ATTR_TYPE, vport->ops->type) || |
1474 | NLA_PUT_STRING(skb, OVS_VPORT_ATTR_NAME, vport->ops->get_name(vport)); | 1478 | nla_put_string(skb, OVS_VPORT_ATTR_NAME, vport->ops->get_name(vport)) || |
1475 | NLA_PUT_U32(skb, OVS_VPORT_ATTR_UPCALL_PID, vport->upcall_pid); | 1479 | nla_put_u32(skb, OVS_VPORT_ATTR_UPCALL_PID, vport->upcall_pid)) |
1480 | goto nla_put_failure; | ||
1476 | 1481 | ||
1477 | ovs_vport_get_stats(vport, &vport_stats); | 1482 | ovs_vport_get_stats(vport, &vport_stats); |
1478 | NLA_PUT(skb, OVS_VPORT_ATTR_STATS, sizeof(struct ovs_vport_stats), | 1483 | if (nla_put(skb, OVS_VPORT_ATTR_STATS, sizeof(struct ovs_vport_stats), |
1479 | &vport_stats); | 1484 | &vport_stats)) |
1485 | goto nla_put_failure; | ||
1480 | 1486 | ||
1481 | err = ovs_vport_get_options(vport, skb); | 1487 | err = ovs_vport_get_options(vport, skb); |
1482 | if (err == -EMSGSIZE) | 1488 | if (err == -EMSGSIZE) |
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c index 1252c3081ef1..7cb416381e87 100644 --- a/net/openvswitch/flow.c +++ b/net/openvswitch/flow.c | |||
@@ -1174,11 +1174,13 @@ int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb) | |||
1174 | struct ovs_key_ethernet *eth_key; | 1174 | struct ovs_key_ethernet *eth_key; |
1175 | struct nlattr *nla, *encap; | 1175 | struct nlattr *nla, *encap; |
1176 | 1176 | ||
1177 | if (swkey->phy.priority) | 1177 | if (swkey->phy.priority && |
1178 | NLA_PUT_U32(skb, OVS_KEY_ATTR_PRIORITY, swkey->phy.priority); | 1178 | nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, swkey->phy.priority)) |
1179 | goto nla_put_failure; | ||
1179 | 1180 | ||
1180 | if (swkey->phy.in_port != USHRT_MAX) | 1181 | if (swkey->phy.in_port != USHRT_MAX && |
1181 | NLA_PUT_U32(skb, OVS_KEY_ATTR_IN_PORT, swkey->phy.in_port); | 1182 | nla_put_u32(skb, OVS_KEY_ATTR_IN_PORT, swkey->phy.in_port)) |
1183 | goto nla_put_failure; | ||
1182 | 1184 | ||
1183 | nla = nla_reserve(skb, OVS_KEY_ATTR_ETHERNET, sizeof(*eth_key)); | 1185 | nla = nla_reserve(skb, OVS_KEY_ATTR_ETHERNET, sizeof(*eth_key)); |
1184 | if (!nla) | 1186 | if (!nla) |
@@ -1188,8 +1190,9 @@ int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb) | |||
1188 | memcpy(eth_key->eth_dst, swkey->eth.dst, ETH_ALEN); | 1190 | memcpy(eth_key->eth_dst, swkey->eth.dst, ETH_ALEN); |
1189 | 1191 | ||
1190 | if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) { | 1192 | if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) { |
1191 | NLA_PUT_BE16(skb, OVS_KEY_ATTR_ETHERTYPE, htons(ETH_P_8021Q)); | 1193 | if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, htons(ETH_P_8021Q)) || |
1192 | NLA_PUT_BE16(skb, OVS_KEY_ATTR_VLAN, swkey->eth.tci); | 1194 | nla_put_be16(skb, OVS_KEY_ATTR_VLAN, swkey->eth.tci)) |
1195 | goto nla_put_failure; | ||
1193 | encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP); | 1196 | encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP); |
1194 | if (!swkey->eth.tci) | 1197 | if (!swkey->eth.tci) |
1195 | goto unencap; | 1198 | goto unencap; |
@@ -1200,7 +1203,8 @@ int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb) | |||
1200 | if (swkey->eth.type == htons(ETH_P_802_2)) | 1203 | if (swkey->eth.type == htons(ETH_P_802_2)) |
1201 | goto unencap; | 1204 | goto unencap; |
1202 | 1205 | ||
1203 | NLA_PUT_BE16(skb, OVS_KEY_ATTR_ETHERTYPE, swkey->eth.type); | 1206 | if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, swkey->eth.type)) |
1207 | goto nla_put_failure; | ||
1204 | 1208 | ||
1205 | if (swkey->eth.type == htons(ETH_P_IP)) { | 1209 | if (swkey->eth.type == htons(ETH_P_IP)) { |
1206 | struct ovs_key_ipv4 *ipv4_key; | 1210 | struct ovs_key_ipv4 *ipv4_key; |