static int xfrm_acquire_print(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct xfrm_user_acquire *xacq = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[XFRMA_MAX+1]; __u16 family; len -= NLMSG_LENGTH(sizeof(*xacq)); if (len < 0) { fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } parse_rtattr(tb, XFRMA_MAX, XFRMACQ_RTA(xacq), len); family = xacq->sel.family; if (family == AF_UNSPEC) family = xacq->policy.sel.family; if (family == AF_UNSPEC) family = preferred_family; fprintf(fp, "acquire "); fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto)); if (show_stats > 0 || xacq->id.spi) { __u32 spi = ntohl(xacq->id.spi); fprintf(fp, "spi 0x%08x", spi); if (show_stats > 0) fprintf(fp, "(%u)", spi); fprintf(fp, " "); } fprintf(fp, "%s", _SL_); xfrm_selector_print(&xacq->sel, family, fp, " sel "); xfrm_policy_info_print(&xacq->policy, tb, fp, " ", " policy "); if (show_stats > 0) fprintf(fp, " seq 0x%08u ", xacq->seq); if (show_stats > 0) { fprintf(fp, "%s-mask %s ", strxf_algotype(XFRMA_ALG_CRYPT), strxf_mask32(xacq->ealgos)); fprintf(fp, "%s-mask %s ", strxf_algotype(XFRMA_ALG_AUTH), strxf_mask32(xacq->aalgos)); fprintf(fp, "%s-mask %s", strxf_algotype(XFRMA_ALG_COMP), strxf_mask32(xacq->calgos)); } fprintf(fp, "%s", _SL_); if (oneline) fprintf(fp, "\n"); fflush(fp); return 0; }
int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { struct rtattr * tb[XFRMA_MAX+1]; struct rtattr * rta; struct xfrm_userpolicy_info *xpinfo = NULL; struct xfrm_user_polexpire *xpexp = NULL; struct xfrm_userpolicy_id *xpid = NULL; __u8 ptype = XFRM_POLICY_TYPE_MAIN; FILE *fp = (FILE*)arg; int len = n->nlmsg_len; if (n->nlmsg_type != XFRM_MSG_NEWPOLICY && n->nlmsg_type != XFRM_MSG_DELPOLICY && n->nlmsg_type != XFRM_MSG_UPDPOLICY && n->nlmsg_type != XFRM_MSG_POLEXPIRE) { fprintf(stderr, "Not a policy: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); return 0; } if (n->nlmsg_type == XFRM_MSG_DELPOLICY) { xpid = NLMSG_DATA(n); len -= NLMSG_SPACE(sizeof(*xpid)); } else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) { xpexp = NLMSG_DATA(n); xpinfo = &xpexp->pol; len -= NLMSG_SPACE(sizeof(*xpexp)); } else { xpexp = NULL; xpinfo = NLMSG_DATA(n); len -= NLMSG_SPACE(sizeof(*xpinfo)); } if (len < 0) { fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } if (n->nlmsg_type == XFRM_MSG_DELPOLICY) rta = XFRMPID_RTA(xpid); else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) rta = XFRMPEXP_RTA(xpexp); else rta = XFRMP_RTA(xpinfo); parse_rtattr(tb, XFRMA_MAX, rta, len); if (tb[XFRMA_POLICY_TYPE]) { struct xfrm_userpolicy_type *upt; if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt)) { fprintf(stderr, "too short XFRMA_POLICY_TYPE len\n"); return -1; } upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]); ptype = upt->type; } if (xpinfo && !xfrm_policy_filter_match(xpinfo, ptype)) return 0; if (n->nlmsg_type == XFRM_MSG_DELPOLICY) fprintf(fp, "Deleted "); else if (n->nlmsg_type == XFRM_MSG_UPDPOLICY) fprintf(fp, "Updated "); else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) fprintf(fp, "Expired "); if (n->nlmsg_type == XFRM_MSG_DELPOLICY) { //xfrm_policy_id_print(); if (!tb[XFRMA_POLICY]) { fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n"); return -1; } if (RTA_PAYLOAD(tb[XFRMA_POLICY]) < sizeof(*xpinfo)) { fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n"); return -1; } xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]); } xfrm_policy_info_print(xpinfo, tb, fp, NULL, NULL); if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) { fprintf(fp, "\t"); fprintf(fp, "hard %u", xpexp->hard); fprintf(fp, "%s", _SL_); } if (oneline) fprintf(fp, "\n"); fflush(fp); return 0; }