Ejemplo n.º 1
0
static int link_mon_summary_cb(const struct nlmsghdr *nlh, void *data)
{
	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
	struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};

	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
	if (!info[TIPC_NLA_MON])
		return MNL_CB_ERROR;

	mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);

	open_json_object(NULL);
	print_string(PRINT_ANY, "bearer", "\nbearer %s\n",
		mnl_attr_get_str(attrs[TIPC_NLA_MON_BEARER_NAME]));

	print_uint(PRINT_ANY, "table_generation", "    table_generation %u\n",
	       mnl_attr_get_u32(attrs[TIPC_NLA_MON_LISTGEN]));
	print_uint(PRINT_ANY, "cluster_size", "    cluster_size %u\n",
		mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEERCNT]));
	print_string(PRINT_ANY, "algorithm", "    algorithm %s\n",
		attrs[TIPC_NLA_MON_ACTIVE] ? "overlapping-ring" : "full-mesh");
	close_json_object();

	return MNL_CB_OK;
}
Ejemplo n.º 2
0
static void vlan_print_map(FILE *f,
			   const char *name_json,
			   const char *name_fp,
			   struct rtattr *attr)
{
	struct ifla_vlan_qos_mapping *m;
	struct rtattr *i;
	int rem;

	open_json_array(PRINT_JSON, name_json);
	print_string(PRINT_FP, NULL, "\n      %s { ", name_fp);

	rem = RTA_PAYLOAD(attr);
	for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
		m = RTA_DATA(i);

		if (is_json_context()) {
			open_json_object(NULL);
			print_uint(PRINT_JSON, "from", NULL, m->from);
			print_uint(PRINT_JSON, "to", NULL, m->to);
			close_json_object();
		} else {
			fprintf(f, "%u:%u ", m->from, m->to);
		}
	}

	close_json_array(PRINT_JSON, NULL);
	print_string(PRINT_FP, NULL, "%s ", "}");
}
Ejemplo n.º 3
0
static int link_mon_list_cb(const struct nlmsghdr *nlh, void *data)
{
	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
	struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};
	char *req_bearer = data;
	const char *bname;
	const char title[] =
	  "node          status monitored generation applied_node_status [non_applied_node:status]";

	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
	if (!info[TIPC_NLA_MON])
		return MNL_CB_ERROR;

	mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);

	bname = mnl_attr_get_str(attrs[TIPC_NLA_MON_BEARER_NAME]);

	if (*req_bearer && (strcmp(req_bearer, bname) != 0))
		return MNL_CB_OK;

	open_json_object(NULL);
	print_string(PRINT_ANY, "bearer", "\nbearer %s\n", bname);
	print_string(PRINT_FP, NULL, "%s\n", title);

	open_json_array(PRINT_JSON, bname);
	if (mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEERCNT]))
		link_mon_peer_list(mnl_attr_get_u32(attrs[TIPC_NLA_MON_REF]));
	close_json_array(PRINT_JSON, bname);

	close_json_object();
	return MNL_CB_OK;
}
Ejemplo n.º 4
0
static int link_mon_peer_list_cb(const struct nlmsghdr *nlh, void *data)
{
	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
	struct nlattr *attrs[TIPC_NLA_MON_PEER_MAX + 1] = {};
	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
	uint16_t member_cnt;
	uint32_t applied;
	uint32_t dom_gen;
	uint64_t up_map;
	char status[16];
	char monitored[16];

	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
	if (!info[TIPC_NLA_MON_PEER])
		return MNL_CB_ERROR;

	open_json_object(NULL);
	mnl_attr_parse_nested(info[TIPC_NLA_MON_PEER], parse_attrs, attrs);

	(attrs[TIPC_NLA_MON_PEER_LOCAL] || attrs[TIPC_NLA_MON_PEER_HEAD]) ?
		strcpy(monitored, "direct") :
		strcpy(monitored, "indirect");

	attrs[TIPC_NLA_MON_PEER_UP] ?
		strcpy(status, "up") :
		strcpy(status, "down");

	dom_gen = attrs[TIPC_NLA_MON_PEER_DOMGEN] ?
		mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEER_DOMGEN]) : 0;

	link_mon_print_peer_state(mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEER_ADDR]),
				  status, monitored, dom_gen);

	applied = mnl_attr_get_u32(attrs[TIPC_NLA_MON_PEER_APPLIED]);

	if (!applied)
		goto exit;

	up_map = mnl_attr_get_u64(attrs[TIPC_NLA_MON_PEER_UPMAP]);

	member_cnt = mnl_attr_get_payload_len(attrs[TIPC_NLA_MON_PEER_MEMBERS]);

	/* each tipc address occupies 4 bytes of payload, hence compensate it */
	member_cnt /= sizeof(uint32_t);

	link_mon_print_applied(applied, up_map);

	link_mon_print_non_applied(applied, member_cnt, up_map,
				   mnl_attr_get_payload(attrs[TIPC_NLA_MON_PEER_MEMBERS]));

