Пример #1
0
void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
		      FILE *fp, const char *prefix)
{
	if (tb[XFRMA_ALG_AUTH]) {
		struct rtattr *rta = tb[XFRMA_ALG_AUTH];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_CRYPT]) {
		struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_COMP]) {
		struct rtattr *rta = tb[XFRMA_ALG_COMP];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ENCAP]) {
		struct xfrm_encap_tmpl *e;
		char abuf[256];

		if (prefix)
			fprintf(fp, prefix);
		fprintf(fp, "encap ");

		if (RTA_PAYLOAD(tb[XFRMA_ENCAP]) < sizeof(*e)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}
		e = (struct xfrm_encap_tmpl *) RTA_DATA(tb[XFRMA_ENCAP]);

		fprintf(fp, "type ");
		switch (e->encap_type) {
		case 1:
			fprintf(fp, "espinudp-nonike ");
			break;
		case 2:
			fprintf(fp, "espinudp ");
			break;
		default:
			fprintf(fp, "%u ", e->encap_type);
			break;
		}
		fprintf(fp, "sport %u ", ntohs(e->encap_sport));
		fprintf(fp, "dport %u ", ntohs(e->encap_dport));

		memset(abuf, '\0', sizeof(abuf));
		fprintf(fp, "addr %s",
			rt_addr_n2a(family, sizeof(e->encap_oa),
				    &e->encap_oa, abuf, sizeof(abuf)));
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_TMPL]) {
		struct rtattr *rta = tb[XFRMA_TMPL];
		xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
				RTA_PAYLOAD(rta), family, fp, prefix);
	}
}
Пример #2
0
void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
		      FILE *fp, const char *prefix)
{
	if (tb[XFRMA_MARK]) {
		struct rtattr *rta = tb[XFRMA_MARK];
		struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta);
		fprintf(fp, "\tmark %d/0x%x\n", m->v, m->m);
	}

	if (tb[XFRMA_ALG_AUTH]) {
		struct rtattr *rta = tb[XFRMA_ALG_AUTH];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_AEAD]) {
		struct rtattr *rta = tb[XFRMA_ALG_AEAD];
		xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
				RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_CRYPT]) {
		struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_COMP]) {
		struct rtattr *rta = tb[XFRMA_ALG_COMP];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ENCAP]) {
		struct xfrm_encap_tmpl *e;
		char abuf[256];

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "encap ");

		if (RTA_PAYLOAD(tb[XFRMA_ENCAP]) < sizeof(*e)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}
		e = (struct xfrm_encap_tmpl *) RTA_DATA(tb[XFRMA_ENCAP]);

		fprintf(fp, "type ");
		switch (e->encap_type) {
		case 1:
			fprintf(fp, "espinudp-nonike ");
			break;
		case 2:
			fprintf(fp, "espinudp ");
			break;
		default:
			fprintf(fp, "%u ", e->encap_type);
			break;
		}
		fprintf(fp, "sport %u ", ntohs(e->encap_sport));
		fprintf(fp, "dport %u ", ntohs(e->encap_dport));

		memset(abuf, '\0', sizeof(abuf));
		fprintf(fp, "addr %s",
			rt_addr_n2a(family, sizeof(e->encap_oa),
				    &e->encap_oa, abuf, sizeof(abuf)));
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_TMPL]) {
		struct rtattr *rta = tb[XFRMA_TMPL];
		xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
				RTA_PAYLOAD(rta), family, fp, prefix);
	}

	if (tb[XFRMA_COADDR]) {
		char abuf[256];
		xfrm_address_t *coa;

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "coa ");

		coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);

		if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}

		memset(abuf, '\0', sizeof(abuf));
		fprintf(fp, "%s",
			rt_addr_n2a(family, sizeof(*coa), coa,
				    abuf, sizeof(abuf)));
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_LASTUSED]) {
		__u64 lastused;

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "lastused ");

		if (RTA_PAYLOAD(tb[XFRMA_LASTUSED]) < sizeof(lastused)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}

		lastused = *(__u64 *)RTA_DATA(tb[XFRMA_LASTUSED]);

		fprintf(fp, "%s", strxf_time(lastused));
		fprintf(fp, "%s", _SL_);
	}

}
Пример #3
0
void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
		      FILE *fp, const char *prefix)
{
	if (tb[XFRMA_MARK]) {
		struct rtattr *rta = tb[XFRMA_MARK];
		struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta);
		fprintf(fp, "\tmark %#x/%#x", m->v, m->m);
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_ALG_AUTH] && !tb[XFRMA_ALG_AUTH_TRUNC]) {
		struct rtattr *rta = tb[XFRMA_ALG_AUTH];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_AUTH_TRUNC]) {
		struct rtattr *rta = tb[XFRMA_ALG_AUTH_TRUNC];
		xfrm_auth_trunc_print((struct xfrm_algo_auth *) RTA_DATA(rta),
				      RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_AEAD]) {
		struct rtattr *rta = tb[XFRMA_ALG_AEAD];
		xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
				RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_CRYPT]) {
		struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ALG_COMP]) {
		struct rtattr *rta = tb[XFRMA_ALG_COMP];
		xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
				XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_ENCAP]) {
		struct xfrm_encap_tmpl *e;
		char abuf[256];

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "encap ");

		if (RTA_PAYLOAD(tb[XFRMA_ENCAP]) < sizeof(*e)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}
		e = (struct xfrm_encap_tmpl *) RTA_DATA(tb[XFRMA_ENCAP]);

		fprintf(fp, "type ");
		switch (e->encap_type) {
		case 1:
			fprintf(fp, "espinudp-nonike ");
			break;
		case 2:
			fprintf(fp, "espinudp ");
			break;
		default:
			fprintf(fp, "%u ", e->encap_type);
			break;
		}
		fprintf(fp, "sport %u ", ntohs(e->encap_sport));
		fprintf(fp, "dport %u ", ntohs(e->encap_dport));

		memset(abuf, '\0', sizeof(abuf));
		fprintf(fp, "addr %s",
			rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa,
				    abuf, sizeof(abuf)));
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_TMPL]) {
		struct rtattr *rta = tb[XFRMA_TMPL];
		xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
				RTA_PAYLOAD(rta), fp, prefix);
	}

	if (tb[XFRMA_COADDR]) {
		char abuf[256];
		xfrm_address_t *coa;

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "coa ");

		coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);

		if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}

		memset(abuf, '\0', sizeof(abuf));
		fprintf(fp, "%s",
			rt_addr_n2a(family, sizeof(*coa), coa,
				    abuf, sizeof(abuf)));
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_LASTUSED]) {
		__u64 lastused;

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "lastused ");

		if (RTA_PAYLOAD(tb[XFRMA_LASTUSED]) < sizeof(lastused)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}

		lastused = rta_getattr_u64(tb[XFRMA_LASTUSED]);

		fprintf(fp, "%s", strxf_time(lastused));
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_REPLAY_VAL]) {
		struct xfrm_replay_state *replay;

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "anti-replay context: ");

		if (RTA_PAYLOAD(tb[XFRMA_REPLAY_VAL]) < sizeof(*replay)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}

		replay = (struct xfrm_replay_state *)RTA_DATA(tb[XFRMA_REPLAY_VAL]);
		fprintf(fp, "seq 0x%x, oseq 0x%x, bitmap 0x%08x",
			replay->seq, replay->oseq, replay->bitmap);
		fprintf(fp, "%s", _SL_);
	}

	if (tb[XFRMA_REPLAY_ESN_VAL]) {
		struct xfrm_replay_state_esn *replay;
		unsigned int i, j;

		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, "anti-replay esn context:");

		if (RTA_PAYLOAD(tb[XFRMA_REPLAY_ESN_VAL]) < sizeof(*replay)) {
			fprintf(fp, "(ERROR truncated)");
			fprintf(fp, "%s", _SL_);
			return;
		}
		fprintf(fp, "%s", _SL_);

		replay = (struct xfrm_replay_state_esn *)RTA_DATA(tb[XFRMA_REPLAY_ESN_VAL]);
		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, " seq-hi 0x%x, seq 0x%x, oseq-hi 0x%0x, oseq 0x%0x",
			replay->seq_hi, replay->seq, replay->oseq_hi,
			replay->oseq);
		fprintf(fp, "%s", _SL_);
		if (prefix)
			fputs(prefix, fp);
		fprintf(fp, " replay_window %u, bitmap-length %u",
			replay->replay_window, replay->bmp_len);
		for (i = replay->bmp_len, j = 0; i; i--) {
			if (j++ % 8 == 0) {
				fprintf(fp, "%s", _SL_);
				if (prefix)
					fputs(prefix, fp);
				fprintf(fp, " ");
			}
			fprintf(fp, "%08x ", replay->bmp[i - 1]);
		}
		fprintf(fp, "%s", _SL_);
	}
}