}
static ssize_t
-write_path(const char *path, const char *val)
+if_writepathstr(const char *path, const char *val)
{
FILE *fp;
ssize_t r;
return errno == ENOENT ? 0 : -1;
if (n == 1)
return 0;
- return write_path(path, "1") == -1 ? -1 : 0;
+ return if_writepathstr(path, "1") == -1 ? -1 : 0;
}
int
}
static int
-get_netlink(struct dhcpcd_ctx *ctx, struct iovec *iov,
+if_getnetlink(struct dhcpcd_ctx *ctx, struct iovec *iov,
void *arg, int fd, int flags,
int (*callback)(struct dhcpcd_ctx *, void *, struct nlmsghdr *))
{
.iov_len = sizeof(buf),
};
- return get_netlink(ctx, &iov, NULL,
+ return if_getnetlink(ctx, &iov, NULL,
ctx->link_fd, MSG_DONTWAIT, &link_netlink);
}
static int
-send_netlink(struct dhcpcd_ctx *ctx, void *arg,
+if_sendnetlink(struct dhcpcd_ctx *ctx, void *arg,
int protocol, struct nlmsghdr *hdr,
int (*callback)(struct dhcpcd_ctx *, void *, struct nlmsghdr *))
{
int s, r;
- bool privsock;
struct sockaddr_nl snl = { .nl_family = AF_NETLINK };
struct iovec iov = { .iov_base = hdr, .iov_len = hdr->nlmsg_len };
struct msghdr msg = {
.msg_iov = &iov, .msg_iovlen = 1
};
- privsock = (protocol == NETLINK_ROUTE && hdr->nlmsg_type != RTM_GETADDR);
- if (privsock) {
- struct priv *priv;
-
- priv = (struct priv *)ctx->priv;
- s = priv->route_fd;
- } else {
- if ((s = _open_link_socket(&snl, protocol)) == -1)
- return -1;
+ if ((s = _open_link_socket(&snl, protocol)) == -1)
+ return -1;
#ifdef NETLINK_GET_STRICT_CHK
- if (hdr->nlmsg_type == RTM_GETADDR) {
- int on = 1;
+ if (hdr->nlmsg_type == RTM_GETADDR) {
+ int on = 1;
- if (setsockopt(s, SOL_NETLINK, NETLINK_GET_STRICT_CHK,
- &on, sizeof(on)) == -1)
- logerr("%s: NETLINK_GET_STRICT_CHK", __func__);
- }
-#endif
+ if (setsockopt(s, SOL_NETLINK, NETLINK_GET_STRICT_CHK,
+ &on, sizeof(on)) == -1)
+ logerr("%s: NETLINK_GET_STRICT_CHK", __func__);
}
+#endif
/* Request a reply */
hdr->nlmsg_flags |= NLM_F_ACK;
.iov_len = sizeof(buf),
};
- r = get_netlink(ctx, &riov, arg, s, 0, callback);
+ r = if_getnetlink(ctx, &riov, arg, s, 0, callback);
} else
r = -1;
- if (!privsock)
- close(s);
+ close(s);
return r;
}
if (nla_put_string(&nlm.hdr, sizeof(nlm),
CTRL_ATTR_FAMILY_NAME, name) == -1)
return -1;
- return send_netlink(ctx, NULL, NETLINK_GENERIC, &nlm.hdr,
+ return if_sendnetlink(ctx, NULL, NETLINK_GENERIC, &nlm.hdr,
&_gnl_getfamily);
}
nlm.hdr.nlmsg_flags = NLM_F_REQUEST;
nlm.ghdr.cmd = NL80211_CMD_GET_WIPHY;
nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index);
- if (send_netlink(ifp->ctx, ifp, NETLINK_GENERIC, &nlm.hdr, NULL) == -1)
+ if (if_sendnetlink(ifp->ctx, ifp, NETLINK_GENERIC, &nlm.hdr, NULL) == -1)
return -1;
/* We need to parse out the list of scan results and find the one
nlm.ghdr.cmd = NL80211_CMD_GET_SCAN;
nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index);
- return send_netlink(ifp->ctx, ifp,
+ return if_sendnetlink(ifp->ctx, ifp,
NETLINK_GENERIC, &nlm.hdr, &_if_getssid_nl80211);
}
#endif
.ifa.ifa_index = ifp->index,
};
- return send_netlink(ifp->ctx, &ia, NETLINK_ROUTE, &nlm.hdr,
+ return if_sendnetlink(ifp->ctx, &ia, NETLINK_ROUTE, &nlm.hdr,
&_if_addressexists);
}
#endif
add_attr_32(&nlm.hdr, sizeof(nlm), RTA_PRIORITY,
rt->rt_metric);
- return send_netlink(rt->rt_ifp->ctx, NULL,
+ return if_sendnetlink(rt->rt_ifp->ctx, NULL,
NETLINK_ROUTE, &nlm.hdr, NULL);
}
.rt.rtm_family = (unsigned char)af,
};
- return send_netlink(ctx, kroutes, NETLINK_ROUTE, &nlm.hdr, &_if_initrt);
+ return if_sendnetlink(ctx, kroutes, NETLINK_ROUTE, &nlm.hdr, &_if_initrt);
}
&cinfo, sizeof(cinfo));
}
- if (send_netlink(ia->iface->ctx, NULL,
+ if (if_sendnetlink(ia->iface->ctx, NULL,
NETLINK_ROUTE, &nlm.hdr, NULL) == -1)
retval = -1;
return retval;
&cinfo, sizeof(cinfo));
}
- return send_netlink(ia->iface->ctx, NULL,
+ return if_sendnetlink(ia->iface->ctx, NULL,
NETLINK_ROUTE, &nlm.hdr, NULL);
}
add_attr_nest_end(&nlm.hdr, afs6);
add_attr_nest_end(&nlm.hdr, afs);
- return send_netlink(ctx, NULL, NETLINK_ROUTE, &nlm.hdr, NULL);
+ return if_sendnetlink(ctx, NULL, NETLINK_ROUTE, &nlm.hdr, NULL);
#else
UNUSED(ctx);
UNUSED(ifindex);
snprintf(path, sizeof(path), "%s/%s/autoconf", prefix, ifp->name);
ra = check_proc_int(path);
if (ra != 1 && ra != -1) {
- if (write_path(path, "0") == -1)
+ if (if_writepathstr(path, "0") == -1)
logerr("%s: %s", __func__, path);
}
* error as such so just log it and continue */
logfunc("%s", path);
} else if (ra != 0) {
- if (write_path(path, "0") == -1)
+ if (if_writepathstr(path, "0") == -1)
logerr("%s: %s", __func__, path);
}
}