X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fnetlink-socket.c;h=fbb1724f5294e01fef5c92278a7840d1f276d79f;hb=4fff3facd33f3265e8b0066dbd82ec1385afcac7;hp=3bdbbd73c70775d05b6a38ae50ae30afe50dcd9a;hpb=ff459dd649b17f2a2613799c466e979ddd64cdf0;p=sliver-openvswitch.git diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 3bdbbd73c..fbb1724f5 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -16,7 +16,6 @@ #include #include "netlink-socket.h" -#include #include #include #include @@ -60,8 +59,7 @@ static void log_nlmsg(const char *function, int error, /* Netlink sockets. */ -struct nl_sock -{ +struct nl_sock { int fd; uint32_t next_seq; uint32_t pid; @@ -112,10 +110,7 @@ nl_sock_create(int protocol, struct nl_sock **sockp) } *sockp = NULL; - sock = malloc(sizeof *sock); - if (sock == NULL) { - return ENOMEM; - } + sock = xmalloc(sizeof *sock); sock->fd = socket(AF_NETLINK, SOCK_RAW, protocol); if (sock->fd < 0) { @@ -129,8 +124,12 @@ nl_sock_create(int protocol, struct nl_sock **sockp) rcvbuf = 1024 * 1024; if (setsockopt(sock->fd, SOL_SOCKET, SO_RCVBUFFORCE, &rcvbuf, sizeof rcvbuf)) { - VLOG_WARN_RL(&rl, "setting %d-byte socket receive buffer failed (%s)", - rcvbuf, strerror(errno)); + /* Only root can use SO_RCVBUFFORCE. Everyone else gets EPERM. + * Warn only if the failure is therefore unexpected. */ + if (errno != EPERM) { + VLOG_WARN_RL(&rl, "setting %d-byte socket receive buffer failed " + "(%s)", rcvbuf, strerror(errno)); + } } retval = get_socket_rcvbuf(sock->fd); @@ -242,7 +241,7 @@ nl_sock_join_mcgroup(struct nl_sock *sock, unsigned int multicast_group) int nl_sock_leave_mcgroup(struct nl_sock *sock, unsigned int multicast_group) { - assert(!sock->dump); + ovs_assert(!sock->dump); if (setsockopt(sock->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, &multicast_group, sizeof multicast_group) < 0) { VLOG_WARN("could not leave multicast group %u (%s)", @@ -333,7 +332,7 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) struct msghdr msg; ssize_t retval; - assert(buf->allocated >= sizeof *nlmsghdr); + ovs_assert(buf->allocated >= sizeof *nlmsghdr); ofpbuf_clear(buf); iov[0].iov_base = buf->base; @@ -683,7 +682,7 @@ nl_sock_transact(struct nl_sock *sock, const struct ofpbuf *request, struct nl_transaction *transactionp; struct nl_transaction transaction; - transaction.request = (struct ofpbuf *) request; + transaction.request = CONST_CAST(struct ofpbuf *, request); transaction.reply = replyp ? ofpbuf_new(1024) : NULL; transactionp = &transaction; @@ -881,7 +880,7 @@ nl_dump_done(struct nl_dump *dump) while (!dump->status) { struct ofpbuf reply; if (!nl_dump_next(dump, &reply)) { - assert(dump->status); + ovs_assert(dump->status); } } @@ -1100,7 +1099,7 @@ nl_lookup_genl_family(const char *name, int *number) } ofpbuf_delete(reply); - assert(*number != 0); + ovs_assert(*number != 0); } return *number > 0 ? 0 : -*number; }