Esempio n. 1
0
void
dump_iproute(void *rt_data)
{
	ip_route_t *route = rt_data;
	char *log_msg = MALLOC(1024);
	char *op = log_msg;

	if (route->blackhole) {
		strncat(log_msg, "blackhole ", 30);
	}
	if (route->dst)
		op += snprintf(op, log_msg + 1024 - op, "%s/%d", ipaddresstos(NULL, route->dst), route->dmask);
	if (route->gw)
		op += snprintf(op, log_msg + 1024 - op, " gw %s", ipaddresstos(NULL, route->gw));
	if (route->gw2)
		op += snprintf(op, log_msg + 1024 - op, " or gw %s", ipaddresstos(NULL, route->gw2));
	if (route->src)
		op += snprintf(op, log_msg + 1024 - op, " src %s", ipaddresstos(NULL, route->src));
	if (route->index)
		op += snprintf(op, log_msg + 1024 - op, " dev %s",
			 IF_NAME(if_get_by_ifindex(route->index)));
	if (route->table)
		op += snprintf(op, log_msg + 1024 - op, " table %d", route->table);
	if (route->scope)
		op += snprintf(op, log_msg + 1024 - op, " scope %s",
			 netlink_scope_n2a(route->scope));
	if (route->metric)
		op += snprintf(op, log_msg + 1024 - op, " metric %d", route->metric);

	log_message(LOG_INFO, "     %s", log_msg);

	FREE(log_msg);
}
Esempio n. 2
0
void
address_print(FILE *file, void *data)
{
	ip_address_t *ipaddr = data;
	char *broadcast = (char *) MALLOC(21);
	char *addr_str = (char *) MALLOC(41);

	if (IP_IS6(ipaddr)) {
		inet_ntop(AF_INET6, &ipaddr->u.sin6_addr, addr_str, 41);
	} else {
		inet_ntop(AF_INET, &ipaddr->u.sin.sin_addr, addr_str, 41);
	if (ipaddr->u.sin.sin_brd.s_addr)
		snprintf(broadcast, 20, " brd %s",
			 inet_ntop2(ipaddr->u.sin.sin_brd.s_addr));
	}

	fprintf(file, "     %s/%d%s dev %s scope %s%s%s\n"
		, addr_str
		, ipaddr->ifa.ifa_prefixlen
		, broadcast
		, IF_NAME(ipaddr->ifp)
		, netlink_scope_n2a(ipaddr->ifa.ifa_scope)
		, ipaddr->label ? " label " : ""
		, ipaddr->label ? ipaddr->label : "");
	FREE(broadcast);
	FREE(addr_str);
}
Esempio n. 3
0
static void
route_print(FILE *file, void *data)
{
	ip_route_t *route = data;

	fprintf(file, "     ");

	if (route->blackhole)
		fprintf(file, "blackhole ");
	if (route->dst)
		fprintf(file, "%s/%d", ipaddresstos(NULL, route->dst), route->dmask);
	if (route->gw)
		fprintf(file, " gw %s", ipaddresstos(NULL, route->gw));
	if (route->gw2)
		fprintf(file, " or gw %s", ipaddresstos(NULL, route->gw2));
	if (route->src)
		fprintf(file, " src %s", ipaddresstos(NULL, route->src));
	if (route->index)
		fprintf(file, " dev %s", IF_NAME(if_get_by_ifindex(route->index)));
	if (route->table)
		fprintf(file, " table %d", route->table);
	if (route->scope)
		fprintf(file, " scope %s", netlink_scope_n2a(route->scope));
	if (route->metric)
		fprintf(file, " metric %d", route->metric);

	fprintf(file, "\n");
}
Esempio n. 4
0
static void
address_print(FILE *file, void *data)
{
	ip_address_t *ipaddr = data;
	char broadcast[INET_ADDRSTRLEN + 5] = "";	/* allow for " brd " */
	char addr_str[INET6_ADDRSTRLEN] = "";

	if (IP_IS6(ipaddr)) {
		inet_ntop(AF_INET6, &ipaddr->u.sin6_addr, addr_str, sizeof(addr_str));
	} else {
		inet_ntop(AF_INET, &ipaddr->u.sin.sin_addr, addr_str, sizeof(addr_str));
	if (ipaddr->u.sin.sin_brd.s_addr)
		snprintf(broadcast, sizeof(broadcast) - 1, " brd %s",
			 inet_ntop2(ipaddr->u.sin.sin_brd.s_addr));
	}

	fprintf(file, "     %s/%d%s dev %s%s%s%s%s\n"
		, addr_str
		, ipaddr->ifa.ifa_prefixlen
		, broadcast
		, IF_NAME(ipaddr->ifp)
		, IP_IS4(ipaddr) ? " scope " : ""
		, IP_IS4(ipaddr) ? netlink_scope_n2a(ipaddr->ifa.ifa_scope) : ""
		, ipaddr->label ? " label " : ""
		, ipaddr->label ? ipaddr->label : "");
}
Esempio n. 5
0
void
dump_iproute(void *rt_data)
{
	ip_route_t *route = rt_data;
	char *log_msg = MALLOC(1024);
	char *tmp = MALLOC(INET6_ADDRSTRLEN + 30);
	char *tmp_str;

	if (route->blackhole) {
		strncat(log_msg, "blackhole ", 30);
	}
	if (route->dst) {
		tmp_str = ipaddresstos(route->dst);
		snprintf(tmp, INET6_ADDRSTRLEN + 30, "%s/%d", tmp_str, route->dmask);
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
		FREE(tmp_str);
	}
	if (route->gw) {
		tmp_str = ipaddresstos(route->gw);
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " gw %s", tmp_str);
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
		FREE(tmp_str);
	}
	if (route->gw2) {
		tmp_str = ipaddresstos(route->gw2);
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " or gw %s", tmp_str);
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
		FREE(tmp_str);
	}
	if (route->src) {
		tmp_str = ipaddresstos(route->src);
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " src %s", tmp_str);
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
		FREE(tmp_str);
	}
	if (route->index) {
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " dev %s",
			 IF_NAME(if_get_by_ifindex(route->index)));
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
	}
	if (route->table) {
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " table %d", route->table);
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
	}
	if (route->scope) {
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " scope %s",
			 netlink_scope_n2a(route->scope));
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
	}
	if (route->metric) {
		snprintf(tmp, INET6_ADDRSTRLEN + 30, " metric %d", route->metric);
		strncat(log_msg, tmp, INET6_ADDRSTRLEN + 30);
	}

	log_message(LOG_INFO, "     %s", log_msg);

	FREE(tmp);
	FREE(log_msg);
}
Esempio n. 6
0
void
route_print(FILE *file, void *data)
{
	ip_route_t *route = data;
	char *msg = MALLOC(150);
	char *tmp = MALLOC(30);

	if (route->blackhole) {
		strncat(msg, "blackhole ", 30);
	}
	if (route->dst) {
		snprintf(tmp, 30, "%s/%d", ipaddresstos(route->dst),
			route->dmask);
		strncat(msg, tmp, 30);
	}
	if (route->gw) {
		snprintf(tmp, 30, " gw %s", ipaddresstos(route->gw));
		strncat(msg, tmp, 30);
	}
	if (route->gw2) {
		snprintf(tmp, 30, " or gw %s", ipaddresstos(route->gw2));
		strncat(msg, tmp, 30);
	}
	if (route->src) {
		snprintf(tmp, 30, " src %s", ipaddresstos(route->src));
		strncat(msg, tmp, 30);
	}
	if (route->index) {
		snprintf(tmp, 30, " dev %s",
		  IF_NAME(if_get_by_ifindex(route->index)));
		strncat(msg, tmp, 30);
	}
	if (route->table) {
		snprintf(tmp, 30, " table %d", route->table);
		strncat(msg, tmp, 30);
	}
	if (route->scope) {
		snprintf(tmp, 30, " scope %s",
		  netlink_scope_n2a(route->scope));
		strncat(msg, tmp, 30);
	}
	if (route->metric) {
		snprintf(tmp, 30, " metric %d", route->metric);
		strncat(msg, tmp, 30);
	}

	fprintf(file, "     %s\n", msg);

	FREE(tmp);
	FREE(msg);

}