Пример #1
0
static int eam_display_response(struct nl_msg *msg, void *arg)
{
	struct nlmsghdr *hdr;
	struct eamt_entry *entries;
	struct display_params *params = arg;
	__u16 entry_count, i;

	hdr = nlmsg_hdr(msg);
	entries = nlmsg_data(hdr);
	entry_count = nlmsg_datalen(hdr) / sizeof(*entries);

	if (params->csv_format) {
		for (i = 0; i < entry_count; i++) {
			print_eamt_entry(&entries[i], ",");
		}
	} else {
		for (i = 0; i < entry_count; i++) {
			print_eamt_entry(&entries[i], " - ");
		}
	}

	params->row_count += entry_count;
	params->req_payload->display.prefix4_set = hdr->nlmsg_flags & NLM_F_MULTI;
	if (entry_count > 0)
		params->req_payload->display.prefix4 = entries[entry_count - 1].prefix4;
	return 0;
}
Пример #2
0
static NMIP6Device *
process_nduseropt (NMIP6Manager *manager, struct nl_msg *msg)
{
	NMIP6Device *device;
	struct nduseroptmsg *ndmsg;
	struct nd_opt_hdr *opt;
	guint opts_len;
	gboolean changed = FALSE;

	nm_log_dbg (LOGD_IP6, "processing netlink nduseropt message");

	ndmsg = (struct nduseroptmsg *) NLMSG_DATA (nlmsg_hdr (msg));

	if (!nlmsg_valid_hdr (nlmsg_hdr (msg), sizeof (*ndmsg)) ||
	    nlmsg_datalen (nlmsg_hdr (msg)) <
		(ndmsg->nduseropt_opts_len + sizeof (*ndmsg))) {
		nm_log_dbg (LOGD_IP6, "ignoring invalid nduseropt message");
		return NULL;
	}

	if (ndmsg->nduseropt_family != AF_INET6 ||
		ndmsg->nduseropt_icmp_type != ND_ROUTER_ADVERT ||
		ndmsg->nduseropt_icmp_code != 0) {
		nm_log_dbg (LOGD_IP6, "ignoring non-Router Advertisement message");
		return NULL;
	}

	device = nm_ip6_manager_get_device (manager, ndmsg->nduseropt_ifindex);
	if (!device) {
		nm_log_dbg (LOGD_IP6, "ignoring message for unknown device");
		return NULL;
	}

	opt = (struct nd_opt_hdr *) (ndmsg + 1);
	opts_len = ndmsg->nduseropt_opts_len;

	while (opts_len >= sizeof (struct nd_opt_hdr)) {
		size_t nd_opt_len = opt->nd_opt_len;

		if (nd_opt_len == 0 || opts_len < (nd_opt_len << 3))
			break;

		switch (opt->nd_opt_type) {
		case ND_OPT_RDNSS:
			changed = process_nduseropt_rdnss (device, opt);
			break;
		case ND_OPT_DNSSL:
			changed = process_nduseropt_dnssl (device, opt);
			break;
		}

		opts_len -= opt->nd_opt_len << 3;
		opt = (struct nd_opt_hdr *) ((uint8_t *) opt + (opt->nd_opt_len << 3));
	}

	if (changed)
		return device;
	else
		return NULL;
}
Пример #3
0
static int pool4_display_response(struct nl_msg *msg, void *arg)
{
	struct nlmsghdr *hdr;
	struct in_addr *addresses;
	__u16 addr_count, i;

	hdr = nlmsg_hdr(msg);
	addresses = nlmsg_data(hdr);
	addr_count = nlmsg_datalen(hdr) / sizeof(*addresses);

	for (i = 0; i < addr_count; i++)
		printf("%s\n", inet_ntoa(addresses[i]));

	*((int *) arg) += addr_count;
	return 0;
}
Пример #4
0
static int pool6_display_response(struct nl_msg *msg, void *arg)
{
	struct nlmsghdr *hdr;
	struct ipv6_prefix *prefixes;
	int pref_count, i;
	char addr_str[INET6_ADDRSTRLEN];

	hdr = nlmsg_hdr(msg);
	prefixes = nlmsg_data(hdr);
	pref_count = nlmsg_datalen(hdr) / sizeof(*prefixes);

	for (i = 0; i < pref_count; i++) {
		inet_ntop(AF_INET6, &prefixes[i].address, addr_str, INET6_ADDRSTRLEN);
		printf("%s/%u\n", addr_str, prefixes[i].len);
	}

	*((int *) arg) += pref_count;
	return 0;
}
Пример #5
0
static int pool4_display_response(struct nl_msg *response, void *arg)
{
    struct nlmsghdr *hdr;
    struct ipv4_prefix *prefixes;
    unsigned int prefix_count, i;
    struct display_args *args = arg;

    hdr = nlmsg_hdr(response);
    prefixes = nlmsg_data(hdr);
    prefix_count = nlmsg_datalen(hdr) / sizeof(*prefixes);

    for (i = 0; i < prefix_count; i++)
        printf("%s/%u\n", inet_ntoa(prefixes[i].address), prefixes[i].len);

    args->row_count += prefix_count;
    args->request->display.prefix_set = hdr->nlmsg_flags & NLM_F_MULTI;
    if (prefix_count > 0)
        args->request->display.prefix = prefixes[prefix_count - 1];
    return 0;
}
Пример #6
0
static int logtime_display_response(struct nl_msg *msg, void *arg)
{
	struct nlmsghdr *hdr;
	struct logtime_entry_usr *entries;
	struct display_params *params = arg;
	const char *l3_proto_out, *l4_proto;
	char *l3_proto_in;
	__u16 entry_count, i;

	hdr = nlmsg_hdr(msg);
	entries = nlmsg_data(hdr);
	entry_count = nlmsg_datalen(hdr) / sizeof(*entries);

	if (params->req_payload->l3_proto == L3PROTO_IPV4) {
		l3_proto_in = "IPv6";
	} else {
		l3_proto_in = "IPv4";
	}
	l3_proto_out = l3proto_to_string(params->req_payload->l3_proto);
	l4_proto = l4proto_to_string(params->req_payload->l4_proto);

	for (i = 0; i < entry_count; i++) {
		printf ("%s->%s,", l3_proto_in, l3_proto_out);
		printf ("%s,", l4_proto);
		printf ("%ld,%ld\n", entries[i].time.tv_sec, entries[i].time.tv_nsec);
	}

	params->row_count += entry_count;

	if (hdr->nlmsg_flags & NLM_F_MULTI) {
		params->req_payload->display.iterate = true;
	} else {
		params->req_payload->display.iterate = false;
	}
	return 0;
}
Пример #7
0
/* Length of attributes data */
int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
{
	return nlmsg_datalen(nlh) - NLMSG_ALIGN(hdrlen);
}
Пример #8
0
static int session_display_response(struct nl_msg *msg, void *arg)
{
    struct nlmsghdr *hdr;
    struct session_entry_usr *entries;
    struct display_params *params = arg;
    __u16 entry_count, i;

    hdr = nlmsg_hdr(msg);
    entries = nlmsg_data(hdr);
    entry_count = nlmsg_datalen(hdr) / sizeof(*entries);

    if (params->csv_format) {
        for (i = 0; i < entry_count; i++) {
            struct session_entry_usr *entry = &entries[i];

            printf("%s,", l4proto_to_string(params->req_payload->l4_proto));
            print_addr6(&entry->remote6, params->numeric_hostname, ",",
                        params->req_payload->l4_proto);
            printf(",");
            print_addr6(&entry->local6, true, ",", params->req_payload->l4_proto);
            printf(",");
            print_addr4(&entry->local4, true, ",", params->req_payload->l4_proto);
            printf(",");
            print_addr4(&entry->remote4, params->numeric_hostname, ",",
                        params->req_payload->l4_proto);
            printf(",");
            print_time_csv(entry->dying_time);
            if (params->req_payload->l4_proto == L4PROTO_TCP)
                printf(",%s", tcp_state_to_string(entry->state));
            printf("\n");
        }
    } else {
        for (i = 0; i < entry_count; i++) {
            struct session_entry_usr *entry = &entries[i];

            if (params->req_payload->l4_proto == L4PROTO_TCP)
                printf("(%s) ", tcp_state_to_string(entry->state));

            printf("Expires in ");
            print_time_friendly(entry->dying_time);

            printf("Remote: ");
            print_addr4(&entry->remote4, params->numeric_hostname, "#",
                        params->req_payload->l4_proto);

            printf("\t");
            print_addr6(&entry->remote6, params->numeric_hostname, "#",
                        params->req_payload->l4_proto);
            printf("\n");

            printf("Local: ");
            print_addr4(&entry->local4, true, "#", params->req_payload->l4_proto);

            printf("\t");
            print_addr6(&entry->local6, true, "#", params->req_payload->l4_proto);
            printf("\n");

            printf("---------------------------------\n");
        }
    }

    params->row_count += entry_count;
    params->req_payload->display.connection_set = hdr->nlmsg_flags == NLM_F_MULTI;
    if (entry_count > 0) {
        params->req_payload->display.remote4 = entries[entry_count - 1].remote4;
        params->req_payload->display.local4 = entries[entry_count - 1].local4;
    }
    return 0;
}