exit:
	print_string(PRINT_FP, NULL, "\n", "");

	close_json_object();
	return MNL_CB_OK;
}
Ejemplo n.º 5
0
static void print_tx_sc(const char *prefix, __u64 sci, __u8 encoding_sa,
			struct rtattr *txsc_stats, struct rtattr *secy_stats,
			struct rtattr *sa)
{
	struct rtattr *sa_attr[MACSEC_SA_ATTR_MAX + 1];
	struct rtattr *a;
	int rem;

	print_string(PRINT_FP, NULL, "%s", prefix);
	print_0xhex(PRINT_ANY, "sci",
		    "TXSC: %016llx", ntohll(sci));
	print_uint(PRINT_ANY, "encoding_sa",
		   " on SA %d\n", encoding_sa);

	print_secy_stats(prefix, secy_stats);
	print_txsc_stats(prefix, txsc_stats);

	open_json_array(PRINT_JSON, "sa_list");
	rem = RTA_PAYLOAD(sa);
	for (a = RTA_DATA(sa); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) {
		bool state;

		open_json_object(NULL);
		parse_rtattr_nested(sa_attr, MACSEC_SA_ATTR_MAX + 1, a);
		state = rta_getattr_u8(sa_attr[MACSEC_SA_ATTR_ACTIVE]);

		print_string(PRINT_FP, NULL, "%s", prefix);
		print_string(PRINT_FP, NULL, "%s", prefix);
		print_uint(PRINT_ANY, "an", "%d:",
			   rta_getattr_u8(sa_attr[MACSEC_SA_ATTR_AN]));
		print_uint(PRINT_ANY, "pn", " PN %u,",
			   rta_getattr_u32(sa_attr[MACSEC_SA_ATTR_PN]));

		print_bool(PRINT_JSON, "active", NULL, state);
		print_string(PRINT_FP, NULL,
			     " state %s,", state ? "on" : "off");
		print_key(sa_attr[MACSEC_SA_ATTR_KEYID]);

		print_txsa_stats(prefix, sa_attr[MACSEC_SA_ATTR_STATS]);
		close_json_object();
	}
	close_json_array(PRINT_JSON, NULL);
}
Ejemplo n.º 6
0
static void print_rxsc_list(struct rtattr *sc)
{
	int rem = RTA_PAYLOAD(sc);
	struct rtattr *c;

	open_json_array(PRINT_JSON, "rx_sc");
	for (c = RTA_DATA(sc); RTA_OK(c, rem); c = RTA_NEXT(c, rem)) {
		struct rtattr *sc_attr[MACSEC_RXSC_ATTR_MAX + 1];

		open_json_object(NULL);

		parse_rtattr_nested(sc_attr, MACSEC_RXSC_ATTR_MAX + 1, c);
		print_rx_sc("    ",
			    rta_getattr_u64(sc_attr[MACSEC_RXSC_ATTR_SCI]),
			    rta_getattr_u32(sc_attr[MACSEC_RXSC_ATTR_ACTIVE]),
			    sc_attr[MACSEC_RXSC_ATTR_STATS],
			    sc_attr[MACSEC_RXSC_ATTR_SA_LIST]);
		close_json_object();
	}
	close_json_array(PRINT_JSON, NULL);
}
Ejemplo n.º 7
0
static int link_get_cb(const struct nlmsghdr *nlh, void *data)
{
	int *prop = data;
	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
	struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1] = {};
	struct nlattr *props[TIPC_NLA_PROP_MAX + 1] = {};

	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
	if (!info[TIPC_NLA_LINK])
		return MNL_CB_ERROR;

	mnl_attr_parse_nested(info[TIPC_NLA_LINK], parse_attrs, attrs);
	if (!attrs[TIPC_NLA_LINK_PROP])
		return MNL_CB_ERROR;

	mnl_attr_parse_nested(attrs[TIPC_NLA_LINK_PROP], parse_attrs, props);
	if (!props[*prop])
		return MNL_CB_ERROR;

	new_json_obj(json);
	open_json_object(NULL);
	switch (*prop) {
		case TIPC_NLA_PROP_PRIO:
			print_uint(PRINT_ANY, PRIORITY_STR, "%u\n", mnl_attr_get_u32(props[*prop]));
		break;
		case TIPC_NLA_PROP_TOL:
			print_uint(PRINT_ANY, TOLERANCE_STR, "%u\n", mnl_attr_get_u32(props[*prop]));
		break;
		case TIPC_NLA_PROP_WIN:
			print_uint(PRINT_ANY, WINDOW_STR, "%u\n", mnl_attr_get_u32(props[*prop]));
		break;
		default:
			break;
	}
	close_json_object();
	delete_json_obj();
	return MNL_CB_OK;
}
Ejemplo n.º 8
0
static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd,
			 struct cmdl *cmdl, void *data)
{
	char buf[MNL_SOCKET_BUFFER_SIZE];
	int err = 0;

