Loading libnl_2/handlers.c +6 −4 Original line number Original line Diff line number Diff line Loading @@ -39,14 +39,16 @@ fail: struct nl_cb *nl_cb_clone(struct nl_cb *orig) struct nl_cb *nl_cb_clone(struct nl_cb *orig) { { struct nl_cb *new_cb; struct nl_cb *new_cb; int new_refcnt; new_cb = nl_cb_alloc(NL_CB_DEFAULT); new_cb = nl_cb_alloc(NL_CB_DEFAULT); if (new_cb == NULL) if (new_cb == NULL) goto fail; goto fail; /* Copy original and set refcount to 1 */ /* Preserve reference count and copy original */ new_refcnt = new_cb->cb_refcnt; memcpy(new_cb, orig, sizeof(*orig)); memcpy(new_cb, orig, sizeof(*orig)); new_cb->cb_refcnt = 1; new_cb->cb_refcnt = new_refcnt; return new_cb; return new_cb; fail: fail: Loading Loading @@ -82,9 +84,9 @@ struct nl_cb *nl_cb_get(struct nl_cb *cb) void nl_cb_put(struct nl_cb *cb) void nl_cb_put(struct nl_cb *cb) { { if (!cb) return; cb->cb_refcnt--; cb->cb_refcnt--; if (cb->cb_refcnt <= 0) if (cb->cb_refcnt <= 0) free(cb); free(cb); } } libnl_2/netlink.c +8 −8 Original line number Original line Diff line number Diff line Loading @@ -59,14 +59,15 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \ { { int rc = -1; int rc = -1; int sk_flags; int sk_flags; int RECV_BUF_SIZE = getpagesize(); int RECV_BUF_SIZE; int errsv; int errsv; struct iovec recvmsg_iov; struct iovec recvmsg_iov; struct msghdr msg; struct msghdr msg; /* Allocate buffer */ /* Allocate buffer */ RECV_BUF_SIZE = getpagesize(); *buf = (unsigned char *) malloc(RECV_BUF_SIZE); *buf = (unsigned char *) malloc(RECV_BUF_SIZE); if (!(*buf)) { if (!buf) { rc = -ENOMEM; rc = -ENOMEM; goto fail; goto fail; } } Loading @@ -90,11 +91,8 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \ errsv = errno; errsv = errno; fcntl(sk->s_fd, F_SETFL, sk_flags); fcntl(sk->s_fd, F_SETFL, sk_flags); if (rc < 0) { if (rc < 0) rc = -errsv; rc = -errsv; free(*buf); *buf = NULL; } fail: fail: return rc; return rc; Loading @@ -110,6 +108,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb) int rc, cb_rc = NL_OK, done = 0; int rc, cb_rc = NL_OK, done = 0; do { do { unsigned char *buf; unsigned char *buf; int i, rem, flags; int i, rem, flags; struct nlmsghdr *nlh; struct nlmsghdr *nlh; Loading Loading @@ -188,6 +187,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb) if (done) if (done) break; break; } } free(buf); free(buf); buf = NULL; buf = NULL; Loading libnl_2/socket.c +13 −22 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,7 @@ int nl_socket_add_membership(struct nl_sock *sk, int group) } } /* Allocate new netlink socket. */ /* Allocate new netlink socket. */ static struct nl_sock *_nl_socket_alloc(void) struct nl_sock *nl_socket_alloc(void) { { struct nl_sock *sk; struct nl_sock *sk; struct timeval tv; struct timeval tv; Loading @@ -39,13 +39,13 @@ static struct nl_sock *_nl_socket_alloc(void) sk = (struct nl_sock *) malloc(sizeof(struct nl_sock)); sk = (struct nl_sock *) malloc(sizeof(struct nl_sock)); if (!sk) if (!sk) return NULL; goto fail; memset(sk, 0, sizeof(*sk)); memset(sk, 0, sizeof(*sk)); /* Get current time */ /* Get current time */ if (gettimeofday(&tv, NULL)) if (gettimeofday(&tv, NULL)) goto fail; return NULL; else else sk->s_seq_next = (int) tv.tv_sec; sk->s_seq_next = (int) tv.tv_sec; Loading @@ -59,36 +59,24 @@ static struct nl_sock *_nl_socket_alloc(void) sk->s_peer.nl_pid = 0; /* Kernel */ sk->s_peer.nl_pid = 0; /* Kernel */ sk->s_peer.nl_groups = 0; /* No groups */ sk->s_peer.nl_groups = 0; /* No groups */ return sk; cb = (struct nl_cb *) malloc(sizeof(struct nl_cb)); fail: free(sk); return NULL; } /* Allocate new netlink socket. */ struct nl_sock *nl_socket_alloc(void) { struct nl_sock *sk = _nl_socket_alloc(); struct nl_cb *cb; if (!sk) return NULL; cb = nl_cb_alloc(NL_CB_DEFAULT); if (!cb) if (!cb) goto cb_fail; goto cb_fail; sk->s_cb = cb; memset(cb, 0, sizeof(*cb)); sk->s_cb = nl_cb_alloc(NL_CB_DEFAULT); return sk; return sk; cb_fail: cb_fail: free(sk); free(sk); fail: return NULL; return NULL; } } /* Allocate new socket with custom callbacks. */ /* Allocate new socket with custom callbacks. */ struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) { { struct nl_sock *sk = _nl_socket_alloc(); struct nl_sock *sk = nl_socket_alloc(); if (!sk) if (!sk) return NULL; return NULL; Loading @@ -96,6 +84,7 @@ struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) nl_cb_get(cb); nl_cb_get(cb); return sk; return sk; } } /* Free a netlink socket. */ /* Free a netlink socket. */ Loading Loading @@ -127,3 +116,5 @@ int nl_socket_get_fd(struct nl_sock *sk) { { return sk->s_fd; return sk->s_fd; } } Loading
libnl_2/handlers.c +6 −4 Original line number Original line Diff line number Diff line Loading @@ -39,14 +39,16 @@ fail: struct nl_cb *nl_cb_clone(struct nl_cb *orig) struct nl_cb *nl_cb_clone(struct nl_cb *orig) { { struct nl_cb *new_cb; struct nl_cb *new_cb; int new_refcnt; new_cb = nl_cb_alloc(NL_CB_DEFAULT); new_cb = nl_cb_alloc(NL_CB_DEFAULT); if (new_cb == NULL) if (new_cb == NULL) goto fail; goto fail; /* Copy original and set refcount to 1 */ /* Preserve reference count and copy original */ new_refcnt = new_cb->cb_refcnt; memcpy(new_cb, orig, sizeof(*orig)); memcpy(new_cb, orig, sizeof(*orig)); new_cb->cb_refcnt = 1; new_cb->cb_refcnt = new_refcnt; return new_cb; return new_cb; fail: fail: Loading Loading @@ -82,9 +84,9 @@ struct nl_cb *nl_cb_get(struct nl_cb *cb) void nl_cb_put(struct nl_cb *cb) void nl_cb_put(struct nl_cb *cb) { { if (!cb) return; cb->cb_refcnt--; cb->cb_refcnt--; if (cb->cb_refcnt <= 0) if (cb->cb_refcnt <= 0) free(cb); free(cb); } }
libnl_2/netlink.c +8 −8 Original line number Original line Diff line number Diff line Loading @@ -59,14 +59,15 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \ { { int rc = -1; int rc = -1; int sk_flags; int sk_flags; int RECV_BUF_SIZE = getpagesize(); int RECV_BUF_SIZE; int errsv; int errsv; struct iovec recvmsg_iov; struct iovec recvmsg_iov; struct msghdr msg; struct msghdr msg; /* Allocate buffer */ /* Allocate buffer */ RECV_BUF_SIZE = getpagesize(); *buf = (unsigned char *) malloc(RECV_BUF_SIZE); *buf = (unsigned char *) malloc(RECV_BUF_SIZE); if (!(*buf)) { if (!buf) { rc = -ENOMEM; rc = -ENOMEM; goto fail; goto fail; } } Loading @@ -90,11 +91,8 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \ errsv = errno; errsv = errno; fcntl(sk->s_fd, F_SETFL, sk_flags); fcntl(sk->s_fd, F_SETFL, sk_flags); if (rc < 0) { if (rc < 0) rc = -errsv; rc = -errsv; free(*buf); *buf = NULL; } fail: fail: return rc; return rc; Loading @@ -110,6 +108,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb) int rc, cb_rc = NL_OK, done = 0; int rc, cb_rc = NL_OK, done = 0; do { do { unsigned char *buf; unsigned char *buf; int i, rem, flags; int i, rem, flags; struct nlmsghdr *nlh; struct nlmsghdr *nlh; Loading Loading @@ -188,6 +187,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb) if (done) if (done) break; break; } } free(buf); free(buf); buf = NULL; buf = NULL; Loading
libnl_2/socket.c +13 −22 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,7 @@ int nl_socket_add_membership(struct nl_sock *sk, int group) } } /* Allocate new netlink socket. */ /* Allocate new netlink socket. */ static struct nl_sock *_nl_socket_alloc(void) struct nl_sock *nl_socket_alloc(void) { { struct nl_sock *sk; struct nl_sock *sk; struct timeval tv; struct timeval tv; Loading @@ -39,13 +39,13 @@ static struct nl_sock *_nl_socket_alloc(void) sk = (struct nl_sock *) malloc(sizeof(struct nl_sock)); sk = (struct nl_sock *) malloc(sizeof(struct nl_sock)); if (!sk) if (!sk) return NULL; goto fail; memset(sk, 0, sizeof(*sk)); memset(sk, 0, sizeof(*sk)); /* Get current time */ /* Get current time */ if (gettimeofday(&tv, NULL)) if (gettimeofday(&tv, NULL)) goto fail; return NULL; else else sk->s_seq_next = (int) tv.tv_sec; sk->s_seq_next = (int) tv.tv_sec; Loading @@ -59,36 +59,24 @@ static struct nl_sock *_nl_socket_alloc(void) sk->s_peer.nl_pid = 0; /* Kernel */ sk->s_peer.nl_pid = 0; /* Kernel */ sk->s_peer.nl_groups = 0; /* No groups */ sk->s_peer.nl_groups = 0; /* No groups */ return sk; cb = (struct nl_cb *) malloc(sizeof(struct nl_cb)); fail: free(sk); return NULL; } /* Allocate new netlink socket. */ struct nl_sock *nl_socket_alloc(void) { struct nl_sock *sk = _nl_socket_alloc(); struct nl_cb *cb; if (!sk) return NULL; cb = nl_cb_alloc(NL_CB_DEFAULT); if (!cb) if (!cb) goto cb_fail; goto cb_fail; sk->s_cb = cb; memset(cb, 0, sizeof(*cb)); sk->s_cb = nl_cb_alloc(NL_CB_DEFAULT); return sk; return sk; cb_fail: cb_fail: free(sk); free(sk); fail: return NULL; return NULL; } } /* Allocate new socket with custom callbacks. */ /* Allocate new socket with custom callbacks. */ struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) { { struct nl_sock *sk = _nl_socket_alloc(); struct nl_sock *sk = nl_socket_alloc(); if (!sk) if (!sk) return NULL; return NULL; Loading @@ -96,6 +84,7 @@ struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) nl_cb_get(cb); nl_cb_get(cb); return sk; return sk; } } /* Free a netlink socket. */ /* Free a netlink socket. */ Loading Loading @@ -127,3 +116,5 @@ int nl_socket_get_fd(struct nl_sock *sk) { { return sk->s_fd; return sk->s_fd; } }