~ubuntu-branches/ubuntu/wily/openvswitch/wily

« back to all changes in this revision

Viewing changes to lib/netlink.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-08-10 11:35:15 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20150810113515-575vj06oq29emxsn
Tags: 2.4.0~git20150810.97bab95-0ubuntu1
* New upstream snapshot from 2.4 branch:
  - d/*: Align any relevant packaging changes with upstream.
* d/*: wrap-and-sort.
* d/openvswitch-{common,vswitch}.install: Correct install location for
  bash completion files.
* d/tests/openflow.py: Explicitly use ovs-testcontroller as provided
  by 2.4.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "ofpbuf.h"
27
27
#include "timeval.h"
28
28
#include "unaligned.h"
29
 
#include "vlog.h"
 
29
#include "openvswitch/vlog.h"
30
30
 
31
31
VLOG_DEFINE_THIS_MODULE(netlink);
32
32
 
67
67
        int code = EPROTO;
68
68
        if (!err) {
69
69
            VLOG_ERR_RL(&rl, "received invalid nlmsgerr (%"PRIu32" bytes < %"PRIuSIZE")",
70
 
                        ofpbuf_size(msg), NLMSG_HDRLEN + sizeof *err);
 
70
                        msg->size, NLMSG_HDRLEN + sizeof *err);
71
71
        } else if (err->error <= 0 && err->error > INT_MIN) {
72
72
            code = -err->error;
73
73
        }
113
113
{
114
114
    struct nlmsghdr *nlmsghdr;
115
115
 
116
 
    ovs_assert(ofpbuf_size(msg) == 0);
 
116
    ovs_assert(msg->size == 0);
117
117
 
118
118
    nl_msg_reserve(msg, NLMSG_HDRLEN + expected_payload);
119
119
    nlmsghdr = nl_msg_put_uninit(msg, NLMSG_HDRLEN);
152
152
    struct genlmsghdr *genlmsghdr;
153
153
 
154
154
    nl_msg_put_nlmsghdr(msg, GENL_HDRLEN + expected_payload, family, flags);
155
 
    ovs_assert(ofpbuf_size(msg) == NLMSG_HDRLEN);
 
155
    ovs_assert(msg->size == NLMSG_HDRLEN);
156
156
    genlmsghdr = nl_msg_put_uninit(msg, GENL_HDRLEN);
157
157
    genlmsghdr->cmd = cmd;
158
158
    genlmsghdr->version = version;
432
432
size_t
433
433
nl_msg_start_nested(struct ofpbuf *msg, uint16_t type)
434
434
{
435
 
    size_t offset = ofpbuf_size(msg);
 
435
    size_t offset = msg->size;
436
436
    nl_msg_put_unspec(msg, type, NULL, 0);
437
437
    return offset;
438
438
}
443
443
nl_msg_end_nested(struct ofpbuf *msg, size_t offset)
444
444
{
445
445
    struct nlattr *attr = ofpbuf_at_assert(msg, offset, sizeof *attr);
446
 
    attr->nla_len = ofpbuf_size(msg) - offset;
 
446
    attr->nla_len = msg->size - offset;
447
447
}
448
448
 
449
449
/* Appends a nested Netlink attribute of the given 'type', with the 'size'
459
459
 
460
460
/* If 'buffer' begins with a valid "struct nlmsghdr", pulls the header and its
461
461
 * payload off 'buffer', stores header and payload in 'msg->data' and
462
 
 * 'ofpbuf_size(msg)', and returns a pointer to the header.
 
462
 * 'msg->size', and returns a pointer to the header.
463
463
 *
464
464
 * If 'buffer' does not begin with a "struct nlmsghdr" or begins with one that
465
 
 * is invalid, returns NULL without modifying 'buffer'. */
 
465
 * is invalid, returns NULL and clears 'buffer' and 'msg'. */
466
466
struct nlmsghdr *
467
467
nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg)
468
468
{
469
 
    if (ofpbuf_size(buffer) >= sizeof(struct nlmsghdr)) {
 
469
    if (buffer->size >= sizeof(struct nlmsghdr)) {
470
470
        struct nlmsghdr *nlmsghdr = nl_msg_nlmsghdr(buffer);
471
471
        size_t len = nlmsghdr->nlmsg_len;
472
 
        if (len >= sizeof *nlmsghdr && len <= ofpbuf_size(buffer)) {
 
472
        if (len >= sizeof *nlmsghdr && len <= buffer->size) {
473
473
            ofpbuf_use_const(msg, nlmsghdr, len);
474
474
            ofpbuf_pull(buffer, len);
475
475
            return nlmsghdr;
476
476
        }
477
477
    }
478
478
 
479
 
    ofpbuf_set_data(msg, NULL);
480
 
    ofpbuf_set_size(msg, 0);
 
479
    ofpbuf_clear(buffer);
 
480
    msg->data = NULL;
 
481
    msg->size = 0;
481
482
    return NULL;
482
483
}
483
484
 
728
729
 
729
730
    memset(attrs, 0, n_attrs * sizeof *attrs);
730
731
 
731
 
    if (ofpbuf_size(msg) < nla_offset) {
 
732
    if (msg->size < nla_offset) {
732
733
        VLOG_DBG_RL(&rl, "missing headers in nl_policy_parse");
733
734
        return false;
734
735
    }
735
736
 
736
737
    NL_ATTR_FOR_EACH (nla, left, ofpbuf_at(msg, nla_offset, 0),
737
 
                      ofpbuf_size(msg) - nla_offset)
 
738
                      msg->size - nla_offset)
738
739
    {
739
740
        uint16_t type = nl_attr_type(nla);
740
741
        if (type < n_attrs && policy[type].type != NL_A_NO_ATTR) {
798
799
const struct nlattr *
799
800
nl_attr_find(const struct ofpbuf *buf, size_t hdr_len, uint16_t type)
800
801
{
801
 
    return nl_attr_find__(ofpbuf_at(buf, hdr_len, 0), ofpbuf_size(buf) - hdr_len,
 
802
    return nl_attr_find__(ofpbuf_at(buf, hdr_len, 0), buf->size - hdr_len,
802
803
                          type);
803
804
}
804
805