	if (help_flag) {
		fprintf(stderr, "Usage: %s link list\n", cmdl->argv[0]);
		return -EINVAL;
	}

	nlh = msg_init(buf, TIPC_NL_LINK_GET);
	if (!nlh) {
		fprintf(stderr, "error, message initialisation failed\n");
		return -1;
	}

	new_json_obj(json);
	open_json_object(NULL);
	err = msg_dumpit(nlh, link_list_cb, NULL);
	close_json_object();
	delete_json_obj();
	return err;
}
Ejemplo n.º 9
0
int print_neigh(struct nlmsghdr *n, void *arg)
{
	FILE *fp = (FILE *)arg;
	struct ndmsg *r = NLMSG_DATA(n);
	int len = n->nlmsg_len;
	struct rtattr *tb[NDA_MAX+1];
	static int logit = 1;
	__u8 protocol = 0;

	if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH &&
	    n->nlmsg_type != RTM_GETNEIGH) {
		fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n",
			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);

		return 0;
	}
	len -= NLMSG_LENGTH(sizeof(*r));
	if (len < 0) {
		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
		return -1;
	}

	if (filter.flushb && n->nlmsg_type != RTM_NEWNEIGH)
		return 0;

	if (filter.family && filter.family != r->ndm_family)
		return 0;
	if (filter.index && filter.index != r->ndm_ifindex)
		return 0;
	if (!(filter.state&r->ndm_state) &&
	    !(r->ndm_flags & NTF_PROXY) &&
	    !(r->ndm_flags & NTF_EXT_LEARNED) &&
	    (r->ndm_state || !(filter.state&0x100)) &&
	    (r->ndm_family != AF_DECnet))
		return 0;

	if (filter.master && !(n->nlmsg_flags & NLM_F_DUMP_FILTERED)) {
		if (logit) {
			logit = 0;
			fprintf(fp,
				"\nWARNING: Kernel does not support filtering by master device\n\n");
		}
	}

	parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));

	if (inet_addr_match_rta(&filter.pfx, tb[NDA_DST]))
		return 0;

	if (tb[NDA_PROTOCOL])
		protocol = rta_getattr_u8(tb[NDA_PROTOCOL]);

	if (filter.protocol && filter.protocol != protocol)
		return 0;

	if (filter.unused_only && tb[NDA_CACHEINFO]) {
		struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);

		if (ci->ndm_refcnt)
			return 0;
	}

	if (filter.flushb) {
		struct nlmsghdr *fn;

		if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
			if (flush_update())
				return -1;
		}
		fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
		memcpy(fn, n, n->nlmsg_len);
		fn->nlmsg_type = RTM_DELNEIGH;
		fn->nlmsg_flags = NLM_F_REQUEST;
		fn->nlmsg_seq = ++rth.seq;
		filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
		filter.flushed++;
		if (show_stats < 2)
			return 0;
	}

	open_json_object(NULL);
	if (n->nlmsg_type == RTM_DELNEIGH)
		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
	else if (n->nlmsg_type == RTM_GETNEIGH)
		print_null(PRINT_ANY, "miss", "%s ", "miss");

	if (tb[NDA_DST]) {
		const char *dst;
		int family = r->ndm_family;

		if (family == AF_BRIDGE) {
			if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
				family = AF_INET6;
			else
				family = AF_INET;
		}

		dst = format_host_rta(family, tb[NDA_DST]);
		print_color_string(PRINT_ANY,
				   ifa_family_color(family),
				   "dst", "%s ", dst);
	}

	if (!filter.index && r->ndm_ifindex) {
		if (!is_json_context())
			fprintf(fp, "dev ");

		print_color_string(PRINT_ANY, COLOR_IFNAME,
				   "dev", "%s ",
				   ll_index_to_name(r->ndm_ifindex));
	}

	if (tb[NDA_LLADDR]) {
		const char *lladdr;
		SPRINT_BUF(b1);

		lladdr = ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
				     RTA_PAYLOAD(tb[NDA_LLADDR]),
				     ll_index_to_type(r->ndm_ifindex),
				     b1, sizeof(b1));

		if (!is_json_context())
			fprintf(fp, "lladdr ");

		print_color_string(PRINT_ANY, COLOR_MAC,
				   "lladdr", "%s", lladdr);
	}

	if (r->ndm_flags & NTF_ROUTER)
		print_null(PRINT_ANY, "router", " %s", "router");

	if (r->ndm_flags & NTF_PROXY)
		print_null(PRINT_ANY, "proxy", " %s", "proxy");

	if (r->ndm_flags & NTF_EXT_LEARNED)
		print_null(PRINT_ANY, "extern_learn", " %s ", "extern_learn");

	if (show_stats) {
		if (tb[NDA_CACHEINFO])
			print_cacheinfo(RTA_DATA(tb[NDA_CACHEINFO]));

		if (tb[NDA_PROBES])
			print_uint(PRINT_ANY, "probes", " probes %u",
				   rta_getattr_u32(tb[NDA_PROBES]));
	}

	if (r->ndm_state)
		print_neigh_state(r->ndm_state);

	if (protocol) {
		SPRINT_BUF(b1);

		print_string(PRINT_ANY, "protocol", " proto %s ",
			     rtnl_rtprot_n2a(protocol, b1, sizeof(b1)));
	}

	print_string(PRINT_FP, NULL, "\n", "");
	close_json_object();
	fflush(stdout);

	return 0;
}
Ejemplo n.º 10
0
static int process(const struct sockaddr_nl *who, struct nlmsghdr *n,
		   void *arg)
{
	struct genlmsghdr *ghdr;
	struct rtattr *attrs[MACSEC_ATTR_MAX + 1];
	struct rtattr *attrs_secy[MACSEC_SECY_ATTR_MAX + 1];
	int len = n->nlmsg_len;
	int ifindex;
	__u64 sci;
	__u8 encoding_sa;

	if (n->nlmsg_type != genl_family)
		return -1;

	len -= NLMSG_LENGTH(GENL_HDRLEN);
	if (len < 0)
		return -1;

	ghdr = NLMSG_DATA(n);
	if (ghdr->cmd != MACSEC_CMD_GET_TXSC)
		return 0;

	parse_rtattr(attrs, MACSEC_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
	if (!validate_dump(attrs)) {
		fprintf(stderr, "incomplete dump message\n");
		return -1;
	}

	ifindex = rta_getattr_u32(attrs[MACSEC_ATTR_IFINDEX]);
	parse_rtattr_nested(attrs_secy, MACSEC_SECY_ATTR_MAX + 1,
			    attrs[MACSEC_ATTR_SECY]);

	if (!validate_secy_dump(attrs_secy)) {
		fprintf(stderr, "incomplete dump message\n");
		return -1;
	}

	sci = rta_getattr_u64(attrs_secy[MACSEC_SECY_ATTR_SCI]);
	encoding_sa = rta_getattr_u8(attrs_secy[MACSEC_SECY_ATTR_ENCODING_SA]);

	if (filter.ifindex && ifindex != filter.ifindex)
		return 0;

	if (filter.sci && sci != filter.sci)
		return 0;

	open_json_object(NULL);
	print_uint(PRINT_ANY, "ifindex", "%u: ", ifindex);
	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname",
			   "%s: ", ll_index_to_name(ifindex));

	print_attrs(attrs_secy);

	print_tx_sc("    ", sci, encoding_sa,
		    attrs[MACSEC_ATTR_TXSC_STATS],
		    attrs[MACSEC_ATTR_SECY_STATS],
		    attrs[MACSEC_ATTR_TXSA_LIST]);

	if (attrs[MACSEC_ATTR_RXSC_LIST])
		print_rxsc_list(attrs[MACSEC_ATTR_RXSC_LIST]);

	close_json_object();

	return 0;
}
Ejemplo n.º 11
0
static int _show_bc_link_stat(const char *name, struct nlattr *prop[],
			   struct nlattr *stats[])
{
	open_json_object(NULL);
	print_string(PRINT_ANY, "link", "Link <%s>\n", name);
	print_uint(PRINT_ANY, WINDOW_STR, "  Window:%u packets\n",
			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));

	open_json_object("rx packets");
	print_uint(PRINT_ANY, "rx packets", "  RX packets:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_INFO]));
	print_uint(PRINT_ANY, "fragments", " fragments:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]));
	print_uint(PRINT_ANY, "fragmented", "/%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]));
	print_uint(PRINT_ANY, "bundles", " bundles:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]));
	print_uint(PRINT_ANY, "bundled", "/%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
	close_json_object();

	open_json_object("tx packets");
	print_uint(PRINT_ANY, "tx packets", "  TX packets:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_INFO]));
	print_uint(PRINT_ANY, "fragments", " fragments:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]));
	print_uint(PRINT_ANY, "fragmented", "/%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]));
	print_uint(PRINT_ANY, "bundles", " bundles:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]));
	print_uint(PRINT_ANY, "bundled", "/%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
	close_json_object();

	open_json_object("rx naks");
	print_uint(PRINT_ANY, "rx naks", "  RX naks:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]));
	print_uint(PRINT_ANY, "defs",  " defs:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]));
	print_uint(PRINT_ANY, "dups",  " dups:%u\n",
		   mnl_attr_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
	close_json_object();

	open_json_object("tx naks");
	print_uint(PRINT_ANY, "tx naks", "  TX naks:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]));
	print_uint(PRINT_ANY, "acks",  " acks:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]));
	print_uint(PRINT_ANY, "retrans",  " retrans:%u\n",
		   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
	close_json_object();

	print_uint(PRINT_ANY, "congestion link", "  Congestion link:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]));
	print_uint(PRINT_ANY, "send queue max", "  Send queue max:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]));
	print_uint(PRINT_ANY, "avg", " avg:%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
	close_json_object();

	return MNL_CB_OK;
}
Ejemplo n.º 12
0
static int _show_link_stat(const char *name, struct nlattr *attrs[],
			   struct nlattr *prop[], struct nlattr *stats[])
{
	uint32_t proft;

	open_json_object(NULL);

	print_string(PRINT_ANY, "link", "\nLink <%s>\n", name);
	print_string(PRINT_JSON, "state", "", NULL);
	open_json_array(PRINT_JSON, NULL);
	if (attrs[TIPC_NLA_LINK_ACTIVE])
		print_string(PRINT_ANY, NULL, "  %s", "ACTIVE");
	else if (attrs[TIPC_NLA_LINK_UP])
		print_string(PRINT_ANY, NULL, "  %s", "STANDBY");
	else
		print_string(PRINT_ANY, NULL, "  %s", "DEFUNCT");
	close_json_array(PRINT_JSON, NULL);

	print_uint(PRINT_ANY, "mtu", "  MTU:%u",
			   mnl_attr_get_u32(attrs[TIPC_NLA_LINK_MTU]));
	print_uint(PRINT_ANY, PRIORITY_STR, "  Priority:%u",
			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_PRIO]));
	print_uint(PRINT_ANY, TOLERANCE_STR, "  Tolerance:%u ms",
			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_TOL]));
	print_uint(PRINT_ANY, WINDOW_STR, "  Window:%u packets\n",
			   mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));

	open_json_object("rx packets");
	print_uint(PRINT_ANY, "rx packets", "  RX packets:%u",
			   mnl_attr_get_u32(attrs[TIPC_NLA_LINK_RX]) -
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_INFO]));
	print_uint(PRINT_ANY, "fragments", " fragments:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]));
	print_uint(PRINT_ANY, "fragmented", "/%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]));
	print_uint(PRINT_ANY, "bundles", " bundles:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]));
	print_uint(PRINT_ANY, "bundled", "/%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
	close_json_object();

	open_json_object("tx packets");
	print_uint(PRINT_ANY, "tx packets", "  TX packets:%u",
			   mnl_attr_get_u32(attrs[TIPC_NLA_LINK_TX]) -
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_INFO]));
	print_uint(PRINT_ANY, "fragments", " fragments:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]));
	print_uint(PRINT_ANY, "fragmented", "/%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]));
	print_uint(PRINT_ANY, "bundles", " bundles:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]));
	print_uint(PRINT_ANY, "bundled", "/%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
	close_json_object();

	proft = mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT]);
	print_uint(PRINT_ANY, "tx profile sample", "  TX profile sample:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_CNT]));
	print_uint(PRINT_ANY, "packets average", " packets average:%u octets\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_TOT]) / proft);

	print_uint(PRINT_ANY, "0-64", "  0-64:%u%%",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P0]), proft));
	print_uint(PRINT_ANY, "-256", " -256:%u%%",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P1]), proft));
	print_uint(PRINT_ANY, "-1024", " -1024:%u%%",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P2]), proft));
	print_uint(PRINT_ANY, "-4096", " -4096:%u%%",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P3]), proft));
	print_uint(PRINT_ANY, "-16384", " -16384:%u%%",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P4]), proft));
	print_uint(PRINT_ANY, "-32768", " -32768:%u%%",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P5]), proft));
	print_uint(PRINT_ANY, "-66000", " -66000:%u%%\n",
			   perc(mnl_attr_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P6]), proft));

	open_json_object("rx states");
	print_uint(PRINT_ANY, "rx states", "  RX states:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_STATES]));
	print_uint(PRINT_ANY, "probes", " probes:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_PROBES]));
	print_uint(PRINT_ANY, "naks", " naks:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]));
	print_uint(PRINT_ANY, "defs", " defs:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]));
	print_uint(PRINT_ANY, "dups", " dups:%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
	close_json_object();

	open_json_object("tx states");
	print_uint(PRINT_ANY, "tx states", "  TX states:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_STATES]));
	print_uint(PRINT_ANY, "probes", " probes:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_PROBES]));
	print_uint(PRINT_ANY, "naks", " naks:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]));
	print_uint(PRINT_ANY, "acks", " acks:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]));
	print_uint(PRINT_ANY, "retrans", " retrans:%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
	close_json_object();

	print_uint(PRINT_ANY, "congestion link", "  Congestion link:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]));
	print_uint(PRINT_ANY, "send queue max", "  Send queue max:%u",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]));
	print_uint(PRINT_ANY, "avg", " avg:%u\n",
			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));

	close_json_object();
	return MNL_CB_OK;
}
Ejemplo n.º 13
0
static int print_ntable(struct nlmsghdr *n, void *arg)
{
	FILE *fp = (FILE *)arg;
	struct ndtmsg *ndtm = NLMSG_DATA(n);
	int len = n->nlmsg_len;
	struct rtattr *tb[NDTA_MAX+1];
	struct rtattr *tpb[NDTPA_MAX+1];
	int ret;

	if (n->nlmsg_type != RTM_NEWNEIGHTBL) {
		fprintf(stderr, "Not NEIGHTBL: %08x %08x %08x\n",
			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
		return 0;
	}
	len -= NLMSG_LENGTH(sizeof(*ndtm));
	if (len < 0) {
		fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
		return -1;
	}

	if (preferred_family && preferred_family != ndtm->ndtm_family)
		return 0;

	parse_rtattr(tb, NDTA_MAX, NDTA_RTA(ndtm),
		     n->nlmsg_len - NLMSG_LENGTH(sizeof(*ndtm)));

	if (tb[NDTA_NAME]) {
		const char *name = rta_getattr_str(tb[NDTA_NAME]);

		if (filter.name && strcmp(filter.name, name))
			return 0;
	}

	if (tb[NDTA_PARMS]) {
		parse_rtattr(tpb, NDTPA_MAX, RTA_DATA(tb[NDTA_PARMS]),
			     RTA_PAYLOAD(tb[NDTA_PARMS]));

		if (tpb[NDTPA_IFINDEX]) {
			__u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);

			if (filter.index && filter.index != ifindex)
				return 0;
		} else {
			if (filter.index && filter.index != NONE_DEV)
				return 0;
		}
	}

	open_json_object(NULL);
	print_string(PRINT_ANY, "family",
		     "%s ", family_name(ndtm->ndtm_family));

	if (tb[NDTA_NAME]) {
		const char *name = rta_getattr_str(tb[NDTA_NAME]);

		print_string(PRINT_ANY, "name", "%s ", name);
	}

	print_nl();

	ret = (tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || tb[NDTA_THRESH3] ||
	       tb[NDTA_GC_INTERVAL]);
	if (ret)
		print_string(PRINT_FP, NULL, "    ", NULL);

	if (tb[NDTA_THRESH1]) {
		__u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);

		print_uint(PRINT_ANY, "thresh1", "thresh1 %u ", thresh1);
	}

	if (tb[NDTA_THRESH2]) {
		__u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);

		print_uint(PRINT_ANY, "thresh2", "thresh2 %u ", thresh2);
	}

	if (tb[NDTA_THRESH3]) {
		__u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);

		print_uint(PRINT_ANY, "thresh3", "thresh3 %u ", thresh3);
	}

	if (tb[NDTA_GC_INTERVAL]) {
		__u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);

		print_u64(PRINT_ANY, "gc_interval", "gc_int %llu ", gc_int);
	}

	if (ret)
		print_nl();

	if (tb[NDTA_CONFIG] && show_stats)
		print_ndtconfig(RTA_DATA(tb[NDTA_CONFIG]));

	if (tb[NDTA_PARMS])
		print_ndtparams(tpb);

	if (tb[NDTA_STATS] && show_stats)
		print_ndtstats(RTA_DATA(tb[NDTA_STATS]));

	print_string(PRINT_FP, NULL, "\n", "");
	close_json_object();
	fflush(fp);

	return 0;
}
Ejemplo n.º 14
0
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	if (!tb)
		return;

	if (!tb[IFLA_GRE_COLLECT_METADATA])
		gre_print_direct_opt(f, tb);
	else
		print_bool(PRINT_ANY, "external", "external ", true);

	if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF]))
		print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true);

	if (tb[IFLA_GRE_ERSPAN_INDEX]) {
		__u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]);

		fprintf(f, "erspan_index %u ", erspan_idx);
	}

	if (tb[IFLA_GRE_ENCAP_TYPE] &&
	    rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
		__u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
		__u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
		__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
		__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);


		open_json_object("encap");
		print_string(PRINT_FP, NULL, "encap ", NULL);

		switch (type) {
		case TUNNEL_ENCAP_FOU:
			print_string(PRINT_ANY, "type", "%s ", "fou");
			break;
		case TUNNEL_ENCAP_GUE:
			print_string(PRINT_ANY, "type", "%s ", "gue");
			break;
		default:
			print_null(PRINT_ANY, "type", "%s ", "unknown");
			break;
		}

		if (is_json_context()) {
			print_uint(PRINT_JSON,
				   "sport",
				   NULL,
				   sport ? ntohs(sport) : 0);
			print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));

			print_bool(PRINT_JSON,
				   "csum",
				   NULL,
				   flags & TUNNEL_ENCAP_FLAG_CSUM);

			print_bool(PRINT_JSON,
				   "csum6",
				   NULL,
				   flags & TUNNEL_ENCAP_FLAG_CSUM6);

			print_bool(PRINT_JSON,
				   "remcsum",
				   NULL,
				   flags & TUNNEL_ENCAP_FLAG_REMCSUM);

			close_json_object();
		} else {
			if (sport == 0)
				fputs("encap-sport auto ", f);
			else
				fprintf(f, "encap-sport %u", ntohs(sport));

			fprintf(f, "encap-dport %u ", ntohs(dport));

			if (flags & TUNNEL_ENCAP_FLAG_CSUM)
				fputs("encap-csum ", f);
			else
				fputs("noencap-csum ", f);

			if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
				fputs("encap-csum6 ", f);
			else
				fputs("noencap-csum6 ", f);

			if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
				fputs("encap-remcsum ", f);
			else
				fputs("noencap-remcsum ", f);
		}
	}
}