static void print_tunnel(struct ip6_tnl_parm2 *p)
{
	char s1[1024];
	char s2[1024];

	/* Do not use format_host() for local addr,
	 * symbolic name will not be useful.
	 */
	printf("%s: %s/ipv6 remote %s local %s",
	       p->name,
	       tnl_strproto(p->proto),
	       format_host_r(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
	       rt_addr_n2a_r(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
	if (p->link) {
		const char *n = ll_index_to_name(p->link);

		if (n)
			printf(" dev %s", n);
	}

	if (p->flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
		printf(" encaplimit none");
	else
		printf(" encaplimit %u", p->encap_limit);

	printf(" hoplimit %u", p->hop_limit);

	if (p->flags & IP6_TNL_F_USE_ORIG_TCLASS)
		printf(" tclass inherit");
	else {
		__u32 val = ntohl(p->flowinfo & IP6_FLOWINFO_TCLASS);

		printf(" tclass 0x%02x", (__u8)(val >> 20));
	}

	if (p->flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
		printf(" flowlabel inherit");
	else
		printf(" flowlabel 0x%05x", ntohl(p->flowinfo & IP6_FLOWINFO_FLOWLABEL));

	printf(" (flowinfo 0x%08x)", ntohl(p->flowinfo));

	if (p->flags & IP6_TNL_F_RCV_DSCP_COPY)
		printf(" dscp inherit");

	if (p->proto == IPPROTO_GRE) {
		if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
			printf(" key %u", ntohl(p->i_key));
		else if ((p->i_flags | p->o_flags) & GRE_KEY) {
			if (p->i_flags & GRE_KEY)
				printf(" ikey %u", ntohl(p->i_key));
			if (p->o_flags & GRE_KEY)
				printf(" okey %u", ntohl(p->o_key));
		}

		if (p->i_flags & GRE_SEQ)
			printf("%s  Drop packets out of sequence.", _SL_);
		if (p->i_flags & GRE_CSUM)
			printf("%s  Checksum in received packet is required.", _SL_);
		if (p->o_flags & GRE_SEQ)
			printf("%s  Sequence packets on output.", _SL_);
		if (p->o_flags & GRE_CSUM)
			printf("%s  Checksum output packets.", _SL_);
	}
}
Exemple #2
0
const char *format_host(int af, int len, const void *addr)
{
	static char buf[256];

	return format_host_r(af, len, addr, buf, 256);
}
Exemple #3
0
static void print_tunnel(const void *t)
{
	const struct ip_tunnel_parm *p = t;
	struct ip_tunnel_6rd ip6rd = {};
	char s1[1024];
	char s2[1024];

	/* Do not use format_host() for local addr,
	 * symbolic name will not be useful.
	 */
	printf("%s: %s/ip remote %s local %s",
	       p->name,
	       tnl_strproto(p->iph.protocol),
	       p->iph.daddr ? format_host_r(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
	       p->iph.saddr ? rt_addr_n2a_r(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");

	if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
		struct ip_tunnel_prl prl[16] = {};
		int i;

		prl[0].datalen = sizeof(prl) - sizeof(prl[0]);
		prl[0].addr = htonl(INADDR_ANY);

		if (!tnl_prl_ioctl(SIOCGETPRL, p->name, prl))
			for (i = 1; i < ARRAY_SIZE(prl); i++) {
				if (prl[i].addr != htonl(INADDR_ANY)) {
					printf(" %s %s ",
					       (prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr",
					       format_host(AF_INET, 4, &prl[i].addr));
				}
			}
	}

	if (p->link) {
		const char *n = ll_index_to_name(p->link);

		if (n)
			printf(" dev %s", n);
	}

	if (p->iph.ttl)
		printf(" ttl %u", p->iph.ttl);
	else
		printf(" ttl inherit");

	if (p->iph.tos) {
		SPRINT_BUF(b1);
		printf(" tos");
		if (p->iph.tos & 1)
			printf(" inherit");
		if (p->iph.tos & ~1)
			printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
			       rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1)));
	}

	if (!(p->iph.frag_off & htons(IP_DF)))
		printf(" nopmtudisc");

	if (p->iph.protocol == IPPROTO_IPV6 && !tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
		printf(" 6rd-prefix %s/%u",
		       inet_ntop(AF_INET6, &ip6rd.prefix, s1, sizeof(s1)),
		       ip6rd.prefixlen);
		if (ip6rd.relay_prefix) {
			printf(" 6rd-relay_prefix %s/%u",
			       format_host(AF_INET, 4, &ip6rd.relay_prefix),
			       ip6rd.relay_prefixlen);
		}
	}

	if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
		printf(" key %u", ntohl(p->i_key));
	else if ((p->i_flags | p->o_flags) & GRE_KEY) {
		if (p->i_flags & GRE_KEY)
			printf(" ikey %u", ntohl(p->i_key));
		if (p->o_flags & GRE_KEY)
			printf(" okey %u", ntohl(p->o_key));
	}

	if (p->i_flags & GRE_SEQ)
		printf("%s  Drop packets out of sequence.", _SL_);
	if (p->i_flags & GRE_CSUM)
		printf("%s  Checksum in received packet is required.", _SL_);
	if (p->o_flags & GRE_SEQ)
		printf("%s  Sequence packets on output.", _SL_);
	if (p->o_flags & GRE_CSUM)
		printf("%s  Checksum output packets.", _SL_);
}