Lines Matching +full:ftrace +full:- +full:size

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
41 FILE *ftrace; /* output trace file */ variable
61 for (p = buf; len != 0 && p < &buf[sizeof(buf)-1]; len--) { in qstring()
154 (void)fprintf(ftrace, "-- %s --\n", ts(now.tv_sec)); in lastlog()
165 if (ftrace != NULL) { in tmsg()
168 vfprintf(ftrace, p, args); in tmsg()
170 (void)fputc('\n',ftrace); in tmsg()
171 fflush(ftrace); in tmsg()
185 if (ftrace != NULL && zap_stdio) { in trace_close()
186 if (ftrace != stdout) in trace_close()
187 fclose(ftrace); in trace_close()
188 ftrace = NULL; in trace_close()
207 if (ftrace != NULL) { in trace_flush()
208 fflush(ftrace); in trace_flush()
209 if (ferror(ftrace)) in trace_flush()
210 trace_off("tracing off: %s", strerror(ferror(ftrace))); in trace_flush()
221 if (ftrace != NULL) { in trace_off()
224 vfprintf(ftrace, p, args); in trace_off()
226 (void)fputc('\n',ftrace); in trace_off()
238 int dump) /* -1=no dump, 0=default, 1=force */ in tracelevel_msg()
266 while (--tracelevel != new_tracelevel); in tracelevel_msg()
283 int dump) /* -1=no dump, 0=default, 1=force */ in set_tracefile()
296 if (ftrace == NULL) { in set_tracefile()
311 /* Allow the file specified with "-T file" to be reopened, in set_tracefile()
318 && (strncmp(filename, _PATH_TRACE, sizeof(_PATH_TRACE)-1) in set_tracefile()
353 strncpy(savetracename, fn, sizeof(savetracename)-1); in set_tracefile()
354 ftrace = n_ftrace; in set_tracefile()
358 dup2(fileno(ftrace), STDOUT_FILENO); in set_tracefile()
359 dup2(fileno(ftrace), STDERR_FILENO); in set_tracefile()
381 new_tracelevel--; in sigtrace_off()
397 if (new_tracelevel > tracelevel && ftrace == NULL) { in set_tracelevel()
437 dmask = mask & -mask; in addrname()
441 (void)snprintf(sp, s + l - sp, "/%d", 32-i); in addrname()
444 (void)snprintf(sp, s + l - sp, " (mask %#x)", in addrname()
454 /* display a bit-field
464 { IFF_POINTOPOINT, 0, "PT-TO-PT" },
534 (void)putc('<', ftrace); in trace_bits()
541 && (b = tbl->bits_mask) != 0) { in trace_bits()
543 if (tbl->bits_name[0] != '\0') { in trace_bits()
545 (void)putc(c, ftrace); in trace_bits()
546 (void)fprintf(ftrace, "%s", tbl->bits_name); in trace_bits()
549 if (0 == (field &= ~(b | tbl->bits_clear))) in trace_bits()
554 if (field != 0 && tbl->bits_name != NULL) { in trace_bits()
556 (void)putc(c, ftrace); in trace_bits()
557 (void)fprintf(ftrace, tbl->bits_name, field); in trace_bits()
562 (void)fputs("> ", ftrace); in trace_bits()
571 static char buf[3*4+3+1+2+3 /* "xxx.xxx.xxx.xxx/xx-->" */ in rtname()
575 i = sprintf(buf, "%-16s-->", addrname(dst, mask, 0)); in rtname()
576 (void)sprintf(&buf[i], "%-*s", 15+20-MAX(20,i), naddr_ntoa(gate)); in rtname()
583 int force_metric, /* -1=suppress, 0=default */ in print_rts()
584 int force_ifp, /* -1=suppress, 0=default */ in print_rts()
585 int force_router, /* -1=suppress, 0=default, 1=display */ in print_rts()
586 int force_tag, /* -1=suppress, 0=default, 1=display */ in print_rts()
593 (void)fprintf(ftrace, "metric=%-2d ", rts->rts_metric); in print_rts()
595 (void)fprintf(ftrace, "%s ", (rts->rts_ifp == NULL ? in print_rts()
596 "if?" : rts->rts_ifp->int_name)); in print_rts()
598 || (force_router == 0 && rts->rts_router != rts->rts_gate)) in print_rts()
599 (void)fprintf(ftrace, "router=%s ", in print_rts()
600 naddr_ntoa(rts->rts_router)); in print_rts()
602 (void)fprintf(ftrace, "%s ", ts(rts->rts_time)); in print_rts()
604 || (force_tag == 0 && rts->rts_tag != 0)) in print_rts()
605 (void)fprintf(ftrace, "tag=%#x ", ntohs(rts->rts_tag)); in print_rts()
606 if (rts->rts_de_ag != 0) { in print_rts()
607 for (i = 1; (u_int)(1 << i) <= rts->rts_de_ag; i++) in print_rts()
609 (void)fprintf(ftrace, "de_ag=%d ", i); in print_rts()
619 if (!TRACEACTIONS || ftrace == NULL) in trace_if()
623 (void)fprintf(ftrace, "%-3s interface %-4s ", act, ifp->int_name); in trace_if()
624 (void)fprintf(ftrace, "%-15s-->%-15s ", in trace_if()
625 naddr_ntoa(ifp->int_addr), in trace_if()
626 addrname(((ifp->int_if_flags & IFF_POINTOPOINT) in trace_if()
627 ? ifp->int_dstaddr in trace_if()
628 : htonl(ifp->int_net)), in trace_if()
629 ifp->int_mask, 1)); in trace_if()
630 if (ifp->int_metric != 0) in trace_if()
631 (void)fprintf(ftrace, "metric=%d ", ifp->int_metric); in trace_if()
632 if (ifp->int_adj_inmetric != 0) in trace_if()
633 (void)fprintf(ftrace, "adj_inmetric=%u ", in trace_if()
634 ifp->int_adj_inmetric); in trace_if()
635 if (ifp->int_adj_outmetric != 0) in trace_if()
636 (void)fprintf(ftrace, "adj_outmetric=%u ", in trace_if()
637 ifp->int_adj_outmetric); in trace_if()
638 if (!IS_RIP_OUT_OFF(ifp->int_state) in trace_if()
639 && ifp->int_d_metric != 0) in trace_if()
640 (void)fprintf(ftrace, "fake_default=%u ", ifp->int_d_metric); in trace_if()
641 trace_bits(if_bits, ifp->int_if_flags, 0); in trace_if()
642 trace_bits(is_bits, ifp->int_state, 0); in trace_if()
643 (void)fputc('\n',ftrace); in trace_if()
652 if (!TRACEACTIONS || ftrace == NULL) in trace_upslot()
655 if (rts->rts_gate == new->rts_gate in trace_upslot()
656 && rts->rts_router == new->rts_router in trace_upslot()
657 && rts->rts_metric == new->rts_metric in trace_upslot()
658 && rts->rts_tag == new->rts_tag in trace_upslot()
659 && rts->rts_de_ag == new->rts_de_ag) in trace_upslot()
663 if (new->rts_gate == 0) { in trace_upslot()
664 (void)fprintf(ftrace, "Del #%d %-35s ", in trace_upslot()
665 (int)(rts - rt->rt_spares), in trace_upslot()
666 rtname(rt->rt_dst, rt->rt_mask, rts->rts_gate)); in trace_upslot()
668 (rts != rt->rt_spares in trace_upslot()
669 || AGE_RT(rt->rt_state,new->rts_ifp))); in trace_upslot()
671 } else if (rts->rts_gate != RIP_DEFAULT) { in trace_upslot()
672 (void)fprintf(ftrace, "Chg #%d %-35s ", in trace_upslot()
673 (int)(rts - rt->rt_spares), in trace_upslot()
674 rtname(rt->rt_dst, rt->rt_mask, rts->rts_gate)); in trace_upslot()
676 rts->rts_gate != new->rts_gate, in trace_upslot()
677 rts->rts_tag != new->rts_tag, in trace_upslot()
678 rts != rt->rt_spares || AGE_RT(rt->rt_state, in trace_upslot()
679 rt->rt_ifp)); in trace_upslot()
681 (void)fprintf(ftrace, "\n %19s%-16s ", "", in trace_upslot()
682 (new->rts_gate != rts->rts_gate in trace_upslot()
683 ? naddr_ntoa(new->rts_gate) : "")); in trace_upslot()
685 -(new->rts_metric == rts->rts_metric), in trace_upslot()
686 -(new->rts_ifp == rts->rts_ifp), in trace_upslot()
688 rts->rts_tag != new->rts_tag, in trace_upslot()
689 (new->rts_time != rts->rts_time in trace_upslot()
690 && (rts != rt->rt_spares in trace_upslot()
691 || AGE_RT(rt->rt_state, new->rts_ifp)))); in trace_upslot()
694 (void)fprintf(ftrace, "Add #%d %-35s ", in trace_upslot()
695 (int)(rts - rt->rt_spares), in trace_upslot()
696 rtname(rt->rt_dst, rt->rt_mask, new->rts_gate)); in trace_upslot()
698 (rts != rt->rt_spares in trace_upslot()
699 || AGE_RT(rt->rt_state,new->rts_ifp))); in trace_upslot()
701 (void)fputc('\n',ftrace); in trace_upslot()
712 if (ftrace == NULL) in trace_misc()
717 vfprintf(ftrace, p, args); in trace_misc()
719 (void)fputc('\n',ftrace); in trace_misc()
730 if (!TRACEACTIONS || ftrace == NULL) in trace_act()
735 vfprintf(ftrace, p, args); in trace_act()
737 (void)fputc('\n',ftrace); in trace_act()
748 if (!TRACEPACKETS || ftrace == NULL) in trace_pkt()
753 vfprintf(ftrace, p, args); in trace_pkt()
755 (void)fputc('\n',ftrace); in trace_pkt()
765 if (ftrace == NULL) in trace_change()
768 if (rt->rt_metric == new->rts_metric in trace_change()
769 && rt->rt_gate == new->rts_gate in trace_change()
770 && rt->rt_router == new->rts_router in trace_change()
771 && rt->rt_state == state in trace_change()
772 && rt->rt_tag == new->rts_tag in trace_change()
773 && rt->rt_de_ag == new->rts_de_ag) in trace_change()
777 (void)fprintf(ftrace, "%s %-35s ", in trace_change()
779 rtname(rt->rt_dst, rt->rt_mask, rt->rt_gate)); in trace_change()
780 print_rts(rt->rt_spares, in trace_change()
781 0,0,0,0, AGE_RT(rt->rt_state, rt->rt_ifp)); in trace_change()
782 trace_bits(rs_bits, rt->rt_state, rt->rt_state != state); in trace_change()
784 (void)fprintf(ftrace, "\n%*s %19s%-16s ", in trace_change()
786 (rt->rt_gate != new->rts_gate in trace_change()
787 ? naddr_ntoa(new->rts_gate) : "")); in trace_change()
789 -(new->rts_metric == rt->rt_metric), in trace_change()
790 -(new->rts_ifp == rt->rt_ifp), in trace_change()
792 rt->rt_tag != new->rts_tag, in trace_change()
793 (rt->rt_time != new->rts_time in trace_change()
794 && AGE_RT(rt->rt_state,new->rts_ifp))); in trace_change()
795 if (rt->rt_state != state) in trace_change()
797 (void)fputc('\n',ftrace); in trace_change()
804 if (ftrace == NULL) in trace_add_del()
808 (void)fprintf(ftrace, "%s %-35s ", in trace_add_del()
810 rtname(rt->rt_dst, rt->rt_mask, rt->rt_gate)); in trace_add_del()
811 print_rts(rt->rt_spares, 0,0,0,0,AGE_RT(rt->rt_state,rt->rt_ifp)); in trace_add_del()
812 trace_bits(rs_bits, rt->rt_state, 0); in trace_add_del()
813 (void)fputc('\n',ftrace); in trace_add_del()
826 (void)fprintf(ftrace, " %-35s ", in walk_trace()
827 rtname(RT->rt_dst, RT->rt_mask, RT->rt_gate)); in walk_trace()
828 print_rts(&RT->rt_spares[0], 0,0,0,0, AGE_RT(RT->rt_state, RT->rt_ifp)); in walk_trace()
829 trace_bits(rs_bits, RT->rt_state, 0); in walk_trace()
830 if (RT->rt_poison_time >= now_garbage in walk_trace()
831 && RT->rt_poison_metric < RT->rt_metric) in walk_trace()
832 (void)fprintf(ftrace, "pm=%d@%s", in walk_trace()
833 RT->rt_poison_metric, ts(RT->rt_poison_time)); in walk_trace()
835 rts = &RT->rt_spares[1]; in walk_trace()
837 if (rts->rts_gate != RIP_DEFAULT) { in walk_trace()
838 (void)fprintf(ftrace,"\n #%d%15s%-16s ", in walk_trace()
839 i, "", naddr_ntoa(rts->rts_gate)); in walk_trace()
843 (void)fputc('\n',ftrace); in walk_trace()
854 if (ftrace == NULL) in trace_dump()
858 (void)fputs("current daemon state:\n", ftrace); in trace_dump()
870 int size) /* total size of message */ in trace_rip() argument
876 if (!TRACEPACKETS || ftrace == NULL) in trace_rip()
880 if (msg->rip_cmd >= RIPCMD_MAX in trace_rip()
881 || msg->rip_vers == 0) { in trace_rip()
882 (void)fprintf(ftrace, "%s bad RIPv%d cmd=%d %s" in trace_rip()
883 " %s.%d size=%d\n", in trace_rip()
884 dir1, msg->rip_vers, msg->rip_cmd, dir2, in trace_rip()
885 naddr_ntoa(who->sin_addr.s_addr), in trace_rip()
886 ntohs(who->sin_port), in trace_rip()
887 size); in trace_rip()
891 (void)fprintf(ftrace, "%s RIPv%d %s %s %s.%d%s%s\n", in trace_rip()
892 dir1, msg->rip_vers, ripcmds[msg->rip_cmd], dir2, in trace_rip()
893 naddr_ntoa(who->sin_addr.s_addr), ntohs(who->sin_port), in trace_rip()
894 ifp ? " via " : "", ifp ? ifp->int_name : ""); in trace_rip()
899 switch (msg->rip_cmd) { in trace_rip()
902 n = msg->rip_nets; in trace_rip()
903 lim = (struct netinfo *)((char*)msg + size); in trace_rip()
906 && n->n_family == RIP_AF_UNSPEC in trace_rip()
907 && ntohl(n->n_metric) == HOPCNT_INFINITY in trace_rip()
908 && msg->rip_cmd == RIPCMD_REQUEST in trace_rip()
911 && (n+1)->n_family == RIP_AF_AUTH))) { in trace_rip()
912 (void)fputs("\tQUERY ", ftrace); in trace_rip()
913 if (n->n_dst != 0) in trace_rip()
914 (void)fprintf(ftrace, "%s ", in trace_rip()
915 naddr_ntoa(n->n_dst)); in trace_rip()
916 if (n->n_mask != 0) in trace_rip()
917 (void)fprintf(ftrace, "mask=%#x ", in trace_rip()
918 (u_int)ntohl(n->n_mask)); in trace_rip()
919 if (n->n_nhop != 0) in trace_rip()
920 (void)fprintf(ftrace, "nhop=%s ", in trace_rip()
921 naddr_ntoa(n->n_nhop)); in trace_rip()
922 if (n->n_tag != 0) in trace_rip()
923 (void)fprintf(ftrace, "tag=%#x ", in trace_rip()
924 ntohs(n->n_tag)); in trace_rip()
925 (void)fputc('\n',ftrace); in trace_rip()
929 if (n->n_family == RIP_AF_AUTH) { in trace_rip()
930 if (NA->a_type == RIP_AUTH_PW in trace_rip()
931 && n == msg->rip_nets) { in trace_rip()
932 (void)fprintf(ftrace, "\tPassword" in trace_rip()
935 qstring(NA->au.au_pw, in trace_rip()
940 if (NA->a_type == RIP_AUTH_MD5 in trace_rip()
941 && n == msg->rip_nets) { in trace_rip()
942 (void)fprintf(ftrace, in trace_rip()
948 ntohs(NA->au.a_md5.md5_pkt_len), in trace_rip()
949 NA->au.a_md5.md5_keyid, in trace_rip()
950 NA->au.a_md5.md5_auth_len, in trace_rip()
951 (int)ntohl(NA->au.a_md5.md5_seqno), in trace_rip()
952 (int)ntohs(NA->au.a_md5.rsvd[0]), in trace_rip()
953 (int)ntohs(NA->au.a_md5.rsvd[1])); in trace_rip()
956 (void)fprintf(ftrace, in trace_rip()
958 ntohs(NA->a_type)); in trace_rip()
960 i < (int)sizeof(NA->au.au_pw); in trace_rip()
962 (void)fprintf(ftrace, "%02x ", in trace_rip()
963 NA->au.au_pw[i]); in trace_rip()
964 (void)fputc('\n',ftrace); in trace_rip()
969 if (n->n_family != RIP_AF_INET) { in trace_rip()
970 (void)fprintf(ftrace, in trace_rip()
971 "\t(af %d) %-18s mask=%#x ", in trace_rip()
972 ntohs(n->n_family), in trace_rip()
973 naddr_ntoa(n->n_dst), in trace_rip()
974 (u_int)ntohl(n->n_mask)); in trace_rip()
975 } else if (msg->rip_vers == RIPv1) { in trace_rip()
976 (void)fprintf(ftrace, "\t%-18s ", in trace_rip()
977 addrname(n->n_dst, in trace_rip()
978 ntohl(n->n_mask), in trace_rip()
979 n->n_mask==0 ? 2 : 1)); in trace_rip()
981 (void)fprintf(ftrace, "\t%-18s ", in trace_rip()
982 addrname(n->n_dst, in trace_rip()
983 ntohl(n->n_mask), in trace_rip()
984 n->n_mask==0 ? 2 : 0)); in trace_rip()
986 (void)fprintf(ftrace, "metric=%-2d ", in trace_rip()
987 (u_int)ntohl(n->n_metric)); in trace_rip()
988 if (n->n_nhop != 0) in trace_rip()
989 (void)fprintf(ftrace, " nhop=%s ", in trace_rip()
990 naddr_ntoa(n->n_nhop)); in trace_rip()
991 if (n->n_tag != 0) in trace_rip()
992 (void)fprintf(ftrace, "tag=%#x", in trace_rip()
993 ntohs(n->n_tag)); in trace_rip()
994 (void)fputc('\n',ftrace); in trace_rip()
996 if (size != (char *)n - (char *)msg) in trace_rip()
997 (void)fprintf(ftrace, "truncated record, len %d\n", in trace_rip()
998 size); in trace_rip()
1002 fprintf(ftrace, "\tfile=\"%.*s\"\n", size-4, in trace_rip()
1003 msg->rip_tracefile); in trace_rip()