}
if (hint == AF_UNSPEC && strchr(str, ':')) {
- int i = 0;
+ size_t i = 0;
char *s = str, *p;
for (;;) {
long l = strtol(s, &p, 16);
*/
int nl_addr_iszero(struct nl_addr *addr)
{
- int i;
+ unsigned int i;
for (i = 0; i < addr->a_len; i++)
if (addr->a_addr[i])
*/
char *nl_addr2str(struct nl_addr *addr, char *buf, size_t size)
{
- int i;
+ unsigned int i;
char tmp[16];
if (!addr || !addr->a_len) {
struct nla_policy *policy)
{
struct nla_policy *pt;
- int minlen = 0, type = nla_type(nla);
+ unsigned int minlen = 0;
+ int type = nla_type(nla);
if (type <= 0 || type > maxtype)
return 0;
*/
int nl_data_append(struct nl_data *data, void *buf, size_t size)
{
- if (size < 0)
- BUG();
-
if (size > 0) {
data->d_data = realloc(data->d_data, data->d_size + size);
if (!data->d_data)
*/
int genlmsg_len(const struct genlmsghdr *gnlh)
{
- struct nlmsghdr *nlh;
+ const struct nlmsghdr *nlh;
- nlh = (struct nlmsghdr *)((unsigned char *) gnlh - NLMSG_HDRLEN);
+ nlh = (const struct nlmsghdr *)((const unsigned char *) gnlh - NLMSG_HDRLEN);
return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN);
}
*/
int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
{
- return (remaining >= (int)sizeof(struct nlmsghdr) &&
+ return (remaining >= sizeof(struct nlmsghdr) &&
nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
nlh->nlmsg_len <= remaining);
}
"-------------------------- BEGIN NETLINK MESSAGE "
"---------------------------\n");
- fprintf(ofd, " [HEADER] %Zu octets\n", sizeof(struct nlmsghdr));
+ fprintf(ofd, " [HEADER] %zu octets\n", sizeof(struct nlmsghdr));
print_hdr(ofd, msg);
if (hdr->nlmsg_type == NLMSG_ERROR &&
struct nl_msg *errmsg;
struct nlmsgerr *err = nlmsg_data(hdr);
- fprintf(ofd, " [ERRORMSG] %Zu octets\n", sizeof(*err));
+ fprintf(ofd, " [ERRORMSG] %zu octets\n", sizeof(*err));
fprintf(ofd, " .error = %d \"%s\"\n", err->error,
strerror(-err->error));
- fprintf(ofd, " [ORIGINAL MESSAGE] %Zu octets\n", sizeof(*hdr));
+ fprintf(ofd, " [ORIGINAL MESSAGE] %zu octets\n", sizeof(*hdr));
errmsg = nlmsg_inherit(&err->msg);
print_hdr(ofd, errmsg);
int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
unsigned char **buf, struct ucred **creds)
{
- int n;
+ ssize_t n;
int flags = 0;
static int page_size = 0;
struct iovec iov;
int nl_object_identical(struct nl_object *a, struct nl_object *b)
{
struct nl_object_ops *ops = obj_ops(a);
- int req_attrs;
+ uint32_t req_attrs;
/* Both objects must be of same type */
if (ops != obj_ops(b))
return 0;
req_attrs = ops->oo_id_attrs;
- if (req_attrs == ~0)
+ if (req_attrs == 0xFFFFFFFF)
req_attrs = a->ce_mask & b->ce_mask;
/* Both objects must provide all required attributes to uniquely
int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags,
struct nl_msg **result)
{
- int required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
+ uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
ADDR_ATTR_PREFIXLEN | ADDR_ATTR_LOCAL;
if ((addr->ce_mask & required) != required)
int rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags,
struct nl_msg **result)
{
- int required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
+ uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
if ((addr->ce_mask & required) != required)
return -NLE_MISSING_ATTR;
static int class_build(struct rtnl_class *class, int type, int flags,
struct nl_msg **result)
{
- int needed = TCA_ATTR_PARENT | TCA_ATTR_HANDLE;
+ uint32_t needed = TCA_ATTR_PARENT | TCA_ATTR_HANDLE;
if ((class->ce_mask & needed) == needed &&
TC_H_MAJ(class->c_parent) && TC_H_MAJ(class->c_handle) &&
{
struct nl_msg *msg;
struct tcmsg tchdr;
- int required = TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE;
+ uint32_t required = TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE;
if ((class->ce_mask & required) != required) {
APPBUG("ifindex and handle must be specified");
int rtnl_tc_str2handle(const char *str, uint32_t *res)
{
char *colon, *end;
- uint32_t h, err;
+ uint32_t h;
+ int err;
if (!strcasecmp(str, "root")) {
*res = TC_H_ROOT;
{
int err, prio, proto;
struct tcmsg *tchdr;
- int required = TCA_ATTR_IFINDEX;
+ uint32_t required = TCA_ATTR_IFINDEX;
if ((cls->ce_mask & required) != required) {
APPBUG("ifindex must be specified");
int rtnl_cls_build_delete_request(struct rtnl_cls *cls, int flags,
struct nl_msg **result)
{
- int required = CLS_ATTR_PRIO;
+ uint32_t required = CLS_ATTR_PRIO;
if ((cls->ce_mask & required) != required) {
APPBUG("prio must be specified");
if (tb[TCA_U32_PCNT]) {
struct tc_u32_sel *sel;
- int pcnt_size;
+ size_t pcnt_size;
if (!tb[TCA_U32_SEL]) {
err = -NLE_MISSING_ATTR;
return -NLE_INVAL;
map = nla_data(nla);
- if (map->from < 0 || map->from > VLAN_PRIO_MAX) {
+ if (map->from > VLAN_PRIO_MAX) {
return -NLE_INVAL;
}
static void vlan_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
{
struct vlan_info *vi = link->l_info;
- int i, printed;
+ int printed;
+ uint32_t i;
char buf[64];
rtnl_link_vlan_flags2str(vi->vi_flags, buf, sizeof(buf));
if (vi->vi_mask & VLAN_HAS_EGRESS_QOS) {
struct ifla_vlan_qos_mapping map;
struct nlattr *qos;
- int i;
+ uint32_t i;
if (!(qos = nla_nest_start(msg, IFLA_VLAN_EGRESS_QOS)))
goto nla_put_failure;
{
struct nl_msg *msg;
struct tcmsg tchdr;
- int required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT;
+ uint32_t required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT;
if ((qdisc->ce_mask & required) != required) {
APPBUG("ifindex and parent must be specified");
BUG();
FILE *f;
- int i, n = 0;
+ int n = 0;
+ size_t i;
size_t len = 2048;
char *line;
char name[NAME_MAX];
struct rtnl_nexthop *rtnl_route_nexthop_n(struct rtnl_route *r, int n)
{
struct rtnl_nexthop *nh;
- int i;
+ uint32_t i;
if (r->ce_mask & ROUTE_ATTR_MULTIPATH && r->rt_nr_nh > n) {
i = 0;
*/
char *nl_size2str(const size_t size, char *buf, const size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < ARRAY_SIZE(size_units); i++) {
if (size >= size_units[i].limit) {
*/
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
{
- int i, split[5];
- char *units[] = {"d", "h", "m", "s", "msec"};
+ uint64_t split[5];
+ size_t i;
+ static const char *units[5] = {"d", "h", "m", "s", "msec"};
+ char * const buf_orig = buf;
-#define _SPLIT(idx, unit) if ((split[idx] = msec / unit) > 0) msec %= unit
+#define _SPLIT(idx, unit) if ((split[idx] = msec / unit)) msec %= unit
_SPLIT(0, 86400000); /* days */
_SPLIT(1, 3600000); /* hours */
_SPLIT(2, 60000); /* minutes */
#undef _SPLIT
split[4] = msec;
- memset(buf, 0, len);
-
- for (i = 0; i < ARRAY_SIZE(split); i++) {
- if (split[i] > 0) {
- char t[64];
- snprintf(t, sizeof(t), "%s%d%s",
- strlen(buf) ? " " : "", split[i], units[i]);
- strncat(buf, t, len - strlen(buf) - 1);
- }
+ for (i = 0; i < ARRAY_SIZE(split) && len; i++) {
+ int l;
+ if (split[i] == 0)
+ continue;
+ l = snprintf(buf, len, "%s%" PRIu64 "%s",
+ (buf==buf_orig) ? "" : " ", split[i], units[i]);
+ buf += l;
+ len -= l;
}
- return buf;
+ return buf_orig;
}
/** @} */
char *__type2str(int type, char *buf, size_t len,
const struct trans_tbl *tbl, size_t tbl_len)
{
- int i;
+ size_t i;
for (i = 0; i < tbl_len; i++) {
if (tbl[i].i == type) {
snprintf(buf, len, "%s", tbl[i].a);
char *__flags2str(int flags, char *buf, size_t len,
const struct trans_tbl *tbl, size_t tbl_len)
{
- int i;
+ size_t i;
int tmp = flags;
memset(buf, 0, len);
{
unsigned long l;
char *end;
- int i;
+ size_t i;
if (*buf == '\0')
return -NLE_INVAL;
int __str2flags(const char *buf, const struct trans_tbl *tbl, size_t tbl_len)
{
- int i, flags = 0, len;
+ int flags = 0;
+ size_t i;
+ size_t len; /* ptrdiff_t ? */
char *p = (char *) buf, *t;
for (;;) {
{
unsigned long lval;
char *endptr;
+ int table;
lval = strtoul(arg, &endptr, 0);
if (endptr == arg) {
- if ((lval = rtnl_route_str2table(arg)) < 0)
+ if ((table = rtnl_route_str2table(arg)) < 0)
nl_cli_fatal(EINVAL, "Unknown table name \"%s\"", arg);
}
+ else {
+ table = lval;
+ }
rtnl_route_set_table(route, lval);
}
{
unsigned long lval;
char *endptr;
+ int proto;
lval = strtoul(arg, &endptr, 0);
if (endptr == arg) {
- if ((lval = rtnl_route_str2proto(arg)) < 0)
+ if ((proto = rtnl_route_str2proto(arg)) < 0)
nl_cli_fatal(EINVAL,
"Unknown routing protocol name \"%s\"",
arg);
}
+ else {
+ proto = lval;
+ }
- rtnl_route_set_protocol(route, lval);
+ rtnl_route_set_protocol(route, proto);
}
void nl_cli_route_parse_type(struct rtnl_route *route, char *arg)