[ovs-dev] [ofp-print 03/18] Use ofpbuf_pull() instead of ofpbuf_try_pull() where it is valid.
Justin Pettit
jpettit at nicira.com
Thu Dec 9 01:01:19 UTC 2010
Looks good.
--Justin
On Dec 8, 2010, at 4:26 PM, Ben Pfaff wrote:
> In each of these cases, we know that the buffer is long enough to pull
> the header because ofputil_decode_msg_type() already checked for us.
> ---
> lib/ofp-util.c | 15 +++------------
> ofproto/ofproto.c | 15 +++------------
> 2 files changed, 6 insertions(+), 24 deletions(-)
>
> diff --git a/lib/ofp-util.c b/lib/ofp-util.c
> index 7673b66..cbba506 100644
> --- a/lib/ofp-util.c
> +++ b/lib/ofp-util.c
> @@ -897,10 +897,7 @@ ofputil_decode_flow_mod(struct flow_mod *fm, const struct ofp_header *oh,
> int error;
>
> /* Dissect the message. */
> - ofm = ofpbuf_try_pull(&b, sizeof *ofm);
> - if (!ofm) {
> - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
> - }
> + ofm = ofpbuf_pull(&b, sizeof *ofm);
> error = ofputil_pull_actions(&b, b.size, &fm->actions, &fm->n_actions);
> if (error) {
> return error;
> @@ -940,10 +937,7 @@ ofputil_decode_flow_mod(struct flow_mod *fm, const struct ofp_header *oh,
> int error;
>
> /* Dissect the message. */
> - nfm = ofpbuf_try_pull(&b, sizeof *nfm);
> - if (!nfm) {
> - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
> - }
> + nfm = ofpbuf_pull(&b, sizeof *nfm);
> error = nx_pull_match(&b, ntohs(nfm->match_len), ntohs(nfm->priority),
> &fm->cr);
> if (error) {
> @@ -1054,10 +1048,7 @@ ofputil_decode_nxst_flow_request(struct flow_stats_request *fsr,
>
> ofpbuf_use_const(&b, oh, ntohs(oh->length));
>
> - nfsr = ofpbuf_try_pull(&b, sizeof *nfsr);
> - if (!nfsr) {
> - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
> - }
> + nfsr = ofpbuf_pull(&b, sizeof *nfsr);
> error = nx_pull_match(&b, ntohs(nfsr->match_len), 0, &fsr->match);
> if (error) {
> return error;
> diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
> index 1ac5983..d5f258f 100644
> --- a/ofproto/ofproto.c
> +++ b/ofproto/ofproto.c
> @@ -3073,10 +3073,7 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh)
>
> /* Get ofp_packet_out. */
> ofpbuf_use_const(&request, oh, ntohs(oh->length));
> - opo = ofpbuf_try_pull(&request, offsetof(struct ofp_packet_out, actions));
> - if (!opo) {
> - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
> - }
> + opo = ofpbuf_pull(&request, offsetof(struct ofp_packet_out, actions));
>
> /* Get actions. */
> error = ofputil_pull_actions(&request, ntohs(opo->actions_len),
> @@ -3517,10 +3514,7 @@ handle_nxst_flow(struct ofconn *ofconn, const struct ofp_header *oh)
> ofpbuf_use_const(&b, oh, ntohs(oh->length));
>
> /* Dissect the message. */
> - nfsr = ofpbuf_try_pull(&b, sizeof *nfsr);
> - if (!nfsr) {
> - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
> - }
> + nfsr = ofpbuf_pull(&b, sizeof *nfsr);
> error = nx_pull_match(&b, ntohs(nfsr->match_len), 0, &target);
> if (error) {
> return error;
> @@ -3652,10 +3646,7 @@ handle_nxst_aggregate(struct ofconn *ofconn, const struct ofp_header *oh)
> ofpbuf_use_const(&b, oh, ntohs(oh->length));
>
> /* Dissect the message. */
> - request = ofpbuf_try_pull(&b, sizeof *request);
> - if (!request) {
> - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
> - }
> + request = ofpbuf_pull(&b, sizeof *request);
> error = nx_pull_match(&b, ntohs(request->match_len), 0, &target);
> if (error) {
> return error;
> --
> 1.7.1
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
More information about the dev
mailing list