示例#1
0
int
if_handlelink(struct dhcpcd_ctx *ctx)
{

	return get_netlink(ctx, ctx->iov, NULL,
	    ctx->link_fd, MSG_DONTWAIT, &link_netlink);
}
示例#2
0
static int
send_netlink(struct nlmsghdr *hdr)
{
	int r;
	struct iovec iov;
	struct msghdr msg;
	static unsigned int seq;

	memset(&iov, 0, sizeof(iov));
	iov.iov_base = hdr;
	iov.iov_len = hdr->nlmsg_len;
	memset(&msg, 0, sizeof(msg));
	msg.msg_name = &sock_nl;
	msg.msg_namelen = sizeof(sock_nl);
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	/* Request a reply */
	hdr->nlmsg_flags |= NLM_F_ACK;
	hdr->nlmsg_seq = ++seq;

	if (sendmsg(sock_fd, &msg, 0) != -1)
		r = get_netlink(sock_fd, 0, &err_netlink);
	else
		r = -1;
	return r;
}
示例#3
0
static int
send_netlink(struct dhcpcd_ctx *ctx, struct interface *ifp,
    int protocol, struct nlmsghdr *hdr,
    int (*callback)(struct dhcpcd_ctx *, struct interface *, struct nlmsghdr *))
{
	int s, r;
	struct sockaddr_nl snl;
	struct iovec iov[1];
	struct msghdr msg;

	memset(&snl, 0, sizeof(snl));
	snl.nl_family = AF_NETLINK;

	if (protocol == NETLINK_ROUTE) {
		struct priv *priv;

		priv = (struct priv *)ctx->priv;
		s = priv->route_fd;
	} else {
		if ((s = _open_link_socket(&snl, protocol)) == -1)
			return -1;
	}

	memset(&msg, 0, sizeof(msg));
	msg.msg_name = &snl;
	msg.msg_namelen = sizeof(snl);
	memset(&iov, 0, sizeof(iov));
	iov[0].iov_base = hdr;
	iov[0].iov_len = hdr->nlmsg_len;
	msg.msg_iov = iov;
	msg.msg_iovlen = 1;
	/* Request a reply */
	hdr->nlmsg_flags |= NLM_F_ACK;
	hdr->nlmsg_seq = (uint32_t)++ctx->seq;
	if (sendmsg(s, &msg, 0) != -1) {
		struct priv *priv;

		priv = (struct priv *)ctx->priv;
		r = get_netlink(ctx, priv->sndrcv_iov, ifp, s, 0, callback);
	} else
		r = -1;
	if (protocol != NETLINK_ROUTE)
		close(s);
	return r;
}
static int
send_netlink(struct nlmsghdr *hdr)
{
	int fd, r;
	struct sockaddr_nl nl;
	struct iovec iov;
	struct msghdr msg;
	static unsigned int seq;

	if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1)
		return -1;
	memset(&nl, 0, sizeof(nl));
	nl.nl_family = AF_NETLINK;
	if (bind(fd, (struct sockaddr *)&nl, sizeof(nl)) == -1) {
		close(fd);
		return -1;
	}
	memset(&iov, 0, sizeof(iov));
	iov.iov_base = hdr;
	iov.iov_len = hdr->nlmsg_len;
	memset(&msg, 0, sizeof(msg));
	msg.msg_name = &nl;
	msg.msg_namelen = sizeof(nl);
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	/* Request a reply */
	hdr->nlmsg_flags |= NLM_F_ACK;
	hdr->nlmsg_seq = ++seq;

	if (sendmsg(fd, &msg, 0) != -1)
		r = get_netlink(fd, 0, &err_netlink, NULL);
	else
		r = -1;
	close(fd);
	return r;
}
int
link_changed(struct interface *iface)
{
	return get_netlink(iface->link_fd, MSG_DONTWAIT,
			   &link_netlink, iface->name);
}
示例#6
0
int
manage_link(int fd)
{
	return get_netlink(fd, MSG_DONTWAIT, &link_netlink);
}