int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct xfrm_usersa_info *xsinfo = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[XFRMA_MAX+1]; if (n->nlmsg_type != XFRM_MSG_NEWSA && n->nlmsg_type != XFRM_MSG_DELSA) { // fprintf(stderr, "Not a state: %08x %08x %08x\n", // n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); return 0; } len -= NLMSG_LENGTH(sizeof(*xsinfo)); if (len < 0) { // fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } if (!xfrm_state_filter_match(xsinfo)) return 0; parse_rtattr(tb, XFRMA_MAX, XFRMS_RTA(xsinfo), len); if (n->nlmsg_type == XFRM_MSG_DELSA) fprintf(fp, "Deleted "); xfrm_state_info_print(xsinfo, tb, fp, NULL, NULL); if (oneline) fprintf(fp, "\n"); return 0; }
int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct rtattr * tb[XFRMA_MAX+1]; struct rtattr * rta; struct xfrm_usersa_info *xsinfo = NULL; struct xfrm_user_expire *xexp = NULL; struct xfrm_usersa_id *xsid = NULL; int len = n->nlmsg_len; if (n->nlmsg_type != XFRM_MSG_NEWSA && n->nlmsg_type != XFRM_MSG_DELSA && n->nlmsg_type != XFRM_MSG_UPDSA && n->nlmsg_type != XFRM_MSG_EXPIRE) { fprintf(stderr, "Not a state: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); return 0; } if (n->nlmsg_type == XFRM_MSG_DELSA) { /* Dont blame me for this .. Herbert made me do it */ xsid = NLMSG_DATA(n); len -= NLMSG_SPACE(sizeof(*xsid)); } else if (n->nlmsg_type == XFRM_MSG_EXPIRE) { xexp = NLMSG_DATA(n); xsinfo = &xexp->state; len -= NLMSG_SPACE(sizeof(*xexp)); } else { xexp = NULL; xsinfo = NLMSG_DATA(n); len -= NLMSG_SPACE(sizeof(*xsinfo)); } if (len < 0) { fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } if (xsinfo && !xfrm_state_filter_match(xsinfo)) return 0; if (n->nlmsg_type == XFRM_MSG_DELSA) fprintf(fp, "Deleted "); else if (n->nlmsg_type == XFRM_MSG_UPDSA) fprintf(fp, "Updated "); else if (n->nlmsg_type == XFRM_MSG_EXPIRE) fprintf(fp, "Expired "); if (n->nlmsg_type == XFRM_MSG_DELSA) rta = XFRMSID_RTA(xsid); else if (n->nlmsg_type == XFRM_MSG_EXPIRE) rta = XFRMEXP_RTA(xexp); else rta = XFRMS_RTA(xsinfo); parse_rtattr(tb, XFRMA_MAX, rta, len); if (n->nlmsg_type == XFRM_MSG_DELSA) { //xfrm_policy_id_print(); if (!tb[XFRMA_SA]) { fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n"); return -1; } if (RTA_PAYLOAD(tb[XFRMA_SA]) < sizeof(*xsinfo)) { fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n"); return -1; } xsinfo = RTA_DATA(tb[XFRMA_SA]); } xfrm_state_info_print(xsinfo, tb, fp, NULL, NULL); if (n->nlmsg_type == XFRM_MSG_EXPIRE) { fprintf(fp, "\t"); fprintf(fp, "hard %u", xexp->hard); fprintf(fp, "%s", _SL_); } if (oneline) fprintf(fp, "\n"); fflush(fp); return 0; }